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:
parent
f6275f4501
commit
cf2605fa4a
11 changed files with 1089 additions and 53 deletions
|
|
@ -181,6 +181,76 @@ public sealed class LocalPlayerState
|
|||
public AttributeSnapshot? GetAttribute(AttributeKind kind) =>
|
||||
_attrs.TryGetValue(kind, out var a) ? a : null;
|
||||
|
||||
/// <summary>The optional wired spellbook — read-only exposure of the same
|
||||
/// reference passed to the constructor. Issue #267: lets presentation
|
||||
/// code (e.g. <c>CharacterSheetProvider</c>) subscribe to
|
||||
/// <see cref="Spells.Spellbook.EnchantmentsChanged"/> for live character-sheet
|
||||
/// refresh without duplicating the reference in its own constructor.</summary>
|
||||
public Spellbook? Spellbook => _spellbook;
|
||||
|
||||
/// <summary>
|
||||
/// Issue #267 — effective (post-buff) primary-attribute value. Retail
|
||||
/// <c>CACQualities::EnchantAttribute</c> (0x00594570): primary attributes
|
||||
/// do NOT receive vitae (only <see cref="GetMaxApprox"/>'s secondary
|
||||
/// attributes and <see cref="GetEffectiveSkill"/>'s skills do). Returns
|
||||
/// the unenchanted base when no spellbook is wired (back-compat) or the
|
||||
/// attribute hasn't arrived yet.
|
||||
/// </summary>
|
||||
public int? GetEffectiveAttribute(AttributeKind kind)
|
||||
{
|
||||
AttributeSnapshot? attr = GetAttribute(kind);
|
||||
if (attr is null) return null;
|
||||
uint baseValue = attr.Value.Current;
|
||||
if (_spellbook is null) return (int)baseValue;
|
||||
EnchantmentMath.VitalMod mod = _spellbook.GetAttributeMod(AttributeKindToId(kind));
|
||||
return EnchantmentMath.EnchantAttribute(mod, baseValue);
|
||||
}
|
||||
|
||||
/// <summary>Reverse of <see cref="AttributeIdToKind"/> — the wire
|
||||
/// PropertyAttribute id (1..6) for a given <see cref="AttributeKind"/>.</summary>
|
||||
public static uint AttributeKindToId(AttributeKind kind) => kind switch
|
||||
{
|
||||
AttributeKind.Strength => 1u,
|
||||
AttributeKind.Endurance => 2u,
|
||||
AttributeKind.Quickness => 3u,
|
||||
AttributeKind.Coordination => 4u,
|
||||
AttributeKind.Focus => 5u,
|
||||
AttributeKind.Self => 6u,
|
||||
_ => 0u,
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Issue #267 — effective (post-vitae, post-buff) skill level. Retail
|
||||
/// <c>CACQualities::EnchantSkill</c> (0x005947b0). Returns the
|
||||
/// unenchanted base when no spellbook is wired (back-compat) or the
|
||||
/// skill hasn't arrived yet.
|
||||
/// </summary>
|
||||
public int? GetEffectiveSkill(uint skillId)
|
||||
{
|
||||
SkillSnapshot? skill = GetSkill(skillId);
|
||||
if (skill is null) return null;
|
||||
uint baseValue = skill.Value.CurrentLevel;
|
||||
if (_spellbook is null) return (int)baseValue;
|
||||
EnchantmentMath.VitalMod mod = _spellbook.GetSkillMod(skillId);
|
||||
return EnchantmentMath.EnchantSkill(mod, baseValue);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Issue #267 — vitae's isolated contribution to a skill's effective
|
||||
/// level (retail <c>SkillInfoRegion::GetVitaeModifier</c> 0x004f0fa0),
|
||||
/// separate from any buff delta. Always ≤ 0. Returns 0 when no spellbook
|
||||
/// is wired, no vitae is active, or the skill hasn't arrived yet.
|
||||
/// </summary>
|
||||
public int GetSkillVitaeModifier(uint skillId)
|
||||
{
|
||||
if (_spellbook is null) return 0;
|
||||
SkillSnapshot? skill = GetSkill(skillId);
|
||||
if (skill is null) return 0;
|
||||
return EnchantmentMath.SkillVitaeModifier(
|
||||
_spellbook.ActiveEnchantments,
|
||||
skill.Value.CurrentLevel);
|
||||
}
|
||||
|
||||
/// <summary>Snapshot of the local player's current property bundle.</summary>
|
||||
public PropertyBundle Properties => _properties;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace AcDream.Core.Spells;
|
||||
|
|
@ -65,6 +66,35 @@ public static class EnchantmentMath
|
|||
public static readonly VitalMod Identity = new(1.0f, 0.0f);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retail <c>EnchantmentTypeFlags</c> — the low "StatTypes" byte of the
|
||||
/// wire <c>StatMod.type</c> field, distinguishing which domain a
|
||||
/// mult/add enchantment record targets. Verified against
|
||||
/// <c>references/ACE/Source/ACE.Entity/Enum/EnchantmentTypeFlags.cs</c>
|
||||
/// and the <c>type</c> argument literals passed to
|
||||
/// <c>CEnchantmentRegistry::CullEnchantmentsFromList</c> inside
|
||||
/// <c>EnchantAttribute</c> (0x00594570, type=1),
|
||||
/// <c>EnchantAttribute2nd</c> (0x00594670, type=2), and
|
||||
/// <c>EnchantSkill</c> (0x005947b0, type=0x10).
|
||||
/// </summary>
|
||||
[Flags]
|
||||
public enum EnchantmentTypeFlag : uint
|
||||
{
|
||||
/// <summary>Primary attribute (Strength/Endurance/Coordination/
|
||||
/// Quickness/Focus/Self). <c>CEnchantmentRegistry::EnchantAttribute</c>
|
||||
/// filters on this bit and does NOT reference the vitae singleton.</summary>
|
||||
Attribute = 0x0000001,
|
||||
|
||||
/// <summary>Secondary attribute — vital max (MaxHealth/MaxStamina/
|
||||
/// MaxMana). <c>EnchantAttribute2nd</c> filters on this bit and DOES
|
||||
/// apply vitae first.</summary>
|
||||
SecondAtt = 0x0000002,
|
||||
|
||||
/// <summary>Skill. <c>EnchantSkill</c> filters on this bit and DOES
|
||||
/// apply vitae first.</summary>
|
||||
Skill = 0x0000010,
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Compute the combined buff modifier for a given stat key from
|
||||
/// the player's active enchantments. Returns <see cref="VitalMod.Identity"/>
|
||||
|
|
@ -77,10 +107,22 @@ public static class EnchantmentMath
|
|||
/// <param name="statKey">Target stat key (ACE
|
||||
/// <c>PropertyAttribute2nd</c> enum value: 1=MaxHealth,
|
||||
/// 3=MaxStamina, 5=MaxMana).</param>
|
||||
/// <param name="requiredType">When non-null, mult/add records must also
|
||||
/// carry this bit in their wire <c>StatModType</c> to contribute — this
|
||||
/// is what keeps a Strength buff (Attribute, key=1) from leaking into a
|
||||
/// MaxHealth (SecondAtt, key=1) computation just because the numeric key
|
||||
/// happens to collide. <c>null</c> preserves the original no-type-filter
|
||||
/// behavior (existing <see cref="Spellbook.GetVitalMod"/> callers).</param>
|
||||
/// <param name="includeVitae">Whether the vitae singleton (Bucket 4)
|
||||
/// contributes. Retail's <c>EnchantAttribute</c> never references vitae
|
||||
/// at all (primary attributes are vitae-immune); pass <c>false</c> for
|
||||
/// that domain. Defaults to <c>true</c>, matching every existing caller.</param>
|
||||
public static VitalMod GetMod(
|
||||
IEnumerable<ActiveEnchantmentRecord> enchantments,
|
||||
SpellTable table,
|
||||
uint statKey)
|
||||
uint statKey,
|
||||
EnchantmentTypeFlag? requiredType = null,
|
||||
bool includeVitae = true)
|
||||
{
|
||||
// Family-stacking: bucket the active enchantments by Family and
|
||||
// keep the strongest one per bucket (the one with the largest
|
||||
|
|
@ -121,17 +163,24 @@ public static class EnchantmentMath
|
|||
// Vitae (bucket 4) is a special-case singleton on
|
||||
// CEnchantmentRegistry._vitae and applies its multiplier
|
||||
// to ALL vitals regardless of StatModKey (retail uses
|
||||
// key=0 as "any vital"). Apply unconditionally and skip
|
||||
// the per-key check.
|
||||
// key=0 as "any vital"). Apply unconditionally (subject only
|
||||
// to includeVitae — EnchantAttribute never references vitae
|
||||
// at all) and skip the per-key check.
|
||||
if (ench.Bucket == 4)
|
||||
{
|
||||
vitae *= val;
|
||||
if (includeVitae) vitae *= val;
|
||||
continue;
|
||||
}
|
||||
|
||||
// Multiplicative + Additive buffs filter by stat key —
|
||||
// only those targeting the requested vital contribute.
|
||||
if (ench.StatModKey is not uint key || key != statKey) continue;
|
||||
// Domain filter: a numeric key can collide across Attribute /
|
||||
// SecondAtt / Skill (e.g. key=1 is both Strength and MaxHealth).
|
||||
// requiredType disambiguates using the wire StatModType bits.
|
||||
if (requiredType is EnchantmentTypeFlag type
|
||||
&& (ench.StatModType.GetValueOrDefault() & (uint)type) == 0)
|
||||
continue;
|
||||
switch (ench.Bucket)
|
||||
{
|
||||
case 1: multiplier *= val; break;
|
||||
|
|
@ -139,14 +188,90 @@ public static class EnchantmentMath
|
|||
// Bucket 8 (Cooldown) doesn't affect vital max.
|
||||
}
|
||||
}
|
||||
// Vitae is applied multiplicatively last per retail
|
||||
// CEnchantmentRegistry::EnchantAttribute behaviour.
|
||||
// Vitae is applied multiplicatively before the buff lists per retail
|
||||
// CEnchantmentRegistry::EnchantAttribute2nd (0x00594670) / EnchantSkill
|
||||
// (0x005947b0) — both apply `_vitae` to the base value first, then run
|
||||
// the mult/add culled list on top. Multiplication is commutative, so
|
||||
// folding vitae into `multiplier` here is equivalent regardless of
|
||||
// includeVitae being honored above. Retail's primary-attribute sibling
|
||||
// (EnchantAttribute, 0x00594570) never references `_vitae` at all —
|
||||
// callers pass includeVitae:false for that domain.
|
||||
multiplier *= vitae;
|
||||
return multiplier == 1.0f && additive == 0.0f
|
||||
? VitalMod.Identity
|
||||
: new VitalMod(multiplier, additive);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retail <c>CEnchantmentRegistry::EnchantAttribute</c> (0x00594570) final
|
||||
/// composition step: apply the aggregated mult/add modifier (from
|
||||
/// <see cref="GetMod"/> with <see cref="EnchantmentTypeFlag.Attribute"/>
|
||||
/// and <c>includeVitae:false</c>) to the base value, floor the result at 1
|
||||
/// when the base is below 10 or at 10 otherwise, then truncate to an int
|
||||
/// (retail <c>_ftol2</c>, C# <c>(int)</c> cast — both truncate toward
|
||||
/// zero). Primary attributes are vitae-immune in retail; only buffs move
|
||||
/// this number.
|
||||
/// </summary>
|
||||
public static int EnchantAttribute(VitalMod mod, uint baseValue)
|
||||
{
|
||||
float value = (baseValue * mod.Multiplier) + mod.Additive;
|
||||
float floor = baseValue < 10u ? 1f : 10f;
|
||||
if (value < floor) value = floor;
|
||||
return (int)value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retail <c>CEnchantmentRegistry::EnchantSkill</c> (0x005947b0) final
|
||||
/// composition step: apply the aggregated (vitae-inclusive) mult/add
|
||||
/// modifier from <see cref="GetMod"/> (with
|
||||
/// <see cref="EnchantmentTypeFlag.Skill"/>, <c>includeVitae:true</c>) to
|
||||
/// the base value, zero-floor when the result drops below 0.5, then
|
||||
/// truncate to an int.
|
||||
/// </summary>
|
||||
public static int EnchantSkill(VitalMod mod, uint baseValue)
|
||||
{
|
||||
float value = (baseValue * mod.Multiplier) + mod.Additive;
|
||||
if (value < 0.5f) value = 0f;
|
||||
return (int)value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Isolated vitae multiplier — retail's <c>CEnchantmentRegistry::_vitae</c>
|
||||
/// singleton applied WITHOUT the mult/add buff lists. Returns <c>1.0</c>
|
||||
/// (no penalty) when no vitae enchantment is active. Vitae is never
|
||||
/// subject to family-stacking dedup in retail (there is exactly one
|
||||
/// <c>_vitae</c> field, never a list), so this scans directly rather than
|
||||
/// routing through <see cref="GetMod"/>'s family-stacking pass.
|
||||
/// </summary>
|
||||
public static float GetVitaeMultiplier(IEnumerable<ActiveEnchantmentRecord> enchantments)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(enchantments);
|
||||
float vitae = 1.0f;
|
||||
foreach (ActiveEnchantmentRecord ench in enchantments)
|
||||
{
|
||||
if (ench.Bucket == 4 && ench.StatModValue is float val)
|
||||
vitae *= val;
|
||||
}
|
||||
return vitae;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retail <c>SkillInfoRegion::GetVitaeModifier</c> (0x004f0fa0): the
|
||||
/// vitae-only contribution to a skill's effective level, reported in
|
||||
/// isolation from any buffs — <c>truncate(base × vitaeMult) − base</c>,
|
||||
/// always ≤ 0 (vitae is a strict penalty). This is the exact number the
|
||||
/// retail Character window shows in the vitae-specific footer
|
||||
/// parenthetical (e.g. <c>"(-100)"</c>), separate from any buff delta.
|
||||
/// </summary>
|
||||
public static int SkillVitaeModifier(
|
||||
IEnumerable<ActiveEnchantmentRecord> enchantments,
|
||||
uint baseValue)
|
||||
{
|
||||
float vitae = GetVitaeMultiplier(enchantments);
|
||||
if (vitae == 1.0f) return 0;
|
||||
return (int)(baseValue * vitae) - (int)baseValue;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Stat-key constants matching ACE <c>PropertyAttribute2nd</c>
|
||||
/// (verified against <c>docs/research/named-retail/acclient.h</c>
|
||||
|
|
|
|||
|
|
@ -24,6 +24,8 @@ public sealed class Spellbook
|
|||
private readonly Dictionary<uint, ActiveEnchantmentRecord> _activeById = new();
|
||||
private readonly Dictionary<uint, List<uint>> _enchantmentOrderByBucket = new();
|
||||
private readonly Dictionary<uint, EnchantmentMath.VitalMod> _vitalModCache = new();
|
||||
private readonly Dictionary<uint, EnchantmentMath.VitalMod> _attributeModCache = new();
|
||||
private readonly Dictionary<uint, EnchantmentMath.VitalMod> _skillModCache = new();
|
||||
private readonly List<uint>[] _favoriteSpells = Enumerable.Range(0, 8)
|
||||
.Select(_ => new List<uint>()).ToArray();
|
||||
private readonly Dictionary<uint, uint> _desiredComponents = new();
|
||||
|
|
@ -102,6 +104,61 @@ public sealed class Spellbook
|
|||
return calculated;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Issue #267 — combined buff modifier for a primary attribute
|
||||
/// (Strength/Endurance/Coordination/Quickness/Focus/Self; ACE
|
||||
/// <c>PropertyAttribute</c> id 1-6). Retail
|
||||
/// <c>CEnchantmentRegistry::EnchantAttribute</c> (0x00594570) never
|
||||
/// references the vitae singleton, so this excludes vitae —
|
||||
/// primary attributes are vitae-immune in retail. Feed the result
|
||||
/// through <see cref="EnchantmentMath.EnchantAttribute"/> with the
|
||||
/// base value to get the final displayed int.
|
||||
/// </summary>
|
||||
public EnchantmentMath.VitalMod GetAttributeMod(uint attributeId)
|
||||
{
|
||||
if (_attributeModCache.TryGetValue(
|
||||
attributeId,
|
||||
out EnchantmentMath.VitalMod cached))
|
||||
{
|
||||
return cached;
|
||||
}
|
||||
|
||||
EnchantmentMath.VitalMod calculated = EnchantmentMath.GetMod(
|
||||
ActiveEnchantments,
|
||||
_table,
|
||||
attributeId,
|
||||
EnchantmentMath.EnchantmentTypeFlag.Attribute,
|
||||
includeVitae: false);
|
||||
_attributeModCache.Add(attributeId, calculated);
|
||||
return calculated;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Issue #267 — combined (vitae-inclusive) buff modifier for a skill
|
||||
/// (ACE <c>SkillId</c>). Retail <c>CEnchantmentRegistry::EnchantSkill</c>
|
||||
/// (0x005947b0) applies the vitae singleton before the mult/add buff
|
||||
/// lists. Feed the result through <see cref="EnchantmentMath.EnchantSkill"/>
|
||||
/// with the base skill level to get the final displayed int.
|
||||
/// </summary>
|
||||
public EnchantmentMath.VitalMod GetSkillMod(uint skillId)
|
||||
{
|
||||
if (_skillModCache.TryGetValue(
|
||||
skillId,
|
||||
out EnchantmentMath.VitalMod cached))
|
||||
{
|
||||
return cached;
|
||||
}
|
||||
|
||||
EnchantmentMath.VitalMod calculated = EnchantmentMath.GetMod(
|
||||
ActiveEnchantments,
|
||||
_table,
|
||||
skillId,
|
||||
EnchantmentMath.EnchantmentTypeFlag.Skill,
|
||||
includeVitae: true);
|
||||
_skillModCache.Add(skillId, calculated);
|
||||
return calculated;
|
||||
}
|
||||
|
||||
/// <summary>Fires when a spell is added to the player's spellbook.</summary>
|
||||
public event Action<uint>? SpellLearned;
|
||||
|
||||
|
|
@ -356,6 +413,8 @@ public sealed class Spellbook
|
|||
_activeById.Clear();
|
||||
_enchantmentOrderByBucket.Clear();
|
||||
_vitalModCache.Clear();
|
||||
_attributeModCache.Clear();
|
||||
_skillModCache.Clear();
|
||||
foreach (ActiveEnchantmentRecord enchantment in enchantments)
|
||||
UpsertManifestEnchantment(enchantment);
|
||||
|
||||
|
|
@ -430,6 +489,8 @@ public sealed class Spellbook
|
|||
_activeById.Clear();
|
||||
_enchantmentOrderByBucket.Clear();
|
||||
_vitalModCache.Clear();
|
||||
_attributeModCache.Clear();
|
||||
_skillModCache.Clear();
|
||||
foreach (List<uint> tab in _favoriteSpells) tab.Clear();
|
||||
_desiredComponents.Clear();
|
||||
_spellbookFilters = 0x3FFFu;
|
||||
|
|
@ -448,6 +509,8 @@ public sealed class Spellbook
|
|||
private void NotifyEnchantmentsChanged()
|
||||
{
|
||||
_vitalModCache.Clear();
|
||||
_attributeModCache.Clear();
|
||||
_skillModCache.Clear();
|
||||
EnchantmentsChanged?.Invoke();
|
||||
StateChanged?.Invoke();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue