Snapshot for release 2026.10.7.1 (internal 2a9c773)

This commit is contained in:
Tom Bohar 2026-10-07 12:54:26 -04:00
commit 26907e6ab1
29 changed files with 1900 additions and 110 deletions

View file

@ -82,6 +82,9 @@ internal static unsafe class FakeHost
public static readonly List<bool> AutoRunCalls = new();
public static bool AutoRun;
public static int Jumps;
/// <summary>Opt-in: wires TapJump (the keyboard jump, 0xF61B); calls land in <see cref="TapJumps"/>.</summary>
public static bool TapJumpCalls;
public static int TapJumps;
public static int Turns;
public static readonly List<(uint Target, int SpellId)> Casts = new();
/// <summary>Opt-in: wires GiveObjectTo (AC's give action); every call lands in <see cref="Gives"/>.</summary>
@ -193,7 +196,7 @@ internal static unsafe class FakeHost
Vitals = default; BaseVitals = default; WorldName = ""; AccountName = "";
HeadingDeg = 0; Wcids.Clear(); Spellbook.Clear(); PlayerIdValue = 0;
Logs.Clear(); Chat.Clear(); ChatCommands.Clear();
AutoRunCalls.Clear(); AutoRun = false; Jumps = 0; Turns = 0; Casts.Clear(); StopCalls = false; Stops = 0; GiveCalls = false; Gives.Clear();
AutoRunCalls.Clear(); AutoRun = false; Jumps = 0; TapJumpCalls = false; TapJumps = 0; Turns = 0; Casts.Clear(); StopCalls = false; Stops = 0; GiveCalls = false; Gives.Clear();
Uses.Clear(); IdRequests.Clear(); Moves.Clear(); Appraised.Clear(); WeaponCalls = false; CombatModeValue = 1;
VTankFlags = -1; VTankSeq = 0; LogCostMicros = 0;
ServerGates = false; UseDoneSeq = 0; CastBusy = 0; LastUseDoneError = 0; LastUseDoneCalls = false;
@ -245,6 +248,8 @@ internal static unsafe class FakeHost
api.SetAutoRunFn = (IntPtr)(delegate* unmanaged[Cdecl]<int, int>)&SetAutoRun;
api.TurnToHeadingFn = (IntPtr)(delegate* unmanaged[Cdecl]<float, int>)&TurnToHeading;
api.JumpNonAutonomousFn = (IntPtr)(delegate* unmanaged[Cdecl]<float, int>)&JumpNonAutonomous;
if (TapJumpCalls)
api.TapJumpFn = (IntPtr)(delegate* unmanaged[Cdecl]<int>)&TapJump;
api.CastSpellFn = (IntPtr)(delegate* unmanaged[Cdecl]<uint, int, int>)&CastSpell;
if (StopCalls)
api.StopCompletelyFn = (IntPtr)(delegate* unmanaged[Cdecl]<int>)&StopCompletely;
@ -614,6 +619,9 @@ internal static unsafe class FakeHost
[UnmanagedCallersOnly(CallConvs = new[] { typeof(CallConvCdecl) })]
private static int JumpNonAutonomous(float extent) { Jumps++; return 1; }
[UnmanagedCallersOnly(CallConvs = new[] { typeof(CallConvCdecl) })]
private static int TapJump() { TapJumps++; return 1; }
[UnmanagedCallersOnly(CallConvs = new[] { typeof(CallConvCdecl) })]
private static int CastSpell(uint target, int spellId) { Casts.Add((target, spellId)); return 1; }
[UnmanagedCallersOnly(CallConvs = new[] { typeof(CallConvCdecl) })]

View file

@ -64,6 +64,7 @@ internal static class Program
OwnCorpseTests.Register(runner);
UseRefusalTests.Register(runner);
VitalsTests.Register(runner);
MultiTargetTests.Register(runner);
CastSafetyTests.Register(runner);
HealLatencyTests.Register(runner);
BlastTests.Register(runner);

View file

