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:
parent
2fc253d9ff
commit
b506f53633
8 changed files with 142 additions and 145 deletions
|
|
@ -595,7 +595,7 @@ public sealed class GameWindow : IDisposable
|
|||
// SpellTable.Empty if the file is missing (e.g. tooling contexts).
|
||||
public readonly AcDream.Core.Spells.SpellTable SpellTable = LoadSpellTable();
|
||||
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>
|
||||
public IReadOnlyList<AcDream.Core.Net.Messages.PlayerDescriptionParser.ShortcutEntry> Shortcuts { get; private set; }
|
||||
= System.Array.Empty<AcDream.Core.Net.Messages.PlayerDescriptionParser.ShortcutEntry>();
|
||||
|
|
@ -2000,7 +2000,7 @@ public sealed class GameWindow : IDisposable
|
|||
if (toolbarLayout is not null)
|
||||
{
|
||||
_toolbarController = AcDream.App.UI.Layout.ToolbarController.Bind(
|
||||
toolbarLayout, Items,
|
||||
toolbarLayout, Objects,
|
||||
() => Shortcuts,
|
||||
iconIds: (type, icon, under, over, effects) => iconComposer.GetIcon(type, icon, under, over, effects),
|
||||
useItem: guid => UseItemByGuid(guid),
|
||||
|
|
@ -2411,7 +2411,7 @@ public sealed class GameWindow : IDisposable
|
|||
var skillTable = _dats?.Get<DatReaderWriter.DBObjs.SkillTable>(0x0E000004u);
|
||||
|
||||
AcDream.Core.Net.GameEventWiring.WireAll(
|
||||
_liveSession.GameEvents, Items, Combat, SpellBook, Chat, LocalPlayer,
|
||||
_liveSession.GameEvents, Objects, Combat, SpellBook, Chat, LocalPlayer,
|
||||
TurbineChat,
|
||||
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.
|
||||
_liveSession.ObjectIntPropertyUpdated += u =>
|
||||
{
|
||||
if (u.Property == AcDream.Core.Items.ItemRepository.UiEffectsPropertyId)
|
||||
Items.UpdateIntProperty(u.Guid, u.Property, u.Value);
|
||||
if (u.Property == AcDream.Core.Items.ClientObjectTable.UiEffectsPropertyId)
|
||||
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.
|
||||
// D.5.1 (2026-06-17): also pass overlay/underlay ids from the extended
|
||||
// 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),
|
||||
spawn.IconOverlayId, spawn.IconUnderlayId, spawn.UiEffects);
|
||||
|
||||
|
|
|
|||
|
|
@ -49,7 +49,7 @@ public sealed class ToolbarController
|
|||
|
||||
private readonly UiItemList?[] _slots = new UiItemList?[SlotIds.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<ItemType, uint, uint, uint, uint, uint> _iconIds; // (itemType, icon, underlay, overlay, effects) → GL tex
|
||||
private readonly Action<uint> _useItem; // guid → fire UseObject
|
||||
|
|
@ -68,7 +68,7 @@ public sealed class ToolbarController
|
|||
|
||||
private ToolbarController(
|
||||
ImportedLayout layout,
|
||||
ItemRepository repo,
|
||||
ClientObjectTable repo,
|
||||
Func<IReadOnlyList<PlayerDescriptionParser.ShortcutEntry>> shortcuts,
|
||||
Func<ItemType, uint, uint, uint, uint, uint> iconIds,
|
||||
Action<uint> useItem,
|
||||
|
|
@ -110,8 +110,8 @@ public sealed class ToolbarController
|
|||
combatState.CombatModeChanged += SetCombatMode;
|
||||
|
||||
// Re-bind any deferred slot whenever the repo learns about a new/updated item.
|
||||
repo.ItemAdded += _ => Populate();
|
||||
repo.ItemPropertiesUpdated += _ => Populate();
|
||||
repo.ObjectAdded += _ => Populate();
|
||||
repo.ObjectUpdated += _ => Populate();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -146,7 +146,7 @@ public sealed class ToolbarController
|
|||
/// </param>
|
||||
public static ToolbarController Bind(
|
||||
ImportedLayout layout,
|
||||
ItemRepository repo,
|
||||
ClientObjectTable repo,
|
||||
Func<IReadOnlyList<PlayerDescriptionParser.ShortcutEntry>> shortcuts,
|
||||
Func<ItemType, uint, uint, uint, uint, uint> iconIds,
|
||||
Action<uint> useItem,
|
||||
|
|
@ -165,7 +165,7 @@ public sealed class ToolbarController
|
|||
/// Port of <c>gmToolbarUI::UpdateFromPlayerDesc</c>: clear all slots, then bind
|
||||
/// 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
|
||||
/// <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).
|
||||
/// </summary>
|
||||
public void Populate()
|
||||
|
|
@ -180,8 +180,8 @@ public sealed class ToolbarController
|
|||
var list = _slots[(int)sc.Index];
|
||||
if (list is null) continue;
|
||||
|
||||
var item = _repo.GetItem(sc.ObjectGuid);
|
||||
if (item is null) continue; // deferred: ItemAdded will re-call Populate
|
||||
var item = _repo.Get(sc.ObjectGuid);
|
||||
if (item is null) continue; // deferred: ObjectAdded will re-call Populate
|
||||
|
||||
uint tex = _iconIds(item.Type, item.IconId, item.IconUnderlayId, item.IconOverlayId, item.Effects);
|
||||
list.Cell.SetItem(sc.ObjectGuid, tex);
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ namespace AcDream.Core.Net;
|
|||
/// <summary>
|
||||
/// Central registration point that wires every parsed GameEvent from
|
||||
/// <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"/>).
|
||||
///
|
||||
/// <para>
|
||||
|
|
@ -32,7 +32,7 @@ public static class GameEventWiring
|
|||
{
|
||||
public static void WireAll(
|
||||
GameEventDispatcher dispatcher,
|
||||
ItemRepository items,
|
||||
ClientObjectTable items,
|
||||
CombatState combat,
|
||||
Spellbook spellbook,
|
||||
ChatLog chat,
|
||||
|
|
@ -251,7 +251,7 @@ public static class GameEventWiring
|
|||
var p = AppraiseInfoParser.TryParse(e.Payload.Span);
|
||||
if (p is null || !p.Value.Success) return;
|
||||
// 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);
|
||||
// Spellbook from appraise: for caster items / scrolls this is
|
||||
// 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}");
|
||||
}
|
||||
|
||||
// Issue #13 — register inventory entries with ItemRepository so
|
||||
// Issue #13 — register inventory entries with ClientObjectTable so
|
||||
// panels (inventory, paperdoll, hotbars) light up after login.
|
||||
// Equipped entries share the same ObjectId as inventory entries
|
||||
// (an equipped item is also in inventory) — register both, but
|
||||
|
|
@ -408,9 +408,9 @@ public static class GameEventWiring
|
|||
// MoveItem so paperdoll can render.
|
||||
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,
|
||||
WeenieClassId = inv.ContainerType,
|
||||
|
|
@ -419,9 +419,9 @@ public static class GameEventWiring
|
|||
}
|
||||
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,
|
||||
WeenieClassId = 0,
|
||||
|
|
|
|||
|
|
@ -121,11 +121,10 @@ public sealed class PropertyBundle
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// Per-item live state. The server owns item identity (ObjectId);
|
||||
/// acdream mirrors properties here on <c>CreateObject</c> and updates
|
||||
/// via <c>UpdateProperty*</c> messages.
|
||||
/// Per-object live state (the data side of every server object — items and creatures alike).
|
||||
/// Retail <c>ACCWeenieObject</c>.
|
||||
/// </summary>
|
||||
public sealed class ItemInstance
|
||||
public sealed class ClientObject
|
||||
{
|
||||
public uint ObjectId { get; init; }
|
||||
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 SideCapacity { get; set; } = 0; // 0 for side-pack
|
||||
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 bool IsSidePack => SideCapacity == 0;
|
||||
}
|
||||
|
|
@ -5,16 +5,14 @@ using System.Collections.Generic;
|
|||
namespace AcDream.Core.Items;
|
||||
|
||||
/// <summary>
|
||||
/// Live item-state mirror — the client-side view of every item the
|
||||
/// server has spawned for this session. Owns <see cref="ItemInstance"/>
|
||||
/// records, tracks which container holds each item, and fires events so
|
||||
/// UI panels (inventory, paperdoll, hotbars) can redraw on change.
|
||||
/// The client's table of every server object (retail <c>weenie_object_table</c> /
|
||||
/// <c>CObjectMaint</c>). Resolve by guid via <c>Get</c>.
|
||||
///
|
||||
/// <para>
|
||||
/// Retail semantics (r06):
|
||||
/// <list type="bullet">
|
||||
/// <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
|
||||
/// the item exists (in our inventory, on the ground, in a
|
||||
/// vendor's list, etc).
|
||||
|
|
@ -40,42 +38,42 @@ namespace AcDream.Core.Items;
|
|||
/// corrupting state.
|
||||
/// </para>
|
||||
/// </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();
|
||||
|
||||
/// <summary>Fires when an item is first added to the session.</summary>
|
||||
public event Action<ItemInstance>? ItemAdded;
|
||||
/// <summary>Fires when an object is first added to the session.</summary>
|
||||
public event Action<ClientObject>? ObjectAdded;
|
||||
|
||||
/// <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
|
||||
/// container ids are 0 if origin or destination is "world" / "nowhere".
|
||||
/// </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>
|
||||
public event Action<ItemInstance>? ItemRemoved;
|
||||
/// <summary>Fires when an object is removed from the session.</summary>
|
||||
public event Action<ClientObject>? ObjectRemoved;
|
||||
|
||||
/// <summary>Fires when an item's properties are updated (typically after Appraise).</summary>
|
||||
public event Action<ItemInstance>? ItemPropertiesUpdated;
|
||||
/// <summary>Fires when an object's properties are updated (typically after Appraise).</summary>
|
||||
public event Action<ClientObject>? ObjectUpdated;
|
||||
|
||||
/// <summary>PropertyInt.UiEffects (ACE enum value 18) — the icon effect bitfield;
|
||||
/// the typed mirror <see cref="UpdateIntProperty"/> maintains on
|
||||
/// <see cref="ItemInstance.Effects"/>.</summary>
|
||||
/// <see cref="ClientObject.Effects"/>.</summary>
|
||||
public const uint UiEffectsPropertyId = 18u;
|
||||
|
||||
public int ItemCount => _items.Count;
|
||||
public int ObjectCount => _items.Count;
|
||||
public int ContainerCount => _containers.Count;
|
||||
|
||||
public IEnumerable<ItemInstance> Items => _items.Values;
|
||||
public IEnumerable<ClientObject> Objects => _items.Values;
|
||||
public IEnumerable<Container> Containers => _containers.Values;
|
||||
|
||||
/// <summary>
|
||||
/// Look up an item by its server-assigned <c>ObjectId</c>.
|
||||
/// Look up an object by its server-assigned <c>ObjectId</c>.
|
||||
/// </summary>
|
||||
public ItemInstance? GetItem(uint objectId) =>
|
||||
public ClientObject? Get(uint objectId) =>
|
||||
_items.TryGetValue(objectId, out var item) ? item : null;
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -88,17 +86,17 @@ public sealed class ItemRepository
|
|||
_containers.TryGetValue(objectId, out var c) ? c : null;
|
||||
|
||||
/// <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
|
||||
/// to fill in detail properties.
|
||||
/// </summary>
|
||||
public void AddOrUpdate(ItemInstance item)
|
||||
public void AddOrUpdate(ClientObject item)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(item);
|
||||
bool existed = _items.ContainsKey(item.ObjectId);
|
||||
_items[item.ObjectId] = item;
|
||||
if (!existed) ItemAdded?.Invoke(item);
|
||||
else ItemPropertiesUpdated?.Invoke(item);
|
||||
if (!existed) ObjectAdded?.Invoke(item);
|
||||
else ObjectUpdated?.Invoke(item);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -114,7 +112,7 @@ public sealed class ItemRepository
|
|||
/// Handle a server-driven move — called from
|
||||
/// InventoryPutObjInContainer (0x0022) and WieldObject (0x0023)
|
||||
/// handlers. Updates ContainerId / ContainerSlot / CurrentlyEquippedLocation
|
||||
/// and fires ItemMoved.
|
||||
/// and fires ObjectMoved.
|
||||
/// </summary>
|
||||
public bool MoveItem(uint itemId, uint newContainerId, int newSlot = -1,
|
||||
EquipMask newEquipLocation = EquipMask.None)
|
||||
|
|
@ -126,7 +124,7 @@ public sealed class ItemRepository
|
|||
item.ContainerSlot = newSlot;
|
||||
item.CurrentlyEquippedLocation = newEquipLocation;
|
||||
|
||||
ItemMoved?.Invoke(item, oldContainer, newContainerId);
|
||||
ObjectMoved?.Invoke(item, oldContainer, newContainerId);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -137,16 +135,16 @@ public sealed class ItemRepository
|
|||
public bool Remove(uint itemId)
|
||||
{
|
||||
if (!_items.TryRemove(itemId, out var item)) return false;
|
||||
ItemRemoved?.Invoke(item);
|
||||
ObjectRemoved?.Invoke(item);
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <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
|
||||
/// 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.
|
||||
/// 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
|
||||
/// actually changed) so bound widgets (the toolbar) re-render.
|
||||
/// <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),
|
||||
// so assign unconditionally — re-composition reflects the CURRENT state.
|
||||
item.Effects = effects;
|
||||
ItemPropertiesUpdated?.Invoke(item);
|
||||
ObjectUpdated?.Invoke(item);
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 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
|
||||
/// present are left untouched.
|
||||
/// </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.DataIds) item.Properties.DataIds[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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 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
|
||||
/// field. Today: UiEffects (18) → <see cref="ItemInstance.Effects"/>. Fires
|
||||
/// ItemPropertiesUpdated so bound widgets re-composite. Extensible hook for future
|
||||
/// typed PropertyInts (StackSize, Structure, …). False if the item is unknown.
|
||||
/// object: store it in the bundle and, for known typed ints, mirror to the typed
|
||||
/// field. Today: UiEffects (18) → <see cref="ClientObject.Effects"/>. Fires
|
||||
/// ObjectUpdated so bound widgets re-composite. Extensible hook for future
|
||||
/// typed PropertyInts (StackSize, Structure, …). False if the object is unknown.
|
||||
/// </summary>
|
||||
public bool UpdateIntProperty(uint itemId, uint propertyId, int value)
|
||||
{
|
||||
if (!_items.TryGetValue(itemId, out var item)) return false;
|
||||
item.Properties.Ints[propertyId] = value;
|
||||
if (propertyId == UiEffectsPropertyId) item.Effects = (uint)value;
|
||||
ItemPropertiesUpdated?.Invoke(item);
|
||||
ObjectUpdated?.Invoke(item);
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Flush the repository — typically called on logoff or teleport
|
||||
/// that drops the session's item state.
|
||||
/// Flush the table — typically called on logoff or teleport
|
||||
/// that drops the session's object state.
|
||||
/// </summary>
|
||||
public void Clear()
|
||||
{
|
||||
Loading…
Add table
Add a link
Reference in a new issue