feat(技能系统): 添加施法者实体ID字段用于安全校验

在SDataCom组件中添加casterEid字段,并在Skill和SkillView中使用该字段替代原有的链式访问,提高代码安全性和可读性
This commit is contained in:
walkpan
2026-01-06 14:20:45 +08:00
parent a32aa5ad08
commit 31321a1a45
3 changed files with 4 additions and 1 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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';