fix(hero): 修复DamageQueueComp中caster可能为null时的错误
当caster或caster.ent为null时,使用可选链操作符和空值合并运算符提供默认值,避免生成eventId时出现错误
This commit is contained in:
@@ -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, // 深拷贝属性数据
|
||||
|
||||
Reference in New Issue
Block a user