From 3bd7f56906e31e8fe0072108c9d4652707b51de8 Mon Sep 17 00:00:00 2001
From: yyl <yyl>
Date: 星期二, 21 十月 2025 17:59:00 +0800
Subject: [PATCH] 125 战斗 战斗UI

---
 Main/System/Battle/BattleManager.cs |  285 +++++++++++++++++++++++++++++++++++++++++++++-----------
 1 files changed, 227 insertions(+), 58 deletions(-)

diff --git a/Main/System/Battle/BattleManager.cs b/Main/System/Battle/BattleManager.cs
index bc0fe5f..732c309 100644
--- a/Main/System/Battle/BattleManager.cs
+++ b/Main/System/Battle/BattleManager.cs
@@ -10,6 +10,23 @@
     //  鍚屾椂鍙兘鏈変竴鍦烘垬鏂楀湪杩涜 guid, battlefield
     protected Dictionary<string, BattleField> battleFields = new Dictionary<string, BattleField>();
 
+    public float[] speedGear; //鎴樻枟鍊嶆暟瀵瑰簲鐨勫疄闄呴�熺巼
+    public int speedIndex
+    {
+        get
+        {
+            return QuickSetting.Instance.GetQuickSettingValue<int>(QuickSettingType.BattleSpeed, 0);
+        }
+        set
+        {
+            QuickSetting.Instance.SetQuickSetting(QuickSettingType.BattleSpeed, value);
+            QuickSetting.Instance.SendPackage();
+        }
+    }
+
+    public int fightGuideID;
+    public int fightGuideMainLevelLimit;
+    public int fightGuideNoClickSeconds;
 
     public Action<string, BattleField> onBattleFieldCreate;
 
@@ -24,8 +41,21 @@
         LogicEngine.Instance.OnUpdate += Run;
         DTC0403_tagPlayerLoginLoadOK.playerLoginOkEvent += OnPlayerLoginOk;
         DTC0102_tagCDBPlayer.beforePlayerDataInitializeEvent += BeforePlayerInit;
+        ParseConfig();
         
     }
