From 31321a1a452d02bb9c5b358477e9a7c6c1e2a4d2 Mon Sep 17 00:00:00 2001 From: walkpan Date: Tue, 6 Jan 2026 14:20:45 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E6=8A=80=E8=83=BD=E7=B3=BB=E7=BB=9F):=20?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=96=BD=E6=B3=95=E8=80=85=E5=AE=9E=E4=BD=93?= =?UTF-8?q?ID=E5=AD=97=E6=AE=B5=E7=94=A8=E4=BA=8E=E5=AE=89=E5=85=A8?= =?UTF-8?q?=E6=A0=A1=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 在SDataCom组件中添加casterEid字段,并在Skill和SkillView中使用该字段替代原有的链式访问,提高代码安全性和可读性 --- assets/script/game/skill/SDataCom.ts | 2 ++ assets/script/game/skill/Skill.ts | 1 + assets/script/game/skill/SkillView.ts | 2 +- 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/assets/script/game/skill/SDataCom.ts b/assets/script/game/skill/SDataCom.ts index be6a8470..9a659067 100644 --- a/assets/script/game/skill/SDataCom.ts +++ b/assets/script/game/skill/SDataCom.ts @@ -9,6 +9,7 @@ export class SDataCom extends ecs.Comp { /** 业务层组件移除时,重置所有数据为默认值 */ Attrs:any=null caster:HeroViewComp=null + casterEid: number = -1; // 施法者实体ID,用于安全校验 group:BoxSet=BoxSet.HERO fac: number = 0; // 0:hero 1:monster s_uuid:number=0 @@ -21,6 +22,7 @@ export class SDataCom extends ecs.Comp { this.fac=0 this.s_uuid=0 this.caster=null + this.casterEid = -1; this.hit_count=0 this.ext_dmg=0 this.dmg_ratio=1 diff --git a/assets/script/game/skill/Skill.ts b/assets/script/game/skill/Skill.ts index cf21d022..4edc1efc 100644 --- a/assets/script/game/skill/Skill.ts +++ b/assets/script/game/skill/Skill.ts @@ -121,6 +121,7 @@ export class Skill extends ecs.Entity { sDataCom.reset(); sDataCom.group=caster.box_group sDataCom.caster=caster + sDataCom.casterEid=caster.ent.eid sDataCom.Attrs={...cAttrsComp.Attrs} sDataCom.s_uuid=s_uuid sDataCom.fac=cAttrsComp.fac diff --git a/assets/script/game/skill/SkillView.ts b/assets/script/game/skill/SkillView.ts index 3249c581..6c187342 100644 --- a/assets/script/game/skill/SkillView.ts +++ b/assets/script/game/skill/SkillView.ts @@ -59,7 +59,7 @@ export class SkillView extends CCComp { onBeginContact (seCol: Collider2D, oCol: Collider2D) { // 安全获取双方信息用于日志 const casterName = this.sData.caster?.ent?.get(HeroAttrsComp)?.hero_name ?? '未知施法者'; - const casterEid = this.sData.caster?.ent?.eid ?? '未知EID'; + const casterEid = this.sData.casterEid; const targetView = oCol.getComponent(HeroViewComp); const targetName = targetView?.ent?.get(HeroAttrsComp)?.hero_name ?? '非英雄对象'; const targetEid = targetView?.ent?.eid ?? '未知EID';