hch
2026-01-26 aa84cb62bebb9c8a4e586bcc1ec28eb7a16a8860
Main/System/Battle/Skill/SkillBase.cs
@@ -24,12 +24,11 @@
    protected RectTransform targetNode = null; // 目标节点
    public BattleObject caster = null; // 施法者
    protected List<GameNetPackBasic> packList;
    protected List<SkillRecordAction> otherSkillActionList = new List<SkillRecordAction>();
    protected List<RecordAction> currentWaitingSkill = new List<RecordAction>();
    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;
@@ -66,6 +65,11 @@
        }
        SafetyCheck();
    }
    public virtual void AfterAddToQueue()
    {
    }
    //  设置父RecordAction
@@ -190,22 +194,7 @@
            return;
        }
        if (otherSkillActionList.Count > 0)
        {
            for (int i = otherSkillActionList.Count - 1; i >= 0; i--)
            {
                var action = otherSkillActionList[i];
                if (action.IsFinished())
                {
                    otherSkillActionList.RemoveAt(i);
                    OnSkillFinished();
                }
                else if (moveFinished)
                {
                    action.Run();
                }
            }
        }
    }
    protected void ShadowIllutionCreate(bool create)
@@ -495,62 +484,73 @@
            return;
        }
        //  先把死亡包收集了
        HandleDead();
        //  再处理 内嵌技能
        ProcessSubSkill();
        skillEffect = SkillEffectFactory.CreateSkillEffect(this, caster, skillConfig, tagUseSkillAttack);
        skillEffect.Play(OnHitTargets);
        ProcessSubSkill();
        HandleWaitingCastSkill();
        isPlay = true;
    }
    protected void ProcessSubSkill()
    {
        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);
        }
        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);
        }
        tagUseSkillAttack.subSkillCombinePackList.Clear();
        waitingCastSkillRecordAction.OrderBy(recordAction => recordAction.hB427_TagSCUseSkill.packUID);
        // 按packUID排序所有子技能
        var allSubSkills = new List<(ulong packUID, SkillRecordAction action)>();
        
    }
        List<GameNetPackBasic> removePackList = new List<GameNetPackBasic>();
    protected void HandleWaitingCastSkill()
    {
        RecordAction waitingRecordAction = null;
        for (int i = 0; i < waitingCastSkillRecordAction.Count; i++)
        foreach (var pack in packList)
        {
            var recordAction = waitingCastSkillRecordAction[i];
            if (pack is HB427_tagSCUseSkill skillPack)
            {
                SkillConfig ssc = SkillConfig.Get((int)skillPack.SkillID);
                if (!string.IsNullOrEmpty(ssc.SkillMotionName))
                {
                    break;
                }
                SkillRecordAction skillRecordAction = CustomHB426CombinePack.CreateSkillAction(battleField.guid, new List<GameNetPackBasic> { skillPack });
                allSubSkills.Add((skillPack.packUID, skillRecordAction));
                removePackList.Add(pack);
            }
            else if (pack is HB422_tagMCTurnFightObjDead dead)
            {
                break;
            }
            else if (pack is CustomHB426CombinePack combinePack)
            {
                HB427_tagSCUseSkill sp = combinePack.GetMainHB427SkillPack();
                SkillConfig ssc = SkillConfig.Get((int)sp.SkillID);
            if (waitingRecordAction != null)
            {
                //  每个都应该等前一个结束后
                battleField.recordPlayer.ImmediatelyPlay(recordAction, waitingRecordAction, true);
                if (!string.IsNullOrEmpty(ssc.SkillMotionName))
                {
                    break;
                }
                SkillRecordAction skillRecordAction = combinePack.CreateSkillAction();
                allSubSkills.Add((sp.packUID, skillRecordAction));
                removePackList.Add(pack);
            }
            else
            {
                battleField.recordPlayer.ImmediatelyPlay(recordAction, parentRecordAction, true);
            }
        }
        for (int i = 0; i < removePackList.Count; i++)
        {
            packList.Remove(removePackList[i]);
        }
        // 按packUID排序
        allSubSkills.Sort((a, b) => a.packUID.CompareTo(b.packUID));
        foreach (var (packUID, recordAction) in allSubSkills)
        {
            battleField.recordPlayer.ImmediatelyPlay(recordAction);
            if (recordAction.IsNeedWaiting())
            {
                waitingRecordAction = recordAction;
                currentWaitingSkill.Add(recordAction);
            }
        }
    }
@@ -720,6 +720,11 @@
            }
        }
        HandleHint(_hitIndex, hitList);
    }
    protected void HandleHint(int _hitIndex, List<HB427_tagSCUseSkill.tagSCUseSkillHurt> hitList)
    {
        if (0 == _hitIndex)
        {
            bool needhint = false;
@@ -755,9 +760,37 @@
                DamageNumConfig hintConfig = DamageNumConfig.Get(BattleConst.BattleStun);
                Hint(caster, hintConfig);
            }
        }
            for (int i = 0; i < hitList.Count; i++)
            {
                var hurt = hitList[i];
                if ((hurt.AttackTypes & (int)DamageType.BreakArmor) == (int)DamageType.BreakArmor)
                {
                    BattleObject battleObject = caster.battleField.battleObjMgr.GetBattleObject((int)hurt.ObjID);
                    if (battleObject != null)
                    {
                        DamageNumConfig hintConfig = DamageNumConfig.Get(BattleConst.BreakArmor);
                        Hint(battleObject, hintConfig);
                        battleField.battleEffectMgr.PlayEffect(battleObject,
                            BattleConst.BreakArmorEffectID, battleObject.heroRectTrans, battleObject.Camp,
                            battleObject.teamHero.modelScale);
                    }
                }
                else if ((hurt.AttackTypes & (int)DamageType.Parry) == (int)DamageType.Parry)
                {
                    BattleObject battleObject = caster.battleField.battleObjMgr.GetBattleObject((int)hurt.ObjID);
                    if (battleObject != null)
                    {
                        DamageNumConfig hintConfig = DamageNumConfig.Get(BattleConst.Parry);
                        Hint(battleObject, hintConfig);
                        battleField.battleEffectMgr.PlayEffect(battleObject,
                            BattleConst.ParryEffectID, battleObject.heroRectTrans, battleObject.Camp,
                            battleObject.teamHero.modelScale);
                    }
                }
            }
        }
    }
    // 处理单个目标被命中:应用伤害和施法者效果
