Corpse looting: no close before the next corpse, confirm stack merges, jump-loot on ACE
Next corpse without a close: when another lootable corpse is in range, a finished corpse is no longer closed (CloseContainer and its 500 ms answer wait). ACE closes the open container itself when the next one is used (Container.ActOnUse). The close is held back and still sent when no other corpse is opened within 3 s, or looting stops; the last corpse in range is closed at once as before. A finished corpse the client still shows is not taken as a close of the corpse opened after it (SyncCorpseContainerState), so its late CloseGroundContainer cannot make the bot re-use, and so close, the new corpse. Stack merges: a pickup that merges into a stack already in the pack never arrives as an object in the pack, so it waited out PickupArriveMaxMs (4 s). The same-name stacks in the inventory are noted when the pickup goes out; one that has grown since confirms the pickup. Jump-loot: the jump is the keyboard one (TapJump, 0xF61B Jump), which ACE handles; JumpNonAutonomous (0xF7C9) has no handler there. The jump goes before the move, since ACE's jump handler stops any walk-to in progress. It runs on every pickup, a corpse's only match included: most corpses hold a single match, so a "more than one item left" gate would mean jump-loot almost never ran. The tap jump has a fixed height, so the Jump Height slider is gone from the RynthAi settings page (LootJumpHeight itself stays plumbed). Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
b3960e157d
commit
fd9fe82095
6 changed files with 472 additions and 25 deletions
|
|
@ -522,6 +522,7 @@ public sealed partial class RynthAiPlugin
|
|||
return;
|
||||
|
||||
SyncCorpseContainerState();
|
||||
TickDeferredClose(settings);
|
||||
|
||||
// ── Macro off / looting disabled / nav-boost — full stop and reset ──
|
||||
// Must come before the Buffing check so that turning off the macro always
|
||||
|
|
@ -1471,17 +1472,21 @@ public sealed partial class RynthAiPlugin
|
|||
Host.SelectItem(unchecked((uint)firstMatchId));
|
||||
LootDiag($"[RynthAi] Corpse loot: picking up 0x{(uint)firstMatchId:X8} '{matchItemName}' from corpse 0x{(uint)corpseId:X8}.");
|
||||
|
||||
// Jump-loot: jump before the move to cancel the pickup animation.
|
||||
// Only jump when multiple items remain (single-item: no animation worth cancelling).
|
||||
// Guards: needs both hooks, stamina > 5 to cover the cost.
|
||||
int remainingItems = visibleItemCount - _processedCorpseItems.Count;
|
||||
bool useJumpLoot = settings.LootJumpEnabled
|
||||
&& Host.HasJumpNonAutonomous
|
||||
&& Host.HasMoveItemExternal
|
||||
&& _vitals.CurrentStamina > 5;
|
||||
|
||||
if (useJumpLoot && remainingItems > 1)
|
||||
Host.JumpNonAutonomous(Math.Clamp(settings.LootJumpHeight / 100f, 0.01f, 1f));
|
||||
// Jump-loot: jump, then the move while the character is still in the air, so the server
|
||||
// skips the pickup bend-down (ACE GetPickupMotion: IsJumping and allow_jump_loot ->
|
||||
// MotionCommand.Invalid, decided in the move's walk-to callback). The jump is the
|
||||
// keyboard one (TapJump, 0xF61B Jump, which ACE handles: Player.HandleActionJump);
|
||||
// JumpNonAutonomous (0xF7C9) has no handler on ACE and did nothing. The
|
||||
// jump goes FIRST: ACE's jump handler stops any walk-to in progress
|
||||
// (GameActionJump -> StopExistingMoveToChains), so a jump after the move would cancel
|
||||
// the pickup. Both calls run in order on AC's main thread (one FIFO queue), and the
|
||||
// engine's TapJump sends the Jump at once (about 10 ms apart in a client log).
|
||||
// Every pickup, a corpse's only match included (by design: most corpses hold one
|
||||
// match, so a multi-item gate meant jump-loot almost never ran), with stamina > 5 to
|
||||
// cover the cost. The pacer does not track this jump, so a cast sent before landing
|
||||
// is refused in the air and retried.
|
||||
if (ShouldJumpLoot(settings))
|
||||
Host.TapJump();
|
||||
|
||||
// Always a move into a pack, never a use: a use on a wearable corpse item is
|
||||
// get-and-wield, which put salvage jewellery on the character (2026-10-02).
|
||||
|
|
@ -1537,6 +1542,50 @@ public sealed partial class RynthAiPlugin
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>Jump-loot for this pickup: the setting, the keyboard jump and the move call, stamina for
|
||||
/// the jump.</summary>
|
||||
private bool ShouldJumpLoot(LegacyUiSettings settings) =>
|
||||
settings.LootJumpEnabled
|
||||
&& Host.HasTapJump
|
||||
&& Host.HasMoveItemExternal
|
||||
&& _vitals.CurrentStamina > 5;
|
||||
|
||||
// A pickup that merges into a stack already in the pack (a Silver Pea onto the Silver Peas):
|
||||
// the server removes the corpse item (InventoryRemoveObject) and raises the pack stack's size,
|
||||
// so the picked object never shows up in the inventory and the arrival check waited out
|
||||
// PickupArriveMaxMs (in a client log, 39 stack pickups: median 5018 ms to confirm against
|
||||
// 2731 ms). The stacks of that name in the inventory are noted when the pickup goes out; one that has grown since counts as arrival.
|
||||
private readonly Dictionary<int, int> _mergeBaseline = new();
|
||||
|
||||
private void NoteMergeTargets(int itemId, string itemName)
|
||||
{
|
||||
_mergeBaseline.Clear();
|
||||
if (_objectCache == null || string.IsNullOrEmpty(itemName)) return;
|
||||
foreach (WorldObject inv in _objectCache.GetDirectInventory(forceRefresh: true))
|
||||
{
|
||||
if (inv.Id == itemId || !string.Equals(inv.Name, itemName, StringComparison.Ordinal)) continue;
|
||||
_mergeBaseline[inv.Id] = Math.Max(1, inv.Values(LongValueKey.StackCount, 1));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>A same-name stack in the inventory has grown since the pickup went out.</summary>
|
||||
private bool MergedIntoInventoryStack(out int stackId)
|
||||
{
|
||||
stackId = 0;
|
||||
if (_objectCache == null) return false;
|
||||
foreach (var kv in _mergeBaseline)
|
||||
{
|
||||
WorldObject? stack = _objectCache[kv.Key];
|
||||
if (stack == null || !InPlayerInventory(stack.Container)) continue;
|
||||
if (Math.Max(1, stack.Values(LongValueKey.StackCount, 1)) > kv.Value)
|
||||
{
|
||||
stackId = kv.Key;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>Longest a pickup waits on the motion queue (the engine's own hold is 2.5 s).</summary>
|
||||
internal const long PickupAnimMaxMs = 3000;
|
||||
|
||||
|
|
@ -1624,6 +1673,9 @@ public sealed partial class RynthAiPlugin
|
|||
{
|
||||
if (_currentLootItemLeftAt == 0) _currentLootItemLeftAt = now;
|
||||
bool inInventory = currentItem == null || InPlayerInventory(currentContainer);
|
||||
int mergedInto = 0;
|
||||
if (!inInventory && MergedIntoInventoryStack(out mergedInto))
|
||||
inInventory = true;
|
||||
long since = now - _currentLootItemLeftAt;
|
||||
bool settled = !animating && (_currentLootItemSawAnim || since >= PickupSettleMs);
|
||||
if (!(inInventory && settled) && since < PickupArriveMaxMs)
|
||||
|
|
@ -1632,9 +1684,11 @@ public sealed partial class RynthAiPlugin
|
|||
now,
|
||||
currentItem == null
|
||||
? "item left cache after use"
|
||||
: (!stillVisibleOnCorpse
|
||||
? "item no longer listed on corpse"
|
||||
: $"new container=0x{(uint)currentContainer:X8}"));
|
||||
: mergedInto != 0
|
||||
? $"merged into the stack 0x{(uint)mergedInto:X8} in the pack"
|
||||
: (!stillVisibleOnCorpse
|
||||
? "item no longer listed on corpse"
|
||||
: $"new container=0x{(uint)currentContainer:X8}"));
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -1725,6 +1779,7 @@ public sealed partial class RynthAiPlugin
|
|||
/// </summary>
|
||||
private LootPickupResult SendLootPickup(int itemId, string itemName, int corpseId)
|
||||
{
|
||||
NoteMergeTargets(itemId, itemName);
|
||||
bool ownCorpse = corpseId != 0 && corpseId == _ownRecoveryCorpseId;
|
||||
uint dest;
|
||||
LootPickupResult r = ownCorpse
|
||||
|
|
@ -2434,7 +2489,13 @@ public sealed partial class RynthAiPlugin
|
|||
// server closes this corpse when the next UseObject open is sent.
|
||||
// Clear container state immediately; SyncCorpseContainerState guards against
|
||||
// re-claiming via _completedCorpses until the server's close lands.
|
||||
CloseCorpseContainer(corpseId, "completed");
|
||||
// With another corpse to loot in range, no close at all: ACE closes the open
|
||||
// container itself when the next one is used (Container.ActOnUse closes the player's
|
||||
// LastOpenedContainerId first), so the close and its answer wait (CloseAnswerWaitMs) only
|
||||
// delayed the next open. The close is held back (TickDeferredClose) and still sent if no
|
||||
// other corpse is opened, or looting stops.
|
||||
if (!(OtherCorpseToLoot(corpseId) && DeferClose(corpseId)))
|
||||
CloseCorpseContainer(corpseId, "completed");
|
||||
if (_openedContainerId == corpseId)
|
||||
{
|
||||
_openedContainerId = 0;
|
||||
|
|
@ -2604,6 +2665,12 @@ public sealed partial class RynthAiPlugin
|
|||
if (watch && sent)
|
||||
_useRefusals.OnOpenSent(corpseId, now, seqBefore);
|
||||
LootDiag($"[RynthAi] Corpse loot: attempting open for 0x{(uint)corpseId:X8}.");
|
||||
// The finished corpse held open (MarkCorpseCompleted): this use closes it on the server.
|
||||
if (sent && _closeDeferredFor != 0 && _closeDeferredFor != corpseId)
|
||||
{
|
||||
LootDiag($"[RynthAi] Corpse loot: 0x{(uint)_closeDeferredFor:X8} is left for the server to close with this open.");
|
||||
_closeDeferredFor = 0;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -2771,6 +2838,12 @@ public sealed partial class RynthAiPlugin
|
|||
return;
|
||||
|
||||
long now = CorpseNowMs;
|
||||
// A finished corpse the client still shows (its close from the server not in yet: the next
|
||||
// corpse was used without closing it, MarkCorpseCompleted) is not a close of the corpse we
|
||||
// have open now. A real close of that one empties the client's container (or brings
|
||||
// OnStopViewingObjectContents), never shows the old corpse again.
|
||||
if (_openedContainerId != 0 && rawOpen != 0 && rawOpen != _openedContainerId && _completedCorpses.ContainsKey(rawOpen))
|
||||
return;
|
||||
if (_openedContainerId != 0 && rawOpen != _openedContainerId)
|
||||
{
|
||||
int previousOpen = _openedContainerId;
|
||||
|
|
@ -3002,6 +3075,57 @@ public sealed partial class RynthAiPlugin
|
|||
private long _closeSentAt;
|
||||
private const long CloseAnswerWaitMs = 500;
|
||||
|
||||
// A finished corpse left open for the server to close when the next one is used (MarkCorpseCompleted).
|
||||
private int _closeDeferredFor;
|
||||
private long _closeDeferredAt;
|
||||
/// <summary>A held-back close is sent anyway when no other corpse has been opened this long.</summary>
|
||||
internal const long DeferredCloseMaxMs = 3000;
|
||||
|
||||
/// <summary>Another corpse to loot is in range (the finished one is already marked completed).</summary>
|
||||
private bool OtherCorpseToLoot(int doneCorpseId)
|
||||
{
|
||||
var settings = _dashboard?.Settings;
|
||||
if (settings == null || _objectCache == null) return false;
|
||||
double maxMeters = GetCorpseApproachRangeMaxMeters(settings);
|
||||
if (maxMeters <= 0.25) return false;
|
||||
return TryFindNearestCorpse(maxMeters, out WorldObject? next, out _) && next != null && next.Id != doneCorpseId;
|
||||
}
|
||||
|
||||
/// <summary>Holds the close of a finished corpse back. Only when the engine can close it later and
|
||||
/// reports which container the client has open (so the hold can see the server close it).</summary>
|
||||
private bool DeferClose(int corpseId)
|
||||
{
|
||||
if (!Host.HasCloseContainer || !Host.HasGetGroundContainerId)
|
||||
return false;
|
||||
if (unchecked((int)Host.GetGroundContainerId()) != corpseId && _openedContainerId != corpseId)
|
||||
return false;
|
||||
_closeDeferredFor = corpseId;
|
||||
_closeDeferredAt = CorpseNowMs;
|
||||
LootDiag($"[RynthAi] Corpse loot: 0x{(uint)corpseId:X8} done; no close sent (the server closes it when the next corpse is used).");
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Each tick: a held-back close. Gone from the client (the server closed it): done. Looting
|
||||
/// stopped, or no other corpse opened within DeferredCloseMaxMs: the close is sent now.
|
||||
/// </summary>
|
||||
private void TickDeferredClose(LegacyUiSettings settings)
|
||||
{
|
||||
int id = _closeDeferredFor;
|
||||
if (id == 0) return;
|
||||
if (!Host.HasGetGroundContainerId || unchecked((int)Host.GetGroundContainerId()) != id)
|
||||
{
|
||||
_closeDeferredFor = 0;
|
||||
LootDiag($"[RynthAi] Corpse loot: 0x{(uint)id:X8} closed by the server.");
|
||||
return;
|
||||
}
|
||||
bool stopped = !settings.IsMacroRunning || !settings.EnableLooting || settings.BoostNavPriority;
|
||||
if (!stopped && CorpseNowMs - _closeDeferredAt < DeferredCloseMaxMs)
|
||||
return;
|
||||
_closeDeferredFor = 0;
|
||||
CloseCorpseContainer(id, stopped ? "completed; looting stopped" : "completed; no other corpse opened");
|
||||
}
|
||||
|
||||
private void CloseCorpseContainer(int corpseId, string why)
|
||||
{
|
||||
if (corpseId == 0 || !Host.HasCloseContainer)
|
||||
|
|
|
|||
|
|
@ -817,11 +817,8 @@ internal sealed class LegacyAdvancedSettingsUi
|
|||
if (ImGui.IsItemHovered())
|
||||
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("Jump When Looting", ref _settings.LootJumpEnabled);
|
||||
if (_settings.LootJumpEnabled)
|
||||
{
|
||||
ImGui.SetNextItemWidth(120);
|
||||
ImGui.SliderInt("Jump Height", ref _settings.LootJumpHeight, 1, 100);
|
||||
}
|
||||
if (ImGui.IsItemHovered())
|
||||
ImGui.SetTooltip("Hop (the keyboard jump) just before each pickup,\nso the server skips the bend-down. The hop has a fixed height.");
|
||||
|
||||
ImGui.Spacing();
|
||||
ImGui.Text("Corpse Ownership");
|
||||
|
|
|
|||
|
|
@ -92,7 +92,7 @@ public sealed class LegacyUiSettings
|
|||
public int LootOpenRetryMs = 1500;
|
||||
public int LootCorpseTimeoutMs = 12000;
|
||||
public bool LootJumpEnabled = false;
|
||||
public int LootJumpHeight = 10; // 0–100; maps to 0.0–1.0 JumpNonAutonomous extent
|
||||
public int LootJumpHeight = 10; // kept for old profiles and metas; jump-loot uses the keyboard tap jump (fixed height)
|
||||
|
||||
public int SalvageOpenDelayFirstMs = 400;
|
||||
public int SalvageOpenDelayFastMs = 50;
|
||||
|
|
|
|||
|
|
@ -88,6 +88,8 @@ internal static unsafe class FakeHost
|
|||
/// <summary>Opt-in: wires TapJump (the keyboard jump, 0xF61B); calls land in <see cref="TapJumps"/>.</summary>
|
||||
public static bool TapJumpCalls;
|
||||
public static int TapJumps;
|
||||
/// <summary>Jumps and item moves in the order they were called ("tapjump", "jump", "move:XXXXXXXX").</summary>
|
||||
public static readonly List<string> Order = new();
|
||||
public static int Turns;
|
||||
public static readonly List<(uint Target, int SpellId)> Casts = new();
|
||||
/// <summary>Opt-in: wires GiveObjectTo (AC's give action); every call lands in <see cref="Gives"/>.</summary>
|
||||
|
|
@ -209,7 +211,7 @@ internal static unsafe class FakeHost
|
|||
Vitals = default; BaseVitals = default; WorldName = ""; AccountName = "";
|
||||
HeadingDeg = 0; Wcids.Clear(); Spellbook.Clear(); PlayerIdValue = 0;
|
||||
Logs.Clear(); Chat.Clear(); ChatCommands.Clear();
|
||||
AutoRunCalls.Clear(); AutoRun = false; Jumps = 0; TapJumpCalls = false; TapJumps = 0; Turns = 0; Casts.Clear(); StopCalls = false; Stops = 0; SetMotionCalls = false; MotionCalls.Clear(); Sent.Clear(); GiveCalls = false; Gives.Clear(); GiveLands = true;
|
||||
AutoRunCalls.Clear(); AutoRun = false; Jumps = 0; TapJumpCalls = false; TapJumps = 0; Order.Clear(); Turns = 0; Casts.Clear(); StopCalls = false; Stops = 0; SetMotionCalls = false; MotionCalls.Clear(); Sent.Clear(); GiveCalls = false; Gives.Clear(); GiveLands = true;
|
||||
Uses.Clear(); IdRequests.Clear(); Moves.Clear(); Appraised.Clear(); WeaponCalls = false; CombatModeValue = 1;
|
||||
VTankFlags = -1; VTankSeq = 0; LogCostMicros = 0;
|
||||
ServerGates = false; UseDoneSeq = 0; CastBusy = 0; LastUseDoneError = 0; LastUseDoneCalls = false;
|
||||
|
|
@ -648,10 +650,10 @@ internal static unsafe class FakeHost
|
|||
private static int TurnToHeading(float deg) { HeadingDeg = deg; Turns++; return 1; }
|
||||
|
||||
[UnmanagedCallersOnly(CallConvs = new[] { typeof(CallConvCdecl) })]
|
||||
private static int JumpNonAutonomous(float extent) { Jumps++; return 1; }
|
||||
private static int JumpNonAutonomous(float extent) { Jumps++; Order.Add("jump"); return 1; }
|
||||
|
||||
[UnmanagedCallersOnly(CallConvs = new[] { typeof(CallConvCdecl) })]
|
||||
private static int TapJump() { TapJumps++; return 1; }
|
||||
private static int TapJump() { TapJumps++; Order.Add("tapjump"); return 1; }
|
||||
|
||||
[UnmanagedCallersOnly(CallConvs = new[] { typeof(CallConvCdecl) })]
|
||||
private static int CastSpell(uint target, int spellId) { Casts.Add((target, spellId)); Sent.Add($"cast {spellId}"); return 1; }
|
||||
|
|
@ -690,7 +692,7 @@ internal static unsafe class FakeHost
|
|||
private static uint GetGroundContainerId() => GroundContainer;
|
||||
|
||||
[UnmanagedCallersOnly(CallConvs = new[] { typeof(CallConvCdecl) })]
|
||||
private static int MoveItemExternal(uint id, uint target, int amount) { ExternalMoves.Add((id, target, amount)); return 1; }
|
||||
private static int MoveItemExternal(uint id, uint target, int amount) { ExternalMoves.Add((id, target, amount)); Order.Add($"move:{id:X8}"); return 1; }
|
||||
|
||||
[UnmanagedCallersOnly(CallConvs = new[] { typeof(CallConvCdecl) })]
|
||||
private static int SalvagePanelOpen(uint tool) => 1;
|
||||
|
|
|
|||
|
|
@ -100,6 +100,7 @@ internal static class Program
|
|||
ManaReserveTests.Register(runner);
|
||||
DamageRowsTests.Register(runner);
|
||||
LootPacingTests.Register(runner);
|
||||
CorpseCloseTests.Register(runner);
|
||||
return runner.Run("RynthAi host tests", args.Length > 0 ? args[0] : null);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
323
Tools/RynthCore.RynthAiHostTests/Tests/CorpseCloseTests.cs
Normal file
323
Tools/RynthCore.RynthAiHostTests/Tests/CorpseCloseTests.cs
Normal file
|
|
@ -0,0 +1,323 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using RynthCore.Loot;
|
||||
using RynthCore.Plugin.RynthAi;
|
||||
using RynthCore.Plugin.RynthAi.LegacyUi;
|
||||
using RynthCore.PluginCore;
|
||||
using RynthCore.PluginSdk;
|
||||
using RynthCore.RynthAiHostTests.Fakes;
|
||||
using RynthCore.RynthAiTests.Harness;
|
||||
|
||||
namespace RynthCore.RynthAiHostTests.Tests;
|
||||
|
||||
// Corpse looting speed:
|
||||
// - the finished corpse is not closed when another one is next (ACE closes it when the next
|
||||
// one is used); the late close of the old corpse must not disturb the new open.
|
||||
// - a pickup that merges into a stack already in the pack is confirmed when that stack grows
|
||||
// (it never arrives as an object in the pack: it waited out PickupArriveMaxMs, 4 s).
|
||||
// - jump-loot sends the keyboard jump (0xF61B, which ACE handles), and before the move.
|
||||
// The loot clock (CorpseOpenController.CorpseClock) is moved by hand here.
|
||||
internal static class CorpseCloseTests
|
||||
{
|
||||
private const uint Player = 0x50000D21;
|
||||
private const uint CorpseA = 0x80262100;
|
||||
private const uint CorpseB = 0x80262200;
|
||||
private const uint GemA = 0x80262101;
|
||||
private const uint GemA2 = 0x80262102;
|
||||
private const uint GemB = 0x80262201;
|
||||
private const uint PackStack = 0x80262301;
|
||||
private const uint ItemTypeContainer = 0x200, ItemTypeGem = 0x800;
|
||||
private const uint LongDescKey = 16;
|
||||
private const uint StackSizeKey = 12;
|
||||
private const string Me = "Ilsa Corvane";
|
||||
private const BindingFlags Any = BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public;
|
||||
private static (uint Cell, float X, float Y, float Z) Me0 => (0x1048002Au, 100f, 100f, 0f);
|
||||
|
||||
public static void Register(Runner r)
|
||||
{
|
||||
r.Add("corpse close: the next corpse is opened without closing the finished one; its late close doesn't disturb the new open", NextCorpseWithoutClose);
|
||||
r.Add("corpse close: a held-back close is sent when no other corpse is opened in time, and when the macro stops", DeferredCloseFallback);
|
||||
r.Add("loot pickup: a pickup that merges into a pack stack is confirmed when the stack grows, not after 4 s", StackMergeConfirmed);
|
||||
r.Add("jump loot: the keyboard jump (0xF61B) goes out before the move; never the unhandled 0xF7C9", JumpBeforeMove);
|
||||
}
|
||||
|
||||
private static long _now;
|
||||
|
||||
private static void Clocked(Action body)
|
||||
{
|
||||
var old = RynthAiPlugin.CorpseClock;
|
||||
_now = 50_000_000;
|
||||
RynthAiPlugin.CorpseClock = () => _now;
|
||||
try { body(); }
|
||||
finally { RynthAiPlugin.CorpseClock = old; }
|
||||
}
|
||||
|
||||
private static void Corpse(uint id, float dx)
|
||||
{
|
||||
FakeHost.Names[id] = "Corpse of Olthoi Swarm Drone";
|
||||
FakeHost.ItemTypes[id] = ItemTypeContainer;
|
||||
FakeHost.Strings[(id, LongDescKey)] = $"Killed by {Me}.";
|
||||
FakeHost.NotAttackable.Add(id);
|
||||
FakeHost.Positions[id] = (Me0.Cell, Me0.X + dx, Me0.Y, Me0.Z);
|
||||
}
|
||||
|
||||
private static void Gem(uint id, uint container)
|
||||
{
|
||||
FakeHost.Names[id] = "Black Opal";
|
||||
FakeHost.ItemTypes[id] = ItemTypeGem;
|
||||
FakeHost.Containers[id] = container;
|
||||
FakeHost.Appraised.Add(id);
|
||||
}
|
||||
|
||||
private static void World(bool twoCorpses, bool secondGem = false)
|
||||
{
|
||||
FakeHost.Reset();
|
||||
FakeHost.SalvageCalls = true; // UseObject + MoveItemExternal
|
||||
FakeHost.WeaponCalls = true; // RequestId, HasAppraisalData
|
||||
FakeHost.CloseContainerCalls = true; // CloseContainer + GetGroundContainerId
|
||||
FakeHost.TapJumpCalls = true;
|
||||
FakeHost.Names[Player] = Me;
|
||||
FakeHost.Positions[Player] = Me0;
|
||||
FakeHost.PlayerPose = Me0;
|
||||
Corpse(CorpseA, 1.0f);
|
||||
Gem(GemA, CorpseA);
|
||||
if (secondGem) Gem(GemA2, CorpseA);
|
||||
if (twoCorpses)
|
||||
{
|
||||
Corpse(CorpseB, 1.5f);
|
||||
Gem(GemB, CorpseB);
|
||||
}
|
||||
}
|
||||
|
||||
private sealed class Bot
|
||||
{
|
||||
public readonly RynthAiPlugin P = new();
|
||||
public readonly LegacyUiSettings S = new()
|
||||
{
|
||||
IsMacroRunning = true, EnableLooting = true, EnableCombat = false, LootOwnership = 0,
|
||||
LootContentSettleMs = 0, LootEmptyCorpseMs = 0, StopLootingWhenPackFull = false,
|
||||
};
|
||||
public readonly WorldObjectCache Cache;
|
||||
|
||||
public Bot(RynthCoreHost host)
|
||||
{
|
||||
typeof(RynthPluginBase).GetMethod("Attach", Any)!.Invoke(P, new object[] { FakeHost.LastApi });
|
||||
var dash = (LegacyDashboardRenderer)RuntimeHelpers.GetUninitializedObject(typeof(LegacyDashboardRenderer));
|
||||
typeof(LegacyDashboardRenderer).GetField("_settings", Any)!.SetValue(dash, S);
|
||||
Set("_dashboard", dash);
|
||||
Cache = new WorldObjectCache(host);
|
||||
Cache.SetPlayerId(Player);
|
||||
Set("_objectCache", Cache);
|
||||
Set("_playerId", Player);
|
||||
Set("_vitals", new PlayerVitalsCache { MaxHealth = 100, CurrentHealth = 100, MaxStamina = 100, CurrentStamina = 100, MaxMana = 100, CurrentMana = 100 });
|
||||
|
||||
string profile = Path.Combine(Program.TempRoot, "corpse-close-test.json");
|
||||
var p = new LootProfile { Name = "gems" };
|
||||
var rule = new LootRule { Name = "Gems", Action = LootAction.Keep };
|
||||
rule.Conditions.Add(new ObjectClassCondition { ObjectClass = AcObjectClass.Gem });
|
||||
p.Rules.Add(rule);
|
||||
p.Save(profile);
|
||||
S.CurrentLootPath = profile;
|
||||
}
|
||||
|
||||
public void Set(string f, object? v) => typeof(RynthAiPlugin).GetField(f, Any)!.SetValue(P, v);
|
||||
public T Get<T>(string f) => (T)typeof(RynthAiPlugin).GetField(f, Any)!.GetValue(P)!;
|
||||
public void Tick(BotActivity act = BotActivity.Looting)
|
||||
{
|
||||
Set("_activity", act);
|
||||
typeof(RynthAiPlugin).GetMethod("TickCorpseOpening", Any)!.Invoke(P, null);
|
||||
}
|
||||
public void TickFor(long ms, BotActivity act = BotActivity.Looting)
|
||||
{
|
||||
long end = _now + ms;
|
||||
while (_now < end) { _now += 20; Tick(act); }
|
||||
}
|
||||
public void Create(params uint[] ids)
|
||||
{
|
||||
foreach (uint id in ids) Cache.OnCreateObject(id);
|
||||
Cache.Tick();
|
||||
}
|
||||
public bool Completed(uint corpse) =>
|
||||
Get<Dictionary<int, long>>("_completedCorpses").ContainsKey(unchecked((int)corpse));
|
||||
}
|
||||
|
||||
private static bool Logged(string part) => FakeHost.Logs.Any(l => l.Contains(part, StringComparison.Ordinal));
|
||||
|
||||
/// <summary>Opens corpse A (the server's ViewContents) and loots its gem into the pack until A completes.</summary>
|
||||
private static void LootCorpseA(Bot bot)
|
||||
{
|
||||
bot.Tick();
|
||||
Check.True(FakeHost.Uses.Contains(CorpseA), "corpse A is opened");
|
||||
FakeHost.UseDone(0);
|
||||
FakeHost.GroundContainer = CorpseA;
|
||||
bot.P.OnViewObjectContents(CorpseA);
|
||||
for (int i = 0; i < 200 && !FakeHost.ExternalMoves.Any(m => m.Id == GemA); i++) { _now += 20; bot.Tick(); }
|
||||
Check.True(FakeHost.ExternalMoves.Any(m => m.Id == GemA), "the gem's move is sent");
|
||||
FakeHost.Containers[GemA] = Player;
|
||||
for (int i = 0; i < 200 && !bot.Completed(CorpseA); i++) { _now += 20; bot.Tick(); }
|
||||
Check.True(bot.Completed(CorpseA), "corpse A is completed");
|
||||
}
|
||||
|
||||
private static void NextCorpseWithoutClose() => Clocked(() =>
|
||||
{
|
||||
World(twoCorpses: true);
|
||||
var host = FakeHost.Create(Player);
|
||||
var bot = new Bot(host);
|
||||
bot.Create(CorpseA, CorpseB, GemA, GemB);
|
||||
LootCorpseA(bot);
|
||||
|
||||
Check.Eq(FakeHost.Closes.Count, 0, "corpse B is next: no close is sent for A");
|
||||
Check.True(Logged("no close sent (the server closes it when the next corpse is used)"), "and that is logged");
|
||||
|
||||
// The next corpse's open goes out at once: nothing waits for a close answer.
|
||||
long doneAt = _now;
|
||||
for (int i = 0; i < 10 && !FakeHost.Uses.Contains(CorpseB); i++) { _now += 20; bot.Tick(); }
|
||||
Check.True(FakeHost.Uses.Contains(CorpseB), "corpse B is opened");
|
||||
Check.True(_now - doneAt < 200, $"within {_now - doneAt} ms of A completing (the close answer wait was 500 ms)");
|
||||
Check.Eq(FakeHost.Closes.Count, 0, "still no close for A");
|
||||
Check.True(Logged($"0x{CorpseA:X8} is left for the server to close with this open"), "the open of B leaves A to the server");
|
||||
|
||||
// The server opens B; the client still shows A for a moment (its close not in yet).
|
||||
FakeHost.UseDone(0);
|
||||
bot.P.OnViewObjectContents(CorpseB);
|
||||
for (int i = 0; i < 5; i++) { _now += 20; bot.Tick(); }
|
||||
Check.Eq(bot.Get<int>("_openedContainerId"), unchecked((int)CorpseB), "B stays the open corpse while the client still shows A");
|
||||
// A's close lands (CloseGroundContainer A), then the client shows B.
|
||||
bot.P.OnStopViewingObjectContents(CorpseA);
|
||||
FakeHost.GroundContainer = CorpseB;
|
||||
for (int i = 0; i < 5; i++) { _now += 20; bot.Tick(); }
|
||||
Check.Eq(bot.Get<int>("_openedContainerId"), unchecked((int)CorpseB), "A's close doesn't touch B");
|
||||
Check.False(Logged($"container 0x{CorpseB:X8} closed before completion"), "B is not taken as closed");
|
||||
Check.Eq(FakeHost.Uses.Count(u => u == CorpseB), 1, "B is opened once (a second use would close it on ACE)");
|
||||
Check.Eq(FakeHost.Closes.Count, 0, "and A was never closed by RynthAi");
|
||||
});
|
||||
|
||||
private static void DeferredCloseFallback() => Clocked(() =>
|
||||
{
|
||||
// Corpse B in range, but combat holds the tick: no open of B, so A's close goes after the hold limit.
|
||||
World(twoCorpses: true);
|
||||
var host = FakeHost.Create(Player);
|
||||
var bot = new Bot(host);
|
||||
bot.Create(CorpseA, CorpseB, GemA, GemB);
|
||||
LootCorpseA(bot);
|
||||
Check.Eq(FakeHost.Closes.Count, 0, "held back at first");
|
||||
bot.TickFor(RynthAiPlugin.DeferredCloseMaxMs - 200, BotActivity.Combat);
|
||||
Check.Eq(FakeHost.Closes.Count, 0, "still held just under the limit");
|
||||
bot.TickFor(400, BotActivity.Combat);
|
||||
Check.Eq(string.Join(",", FakeHost.Closes.Select(c => $"{c:X8}")), $"{CorpseA:X8}", "no other corpse opened in time: A is closed, once");
|
||||
|
||||
// The macro stops while a close is held back: it goes at once.
|
||||
World(twoCorpses: true);
|
||||
var host2 = FakeHost.Create(Player);
|
||||
var bot2 = new Bot(host2);
|
||||
bot2.Create(CorpseA, CorpseB, GemA, GemB);
|
||||
LootCorpseA(bot2);
|
||||
Check.Eq(FakeHost.Closes.Count, 0, "held back");
|
||||
bot2.S.IsMacroRunning = false;
|
||||
_now += 20; bot2.Tick(BotActivity.Idle);
|
||||
Check.Eq(string.Join(",", FakeHost.Closes.Select(c => $"{c:X8}")), $"{CorpseA:X8}", "macro stopped: A is closed");
|
||||
|
||||
// Only corpse A: closed at once on completion, as before.
|
||||
World(twoCorpses: false);
|
||||
var host3 = FakeHost.Create(Player);
|
||||
var bot3 = new Bot(host3);
|
||||
bot3.Create(CorpseA, GemA);
|
||||
LootCorpseA(bot3);
|
||||
Check.Eq(string.Join(",", FakeHost.Closes.Select(c => $"{c:X8}")), $"{CorpseA:X8}", "the last corpse is closed at once");
|
||||
});
|
||||
|
||||
private static void StackMergeConfirmed() => Clocked(() =>
|
||||
{
|
||||
World(twoCorpses: false);
|
||||
Gem(PackStack, Player);
|
||||
FakeHost.Ints[(PackStack, StackSizeKey)] = 3;
|
||||
FakeHost.Ints[(GemA, StackSizeKey)] = 1;
|
||||
var host = FakeHost.Create(Player);
|
||||
var bot = new Bot(host);
|
||||
bot.Create(CorpseA, GemA, PackStack);
|
||||
bot.Tick();
|
||||
FakeHost.UseDone(0);
|
||||
FakeHost.GroundContainer = CorpseA;
|
||||
bot.P.OnViewObjectContents(CorpseA);
|
||||
for (int i = 0; i < 200 && !FakeHost.ExternalMoves.Any(m => m.Id == GemA); i++) { _now += 20; bot.Tick(); }
|
||||
Check.True(FakeHost.ExternalMoves.Any(m => m.Id == GemA), "the gem's move is sent");
|
||||
long sentAt = _now;
|
||||
|
||||
// The server merges it: the corpse item is removed (still known to the client's cache, in no
|
||||
// container), and the pack stack grows from 3 to 4.
|
||||
FakeHost.Containers[GemA] = 0;
|
||||
FakeHost.Ints[(PackStack, StackSizeKey)] = 4;
|
||||
for (int i = 0; i < 400 && !Logged("pickup confirmed for"); i++) { _now += 20; bot.Tick(); }
|
||||
Check.True(Logged($"pickup confirmed for 0x{GemA:X8}; merged into the stack 0x{PackStack:X8} in the pack"),
|
||||
"confirmed as a merge into the pack stack: " + (FakeHost.Logs.LastOrDefault(l => l.Contains("pickup confirmed")) ?? "(none)"));
|
||||
Check.True(_now - sentAt < RynthAiPlugin.PickupArriveMaxMs, $"confirmed {_now - sentAt} ms after the send, under the 4 s limit");
|
||||
|
||||
// A same-name stack that did not grow: not a merge, waits for the limit as before.
|
||||
World(twoCorpses: false);
|
||||
Gem(PackStack, Player);
|
||||
FakeHost.Ints[(PackStack, StackSizeKey)] = 3;
|
||||
var host2 = FakeHost.Create(Player);
|
||||
var bot2 = new Bot(host2);
|
||||
bot2.Create(CorpseA, GemA, PackStack);
|
||||
bot2.Tick();
|
||||
FakeHost.UseDone(0);
|
||||
FakeHost.GroundContainer = CorpseA;
|
||||
bot2.P.OnViewObjectContents(CorpseA);
|
||||
for (int i = 0; i < 200 && !FakeHost.ExternalMoves.Any(m => m.Id == GemA); i++) { _now += 20; bot2.Tick(); }
|
||||
long sent2 = _now;
|
||||
FakeHost.Containers[GemA] = 0; // gone from the corpse, the pack stack unchanged
|
||||
for (int i = 0; i < 400 && !Logged("pickup confirmed for"); i++) { _now += 20; bot2.Tick(); }
|
||||
Check.True(_now - sent2 >= RynthAiPlugin.PickupArriveMaxMs, $"no stack grew: confirmed only at the limit ({_now - sent2} ms)");
|
||||
});
|
||||
|
||||
private static void JumpBeforeMove() => Clocked(() =>
|
||||
{
|
||||
World(twoCorpses: false, secondGem: true);
|
||||
var host = FakeHost.Create(Player);
|
||||
var bot = new Bot(host);
|
||||
bot.S.LootJumpEnabled = true;
|
||||
bot.Create(CorpseA, GemA, GemA2);
|
||||
bot.Tick();
|
||||
FakeHost.UseDone(0);
|
||||
FakeHost.GroundContainer = CorpseA;
|
||||
bot.P.OnViewObjectContents(CorpseA);
|
||||
for (int i = 0; i < 200 && FakeHost.ExternalMoves.Count == 0; i++) { _now += 20; bot.Tick(); }
|
||||
Check.True(FakeHost.ExternalMoves.Count > 0, "a gem's move is sent");
|
||||
Check.Eq(FakeHost.Order.FirstOrDefault() ?? "", "tapjump", "the keyboard jump goes first: " + string.Join(",", FakeHost.Order));
|
||||
Check.True(FakeHost.Order.Count >= 2 && FakeHost.Order[1].StartsWith("move:", StringComparison.Ordinal), "then the move: " + string.Join(",", FakeHost.Order));
|
||||
Check.Eq(FakeHost.Jumps, 0, "never JumpNonAutonomous (0xF7C9, no handler on ACE)");
|
||||
|
||||
// A corpse's only match jumps too (by design).
|
||||
World(twoCorpses: false);
|
||||
var host1 = FakeHost.Create(Player);
|
||||
var bot1 = new Bot(host1);
|
||||
bot1.S.LootJumpEnabled = true;
|
||||
bot1.Create(CorpseA, GemA);
|
||||
bot1.Tick();
|
||||
FakeHost.UseDone(0);
|
||||
FakeHost.GroundContainer = CorpseA;
|
||||
bot1.P.OnViewObjectContents(CorpseA);
|
||||
for (int i = 0; i < 200 && FakeHost.ExternalMoves.Count == 0; i++) { _now += 20; bot1.Tick(); }
|
||||
Check.True(FakeHost.ExternalMoves.Count > 0, "single item: the move is sent");
|
||||
Check.Eq(FakeHost.Order.FirstOrDefault() ?? "", "tapjump", "single item: the jump goes first: " + string.Join(",", FakeHost.Order));
|
||||
Check.True(FakeHost.Order.Count >= 2 && FakeHost.Order[1].StartsWith("move:", StringComparison.Ordinal), "single item: then the move: " + string.Join(",", FakeHost.Order));
|
||||
Check.Eq(FakeHost.TapJumps, 1, "single item: one jump");
|
||||
Check.Eq(FakeHost.Jumps, 0, "single item: never JumpNonAutonomous");
|
||||
|
||||
// Off: no jump at all.
|
||||
World(twoCorpses: false, secondGem: true);
|
||||
var host2 = FakeHost.Create(Player);
|
||||
var bot2 = new Bot(host2);
|
||||
bot2.Create(CorpseA, GemA, GemA2);
|
||||
bot2.Tick();
|
||||
FakeHost.UseDone(0);
|
||||
FakeHost.GroundContainer = CorpseA;
|
||||
bot2.P.OnViewObjectContents(CorpseA);
|
||||
for (int i = 0; i < 200 && FakeHost.ExternalMoves.Count == 0; i++) { _now += 20; bot2.Tick(); }
|
||||
Check.Eq(FakeHost.TapJumps + FakeHost.Jumps, 0, "jump-loot off: no jump");
|
||||
});
|
||||
}
|
||||
Loading…
Reference in a new issue