From a32aa5ad08b7d675c4dbc9b6df50193a59276f6f Mon Sep 17 00:00:00 2001 From: walkpan Date: Tue, 6 Jan 2026 12:14:14 +0800 Subject: [PATCH] =?UTF-8?q?fix(hero):=20=E4=BF=AE=E5=A4=8DDamageQueueComp?= =?UTF-8?q?=E4=B8=ADcaster=E5=8F=AF=E8=83=BD=E4=B8=BAnull=E6=97=B6?= =?UTF-8?q?=E7=9A=84=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 当caster或caster.ent为null时,使用可选链操作符和空值合并运算符提供默认值,避免生成eventId时出现错误 --- assets/script/game/hero/DamageQueueComp.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/assets/script/game/hero/DamageQueueComp.ts b/assets/script/game/hero/DamageQueueComp.ts index 36112a41..95d4289d 100644 --- a/assets/script/game/hero/DamageQueueComp.ts +++ b/assets/script/game/hero/DamageQueueComp.ts @@ -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, // 深拷贝属性数据