@@ -781,7 +814,14 @@
#endif
        // 先调用目标受伤
        target.Hurt(hurtParam, parentRecordAction);
        DeathRecordAction recordAc = target.Hurt(hurtParam, parentRecordAction);
        if (null != recordAc)
        {
            tempDeadPackList.Remove(hurtParam.hurter.hurtObj.ObjID);
            battleField.recordPlayer.ImmediatelyPlay(recordAc, parentRecordAction, true);
            currentWaitingSkill.Add(recordAc);
        }
        
        // 再调用施法者吸血/反伤
        caster.OnHurtTarget(hurtParam);
@@ -866,7 +906,10 @@
        if (refreshPack != null)
        {
            // 分发HP刷新包
            PackageRegedit.Distribute(refreshPack);
            // 【使用 parentRecordAction.innerRecordPlayer】
            // 原因:HP刷新包是技能内部产生的,应该由当前SkillRecordAction的innerRecordPlayer管理
            // 这样可以确保HP刷新与技能的生命周期绑定,ForceFinish时一并处理
            PackageRegeditEx.DistributeToRecordAction(refreshPack, parentRecordAction);
            packList.Remove(refreshPack);
        }
    }
@@ -877,13 +920,62 @@
        List<BattleDeadPack> deadPackList = BattleUtility.FindDeadPack(packList);
        if (deadPackList.Count <= 0) return;
        foreach (var deadPack in deadPackList)
        {
            packList.Remove(deadPack.deadPack);
            packList.Remove(deadPack.deadTriggerSkill);
        }
        // 找到最大的死亡包 packUID
        BattleDeadPack lastBattleDeadPack = null;
        ulong maxDeathPackUID = 0;
        foreach (var deadPack in deadPackList)
        {
            if (deadPack.deadPack != null && deadPack.deadPack.packUID > maxDeathPackUID)
            {
                maxDeathPackUID = deadPack.deadPack.packUID;
                lastBattleDeadPack = deadPack;
            }
        }
        // 如果找到了死亡包,收集所有 packUID > maxDeathPackUID 的包
        if (maxDeathPackUID > 0 && lastBattleDeadPack != null)
        {
            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)
                {
                    // 排除经验包和掉落包,它们属于当前死亡事件的一部分,不是"死亡后"的包
                    if (pack is HB405_tagMCAddExp expPack && expPack.Source == 2 ||
                        (pack is H0704_tagRolePackRefresh h0704 && h0704.PackType == (byte)PackType.DropItem && h0704.IsBind == 1))
                    {
                        continue; // 跳过经验包和掉落包,让 CheckAfterDeadhPack() 处理它们
                    }
                    BattleDebug.LogError($"SkillBase.HandleDead: 从packList收集死亡后的包 - Type: {pack.GetType().Name}, UID: {packUID}");
                    lastBattleDeadPack.packListAfterDeath.Add(pack);
                    packsToRemove.Add(pack);
                }
            }
            packList.RemoveAll(p => packsToRemove.Contains(p));
        }
        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);
        }