@ -49,14 +49,22 @@ internal static class ActionPacingTests
r.Add("pacing: the stall onset replayed - the idle peace swap waits for the corpse use's answer, then goes; no swap to the mode you're in", OnsetModeChangeHeld);
r.Add("pacing: moves, turns and redundant stops wait while the server answers; a real stop and the cast nudge go through", MovesHeld);
r.Add("pacing: no answer - each kind's time limit lets the next action go, logged, and nothing is force-cleared", TimeLimits);
r.Add("pacing: heals keep their priority (1 s behind a corpse use, 300 ms at Emergency, one behind a cast's result, 300 ms after the stance reads)", HealRules);
r.Add("pacing: heals (a plain heal waits for a corpse use's answer, 300 ms at Emergency, one behind a cast's result, 300 ms after the stance reads)", HealRules);
r.Add("pacing (vitals): Drakkon 07:03 - a cast whose result is in waits for its UseDone: one cast, not a too-busy flood", CastWaitsForUseDone);
r.Add("pacing (vitals): a heal goes 1 s behind an unanswered corpse use; the emergency stance settle is unchanged", HealLatencyKept);
r.Add("pacing (vitals): a heal waits for an unanswered corpse use's answer, then goes at once; the emergency stance settle is unchanged", HealLatencyKept);
r.Add("pacing (looting): one open per server answer, never re-sent on top of an unanswered one", LootOneOpenPerAnswer);
r.Add("pacing (looting): Drakkon's stall is still found and said once with pacing on", LootStallStillDetected);
r.Add("pacing (combat): the idle peace swap waits while a kit is unanswered", CombatPeaceWaitsForKit);
r.Add("pacing (arbiter): the activity-change StopCompletely only when RynthAi itself has the character moving", ArbiterStopOnlyWhenMoving);
r.Add("busy mirror: follows the engine's count (1.5 s), never reset while the engine says busy; old engines: the mirror only; never a force-clear", MirrorResetOnly);
r.Add("motion gate (14:29): a kit waits for the swing's animation; the corpse open waits for the kit's answer and then its animation", MotionGate1429);
r.Add("pacing (motion): after a swing is sent, nothing else starts until it has played (16:45 wand on a swing)", SwingNotStarted);
r.Add("motion gate (13:58): wand wield -> the cast and the Magic stance wait until the wield's animation is over", MotionGate1358);
r.Add("motion gate (morning): corpse use -> the idle peace swap waits for the UseDone and then the turn's animation", MotionGateMorning);
r.Add("motion gate: 4 s of 'animating' is taken as stuck (logged once, open until it reads clear); an emergency heal waits 1.5 s at most", MotionGateLimits);
r.Add("motion gate: melee/missile attack repeats are not held by the animation, peace/magic combat starts are; off with the pacing", MotionGateAttackExempt);
r.Add("motion gate (looting): a corpse open waits while the character animates, then goes", MotionGateLooting);
r.Add("motion gate (items): the item managers' busy count includes the animation", MotionGateItems);
}
// ── Pacer rig ───────────────────────────────────────────────────────────────
@ -239,14 +247,18 @@ internal static class ActionPacingTests
host.UseFor(Corpse, "Loot", "open");
_t += 900;
Check.False(ActionPacer.MayStart(host, "Buff", HealNeed.Heal, out _), "a heal 900 ms behind an unanswered corpse use waits");
_t += 100;
Check.True(ActionPacer.MayStart(host, "Buff", HealNeed.Heal, out _), "at 1 s it goes ahead (the server cancels the walk cleanly)");
Check.True(Logged("the heal goes ahead of the use of"), "logged");
_t += 3000;
Check.False(ActionPacer.MayStart(host, "Buff", HealNeed.Heal, out _),
"a plain heal still waits at 3.9 s: on ACE any motion during the server's turn to the corpse stops that turn for good");
FakeHost.UseDone(0);
Check.True(ActionPacer.MayStart(host, "Buff", HealNeed.Heal, out _), "the use is answered: the heal goes");
host.UseFor(Corpse, "Loot", "open");
_t += 300;
_t += 299;
Check.False(ActionPacer.MayStart(host, "Buff", HealNeed.Emergency, out _), "at Emergency Heal At: not before 300 ms");
_t += 1;
Check.True(ActionPacer.MayStart(host, "Buff", HealNeed.Emergency, out _), "at Emergency Heal At: 300 ms");
Check.True(Logged("the heal goes ahead of the use of"), "logged");
Check.False(ActionPacer.MayStart(host, "Combat", HealNeed.None, out _), "anything else still waits");
FakeHost.UseDone(0);
@ -356,17 +368,20 @@ internal static class ActionPacingTests
PaceOn();
try
{
// A heal behind a corpse use the server walks to: it waits 1 s, not the whole walk.
// A heal behind a corpse use the server walks/turns to: it waits for the use's answer (a cast
// during the server's turn stops the turn for good on ACE), then goes at once.
var r = new BuffRig();
r.S.HealAt = 60; r.S.TopOffHP = 60; r.S.GetManaAt = 0; r.S.TopOffMana = 0;
r.V.CurrentHealth = 50; r.V.CurrentMana = 100;
r.At(0);
r.Host.UseFor(Corpse, "Loot", "open the claimed corpse");
r.B.BusyCount = 1; // the open's +1 on the client's count, as the engine reports it
for (double s = 0; s < 0.95; s += 0.1) { r.At(s); r.B.OnHeartbeat(); }
Check.Eq(FakeHost.Casts.Count, 0, "under 1 s behind the unanswered open: no heal yet");
r.At(1.0); r.B.OnHeartbeat();
Check.Eq(FakeHost.Casts.Count, 1, "at 1 s the heal goes (the open's busy count doesn't hold it again)");
for (double s = 0; s < 1.45; s += 0.1) { r.At(s); r.B.OnHeartbeat(); }
Check.Eq(FakeHost.Casts.Count, 0, "behind the unanswered open: no heal");
FakeHost.UseDone(0);
r.B.BusyCount = 0; // the engine's UseDone decrement
r.At(1.5); r.B.OnHeartbeat();
Check.Eq(FakeHost.Casts.Count, 1, "the open is answered: the heal goes on the next heartbeat");
string healName = SpellTable.ById(FakeHost.Casts[0].SpellId)?.Name ?? "";
Check.True(healName.StartsWith("Heal Self") || healName == "Adja's Intervention", "and it is the heal spell: " + healName);
@ -619,4 +634,199 @@ internal static class ActionPacingTests
Check.True(Logged("resetting the mirror only"), "and the line says so");
});
}
// ── The motion gate (2026-10-06 afternoon, ops\overnight\2026-10-06-turnto-stall.md) ──────────
// Nothing starts while the character is still animating (the client's motion queue, the engine's
// GetCastBusyState); FakeHost.CastBusy = 1 stands for "animating".
// 16:45:37: the wand's use went 110 ms after a MeleeAttack, before the swing animated.
private static void SwingNotStarted() => Paced(() =>
{
var host = World();
FakeHost.CastBusy = 0;
ActionPacer.NoteAttackSent();
_t += 110;
Check.False(ActionPacer.MayStart(host, "Buff", HealNeed.None, out string why), "the wand waits: the swing hasn't animated yet");
Check.True(why.Contains("swing"), "why: " + why);
Check.True(ActionPacer.MayStart(host, "Combat", HealNeed.None, out _, gestureGate: false), "the next attack isn't held");
_t += 200;
FakeHost.CastBusy = 1;
Check.False(ActionPacer.MayStart(host, "Buff", HealNeed.None, out _), "swinging: still waits");
_t += 700;
FakeHost.CastBusy = 0;
Check.True(ActionPacer.MayStart(host, "Buff", HealNeed.None, out _), "the swing played: the wand goes");
ActionPacer.NoteAttackSent();
_t += 600;
Check.True(ActionPacer.MayStart(host, "Buff", HealNeed.Emergency, out _), "an emergency heal waits at most 500 ms");
Check.False(ActionPacer.MayStart(host, "Buff", HealNeed.None, out _), "anything else still waits");
_t += 1000;
Check.True(ActionPacer.MayStart(host, "Buff", HealNeed.None, out _), "a swing that never animates holds at most 1.5 s");
Check.True(ActionPacer.SwingHoldCount >= 2, "holds counted");
});
private static void MotionGate1429() => Paced(() =>
{
var host = World();
// 14:29:21.435 the swing; 22.380 AttackDone (the attack sequence is over, the swing still plays).
FakeHost.CastBusy = 1;
Check.False(ActionPacer.MayStart(host, "Buff", HealNeed.Heal, out string why), "22.41: the kit waits for the swing's animation");
Check.True(why.Contains("still animating"), "why says so: " + why);
Check.True(Logged("[Pace] Buff waits: the character is still animating"), "logged once");
_t += 300;
FakeHost.CastBusy = 0;
Check.True(ActionPacer.MayStart(host, "Buff", HealNeed.Heal, out _), "the swing is over: the kit goes");
host.UseOnFor(Kit, Player, "Buff", "vitals: healing kit on yourself");
FakeHost.CastBusy = 1; // the kit's SkillHealSelf
_t += 2400;
Check.False(ActionPacer.MayStart(host, "Loot", HealNeed.None, out _), "the corpse open waits for the kit's answer");
FakeHost.UseDone(0); // 24.794 the kit's UseDone; the client still plays the kit's last frames
Check.False(ActionPacer.MayStart(host, "Loot", HealNeed.None, out why), "answered, but still animating: the open waits");
Check.True(why.Contains("still animating"), "why: " + why);
_t += 120;
FakeHost.CastBusy = 0;
Check.True(ActionPacer.MayStart(host, "Loot", HealNeed.None, out _), "at rest: the corpse open goes");
Check.True(ActionPacer.GestureHoldCount >= 2, "holds counted");
});
private static void MotionGate1358() => Paced(() =>
{
var host = World(combatMode: 2);
// 13:58:54.210 the wand is wielded in melee stance (its use is an item use, answered by wielding).
host.UseFor(Wand, "Buff", "buffing: switch to the wand");
FakeHost.CastBusy = 1; // the unwield/wield and stance motion
FakeHost.Wielded[Wand] = 0x01000000;
_t += 50;
ActionPacer.Current(host); // the wield is first seen done
_t += 200;
Check.True(ActionPacer.Current(host) == null, "the wield reads done: answered");
Check.False(ActionPacer.MayStart(host, "Buff", HealNeed.None, out _), "the cast waits: still animating");
Check.False(host.ChangeCombatModeFor(CombatMode.Magic, "Buff", "wand wielded: Magic mode"), "the Magic stance waits too");
Check.Eq(FakeHost.CombatModeRequests.Count, 0, "no mode request sent");
Check.True(Logged("[Pace] mode:Buff waits: the character is still animating"), "logged");
_t += 900;
FakeHost.CastBusy = 0;
Check.True(host.ChangeCombatModeFor(CombatMode.Magic, "Buff", "wand wielded: Magic mode"), "at rest: Magic mode");
Check.Eq(string.Join(",", FakeHost.CombatModeRequests), "8", "sent");
FakeHost.CombatModeValue = 8;
FakeHost.CastBusy = 1; // the stance animation
_t += ActionPacer.ModeSettleMs;
Check.True(ActionPacer.Current(host) == null, "the stance is read and settled");
Check.False(ActionPacer.MayStart(host, "Buff", HealNeed.None, out _), "but the client still animates it: the cast waits");
FakeHost.CastBusy = 0;
Check.True(ActionPacer.MayStart(host, "Buff", HealNeed.None, out _), "at rest: the cast goes");
});
private static void MotionGateMorning() => Paced(() =>
{
var host = World(combatMode: 2);
FakeHost.Positions[Player] = Me0;
FakeHost.PlayerPose = Me0;
var s = new LegacyUiSettings { IsMacroRunning = true, EnableCombat = true, PeaceModeWhenIdle = true, MonsterRange = 50 };
var cache = new WorldObjectCache(host);
cache.SetPlayerId(Player);
var combat = new CombatManager(host, s, cache);
combat.SetPlayerId(Player);
// 06:18:44.549 the corpse use in melee stance; the idle peace swap came 3 ms later.
host.UseFor(Corpse, "Loot", "open the claimed corpse");
_t += 3;
combat.Think();
Check.Eq(FakeHost.CombatModeRequests.Count, 0, "3 ms later: no peace swap (the use is unanswered)");
FakeHost.CastBusy = 1; // the turn to the corpse
_t += 400;
FakeHost.UseDone(0);
typeof(CombatManager).GetField("_lastPeaceAttempt", Any)!.SetValue(combat, DateTime.MinValue);
combat.Think();
Check.Eq(FakeHost.CombatModeRequests.Count, 0, "answered, but the character still animates: no peace swap");
_t += 200;
FakeHost.CastBusy = 0;
typeof(CombatManager).GetField("_lastPeaceAttempt", Any)!.SetValue(combat, DateTime.MinValue);
combat.Think();
Check.Eq(string.Join(",", FakeHost.CombatModeRequests), "1", "at rest: the idle swap goes out");
});
private static void MotionGateLimits() => Paced(() =>
{
var host = World();
FakeHost.CastBusy = 1;
Check.False(ActionPacer.MayStart(host, "Loot", HealNeed.None, out _), "animating: held");
_t += 1499;
Check.False(ActionPacer.MayStart(host, "Buff", HealNeed.Emergency, out _), "an emergency heal waits up to 1.5 s");
_t += 1;
Check.True(ActionPacer.MayStart(host, "Buff", HealNeed.Emergency, out _), "at 1.5 s the emergency heal goes");
Check.True(Logged("emergency heal after 1500 ms of animation - going on"), "logged");
Check.False(ActionPacer.MayStart(host, "Loot", HealNeed.None, out _), "anything else still waits");
_t += ActionPacer.GestureHoldMaxMs - 1500;
Check.True(ActionPacer.MayStart(host, "Loot", HealNeed.None, out _), "4 s: taken as stuck, the action goes");
Check.Eq(FakeHost.Logs.Count(l => l.Contains("taken as stuck, going on")), 1, "logged once");
_t += 5000;
Check.True(ActionPacer.MayStart(host, "Combat", HealNeed.None, out _), "still open while it reads busy");
Check.Eq(FakeHost.Logs.Count(l => l.Contains("taken as stuck, going on")), 1, "not logged again");
Check.Eq(ActionPacer.GestureLimits, 2L, "two limits counted");
FakeHost.CastBusy = 0;
Check.True(ActionPacer.MayStart(host, "Loot", HealNeed.None, out _), "clear");
Check.True(Logged("animation queue reads clear again"), "the recovery is logged");
FakeHost.CastBusy = 1;
Check.False(ActionPacer.MayStart(host, "Loot", HealNeed.None, out _), "a new animation: held again (a fresh 4 s)");
});
private static void MotionGateAttackExempt() => Paced(() =>
{
var host = World(combatMode: 2);
FakeHost.CastBusy = 1; // the last swing still plays
Check.True(ActionPacer.MayStart(host, "Combat", HealNeed.None, out _, gestureGate: false), "a melee attack repeat is not held by the animation");
Check.False(ActionPacer.MayStart(host, "Combat", HealNeed.None, out _), "anything gated is");
host.UseFor(Corpse, "Loot", "open");
Check.False(ActionPacer.MayStart(host, "Combat", HealNeed.None, out _, gestureGate: false), "but an attack still waits for an unanswered corpse use (the server's turn)");
FakeHost.UseDone(0);
Check.True(ActionPacer.Current(host) == null, "the use is answered");
ActionPacer.Enabled = false;
Check.True(ActionPacer.MayStart(host, "Loot", HealNeed.None, out _), "pacing off: no gate");
Check.False(ActionPacer.GestureHolds(host, "Loot", HealNeed.None, out _), "pacing off: no animation hold");
ActionPacer.Enabled = true;
FakeHost.ServerGates = false;
var old = FakeHost.Create(Player);
Check.True(ActionPacer.MayStart(old, "Loot", HealNeed.None, out _), "an engine without the gate: no opinion");
});
private static void MotionGateLooting()
{
LootWorld();
var host = FakeHost.Create(Player);
var bot = new Bot(host);
PaceOn();
try
{
WithClock((now, advance) =>
{
FakeHost.CastBusy = 1;
for (int i = 0; i < 20; i++) { bot.Tick(); advance(100); }
Check.Eq(FakeHost.Uses.Count, 0, "no open while the character animates");
Check.True(Logged("[Pace] Loot waits: the character is still animating"), "logged");
FakeHost.CastBusy = 0;
for (int i = 0; i < 10 && FakeHost.Uses.Count == 0; i++) { bot.Tick(); advance(100); }
Check.Eq(FakeHost.Uses.Count, 1, "at rest: the open goes");
});
}
finally { PaceOff(); }
}
private static void MotionGateItems()
{
LootWorld();
var host = FakeHost.Create(Player);
var bot = new Bot(host);
PaceOn();
try
{
int Busy() => (int)typeof(RynthAiPlugin).GetProperty("PacedBusy", Any)!.GetValue(bot.P)!;
Check.Eq(Busy(), 0, "at rest, nothing outstanding: 0");
FakeHost.CastBusy = 1;
Check.Eq(Busy(), 1, "animating: +1 (a pack move of a wielded item, a stone, a summon waits)");
FakeHost.CastBusy = 0;
Check.Eq(Busy(), 0, "at rest again: 0");
}
finally { PaceOff(); }
}
}

