refactor(D.5.4): rename ItemRepository->ClientObjectTable, ItemInstance->ClientObject

Broaden naming to the data side of every server object (retail weenie_object_table
shape). Pure rename; no behavior change.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Erik 2026-06-18 15:33:03 +02:00
parent 2fc253d9ff
commit b506f53633
8 changed files with 142 additions and 145 deletions

View file

@ -595,7 +595,7 @@ public sealed class GameWindow : IDisposable
// SpellTable.Empty if the file is missing (e.g. tooling contexts). // SpellTable.Empty if the file is missing (e.g. tooling contexts).
public readonly AcDream.Core.Spells.SpellTable SpellTable = LoadSpellTable(); public readonly AcDream.Core.Spells.SpellTable SpellTable = LoadSpellTable();
public readonly AcDream.Core.Spells.Spellbook SpellBook = null!; public readonly AcDream.Core.Spells.Spellbook SpellBook = null!;
public readonly AcDream.Core.Items.ItemRepository Items = new(); public readonly AcDream.Core.Items.ClientObjectTable Objects = new();
/// <summary>Persisted hotbar shortcuts from the last PlayerDescription (D.5.1 toolbar source).</summary> /// <summary>Persisted hotbar shortcuts from the last PlayerDescription (D.5.1 toolbar source).</summary>
public IReadOnlyList<AcDream.Core.Net.Messages.PlayerDescriptionParser.ShortcutEntry> Shortcuts { get; private set; } public IReadOnlyList<AcDream.Core.Net.Messages.PlayerDescriptionParser.ShortcutEntry> Shortcuts { get; private set; }
= System.Array.Empty<AcDream.Core.Net.Messages.PlayerDescriptionParser.ShortcutEntry>(); = System.Array.Empty<AcDream.Core.Net.Messages.PlayerDescriptionParser.ShortcutEntry>();
@ -2000,7 +2000,7 @@ public sealed class GameWindow : IDisposable
if (toolbarLayout is not null) if (toolbarLayout is not null)
{ {
_toolbarController = AcDream.App.UI.Layout.ToolbarController.Bind( _toolbarController = AcDream.App.UI.Layout.ToolbarController.Bind(
toolbarLayout, Items, toolbarLayout, Objects,
() => Shortcuts, () => Shortcuts,
iconIds: (type, icon, under, over, effects) => iconComposer.GetIcon(type, icon, under, over, effects), iconIds: (type, icon, under, over, effects) => iconComposer.GetIcon(type, icon, under, over, effects),
useItem: guid => UseItemByGuid(guid), useItem: guid => UseItemByGuid(guid),
@ -2411,7 +2411,7 @@ public sealed class GameWindow : IDisposable
var skillTable = _dats?.Get<DatReaderWriter.DBObjs.SkillTable>(0x0E000004u); var skillTable = _dats?.Get<DatReaderWriter.DBObjs.SkillTable>(0x0E000004u);
AcDream.Core.Net.GameEventWiring.WireAll( AcDream.Core.Net.GameEventWiring.WireAll(
_liveSession.GameEvents, Items, Combat, SpellBook, Chat, LocalPlayer, _liveSession.GameEvents, Objects, Combat, SpellBook, Chat, LocalPlayer,
TurbineChat, TurbineChat,
resolveSkillFormulaBonus: (skillId, attrCurrents) => resolveSkillFormulaBonus: (skillId, attrCurrents) =>
{ {
@ -2636,8 +2636,8 @@ public sealed class GameWindow : IDisposable
// repository so a draining/charging item re-composites its icon in real time. // repository so a draining/charging item re-composites its icon in real time.
_liveSession.ObjectIntPropertyUpdated += u => _liveSession.ObjectIntPropertyUpdated += u =>
{ {
if (u.Property == AcDream.Core.Items.ItemRepository.UiEffectsPropertyId) if (u.Property == AcDream.Core.Items.ClientObjectTable.UiEffectsPropertyId)
Items.UpdateIntProperty(u.Guid, u.Property, u.Value); Objects.UpdateIntProperty(u.Guid, u.Property, u.Value);
}; };
} }
@ -2652,7 +2652,7 @@ public sealed class GameWindow : IDisposable
// with the icon/name/type its CreateObject carries, so the toolbar can render it. // with the icon/name/type its CreateObject carries, so the toolbar can render it.
// D.5.1 (2026-06-17): also pass overlay/underlay ids from the extended // D.5.1 (2026-06-17): also pass overlay/underlay ids from the extended
// WeenieHeader tail so IconComposer composites all icon layers. // WeenieHeader tail so IconComposer composites all icon layers.
Items.EnrichItem(spawn.Guid, spawn.IconId, spawn.Name ?? string.Empty, Objects.EnrichItem(spawn.Guid, spawn.IconId, spawn.Name ?? string.Empty,
(AcDream.Core.Items.ItemType)(spawn.ItemType ?? 0), (AcDream.Core.Items.ItemType)(spawn.ItemType ?? 0),
spawn.IconOverlayId, spawn.IconUnderlayId, spawn.UiEffects); spawn.IconOverlayId, spawn.IconUnderlayId, spawn.UiEffects);

View file

@ -49,7 +49,7 @@ public sealed class ToolbarController
private readonly UiItemList?[] _slots = new UiItemList?[SlotIds.Length]; private readonly UiItemList?[] _slots = new UiItemList?[SlotIds.Length];
private readonly UiElement?[] _combatIndicators = new UiElement?[CombatIndicatorIds.Length]; private readonly UiElement?[] _combatIndicators = new UiElement?[CombatIndicatorIds.Length];
private readonly ItemRepository _repo; private readonly ClientObjectTable _repo;
private readonly Func<IReadOnlyList<PlayerDescriptionParser.ShortcutEntry>> _shortcuts; private readonly Func<IReadOnlyList<PlayerDescriptionParser.ShortcutEntry>> _shortcuts;
private readonly Func<ItemType, uint, uint, uint, uint, uint> _iconIds; // (itemType, icon, underlay, overlay, effects) → GL tex private readonly Func<ItemType, uint, uint, uint, uint, uint> _iconIds; // (itemType, icon, underlay, overlay, effects) → GL tex
private readonly Action<uint> _useItem; // guid → fire UseObject private readonly Action<uint> _useItem; // guid → fire UseObject
@ -68,7 +68,7 @@ public sealed class ToolbarController
private ToolbarController( private ToolbarController(
ImportedLayout layout, ImportedLayout layout,
ItemRepository repo, ClientObjectTable repo,
Func<IReadOnlyList<PlayerDescriptionParser.ShortcutEntry>> shortcuts, Func<IReadOnlyList<PlayerDescriptionParser.ShortcutEntry>> shortcuts,
Func<ItemType, uint, uint, uint, uint, uint> iconIds, Func<ItemType, uint, uint, uint, uint, uint> iconIds,
Action<uint> useItem, Action<uint> useItem,
@ -110,8 +110,8 @@ public sealed class ToolbarController
combatState.CombatModeChanged += SetCombatMode; combatState.CombatModeChanged += SetCombatMode;
// Re-bind any deferred slot whenever the repo learns about a new/updated item. // Re-bind any deferred slot whenever the repo learns about a new/updated item.
repo.ItemAdded += _ => Populate(); repo.ObjectAdded += _ => Populate();
repo.ItemPropertiesUpdated += _ => Populate(); repo.ObjectUpdated += _ => Populate();
} }
/// <summary> /// <summary>
@ -146,7 +146,7 @@ public sealed class ToolbarController
/// </param> /// </param>
public static ToolbarController Bind( public static ToolbarController Bind(
ImportedLayout layout, ImportedLayout layout,
ItemRepository repo, ClientObjectTable repo,
Func<IReadOnlyList<PlayerDescriptionParser.ShortcutEntry>> shortcuts, Func<IReadOnlyList<PlayerDescriptionParser.ShortcutEntry>> shortcuts,
Func<ItemType, uint, uint, uint, uint, uint> iconIds, Func<ItemType, uint, uint, uint, uint, uint> iconIds,
Action<uint> useItem, Action<uint> useItem,
@ -165,7 +165,7 @@ public sealed class ToolbarController
/// Port of <c>gmToolbarUI::UpdateFromPlayerDesc</c>: clear all slots, then bind /// Port of <c>gmToolbarUI::UpdateFromPlayerDesc</c>: clear all slots, then bind
/// each shortcut entry that has a resolved item in the repository. /// each shortcut entry that has a resolved item in the repository.
/// Entries whose item is not yet in the repo are silently skipped here; the /// Entries whose item is not yet in the repo are silently skipped here; the
/// <c>ItemAdded</c> event re-fires this method when the item arrives /// <c>ObjectAdded</c> event re-fires this method when the item arrives
/// (matching retail's <c>SetDelayedShortcutNum</c> deferred-rebind path). /// (matching retail's <c>SetDelayedShortcutNum</c> deferred-rebind path).
/// </summary> /// </summary>
public void Populate() public void Populate()
@ -180,8 +180,8 @@ public sealed class ToolbarController
var list = _slots[(int)sc.Index]; var list = _slots[(int)sc.Index];
if (list is null) continue; if (list is null) continue;
var item = _repo.GetItem(sc.ObjectGuid); var item = _repo.Get(sc.ObjectGuid);
if (item is null) continue; // deferred: ItemAdded will re-call Populate if (item is null) continue; // deferred: ObjectAdded will re-call Populate
uint tex = _iconIds(item.Type, item.IconId, item.IconUnderlayId, item.IconOverlayId, item.Effects); uint tex = _iconIds(item.Type, item.IconId, item.IconUnderlayId, item.IconOverlayId, item.Effects);
list.Cell.SetItem(sc.ObjectGuid, tex); list.Cell.SetItem(sc.ObjectGuid, tex);

View file

@ -11,7 +11,7 @@ namespace AcDream.Core.Net;
/// <summary> /// <summary>
/// Central registration point that wires every parsed GameEvent from /// Central registration point that wires every parsed GameEvent from
/// <see cref="GameEventDispatcher"/> into the appropriate Core state /// <see cref="GameEventDispatcher"/> into the appropriate Core state
/// class (<see cref="ItemRepository"/>, <see cref="CombatState"/>, /// class (<see cref="ClientObjectTable"/>, <see cref="CombatState"/>,
/// <see cref="Spellbook"/>, <see cref="ChatLog"/>). /// <see cref="Spellbook"/>, <see cref="ChatLog"/>).
/// ///
/// <para> /// <para>
@ -32,7 +32,7 @@ public static class GameEventWiring
{ {
public static void WireAll( public static void WireAll(
GameEventDispatcher dispatcher, GameEventDispatcher dispatcher,
ItemRepository items, ClientObjectTable items,
CombatState combat, CombatState combat,
Spellbook spellbook, Spellbook spellbook,
ChatLog chat, ChatLog chat,
@ -251,7 +251,7 @@ public static class GameEventWiring
var p = AppraiseInfoParser.TryParse(e.Payload.Span); var p = AppraiseInfoParser.TryParse(e.Payload.Span);
if (p is null || !p.Value.Success) return; if (p is null || !p.Value.Success) return;
// Merge parsed properties into the item if we know about it. // Merge parsed properties into the item if we know about it.
if (items.GetItem(p.Value.Guid) is not null) if (items.Get(p.Value.Guid) is not null)
items.UpdateProperties(p.Value.Guid, p.Value.Properties); items.UpdateProperties(p.Value.Guid, p.Value.Properties);
// Spellbook from appraise: for caster items / scrolls this is // Spellbook from appraise: for caster items / scrolls this is
// the cast-on-use list. The local player's full learned // the cast-on-use list. The local player's full learned
@ -400,7 +400,7 @@ public static class GameEventWiring
Console.WriteLine($"vitals: PD-ench spell={ench.SpellId} layer={ench.Layer} bucket={ench.Bucket} key={ench.StatModKey} val={ench.StatModValue}"); Console.WriteLine($"vitals: PD-ench spell={ench.SpellId} layer={ench.Layer} bucket={ench.Bucket} key={ench.StatModKey} val={ench.StatModValue}");
} }
// Issue #13 — register inventory entries with ItemRepository so // Issue #13 — register inventory entries with ClientObjectTable so
// panels (inventory, paperdoll, hotbars) light up after login. // panels (inventory, paperdoll, hotbars) light up after login.
// Equipped entries share the same ObjectId as inventory entries // Equipped entries share the same ObjectId as inventory entries
// (an equipped item is also in inventory) — register both, but // (an equipped item is also in inventory) — register both, but
@ -408,9 +408,9 @@ public static class GameEventWiring
// MoveItem so paperdoll can render. // MoveItem so paperdoll can render.
foreach (var inv in p.Value.Inventory) foreach (var inv in p.Value.Inventory)
{ {
if (items.GetItem(inv.Guid) is null) if (items.Get(inv.Guid) is null)
{ {
items.AddOrUpdate(new ItemInstance items.AddOrUpdate(new ClientObject
{ {
ObjectId = inv.Guid, ObjectId = inv.Guid,
WeenieClassId = inv.ContainerType, WeenieClassId = inv.ContainerType,
@ -419,9 +419,9 @@ public static class GameEventWiring
} }
foreach (var eq in p.Value.Equipped) foreach (var eq in p.Value.Equipped)
{ {
if (items.GetItem(eq.Guid) is null) if (items.Get(eq.Guid) is null)
{ {
items.AddOrUpdate(new ItemInstance items.AddOrUpdate(new ClientObject
{ {
ObjectId = eq.Guid, ObjectId = eq.Guid,
WeenieClassId = 0, WeenieClassId = 0,

View file

@ -121,11 +121,10 @@ public sealed class PropertyBundle
} }
/// <summary> /// <summary>
/// Per-item live state. The server owns item identity (ObjectId); /// Per-object live state (the data side of every server object — items and creatures alike).
/// acdream mirrors properties here on <c>CreateObject</c> and updates /// Retail <c>ACCWeenieObject</c>.
/// via <c>UpdateProperty*</c> messages.
/// </summary> /// </summary>
public sealed class ItemInstance public sealed class ClientObject
{ {
public uint ObjectId { get; init; } public uint ObjectId { get; init; }
public uint WeenieClassId { get; init; } // "blueprint" public uint WeenieClassId { get; init; } // "blueprint"
@ -164,7 +163,7 @@ public sealed class Container
public int Capacity { get; set; } = 102; // main inv default public int Capacity { get; set; } = 102; // main inv default
public int SideCapacity { get; set; } = 0; // 0 for side-pack public int SideCapacity { get; set; } = 0; // 0 for side-pack
public int BurdenLimit { get; set; } public int BurdenLimit { get; set; }
public List<ItemInstance> Items { get; } = new(); public List<ClientObject> Items { get; } = new();
public List<Container> SidePacks { get; } = new(); // empty for side-pack public List<Container> SidePacks { get; } = new(); // empty for side-pack
public bool IsSidePack => SideCapacity == 0; public bool IsSidePack => SideCapacity == 0;
} }

View file

@ -5,16 +5,14 @@ using System.Collections.Generic;
namespace AcDream.Core.Items; namespace AcDream.Core.Items;
/// <summary> /// <summary>
/// Live item-state mirror — the client-side view of every item the /// The client's table of every server object (retail <c>weenie_object_table</c> /
/// server has spawned for this session. Owns <see cref="ItemInstance"/> /// <c>CObjectMaint</c>). Resolve by guid via <c>Get</c>.
/// records, tracks which container holds each item, and fires events so
/// UI panels (inventory, paperdoll, hotbars) can redraw on change.
/// ///
/// <para> /// <para>
/// Retail semantics (r06): /// Retail semantics (r06):
/// <list type="bullet"> /// <list type="bullet">
/// <item><description> /// <item><description>
/// Every item is a <see cref="ItemInstance"/> with a unique /// Every object is a <see cref="ClientObject"/> with a unique
/// <c>ObjectId</c>. CreateObject seeds it when the server tells us /// <c>ObjectId</c>. CreateObject seeds it when the server tells us
/// the item exists (in our inventory, on the ground, in a /// the item exists (in our inventory, on the ground, in a
/// vendor's list, etc). /// vendor's list, etc).
@ -40,42 +38,42 @@ namespace AcDream.Core.Items;
/// corrupting state. /// corrupting state.
/// </para> /// </para>
/// </summary> /// </summary>
public sealed class ItemRepository public sealed class ClientObjectTable
{ {
private readonly ConcurrentDictionary<uint, ItemInstance> _items = new(); private readonly ConcurrentDictionary<uint, ClientObject> _items = new();
private readonly ConcurrentDictionary<uint, Container> _containers = new(); private readonly ConcurrentDictionary<uint, Container> _containers = new();
/// <summary>Fires when an item is first added to the session.</summary> /// <summary>Fires when an object is first added to the session.</summary>
public event Action<ItemInstance>? ItemAdded; public event Action<ClientObject>? ObjectAdded;
/// <summary> /// <summary>
/// Fires when an item's container / slot changes (moved between /// Fires when an object's container / slot changes (moved between
/// packs, equipped, unequipped, dropped on ground). Old and new /// packs, equipped, unequipped, dropped on ground). Old and new
/// container ids are 0 if origin or destination is "world" / "nowhere". /// container ids are 0 if origin or destination is "world" / "nowhere".
/// </summary> /// </summary>
public event Action<ItemInstance, uint, uint>? ItemMoved; public event Action<ClientObject, uint, uint>? ObjectMoved;
/// <summary>Fires when an item is removed from the session.</summary> /// <summary>Fires when an object is removed from the session.</summary>
public event Action<ItemInstance>? ItemRemoved; public event Action<ClientObject>? ObjectRemoved;
/// <summary>Fires when an item's properties are updated (typically after Appraise).</summary> /// <summary>Fires when an object's properties are updated (typically after Appraise).</summary>
public event Action<ItemInstance>? ItemPropertiesUpdated; public event Action<ClientObject>? ObjectUpdated;
/// <summary>PropertyInt.UiEffects (ACE enum value 18) — the icon effect bitfield; /// <summary>PropertyInt.UiEffects (ACE enum value 18) — the icon effect bitfield;
/// the typed mirror <see cref="UpdateIntProperty"/> maintains on /// the typed mirror <see cref="UpdateIntProperty"/> maintains on
/// <see cref="ItemInstance.Effects"/>.</summary> /// <see cref="ClientObject.Effects"/>.</summary>
public const uint UiEffectsPropertyId = 18u; public const uint UiEffectsPropertyId = 18u;
public int ItemCount => _items.Count; public int ObjectCount => _items.Count;
public int ContainerCount => _containers.Count; public int ContainerCount => _containers.Count;
public IEnumerable<ItemInstance> Items => _items.Values; public IEnumerable<ClientObject> Objects => _items.Values;
public IEnumerable<Container> Containers => _containers.Values; public IEnumerable<Container> Containers => _containers.Values;
/// <summary> /// <summary>
/// Look up an item by its server-assigned <c>ObjectId</c>. /// Look up an object by its server-assigned <c>ObjectId</c>.
/// </summary> /// </summary>
public ItemInstance? GetItem(uint objectId) => public ClientObject? Get(uint objectId) =>
_items.TryGetValue(objectId, out var item) ? item : null; _items.TryGetValue(objectId, out var item) ? item : null;
/// <summary> /// <summary>
@ -88,17 +86,17 @@ public sealed class ItemRepository
_containers.TryGetValue(objectId, out var c) ? c : null; _containers.TryGetValue(objectId, out var c) ? c : null;
/// <summary> /// <summary>
/// Register / refresh an item in the repository. Called on /// Register / refresh an object in the table. Called on
/// CreateObject for item-typed weenies and on IdentifyObjectResponse /// CreateObject for item-typed weenies and on IdentifyObjectResponse
/// to fill in detail properties. /// to fill in detail properties.
/// </summary> /// </summary>
public void AddOrUpdate(ItemInstance item) public void AddOrUpdate(ClientObject item)
{ {
ArgumentNullException.ThrowIfNull(item); ArgumentNullException.ThrowIfNull(item);
bool existed = _items.ContainsKey(item.ObjectId); bool existed = _items.ContainsKey(item.ObjectId);
_items[item.ObjectId] = item; _items[item.ObjectId] = item;
if (!existed) ItemAdded?.Invoke(item); if (!existed) ObjectAdded?.Invoke(item);
else ItemPropertiesUpdated?.Invoke(item); else ObjectUpdated?.Invoke(item);
} }
/// <summary> /// <summary>
@ -114,7 +112,7 @@ public sealed class ItemRepository
/// Handle a server-driven move — called from /// Handle a server-driven move — called from
/// InventoryPutObjInContainer (0x0022) and WieldObject (0x0023) /// InventoryPutObjInContainer (0x0022) and WieldObject (0x0023)
/// handlers. Updates ContainerId / ContainerSlot / CurrentlyEquippedLocation /// handlers. Updates ContainerId / ContainerSlot / CurrentlyEquippedLocation
/// and fires ItemMoved. /// and fires ObjectMoved.
/// </summary> /// </summary>
public bool MoveItem(uint itemId, uint newContainerId, int newSlot = -1, public bool MoveItem(uint itemId, uint newContainerId, int newSlot = -1,
EquipMask newEquipLocation = EquipMask.None) EquipMask newEquipLocation = EquipMask.None)
@ -126,7 +124,7 @@ public sealed class ItemRepository
item.ContainerSlot = newSlot; item.ContainerSlot = newSlot;
item.CurrentlyEquippedLocation = newEquipLocation; item.CurrentlyEquippedLocation = newEquipLocation;
ItemMoved?.Invoke(item, oldContainer, newContainerId); ObjectMoved?.Invoke(item, oldContainer, newContainerId);
return true; return true;
} }
@ -137,16 +135,16 @@ public sealed class ItemRepository
public bool Remove(uint itemId) public bool Remove(uint itemId)
{ {
if (!_items.TryRemove(itemId, out var item)) return false; if (!_items.TryRemove(itemId, out var item)) return false;
ItemRemoved?.Invoke(item); ObjectRemoved?.Invoke(item);
return true; return true;
} }
/// <summary> /// <summary>
/// Enrich an already-known item (a stub created from PlayerDescription) with the /// Enrich an already-known object (a stub created from PlayerDescription) with the
/// fuller data carried by its CreateObject (icon, name, type). Returns false if the /// fuller data carried by its CreateObject (icon, name, type). Returns false if the
/// item isn't tracked yet — phase 1 enriches existing items only; full /// object isn't tracked yet — phase 1 enriches existing objects only; full
/// CreateObject ingestion of newly-acquired items is the inventory phase. /// CreateObject ingestion of newly-acquired items is the inventory phase.
/// Raises ItemPropertiesUpdated whenever the item is found (matching the /// Raises ObjectUpdated whenever the object is found (matching the
/// UpdateProperties convention — it fires on found regardless of whether a field /// UpdateProperties convention — it fires on found regardless of whether a field
/// actually changed) so bound widgets (the toolbar) re-render. /// actually changed) so bound widgets (the toolbar) re-render.
/// <para> /// <para>
@ -168,13 +166,13 @@ public sealed class ItemRepository
// D.5.2: 0 is a meaningful "no effect" state (e.g. a caster out of mana), // D.5.2: 0 is a meaningful "no effect" state (e.g. a caster out of mana),
// so assign unconditionally — re-composition reflects the CURRENT state. // so assign unconditionally — re-composition reflects the CURRENT state.
item.Effects = effects; item.Effects = effects;
ItemPropertiesUpdated?.Invoke(item); ObjectUpdated?.Invoke(item);
return true; return true;
} }
/// <summary> /// <summary>
/// Apply a <see cref="PropertyBundle"/> patch (e.g. from an /// Apply a <see cref="PropertyBundle"/> patch (e.g. from an
/// <c>IdentifyObjectResponse</c>) to an existing item. Individual /// <c>IdentifyObjectResponse</c>) to an existing object. Individual
/// keys in the incoming bundle overwrite existing values; keys not /// keys in the incoming bundle overwrite existing values; keys not
/// present are left untouched. /// present are left untouched.
/// </summary> /// </summary>
@ -188,29 +186,29 @@ public sealed class ItemRepository
foreach (var kv in incoming.Strings) item.Properties.Strings[kv.Key] = kv.Value; foreach (var kv in incoming.Strings) item.Properties.Strings[kv.Key] = kv.Value;
foreach (var kv in incoming.DataIds) item.Properties.DataIds[kv.Key] = kv.Value; foreach (var kv in incoming.DataIds) item.Properties.DataIds[kv.Key] = kv.Value;
foreach (var kv in incoming.InstanceIds) item.Properties.InstanceIds[kv.Key] = kv.Value; foreach (var kv in incoming.InstanceIds) item.Properties.InstanceIds[kv.Key] = kv.Value;
ItemPropertiesUpdated?.Invoke(item); ObjectUpdated?.Invoke(item);
return true; return true;
} }
/// <summary> /// <summary>
/// Apply a single PropertyInt update (from PublicUpdatePropertyInt 0x02CE) to an /// Apply a single PropertyInt update (from PublicUpdatePropertyInt 0x02CE) to an
/// item: store it in the bundle and, for known typed ints, mirror to the typed /// object: store it in the bundle and, for known typed ints, mirror to the typed
/// field. Today: UiEffects (18) → <see cref="ItemInstance.Effects"/>. Fires /// field. Today: UiEffects (18) → <see cref="ClientObject.Effects"/>. Fires
/// ItemPropertiesUpdated so bound widgets re-composite. Extensible hook for future /// ObjectUpdated so bound widgets re-composite. Extensible hook for future
/// typed PropertyInts (StackSize, Structure, …). False if the item is unknown. /// typed PropertyInts (StackSize, Structure, …). False if the object is unknown.
/// </summary> /// </summary>
public bool UpdateIntProperty(uint itemId, uint propertyId, int value) public bool UpdateIntProperty(uint itemId, uint propertyId, int value)
{ {
if (!_items.TryGetValue(itemId, out var item)) return false; if (!_items.TryGetValue(itemId, out var item)) return false;
item.Properties.Ints[propertyId] = value; item.Properties.Ints[propertyId] = value;
if (propertyId == UiEffectsPropertyId) item.Effects = (uint)value; if (propertyId == UiEffectsPropertyId) item.Effects = (uint)value;
ItemPropertiesUpdated?.Invoke(item); ObjectUpdated?.Invoke(item);
return true; return true;
} }
/// <summary> /// <summary>
/// Flush the repository — typically called on logoff or teleport /// Flush the table — typically called on logoff or teleport
/// that drops the session's item state. /// that drops the session's object state.
/// </summary> /// </summary>
public void Clear() public void Clear()
{ {

View file

@ -47,8 +47,8 @@ public class ToolbarControllerTests
public void Populate_bindsShortcutToCorrectSlot() public void Populate_bindsShortcutToCorrectSlot()
{ {
var (layout, slots, _) = FakeToolbar(); var (layout, slots, _) = FakeToolbar();
var repo = new ItemRepository(); var repo = new ClientObjectTable();
repo.AddOrUpdate(new ItemInstance { ObjectId = 0x5001u, WeenieClassId = 1u, IconId = 0x06001234u }); repo.AddOrUpdate(new ClientObject { ObjectId = 0x5001u, WeenieClassId = 1u, IconId = 0x06001234u });
var shortcuts = new List<PlayerDescriptionParser.ShortcutEntry> var shortcuts = new List<PlayerDescriptionParser.ShortcutEntry>
{ new(Index: 0, ObjectGuid: 0x5001u, SpellId: 0, Layer: 0) }; { new(Index: 0, ObjectGuid: 0x5001u, SpellId: 0, Layer: 0) };
@ -64,7 +64,7 @@ public class ToolbarControllerTests
public void DeferredRebind_whenItemArrivesLate() public void DeferredRebind_whenItemArrivesLate()
{ {
var (layout, slots, _) = FakeToolbar(); var (layout, slots, _) = FakeToolbar();
var repo = new ItemRepository(); // item NOT present yet var repo = new ClientObjectTable(); // item NOT present yet
var shortcuts = new List<PlayerDescriptionParser.ShortcutEntry> var shortcuts = new List<PlayerDescriptionParser.ShortcutEntry>
{ new(Index: 2, ObjectGuid: 0x5002u, SpellId: 0, Layer: 0) }; { new(Index: 2, ObjectGuid: 0x5002u, SpellId: 0, Layer: 0) };
@ -72,7 +72,7 @@ public class ToolbarControllerTests
iconIds: (_,_,_,_,_) => 0x88u, useItem: _ => { }); iconIds: (_,_,_,_,_) => 0x88u, useItem: _ => { });
Assert.Equal(0u, slots[Row1[2]].Cell.ItemId); // not bound yet Assert.Equal(0u, slots[Row1[2]].Cell.ItemId); // not bound yet
repo.AddOrUpdate(new ItemInstance { ObjectId = 0x5002u, WeenieClassId = 1u, IconId = 0x06005678u }); repo.AddOrUpdate(new ClientObject { ObjectId = 0x5002u, WeenieClassId = 1u, IconId = 0x06005678u });
Assert.Equal(0x5002u, slots[Row1[2]].Cell.ItemId); // rebound on ItemAdded Assert.Equal(0x5002u, slots[Row1[2]].Cell.ItemId); // rebound on ItemAdded
} }
@ -81,8 +81,8 @@ public class ToolbarControllerTests
public void Click_emitsUseForBoundItem() public void Click_emitsUseForBoundItem()
{ {
var (layout, slots, _) = FakeToolbar(); var (layout, slots, _) = FakeToolbar();
var repo = new ItemRepository(); var repo = new ClientObjectTable();
repo.AddOrUpdate(new ItemInstance { ObjectId = 0x5001u, WeenieClassId = 1u, IconId = 0x06001234u }); repo.AddOrUpdate(new ClientObject { ObjectId = 0x5001u, WeenieClassId = 1u, IconId = 0x06001234u });
var shortcuts = new List<PlayerDescriptionParser.ShortcutEntry> var shortcuts = new List<PlayerDescriptionParser.ShortcutEntry>
{ new(Index: 0, ObjectGuid: 0x5001u, SpellId: 0, Layer: 0) }; { new(Index: 0, ObjectGuid: 0x5001u, SpellId: 0, Layer: 0) };
uint used = 0; uint used = 0;
@ -106,7 +106,7 @@ public class ToolbarControllerTests
public void CombatIndicator_defaultNonCombat_onlyPeaceVisible() public void CombatIndicator_defaultNonCombat_onlyPeaceVisible()
{ {
var (layout, _, indicators) = FakeToolbar(); var (layout, _, indicators) = FakeToolbar();
var repo = new ItemRepository(); var repo = new ClientObjectTable();
ToolbarController.Bind(layout, repo, ToolbarController.Bind(layout, repo,
() => Array.Empty<PlayerDescriptionParser.ShortcutEntry>(), () => Array.Empty<PlayerDescriptionParser.ShortcutEntry>(),
@ -126,7 +126,7 @@ public class ToolbarControllerTests
public void CombatIndicator_setCombatModeMelee_onlyMeleeVisible() public void CombatIndicator_setCombatModeMelee_onlyMeleeVisible()
{ {
var (layout, _, indicators) = FakeToolbar(); var (layout, _, indicators) = FakeToolbar();
var repo = new ItemRepository(); var repo = new ClientObjectTable();
var ctrl = ToolbarController.Bind(layout, repo, var ctrl = ToolbarController.Bind(layout, repo,
() => Array.Empty<PlayerDescriptionParser.ShortcutEntry>(), () => Array.Empty<PlayerDescriptionParser.ShortcutEntry>(),
@ -147,7 +147,7 @@ public class ToolbarControllerTests
public void CombatIndicator_liveSignal_updatesWhenCombatStateChanges() public void CombatIndicator_liveSignal_updatesWhenCombatStateChanges()
{ {
var (layout, _, indicators) = FakeToolbar(); var (layout, _, indicators) = FakeToolbar();
var repo = new ItemRepository(); var repo = new ClientObjectTable();
var combat = new CombatState(); var combat = new CombatState();
ToolbarController.Bind(layout, repo, ToolbarController.Bind(layout, repo,
@ -187,7 +187,7 @@ public class ToolbarControllerTests
public void ShortcutNumbers_afterBind_topRowHasNumbers_bottomRowEmpty() public void ShortcutNumbers_afterBind_topRowHasNumbers_bottomRowEmpty()
{ {
var (layout, slots, _) = FakeToolbar(); var (layout, slots, _) = FakeToolbar();
var repo = new ItemRepository(); var repo = new ClientObjectTable();
ToolbarController.Bind(layout, repo, ToolbarController.Bind(layout, repo,
() => Array.Empty<PlayerDescriptionParser.ShortcutEntry>(), () => Array.Empty<PlayerDescriptionParser.ShortcutEntry>(),
@ -213,7 +213,7 @@ public class ToolbarControllerTests
public void ShortcutNumbers_setCombatModeWar_topRowUsesWarDigits() public void ShortcutNumbers_setCombatModeWar_topRowUsesWarDigits()
{ {
var (layout, slots, _) = FakeToolbar(); var (layout, slots, _) = FakeToolbar();
var repo = new ItemRepository(); var repo = new ClientObjectTable();
var ctrl = ToolbarController.Bind(layout, repo, var ctrl = ToolbarController.Bind(layout, repo,
() => Array.Empty<PlayerDescriptionParser.ShortcutEntry>(), () => Array.Empty<PlayerDescriptionParser.ShortcutEntry>(),
iconIds: (_,_,_,_,_) => 0u, useItem: _ => { }, iconIds: (_,_,_,_,_) => 0u, useItem: _ => { },
@ -240,7 +240,7 @@ public class ToolbarControllerTests
public void ShortcutNumbers_backToNonCombat_restoresPeaceDigits() public void ShortcutNumbers_backToNonCombat_restoresPeaceDigits()
{ {
var (layout, slots, _) = FakeToolbar(); var (layout, slots, _) = FakeToolbar();
var repo = new ItemRepository(); var repo = new ClientObjectTable();
var ctrl = ToolbarController.Bind(layout, repo, var ctrl = ToolbarController.Bind(layout, repo,
() => Array.Empty<PlayerDescriptionParser.ShortcutEntry>(), () => Array.Empty<PlayerDescriptionParser.ShortcutEntry>(),
iconIds: (_,_,_,_,_) => 0u, useItem: _ => { }, iconIds: (_,_,_,_,_) => 0u, useItem: _ => { },
@ -261,7 +261,7 @@ public class ToolbarControllerTests
public void ShortcutNumbers_digitArraysInjected() public void ShortcutNumbers_digitArraysInjected()
{ {
var (layout, slots, _) = FakeToolbar(); var (layout, slots, _) = FakeToolbar();
var repo = new ItemRepository(); var repo = new ClientObjectTable();
ToolbarController.Bind(layout, repo, ToolbarController.Bind(layout, repo,
() => Array.Empty<PlayerDescriptionParser.ShortcutEntry>(), () => Array.Empty<PlayerDescriptionParser.ShortcutEntry>(),
@ -283,7 +283,7 @@ public class ToolbarControllerTests
public void ShortcutNumbers_emptyDigitArrayInjected() public void ShortcutNumbers_emptyDigitArrayInjected()
{ {
var (layout, slots, _) = FakeToolbar(); var (layout, slots, _) = FakeToolbar();
var repo = new ItemRepository(); var repo = new ClientObjectTable();
ToolbarController.Bind(layout, repo, ToolbarController.Bind(layout, repo,
() => Array.Empty<PlayerDescriptionParser.ShortcutEntry>(), () => Array.Empty<PlayerDescriptionParser.ShortcutEntry>(),
@ -304,7 +304,7 @@ public class ToolbarControllerTests
public void ShortcutNumbers_nullEmptyDigits_cellsHaveNullEmptyDigits() public void ShortcutNumbers_nullEmptyDigits_cellsHaveNullEmptyDigits()
{ {
var (layout, slots, _) = FakeToolbar(); var (layout, slots, _) = FakeToolbar();
var repo = new ItemRepository(); var repo = new ClientObjectTable();
ToolbarController.Bind(layout, repo, ToolbarController.Bind(layout, repo,
() => Array.Empty<PlayerDescriptionParser.ShortcutEntry>(), () => Array.Empty<PlayerDescriptionParser.ShortcutEntry>(),

View file

@ -37,10 +37,10 @@ public sealed class GameEventWiringTests
return body; return body;
} }
private static (GameEventDispatcher, ItemRepository, CombatState, Spellbook, ChatLog) MakeAll() private static (GameEventDispatcher, ClientObjectTable, CombatState, Spellbook, ChatLog) MakeAll()
{ {
var dispatcher = new GameEventDispatcher(); var dispatcher = new GameEventDispatcher();
var items = new ItemRepository(); var items = new ClientObjectTable();
var combat = new CombatState(); var combat = new CombatState();
var spellbook = new Spellbook(); var spellbook = new Spellbook();
var chat = new ChatLog(); var chat = new ChatLog();
@ -101,10 +101,10 @@ public sealed class GameEventWiringTests
} }
[Fact] [Fact]
public void WireAll_WieldObject_RoutesToItemRepository() public void WireAll_WieldObject_RoutesToClientObjectTable()
{ {
var (d, items, _, _, _) = MakeAll(); var (d, items, _, _, _) = MakeAll();
items.AddOrUpdate(new ItemInstance { ObjectId = 0x1000, WeenieClassId = 1 }); items.AddOrUpdate(new ClientObject { ObjectId = 0x1000, WeenieClassId = 1 });
byte[] payload = new byte[12]; byte[] payload = new byte[12];
BinaryPrimitives.WriteUInt32LittleEndian(payload, 0x1000); BinaryPrimitives.WriteUInt32LittleEndian(payload, 0x1000);
@ -114,7 +114,7 @@ public sealed class GameEventWiringTests
var env = GameEventEnvelope.TryParse(WrapEnvelope(GameEventType.WieldObject, payload)); var env = GameEventEnvelope.TryParse(WrapEnvelope(GameEventType.WieldObject, payload));
d.Dispatch(env!.Value); d.Dispatch(env!.Value);
var item = items.GetItem(0x1000); var item = items.Get(0x1000);
Assert.NotNull(item); Assert.NotNull(item);
Assert.Equal(EquipMask.MeleeWeapon, item!.CurrentlyEquippedLocation); Assert.Equal(EquipMask.MeleeWeapon, item!.CurrentlyEquippedLocation);
Assert.Equal(0x2000u, item.ContainerId); Assert.Equal(0x2000u, item.ContainerId);
@ -141,7 +141,7 @@ public sealed class GameEventWiringTests
// through WireAll, lands in LocalPlayerState with the right // through WireAll, lands in LocalPlayerState with the right
// ranks/start/current values. // ranks/start/current values.
var dispatcher = new GameEventDispatcher(); var dispatcher = new GameEventDispatcher();
var items = new ItemRepository(); var items = new ClientObjectTable();
var combat = new CombatState(); var combat = new CombatState();
var spellbook = new Spellbook(); var spellbook = new Spellbook();
var chat = new ChatLog(); var chat = new ChatLog();
@ -200,7 +200,7 @@ public sealed class GameEventWiringTests
public void WireAll_PlayerDescription_FeedsSpellbook() public void WireAll_PlayerDescription_FeedsSpellbook()
{ {
var dispatcher = new GameEventDispatcher(); var dispatcher = new GameEventDispatcher();
var items = new ItemRepository(); var items = new ClientObjectTable();
var combat = new CombatState(); var combat = new CombatState();
var spellbook = new Spellbook(); var spellbook = new Spellbook();
var chat = new ChatLog(); var chat = new ChatLog();
@ -330,20 +330,20 @@ public sealed class GameEventWiringTests
} }
[Fact] [Fact]
public void PlayerDescription_RegistersInventoryEntries_InItemRepository() public void PlayerDescription_RegistersInventoryEntries_InClientObjectTable()
{ {
// Issue #13 acceptance test: after a PlayerDescription with non-empty // Issue #13 acceptance test: after a PlayerDescription with non-empty
// Inventory is dispatched through WireAll, ItemRepository.ItemCount > 0. // Inventory is dispatched through WireAll, ClientObjectTable.ObjectCount > 0.
// Wire format: strict path (no GAMEPLAY_OPTIONS bit) so inventory + // Wire format: strict path (no GAMEPLAY_OPTIONS bit) so inventory +
// equipped follow directly after spellbook_filters. // equipped follow directly after spellbook_filters.
var dispatcher = new GameEventDispatcher(); var dispatcher = new GameEventDispatcher();
var items = new ItemRepository(); var items = new ClientObjectTable();
var combat = new CombatState(); var combat = new CombatState();
var spellbook = new Spellbook(); var spellbook = new Spellbook();
var chat = new ChatLog(); var chat = new ChatLog();
GameEventWiring.WireAll(dispatcher, items, combat, spellbook, chat); GameEventWiring.WireAll(dispatcher, items, combat, spellbook, chat);
Assert.Equal(0, items.ItemCount); // pre-condition Assert.Equal(0, items.ObjectCount); // pre-condition
var sb = new MemoryStream(); var sb = new MemoryStream();
using var w = new BinaryWriter(sb); using var w = new BinaryWriter(sb);
@ -370,9 +370,9 @@ public sealed class GameEventWiringTests
var env = GameEventEnvelope.TryParse(WrapEnvelope(GameEventType.PlayerDescription, sb.ToArray())); var env = GameEventEnvelope.TryParse(WrapEnvelope(GameEventType.PlayerDescription, sb.ToArray()));
dispatcher.Dispatch(env!.Value); dispatcher.Dispatch(env!.Value);
Assert.Equal(2, items.ItemCount); Assert.Equal(2, items.ObjectCount);
Assert.NotNull(items.GetItem(0x50000A01u)); Assert.NotNull(items.Get(0x50000A01u));
Assert.NotNull(items.GetItem(0x50000A02u)); Assert.NotNull(items.Get(0x50000A02u));
} }
[Fact] [Fact]
@ -380,14 +380,14 @@ public sealed class GameEventWiringTests
{ {
// D.5.1 Task 4: WireAll must forward parsed.Shortcuts to the onShortcuts // D.5.1 Task 4: WireAll must forward parsed.Shortcuts to the onShortcuts
// callback so the toolbar can read them without keeping a parser reference. // callback so the toolbar can read them without keeping a parser reference.
// Mirrors PlayerDescription_RegistersInventoryEntries_InItemRepository // Mirrors PlayerDescription_RegistersInventoryEntries_InClientObjectTable
// for the harness pattern; adds the Shortcut flag (0x1) + one 12-byte // for the harness pattern; adds the Shortcut flag (0x1) + one 12-byte
// entry, followed by the legacy-hotbar count (0) + spellbook_filters (0) // entry, followed by the legacy-hotbar count (0) + spellbook_filters (0)
// then empty inventory and equipped. // then empty inventory and equipped.
IReadOnlyList<PlayerDescriptionParser.ShortcutEntry>? got = null; IReadOnlyList<PlayerDescriptionParser.ShortcutEntry>? got = null;
var dispatcher = new GameEventDispatcher(); var dispatcher = new GameEventDispatcher();
var items = new ItemRepository(); var items = new ClientObjectTable();
var combat = new CombatState(); var combat = new CombatState();
var spellbook = new Spellbook(); var spellbook = new Spellbook();
var chat = new ChatLog(); var chat = new ChatLog();

View file

@ -3,10 +3,10 @@ using Xunit;
namespace AcDream.Core.Tests.Items; namespace AcDream.Core.Tests.Items;
public sealed class ItemRepositoryTests public sealed class ClientObjectTableTests
{ {
private static ItemInstance MakeItem(uint id, string name = "Widget") => private static ClientObject MakeItem(uint id, string name = "Widget") =>
new ItemInstance new ClientObject
{ {
ObjectId = id, ObjectId = id,
WeenieClassId = 1, WeenieClassId = 1,
@ -20,27 +20,27 @@ public sealed class ItemRepositoryTests
[Fact] [Fact]
public void AddOrUpdate_FiresAddedEvent() public void AddOrUpdate_FiresAddedEvent()
{ {
var repo = new ItemRepository(); var repo = new ClientObjectTable();
ItemInstance? added = null; ClientObject? added = null;
repo.ItemAdded += i => added = i; repo.ObjectAdded += i => added = i;
var item = MakeItem(100); var item = MakeItem(100);
repo.AddOrUpdate(item); repo.AddOrUpdate(item);
Assert.Same(item, added); Assert.Same(item, added);
Assert.Equal(1, repo.ItemCount); Assert.Equal(1, repo.ObjectCount);
Assert.Same(item, repo.GetItem(100)); Assert.Same(item, repo.Get(100));
} }
[Fact] [Fact]
public void AddOrUpdate_ExistingItem_FiresPropertiesUpdated() public void AddOrUpdate_ExistingItem_FiresPropertiesUpdated()
{ {
var repo = new ItemRepository(); var repo = new ClientObjectTable();
var item = MakeItem(100); var item = MakeItem(100);
repo.AddOrUpdate(item); repo.AddOrUpdate(item);
int propUpdateCount = 0; int propUpdateCount = 0;
repo.ItemPropertiesUpdated += _ => propUpdateCount++; repo.ObjectUpdated += _ => propUpdateCount++;
repo.AddOrUpdate(item); // second call is an update repo.AddOrUpdate(item); // second call is an update
Assert.Equal(1, propUpdateCount); Assert.Equal(1, propUpdateCount);
@ -49,12 +49,12 @@ public sealed class ItemRepositoryTests
[Fact] [Fact]
public void MoveItem_UpdatesContainerAndFiresEvent() public void MoveItem_UpdatesContainerAndFiresEvent()
{ {
var repo = new ItemRepository(); var repo = new ClientObjectTable();
var item = MakeItem(100); var item = MakeItem(100);
repo.AddOrUpdate(item); repo.AddOrUpdate(item);
uint seenOld = 999, seenNew = 999; uint seenOld = 999, seenNew = 999;
repo.ItemMoved += (it, oldC, newC) => { seenOld = oldC; seenNew = newC; }; repo.ObjectMoved += (it, oldC, newC) => { seenOld = oldC; seenNew = newC; };
repo.MoveItem(100, 42, newSlot: 3); repo.MoveItem(100, 42, newSlot: 3);
@ -67,29 +67,29 @@ public sealed class ItemRepositoryTests
[Fact] [Fact]
public void MoveItem_Nonexistent_ReturnsFalse() public void MoveItem_Nonexistent_ReturnsFalse()
{ {
var repo = new ItemRepository(); var repo = new ClientObjectTable();
Assert.False(repo.MoveItem(999, 42)); Assert.False(repo.MoveItem(999, 42));
} }
[Fact] [Fact]
public void Remove_FiresEventAndRemoves() public void Remove_FiresEventAndRemoves()
{ {
var repo = new ItemRepository(); var repo = new ClientObjectTable();
var item = MakeItem(100); var item = MakeItem(100);
repo.AddOrUpdate(item); repo.AddOrUpdate(item);
ItemInstance? removed = null; ClientObject? removed = null;
repo.ItemRemoved += i => removed = i; repo.ObjectRemoved += i => removed = i;
Assert.True(repo.Remove(100)); Assert.True(repo.Remove(100));
Assert.Same(item, removed); Assert.Same(item, removed);
Assert.Null(repo.GetItem(100)); Assert.Null(repo.Get(100));
} }
[Fact] [Fact]
public void UpdateProperties_MergesIncomingBundle() public void UpdateProperties_MergesIncomingBundle()
{ {
var repo = new ItemRepository(); var repo = new ClientObjectTable();
var item = MakeItem(100); var item = MakeItem(100);
item.Properties.Ints[1] = 10; item.Properties.Ints[1] = 10;
repo.AddOrUpdate(item); repo.AddOrUpdate(item);
@ -108,67 +108,67 @@ public sealed class ItemRepositoryTests
[Fact] [Fact]
public void Clear_RemovesAllItems() public void Clear_RemovesAllItems()
{ {
var repo = new ItemRepository(); var repo = new ClientObjectTable();
repo.AddOrUpdate(MakeItem(1)); repo.AddOrUpdate(MakeItem(1));
repo.AddOrUpdate(MakeItem(2)); repo.AddOrUpdate(MakeItem(2));
repo.AddOrUpdate(MakeItem(3)); repo.AddOrUpdate(MakeItem(3));
repo.Clear(); repo.Clear();
Assert.Equal(0, repo.ItemCount); Assert.Equal(0, repo.ObjectCount);
} }
[Fact] [Fact]
public void EnrichItem_updatesIconOnExistingStub_andRaisesUpdated() public void EnrichItem_updatesIconOnExistingStub_andRaisesUpdated()
{ {
var repo = new ItemRepository(); var repo = new ClientObjectTable();
repo.AddOrUpdate(new ItemInstance { ObjectId = 0x5001u, WeenieClassId = 42u }); // stub from PlayerDescription repo.AddOrUpdate(new ClientObject { ObjectId = 0x5001u, WeenieClassId = 42u }); // stub from PlayerDescription
ItemInstance? updated = null; ClientObject? updated = null;
repo.ItemPropertiesUpdated += i => updated = i; repo.ObjectUpdated += i => updated = i;
bool hit = repo.EnrichItem(0x5001u, iconId: 0x06001234u, name: "Mana Stone", type: ItemType.Misc); bool hit = repo.EnrichItem(0x5001u, iconId: 0x06001234u, name: "Mana Stone", type: ItemType.Misc);
Assert.True(hit); Assert.True(hit);
Assert.Equal(0x06001234u, repo.GetItem(0x5001u)!.IconId); Assert.Equal(0x06001234u, repo.Get(0x5001u)!.IconId);
Assert.Equal("Mana Stone", repo.GetItem(0x5001u)!.Name); Assert.Equal("Mana Stone", repo.Get(0x5001u)!.Name);
Assert.NotNull(updated); Assert.NotNull(updated);
} }
[Fact] [Fact]
public void EnrichItem_returnsFalse_whenItemUnknown() public void EnrichItem_returnsFalse_whenItemUnknown()
{ {
var repo = new ItemRepository(); var repo = new ClientObjectTable();
Assert.False(repo.EnrichItem(0x9999u, 0x06001234u, "x", ItemType.Misc)); Assert.False(repo.EnrichItem(0x9999u, 0x06001234u, "x", ItemType.Misc));
} }
[Fact] [Fact]
public void EnrichItem_carriesEffects() public void EnrichItem_carriesEffects()
{ {
var repo = new ItemRepository(); var repo = new ClientObjectTable();
repo.AddOrUpdate(new ItemInstance { ObjectId = 0x500000AAu }); repo.AddOrUpdate(new ClientObject { ObjectId = 0x500000AAu });
bool ok = repo.EnrichItem(0x500000AAu, iconId: 0x06001234u, name: "Wand", bool ok = repo.EnrichItem(0x500000AAu, iconId: 0x06001234u, name: "Wand",
type: ItemType.Caster, iconOverlayId: 0, iconUnderlayId: 0, effects: 0x1u); type: ItemType.Caster, iconOverlayId: 0, iconUnderlayId: 0, effects: 0x1u);
Assert.True(ok); Assert.True(ok);
Assert.Equal(0x1u, repo.GetItem(0x500000AAu)!.Effects); Assert.Equal(0x1u, repo.Get(0x500000AAu)!.Effects);
} }
[Fact] [Fact]
public void UpdateIntProperty_uiEffects_setsEffectsAndFires() public void UpdateIntProperty_uiEffects_setsEffectsAndFires()
{ {
var repo = new ItemRepository(); var repo = new ClientObjectTable();
repo.AddOrUpdate(new ItemInstance { ObjectId = 0x500000ABu }); repo.AddOrUpdate(new ClientObject { ObjectId = 0x500000ABu });
ItemInstance? fired = null; ClientObject? fired = null;
repo.ItemPropertiesUpdated += i => fired = i; repo.ObjectUpdated += i => fired = i;
bool ok = repo.UpdateIntProperty(0x500000ABu, ItemRepository.UiEffectsPropertyId, value: 0x9); bool ok = repo.UpdateIntProperty(0x500000ABu, ClientObjectTable.UiEffectsPropertyId, value: 0x9);
Assert.True(ok); Assert.True(ok);
Assert.Equal(0x9u, repo.GetItem(0x500000ABu)!.Effects); Assert.Equal(0x9u, repo.Get(0x500000ABu)!.Effects);
Assert.Equal(0x9, repo.GetItem(0x500000ABu)!.Properties.Ints[ItemRepository.UiEffectsPropertyId]); Assert.Equal(0x9, repo.Get(0x500000ABu)!.Properties.Ints[ClientObjectTable.UiEffectsPropertyId]);
Assert.NotNull(fired); Assert.NotNull(fired);
} }
[Fact] [Fact]
public void UpdateIntProperty_unknownItem_returnsFalse() public void UpdateIntProperty_unknownItem_returnsFalse()
{ {
var repo = new ItemRepository(); var repo = new ClientObjectTable();
Assert.False(repo.UpdateIntProperty(0xDEADBEEFu, 18u, 1)); Assert.False(repo.UpdateIntProperty(0xDEADBEEFu, 18u, 1));
} }
@ -178,12 +178,12 @@ public sealed class ItemRepositoryTests
// The core "item with mana vs out of mana" promise: a draining item whose // The core "item with mana vs out of mana" promise: a draining item whose
// UiEffects clears to 0 must return to its base (un-tinted) icon. Guards // UiEffects clears to 0 must return to its base (un-tinted) icon. Guards
// against a future `if (value != 0)` regression on the unconditional assign. // against a future `if (value != 0)` regression on the unconditional assign.
var repo = new ItemRepository(); var repo = new ClientObjectTable();
repo.AddOrUpdate(new ItemInstance { ObjectId = 0x500000ACu, Effects = 0x1u }); repo.AddOrUpdate(new ClientObject { ObjectId = 0x500000ACu, Effects = 0x1u });
repo.UpdateIntProperty(0x500000ACu, ItemRepository.UiEffectsPropertyId, value: 0x1); repo.UpdateIntProperty(0x500000ACu, ClientObjectTable.UiEffectsPropertyId, value: 0x1);
Assert.Equal(0x1u, repo.GetItem(0x500000ACu)!.Effects); Assert.Equal(0x1u, repo.Get(0x500000ACu)!.Effects);
repo.UpdateIntProperty(0x500000ACu, ItemRepository.UiEffectsPropertyId, value: 0); repo.UpdateIntProperty(0x500000ACu, ClientObjectTable.UiEffectsPropertyId, value: 0);
Assert.Equal(0u, repo.GetItem(0x500000ACu)!.Effects); Assert.Equal(0u, repo.Get(0x500000ACu)!.Effects);
} }
[Fact] [Fact]
@ -191,11 +191,11 @@ public sealed class ItemRepositoryTests
{ {
// A re-spawn (CreateObject) of a now-inert item carries effects=0; it must // A re-spawn (CreateObject) of a now-inert item carries effects=0; it must
// clear a previously-set effect (unconditional assign, not gated on != 0). // clear a previously-set effect (unconditional assign, not gated on != 0).
var repo = new ItemRepository(); var repo = new ClientObjectTable();
repo.AddOrUpdate(new ItemInstance { ObjectId = 0x500000ADu, Effects = 0x1u }); repo.AddOrUpdate(new ClientObject { ObjectId = 0x500000ADu, Effects = 0x1u });
bool ok = repo.EnrichItem(0x500000ADu, iconId: 0x06001234u, name: "Wand", bool ok = repo.EnrichItem(0x500000ADu, iconId: 0x06001234u, name: "Wand",
type: ItemType.Caster, effects: 0u); type: ItemType.Caster, effects: 0u);
Assert.True(ok); Assert.True(ok);
Assert.Equal(0u, repo.GetItem(0x500000ADu)!.Effects); Assert.Equal(0u, repo.Get(0x500000ADu)!.Effects);
} }
} }