From e0b89d0cab36854a292e50ab09d3304afda0040f Mon Sep 17 00:00:00 2001 From: Tom Bohar Date: Mon, 23 Nov 2026 13:11:00 -0500 Subject: [PATCH] RynthSuite as of 2026-11-23 (internal f4d28d93): release 2026.11.23.2 --- .../Combat/WorldObjectCache.cs | 34 ++- .../CorpseOpenController.cs | 11 +- .../LegacyUi/LegacyAdvancedSettingsUi.cs | 3 +- .../LegacyUi/LegacyUiSettings.cs | 3 +- .../RynthAiPlugin.ChestLoot.cs | 206 +++++++++++++++++- .../Tests/ChestLootTests.cs | 161 +++++++++++++- 6 files changed, 402 insertions(+), 16 deletions(-) diff --git a/Plugins/RynthCore.Plugin.RynthAi/Combat/WorldObjectCache.cs b/Plugins/RynthCore.Plugin.RynthAi/Combat/WorldObjectCache.cs index 733d268..4724b0c 100644 --- a/Plugins/RynthCore.Plugin.RynthAi/Combat/WorldObjectCache.cs +++ b/Plugins/RynthCore.Plugin.RynthAi/Combat/WorldObjectCache.cs @@ -771,7 +771,9 @@ public class WorldObjectCache if (wielder == _playerId || container == _playerId) return Holder.Player; if (wielder != 0) return Holder.OtherWielder; if (container == 0) return Holder.Nobody; - // Side packs sit in the main pack (AC has no deeper nesting). + // Side packs sit in the main pack (AC has no deeper nesting). A pack already filed as ours is ours, + // even when its own ownership can't be read (after an engine reload, 2026-11-23). + if (_inventory.Contains(containerId)) return Holder.Player; return TryGetOwnership(containerId, out int outer, out _, out _) && unchecked((uint)outer) == _playerId ? Holder.Player : Holder.OtherContainer; } @@ -808,7 +810,10 @@ public class WorldObjectCache else { Holder holder = WhoHas(id); - toInventory = holder == Holder.Player || (holder == Holder.Unknown && gear); + // "Nobody" while the last container walk found it in our packs: the container and wielder of + // an item that was wielded earlier can both read 0 once it is back in a pack (2026-11-23). + toInventory = holder == Holder.Player || (holder == Holder.Unknown && gear) + || (holder == Holder.Nobody && _directInventoryIds.Contains(id)); toLandscape = !toInventory && holder != Holder.OtherWielder; } @@ -1500,6 +1505,7 @@ public class WorldObjectCache // parent/slot for the remote inventory view (stashed onto the WorldObject). if (!TryAddDirectInventoryItem(itemId, playerId, containerId, i, out bool isContainer)) continue; + RefileWalkedAsCarried(unchecked((int)itemId)); // The player's own contents can list what the player wields (the 07:27 export had the // wielded Sceptre in it, 2026-10-18), and reading a wielded caster as "in the pack" made // buffing ignore it and try every other one. So only a side pack, or the main pack with @@ -2430,6 +2436,30 @@ public class WorldObjectCache return true; } + /// Entries the container walk moved back from the landscape (for the log and the tests). + internal int WalkRefiled { get; private set; } + + /// + /// The container walk is the client's own pack lists: what it finds there is carried. A weapon that + /// was wielded earlier keeps its physics object (it reads as positioned) while its container and + /// wielder fields can both read 0 back in a pack, so a classify after an engine reload filed it as + /// lying loose and nothing filed it back: the Items panel showed packed weapons as "(missing)" and + /// combat skipped the listed wand (2026-11-23). Only ids the cache already knows; no new probes. + /// + private void RefileWalkedAsCarried(int id) + { + lock (_gate) + { + if (!_byId.TryGetValue(id, out var wo) || _inventory.Contains(id)) return; + if (wo.ObjectClass == AcObjectClass.Monster || wo.ObjectClass == AcObjectClass.Corpse) return; + _inventory.Add(id); + _landscape.Remove(id); + _inventoryDirty = true; + WalkRefiled++; + _host.Log($"[RynthAi] Inventory: 0x{unchecked((uint)id):X8} '{wo.Name}' was filed as lying loose, but the container walk found it in a pack: back in the inventory."); + } + } + /// Inventory entries dropped by (for the log and the tests). internal int VanishedDropped { get; private set; } diff --git a/Plugins/RynthCore.Plugin.RynthAi/CorpseOpenController.cs b/Plugins/RynthCore.Plugin.RynthAi/CorpseOpenController.cs index cebbb71..c4c00b0 100644 --- a/Plugins/RynthCore.Plugin.RynthAi/CorpseOpenController.cs +++ b/Plugins/RynthCore.Plugin.RynthAi/CorpseOpenController.cs @@ -518,6 +518,8 @@ public sealed partial class RynthAiPlugin public override void OnViewObjectContents(uint objectId) { int sid = unchecked((int)objectId); + // Another container opened (the player's, a meta's): a Pickup-with-macro-off reopen is dropped. + CancelManualChestReopen(sid, $"0x{objectId:X8} was opened instead"); if (!IsCorpseLikeObject(sid)) { // Non-corpse container (chest, bag, etc.) — queue a loot-check once inventory arrives. @@ -626,7 +628,8 @@ public sealed partial class RynthAiPlugin int sid = unchecked((int)objectId); if (_pendingLootCheckContainerId == sid) _pendingLootCheckContainerId = 0; - // A chest: closed by the player, the server (walked away) or our own close. Never reopened. + // A chest: closed by the player, the client (out of its reach) or our own close. Reopened + // only as OnChestGone decides (RynthAiPlugin.ChestLoot.cs). if (OnChestGone(sid, "was closed")) return; bool wasOpenCorpse = _openedContainerId == sid; @@ -656,6 +659,7 @@ public sealed partial class RynthAiPlugin public override void OnVendorOpen(uint vendorId) { + CancelManualChestReopen(unchecked((int)vendorId), "a vendor was opened"); _metaManager?.OnVendorOpen(vendorId); // AutoVendor prints the open line itself (UB's merchant-info line when it can read the @@ -765,6 +769,7 @@ public sealed partial class RynthAiPlugin TakeLootThisRequest(settings); // /ra lootthis (RynthAiPlugin.VTankHotkeys.cs) TakeChestKeyRequest(); // the Item Tool's chest looter (RynthAiPlugin.ItemTool.cs) TakeManualChest(settings); // Pickup with macro off (RynthAiPlugin.ChestLoot.cs) + TickManualChestReopen(settings, CorpseNowMs); // ... and its one reopen of a chest the client closed // ── Macro off / looting disabled / nav-boost — full stop and reset ── // Must come before the Buffing check so that turning off the macro always @@ -1695,7 +1700,9 @@ public sealed partial class RynthAiPlugin // Wait for inventory update event from server if (_openedContainerInventoryObservedAt == 0) { - if (openAge < Math.Max(300, settings.LootEmptyCorpseMs)) + // A chest's contents can come well after the open (a 120-item cache took over + // 312 ms): waiting only the corpse's short time called it empty and finished it. + if (openAge < EmptyContainerWaitMs(corpseId, settings.LootEmptyCorpseMs)) return; _openedContainerInventoryObservedAt = _openedContainerAt; LootDiag($"[RynthAi] {LootTag}: no inventory update for 0x{(uint)corpseId:X8}; probing after {openAge}ms."); diff --git a/Plugins/RynthCore.Plugin.RynthAi/LegacyUi/LegacyAdvancedSettingsUi.cs b/Plugins/RynthCore.Plugin.RynthAi/LegacyUi/LegacyAdvancedSettingsUi.cs index 121b65d..11b1018 100644 --- a/Plugins/RynthCore.Plugin.RynthAi/LegacyUi/LegacyAdvancedSettingsUi.cs +++ b/Plugins/RynthCore.Plugin.RynthAi/LegacyUi/LegacyAdvancedSettingsUi.cs @@ -1155,7 +1155,8 @@ internal sealed class LegacyAdvancedSettingsUi ImGui.SetTooltip("Loots scrolls of spells you don't know and can learn (magic school trained or\nspecialized, skill high enough), and reads them when it's safe. Scrolls already\nin your pack are read too."); ImGui.Checkbox("Pickup with macro off", ref _settings.LootChestsMacroOff); if (ImGui.IsItemHovered()) - ImGui.SetTooltip("A chest you open is looted by the loaded loot profile\neven with the macro or Looting off."); + ImGui.SetTooltip("A chest you open is looted by the loaded loot profile\neven with the macro or Looting off.\n" + + "If the game closes it before that's done because the character\nstepped out of its reach, it is opened once more. A chest you\nclose yourself, or leave for another, is not."); if (_settings.LootChestsMacroOff) { ImGui.Indent(); diff --git a/Plugins/RynthCore.Plugin.RynthAi/LegacyUi/LegacyUiSettings.cs b/Plugins/RynthCore.Plugin.RynthAi/LegacyUi/LegacyUiSettings.cs index 714bc05..c394c21 100644 --- a/Plugins/RynthCore.Plugin.RynthAi/LegacyUi/LegacyUiSettings.cs +++ b/Plugins/RynthCore.Plugin.RynthAi/LegacyUi/LegacyUiSettings.cs @@ -234,7 +234,8 @@ public sealed class LegacyUiSettings /// /// Pickup with macro off (2026-11-02, on by default): a chest the player opens is looted by the /// loaded loot profile even with the macro or Looting off (like /ra lootthis). With both on the - /// macro's own chest looting takes it. + /// macro's own chest looting takes it. A chest the client closes before it is done (the + /// character out of its use radius) is opened again once (2026-11-23, RynthAiPlugin.ChestLoot.cs). /// public bool LootChestsMacroOff = true; /// diff --git a/Plugins/RynthCore.Plugin.RynthAi/RynthAiPlugin.ChestLoot.cs b/Plugins/RynthCore.Plugin.RynthAi/RynthAiPlugin.ChestLoot.cs index d20f6c0..e5dc1aa 100644 --- a/Plugins/RynthCore.Plugin.RynthAi/RynthAiPlugin.ChestLoot.cs +++ b/Plugins/RynthCore.Plugin.RynthAi/RynthAiPlugin.ChestLoot.cs @@ -40,6 +40,16 @@ public sealed partial class RynthAiPlugin private bool IsChestLoot(int id) => id != 0 && id == _lootChestId; + /// How long an open chest may show no contents before it counts as empty. A big chest's + /// contents can arrive well after the open (a 120-item cache had nothing after 312 ms, then all of + /// it); the corpse's short wait finished it unlooted and a script moved on to the next one. + internal const int ChestNoContentsWaitMs = 3000; + + /// The no-contents wait for the open container: for a + /// chest, the corpse setting (at least 300 ms) otherwise. + internal int EmptyContainerWaitMs(int id, int corpseEmptyMs) + => IsChestLoot(id) ? Math.Max(ChestNoContentsWaitMs, corpseEmptyMs) : Math.Max(300, corpseEmptyMs); + /// The last chest looted to the end (every item judged), for the meta's ralastchestlooted[] (0 = none). private uint _lastChestLootedId; @@ -326,10 +336,15 @@ public sealed partial class RynthAiPlugin _lootChestId = 0; return true; } - // Not a chest the player opened with the macro off: that one is the player's to close. - bool reopens = how == ChestClosedHow && id != _manualChestLootId && ConsiderChestReopen(id, taken: true); + // A chest the player opened with the macro off (Pickup with macro off) is opened again once, + // and only when the client closed it on its own (ConsiderManualChestReopen, below). + bool manual = id == _manualChestLootId; + string manualWhy = string.Empty; + bool reopens = how == ChestClosedHow + && (manual ? ConsiderManualChestReopen(id, out manualWhy) : ConsiderChestReopen(id, taken: true)); if (!reopens) - LootDiag($"[RynthAi] Chest loot: chest 0x{(uint)id:X8} {how} before looting finished; not reopening it (open it again to loot the rest)."); + LootDiag($"[RynthAi] Chest loot: chest 0x{(uint)id:X8} {how} before looting finished; not reopening it" + + (manualWhy.Length > 0 ? $" ({manualWhy})" : string.Empty) + " (open it again to loot the rest)."); FinishChestLoot(id, how, close: false, sayNothingMatched: false); return true; } @@ -347,8 +362,8 @@ public sealed partial class RynthAiPlugin // A corpse the looter was on is opened again (OnStopViewingObjectContents); a chest was not, // so the rest stayed in it until someone opened it again. Now the looter uses the chest again, // at most ChestReopenMax times a minute per chest: a chest that keeps closing (locked again, - // a player closing it on purpose) is left after that. Only with the macro and Looting on, and - // never for a chest the player opened with the macro off. + // a player closing it on purpose) is left after that. Only with the macro and Looting on; a + // chest Pickup with macro off is looting has its own, narrower rule (further down). /// OnChestGone's "how" for the server's close (the other is "left range": the object is gone). internal const string ChestClosedHow = "was closed"; @@ -373,6 +388,7 @@ public sealed partial class RynthAiPlugin _chestReopenId = 0; _chestReopenDueAt = 0; _chestReopenSentAt = 0; + _chestReopenManual = false; } /// @@ -417,7 +433,7 @@ public sealed partial class RynthAiPlugin /// HasLootWork: a chest waits to be opened again (no state changed). private bool HasChestReopenWork() => - _chestReopenId != 0 && _targetCorpseId == 0 && _openedContainerId == 0; + _chestReopenId != 0 && !_chestReopenManual && _targetCorpseId == 0 && _openedContainerId == 0; /// /// TickCorpseOpening, nothing claimed or open: uses the chest booked by ConsiderChestReopen once @@ -428,8 +444,8 @@ public sealed partial class RynthAiPlugin private bool TryReopenChest(LegacyUiSettings settings, long now) { int id = _chestReopenId; - if (id == 0 || _targetCorpseId != 0 || _openedContainerId != 0) - return false; + if (id == 0 || _chestReopenManual || _targetCorpseId != 0 || _openedContainerId != 0) + return false; // (a Pickup-with-macro-off reopen is TickManualChestReopen's) if (_objectCache?[id] == null) { ClearChestReopen(); @@ -527,5 +543,179 @@ public sealed partial class RynthAiPlugin LootDiag($"[RynthAi] Pickup with macro off: looting the opened chest 0x{(uint)id:X8} by the loot profile."); ForceLootOpenChest(id); _manualChestLootId = id; + _manualChestTakenAtMeters = _objectCache?.Distance(unchecked((int)_playerId), id) ?? double.NaN; + } + + // ── Pickup with macro off: one reopen of a chest the client closed (2026-11-23) ──────────── + // A treasure cache a Lua script opened closed three times in two minutes with items left, + // each one "was closed before looting finished; not reopening it". The client's LootWindowProbe + // named the sender each time: CPlayerSystem::CalculateObjectRangeChecks (0x005600D0), the + // once-a-second check gmExternalContainerUI::SetGroundObject registers with the container's use + // radius, found the character out of it (3.0, 3.7 and 2.5 m off) and hid the loot window, whose + // hide uses the container (CloseCurrentContainer) - and the server closes it. 235 of 238 probe + // lines in a month of logs are that check; the other 3 are the window's close button + // (UIElement_Button::MouseUp). Salvage without the panel opens no window and was not involved. + // + // So with the macro off a chest the client closed is opened again, once a minute per chest - + // but not one the player closed or left for something else: + // - the player's close (the close button, a second use) happens within the chest's reach. The + // client's check closes it only out of reach, and its cylinder distance is never more than + // the centre distance read here, so a close with the character inside the chest's use radius + // (STypeFloat 54) is the player's. Without a readable radius, a close where the character + // stands no farther than when looting began is taken as the player's too. + // - anything else opened before the reopen goes out (another chest, a corpse, a vendor) drops it. + // - a character walked past the loot range is not walked back (TryReopenChest's distance rule). + + /// Pickup with macro off opens a chest the client closed again at most this often a minute. + internal const int ManualChestReopenMax = 1; + /// Without a use radius: this much farther from the chest than when looting began counts as moved out of reach. + internal const double ManualChestMovedMeters = 0.5; + private const uint UseRadiusFloat = 54; + + /// The booked reopen is Pickup with macro off's (TickManualChestReopen), not the macro's. + private bool _chestReopenManual; + /// The character's distance to the Pickup-with-macro-off chest when looting began. + private double _manualChestTakenAtMeters = double.NaN; + + /// + /// The Pickup-with-macro-off chest was closed with loot left: books one + /// reopen when the client closed it (the character out of its reach) and logs it. False, with + /// , when it was the player's close or it was reopened already. + /// + private bool ConsiderManualChestReopen(int id, out string why) + { + why = string.Empty; + var settings = _dashboard?.Settings; + if (settings == null || !settings.LootChestsMacroOff || _objectCache?[id] == null || _playerId == 0) + return false; + + double meters = _objectCache.Distance(unchecked((int)_playerId), id); + if (double.IsNaN(meters) || meters >= double.MaxValue / 2) + { + why = "where the character stands can't be read, so it is taken as your own close"; + return false; + } + double radius = Host.HasGetObjectDoubleProperty + && Host.TryGetObjectDoubleProperty(unchecked((uint)id), UseRadiusFloat, out double r) && r > 0 ? r : 0; + string where; + if (radius > 0) + { + if (meters < radius) + { + why = $"you were {meters:0.0} m from it, inside its {radius:0.0} m reach, so it was your own close"; + return false; + } + where = $"you were {meters:0.0} m from it, past its {radius:0.0} m reach"; + } + else + { + double moved = double.IsNaN(_manualChestTakenAtMeters) ? 0 : meters - _manualChestTakenAtMeters; + if (moved < ManualChestMovedMeters) + { + why = $"you were {meters:0.0} m from it, no farther than when looting began, so it was your own close"; + return false; + } + where = $"you were {meters:0.0} m from it, {moved:0.0} m farther than when looting began"; + } + + long now = CorpseNowMs; + int count = 0; + long firstAt = now; + if (_chestReopens.TryGetValue(id, out var seen) && now - seen.FirstAt < ChestReopenWindowMs) + { + count = seen.Count; + firstAt = seen.FirstAt; + } + if (count >= ManualChestReopenMax) + { + why = $"{where}; it was opened again once in the last minute already"; + return false; + } + if (_chestReopens.Count > 32) + _chestReopens.Clear(); + _chestReopens[id] = (firstAt, count + 1); + _chestReopenId = id; + _chestReopenManual = true; + _chestReopenDueAt = now + ChestReopenDelayMs; + _chestReopenSentAt = 0; + LootDiag($"[RynthAi] Pickup with macro off: chest 0x{(uint)id:X8} {ChestClosedHow} before looting finished, " + + $"by the client ({where}), not by you; opening it again (once)."); + return true; + } + + /// Drops a booked Pickup-with-macro-off reopen when container , not the chest, opens. + private void CancelManualChestReopen(int openedId, string what) + { + int id = _chestReopenId; + if (id == 0 || !_chestReopenManual || openedId == id) + return; + LootDiag($"[RynthAi] Pickup with macro off: not opening chest 0x{(uint)id:X8} again: {what}."); + ClearChestReopen(); + } + + /// + /// TickCorpseOpening, every tick (the macro or Looting may be off): uses the chest booked by + /// ConsiderManualChestReopen once its delay is over and nothing holds a use, then waits for it + /// to open (OnViewObjectContents hands it to TakeManualChest again). + /// + private void TickManualChestReopen(LegacyUiSettings settings, long now) + { + int id = _chestReopenId; + if (id == 0 || !_chestReopenManual) + return; + if (!settings.LootChestsMacroOff || _objectCache?[id] == null || _playerId == 0) + { + ClearChestReopen(); + return; + } + if (settings.IsMacroRunning && settings.EnableLooting) + { + _chestReopenManual = false; // the macro's own chest looting has it now (TryReopenChest) + return; + } + if (_openedContainerId != 0 || _targetCorpseId != 0) + return; // something else is open (an open cancels the booking; this is a guard) + + if (_chestReopenSentAt != 0) + { + if (now - _chestReopenSentAt < ChestReopenAnswerMs) + return; + LootDiag($"[RynthAi] Pickup with macro off: chest 0x{(uint)id:X8} didn't open again within {ChestReopenAnswerMs / 1000} s of the use; it is left (open it again to loot the rest)."); + ClearChestReopen(); + return; + } + if (now - _chestReopenDueAt >= ChestReopenStaleMs) + { + LootDiag($"[RynthAi] Pickup with macro off: the reopen of chest 0x{(uint)id:X8} waited {ChestReopenStaleMs / 1000} s; dropped (open it again to loot the rest)."); + ClearChestReopen(); + return; + } + if (now < _chestReopenDueAt) + return; + // The macro on with Looting off: a fight or a buff run has the tick; the use waits for it. + if (settings.IsMacroRunning && _activity is BotActivity.Combat or BotActivity.Buffing) + return; + // A salvage panel opening, or an item move with no answer yet: the client would drop the use. + if (WorldUseHoldReason() != null) + return; + + double maxMeters = GetCorpseApproachRangeMaxMeters(settings); + double distance = _objectCache.Distance(unchecked((int)_playerId), id); + if (double.IsNaN(distance) || distance > Math.Max(maxMeters * 1.5, maxMeters + 2.0)) + { + LootDiag($"[RynthAi] Pickup with macro off: not opening chest 0x{(uint)id:X8} again - it is {distance:0.0} m away, past the loot range ({maxMeters:0.0} m)."); + ClearChestReopen(); + return; + } + + bool sent = Host.UseFor(unchecked((uint)id), "Loot", "open the chest again: the client closed it before Pickup with macro off was done"); + if (!sent) + { + LootDiag($"[RynthAi] Pickup with macro off: the use to open chest 0x{(uint)id:X8} again wasn't taken; it is left (open it again to loot the rest)."); + ClearChestReopen(); + return; + } + _chestReopenSentAt = now; + LootDiag($"[RynthAi] Pickup with macro off: used chest 0x{(uint)id:X8} to open it again."); } } diff --git a/Tools/RynthCore.RynthAiHostTests/Tests/ChestLootTests.cs b/Tools/RynthCore.RynthAiHostTests/Tests/ChestLootTests.cs index f804b57..596838d 100644 --- a/Tools/RynthCore.RynthAiHostTests/Tests/ChestLootTests.cs +++ b/Tools/RynthCore.RynthAiHostTests/Tests/ChestLootTests.cs @@ -51,6 +51,10 @@ internal static class ChestLootTests r.Add("chest loot: closed mid-loot -> the looter opens it again and takes the rest", ClosedMidLootReopened); r.Add("chest loot: a chest that keeps closing is opened again twice in a minute, then left", ReopenIsBounded); r.Add("chest loot: a chest the player opened with the macro off is not reopened when it closes", ManualChestNotReopened); + r.Add("chest loot: Pickup with macro off opens a chest the client closed out of reach again, once, and takes the rest", ManualChestClosedOutOfReachReopened); + r.Add("chest loot: Pickup with macro off: no use radius readable -> moved away counts, standing still is the player's close", ManualChestReopenWithoutRadius); + r.Add("chest loot: Pickup with macro off: something else opened before the reopen -> it is dropped", ManualChestReopenDroppedForOtherOpen); + r.Add("chest loot: Pickup with macro off with the macro on and Looting off: the reopen waits for the fight", ManualChestReopenWaitsForFight); r.Add("chest loot: an open chest that closes before the looter gets to it (a fight had the tick) is opened again", ClosedBeforeTakenReopened); r.Add("chest loot: no jump-loot from a chest (a hop can take the character out of its use radius)", NoJumpLootFromChest); r.Add("chest loot: a chest gets 2 minutes (not the 12 s corpse timeout), restarted by each pickup", ChestTimeoutLongAndRestarted); @@ -646,8 +650,161 @@ internal static class ChestLootTests bot.ServerCloses(Chest); // the player closes it bot.TickFor((int)RynthAiPlugin.ChestReopenDelayMs + 400); - Check.Eq(ChestUses(), 0, "the player's chest is the player's to close: never reopened"); - Check.True(FakeHost.Logs.Any(l => l.Contains("Chest loot:") && l.Contains("not reopening it")), "logged as before"); + Check.Eq(ChestUses(), 0, "the player's close (where looting began) is the player's: not reopened"); + Check.True(FakeHost.Logs.Any(l => l.Contains("Chest loot:") && l.Contains("not reopening it") && l.Contains("your own close")), + "logged, with why"); + } + + // ── Pickup with macro off: one reopen of a chest the client closed (2026-11-23) ────────────── + // A treasure cache a script opened closed three times with items left; the LootWindowProbe named + // the client's once-a-second range check (CPlayerSystem::CalculateObjectRangeChecks) each time, + // with the character 2.5-3.7 m off. Salvage was not involved. + + private const uint OtherChest = 0x7A9B4005; + private const uint UseRadiusFloat = 54; + + /// Puts the character west of the chest (the chest is at Me0.X + 1). + private static void StandFromChest(float meters) + { + var at = (Me0.Cell, Me0.X + 1.0f - meters, Me0.Y, Me0.Z); + FakeHost.Positions[Player] = at; + FakeHost.PlayerPose = at; + } + + /// Macro off, the chest opened by the player and the gem's pickup sent. + private static Bot ManualChestMidLoot(bool macroOn = false) + { + var host = FakeHost.Create(Player); + var bot = new Bot(host); + if (macroOn) bot.S.EnableLooting = false; else bot.S.IsMacroRunning = false; + bot.Create(Chest, Gem, Spoon); + bot.ServerOpens(Chest); + bot.TickUntil(() => bot.Moved(Gem)); + Check.True(bot.Moved(Gem), "the gem's move is sent"); + return bot; + } + + private static void ManualChestClosedOutOfReachReopened() + { + BaseWorld(); + FakeHost.Doubles[(Chest, UseRadiusFloat)] = 2.0; // the chest's use radius (its PublicWeenieDesc) + var bot = ManualChestMidLoot(); + + // A step back past its reach: the client's range check closes it. + StandFromChest(3.5f); + bot.ServerCloses(Chest); + Check.Eq(bot.Get("_openedContainerId"), 0, "the session ends"); + Check.True(FakeHost.Logs.Any(l => l.Contains("Pickup with macro off: chest") && l.Contains("by the client") + && l.Contains("past its 2.0 m reach") && l.Contains("opening it again (once)")), "booked and logged with why"); + Check.False(bot.HasLootWork(), "not macro loot work: the arbiter is not asked for Looting"); + bot.Tick(); + Check.Eq(ChestUses(), 0, "not at once: the close settles first"); + bot.TickUntil(() => ChestUses() > 0); + Check.Eq(ChestUses(), 1, "then the chest is used to open it again"); + bot.TickFor(200); + Check.Eq(ChestUses(), 1, "one use while it waits for the chest to open"); + + // It opens (the server walked the character back): Pickup with macro off takes it again. + StandFromChest(1.0f); + int movesBefore = FakeHost.ExternalMoves.Count; + bot.ServerOpens(Chest); + bot.TickUntil(() => FakeHost.ExternalMoves.Count > movesBefore); + Check.True(FakeHost.ExternalMoves.Count > movesBefore, "the gem's move is sent again"); + Check.Eq(FakeHost.Logs.Count(l => l.Contains("Pickup with macro off: looting the opened chest")), 2, "taken a second time"); + + // It closes out of reach again within the minute: once is all. + StandFromChest(3.5f); + bot.ServerCloses(Chest); + bot.TickFor((int)RynthAiPlugin.ChestReopenDelayMs + 400); + Check.Eq(ChestUses(), 1, "no second reopen in a minute"); + Check.True(FakeHost.Logs.Any(l => l.Contains("not reopening it") && l.Contains("opened again once in the last minute")), "logged"); + + // A close inside its reach is the player's (the close button, a second use): not reopened. + BaseWorld(); + FakeHost.Doubles[(Chest, UseRadiusFloat)] = 2.0; + var bot2 = ManualChestMidLoot(); + StandFromChest(1.5f); + bot2.ServerCloses(Chest); + bot2.TickFor((int)RynthAiPlugin.ChestReopenDelayMs + 400); + Check.Eq(ChestUses(), 0, "closed within its reach: the player's close, not reopened"); + Check.True(FakeHost.Logs.Any(l => l.Contains("not reopening it") && l.Contains("inside its 2.0 m reach") && l.Contains("your own close")), "logged with why"); + } + + private static void ManualChestReopenWithoutRadius() + { + // No use radius readable: a close after the character moved away is the client's. + BaseWorld(); + var bot = ManualChestMidLoot(); + StandFromChest(1.0f + (float)RynthAiPlugin.ManualChestMovedMeters + 0.5f); + bot.ServerCloses(Chest); + Check.True(FakeHost.Logs.Any(l => l.Contains("by the client") && l.Contains("farther than when looting began")), "booked: it moved away"); + bot.TickUntil(() => ChestUses() > 0); + Check.Eq(ChestUses(), 1, "opened again"); + + // Standing where looting began (0.2 m is within the margin): the player's close. + BaseWorld(); + var bot2 = ManualChestMidLoot(); + StandFromChest(1.2f); + bot2.ServerCloses(Chest); + bot2.TickFor((int)RynthAiPlugin.ChestReopenDelayMs + 400); + Check.Eq(ChestUses(), 0, "not reopened"); + + // Pickup with macro off turned off meanwhile: the booking goes. + BaseWorld(); + var bot3 = ManualChestMidLoot(); + StandFromChest(3.0f); + bot3.ServerCloses(Chest); + bot3.S.LootChestsMacroOff = false; + bot3.TickFor((int)RynthAiPlugin.ChestReopenDelayMs + 400); + Check.Eq(ChestUses(), 0, "the setting went off: not reopened"); + } + + private static void ManualChestReopenDroppedForOtherOpen() + { + BaseWorld(); + FakeHost.Doubles[(Chest, UseRadiusFloat)] = 2.0; + FakeHost.Names[OtherChest] = "Chest"; + FakeHost.ItemTypes[OtherChest] = ItemTypeContainer; + FakeHost.Positions[OtherChest] = (Me0.Cell, Me0.X - 4.0f, Me0.Y, Me0.Z); + FakeHost.NotAttackable.Add(OtherChest); + FakeHost.Containers[OtherChest] = 0; + var bot = ManualChestMidLoot(); + bot.Create(OtherChest); + + StandFromChest(3.5f); + bot.ServerCloses(Chest); + Check.True(FakeHost.Logs.Any(l => l.Contains("opening it again (once)")), "booked"); + // The player opens another chest before the reopen goes out (the server closed the first for it). + bot.ServerOpens(OtherChest); + Check.True(FakeHost.Logs.Any(l => l.Contains("Pickup with macro off: not opening chest") && l.Contains("was opened instead")), "dropped and logged"); + bot.TickFor((int)RynthAiPlugin.ChestReopenDelayMs + 400); + Check.Eq(ChestUses(), 0, "the first chest is not used again"); + + // A vendor opening drops it too. + BaseWorld(); + FakeHost.Doubles[(Chest, UseRadiusFloat)] = 2.0; + var bot2 = ManualChestMidLoot(); + StandFromChest(3.5f); + bot2.ServerCloses(Chest); + bot2.P.OnVendorOpen(0x7A9B4006); + bot2.TickFor((int)RynthAiPlugin.ChestReopenDelayMs + 400); + Check.Eq(ChestUses(), 0, "a vendor opened: not reopened"); + } + + private static void ManualChestReopenWaitsForFight() + { + BaseWorld(); + FakeHost.Doubles[(Chest, UseRadiusFloat)] = 2.0; + var bot = ManualChestMidLoot(macroOn: true); // the macro on, Looting off: Pickup with macro off has the chest + Check.True(FakeHost.Logs.Any(l => l.Contains("Pickup with macro off: looting the opened chest")), "Pickup with macro off took it"); + + StandFromChest(3.5f); // a step toward a monster + bot.ServerCloses(Chest); + Check.True(FakeHost.Logs.Any(l => l.Contains("opening it again (once)")), "booked"); + bot.TickFor((int)RynthAiPlugin.ChestReopenDelayMs + 300, BotActivity.Combat); + Check.Eq(ChestUses(), 0, "no use while the fight has the tick"); + bot.TickUntil(() => ChestUses() > 0); + Check.Eq(ChestUses(), 1, "used once the fight is over"); } // The 2026-11-11 20:02 case: a meta opened a cache while the looter was on a corpse; the corpse's