hch
2 天以前 87d5c46997d61523aed87fdb7ed0b07e9dded223
0312 优化淘金派遣
3个文件已修改
165 ■■■■■ 已修改文件
Main/System/InternalAffairs/GoldRushLeader.cs 14 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Main/System/InternalAffairs/GoldRushManager.cs 68 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Main/System/InternalAffairs/GoldRushTentCell.cs 83 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Main/System/InternalAffairs/GoldRushLeader.cs
@@ -16,19 +16,19 @@
    public Tween leaderSequence;
    private int leaderPosIndex = -1; //监工已达移动点
    private int state = 0; //0 站岗(不显示) 1 前进 2 空手返程 3 货物返程(不中断)
    int tendID;
    GoldRushPosEvent[] leaderPathPointArr;  //监工移动点
    Action<bool> OnComplete;
    public Action<bool> OnComplete;
    public bool forcrCallBack;
    public void Init(GoldRushPosEvent[] _leaderPathPointArr, float waitTime, int _tendID, int index, bool isBack, Action<bool> _OnComplete)
    public void Init(GoldRushPosEvent[] _leaderPathPointArr, float waitTime, int _tendID, int index, bool isBack,
        Action<bool> _OnComplete)
    {
        tendID = _tendID;
        leaderPathPointArr = _leaderPathPointArr;
        leaderPosIndex = !isBack ? -1: leaderPathPointArr.Length - 1;
        state = 0;
        leaderPosIndex = !isBack ? -1 : leaderPathPointArr.Length - 1;
        leaderWord.Stop();
        leaderWord.SetEndState();
        // goods.SetActive(isBack);
@@ -77,12 +77,12 @@
        Vector3 nextPos = leaderPathPointArr[moveIndex].transform.localPosition;
        if (isBack)
        {
            if (GoldRushManager.Instance.HasWorking(tendID))
            if (forcrCallBack)
            {
                leader.PlayAnimation("run", true, false);
            }
            else
            {
            {
                leader.PlayAnimation("run_xiangzi", true, false);
            }
        }
Main/System/InternalAffairs/GoldRushManager.cs
@@ -15,7 +15,7 @@
    public int housekeeperEndTime;   // 自动管家到期时间戳,有值同时也代表免费试用已使用
    public byte[] warehouseIDList;  //完成的,包含0空,主要用于领取的索引
    public Dictionary<int, HB037_tagSCGoldRushCampInfo.tagSCGoldRushCamp> campInfoDict = new Dictionary<int, HB037_tagSCGoldRushCampInfo.tagSCGoldRushCamp>();
    public Dictionary<int, Dictionary<int, int[]>> tmpCampWorkerSkinIDDict = new Dictionary<int, Dictionary<int, int[]>>(); //最后一次营地淘金对应的皮肤(预分配),纯粹用于显示模型
    public Dictionary<int, List<int>> tmpCampWorkerSkinIDDict = new Dictionary<int, List<int>>(); //最后一次营地淘金对应的皮肤(预分配),纯粹用于显示模型
    public event Action<int> OnGoldRushCampEvent;    //服务端通知营地信息
    public event Action OnGoldRushInfoEvent;
@@ -23,7 +23,6 @@
    //行为事件
    public event Action<int> OnRefreshItemEvent; //刷新淘金道具
    public event Action<int, int, int> GoldRushEvent; //营地ID,执行事件(0出发,1返程),监工数量
    public event Action<PosEvent, bool, int, int, string> PathEvent; //事件,是否返程,营地ID,第几个工人,聊天内容(后续考虑传结构数据)
    public const int followWorkerCount = 3;   //小兵的数量,非监工
@@ -125,6 +124,8 @@
    public PlayerDataType unLockMoneyType; //刷新用
    public float lastAssignWorkTime;
    public float lastCallBackTime;
    public override void Init()
@@ -218,31 +219,41 @@
        // }
    }
    int skinIDIndex;
    public int GetRandommSkinID()
    {
        var skinID = skinIDs[skinIDIndex % skinIDs.Count];
        skinIDIndex++;
        //从已解锁中随机
        return skinIDs[UnityEngine.Random.Range(0, skinIDs.Count)];
        return skinID;
    }
    //参考:
    //未发布 goldid = 0 endtime不定(完成或者从未开始)
    //已发布未进行 goldid != 0 endtime = 0
    //已发布进行中 goldid != 0 endtime !=0
    //预分配监工皮肤
    void InitWorkerSkinID(HB037_tagSCGoldRushCampInfo.tagSCGoldRushCamp campInfo)
    {
        if (campInfo.EndTime == 0 && forceStopCampID == 0)
        {
            if (tmpCampWorkerSkinIDDict.ContainsKey(campInfo.CampID))
            {
                tmpCampWorkerSkinIDDict[campInfo.CampID].Clear();
            }
            return;
        }
        if (campInfo.GoldID != 0 && campInfo.EndTime != 0)
        {
            //预防重复随机
            if (tmpCampWorkerSkinIDDict.ContainsKey(campInfo.CampID) && tmpCampWorkerSkinIDDict[campInfo.CampID].ContainsKey((int)campInfo.EndTime))
            if (tmpCampWorkerSkinIDDict.ContainsKey(campInfo.CampID) && tmpCampWorkerSkinIDDict[campInfo.CampID].Count != 0)
            {
                return;
            }
            if (!tmpCampWorkerSkinIDDict.ContainsKey(campInfo.CampID))
            tmpCampWorkerSkinIDDict[campInfo.CampID] = new List<int>();
            for (int i = 0; i < campInfo.WorkerCnt; i++)
            {
                tmpCampWorkerSkinIDDict[campInfo.CampID] = new Dictionary<int, int[]>();
                tmpCampWorkerSkinIDDict[campInfo.CampID].Add(GetRandommSkinID());
            }
            tmpCampWorkerSkinIDDict[campInfo.CampID].Clear();
            //预分配随机3个
            tmpCampWorkerSkinIDDict[campInfo.CampID][(int)campInfo.EndTime] = new int[] { GetRandommSkinID(), GetRandommSkinID(), GetRandommSkinID() };
        }
    }
@@ -251,17 +262,20 @@
    {
        if (tmpCampWorkerSkinIDDict.ContainsKey(campID))
        { 
            var keys = tmpCampWorkerSkinIDDict[campID].Keys.ToList();
            if (keys.Count > 0)
            var skinIDs = tmpCampWorkerSkinIDDict[campID];
            if (index < skinIDs.Count)
            {
                var skinIDs = tmpCampWorkerSkinIDDict[campID][keys[0]];
                if (index < skinIDs.Length)
                {
                    return skinIDs[index];
                }
                return skinIDs[index];
            }
            else
            {
                var skinID = GetRandommSkinID();
                skinIDs.Add(skinID);
                return skinID;
            }
        }
        //没有预分配则随机
        return skinIDs[UnityEngine.Random.Range(0, skinIDs.Count)];
    }
@@ -419,9 +433,18 @@
        return (workerUnlockState & (1 << workerID)) != 0;
    }
    public int forceStopCampID;
    // 0-发布淘金(消耗淘金令);1-刷新淘金;2-开始淘金或调整监工数;3-取消淘金
    public void SendGoldRushOP(int opType, int campID, int workerCnt)
    {
        if (opType == 3)
        {
            forceStopCampID = campID;
        }
        if (opType == 2 && workerCnt < GetCampWorkerCnt(campID))
        {
            forceStopCampID = campID;
        }
        var pack = new CB036_tagCSGoldRushOP();
        pack.OPType = (byte)opType;
        pack.CampID = (byte)campID;
@@ -459,11 +482,6 @@
    }
    //通知外出行为事件
    public void NotifyGoldRushEvent(int campID, int eventType, int leaderCount)
    {
        GoldRushEvent?.Invoke(campID, eventType, leaderCount);
    }
    //通知路径行为事件
    public void NotifyPathEvent(PosEvent posEvent, bool isBack, int tendID, int index, string content)