View file

@ -35,9 +35,7 @@ internal static class CombatMathTests
r.Add("target range: closest first, then the one in front", ScanOrder);
r.Add("target range: dead, unattackable, never-attack and spell projectiles are skipped", ScanFilters);
r.KnownFailure("damage text: a monster hitting our body part isn't our damage",
"TryParseOutgoingDamage only rejects \"you for\"; a hit like 'Olthoi Swarm Harvester blisters your lower leg for 12 points of acid damage!' is counted as a hit by us while casting, which skews the Damage tab averages and the kill-shot prediction (not fixed on any branch)",
BodyPartHitIsNotOurs);
r.Add("damage text: a monster hitting our body part isn't our damage", BodyPartHitIsNotOurs); // was a known failure; fixed by feature/warchain-fix (the line must start with "You")
r.Add("weapon choice: a weapon the character no longer has is skipped", WeaponMissingSkipped); // was a known failure; fixed by 996b2a5
}

View file

@ -50,6 +50,7 @@ internal static class LootCorpseTests
r.Add("corpse close: an engine without CloseContainer leaves it to the next open (no close)", FinishedCorpseNotClosedOnOldEngine);
r.Add("corpse close: an abandoned open corpse is closed once", AbandonedCorpseClosed);
r.Add("corpse close: stopping the macro mid-loot closes the open corpse, not marked completed", MacroStopClosesCorpse);
r.Add("loot pacing: a pickup waits for the last bend-down, and no retry is timed while it plays", PickupWaitsForAnimation);
}
// ── World set-up ──────────────────────────────────────────────────────────
@ -440,4 +441,58 @@ internal static class LootCorpseTests
bot.Call("CloseOpenCorpseOnMacroStop");
Check.Eq(FakeHost.Closes.Count, 1, "a stop with no corpse open closes nothing");
}
// 2026-10-07, Drakkon: picking up an item plays a bend-down, and the engine holds queued
// moves until it ends (about 2.2 s). RynthAi retried every 0.5 s from the send and gave up
// after 3 tries, so items were skipped while their first move had not even gone out.
private static void PickupWaitsForAnimation()
{
BaseWorld(corpsePositioned: true);
FakeHost.ServerGates = true; // GetCastBusyState
var host = FakeHost.Create(Player);
var bot = new Bot(host);
bot.Cache.OnCreateObject(Corpse);
bot.Cache.Tick();
bot.Tick(BotActivity.Looting);
Check.True(FakeHost.Uses.Contains(Corpse), "the corpse is opened");
// The last pickup is still animating when the corpse's contents arrive.
FakeHost.CastBusy = 1;
bot.Cache.OnCreateObject(Gem);
bot.Cache.Tick();
bot.P.OnViewObjectContents(Corpse);
TickFor(bot, 500);
Check.False(FakeHost.ExternalMoves.Any(m => m.Id == Gem), "no pickup sent while the character animates");
FakeHost.CastBusy = 0;
for (int i = 0; i < 100 && !FakeHost.ExternalMoves.Any(m => m.Id == Gem); i++)
{
bot.Tick(BotActivity.Looting);
Thread.Sleep(10);
}
Check.Eq(FakeHost.ExternalMoves.Count(m => m.Id == Gem), 1, "the pickup goes out once the character is still");
// Its own bend-down plays for longer than 3 retry windows: no retry, no give-up.
FakeHost.CastBusy = 1;
TickFor(bot, 1800);
Check.Eq(FakeHost.ExternalMoves.Count(m => m.Id == Gem), 1, "no retry while the pickup animates");
Check.False(FakeHost.Logs.Any(l => l.Contains("pickup failed")), "the item is not given up on");
// Still again and the item still on the corpse: the retry window starts now.
FakeHost.CastBusy = 0;
TickFor(bot, 250);
Check.Eq(FakeHost.ExternalMoves.Count(m => m.Id == Gem), 1, "the retry window counts from when the character is still");
TickFor(bot, 500);
Check.Eq(FakeHost.ExternalMoves.Count(m => m.Id == Gem), 2, "then one retry");
}
private static void TickFor(Bot bot, int ms)
{
long end = Environment.TickCount64 + ms;
while (Environment.TickCount64 < end)
{
bot.Tick(BotActivity.Looting);
Thread.Sleep(10);
}
}
}

