feat(player): #5 PlayerDescription parser — Stam/Mana via attribute block
Visual-verified — Vitals window now shows three bars (HP/Stam/Mana)
with live values. Closes ISSUES.md #5; ~95% reading on Stam/Mana
traced to active buff multipliers, filed as #6.
Why the rewrite
The first attempt (commit d42bf57) routed PlayerDescription (0x0013)
through AppraiseInfoParser, trusting a misleading xmldoc claim.
Live diagnostics proved the format is wrong — ACE source
(GameEventPlayerDescription.WriteEventBody) hand-writes a body
distinct from IdentifyObjectResponse's AppraiseInfo: property
hashtables gated on DescriptionPropertyFlag, vector-flag-gated
attribute / skill / spell blocks, then a long options + inventory
trailer. Vitals only arrive via the attribute block at login.
Holtburger's events.rs:220-625 has the canonical client-side
unpacker; this commit ports the early-section walker through spells.
What landed
PlayerDescriptionParser.cs (new — 350 LOC):
Walks propertyFlags + weenieType, then property hashtables
(Int32/Int64/Bool/Double/String/Did/Iid) + Position table —
each gated on a property flag bit, header is `u16 count, u16
buckets`. Then vectorFlags + has_health + the attribute block
(primary attrs 1..6 = 12 B each, vitals 7..9 = 16 B with
`current`), then optional Skill + Spell tables. Stops cleanly
before the options/shortcuts/hotbars/inventory trailer (filed
as #7 — heuristic alignment search needed for gameplay_options).
PrivateUpdateVital.cs (new — 95 LOC):
Wire parsers for the GameMessage opcodes 0x02E7 (full snapshot)
and 0x02E9 (current-only delta), per holtburger UpdateVital +
UpdateVitalCurrent. WorldSession dispatches each to a session-
level event the GameWindow forwards into LocalPlayerState.
LocalPlayerState (full redesign):
VitalKind (Health/Stamina/Mana) + AttributeKind (six primary).
VitalSnapshot stores ranks/start/xp/current; AttributeSnapshot
stores ranks/start/xp with `Current = ranks+start` per
holtburger. GetMaxApprox computes the retail formula
vital.(ranks+start) + attribute_contribution
where the contribution is hardcoded from retail's
SecondaryAttributeTable: Endurance/2 for Health, Endurance for
Stamina, Self for Mana. Enchantment buffs not yet folded in
(filed as #6). VitalIdToKind now accepts both ID systems
(1..6 wire, 7..9 PD attribute block); AttributeIdToKind covers
primary attrs 1..6.
GameEventWiring:
PlayerDescription handler. Walks parsed.Attributes, routes
primary attrs (id 1..6) to OnAttributeUpdate and vitals
(id 7..9) to OnVitalUpdate. Player's full learned spellbook
also lands here. ACDREAM_DUMP_VITALS=1 traces every PD attribute
+ every PrivateUpdateVital(Current) opcode for diagnostics.
WorldSession:
Dispatch chain re-ordered — the diagnostic else-if for
ACDREAM_DUMP_OPCODES=1 was originally placed before
GameEventEnvelope.Opcode, which silently intercepted 0xF7B0 and
broke UpdateHealth dispatch when the env var was set. Moved to
the very end of the chain so it only fires for genuinely
unhandled opcodes. (Diagnostic-only regression; production
launches without the env var were unaffected.)
Test deltas
Added:
- PlayerDescriptionParserTests (6 — empty header, full attribute
block, partial flags, post-property-table walk, spell table)
- PrivateUpdateVitalTests (7 — fixture round-trip, vital ID
coverage, opcode rejection, truncation)
- LocalPlayerStateTests rewritten (20 — VitalIdToKind +
AttributeIdToKind theories, Endurance/Self formula coverage,
delta semantics, change events)
- GameEventWiringTests for PlayerDescription dispatch (2 —
end-to-end populate + spellbook feed)
Updated:
- VitalsVMTests rephrased onto the new OnVitalUpdate API.
Total: 765 → 817 tests passing.
Diagnostics
ACDREAM_DUMP_VITALS=1 — log every PD attribute extracted,
every 0x02E7/0x02E9 dispatch.
ACDREAM_DUMP_OPCODES=1 — log first occurrence of any unhandled
GameMessage opcode (now correctly placed at end of chain).
Visual verify
$env:ACDREAM_DEVTOOLS = "1"
dotnet run --project src\AcDream.App\AcDream.App.csproj -c Debug
Vitals window shows three bars; HP at 100%, Stam/Mana at ~95%
(the gap is buff enchantments — filed as #6 with the holtburger
multiplier+additive aggregator pattern as the reference for the
fix).
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
d42bf5735d
commit
7da2a027d4
14 changed files with 1660 additions and 272 deletions
|
|
@ -160,37 +160,75 @@ public static class GameEventWiring
|
|||
// Merge parsed properties into the item if we know about it.
|
||||
if (items.GetItem(p.Value.Guid) is not null)
|
||||
items.UpdateProperties(p.Value.Guid, p.Value.Properties);
|
||||
// Spell book from appraise: for ITEMS (caster / scrolls) this
|
||||
// lists cast-on-use effects; for players (PlayerDescription)
|
||||
// it's the whole learned spellbook. Both mutate the spellbook
|
||||
// by adding any not-yet-known ids.
|
||||
// Spellbook from appraise: for caster items / scrolls this is
|
||||
// the cast-on-use list. The local player's full learned
|
||||
// spellbook arrives via PlayerDescription (0x0013), which uses
|
||||
// a different wire format (see WorldSession + LocalPlayerState
|
||||
// — feeds vitals from PrivateUpdateVital instead).
|
||||
foreach (uint sid in p.Value.SpellBook)
|
||||
spellbook.OnSpellLearned(sid);
|
||||
});
|
||||
|
||||
// ── Player ────────────────────────────────────────────────
|
||||
// PlayerDescription (0x0013) carries the same AppraiseInfo body as
|
||||
// IdentifyObjectResponse (0x00C9), but it's targeted at the local
|
||||
// player. Issue #5: feed CreatureProfile.{Stamina, Mana, *Max}
|
||||
// into LocalPlayerState so the Vitals HUD can render those bars.
|
||||
// Spellbook + properties get the same downstream treatment as
|
||||
// IdentifyObjectResponse so the player's full learned spellbook
|
||||
// also lands here.
|
||||
// PlayerDescription (0x0013) — full local-player snapshot at
|
||||
// login. Distinct wire format from IdentifyObjectResponse
|
||||
// (0x00C9): hand-written body with property hashtables,
|
||||
// vector-flag-gated blocks, attribute block (where vitals 7/8/9
|
||||
// carry their absolute current values), skills, spells, and a
|
||||
// long trailer of options + inventory. See
|
||||
// PlayerDescriptionParser for the full layout reference (mirrors
|
||||
// holtburger events.rs:220-625).
|
||||
//
|
||||
// Two outputs from each parsed PlayerDescription:
|
||||
// 1. LocalPlayerState absorbs vital ids 7/8/9 (Health/Stam/Mana).
|
||||
// This is the ONLY way these arrive at login; PrivateUpdateVital
|
||||
// delta opcodes only fire on rank-up / Enlightenment / admin
|
||||
// changes — not initial sync.
|
||||
// 2. Spellbook absorbs the learned spell list — for the local
|
||||
// player this is the authoritative source (the per-item
|
||||
// SpellBook flag in IdentifyObjectResponse is for caster
|
||||
// items / scrolls only).
|
||||
bool dumpPd = Environment.GetEnvironmentVariable("ACDREAM_DUMP_VITALS") == "1";
|
||||
dispatcher.Register(GameEventType.PlayerDescription, e =>
|
||||
{
|
||||
var p = AppraiseInfoParser.TryParse(e.Payload.Span);
|
||||
if (p is null || !p.Value.Success) return;
|
||||
var p = PlayerDescriptionParser.TryParse(e.Payload.Span);
|
||||
if (dumpPd)
|
||||
Console.WriteLine($"vitals: PlayerDescription body.len={e.Payload.Length} parsed={(p is null ? "NULL" : $"vec={p.Value.VectorFlags} attrs={p.Value.Attributes.Count} spells={p.Value.Spells.Count}")}");
|
||||
if (p is null) return;
|
||||
|
||||
if (localPlayer is not null && p.Value.CreatureProfile is { } profile)
|
||||
if (localPlayer is not null)
|
||||
{
|
||||
localPlayer.OnPlayerDescription(
|
||||
currentStamina: profile.Stamina,
|
||||
maxStamina: profile.StaminaMax,
|
||||
currentMana: profile.Mana,
|
||||
maxMana: profile.ManaMax);
|
||||
foreach (var attr in p.Value.Attributes)
|
||||
{
|
||||
if (attr.Current is uint cur)
|
||||
{
|
||||
// Vital entry (id 7/8/9) — has absolute current.
|
||||
if (dumpPd)
|
||||
Console.WriteLine($"vitals: PD-vital id={attr.AtType} ranks={attr.Ranks} start={attr.Start} cur={cur}");
|
||||
localPlayer.OnVitalUpdate(
|
||||
vitalId: attr.AtType,
|
||||
ranks: attr.Ranks,
|
||||
start: attr.Start,
|
||||
xp: attr.Xp,
|
||||
current: cur);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Primary attribute (id 1..6) — Endurance+Self feed
|
||||
// the vital max formula (Endurance/2 for Health,
|
||||
// Endurance for Stamina, Self for Mana).
|
||||
if (dumpPd)
|
||||
Console.WriteLine($"vitals: PD-attr id={attr.AtType} ranks={attr.Ranks} start={attr.Start}");
|
||||
localPlayer.OnAttributeUpdate(
|
||||
atType: attr.AtType,
|
||||
ranks: attr.Ranks,
|
||||
start: attr.Start,
|
||||
xp: attr.Xp);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach (uint sid in p.Value.SpellBook)
|
||||
foreach (uint sid in p.Value.Spells.Keys)
|
||||
spellbook.OnSpellLearned(sid);
|
||||
});
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue