From 87d5c46997d61523aed87fdb7ed0b07e9dded223 Mon Sep 17 00:00:00 2001
From: hch <305670599@qq.com>
Date: 星期二, 30 九月 2025 21:45:08 +0800
Subject: [PATCH] 0312 优化淘金派遣

---
 Main/System/InternalAffairs/GoldRushTentCell.cs |   83 +++++++++++++++++++++------
 Main/System/InternalAffairs/GoldRushLeader.cs   |   14 ++--
 Main/System/InternalAffairs/GoldRushManager.cs  |   68 ++++++++++++++--------
 3 files changed, 115 insertions(+), 50 deletions(-)

diff --git a/Main/System/InternalAffairs/GoldRushLeader.cs b/Main/System/InternalAffairs/GoldRushLeader.cs
index 1aff9c1..2ec9c60 100644
--- a/Main/System/InternalAffairs/GoldRushLeader.cs
+++ b/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);
             }
         }
diff --git a/Main/System/InternalAffairs/GoldRushManager.cs b/Main/System/InternalAffairs/GoldRushManager.cs
index c84e110..b38d1f5 100644
--- a/Main/System/InternalAffairs/GoldRushManager.cs
+++ b/Main/System/InternalAffairs/GoldRushManager.cs
@@ -15,7 +15,7 @@
     public int housekeeperEndTime;   // 鑷姩绠″鍒版湡鏃堕棿鎴筹紝鏈夊�煎悓鏃朵篃浠h〃鍏嶈垂璇曠敤宸蹭娇鐢�
     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++;
         //浠庡凡瑙i攣涓殢鏈�
-        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)
diff --git a/Main/System/InternalAffairs/GoldRushTentCell.cs b/Main/System/InternalAffairs/GoldRushTentCell.cs
index e71b374..5f05a3d 100644
--- a/Main/System/InternalAffairs/GoldRushTentCell.cs
+++ b/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;
+        }
+
         //浠巜orkingLeaderList 涓彇鍑烘渶鍚庨潰璋冨洖鐨勭洃宸ワ紝涓嶅鐨勬柊寤�
         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()

--
Gitblit v1.8.0