| | |
| | | { |
| | | const float moveTime = 0.5f; |
| | | |
| | | 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 SkillEffect skillEffect; |
| | | protected HB427_tagSCUseSkill tagUseSkillAttack; |
| | | public HB427_tagSCUseSkill tagUseSkillAttack; |
| | | public SkillConfig skillConfig; |
| | | protected bool isFinished = false; |
| | | protected BattleField battleField = null; // 战场 |
| | | protected RectTransform targetNode = null; // 目标节点 |
| | | protected BattleObject caster = 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 bool moveFinished = false; |
| | | public int fromSkillId; |
| | | public SkillBase fromSkill; |
| | | public bool isPlay = false; |
| | | |
| | | private float MoveSpeed = 750f; |
| | | |
| | | private Dictionary<int, BattleDrops> tempDropList = new Dictionary<int, BattleDrops>(); |
| | | private Dictionary<int, HB422_tagMCTurnFightObjDead> tempDeadPackList = new Dictionary<int, HB422_tagMCTurnFightObjDead>(); |
| | | |
| | | protected List<HB428_tagSCBuffRefresh> buffCollections = new List<HB428_tagSCBuffRefresh>(); |
| | | |
| | | |
| | | // 构造函数:初始化技能基础数据 |
| | | public SkillBase(BattleObject _caster, SkillConfig _skillCfg, HB427_tagSCUseSkill vNetData, List<GameNetPackBasic> _packList, BattleField _battleField = null) |
| | |
| | | tagUseSkillAttack = vNetData; |
| | | battleField = _battleField; |
| | | packList = _packList; |
| | | |
| | | SafetyCheck(); |
| | | #if UNITY_EDITOR |
| | | if (Launch.Instance.isOpenSkillLogFile) |
| | | { |
| | | PinrtHB427Hp(); |
| | | } |
| | | #endif |
| | | } |
| | | |
| | | #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"; |
| | | } |
| | | } |
| | | } |
| | | |
| | | 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"; |
| | | } |
| | | } |
| | | |
| | | 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); |
| | | |
| | | Debug.LogError("skillDetail : " + skillDetail); |
| | | #endif |
| | | } |
| | | |
| | | private void SafetyCheck() |
| | | { |
| | | bool safety = caster != null |
| | | && skillConfig != null |
| | | && tagUseSkillAttack != null |
| | | && battleField != null |
| | | && caster.IsDead() == false; |
| | | |
| | | |
| | | if (!safety) |
| | | { |
| | | Debug.LogError("SkillBase SafetyCheck failed! Caster or SkillConfig or TagUseSkillAttack or BattleField is null, or Caster is dead."); |
| | | ForceFinished(); |
| | | } |
| | | |
| | | |
| | | } |
| | | |
| | | // 技能运行主逻辑:处理技能效果和其他技能动作 |
| | |
| | | } |
| | | } |
| | | |
| | | 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); |
| | | } |
| | | } |
| | | |
| | | // 技能释放主逻辑:广播事件、高亮目标、执行释放 |
| | | public virtual void Cast() |
| | | { |
| | |
| | | TeamHero teamHero = caster.teamHero; |
| | | EventBroadcast.Instance.Broadcast<string, SkillConfig, TeamHero>(EventName.BATTLE_CAST_SKILL, guid, skillConfig, teamHero); |
| | | |
| | | if (skillConfig.SkinllSFX1 != 0) |
| | | { |
| | | battleField.soundManager.PlayEffectSound(skillConfig.SkinllSFX1, false); |
| | | } |
| | | |
| | | 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); |
| | | |
| | | |
| | | } |
| | | |
| | | // 高亮所有本次技能相关的目标 |
| | | HighLightAllTargets(); |
| | | |
| | | // 根据释放模式执行相应逻辑 |
| | | switch (skillConfig.castMode) |
| | | { |
| | | case SkillCastMode.None: |
| | | case SkillCastMode.Self: |
| | | CastImpl(OnAttackFinish); |
| | | 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) |
| | | { |
| | |
| | | RectTransform target = battleField.GetTeamNode(caster.GetEnemyCamp(), skillConfig); |
| | | ExecuteMoveAndCastSequence(target, () => |
| | | { |
| | | MoveToTarget(battleField.GetTeamNode(caster.Camp, caster.teamHero.positionNum), Vector2.zero, OnAttackFinish, 750F); |
| | | // ShadowIllutionCreate(true); |
| | | MoveToTarget(battleField.GetTeamNode(caster.Camp, caster.teamHero.positionNum), Vector2.zero, () => |
| | | { |
| | | // ShadowIllutionCreate(false); |
| | | OnAttackFinish(); |
| | | }, MoveSpeed); |
| | | }); |
| | | } |
| | | |
| | |
| | | return; |
| | | } |
| | | |
| | | int mainTargetPosNum = BattleUtility.GetMainTargetPositionNum(caster, tagUseSkillAttack.HurtList.ToList(), skillConfig); |
| | | 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); |
| | | MoveToTarget(rectTransform, Vector2.zero, OnAttackFinish, 750F); |
| | | // ShadowIllutionCreate(true); |
| | | MoveToTarget(rectTransform, Vector2.zero, () => |
| | | { |
| | | // ShadowIllutionCreate(false); |
| | | OnAttackFinish(); |
| | | }, MoveSpeed); |
| | | }); |
| | | } |
| | | |
| | |
| | | RectTransform target = battleField.GetTeamNode(caster.Camp, skillConfig); |
| | | ExecuteMoveAndCastSequence(target, () => |
| | | { |
| | | MoveToTarget(battleField.GetTeamNode(caster.Camp, caster.teamHero.positionNum), Vector2.zero, OnAttackFinish, 750F); |
| | | // 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(() => |
| | |
| | | } |
| | | |
| | | // 移动到目标位置:处理角色的移动动画和逻辑 |
| | | protected void MoveToTarget(RectTransform target, Vector2 offset, Action _onComplete = null, float speed = 500f) |
| | | protected void MoveToTarget(RectTransform target, Vector2 offset, Action _onComplete = null, float speed = 750f) |
| | | { |
| | | if (skillConfig.CastDistance >= 9999) |
| | | { |
| | |
| | | // 技能开始回调:处理死亡、子技能、技能效果初始化 |
| | | public void OnSkillStart() |
| | | { |
| | | if (isPlay) |
| | | { |
| | | Debug.LogError(" play twice OnSkillStart skillId :" + skillConfig.SkillID); |
| | | return; |
| | | } |
| | | |
| | | HandleDead(); |
| | | skillEffect = SkillEffectFactory.CreateSkillEffect(caster, skillConfig, tagUseSkillAttack); |
| | | |
| | | skillEffect = SkillEffectFactory.CreateSkillEffect(this, caster, skillConfig, tagUseSkillAttack); |
| | | skillEffect.Play(OnHitTargets); |
| | | foreach (var subSkillPack in tagUseSkillAttack.subSkillList) |
| | | { |
| | | RecordAction recordAction = CustomHB426CombinePack.CreateSkillAction(battleField.guid, new List<GameNetPackBasic>() { subSkillPack }); |
| | | SkillRecordAction recordAction = CustomHB426CombinePack.CreateSkillAction(battleField.guid, new List<GameNetPackBasic>() { subSkillPack }); |
| | | recordAction.fromSkill = this; |
| | | otherSkillActionList.Add(recordAction); |
| | | battleField.recordPlayer.ImmediatelyPlay(recordAction); |
| | | } |
| | | 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.ImmediatelyPlay(recordAction); |
| | | } |
| | | tagUseSkillAttack.subSkillCombinePackList.Clear(); |
| | | |
| | | isPlay = true; |
| | | } |
| | | |
| | |
| | | // 技能后摇结束回调:通知技能效果处理后摇结束 |
| | | public virtual void OnFinalFrameEnd() |
| | | { |
| | | |
| | | skillEffect?.OnFinalFrameEnd(); // 修复:添加空值检查 |
| | | } |
| | | |
| | |
| | | if (skillConfig.FuncType != 2) |
| | | return; |
| | | |
| | | List<BattleObject> targetList = battleField.battleObjMgr.GetBattleObjList(tagUseSkillAttack); |
| | | List<BattleObject> highlightList = new List<BattleObject>(targetList) { caster }; |
| | | List<BattleObject> allList = battleField.battleObjMgr.allBattleObjDict.Values.ToList<BattleObject>(); |
| | | |
| | | // 修复:使用HashSet优化性能,避免重复设置 |
| | | var targetSet = new HashSet<BattleObject>(targetList); |
| | | // 收集所有目标(包含 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 = targetSet.Contains(bo); |
| | | |
| | | bool isTarget = targetSetLookup.Contains(bo); |
| | | |
| | | if (isHighlight) |
| | | { |
| | | bo.layerMgr.SetFront(); |
| | |
| | | bo.layerMgr.SetBack(); |
| | | } |
| | | |
| | | // 目标(含 HurtListEx)都应显示 InfoBar |
| | | bo.heroInfoBar.SetActive(isTarget); |
| | | } |
| | | |
| | | battleField.battleRootNode.skillMaskNode.SetActive(true); |
| | | battleField.battleRootNode.SetSortingOrder(); |
| | | } |
| | | |
| | | // 命中目标回调:处理所有被命中的目标 |
| | | protected long suckHp = 0; |
| | | |
| | | // 命中目标回调:处理所有被命中的目标(包括主目标、弹射目标、溅射目标) |
| | | protected virtual void OnHitTargets(int _hitIndex, List<HB427_tagSCUseSkill.tagSCUseSkillHurt> hitList) |
| | | { |
| | | // 造成伤害前先处理血量刷新包 |
| | | HandleRefreshHP(); |
| | | |
| | | suckHp = 0; |
| | | |
| | | // 统计吸血总量(主目标) |
| | | foreach (var hurt in hitList) |
| | | { |
| | | suckHp += hurt.SuckHP; |
| | | } |
| | | |
| | | // 处理主目标列表 |
| | | foreach (var hurt in hitList) |
| | | { |
| | | BattleObject target = caster.battleField.battleObjMgr.GetBattleObject((int)hurt.ObjID); |
| | | if (target == null) |
| | | { |
| | |
| | | } |
| | | |
| | | OnHitEachTarget(_hitIndex, target, hurt); |
| | | |
| | | // 处理该目标的额外目标列表(如弹射伤害的平摊目标) |
| | | 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); |
| | | } |
| | | } |
| | | |
| | | 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); |
| | | } |
| | | } |
| | | |
| | | |
| | | } |
| | | |
| | | // 处理单个目标被命中:应用伤害和施法者效果 |
| | | // 处理单个目标被命中:应用伤害和施法者效果 |
| | | protected virtual void OnHitEachTarget(int _hitIndex, BattleObject target, HB427_tagSCUseSkill.tagSCUseSkillHurt hurt) |
| | | { |
| | | List<int> damageDivide = new List<int>(); |
| | | if (_hitIndex == 0 && skillConfig.DamageDivide.Length <= 0) |
| | | { |
| | | damageDivide.Add(10000); |
| | | } |
| | | else |
| | | { |
| | | if (skillConfig.DamageDivide.Length <= _hitIndex) |
| | | { |
| | | Debug.LogError("技能伤害分布配置错误 skillId: " + skillConfig.SkillID + " hitIndex: " + _hitIndex); |
| | | damageDivide.Add(10000); |
| | | } |
| | | else |
| | | { |
| | | damageDivide = skillConfig.DamageDivide[_hitIndex].ToList(); |
| | | } |
| | | } |
| | | |
| | | // 伤害分布计算和应用 |
| | | long totalDamage = GeneralDefine.GetFactValue(hurt.HurtHP, hurt.HurtHPEx); |
| | | List<long> damageList = BattleUtility.DivideDamageToList(damageDivide.ToArray(), totalDamage); |
| | | |
| | | // 获取临时数据并应用伤害 |
| | | // ============ 获取临时数据(掉落、死亡等) ============ |
| | | int objID = (int)target.ObjID; |
| | | tempDropList.TryGetValue(objID, out BattleDrops battleDrops); |
| | | tempDeadPackList.TryGetValue(objID, out HB422_tagMCTurnFightObjDead deadPack); |
| | | target.Hurt(damageList, totalDamage, hurt, skillConfig, _hitIndex, battleDrops, deadPack); |
| | | |
| | | // 处理施法者相关效果 |
| | | caster.SuckHp(hurt.SuckHP, skillConfig); |
| | | caster.HurtByReflect(hurt.BounceHP, skillConfig); |
| | | // ============ 参数打包 ============ |
| | | BattleHurtParam hurtParam = BattleUtility.CalcBattleHurtParam(this, _hitIndex, target, hurt, battleDrops, deadPack); |
| | | |
| | | #if UNITY_EDITOR |
| | | PrintHurtParamDebugInfo(hurtParam); |
| | | #endif |
| | | |
| | | // 先调用目标受伤 |
| | | target.Hurt(hurtParam); |
| | | |
| | | // 再调用施法者吸血/反伤 |
| | | 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 HB422_tagMCTurnFightObjDead deadPack); |
| | | |
| | | // ============ 参数打包(将 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 = hurtEx.SuckHP, |
| | | BounceHP = 0, // HurtEx 没有反伤字段 |
| | | HurtCountEx = 0, |
| | | HurtListEx = null |
| | | }; |
| | | |
| | | BattleHurtParam hurtParam = BattleUtility.CalcBattleHurtParam(this, _hitIndex, target, hurt, battleDrops, deadPack); |
| | | |
| | | #if UNITY_EDITOR |
| | | PrintHurtParamDebugInfo(hurtParam); |
| | | #endif |
| | | |
| | | // 先调用目标受伤 |
| | | target.Hurt(hurtParam); |
| | | |
| | | // 再调用施法者吸血/反伤 |
| | | caster.OnHurtTarget(hurtParam); |
| | | } |
| | | |
| | | #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刷新包 |
| | | PackageRegedit.Distribute(refreshPack); |
| | | packList.Remove(refreshPack); |
| | | } |
| | | } |
| | | |
| | | // 处理死亡相关逻辑:分配掉落和经验 |
| | |
| | | long assignExp = avgExp + (i < remain ? 1 : 0); |
| | | var newPack = new HB405_tagMCAddExp |
| | | { |
| | | Exp = (uint)(assignExp % 100000000), |
| | | ExpPoint = (uint)(assignExp / 100000000), |
| | | Exp = (uint)(assignExp % Constants.ExpPointValue), |
| | | ExpPoint = (uint)(assignExp / Constants.ExpPointValue), |
| | | Source = expPack.Source |
| | | }; |
| | | expAssign[i].Add(newPack); |
| | |
| | | { |
| | | if (!isPlay) return false; |
| | | |
| | | bool tempRetValue = true; |
| | | |
| | | // 检查技能效果是否完成 |
| | | if (skillEffect != null) |
| | |
| | | if (!skillEffect.IsFinished()) return false; |
| | | skillEffect = null; |
| | | OnSkillFinished(); |
| | | return false; |
| | | tempRetValue = false; |
| | | } |
| | | |
| | | // 检查其他技能动作是否完成 |
| | |
| | | OnSkillFinished(); |
| | | } |
| | | } |
| | | if (otherSkillActionList.Count > 0) return false; |
| | | if (otherSkillActionList.Count > 0) |
| | | { |
| | | tempRetValue = false; |
| | | } |
| | | } |
| | | |
| | | if (!tempRetValue) |
| | | { |
| | | return false; |
| | | } |
| | | |
| | | // 检查最终完成状态 |
| | |
| | | if (pack is CustomHB426CombinePack combinePack && combinePack.startTag.Tag.StartsWith("Skill_")) |
| | | { |
| | | var otherSkillAction = combinePack.CreateSkillAction(); |
| | | otherSkillAction.fromSkillId = skillConfig.SkillID; |
| | | otherSkillAction.fromSkill = this; |
| | | otherSkillAction.ForceFinish(); |
| | | } |
| | | else |
| | |
| | | public void OnSkillFinished() |
| | | { |
| | | // 修复:使用循环代替递归,避免栈溢出风险 |
| | | try |
| | | // try |
| | | // { |
| | | while (true) |
| | | { |
| | | while (true) |
| | | // 验证技能效果是否完成 |
| | | if (skillEffect != null && !skillEffect.IsFinished()) |
| | | return; |
| | | |
| | | if (skillEffect != null) |
| | | { |
| | | // 验证技能效果是否完成 |
| | | if (skillEffect != null && !skillEffect.IsFinished()) |
| | | return; |
| | | |
| | | if (skillEffect != null) |
| | | { |
| | | skillEffect = null; |
| | | continue; // 使用continue代替递归调用 |
| | | } |
| | | |
| | | // 验证其他技能动作是否完成 |
| | | 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; // 没有更多需要处理的,退出循环 |
| | | skillEffect = null; |
| | | continue; // 使用continue代替递归调用 |
| | | } |
| | | |
| | | // 处理剩余包 |
| | | while (packList.Count > 0) |
| | | // 验证其他技能动作是否完成 |
| | | if (otherSkillActionList.Count > 0) |
| | | { |
| | | var pack = packList[0]; |
| | | packList.RemoveAt(0); |
| | | |
| | | if (pack is CustomHB426CombinePack combinePack && combinePack.startTag.Tag.StartsWith("Skill_")) |
| | | bool hasFinishedAction = false; |
| | | for (int i = otherSkillActionList.Count - 1; i >= 0; i--) |
| | | { |
| | | BattleDebug.LogError("other skill casting " + combinePack.startTag.Tag); |
| | | var otherSkillAction = combinePack.CreateSkillAction(); |
| | | otherSkillAction.fromSkillId = skillConfig.SkillID; |
| | | return; |
| | | 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 (pack is HB428_tagSCBuffRefresh buffRefresh) |
| | | { |
| | | // 从找到第一个HB428开始 找出连续的HB428_tagSCBuffRefresh包 如果找到一个B428后 之后碰到非HB428包就停止 |
| | | buffCollections.Add(buffRefresh); |
| | | while (packList.Count > 0) |
| | | { |
| | | var nextPack = packList[0]; |
| | | if (nextPack is HB428_tagSCBuffRefresh nextBuffRefresh) |
| | | { |
| | | buffCollections.Add(nextBuffRefresh); |
| | | packList.RemoveAt(0); |
| | | } |
| | | else |
| | | { |
| | | break; |
| | | } |
| | | } |
| | | |
| | | if (pack is CustomB421ActionPack actionPack) |
| | | actionPack.Distribute(); |
| | | // 同时刷新所有对象的buff,不分组 |
| | | foreach (var buff in buffCollections) |
| | | { |
| | | BattleObject battleObj = battleField.battleObjMgr.GetBattleObject((int)buff.ObjID); |
| | | if (battleObj != null) |
| | | { |
| | | battleObj.buffMgr.RefreshBuff(buff, true); |
| | | } |
| | | } |
| | | |
| | | // 清空已处理的buff集合 |
| | | buffCollections.Clear(); |
| | | continue; |
| | | } |
| | | |
| | | if (pack is CustomB421ActionPack actionPack) |
| | | { |
| | | actionPack.Distribute(); |
| | | } |
| | | else |
| | | { |
| | | PackageRegedit.Distribute(pack); |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | Debug.LogError($"OnSkillFinished异常: {ex.Message},技能ID={skillConfig.SkillID}"); |
| | | // 确保状态一致性,即使出现异常也要标记完成 |
| | | isFinished = true; |
| | | throw; // 重新抛出异常供上层处理 |
| | | } |
| | | |
| | | isFinished = true; |
| | | return true; |
| | | } |
| | | |
| | | // 添加清理方法:防止内存泄漏 |