+
+    void ParseConfig()
+    {
+        var config = FuncConfigConfig.Get("AutoGuaji");
+        speedGear = JsonMapper.ToObject<float[]>(config.Numerical4);
+
+        config = FuncConfigConfig.Get("FightGuide");
+        fightGuideID = int.Parse(config.Numerical1);
+        fightGuideMainLevelLimit = int.Parse(config.Numerical2);
+        fightGuideNoClickSeconds = int.Parse(config.Numerical3);
+    }
+
 
     public override void Release()
     {
@@ -63,7 +93,11 @@
 
             redTeamList.Add(storyTeam);
 
-            CreateBattleField(string.Empty, MapID, FuncLineID, extendData, redTeamList, blueTeamList);
+            HB424_tagSCTurnFightInit vNetData = new HB424_tagSCTurnFightInit();
+            vNetData.MapID = (uint)MapID;
+            vNetData.FuncLineID = (uint)FuncLineID;
+
+            CreateBattleField(string.Empty, vNetData, extendData, redTeamList, blueTeamList);
         }
         else
         {
@@ -125,50 +159,76 @@
 
         List<GameNetPackBasic> packQueueSnapshot = new List<GameNetPackBasic>(packQueue);
 
-        List<GameNetPackBasic> newPackList = new List<GameNetPackBasic>();
-        HashSet<int> skipIndexes = new HashSet<int>();
+        List<GameNetPackBasic> newPackList = ParseBattlePackList(string.Empty, packQueueSnapshot);
 
-        // 杩欓噷宸茬粡鏄寜鐓equeue鐨勯『搴忎簡
-        for (int i = 0; i < packQueueSnapshot.Count; i++)
+        Action printNewPack = () =>
         {
-            if (skipIndexes.Contains(i)) continue;
-
-            GameNetPackBasic pack = packQueueSnapshot[i];
-
-            // 纰板埌B421 鎴柇 寰�涓嬫敹闆哹421閲岀殑鍏ㄩ儴鍐呭
-            if (pack is HB421_tagMCTurnFightObjAction)
+            string temp = "After AnalysisPackQueueAndDistribute newPackList count: " + newPackList.Count + "\n";
+            foreach (var pack in newPackList)
             {
-                HB421_tagMCTurnFightObjAction b421Pack = pack as HB421_tagMCTurnFightObjAction;
-
-                List<GameNetPackBasic> b421PackList = new List<GameNetPackBasic>();
-                i++;    // 璺宠繃褰撳墠鐨凚421鍖�
-
-                // 鏀堕泦鎵�鏈夐潪B421鍖咃紝鐩村埌閬囧埌涓嬩竴涓狟421鎴栭槦鍒楃粨鏉�
-                for (; i < packQueueSnapshot.Count; i++)
+                if (pack is CustomHB426CombinePack b426Pack)
                 {
-                    GameNetPackBasic nextPack = packQueueSnapshot[i];
-                    if (nextPack is HB421_tagMCTurnFightObjAction)
-                    {
-                        i--; // 鍥為��涓�涓綅缃紝鐣欑粰澶栧眰寰幆澶勭悊
-                        break;
-                    }
-                    else
-                    {
-                        b421PackList.Add(nextPack);
-                        skipIndexes.Add(i); // 鏍囪宸茶鍚堝寘
-                    }
+                    temp += "  pack type is " + pack.GetType().Name + " tag is " + (b426Pack.startTag != null ? b426Pack.startTag.Tag : "null") + "\n";
                 }
-
-                // 鍚堝苟鎵�鏈夌浉鍏冲寘
-                CustomB421ActionPack actionPack = CustomB421ActionPack.CreateB421ActionPack(GetGUID(b421Pack.packUID), b421PackList);
-
-                newPackList.Add(actionPack);
+                else if (pack is CustomB421ActionPack b421Pack)
+                {
+                    temp += "  pack type is " + pack.GetType().Name + " guid is " + b421Pack.guid + "\n";
+                }
+                else
+                {
+                    temp += "  pack type is " + pack.GetType().Name + "\n";
+                }
             }
-            else
-            {
-                newPackList.Add(pack);
-            }
-        }
+            Debug.LogWarning(temp);
+        };
+
+        printNewPack();
+
+        // HashSet<int> skipIndexes = new HashSet<int>();
+
+        // // 杩欓噷宸茬粡鏄寜鐓equeue鐨勯『搴忎簡
+        // for (int i = 0; i < packQueueSnapshot.Count; i++)
+        // {
+        //     if (skipIndexes.Contains(i)) continue;
+
+        //     GameNetPackBasic pack = packQueueSnapshot[i];
+
+        //     // 纰板埌B421 鎴柇 寰�涓嬫敹闆哹421閲岀殑鍏ㄩ儴鍐呭
+        //     if (pack is HB421_tagMCTurnFightObjAction)
+        //     {
+        //         HB421_tagMCTurnFightObjAction b421Pack = pack as HB421_tagMCTurnFightObjAction;
+
+        //         List<GameNetPackBasic> b421PackList = new List<GameNetPackBasic>();
+        //         i++;    // 璺宠繃褰撳墠鐨凚421鍖�
+
+        //         // 鏀堕泦鎵�鏈夐潪B421鍖咃紝鐩村埌閬囧埌涓嬩竴涓狟421鎴栭槦鍒楃粨鏉�
+        //         for (; i < packQueueSnapshot.Count; i++)
+        //         {
+        //             GameNetPackBasic nextPack = packQueueSnapshot[i];
+        //             if (nextPack is HB421_tagMCTurnFightObjAction)
+        //             {
+        //                 i--; // 鍥為��涓�涓綅缃紝鐣欑粰澶栧眰寰幆澶勭悊
+        //                 break;
+        //             }
+        //             else
+        //             {
+        //                 b421PackList.Add(nextPack);
+        //                 skipIndexes.Add(i); // 鏍囪宸茶鍚堝寘
+        //             }
+        //         }
+
+
+
+        //         // 鍚堝苟鎵�鏈夌浉鍏冲寘
+        //         CustomB421ActionPack actionPack = CustomB421ActionPack.CreateB421ActionPack(GetGUID(b421Pack.packUID), b421PackList);
+
+        //         newPackList.Add(actionPack);
+        //     }
+        //     else
+        //     {
+        //         newPackList.Add(pack);
+        //     }
+        // }
 
         // 闃茶寖鏈哄埗锛氳繛缁娆℃病鏈夋垬鏂楃墖娈靛皝鍖呮椂鑷姩鍥炲煄
         if (newPackList.Count == 0)
