Main/System/Battle/Skill/SkillBase.cs
@@ -28,9 +28,6 @@
    protected List<H0704_tagRolePackRefresh> dropPackList = new List<H0704_tagRolePackRefresh>();
    protected List<HB405_tagMCAddExp> expPackList = new List<HB405_tagMCAddExp>();
    protected List<SkillRecordAction> waitingCastSkillRecordAction = new List<SkillRecordAction>();
    protected bool moveFinished = false;
    public SkillBase fromSkill;
    public bool isPlay = false;
@@ -500,44 +497,48 @@
        skillEffect = SkillEffectFactory.CreateSkillEffect(this, caster, skillConfig, tagUseSkillAttack);
        skillEffect.Play(OnHitTargets);
        ProcessSubSkill();
        HandleWaitingCastSkill();
        isPlay = true;
    }
    protected void ProcessSubSkill()
    {
        // 按packUID排序所有子技能
        var allSubSkills = new List<(ulong packUID, SkillRecordAction action)>();
        foreach (var subSkillPack in tagUseSkillAttack.subSkillList)
        {
            SkillRecordAction recordAction = CustomHB426CombinePack.CreateSkillAction(battleField.guid, new List<GameNetPackBasic>() { subSkillPack });
            recordAction.fromSkill = this;
            //  子技能设置WaitingPlay=true,等待父技能动作完成
            waitingCastSkillRecordAction.Add(recordAction);
            battleField.recordPlayer.ImmediatelyPlay(recordAction, parentRecordAction, true);
            if (recordAction != null)
            {
                recordAction.fromSkill = this;
                allSubSkills.Add((subSkillPack.packUID, recordAction));
            }
        }
        tagUseSkillAttack.subSkillList.Clear();
        foreach (var subCombinePack in tagUseSkillAttack.subSkillCombinePackList)
        {
            SkillRecordAction recordAction = CustomHB426CombinePack.CreateSkillAction(battleField.guid, subCombinePack.packList);
            recordAction.fromSkill = this;
            //  子技能设置WaitingPlay=true,等待父技能动作完成
            waitingCastSkillRecordAction.Add(recordAction);
            if (recordAction != null)
            {
                recordAction.fromSkill = this;
                ulong packUID = subCombinePack.packList.Count > 0 ? GetPackUID(subCombinePack.packList[0]) : 0;
                allSubSkills.Add((packUID, recordAction));
            }
        }
        tagUseSkillAttack.subSkillCombinePackList.Clear();
        waitingCastSkillRecordAction.OrderBy(recordAction => recordAction.hB427_TagSCUseSkill.packUID);
        // 按packUID排序
        allSubSkills.Sort((a, b) => a.packUID.CompareTo(b.packUID));
    }
    protected void HandleWaitingCastSkill()
    {
        // 依次添加到recordPlayer,每个等待前一个完成
        RecordAction waitingRecordAction = null;
        for (int i = 0; i < waitingCastSkillRecordAction.Count; i++)
        foreach (var (packUID, recordAction) in allSubSkills)
        {
            var recordAction = waitingCastSkillRecordAction[i];
            // 【使用 BattleField.recordPlayer】
            // 原因:子技能是独立的SkillRecordAction,应该是顶层RecordAction,由BattleField的主RecordPlayer管理
            // 通过设置父子关系和WaitingPlay,可以控制子技能的执行时机
            if (waitingRecordAction != null)
            {
                //  每个都应该等前一个结束后
@@ -561,19 +562,19 @@
    // 技能中摇开始回调:通知技能效果处理中摇开始
    public virtual void OnMiddleFrameStart(int times)
    {
        skillEffect?.OnMiddleFrameStart(times); // 修复:添加空值检查
        skillEffect.OnMiddleFrameStart(times); // 修复:添加空值检查
    }
    // 技能中摇结束回调:通知技能效果处理中摇结束
    public virtual void OnMiddleFrameEnd(int times, int hitIndex)
    {
        skillEffect?.OnMiddleFrameEnd(times, hitIndex); // 修复:添加空值检查
        skillEffect.OnMiddleFrameEnd(times, hitIndex); // 修复:添加空值检查
    }
    // 技能后摇开始回调:通知技能效果处理后摇开始
    public virtual void OnFinalFrameStart()
    {
        skillEffect?.OnFinalFrameStart(); // 修复:添加空值检查
        skillEffect.OnFinalFrameStart(); // 修复:添加空值检查
    }
    // 技能后摇结束回调:通知技能效果处理后摇结束
@@ -899,7 +900,10 @@
        if (refreshPack != null)
        {
            // 分发HP刷新包
            PackageRegedit.Distribute(refreshPack);
            // 【使用 parentRecordAction.innerRecordPlayer】
            // 原因:HP刷新包是技能内部产生的,应该由当前SkillRecordAction的innerRecordPlayer管理
            // 这样可以确保HP刷新与技能的生命周期绑定,ForceFinish时一并处理
            PackageRegeditEx.DistributeToRecordAction(refreshPack, parentRecordAction);
            packList.Remove(refreshPack);
        }
    }
@@ -910,13 +914,123 @@
        List<BattleDeadPack> deadPackList = BattleUtility.FindDeadPack(packList);
        if (deadPackList.Count <= 0) return;
        // 找到最大的死亡包 packUID(包括死亡包和死亡触发技能)
        ulong maxDeathPackUID = 0;
        foreach (var deadPack in deadPackList)
        {
            if (deadPack.deadPack != null && deadPack.deadPack.packUID > maxDeathPackUID)
            {
                maxDeathPackUID = deadPack.deadPack.packUID;
            }
            if (deadPack.deadTriggerSkill != null)
            {
                var skillPack = deadPack.deadTriggerSkill.GetMainHB427SkillPack();
                if (skillPack != null && skillPack.packUID > maxDeathPackUID)
                {
                    maxDeathPackUID = skillPack.packUID;
                }
            }
        }
        // 如果找到了死亡包,收集所有 packUID > maxDeathPackUID 的包
        if (maxDeathPackUID > 0)
        {
            BattleDebug.LogError($"SkillBase.HandleDead: 找到死亡包,maxDeathPackUID = {maxDeathPackUID},开始收集死亡后的包");
            // 1. 收集 packList 中 packUID 大于死亡包的包
            List<GameNetPackBasic> packsToRemove = new List<GameNetPackBasic>();
            foreach (var pack in packList)
            {
                ulong packUID = GetPackUID(pack);
                if (packUID > maxDeathPackUID)
                {
                    BattleDebug.LogError($"SkillBase.HandleDead: 从packList收集死亡后的包 - Type: {pack.GetType().Name}, UID: {packUID}");
                    foreach (var deadPack in deadPackList)
                    {
                        deadPack.packListAfterDeath.Add(pack);
                    }
                    packsToRemove.Add(pack);
                }
            }
            // 从 packList 中移除这些包
            foreach (var pack in packsToRemove)
            {
                packList.Remove(pack);
            }
            // 2. 收集 subSkillList 中 packUID 大于死亡包的子技能
            if (tagUseSkillAttack.subSkillList != null && tagUseSkillAttack.subSkillList.Count > 0)
            {
                var subSkillsToRemove = new List<HB427_tagSCUseSkill>();
                foreach (var subSkillPack in tagUseSkillAttack.subSkillList)
                {
                    ulong subSkillUID = GetPackUID(subSkillPack);
                    if (subSkillUID > maxDeathPackUID)
                    {
                        BattleDebug.LogError($"SkillBase.HandleDead: 从subSkillList收集死亡后的包 - Type: {subSkillPack.GetType().Name}, UID: {subSkillUID}");
                        foreach (var deadPack in deadPackList)
                        {
                            deadPack.packListAfterDeath.Add(subSkillPack);
                        }
                        subSkillsToRemove.Add(subSkillPack);
                    }
                }
                // 从 subSkillList 中移除这些子技能
                foreach (var subSkill in subSkillsToRemove)
                {
                    tagUseSkillAttack.subSkillList.Remove(subSkill);
                }
            }
            // 3. 收集 subSkillCombinePackList 中 packUID 大于死亡包的组合包
            if (tagUseSkillAttack.subSkillCombinePackList != null && tagUseSkillAttack.subSkillCombinePackList.Count > 0)
            {
                var combinePacksToRemove = new List<CustomHB426CombinePack>();
                foreach (var subCombinePack in tagUseSkillAttack.subSkillCombinePackList)
                {
                    // 找到组合包中的最小 packUID(组合包的 packUID 以第一个包为准)
                    ulong combinePackUID = 0;
                    if (subCombinePack.packList != null && subCombinePack.packList.Count > 0)
                    {
                        combinePackUID = GetPackUID(subCombinePack.packList[0]);
                    }
                    if (combinePackUID > maxDeathPackUID)
                    {
                        BattleDebug.LogError($"SkillBase.HandleDead: 从subSkillCombinePackList收集死亡后的包 - UID: {combinePackUID}, 包含 {subCombinePack.packList.Count} 个子包");
                        // 将组合包中的所有包都添加到 packListAfterDeath
                        foreach (var pack in subCombinePack.packList)
                        {
                            foreach (var deadPack in deadPackList)
                            {
                                deadPack.packListAfterDeath.Add(pack);
                            }
                        }
                        combinePacksToRemove.Add(subCombinePack);
                    }
                }
                // 从 subSkillCombinePackList 中移除这些组合包
                foreach (var combinePack in combinePacksToRemove)
                {
                    tagUseSkillAttack.subSkillCombinePackList.Remove(combinePack);
                }
            }
        }
        CheckAfterDeadhPack();
        // 修复:先收集要删除的包,避免在foreach中修改集合
        var dropPacksToRemove = new List<H0704_tagRolePackRefresh>(dropPackList);
        foreach (var _dropPack in dropPacksToRemove)
        {
            PackageRegedit.Distribute(_dropPack);
            // 【使用 parentRecordAction.innerRecordPlayer】
            // 原因:掉落包是技能效果的一部分,应该由当前SkillRecordAction管理
            // 掉落包的分发与技能完成绑定,确保在技能ForceFinish时正确处理
            PackageRegeditEx.DistributeToRecordAction(_dropPack, parentRecordAction);
            packList.Remove(_dropPack);
        }
@@ -991,6 +1105,48 @@
        for (int i = 0; i < itemList.Count; i++)
            dropAssign[i % deadCount].Add(itemList[i]);
        return dropAssign;
    }
    // 获取包的 packUID
    protected ulong GetPackUID(GameNetPackBasic pack)
    {
        if (pack == null) return 0;
        if (pack is HB422_tagMCTurnFightObjDead deadPack)
            return deadPack.packUID;
        if (pack is CustomHB426CombinePack combinePack)
        {
            var mainSkillPack = combinePack.GetMainHB427SkillPack();
            return mainSkillPack?.packUID ?? 0;
        }
        if (pack is HB427_tagSCUseSkill skillPack)
            return skillPack.packUID;
        if (pack is HB428_tagSCBuffRefresh buffRefresh)
            return buffRefresh.packUID;
        if (pack is HB429_tagSCBuffDel buffDel)
            return buffDel.packUID;
        if (pack is HB419_tagSCObjHPRefresh hpRefresh)
            return hpRefresh.packUID;
        if (pack is HB405_tagMCAddExp expPack)
            return expPack.packUID;
        if (pack is H0704_tagRolePackRefresh dropPack)
            return dropPack.packUID;
        // 尝试通过反射获取 packUID
        var packUIDField = pack.GetType().GetField("packUID");
        if (packUIDField != null)
        {
            return (ulong)packUIDField.GetValue(pack);
        }
        return 0;
    }
    // 分配经验值:将经验包平均分配给每个死亡对象
@@ -1198,7 +1354,10 @@
            SkillRecordAction recordAction = CustomHB426CombinePack.CreateSkillAction(battleField.guid, new List<GameNetPackBasic>() { subSkillPack });
            recordAction.fromSkill = this;
            otherSkillActionList.Add(recordAction);
            //  子技能设置WaitingPlay=true,等待父技能动作完成
            // 【使用 BattleField.recordPlayer】
            // 原因:即使在ForceFinished中,子技能也是顶层RecordAction,应该由主RecordPlayer管理
            // 这些子技能会立即被ForceFinish,但仍需要正确的播放器上下文
            battleField.recordPlayer.ImmediatelyPlay(recordAction, parentRecordAction, true);
        }
        tagUseSkillAttack.subSkillList.Clear();