Main/System/InternalAffairs/GoldRushTentCell.cs
@@ -3,6 +3,7 @@
using UnityEngine.UI;
using DG.Tweening;
using System.Linq;
using System;
//工人是固定的跟随模式,监工是随机分配的,场上的监工数量会比实际更多
//分配监工
@@ -61,7 +62,6 @@
    void OnEnable()
    {
        GoldRushManager.Instance.GoldRushEvent += GoldRushEvent;
        GoldRushManager.Instance.PathEvent += PathEvent;
        GoldRushManager.Instance.OnGoldRushCampEvent += OnGoldRushCampEvent;
        GoldRushManager.Instance.OnGoldRushInfoEvent += Display;
@@ -75,7 +75,6 @@
    void OnDisable()
    {
        GoldRushManager.Instance.GoldRushEvent -= GoldRushEvent;
        GoldRushManager.Instance.PathEvent -= PathEvent;
        GoldRushManager.Instance.OnGoldRushCampEvent -= OnGoldRushCampEvent;
        GoldRushManager.Instance.OnGoldRushInfoEvent -= Display;
@@ -148,12 +147,12 @@
        if (realCount > leaderCount)
        {
            //分配监工
            GoldRushManager.Instance.NotifyGoldRushEvent(campID, 0, realCount - leaderCount);
            GoldRushEvent(campID, 0, realCount - leaderCount);
        }
        else if (realCount < leaderCount)
        {
            //召回监工
            GoldRushManager.Instance.NotifyGoldRushEvent(campID, 1, leaderCount - realCount);
            GoldRushEvent(campID, 1, leaderCount - realCount);
        }
        leaderCount = realCount;
        Display();
@@ -436,30 +435,43 @@
    void AssignLeader(int addCount)
    {
        //不同营地之间错位出发
        float addTime = 0;
        var curTime = Time.time;
        if (curTime - GoldRushManager.Instance.lastAssignWorkTime < 0.2f)
        {
            addTime = 0.2f - (curTime - GoldRushManager.Instance.lastAssignWorkTime);
        }
        if (addTime != 0)
        {
            GoldRushManager.Instance.lastAssignWorkTime += 0.2f;
        }
        else
        {
            GoldRushManager.Instance.lastAssignWorkTime = curTime;
        }
        //分配的时候加新的监工
        for (int i = 0; i < addCount; i++)
        {
            float waitTime = i * 0.6f;
            float waitTime = i * 0.3f + addTime;
            var newLeader = RequestLeader();
            workingLeaderList.Add(newLeader);
            newLeader.Init(leaderPathPointArr, waitTime, campID, i, false, (bool value) =>
            {
                //是否返程
                if (!value)
                {
                    workingLeaderList.Remove(newLeader);
                    ReturnLeader(newLeader);
                }
                else
                {
                    //半路返回的监工
                    callBackLeaderList.Add(newLeader);
                    ReturnLeader(newLeader);
                }
            });
        }
    }
    GoldRushLeader RequestLeader()
@@ -480,7 +492,33 @@
    //半路召回的,拉货回来的
    void CallBackLeader(int callBackCount)
    {
        //不同营地之间错位出发
        float addTime = 0;
        var curTime = Time.time;
        if (curTime - GoldRushManager.Instance.lastCallBackTime < 0.2f)
        {
            addTime = 0.2f - (curTime - GoldRushManager.Instance.lastCallBackTime);
        }
        if (addTime != 0)
        {
            GoldRushManager.Instance.lastCallBackTime += 0.2f;
        }
        else
        {
            GoldRushManager.Instance.lastCallBackTime = curTime;
        }
        bool followBack = false;
        bool forcrCallBack = false;
        if (GoldRushManager.Instance.forceStopCampID == campID)
        {
            forcrCallBack = true;
            GoldRushManager.Instance.forceStopCampID = 0;
        }
        //从workingLeaderList 中取出最后面调回的监工,不够的新建
        for (int i = 0; i < callBackCount; i++)
        {
@@ -492,6 +530,13 @@
                callBackLeaderList.Add(leader);
                workingLeaderList.Remove(leader);
                leader.StartLeaderMove(true);
                leader.forcrCallBack = forcrCallBack;
                leader.OnComplete = (bool value) =>
                {
                    callBackLeaderList.Remove(leader);
                    ReturnLeader(leader);
                };
                if (workingLeaderList.Count == 0 && workState == 1)
                {
                    followBack = true;
@@ -499,19 +544,20 @@
            }
            else
            {
                //需要显示货物
                float waitTime = i * 0.6f;
                float waitTime = i * 0.6f + addTime;
                var newLeader = RequestLeader();
                callBackLeaderList.Add(newLeader);
                newLeader.Init(leaderPathPointArr, waitTime, campID, i, true, (bool value) =>
                int index = Math.Max(leaderCount - i - 1, 0);    //从后往前召回
                newLeader.Init(leaderPathPointArr, waitTime, campID, index, true, (bool value) =>
                {
                    if (value)
                    {
                        //返回的监工,需要显示货物
                        callBackLeaderList.Add(newLeader);
                        //返回的监工
                        callBackLeaderList.Remove(newLeader);
                        ReturnLeader(newLeader);
                    }
                });
                newLeader.forcrCallBack = forcrCallBack;
                if (workState == -1)
                {
@@ -531,11 +577,12 @@
            }
        }
        if (followBack&& GoldRushManager.Instance.GetCampWorkerCnt(campID) == 0)
        if (followBack && GoldRushManager.Instance.GetCampWorkerCnt(campID) == 0)
        {
            StartMove(true);
            workState = 2;
        }
    }
    void ClickTent()