fix(ui): #267 character panel reflects vitae/buffed skills and attributes

Retail CACQualities::EnchantAttribute (0x00594570), EnchantAttribute2nd
(0x00594670, already ported for #6), and EnchantSkill (0x005947b0) are the
three enchantment-composition functions the Character window's Attributes
and Skills tabs depend on. Primary attributes never reference the vitae
singleton in retail (only Attribute2nd/Skill do) — confirmed directly from
the decompiled function bodies, not assumed.

EnchantmentMath.GetMod gains requiredType/includeVitae parameters (default
to the prior behavior) so a numeric StatMod key collision across domains
(e.g. key=1 is both Strength and MaxHealth) can't leak a buff into the
wrong computation. Spellbook.GetAttributeMod/GetSkillMod and
LocalPlayerState.GetEffectiveAttribute/GetEffectiveSkill/
GetSkillVitaeModifier wire the retail chain through to the panel.
CharacterSheetProvider now reports the effective value as the main number
and CharacterSkill.CurrentLevel is no longer an alias of BaseLevel (this
also activates the previously-dead SkillValueColor buffed/debuffed row
coloring). CharacterStatController's footer-title parenthetical is cited
from gmAttributeUI::DisplaySelectionFooter_Attribute (0x0049d280) and
gmSkillUI::DisplaySelectionFooter_Trained (0x0049b860) +
SkillInfoRegion::GetVitaeModifier (0x004f0fa0): skills show up to two
segments (vitae's own contribution, then the buff-only residual), while
vitae-immune attributes show at most one; no parenthetical when the delta
is zero. The panel now refreshes on Spellbook.EnchantmentsChanged, not only
raw property/attribute updates.

Core goldens cover the user-reported 33% vitae example (303->203, "(-100)"
exactly), buff+vitae composition, and the attribute vitae-immunity finding.
Provider/controller tests cover the full row-click -> footer-title path and
live refresh. Full solution suite passes with zero failures.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
Erik 2026-07-30 18:08:55 +02:00
parent f6275f4501
commit cf2605fa4a
11 changed files with 1089 additions and 53 deletions

View file

@ -1,5 +1,6 @@
using AcDream.Core.Items;
using AcDream.Core.Player;
using AcDream.Core.Spells;
namespace AcDream.Core.Tests.Player;
@ -477,4 +478,117 @@ public sealed class LocalPlayerStateTests
Assert.Empty(s.Skills);
Assert.Empty(s.Properties.Ints);
}
// ── Issue #267 — effective attribute/skill values (vitae + buff aware) ──
[Fact]
public void GetEffectiveAttribute_NoSpellbook_ReturnsBaseValue()
{
var s = new LocalPlayerState(); // no spellbook wired — back-compat
s.OnAttributeUpdate(atType: 1u, ranks: 100u, start: 100u, xp: 0u); // Strength, base 200
Assert.Equal(200, s.GetEffectiveAttribute(LocalPlayerState.AttributeKind.Strength));
}
[Fact]
public void GetEffectiveAttribute_Unseen_ReturnsNull()
{
var s = new LocalPlayerState(new Spellbook());
Assert.Null(s.GetEffectiveAttribute(LocalPlayerState.AttributeKind.Strength));
}
[Fact]
public void GetEffectiveAttribute_VitaeActive_AttributesAreVitaeImmune()
{
// Retail CACQualities::EnchantAttribute (0x00594570) never references
// the vitae singleton — a 33% vitae penalty must NOT move Strength.
var book = new Spellbook(SpellTable.Create([TestSpell(1u), TestSpell(2u)]));
book.OnEnchantmentAdded(new ActiveEnchantmentRecord(
SpellId: 1u, LayerId: 1u, Duration: -1d, CasterGuid: 0u,
StatModType: 0u, StatModKey: 0u, StatModValue: 0.67f, Bucket: 4u));
var s = new LocalPlayerState(book);
s.OnAttributeUpdate(atType: 1u, ranks: 100u, start: 100u, xp: 0u); // Strength, base 200
Assert.Equal(200, s.GetEffectiveAttribute(LocalPlayerState.AttributeKind.Strength));
}
[Fact]
public void GetEffectiveAttribute_Buff_AppliesMultiplierAndTruncates()
{
var book = new Spellbook(SpellTable.Create([TestSpell(1u), TestSpell(2u)]));
book.OnEnchantmentAdded(new ActiveEnchantmentRecord(
SpellId: 2u, LayerId: 1u, Duration: 60d, CasterGuid: 0u,
StatModType: (uint)EnchantmentMath.EnchantmentTypeFlag.Attribute,
StatModKey: 1u /* Strength */, StatModValue: 1.1f, Bucket: 1u));
var s = new LocalPlayerState(book);
s.OnAttributeUpdate(atType: 1u, ranks: 100u, start: 100u, xp: 0u); // Strength, base 200
// 200 * 1.1 = 220.
Assert.Equal(220, s.GetEffectiveAttribute(LocalPlayerState.AttributeKind.Strength));
}
[Fact]
public void GetEffectiveSkill_NoSpellbook_ReturnsBaseValue()
{
var s = new LocalPlayerState();
s.OnSkillUpdate(skillId: 6u, ranks: 300u, status: 2u, xp: 0u,
init: 3u, resistance: 0u, lastUsed: 0d, formulaBonus: 0u); // base 303
Assert.Equal(303, s.GetEffectiveSkill(6u));
Assert.Equal(0, s.GetSkillVitaeModifier(6u));
}
[Fact]
public void GetEffectiveSkill_Unseen_ReturnsNull()
{
var s = new LocalPlayerState(new Spellbook());
Assert.Null(s.GetEffectiveSkill(6u));
}
[Fact]
public void GetEffectiveSkill_ThirtyThreePercentVitae_MatchesUserReportedGolden()
{
// User-reported oracle (ISSUES.md #267): a base-303 skill under 33%
// vitae shows the current (reduced) level with "(-100)" in parens.
var book = new Spellbook(SpellTable.Create([TestSpell(1u), TestSpell(2u)]));
book.OnEnchantmentAdded(new ActiveEnchantmentRecord(
SpellId: 1u, LayerId: 1u, Duration: -1d, CasterGuid: 0u,
StatModType: 0u, StatModKey: 0u, StatModValue: 0.67f, Bucket: 4u));
var s = new LocalPlayerState(book);
s.OnSkillUpdate(skillId: 6u, ranks: 300u, status: 2u, xp: 0u,
init: 3u, resistance: 0u, lastUsed: 0d, formulaBonus: 0u); // base 303
Assert.Equal(203, s.GetEffectiveSkill(6u));
Assert.Equal(-100, s.GetSkillVitaeModifier(6u));
}
[Fact]
public void GetEffectiveSkill_BuffPlusVitaeComposition()
{
var book = new Spellbook(SpellTable.Create([TestSpell(1u), TestSpell(2u)]));
book.OnEnchantmentAdded(new ActiveEnchantmentRecord(
SpellId: 1u, LayerId: 1u, Duration: -1d, CasterGuid: 0u,
StatModType: 0u, StatModKey: 0u, StatModValue: 0.67f, Bucket: 4u)); // 33% vitae
book.OnEnchantmentAdded(new ActiveEnchantmentRecord(
SpellId: 2u, LayerId: 2u, Duration: 60d, CasterGuid: 0u,
StatModType: (uint)EnchantmentMath.EnchantmentTypeFlag.Skill,
StatModKey: 6u, StatModValue: 50f, Bucket: 2u)); // +50 additive buff
var s = new LocalPlayerState(book);
s.OnSkillUpdate(skillId: 6u, ranks: 297u, status: 2u, xp: 0u,
init: 3u, resistance: 0u, lastUsed: 0d, formulaBonus: 0u); // base 300
// (300 * 0.67) + 50 = 201 + 50 = 251. Vitae-only contribution stays
// isolated at (300*0.67) - 300 = -99.
Assert.Equal(251, s.GetEffectiveSkill(6u));
Assert.Equal(-99, s.GetSkillVitaeModifier(6u));
}
/// <summary>Minimal SpellTable row — <see cref="EnchantmentMath.GetMod"/>'s
/// family-stacking pass skips any enchantment whose SpellId isn't in the
/// table, so vitae/buff test records need an entry here even with
/// Family=0 (no dedup bucket).</summary>
private static SpellMetadata TestSpell(uint spellId) => new(
spellId, "Test", "War Magic", 0u, 0u, "", 0f, 0,
false, false, "", 0, 0, 0u, 0, false, false, true,
0f, 0u, 0u, 0u, 0);
}