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; }