RynthAi jump loot: hold combat and buffs for the landing, no second jump in the air #23

Open
AwfulWaffle wants to merge 1 commit from AwfulWaffle/RynthSuite:lootjump-landing-gate into main
7 changed files with 381 additions and 30 deletions

View file

@ -2467,6 +2467,16 @@ public partial class CombatManager : IDisposable
if (hit) { _consecutiveCastMisses = 0; _magicMissesSinceHit = 0; return; }
// A swing or shot ACE refused in the air (WeenieError 0x4EB since it went out, Player_Melee /
// Player_Missile: IsJumping) never happened: not a no-damage attack. A cast's 0x4EB comes as
// its UseDone and is dropped before it gets here (JudgePendingOffensiveCast).
if (CurrentCombatMode != CombatMode.Magic && InTheAirErrorSince(_pendingJudgeErrSeq))
{
RefusedCastsNotJudged++;
_host.Log($"[Blacklist] attack at 0x{(uint)tid:X8} refused in the air (0x4EB): not counted as a no-damage attack");
return;
}
if (CurrentCombatMode == CombatMode.Magic) NoteMagicMissForResync(tid);
_consecutiveCastMisses++;
if (_consecutiveCastMisses >= _settings.BlacklistAttempts)
@ -2513,11 +2523,13 @@ public partial class CombatManager : IDisposable
// A refusal is not a cast (in a client log, three healthy targets were blacklisted 'after 3
// no-damage casts' whose casts had all come back UseDone 0x1D):
// the answer 0x1D, or no answer yet while the server is taken as busy, is not judged.
bool refused = _pendingOffensiveErr == ActionPacer.TooBusyErr || (_pendingOffensiveErr < 0 && ActionPacer.ServerBusy);
// So is 0x4EB, "You can't do that while in the air" (a cast sent in a jump).
bool inAir = _pendingOffensiveErr == InTheAirErr;
bool refused = _pendingOffensiveErr == ActionPacer.TooBusyErr || inAir || (_pendingOffensiveErr < 0 && ActionPacer.ServerBusy);
if (refused)
{
RefusedCastsNotJudged++;
_host.Log($"[Blacklist] cast at 0x{(uint)_pendingOffensiveTargetId:X8} {(_pendingOffensiveErr >= 0 ? "refused 'too busy' (UseDone 0x1D)" : "unanswered while the server is busy")}: not counted as a no-damage cast");
_host.Log($"[Blacklist] cast at 0x{(uint)_pendingOffensiveTargetId:X8} {(inAir ? "refused in the air (UseDone 0x4EB)" : _pendingOffensiveErr >= 0 ? "refused 'too busy' (UseDone 0x1D)" : "unanswered while the server is busy")}: not counted as a no-damage cast");
_pendingOffensiveSpellId = 0;
_pendingOffensiveTargetId = 0;
_pendingOffensiveCastAt = DateTime.MinValue;
@ -2572,6 +2584,30 @@ public partial class CombatManager : IDisposable
_pendingJudgeCastAt = RynthClock.Now;
_pendingJudgeTargetId = targetId;
_damageSincePendingCast = false;
_pendingJudgeErrSeq = WeenieErrorSeqNow();
}
/// <summary>WeenieError 0x4EB, "You can't do that while in the air" (ACE WeenieError.YouCantDoThatWhileInTheAir).</summary>
internal const uint InTheAirErr = 0x4EB;
private int _pendingJudgeErrSeq; // the engine's refusal counter when the judged attack was armed
private int WeenieErrorSeqNow()
{
try { return _host.HasGetLastWeenieError && _host.TryGetLastWeenieError(out int seq, out _, out _, out _) ? seq : 0; }
catch { return 0; }
}
/// <summary>The last refusal the engine saw is 0x4EB and came after <paramref name="seqAtArm"/>.</summary>
private bool InTheAirErrorSince(int seqAtArm)
{
try
{
return _host.HasGetLastWeenieError
&& _host.TryGetLastWeenieError(out int seq, out uint err, out _, out _)
&& seq != seqAtArm && err == InTheAirErr;
}
catch { return false; }
}
/// <summary>
@ -3821,6 +3857,17 @@ public partial class CombatManager : IDisposable
_busyGate.Reset();
}
// In the air after a jump-loot pickup's jump: ACE refuses a cast, swing or shot in the
// air (YouCantDoThatWhileInTheAir), so the attack waits for the landing (capped at
// ActionPacer.JumpLandMaxMs). Only the attack: target, approach and stance above go on;
// nothing is stamped, counted or judged for the held tick.
if (ActionPacer.LootJumpAirborne(_host, out _))
{
LastCombatSkipReason = "loot-jump-air"; // D4 record-only
_tickWait = CombatLatencyTracker.Wait.Busy;
return true;
}
// Magic cadence guard: while a previous combat cast is still
// resolving on the ACE server, do NOT turn or issue another cast.
// A turn/stop MoveToState (or the next cast's free-hands stop-thunk)