@@ -898,8 +990,8 @@
        // 构造BattleDrops并缓存
        for (int i = 0; i < deadPackList.Count; i++)
        {
            BattleDeadPack battleDeadPack = deadPackList[i];
            int objID = (int)battleDeadPack.deadPack.ObjID;
            BattleDeadPack bdp = deadPackList[i];
            int objID = (int)bdp.deadPack.ObjID;
            BattleObject deadTarget = battleField.battleObjMgr.GetBattleObject(objID);
            
            // 修复:添加空值检查
@@ -958,6 +1050,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;
    }
    // 分配经验值:将经验包平均分配给每个死亡对象
@@ -1037,7 +1171,7 @@
    }
    public virtual bool IsFinishedForJudge()
    public virtual bool IsActionCompleted()
    {
        if (!isPlay) return false;
@@ -1046,27 +1180,14 @@
            if (!skillEffect.IsFinished()) return false;
        }
        if (otherSkillActionList.Count > 0)
        if (moveFinished)
        {
            foreach (var action in otherSkillActionList)
            {
                if (!action.IsFinishedForJudge()) return false;
            }
        }
        if (isFinished && moveFinished)
        {
            if (packList.Count > 0)
            {
                return false;
            }
            //  如果技能有动画(SkillMotionName不为空),需要等待动画播放完成
            if (skillConfig != null && !string.IsNullOrEmpty(skillConfig.SkillMotionName))
            {
                if (!isMotionCompleted)
                {
                    BattleDebug.LogError($"SkillBase.IsFinishedForJudge: 技能 {skillConfig.SkillID} 等待动画播放完成");
                    BattleDebug.LogError($"SkillBase.IsActionCompleted: 技能 {skillConfig.SkillID} 等待动画播放完成");
                    return false;
                }
            }
@@ -1094,18 +1215,14 @@
        }
        // 检查其他技能动作是否完成
        if (otherSkillActionList.Count > 0)
        if (currentWaitingSkill.Count > 0)
        {
            for (int i = otherSkillActionList.Count - 1; i >= 0; i--)
            if (currentWaitingSkill.Any(s => s.IsFinished()))
            {
                var action = otherSkillActionList[i];
                if (action.IsFinished())
                {
                    otherSkillActionList.RemoveAt(i);
                    OnSkillFinished();
                }
                currentWaitingSkill.RemoveAll(s => s.IsFinished());
                OnSkillFinished();
            }
            if (otherSkillActionList.Count > 0)
            else
            {
                tempRetValue = false;
            }
@@ -1125,13 +1242,25 @@
                return false;
            }
            //  如果自己内部的recora action的 inner record player还有没执行完的包 也是返回false
            if (parentRecordAction != null && parentRecordAction.GetInnerRecordPlayer().IsPlaying())
            {
                return false;
            }
            // 技能完全结束,移除技能注册并触发延迟的死亡判定
            if (battleField != null && caster != null)
            {
                battleField.RemoveCastingSkill(caster.ObjID, this);
                
                //  传递parentRecordAction,让死亡技能等待当前技能完成
                battleField.OnObjsDead(new List<BattleDeadPack>(tempDeadPackList.Values));
                DeathRecordAction recordAction = battleField.OnObjsDead(new List<BattleDeadPack>(tempDeadPackList.Values));
                if (null != recordAction)
                {
                    parentRecordAction.GetInnerRecordPlayer().ImmediatelyPlay(recordAction);
                    tempDeadPackList.Clear();
                    return false;
                }
            }
            return true;
@@ -1154,34 +1283,26 @@
        }
        //  传递parentRecordAction,让死亡技能等待当前技能完成
        battleField.OnObjsDead(new List<BattleDeadPack>(tempDeadPackList.Values), parentRecordAction);
        RecordAction rc = battleField.OnObjsDead(new List<BattleDeadPack>(tempDeadPackList.Values));
        if (null != rc)
        {
            parentRecordAction.GetInnerRecordPlayer().ImmediatelyPlay(rc);
        }
        tempDeadPackList.Clear();
        // 1. 强制结束技能效果
        skillEffect?.ForceFinished();
        skillEffect = null;
        foreach (var subSkillPack in tagUseSkillAttack.subSkillList)
        {
            SkillRecordAction recordAction = CustomHB426CombinePack.CreateSkillAction(battleField.guid, new List<GameNetPackBasic>() { subSkillPack });
            recordAction.fromSkill = this;
            otherSkillActionList.Add(recordAction);
            //  子技能设置WaitingPlay=true,等待父技能动作完成
            battleField.recordPlayer.ImmediatelyPlay(recordAction, parentRecordAction, true);
        }
        tagUseSkillAttack.subSkillList.Clear();
        foreach (var subCombinePack in tagUseSkillAttack.subSkillCombinePackList)
        {
            SkillRecordAction recordAction = CustomHB426CombinePack.CreateSkillAction(battleField.guid, subCombinePack.packList);
            recordAction.fromSkill = this;
            otherSkillActionList.Add(recordAction);
            //  子技能设置WaitingPlay=true,等待父技能动作完成
            battleField.recordPlayer.ImmediatelyPlay(recordAction, parentRecordAction, true);
        }
        tagUseSkillAttack.subSkillCombinePackList.Clear();
        
        // 2. 强制结束所有子技能动作
        otherSkillActionList.ForEach(action => action.ForceFinish());
        otherSkillActionList.Clear();
        if (currentWaitingSkill.Count > 0)
        {
            foreach (var skill in currentWaitingSkill)
            {
                skill.ForceFinish();
            }
            currentWaitingSkill.Clear();
        }
        // 3. 清理 DOTween 动画(防止移动回调在战斗结束后执行)
        if (caster != null && caster.heroRectTrans != null)
