From eb27e5fd31f73b998a4bbd85511a31e40b8c61b7 Mon Sep 17 00:00:00 2001
From: hch <305670599@qq.com>
Date: 星期五, 21 十一月 2025 17:03:47 +0800
Subject: [PATCH] 0312 关闭游戏内日志

---
 Main/System/Battle/BattleManager.cs |  354 ++++++++++++++++++++++++++++++++++++++++++++++++----------
 1 files changed, 290 insertions(+), 64 deletions(-)

diff --git a/Main/System/Battle/BattleManager.cs b/Main/System/Battle/BattleManager.cs
index c695c77..13c35bb 100644
--- a/Main/System/Battle/BattleManager.cs
+++ b/Main/System/Battle/BattleManager.cs
@@ -2,6 +2,7 @@
 using UnityEngine;
 using LitJson;
 using System;
+using System.Linq;
 
 public class BattleManager : GameSystemManager<BattleManager>
 {
@@ -10,10 +11,30 @@
     //  鍚屾椂鍙兘鏈変竴鍦烘垬鏂楀湪杩涜 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 readonly int[] speedIndexfuncIdArr = new int[] { 34, 35, 36 };  // 鎴樻枟鍊嶆暟瀵瑰簲鐨勫姛鑳絀D
+    public readonly int passFuncId = 33;    // 璺宠繃鎴樻枟瀵瑰簲鐨勫姛鑳絀D
+    public int passRound;   // 瓒呰繃X鍥炲悎鍙烦杩�
+    public int fightGuideID;
+    public int fightGuideMainLevelLimit;
+    public int fightGuideNoClickSeconds;
+    public int[] challengeBossGuides;
 
     public Action<string, BattleField> onBattleFieldCreate;
 
-    public Action<string, BattleField> onBattleFieldDestroy;
+    public Action onBattleFieldDestroy;
 
     public bool isWaitServerStory = false;  //涓荤嚎绛夋湇鍔$鍥炴姤 0425
 
@@ -24,8 +45,25 @@
         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);
+        challengeBossGuides = JsonMapper.ToObject<int[]>(config.Numerical4);
+
+        config = FuncConfigConfig.Get("BattleButton");
+        passRound= int.Parse(config.Numerical1);
+    }
+
 
     public override void Release()
     {
@@ -37,8 +75,8 @@
 
     protected void OnPlayerLoginOk()
     {
-        long exAttr1 = PlayerDatas.Instance.GetPlayerDataByType(PlayerDataType.ExAttr1);
-        long exAttr2 = PlayerDatas.Instance.GetPlayerDataByType(PlayerDataType.ExAttr2);
+        long exAttr1 = PlayerDatas.Instance.baseData.ExAttr1;
+        long exAttr2 = PlayerDatas.Instance.baseData.ExAttr2;
 
         int MapID = 1;
         int FuncLineID = (int)exAttr2;
@@ -63,7 +101,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
         {
@@ -105,6 +147,7 @@
         {
             if (!allow)
             {
+                _package.socketType = ServerType.MainFight;
                 packQueue.Enqueue(_package);
             }
         }
@@ -125,52 +168,77 @@
 
         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++)
+#if UNITY_EDITOR
+        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();
+#endif
+        // 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)
@@ -206,6 +274,19 @@
             // 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;
+
     }
 
     //  涓撳睘浜庝富绾挎垬鏂楃殑娲惧彂
@@ -289,6 +370,7 @@
         if (!battleReportDict.TryGetValue(guid, out queue))
         {
             queue = new Queue<GameNetPackBasic>();
+            battleReportDict.Add(guid, queue);
         }
 
         queue.Enqueue(vNetPack);
@@ -301,12 +383,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)
@@ -332,28 +440,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))
@@ -364,14 +494,21 @@
                 isCreate = false;
             }
             else
-            { 
+            {
                 BattleDebug.LogError("鎴樺満宸插瓨鍦� 鍏堣繘琛岄攢姣�");
                 battleField.Destroy();
             }
         }
 
+        var bf = GetBattleFieldByMapID(MapID);
+        if (bf != null && !string.IsNullOrEmpty(guid))
+        {
+            BattleDebug.LogError("鐩稿悓鍦板浘ID鐨勬垬鍦哄凡瀛樺湪 鍏堣繘琛岄攢姣�");
+            bf.Destroy();
+        }
+
         if (isCreate)