View file

@ -1861,9 +1861,16 @@ public sealed partial class RynthAiPlugin
// corpses hold one match, so a multi-item gate meant jump-loot almost never ran), with
// stamina > 5 to cover the cost. Not for a pipelined move: it is already queued behind
// the last pickup's Return, and a jump there would only disturb that queue. The tap jump
// has a fixed height, so LootJumpHeight no longer has an effect.
if (!pipelined && ShouldJumpLoot(settings))
Host.TapJump();
// has a fixed height, so LootJumpHeight no longer has an effect. No second jump while
// still in the air (an air jump only costs stamina); a jump taken is noted for combat.
bool jumpLoot = !pipelined && ShouldJumpLoot(settings);
bool stillInAir = jumpLoot && ActionPacer.LootJumpAirborne(Host, out _);
bool jumped = false;
if (jumpLoot && !stillInAir)
{
try { jumped = Host.TapJump(); } catch { jumped = false; }
if (jumped) ActionPacer.NoteLootJump(Host);
}
// Always a move into a pack, never a use: a use on a wearable corpse item is
// get-and-wield, which put salvage jewellery on the character (2026-10-02).

View file

@ -81,6 +81,7 @@ public sealed partial class RynthAiPlugin
if (portaling && !_wasPortalingForPacer)
{
RynthCore.Plugin.Shared.ActionPacer.Forget("portal space");
RynthCore.Plugin.Shared.ActionPacer.ForgetLootJump(); // out of the air: the teleport moved the character
_buffManager?.ForgetPendingWield("portal space");
}
_wasPortalingForPacer = portaling;
@ -115,6 +116,7 @@ public sealed partial class RynthAiPlugin
_combatManager?.ReleaseHeldTurn();
_navigationEngine?.Stop();
RynthCore.Plugin.Shared.ActionPacer.Forget("death"); // the server dropped whatever was open
RynthCore.Plugin.Shared.ActionPacer.ForgetLootJump(); // no landing to wait for after a death
_buffManager?.CancelPendingRecall("death"); // no /lifestone or macro restart after the respawn
_buffManager?.ForgetPendingWield("death"); // a swap the death cut short is not a failed swap
StopHunt("died", say: true); // from the lifestone it would walk all the way back to where it started

View file

@ -468,6 +468,7 @@ public sealed partial class RynthAiPlugin : RynthPluginBase
while (_engineCommands.TryDequeue(out _)) { } // a fellowship button's command is for this character only
// The server drops whatever it was doing for this character at logout.
RynthCore.Plugin.Shared.ActionPacer.Forget("logout");
RynthCore.Plugin.Shared.ActionPacer.ForgetLootJump();
_navigationEngine?.Stop();
_navigationEngine = null;
// The dungeon cell graph is a static single-landblock cache; nothing may outlive the session.

View file