@@ -1208,12 +1329,6 @@
            // 取消幻影效果
            caster.motionBase?.ShowIllusionShadow(false);
            // 播放待机动画(如果还活着)
            if (!caster.teamHero.isDead)
            {
                caster.motionBase?.ResetForReborn(false);
            }
        }
        // 5. 恢复 UI 状态
@@ -1263,8 +1378,9 @@
            }
            else
            {
                if (pack is CustomB421ActionPack actionPack)
                    actionPack.Distribute();
                // 【使用 parentRecordAction.innerRecordPlayer】
                // 原因:ForceFinished时剩余的包也是技能内部产生的,应该由innerRecordPlayer管理
                // 这样可以确保即使强制结束,包的处理也在正确的上下文中
                PackageRegedit.Distribute(pack);
            }
        }
@@ -1289,20 +1405,14 @@
            }
            // 验证其他技能动作是否完成
            if (otherSkillActionList.Count > 0)
            if (currentWaitingSkill.Count > 0)
            {
                bool hasFinishedAction = false;
                for (int i = otherSkillActionList.Count - 1; i >= 0; i--)
                {
                    var action = otherSkillActionList[i];
                    if (action.IsFinished())
                    {
                        otherSkillActionList.RemoveAt(i);
                        hasFinishedAction = true;
                    }
                }
                bool hasFinishedAction = currentWaitingSkill.All(s => s.IsFinished());
                if (hasFinishedAction)
                {
                    // 修复死循环:完成后需要清空 currentWaitingSkill
                    currentWaitingSkill.Clear();
                    continue; // 使用continue代替递归调用
                }
                return;
@@ -1330,17 +1440,24 @@
    
    protected virtual bool ResolvePackList()
    {
        if (currentWaitingSkill.Count > 0)
        {
            return false;
        }
        while (packList.Count > 0)
        {
            var pack = packList[0];
            packList.RemoveAt(0);
            if (pack is CustomHB426CombinePack combinePack && combinePack.startTag.Tag.StartsWith("Skill_"))
            {
                BattleDebug.LogError("other skill casting " + combinePack.startTag.Tag);
                var otherSkillAction = combinePack.CreateSkillAction();
                otherSkillAction.fromSkill = this;
                otherSkillActionList.Add(otherSkillAction);
                var skillRecordAction = combinePack.CreateSkillAction();
                skillRecordAction.fromSkill = this;
                currentWaitingSkill.Add(skillRecordAction);
                parentRecordAction.GetInnerRecordPlayer().PlayRecord(skillRecordAction);
                return false;
            }
            else if (IsBuffPack(pack))
@@ -1368,14 +1485,12 @@
                buffPackCollections.Clear();
                continue;
            }
            if (pack is CustomB421ActionPack actionPack)
            {
                actionPack.Distribute();
            }
            else
            {
                PackageRegedit.Distribute(pack);
                // 【使用 parentRecordAction.innerRecordPlayer】
                // 原因:技能执行过程中的包(Buff、属性刷新等)是技能效果的一部分
                // 应该由SkillRecordAction的innerRecordPlayer管理,确保与技能生命周期一致
                PackageRegeditEx.DistributeToRecordAction(pack, parentRecordAction);
            }
        }
@@ -1387,7 +1502,7 @@
    {
        tempDropList?.Clear();
        tempDeadPackList?.Clear();
        otherSkillActionList?.Clear();
        currentWaitingSkill?.Clear();
        dropPackList?.Clear();
        expPackList?.Clear();
        buffPackCollections?.Clear();
@@ -1443,7 +1558,10 @@
        foreach (var pack in buffPacks)
        {
            PackageRegedit.Distribute(pack);
            // 【使用 parentRecordAction.innerRecordPlayer】
            // 原因:Buff包是技能效果的核心组成部分,应该由SkillRecordAction管理
            // 即使是强制分发的情况,也要保持在正确的RecordAction上下文中
            PackageRegeditEx.DistributeToRecordAction(pack, parentRecordAction);
        }
    }