feat(ui): D.2b item interaction + retail cursors + live character sheet

Lands the codex-worktree D.2b stream plus the extraction the 2026-07-02
UI architecture review mandated before commit:

- ItemInteractionController: single owner of double-click use/equip/
  container-open, targeted-use mode (health kits), drag-out drop;
  toolbar shortcut drags don't drop the real item. ItemEquipRules for
  multi-slot (coat) coverage via equip masks.
- Cursor phase: CursorFeedbackController (semantic priority chain:
  drag > resize > window-move > target-mode > text) + RetailCursorCatalog
  (enums 0x27/0x28/0x29, hotspot 14,14; ClientUISystem::UpdateCursorState
  0x00564630) resolved through the portal EnumIDMap chain by
  RetailCursorResolver; RetailCursorManager applies dat cursor art to the
  OS cursor. Register row AP-72 covers the OS standard-cursor fallback.
- Character window goes live: CharacterSheetProvider owns sheet assembly,
  XP-curve/raise-cost math and the raise flow — extracted out of
  GameWindow per Code Structure Rule 1 instead of committing the ~430-line
  feature body there. Optimistic XP/credit debits go through eventful
  store APIs (new ClientObjectTable.UpdateInt64Property +
  LocalPlayerState.DebitIntProperty/DebitInt64Property) instead of raw
  property-dictionary writes; register row AP-73 covers the still-missing
  raise ledger (#163).
- RetailWindowFrame: the shared nine-slice window mount recipe; the
  character window uses it, remaining windows migrate via #164.
- Status-bar buttons toggle inventory/character windows; retail row-major
  backpack ordering; WorldSession.SendUseWithTarget + raise/train sends.

GameWindow shrinks 14,214 -> 13,877 lines despite the new features; the
sheet/raise logic is unit-tested in CharacterSheetProviderTests instead
of trapped in the god object. Build green; full suite 3,286 tests pass.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
Erik 2026-07-03 09:18:43 +02:00
parent e3fc7ac5ba
commit b7dc91a053
74 changed files with 6669 additions and 238 deletions

View file

@ -239,9 +239,12 @@ public static class GameEventWiring
{
var p = GameEvents.ParseWieldObject(e.Payload.Span);
if (p is null) return;
uint wielderGuid = p.Value.WielderGuid != 0u
? p.Value.WielderGuid
: (playerGuid?.Invoke() ?? 0u);
items.MoveItem(
p.Value.ItemGuid,
newContainerId: p.Value.WielderGuid,
newContainerId: wielderGuid,
newEquipLocation: (AcDream.Core.Items.EquipMask)p.Value.EquipLoc);
items.ConfirmMove(p.Value.ItemGuid); // Slice 1: confirm an optimistic wield (mirrors the 0x0022 handler)
});
@ -249,7 +252,11 @@ public static class GameEventWiring
{
var p = GameEvents.ParsePutObjInContainer(e.Payload.Span);
if (p is null) return;
items.MoveItem(p.Value.ItemGuid, p.Value.ContainerGuid, newSlot: (int)p.Value.Placement);
items.MoveItem(
p.Value.ItemGuid,
p.Value.ContainerGuid,
newSlot: (int)p.Value.Placement,
containerTypeHint: p.Value.ContainerType);
items.ConfirmMove(p.Value.ItemGuid); // B-Drag: the server confirmed our optimistic move
});
@ -262,9 +269,12 @@ public static class GameEventWiring
{
var p = GameEvents.ParseViewContents(e.Payload.Span);
if (p is null) return;
var guids = new uint[p.Value.Items.Count];
for (int i = 0; i < guids.Length; i++) guids[i] = p.Value.Items[i].Guid;
items.ReplaceContents(p.Value.ContainerGuid, guids);
var entries = new ContainerContentEntry[p.Value.Items.Count];
for (int i = 0; i < entries.Length; i++)
entries[i] = new ContainerContentEntry(
p.Value.Items[i].Guid,
p.Value.Items[i].ContainerType);
items.ReplaceContents(p.Value.ContainerGuid, entries);
});
// B-Wire: InventoryPutObjectIn3D (0x019A) — server confirms an item dropped
@ -273,7 +283,11 @@ public static class GameEventWiring
dispatcher.Register(GameEventType.InventoryPutObjectIn3D, e =>
{
var guid = GameEvents.ParsePutObjectIn3D(e.Payload.Span);
if (guid is not null) items.MoveItem(guid.Value, newContainerId: 0u);
if (guid is not null)
{
items.MoveItem(guid.Value, newContainerId: 0u);
items.ConfirmMove(guid.Value);
}
});
// B-Drag: InventoryServerSaveFailed (0x00A0) — server rejected an optimistic move.
@ -284,8 +298,12 @@ public static class GameEventWiring
var p = GameEvents.ParseInventoryServerSaveFailed(e.Payload.Span);
if (p is null) return;
// B-Drag: the server rejected an optimistic move — snap the item back to its pre-move slot.
if (!items.RollbackMove(p.Value.ItemGuid))
Console.WriteLine($"[B-Drag] InventoryServerSaveFailed guid=0x{p.Value.ItemGuid:X8} err=0x{p.Value.WeenieError:X} (no pending move)");
var item = items.Get(p.Value.ItemGuid);
string itemInfo = item is null
? "unknown"
: $"'{item.Name}' valid=0x{(uint)item.ValidLocations:X8} equip=0x{(uint)item.CurrentlyEquippedLocation:X8} priority=0x{item.Priority:X8} container=0x{item.ContainerId:X8} wielder=0x{item.WielderId:X8}";
bool rolledBack = items.RollbackMove(p.Value.ItemGuid);
Console.WriteLine($"[B-Drag] InventoryServerSaveFailed guid=0x{p.Value.ItemGuid:X8} err=0x{p.Value.WeenieError:X} rolledBack={rolledBack} item={itemInfo}");
});
// B-Wire: CloseGroundContainer (0x0052) — server closed a ground-container
@ -366,6 +384,8 @@ public static class GameEventWiring
if (localPlayer is not null)
{
localPlayer.OnProperties(p.Value.Properties);
foreach (var attr in p.Value.Attributes)
{
if (attr.Current is uint cur)
@ -408,14 +428,12 @@ public static class GameEventWiring
// component; .Ranks is XP-bought additions. Their sum is
// the closest we get to ACE's CreatureSkill.Current short
// of porting the full Aug/Multiplier/Vitae chain.
if (onSkillsUpdated is not null)
if (localPlayer is not null || onSkillsUpdated is not null)
{
int runSkill = -1;
int jumpSkill = -1;
foreach (var s in p.Value.Skills)
{
if (s.SkillId != 22u && s.SkillId != 24u) continue;
// K-fix13: total = AttributeFormula(skill, attrs)
// + InitLevel (s.Init from wire)
// + Ranks (s.Ranks from wire)
@ -428,6 +446,19 @@ public static class GameEventWiring
uint formulaBonus = resolveSkillFormulaBonus is not null
? resolveSkillFormulaBonus(s.SkillId, attrCurrents)
: 0u;
localPlayer?.OnSkillUpdate(
skillId: s.SkillId,
ranks: s.Ranks,
status: s.Status,
xp: s.Xp,
init: s.Init,
resistance: s.Resistance,
lastUsed: s.LastUsed,
formulaBonus: formulaBonus);
if (s.SkillId != 22u && s.SkillId != 24u) continue;
int total = (int)(formulaBonus + s.Init + s.Ranks);
if (s.SkillId == 24u) runSkill = total;
else if (s.SkillId == 22u) jumpSkill = total;
@ -437,7 +468,7 @@ public static class GameEventWiring
$"vitals: PD-skill id={s.SkillId} init={s.Init} ranks={s.Ranks} formulaBonus={formulaBonus} total={total}");
}
if (runSkill >= 0 || jumpSkill >= 0)
onSkillsUpdated(runSkill, jumpSkill);
onSkillsUpdated?.Invoke(runSkill, jumpSkill);
}
// Issue #7 — enchantment block: feed each entry into the
@ -463,8 +494,21 @@ public static class GameEventWiring
// actual weenie data via ObjectTableWiring. (Previously this seeded
// stubs with WeenieClassId = ContainerType, a misuse — ContainerType
// is a 0/1/2 container-kind discriminator, not a weenie class id.)
foreach (var inv in p.Value.Inventory)
items.RecordMembership(inv.Guid);
uint ownerGuid = playerGuid?.Invoke() ?? 0u;
if (ownerGuid != 0u)
{
var entries = new ContainerContentEntry[p.Value.Inventory.Count];
for (int i = 0; i < entries.Length; i++)
entries[i] = new ContainerContentEntry(
p.Value.Inventory[i].Guid,
p.Value.Inventory[i].ContainerType);
items.ReplaceContents(ownerGuid, entries);
}
else
{
foreach (var inv in p.Value.Inventory)
items.RecordMembership(inv.Guid, containerTypeHint: inv.ContainerType);
}
foreach (var eq in p.Value.Equipped)
items.RecordMembership(eq.Guid, equip: (EquipMask)eq.EquipLocation);

View file

@ -146,6 +146,7 @@ public static class CreateObject
// publish it.
uint? Useability = null,
float? UseRadius = null,
uint? TargetType = null,
// D.5.1 (2026-06-17): icon overlay/underlay dat ids from the
// WeenieHeader optional tail. IconOverlayId is gated by
// WeenieHeaderFlag.IconOverlay (0x40000000) in weenieFlags;
@ -645,6 +646,7 @@ public static class CreateObject
// SAFE because IconComposer early-returns on id==0 per layer.
uint? useability = null;
float? useRadius = null;
uint? targetType = null;
uint iconOverlayId = 0;
uint iconUnderlayId = 0;
uint uiEffects = 0;
@ -707,7 +709,7 @@ public static class CreateObject
if ((weenieFlags & 0x00080000u) != 0) // TargetType u32
{
if (body.Length - pos < 4) throw new FormatException("trunc TargetType");
pos += 4;
targetType = ReadU32(body, ref pos);
}
if ((weenieFlags & 0x00000080u) != 0) // UiEffects u32 ← CAPTURE
{
@ -850,7 +852,7 @@ public static class CreateObject
physicsState, objectDescriptionFlags,
friction, elasticity,
IconId: iconId,
Useability: useability, UseRadius: useRadius,
Useability: useability, UseRadius: useRadius, TargetType: targetType,
IconOverlayId: iconOverlayId, IconUnderlayId: iconUnderlayId,
UiEffects: uiEffects,
WeenieClassId: weenieClassId,

View file

@ -336,11 +336,14 @@ public static class GameEvents
public static WieldObject? ParseWieldObject(ReadOnlySpan<byte> payload)
{
if (payload.Length < 12) return null;
if (payload.Length < 8) return null;
uint wielderGuid = payload.Length >= 12
? BinaryPrimitives.ReadUInt32LittleEndian(payload.Slice(8))
: 0u;
return new WieldObject(
BinaryPrimitives.ReadUInt32LittleEndian(payload),
BinaryPrimitives.ReadUInt32LittleEndian(payload.Slice(4)),
BinaryPrimitives.ReadUInt32LittleEndian(payload.Slice(8)));
wielderGuid);
}
/// <summary>0x0022 InventoryPutObjInContainer: server puts item into container slot.

View file

@ -81,5 +81,7 @@ public static class ObjectTableWiring
ContainersCapacity: s.ContainersCapacity,
Structure: s.Structure,
MaxStructure: s.MaxStructure,
Workmanship: s.Workmanship);
Workmanship: s.Workmanship,
Useability: s.Useability,
TargetType: s.TargetType);
}

