// MiniRemoteInventory.cs — Item / player-property helper for the Mini Remote's universal tabs (Pets, // the VTank .usd importer). The universal part of the ILT Hub's IltInventory (SilentKelpie's; the // ILT Hub went to the RynthILT plugin 2026-10-13, which has its own copy for its ILT features). // // One place for: WCID lookups (cached), stack / use counts, "is it equipped", appraisal requests // (throttled) and player int/bool reads. (The ACECustom pet charms' status went to RynthILT with // the charms, 2026-10-20.) Pump-thread only. using System; using System.Collections.Generic; using System.Linq; using RynthCore.Loot; using RynthCore.Plugin.Shared; using RynthCore.PluginSdk; namespace RynthCore.Plugin.RynthAi.MiniRemote; internal sealed class MiniRemoteInventory { // ── Well-known WCIDs ──────────────────────────────────────────────────── /// Encapsulated Spirit (pet essence refills; never a pet itself). public const uint WcidEncapsulatedSpirit = 49485; // ACECustom's pet charms and the Infinite Casting Stone moved to RynthILT (IltPetAutomation) 2026-10-20. // ── Property ids ──────────────────────────────────────────────────────── public const uint IntStackSize = 12; public const uint IntStructure = 92; // Crafting tab (tinker runs): how often an item was tinkered, its imbue, a salvage bag's material. public const uint IntNumTimesTinkered = 171; public const uint IntImbuedEffect = 179; public const uint IntMaterialType = 131; private readonly RynthCoreHost _host; private readonly Func _cache; private readonly Dictionary _wcidCache = new(); private readonly Dictionary _lastIdRequest = new(); /// Don't re-request appraisal for the same object more often than this. private const long IdRequestThrottleMs = 30_000; public MiniRemoteInventory(RynthCoreHost host, Func cache) { _host = host; _cache = cache; } public RynthCoreHost Host => _host; public WorldObjectCache? Cache => _cache(); public uint PlayerId => _host.GetPlayerId(); // ── Player state ──────────────────────────────────────────────────────── /// The client busy hourglass is up (an action is in progress). public bool IsBusy => _host.HasGetBusyState && _host.GetBusyState() != 0; /// Player is in peace mode (combat mode NonCombat). True when the engine can't tell. public bool InPeaceMode => !_host.HasGetCurrentCombatMode || _host.GetCurrentCombatMode() == CombatMode.NonCombat; public bool PlayerBool(uint stype) => _host.HasGetObjectBoolProperty && _host.TryGetObjectBoolProperty(PlayerId, stype, out bool v) && v; /// Current/max health from the engine vitals read (0/0 when unavailable). public (uint Cur, uint Max) PlayerHealth() { if (_host.HasGetPlayerVitals && _host.TryGetPlayerVitals(out uint h, out uint mh, out _, out _, out _, out _)) return (h, mh); return (0, 0); } // ── Item facts ────────────────────────────────────────────────────────── /// All items the player carries or wears (snapshot). public IEnumerable Items() => _cache()?.GetInventory() ?? Enumerable.Empty(); /// Weenie class id, cached per object (0 when unknown). public uint Wcid(WorldObject wo) { if (_wcidCache.TryGetValue(wo.Id, out uint w) && w != 0) return w; if (_host.HasGetObjectWcid && _host.TryGetObjectWcid(unchecked((uint)wo.Id), out w)) _wcidCache[wo.Id] = w; return w; } public int Int(WorldObject wo, uint stype, int fallback = 0) => wo.Values(unchecked((int)stype), fallback); public string Str(WorldObject wo, uint stype) => _host.HasGetObjectStringProperty && _host.TryGetObjectStringProperty(unchecked((uint)wo.Id), stype, out string v) ? v ?? string.Empty : string.Empty; /// Remaining uses on a structure item (essences, kits, salvage bags). public int Uses(WorldObject wo) => Int(wo, IntStructure, 0); /// A bool property of an object (false when unknown or the engine can't read it). public bool Bool(WorldObject wo, uint stype) => _host.HasGetObjectBoolProperty && _host.TryGetObjectBoolProperty(unchecked((uint)wo.Id), stype, out bool v) && v; /// Stack size (1 for a non-stack). public int StackSize(WorldObject wo) => Math.Max(1, Int(wo, IntStackSize, 1)); /// Worn or wielded by the player. public bool IsEquipped(WorldObject wo) => wo.WieldedLocation > 0 || (wo.Wielder != 0 && unchecked((uint)wo.Wielder) == PlayerId); public bool HasAppraisal(WorldObject wo) => !_host.HasHasAppraisalData || _host.HasAppraisalData(unchecked((uint)wo.Id)); /// Requests appraisal data, throttled per object. Returns true if a request was sent. public bool RequestAppraisal(WorldObject wo) { if (!_host.HasRequestId) return false; long now = Environment.TickCount64; if (_lastIdRequest.TryGetValue(wo.Id, out long last) && now - last < IdRequestThrottleMs) return false; _lastIdRequest[wo.Id] = now; return _host.RequestId(unchecked((uint)wo.Id)); } public WorldObject? FindByWcid(params uint[] wcids) => Items().FirstOrDefault(wo => Array.IndexOf(wcids, Wcid(wo)) >= 0); public IEnumerable AllByWcid(params uint[] wcids) => Items().Where(wo => Array.IndexOf(wcids, Wcid(wo)) >= 0); // ── Actions ───────────────────────────────────────────────────────────── /// /// Uses the item through UseFor, so the log names the feature and the reason /// ("[Use] RynthAi/Pets ... - keep the cosmetic pet out"). It was a bare UseObject: a pet the /// Pets tab summoned (cosmetic, heal pet, the Summon button) left only the engine's "[Use] /// engine:" line, and nothing told it from a combat summon (2026-11-08, R-20261108-194528-ab84). /// public bool Use(WorldObject wo, string why, UseKind kind = UseKind.Auto) => _host.HasUseObject && _host.UseFor(unchecked((uint)wo.Id), "Pets", why, kind); /// Forgets cached WCIDs / appraisal throttles (logout). public void Reset() { _wcidCache.Clear(); _lastIdRequest.Clear(); } }