View file

@ -0,0 +1,207 @@
using System;
using System.Collections.Generic;
using System.Linq;
using RynthCore.Plugin.RynthAi;
using RynthCore.Plugin.RynthAi.CreatureData;
using RynthCore.Plugin.RynthAi.LegacyUi;
using RynthCore.Plugin.Shared;
using RynthCore.RynthAiHostTests.Fakes;
using RynthCore.RynthAiTests.Harness;
namespace RynthCore.RynthAiHostTests.Tests;
// One spell, several monsters: rings, walls, blasts and chain spells (Conquest). Each monster the
// spell hurts gets its own damage line naming it, the server sends health only for the selected
// target, and a kill notice names the monster that died. These tests drive CombatManager with
// those lines on the fake host: every line goes to the monster it names (never to the fight
// target), the other monsters get a health estimate, and kill notices from one cast keep the scan
// off each monster that died without dropping a fight target that is still alive.
internal static class MultiTargetTests
{
private const uint Player = 0x50000C01;
private const uint Lb = 0xA9B40000;
private const uint SkulkerWcid = 1001, MosswartWcid = 1002;
public static void Register(Runner r)
{
r.Add("damage text: the victim's name comes with the amount", VictimNames);
r.Add("multi-target: each damage line goes to the monster it names", LinesGoToTheirMonsters);
r.Add("multi-target: same-named monsters in one volley are told apart", SameNameVolley);
r.Add("multi-target: other targets get a health estimate, the server's number wins", HealthEstimates);
r.Add("multi-target: several kills from one cast keep the live fight target", KillsFromOneCast);
r.Add("multi-target: the fight target's own kill notice still drops it", FightTargetKill);
}
// ── The parser ───────────────────────────────────────────────────────────
private static string? Victim(string text) => CombatText.TryParseOutgoingHit(text, out string v, out _) ? v : null;
private static void VictimNames()
{
Check.Eq(Victim("You blast Drudge Skulker for 153 points with Whirling Blade VII."), "Drudge Skulker", "ACE war magic");
Check.Eq(Victim("You scorch the Mosswart Worshipper for 1,234 points of fire damage!"), "Mosswart Worshipper", "retail, 'the' dropped");
Check.Eq(Victim("Critical hit! Sneak Attack! You gore Olthoi Slasher for 1638 points with Force Arc VII."), "Olthoi Slasher", "two prefixes");
Check.Eq(Victim("Overpower! You frost Tusker Guard for 40 points with Frost Bolt VI."), "Tusker Guard", "Overpower prefix");
Check.Eq(Victim("You slash Banderling Scout for 12 points of slashing damage!"), "Banderling Scout", "melee");
Check.Eq(Victim("Olthoi Swarm Harvester blisters your lower leg for 12 points of acid damage!"), null, "a monster's hit on us");
Check.Eq(Victim("You drain 45 points of mana from Drudge Skulker."), null, "a drain");
Check.Eq(Victim("You heal yourself for 64 points."), null, "a heal");
Check.Eq(CombatText.CorpseOwnerName("Corpse of Drudge Skulker"), "Drudge Skulker", "corpse name");
Check.Eq(CombatText.CorpseOwnerName("Drudge Skulker"), null, "not a corpse");
}
// ── The rig ──────────────────────────────────────────────────────────────
private sealed class Rig
{
public readonly LegacyUiSettings S = new() { MonsterRange = 30 };
public readonly MonsterDamageStore Store = new();
public CombatManager C = null!;
public RynthCore.Plugin.RynthAi.WorldObjectCache Cache = null!;
private readonly List<uint> _ids = new();
private uint _next = 0x80000301;
public Rig()
{
FakeHost.Reset();
FakeHost.WeaponCalls = true; // installs GetCurrentCombatMode
FakeHost.CombatModeValue = CombatMode.Magic;
FakeHost.Names[Player] = "Me";
FakeHost.Positions[Player] = (Lb | 0x1C, 96f, 96f, 0f);
FakeHost.PlayerPose = (Lb | 0x1C, 96f, 96f, 0f);
}
public uint Mob(string name, uint wcid, float north, float east)
{
uint id = _next++;
FakeHost.Names[id] = name;
FakeHost.Positions[id] = (Lb | 0x1C, 96f + east, 96f + north, 0f);
FakeHost.ItemTypes[id] = 0x10;
FakeHost.Wcids[id] = wcid;
_ids.Add(id);
return id;
}
public void Build(uint fightTarget, IReadOnlyDictionary<uint, float>? health = null)
{
var host = FakeHost.Create();
Cache = FakeHost.MakeCache(host, Player, _ids, health);
C = new CombatManager(host, S, Cache);
C.SetPlayerId(Player);
C.SetDamageStores(null, Store);
C.EngageForTest(unchecked((int)fightTarget));
}
public float Hp(uint id) => Cache.GetHealthRatio(unchecked((int)id));
/// <summary>Learned non-crit average damage per monster type (the Damage tab's rows).</summary>
public Dictionary<uint, (double Avg, int Samples)> Learned()
=> Store.Snapshot().GroupBy(r => r.Wcid)
.ToDictionary(g => g.Key, g => (g.First().AvgDamage, g.Sum(r => r.DmgSamples)));
}
// ── The tests ────────────────────────────────────────────────────────────
private static void LinesGoToTheirMonsters()
{
var rig = new Rig();
uint skulker = rig.Mob("Drudge Skulker", SkulkerWcid, 5, 0);
uint moss = rig.Mob("Mosswart Worshipper", MosswartWcid, 6, 2);
rig.Build(skulker);
rig.C.HandleChatForDamage("You blast Drudge Skulker for 100 points with Lightning Chain VI.");
rig.C.HandleChatForDamage("You blast Mosswart Worshipper for 40 points with Lightning Chain VI.");
var learned = rig.Learned();
Check.True(learned.ContainsKey(MosswartWcid), "the Mosswart's hit is learned against the Mosswart");
Check.Near(learned.GetValueOrDefault(MosswartWcid).Avg, 40, 1e-6, "the Mosswart's damage is its own 40");
Check.Near(learned.GetValueOrDefault(SkulkerWcid).Avg, 100, 1e-6, "the Skulker keeps only its own 100 (not 140, not 70)");
Check.Eq(learned.GetValueOrDefault(SkulkerWcid).Samples, 1, "one hit learned for the Skulker");
Check.True(rig.Hp(moss) > 0f && rig.Hp(moss) < 1f, $"the Mosswart is marked hurt ({rig.Hp(moss):0.00})");
Check.True(rig.Cache.IsHealthEstimated(unchecked((int)moss)), "and its health is our estimate");
Check.True(!rig.Cache.IsHealthEstimated(unchecked((int)skulker)), "the fight target gets no estimate (the server sends its health)");
}
private static void SameNameVolley()
{
var rig = new Rig();
uint target = rig.Mob("Olthoi Swarm Soldier", SkulkerWcid, 5, 0);
uint near = rig.Mob("Olthoi Swarm Soldier", SkulkerWcid, 7, 0);
uint far = rig.Mob("Olthoi Swarm Soldier", SkulkerWcid, 20, 0);
rig.Build(target);
rig.Store.SetManualHp(SkulkerWcid, 200);
// One chain: the target, then the nearest other soldier, then the next.
rig.C.HandleChatForDamage("You blast Olthoi Swarm Soldier for 100 points with Lightning Chain VI.");
rig.C.HandleChatForDamage("You blast Olthoi Swarm Soldier for 50 points with Lightning Chain VI.");
rig.C.HandleChatForDamage("You blast Olthoi Swarm Soldier for 20 points with Lightning Chain VI.");
Check.Near(rig.Hp(near), 0.75, 1e-4, "second line -> the nearest other soldier (200 hp, -50)");
Check.Near(rig.Hp(far), 0.90, 1e-4, "third line -> the next one (-20)");
Check.True(!rig.Cache.IsHealthEstimated(unchecked((int)target)), "the first line was the fight target's");
}
private static void HealthEstimates()
{
var rig = new Rig();
uint target = rig.Mob("Drudge Skulker", SkulkerWcid, 5, 0);
uint moss = rig.Mob("Mosswart Worshipper", MosswartWcid, 6, 2);
rig.Build(target);
rig.Store.SetManualHp(MosswartWcid, 100);
int m = unchecked((int)moss);
Check.Near(rig.Hp(moss), -1, 1e-6, "no health known before the hit");
rig.C.HandleChatForDamage("You blast Mosswart Worshipper for 30 points with Flame Ring VI.");
Check.Near(rig.Hp(moss), 0.70, 1e-4, "100 hp, hit for 30 -> 0.70");
System.Threading.Thread.Sleep(900); // next volley
rig.C.HandleChatForDamage("You blast Mosswart Worshipper for 500 points with Flame Ring VI.");
Check.Near(rig.Hp(moss), RynthCore.Plugin.RynthAi.WorldObjectCache.EstimatedHealthFloor, 1e-6,
"an estimate never reads dead (0): only the server says dead");
rig.Cache.OnUpdateHealth(moss, 0.40f);
Check.Near(rig.Hp(moss), 0.40, 1e-6, "the server's number replaces the estimate");
Check.True(!rig.Cache.IsHealthEstimated(m), "and it is no longer an estimate");
rig.Cache.ApplyDamageEstimate(m, 0.0);
Check.Near(rig.Hp(moss), 0.40, 1e-6, "an unknown-max hit never raises a known value");
}
private static void KillsFromOneCast()
{
var rig = new Rig();
uint target = rig.Mob("Olthoi Swarm Soldier", SkulkerWcid, 5, 0);
uint twin = rig.Mob("Olthoi Swarm Soldier", SkulkerWcid, 7, 0);
uint moss = rig.Mob("Mosswart Worshipper", MosswartWcid, 6, 2);
rig.Build(target);
// A cast hits all three; the server has the fight target at 60%.
rig.C.HandleChatForDamage("You blast Olthoi Swarm Soldier for 100 points with Flame Ring VI.");
rig.C.HandleChatForDamage("You blast Olthoi Swarm Soldier for 100 points with Flame Ring VI.");
rig.C.HandleChatForDamage("You blast Mosswart Worshipper for 100 points with Flame Ring VI.");
rig.Cache.OnUpdateHealth(target, 0.60f);
// The next cast kills the twin and the Mosswart (one notice each), not the target.
rig.C.OnKillNotification("Olthoi Swarm Soldier's death is preceded by a sharp, stabbing pain!");
rig.C.OnKillNotification("You slay Mosswart Worshipper viciously enough to impart death several times over!");
Check.True(rig.C.IsKillSuppressed(unchecked((int)twin)), "the same-named twin is the one that died");
Check.True(rig.C.IsKillSuppressed(unchecked((int)moss)), "the Mosswart died");
Check.True(!rig.C.IsKillSuppressed(unchecked((int)target)), "the live fight target is not suppressed");
Check.Eq(rig.C.activeTargetId, unchecked((int)target), "and is still the target");
}
private static void FightTargetKill()
{
var rig = new Rig();
uint target = rig.Mob("Olthoi Swarm Soldier", SkulkerWcid, 5, 0);
uint twin = rig.Mob("Olthoi Swarm Soldier", SkulkerWcid, 7, 0);
rig.Build(target);
rig.C.HandleChatForDamage("You blast Olthoi Swarm Soldier for 100 points with Flame Ring VI.");
rig.C.HandleChatForDamage("You blast Olthoi Swarm Soldier for 100 points with Flame Ring VI.");
rig.Cache.OnUpdateHealth(target, 0f); // ACE: the 0 comes with the lethal hit, before the notice
rig.C.OnKillNotification("Olthoi Swarm Soldier's death is preceded by a sharp, stabbing pain!");
Check.True(rig.C.IsKillSuppressed(unchecked((int)target)), "the fight target died and is suppressed");
Check.Eq(rig.C.activeTargetId, 0, "and dropped");
Check.True(!rig.C.IsKillSuppressed(unchecked((int)twin)), "the twin is untouched");
}
}