@@ -1207,7 +1366,9 @@
            SkillRecordAction recordAction = CustomHB426CombinePack.CreateSkillAction(battleField.guid, subCombinePack.packList);
            recordAction.fromSkill = this;
            otherSkillActionList.Add(recordAction);
            //  子技能设置WaitingPlay=true,等待父技能动作完成
            // 【使用 BattleField.recordPlayer】
            // 原因:即使在ForceFinished中,子技能也是顶层RecordAction,应该由主RecordPlayer管理
            battleField.recordPlayer.ImmediatelyPlay(recordAction, parentRecordAction, true);
        }
        tagUseSkillAttack.subSkillCombinePackList.Clear();
@@ -1298,7 +1459,10 @@
            {
                if (pack is CustomB421ActionPack actionPack)
                    actionPack.Distribute();
                PackageRegedit.Distribute(pack);
                // 【使用 parentRecordAction.innerRecordPlayer】
                // 原因:ForceFinished时剩余的包也是技能内部产生的,应该由innerRecordPlayer管理
                // 这样可以确保即使强制结束,包的处理也在正确的上下文中
                PackageRegeditEx.DistributeToRecordAction(pack, parentRecordAction);
            }
        }
    }
@@ -1408,7 +1572,10 @@
            }
            else
            {
                PackageRegedit.Distribute(pack);
                // 【使用 parentRecordAction.innerRecordPlayer】
                // 原因:技能执行过程中的包(Buff、属性刷新等)是技能效果的一部分
                // 应该由SkillRecordAction的innerRecordPlayer管理,确保与技能生命周期一致
                PackageRegeditEx.DistributeToRecordAction(pack, parentRecordAction);
            }
        }
@@ -1476,7 +1643,10 @@
        foreach (var pack in buffPacks)
        {
            PackageRegedit.Distribute(pack);
            // 【使用 parentRecordAction.innerRecordPlayer】
            // 原因:Buff包是技能效果的核心组成部分,应该由SkillRecordAction管理
            // 即使是强制分发的情况,也要保持在正确的RecordAction上下文中
            PackageRegeditEx.DistributeToRecordAction(pack, parentRecordAction);
        }
    }