From 04ecdd64f4ebfbc967df1fa33730d1a4464b5fa0 Mon Sep 17 00:00:00 2001 From: Daniel Wallace Date: Sat, 7 Nov 2026 08:55:22 -0800 Subject: [PATCH] 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 --- .../Combat/BuffManager.cs | 2 + .../Combat/CombatManager.Offhand.cs | 1 + .../Combat/CombatManager.cs | 2 + .../CorpseOpenController.cs | 152 +++++++++- .../GroundLootController.cs | 2 + .../Huds/HudController.cs | 1 + .../Loot/InventoryManager.cs | 1 + .../Loot/SalvageManager.cs | 7 + .../MagToolsCommands.Extra.cs | 1 + .../MagToolsCommands.cs | 3 + .../Meta/ExpressionEngine.UbCompat.cs | 1 + .../Meta/ExpressionEngine.cs | 4 + .../MiniRemote/MiniRemoteInventory.cs | 7 +- .../RynthAiCommands.cs | 1 + .../RynthAiPlugin.ItemTool.cs | 5 +- .../RynthCore.Plugin.RynthAi/RynthAiPlugin.cs | 1 + .../Trade/AutoTradeCommands.cs | 1 + .../Trade/AutoTradeManager.cs | 1 + .../Vendor/AutoVendorManager.cs | 1 + Plugins/Shared/UseAudit.cs | 38 +++ .../Tests/LootJumpTests.cs | 272 +++++++++++++++++- .../Tests/OwnCorpseTests.cs | 27 ++ 22 files changed, 526 insertions(+), 5 deletions(-) diff --git a/Plugins/RynthCore.Plugin.RynthAi/Combat/BuffManager.cs b/Plugins/RynthCore.Plugin.RynthAi/Combat/BuffManager.cs index 385140f..cf22201 100644 --- a/Plugins/RynthCore.Plugin.RynthAi/Combat/BuffManager.cs +++ b/Plugins/RynthCore.Plugin.RynthAi/Combat/BuffManager.cs @@ -5665,6 +5665,7 @@ public partial class BuffManager : IDisposable // GetAndWieldItem into the Held slot (the paperdoll drag). A use only wields a plain // caster: one with a spell of its own (Electric Baton, Acid Staff) takes the use as // "cast it" (Drakkon, 2026-10-18 14:00). + RynthCore.Plugin.Shared.UseAudit.NoteItemAction(); // a non-loot item action (UseAudit.LastItemActionAt) if (_host.HasWieldItem) _host.WieldItem((uint)step.Id, (uint)step.Slot); else _host.UseFor((uint)step.Id, "Buff", "buffing: wield the wand"); _wandSwap.Sent(step, now); @@ -5780,6 +5781,7 @@ public partial class BuffManager : IDisposable if (hands.TryGetValue(id, out int slot) && (slot & HandSwapSequence.ShieldSlot) != 0) OffhandPutAway(id); _host.PutItemInContainer(unchecked((uint)id), unchecked((uint)pack), 0); } + RynthCore.Plugin.Shared.UseAudit.NoteItemAction(); // a non-loot item action (UseAudit.LastItemActionAt) _host.WieldItem(unchecked((uint)wandId), HeldSlot); _wandSwap.SentBurst(moves, now); _wandSwapLastMoved = wandId; diff --git a/Plugins/RynthCore.Plugin.RynthAi/Combat/CombatManager.Offhand.cs b/Plugins/RynthCore.Plugin.RynthAi/Combat/CombatManager.Offhand.cs index d08d882..447fe2b 100644 --- a/Plugins/RynthCore.Plugin.RynthAi/Combat/CombatManager.Offhand.cs +++ b/Plugins/RynthCore.Plugin.RynthAi/Combat/CombatManager.Offhand.cs @@ -431,6 +431,7 @@ public partial class CombatManager // Another swap just went out (the main weapon, say): fight on and try again after the gate. if (_weaponSwapGate != null && !_weaponSwapGate.TryBeginSwap("combat-offhand")) return false; + RynthCore.Plugin.Shared.UseAudit.NoteItemAction(); // a non-loot item action (UseAudit.LastItemActionAt) bool sent = _host.HasWieldItem ? _host.WieldItem(unchecked((uint)plan.Id), OffhandRules.ShieldSlot) : _host.UseFor(unchecked((uint)plan.Id), "Combat", "offhand: wield the shield or offhand weapon"); diff --git a/Plugins/RynthCore.Plugin.RynthAi/Combat/CombatManager.cs b/Plugins/RynthCore.Plugin.RynthAi/Combat/CombatManager.cs index 2c4269c..22d8716 100644 --- a/Plugins/RynthCore.Plugin.RynthAi/Combat/CombatManager.cs +++ b/Plugins/RynthCore.Plugin.RynthAi/Combat/CombatManager.cs @@ -5585,6 +5585,7 @@ public partial class CombatManager : IDisposable case HandSwapSequence.Act.Wield: { bool off = step.Slot == HandSwapSequence.ShieldSlot; + RynthCore.Plugin.Shared.UseAudit.NoteItemAction(); // a non-loot item action (UseAudit.LastItemActionAt) if (_host.HasWieldItem) _host.WieldItem((uint)step.Id, (uint)step.Slot); else _host.UseFor((uint)step.Id, "Combat", $"wield: {HandsSwapLabel}"); _rearmSwap.Sent(step, now); @@ -5679,6 +5680,7 @@ public partial class CombatManager : IDisposable var wants = _rearmWants; foreach (var (id, slot) in wants) { + RynthCore.Plugin.Shared.UseAudit.NoteItemAction(); // a non-loot item action (UseAudit.LastItemActionAt) _host.WieldItem(unchecked((uint)id), unchecked((uint)slot)); NoteRearmWield(id, slot == HandSwapSequence.ShieldSlot, now); } diff --git a/Plugins/RynthCore.Plugin.RynthAi/CorpseOpenController.cs b/Plugins/RynthCore.Plugin.RynthAi/CorpseOpenController.cs index 5a0b4ae..a346cc4 100644 --- a/Plugins/RynthCore.Plugin.RynthAi/CorpseOpenController.cs +++ b/Plugins/RynthCore.Plugin.RynthAi/CorpseOpenController.cs @@ -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; /// How long the no-bend-down call stays off after the server proved it wrong. 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 _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"); } + /// + /// 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 + /// . Anchored at the line start: a player's chat quoting it is not it. + /// + 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); + } + + /// + /// 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). + /// + 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; + } + /// /// 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. /// - 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; diff --git a/Plugins/RynthCore.Plugin.RynthAi/GroundLootController.cs b/Plugins/RynthCore.Plugin.RynthAi/GroundLootController.cs index 250126f..5c79f61 100644 --- a/Plugins/RynthCore.Plugin.RynthAi/GroundLootController.cs +++ b/Plugins/RynthCore.Plugin.RynthAi/GroundLootController.cs @@ -14,6 +14,7 @@ using System; using System.Collections.Generic; using RynthCore.Plugin.RynthAi.LegacyUi; +using RynthCore.Plugin.Shared; namespace RynthCore.Plugin.RynthAi; @@ -279,6 +280,7 @@ public sealed partial class RynthAiPlugin uint uid = unchecked((uint)_groundTargetId); Host.SelectItem(uid); _groundErrSeqAtSend = LastWeenieErrorSeq(); + UseAudit.NoteItemAction(); bool sent = Host.HasMoveItemExternal ? Host.MoveItemExternal(uid, _playerId, 0) : Host.UseObject(uid); diff --git a/Plugins/RynthCore.Plugin.RynthAi/Huds/HudController.cs b/Plugins/RynthCore.Plugin.RynthAi/Huds/HudController.cs index 6044ed2..af09f85 100644 --- a/Plugins/RynthCore.Plugin.RynthAi/Huds/HudController.cs +++ b/Plugins/RynthCore.Plugin.RynthAi/Huds/HudController.cs @@ -282,6 +282,7 @@ internal sealed class HudController var wo = inv.FirstOrDefault(w => w.Name.Equals(entry.Name, StringComparison.OrdinalIgnoreCase)) ?? (entry.Wcid != 0 ? inv.FirstOrDefault(w => Wcid(w) == entry.Wcid) : null); if (wo == null) { Chat($"[RynthAi] No {entry.Name} in your pack."); return; } + RynthCore.Plugin.Shared.UseAudit.NoteItemAction(); // a non-loot item action (UseAudit.LastItemActionAt) _host.UseObject(unchecked((uint)wo.Id)); RynthLog.Trace(LogCat.Huds, $"use {wo.Name} (0x{wo.Id:X8})"); } diff --git a/Plugins/RynthCore.Plugin.RynthAi/Loot/InventoryManager.cs b/Plugins/RynthCore.Plugin.RynthAi/Loot/InventoryManager.cs index b080161..dc69b5a 100644 --- a/Plugins/RynthCore.Plugin.RynthAi/Loot/InventoryManager.cs +++ b/Plugins/RynthCore.Plugin.RynthAi/Loot/InventoryManager.cs @@ -344,6 +344,7 @@ public sealed class InventoryManager var source = chosenSource.Value; _host.Log($"[RynthAi] AutoStack: merge {source.Item.Name} src=0x{source.Item.Id:X8}({source.Count}) -> tgt=0x{target.Item.Id:X8}({target.Count}) max={max}"); + RynthCore.Plugin.Shared.UseAudit.NoteItemAction(); // a non-loot item action (UseAudit.LastItemActionAt) bool ok = _host.MergeStackInternal( unchecked((uint)source.Item.Id), unchecked((uint)target.Item.Id)); diff --git a/Plugins/RynthCore.Plugin.RynthAi/Loot/SalvageManager.cs b/Plugins/RynthCore.Plugin.RynthAi/Loot/SalvageManager.cs index e79dbd1..3a89465 100644 --- a/Plugins/RynthCore.Plugin.RynthAi/Loot/SalvageManager.cs +++ b/Plugins/RynthCore.Plugin.RynthAi/Loot/SalvageManager.cs @@ -499,6 +499,7 @@ public sealed class SalvageManager var ids = new uint[_batch.Count + _batchBags.Count]; _batch.CopyTo(ids, 0); _batchBags.CopyTo(ids, _batch.Count); + UseAudit.NoteItemAction(); int sent = _host.SalvageDirect(_currentUstId, ids); if (sent <= 0) { @@ -716,6 +717,7 @@ public sealed class SalvageManager if (_batchAddIdx < _batch.Count) { uint id = _batch[_batchAddIdx]; + UseAudit.NoteItemAction(); if (_host.SalvagePanelAddItem(id)) { _batchAdded.Add(id); @@ -787,8 +789,11 @@ public sealed class SalvageManager { int added = 0; foreach (uint bagId in FindMatchingUnderFullBags(itemIds, int.MaxValue)) + { + UseAudit.NoteItemAction(); if (_host.SalvagePanelAddItem(bagId)) added++; + } return added; } @@ -1212,6 +1217,7 @@ public sealed class SalvageManager { uint[] bagIds = group.Take(RynthCoreHost.MaxSalvageDirectItems).ToArray(); _salvageChat.Clear(); + UseAudit.NoteItemAction(); int sent = _host.SalvageDirect(ust, bagIds); if (sent > 0) { @@ -1281,6 +1287,7 @@ public sealed class SalvageManager if (_combineAddIdx < group.Count) { uint bagId = group[_combineAddIdx]; + UseAudit.NoteItemAction(); if (_host.SalvagePanelAddItem(bagId)) Log($"[Salvage] Combine: added bag 0x{bagId:X8} to panel ({_combineAddIdx + 1}/{group.Count})."); else diff --git a/Plugins/RynthCore.Plugin.RynthAi/MagToolsCommands.Extra.cs b/Plugins/RynthCore.Plugin.RynthAi/MagToolsCommands.Extra.cs index 8284526..a59a3c6 100644 --- a/Plugins/RynthCore.Plugin.RynthAi/MagToolsCommands.Extra.cs +++ b/Plugins/RynthCore.Plugin.RynthAi/MagToolsCommands.Extra.cs @@ -202,6 +202,7 @@ public sealed partial class RynthAiPlugin string name = string.Join(" ", parts, 3, parts.Length - 3); var item = FindObject(name, inv: true, land: false, partial: sub == "addp"); if (item == null) { ReplyFail($"[RynthAi] Item not found: '{name}'"); return true; } + RynthCore.Plugin.Shared.UseAudit.NoteItemAction(); // a non-loot item action (UseAudit.LastItemActionAt) if (Host.TradeAdd(unchecked((uint)item.Id))) ReplyOk($"[RynthAi] Added {item.Name} to the trade."); else ReplyFail("[RynthAi] Could not add it to the trade."); return true; diff --git a/Plugins/RynthCore.Plugin.RynthAi/MagToolsCommands.cs b/Plugins/RynthCore.Plugin.RynthAi/MagToolsCommands.cs index d82bc87..cbe4294 100644 --- a/Plugins/RynthCore.Plugin.RynthAi/MagToolsCommands.cs +++ b/Plugins/RynthCore.Plugin.RynthAi/MagToolsCommands.cs @@ -597,6 +597,7 @@ public sealed partial class RynthAiPlugin // pretend it worked. if (Host.HasGiveObjectTo) { + RynthCore.Plugin.Shared.UseAudit.NoteItemAction(); // a non-loot item action (UseAudit.LastItemActionAt) bool ok = Host.GiveObjectTo(unchecked((uint)item.Id), unchecked((uint)target.Id), 0); Host.Log($"[RynthAi] /mt give: {item.Name} → {target.Name} (give ok={ok})"); if (ok) ReplyOk($"[RynthAi] Giving {item.Name} to {target.Name}."); @@ -783,6 +784,7 @@ public sealed partial class RynthAiPlugin if (item == null) { ReplyFail($"[RynthAi] Item not found in inventory: '{name}'"); return true; } // Drop = move to the ground (container 0) + RynthCore.Plugin.Shared.UseAudit.NoteItemAction(); // a non-loot item action (UseAudit.LastItemActionAt) Host.MoveItemExternal(unchecked((uint)item.Id), 0, 0); Host.Log($"[RynthAi] /mt drop: {item.Name} (0x{(uint)item.Id:X8})"); ReplyOk($"[RynthAi] Dropping {item.Name}."); @@ -841,6 +843,7 @@ public sealed partial class RynthAiPlugin ReplyFail($"[RynthAi] /mt dequip: no open pack for '{found.Name}' — inventory full."); return true; } + RynthCore.Plugin.Shared.UseAudit.NoteItemAction(); // a non-loot item action (UseAudit.LastItemActionAt) Host.MoveItemInternal(unchecked((uint)found.Id), unchecked((uint)dest), 0, 1); Host.Log($"[RynthAi] /mt dequip: {found.Name} (0x{(uint)found.Id:X8}) → pack 0x{(uint)dest:X8}"); ReplyOk($"[RynthAi] Taking off {found.Name} (into a pack)."); diff --git a/Plugins/RynthCore.Plugin.RynthAi/Meta/ExpressionEngine.UbCompat.cs b/Plugins/RynthCore.Plugin.RynthAi/Meta/ExpressionEngine.UbCompat.cs index 4793421..f541fa4 100644 --- a/Plugins/RynthCore.Plugin.RynthAi/Meta/ExpressionEngine.UbCompat.cs +++ b/Plugins/RynthCore.Plugin.RynthAi/Meta/ExpressionEngine.UbCompat.cs @@ -146,6 +146,7 @@ internal sealed partial class ExpressionEngine { if (unchecked((uint)wo.Id) == id || !string.Equals(wo.Name, name, StringComparison.Ordinal)) continue; if (StackSizeOf(unchecked((uint)wo.Id)) <= 1 && StackSizeOf(id) <= 1) continue; + RynthCore.Plugin.Shared.UseAudit.NoteItemAction(); // a non-loot item action (UseAudit.LastItemActionAt) return _host.MergeStackInternal(id, unchecked((uint)wo.Id)) ? "1" : "0"; } } diff --git a/Plugins/RynthCore.Plugin.RynthAi/Meta/ExpressionEngine.cs b/Plugins/RynthCore.Plugin.RynthAi/Meta/ExpressionEngine.cs index a78718f..80ead70 100644 --- a/Plugins/RynthCore.Plugin.RynthAi/Meta/ExpressionEngine.cs +++ b/Plugins/RynthCore.Plugin.RynthAi/Meta/ExpressionEngine.cs @@ -3025,6 +3025,7 @@ internal sealed partial class ExpressionEngine if (!_host.HasMoveItemExternal) return "0"; var wo = _worldObjectCache?[unchecked((int)giveId)]; int amount = wo != null ? Math.Max(1, wo.Values(LongValueKey.StackCount, 1)) : 1; + RynthCore.Plugin.Shared.UseAudit.NoteItemAction(); // a non-loot item action (UseAudit.LastItemActionAt) return _host.MoveItemExternal(giveId, destId, amount) ? "1" : "0"; } @@ -3087,6 +3088,7 @@ internal sealed partial class ExpressionEngine { var (action, _) = RynthCore.Plugin.RynthAi.Loot.LootEvaluator.Classify(nativeProfile, wo, null); if (action != RynthCore.Loot.LootAction.Keep) continue; + RynthCore.Plugin.Shared.UseAudit.NoteItemAction(); // a non-loot item action (UseAudit.LastItemActionAt) _host.GiveObjectTo((uint)wo.Id, targetId, 0); return "1"; } @@ -3114,6 +3116,7 @@ internal sealed partial class ExpressionEngine if (VTankLootEvaluator.Match(rule, wo, lootCtx)) { match = rule; break; } if (match == null || match.Action != VTankLootAction.Keep) continue; + RynthCore.Plugin.Shared.UseAudit.NoteItemAction(); // a non-loot item action (UseAudit.LastItemActionAt) _host.GiveObjectTo((uint)wo.Id, targetId, 0); return "1"; } @@ -3364,6 +3367,7 @@ internal sealed partial class ExpressionEngine { if (!uint.TryParse(objArg.Trim(), out uid) || uid == 0) return "0"; } + RynthCore.Plugin.Shared.UseAudit.NoteItemAction(); // a non-loot item action (UseAudit.LastItemActionAt) _host.SalvagePanelAddItem(uid); return "1"; } diff --git a/Plugins/RynthCore.Plugin.RynthAi/MiniRemote/MiniRemoteInventory.cs b/Plugins/RynthCore.Plugin.RynthAi/MiniRemote/MiniRemoteInventory.cs index fa49e7c..1af3e49 100644 --- a/Plugins/RynthCore.Plugin.RynthAi/MiniRemote/MiniRemoteInventory.cs +++ b/Plugins/RynthCore.Plugin.RynthAi/MiniRemote/MiniRemoteInventory.cs @@ -119,7 +119,12 @@ internal sealed class MiniRemoteInventory // ── Actions ───────────────────────────────────────────────────────────── - public bool Use(WorldObject wo) => _host.HasUseObject && _host.UseObject(unchecked((uint)wo.Id)); + 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)); + } /// Forgets cached WCIDs / appraisal throttles (logout). public void Reset() diff --git a/Plugins/RynthCore.Plugin.RynthAi/RynthAiCommands.cs b/Plugins/RynthCore.Plugin.RynthAi/RynthAiCommands.cs index 03fb851..39b79aa 100644 --- a/Plugins/RynthCore.Plugin.RynthAi/RynthAiCommands.cs +++ b/Plugins/RynthCore.Plugin.RynthAi/RynthAiCommands.cs @@ -2819,6 +2819,7 @@ public sealed partial class RynthAiPlugin /// internal bool GiveItem(uint itemId, uint targetId, int amount, int stackSize) { + UseAudit.NoteItemAction(); if (Host.HasGiveObjectTo) return Host.GiveObjectTo(itemId, targetId, amount <= 0 || amount >= stackSize ? 0 : amount); return Host.MoveItemExternal(itemId, targetId, Math.Max(1, amount)); diff --git a/Plugins/RynthCore.Plugin.RynthAi/RynthAiPlugin.ItemTool.cs b/Plugins/RynthCore.Plugin.RynthAi/RynthAiPlugin.ItemTool.cs index 31b63ee..2f9eb4e 100644 --- a/Plugins/RynthCore.Plugin.RynthAi/RynthAiPlugin.ItemTool.cs +++ b/Plugins/RynthCore.Plugin.RynthAi/RynthAiPlugin.ItemTool.cs @@ -581,7 +581,10 @@ public sealed partial class RynthAiPlugin } public bool Send(int itemId, int targetId) - => Host.GiveObjectTo(unchecked((uint)itemId), unchecked((uint)targetId), 0); // amount 0 = the whole object + { + RynthCore.Plugin.Shared.UseAudit.NoteItemAction(); // a non-loot item action (UseAudit.LastItemActionAt) + return Host.GiveObjectTo(unchecked((uint)itemId), unchecked((uint)targetId), 0); // amount 0 = the whole object + } public int RefusalSeq() => Host.HasGetLastWeenieError && Host.TryGetLastWeenieError(out int seq, out _, out _, out _) ? seq : 0; diff --git a/Plugins/RynthCore.Plugin.RynthAi/RynthAiPlugin.cs b/Plugins/RynthCore.Plugin.RynthAi/RynthAiPlugin.cs index f7e5af7..8ee5866 100644 --- a/Plugins/RynthCore.Plugin.RynthAi/RynthAiPlugin.cs +++ b/Plugins/RynthCore.Plugin.RynthAi/RynthAiPlugin.cs @@ -2457,6 +2457,7 @@ public sealed partial class RynthAiPlugin : RynthPluginBase try { NoteServerPolicyChat(text); } catch { } // DreamWeave's Thread lines (ServerPolicy) try { NoteDoorServerText(text); } catch { } // "The door is locked!" (the door logic) try { ItemToolChat(text); } catch { } // the key's answers (chest looter) + try { NoteSlotRefusalChat(text); } catch { } // the client's own "one item at a time" refusal (loot resend) try { _sessionStats?.OnChatWindowText(text); } catch (Exception ex) { RynthLog.Exception(LogCat.Huds, ex, "session stats chat"); } try { NoteMonsterStatsChat(text, chatType); } catch (Exception ex) { RynthLog.Exception(LogCat.Huds, ex, "monster stats chat"); } // The Meta Manager eats the reply to its own /myquests poll (only that). diff --git a/Plugins/RynthCore.Plugin.RynthAi/Trade/AutoTradeCommands.cs b/Plugins/RynthCore.Plugin.RynthAi/Trade/AutoTradeCommands.cs index 0566129..948c07a 100644 --- a/Plugins/RynthCore.Plugin.RynthAi/Trade/AutoTradeCommands.cs +++ b/Plugins/RynthCore.Plugin.RynthAi/Trade/AutoTradeCommands.cs @@ -73,6 +73,7 @@ public sealed partial class RynthAiPlugin { uint item = ParseTradeId(arg); if (item == 0) { ReplyFail("[RynthAi] Usage: /ra trade add "); break; } + RynthCore.Plugin.Shared.UseAudit.NoteItemAction(); // a non-loot item action (UseAudit.LastItemActionAt) ReplyIf(Host.TradeAdd(item), $"[RynthAi] Adding {TradeName(item)} to the trade window.", "[RynthAi] Could not send the add."); diff --git a/Plugins/RynthCore.Plugin.RynthAi/Trade/AutoTradeManager.cs b/Plugins/RynthCore.Plugin.RynthAi/Trade/AutoTradeManager.cs index 8ab5312..1dde440 100644 --- a/Plugins/RynthCore.Plugin.RynthAi/Trade/AutoTradeManager.cs +++ b/Plugins/RynthCore.Plugin.RynthAi/Trade/AutoTradeManager.cs @@ -736,6 +736,7 @@ internal sealed class AutoTradeManager { _handled.Add(itemId); _host.Log($"[RynthAi] AutoTrade: Adding to trade window: {name}"); + RynthCore.Plugin.Shared.UseAudit.NoteItemAction(); // a non-loot item action (UseAudit.LastItemActionAt) if (!_host.TradeAdd(itemId)) { Error($"could not send {name} to the trade window"); diff --git a/Plugins/RynthCore.Plugin.RynthAi/Vendor/AutoVendorManager.cs b/Plugins/RynthCore.Plugin.RynthAi/Vendor/AutoVendorManager.cs index b9dd984..c6eef4a 100644 --- a/Plugins/RynthCore.Plugin.RynthAi/Vendor/AutoVendorManager.cs +++ b/Plugins/RynthCore.Plugin.RynthAi/Vendor/AutoVendorManager.cs @@ -1040,6 +1040,7 @@ internal sealed class AutoVendorManager _mergeTargetCount = target.StackSize; _splitName = source.Name; _host.Log($"[RynthAi] AutoVendor merge {source.Name}:{source.Id:X8} ({source.StackSize}) onto {target.Id:X8} ({target.StackSize}) - {why}"); + RynthCore.Plugin.Shared.UseAudit.NoteItemAction(); // a non-loot item action (UseAudit.LastItemActionAt) if (!_host.MergeStackInternal(source.Id, target.Id)) { TidyFailed($"could not merge {source.Name}"); diff --git a/Plugins/Shared/UseAudit.cs b/Plugins/Shared/UseAudit.cs index fbb1206..dc50f72 100644 --- a/Plugins/Shared/UseAudit.cs +++ b/Plugins/Shared/UseAudit.cs @@ -26,6 +26,7 @@ using System; using System.Collections.Generic; +using System.Threading; using RynthCore.PluginSdk; namespace RynthCore.Plugin.Shared; @@ -46,6 +47,38 @@ internal static class UseAudit private const uint BfDoor = 0x1000; private const uint BfCorpse = 0x2000; + private static long _lastItemActionAt; + + /// + /// When (on ) this plugin last issued an item action other than a loot pickup. + /// The client refuses any of them with the same "one item at a time" line while its request slot + /// is held, so a refusal line heard near one of these cannot be told from a loot send's + /// (CorpseOpenController.PollSlotRefusal). 0 = none yet. + /// Stamped: every UseFor and UseOnFor except the looter's own ("Loot"); the wand, weapon and + /// offhand wields (BuffManager, CombatManager, CombatManager.Offhand); the ground pickup; the give + /// helper (GiveItem) and the item tool's give; the salvage sends and panel adds (SalvageManager); + /// the meta give actions and salvage-panel add (ExpressionEngine); the MagTools give, drop and + /// dequip; the HUD and MiniRemote item uses; the stack merges (MergeStackInternal in + /// InventoryManager, ExpressionEngine.UbCompat and AutoVendorManager); the trade adds (TradeAdd in + /// MagToolsCommands.Extra, AutoTradeCommands and AutoTradeManager). + /// Not stamped: vendor buy and sell (AutoVendorManager, MagToolsCommands.Extra); the salvage panel + /// execute (SalvageManager, ExpressionEngine); the pack-to-pack moves and stack splits + /// (MoveItemInternal, PutItemInContainer, SplitStackInternal) in BuffManager, + /// BuffManager.LegacySwap, CombatManager, CombatManager.Ammo, CombatManager.Offhand, + /// ExpressionEngine, ExpressionEngine.UbCompat, InventoryManager, AutoVendorManager and + /// AutoTradeManager; the legacy swap wields (BuffManager.LegacySwap, CombatManager.LegacySwap); + /// and the dashboard's panel drag (PanelDragWithLastItem, InstrumentDashboard). + /// Item actions of other plugins are not seen at all: each plugin compiles its own copy of this + /// file, so their stamps (where they have any) land on their own copy's clock, not this one's. + /// + public static long LastItemActionAt => Interlocked.Read(ref _lastItemActionAt); + + /// Records that an item action just went out (see ). + public static void NoteItemAction() => Interlocked.Exchange(ref _lastItemActionAt, NowMs()); + + /// Forgets the last item action (a new session, and tests that move the clock). + public static void ForgetItemAction() => Interlocked.Exchange(ref _lastItemActionAt, 0); + /// The plugin's name in every line. Set once at Init. public static string PluginName = "?"; @@ -76,6 +109,7 @@ internal static class UseAudit { PluginName = pluginName; MacroOn = macroOn; + ForgetItemAction(); Seen.Clear(); _windowStart = long.MinValue; _windowLines = 0; @@ -116,6 +150,9 @@ internal static class UseAudit try { seqBefore = host.HasUseDoneSeq ? host.GetUseDoneSeq() : 0; } catch { } } bool sent = host.UseObject(objectId); + // The one choke point for uses (buff and combat wields, salvage, doors, metas, commands). + // The looter's own corpse opens are not "another" item action for its pickups. + if (subsystem != "Loot") NoteItemAction(); if (track && sent) MarkWorldUse(objectId, seqBefore); if (sent && after != null) @@ -224,6 +261,7 @@ internal static class UseAudit try { seqBefore = host.HasUseDoneSeq ? host.GetUseDoneSeq() : 0; } catch { } } bool sent = host.UseObjectOn(sourceId, targetId); + if (subsystem != "Loot") NoteItemAction(); // kits, mana stones, lockpicks, crafting, pets, metas if (sent && after != null) { try { after(host, new SentUse(sourceId, targetId, subsystem, $"{src} on {tgt}", doorOrCorpse, seqBefore, kind)); } catch { } diff --git a/Tools/RynthCore.RynthAiHostTests/Tests/LootJumpTests.cs b/Tools/RynthCore.RynthAiHostTests/Tests/LootJumpTests.cs index 70acc6b..c56055a 100644 --- a/Tools/RynthCore.RynthAiHostTests/Tests/LootJumpTests.cs +++ b/Tools/RynthCore.RynthAiHostTests/Tests/LootJumpTests.cs @@ -49,6 +49,19 @@ internal static class LootJumpTests r.Add("jump loot: a jump send's answer at 150 ms is confirmed then, and the next corpse opened then, not at 500 ms", JumpAnswerConfirmedOnArrival); r.Add("jump loot: a jump send merged into a pack stack keeps the floor (the client's request slot stays held for a merged-away object)", JumpMergeKeepsAnswerFloor); r.Add("jump loot: the no-bend-down window after an in-air send that rode an earlier jump is anchored to that jump", AirWindowAnchoredToTheInAirJump); + r.Add("jump loot: a send the client's held request slot refused (chat line) is sent again within 250 ms, is not one of the 3 tries, and does not wait the answer window", SlotRefusedResentQuickly); + r.Add("jump loot: a slot refusal heard long after the send, or a player's words, is not ours (no resend)", LateSlotRefusalIgnored); + r.Add("jump loot: a refusal line 100 ms after the send, then the server answer at 200 ms, is a single move", ForeignRefusalThenAnswerSingleMove); + r.Add("jump loot: slot resends go on past 7.5 s (9 s of refusals, still resending, no try used)", SlotResendsStillGoingAt9s); + r.Add("jump loot: after 11.5 s of slot refusals the ordinary answer wait takes over", SlotResendCapHandsOver); + r.Add("jump loot: a send made while the motion queue is busy has its refusal at 700 ms taken for its own and resent", DeferredSendRefusalAt700IsResent); + r.Add("jump loot: another item action just before the refusal line keeps it from being taken for ours (one move)", ForeignItemActionSuppressesAttribution); + r.Add("jump loot: ResetCurrentLootItem clears the slot-refusal fields", ResetClearsSlotFields); + r.Add("jump loot: with Jump When Looting off a slot refusal line changes nothing (no quick resend)", SlotNetNeedsJumpLoot); + r.Add("jump loot: a slot refusal heard while a fight has the tick is resent only after the fight, at once, with no try used", SlotRefusalWaitsOutAFight); + r.Add("jump loot: a UseOnFor between the loot send and the refusal line keeps the line from being taken for ours (no resend)", UseOnForSuppressesAttribution); + r.Add("jump loot: the looter's own UseOnFor (Loot) is not stamped, so a refusal line after it is still ours (resent)", LootUseOnForIsNotStamped); + r.Add("jump loot: another item action 1 s before a busy-queue send (2500 ms window) keeps its refusal line from being taken for ours", ForeignActionLookbackUsesSendWindow); r.Add("jump loot: a fast refusal that is not 'too busy' (a code-0 save-failed) does not turn the no-bend-down call off", NonBusyRefusalKeepsNoMotion); r.Add("jump loot: a send with no jump still waits PickupAnswerMinMs before its answer is believed", NoJumpKeepsAnswerFloor); r.Add("jump loot: a jump send's weak sign (an unowned stack, no pack stack grown) still waits PickupAnswerMinMs", JumpWeakSignKeepsAnswerFloor); @@ -69,12 +82,15 @@ internal static class LootJumpTests { var old = RynthAiPlugin.CorpseClock; var oldPace = ActionPacer.NowMs; + var oldUse = UseAudit.NowMs; _now = 50_000_000; + UseAudit.ForgetItemAction(); + UseAudit.NowMs = () => _now; // the item-action stamp (UseAudit.LastItemActionAt) on the same clock RynthAiPlugin.CorpseClock = () => _now; ActionPacer.NowMs = () => _now; // the loot jump's air hold (ActionPacer.LootJumpAirborne) on the same clock ActionPacer.ForgetLootJump(); try { body(); } - finally { RynthAiPlugin.CorpseClock = old; ActionPacer.NowMs = oldPace; ActionPacer.ForgetLootJump(); } + finally { RynthAiPlugin.CorpseClock = old; ActionPacer.NowMs = oldPace; UseAudit.NowMs = oldUse; ActionPacer.ForgetLootJump(); } } private static RynthAiPlugin _bot = null!; // the bot LootUntilFirstMove made @@ -400,6 +416,260 @@ internal static class LootJumpTests $"the window ends JumpLandMaxMs after the jump: {until - jumpAt} ms from it (the second send was {secondAt - jumpAt} ms in)"); }); + private const string SlotChat = "You can only move or use one item at a time"; + + // The client's one request slot is held: it prints its refusal locally and sends nothing, so the + // server never answers. The send is repeated 250 ms after, without using one of the 3 tries and + // without waiting PickupAnswerWaitMs (4-8 s). + private static void SlotRefusedResentQuickly() => Clocked(() => + { + var tick = LootUntilFirstMove(jumpEnabled: true, secondGem: false, stamina: 100u, serverGates: true); + long sent = _now; + Check.Eq(FakeHost.ExternalMoves.Count, 1, "one move out"); + Check.Eq(Field("_currentLootItemMoveAttempts"), 1, "the first try"); + TickFor(tick, 2 * TickMs); + _bot.NoteSlotRefusalChat(SlotChat); // the client's local refusal + TickUntil(tick, () => FakeHost.ExternalMoves.Count >= 2, 1000); + Check.Eq(FakeHost.ExternalMoves.Count, 2, "sent again"); + long resentAfter = _now - sent; + Check.True(resentAfter >= RynthAiPlugin.SlotRefusalRetryMs - TickMs && resentAfter <= RynthAiPlugin.SlotRefusalRetryMs + 3 * TickMs, + $"about {RynthAiPlugin.SlotRefusalRetryMs} ms after the refused send: {resentAfter} ms"); + Check.Eq(FakeHost.ExternalMoves[1].Id, GemA, "the same item"); + Check.Eq(Field("_currentLootItemMoveAttempts"), 1, "still the first try"); + Check.Eq(Field("_currentLootItemFreeRetries"), 0, "and not a too-busy free retry either"); + Check.True(FakeHost.Logs.Any(l => l.Contains("request slot refused the move of 0x" + GemA.ToString("X8"))), "logged for the live logs"); + Check.False(FakeHost.Logs.Any(l => l.Contains("retrying use")), "not the ordinary retry"); + // Refused again: the same, still no try used. + TickFor(tick, 2 * TickMs); + _bot.NoteSlotRefusalChat(SlotChat); + TickUntil(tick, () => FakeHost.ExternalMoves.Count >= 3, 1000); + Check.Eq(FakeHost.ExternalMoves.Count, 3, "and again"); + Check.Eq(Field("_currentLootItemMoveAttempts"), 1, "still the first try"); + // The slot is free now and the server answers. + TickFor(tick, 100); + FakeHost.Containers[GemA] = Player; + TickUntil(tick, () => Confirmed(GemA), 1000); + Check.True(Confirmed(GemA), "the pickup is confirmed"); + }); + + // The refusal text of something else (a buff swap, a use) first seen long after our send is not ours, + // and a player's words are never the client's line. + private static void LateSlotRefusalIgnored() => Clocked(() => + { + var tick = LootUntilFirstMove(jumpEnabled: true, secondGem: false, stamina: 100u, serverGates: true); + _bot.NoteSlotRefusalChat("Tarsh tells you, \"" + SlotChat + "\""); + Check.Eq(Field("_slotRefusalSeq"), 0, "a player's words never count"); + TickFor(tick, RynthAiPlugin.SlotRefusalAttributionMs + 100); + _bot.NoteSlotRefusalChat(SlotChat); + TickFor(tick, 600); + Check.Eq(FakeHost.ExternalMoves.Count, 1, "no resend: the move is still awaiting its answer"); + Check.False(FakeHost.Logs.Any(l => l.Contains("request slot refused")), "not logged as ours"); + }); + + // A refusal line from something else lands 100 ms after our send (inside the attribution window, + // so it is taken for ours); the server answers at 200 ms, before the resend is due at 250 ms: + // one move only. + private static void ForeignRefusalThenAnswerSingleMove() => Clocked(() => + { + var tick = LootUntilFirstMove(jumpEnabled: true, secondGem: false, stamina: 100u, serverGates: true); + TickFor(tick, 100); + _bot.NoteSlotRefusalChat(SlotChat); + TickFor(tick, 100); + FakeHost.Containers[GemA] = Player; // the server answer at ~200 ms + TickFor(tick, 600); + Check.True(Confirmed(GemA), "the pickup is confirmed"); + Check.Eq(FakeHost.ExternalMoves.Count, 1, "a single move: the answer beat the resend"); + }); + + // The resends are time-based: the engine clears a request slot whose object is still present only + // after 10 s, so the item keeps being sent for SlotRefusalGiveUpMs from its first refusal. + // One refused send after another, each answered by a refusal line 40 ms after the send, for + // of fake time. Returns the number of resends made. + private static int RefuseForMs(Action tick, long ms) + { + long end = _now + ms; + int resends = 0; + while (_now < end) + { + int before = FakeHost.ExternalMoves.Count; + TickFor(tick, 2 * TickMs); + _bot.NoteSlotRefusalChat(SlotChat); + TickUntil(tick, () => FakeHost.ExternalMoves.Count > before, 500); + if (FakeHost.ExternalMoves.Count == before) break; + resends++; + } + return resends; + } + + private static void SlotResendsStillGoingAt9s() => Clocked(() => + { + var tick = LootUntilFirstMove(jumpEnabled: true, secondGem: false, stamina: 100u, serverGates: true); + int resends = RefuseForMs(tick, 9000); + Check.True(resends >= 30, $"still resending after 9 s of refusals (a count cap of 30 would have stopped at 7.5 s): {resends} resends"); + Check.False(Field("_currentLootItemSlotGaveUp"), "not given up"); + Check.Eq(Field("_currentLootItemMoveAttempts"), 1, "and no try used"); + Check.Eq(FakeHost.ExternalMoves.Count, resends + 1, "one move per resend: " + Order()); + }); + + // After SlotRefusalGiveUpMs from the first refusal the ordinary answer wait takes over. + private static void SlotResendCapHandsOver() => Clocked(() => + { + var tick = LootUntilFirstMove(jumpEnabled: true, secondGem: false, stamina: 100u, serverGates: true); + long start = _now; + int resends = RefuseForMs(tick, RynthAiPlugin.SlotRefusalGiveUpMs + 2000); + Check.True(Field("_currentLootItemSlotGaveUp"), $"given up after {_now - start} ms ({resends} resends)"); + Check.True(_now - start >= RynthAiPlugin.SlotRefusalGiveUpMs, $"not before {RynthAiPlugin.SlotRefusalGiveUpMs} ms: {_now - start}"); + Check.True(_now - start <= RynthAiPlugin.SlotRefusalGiveUpMs + 1000, $"and soon after it: {_now - start}"); + int moves = FakeHost.ExternalMoves.Count; + TickFor(tick, 2 * TickMs); + _bot.NoteSlotRefusalChat(SlotChat); + TickFor(tick, 1000); + Check.Eq(FakeHost.ExternalMoves.Count, moves, "no resend after it: the ordinary answer wait (4 s or more) holds the item"); + Check.Eq(Field("_currentLootItemMoveAttempts"), 1, "and no try was used"); + Check.True(FakeHost.Logs.Any(l => l.Contains("the ordinary answer wait takes over")), "logged"); + }); + + // A send made while the character's motion queue is busy is held by the engine's main-thread queue + // (up to 2.5 s): its refusal line can come long after 200 ms and is still its own. + private static void DeferredSendRefusalAt700IsResent() => Clocked(() => + { + var tick = LootUntilFirstMove(jumpEnabled: true, secondGem: true, stamina: 100u, serverGates: true); + uint first = FakeHost.ExternalMoves[0].Id; + Air(up: true); + TickFor(tick, 100); + FakeHost.CastBusy = 1; // the jump's motion plays + FakeHost.Containers[first] = Player; // no bend-down: the next goes out in the air + TickUntil(tick, () => FakeHost.ExternalMoves.Count >= 2, 500); + Check.Eq(FakeHost.ExternalMoves.Count, 2, "the second move is out while the queue is busy"); + Check.Eq(Field("_currentLootItemSlotWindowMs"), RynthAiPlugin.SlotRefusalDeferredWindowMs, "its refusal window is the deferred one"); + TickFor(tick, 700); + _bot.NoteSlotRefusalChat(SlotChat); + TickUntil(tick, () => FakeHost.ExternalMoves.Count >= 3, 600); + Check.Eq(FakeHost.ExternalMoves.Count, 3, "a refusal 700 ms after the send is taken for its own and the item is sent again"); + }); + + // Another item action of this plugin went out just before the line: it may be that one's refusal. + private static void ForeignItemActionSuppressesAttribution() => Clocked(() => + { + var tick = LootUntilFirstMove(jumpEnabled: true, secondGem: false, stamina: 100u, serverGates: true); + TickFor(tick, 50); + _host.UseFor(0x80263199u, "Buff", "test: a buff item use"); // the UseAudit choke point notes it + TickFor(tick, 50); + _bot.NoteSlotRefusalChat(SlotChat); // 100 ms after the send + TickFor(tick, 600); + FakeHost.Containers[GemA] = Player; // the answer, 700 ms in + TickFor(tick, 100); + Check.True(Confirmed(GemA), "the pickup is confirmed"); + Check.Eq(FakeHost.ExternalMoves.Count, 1, "one move: the line was not taken for ours"); + Check.False(FakeHost.Logs.Any(l => l.Contains("request slot refused")), "not logged as ours"); + }); + + private static void ResetClearsSlotFields() => Clocked(() => + { + var tick = LootUntilFirstMove(jumpEnabled: true, secondGem: false, stamina: 100u, serverGates: true); + TickFor(tick, 2 * TickMs); + _bot.NoteSlotRefusalChat(SlotChat); + TickUntil(tick, () => FakeHost.ExternalMoves.Count >= 2, 1000); + Check.True(Field("_currentLootItemSlotResends") > 0, "a slot resend was made"); + typeof(RynthAiPlugin).GetMethod("ResetCurrentLootItem", Any)!.Invoke(_bot, null); + Check.Eq(Field("_currentLootItemSlotResends"), 0, "resends cleared"); + Check.Eq(Field("_currentLootItemSlotSeqAtSend"), 0, "baseline cleared"); + Check.Eq(Field("_currentLootItemSlotRefusedAt"), 0L, "refusal time cleared"); + }); + + // The net runs with Jump When Looting on only: with it off, a refusal line changes nothing and + // the send keeps its ordinary answer wait. + private static void SlotNetNeedsJumpLoot() => Clocked(() => + { + var tick = LootUntilFirstMove(jumpEnabled: false, secondGem: false, stamina: 100u, serverGates: true); + TickFor(tick, 2 * TickMs); + _bot.NoteSlotRefusalChat(SlotChat); // inside the attribution window + TickFor(tick, 1000); + Check.Eq(FakeHost.ExternalMoves.Count, 1, "no quick resend with jump-loot off"); + Check.False(FakeHost.Logs.Any(l => l.Contains("request slot refused")), "not taken for a slot refusal"); + }); + + // A UseOnFor (a kit, a mana stone, a lockpick) between a loot send and the refusal line is another + // item action of this plugin: the line may be its refusal, so it is not taken for the loot send's. + private static void UseOnForSuppressesAttribution() => Clocked(() => + { + var tick = LootUntilFirstMove(jumpEnabled: true, secondGem: false, stamina: 100u, serverGates: true); + TickFor(tick, 40); + _host.UseOnFor(0x80263198u, Player, "Buff", "test: a kit on the player"); // UseAudit.UseOnFor notes it + TickFor(tick, 40); + _bot.NoteSlotRefusalChat(SlotChat); // 80 ms after the send + TickFor(tick, 600); + Check.Eq(FakeHost.ExternalMoves.Count, 1, "no resend: the line was not taken for ours"); + Check.False(FakeHost.Logs.Any(l => l.Contains("request slot refused")), "not logged as ours"); + }); + + // The looter's own UseOnFor ("Loot") is not another item action: it leaves LastItemActionAt as it + // was, so a refusal line after it is still taken for the loot send's and the item is resent. + private static void LootUseOnForIsNotStamped() => Clocked(() => + { + var tick = LootUntilFirstMove(jumpEnabled: true, secondGem: false, stamina: 100u, serverGates: true); + TickFor(tick, 40); + long before = UseAudit.LastItemActionAt; + _host.UseOnFor(0x80263198u, Player, "Loot", "test: the looter's own use"); + Check.Eq(UseAudit.LastItemActionAt, before, "a Loot UseOnFor leaves the stamp as it was"); + TickFor(tick, 40); + _bot.NoteSlotRefusalChat(SlotChat); // 80 ms after the send + TickUntil(tick, () => FakeHost.ExternalMoves.Count >= 2, 600); + Check.Eq(FakeHost.ExternalMoves.Count, 2, "resent: the line was taken for ours"); + Check.True(FakeHost.Logs.Any(l => l.Contains("request slot refused")), "logged as ours"); + }); + + // A send made while the motion queue is busy has a 2500 ms refusal window, and the look back for + // another item action is that same window: an action 1 s before such a send keeps a line that + // arrives 700 ms after it from being taken for the send's (a 200 ms look back would miss it). + private static void ForeignActionLookbackUsesSendWindow() => Clocked(() => + { + var tick = LootUntilFirstMove(jumpEnabled: true, secondGem: true, stamina: 100u, serverGates: true); + uint first = FakeHost.ExternalMoves[0].Id; + Air(up: true); + TickFor(tick, 100); + FakeHost.CastBusy = 1; // the jump's motion plays + FakeHost.Containers[first] = Player; // no bend-down: the next goes out in the air + TickUntil(tick, () => FakeHost.ExternalMoves.Count >= 2, 500); + Check.Eq(FakeHost.ExternalMoves.Count, 2, "the second move is out while the queue is busy"); + Check.Eq(Field("_currentLootItemSlotWindowMs"), RynthAiPlugin.SlotRefusalDeferredWindowMs, "its window is the deferred one"); + var clock = UseAudit.NowMs; + UseAudit.NowMs = () => _now - 1000; // another item action 1 s before this send + UseAudit.NoteItemAction(); + UseAudit.NowMs = clock; + TickFor(tick, 700); + _bot.NoteSlotRefusalChat(SlotChat); + TickFor(tick, 600); + Check.Eq(FakeHost.ExternalMoves.Count, 2, "no resend: the earlier item action may own the line"); + Check.False(FakeHost.Logs.Any(l => l.Contains("request slot refused")), "not logged as ours"); + }); + + // A fight has the tick (HoldOpenCorpseForFight, reached through TickCorpseOpening with Combat + // given the tick): no resend then, since the client drops an item move while the character + // attacks. The refusal heard during the fight is attributed by its own arrival time, so after the + // fight the item goes again at once, without costing a try, and the fight flag of the refused send + // is not carried onto the fresh one. + private static void SlotRefusalWaitsOutAFight() => Clocked(() => + { + var tick = LootUntilFirstMove(jumpEnabled: true, secondGem: false, stamina: 100u, serverGates: true); + void FightTick() + { + SetField("_activity", BotActivity.Combat); + typeof(RynthAiPlugin).GetMethod("TickCorpseOpening", Any)!.Invoke(_bot, null); + } + TickFor(tick, 2 * TickMs); + _bot.NoteSlotRefusalChat(SlotChat); // 40 ms after the send: ours + for (int i = 0; i < 25; i++) { _now += TickMs; FightTick(); } // 500 ms of fight + Check.True(FakeHost.Logs.Any(l => l.Contains("waits for the fight")), "the corpse is held for the fight"); + Check.Eq(FakeHost.ExternalMoves.Count, 1, "no resend while a fight has the tick"); + long fightEnd = _now; + TickUntil(tick, () => FakeHost.ExternalMoves.Count >= 2, 500); + Check.Eq(FakeHost.ExternalMoves.Count, 2, "after the fight the refused move goes again"); + Check.True(_now - fightEnd <= 2 * TickMs, $"at once: {_now - fightEnd} ms after the fight"); + Check.Eq(Field("_currentLootItemMoveAttempts"), 1, "not one of the 3 tries"); + Check.False(Field("_currentLootItemFightHeld"), "the fresh send carries no fight flag"); + }); + // Only "You're too busy" (0x1D) proves the no-bend-down call wrong. A save-failed with // no code (a full pack, or anything else) that comes fast is not that evidence. private static void NonBusyRefusalKeepsNoMotion() => Clocked(() => diff --git a/Tools/RynthCore.RynthAiHostTests/Tests/OwnCorpseTests.cs b/Tools/RynthCore.RynthAiHostTests/Tests/OwnCorpseTests.cs index eb131b9..ae6d860 100644 --- a/Tools/RynthCore.RynthAiHostTests/Tests/OwnCorpseTests.cs +++ b/Tools/RynthCore.RynthAiHostTests/Tests/OwnCorpseTests.cs @@ -36,6 +36,7 @@ internal static class OwnCorpseTests { r.Add("own corpse: recognised by exact name + 'Killed by' line, never a namesake or another player's", Identification); r.Add("own corpse: every item is taken, the loot profile and Loot From ignored, then closed", RecoveredWhole); + r.Add("own corpse: a slot-refusal line heard earlier in the session does not make an own-corpse send repeat (one move, the server silent)", EarlierSlotRefusalNoSpuriousResend); r.Add("own corpse: another player's corpse with a similar name is left alone", SimilarNameUntouched); r.Add("own corpse: Recover My Corpse off = the behaviour before (profile only, My Kills skips it)", SettingOffIsOldBehaviour); r.Add("own corpse: beats a nearer corpse of your kill; a timeout retries it instead of writing it off", PriorityAndTimeout); @@ -203,6 +204,32 @@ internal static class OwnCorpseTests Check.False(bot.Get("_currentLootItemIsSalvage"), "nothing queued for salvage"); } + // The refusal count is session-wide. An own-corpse send used to leave its baseline at 0, so any + // refusal line heard earlier (a buff swap's) read as a refusal of this send and the item was + // sent again 250 ms later into a server that was still busy with the first (two in flight). + // The baseline is taken in the shared send path now. Real time, as the other tests here. + private static void EarlierSlotRefusalNoSpuriousResend() + { + World("Corpse of " + Me, "Killed by Ancient Water Elemental.", closeCalls: true); + var bot = NewBot(); + bot.S.LootJumpEnabled = true; // the slot-refusal net runs only with Jump When Looting on + bot.P.NoteSlotRefusalChat("You can only move or use one item at a time"); // an earlier, unrelated refusal + bot.Tick(BotActivity.Looting); + Check.True(FakeHost.Uses.Contains(Corpse), "the corpse is opened"); + foreach (uint id in new[] { Gem, Cloak, Coins }) + bot.Cache.OnCreateObject(id); + bot.Cache.Tick(); + FakeHost.GroundContainer = Corpse; + bot.P.OnViewObjectContents(Corpse); + for (int i = 0; i < 400 && FakeHost.ExternalMoves.Count == 0; i++) { bot.Tick(BotActivity.Looting); Thread.Sleep(10); } + Check.Eq(FakeHost.ExternalMoves.Count, 1, "the first own-corpse move is out: " + Moves()); + Check.Eq(bot.Get("_currentLootItemSlotSeqAtSend"), bot.Get("_slotRefusalSeq"), "the send took the refusal baseline (shared send path)"); + var sw = System.Diagnostics.Stopwatch.StartNew(); + while (sw.ElapsedMilliseconds < 600) { bot.Tick(BotActivity.Looting); Thread.Sleep(10); } // the server is silent + Check.Eq(FakeHost.ExternalMoves.Count, 1, "exactly one move over 600 ms: " + Moves()); + Check.False(FakeHost.Logs.Any(l => l.Contains("request slot refused")), "no refusal was taken for this send"); + } + private static void SimilarNameUntouched() { World("Corpse of " + Me + "s", "Killed by Ancient Water Elemental.");