hch
2026-01-26 aa84cb62bebb9c8a4e586bcc1ec28eb7a16a8860
Main/Core/NetworkPackage/CustomServerPack/CustomHB426CombinePack.cs
@@ -1,3 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
@@ -16,6 +17,13 @@
    public string guid;
    public List<GameNetPackBasic> packList = new List<GameNetPackBasic>();
#if UNITY_EDITOR
    // 编辑器下保存packList的副本,避免distribute过程中remove导致查看器显示不全
    public List<GameNetPackBasic> copiedPackList = new List<GameNetPackBasic>();
#endif
    private bool isCreated = false;
    public override void ReadFromBytes(byte[] vBytes)
    {
@@ -44,7 +52,6 @@
        }
        fromIndex = _fromIndex;
        startTag = tag;
        
    }
@@ -76,6 +83,11 @@
        }
        packList.Add(pack);
#if UNITY_EDITOR
        copiedPackList.Add(pack);
#endif
    }
    public bool IsEndPack(HB426_tagSCTurnFightTag tag)
@@ -99,8 +111,6 @@
        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++)
        {
@@ -137,42 +147,7 @@
            }
            else
            {
                if (pack is HB427_tagSCUseSkill skillPack)
                {
                    //  处理技能之间的链接关系
                    if (skillPack.RelatedSkillID > 0)
                    {
                        // 如果是被 HB426_tagSCTurnFightTag 包裹的第一个技能包 并且前面没有CustomHB426CombinePack
                        // 则需要把CustomHB426CombinePack加入skillPack的subSkillCombinePackList里
                        // 同时 需要把indexDict里删掉对应的subSkillCombinePackList
                        // subSkillList删掉对应skillPack,但是skillPack的parentSkill不变
                        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);
                }
                indexDict.Add(i, pack);
            }
        }
@@ -195,70 +170,6 @@
                        //  如果是嵌套的包 加入之后 调整i
                        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("落单的技能");
                }
            }
        }
@@ -316,25 +227,35 @@
        }
        return false;
    }
    public void Distribute()
    public bool Distribute(RecordAction parentAction = null)
    {
        BattleField battleField = BattleManager.Instance.GetBattleField(guid);
        if (null == battleField)
        {
            Debug.LogError("BattleField not found for guid: " + guid);
            return;
            return false;
        }
        var skillAction = CreateSkillAction();
        if (null != skillAction)
        {
            battleField.PlayRecord(skillAction);
            if (parentAction != null)
            {
                parentAction.GetInnerRecordPlayer().PlayRecord(skillAction);
            }
            else
            {
                battleField.PlayRecord(skillAction);
            }
        }
        else
        {
            battleField.DistributeNextPackage();
            return false;
        }
        return true;
    }
@@ -365,7 +286,11 @@
            }
            else
            {
                // Debug.LogError("发现非Skill包,先分发掉: " + pack.GetType().Name);
                pack.commonMark = true;
                // 【使用 BattleField.recordPlayer】
                // 原因:这里是在CreateSkillAction静态方法中,还没有创建SkillRecordAction
                // 这些包是在找到技能包之前遇到的,需要提前处理掉
                // 此时没有RecordAction上下文,应该使用BattleField的主RecordPlayer
                PackageRegedit.Distribute(pack);
            }
        }
@@ -381,6 +306,7 @@
        BattleObject _caster = battleField.battleObjMgr.GetBattleObject((int)skill.ObjID);
        SkillRecordAction skillAction = new SkillRecordAction(battleField, _caster, skill, _packList);
        skillAction.tracePackUID = skill.packUID;
        return skillAction;
    }
@@ -392,6 +318,12 @@
        if (null == battleField)
        {
            Debug.LogError("BattleField not found for guid: " + guid);
            return null;
        }
        if (isCreated)
        {
            Debug.LogError("create skill twice check the code");
            return null;
        }
@@ -408,12 +340,18 @@
            }
            else if (pack is CustomHB426CombinePack)
            {
                Debug.LogError("无法找到Skill包,先发现了嵌套包");
                Debug.LogError("无法找到Skill包,先发现了嵌套包 " + startTag.Tag);
                //  保持原样 不去动他
                packList.Insert(0, pack);
                return null;
            }
            else
            {
                // Debug.LogError("发现非Skill包,先分发掉: " + pack.GetType().Name);
                pack.commonMark = true;
                // 【使用 BattleField.recordPlayer】
                // 原因:这里是在CreateSkillAction方法中,还没有创建SkillRecordAction
                // 这些包是在找到技能包之前遇到的(如Buff包),需要提前处理
                // 此时没有RecordAction上下文,应该使用BattleField的主RecordPlayer
                PackageRegedit.Distribute(pack);
            }
        }
@@ -426,38 +364,60 @@
                return null;
            }
            HB427_tagSCUseSkill skill = packList[0] as HB427_tagSCUseSkill;
            packList.RemoveAt(0);
            if (null == skill)
            {
                Debug.LogError("No HB427_tagSCUseSkill found in packList.");
                return null;
            }
            packList.RemoveAt(0);
            BattleObject _caster = battleField.battleObjMgr.GetBattleObject((int)skill.ObjID);
            // BattleDebug.LogError("_caster == null : " + (_caster == null) + " skill.ObjID : " + skill.ObjID);
            isCreated = true;
            SkillRecordAction skillAction = new SkillRecordAction(battleField, _caster, skill, packList);
            skillAction.tracePackUID = packUID;
            return skillAction;
        }
        return null;
    }
#if UNITY_EDITOR
    public static CustomHB426CombinePack CreateCustomPack(string _guid, HB427_tagSCUseSkill skill)
    public bool NeedWaiting()
    {
        CustomHB426CombinePack pack = new CustomHB426CombinePack();
        pack.guid = string.Empty;
        bool needWaiting = false;
        pack.startTag = new HB426_tagSCTurnFightTag
        HB427_tagSCUseSkill hB427_TagSCUseSkill = GetMainHB427SkillPack();
        for (int i = 0; i < packList.Count; i++)
        {
            Tag = "Skill_Start",
            Sign = 0
        };
            var pack = packList[i];
            if (pack is HB427_tagSCUseSkill skillPack && skillPack != hB427_TagSCUseSkill)
            {
                SkillConfig ssc = SkillConfig.Get((int)skillPack.SkillID);
                if (!string.IsNullOrEmpty(ssc.SkillMotionName))
                {
                    needWaiting = true;
                    break;
                }
            }
            else if (pack is HB422_tagMCTurnFightObjDead dead)
            {
                needWaiting = true;
                break;
            }
            else if (pack is CustomHB426CombinePack combinePack)
            {
                if (combinePack.NeedWaiting())
                {
                    needWaiting = true;
                    break;
                }
            }
        }
        pack.packList.Add(skill);
        return pack;
        return needWaiting;
    }
#endif
}