View file

@ -49,6 +49,10 @@ internal static class UseRefusalTests
r.Add("move hold: off unless the plugin opts in (RynthNav, RynthLua unchanged)", MoveHoldOptIn);
r.Add("idle peace: Combat's idle peace swap waits while looting has work", IdlePeaceHeldWhileLooting);
r.Add("idle peace: looting has work = a corpse claimed, a corpse open, a corpse in range, or a use in flight", LootHoldsIdlePeaceInputs);
r.Add("use check jump: one jump per back-off, before the probe; none while normal or during the back-off", WatchProbeJump);
r.Add("use check jump (looting): the clean stop jumps (TapJump, not JumpNonAutonomous), the retry waits the pause, an open after it is logged as cleared", LootingStallJumpClears);
r.Add("use check jump (looting): still stuck after the jump -> back-off; the probe goes out only after a jump and the pause", LootingStallJumpBeforeProbe);
r.Add("use check jump: no jump while the server still owes an answer to a cast (a jump would fail it)", NoJumpWhilePacerOutstanding);
}
// ── UseRefusalWatch alone ─────────────────────────────────────────────────
@ -536,4 +540,154 @@ internal static class UseRefusalTests
});
Check.False(Holds(), "all clear: no hold");
}
// ── The jump (2026-10-06 afternoon) ───────────────────────────────────────
// On ACE the player's jump (Player.HandleActionJump) is the one in-world action that empties the
// server's animation queues (the stuck state); the use check jumps at the clean stop and before
// each probe.
private static void WatchProbeJump()
{
var r = new Rig();
int a = unchecked((int)CorpseA), b = unchecked((int)CorpseB);
Check.False(r.W.TakeProbeJump(r.T), "normal: no jump");
r.RefusedOpen(a); r.RefusedOpen(a); r.RefusedOpen(a);
Check.False(r.W.TakeProbeJump(r.T), "retrying: no probe jump (the clean stop jumps itself)");
r.RefusedOpen(a);
Check.Eq(r.RefusedOpen(b), UseRefusalWatch.Verdict.Stuck, "stuck");
Check.False(r.W.TakeProbeJump(r.T), "during the back-off: no jump");
r.T = r.W.BackoffUntil;
Check.True(r.W.TakeProbeJump(r.T), "the back-off is over: jump before the probe");
Check.False(r.W.TakeProbeJump(r.T + 100), "once");
Check.Eq(r.RefusedOpen(b), UseRefusalWatch.Verdict.StillStuck, "the probe refused");
Check.False(r.W.TakeProbeJump(r.T), "a new back-off: no jump yet");
r.T = r.W.BackoffUntil;
Check.True(r.W.TakeProbeJump(r.T), "again once the longer back-off is over");
r.W.OnOpened(r.T);
Check.False(r.W.TakeProbeJump(r.T + UseRefusalWatch.MaxBackoffMs), "after an open: never");
}
/// <summary>The 14:29 server: every open is answered 60 ms later and nothing opens, until the
/// first open after a jump (when <paramref name="jumpClears"/>).</summary>
private static void StallServer(Bot bot, Func<long> now, Action<long> advance, bool jumpClears, int maxSteps, Func<bool> until)
{
long answerAt = 0; uint answerFor = 0;
for (int steps = 0; steps < maxSteps && !until(); steps++)
{
int uses = FakeHost.Uses.Count;
bot.Tick(BotActivity.Looting);
if (FakeHost.Uses.Count > uses) { answerAt = now() + 60; answerFor = FakeHost.Uses.Last(); }
advance(100);
if (answerAt != 0 && now() >= answerAt)
{
FakeHost.UseDone(0);
if (jumpClears && FakeHost.TapJumps > 0)
bot.P.OnViewObjectContents(answerFor);
answerAt = 0;
}
}
}
private static void LootingStallJumpClears()
{
World();
FakeHost.TapJumpCalls = true;
var host = FakeHost.Create(Player);
var bot = new Bot(host);
WithClock((now, advance) =>
{
int usesAtJump = -1; long jumpAt = 0;
StallServer(bot, now, advance, jumpClears: false, maxSteps: 400, until: () =>
{
if (FakeHost.TapJumps > 0 && usesAtJump < 0) { usesAtJump = FakeHost.Uses.Count; jumpAt = now(); }
return usesAtJump >= 0;
});
Check.Eq(FakeHost.TapJumps, 1, "the clean stop jumps once");
Check.Eq(FakeHost.Jumps, 0, "with the keyboard jump, not JumpNonAutonomous (ACE ignores 0xF7C9)");
Check.True(FakeHost.Logs.Any(l => l.Contains("one clean stop, a jump")), "logged");
Check.True(FakeHost.Logs.Any(l => l.Contains("Use check: jump for the retry")), "the jump is logged");
Check.False(FakeHost.Logs.Any(l => l.Contains("Use check: facing")), "no facing turn when it jumps");
// The retry waits for the pause, then the server (cleared by the jump) opens it.
long retryAt = 0;
StallServer(bot, now, advance, jumpClears: true, maxSteps: 100, until: () =>
{
if (retryAt == 0 && FakeHost.Uses.Count > usesAtJump) retryAt = now();
return bot.Get<int>("_openedContainerId") != 0;
});
Check.True(retryAt != 0, "a retry went out");
Check.True(retryAt - jumpAt >= UseRefusalWatch.CleanStopPauseMs, $"after the pause ({retryAt - jumpAt} ms)");
Check.True(FakeHost.Logs.Any(l => l.Contains("after the use check's jump - the jump cleared")), "the open after the jump is logged as the fix");
Check.Eq(ChatCount(StuckLine), 0, "the player is never told to relog");
Check.Eq(bot.Get<UseRefusalWatch>("_useRefusals").State, UseRefusalWatch.Phase.Normal, "back to normal");
});
}
private static void LootingStallJumpBeforeProbe()
{
World();
FakeHost.TapJumpCalls = true;
var host = FakeHost.Create(Player);
var bot = new Bot(host);
WithClock((now, advance) =>
{
StallServer(bot, now, advance, jumpClears: false, maxSteps: 600, until: () => ChatCount(StuckLine) > 0);
Check.Eq(ChatCount(StuckLine), 1, "the jump didn't help here: the player is told once");
Check.Eq(FakeHost.TapJumps, 1, "one jump so far (the clean stop)");
Check.True(FakeHost.Logs.Any(l => l.Contains("the clean stop, the jump and retry didn't help")), "the verdict says the jump was tried");
var w = bot.Get<UseRefusalWatch>("_useRefusals");
int usesAtStuck = FakeHost.Uses.Count;
for (int i = 0; i < 2400; i++) { bot.Tick(BotActivity.Looting); advance(100); } // 4 minutes
Check.Eq(FakeHost.TapJumps, 1, "no jump during the back-off");
Check.Eq(FakeHost.Uses.Count, usesAtStuck, "no opens during the back-off");
long probeJumpAt = 0;
for (int i = 0; i < 700 && FakeHost.Uses.Count == usesAtStuck; i++)
{
bot.Tick(BotActivity.Looting);
if (probeJumpAt == 0 && FakeHost.TapJumps == 2) probeJumpAt = now();
advance(100);
}
Check.Eq(FakeHost.TapJumps, 2, "a jump before the probe");
Check.Eq(FakeHost.Uses.Count, usesAtStuck + 1, "then the probe");
Check.True(now() - 100 - probeJumpAt >= UseRefusalWatch.CleanStopPauseMs, "the probe waits the pause after the jump");
Check.True(FakeHost.Logs.Any(l => l.Contains("Use check: jump before the probe")), "logged");
// The jump cleared it: the probe opens.
bot.P.OnViewObjectContents(FakeHost.Uses.Last());
Check.Eq(ChatCount("Objects open again"), 1, "the player is told uses work again");
Check.True(FakeHost.Logs.Any(l => l.Contains("the jump cleared")), "and the log says the jump did it");
Check.False(w.HoldsOpens(now()), "looting is back on");
});
}
private static void NoJumpWhilePacerOutstanding()
{
World();
FakeHost.TapJumpCalls = true;
var host = FakeHost.Create(Player);
var bot = new Bot(host);
long t = 10_000_000;
ActionPacer.Reset();
ActionPacer.Enabled = true;
ActionPacer.NowMs = () => t;
try
{
ActionPacer.Begin(host, PacedKind.Cast, 0, "Revitalize Self VI", "Buff", FakeHost.UseDoneSeq);
Check.False((bool)bot.Call("TryUseCheckJump", t, "test")!, "no jump while the cast is unanswered");
Check.Eq(FakeHost.TapJumps, 0, "nothing sent");
Check.True(FakeHost.Logs.Any(l => l.Contains("Use check: no jump test - the server still owes an answer")), "logged");
FakeHost.UseDone(0);
t += 50;
Check.True((bool)bot.Call("TryUseCheckJump", t, "test")!, "answered: the jump goes");
Check.Eq(FakeHost.TapJumps, 1, "one jump");
}
finally
{
ActionPacer.Enabled = false;
ActionPacer.Reset();
ActionPacer.NowMs = () => Environment.TickCount64;
}
}
}

