refactor(伤害系统): 将caster从HeroViewComp改为使用casterEid
统一伤害系统中施法者的标识方式,从直接使用HeroViewComp改为使用实体ID(casterEid) 修复反伤逻辑中可能存在的空指针问题
This commit is contained in:
@@ -130,8 +130,9 @@ export class HeroAtkSystem extends ecs.ComblockSystem implements ecs.ISystemUpd
|
||||
}
|
||||
if (!TAttrsComp || TAttrsComp.is_dead || TAttrsComp.is_reviving) return reDate;
|
||||
|
||||
const caster = damageEvent.caster;
|
||||
const CAttrsComp = caster?.ent?.get(HeroAttrsComp);
|
||||
const casterEid = damageEvent.casterEid;
|
||||
const caster = ecs.getEntityByEid(casterEid);
|
||||
const CAttrsComp = caster?.get(HeroAttrsComp);
|
||||
|
||||
// 获取技能配置
|
||||
const skillConf = SkillSet[damageEvent.s_uuid];
|
||||
@@ -186,12 +187,11 @@ export class HeroAtkSystem extends ecs.ComblockSystem implements ecs.ISystemUpd
|
||||
|
||||
smc.updateHeroInfo(TAttrsComp); // 更新英雄数据到 VM
|
||||
if (this.debugMode) {
|
||||
const casterName = damageEvent.caster?.ent?.get(HeroAttrsComp)?.hero_name || "未知";
|
||||
const casterUuid = damageEvent.caster?.ent?.get(HeroAttrsComp)?.hero_uuid || 0;
|
||||
console.log(`[HeroAtkSystem] 英雄${TAttrsComp.hero_name} (uuid: ${TAttrsComp.hero_uuid}) 受到 ${casterName}(uuid: ${casterUuid})的 伤害 ${damage},${isCrit?"暴击":"普通"}攻击,技能ID ${damageEvent.s_uuid}`);
|
||||
const casterName = CAttrsComp?.hero_name || "未知";
|
||||
console.log(`[HeroAtkSystem] 英雄${TAttrsComp.hero_name} (uuid: ${TAttrsComp.hero_uuid}) 受到 ${casterName}(eid: ${casterEid})的 伤害 ${damage},${isCrit?"暴击":"普通"}攻击,技能ID ${damageEvent.s_uuid}`);
|
||||
}
|
||||
//反伤判定 并应用到施法者
|
||||
this.check_thorns(TAttrsComp, caster?.ent,damage);
|
||||
this.check_thorns(TAttrsComp, caster, damage);
|
||||
// 击退判定
|
||||
// 使用施法者的击退概率属性(damageEvent.Attrs 快照) - 被攻击者的控制抗性
|
||||
// 击退成功后需要清理施法者的相关天赋buff
|
||||
@@ -249,7 +249,8 @@ export class HeroAtkSystem extends ecs.ComblockSystem implements ecs.ISystemUpd
|
||||
}
|
||||
check_thorns(TAttrsComp:HeroAttrsComp, caster: ecs.Entity, damage:number) {
|
||||
// 检查目标是否有反伤属性,这里受伤的时时施法者
|
||||
if (!caster||damage<=0) return;
|
||||
// 修复:如果施法者已销毁(caster为空),则不执行反伤逻辑
|
||||
if (!caster || damage<=0) return;
|
||||
let thornsDamage=0;
|
||||
thornsDamage=TAttrsComp.Attrs[Attrs.THORNS]||0+TAttrsComp.useCountValTal(Attrs.THORNS);
|
||||
let CAttrs=caster.get(HeroAttrsComp);
|
||||
|
||||
Reference in New Issue
Block a user