using System.Collections.Generic;
|
using UnityEngine;
|
using DG.Tweening;
|
using Spine;
|
using System.Linq;
|
using System;
|
|
public class SkillBase
|
{
|
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;
|
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 bool moveFinished = false;
|
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)
|
{
|
caster = _caster;
|
if (null == caster)
|
{
|
throw new Exception("SkillBase caster is null ");
|
}
|
skillConfig = _skillCfg;
|
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();
|
}
|
|
|
}
|
|
// 技能运行主逻辑:处理技能效果和其他技能动作
|
public virtual void Run()
|
{
|
if (skillEffect != null)
|
{
|
if (skillEffect.IsFinished())
|
{
|
skillEffect = null;
|
OnSkillFinished();
|
}
|
else
|
{
|
skillEffect.Run();
|
}
|
return;
|
}
|
|
if (otherSkillActionList.Count > 0)
|
{
|
for (int i = otherSkillActionList.Count - 1; i >= 0; i--)
|
{
|
var action = otherSkillActionList[i];
|
if (action.IsFinished())
|
{
|
otherSkillActionList.RemoveAt(i);
|
OnSkillFinished();
|
}
|
else if (moveFinished)
|
{
|
action.Run();
|
}
|
}
|
}
|
}
|
|
protected void ShadowIllutionCreate(bool create)
|
{
|
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()
|
{
|
// 广播技能释放事件
|
string guid = battleField.guid;
|
TeamHero teamHero = caster.teamHero;
|
EventBroadcast.Instance.Broadcast<string, SkillConfig, TeamHero>(EventName.BATTLE_CAST_SKILL, guid, skillConfig, teamHero);
|
|
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;
|
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, () =>
|
{
|
// 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, () =>
|
{
|
// 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), () =>
|
{
|
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);
|
foreach (var subSkillPack in tagUseSkillAttack.subSkillList)
|
{
|
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 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()
|
{
|
|
skillEffect?.OnFinalFrameEnd(); // 修复:添加空值检查
|
}
|
|
// 高亮所有相关目标:设置施法者和目标的显示层级
|
protected void HighLightAllTargets()
|
{
|
caster.layerMgr.SetSortingOrder(BattleConst.ActiveHeroActionSortingOrder);
|
|
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 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)
|
{
|
Debug.LogError("目标为空 target == null ObjId : " + hurt.ObjID);
|
continue;
|
}
|
|
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)
|
{
|
// ============ 获取临时数据(掉落、死亡等) ============
|
int objID = (int)target.ObjID;
|
tempDropList.TryGetValue(objID, out BattleDrops battleDrops);
|
tempDeadPackList.TryGetValue(objID, out HB422_tagMCTurnFightObjDead deadPack);
|
|
// ============ 参数打包 ============
|
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);
|
}
|
}
|
|
// 处理死亡相关逻辑:分配掉落和经验
|
protected void HandleDead()
|
{
|
var deadPackList = BattleUtility.FindDeadPack(packList);
|
if (deadPackList.Count <= 0) return;
|
|
CheckAfterDeadhPack();
|
|
// 修复:先收集要删除的包,避免在foreach中修改集合
|
var dropPacksToRemove = new List<H0704_tagRolePackRefresh>(dropPackList);
|
foreach (var _dropPack in dropPacksToRemove)
|
{
|
PackageRegedit.Distribute(_dropPack);
|
packList.Remove(_dropPack);
|
}
|
|
// 获取并分配掉落物品和经验
|
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++)
|
{
|
int objID = (int)deadPackList[i].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]
|
};
|
|
// 修复:避免字典键冲突,使用安全的添加方式
|
if (!tempDropList.ContainsKey(objID))
|
{
|
tempDropList.Add(objID, battleDrops);
|
}
|
else
|
{
|
Debug.LogWarning($"tempDropList中已存在ObjID={objID}的记录,将覆盖原值");
|
tempDropList[objID] = battleDrops; // 覆盖现有值
|
}
|
|
if (!tempDeadPackList.ContainsKey(objID))
|
{
|
tempDeadPackList.Add(objID, deadPackList[i]);
|
}
|
else
|
{
|
Debug.LogWarning($"tempDeadPackList中已存在ObjID={objID}的记录,将覆盖原值");
|
tempDeadPackList[objID] = deadPackList[i]; // 覆盖现有值
|
}
|
}
|
|
// 修复:避免在遍历时修改集合,先收集后删除
|
var deadPacksToRemove = new List<GameNetPackBasic>(deadPackList.Cast<GameNetPackBasic>());
|
foreach (var deadPack in deadPacksToRemove)
|
{
|
packList.Remove(deadPack);
|
}
|
}
|
|
// 分配掉落物品:将掉落物品平均分配给死亡对象
|
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 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>());
|
|
// 修复:检查除零风险
|
if (deadCount == 0)
|
{
|
Debug.LogWarning("AssignExp: deadCount为0,无法分配经验");
|
return expAssign;
|
}
|
|
// 修复:先收集要删除的包,避免在foreach中修改packList
|
var expPacksToRemove = new List<HB405_tagMCAddExp>();
|
|
foreach (var expPack in expList)
|
{
|
long totalExp = GeneralDefine.GetFactValue(expPack.Exp, expPack.ExpPoint);
|
long avgExp = totalExp / deadCount;
|
long remain = totalExp % deadCount;
|
|
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);
|
}
|
|
return expAssign;
|
}
|
|
// 检查死亡后的包处理:处理技能包、掉落包、经验包
|
protected void CheckAfterDeadhPack()
|
{
|
List<int> removeIndexList = new List<int>();
|
|
for (int i = 0; i < packList.Count; i++)
|
{
|
var pack = packList[i];
|
|
// 复活基本都靠技能包
|
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);
|
}
|
}
|
|
for (int i = removeIndexList.Count - 1; i >= 0; i--)
|
packList.RemoveAt(removeIndexList[i]);
|
}
|
|
// 检查技能是否完成:综合检查所有完成条件
|
public virtual bool IsFinished()
|
{
|
if (!isPlay) return false;
|
|
bool tempRetValue = true;
|
|
// 检查技能效果是否完成
|
if (skillEffect != null)
|
{
|
if (!skillEffect.IsFinished()) return false;
|
skillEffect = null;
|
OnSkillFinished();
|
tempRetValue = false;
|
}
|
|
// 检查其他技能动作是否完成
|
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;
|
}
|
}
|
|
if (!tempRetValue)
|
{
|
return false;
|
}
|
|
// 检查最终完成状态
|
if (isFinished && moveFinished)
|
{
|
if (packList.Count > 0)
|
{
|
OnSkillFinished();
|
return false;
|
}
|
|
return true;
|
}
|
|
return false;
|
}
|
|
|
// 强制结束技能:立即结束所有技能相关的处理
|
public virtual void ForceFinished()
|
{
|
skillEffect?.ForceFinished();
|
|
otherSkillActionList.ForEach(action => action.ForceFinish());
|
otherSkillActionList.Clear();
|
|
isFinished = true;
|
moveFinished = true;
|
isPlay = true;
|
|
// 处理所有剩余包
|
while (packList.Count > 0)
|
{
|
var pack = packList[0];
|
packList.RemoveAt(0);
|
|
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();
|
PackageRegedit.Distribute(pack);
|
}
|
}
|
}
|
|
// 技能完成处理:正常完成时的清理工作
|
public void OnSkillFinished()
|
{
|
// 修复:使用循环代替递归,避免栈溢出风险
|
// try
|
// {
|
while (true)
|
{
|
// 验证技能效果是否完成
|
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; // 没有更多需要处理的,退出循环
|
}
|
|
// 处理剩余包
|
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;
|
}
|
}
|
|
// 同时刷新所有对象的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);
|
}
|
}
|
|
return true;
|
}
|
|
// 添加清理方法:防止内存泄漏
|
public virtual void Cleanup()
|
{
|
tempDropList?.Clear();
|
tempDeadPackList?.Clear();
|
otherSkillActionList?.Clear();
|
dropPackList?.Clear();
|
expPackList?.Clear();
|
|
skillEffect = null;
|
packList = null;
|
}
|
}
|