View file

@ -22,6 +22,8 @@ internal static class VitalsTests
{
r.Add("vitals: Stamina to Health follows its own health line and stamina floor", StaminaToHealthThresholds);
r.Add("vitals: profiles without the Stamina to Health keys load today's 30 / 20", StaminaToHealthDefaults);
r.Add("vitals: Re-stam To keeps a started recharge going to its line; off = one recharge as before", RestamTo);
r.Add("vitals: out of Magic stance a listed stamina potion goes before Revitalize; a caster casts first", StaminaPotionFirst);
r.Add("vitals: after a kit, nothing else heals until the kit's result line lands", KitResultWait);
r.Add("vitals: Heal Self known only above the tier Life Magic allows (vitae) is still cast", HealAboveAllowedTier);
r.Add("vitals: low health wins the arbiter even on a busy tick; backs off when nothing can heal", HealthWinsArbiter);
@ -210,6 +212,75 @@ internal static class VitalsTests
return cast;
}
// Tom, 2026-10-06: a melee character should drink its listed stamina potions before Revitalize
// (which means switching the weapon for the wand and back).
private static void StaminaPotionFirst()
{
const uint Tincture = 0x80001234;
foreach (int mode in new[] { CombatMode.Melee, CombatMode.Magic })
{
FakeHost.Reset();
FakeHost.WeaponCalls = true;
FakeHost.CombatModeValue = mode;
foreach (var row in SpellTable.Rows) FakeHost.Spellbook.Add((uint)row.Id);
FakeHost.Skills[(Player, STypeLife)] = (400, 2);
FakeHost.Names[Tincture] = "Stamina Tincture";
var host = FakeHost.Create();
var s = new LegacyUiSettings { IsMacroRunning = true, HealAt = 0, TopOffHP = 0, EmergencyHealAt = 0, StaminaToHealthAt = 0,
GetManaAt = 0, TopOffMana = 0, RestamAt = 30, TopOffStam = 95, UsePotions = true, EnableBuffing = false };
s.ConsumableRules.Add(new ConsumableRule { Id = unchecked((int)Tincture), Name = "Stamina Tincture", Type = "Stamina" });
var skills = new CharacterSkills(host);
skills.SetPlayerId(Player);
var sm = new SpellManager(host, s);
sm.InitializeNatively();
sm.SetCharacterSkills(skills);
var vitals = new PlayerVitalsCache { MaxHealth = 100, CurrentHealth = 100, MaxStamina = 100, CurrentStamina = 20, MaxMana = 100, CurrentMana = 100 };
var b = new BuffManager(host, s, sm, vitals);
b.SetCharacterSkills(skills);
b.SetWorldObjectCache(FakeHost.MakeCache(host, Player, new[] { Tincture }));
Check.True(b.CheckVitals(), $"mode {mode}: stamina 20% acts");
bool drank = FakeHost.Uses.Contains(Tincture);
if (mode == CombatMode.Melee)
{
Check.True(drank, "melee: the tincture is drunk");
Check.Eq(FakeHost.Casts.Count, 0, "melee: no Revitalize (no wand switch)");
}
else
{
Check.False(drank, "caster in Magic stance: no potion first");
Check.True(FakeHost.Casts.Count > 0, "caster: Revitalize is cast");
}
}
}
// Tom, 2026-10-06: one Revitalize often doesn't recover enough stamina.
private static void RestamTo()
{
var s = new LegacyUiSettings { RestamAt = 30, RestamTo = 0, TopOffStam = 95 };
bool run = false; int casts = 0;
Check.Eq(BuffManager.StaminaLine(true, 25, s, ref run, ref casts), 30, "off: Re-stam At");
Check.Eq(BuffManager.StaminaLine(true, 40, s, ref run, ref casts), 30, "off: at 40% no recharge");
s.RestamTo = 70;
Check.Eq(BuffManager.StaminaLine(true, 40, s, ref run, ref casts), 30, "above Re-stam At with no recharge started: nothing new");
Check.Eq(BuffManager.StaminaLine(true, 25, s, ref run, ref casts), 70, "under Re-stam At: recharge to 70");
casts++;
Check.Eq(BuffManager.StaminaLine(true, 45, s, ref run, ref casts), 70, "one cast got it to 45%: still recharging (the second cast)");
casts++;
Check.Eq(BuffManager.StaminaLine(true, 72, s, ref run, ref casts), 30, "reached 70: done");
Check.False(run, "the recharge ended");
// A recharge that never gains stops after the cap.
Check.Eq(BuffManager.StaminaLine(true, 20, s, ref run, ref casts), 70, "new recharge");
casts = BuffManager.RestamRunMaxCasts;
Check.Eq(BuffManager.StaminaLine(true, 35, s, ref run, ref casts), 30, "cap reached above Re-stam At: back to Re-stam At");
// Out of combat the top-off line applies, as before.
Check.Eq(BuffManager.StaminaLine(false, 50, s, ref run, ref casts), 95, "idle: Top Stam");
s.RestamTo = 20;
Check.Eq(BuffManager.StaminaLine(true, 25, s, ref run, ref casts), 30, "Re-stam To not above Re-stam At: ignored");
}
private static void StaminaToHealthThresholds()
{
// Defaults: today's behaviour (30% health, stamina over 20%).

View file

@ -0,0 +1,131 @@
using System;
using RynthCore.Plugin.RynthTracker;
using RynthCore.Plugin.Shared;
namespace RynthCore.TrackerSessionTests;
// KillCounter (RynthTracker 0.3.0): one cast, several kills. The events are what the client
// sees, in the order it sees them: our damage lines (one per monster a spell hurt), the
// server's kill notices, and corpses ("Corpse of X") a few seconds later.
internal static partial class Program
{
private static readonly DateTime T0 = new(2026, 10, 3, 2, 0, 0, DateTimeKind.Utc);
private static DateTime At(double seconds) => T0.AddSeconds(seconds);
private static void Hit(KillCounter k, string line, double t)
{
Check(CombatText.TryParseOutgoingHit(line, out string victim, out _), $"parses: {line}");
k.OnHit(victim, At(t));
}
private static void TestKillCounter()
{
Console.WriteLine("-- kill counter");
// ACE ring: every kill gets its notice; the corpses that follow add nothing.
{
var k = new KillCounter();
Hit(k, "You blast Drudge Skulker for 80 points with Flame Ring VI.", 0.0);
Hit(k, "You blast Drudge Slinker for 75 points with Flame Ring VI.", 0.1);
Hit(k, "You blast Mosswart Worshipper for 70 points with Flame Ring VI.", 0.2);
k.OnKillNotice("Drudge Skulker's seared corpse smolders before you!", At(2.0));
k.OnKillNotice("You bring Drudge Slinker to a fiery end!", At(2.1));
k.OnKillNotice("Mosswart Worshipper is incinerated by your assault!", At(2.2));
Eq(k.OnCorpse("Drudge Skulker", At(5.0)), KillCounter.CorpseResult.Notified, "ring: corpse 1 matches its notice");
Eq(k.OnCorpse("Drudge Slinker", At(5.1)), KillCounter.CorpseResult.Notified, "ring: corpse 2 matches its notice");
Eq(k.OnCorpse("Mosswart Worshipper", At(5.2)), KillCounter.CorpseResult.Notified, "ring: corpse 3 matches its notice");
Eq(k.Kills, 3, "ring: three kills, none counted twice");
}
// Conquest chain: the primary's kill has a notice, the extra targets' don't.
{
var k = new KillCounter();
Hit(k, "You blast Drudge Skulker for 120 points with Lightning Chain VI.", 0.0);
Hit(k, "You blast Drudge Slinker for 60 points with Lightning Chain VI.", 0.2);
Hit(k, "You blast Mosswart Worshipper for 30 points with Lightning Chain VI.", 0.4);
k.OnKillNotice("You smite Drudge Skulker mightily!", At(2.0)); // the primary
Hit(k, "You blast Mosswart Worshipper for 30 points with Lightning Chain VI.", 2.2);
// the Slinker died on that cast with no line and no notice
Eq(k.OnCorpse("Drudge Skulker", At(5.0)), KillCounter.CorpseResult.Notified, "chain: the primary's corpse is its notice's");
Eq(k.OnCorpse("Drudge Slinker", At(5.1)), KillCounter.CorpseResult.Counted, "chain: the silent extra kill counts from its corpse");
Hit(k, "You blast Mosswart Worshipper for 30 points with Lightning Chain VI.", 6.0);
Eq(k.OnCorpse("Mosswart Worshipper", At(9.0)), KillCounter.CorpseResult.Counted, "chain: the last extra target too");
Eq(k.Kills, 3, "chain: three kills from the chain fight");
Eq(k.CorpseKills, 2, "chain: two of them found by their corpse");
}
// A swarm: same-named monsters, two die from one cast, one notice.
{
var k = new KillCounter();
Hit(k, "You blast Olthoi Swarm Soldier for 100 points with Lightning Chain VI.", 0.0);
Hit(k, "You blast Olthoi Swarm Soldier for 100 points with Lightning Chain VI.", 0.1);
k.OnKillNotice("Olthoi Swarm Soldier's death is preceded by a sharp, stabbing pain!", At(1.5));
Eq(k.OnCorpse("Olthoi Swarm Soldier", At(4.0)), KillCounter.CorpseResult.Notified, "swarm: first corpse takes the notice");
Eq(k.OnCorpse("Olthoi Swarm Soldier", At(4.1)), KillCounter.CorpseResult.Counted, "swarm: second corpse counts");
Eq(k.OnCorpse("Olthoi Swarm Soldier", At(4.2)), KillCounter.CorpseResult.HitNotCounted, "swarm: never more corpses than the volley hit");
Eq(k.Kills, 2, "swarm: two kills");
}
// The primary's kill notice and an extra target's line in one volley, same name: the
// notice stands for the primary, so the silent twin still counts from its corpse.
{
var k = new KillCounter();
Hit(k, "You blast Olthoi Swarm Soldier for 100 points with Lightning Chain VI.", 0.0); // earlier cast, primary
k.OnKillNotice("You slay Olthoi Swarm Soldier viciously enough to impart death several times over!", At(2.0));
Hit(k, "You blast Olthoi Swarm Soldier for 60 points with Lightning Chain VI.", 2.1); // the twin, same cast
Eq(k.OnCorpse("Olthoi Swarm Soldier", At(5.0)), KillCounter.CorpseResult.Notified, "notice + twin: primary's corpse");
Hit(k, "You blast Olthoi Swarm Soldier for 60 points with Lightning Chain VI.", 5.5); // a lone hit later on the twin
Eq(k.OnCorpse("Olthoi Swarm Soldier", At(8.0)), KillCounter.CorpseResult.Counted, "notice + twin: the twin counts");
Eq(k.Kills, 2, "notice + twin: two kills");
}
// Several casts at the same two monsters are still two monsters (max, not sum).
{
var k = new KillCounter();
for (int cast = 0; cast < 4; cast++)
{
Hit(k, "You blast Drudge Skulker for 10 points with Flame Ring VI.", cast * 2.0);
Hit(k, "You blast Drudge Skulker for 10 points with Flame Ring VI.", cast * 2.0 + 0.1);
}
Eq(k.OnCorpse("Drudge Skulker", At(9.0)), KillCounter.CorpseResult.Counted, "repeat casts: first corpse");
Eq(k.OnCorpse("Drudge Skulker", At(9.1)), KillCounter.CorpseResult.Counted, "repeat casts: second corpse");
Eq(k.OnCorpse("Drudge Skulker", At(9.2)), KillCounter.CorpseResult.HitNotCounted, "repeat casts: not a third");
}
// Single-target fighting: a corpse with no notice is someone else's kill, as before.
{
var k = new KillCounter();
Hit(k, "You slash Banderling Scout for 12 points of slashing damage!", 0.0);
Hit(k, "You slash Banderling Scout for 14 points of slashing damage!", 1.5);
Eq(k.OnCorpse("Banderling Scout", At(4.0)), KillCounter.CorpseResult.HitNotCounted, "single-target: not counted without a notice");
Eq(k.OnCorpse("Tusker Guard", At(4.0)), KillCounter.CorpseResult.NotOurs, "a corpse we never hit");
Eq(k.Kills, 0, "single-target: no kills");
}
// Lines a second apart are separate casts (a melee swing each), not one volley.
{
var k = new KillCounter();
Hit(k, "You slash Banderling Scout for 12 points of slashing damage!", 0.0);
Hit(k, "You slash Banderling Guard for 14 points of slashing damage!", 1.0);
Eq(k.OnCorpse("Banderling Guard", At(3.0)), KillCounter.CorpseResult.HitNotCounted, "a second apart is not multi-target");
}
// Expiry: a multi-target hit stops vouching for a corpse after TokenLifeMs.
{
var k = new KillCounter();
Hit(k, "You blast Drudge Skulker for 10 points with Flame Ring VI.", 0.0);
Hit(k, "You blast Drudge Slinker for 10 points with Flame Ring VI.", 0.1);
Eq(k.OnCorpse("Drudge Slinker", At(0.1 + KillCounter.TokenLifeMs / 1000.0 + 1)), KillCounter.CorpseResult.NotOurs, "an old hit doesn't count");
}
// A notice waits NoticeLifeMs for its corpse, then is forgotten (the kill stays counted).
{
var k = new KillCounter();
k.OnKillNotice("You smite Drudge Skulker mightily!", At(0));
Eq(k.OnCorpse("Drudge Skulker", At(KillCounter.NoticeLifeMs / 1000.0 + 1)), KillCounter.CorpseResult.NotOurs, "an old notice is gone");
Eq(k.Kills, 1, "the notice's kill stays counted");
k.Reset();
Eq(k.Kills, 0, "reset clears the count");
}
}
}

View file

@ -11,7 +11,7 @@ namespace RynthCore.TrackerSessionTests;
// Self-contained; fails on zero assertions.
//
// Run: dotnet run -c Release (exit 0 = pass, 1 = fail)
internal static class Program
internal static partial class Program
{
private static int _asserts;
private static int _fails;
@ -45,6 +45,7 @@ internal static class Program
TestFileNames();
TestFiles();
TestCleanup();
TestKillCounter();
Console.WriteLine($"\n{_asserts} assertions, {_fails} failed.");
if (_asserts == 0) { Console.WriteLine("ABORT: zero assertions ran."); return 1; }

View file

@ -17,6 +17,8 @@
<ItemGroup>
<Compile Include="..\..\Plugins\RynthCore.Plugin.RynthTracker\TrackerSessionStore.cs" Link="Linked\TrackerSessionStore.cs" />
<Compile Include="..\..\Plugins\RynthCore.Plugin.RynthTracker\KillCounter.cs" Link="Linked\KillCounter.cs" />
<Compile Include="..\..\Plugins\Shared\CombatText.cs" Link="Linked\CombatText.cs" />
</ItemGroup>
</Project>