RynthSuite/Plugins/RynthCore.Plugin.RynthAi/MiniRemote/MiniRemoteInventory.cs
Daniel Wallace 04ecdd64f4 RynthAi jump loot: resend at once when the client's request slot refused the move
The acclient holds one pending inventory request. While it is held, it
refuses any other item move with a LOCAL chat line ("You can only move or
use one item at a time"): nothing reaches the server, no WeenieError
comes, and the engine's MoveItemExternal returns true regardless. The
looter took that send for one in flight and waited the whole answer
window (PickupAnswerWaitMs, 4-8 s) before trying again, and the retry
cost the item one of its 3 tries. At the jump-loot cadence this stalled
the loot 4-8 s at a time.

The line is now heard (NoteSlotRefusalChat, anchored at the line start,
stamped with its arrival time on the loot clock) and attributed to the
current send when it arrived within the send's window (200 ms, or 2.5 s
for a send made while the motion queue was busy, since the engine's main
thread queue holds the move that long) and no other item action of this
plugin went out between that same window before the send and the line
(UseAudit.LastItemActionAt). The send is then repeated 250 ms after it,
without a jump, never counted as one of the 3 tries or as a too-busy free
retry, for up to 11.5 s from the item's first slot refusal (the engine
clears a held slot after 10 s); then the ordinary answer wait takes over.
The refusal baseline is taken in SendLootPickup, the one path every send
goes through, own-corpse sends included.

Item actions are stamped at every UseFor and UseOnFor except the
looter's own, the wand, weapon and offhand wields, the ground pickup, the
give helper and the item tool's give, the salvage sends and panel adds,
the meta give actions and salvage-panel add, the MagTools give, drop and
dequip, the HUD and MiniRemote uses, the stack merges and the trade adds.
Not stamped: vendor buy and sell, the salvage panel execute, pack-to-pack
moves and stack splits, the legacy swap wields and the dashboard's panel
drag (the UseAudit doc names the files). Other plugins' item actions are
not seen: each plugin compiles its own copy of UseAudit.

Adapted to upstream's fight hold: no slot resend while a fight has the
tick (the client drops an item move while the character attacks); the
line is attributed by its arrival time, so the resend goes at once after
the fight, and the fresh send does not inherit the fight flag.

Gated by Jump When Looting (LootJumpEnabled, default off): the net was
measured and tuned on ACE's jump-loot cadence. With the setting off every
send keeps its old wait. The UseAudit stamps are a timestamp only.

Host tests: a slot-refused send is resent in about 250 ms with no try
used; a late line or a player's words are not ours; a line then the
server's answer at 200 ms is one move; resends go on past 7.5 s and hand
over after 11.5 s; a busy-queue send's refusal at 700 ms is its own;
another item action before the line, a UseOnFor included, suppresses it,
and so does one 1 s before a busy-queue send; the reset clears the slot
fields; the looter's own UseOnFor is not stamped, so a line after it is
still ours; with the setting off nothing changes; a refusal during a fight
(driven through the real fight hold) is resent only after it; an
own-corpse send after an earlier refusal line is one move.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-07 10:07:23 -08:00

135 lines
6.7 KiB
C#

// 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.PluginSdk;
namespace RynthCore.Plugin.RynthAi.MiniRemote;
internal sealed class MiniRemoteInventory
{
// ── Well-known WCIDs ────────────────────────────────────────────────────
/// <summary>Encapsulated Spirit (pet essence refills; never a pet itself).</summary>
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<WorldObjectCache?> _cache;
private readonly Dictionary<int, uint> _wcidCache = new();
private readonly Dictionary<int, long> _lastIdRequest = new();
/// <summary>Don't re-request appraisal for the same object more often than this.</summary>
private const long IdRequestThrottleMs = 30_000;
public MiniRemoteInventory(RynthCoreHost host, Func<WorldObjectCache?> cache)
{
_host = host;
_cache = cache;
}
public RynthCoreHost Host => _host;
public WorldObjectCache? Cache => _cache();
public uint PlayerId => _host.GetPlayerId();
// ── Player state ────────────────────────────────────────────────────────
/// <summary>The client busy hourglass is up (an action is in progress).</summary>
public bool IsBusy => _host.HasGetBusyState && _host.GetBusyState() != 0;
/// <summary>Player is in peace mode (combat mode NonCombat). True when the engine can't tell.</summary>
public bool InPeaceMode => !_host.HasGetCurrentCombatMode || _host.GetCurrentCombatMode() == CombatMode.NonCombat;
public bool PlayerBool(uint stype)
=> _host.HasGetObjectBoolProperty && _host.TryGetObjectBoolProperty(PlayerId, stype, out bool v) && v;
/// <summary>Current/max health from the engine vitals read (0/0 when unavailable).</summary>
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 ──────────────────────────────────────────────────────────
/// <summary>All items the player carries or wears (snapshot).</summary>
public IEnumerable<WorldObject> Items() => _cache()?.GetInventory() ?? Enumerable.Empty<WorldObject>();
/// <summary>Weenie class id, cached per object (0 when unknown).</summary>
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;
/// <summary>Remaining uses on a structure item (essences, kits, salvage bags).</summary>
public int Uses(WorldObject wo) => Int(wo, IntStructure, 0);
/// <summary>A bool property of an object (false when unknown or the engine can't read it).</summary>
public bool Bool(WorldObject wo, uint stype)
=> _host.HasGetObjectBoolProperty && _host.TryGetObjectBoolProperty(unchecked((uint)wo.Id), stype, out bool v) && v;
/// <summary>Stack size (1 for a non-stack).</summary>
public int StackSize(WorldObject wo) => Math.Max(1, Int(wo, IntStackSize, 1));
/// <summary>Worn or wielded by the player.</summary>
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));
/// <summary>Requests appraisal data, throttled per object. Returns true if a request was sent.</summary>
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<WorldObject> AllByWcid(params uint[] wcids)
=> Items().Where(wo => Array.IndexOf(wcids, Wcid(wo)) >= 0);
// ── Actions ─────────────────────────────────────────────────────────────
public bool Use(WorldObject wo)
{
if (!_host.HasUseObject) return false;
RynthCore.Plugin.Shared.UseAudit.NoteItemAction(); // a non-loot item action (UseAudit.LastItemActionAt)
return _host.UseObject(unchecked((uint)wo.Id));
}
/// <summary>Forgets cached WCIDs / appraisal throttles (logout).</summary>
public void Reset()
{
_wcidCache.Clear();
_lastIdRequest.Clear();
}
}