feat(items): Phase F.2 ItemRepository + AppraiseRequest round-trip

Implements the item-state mirror + appraise round-trip infrastructure
on top of Phase F.1's GameEvent dispatcher.

Core layer (AcDream.Core/Items):
- ItemRepository: ConcurrentDictionary-backed live item state keyed by
  server ObjectId. Events: ItemAdded, ItemMoved, ItemRemoved,
  ItemPropertiesUpdated. MoveItem handles container / slot / equip
  location updates atomically and fires ItemMoved with old+new container
  ids. UpdateProperties merges a PropertyBundle patch (for appraise
  results) without clobbering existing untouched keys.

Wire layer (AcDream.Core.Net/Messages):
- AppraiseRequest (0x00C8 C→S, inside 0xF7B1 GameAction envelope):
  Build(sequence, targetGuid) → 16-byte body ready for SendGameAction.
- GameEvents.ParseIdentifyResponseHeader for 0x00C9 S→C — extracts
  (guid, appraiseFlags, success). Full PropertyBundle deserialization
  (the 10-flag bitfield-indexed tables) is a future pass; header alone
  is enough to route into the repository + surface "appraise complete"
  to UI.
- GameEvents.ParseWieldObject (0x0023) — server-driven equip.
- GameEvents.ParsePutObjInContainer (0x0022) — server-driven inventory
  move (item, container, placement).

Tests (11 new):
- ItemRepository: add/update fires correct event, move updates fields,
  missing-id returns false, remove, properties merge, clear.
- Wire: AppraiseRequest byte-exact encoding, IdentifyResponse header
  round-trip, WieldObject round-trip, PutObjInContainer round-trip.

Build green, 532 tests pass (up from 521).

Phase F.2 unblocks the Paperdoll + Inventory UI panels and the
"appraise on right-click" UX. Next pieces: PropertyBundle full
deserializer (AppraiseInfo 10-flag bitfield), outbound move/drop/
pickup actions.

Ref: r06 §1 (ItemType), §2 (EquipMask), §5 (appraise wire), §7 (pack
depth rules).
Ref: ACE GameEventIdentifyObjectResponse.cs for AppraiseInfo format.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Erik 2026-04-18 16:55:36 +02:00
parent d86fd08011
commit 2561f5599f
5 changed files with 453 additions and 0 deletions

View file

@ -0,0 +1,70 @@
using System;
using System.Buffers.Binary;
using AcDream.Core.Net.Messages;
using Xunit;
namespace AcDream.Core.Net.Tests.Messages;
public sealed class AppraiseTests
{
[Fact]
public void AppraiseRequest_Build_EmitsCorrectWireBytes()
{
byte[] body = AppraiseRequest.Build(gameActionSequence: 7, targetGuid: 0x12345678u);
Assert.Equal(16, body.Length);
Assert.Equal(AppraiseRequest.GameActionEnvelope,
BinaryPrimitives.ReadUInt32LittleEndian(body));
Assert.Equal(7u,
BinaryPrimitives.ReadUInt32LittleEndian(body.AsSpan(4)));
Assert.Equal(AppraiseRequest.SubOpcode,
BinaryPrimitives.ReadUInt32LittleEndian(body.AsSpan(8)));
Assert.Equal(0x12345678u,
BinaryPrimitives.ReadUInt32LittleEndian(body.AsSpan(12)));
}
[Fact]
public void ParseIdentifyResponseHeader_RoundTrip()
{
byte[] payload = new byte[12];
BinaryPrimitives.WriteUInt32LittleEndian(payload, 0xDEADBEEFu); // guid
BinaryPrimitives.WriteUInt32LittleEndian(payload.AsSpan(4), 0x000F); // flags
BinaryPrimitives.WriteUInt32LittleEndian(payload.AsSpan(8), 1u); // success
var parsed = GameEvents.ParseIdentifyResponseHeader(payload);
Assert.NotNull(parsed);
Assert.Equal(0xDEADBEEFu, parsed!.Value.Guid);
Assert.Equal(0x000Fu, parsed.Value.AppraiseFlags);
Assert.True(parsed.Value.Success);
}
[Fact]
public void ParseWieldObject_RoundTrip()
{
byte[] payload = new byte[12];
BinaryPrimitives.WriteUInt32LittleEndian(payload, 0x1000u);
BinaryPrimitives.WriteUInt32LittleEndian(payload.AsSpan(4), 0x00400000u); // MeleeWeapon slot
BinaryPrimitives.WriteUInt32LittleEndian(payload.AsSpan(8), 0x2000u); // wielder
var parsed = GameEvents.ParseWieldObject(payload);
Assert.NotNull(parsed);
Assert.Equal(0x1000u, parsed!.Value.ItemGuid);
Assert.Equal(0x00400000u, parsed.Value.EquipLoc);
Assert.Equal(0x2000u, parsed.Value.WielderGuid);
}
[Fact]
public void ParsePutObjInContainer_RoundTrip()
{
byte[] payload = new byte[12];
BinaryPrimitives.WriteUInt32LittleEndian(payload, 0x1001u);
BinaryPrimitives.WriteUInt32LittleEndian(payload.AsSpan(4), 0x2001u);
BinaryPrimitives.WriteUInt32LittleEndian(payload.AsSpan(8), 3u);
var parsed = GameEvents.ParsePutObjInContainer(payload);
Assert.NotNull(parsed);
Assert.Equal(0x1001u, parsed!.Value.ItemGuid);
Assert.Equal(0x2001u, parsed.Value.ContainerGuid);
Assert.Equal(3u, parsed.Value.Placement);
}
}