refactor(伤害系统): 将caster从HeroViewComp改为使用casterEid
统一伤害系统中施法者的标识方式,从直接使用HeroViewComp改为使用实体ID(casterEid) 修复反伤逻辑中可能存在的空指针问题
This commit is contained in:
@@ -10,8 +10,8 @@ export interface DamageEvent {
|
|||||||
/** 伤害属性数据 */
|
/** 伤害属性数据 */
|
||||||
Attrs: any;
|
Attrs: any;
|
||||||
|
|
||||||
/** 施法者 */
|
/** 施法者ID */
|
||||||
caster: HeroViewComp;
|
casterEid: number;
|
||||||
|
|
||||||
/** 技能UUID */
|
/** 技能UUID */
|
||||||
s_uuid: number;
|
s_uuid: number;
|
||||||
@@ -58,14 +58,13 @@ export class DamageQueueComp extends ecs.Comp {
|
|||||||
/**
|
/**
|
||||||
* 添加伤害事件到队列
|
* 添加伤害事件到队列
|
||||||
*/
|
*/
|
||||||
addDamageEvent(attrs: any, caster: HeroViewComp, s_uuid: number,ext_dmg:number=0,dmg_ratio:number=1): void {
|
addDamageEvent(attrs: any, casterEid: number, s_uuid: number,ext_dmg:number=0,dmg_ratio:number=1): void {
|
||||||
const timestamp = Date.now();
|
const timestamp = Date.now();
|
||||||
const casterEid = caster?.ent?.eid ?? -1;
|
|
||||||
const eventId = `${casterEid}_${s_uuid}_${timestamp}_${Math.random()}`;
|
const eventId = `${casterEid}_${s_uuid}_${timestamp}_${Math.random()}`;
|
||||||
|
|
||||||
const damageEvent: DamageEvent = {
|
const damageEvent: DamageEvent = {
|
||||||
Attrs: attrs ? { ...attrs } : null, // 深拷贝属性数据
|
Attrs: attrs ? { ...attrs } : null, // 深拷贝属性数据
|
||||||
caster: caster,
|
casterEid: casterEid,
|
||||||
s_uuid: s_uuid,
|
s_uuid: s_uuid,
|
||||||
timestamp: timestamp,
|
timestamp: timestamp,
|
||||||
eventId: eventId,
|
eventId: eventId,
|
||||||
@@ -161,7 +160,7 @@ export class DamageQueueHelper {
|
|||||||
* 为实体添加伤害事件
|
* 为实体添加伤害事件
|
||||||
* 如果实体没有伤害队列组件,会自动创建
|
* 如果实体没有伤害队列组件,会自动创建
|
||||||
*/
|
*/
|
||||||
static addDamageToEntity(entity: ecs.Entity, attrs: any, caster: HeroViewComp, s_uuid: number,ext_dmg:number=0,dmg_ratio:number=1): void {
|
static addDamageToEntity(entity: ecs.Entity, attrs: any, casterEid: number, s_uuid: number,ext_dmg:number=0,dmg_ratio:number=1): void {
|
||||||
let damageQueue = entity.get(DamageQueueComp);
|
let damageQueue = entity.get(DamageQueueComp);
|
||||||
|
|
||||||
// 如果实体没有伤害队列组件,创建一个
|
// 如果实体没有伤害队列组件,创建一个
|
||||||
@@ -170,7 +169,7 @@ export class DamageQueueHelper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 添加伤害事件到队列
|
// 添加伤害事件到队列
|
||||||
damageQueue.addDamageEvent(attrs, caster, s_uuid,ext_dmg,dmg_ratio);
|
damageQueue.addDamageEvent(attrs, casterEid, s_uuid,ext_dmg,dmg_ratio);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -130,8 +130,9 @@ export class HeroAtkSystem extends ecs.ComblockSystem implements ecs.ISystemUpd
|
|||||||
}
|
}
|
||||||
if (!TAttrsComp || TAttrsComp.is_dead || TAttrsComp.is_reviving) return reDate;
|
if (!TAttrsComp || TAttrsComp.is_dead || TAttrsComp.is_reviving) return reDate;
|
||||||
|
|
||||||
const caster = damageEvent.caster;
|
const casterEid = damageEvent.casterEid;
|
||||||
const CAttrsComp = caster?.ent?.get(HeroAttrsComp);
|
const caster = ecs.getEntityByEid(casterEid);
|
||||||
|
const CAttrsComp = caster?.get(HeroAttrsComp);
|
||||||
|
|
||||||
// 获取技能配置
|
// 获取技能配置
|
||||||
const skillConf = SkillSet[damageEvent.s_uuid];
|
const skillConf = SkillSet[damageEvent.s_uuid];
|
||||||
@@ -186,12 +187,11 @@ export class HeroAtkSystem extends ecs.ComblockSystem implements ecs.ISystemUpd
|
|||||||
|
|
||||||
smc.updateHeroInfo(TAttrsComp); // 更新英雄数据到 VM
|
smc.updateHeroInfo(TAttrsComp); // 更新英雄数据到 VM
|
||||||
if (this.debugMode) {
|
if (this.debugMode) {
|
||||||
const casterName = damageEvent.caster?.ent?.get(HeroAttrsComp)?.hero_name || "未知";
|
const casterName = CAttrsComp?.hero_name || "未知";
|
||||||
const casterUuid = damageEvent.caster?.ent?.get(HeroAttrsComp)?.hero_uuid || 0;
|
console.log(`[HeroAtkSystem] 英雄${TAttrsComp.hero_name} (uuid: ${TAttrsComp.hero_uuid}) 受到 ${casterName}(eid: ${casterEid})的 伤害 ${damage},${isCrit?"暴击":"普通"}攻击,技能ID ${damageEvent.s_uuid}`);
|
||||||
console.log(`[HeroAtkSystem] 英雄${TAttrsComp.hero_name} (uuid: ${TAttrsComp.hero_uuid}) 受到 ${casterName}(uuid: ${casterUuid})的 伤害 ${damage},${isCrit?"暴击":"普通"}攻击,技能ID ${damageEvent.s_uuid}`);
|
|
||||||
}
|
}
|
||||||
//反伤判定 并应用到施法者
|
//反伤判定 并应用到施法者
|
||||||
this.check_thorns(TAttrsComp, caster?.ent,damage);
|
this.check_thorns(TAttrsComp, caster, damage);
|
||||||
// 击退判定
|
// 击退判定
|
||||||
// 使用施法者的击退概率属性(damageEvent.Attrs 快照) - 被攻击者的控制抗性
|
// 使用施法者的击退概率属性(damageEvent.Attrs 快照) - 被攻击者的控制抗性
|
||||||
// 击退成功后需要清理施法者的相关天赋buff
|
// 击退成功后需要清理施法者的相关天赋buff
|
||||||
@@ -249,7 +249,8 @@ export class HeroAtkSystem extends ecs.ComblockSystem implements ecs.ISystemUpd
|
|||||||
}
|
}
|
||||||
check_thorns(TAttrsComp:HeroAttrsComp, caster: ecs.Entity, damage:number) {
|
check_thorns(TAttrsComp:HeroAttrsComp, caster: ecs.Entity, damage:number) {
|
||||||
// 检查目标是否有反伤属性,这里受伤的时时施法者
|
// 检查目标是否有反伤属性,这里受伤的时时施法者
|
||||||
if (!caster||damage<=0) return;
|
// 修复:如果施法者已销毁(caster为空),则不执行反伤逻辑
|
||||||
|
if (!caster || damage<=0) return;
|
||||||
let thornsDamage=0;
|
let thornsDamage=0;
|
||||||
thornsDamage=TAttrsComp.Attrs[Attrs.THORNS]||0+TAttrsComp.useCountValTal(Attrs.THORNS);
|
thornsDamage=TAttrsComp.Attrs[Attrs.THORNS]||0+TAttrsComp.useCountValTal(Attrs.THORNS);
|
||||||
let CAttrs=caster.get(HeroAttrsComp);
|
let CAttrs=caster.get(HeroAttrsComp);
|
||||||
|
|||||||
@@ -163,7 +163,7 @@ export class SkillView extends CCComp {
|
|||||||
DamageQueueHelper.addDamageToEntity(
|
DamageQueueHelper.addDamageToEntity(
|
||||||
target.ent,
|
target.ent,
|
||||||
this.sData.Attrs,
|
this.sData.Attrs,
|
||||||
this.sData.caster,
|
this.sData.casterEid,
|
||||||
this.sData.s_uuid,
|
this.sData.s_uuid,
|
||||||
this.sData.ext_dmg,
|
this.sData.ext_dmg,
|
||||||
this.sData.dmg_ratio,
|
this.sData.dmg_ratio,
|
||||||
|
|||||||
Reference in New Issue
Block a user