From cb4ec28d83ba847f362392936b20e52e17b03081 Mon Sep 17 00:00:00 2001
From: hch <305670599@qq.com>
Date: 星期五, 31 十月 2025 19:30:45 +0800
Subject: [PATCH] Merge branch 'master' of http://mobile.secondworld.net.cn:10010/r/Project_SG_scripts

---
 Main/Core/NetworkPackage/CustomServerPack/CustomHB426CombinePack.cs |  237 +++++++++++++++++++++++++++++++++++++++++++++++++++--------
 1 files changed, 204 insertions(+), 33 deletions(-)

diff --git a/Main/Core/NetworkPackage/CustomServerPack/CustomHB426CombinePack.cs b/Main/Core/NetworkPackage/CustomServerPack/CustomHB426CombinePack.cs
index 2593088..364f3fe 100644
--- a/Main/Core/NetworkPackage/CustomServerPack/CustomHB426CombinePack.cs
+++ b/Main/Core/NetworkPackage/CustomServerPack/CustomHB426CombinePack.cs
@@ -1,4 +1,3 @@
-
 using System.Collections.Generic;
 using UnityEngine;
 
@@ -31,8 +30,7 @@
         }
         endTag = _endTag;
         toIndex = _toIndex;
-
-        packList = CombineToSkillPackFromList(guid, packList);
+        PrintAllPack();
     }
 
 
@@ -45,6 +43,27 @@
         }
         fromIndex = _fromIndex;
         startTag = tag;
+
+        
+    }
+
+    public void PrintAllPack()
+    {
+        string temp = "CustomHB426CombinePack startTag: " + (startTag != null ? startTag.Tag : "null") +
+            " fromIndex: " + fromIndex + " toIndex: " + toIndex + " packList.Count: " + packList.Count + "\n";
+        for (int i = 0; i < packList.Count; i++)
+        {
+            var pack = packList[i];
+            if (pack is CustomHB426CombinePack b426Pack)
+            {
+                temp += "  pack type is " + pack.GetType().Name + " tag is " + (b426Pack.startTag != null ? b426Pack.startTag.Tag : "null") + "\n";
+            }
+            else
+            {
+                temp += "  pack type is " + pack.GetType().Name + "\n";
+            }
+        }
+        BattleDebug.LogError(temp);
     }
 
     public void AddPack(GameNetPackBasic pack)
@@ -74,66 +93,130 @@
         return startTag.Tag == tag.Tag && tag.Sign == 1;
     }
 
-
     public static List<GameNetPackBasic> CombineToSkillPackFromList(string _guid, List<GameNetPackBasic> b421SeriesPackList)
     {
-        CustomHB426CombinePack combinePack = null;
+        Dictionary<string, CustomHB426CombinePack> combineDict = new Dictionary<string, CustomHB426CombinePack>();
+
+        Dictionary<int, GameNetPackBasic> indexDict = new Dictionary<int, GameNetPackBasic>();
+
+        Dictionary<uint, HB427_tagSCUseSkill> skillDict = new Dictionary<uint, HB427_tagSCUseSkill>();
+
         for (int i = 0; i < b421SeriesPackList.Count; i++)
         {
             var pack = b421SeriesPackList[i];
+
             if (pack is HB426_tagSCTurnFightTag)
             {
                 var tag = pack as HB426_tagSCTurnFightTag;
-                if (null == combinePack)
+                CustomHB426CombinePack combinePack;
+
+                if (!combineDict.TryGetValue(tag.Tag, out combinePack))
                 {
                     combinePack = new CustomHB426CombinePack();
                     combinePack.guid = _guid;
+                    combineDict.Add(tag.Tag, combinePack);
+
+                    indexDict.Add(i, combinePack);
+                }
+
+                if (tag.Sign == 0)
+                {
                     combinePack.SetHB426Start(i, tag);
                     continue;
                 }
-                else
+                //  鎵惧埌瀵瑰簲鐨勫紑濮嬫爣绛�
+                if (combinePack.IsEndPack(tag))
                 {
-                    if (combinePack.IsEndPack(tag))
+                    combinePack.SetHB426End(i, tag);
+                    continue;
+                }
+
+                Debug.LogError("No matching start tag or end tag found: " + tag.Tag);
+                continue;
+            }
+            else
+            {
+                if (pack is HB427_tagSCUseSkill skillPack)
+                {
+                    //  澶勭悊鎶�鑳戒箣闂寸殑閾炬帴鍏崇郴
+                    if (skillPack.RelatedSkillID > 0)
                     {
-                        combinePack.SetHB426End(i, tag);
-                        break;
+                        skillDict.TryGetValue(skillPack.RelatedSkillID, out var parentSkill);
+
+                        if (parentSkill != null && skillPack.BattleType == 4)//4=瀛愭妧鑳�
+                        {
+                            parentSkill.subSkillList.Add(skillPack);
+                            skillPack.parentSkill = parentSkill;
+                        }
+                        indexDict.Add(i, pack);
+
+                    }
+                    else
+                    {
+                        indexDict.Add(i, pack);
+                    }
+
+                    if (skillDict.ContainsKey(skillPack.SkillID))
+                    {
+                        skillDict[skillPack.SkillID] = skillPack;
+                    }
+                    else
+                    {
+                        skillDict.Add(skillPack.SkillID, skillPack);
                     }
                 }
+                else
+                {
+                    indexDict.Add(i, pack);
+                }
             }
+        }
 
-            if (null != combinePack)
+
+        //  宓屽鍖呭唴鐨勫寘鍚堝苟
+        foreach (var combinePack in combineDict.Values)
+        {
+            for (int i = combinePack.fromIndex + 1; i < combinePack.toIndex; i++)
             {
-                combinePack.AddPack(pack);
+                if (indexDict.TryGetValue(i, out var pack))
+                {
+                    indexDict.Remove(i);
+                    combinePack.AddPack(pack);
+                    if (pack is CustomHB426CombinePack)
+                    {
+                        //  濡傛灉鏄祵濂楃殑鍖� 鍔犲叆涔嬪悗 璋冩暣i
+                        i = (pack as CustomHB426CombinePack).toIndex;
+                    }
+                }
             }
         }
 
         List<GameNetPackBasic> newPackList = new List<GameNetPackBasic>();
 
-        if (null != combinePack)
+        // string temp = string.Empty;
+
+        for (int i = 0; i < b421SeriesPackList.Count; i++)
         {
-            //  鎶�鑳藉寘鍓嶉潰鐨勫寘锛堜笉鍖呮嫭b426鐨勫紑濮嬫爣绛撅級
-            for (int i = 0; i < combinePack.fromIndex; i++)
+            if (indexDict.TryGetValue(i, out var pack))
             {
-                newPackList.Add(b421SeriesPackList[i]);
+                newPackList.Add(pack);
+                if (pack is CustomHB426CombinePack)
+                {
+                    var cbpack = pack as CustomHB426CombinePack;
+                    // temp += "pack type is " + pack.GetType().Name + " tag is " + cbpack.startTag.Tag + "\n";
+                }
+                else
+                {
+                    // temp += "pack type is " + pack.GetType().Name + "\n";
+                }
             }
-
-            //  鎶婂悎骞剁殑鎶�鑳藉寘鍔犺繘鏉�
-            newPackList.Add(combinePack);
-
-            //  鎶�鑳藉寘鍚庨潰鐨勫寘锛堜笉鍖呮嫭b426鐨勭粨鏉熸爣绛撅級
-            for (int i = combinePack.toIndex + 1; i < b421SeriesPackList.Count; i++)
-            {
-                newPackList.Add(b421SeriesPackList[i]);
-            }
-
-            return CombineToSkillPackFromList(_guid, newPackList);
-
-        }
-        else
-        {
-            return b421SeriesPackList;
         }
 
+        // newPackList = BattleManager.ParseBattlePackList(_guid, newPackList);
+
+        // Debug.LogError(temp);
+
+        return newPackList;
     }
 
     public void Distribute()
@@ -151,6 +234,58 @@
         {
             battleField.PlayRecord(skillAction);
         }
+        else
+        {
+            battleField.DistributeNextPackage();
+        }
+
+    }
+
+    public static SkillRecordAction CreateSkillAction(string guid, List<GameNetPackBasic> _packList)
+    {
+        BattleField battleField = BattleManager.Instance.GetBattleField(guid);
+
+        if (null == battleField)
+        {
+            Debug.LogError("BattleField not found for guid: " + guid);
+            return null;
+        }
+
+        while (_packList.Count > 0)
+        {
+            var pack = _packList[0];
+            _packList.RemoveAt(0);
+
+            if (pack is HB427_tagSCUseSkill)
+            {
+                _packList.Insert(0, pack);
+                break;
+            }
+            else if (pack is CustomHB426CombinePack)
+            {
+                Debug.LogError("鏃犳硶鎵惧埌Skill鍖咃紝鍏堝彂鐜颁簡宓屽鍖�");
+                return null;
+            }
+            else
+            {
+                // Debug.LogError("鍙戠幇闈濻kill鍖咃紝鍏堝垎鍙戞帀: " + pack.GetType().Name);
+                PackageRegedit.Distribute(pack);
+            }
+        }
+
+        HB427_tagSCUseSkill skill = _packList[0] as HB427_tagSCUseSkill;
+        _packList.RemoveAt(0);
+        if (null == skill)
+        {
+            Debug.LogError("No HB427_tagSCUseSkill found in packList.");
+            return null;
+        }
+
+        BattleObject _caster = battleField.battleObjMgr.GetBattleObject((int)skill.ObjID);
+
+        SkillRecordAction skillAction = new SkillRecordAction(battleField, _caster, skill, _packList);
+        return skillAction;
+
     }
 
     public SkillRecordAction CreateSkillAction()
@@ -163,11 +298,47 @@
             return null;
         }
 
+        //  鏈嶅姟鍣ㄤ慨鏀逛簡 鐜板湪绗竴涓笉涓�瀹氭槸B427 涔熸湁鍙兘鏄疊428 鍏堟斁Buff
+        while (packList.Count > 0)
+        {
+            var pack = packList[0];
+            packList.RemoveAt(0);
+
+            if (pack is HB427_tagSCUseSkill)
+            {
+                packList.Insert(0, pack);
+                break;
+            }
+            else if (pack is CustomHB426CombinePack)
+            {
+                Debug.LogError("鏃犳硶鎵惧埌Skill鍖咃紝鍏堝彂鐜颁簡宓屽鍖�");
+                return null;
+            }
+            else
+            {
+                // Debug.LogError("鍙戠幇闈濻kill鍖咃紝鍏堝垎鍙戞帀: " + pack.GetType().Name);
+                PackageRegedit.Distribute(pack);
+            }
+        }
+
         if (startTag.Tag.StartsWith("Skill_"))
         {
+            if (packList.Count <= 0)
+            {
+                Debug.LogError("No HB427_tagSCUseSkill found in packList." + startTag.Tag);
+                return null;
+            }
             HB427_tagSCUseSkill skill = packList[0] as HB427_tagSCUseSkill;
-            packList.Remove(skill);
+            packList.RemoveAt(0);
+            if (null == skill)
+            {
+                Debug.LogError("No HB427_tagSCUseSkill found in packList.");
+                return null;
+            }
+
             BattleObject _caster = battleField.battleObjMgr.GetBattleObject((int)skill.ObjID);
+            // BattleDebug.LogError("_caster == null : " + (_caster == null) + " skill.ObjID : " + skill.ObjID);
+
             SkillRecordAction skillAction = new SkillRecordAction(battleField, _caster, skill, packList);
             return skillAction;
         }

--
Gitblit v1.8.0