RynthSuite/Tools/RynthCore.RynthAiHostTests/Tests/LootJumpTests.cs
Daniel Wallace 1fc4d68cfc RynthAi jump loot: answer merged stacks on arrival
A jump send that merged into a pack stack still waited the 500 ms
PickupAnswerMinMs floor, kept for fear that a merged-away object leaves
the client's request slot held. In client logs from one server the
merged stacks were off the corpse 157-234 ms after the send but confirmed
only at 500-516 ms, and the next send, made 1 ms after the confirm, was
answered normally, so the slot was free.

A jump send's merge is now answered on arrival when it is positively
seen: a same-name pack stack grown (checked whenever the item is not in
a pack), or the object of a STACK gone from the client. An unowned stack
still in the client, and a non-stack object that vanishes, keep the
floor, as does every send with no jump. The rare held slot is caught by
the slot-refusal resend; its log line now says whether a floor-less
merge confirm came just before it.

Only jump sends take this path, so it needs Jump When Looting
(LootJumpEnabled, default off).

Host tests: a jump merge into a grown stack and a jump stack gone from
the client are confirmed before the floor; a no-jump merge and a vanished
non-stack keep it.

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

1031 lines
62 KiB
C#

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.Plugin.Shared;
using RynthCore.PluginCore;
using RynthCore.PluginSdk;
using RynthCore.RynthAiHostTests.Fakes;
using RynthCore.RynthAiTests.Harness;
namespace RynthCore.RynthAiHostTests.Tests;
// Jump-loot: the jump is the keyboard one (TapJump, 0xF61B Jump, which ACE handles), never
// JumpNonAutonomous (0xF7C9, no handler on ACE). It goes BEFORE the move, on every pickup (a
// corpse's only match included), only with the setting on and stamina above 5.
// The loot clock (RynthAiPlugin.CorpseClock) is moved by hand here.
internal static class LootJumpTests
{
private const uint Player = 0x50000F31;
private const uint CorpseA = 0x80263100;
private const uint GemA = 0x80263101;
private const uint GemA2 = 0x80263102;
private const uint GemA3 = 0x80263103;
private const uint PackStack = 0x80263120;
private const uint KeyMaxStack = 11, KeyStack = 12;
private const uint CorpseB = 0x80263110;
private const uint GemB = 0x80263111;
private const uint ItemTypeContainer = 0x200, ItemTypeGem = 0x800;
private const uint LongDescKey = 16;
private const string Me = "Test Looter";
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("jump loot: two-item corpse - the keyboard jump (0xF61B) goes out before the move; never the unhandled 0xF7C9", TwoItemJumpsBeforeMove);
r.Add("jump loot: a corpse's only match jumps too (one tap jump)", SingleItemJumps);
r.Add("jump loot: the setting off sends no jump", SettingOffNoJump);
r.Add("jump loot: stamina of 5 or less sends no jump", LowStaminaNoJump);
r.Add("jump loot: a pickup answered with no bend-down releases the corpse at once; the next corpse is opened while still in the air", NoReturnNextCorpseInAir);
r.Add("jump loot: after a pickup answered with no bend-down, the next item goes out at once in the air with no second jump (not queued); after the landing the next one jumps again", NoReturnNextItemJumps);
r.Add("jump loot: a jump pickup answered only after a bend-down's time still waits for its Return before the corpse is released", SlowAnswerKeepsReturnWait);
r.Add("jump loot: a bend-down answer inside an earlier jump's flight ends it: the next item is queued behind that Return, with no jump", SlowAnswerEndsAirWindow);
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: 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 jump send merged into a pack stack (object still in the client, unowned; stack grown) is confirmed on arrival, before the 500 ms floor", JumpMergeConfirmedOnArrival);
r.Add("jump loot: a jump send of a stack whose object is gone from the client with no stack grown is confirmed on arrival too", JumpGoneConfirmedOnArrival);
r.Add("jump loot: a send with no jump that merged still waits PickupAnswerMinMs", NoJumpMergeKeepsAnswerFloor);
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 non-stack object that vanishes is no merge answer: the floor stays", NonStackVanishKeepsFloor);
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);
r.Add("jump loot: a send with no jump answered at 100 ms still waits its Return before the next corpse", NoJumpFastAnswerWaitsReturn);
r.Add("jump loot: a jump send refused, then resent (no jump), answered at 100 ms still waits its Return", ResentFastAnswerWaitsReturn);
r.Add("jump loot: a move sent on a no-bend-down call and refused 'too busy' turns the call off: the next fast jump answer waits its Return", BusyRefusalTurnsNoMotionOff);
r.Add("jump loot: an open sent on a no-bend-down call and refused 'too busy' turns the call off too", BusyOpenTurnsNoMotionOff);
r.Add("jump loot: dropping the corpse claim (macro off) ends the no-bend-down window", ResetEndsAirWindow);
r.Add("jump loot: a pickup sent while still in the air from the last loot jump takes no second jump; after the landing the next one jumps", NoSecondJumpInTheAir);
r.Add("jump loot: the pickup's jump puts combat and buffs on hold until the landing (or the cap); loot never", JumpHoldsCombatNotLoot);
r.Add("jump loot: portal space and a death drop the combat hold (no landing is coming)", PortalAndDeathEndJumpHold);
r.Add("jump loot cadence: one move in flight at a time (the client's one inventory request), the next sent on the tick the answer shows", OneInFlightNextOnAnswerTick);
}
private static long _now;
private static void Clocked(Action body)
{
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; UseAudit.NowMs = oldUse; ActionPacer.ForgetLootJump(); }
}
private static RynthAiPlugin _bot = null!; // the bot LootUntilFirstMove made
private static RynthCoreHost _host; // and its host
private static T Field<T>(string name) => (T)typeof(RynthAiPlugin).GetField(name, Any)!.GetValue(_bot)!;
private static void SetField(string name, object v) => typeof(RynthAiPlugin).GetField(name, Any)!.SetValue(_bot, v);
/// <summary>The character's height: up in the air, or back on the ground (ActionPacer's landing check reads it).</summary>
private static void Air(bool up) => FakeHost.PlayerPose = (Me0.Cell, Me0.X, Me0.Y, up ? Me0.Z + 1.0f : Me0.Z);
private static void Gem(uint id, uint container = CorpseA)
{
FakeHost.Names[id] = "Black Opal";
FakeHost.ItemTypes[id] = ItemTypeGem;
FakeHost.Containers[id] = container;
FakeHost.Appraised.Add(id);
}
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 World(bool secondGem, bool secondCorpse, bool serverGates, bool thirdGem = false, bool packStack = false)
{
FakeHost.Reset();
FakeHost.SalvageCalls = true; // UseObject + MoveItemExternal
FakeHost.WeaponCalls = true; // RequestId, HasAppraisalData
FakeHost.CloseContainerCalls = true; // CloseContainer + GetGroundContainerId
FakeHost.TapJumpCalls = true;
FakeHost.ServerGates = serverGates; // GetCastBusyState: the client's motion queue
FakeHost.LastUseDoneCalls = serverGates; // GetLastUseDone: the open's answer
FakeHost.WeenieErrorCalls = true; // GetLastWeenieError: "You're too busy"
FakeHost.Names[Player] = Me;
FakeHost.Positions[Player] = Me0;
FakeHost.PlayerPose = Me0;
Corpse(CorpseA, 1.0f);
Gem(GemA);
if (secondGem) Gem(GemA2);
if (thirdGem) Gem(GemA3);
if (secondCorpse)
{
Corpse(CorpseB, 1.5f);
Gem(GemB, CorpseB);
}
if (packStack)
{
// GemA is a stack of 1, and the pack holds a same-name stack of 3 it can merge into.
FakeHost.Ints[(GemA, KeyMaxStack)] = 100;
FakeHost.Ints[(GemA, KeyStack)] = 1;
Gem(PackStack, Player);
FakeHost.Ints[(PackStack, KeyMaxStack)] = 100;
FakeHost.Ints[(PackStack, KeyStack)] = 3;
}
}
/// <summary>Opens the corpse and ticks until the first pickup's move has gone out. Returns the tick.</summary>
private static Action LootUntilFirstMove(bool jumpEnabled, bool secondGem, uint stamina, bool secondCorpse = false, bool serverGates = false, bool thirdGem = false, bool packStack = false)
{
World(secondGem, secondCorpse, serverGates, thirdGem, packStack);
var host = FakeHost.Create(Player);
_host = host;
var bot = new RynthAiPlugin();
_bot = bot;
var s = new LegacyUiSettings
{
IsMacroRunning = true, EnableLooting = true, EnableCombat = false, LootOwnership = 0,
LootContentSettleMs = 0, LootEmptyCorpseMs = 0, StopLootingWhenPackFull = false,
LootJumpEnabled = jumpEnabled,
};
typeof(RynthPluginBase).GetMethod("Attach", Any)!.Invoke(bot, new object[] { FakeHost.LastApi });
var dash = (LegacyDashboardRenderer)RuntimeHelpers.GetUninitializedObject(typeof(LegacyDashboardRenderer));
typeof(LegacyDashboardRenderer).GetField("_profileLoaded", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic)!.SetValue(dash, true); // a stand-in with its profile in memory
typeof(LegacyDashboardRenderer).GetField("_settings", Any)!.SetValue(dash, s);
void Set(string f, object? v) => typeof(RynthAiPlugin).GetField(f, Any)!.SetValue(bot, v);
Set("_dashboard", dash);
var cache = new WorldObjectCache(host);
cache.SetPlayerId(Player);
Set("_objectCache", cache);
Set("_playerId", Player);
Set("_vitals", new PlayerVitalsCache { MaxHealth = 100, CurrentHealth = 100, MaxStamina = 100, CurrentStamina = stamina, MaxMana = 100, CurrentMana = 100 });
string profile = Path.Combine(Program.TempRoot, "loot-jump-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;
void Tick()
{
Set("_activity", BotActivity.Looting);
typeof(RynthAiPlugin).GetMethod("TickCorpseOpening", Any)!.Invoke(bot, null);
}
var ids = new List<uint> { CorpseA, GemA };
if (secondGem) ids.Add(GemA2);
if (thirdGem) ids.Add(GemA3);
if (packStack) ids.Add(PackStack);
if (secondCorpse) { ids.Add(CorpseB); ids.Add(GemB); }
foreach (uint id in ids) cache.OnCreateObject(id);
for (int i = 0; i < 50; i++) cache.Tick();
Tick();
Check.True(FakeHost.Uses.Contains(CorpseA), "the corpse is opened");
FakeHost.UseDone(0);
FakeHost.GroundContainer = CorpseA;
bot.OnViewObjectContents(CorpseA);
_openedAt = _now;
for (int i = 0; i < 200 && FakeHost.ExternalMoves.Count == 0; i++) { _now += 20; Tick(); }
Check.True(FakeHost.ExternalMoves.Count > 0, "a gem's move is sent");
return Tick;
}
private const long TickMs = 20;
private static long _openedAt; // CorpseA's contents arrived (LootUntilFirstMove)
/// <summary>
/// The latest tick the next corpse's open may go out after the last item's confirm at
/// <paramref name="confirmed"/>: at once, except that a corpse emptied sooner than the
/// Loot Empty Corpse floor (max(200 ms, LootEmptyCorpseMs) from its open, a user setting, not
/// a landing wait) is completed only then; a tick or two of slack.
/// </summary>
private static long NextOpenDue(long confirmed) => Math.Max(confirmed, _openedAt + 200) + 3 * TickMs;
private static bool Confirmed(uint id) => FakeHost.Logs.Any(l => l.Contains($"pickup confirmed for 0x{id:X8}"));
/// <summary>Ticks (TickMs each) until <paramref name="done"/> or <paramref name="maxMs"/> has passed.</summary>
private static void TickUntil(Action tick, Func<bool> done, long maxMs)
{
long end = _now + maxMs;
while (_now < end && !done()) { _now += TickMs; tick(); }
}
private static void TickFor(Action tick, long ms)
{
long end = _now + ms;
while (_now < end) { _now += TickMs; tick(); }
}
// ACE with allow_jump_loot (Player_Inventory.GetPickupMotion): the move reaches the server while
// the character is in the air, the pickup motion is Invalid, so the item moves at once (about the
// round trip) and EnqueuePickupDone has no Return to play (IsBusy clears at once). What the
// client's motion queue (GetCastBusyState) reads in the air is not known, so both readings are
// run: busy (the jump's own motion for the whole flight) and idle.
private static void NoReturnNextCorpseInAir() => Clocked(() =>
{
foreach (int airQueue in new[] { 1, 0 })
{
var tick = LootUntilFirstMove(jumpEnabled: true, secondGem: false, stamina: 100u, secondCorpse: true, serverGates: true);
Check.Eq(FakeHost.ExternalMoves[0].Id, GemA, $"[air queue {airQueue}] corpse A's gem goes first");
long sent = _now;
FakeHost.CastBusy = airQueue;
TickFor(tick, 100);
FakeHost.Containers[GemA] = Player; // the answer, no bend-down
TickUntil(tick, () => Confirmed(GemA), 1000);
Check.True(Confirmed(GemA), $"[air queue {airQueue}] the pickup is confirmed");
long confirmed = _now;
TickUntil(tick, () => FakeHost.Uses.Contains(CorpseB), 1500);
Check.True(FakeHost.Uses.Contains(CorpseB), $"[air queue {airQueue}] the next corpse is opened");
Check.True(_now <= NextOpenDue(confirmed),
$"[air queue {airQueue}] the next corpse is opened at the confirm, not after a landing / Return wait: {_now - confirmed} ms after the confirm, {_now - sent} ms after the send");
}
});
// The second item goes out at once, still in the air, with no second jump (an air jump costs
// stamina on ACE and does nothing for the pickup); once the character has landed, the next one
// jumps again.
private static void NoReturnNextItemJumps() => Clocked(() =>
{
var tick = LootUntilFirstMove(jumpEnabled: true, secondGem: true, stamina: 100u, serverGates: true, thirdGem: true);
uint first = FakeHost.ExternalMoves[0].Id;
Check.Eq(FakeHost.TapJumps, 1, "the first pickup jumps");
Air(up: true);
FakeHost.CastBusy = 1; // the jump's motion plays
TickFor(tick, 100);
FakeHost.Containers[first] = Player; // the answer, no bend-down
TickUntil(tick, () => Confirmed(first), 1000);
Check.True(Confirmed(first), "the first pickup is confirmed");
long confirmed = _now;
TickUntil(tick, () => FakeHost.ExternalMoves.Count >= 2, 1500);
Check.Eq(FakeHost.ExternalMoves.Count, 2, "the second move is sent");
uint second = FakeHost.ExternalMoves[1].Id;
Check.True(_now - confirmed <= 3 * TickMs, $"at the confirm, not after the landing: {_now - confirmed} ms");
Check.Eq(FakeHost.TapJumps, 1, "no jump in the air: " + Order());
Check.False(FakeHost.Logs.Any(l => l.Contains("queuing 0x")), "not queued behind a Return that ACE never plays for it");
// The second, sent in the air, answered with no bend-down; the character has landed by now.
Air(up: false);
TickFor(tick, ActionPacer.JumpLandMinMs);
FakeHost.Containers[second] = Player;
TickUntil(tick, () => FakeHost.ExternalMoves.Count >= 3, 1500);
Check.Eq(FakeHost.ExternalMoves.Count, 3, "the third move is sent");
int at = FakeHost.Order.IndexOf($"move:{FakeHost.ExternalMoves[2].Id:X8}");
Check.True(at > 0 && FakeHost.Order[at - 1] == "tapjump", "landed: the third jumps again: " + Order());
Check.Eq(FakeHost.TapJumps, 2, "two jumps in all");
});
// The jump went out, but the answer took a bend-down's time (the server turned the character
// first and it landed, so ACE played the pickup motion and its Return): that Return is waited out.
private static void SlowAnswerKeepsReturnWait() => Clocked(() =>
{
var tick = LootUntilFirstMove(jumpEnabled: true, secondGem: false, stamina: 100u, secondCorpse: true, serverGates: true);
FakeHost.CastBusy = 1;
TickFor(tick, 800);
FakeHost.Containers[GemA] = Player; // answered after the bend-down; the Return plays
TickUntil(tick, () => Confirmed(GemA), 1000);
Check.True(Confirmed(GemA), "the pickup is confirmed");
TickFor(tick, 600);
Check.False(FakeHost.Uses.Contains(CorpseB), "no next open while the Return plays");
FakeHost.CastBusy = 0;
TickUntil(tick, () => FakeHost.Uses.Contains(CorpseB), 1000);
Check.True(FakeHost.Uses.Contains(CorpseB), "the next corpse is opened once the character stands still");
});
// First pickup in the air with no bend-down; the second, sent at once, is answered only after a
// bend-down (the character had landed), so its Return plays: the third is queued behind that
// Return (ACE NextPickup) and gets no jump, which would disturb the queue - the first jump's
// flight window no longer counts.
private static void SlowAnswerEndsAirWindow() => Clocked(() =>
{
var tick = LootUntilFirstMove(jumpEnabled: true, secondGem: true, stamina: 100u, serverGates: true, thirdGem: true);
uint first = FakeHost.ExternalMoves[0].Id;
FakeHost.CastBusy = 1;
TickFor(tick, 100);
FakeHost.Containers[first] = Player; // no bend-down
TickUntil(tick, () => FakeHost.ExternalMoves.Count >= 2, 1000);
Check.Eq(FakeHost.ExternalMoves.Count, 2, "the second move goes out at the first's confirm");
uint second = FakeHost.ExternalMoves[1].Id;
long secondSent = _now;
TickFor(tick, 700);
FakeHost.Containers[second] = Player; // answered after a bend-down: its Return plays
TickUntil(tick, () => Confirmed(second), 1000);
Check.True(Confirmed(second), "the second pickup is confirmed");
Check.True(_now - secondSent < 1500 - 100, $"(still inside the first jump's flight window: {_now - secondSent} ms after the second send)");
TickUntil(tick, () => FakeHost.ExternalMoves.Count >= 3, 300);
Check.Eq(FakeHost.ExternalMoves.Count, 3, "the third move goes out during the Return");
uint third = FakeHost.ExternalMoves[2].Id;
int at = FakeHost.Order.IndexOf($"move:{third:X8}");
Check.True(at > 0 && FakeHost.Order[at - 1] != "tapjump", "with no jump into the Return: " + Order());
Check.True(FakeHost.Logs.Any(l => l.Contains($"queuing 0x{third:X8}")), "queued behind the second's Return");
});
// -- The PickupAnswerMinMs floor --
// The floor is ACE's pickup motion time. A jump send has no motion: its server-only answer
// (the item in a pack, a pack stack grown, the object gone from the client) is believed on
// arrival. Every other send, and a jump send's weak sign (an unowned stack the client still has),
// keep the floor.
private const long AnswerAtMs = 150;
/// <summary>The ms from <paramref name="sent"/> to the tick the pickup of <paramref name="id"/> is confirmed (-1: never, in 1.5 s).</summary>
private static long ConfirmAfter(Action tick, uint id, long sent)
{
TickUntil(tick, () => Confirmed(id), 1500);
return Confirmed(id) ? _now - sent : -1;
}
private static void JumpAnswerConfirmedOnArrival() => Clocked(() =>
{
var tick = LootUntilFirstMove(jumpEnabled: true, secondGem: false, stamina: 100u, secondCorpse: true, serverGates: true);
long sent = _now;
TickFor(tick, AnswerAtMs - TickMs);
FakeHost.Containers[GemA] = Player; // ACE's answer, no bend-down
long confirmedAfter = ConfirmAfter(tick, GemA, sent);
Check.True(confirmedAfter >= 0 && confirmedAfter <= AnswerAtMs + TickMs,
$"confirmed on the tick the answer shows ({AnswerAtMs} ms), not at PickupAnswerMinMs: {confirmedAfter} ms after the send");
long confirmed = _now;
TickUntil(tick, () => FakeHost.Uses.Contains(CorpseB), 1000);
Check.True(FakeHost.Uses.Contains(CorpseB) && _now <= NextOpenDue(confirmed),
$"the next corpse is opened then too (or at the empty-corpse floor, 200 ms from the open): {_now - sent} ms after the send, {_now - _openedAt} ms after the open");
Check.True(FakeHost.Logs.Any(l => l.Contains("no bend-down or Return to wait for")), "classed as a pickup with no bend-down");
});
// The no-bend-down window after a pickup is anchored to the JUMP (it ends JumpLandMaxMs after
// it), not to the send that confirmed: a second send that rode the first jump, in the air, must
// not stretch it.
private static void AirWindowAnchoredToTheInAirJump() => Clocked(() =>
{
var tick = LootUntilFirstMove(jumpEnabled: true, secondGem: true, stamina: 100u, serverGates: true);
long jumpAt = _now;
uint first = FakeHost.ExternalMoves[0].Id;
Air(up: true);
TickFor(tick, 100);
FakeHost.Containers[first] = Player; // no bend-down
TickUntil(tick, () => FakeHost.ExternalMoves.Count >= 2, 500);
Check.Eq(FakeHost.ExternalMoves.Count, 2, "the second goes out in the air");
Check.Eq(FakeHost.TapJumps, 1, "riding the first jump");
uint second = FakeHost.ExternalMoves[1].Id;
long secondAt = _now;
TickFor(tick, 100);
FakeHost.Containers[second] = Player; // no bend-down
TickUntil(tick, () => Confirmed(second), 500);
Check.True(Confirmed(second), "the second is confirmed");
Check.True(FakeHost.Logs.Count(l => l.Contains("no bend-down or Return to wait for")) == 2, "both as no-bend-down pickups");
long until = Field<long>("_jumpPickupAirUntil");
Check.True(Math.Abs(until - (jumpAt + ActionPacer.JumpLandMaxMs)) <= TickMs,
$"the window ends JumpLandMaxMs after the jump: {until - jumpAt} ms from it (the second send was {secondAt - jumpAt} ms in)");
});
private static void JumpMergeConfirmedOnArrival() => Clocked(() =>
{
var tick = LootUntilFirstMove(jumpEnabled: true, secondGem: false, stamina: 100u, serverGates: true, packStack: true);
Check.Eq(FakeHost.ExternalMoves[0].Id, GemA, "the corpse gem goes");
long sent = _now;
TickFor(tick, AnswerAtMs - TickMs);
// The object is still in the client, unowned (container 0: the unowned-stack test alone says
// "merged"), and the same-name pack stack has grown. Only the grown stack is positive
// evidence here, so this pins `mergedInto != 0` (and that the grown-stack check runs when
// the unowned-stack test has already matched).
FakeHost.Containers[GemA] = 0;
FakeHost.Ints[(PackStack, KeyStack)] = 4;
long confirmedAfter = ConfirmAfter(tick, GemA, sent);
Check.True(confirmedAfter >= 0 && confirmedAfter <= AnswerAtMs + TickMs,
$"a merge on a jump send is confirmed on the tick it shows ({AnswerAtMs} ms), not at the floor: {confirmedAfter} ms after the send");
Check.True(FakeHost.Logs.Any(l => l.Contains("pickup confirmed") && l.Contains("merged into the stack 0x" + PackStack.ToString("X8"))),
"as a merge into the grown pack stack: " + (FakeHost.Logs.LastOrDefault(l => l.Contains("pickup confirmed")) ?? "(none)"));
Check.True(Field<long>("_lastEarlyMergeConfirmAt") != 0, "noted as a floor-less merge confirm (the slot-refusal log reads it)");
});
// The object gone from the client is the evidence on its own for a STACK (ACE's
// InventoryRemoveObject), with no same-name stack grown.
private static void JumpGoneConfirmedOnArrival() => Clocked(() =>
{
var tick = LootUntilFirstMove(jumpEnabled: true, secondGem: false, stamina: 100u, serverGates: true, packStack: true);
long sent = _now;
TickFor(tick, AnswerAtMs - TickMs);
FakeHost.Containers.Remove(GemA);
FakeHost.Names.Remove(GemA);
FakeHost.Positions.Remove(GemA); // the pack stack stays at 3
long confirmedAfter = ConfirmAfter(tick, GemA, sent);
Check.True(confirmedAfter >= 0 && confirmedAfter <= AnswerAtMs + TickMs,
$"gone from the client is enough on a jump send: confirmed {confirmedAfter} ms after the send");
});
// A single object (not a stack) that vanishes (the corpse decayed, someone else looted it) is no
// merge and no answer: the floor stays.
private static void NonStackVanishKeepsFloor() => Clocked(() =>
{
var tick = LootUntilFirstMove(jumpEnabled: true, secondGem: false, stamina: 100u, serverGates: true);
long sent = _now;
TickFor(tick, AnswerAtMs - TickMs);
FakeHost.Containers.Remove(GemA);
FakeHost.Names.Remove(GemA);
FakeHost.Positions.Remove(GemA);
long confirmedAfter = ConfirmAfter(tick, GemA, sent);
Check.True(confirmedAfter >= RynthAiPlugin.PickupAnswerMinMs,
$"a vanished non-stack keeps the floor ({RynthAiPlugin.PickupAnswerMinMs} ms): confirmed {confirmedAfter} ms after the send");
});
// The same merge on a send with no jump: ACE plays the pickup motion first, so the floor stays.
private static void NoJumpMergeKeepsAnswerFloor() => Clocked(() =>
{
var tick = LootUntilFirstMove(jumpEnabled: false, secondGem: false, stamina: 100u, serverGates: true, packStack: true);
Check.Eq(FakeHost.TapJumps, 0, "no jump went out");
long sent = _now;
TickFor(tick, AnswerAtMs - TickMs);
FakeHost.Containers.Remove(GemA);
FakeHost.Names.Remove(GemA);
FakeHost.Positions.Remove(GemA);
FakeHost.Ints[(PackStack, KeyStack)] = 4;
long confirmedAfter = ConfirmAfter(tick, GemA, sent);
Check.True(confirmedAfter >= RynthAiPlugin.PickupAnswerMinMs,
$"a merge with no jump keeps the floor ({RynthAiPlugin.PickupAnswerMinMs} ms): confirmed {confirmedAfter} ms after the send");
});
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<int>("_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<int>("_currentLootItemMoveAttempts"), 1, "still the first try");
Check.Eq(Field<int>("_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<int>("_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<int>("_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
// <paramref name="ms"/> 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<bool>("_currentLootItemSlotGaveUp"), "not given up");
Check.Eq(Field<int>("_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<bool>("_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<int>("_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<long>("_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<int>("_currentLootItemSlotResends") > 0, "a slot resend was made");
typeof(RynthAiPlugin).GetMethod("ResetCurrentLootItem", Any)!.Invoke(_bot, null);
Check.Eq(Field<int>("_currentLootItemSlotResends"), 0, "resends cleared");
Check.Eq(Field<int>("_currentLootItemSlotSeqAtSend"), 0, "baseline cleared");
Check.Eq(Field<long>("_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<long>("_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<int>("_currentLootItemMoveAttempts"), 1, "not one of the 3 tries");
Check.False(Field<bool>("_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(() =>
{
var tick = LootUntilFirstMove(jumpEnabled: true, secondGem: true, stamina: 100u, serverGates: true);
uint first = FakeHost.ExternalMoves[0].Id;
TickFor(tick, 100 - TickMs);
FakeHost.Containers[first] = Player; // no bend-down: the window opens
TickUntil(tick, () => FakeHost.ExternalMoves.Count >= 2, 1000);
Check.True(Field<long>("_jumpPickupAirUntil") > _now, "the window is open");
uint second = FakeHost.ExternalMoves[1].Id;
Check.True(Field<bool>("_currentLootItemSentInAirWindow"), "the second went out in it");
TickFor(tick, 100);
FakeHost.WeenieError(0, 0x00A0, second); // InventoryServerSaveFailed, no code, 100 ms after the send
TickFor(tick, 3 * TickMs);
Check.False(FakeHost.Logs.Any(l => l.Contains("the server played a bend-down after all")), "no distrust line");
Check.Eq(Field<long>("_jumpNoMotionOffUntil"), 0L, "the call stays on");
});
private static void NoJumpKeepsAnswerFloor() => Clocked(() =>
{
var tick = LootUntilFirstMove(jumpEnabled: false, secondGem: false, stamina: 100u, serverGates: true);
Check.Eq(FakeHost.TapJumps, 0, "no jump went out");
long sent = _now;
TickFor(tick, AnswerAtMs - TickMs);
FakeHost.Containers[GemA] = Player;
long confirmedAfter = ConfirmAfter(tick, GemA, sent);
Check.True(confirmedAfter >= RynthAiPlugin.PickupAnswerMinMs,
$"not believed before PickupAnswerMinMs ({RynthAiPlugin.PickupAnswerMinMs} ms): confirmed {confirmedAfter} ms after the send");
});
// -- What JumpPickupHadNoMotion must not take for a no-bend-down pickup --
/// <summary>
/// After the last item's confirm: the next corpse is not opened while the Return plays
/// (CastBusy 1 for <paramref name="returnMs"/>), and is opened once it ends.
/// </summary>
private static void NextOpenWaitsReturn(Action tick, uint item, long returnMs, string what)
{
TickUntil(tick, () => Confirmed(item), 1500);
Check.True(Confirmed(item), what + ": the pickup is confirmed");
TickFor(tick, returnMs);
Check.False(FakeHost.Uses.Contains(CorpseB), what + ": no next open while the Return plays");
FakeHost.CastBusy = 0;
TickUntil(tick, () => FakeHost.Uses.Contains(CorpseB), 1500);
Check.True(FakeHost.Uses.Contains(CorpseB), what + ": the next corpse is opened once the character stands still");
}
private static void NoJumpFastAnswerWaitsReturn() => Clocked(() =>
{
var tick = LootUntilFirstMove(jumpEnabled: false, secondGem: false, stamina: 100u, secondCorpse: true, serverGates: true);
TickFor(tick, 100 - TickMs);
FakeHost.Containers[GemA] = Player;
FakeHost.CastBusy = 1; // its Return
NextOpenWaitsReturn(tick, GemA, 300, "no jump");
});
private static void ResentFastAnswerWaitsReturn() => Clocked(() =>
{
var tick = LootUntilFirstMove(jumpEnabled: true, secondGem: false, stamina: 100u, secondCorpse: true, serverGates: true);
Check.Eq(FakeHost.TapJumps, 1, "the first send jumps");
TickFor(tick, 40);
FakeHost.WeenieError(0x1D); // YoureTooBusy
FakeHost.WeenieError(0, 0x00A0, GemA); // InventoryServerSaveFailed(item)
TickUntil(tick, () => FakeHost.ExternalMoves.Count >= 2, 1000);
Check.Eq(FakeHost.ExternalMoves.Count, 2, "resent");
Check.Eq(FakeHost.TapJumps, 1, "the resend goes without a jump");
TickFor(tick, 100 - TickMs);
FakeHost.Containers[GemA] = Player;
FakeHost.CastBusy = 1;
NextOpenWaitsReturn(tick, GemA, 300, "resent");
});
// On a fast server a real bend-down can be 0.25-0.4 s, inside PickupAnswerMinMs.
// A move sent on the no-bend-down call and refused 'too busy' proves the call wrong: it is off.
private static void BusyRefusalTurnsNoMotionOff() => Clocked(() =>
{
var tick = LootUntilFirstMove(jumpEnabled: true, secondGem: true, stamina: 100u, secondCorpse: true, serverGates: true, thirdGem: true);
uint first = FakeHost.ExternalMoves[0].Id;
FakeHost.CastBusy = 1; // a fast real bend-down, then its Return
TickFor(tick, 300 - TickMs);
FakeHost.Containers[first] = Player; // answered at 300 ms: taken for no bend-down
TickUntil(tick, () => FakeHost.ExternalMoves.Count >= 2, 1000);
Check.True(FakeHost.Logs.Any(l => l.Contains("no bend-down or Return to wait for")), "the first is (wrongly) called no bend-down");
uint second = FakeHost.ExternalMoves[1].Id;
TickFor(tick, 40);
FakeHost.WeenieError(0x1D); // the Return is playing: too busy
FakeHost.WeenieError(0, 0x00A0, second);
TickFor(tick, 2 * TickMs);
Check.True(FakeHost.Logs.Any(l => l.Contains("the server played a bend-down after all")), "the call is turned off");
Check.Eq(Field<long>("_jumpPickupAirUntil"), 0L, "and the window ended");
TickFor(tick, 400);
FakeHost.CastBusy = 0; // the Return ends: the refused move goes again
TickUntil(tick, () => FakeHost.ExternalMoves.Count >= 3, 1000);
Check.Eq(FakeHost.ExternalMoves[2].Id, second, "the refused move is resent");
TickFor(tick, 150);
FakeHost.Containers[second] = Player;
TickUntil(tick, () => FakeHost.ExternalMoves.Count >= 4, 1500);
Check.Eq(FakeHost.ExternalMoves.Count, 4, "the third goes");
uint third = FakeHost.ExternalMoves[3].Id;
int at = FakeHost.Order.IndexOf($"move:{third:X8}");
Check.True(at > 0 && FakeHost.Order[at - 1] == "tapjump", "with a jump (landed by now): " + Order());
// Answered at 300 ms again: with the call off it waits its Return.
FakeHost.CastBusy = 1;
TickFor(tick, 300 - TickMs);
FakeHost.Containers[third] = Player;
NextOpenWaitsReturn(tick, third, 300, "after the call was turned off");
});
private static void BusyOpenTurnsNoMotionOff() => Clocked(() =>
{
var tick = LootUntilFirstMove(jumpEnabled: true, secondGem: false, stamina: 100u, secondCorpse: true, serverGates: true);
TickFor(tick, 300 - TickMs);
FakeHost.Containers[GemA] = Player; // taken for no bend-down
TickUntil(tick, () => FakeHost.Uses.Contains(CorpseB), 1000);
Check.True(FakeHost.Uses.Contains(CorpseB), "the next corpse is opened on the call");
Check.True(Field<int>("_openInAirWindowSeq") >= 0, "its answer is watched");
FakeHost.UseDone(0x1D); // too busy: the Return was playing
TickFor(tick, 2 * TickMs);
Check.True(FakeHost.Logs.Any(l => l.Contains("the next corpse's open, sent on it, was refused as too busy")), "the call is turned off");
Check.True(Field<long>("_jumpNoMotionOffUntil") > _now, "for a while");
});
// The fastest cadence there is. The acclient holds ONE pending inventory request and refuses
// every other move until the server's answer about that object ("You can only move or use one
// item at a time", RynthCore ClientActionGates), and on a FastTick character ACE cancels a pickup
// whose turn is still pending when the next one arrives (Player_Move2.CreateMoveToChain2 ->
// CheckMoveToParams -> ActionCancelled). So never two at once: the next goes on the very tick
// the last one's answer shows, with no tick lost in between.
private static void OneInFlightNextOnAnswerTick() => Clocked(() =>
{
var tick = LootUntilFirstMove(jumpEnabled: true, secondGem: true, stamina: 100u, serverGates: true, thirdGem: true);
Air(up: true);
var answered = new HashSet<uint>();
int maxInFlight = 1;
for (int k = 0; k < 3; k++)
{
Check.Eq(FakeHost.ExternalMoves.Count, k + 1, $"move {k + 1} is out");
uint id = FakeHost.ExternalMoves[k].Id;
for (int i = 0; i < 4; i++)
{
_now += TickMs; tick();
maxInFlight = Math.Max(maxInFlight, FakeHost.ExternalMoves.Count - answered.Count);
}
Check.Eq(FakeHost.ExternalMoves.Count, k + 1, $"nothing more while move {k + 1} is unanswered");
FakeHost.Containers[id] = Player; // the answer arrives
answered.Add(id);
_now += TickMs; tick(); // the one tick that sees it
Check.True(Confirmed(id), $"move {k + 1} confirmed on the tick its answer shows");
if (k < 2)
Check.Eq(FakeHost.ExternalMoves.Count, k + 2, $"and move {k + 2} goes on that same tick");
}
Check.Eq(maxInFlight, 1, "never two moves in flight");
});
// Dropping the corpse claim ends the no-bend-down window and the open watch.
private static void ResetEndsAirWindow() => Clocked(() =>
{
LootUntilFirstMove(jumpEnabled: true, secondGem: false, stamina: 100u, serverGates: true);
SetField("_jumpPickupAirUntil", _now + 1000);
SetField("_openInAirWindowSeq", 3);
typeof(RynthAiPlugin).GetMethod("ResetCorpseTarget", Any)!.Invoke(_bot, null);
Check.Eq(Field<long>("_jumpPickupAirUntil"), 0L, "the window is gone");
Check.Eq(Field<int>("_openInAirWindowSeq"), -1, "and the open watch");
});
// A pickup sent while the character is still in the air from the last loot jump takes no second
// jump: the move arrives in the air anyway, and ACE HandleActionJump has no ground check, so an
// air jump only costs stamina. Once the character has landed, the next pickup jumps again.
private static void NoSecondJumpInTheAir() => Clocked(() =>
{
var tick = LootUntilFirstMove(jumpEnabled: true, secondGem: true, stamina: 100u, serverGates: true, thirdGem: true);
long jumpAt = _now;
uint first = FakeHost.ExternalMoves[0].Id;
Check.Eq(FakeHost.TapJumps, 1, "the first pickup jumps");
Air(up: true); // and stays up: no landing is seen
TickFor(tick, 100);
FakeHost.Containers[first] = Player; // the answer
TickUntil(tick, () => FakeHost.ExternalMoves.Count >= 2, ActionPacer.JumpLandMaxMs);
Check.Eq(FakeHost.ExternalMoves.Count, 2, "the second move is sent");
Check.True(_now - jumpAt < ActionPacer.JumpLandMaxMs, $"(inside the first jump's flight: {_now - jumpAt} ms after it)");
Check.True(ActionPacer.LootJumpAirborne(_host, out _), "(still in the air at the second send)");
Check.Eq(FakeHost.TapJumps, 1, "no second jump in the air: " + Order());
uint second = FakeHost.ExternalMoves[1].Id;
Air(up: false); // landed
TickFor(tick, ActionPacer.JumpLandMinMs); // the landing check looks from JumpLandMinMs on
FakeHost.Containers[second] = Player;
TickUntil(tick, () => FakeHost.ExternalMoves.Count >= 3, 3000);
Check.Eq(FakeHost.ExternalMoves.Count, 3, "the third move is sent");
int at = FakeHost.Order.IndexOf($"move:{FakeHost.ExternalMoves[2].Id:X8}");
Check.True(at > 0 && FakeHost.Order[at - 1] == "tapjump", "landed: the third jumps again: " + Order());
Check.Eq(FakeHost.TapJumps, 2, "two jumps in all");
});
// The loot half: the pickup's jump is what holds combat and buffs (ActionPacer); loot is not held.
// CombatHookTests has the combat half (Think sends no attack while it holds).
private static void JumpHoldsCombatNotLoot() => Clocked(() =>
{
bool pacer = ActionPacer.Enabled;
try
{
LootUntilFirstMove(jumpEnabled: true, secondGem: false, stamina: 100u, serverGates: true);
Check.Eq(FakeHost.TapJumps, 1, "the pickup jumped");
Check.True(ActionPacer.LootJumpAirborne(_host, out _), "and the loot code noted the jump for combat and buffs");
// The pacer from here on, on this clock, with nothing of other tests' left in it
// (CorpseCloseTests.PacerOn): only the jump can hold anything.
ActionPacer.Reset(); ActionPacer.Enabled = true;
MoveAudit.Reset(); MoveAudit.NowMs = () => _now;
UseAudit.NowMs = () => _now;
ActionPacer.NoteLootJump(_host); // (Reset dropped the pickup's; the same jump, noted again)
var host = _host;
Air(up: true);
Check.True(ActionPacer.LootJumpAirborne(host, out string why), "in the air after the pickup's jump: " + why);
Check.False(ActionPacer.MayStart(host, "Buff", HealNeed.None, out _), "a buff or heal waits");
Check.False(ActionPacer.MayStart(host, "Buff", HealNeed.Emergency, out _), "an emergency heal too (ACE refuses it in the air)");
Check.True(ActionPacer.MayStart(host, "Loot", HealNeed.None, out _), "loot does not");
_now += ActionPacer.JumpLandMinMs;
Check.True(ActionPacer.LootJumpAirborne(host, out _), "still up at the height check");
Air(up: false);
Check.False(ActionPacer.LootJumpAirborne(host, out _), "landed: the hold ends");
Check.True(ActionPacer.MayStart(host, "Buff", HealNeed.None, out _), "the buff goes");
// The cap: a landing never seen still ends the hold at JumpLandMaxMs.
ActionPacer.NoteLootJump(host);
Air(up: true);
_now += ActionPacer.JumpLandMaxMs - 1;
Check.True(ActionPacer.LootJumpAirborne(host, out _), "up, under the cap");
_now += 1;
Check.False(ActionPacer.LootJumpAirborne(host, out _), "the cap ends it");
}
finally
{
ActionPacer.Enabled = pacer; ActionPacer.Reset();
MoveAudit.Reset(); MoveAudit.NowMs = () => Environment.TickCount64;
UseAudit.NowMs = () => Environment.TickCount64;
}
});
// The plugin's portal-space and death paths drop the hold: no landing is coming to end it.
private static void PortalAndDeathEndJumpHold() => Clocked(() =>
{
var oldVitals = FakeHost.Vitals;
try
{
LootUntilFirstMove(jumpEnabled: true, secondGem: false, stamina: 100u, serverGates: true);
var host = _host;
const System.Reflection.BindingFlags Inst = System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic;
Air(up: true);
Check.True(ActionPacer.LootJumpAirborne(host, out _), "the pickup's jump holds combat");
FakeHost.Portaling = true;
typeof(RynthAiPlugin).GetMethod("NotePortalForPacer", Inst)!.Invoke(_bot, null);
Check.False(ActionPacer.LootJumpAirborne(host, out _), "portal space ends the hold");
FakeHost.Portaling = false;
typeof(RynthAiPlugin).GetMethod("NotePortalForPacer", Inst)!.Invoke(_bot, null);
ActionPacer.NoteLootJump(host);
Check.True(ActionPacer.LootJumpAirborne(host, out _), "a second jump holds again");
FakeHost.Vitals = (0, 100, 0, 100, 0, 100);
typeof(RynthAiPlugin).GetMethod("HoldForDeath", Inst)!.Invoke(_bot, null);
Check.False(ActionPacer.LootJumpAirborne(host, out _), "the death ends the hold");
}
finally { FakeHost.Vitals = oldVitals; FakeHost.Portaling = false; Air(up: false); }
});
private static void JumpWeakSignKeepsAnswerFloor() => Clocked(() =>
{
var tick = LootUntilFirstMove(jumpEnabled: true, secondGem: false, stamina: 100u, serverGates: true, packStack: true);
Check.Eq(FakeHost.TapJumps, 1, "the jump went out");
long sent = _now;
TickFor(tick, AnswerAtMs - TickMs);
FakeHost.Containers[GemA] = 0; // an unowned stack; the pack stack has not grown
long confirmedAfter = ConfirmAfter(tick, GemA, sent);
Check.True(confirmedAfter >= RynthAiPlugin.PickupAnswerMinMs,
$"a weak sign keeps the floor ({RynthAiPlugin.PickupAnswerMinMs} ms): confirmed {confirmedAfter} ms after the send");
});
private static string Order() => string.Join(",", FakeHost.Order);
private static void TwoItemJumpsBeforeMove() => Clocked(() =>
{
LootUntilFirstMove(jumpEnabled: true, secondGem: true, stamina: 100u);
Check.Eq(FakeHost.Order.FirstOrDefault() ?? "", "tapjump", "the keyboard jump goes first: " + Order());
Check.True(FakeHost.Order.Count >= 2 && FakeHost.Order[1].StartsWith("move:", StringComparison.Ordinal), "then the move: " + Order());
Check.Eq(FakeHost.Jumps, 0, "never JumpNonAutonomous (0xF7C9, no handler on ACE)");
});
private static void SingleItemJumps() => Clocked(() =>
{
LootUntilFirstMove(jumpEnabled: true, secondGem: false, stamina: 100u);
Check.Eq(FakeHost.Order.FirstOrDefault() ?? "", "tapjump", "single item: the jump goes first: " + Order());
Check.True(FakeHost.Order.Count >= 2 && FakeHost.Order[1].StartsWith("move:", StringComparison.Ordinal), "single item: then the move: " + Order());
Check.Eq(FakeHost.TapJumps, 1, "single item: exactly one tap jump");
Check.Eq(FakeHost.Jumps, 0, "single item: never JumpNonAutonomous");
});
private static void SettingOffNoJump() => Clocked(() =>
{
LootUntilFirstMove(jumpEnabled: false, secondGem: true, stamina: 100u);
Check.Eq(FakeHost.TapJumps + FakeHost.Jumps, 0, "jump-loot off: no jump: " + Order());
});
private static void LowStaminaNoJump() => Clocked(() =>
{
LootUntilFirstMove(jumpEnabled: true, secondGem: true, stamina: 5u);
Check.Eq(FakeHost.TapJumps + FakeHost.Jumps, 0, "stamina 5: no jump: " + Order());
});
}