Parse and route the complete 0x0264 guid/fraction/valid response, send exact 0x0263 item-mana queries, and reproduce retail meter visibility plus guid-zero cancellation for mana and health selection changes. Keep the behavior in Core state and the retained selected-object controller with wire/state/UI conformance coverage. Co-Authored-By: Codex <codex@openai.com>
35 lines
1.2 KiB
C#
35 lines
1.2 KiB
C#
using System;
|
|
using System.Collections.Concurrent;
|
|
|
|
namespace AcDream.Core.Items;
|
|
|
|
/// <summary>
|
|
/// Last server-reported mana fraction for queried inventory items.
|
|
/// Retail routes <c>QueryItemManaResponse (0x0264)</c> through
|
|
/// <c>ClientUISystem::Handle_Item__QueryItemManaResponse @ 0x00563FE0</c>, including
|
|
/// the response's validity flag, before notifying the selected-object toolbar.
|
|
/// </summary>
|
|
public sealed class ItemManaState
|
|
{
|
|
private readonly ConcurrentDictionary<uint, float> _manaByGuid = new();
|
|
|
|
/// <summary>Fires for every valid or invalid query response.</summary>
|
|
public event Action<uint /*guid*/, float /*fraction*/, bool /*valid*/>? ItemManaChanged;
|
|
|
|
public float GetManaPercent(uint guid) =>
|
|
_manaByGuid.TryGetValue(guid, out float percent) ? percent : 0f;
|
|
|
|
public bool HasMana(uint guid) => _manaByGuid.ContainsKey(guid);
|
|
|
|
public void OnQueryItemManaResponse(uint itemGuid, float manaPercent, bool valid)
|
|
{
|
|
if (valid)
|
|
_manaByGuid[itemGuid] = manaPercent;
|
|
else
|
|
_manaByGuid.TryRemove(itemGuid, out _);
|
|
|
|
ItemManaChanged?.Invoke(itemGuid, manaPercent, valid);
|
|
}
|
|
|
|
public void Clear() => _manaByGuid.Clear();
|
|
}
|