@@ -191,9 +251,32 @@
 
 
         // b421璺焍426鐨勫寘宸茬粡澶勭悊瀹屼簡
-            packQueue = new Queue<GameNetPackBasic>(newPackList);
+        packQueue.Clear();
+        for (int i = 0; i < newPackList.Count; i++)
+        {
+            var pack = newPackList[i];
+
+            packQueue.Enqueue(pack);
+        }
+
+    
+
+            // packQueue = new Queue<GameNetPackBasic>(newPackList);
 
         DistributeNextPackage();
+    }
+
+    public static List<GameNetPackBasic> ParseBattlePackList(string guid, List<GameNetPackBasic> packQueueSnapshot)
+    {
+        var list = CustomHB426CombinePack.CombineToSkillPackFromList(guid, packQueueSnapshot);
+        string str = "ParseBattlePackList \n";
+        for (int i = 0; i < list.Count; i++)
+        {
+            str += "  " + list[i].GetType().Name + "\n";
+        }
+        // BattleDebug.LogError(str);
+        return list;
+
     }
 
     //  涓撳睘浜庝富绾挎垬鏂楃殑娲惧彂
@@ -277,6 +360,7 @@
         if (!battleReportDict.TryGetValue(guid, out queue))
         {
             queue = new Queue<GameNetPackBasic>();
+            battleReportDict.Add(guid, queue);
         }
 
         queue.Enqueue(vNetPack);
@@ -289,12 +373,38 @@
             battlePackRelationList.Add(guid, uidList);
         }
 
-        uidList.Add(vNetPack.packUID);
+        if (!uidList.Contains(vNetPack.packUID))
+        {
+            uidList.Add(vNetPack.packUID);
+        }
+    }
+
+    public void PushPackUID(string guid, ulong packUID)
+    {
+        List<ulong> uidList = null;
+
+        if (!battlePackRelationList.TryGetValue(guid, out uidList))
+        {
+            uidList = new List<ulong>();
+            battlePackRelationList.Add(guid, uidList);
+        }
+
+        if (!uidList.Contains(packUID))
+        {
+            uidList.Add(packUID);
+        }
+
     }
 
     public BattleField GetBattleField(ulong packUID)
     {
-        return GetBattleField(GetGUID(packUID));
+        string guid = GetGUID(packUID);
+        BattleField battleField = GetBattleField(GetGUID(packUID));
+        if (battleField == null || battleField.rejectNewPackage)
+        {
+            return null;
+        }
+        return battleField;
     }
 
     public BattleField GetBattleField(string guid)
@@ -320,28 +430,50 @@
     {
         Queue<GameNetPackBasic> queue = null;
 
+
         if (!battleReportDict.TryGetValue(guid, out queue))
         {
             BattleDebug.LogError("DistributeNextReportPackage could not find queue for guid : " + guid);
             return;
         }
 
-        var pack = queue.Dequeue();
-
-        PackageRegedit.Distribute(pack);
-
         if (queue.Count <= 0)
         {
-            battleReportDict.Remove(guid);
-            battlePackRelationList.Remove(guid);
+            return;
         }
 
+        var pack = queue.Dequeue();
+
+        // Debug.LogError("DistributeNextReportPackage for guid : " + guid + " pack type : " + pack.GetType());
+
+        try
+        {
+            if (pack is CustomHB426CombinePack combinePack)
+            {
+                combinePack.Distribute();
+            }
+            else if (pack is CustomB421ActionPack actionPack)
+            {
+                actionPack.Distribute();
+            }
+            else
+            {
+                PackageRegedit.Distribute(pack);
+            }
+        }
+        catch (Exception ex)
+        {
+            Debug.LogError("DistributeNextPackage: 鍒嗗彂鍖呭紓甯� " + ex);
+        }
     }
     #endregion
 
-    public BattleField CreateBattleField(string guid, int MapID, int FuncLineID, JsonData extendData, List<TeamBase> redTeamList, List<TeamBase> blueTeamList)
+    public BattleField CreateBattleField(string guid, HB424_tagSCTurnFightInit vNetData, JsonData extendData, List<TeamBase> redTeamList, List<TeamBase> blueTeamList)
     {
         BattleField battleField = null;
+
+        int MapID = (int)vNetData.MapID;
+        int FuncLineID = (int)vNetData.FuncLineID;
 
         bool isCreate = true;
         if (battleFields.TryGetValue(guid, out battleField))
@@ -359,7 +491,7 @@
         }
 
         if (isCreate)
