| | |
| | | using System.Collections.Generic; |
| | | using UnityEngine; |
| | | using System; |
| | | using DG.Tweening; |
| | | using Spine; |
| | | using System.Linq; |
| | | using PlasticGui.WorkspaceWindow.BranchExplorer; |
| | | |
| | | using System; |
| | | |
| | | public class SkillBase |
| | | { |
| | | const float moveTime = 0.5f; |
| | | const float moveTime = 0.5f; |
| | | |
| | | protected SkillEffect skillEffect; |
| | | private static readonly Color colorGreen = new Color(33f / 255f, |
| | | 133f / 255f, |
| | | 6f / 255f); |
| | | private static readonly Color colorBlue = new Color(40f / 255f, |
| | | 87f / 255f, |
| | | 189f / 255f); |
| | | |
| | | protected HB427_tagSCUseSkill tagUseSkillAttack; |
| | | protected SkillEffect skillEffect; |
| | | public HB427_tagSCUseSkill tagUseSkillAttack; |
| | | public SkillConfig skillConfig; |
| | | protected bool isFinished = false; |
| | | protected BattleField battleField = null; // 战场 |
| | | protected RectTransform targetNode = null; // 目标节点 |
| | | public BattleObject caster = null; // 施法者 |
| | | protected List<GameNetPackBasic> packList; |
| | | protected List<SkillRecordAction> otherSkillActionList = new List<SkillRecordAction>(); |
| | | protected List<H0704_tagRolePackRefresh> dropPackList = new List<H0704_tagRolePackRefresh>(); |
| | | protected List<HB405_tagMCAddExp> expPackList = new List<HB405_tagMCAddExp>(); |
| | | |
| | | protected SkillConfig skillConfig; |
| | | protected bool moveFinished = false; |
| | | public SkillBase fromSkill; |
| | | public bool isPlay = false; |
| | | |
| | | protected bool isFinished = false; |
| | | // 父RecordAction(SkillRecordAction),用于子技能建立父子关系 |
| | | protected RecordAction parentRecordAction; |
| | | |
| | | // 技能动画是否播放完成(针对有动画的技能) |
| | | protected bool isMotionCompleted = false; |
| | | |
| | | protected BattleField battleField = null; // 战场 |
| | | private float MoveSpeed = 750f; |
| | | |
| | | protected RectTransform targetNode = null; // 目标节点 |
| | | private Dictionary<int, BattleDrops> tempDropList = new Dictionary<int, BattleDrops>(); |
| | | private Dictionary<int, BattleDeadPack> tempDeadPackList = new Dictionary<int, BattleDeadPack>(); |
| | | |
| | | protected BattleObject caster = null; // 施法者 |
| | | // Buff相关包集合,支持 HB428(刷新) 和 HB429(删除) |
| | | protected List<GameNetPackBasic> buffPackCollections = new List<GameNetPackBasic>(); |
| | | |
| | | protected bool startCounting = false; |
| | | |
| | | protected bool pauseState = false; |
| | | // 构造函数:初始化技能基础数据 |
| | | public SkillBase(BattleObject _caster, SkillConfig _skillCfg, HB427_tagSCUseSkill vNetData, List<GameNetPackBasic> _packList, BattleField _battleField = null) |
| | | { |
| | | caster = _caster; |
| | | skillConfig = _skillCfg; |
| | | tagUseSkillAttack = vNetData; |
| | | battleField = _battleField; |
| | | packList = _packList; |
| | | |
| | | protected int curFrame = 0; |
| | | // 注册正在释放的技能 |
| | | if (battleField != null && caster != null) |
| | | { |
| | | battleField.AddCastingSkill(caster.ObjID, this); |
| | | } |
| | | |
| | | protected List<GameNetPackBasic> packList; |
| | | SafetyCheck(); |
| | | } |
| | | |
| | | protected SkillRecordAction otherSkillAction; |
| | | // 设置父RecordAction |
| | | public void SetParentRecordAction(RecordAction recordAction) |
| | | { |
| | | parentRecordAction = recordAction; |
| | | } |
| | | |
| | | protected List<H0704_tagRolePackRefresh> dropPackList = new List<H0704_tagRolePackRefresh>(); |
| | | #if UNITY_EDITOR |
| | | public static Dictionary<string, string> changeListDict = new Dictionary<string, string>(); |
| | | #endif |
| | | private void PinrtHB427Hp() |
| | | { |
| | | #if UNITY_EDITOR |
| | | string skillDetail = "SkillCaster : " + tagUseSkillAttack.ObjID + " -> cast SkillID: " + skillConfig.SkillID + "\n"; |
| | | |
| | | skillDetail += "------------------ HurtList ------------------\n"; |
| | | for (int i = 0; i < tagUseSkillAttack.HurtCount; i++) |
| | | { |
| | | var Hurt = tagUseSkillAttack.HurtList[i]; |
| | | BattleObject battleObject = caster.battleField.battleObjMgr.GetBattleObject((int)Hurt.ObjID); |
| | | |
| | | string targetName = battleObject != null ? battleObject.teamHero.name : "Unknown"; |
| | | long hurtHp = GeneralDefine.GetFactValue(Hurt.HurtHP, Hurt.HurtHPEx); |
| | | long curHp = GeneralDefine.GetFactValue(Hurt.CurHP, Hurt.CurHPEx); |
| | | |
| | | skillDetail += $" [{i}] Target: {targetName} (ObjID:{Hurt.ObjID})\n"; |
| | | skillDetail += $" HurtHP: {hurtHp}\n"; |
| | | skillDetail += $" CurHP: {curHp}\n"; |
| | | skillDetail += $" SuckHP: {Hurt.SuckHP}\n"; |
| | | skillDetail += $" BounceHP: {Hurt.BounceHP}\n"; |
| | | skillDetail += $" AttackTypes: {Hurt.AttackTypes}\n"; |
| | | |
| | | if (Hurt.HurtListEx != null && Hurt.HurtListEx.Length > 0) |
| | | { |
| | | skillDetail += $" HurtListEx ({Hurt.HurtListEx.Length}):\n"; |
| | | for (int j = 0; j < Hurt.HurtListEx.Length; j++) |
| | | { |
| | | var hurtEx = Hurt.HurtListEx[j]; |
| | | long hurtExHp = GeneralDefine.GetFactValue(hurtEx.HurtHP, hurtEx.HurtHPEx); |
| | | long curExHp = GeneralDefine.GetFactValue(hurtEx.CurHP, hurtEx.CurHPEx); |
| | | |
| | | skillDetail += $" [{j}] ObjID:{hurtEx.ObjID} HurtHP:{hurtExHp} CurHP:{curExHp} SuckHP:{hurtEx.SuckHP} AttackTypes:{hurtEx.AttackTypes}\n"; |
| | | } |
| | | } |
| | | } |
| | | |
| | | protected List<HB405_tagMCAddExp> expPackList = new List<HB405_tagMCAddExp>(); |
| | | skillDetail += "------------------ HurtListEx ------------------\n"; |
| | | if (tagUseSkillAttack.HurtListEx != null) |
| | | { |
| | | for (int i = 0; i < tagUseSkillAttack.HurtListEx.Length; i++) |
| | | { |
| | | var HurtEx = tagUseSkillAttack.HurtListEx[i]; |
| | | BattleObject battleObject = caster.battleField.battleObjMgr.GetBattleObject((int)HurtEx.ObjID); |
| | | |
| | | string targetName = battleObject != null ? battleObject.teamHero.name : "Unknown"; |
| | | long hurtHp = GeneralDefine.GetFactValue(HurtEx.HurtHP, HurtEx.HurtHPEx); |
| | | long curHp = GeneralDefine.GetFactValue(HurtEx.CurHP, HurtEx.CurHPEx); |
| | | |
| | | skillDetail += $" [{i}] Target: {targetName} (ObjID:{HurtEx.ObjID})\n"; |
| | | skillDetail += $" HurtHP: {hurtHp}\n"; |
| | | skillDetail += $" CurHP: {curHp}\n"; |
| | | skillDetail += $" SuckHP: {HurtEx.SuckHP}\n"; |
| | | skillDetail += $" AttackTypes: {HurtEx.AttackTypes}\n"; |
| | | } |
| | | } |
| | | |
| | | public SkillBase(BattleObject _caster, SkillConfig _skillCfg, HB427_tagSCUseSkill vNetData, List<GameNetPackBasic> _packList, BattleField _battleField = null) |
| | | { |
| | | caster = _caster; |
| | | skillConfig = _skillCfg; |
| | | tagUseSkillAttack = vNetData; |
| | | battleField = _battleField; |
| | | packList = _packList; |
| | | skillDetail += "------------------ END ------------------\n"; |
| | | |
| | | } |
| | | if (changeListDict.ContainsKey(caster.battleField.guid)) |
| | | { |
| | | string origin = changeListDict[caster.battleField.guid]; |
| | | origin += skillDetail; |
| | | changeListDict[caster.battleField.guid] = origin; |
| | | |
| | | } |
| | | else |
| | | changeListDict.Add(caster.battleField.guid, skillDetail); |
| | | |
| | | public virtual void Run() |
| | | { |
| | | if (startCounting) |
| | | { |
| | | curFrame++; |
| | | } |
| | | Debug.LogError("skillDetail : " + skillDetail); |
| | | #endif |
| | | } |
| | | |
| | | if (null != skillEffect) |
| | | { |
| | | skillEffect.Run(); |
| | | } |
| | | private void SafetyCheck() |
| | | { |
| | | #if UNITY_EDITOR |
| | | if (Launch.Instance.isOpenSkillLogFile) |
| | | { |
| | | PinrtHB427Hp(); |
| | | } |
| | | #endif |
| | | |
| | | if (otherSkillAction != null) |
| | | { |
| | | if (otherSkillAction.IsFinished()) |
| | | { |
| | | otherSkillAction = null; |
| | | OnSkillFinished(); |
| | | } |
| | | else |
| | | { |
| | | otherSkillAction.Run(); |
| | | } |
| | | } |
| | | } |
| | | bool safety = caster != null |
| | | && skillConfig != null |
| | | && tagUseSkillAttack != null |
| | | && battleField != null; |
| | | |
| | | |
| | | if (!safety) |
| | | { |
| | | Debug.LogError("SkillBase SafetyCheck failed! Caster or SkillConfig or TagUseSkillAttack or BattleField is null, or Caster is dead."); |
| | | ForceFinished(); |
| | | } |
| | | |
| | | |
| | | } |
| | | |
| | | public void Pause() |
| | | { |
| | | pauseState = startCounting; |
| | | startCounting = false; |
| | | } |
| | | // 技能运行主逻辑:处理技能效果和其他技能动作 |
| | | public virtual void Run() |
| | | { |
| | | if (skillEffect != null) |
| | | { |
| | | if (skillEffect.IsFinished()) |
| | | { |
| | | skillEffect = null; |
| | | OnSkillFinished(); |
| | | } |
| | | else |
| | | { |
| | | skillEffect.Run(); |
| | | } |
| | | return; |
| | | } |
| | | |
| | | public void Resume() |
| | | { |
| | | startCounting = pauseState; |
| | | } |
| | | 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) |
| | | { |
| | | if (create) |
| | | { |
| | | Color color = Color.white; |
| | | //1-连击;2-反击;3-追击 |
| | | // 反击蓝色 |
| | | // 追击连击绿色 |
| | | bool change = false; |
| | | if (tagUseSkillAttack.BattleType == 1) |
| | | { |
| | | color = colorGreen; |
| | | change = true; |
| | | } |
| | | else if (tagUseSkillAttack.BattleType == 2) |
| | | { |
| | | color = colorBlue; |
| | | change = true; |
| | | } |
| | | else if (tagUseSkillAttack.BattleType == 3) |
| | | { |
| | | color = colorGreen; |
| | | change = true; |
| | | } |
| | | |
| | | if (change) |
| | | { |
| | | MoveSpeed = 1125f; |
| | | caster.motionBase.ShowIllusionShadow(true, color); |
| | | } |
| | | } |
| | | else |
| | | { |
| | | MoveSpeed = 750f; |
| | | caster.motionBase.ShowIllusionShadow(false); |
| | | } |
| | | } |
| | | |
| | | // 0·移动到距离目标n码,的距离释放(可配置,9999即原地释放,负数则是移动到人物背面,人物要转身) |
| | | // 1·移动到距离阵容位置n码的距离(如2号位,5号位)释放(即战场中央此类) |
| | | public virtual void Cast() |
| | | { |
| | | EventBroadcast.Instance.Broadcast<string, SkillConfig, TeamHero>(EventName.BATTLE_CAST_SKILL, battleField.guid, skillConfig, caster.teamHero); |
| | | // 技能释放主逻辑:广播事件、高亮目标、执行释放 |
| | | public virtual void Cast() |
| | | { |
| | | // 广播技能释放事件 |
| | | string guid = battleField.guid; |
| | | TeamHero teamHero = caster.teamHero; |
| | | EventBroadcast.Instance.Broadcast<string, SkillConfig, TeamHero>(EventName.BATTLE_CAST_SKILL, guid, skillConfig, teamHero); |
| | | |
| | | BattleDebug.LogError(GetType().Name + " Skill Cast Start"); |
| | | // 高亮所有本次技能相关的目标 |
| | | HighLightAllTargets(); |
| | | if (skillConfig.SkinllSFX1 != 0) |
| | | { |
| | | battleField.soundManager.PlayEffectSound(skillConfig.SkinllSFX1, false); |
| | | } |
| | | |
| | | // 距离配成负数要转身 TurnBack |
| | | BattleDebug.LogError(GetType().Name + " Skill CastMode : " + skillConfig.castMode); |
| | | switch (skillConfig.castMode) |
| | | { |
| | | case SkillCastMode.Self: |
| | | CastImpl(); |
| | | break; |
| | | case SkillCastMode.Enemy: |
| | | CastToEnemy(); |
| | | break; |
| | | case SkillCastMode.Target: |
| | | CastToTarget(); |
| | | break; |
| | | case SkillCastMode.Allies: |
| | | CastToAllies(); |
| | | break; |
| | | // case SkillCastMode.DashCast: |
| | | // DashToTarget(() => BackToOrigin(OnSkillFinished)); |
| | | // break; |
| | | default: |
| | | BattleDebug.LogError("暂时不支持其他的方式释放 有需求请联系策划 技能id:" + skillConfig.SkillID + " cast position " + skillConfig.CastPosition); |
| | | OnSkillFinished(); |
| | | break; |
| | | } |
| | | } |
| | | if (caster != null) |
| | | { |
| | | // 战斗类型 0-常规;1-连击;2-反击;3-追击;4-子技能;5-被动触发的 |
| | | DamageNumConfig hintConfig = null; |
| | | if (tagUseSkillAttack.BattleType == 1) |
| | | { |
| | | hintConfig = DamageNumConfig.Get(BattleConst.BattleComboAttack); |
| | | } |
| | | else if (tagUseSkillAttack.BattleType == 2) |
| | | { |
| | | hintConfig = DamageNumConfig.Get(BattleConst.BattleCounterAttack); |
| | | } |
| | | else if (tagUseSkillAttack.BattleType == 3) |
| | | { |
| | | hintConfig = DamageNumConfig.Get(BattleConst.BattleChaseAttack); |
| | | } |
| | | |
| | | Hint(caster, hintConfig); |
| | | |
| | | protected void MoveToTarget(RectTransform target, Vector2 offset, float duration, Action onComplete = null) |
| | | { |
| | | BattleDebug.LogError("Move to target , target is " + target.name); |
| | | // 原地释放 |
| | | if (skillConfig.CastDistance >= 9999) |
| | | { |
| | | onComplete?.Invoke(); |
| | | return; |
| | | } |
| | | |
| | | caster.motionBase.PlayAnimation(MotionName.run, true); |
| | | var tweener = BattleUtility.MoveToTarget(caster.heroRectTrans, target, offset, duration, () => |
| | | { |
| | | caster.motionBase.PlayAnimation(MotionName.idle, true); |
| | | onComplete?.Invoke(); |
| | | }); |
| | | battleField.battleTweenMgr.OnPlayTween(tweener); |
| | | } |
| | | } |
| | | |
| | | protected void TurnBack(Action _onComplete, float forward) |
| | | { |
| | | if (skillConfig.CastDistance < 0) |
| | | { |
| | | // 转身 |
| | | Vector3 scale = caster.heroGo.transform.localScale; |
| | | scale.x = Mathf.Abs(scale.x) * forward; |
| | | caster.heroGo.transform.localScale = scale; |
| | | } |
| | | _onComplete?.Invoke(); |
| | | } |
| | | // 高亮所有本次技能相关的目标 |
| | | HighLightAllTargets(); |
| | | |
| | | // 根据释放模式执行相应逻辑 |
| | | switch (skillConfig.castMode) |
| | | { |
| | | case SkillCastMode.None: |
| | | case SkillCastMode.Self: |
| | | CastImpl(OnAttackFinish); |
| | | break; |
| | | case SkillCastMode.Enemy: |
| | | CastToEnemy(); |
| | | break; |
| | | case SkillCastMode.Target: |
| | | CastToTarget(); |
| | | break; |
| | | case SkillCastMode.Allies: |
| | | CastToAllies(); |
| | | break; |
| | | case SkillCastMode.DashCast: |
| | | DashCast(OnAttackFinish); |
| | | break; |
| | | default: |
| | | Debug.LogError("强制结束技能 暂时不支持其他的方式释放 有需求please联系策划 技能id:" + skillConfig.SkillID + " cast position " + skillConfig.CastPosition); |
| | | ForceFinished(); |
| | | break; |
| | | } |
| | | } |
| | | |
| | | protected void Hint(BattleObject battleObject, DamageNumConfig hintConfig) |
| | | { |
| | | if (hintConfig != null) |
| | | { |
| | | battleObject.heroInfoBar.ShowTips(((char)hintConfig.prefix).ToString(), true, false, 1.25f); |
| | | } |
| | | } |
| | | |
| | | // 冲撞攻击模式(待实现) |
| | | protected void DashCast(Action _onComplete) |
| | | { |
| | | Debug.LogError("DashCast 还没实现"); |
| | | ForceFinished(); |
| | | } |
| | | |
| | | // 对敌方释放技能:移动到敌方区域进行攻击 |
| | | protected void CastToEnemy() |
| | | { |
| | | RectTransform target = battleField.GetTeamNode(caster.GetEnemyCamp(), skillConfig); |
| | | ExecuteMoveAndCastSequence(target, () => |
| | | { |
| | | if (skillConfig.ClientTriggerTiming == 1) |
| | | { |
| | | OnAttackFinish(); |
| | | } |
| | | else |
| | | { |
| | | // ShadowIllutionCreate(true); |
| | | MoveToTarget(battleField.GetTeamNode(caster.Camp, caster.teamHero.positionNum), Vector2.zero, () => |
| | | { |
| | | // ShadowIllutionCreate(false); |
| | | OnAttackFinish(); |
| | | }, MoveSpeed); |
| | | } |
| | | }); |
| | | } |
| | | |
| | | // 对指定目标释放技能:移动到主要目标位置进行攻击 |
| | | protected void CastToTarget() |
| | | { |
| | | if (tagUseSkillAttack.HurtCount <= 0) |
| | | { |
| | | Debug.LogError("技能攻击包没有目标 HurtCount <= 0"); |
| | | OnSkillFinished(); |
| | | return; |
| | | } |
| | | |
| | | int mainTargetPosNum = BattleUtility.GetMainTargetPositionNum(this, caster, tagUseSkillAttack.HurtList.ToList(), skillConfig); |
| | | BattleCamp battleCamp = skillConfig.TagFriendly != 0 ? caster.Camp : caster.GetEnemyCamp(); |
| | | RectTransform targetTrans = battleField.GetTeamNode(battleCamp, mainTargetPosNum); |
| | | |
| | | ExecuteMoveAndCastSequence(targetTrans, () => |
| | | { |
| | | RectTransform rectTransform = battleField.GetTeamNode(caster.Camp, caster.teamHero.positionNum); |
| | | // ShadowIllutionCreate(true); |
| | | MoveToTarget(rectTransform, Vector2.zero, () => |
| | | { |
| | | // ShadowIllutionCreate(false); |
| | | OnAttackFinish(); |
| | | }, MoveSpeed); |
| | | }); |
| | | } |
| | | |
| | | // 对友方释放技能:移动到友方区域进行治疗或增益 |
| | | protected void CastToAllies() |
| | | { |
| | | RectTransform target = battleField.GetTeamNode(caster.Camp, skillConfig); |
| | | ExecuteMoveAndCastSequence(target, () => |
| | | { |
| | | if (skillConfig.ClientTriggerTiming == 1) |
| | | { |
| | | OnAttackFinish(); |
| | | } |
| | | else |
| | | { |
| | | // ShadowIllutionCreate(true); |
| | | MoveToTarget(battleField.GetTeamNode(caster.Camp, caster.teamHero.positionNum), Vector2.zero, () => |
| | | { |
| | | // ShadowIllutionCreate(false); |
| | | OnAttackFinish(); |
| | | }, MoveSpeed); |
| | | } |
| | | }); |
| | | } |
| | | |
| | | // 执行移动-施法-返回序列:通用的移动攻击流程 |
| | | private void ExecuteMoveAndCastSequence(RectTransform target, Action onReturnComplete) |
| | | { |
| | | ShadowIllutionCreate(true); |
| | | MoveToTarget(target, new Vector2(skillConfig.CastDistance, 0), () => |
| | | { |
| | | if (skillConfig.CastDistance < 9999 && skillConfig.SkinllSFX2 != 0) |
| | | { |
| | | battleField.soundManager.PlayEffectSound(skillConfig.SkinllSFX2, false); |
| | | } |
| | | |
| | | TurnBack(() => |
| | | { |
| | | ShadowIllutionCreate(false); |
| | | |
| | | CastImpl(() => |
| | | { |
| | | TurnBack(() => |
| | | { |
| | | try |
| | | { |
| | | onReturnComplete?.Invoke(); // 添加异常处理防止回调异常导致状态不完整 |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | Debug.LogError($"ExecuteMoveAndCastSequence回调异常: {ex.Message}"); |
| | | throw; |
| | | } |
| | | }, -1f); |
| | | }); |
| | | }, -1f); |
| | | }); |
| | | } |
| | | |
| | | // 移动到目标位置:处理角色的移动动画和逻辑 |
| | | protected void MoveToTarget(RectTransform target, Vector2 offset, Action _onComplete = null, float speed = 750f) |
| | | { |
| | | if (skillConfig.CastDistance >= 9999) |
| | | { |
| | | _onComplete?.Invoke(); |
| | | return; |
| | | } |
| | | |
| | | caster.motionBase.PlayAnimation(MotionName.run, true); |
| | | var tweener = BattleUtility.MoveToTarget(caster.heroRectTrans, target, offset, () => |
| | | { |
| | | caster.motionBase.PlayAnimation(MotionName.idle, true); |
| | | _onComplete?.Invoke(); |
| | | }, speed); |
| | | battleField.battleTweenMgr.OnPlayTween(tweener); |
| | | } |
| | | |
| | | // 转身逻辑:根据技能配置处理角色转向 |
| | | protected void TurnBack(Action _onComplete, float forward) |
| | | { |
| | | if (skillConfig.CastDistance < 0) |
| | | { |
| | | Vector3 scale = caster.heroGo.transform.localScale; |
| | | scale.x = Mathf.Abs(scale.x) * forward; |
| | | caster.heroGo.transform.localScale = scale; |
| | | } |
| | | _onComplete?.Invoke(); |
| | | } |
| | | |
| | | // 攻击完成后的处理:转身、恢复状态、播放待机动画 |
| | | protected void OnAttackFinish() |
| | | { |
| | | TurnBack(null, 1f); |
| | | OnAllAttackMoveFinished(); |
| | | caster.motionBase.PlayAnimation(MotionName.idle, true); |
| | | } |
| | | |
| | | // 所有攻击移动完成后的处理:恢复UI显示状态 |
| | | protected virtual void OnAllAttackMoveFinished() |
| | | { |
| | | moveFinished = true; |
| | | List<BattleObject> allList = battleField.battleObjMgr.allBattleObjDict.Values.ToList<BattleObject>(); |
| | | foreach (BattleObject bo in allList) |
| | | { |
| | | bo.layerMgr.SetFront(); |
| | | bo.heroInfoBar.SetActive(true); |
| | | } |
| | | battleField.battleRootNode.skillMaskNode.SetActive(false); |
| | | } |
| | | |
| | | // 执行技能释放动画和逻辑:播放施法动作并提供回调 |
| | | protected TrackEntry CastImpl(Action onComplete = null) |
| | | { |
| | | return caster.motionBase.PlaySkillAnimation(skillConfig, this, tagUseSkillAttack.BattleType == 4, onComplete); |
| | | } |
| | | |
| | | // 技能开始回调:处理死亡、子技能、技能效果初始化 |
| | | public void OnSkillStart() |
| | | { |
| | | if (isPlay) |
| | | { |
| | | Debug.LogError(" play twice OnSkillStart skillId :" + skillConfig.SkillID); |
| | | return; |
| | | } |
| | | |
| | | HandleDead(); |
| | | |
| | | skillEffect = SkillEffectFactory.CreateSkillEffect(this, caster, skillConfig, tagUseSkillAttack); |
| | | skillEffect.Play(OnHitTargets); |
| | | ProcessSubSkill(); |
| | | |
| | | 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 }); |
| | | 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); |
| | | if (recordAction != null) |
| | | { |
| | | recordAction.fromSkill = this; |
| | | ulong packUID = subCombinePack.packList.Count > 0 ? GetPackUID(subCombinePack.packList[0]) : 0; |
| | | allSubSkills.Add((packUID, recordAction)); |
| | | } |
| | | } |
| | | tagUseSkillAttack.subSkillCombinePackList.Clear(); |
| | | |
| | | // 按packUID排序 |
| | | allSubSkills.Sort((a, b) => a.packUID.CompareTo(b.packUID)); |
| | | |
| | | // 依次添加到recordPlayer,每个等待前一个完成 |
| | | RecordAction waitingRecordAction = null; |
| | | foreach (var (packUID, recordAction) in allSubSkills) |
| | | { |
| | | // 【使用 BattleField.recordPlayer】 |
| | | // 原因:子技能是独立的SkillRecordAction,应该是顶层RecordAction,由BattleField的主RecordPlayer管理 |
| | | // 通过设置父子关系和WaitingPlay,可以控制子技能的执行时机 |
| | | if (waitingRecordAction != null) |
| | | { |
| | | // 每个都应该等前一个结束后 |
| | | battleField.recordPlayer.ImmediatelyPlay(recordAction, waitingRecordAction, true); |
| | | } |
| | | else |
| | | { |
| | | battleField.recordPlayer.ImmediatelyPlay(recordAction, parentRecordAction, true); |
| | | } |
| | | |
| | | if (recordAction.IsNeedWaiting()) |
| | | { |
| | | waitingRecordAction = recordAction; |
| | | } |
| | | } |
| | | } |
| | | |
| | | // 技能前摇结束回调 |
| | | public virtual void OnStartSkillFrameEnd() { } |
| | | |
| | | // 技能中摇开始回调:通知技能效果处理中摇开始 |
| | | public virtual void OnMiddleFrameStart(int times) |
| | | { |
| | | skillEffect.OnMiddleFrameStart(times); // 修复:添加空值检查 |
| | | } |
| | | |
| | | // 技能中摇结束回调:通知技能效果处理中摇结束 |
| | | public virtual void OnMiddleFrameEnd(int times, int hitIndex) |
| | | { |
| | | skillEffect.OnMiddleFrameEnd(times, hitIndex); // 修复:添加空值检查 |
| | | } |
| | | |
| | | // 技能后摇开始回调:通知技能效果处理后摇开始 |
| | | public virtual void OnFinalFrameStart() |
| | | { |
| | | skillEffect.OnFinalFrameStart(); // 修复:添加空值检查 |
| | | } |
| | | |
| | | // 技能后摇结束回调:通知技能效果处理后摇结束 |
| | | public virtual void OnFinalFrameEnd() |
| | | { |
| | | // 标记动画播放完成 |
| | | isMotionCompleted = true; |
| | | BattleDebug.LogError($"SkillBase.OnFinalFrameEnd: 技能 {skillConfig?.SkillID} 动画播放完成"); |
| | | |
| | | skillEffect?.OnFinalFrameEnd(); // 修复:添加空值检查 |
| | | } |
| | | |
| | | // 高亮所有相关目标:设置施法者和目标的显示层级 |
| | | protected void HighLightAllTargets() |
| | | { |
| | | caster.layerMgr.SetSortingOrder(BattleConst.SkillMaskOrder + BattleConst.BattleActiveHeroOffset); |
| | | |
| | | if (skillConfig.FuncType != 2) |
| | | return; |
| | | |
| | | // 收集所有目标(包含 HurtList、每个 Hurt 的 HurtListEx、以及顶层 HurtListEx) |
| | | var targetSet = new HashSet<BattleObject>(); |
| | | if (tagUseSkillAttack != null) |
| | | { |
| | | // 主目标列表 |
| | | if (tagUseSkillAttack.HurtList != null) |
| | | { |
| | | foreach (var hurt in tagUseSkillAttack.HurtList) |
| | | { |
| | | var bo = battleField.battleObjMgr.GetBattleObject((int)hurt.ObjID); |
| | | if (bo != null) targetSet.Add(bo); |
| | | |
| | | // 主目标的额外目标(弹射/平摊) |
| | | if (hurt.HurtListEx != null) |
| | | { |
| | | foreach (var hurtEx in hurt.HurtListEx) |
| | | { |
| | | var exBo = battleField.battleObjMgr.GetBattleObject((int)hurtEx.ObjID); |
| | | if (exBo != null) targetSet.Add(exBo); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | // 技能包顶层的 HurtListEx(如溅射、顶层平摊) |
| | | if (tagUseSkillAttack.HurtListEx != null) |
| | | { |
| | | foreach (var hurtEx in tagUseSkillAttack.HurtListEx) |
| | | { |
| | | var exBo = battleField.battleObjMgr.GetBattleObject((int)hurtEx.ObjID); |
| | | if (exBo != null) targetSet.Add(exBo); |
| | | } |
| | | } |
| | | } |
| | | |
| | | // 确保施法者也被高亮(原逻辑) |
| | | var highlightList = new List<BattleObject>(targetSet) { caster }; |
| | | |
| | | var allList = battleField.battleObjMgr.allBattleObjDict.Values.ToList(); |
| | | |
| | | // 构造集合便于判断 |
| | | var targetSetLookup = new HashSet<BattleObject>(targetSet); |
| | | var highlightSet = new HashSet<BattleObject>(highlightList); |
| | | |
| | | // 先把施法者的 InfoBar 隐藏(原逻辑保留) |
| | | caster.heroInfoBar.SetActive(false); |
| | | |
| | | foreach (BattleObject bo in allList) |
| | | { |
| | | bool isHighlight = highlightSet.Contains(bo); |
| | | bool isTarget = targetSetLookup.Contains(bo); |
| | | |
| | | if (isHighlight) |
| | | { |
| | | bo.layerMgr.SetFront(); |
| | | } |
| | | else |
| | | { |
| | | bo.layerMgr.SetBack(); |
| | | } |
| | | |
| | | // 目标(含 HurtListEx)都应显示 InfoBar |
| | | bo.heroInfoBar.SetActive(isTarget); |
| | | } |
| | | |
| | | battleField.battleRootNode.skillMaskNode.SetActive(true); |
| | | } |
| | | |
| | | |
| | | // 命中目标回调:处理所有被命中的目标(包括主目标、弹射目标、溅射目标) |
| | | protected virtual void OnHitTargets(int _hitIndex, List<HB427_tagSCUseSkill.tagSCUseSkillHurt> hitList) |
| | | { |
| | | // Debug.LogError($"Skill {skillConfig.SkillID} hit targets _hitIndex: {_hitIndex} hit {string.Join(", ", hitList.Select(h => h.ObjID + ":" + battleField.battleObjMgr.GetBattleObject((int)h.ObjID)?.teamHero.name))}"); |
| | | |
| | | // 造成伤害前先处理血量刷新包 |
| | | HandleRefreshHP(); |
| | | |
| | | bool suckHp = true; |
| | | |
| | | // 处理主目标列表 |
| | | foreach (var hurt in hitList) |
| | | { |
| | | BattleObject target = caster.battleField.battleObjMgr.GetBattleObject((int)hurt.ObjID); |
| | | if (target == null) |
| | | { |
| | | Debug.LogError("目标为空 target == null ObjId : " + hurt.ObjID); |
| | | continue; |
| | | } |
| | | |
| | | OnHitEachTarget(_hitIndex, target, hurt, suckHp); |
| | | |
| | | suckHp = false; |
| | | |
| | | // 处理该目标的额外目标列表(如弹射伤害的平摊目标) |
| | | if (hurt.HurtListEx != null && hurt.HurtListEx.Length > 0) |
| | | { |
| | | foreach (var hurtEx in hurt.HurtListEx) |
| | | { |
| | | BattleObject exTarget = caster.battleField.battleObjMgr.GetBattleObject((int)hurtEx.ObjID); |
| | | if (exTarget == null) |
| | | { |
| | | Debug.LogError($"额外目标为空 HurtListEx target == null ObjId : {hurtEx.ObjID}"); |
| | | continue; |
| | | } |
| | | |
| | | OnHitEachTargetEx(_hitIndex, exTarget, hurtEx); |
| | | } |
| | | } |
| | | } |
| | | |
| | | // 处理技能包顶层的额外目标列表(如溅射伤害、平摊伤害) |
| | | if (tagUseSkillAttack.HurtListEx != null && tagUseSkillAttack.HurtListEx.Length > 0) |
| | | { |
| | | foreach (var hurtEx in tagUseSkillAttack.HurtListEx) |
| | | { |
| | | BattleObject exTarget = caster.battleField.battleObjMgr.GetBattleObject((int)hurtEx.ObjID); |
| | | if (exTarget == null) |
| | | { |
| | | Debug.LogError($"顶层额外目标为空 tagUseSkillAttack.HurtListEx target == null ObjId : {hurtEx.ObjID}"); |
| | | continue; |
| | | } |
| | | |
| | | OnHitEachTargetEx(_hitIndex, exTarget, hurtEx); |
| | | } |
| | | } |
| | | |
| | | HandleHint(_hitIndex, hitList); |
| | | } |
| | | |
| | | protected void HandleHint(int _hitIndex, List<HB427_tagSCUseSkill.tagSCUseSkillHurt> hitList) |
| | | { |
| | | if (0 == _hitIndex) |
| | | { |
| | | bool needhint = false; |
| | | |
| | | for (int i = 0; i < hitList.Count; i++) |
| | | { |
| | | var hurt = hitList[i]; |
| | | |
| | | //8-击晕 |
| | | if ((hurt.AttackTypes & (int)DamageType.Stunned) == (int)DamageType.Stunned) |
| | | { |
| | | needhint = true; |
| | | break; |
| | | } |
| | | |
| | | for (int j = 0; j < hurt.HurtListEx?.Length; j++) |
| | | { |
| | | var hurtex = hurt.HurtListEx[j]; |
| | | //8-击晕 |
| | | if ((hurtex.AttackTypes & (int)ServerDamageType.Stunned) == (int)ServerDamageType.Stunned) |
| | | { |
| | | needhint = true; |
| | | break; |
| | | } |
| | | } |
| | | |
| | | if (needhint) |
| | | break; |
| | | } |
| | | |
| | | if (needhint) |
| | | { |
| | | 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); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | // 处理单个目标被命中:应用伤害和施法者效果 |
| | | protected virtual void OnHitEachTarget(int _hitIndex, BattleObject target, HB427_tagSCUseSkill.tagSCUseSkillHurt hurt, bool suckHp) |
| | | { |
| | | // ============ 获取临时数据(掉落、死亡等) ============ |
| | | int objID = (int)target.ObjID; |
| | | tempDropList.TryGetValue(objID, out BattleDrops battleDrops); |
| | | tempDeadPackList.TryGetValue(objID, out BattleDeadPack deadPack); |
| | | |
| | | // 如果目标正在释放技能,跳过死亡处理(延迟到技能结束) |
| | | if (battleField != null && battleField.IsCastingSkill(target.ObjID)) |
| | | { |
| | | deadPack = null; |
| | | } |
| | | |
| | | // ============ 参数打包 ============ |
| | | BattleHurtParam hurtParam = BattleUtility.CalcBattleHurtParam(this, _hitIndex, target, hurt, battleDrops, deadPack, suckHp); |
| | | #if UNITY_EDITOR |
| | | PrintHurtParamDebugInfo(hurtParam); |
| | | #endif |
| | | |
| | | // 先调用目标受伤 |
| | | target.Hurt(hurtParam, parentRecordAction); |
| | | |
| | | // 再调用施法者吸血/反伤 |
| | | caster.OnHurtTarget(hurtParam); |
| | | } |
| | | |
| | | // 处理额外目标被命中(HurtListEx):溅射、弹射、平摊伤害等 |
| | | protected virtual void OnHitEachTargetEx(int _hitIndex, BattleObject target, HB427_tagSCUseSkill.tagSCUseSkillHurtEx hurtEx) |
| | | { |
| | | // ============ 获取临时数据(掉落、死亡等) ============ |
| | | int objID = (int)target.ObjID; |
| | | tempDropList.TryGetValue(objID, out BattleDrops battleDrops); |
| | | |
| | | tempDeadPackList.TryGetValue(objID, out BattleDeadPack deadPack); |
| | | |
| | | // 如果目标正在释放技能,跳过死亡处理(延迟到技能结束) |
| | | if (battleField != null && battleField.IsCastingSkill(target.ObjID)) |
| | | { |
| | | deadPack = null; |
| | | } |
| | | // ============ 参数打包(将 tagSCUseSkillHurtEx 转换为 tagSCUseSkillHurt)============ |
| | | HB427_tagSCUseSkill.tagSCUseSkillHurt hurt = new HB427_tagSCUseSkill.tagSCUseSkillHurt |
| | | { |
| | | ObjID = hurtEx.ObjID, |
| | | AttackTypes = hurtEx.AttackTypes, |
| | | HurtHP = hurtEx.HurtHP, |
| | | HurtHPEx = hurtEx.HurtHPEx, |
| | | CurHP = hurtEx.CurHP, |
| | | CurHPEx = hurtEx.CurHPEx, |
| | | SuckHP = 0,//hurtEx.SuckHP, 获取全部吸血时已经计算过 这里就不再计算 |
| | | BounceHP = 0, // HurtEx 没有反伤字段 |
| | | HurtCountEx = 0, |
| | | HurtListEx = null |
| | | }; |
| | | |
| | | OnHitEachTarget(_hitIndex, target, hurt, false);//获取全部吸血时已经计算过 这里就不再计算 |
| | | } |
| | | |
| | | #if UNITY_EDITOR |
| | | private void PrintHurtParamDebugInfo(BattleHurtParam hurtParam) |
| | | { |
| | | bool isLastHit = hurtParam.hitIndex >= hurtParam.skillConfig.DamageDivide.Length - 1; |
| | | |
| | | long currentHitDamage = hurtParam.hurter.damageList != null ? hurtParam.hurter.damageList.Sum() : 0; |
| | | long currentHitSuckHp = hurtParam.caster.suckHpList != null ? hurtParam.caster.suckHpList.Sum() : 0; |
| | | long currentHitReflectHp = hurtParam.caster.reflectHpList != null ? hurtParam.caster.reflectHpList.Sum() : 0; |
| | | |
| | | long totalDamage = GeneralDefine.GetFactValue(hurtParam.hurt.HurtHP, hurtParam.hurt.HurtHPEx); |
| | | long totalSuckHp = BattleUtility.GetSuckHp(tagUseSkillAttack); |
| | | long totalReflectHp = hurtParam.hurt.BounceHP; |
| | | |
| | | BattleDebug.LogError( |
| | | (hurtParam.caster.casterObj.Camp == BattleCamp.Red ? "【红方行动】" : "【蓝方行动】 ") + |
| | | $"攻击者: {hurtParam.caster.casterObj.teamHero.name} (ObjID:{hurtParam.caster.casterObj.ObjID})\n" + |
| | | $"目标: {hurtParam.hurter.hurtObj.teamHero.name} (ObjID:{hurtParam.hurter.hurtObj.ObjID})\n" + |
| | | $"技能: {hurtParam.skillConfig.SkillName} (ID:{hurtParam.skillConfig.SkillID})\n" + |
| | | $"击数: 第{hurtParam.hitIndex + 1}击 / 共{hurtParam.skillConfig.DamageDivide.Length}击" + (isLastHit ? " [最后一击]" : " [中间击]") + "\n" + |
| | | $"\n" + |
| | | $"========== 目标受伤数据 ==========\n" + |
| | | $"伤害: {currentHitDamage} / 总伤害: {totalDamage}\n" + |
| | | $"伤害分段: [{string.Join(", ", hurtParam.hurter.damageList ?? new List<long>())}]\n" + |
| | | $"目标血量: {hurtParam.hurter.fromHp} -> {hurtParam.hurter.toHp} (最大:{hurtParam.hurter.maxHp})\n" + |
| | | $"目标护盾: {hurtParam.hurter.fromShieldValue} -> {hurtParam.hurter.toShieldValue}\n" + |
| | | $"攻击类型: {hurtParam.hurt.AttackTypes}\n" + |
| | | $"\n" + |
| | | $"========== 施法者数据 ==========\n" + |
| | | $"吸血: {currentHitSuckHp} / 总吸血: {totalSuckHp}\n" + |
| | | $"吸血分段: [{string.Join(", ", hurtParam.caster.suckHpList ?? new List<long>())}]\n" + |
| | | $"反伤: {currentHitReflectHp} / 总反伤: {totalReflectHp}\n" + |
| | | $"反伤分段: [{string.Join(", ", hurtParam.caster.reflectHpList ?? new List<long>())}]\n" + |
| | | $"施法者血量: {hurtParam.caster.fromHp} -> {hurtParam.caster.toHp} (最大:{hurtParam.caster.maxHp})\n" + |
| | | $"施法者护盾: {hurtParam.caster.fromShieldValue} -> {hurtParam.caster.toShieldValue}\n" |
| | | ); |
| | | } |
| | | #endif |
| | | |
| | | // 处理HP刷新包(简化逻辑) |
| | | private void HandleRefreshHP() |
| | | { |
| | | // 查找HP刷新包 |
| | | HB419_tagSCObjHPRefresh refreshPack = BattleUtility.FindObjHPRefreshPack(packList); |
| | | |
| | | if (refreshPack != null) |
| | | { |
| | | // 分发HP刷新包 |
| | | // 【使用 parentRecordAction.innerRecordPlayer】 |
| | | // 原因:HP刷新包是技能内部产生的,应该由当前SkillRecordAction的innerRecordPlayer管理 |
| | | // 这样可以确保HP刷新与技能的生命周期绑定,ForceFinish时一并处理 |
| | | PackageRegeditEx.DistributeToRecordAction(refreshPack, parentRecordAction); |
| | | packList.Remove(refreshPack); |
| | | } |
| | | } |
| | | |
| | | // 处理死亡相关逻辑:分配掉落和经验 |
| | | protected void HandleDead() |
| | | { |
| | | 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); |
| | | } |
| | | } |
| | | } |
| | | |
| | | protected void CastToEnemy() |
| | | { |
| | | CheckAfterDeadhPack(); |
| | | |
| | | RectTransform target = battleField.GetTeamNode(caster.GetEnemyCamp(), skillConfig); |
| | | // 修复:先收集要删除的包,避免在foreach中修改集合 |
| | | var dropPacksToRemove = new List<H0704_tagRolePackRefresh>(dropPackList); |
| | | foreach (var _dropPack in dropPacksToRemove) |
| | | { |
| | | // 【使用 parentRecordAction.innerRecordPlayer】 |
| | | // 原因:掉落包是技能效果的一部分,应该由当前SkillRecordAction管理 |
| | | // 掉落包的分发与技能完成绑定,确保在技能ForceFinish时正确处理 |
| | | PackageRegeditEx.DistributeToRecordAction(_dropPack, parentRecordAction); |
| | | packList.Remove(_dropPack); |
| | | } |
| | | |
| | | MoveToTarget(target, new Vector2(skillConfig.CastDistance, 0), moveTime, () => |
| | | { |
| | | // 到位置转身(不一定非要转身 但是流程要写) |
| | | TurnBack(() => |
| | | { |
| | | // 到达目标位置 |
| | | CastImpl(() => |
| | | { |
| | | TurnBack( |
| | | () => |
| | | { |
| | | // 回到原来的位置 |
| | | MoveToTarget(battleField.GetTeamNode(caster.Camp, caster.teamHero.positionNum), Vector2.zero, moveTime, () => |
| | | { |
| | | TurnBack(null, 1f); |
| | | caster.motionBase.PlayAnimation(MotionName.idle, true); |
| | | OnAllAttackMoveFinished(); |
| | | }); |
| | | } |
| | | , -1f); |
| | | }); |
| | | }, -1f); |
| | | }); |
| | | } |
| | | // 获取并分配掉落物品和经验 |
| | | var dropPack = PackManager.Instance.GetSinglePack(PackType.DropItem); |
| | | var itemDict = dropPack.GetAllItems(); |
| | | List<ItemModel> itemList = new List<ItemModel>(itemDict.Values.Where(item => item != null && item.isAuction)); |
| | | |
| | | var dropAssign = AssignDrops(itemList, deadPackList.Count); |
| | | var expAssign = AssignExp(expPackList, deadPackList.Count); |
| | | |
| | | // 构造BattleDrops并缓存 |
| | | for (int i = 0; i < deadPackList.Count; i++) |
| | | { |
| | | BattleDeadPack battleDeadPack = deadPackList[i]; |
| | | int objID = (int)battleDeadPack.deadPack.ObjID; |
| | | BattleObject deadTarget = battleField.battleObjMgr.GetBattleObject(objID); |
| | | |
| | | // 修复:添加空值检查 |
| | | if (deadTarget == null) |
| | | { |
| | | Debug.LogError($"找不到死亡目标,ObjID: {objID}"); |
| | | continue; |
| | | } |
| | | |
| | | List<int> itemIndexList = dropAssign[i].Select(item => item.gridIndex).ToList(); |
| | | |
| | | BattleDrops battleDrops = new BattleDrops() |
| | | { |
| | | rectTransform = deadTarget.heroRectTrans, |
| | | dropItemPackIndex = itemIndexList, |
| | | expDrops = expAssign[i] |
| | | }; |
| | | |
| | | protected void CastToTarget() |
| | | { |
| | | // 目标是敌方主目标 |
| | | if (tagUseSkillAttack.HurtCount <= 0) |
| | | { |
| | | BattleDebug.LogError("技能攻击包没有目标 HurtCount <= 0"); |
| | | OnSkillFinished(); |
| | | return; |
| | | } |
| | | // 修复:避免字典键冲突,使用安全的添加方式 |
| | | if (!tempDropList.ContainsKey(objID)) |
| | | { |
| | | tempDropList.Add(objID, battleDrops); |
| | | } |
| | | else |
| | | { |
| | | Debug.LogWarning($"tempDropList中已存在ObjID={objID}的记录,将覆盖原值"); |
| | | tempDropList[objID] = battleDrops; // 覆盖现有值 |
| | | } |
| | | |
| | | var mainHurt = tagUseSkillAttack.HurtList[0]; |
| | | if (!tempDeadPackList.ContainsKey(objID)) |
| | | { |
| | | tempDeadPackList.Add(objID, deadPackList[i]); |
| | | } |
| | | else |
| | | { |
| | | Debug.LogWarning($"tempDeadPackList中已存在ObjID={objID}的记录,将覆盖原值"); |
| | | tempDeadPackList[objID] = deadPackList[i]; // 覆盖现有值 |
| | | } |
| | | } |
| | | |
| | | BattleObject mainTarget = battleField.battleObjMgr.GetBattleObject((int)mainHurt.ObjID); |
| | | if (mainTarget == null) |
| | | { |
| | | BattleDebug.LogError("目标为空 mainTarget == null ObjID : " + mainHurt.ObjID); |
| | | OnSkillFinished(); |
| | | return; |
| | | } |
| | | // 修复:避免在遍历时修改集合,先收集后删除 |
| | | var deadPacksToRemove = new List<GameNetPackBasic>(deadPackList.Select(d => d.deadPack)); |
| | | deadPacksToRemove.AddRange(deadPackList.Where(d => d.deadTriggerSkill != null).Select(d => d.deadTriggerSkill)); |
| | | foreach (var deadPack in deadPacksToRemove) |
| | | { |
| | | packList.Remove(deadPack); |
| | | } |
| | | } |
| | | |
| | | MoveToTarget(mainTarget.heroRectTrans, new Vector2(skillConfig.CastDistance, 0), moveTime, () => |
| | | { |
| | | // 到位置转身(不一定非要转身 但是流程要写) |
| | | TurnBack(() => |
| | | { |
| | | // 到达目标位置 |
| | | CastImpl(() => |
| | | { |
| | | TurnBack( |
| | | () => |
| | | { |
| | | // 回到原来的位置 |
| | | MoveToTarget(battleField.GetTeamNode(caster.Camp, caster.teamHero.positionNum), Vector2.zero, moveTime, () => |
| | | { |
| | | TurnBack(null, 1f); |
| | | caster.motionBase.PlayAnimation(MotionName.idle, true); |
| | | OnAllAttackMoveFinished(); |
| | | }); |
| | | } |
| | | , -1f); |
| | | }); |
| | | }, -1f); |
| | | }); |
| | | } |
| | | // 分配掉落物品:将掉落物品平均分配给死亡对象 |
| | | protected List<List<ItemModel>> AssignDrops(List<ItemModel> itemList, int deadCount) |
| | | { |
| | | var dropAssign = new List<List<ItemModel>>(); |
| | | for (int i = 0; i < deadCount; i++) |
| | | dropAssign.Add(new List<ItemModel>()); |
| | | for (int i = 0; i < itemList.Count; i++) |
| | | dropAssign[i % deadCount].Add(itemList[i]); |
| | | return dropAssign; |
| | | } |
| | | |
| | | protected virtual void OnAllAttackMoveFinished() |
| | | { |
| | | |
| | | } |
| | | // 获取包的 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; |
| | | } |
| | | |
| | | protected void CastToAllies() |
| | | { |
| | | RectTransform target = battleField.GetTeamNode(caster.Camp, skillConfig); |
| | | // 分配经验值:将经验包平均分配给每个死亡对象 |
| | | protected List<List<HB405_tagMCAddExp>> AssignExp(List<HB405_tagMCAddExp> expList, int deadCount) |
| | | { |
| | | var expAssign = new List<List<HB405_tagMCAddExp>>(); |
| | | for (int i = 0; i < deadCount; i++) |
| | | expAssign.Add(new List<HB405_tagMCAddExp>()); |
| | | |
| | | MoveToTarget(target, new Vector2(skillConfig.CastDistance, 0), moveTime, () => |
| | | { |
| | | // 到位置转身(不一定非要转身 但是流程要写) |
| | | TurnBack(() => |
| | | { |
| | | // 到达目标位置 |
| | | CastImpl(() => |
| | | { |
| | | TurnBack( |
| | | () => |
| | | { |
| | | // 回到原来的位置 |
| | | MoveToTarget(battleField.GetTeamNode(caster.Camp, caster.teamHero.positionNum), Vector2.zero, moveTime, () => |
| | | { |
| | | TurnBack(null, 1f); |
| | | caster.motionBase.PlayAnimation(MotionName.idle, true); |
| | | OnAllAttackMoveFinished(); |
| | | }); |
| | | } |
| | | , -1f); |
| | | }); |
| | | }, -1f); |
| | | }); |
| | | } |
| | | // 修复:检查除零风险 |
| | | if (deadCount == 0) |
| | | { |
| | | Debug.LogWarning("AssignExp: deadCount为0,无法分配经验"); |
| | | return expAssign; |
| | | } |
| | | |
| | | // 修复:先收集要删除的包,避免在foreach中修改packList |
| | | var expPacksToRemove = new List<HB405_tagMCAddExp>(); |
| | | |
| | | // 承载技能大部分的逻辑 |
| | | protected TrackEntry CastImpl(Action onComplete = null) |
| | | { |
| | | // 播放施法动作 |
| | | // onComplete是指施法动作播放完的回调 不代表是技能结束 |
| | | // 具体技能结束的时间应该看技能对应的逻辑 |
| | | // 这里只提供6个动作相关的函数 |
| | | // OnSkillStart 动作第一帧 |
| | | // OnStartSkillFrameEnd 前摇结束 |
| | | // OnMiddleFrameStart 中摇开始 |
| | | // OnMiddleFrameEnd 中摇结束 |
| | | // OnFinalFrameStart 后摇开始 |
| | | // OnFinalFrameEnd 后摇结束 |
| | | return caster.motionBase.PlaySkillAnimation(skillConfig, this, onComplete); |
| | | } |
| | | foreach (var expPack in expList) |
| | | { |
| | | long totalExp = GeneralDefine.GetFactValue(expPack.Exp, expPack.ExpPoint); |
| | | long avgExp = totalExp / deadCount; |
| | | long remain = totalExp % deadCount; |
| | | |
| | | // 技能开始 |
| | | public virtual void OnSkillStart() |
| | | { |
| | | skillEffect = SkillEffectFactory.CreateSkillEffect( |
| | | caster, |
| | | skillConfig, |
| | | tagUseSkillAttack |
| | | ); |
| | | if (skillEffect != null) |
| | | { |
| | | skillEffect.Play(OnHitTargets); |
| | | } |
| | | } |
| | | for (int i = 0; i < deadCount; i++) |
| | | { |
| | | long assignExp = avgExp + (i < remain ? 1 : 0); |
| | | var newPack = new HB405_tagMCAddExp |
| | | { |
| | | Exp = (uint)(assignExp % Constants.ExpPointValue), |
| | | ExpPoint = (uint)(assignExp / Constants.ExpPointValue), |
| | | Source = expPack.Source |
| | | }; |
| | | expAssign[i].Add(newPack); |
| | | } |
| | | expPacksToRemove.Add(expPack); |
| | | } |
| | | |
| | | // 统一删除收集的包 |
| | | foreach (var pack in expPacksToRemove) |
| | | { |
| | | packList.Remove(pack); |
| | | } |
| | | |
| | | // 技能前摇帧结束 |
| | | public virtual void OnStartSkillFrameEnd() |
| | | { |
| | | return expAssign; |
| | | } |
| | | |
| | | } |
| | | // 检查死亡后的包处理:处理技能包、掉落包、经验包 |
| | | protected void CheckAfterDeadhPack() |
| | | { |
| | | List<int> removeIndexList = new List<int>(); |
| | | |
| | | for (int i = 0; i < packList.Count; i++) |
| | | { |
| | | var pack = packList[i]; |
| | | |
| | | /// <summary> |
| | | /// 中摇开始 times=第几次循环 从0开始 |
| | | /// </summary> |
| | | /// <param name="times"></param> |
| | | public virtual void OnMiddleFrameStart(int times) |
| | | { |
| | | skillEffect.OnMiddleFrameStart(times); |
| | | } |
| | | // 复活基本都靠技能包 |
| | | if (pack is CustomHB426CombinePack combinePack && combinePack.startTag.Tag.StartsWith("Skill_")) |
| | | break; |
| | | |
| | | if (pack is H0704_tagRolePackRefresh h0704Pack && h0704Pack.PackType == (byte)PackType.DropItem && h0704Pack.IsBind == 1) |
| | | { |
| | | dropPackList.Add(h0704Pack); |
| | | removeIndexList.Add(i); |
| | | } |
| | | |
| | | if (pack is HB405_tagMCAddExp h405Pack && h405Pack.Source == 2) |
| | | { |
| | | expPackList.Add(h405Pack); |
| | | removeIndexList.Add(i); |
| | | } |
| | | } |
| | | |
| | | public virtual void OnMiddleFrameEnd(int times, int hitIndex) |
| | | { |
| | | skillEffect.OnMiddleFrameEnd(times, hitIndex); |
| | | } |
| | | for (int i = removeIndexList.Count - 1; i >= 0; i--) |
| | | packList.RemoveAt(removeIndexList[i]); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 后摇开始 |
| | | /// </summary> |
| | | public virtual void OnFinalFrameStart() |
| | | { |
| | | |
| | | } |
| | | public virtual bool IsFinishedForJudge() |
| | | { |
| | | if (!isPlay) return false; |
| | | |
| | | /// <summary> |
| | | /// 后摇结束 |
| | | /// </summary> |
| | | public virtual void OnFinalFrameEnd() |
| | | { |
| | | if (skillEffect != null) |
| | | { |
| | | if (!skillEffect.IsFinished()) return false; |
| | | } |
| | | |
| | | } |
| | | if (otherSkillActionList.Count > 0) |
| | | { |
| | | 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} 等待动画播放完成"); |
| | | return false; |
| | | } |
| | | } |
| | | |
| | | return true; |
| | | } |
| | | |
| | | protected void HighLightAllTargets() |
| | | { |
| | | // 高亮所有目标 |
| | | HashSet<BattleObject> highlightList = new HashSet<BattleObject>(battleField.battleObjMgr.GetBattleObjList(tagUseSkillAttack)); |
| | | highlightList.Add(caster); |
| | | return false; |
| | | } |
| | | |
| | | // 检查技能是否完成:综合检查所有完成条件 |
| | | public virtual bool IsFinished() |
| | | { |
| | | if (!isPlay) return false; |
| | | |
| | | bool tempRetValue = true; |
| | | |
| | | // 把这些BO全高亮 或者说把除了这些的都放在遮罩后面 |
| | | // YYL TODO |
| | | } |
| | | // 检查技能效果是否完成 |
| | | if (skillEffect != null) |
| | | { |
| | | if (!skillEffect.IsFinished()) return false; |
| | | skillEffect = null; |
| | | OnSkillFinished(); |
| | | tempRetValue = false; |
| | | } |
| | | |
| | | // 命中目标后的回调 正常是以各技能的方式来处理的 |
| | | protected virtual void OnHitTargets(int _hitIndex, List<HB427_tagSCUseSkill.tagSCUseSkillHurt> hitList) |
| | | { |
| | | for (int i = 0; i < hitList.Count; i++) |
| | | { |
| | | HB427_tagSCUseSkill.tagSCUseSkillHurt hurt = hitList[i]; |
| | | // 检查其他技能动作是否完成 |
| | | if (otherSkillActionList.Count > 0) |
| | | { |
| | | for (int i = otherSkillActionList.Count - 1; i >= 0; i--) |
| | | { |
| | | var action = otherSkillActionList[i]; |
| | | if (action.IsFinished()) |
| | | { |
| | | otherSkillActionList.RemoveAt(i); |
| | | OnSkillFinished(); |
| | | } |
| | | } |
| | | if (otherSkillActionList.Count > 0) |
| | | { |
| | | tempRetValue = false; |
| | | } |
| | | } |
| | | |
| | | BattleObject target = caster.battleField.battleObjMgr.GetBattleObject((int)hurt.ObjID); |
| | | if (target == null) |
| | | { |
| | | BattleDebug.LogError("目标为空 target == null ObjId : " + hurt.ObjID); |
| | | continue; |
| | | } |
| | | if (!tempRetValue) |
| | | { |
| | | return false; |
| | | } |
| | | |
| | | OnHitEachTarget(_hitIndex, target, hurt); |
| | | } |
| | | // 检查最终完成状态 |
| | | if (isFinished && moveFinished) |
| | | { |
| | | if (packList.Count > 0) |
| | | { |
| | | OnSkillFinished(); |
| | | return false; |
| | | } |
| | | |
| | | HandleDead(); |
| | | } |
| | | // 技能完全结束,移除技能注册并触发延迟的死亡判定 |
| | | if (battleField != null && caster != null) |
| | | { |
| | | battleField.RemoveCastingSkill(caster.ObjID, this); |
| | | |
| | | // 传递parentRecordAction,让死亡技能等待当前技能完成 |
| | | battleField.OnObjsDead(new List<BattleDeadPack>(tempDeadPackList.Values)); |
| | | } |
| | | |
| | | return true; |
| | | } |
| | | |
| | | protected virtual void OnHitEachTarget(int _hitIndex, BattleObject target, HB427_tagSCUseSkill.tagSCUseSkillHurt hurt) |
| | | { |
| | | // 伤害分布 (万分比) |
| | | int[] damageDivide = skillConfig.DamageDivide[_hitIndex]; |
| | | return false; |
| | | } |
| | | |
| | | long totalDamage = GeneralDefine.GetFactValue(hurt.HurtHP, hurt.HurtHPEx); |
| | | |
| | | // 保证所有分配项加起来等于totalDamage,避免因整除导致的误差 |
| | | List<long> damageList = BattleUtility.DivideDamageToList(damageDivide, totalDamage); |
| | | // public uint ObjID; |
| | | // public uint AttackTypes; // 飘血类型汇总,支持多种类型并存,如无视防御且暴击同时被格挡,二进制或运算最终值;0-失败;1-普通;2-回血;5-格挡;6-无视防御;7-暴击;9-闪避 |
| | | // public uint HurtHP; // 飘血值,求余亿部分 |
| | | // public uint HurtHPEx; // 飘血值,整除亿部分 |
| | | // public uint CurHP; // 更新剩余血量,求余亿部分 |
| | | // public uint CurHPEx; // 更新剩余血量,整除亿部分 |
| | | // public uint SuckHP; // 本次伤害转化的吸血量 |
| | | // public uint BounceHP; // 本次伤害反弹的伤害量 |
| | | // 强制结束技能:立即结束所有技能相关的处理 |
| | | public virtual void ForceFinished() |
| | | { |
| | | if (isFinished) |
| | | return; |
| | | |
| | | // 移除技能注册 |
| | | if (battleField != null && caster != null) |
| | | { |
| | | battleField.RemoveCastingSkill(caster.ObjID, this); |
| | | } |
| | | |
| | | // TODO YYL AttackTypes 要表现成什么样呢? 支持多种类型并存,如无视防御且暴击同时被格挡,二进制或运算最终值;0-失败;1-普通;2-回血;5-格挡;6-无视防御;7-暴击;9-闪避 |
| | | target.Hurt(damageList, totalDamage, hurt.AttackTypes); |
| | | // 传递parentRecordAction,让死亡技能等待当前技能完成 |
| | | battleField.OnObjsDead(new List<BattleDeadPack>(tempDeadPackList.Values)); |
| | | |
| | | // TODO YYL 这里是要做统一计算后再hurt跟suckhp还是怎样 |
| | | // caster.SuckHp(hurt.SuckHP);// 吸血 |
| | | // caster.HurtByReflect(hurt.BounceHP);// 反弹伤害 |
| | | } |
| | | // 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); |
| | | |
| | | // 【使用 BattleField.recordPlayer】 |
| | | // 原因:即使在ForceFinished中,子技能也是顶层RecordAction,应该由主RecordPlayer管理 |
| | | // 这些子技能会立即被ForceFinish,但仍需要正确的播放器上下文 |
| | | 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); |
| | | |
| | | // 【使用 BattleField.recordPlayer】 |
| | | // 原因:即使在ForceFinished中,子技能也是顶层RecordAction,应该由主RecordPlayer管理 |
| | | battleField.recordPlayer.ImmediatelyPlay(recordAction, parentRecordAction, true); |
| | | } |
| | | tagUseSkillAttack.subSkillCombinePackList.Clear(); |
| | | |
| | | // 2. 强制结束所有子技能动作 |
| | | otherSkillActionList.ForEach(action => action.ForceFinish()); |
| | | otherSkillActionList.Clear(); |
| | | |
| | | protected void HandleDead() |
| | | { |
| | | var deadPackList = BattleUtility.FindDeadPack(packList); |
| | | int deadCount = deadPackList.Count; |
| | | // 3. 清理 DOTween 动画(防止移动回调在战斗结束后执行) |
| | | if (caster != null && caster.heroRectTrans != null) |
| | | { |
| | | DG.Tweening.DOTween.Kill(caster.heroRectTrans); |
| | | } |
| | | |
| | | if (deadCount <= 0) |
| | | { |
| | | // 如果没死亡就不用管 |
| | | return; |
| | | } |
| | | // 4. 重置施法者状态 |
| | | if (caster != null) |
| | | { |
| | | // 重置位置到原点 |
| | | if (caster.heroRectTrans != null) |
| | | { |
| | | caster.heroRectTrans.anchoredPosition = Vector2.zero; |
| | | } |
| | | |
| | | // 重置朝向 |
| | | if (caster.heroGo != null) |
| | | { |
| | | Vector3 scale = caster.heroGo.transform.localScale; |
| | | scale.x = Mathf.Abs(scale.x); |
| | | caster.heroGo.transform.localScale = scale; |
| | | } |
| | | |
| | | CheckAfterDeadhPack(); |
| | | // 取消幻影效果 |
| | | caster.motionBase?.ShowIllusionShadow(false); |
| | | |
| | | // 播放待机动画(如果还活着) |
| | | if (!caster.teamHero.isDead) |
| | | { |
| | | caster.motionBase?.ResetForReborn(false); |
| | | } |
| | | } |
| | | |
| | | // 处理掉落包 提前distribute之后 PackManager才有掉落物 所以不跟assignexp一样distribute |
| | | foreach (var _dropPack in dropPackList) |
| | | { |
| | | BattleDebug.LogError("distribute pack " + _dropPack.GetType().Name); |
| | | PackageRegedit.Distribute(_dropPack); |
| | | packList.Remove(_dropPack); |
| | | } |
| | | // 5. 恢复 UI 状态 |
| | | if (battleField != null) |
| | | { |
| | | // 恢复所有角色的显示层级和血条 |
| | | var allList = battleField.battleObjMgr?.allBattleObjDict?.Values; |
| | | if (allList != null) |
| | | { |
| | | foreach (BattleObject bo in allList) |
| | | { |
| | | bo.layerMgr?.SetFront(); |
| | | bo.heroInfoBar?.SetActive(true); |
| | | } |
| | | } |
| | | |
| | | // 关闭技能遮罩 |
| | | if (battleField.battleRootNode != null && battleField.battleRootNode.skillMaskNode != null) |
| | | { |
| | | battleField.battleRootNode.skillMaskNode.SetActive(false); |
| | | } |
| | | } |
| | | |
| | | // 获取掉落物品 |
| | | var dropPack = PackManager.Instance.GetSinglePack(PackType.DropItem); |
| | | var itemDict = dropPack.GetAllItems(); |
| | | List<ItemModel> itemList = new List<ItemModel>( |
| | | from item in itemDict.Values |
| | | where item != null && item.isAuction |
| | | select item); |
| | | isFinished = true; |
| | | moveFinished = true; |
| | | isPlay = true; |
| | | |
| | | // 强制结束时,无论是否有动画,都标记动画完成 |
| | | isMotionCompleted = true; |
| | | |
| | | // 6. 处理所有剩余包(包括 buff 包) |
| | | // 先处理 buffPackCollections |
| | | DistributeBuffPacks(buffPackCollections); |
| | | buffPackCollections.Clear(); |
| | | |
| | | // 处理剩余的 packList |
| | | while (packList.Count > 0) |
| | | { |
| | | var pack = packList[0]; |
| | | packList.RemoveAt(0); |
| | | |
| | | // 分配掉落和经验 |
| | | var dropAssign = AssignDrops(itemList, deadCount); |
| | | var expAssign = AssignExp(expPackList, deadCount); |
| | | if (pack is CustomHB426CombinePack combinePack && combinePack.startTag.Tag.StartsWith("Skill_")) |
| | | { |
| | | var otherSkillAction = combinePack.CreateSkillAction(); |
| | | otherSkillAction.fromSkill = this; |
| | | otherSkillAction.ForceFinish(); |
| | | } |
| | | else |
| | | { |
| | | if (pack is CustomB421ActionPack actionPack) |
| | | actionPack.Distribute(); |
| | | // 【使用 parentRecordAction.innerRecordPlayer】 |
| | | // 原因:ForceFinished时剩余的包也是技能内部产生的,应该由innerRecordPlayer管理 |
| | | // 这样可以确保即使强制结束,包的处理也在正确的上下文中 |
| | | PackageRegedit.Distribute(pack); |
| | | } |
| | | } |
| | | } |
| | | |
| | | // 构造 BattleDrops 并分配 |
| | | for (int i = 0; i < deadCount; i++) |
| | | { |
| | | BattleObject deadTarget = battleField.battleObjMgr.GetBattleObject((int)deadPackList[i].ObjID); |
| | | List<ItemModel> itemModelDrops = dropAssign[i]; |
| | | List<int> itemModelDropsIndexList = new List<int>( |
| | | from item in itemModelDrops select item.gridIndex); |
| | | BattleDrops battleDrops = new BattleDrops() |
| | | { |
| | | rectTransform = deadTarget.heroRectTrans, |
| | | dropItemPackIndex = itemModelDropsIndexList, |
| | | expDrops = expAssign[i] |
| | | }; |
| | | deadTarget.PushDropItems(battleDrops); |
| | | } |
| | | // 技能完成处理:正常完成时的清理工作 |
| | | public void OnSkillFinished() |
| | | { |
| | | // 修复:使用循环代替递归,避免栈溢出风险 |
| | | // try |
| | | // { |
| | | while (true) |
| | | { |
| | | // 验证技能效果是否完成 |
| | | if (skillEffect != null && !skillEffect.IsFinished()) |
| | | return; |
| | | |
| | | // 分发死亡包 |
| | | if (skillEffect != null) |
| | | { |
| | | skillEffect = null; |
| | | continue; // 使用continue代替递归调用 |
| | | } |
| | | |
| | | battleField.OnObjsDead(new List<HB422_tagMCTurnFightObjDead>(deadPackList)); |
| | | foreach (var deadPack in deadPackList) |
| | | { |
| | | packList.Remove(deadPack); |
| | | } |
| | | deadPackList.Clear(); |
| | | // 验证其他技能动作是否完成 |
| | | if (otherSkillActionList.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; |
| | | } |
| | | } |
| | | if (hasFinishedAction) |
| | | { |
| | | continue; // 使用continue代替递归调用 |
| | | } |
| | | return; |
| | | } |
| | | |
| | | break; // 没有更多需要处理的,退出循环 |
| | | } |
| | | |
| | | } |
| | | // 处理剩余包 |
| | | if (!ResolvePackList()) |
| | | { |
| | | return; |
| | | } |
| | | // } |
| | | // catch (Exception ex) |
| | | // { |
| | | // Debug.LogError($"OnSkillFinished异常: {ex.Message},技能ID={skillConfig.SkillID}"); |
| | | // // 确保状态一致性,即使出现异常也要标记完成 |
| | | // isFinished = true; |
| | | // throw; // 重新抛出异常供上层处理 |
| | | // } |
| | | |
| | | isFinished = true; |
| | | } |
| | | |
| | | protected virtual bool ResolvePackList() |
| | | { |
| | | 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); |
| | | return false; |
| | | } |
| | | else if (IsBuffPack(pack)) |
| | | { |
| | | // 从找到第一个 Buff 包开始,收集连续的 HB428/HB429 包 |
| | | buffPackCollections.Add(pack); |
| | | while (packList.Count > 0) |
| | | { |
| | | var nextPack = packList[0]; |
| | | if (IsBuffPack(nextPack)) |
| | | { |
| | | buffPackCollections.Add(nextPack); |
| | | packList.RemoveAt(0); |
| | | } |
| | | else |
| | | { |
| | | break; |
| | | } |
| | | } |
| | | |
| | | // 分配掉落 |
| | | protected List<List<ItemModel>> AssignDrops(List<ItemModel> itemList, int deadCount) |
| | | { |
| | | var dropAssign = new List<List<ItemModel>>(deadCount); |
| | | for (int i = 0; i < deadCount; i++) |
| | | dropAssign.Add(new List<ItemModel>()); |
| | | for (int i = 0; i < itemList.Count; i++) |
| | | dropAssign[i % deadCount].Add(itemList[i]); |
| | | return dropAssign; |
| | | } |
| | | // 处理所有收集到的 buff 包 |
| | | ProcessBuffPacks(buffPackCollections); |
| | | |
| | | // 分配经验:每个原始包都平均分配到每个死亡对象 |
| | | protected List<List<HB405_tagMCAddExp>> AssignExp(List<HB405_tagMCAddExp> expList, int deadCount) |
| | | { |
| | | var expAssign = new List<List<HB405_tagMCAddExp>>(deadCount); |
| | | for (int i = 0; i < deadCount; i++) |
| | | expAssign.Add(new List<HB405_tagMCAddExp>()); |
| | | // 清空已处理的 buff 集合 |
| | | buffPackCollections.Clear(); |
| | | continue; |
| | | } |
| | | |
| | | foreach (var expPack in expList) |
| | | { |
| | | long totalExp = GeneralDefine.GetFactValue(expPack.Exp, expPack.ExpPoint); |
| | | long avgExp = totalExp / deadCount; |
| | | long remain = totalExp % deadCount; |
| | | if (pack is CustomB421ActionPack actionPack) |
| | | { |
| | | actionPack.Distribute(); |
| | | } |
| | | else |
| | | { |
| | | // 【使用 parentRecordAction.innerRecordPlayer】 |
| | | // 原因:技能执行过程中的包(Buff、属性刷新等)是技能效果的一部分 |
| | | // 应该由SkillRecordAction的innerRecordPlayer管理,确保与技能生命周期一致 |
| | | PackageRegeditEx.DistributeToRecordAction(pack, parentRecordAction); |
| | | } |
| | | } |
| | | |
| | | for (int i = 0; i < deadCount; i++) |
| | | { |
| | | long assignExp = avgExp + (i < remain ? 1 : 0); |
| | | long expPoint = assignExp / 100000000; |
| | | long exp = assignExp % 100000000; |
| | | var newPack = new HB405_tagMCAddExp |
| | | { |
| | | Exp = (uint)exp, |
| | | ExpPoint = (uint)expPoint, |
| | | Source = expPack.Source // 保持原包来源 |
| | | }; |
| | | expAssign[i].Add(newPack); |
| | | } |
| | | packList.Remove(expPack); |
| | | } |
| | | return expAssign; |
| | | } |
| | | return true; |
| | | } |
| | | |
| | | // 添加清理方法:防止内存泄漏 |
| | | public virtual void Cleanup() |
| | | { |
| | | tempDropList?.Clear(); |
| | | tempDeadPackList?.Clear(); |
| | | otherSkillActionList?.Clear(); |
| | | dropPackList?.Clear(); |
| | | expPackList?.Clear(); |
| | | buffPackCollections?.Clear(); |
| | | |
| | | skillEffect = null; |
| | | packList = null; |
| | | } |
| | | |
| | | #region Buff包处理 |
| | | |
| | | protected void CheckAfterDeadhPack() |
| | | { |
| | | List<int> removeIndexList = new List<int>(); |
| | | for (int i = 0; i < packList.Count; i++) |
| | | { |
| | | var pack = packList[i]; |
| | | /// <summary> |
| | | /// 判断是否为 Buff 相关的包(HB428 或 HB429) |
| | | /// </summary> |
| | | protected bool IsBuffPack(GameNetPackBasic pack) |
| | | { |
| | | return pack is HB428_tagSCBuffRefresh || pack is HB429_tagSCBuffDel; |
| | | } |
| | | |
| | | // 复活基本都靠技能包 |
| | | if (pack is CustomHB426CombinePack) |
| | | { |
| | | var combinePack = pack as CustomHB426CombinePack; |
| | | if (combinePack.startTag.Tag.StartsWith("Skill_")) |
| | | { |
| | | break; // 找到技能包就不需要再处理了 |
| | | } |
| | | } |
| | | else if (pack is H0704_tagRolePackRefresh) |
| | | { |
| | | var h0704Pack = pack as H0704_tagRolePackRefresh; |
| | | if (h0704Pack.PackType == (byte)PackType.DropItem) |
| | | { |
| | | // 掉落的 |
| | | if (h0704Pack.IsBind == 1) |
| | | { |
| | | // 掉落的物品 |
| | | dropPackList.Add(h0704Pack); |
| | | removeIndexList.Add(i); |
| | | } |
| | | else if (h0704Pack.IsBind == 0) |
| | | { |
| | | // 替换的 |
| | | } |
| | | } |
| | | } |
| | | else if (pack is HB405_tagMCAddExp) |
| | | { |
| | | var h405Pack = pack as HB405_tagMCAddExp; |
| | | /// <summary> |
| | | /// 处理收集到的 Buff 包列表(HB428 刷新 和 HB429 删除) |
| | | /// </summary> |
| | | protected void ProcessBuffPacks(List<GameNetPackBasic> buffPacks) |
| | | { |
| | | if (buffPacks == null || buffPacks.Count == 0) return; |
| | | |
| | | //B4 05 获得经验 #tagMCAddExp 通知获得的经验, |
| | | //可用于做经验获得表现 Source = 2 时为主线击杀怪物获得经验 |
| | | if (h405Pack.Source == 2) |
| | | { |
| | | expPackList.Add(h405Pack); |
| | | removeIndexList.Add(i); |
| | | } |
| | | } |
| | | foreach (var pack in buffPacks) |
| | | { |
| | | if (pack is HB428_tagSCBuffRefresh buffRefresh) |
| | | { |
| | | BattleObject battleObj = battleField.battleObjMgr.GetBattleObject((int)buffRefresh.ObjID); |
| | | if (battleObj != null) |
| | | { |
| | | battleObj.buffMgr.RefreshBuff(buffRefresh, true); |
| | | } |
| | | } |
| | | else if (pack is HB429_tagSCBuffDel buffDel) |
| | | { |
| | | BattleObject battleObj = battleField.battleObjMgr.GetBattleObject((int)buffDel.ObjID); |
| | | if (battleObj != null) |
| | | { |
| | | battleObj.buffMgr.RemoveBuff(buffDel, false); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | } |
| | | /// <summary> |
| | | /// 强制分发 Buff 包(用于 ForceFinished 场景) |
| | | /// </summary> |
| | | protected void DistributeBuffPacks(List<GameNetPackBasic> buffPacks) |
| | | { |
| | | if (buffPacks == null || buffPacks.Count == 0) return; |
| | | |
| | | for (int i = removeIndexList.Count - 1; i >= 0; i--) |
| | | { |
| | | packList.RemoveAt(removeIndexList[i]); |
| | | } |
| | | } |
| | | public virtual bool IsFinished() |
| | | { |
| | | if (skillEffect != null) |
| | | { |
| | | if (!skillEffect.IsFinished()) |
| | | { |
| | | return false; |
| | | } |
| | | else |
| | | { |
| | | OnSkillFinished(); |
| | | skillEffect = null; |
| | | } |
| | | } |
| | | foreach (var pack in buffPacks) |
| | | { |
| | | // 【使用 parentRecordAction.innerRecordPlayer】 |
| | | // 原因:Buff包是技能效果的核心组成部分,应该由SkillRecordAction管理 |
| | | // 即使是强制分发的情况,也要保持在正确的RecordAction上下文中 |
| | | PackageRegeditEx.DistributeToRecordAction(pack, parentRecordAction); |
| | | } |
| | | } |
| | | |
| | | return isFinished; |
| | | } |
| | | public virtual bool CanStartExecution() |
| | | { |
| | | if (null == caster) |
| | | { |
| | | return false; |
| | | } |
| | | |
| | | public virtual void ForceFinished() |
| | | { |
| | | isFinished = true; |
| | | } |
| | | if (null == skillConfig) |
| | | { |
| | | return false; |
| | | } |
| | | |
| | | public void OnSkillFinished() |
| | | { |
| | | if (skillEffect != null) |
| | | { |
| | | if (!skillEffect.IsFinished()) |
| | | { |
| | | return; |
| | | } |
| | | } |
| | | if (string.IsNullOrEmpty(skillConfig.SkillMotionName)) |
| | | { |
| | | return true; |
| | | } |
| | | |
| | | BattleDebug.LogError(GetType().Name + " Skill Finished"); |
| | | while (packList.Count > 0) |
| | | { |
| | | var pack = packList[0]; |
| | | packList.RemoveAt(0); |
| | | return !battleField.IsCastingSkill(caster.ObjID); |
| | | } |
| | | |
| | | if (pack is CustomHB426CombinePack) |
| | | { |
| | | var combinePack = pack as CustomHB426CombinePack; |
| | | if (combinePack.startTag.Tag.StartsWith("Skill_")) |
| | | { |
| | | otherSkillAction = combinePack.CreateSkillAction(); |
| | | return; |
| | | } |
| | | } |
| | | BattleDebug.LogError("distribute pack " + pack.GetType().Name); |
| | | PackageRegedit.Distribute(pack); |
| | | } |
| | | #endregion |
| | | |
| | | isFinished = true; |
| | | } |
| | | } |