From c349319f7b9024a9e3492aa7667016b5b0313159 Mon Sep 17 00:00:00 2001 From: panw Date: Mon, 2 Feb 2026 16:33:55 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E5=A4=A9=E8=B5=8B?= =?UTF-8?q?=E5=B1=9E=E6=80=A7=E5=8A=A0=E6=88=90=E4=B8=8D=E7=94=9F=E6=95=88?= =?UTF-8?q?=E5=8F=8A=E5=85=A8=E5=B1=80=E6=95=B0=E6=8D=AE=E5=90=8C=E6=AD=A5?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修复 TalComp 中永久属性加成类型转换错误,导致天赋属性未正确应用 在 HeroAttrsComp 中添加属性变化后的全局数据同步调用 在 SingletonModuleComp 中确保英雄数据更新后触发 VM 响应 添加 GlobalAttrChange 事件枚举用于后续属性变更监听 --- assets/script/game/common/SingletonModuleComp.ts | 14 ++++++++++++++ assets/script/game/common/config/GameEvent.ts | 1 + assets/script/game/hero/HeroAttrsComp.ts | 2 ++ assets/script/game/hero/TalComp.ts | 7 ++++++- 4 files changed, 23 insertions(+), 1 deletion(-) diff --git a/assets/script/game/common/SingletonModuleComp.ts b/assets/script/game/common/SingletonModuleComp.ts index 91fecf9f..a4b13dd6 100644 --- a/assets/script/game/common/SingletonModuleComp.ts +++ b/assets/script/game/common/SingletonModuleComp.ts @@ -393,6 +393,20 @@ export class SingletonModuleComp extends ecs.Comp { h.speed = Math.floor(heroAttrs.Attrs[Attrs.SPEED] || 0); h.crt = Math.floor(heroAttrs.Attrs[Attrs.CRITICAL] || 0); h.as = Math.floor(heroAttrs.Attrs[Attrs.AS] || 0); + + // 强制触发 VM 更新 + // 如果 VM 监听的是 smc.vmdata.hero 的属性变化,上面的赋值应该有效。 + // 但如果 UI 绑定的是 hero 整体对象,或者因为深层监听问题,可能需要手动通知。 + // 为了保险,我们可以重新赋值一次(如果是对象引用可能不会触发),或者使用 VM 提供的 set 方法 + // 这里尝试直接重新赋值整个对象属性来触发更新,或者假设 VM 已经处理好了深层监听。 + // 如果 UI 没变,可能是 VM 没有检测到深层属性变化。 + + // 尝试手动通知或重新赋值关键路径 + // 注意:Oops Framework 的 VM 通常支持对象属性修改的监听,前提是初始化时已经建立了监听。 + // 这里我们尝试显式调用 VM.modify 来通知更新(如果有这个 API),或者重新赋值给 vmdata + + // 方案:重新设置 vmdata.hero 来触发根节点的更新通知 + this.vmdata.hero = h; } error(){ oops.gui.toast("数据处理异常,请重试或重新登录") diff --git a/assets/script/game/common/config/GameEvent.ts b/assets/script/game/common/config/GameEvent.ts index 133f4353..c4fda76c 100644 --- a/assets/script/game/common/config/GameEvent.ts +++ b/assets/script/game/common/config/GameEvent.ts @@ -71,4 +71,5 @@ export enum GameEvent { CallFriend = "CallFriend", UpdateCollection = "UpdateCollection", UpdateMissionGet = "UpdateMissionGet", + GlobalAttrChange = "GlobalAttrChange", } \ No newline at end of file diff --git a/assets/script/game/hero/HeroAttrsComp.ts b/assets/script/game/hero/HeroAttrsComp.ts index 04e66575..62f07094 100644 --- a/assets/script/game/hero/HeroAttrsComp.ts +++ b/assets/script/game/hero/HeroAttrsComp.ts @@ -104,6 +104,7 @@ export class HeroAttrsComp extends ecs.Comp { chance: 1, // 必中 }; this.addBuff(buffConf); + smc.updateHeroInfo(this); // 确保同步到全局数据 oops.gui.toast(attrCard.desc); } } @@ -306,6 +307,7 @@ export class HeroAttrsComp extends ecs.Comp { // 重新计算受影响的属性 this.recalculateSingleAttr(attrIndex); + smc.updateHeroInfo(this); // 确保同步到全局数据 } diff --git a/assets/script/game/hero/TalComp.ts b/assets/script/game/hero/TalComp.ts index bb5b5d70..d05a3f64 100644 --- a/assets/script/game/hero/TalComp.ts +++ b/assets/script/game/hero/TalComp.ts @@ -279,7 +279,12 @@ export class TalComp extends ecs.Comp { heroAttrs.addValueTal(talent.uuid, talent.attrs, talent.vType, talent.value + talent.value_add); break; case TalEffet.ATTR: //永久属性 - let b:BuffConf={buff:Attrs[TalAttrs[talent.attrs]],BType:talent.vType,value:talent.value,time:0, chance:100, } + // 修正:强制类型转换为 number (Attrs 是数字枚举) + let attrIndex = talent.attrs as unknown as number; + // 如果 TalAttrs 存在且需要映射,请取消注释下一行 + // attrIndex = Attrs[TalAttrs[talent.attrs]]; + + let b:BuffConf={buff:attrIndex, BType:talent.vType, value:talent.value + talent.value_add, time:0, chance:100 } heroAttrs.addBuff(b); break; }