View file

@ -82,6 +82,7 @@ public sealed class WorldSession : IDisposable
// server publishes it for non-useable display entities.
uint? Useability = null,
float? UseRadius = null,
uint? TargetType = null,
// D.5.1: icon datId from CreateObject WeenieHeader, for toolbar rendering.
uint IconId = 0,
// D.5.1 (2026-06-17): icon overlay/underlay dat ids from the extended
@ -807,6 +808,7 @@ public sealed class WorldSession : IDisposable
parsed.Value.Elasticity,
parsed.Value.Useability,
parsed.Value.UseRadius,
parsed.Value.TargetType,
parsed.Value.IconId,
parsed.Value.IconOverlayId,
parsed.Value.IconUnderlayId,
@ -1209,6 +1211,34 @@ public sealed class WorldSession : IDisposable
SendGameAction(body);
}
/// <summary>Send retail RaiseAttribute (0x0045).</summary>
public void SendRaiseAttribute(uint attrId, ulong xpSpent)
{
uint seq = NextGameActionSequence();
SendGameAction(CharacterActions.BuildRaiseAttribute(seq, attrId, xpSpent));
}
/// <summary>Send retail RaiseVital (0x0044).</summary>
public void SendRaiseVital(uint vitalId, ulong xpSpent)
{
uint seq = NextGameActionSequence();
SendGameAction(CharacterActions.BuildRaiseVital(seq, vitalId, xpSpent));
}
/// <summary>Send retail RaiseSkill (0x0046).</summary>
public void SendRaiseSkill(uint skillId, ulong xpSpent)
{
uint seq = NextGameActionSequence();
SendGameAction(CharacterActions.BuildRaiseSkill(seq, skillId, xpSpent));
}
/// <summary>Send retail TrainSkill (0x0047).</summary>
public void SendTrainSkill(uint skillId, uint credits)
{
uint seq = NextGameActionSequence();
SendGameAction(CharacterActions.BuildTrainSkill(seq, skillId, credits));
}
/// <summary>Send AddShortcut (0x019C) — pin an item to toolbar slot <paramref name="index"/>.
/// Retail: CM_Character::Event_AddShortCut. Mirrors the SendChangeCombatMode pattern.</summary>
public void SendAddShortcut(uint index, uint objectGuid, ushort spellId = 0, ushort layer = 0)
@ -1255,9 +1285,17 @@ public sealed class WorldSession : IDisposable
SendGameAction(InteractRequests.BuildUse(seq, targetGuid));
}
/// <summary>Send PutItemInContainer (0x0019) — move an item into a container at a slot. placement
/// <summary>Send UseWithTarget (0x0035) - use a source item on an acquired target.
/// Retail: CM_Inventory::Event_UseWithTargetEvent.</summary>
public void SendUseWithTarget(uint sourceGuid, uint targetGuid)
{
uint seq = NextGameActionSequence();
SendGameAction(InteractRequests.BuildUseWithTarget(seq, sourceGuid, targetGuid));
}
/// <summary>Send PutItemInContainer (0x0019) - move an item into a container at a slot. placement
/// = the target slot (server packs/shifts); the drag-drop drop handler computes it. Retail:
/// CM_Inventory::Event_PutItemInContainer → ACE Player.HandleActionPutItemInContainer.</summary>
/// CM_Inventory::Event_PutItemInContainer -> ACE Player.HandleActionPutItemInContainer.</summary>
public void SendPutItemInContainer(uint itemGuid, uint containerGuid, int placement)
{
uint seq = NextGameActionSequence();