From 46960cfdf737aef4391a9f9d56a22665e59c156d Mon Sep 17 00:00:00 2001
From: hch <305670599@qq.com>
Date: 星期三, 31 十二月 2025 14:43:58 +0800
Subject: [PATCH] 0312 代码防范

---
 Main/Core/NetworkPackage/CustomServerPack/CustomHB426CombinePack.cs |  219 ++++++++++++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 203 insertions(+), 16 deletions(-)

diff --git a/Main/Core/NetworkPackage/CustomServerPack/CustomHB426CombinePack.cs b/Main/Core/NetworkPackage/CustomServerPack/CustomHB426CombinePack.cs
index 563d00f..bcd2b93 100644
--- a/Main/Core/NetworkPackage/CustomServerPack/CustomHB426CombinePack.cs
+++ b/Main/Core/NetworkPackage/CustomServerPack/CustomHB426CombinePack.cs
@@ -1,5 +1,5 @@
-
 using System.Collections.Generic;
+using System.Linq;
 using UnityEngine;
 
 public class CustomHB426CombinePack : GameNetPackBasic
@@ -50,7 +50,8 @@
 
     public void PrintAllPack()
     {
-        string temp = "CustomHB426CombinePack startTag: " + (startTag != null ? startTag.Tag : "null") + " fromIndex: " + fromIndex + " toIndex: " + toIndex + "\n";
+        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];
@@ -63,7 +64,7 @@
                 temp += "  pack type is " + pack.GetType().Name + "\n";
             }
         }
-        // BattleDebug.LogError(temp);
+        BattleDebug.LogError(temp);
     }
 
     public void AddPack(GameNetPackBasic pack)
@@ -98,6 +99,8 @@
         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++)
         {
@@ -134,9 +137,48 @@
             }
             else
             {
-                indexDict.Add(i, pack);
+                if (pack is HB427_tagSCUseSkill skillPack)
+                {
+                    //  澶勭悊鎶�鑳戒箣闂寸殑閾炬帴鍏崇郴
+                    if (skillPack.RelatedSkillID > 0)
+                    {
+                        // 濡傛灉鏄 HB426_tagSCTurnFightTag 鍖呰9鐨勭涓�涓妧鑳藉寘 骞朵笖鍓嶉潰娌℃湁CustomHB426CombinePack 
+                        // 鍒欓渶瑕佹妸CustomHB426CombinePack鍔犲叆skillPack鐨剆ubSkillCombinePackList閲�
+                        // 鍚屾椂 闇�瑕佹妸indexDict閲屽垹鎺夊搴旂殑subSkillCombinePackList
+                        // subSkillList鍒犳帀瀵瑰簲skillPack锛屼絾鏄痵killPack鐨刾arentSkill涓嶅彉
+
+                        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);
+                }
             }
         }
+
+        // 濡傛灉鏄 HB426_tagSCTurnFightTag 鍖呰9鐨勭涓�涓妧鑳藉寘 骞朵笖鍓嶉潰娌℃湁CustomHB426CombinePack 
+        // 缈昏瘧涓�涓嬪氨鏄� 濡傛灉CombinePack閲岀殑涓讳綋Skill鍖� skillPack.RelatedSkillID > 0
+
 
 
         //  宓屽鍖呭唴鐨勫寘鍚堝苟
@@ -148,11 +190,75 @@
                 {
                     indexDict.Remove(i);
                     combinePack.AddPack(pack);
-                    if (pack is CustomHB426CombinePack)
+                    if (pack is CustomHB426CombinePack cbPack)
                     {
                         //  濡傛灉鏄祵濂楃殑鍖� 鍔犲叆涔嬪悗 璋冩暣i
-                        i = (pack as CustomHB426CombinePack).toIndex;
+                        i = cbPack.toIndex;
                     }
+                }
+            }
+        }
+
+
+        for (int i = 0; i < b421SeriesPackList.Count; i++)
+        {
+            if (indexDict.TryGetValue(i, out var pack))
+            {
+                if (pack is CustomHB426CombinePack cbPack)
+                {
+                    HB427_tagSCUseSkill skillPack = cbPack.GetMainHB427SkillPack();
+                
+                    if (null == skillPack)
+                    {
+                        continue;
+                    }
+
+                    //  濡傛灉鏄瓙鎶�鑳�
+                    if (skillPack.isSubSkill)
+                    {
+                        //  璁╁埆浜烘潵澶勭悊
+                        continue;
+                    }
+                    else
+                    {
+                        //  澶勭悊瀛愭妧鑳�
+                        if (skillPack.subSkillList.Count > 0)
+                        {
+                            var parentSkill = skillPack;
+                            List<HB427_tagSCUseSkill> toRemoveSubSkills = new List<HB427_tagSCUseSkill>();
+                            foreach (var subSkill in parentSkill.subSkillList)
+                            {
+                                CustomHB426CombinePack innerCBPack = null;
+                                if (cbPack.IsInnerCBPackContainsSkill(subSkill, ref innerCBPack))
+                                {
+                                    if (cbPack.GetMainHB427SkillPack() == subSkill)
+                                    {
+                                        parentSkill.subSkillList.Remove(subSkill);
+                                        Debug.LogError("瀛愭妧鑳戒笉鑳芥槸涓绘妧鑳�: " + subSkill.SkillID);
+                                        continue;
+                                    }
+                                    subSkill.parentCombinePack = innerCBPack;
+                                    cbPack.packList.Remove(innerCBPack);
+                                    toRemoveSubSkills.Add(subSkill);
+                                    parentSkill.subSkillCombinePackList.Add(innerCBPack);
+                                    indexDict.Remove(innerCBPack.fromIndex);
+                                }
+                            }
+                            foreach (var subSkill in toRemoveSubSkills)
+                            {
+                                parentSkill.subSkillList.Remove(subSkill);
+                            }
+                        }
+                        else
+                        {
+                            // 涓绘妧鑳芥病鏈夊瓙鎶�鑳� 鐩存帴璺宠繃
+                            continue;
+                        }
+                    }
+                }
+                else if (pack is HB427_tagSCUseSkill skillPack)
+                {
+                    // Debug.LogError("钀藉崟鐨勬妧鑳�");
                 }
             }
         }
@@ -166,15 +272,6 @@
             if (indexDict.TryGetValue(i, out var pack))
             {
                 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";
-                }
             }
         }
 
@@ -185,6 +282,40 @@
         return newPackList;
     }
 
+    public HB427_tagSCUseSkill GetMainHB427SkillPack()
+    {
+        for (int i = 0; i < packList.Count; i++)
+        {
+            var pack = packList[i];
+            if (pack is HB427_tagSCUseSkill skillPack)
+            {
+                return skillPack;
+            }
+            else if (pack is CustomHB426CombinePack)
+            {
+                return null;
+            }
+        }
+
+        return null;
+    }
+
+    public bool IsInnerCBPackContainsSkill(HB427_tagSCUseSkill skill, ref CustomHB426CombinePack innerCBPack)
+    {
+        for (int i = 0; i < packList.Count; i++)
+        {
+            var pack = packList[i];
+            if (pack is CustomHB426CombinePack cbPack)
+            {
+                if (cbPack.packList.Contains(skill))
+                {
+                    innerCBPack = cbPack;
+                    return true;
+                }
+            }
+        }
+        return false;
+    }
     public void Distribute()
     {
         BattleField battleField = BattleManager.Instance.GetBattleField(guid);
@@ -200,6 +331,57 @@
         {
             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
+            {
+                pack.commonMark = true;
+                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;
 
     }
 
@@ -231,13 +413,18 @@
             }
             else
             {
-                // Debug.LogError("鍙戠幇闈濻kill鍖咃紝鍏堝垎鍙戞帀: " + pack.GetType().Name);
+                pack.commonMark = true;
                 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.RemoveAt(0);
             if (null == skill)

--
Gitblit v1.8.0