-        { 
+        {
             battleField = BattleFieldFactory.CreateBattleField(guid, MapID, FuncLineID, extendData, redTeamList, blueTeamList);
 
             if (string.IsNullOrEmpty(guid))
@@ -372,7 +504,7 @@
 
 
 
-        battleField.Init(MapID, FuncLineID, extendData, redTeamList, blueTeamList);
+        battleField.Init(MapID, FuncLineID, extendData, redTeamList, blueTeamList, vNetData.TurnMax);
 
         return battleField;
     }
@@ -385,14 +517,13 @@
             return;
         }
 
-        onBattleFieldDestroy?.Invoke(battleField.guid, battleField);
+        battleField.Release();
 
         string guid = battleField.guid;
 
-        if (battleFields.ContainsKey(guid))
-        {
-            battleFields.Remove(guid);
-        }
+        battleFields.Remove(guid);
+        battleReportDict.Remove(guid);
+        battlePackRelationList.Remove(guid);
 
         if (storyBattleField == battleField)
         {
@@ -400,6 +531,9 @@
         }
 
         GameObject.DestroyImmediate(battleField.battleRootNode.gameObject);
+
+        onBattleFieldDestroy?.Invoke(battleField.guid, battleField);
+
     }
 
 
@@ -411,6 +545,7 @@
     // 4-缁х画鎴樻枟          -   鐜╁涓荤嚎鎴樻枟涓紙鍖呭惈涓荤嚎灏忔��佷富绾縝oss锛夛紝鍓嶇琛ㄧ幇瀹屽悗绔悓姝ョ殑鎴樻枟鐗囨鍚庯紝鍙啀鍥炲璇ュ�硷紝鍚庣浼氭牴鎹垬鏂楅�昏緫鍙婃祦绋嬭嚜鍔ㄥ洖澶嶄笅涓�娈电殑鎴樻枟鐗囨灏佸寘锛屼竴鐩村惊鐜�
     public void MainFightRequest(byte reqType, uint reqValue = 0)
     {
+        // Debug.LogError("MainFightRequest reqType " + reqType + " reqValue " + reqValue);
         CB413_tagCSMainFightReq req = new CB413_tagCSMainFightReq();
         req.ReqType = reqType;
         req.ReqValue = reqValue;
@@ -425,9 +560,11 @@
     {
         try
         {
-            foreach (var battleField in battleFields)
+            List<string> keys = new List<string>(battleFields.Keys);
+            for (int i = keys.Count - 1; i >= 0; i--)
             {
-                battleField.Value?.Run();
+                var battleField = battleFields[keys[i]];
+                battleField?.Run();
             }
         }
         catch (System.Exception ex)
@@ -436,4 +573,36 @@
         }
     }
 
+    public BattleField GetBattleFieldByMapID(int v)
+    {
+        foreach (var battleField in battleFields)
+        {
+            if (battleField.Value.MapID == v)
+            {
+                return battleField.Value;
+            }
+        }
+
+        return null;
+    }
+
+    /// <summary>
+    /// 妫�鏌ユ槸鍚︽湁闈炰富绾挎垬鏂楋紙濡傜珵鎶�鍦恒�佺櫧楠ㄧ瓑锛夋鍦ㄨ繘琛�
+    /// </summary>
+    /// <returns>濡傛灉鏈変换浣曢潪涓荤嚎鎴樻枟涓旀湭缁撴潫锛屽垯杩斿洖true</returns>
+    public bool IsOtherBattleInProgress()
+    {
+        foreach (var kvp in battleFields)
+        {
+            BattleField battleField = kvp.Value;
+            // 妫�鏌ユ垬鍦烘槸鍚︽湁鏁堜笖灏氭湭缁撴潫
+            if (battleField == null || battleField.IsBattleFinish)
+                continue;
+            // MapID 1 (StoryBattleField) 鍜� 2 (StoryBossBattleField) 閮芥槸涓荤嚎
+            if (battleField.MapID == 1 || battleField.MapID == 2)
+                continue;
+            return true;
+        }
+        return false;
+    }
 }
\ No newline at end of file

--
Gitblit v1.8.0