@ -208,6 +208,7 @@ internal static class ActionPacer
_heldTurns = 0;
_forcedBreaks = 0;
_jumpAt = 0;
_lootJumpAt = 0;
_cycleBySpell.Clear();
_lastSeenSeq = int.MinValue;
_lastFrameMs = 0;
@ -466,6 +467,9 @@ internal static class ActionPacer
{
if (!Enabled) { why = ""; return true; }
if (PlayerHoldsStart(host, who, out why)) return false;
// A buff, heal, kit or potion in the air is refused by ACE: wait for the landing. Combat checks
// it itself, at the attack, so a stance change is not held; loot and doors never.
if (who == "Buff" && LootJumpAirborne(host, out why)) return false;
if (ServerBusyHolds(host, who, attackRepeat, out why, out bool tryAfterBusy, heal)) return false;
// An emergency heal does not wait for the movement settle (150-600 ms): at Emergency Heal At
// the heal comes first; it still obeys the in-flight rules below (OutstandingAllows, GestureHolds).
@ -1030,6 +1034,62 @@ internal static class ActionPacer
lock (Gate) { if (!ReferenceEquals(_stageFor, forAction)) _turnedAt = 0; _stage = stage; _stageAt = now; _stageFor = forAction; }
}
/// <summary>
/// Landed after a jump at <paramref name="jumpAt"/> from height <paramref name="z0"/>: the height
/// is back (looked at from JumpLandMinMs on), or JumpLandMaxMs has passed whatever it says.
/// </summary>
private static bool Landed(RynthCoreHost host, long now, long jumpAt, float z0)
{
long air = now - jumpAt;
bool landed = air >= JumpLandMaxMs;
if (!landed && air >= JumpLandMinMs)
{
try { landed = !host.HasGetPlayerPose || (host.TryGetPlayerPose(out _, out _, out _, out float z, out _, out _, out _, out _) && Math.Abs(z - z0) < 0.1f); }
catch { landed = true; }
}
return landed;
}
// Jump-loot (CorpseOpenController): the corpse pickup's tap jump. ACE refuses a cast, a swing, a
// shot, a kit, food or a potion in the air (Player_Magic/Melee/Missile, Healer, Food: IsJumping ->
// YouCantDoThatWhileInTheAir), so combat and buffs wait until the character has landed. Loot does
// not: ACE takes a pickup and a corpse use in the air, so this never holds MayStart("Loot").
private static long _lootJumpAt; // 0 = not in the air after a loot jump
private static float _lootJumpZ;
/// <summary>A loot jump went out (the client took it): the character is in the air from now.</summary>
public static void NoteLootJump(RynthCoreHost host)
{
float z = 0;
try { if (host.HasGetPlayerPose) host.TryGetPlayerPose(out _, out _, out _, out z, out _, out _, out _, out _); } catch { }
long now = NowMs();
lock (Gate) { _lootJumpAt = now; _lootJumpZ = z; }
}
/// <summary>
/// True (with why) while the character is in the air after a loot jump: until the height is back
/// (from JumpLandMinMs) or JumpLandMaxMs at most, so a missed landing cannot stall anything. Pure
/// wait: nothing is counted, refused or retried. Independent of <see cref="Enabled"/>.
/// </summary>
public static bool LootJumpAirborne(RynthCoreHost host, out string why)
{
why = "";
long jumpAt; float z0;
lock (Gate) { jumpAt = _lootJumpAt; z0 = _lootJumpZ; }
if (jumpAt == 0) return false;
long now = NowMs();
if (!Landed(host, now, jumpAt, z0))
{
why = $"in the air after the loot jump ({now - jumpAt} ms)";
return true;
}
lock (Gate) { if (_lootJumpAt == jumpAt) _lootJumpAt = 0; }
return false;
}
/// <summary>No loot jump in the air any more (death, portal space, logout: RynthAiPlugin).</summary>
public static void ForgetLootJump() { lock (Gate) _lootJumpAt = 0; }
/// <summary>In the air after a breaker jump: hold until landed (height back, or JumpLandMaxMs).</summary>
private static bool AirborneHolds(RynthCoreHost host, long now, out string why)
{
@ -1038,12 +1098,7 @@ internal static class ActionPacer
lock (Gate) { jumpAt = _jumpAt; z0 = _jumpZ; }
if (jumpAt == 0) return false;
long air = now - jumpAt;
bool landed = air >= JumpLandMaxMs;
if (!landed && air >= JumpLandMinMs)
{
try { landed = !host.HasGetPlayerPose || (host.TryGetPlayerPose(out _, out _, out _, out float z, out _, out _, out _, out _) && Math.Abs(z - z0) < 0.1f); }
catch { landed = true; }
}
bool landed = Landed(host, now, jumpAt, z0);
if (!landed)
{
why = $"in the air after the stuck-cast jump ({air} ms)";

View file

@ -53,6 +53,8 @@ internal static class CombatHookTests
r.Add("combat hook: a script answer at an ignored monster is rejected, even one hitting us (RynthAi casts its own)", HookRejectsIgnoredTarget);
r.Add("combat hook: a script heal (a drain) at a fight target whose rule turned to Priority 0 is rejected", HookHealRejectsIgnoredTarget);
r.Add("blacklist: casts answered 'too busy' (UseDone 0x1D) are not no-damage casts (answered 0: the target is dropped)", RefusedCastsNotJudged);
r.Add("loot jump: Think sends no cast while in the air after a loot jump; it casts on the landing, or at the cap", LootJumpHoldsAttack);
r.Add("loot jump: a swing refused in the air (WeenieError 0x4EB) is not a no-damage attack (without it: a miss)", MeleeInAirNotJudged);
r.Add("combat hook: ctx.pending is the cast in flight; ctx.last the last resolved one, err its first UseDone (final; -1 when missed or after 7 s)", LastErrIsTheCastsAnswer);
r.Add("combat hook: an attack and a heal in flight take their UseDones in send order (attack 0x401, heal 0)", AnswersInSendOrder);
r.Add("combat hook: a script heal refused for mana keeps its 2 s rest (no recovery fast retry)", ScriptHealNoFastRetry);
@ -1049,9 +1051,9 @@ internal static class CombatHookTests
private static void RefusedCastsNotJudged() => Guard(() =>
{
int drain = Id("Drain Health Other V");
foreach (uint answer in new uint[] { 0, ActionPacer.TooBusyErr })
foreach (uint answer in new uint[] { 0, ActionPacer.TooBusyErr, CombatManager.InTheAirErr })
{
string what = answer == 0 ? "answered 0" : "answered 0x1D";
string what = answer == 0 ? "answered 0" : $"answered 0x{answer:X}";
var rig = new AttackRig(setup: () => { FakeHost.ServerGates = true; FakeHost.LastUseDoneCalls = true; });
rig.S.BlacklistAttempts = 2;
rig.S.EnableRaycasting = false;
@ -1071,13 +1073,71 @@ internal static class CombatHookTests
Check.Eq(rig.C.activeTargetId, 0, "answered 0: two no-damage casts blacklist and drop the target");
else
{
Check.Eq(rig.C.activeTargetId, Target, "answered 0x1D: refusals are not casts, the target is kept");
Check.Eq(rig.C.RefusedCastsNotJudged, 2, "both kept out of the count");
Check.True(FakeHost.Logs.Any(l => l.Contains("refused 'too busy' (UseDone 0x1D): not counted")), "logged");
Check.Eq(rig.C.activeTargetId, Target, $"{what}: refusals are not casts, the target is kept");
Check.Eq(rig.C.RefusedCastsNotJudged, 2, $"{what}: both kept out of the count");
Check.Eq(Field<int>(rig.C, "_consecutiveCastMisses"), 0, $"{what}: no miss counted");
Check.True(FakeHost.Logs.Any(l => l.Contains(answer == ActionPacer.TooBusyErr
? "refused 'too busy' (UseDone 0x1D): not counted" : "refused in the air (UseDone 0x4EB): not counted")), $"{what}: logged");
}
}
});
// A jump-loot pickup's jump (ActionPacer.NoteLootJump) holds the attack until the landing.
// ACE refuses a cast, swing or shot in the air (Player_Magic/Melee/Missile: IsJumping).
private static void LootJumpHoldsAttack() => Guard(() =>
{
bool pacer = ActionPacer.Enabled;
var clock = ActionPacer.NowMs;
long t = 1_000_000;
ActionPacer.Enabled = false; // only the air hold under test (it does not depend on the pacer switch)
ActionPacer.NowMs = () => t;
try
{
foreach (bool cap in new[] { false, true })
{
string what = cap ? "landing never seen" : "landing seen";
var rig = new AttackRig(think: true);
ActionPacer.ForgetLootJump();
ActionPacer.NoteLootJump(rig.Host); // the pickup's jump, from the ground
var ground = FakeHost.PlayerPose;
FakeHost.PlayerPose = (ground.Cell, ground.X, ground.Y, ground.Z + 1.0f);
rig.C.Think();
Check.Eq(FakeHost.Casts.Count, 0, $"{what}: no cast in the air");
Check.Eq(rig.C.LastCombatSkipReason, "loot-jump-air", $"{what}: held for the landing");
Check.Eq(rig.C.GetStateSnapshot().LastAttackCmd, DateTime.MinValue, $"{what}: no attack stamped");
Check.Eq(rig.C.activeTargetId, Target, $"{what}: the target stays");
t += ActionPacer.JumpLandMinMs + 100;
rig.C.Think();
Check.Eq(FakeHost.Casts.Count, 0, $"{what}: still up: no cast");
if (!cap)
FakeHost.PlayerPose = ground; // landed
else
t += ActionPacer.JumpLandMaxMs; // up for good: the cap
rig.C.Think();
Check.Eq(rig.LastCast, "Flame Bolt VI", $"{what}: the cast goes at once");
Check.Eq(Field<int>(rig.C, "_consecutiveCastMisses"), 0, $"{what}: nothing counted for the held ticks");
}
}
finally { ActionPacer.Enabled = pacer; ActionPacer.NowMs = clock; ActionPacer.ForgetLootJump(); ActionPacer.Forget("test"); }
});
private static void MeleeInAirNotJudged() => Guard(() =>
{
foreach (bool inAir in new[] { false, true })
{
var rig = new AttackRig(setup: () => { FakeHost.WeaponCalls = true; FakeHost.CombatModeValue = CombatMode.Melee; FakeHost.WeenieErrorCalls = true; });
rig.S.BlacklistAttempts = 5;
rig.S.EnableRaycasting = false; // (the raycast warm-up drops every judgement)
rig.C.RecordOffensiveCast(Target); // a swing goes out
if (inAir) FakeHost.WeenieError(CombatManager.InTheAirErr); // ACE: "You can't do that while in the air"
SetField(rig.C, "_pendingJudgeCastAt", DateTime.Now.AddSeconds(-30));
CallPrivate(rig.C, "JudgePendingCast");
Check.Eq(Field<int>(rig.C, "_consecutiveCastMisses"), inAir ? 0 : 1,
inAir ? "refused in the air: not a miss" : "control, no refusal: a no-damage swing is a miss");
if (inAir) Check.True(FakeHost.Logs.Any(l => l.Contains("refused in the air (0x4EB)")), "logged");
}
});
private static void LastErrIsTheCastsAnswer() => Guard(() =>
{
int drain = Id("Drain Health Other V");

View file

@ -7,6 +7,7 @@ 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;
@ -24,6 +25,11 @@ internal static class LootJumpTests
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";
@ -36,6 +42,9 @@ 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 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);
}
private static long _now;
@ -43,45 +52,81 @@ internal static class LootJumpTests
private static void Clocked(Action body)
{
var old = RynthAiPlugin.CorpseClock;
var oldPace = ActionPacer.NowMs;
_now = 50_000_000;
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; }
finally { RynthAiPlugin.CorpseClock = old; ActionPacer.NowMs = oldPace; ActionPacer.ForgetLootJump(); }
}
private static void Gem(uint id)
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] = CorpseA;
FakeHost.Containers[id] = container;
FakeHost.Appraised.Add(id);
}
private static void World(bool secondGem)
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;
FakeHost.Names[CorpseA] = "Corpse of Olthoi Swarm Drone";
FakeHost.ItemTypes[CorpseA] = ItemTypeContainer;
FakeHost.Strings[(CorpseA, LongDescKey)] = $"Killed by {Me}.";
FakeHost.NotAttackable.Add(CorpseA);
FakeHost.Positions[CorpseA] = (Me0.Cell, Me0.X + 1.0f, Me0.Y, Me0.Z);
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.</summary>
private static void LootUntilFirstMove(bool jumpEnabled, bool secondGem, uint stamina)
/// <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);
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,
@ -113,17 +158,151 @@ internal static class LootJumpTests
Set("_activity", BotActivity.Looting);
typeof(RynthAiPlugin).GetMethod("TickCorpseOpening", Any)!.Invoke(bot, null);
}
foreach (uint id in secondGem ? new[] { CorpseA, GemA, GemA2 } : new[] { CorpseA, GemA }) cache.OnCreateObject(id);
cache.Tick();
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(); }
}
// 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 string Order() => string.Join(",", FakeHost.Order);
private static void TwoItemJumpsBeforeMove() => Clocked(() =>