fix(07-04): #06-05-1 refresh final attributes without modifiers

- recalculateAttribute writes the base value into finalAttribute when no modifier is attached
- un-skip the base-only-change case; catchCalculateProgress is intentionally left untouched
This commit is contained in:
unanmed 2026-09-15 20:29:27 +08:00
parent 02786047d2
commit 04943416a5
2 changed files with 7 additions and 3 deletions

View File

@ -111,8 +111,8 @@ describe('HeroAttribute base and final values', () => {
expect(attribute.getFinalAttribute('atk')).toBe(15);
});
// 疑似 bug:无修饰器时 recalculateAttribute 提前返回,基础属性变化不反映到最终属性,详见 06-TEST-FINDINGS.md #06-05-1
it.skip('reflects base-only changes without any modifier', () => {
// 验证无修饰器时基础属性变化同步反映到最终属性(#06-05-1)
it('reflects base-only changes without any modifier', () => {
const attribute = createAttribute();
attribute.set('hp', 40);
attribute.add('hp', 5);

View File

@ -79,7 +79,11 @@ export class HeroAttribute<THero> implements IHeroAttribute<THero> {
*/
private recalculateAttribute<K extends keyof THero>(name: K): void {
const modifierList = this.modifier.get(name);
if (!modifierList) return;
if (!modifierList) {
// 无修饰器时 final 与 base 保持同值
this.finalAttribute[name] = this.attribute[name];
return;
}
const baseValue = this.attribute[name];
let value = baseValue;