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>
This commit is contained in:
Daniel Wallace 2026-11-07 08:55:22 -08:00
commit 04ecdd64f4
22 changed files with 526 additions and 5 deletions

View file

@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Threading;
using RynthCore.Plugin.RynthAi.LegacyUi;
using RynthCore.Plugin.RynthAi.Loot;
using RynthCore.Loot.VTank;
@ -206,6 +207,45 @@ public sealed partial class RynthAiPlugin
private int _openInAirWindowSeq = -1;
/// <summary>How long the no-bend-down call stays off after the server proved it wrong.</summary>
internal const long JumpNoMotionDistrustMs = 5 * 60_000;
// The client's one pending-inventory-request slot refused a send: it printed "You can only move
// or use one item at a time" locally and sent nothing to the server. The item is sent again
// SlotRefusalRetryMs after the refused send, for up to SlotRefusalGiveUpMs from its first
// refusal, and no resend counts as one of the item's 3 tries.
// The line is taken for ours only when both of these hold:
// - it ARRIVED (its own stamp, NoteSlotRefusalChat) within the send's window after the send
// (SlotRefusalAttributionMs, or SlotRefusalDeferredWindowMs for a send made while the motion
// queue was busy). The window is by arrival, not by the tick that polls it.
// - no other item action of this plugin (UseAudit.LastItemActionAt) went out between one window
// before the send and the line, since another action's refusal reads the same.
// A count across the send call cannot make this exact: MoveItemExternal from the plugin thread
// only queues the move for AC's main thread (ClientHelperHooks.MoveItemExternal -> AcMainThreadQueue
// .MustQueue, ClientHelperHooks.cs:557-558), the client prints its refusal when that queue
// drains, and the chat line reaches the plugin later still, from the pump's queue
// (PluginManager.QueueChatWindowText / DispatchQueuedChatWindowText).
internal const long SlotRefusalRetryMs = 250;
internal const long SlotRefusalAttributionMs = 200;
// A send made while the character's motion queue is busy (the last pickup's Return, a jump's own
// motion) is held by AC's main-thread queue until that queue is empty or DrainDeferMaxMs has
// passed (RynthCore.Engine AcMainThreadQueue.Drain: it holds the whole ring while the
// pending-motion list is non-empty, DrainDeferMaxMs = 2500; RunsDuringGesture does not include
// item moves), so its refusal can arrive that much later than a send made when still.
internal const long SlotRefusalDeferredWindowMs = 2500;
// The engine clears a request slot whose object is still in the client only after its
// PendingTimeoutMs = 10000 (ClientActionGates.cs); the resends go on that long plus a margin
// from the item's first slot refusal, then the ordinary answer wait takes over.
internal const long SlotRefusalGiveUpMs = 10_000 + 1_500;
internal const string SlotRefusalChat = "You can only move or use one item at a time";
private int _slotRefusalSeq; // refusal lines heard in chat (Interlocked: the chat pump is not the tick)
private long _slotRefusalAt; // CorpseNowMs when the last of them arrived (written before the count)
private int _currentLootItemSlotSeqAtSend; // _slotRefusalSeq at the current item's last send
private long _currentLootItemSlotRefusedAt; // when the slot's refusal of the last send was seen (0 = none)
private int _currentLootItemSlotResends; // slot-refused sends of the current item sent again so far
private long _currentLootItemSlotWindowMs = SlotRefusalAttributionMs; // how late after the current send its refusal line may arrive
private long _currentLootItemFirstSlotRefusalAt; // when the current item's first slot refusal was seen (0 = none)
private bool _currentLootItemSlotGaveUp; // the resends ran out of time: the ordinary answer wait has the item
private int _slotRefusalCollisions; // refusals of a send by the held slot, this session
// [LootEval] lines: one per item per open (a matched item was re-printed before every pickup).
private readonly Dictionary<int, string> _lootEvalLogged = new();
private int _manaStoneCapLoggedFor; // container the "ManaStone count for cap check" line was logged for
@ -1940,6 +1980,7 @@ public sealed partial class RynthAiPlugin
_currentLootItemStackable = stackable;
_currentLootItemErrSeqAtSend = errSeqAtSend;
NoteLootMoveSent();
_currentLootItemSlotResends = 0;
_currentLootItemFreeRetries = 0;
_currentLootItemActionLabel = matchActionLabel;
_currentLootItemName = matchItemName;
@ -2223,6 +2264,7 @@ public sealed partial class RynthAiPlugin
{
_currentLootItemAwaitingAnswer = true;
_currentLootItemResendWaitLogged = false;
_currentLootItemSlotRefusedAt = 0;
_currentLootItemRefusedAt = 0;
_currentLootItemRefusalError = 0;
_currentLootItemRefusalObject = 0;
@ -2256,6 +2298,91 @@ public sealed partial class RynthAiPlugin
DistrustJumpNoMotion(now, $"0x{(uint)_currentLootItemId:X8}, sent on it, was refused as too busy {after} ms after the send");
}
/// <summary>
/// Chat from the game (RynthAiPlugin.OnChatWindowText; the chat pump, not the tick thread). The
/// client's own refusal of an item action while its one pending-inventory-request slot is held
/// is a LOCAL chat line, not a server answer: it reaches no WeenieError (those come from server
/// events), and the engine's MoveItemExternal returns true whether or not the client sent
/// anything. The line is the only sign the plugin gets, so it is counted here and read by
/// <see cref="PollSlotRefusal"/>. Anchored at the line start: a player's chat quoting it is not it.
/// </summary>
internal void NoteSlotRefusalChat(string? text)
{
if (!ChatSource.StartsWithMarker(text, SlotRefusalChat, StringComparison.OrdinalIgnoreCase)) return;
Volatile.Write(ref _slotRefusalAt, CorpseNowMs); // the stamp first: a reader that sees the new count sees its time
Interlocked.Increment(ref _slotRefusalSeq);
}
/// <summary>
/// The current send was turned away by the client's held request slot (heard in chat since the
/// send, within SlotRefusalAttributionMs of it) and is due again SlotRefusalRetryMs after it.
/// Returns true while this item is in that state (the tick has nothing else to do for it).
/// The resend is not one of the item's 3 tries, is not a "too busy" free retry, and does not
/// wait for the PickupAnswerWaitMs (4-8 s) a send with no answer would. It goes without a jump
/// (the floor applies), and it is a fresh send: a fight before it is not this send's. After
/// SlotRefusalGiveUpMs from the item's first refusal it stops and the ordinary answer wait takes
/// over (the engine's own watchdog empties a slot whose object is gone after 5 s and any slot
/// after 10 s).
/// </summary>
private bool PollSlotRefusal(long now)
{
if (_currentLootItemSlotGaveUp) return false;
if (_currentLootItemFirstSlotRefusalAt != 0 && now - _currentLootItemFirstSlotRefusalAt > SlotRefusalGiveUpMs)
{
_currentLootItemSlotGaveUp = true;
LootDiag($"[RynthAi] {LootTag}: 0x{(uint)_currentLootItemId:X8} was refused by the client's request slot for {now - _currentLootItemFirstSlotRefusalAt} ms ({_currentLootItemSlotResends} resends); the ordinary answer wait takes over.");
return false;
}
if (_currentLootItemSlotRefusedAt == 0)
{
if (!_currentLootItemAwaitingAnswer || _currentLootItemRefusedAt != 0) return false;
int seq = Volatile.Read(ref _slotRefusalSeq);
if (seq == _currentLootItemSlotSeqAtSend) return false;
_currentLootItemSlotSeqAtSend = seq; // taken: a later line is a new refusal
// By the line's own arrival time, not this tick's.
long lineAt = Volatile.Read(ref _slotRefusalAt);
long after = lineAt - _currentLootItemMoveRequestedAt;
if (after < 0 || after > _currentLootItemSlotWindowMs) return false; // not ours
long otherAt = UseAudit.LastItemActionAt;
if (otherAt != 0 && otherAt >= _currentLootItemMoveRequestedAt - _currentLootItemSlotWindowMs && otherAt <= lineAt)
return false; // another item action of ours went out around it: the line may be that one's refusal
_currentLootItemSlotRefusedAt = now;
if (_currentLootItemFirstSlotRefusalAt == 0) _currentLootItemFirstSlotRefusalAt = now;
_slotRefusalCollisions++;
LootDiag($"[RynthAi] {LootTag}: the client's one request slot refused the move of 0x{(uint)_currentLootItemId:X8}: the line arrived {after} ms after the send (window {_currentLootItemSlotWindowMs} ms) " +
$"(refusal #{_slotRefusalCollisions} this session); sending it again in {SlotRefusalRetryMs} ms, not counted as a try.");
}
if (now - _currentLootItemMoveRequestedAt < SlotRefusalRetryMs)
{
PauseCorpseClockWhileMoveAwaits(now);
return true;
}
if (PickupHeldByServerAction())
return true; // the server owes an answer to a cast or use: it would refuse this as too busy
RynthCore.Plugin.RynthAi.ItemInfo.SelfSelect.Mark(unchecked((uint)_currentLootItemId));
Host.SelectItem(unchecked((uint)_currentLootItemId));
int errSeqAtSend = LastWeenieErrorSeq();
LootPickupResult r = SendLootPickup(_currentLootItemId, _currentLootItemName, _openedContainerId, slotResend: true);
if (r == LootPickupResult.NoRoom || r == LootPickupResult.Refused)
return true; // SendLootPickup finished the item / corpse
_currentLootItemSlotResends++;
if (r != LootPickupResult.Moved && r != LootPickupResult.Used)
_currentLootItemSlotGaveUp = true; // the engine turned the call down: nothing more to repeat
_currentLootItemErrSeqAtSend = errSeqAtSend;
_currentLootItemMoveRequestedAt = now;
_currentLootItemJumped = false; // a resend goes without a jump (the floor applies)
_currentLootItemSentInAirWindow = false;
_currentLootItemFightHeld = false; // a fresh send: a fight before it is not this send's
NoteLootMoveSent();
_currentLootItemStillSince = 0;
_currentLootItemSawAnim = false;
_lastLootActionAt = now;
LootDiag($"[RynthAi] {LootTag}: sent 0x{(uint)_currentLootItemId:X8} again after the slot's refusal (resend {_currentLootItemSlotResends}, no jump).");
return true;
}
/// <summary>
/// The refusal of the current send was ACE's "too busy", not another one (a full pack, a quest
/// item) that only came fast. ACE sends YoureTooBusy (0x1D) and then InventoryServerSaveFailed
@ -2637,6 +2764,13 @@ public sealed partial class RynthAiPlugin
// counting it as one of the item's 3 tries. Refused after the pickup ran (no room): one
// of the tries, and the evidence a pack is full (PollCurrentPickupRefusal).
PollCurrentPickupRefusal(now);
// The client's own one-request slot turned the send away (nothing reached the server):
// sent again within SlotRefusalRetryMs, not one of the 3 tries, not the PickupAnswerWaitMs wait.
// Not while a fight has the tick (no resend then: below); the line is attributed by its own
// arrival time, so it is still taken after the fight. Only with Jump When Looting on: the net
// was measured on ACE's jump-loot cadence, and off it every send keeps its old wait.
if (!heldByFight && settings.LootJumpEnabled && PollSlotRefusal(now))
return;
bool refused = _currentLootItemRefusedAt != 0;
bool busyRefusal = refused && _currentLootItemRefusalBusy;
@ -2853,9 +2987,17 @@ public sealed partial class RynthAiPlugin
/// never a use). NoRoom finishes the corpse like the free-slot check does; Refused
/// leaves the item. Both reset the current item, so the caller just returns.
/// </summary>
private LootPickupResult SendLootPickup(int itemId, string itemName, int corpseId)
private LootPickupResult SendLootPickup(int itemId, string itemName, int corpseId, bool slotResend = false)
{
NoteMergeTargets(itemId, itemName);
// The refusal baseline lives here, in the one path every send goes through (the looter, the
// retry, the slot resend, the own-corpse recovery), so no send site can forget it: the
// session-wide refusal count is read before the move goes out, and only a refusal line
// heard after it can be this send's (PollSlotRefusal).
_currentLootItemSlotSeqAtSend = Volatile.Read(ref _slotRefusalSeq);
_currentLootItemSlotWindowMs = PickupAnimating(CorpseNowMs) ? SlotRefusalDeferredWindowMs : SlotRefusalAttributionMs;
// A slot resend sends the same item again: its stack baseline is the first send's, and a
// stack that has grown since is exactly what the confirm looks for.
if (!slotResend) NoteMergeTargets(itemId, itemName);
bool ownCorpse = corpseId != 0 && corpseId == _ownRecoveryCorpseId;
uint dest;
LootPickupResult r = ownCorpse
@ -3981,6 +4123,12 @@ public sealed partial class RynthAiPlugin
_currentLootItemJumped = false;
_currentLootItemSentInAirWindow = false;
_currentLootItemErrSeqAtSend = 0;
_currentLootItemSlotSeqAtSend = 0;
_currentLootItemSlotRefusedAt = 0;
_currentLootItemSlotResends = 0;
_currentLootItemSlotWindowMs = SlotRefusalAttributionMs;
_currentLootItemFirstSlotRefusalAt = 0;
_currentLootItemSlotGaveUp = false;
_currentLootItemFreeRetries = 0;
_currentLootItemFightHeld = false;
_currentLootItemFightResends = 0;