diff --git a/Plugins/RynthCore.Plugin.RynthAi/CorpseOpenController.cs b/Plugins/RynthCore.Plugin.RynthAi/CorpseOpenController.cs index 8f6117e..5a0b4ae 100644 --- a/Plugins/RynthCore.Plugin.RynthAi/CorpseOpenController.cs +++ b/Plugins/RynthCore.Plugin.RynthAi/CorpseOpenController.cs @@ -156,6 +156,8 @@ public sealed partial class RynthAiPlugin private bool _currentLootItemSawAnim; private bool _currentLootItemStackable; // a stack at send: it may merge into a pack stack and vanish private bool _currentLootItemPipelined; // sent while the last pickup's Return played (ACE queues it) + private bool _currentLootItemJumped; // jump-loot: sent in the air, its own jump or the last one's (not a resend) + private bool _currentLootItemSentInAirWindow; // sent on the strength of the last no-bend-down pickup (JumpPickupInAir) private int _currentLootItemErrSeqAtSend; // TryGetLastWeenieError seq at the send (0 = unknown) private int _currentLootItemFreeRetries; // resends after a too-busy answer (not counted as attempts) // 2026-10-29 (R-20261029-122319-321f): what the server said to the last send, and what the @@ -194,6 +196,16 @@ public sealed partial class RynthAiPlugin private bool _settlingSawAnim; private bool _settlingAllowsPipeline; private int _pipelinedAfterItemId; // the answered pickup a move was already queued behind + // A jump-loot pickup answered with no bend-down (JumpPickupHadNoMotion): until this CorpseNowMs + // the client's motion queue is the jump's own (take-off, fall, landing), not a server pickup. + private long _jumpPickupAirUntil; + // The no-bend-down call is off until this CorpseNowMs (DistrustJumpNoMotion): the server turned a + // move or open away as too busy that went out on it, so it had played a bend-down after all. + private long _jumpNoMotionOffUntil; + // The UseDone count before a corpse open sent inside the no-bend-down window (-1: none watched). + private int _openInAirWindowSeq = -1; + /// How long the no-bend-down call stays off after the server proved it wrong. + internal const long JumpNoMotionDistrustMs = 5 * 60_000; // [LootEval] lines: one per item per open (a matched item was re-printed before every pickup). private readonly Dictionary _lootEvalLogged = new(); private int _manaStoneCapLoggedFor; // container the "ManaStone count for cap check" line was logged for @@ -1832,9 +1844,11 @@ public sealed partial class RynthAiPlugin // The character still animates. Right after a pickup's answer that is its "Return" // (standing up): ACE queues a move that arrives then and runs it the moment the // Return ends (Player.HandleActionPutItemInContainer_Verify, NextPickup), so the next - // move goes out now - one, never two. Any other animation: wait until it ends. + // move goes out now - one, never two. Any other animation: wait until it ends. Not the + // jump's own motion after a jump-loot pickup the server answered with no bend-down: ACE + // has nothing to play then (no Return, not busy) and takes a pickup in the air. bool pipelined = false; - if (PickupAnimating(now)) + if (PickupAnimating(now) && !JumpPickupInAir(now)) { if (!CanPipelinePickup(now)) return; @@ -1921,6 +1935,8 @@ public sealed partial class RynthAiPlugin // slot still held, or "You're too busy") must not cost the item one of its 3 tries. _currentLootItemMoveAttempts = pipelined ? 0 : 1; _currentLootItemPipelined = pipelined; + _currentLootItemJumped = jumped || stillInAir; + _currentLootItemSentInAirWindow = JumpPickupInAir(now); _currentLootItemStackable = stackable; _currentLootItemErrSeqAtSend = errSeqAtSend; NoteLootMoveSent(); @@ -1992,6 +2008,8 @@ public sealed partial class RynthAiPlugin /// /// An answer sooner than this after the send isn't believed: ACE plays the whole pickup /// motion (about 0.75 s standing, longer in a combat stance) before it moves the item. + /// Not for a jump-loot send's server-only answer (TickPendingCorpsePickup): with no motion it + /// comes in about the round trip. /// internal const long PickupAnswerMinMs = 500; @@ -2234,6 +2252,35 @@ public sealed partial class RynthAiPlugin _currentLootItemRefusalBusy = !IsQuestPickupRefusal(err) && (err == WeenieErrorYoureTooBusy || after < PickupAnswerMinMs); if (!_currentLootItemRefusalBusy && !_currentLootItemTimedOut) NotePickupAnswerLatency(after); + if (_currentLootItemSentInAirWindow && RefusedAsTooBusy(err)) + DistrustJumpNoMotion(now, $"0x{(uint)_currentLootItemId:X8}, sent on it, was refused as too busy {after} ms after the send"); + } + + /// + /// The refusal of the current send was ACE's "too busy", not another one (a full pack, a quest + /// item) that only came fast. ACE sends YoureTooBusy (0x1D) and then InventoryServerSaveFailed + /// with no code (Player_Inventory HandleActionPutItemInContainer_Verify); the engine keeps only + /// the last refusal but counts each, so the 0x1D is either the last code or the first of two + /// refusals since the send. A full pack sends one save-failed (its text is a transient string). + /// + private bool RefusedAsTooBusy(uint err) => + err == WeenieErrorYoureTooBusy + || (err == 0 && LastWeenieErrorSeq() - _currentLootItemErrSeqAtSend >= 2); + + /// + /// The server turned away as too busy a move or open that went out on a no-bend-down call: the + /// last pickup had a bend-down and a Return after all (a fast one: on a fast server it can be + /// 0.25-0.4 s, inside PickupAnswerMinMs). The call is wrong here: the window ends and + /// JumpPickupHadNoMotion says no for JumpNoMotionDistrustMs, so every pickup waits its Return. + /// + private void DistrustJumpNoMotion(long now, string why) + { + _jumpPickupAirUntil = 0; + _openInAirWindowSeq = -1; + bool was = now < _jumpNoMotionOffUntil; + _jumpNoMotionOffUntil = now + JumpNoMotionDistrustMs; + if (!was) + LootDiag($"[RynthAi] {LootTag}: jump-loot: {why}; the server played a bend-down after all - every pickup waits its Return for {JumpNoMotionDistrustMs / 60_000} min."); } /// @@ -2560,7 +2607,11 @@ public sealed partial class RynthAiPlugin && (currentItem == null || ObjectGoneFromClient(_currentLootItemId) || (currentContainer == 0 && _currentLootItemStackable) || MergedIntoInventoryStack(out mergedInto)); bool landed = inPack || mergedAway; - bool believable = now - _currentLootItemMoveRequestedAt >= PickupAnswerMinMs; + // The floor is ACE's motion time; a jump send skips it only for the item seen in a pack, + // the server's answer about that object, which also frees the client's one request slot + // (a merged-away object can leave the slot held, so a merge keeps the floor). + bool jumpAnswer = _currentLootItemJumped && inPack; + bool believable = jumpAnswer || now - _currentLootItemMoveRequestedAt >= PickupAnswerMinMs; long since = now - _currentLootItemLeftAt; bool answered = landed && believable; if (!answered && since < PickupArriveMaxMs) @@ -2757,6 +2808,8 @@ public sealed partial class RynthAiPlugin _currentLootItemFightHeld = false; _currentLootItemErrSeqAtSend = errSeqAtSend; _currentLootItemMoveRequestedAt = now; + _currentLootItemJumped = false; // a resend goes without a jump + _currentLootItemSentInAirWindow = false; if (retried) NoteLootMoveSent(); _currentLootItemStillSince = 0; _currentLootItemSawAnim = false; @@ -2881,8 +2934,11 @@ public sealed partial class RynthAiPlugin if (answered) _currentLootItemDestsTried.Clear(); // landed: nothing to watch for (ResetCurrentLootItem) _processedCorpseItems.Add(_currentLootItemId); _corpseItemsLooted++; + bool noMotion = answered && JumpPickupHadNoMotion(); + long jumpSentAt = _currentLootItemMoveRequestedAt; LootDiag($"[RynthAi] {LootTag}: pickup confirmed for 0x{(uint)_currentLootItemId:X8}; {reason}" + - $" ({now - _currentLootItemMoveRequestedAt} ms after the send{(_currentLootItemPipelined ? ", queued" : "")})."); + $" ({now - _currentLootItemMoveRequestedAt} ms after the send{(_currentLootItemPipelined ? ", queued" : "")}" + + $"{(noMotion ? $", jump-loot: off the corpse {_currentLootItemLeftAt - _currentLootItemMoveRequestedAt} ms after the send, no bend-down or Return to wait for" : "")})."); // Each item taken is progress, so the corpse/chest timeout counts from the last pickup: // a chest gets its 2 minutes per pickup, and a corpse with many keeps is no longer // closed part way through by the 12 s timeout (SK, 2026-10-11). Not while a hold @@ -2907,15 +2963,60 @@ public sealed partial class RynthAiPlugin ResetCurrentLootItem(); _lastLootActionAt = now; - // Its Return now plays: the close waits for it, and one move may be queued behind it. + _pickupAnimSince = 0; // the next pickup's animation gets its own PickupAnimMaxMs + if (noMotion) + { + // Jump-loot, answered with no bend-down: ACE played no pickup motion, so EnqueuePickupDone + // has no Return to play and the server is no longer busy. Nothing to settle: the corpse + // can close and the next pickup or open can go now, in the air. What the server refuses + // in the air (a cast, an attack) waits on its own gates, not here. + _settlingLootItemId = 0; + _settlingContainerId = 0; + _settlingAllowsPipeline = false; + // The flight ends JumpLandMaxMs after the JUMP, not after this send: a send that rode an + // earlier jump (the in-air path) is later than its jump. Looked up as an + // age so the pacer's clock and the loot clock need not agree; -1 (no jump noted: it has + // landed, or the pacer was reset) falls back to the send time. + long flightAge = ActionPacer.LootJumpAgeMs(); + _jumpPickupAirUntil = flightAge >= 0 + ? now + (ActionPacer.JumpLandMaxMs - flightAge) + : jumpSentAt + ActionPacer.JumpLandMaxMs; + return; + } + + // Its Return now plays: the close waits for it, and one move may be queued behind it. A + // busy motion queue is that Return now, not an earlier jump's flight. + _jumpPickupAirUntil = 0; _settlingLootItemId = itemId; _settlingContainerId = _openedContainerId; _settlingSince = now; _settlingSawAnim = false; _settlingAllowsPipeline = answered; - _pickupAnimSince = 0; // the next pickup's animation gets its own PickupAnimMaxMs } + /// + /// The current pickup was a jump-loot pickup the server ran with no bend-down: its jump went + /// out with this very send (not a resend), and the item was off the corpse sooner than + /// PickupAnswerMinMs after it - quicker than ACE's pickup motion, so ACE skipped it (with the + /// character in the air, Player_Inventory.GetPickupMotion returns Invalid under allow_jump_loot). + /// A jump pickup answered later (the server turned the character first and it had landed, or + /// allow_jump_loot is off) had a bend-down and gets its Return waited out as before. Measured + /// from the tick the item was first seen off the corpse, not from the confirm, which for a + /// jump send can come at once or wait out PickupAnswerMinMs (TickPendingCorpsePickup). + /// + private bool JumpPickupHadNoMotion() => + _currentLootItemJumped + && CorpseNowMs >= _jumpNoMotionOffUntil + && _currentLootItemLeftAt != 0 + && _currentLootItemLeftAt - _currentLootItemMoveRequestedAt < PickupAnswerMinMs; + + /// + /// Inside the flight of the last jump pickup that had no bend-down (from its send, at most + /// ActionPacer.JumpLandMaxMs, the pacer's own longest flight): a busy motion queue now is the + /// jump's take-off, fall or landing, not a server pickup motion. + /// + private bool JumpPickupInAir(long now) => _jumpPickupAirUntil != 0 && now < _jumpPickupAirUntil; + /// /// WantLooting input for the ActivityArbiter (STEP 4). No game commands, no /// state mutation — safe to call from the decision path every tick. @@ -3877,6 +3978,8 @@ public sealed partial class RynthAiPlugin _currentLootItemSawAnim = false; _currentLootItemStackable = false; _currentLootItemPipelined = false; + _currentLootItemJumped = false; + _currentLootItemSentInAirWindow = false; _currentLootItemErrSeqAtSend = 0; _currentLootItemFreeRetries = 0; _currentLootItemFightHeld = false; @@ -4003,6 +4106,8 @@ public sealed partial class RynthAiPlugin bool sent = Host.UseFor(unchecked((uint)corpseId), "Loot", "open the claimed corpse"); if (watch && sent) _useRefusals.OnOpenSent(corpseId, now, seqBefore); + // An open on a no-bend-down call: its answer says whether the server was free (DistrustJumpNoMotion). + _openInAirWindowSeq = watch && sent && JumpPickupInAir(now) ? seqBefore : -1; 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) @@ -4025,6 +4130,12 @@ public sealed partial class RynthAiPlugin return; int seq = Host.GetUseDoneSeq(); bool haveErr = Host.TryGetLastUseDone(out int lastSeq, out uint err) && lastSeq == seq; + if (_openInAirWindowSeq >= 0 && seq != _openInAirWindowSeq) + { + if (haveErr && err == WeenieErrorYoureTooBusy) + DistrustJumpNoMotion(now, "the next corpse's open, sent on it, was refused as too busy"); + _openInAirWindowSeq = -1; + } ApplyUseRefusalVerdict(_useRefusals.OnTick(now, seq, err, haveErr), now); } @@ -4252,6 +4363,11 @@ public sealed partial class RynthAiPlugin private void ResetCorpseTarget() { StopCorpseMovement(); + // The no-bend-down window belongs to the loot that set it (the macro off, a claim dropped). + // ActionPacer's air hold is the character's own flight: it ends on the landing, or at death, + // portal space and logout (RynthAiPlugin), not with a corpse. + _jumpPickupAirUntil = 0; + _openInAirWindowSeq = -1; _targetCorpseId = 0; _corpseTargetSince = 0; _openedContainerAt = 0; diff --git a/Plugins/Shared/ActionPacer.cs b/Plugins/Shared/ActionPacer.cs index c68b3d9..f12fc9e 100644 --- a/Plugins/Shared/ActionPacer.cs +++ b/Plugins/Shared/ActionPacer.cs @@ -1087,6 +1087,18 @@ internal static class ActionPacer return false; } + /// + /// Ms since the last loot jump went out, or -1 when none is noted (never jumped, landed and + /// cleared by , or forgotten). Read it BEFORE LootJumpAirborne + /// when the answer matters: a landing seen there clears the jump. + /// + public static long LootJumpAgeMs() + { + long jumpAt; + lock (Gate) jumpAt = _lootJumpAt; + return jumpAt == 0 ? -1 : NowMs() - jumpAt; + } + /// No loot jump in the air any more (death, portal space, logout: RynthAiPlugin). public static void ForgetLootJump() { lock (Gate) _lootJumpAt = 0; } diff --git a/Tools/RynthCore.RynthAiHostTests/Tests/LootJumpTests.cs b/Tools/RynthCore.RynthAiHostTests/Tests/LootJumpTests.cs index 1280445..70acc6b 100644 --- a/Tools/RynthCore.RynthAiHostTests/Tests/LootJumpTests.cs +++ b/Tools/RynthCore.RynthAiHostTests/Tests/LootJumpTests.cs @@ -42,9 +42,25 @@ internal static class LootJumpTests 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: a jump send merged into a pack stack keeps the floor (the client's request slot stays held for a merged-away object)", JumpMergeKeepsAnswerFloor); + r.Add("jump loot: the no-bend-down window after an in-air send that rode an earlier jump is anchored to that jump", AirWindowAnchoredToTheInAirJump); + r.Add("jump loot: a 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; @@ -203,6 +219,355 @@ internal static class LootJumpTests 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; + + /// The ms from to the tick the pickup of is confirmed (-1: never, in 1.5 s). + 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"); + }); + + private static void JumpMergeKeepsAnswerFloor() => 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); + // ACE StackableMerge: the corpse item is removed (gone from the client) and the pack stack grows. + FakeHost.Containers.Remove(GemA); + FakeHost.Names.Remove(GemA); + FakeHost.Positions.Remove(GemA); + FakeHost.Ints[(PackStack, KeyStack)] = 4; + // The client's one-request slot is emptied only by an answer about that same object, and a + // merged-away object is gone (RynthCore ClientActionGates): the slot can stay held, and a move + // sent now would be dropped by the client. The floor is kept. + long confirmedAfter = ConfirmAfter(tick, GemA, sent); + Check.True(confirmedAfter >= RynthAiPlugin.PickupAnswerMinMs, $"a merge keeps the floor: confirmed {confirmedAfter} ms after the send"); + // (By the floor the gem is gone from the client, which names no stack: either merge wording.) + Check.True(FakeHost.Logs.Any(l => l.Contains("pickup confirmed") && l.Contains("merged into")), "as a merge into the pack stack: " + + (FakeHost.Logs.LastOrDefault(l => l.Contains("pickup confirmed")) ?? "(none)")); + }); + + // 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("_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)"); + }); + + // 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("_jumpPickupAirUntil") > _now, "the window is open"); + uint second = FakeHost.ExternalMoves[1].Id; + Check.True(Field("_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("_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 -- + + /// + /// After the last item's confirm: the next corpse is not opened while the Return plays + /// (CastBusy 1 for ), and is opened once it ends. + /// + 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("_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("_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("_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(); + 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("_jumpPickupAirUntil"), 0L, "the window is gone"); + Check.Eq(Field("_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. @@ -303,6 +668,18 @@ internal static class LootJumpTests 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(() =>