feat(player): #5 LocalPlayerState — Stam/Mana wired through PlayerDescription
Closes ISSUES.md #5. The Vitals devtools window now draws three bars (HP / Stamina / Mana) once the server sends the first PlayerDescription (0x0013), instead of HP only. Built test-first per CLAUDE.md TDD rule — 16 new tests went red before the implementation went in. New AcDream.Core.Player.LocalPlayerState (cache): - {CurrentStamina, MaxStamina, CurrentMana, MaxMana} as uint? — null until first received. - StaminaPercent / ManaPercent: 0..1 fraction or null when either field is missing or max is zero. Clamps to 1.0 if current > max (server can briefly report this during buff transitions). - OnPlayerDescription preserves any previously known good value when an incoming field is null — partial profiles don't wipe state. - Changed event for future subscribers. GameEventWiring.WireAll: - New optional 6th parameter: LocalPlayerState? localPlayer = null. Existing 5-arg call sites still work; without the parameter the new PlayerDescription handler still parses + feeds the spellbook but skips the cache update. - PlayerDescription (0x0013) shares AppraiseInfo wire format with IdentifyObjectResponse (0x00C9) per AppraiseInfoParser docstring, so the new handler reuses the existing parser and pulls CreatureProfile.{Stamina, StaminaMax, Mana, ManaMax}. - Player's full learned spellbook also lands here (previously only item-scoped Identify responses fed the spellbook). VitalsVM: - Constructor adds optional LocalPlayerState? parameter (default null keeps every existing caller compiling). - StaminaPercent / ManaPercent now read through to LocalPlayerState every access — no VM-side caching, so a server-side delta to the cache surfaces next frame without any explicit refresh. GameWindow: - Public readonly LocalPlayer field alongside Combat / Chat / Items / SpellBook so plugins + future panels can bind directly. - WireAll call updated to pass LocalPlayer. - VitalsVM construction passes LocalPlayer so the existing VitalsPanel automatically picks up the two new bars. Test counts: - AcDream.Core.Tests: 550 → 561 (+11 LocalPlayerStateTests) - AcDream.UI.Abstractions.Tests: 23 → 26 (+3 VitalsVM through-cache) - AcDream.Core.Net.Tests: 192 → 194 (+2 PlayerDescription wiring) - Total: 765 → 781 Build: 0 warnings, 0 errors. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
9faf9d7e3a
commit
d42bf5735d
8 changed files with 436 additions and 50 deletions
|
|
@ -1,4 +1,5 @@
|
|||
using AcDream.Core.Combat;
|
||||
using AcDream.Core.Player;
|
||||
using AcDream.UI.Abstractions.Panels.Vitals;
|
||||
|
||||
namespace AcDream.UI.Abstractions.Tests;
|
||||
|
|
@ -39,22 +40,67 @@ public sealed class VitalsVMTests
|
|||
}
|
||||
|
||||
[Fact]
|
||||
public void StaminaPercent_IsNull_ForD2aScope()
|
||||
public void StaminaPercent_IsNull_WhenNoLocalPlayerStateProvided()
|
||||
{
|
||||
// D.2a explicitly defers Stamina until LocalPlayerState + PlayerDescription
|
||||
// wiring. When that arrives VitalsVM.StaminaPercent becomes non-null and
|
||||
// VitalsPanel starts drawing the Stam bar automatically.
|
||||
// Back-compat with the original D.2a constructor — when no
|
||||
// LocalPlayerState is wired, Stam/Mana remain null and
|
||||
// VitalsPanel skips drawing those bars.
|
||||
var vm = new VitalsVM(new CombatState());
|
||||
Assert.Null(vm.StaminaPercent);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ManaPercent_IsNull_ForD2aScope()
|
||||
public void ManaPercent_IsNull_WhenNoLocalPlayerStateProvided()
|
||||
{
|
||||
var vm = new VitalsVM(new CombatState());
|
||||
Assert.Null(vm.ManaPercent);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void StaminaPercent_FromLocalPlayerState_AfterPlayerDescription()
|
||||
{
|
||||
// Issue #5 — once a LocalPlayerState is wired and the server has
|
||||
// sent a PlayerDescription with CreatureProfile, the Stam bar
|
||||
// surfaces the correct percent without any VM-level caching.
|
||||
var local = new LocalPlayerState();
|
||||
local.OnPlayerDescription(currentStamina: 80, maxStamina: 100,
|
||||
currentMana: null, maxMana: null);
|
||||
|
||||
var vm = new VitalsVM(new CombatState(), local);
|
||||
|
||||
Assert.Equal(0.8f, vm.StaminaPercent!.Value, precision: 3);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ManaPercent_FromLocalPlayerState_AfterPlayerDescription()
|
||||
{
|
||||
var local = new LocalPlayerState();
|
||||
local.OnPlayerDescription(currentStamina: null, maxStamina: null,
|
||||
currentMana: 25, maxMana: 100);
|
||||
|
||||
var vm = new VitalsVM(new CombatState(), local);
|
||||
|
||||
Assert.Equal(0.25f, vm.ManaPercent!.Value, precision: 3);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Vm_ReadsThroughToLocalPlayerState_NoStaleCache()
|
||||
{
|
||||
// Verify the VM doesn't snapshot — it should read live from the
|
||||
// LocalPlayerState every property access so a server delta picks
|
||||
// up next frame without any explicit refresh call.
|
||||
var local = new LocalPlayerState();
|
||||
var vm = new VitalsVM(new CombatState(), local);
|
||||
|
||||
Assert.Null(vm.StaminaPercent); // no data yet
|
||||
|
||||
local.OnPlayerDescription(currentStamina: 50, maxStamina: 100,
|
||||
currentMana: 50, maxMana: 100);
|
||||
|
||||
Assert.Equal(0.5f, vm.StaminaPercent!.Value, precision: 3);
|
||||
Assert.Equal(0.5f, vm.ManaPercent!.Value, precision: 3);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SetLocalPlayerGuid_ReroutesHealthLookup_WithoutStaleCache()
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue