From d40cb26819b7f2821dd9b3f1d773b80fe39d04d1 Mon Sep 17 00:00:00 2001 From: panw Date: Mon, 2 Feb 2026 16:56:05 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E4=B8=BB=E8=A7=92?= =?UTF-8?q?=E5=AE=9E=E4=BD=93=E5=BC=95=E7=94=A8=E5=B9=B6=E7=A1=AE=E4=BF=9D?= =?UTF-8?q?=E8=B7=A8=E5=B1=80=E9=87=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 在 SingletonModuleComp 中添加 role 字段存储主角实体引用,并在 MissionComp 任务开始时重置引用,在 Hero 销毁时清理引用。避免跨局数据残留导致引用错误。 --- assets/script/game/common/SingletonModuleComp.ts | 3 +++ assets/script/game/hero/Hero.ts | 6 ++++++ assets/script/game/map/MissionComp.ts | 3 +++ 3 files changed, 12 insertions(+) diff --git a/assets/script/game/common/SingletonModuleComp.ts b/assets/script/game/common/SingletonModuleComp.ts index a4b13dd6..3389fe12 100644 --- a/assets/script/game/common/SingletonModuleComp.ts +++ b/assets/script/game/common/SingletonModuleComp.ts @@ -153,6 +153,9 @@ export class SingletonModuleComp extends ecs.Comp { [Attrs.WFUNY]: [1, 0], // 风怒率 }; + /** 主角实体引用 */ + role: ecs.Entity | null = null; + /** * 记录天赋获取 * @param id 天赋ID diff --git a/assets/script/game/hero/Hero.ts b/assets/script/game/hero/Hero.ts index d8d5084e..eafbf1f5 100644 --- a/assets/script/game/hero/Hero.ts +++ b/assets/script/game/hero/Hero.ts @@ -31,6 +31,11 @@ export class Hero extends ecs.Entity { } destroy(): void { + // 如果是主角,清理全局引用 + if (smc.role === this) { + smc.role = null; + } + // 销毁节点,防止视觉残留 const view = this.get(HeroViewComp); if (view && view.node && view.node.isValid) { @@ -86,6 +91,7 @@ export class Hero extends ecs.Entity { model.rangeType = hero.rangeType; // 只有主角才挂载天赋组件 if (is_master) { + smc.role = this; // 记录主角实体引用 this.add(TalComp); const talComp = this.get(TalComp); if (talComp) { diff --git a/assets/script/game/map/MissionComp.ts b/assets/script/game/map/MissionComp.ts index 30d65f3e..f791b713 100644 --- a/assets/script/game/map/MissionComp.ts +++ b/assets/script/game/map/MissionComp.ts @@ -272,6 +272,9 @@ do_ad(){ this.revive_times = 1; // 每次任务开始重置复活次数 this.spawnedSpecialIndices.clear(); // 重置特殊刷怪记录 + // 重置全局属性加成和主角引用 (确保新一局数据干净) + smc.role = null; + // 重置英雄数据,确保新一局是初始状态 smc.vmdata.hero = { name:'',