-        { 
+        {
             battleField = BattleFieldFactory.CreateBattleField(guid, MapID, FuncLineID, extendData, redTeamList, blueTeamList);
 
             if (string.IsNullOrEmpty(guid))
@@ -384,7 +521,7 @@
 
 
 
-        battleField.Init(MapID, FuncLineID, extendData, redTeamList, blueTeamList);
+        battleField.Init(MapID, FuncLineID, extendData, redTeamList, blueTeamList, vNetData.TurnMax);
 
         return battleField;
     }
@@ -397,14 +534,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)
         {
@@ -412,6 +548,9 @@
         }
 
         GameObject.DestroyImmediate(battleField.battleRootNode.gameObject);
+
+        onBattleFieldDestroy?.Invoke();
+
     }
 
 
@@ -419,10 +558,11 @@
     // 0-鍋滄鎴樻枟鍥炲煄   -  鐜╁涓诲姩鐐瑰嚮鍥炲煄鏃跺彂閫�
     // 1-璁剧疆娑堣�楀�嶅��   -  鐜╁璁剧疆娑堣�楀�嶅�硷紝瀵瑰簲鍒扮帺瀹秛seHarmerCount鐨勫��
     // 2-鎸戞垬鍏冲崱灏忔��   -  鐜╁鐐瑰嚮寮�濮嬫垬鏂楁椂鍙戦�侊紝浠呬粠浼戞伅鐘舵�佸埌寮�濮嬫垬鏂楁椂鍙戦�佸嵆鍙�
-    // 3-鎸戞垬鍏冲崱boss   -  鐜╁璇锋眰鎸戞垬璇ュ叧鍗oss鏃跺彂閫�
+    // 3-閲嶅畾涔夋殏鏈娇鐢�
     // 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;
@@ -437,9 +577,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)
@@ -448,4 +590,88 @@
         }
     }
 
+    public BattleField GetBattleFieldByMapID(int v)
+    {
+        foreach (var battleField in battleFields)
+        {
+            if (battleField.Value.MapID == v)
+            {
+                return battleField.Value;
+            }
+        }
+
+        return null;
+    }
+
+    //鍙戣繘鍏ユ垬鏂楀寘
+    private float lastTime = 0f;
+    private float turnCoolDown = 0.5f; // 鍐峰嵈鏃堕棿
+    public void SendTurnFight(uint mapID, uint funcLineID = 0, byte tagType = 0, uint tagID = 0, uint[] valueList = null)
+    {
+        // 杩炵画棰戠箒鍙戝寘锛岃Е鍙戞彁绀�
+        float currentTime = Time.time;
+        if (currentTime - lastTime < turnCoolDown)
+        {
+            SysNotifyMgr.Instance.ShowTip("BattleCoolDown");
+            return;
+        }
+        lastTime = currentTime;
+
+        CB410_tagCMTurnFight pack = new CB410_tagCMTurnFight();
+        pack.MapID = mapID;
+        pack.FuncLineID = funcLineID;
+        pack.TagType = tagType;
+        pack.TagID = tagID;
+        if (!valueList.IsNullOrEmpty())
+        {
+            pack.ValueList = valueList;
+            pack.ValueCount = (byte)valueList.Length;
+        }
+        GameNetSystem.Instance.SendInfo(pack);
+    }
+
+    // 鑾峰彇褰撳墠姝e湪鏄剧ず鐨勬垬鏂楀満鏅悕绉帮紝濡傛灉娌℃湁鍒欒繑鍥炵┖瀛楃涓�
+    public string GetActiveBattleName()
+    {
+        foreach (var kvp in battleFields)
+        {
+            BattleField battleField = kvp.Value;
+            if (battleField == null)
+                continue;
+
+            var battleName = battleField.ToString();
+            if (BattleConst.battleNameToWinName.ContainsKey(battleName)
+            && UIManager.Instance.IsOpened(BattleConst.battleNameToWinName[battleName]))
+                return battleName;
+        }
+        return "";
+    }
+
+    // 鑾峰彇褰撳墠姝e湪鏄剧ず鐨勬垬鏂楀満鏅�,濡傛灉娌℃湁鍒欒繑鍥瀗ull
+    public BattleField GetActiveBattleFieldByName(string battleName)
+    {
+        foreach (var kvp in battleFields)
+        {
+            BattleField battleField = kvp.Value;
+            if (battleField == null)
+                continue;
+
+            var name = battleField.ToString();
+            if (name == battleName)
+                return battleField;
+        }
+        return null;
+    }
+
+    public void DestroyAllBattleField()
+    {
+        var battleFieldsList = battleFields.Values.ToList();
+        foreach (var battleField in battleFieldsList)
+        {
+            if (battleField == null)
+                continue;
+            battleField.Destroy();
+        }
+    }
+
 }
\ No newline at end of file

--
Gitblit v1.8.0