fix(hero): 修复DamageQueueComp中caster可能为null时的错误

当caster或caster.ent为null时,使用可选链操作符和空值合并运算符提供默认值,避免生成eventId时出现错误
This commit is contained in:
walkpan
2026-01-06 12:14:14 +08:00
parent c9b1583cd2
commit a32aa5ad08

View File

@@ -60,7 +60,8 @@ export class DamageQueueComp extends ecs.Comp {
*/
addDamageEvent(attrs: any, caster: HeroViewComp, s_uuid: number,ext_dmg:number=0,dmg_ratio:number=1): void {
const timestamp = Date.now();
const eventId = `${caster.ent.eid}_${s_uuid}_${timestamp}_${Math.random()}`;
const casterEid = caster?.ent?.eid ?? -1;
const eventId = `${casterEid}_${s_uuid}_${timestamp}_${Math.random()}`;
const damageEvent: DamageEvent = {
Attrs: attrs ? { ...attrs } : null, // 深拷贝属性数据