Two casts were held open 40.8 s and 37 s by ACE's fast-tick turn-to-cast wait; every later send was answered UseDone 0x1D and a heal was re-sent every 2.5 s. - ActionPacer: after a 0x1D UseDone nothing starts until the server answers; with no cast of ours open, one probe after 1.5 s, then doubling (max 6 s). Attack repeats are not held (ACE sends no UseDone for a swing), and a latch with no cast of ours open ends after LatchMaxMs (15 s). A cast still unanswered 1 s past its normal cycle (learned per spell, at least 3 s) is turned to face its target; 2 s past it (capped by Stuck Cast Break, default 8000 ms) or on a 0x1D while it has been open 3 s, it is broken with a jump (TapJump; ACE fails a cast on a fast-tick jump). Starts wait until landed; no UseDone 3 s after landing -> Peace mode; 3 s more -> going on. Every hold is bounded: a cast StaleCastMs old, or sent before a frame gap of 5 s (keyed on the gap's end), is dropped with the latch, never broken. No breaker step in portal space; Forget on portal-enter and the death hold. A burst of 5 'too busy' answers in a second holds every start except a heal. A refused forced jump with no cast open leaves no breaker stage. A cast a script chose (the combat hook) is not jumped before 6 s from its send (ScriptCastMinBreakMs, the held-cast nudge's HeldAfterIncantMs). Stuck Cast Break is read from the settings once per tick. - MoveAudit: no start in the tick of a movement change; 150 ms and a clear motion queue (or 600 ms) let it go. A held stop sent later by FlushPendingStops counts as a movement change too; the forced flush in CastSpellFor still goes out in the same tick as the cast that follows it. - Blacklist: casts answered 0x1D (or unanswered while the server is busy) are not no-damage casts. - Combat hook: ctx.pending is the cast in flight; ctx.last is the most recent RESOLVED cast, its err final (the first UseDone after its send; nil only when none could be read: 7 s timeout, or another answer came first). The casts in flight of both kinds resolve in send order through one queue. The send-time UseDone count comes from the pacer (LastCastSeqAtSend). CombatRequestV1 appends Resolved*/Pending* fields (StructSize-gated, no Version bump); an older RynthAi keeps the old ctx.last. - HP failsafe (BuffManager.HpFailsafe.cs): at or under Emergency Heal At with no heal landing for 3 rounds of 2.5 s, a forced jump; 3 more rounds, the macro stops and /lifestone goes out (HP Failsafe Recall, default on). Nothing counts in portal space; a pending recall is dropped on death; a recall that never starts turns the macro back on (only one the failsafe stopped, never past the VTank yield) and re-arms after a 30 s cooldown. Recovery retry: recovery vitals (Heal Self, Stamina to Health, Revitalize, Stamina to Mana) refused for "not enough mana" retry after Recovery Retry (200 ms, a setting) instead of resting the family: ACE rolls Mana Conversion on every attempt before the windup and a refusal costs nothing. At most 5 recovery casts a second, 20 refusals in a row, stamina and Mana Conversion checks, an episode with no refusal for 7 s ends; an episode summary line. Stamina to Mana and Revitalize are still held under their cost by the mana reserve (AttemptVitalCast), so for them the retry applies when the mana reading is stale or costs are unknown; Heal Self and Stamina to Health, which are tried below cost, gain the most. When the retry stops, the vital rests as the existing mana reserve has it (LowManaHealRestSec, 2 s). Script heals and other casts are unchanged. Tests: StuckCastTests (incl. the script cast's break floor), PacerEdgeTests, RecoveryRetryTests (incl. costs known: Stamina to Mana held), HpFailsafeTests, CombatHookTests (ctx.last/ctx.pending, send order, an answer during the send, 0x1D blacklist, script heal keeps its rest, script attack and heal not jumped before 6 s with or without a 'too busy' answer); HealLatencyTests' and ManaReserveTests' low-mana rest cases pin untrained Mana Conversion; RynthLua compat combathook.lua. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
364 lines
17 KiB
C#
364 lines
17 KiB
C#
using System;
|
|
using System.Linq;
|
|
using RynthCore.Plugin.Shared;
|
|
using RynthCore.PluginSdk;
|
|
using RynthCore.RynthAiHostTests.Fakes;
|
|
using RynthCore.RynthAiTests.Harness;
|
|
|
|
namespace RynthCore.RynthAiHostTests.Tests;
|
|
|
|
// In a client log, two casts were held open by ACE's fast-tick turn-to-cast wait (40.8 s and 37 s);
|
|
// every cast after them came back UseDone 0x1D and the vitals path re-sent a heal every 2.5 s. A
|
|
// client mode change ended the second. ActionPacer now holds every start after a 0x1D until the
|
|
// server answers, turns to face a held cast's target, breaks a stuck cast with a jump (then Peace
|
|
// mode), waits until landed, and holds starts until a movement change has settled.
|
|
internal static class StuckCastTests
|
|
{
|
|
private const uint Player = 0x50000F01;
|
|
private const uint Monster = 0x80116781;
|
|
private const int DrainHealthOtherI = 1237;
|
|
private static (uint Cell, float X, float Y, float Z) Me0 => (0x6347028Au, 100f, 100f, 0f);
|
|
|
|
public static void Register(Runner r)
|
|
{
|
|
r.Add("stuck cast: after a 'too busy' UseDone nothing starts until the server answers; no timer re-send while our cast is open", NoResendAfterTooBusy);
|
|
r.Add("stuck cast: with no cast of ours open, one probe after 1.5 s, then doubling; a UseDone(0) clears", ProbeWhenNothingOpen);
|
|
r.Add("stuck cast: a held cast is turned to its target at cycle + 1 s, broken by a jump at cycle + 2 s; a normal 4 s cast trips neither", TurnThenJump);
|
|
r.Add("stuck cast: no starts in the air; after landing, no UseDone in 3 s -> Peace mode, 3 s more -> going on", AfterTheJump);
|
|
r.Add("stuck cast: a 'too busy' answer while our cast is open past 3 s breaks it at once; before 3 s it does not", RefusalWhileOpen);
|
|
r.Add("stuck cast: StuckCastMs 0 turns nothing and breaks nothing; no TapJump -> Peace mode", BreakerOffAndNoJump);
|
|
r.Add("move settle: no start in the tick of a movement change; 150 ms and a clear motion queue (or 600 ms) let it go", MoveSettle);
|
|
r.Add("stuck cast: the HP failsafe's forced break jumps once and holds starts until landed", ForcedBreak);
|
|
r.Add("stuck cast: a script's cast is not jumped before ScriptCastMinBreakMs (6 s): answered at 5.5 s, no jump; RynthAi's own is jumped at 5 s", ScriptCastGetsNudgeWindow);
|
|
}
|
|
|
|
private static long _t;
|
|
|
|
private static RynthCoreHost Setup(int mode = ActionPacer.MagicMode, bool tapJump = true)
|
|
{
|
|
FakeHost.Reset();
|
|
FakeHost.ServerGates = true;
|
|
FakeHost.LastUseDoneCalls = true;
|
|
FakeHost.WeaponCalls = true; // GetCurrentCombatMode
|
|
FakeHost.CombatModeCalls = true; // ChangeCombatMode
|
|
FakeHost.TapJumpCalls = tapJump;
|
|
FakeHost.CombatModeValue = mode;
|
|
FakeHost.Names[Player] = "Mira";
|
|
FakeHost.PlayerPose = Me0;
|
|
FakeHost.Positions[Player] = Me0;
|
|
FakeHost.HeadingDeg = 0; // facing north
|
|
FakeHost.Positions[Monster] = (Me0.Cell, Me0.X + 10f, Me0.Y, Me0.Z); // due east: 90 deg off
|
|
var host = FakeHost.Create(Player);
|
|
_t = 90_000_000;
|
|
ActionPacer.Reset();
|
|
ActionPacer.Enabled = true;
|
|
ActionPacer.NowMs = () => _t;
|
|
MoveAudit.Reset();
|
|
MoveAudit.NowMs = () => _t;
|
|
ActionPacer.StuckCastMs = 8000;
|
|
FakeHost.UseDone(0); // an earlier action's answer: the observer's baseline
|
|
return host;
|
|
}
|
|
|
|
private static void Done()
|
|
{
|
|
ActionPacer.Enabled = false;
|
|
ActionPacer.Reset();
|
|
ActionPacer.NowMs = () => Environment.TickCount64;
|
|
MoveAudit.Reset();
|
|
MoveAudit.NowMs = () => Environment.TickCount64;
|
|
ActionPacer.StuckCastMs = 8000;
|
|
}
|
|
|
|
private static bool May(RynthCoreHost host, HealNeed heal = HealNeed.Heal) =>
|
|
ActionPacer.MayStart(host, "Buff", heal, out _);
|
|
|
|
private static void Cast(RynthCoreHost host, string label = "Drain Health Other I") =>
|
|
Check.True(host.CastSpellFor(Monster, DrainHealthOtherI, "Buff", label), "cast sent");
|
|
|
|
private static int JumpLines() => FakeHost.Logs.Count(l => l.Contains("stuck cast broken by jump after"));
|
|
|
|
private static void Run(RynthCoreHost host, long ms) { for (long s = 0; s < ms; s += 100) { _t += 100; May(host); } }
|
|
|
|
private static void ScriptCastGetsNudgeWindow()
|
|
{
|
|
// Control: RynthAi's own cast of a spell with no learned cycle (3 s) is jumped at cycle + 2 s.
|
|
var own = Setup();
|
|
try
|
|
{
|
|
Cast(own);
|
|
Run(own, 5500);
|
|
Check.Eq(JumpLines(), 1, "RynthAi's own cast: jumped by 5.5 s (at 5 s)");
|
|
}
|
|
finally { Done(); }
|
|
|
|
// The same cast chosen by a script, answered at 5.5 s: no jump.
|
|
var host = Setup();
|
|
try
|
|
{
|
|
Cast(host);
|
|
ActionPacer.MarkScriptCast(DrainHealthOtherI);
|
|
Run(host, 5500);
|
|
Check.Eq(JumpLines(), 0, "a script's cast: no jump in the first 5.5 s");
|
|
FakeHost.UseDone(0); // its answer
|
|
Run(host, 3000);
|
|
Check.Eq(JumpLines(), 0, "answered: never jumped");
|
|
}
|
|
finally { Done(); }
|
|
|
|
// A script's cast with no answer is still broken, once ScriptCastMinBreakMs has passed.
|
|
var held = Setup();
|
|
try
|
|
{
|
|
Cast(held);
|
|
ActionPacer.MarkScriptCast(DrainHealthOtherI);
|
|
Run(held, ActionPacer.ScriptCastMinBreakMs + 200);
|
|
Check.Eq(JumpLines(), 1, "unanswered: jumped after ScriptCastMinBreakMs");
|
|
}
|
|
finally { Done(); }
|
|
}
|
|
|
|
private static void NoResendAfterTooBusy()
|
|
{
|
|
var host = Setup();
|
|
ActionPacer.StuckCastMs = 0; // the hold alone (the breaker has its own tests)
|
|
try
|
|
{
|
|
Check.True(May(host), "free at first");
|
|
Cast(host); // the cast the server will hold open: no UseDone
|
|
_t += 500;
|
|
Check.False(May(host), "our cast is unanswered");
|
|
|
|
// Past CastMaxMs (7 s) the pacer used to "go on" and the heal went out into a busy server.
|
|
_t += ActionPacer.CastMaxMs - 500;
|
|
Check.False(May(host), "unanswered past CastMaxMs: still held (the cast is hung, the server is busy with it)");
|
|
Check.True(ActionPacer.ServerBusy, "the server is taken as busy");
|
|
|
|
// A cast the player sent by hand is refused: 0x1D. Still nothing goes for 13 s (no timer re-send).
|
|
FakeHost.UseDone(ActionPacer.TooBusyErr);
|
|
bool any = false;
|
|
for (int i = 0; i < 130; i++) { _t += 100; any |= May(host); }
|
|
Check.False(any, "nothing goes for 13 s after the 0x1D while our cast is hung");
|
|
Check.True(FakeHost.Logs.Any(l => l.Contains("Buff waits:") && l.Contains("has had no answer")), "the hold is logged");
|
|
Check.Eq(FakeHost.Logs.Count(l => l.Contains("Buff waits:") && l.Contains("has had no answer")), 1, "once");
|
|
|
|
// The server finally answers (the cast's own UseDone): everything goes again.
|
|
FakeHost.UseDone(0x402);
|
|
Check.True(May(host), "a UseDone with another error clears the hold");
|
|
Check.False(ActionPacer.ServerBusy, "not busy any more");
|
|
Check.True(FakeHost.Logs.Any(l => l.Contains("the server answered again (UseDone 0x402)")), "logged");
|
|
}
|
|
finally { Done(); }
|
|
}
|
|
|
|
private static void ProbeWhenNothingOpen()
|
|
{
|
|
var host = Setup();
|
|
try
|
|
{
|
|
Check.True(May(host), "free");
|
|
Cast(host, "Heart Rend");
|
|
_t += 100;
|
|
FakeHost.UseDone(ActionPacer.TooBusyErr); // refused: the server is busy with something of no UseDone (a pickup)
|
|
Check.False(May(host), "held right after the 0x1D");
|
|
_t += ActionPacer.BusyProbeMs - 1;
|
|
Check.False(May(host), "held until BusyProbeMs");
|
|
_t += 1;
|
|
Check.True(May(host), "one probe at BusyProbeMs");
|
|
Check.False(May(host), "only one");
|
|
Cast(host, "Heart Rend");
|
|
_t += 100;
|
|
FakeHost.UseDone(ActionPacer.TooBusyErr); // refused again
|
|
_t += ActionPacer.BusyProbeMs * 2 - 101;
|
|
Check.False(May(host), "the next probe waits twice as long");
|
|
_t += 1;
|
|
Check.True(May(host), "second probe at 2 x BusyProbeMs");
|
|
Check.Eq(FakeHost.TapJumps + FakeHost.CombatModeRequests.Count, 0, "no breaker: no cast of ours was left open");
|
|
Cast(host, "Heart Rend");
|
|
_t += 900;
|
|
FakeHost.UseDone(0);
|
|
Check.True(May(host), "a UseDone(0) clears it");
|
|
}
|
|
finally { Done(); }
|
|
}
|
|
|
|
private static void TurnThenJump()
|
|
{
|
|
var host = Setup();
|
|
try
|
|
{
|
|
// A normal 4 s cast: answered; it sets the spell's cycle (4 s) and trips nothing.
|
|
Check.True(May(host), "free");
|
|
Cast(host);
|
|
_t += 4000;
|
|
FakeHost.UseDone(0);
|
|
May(host); // the answer seen at 4000 ms
|
|
Run(host, 10_000);
|
|
Check.Eq(FakeHost.Turns + FakeHost.TapJumps + FakeHost.CombatModeRequests.Count, 0, "a normal 4 s cast: no turn, no jump, no mode change");
|
|
Check.Eq(ActionPacer.NormalCycleMs(DrainHealthOtherI), 4000L, "the cycle learned from it");
|
|
|
|
// The next one is held open: turn at 4 + 1 s, jump at 4 + 2 s.
|
|
Cast(host);
|
|
long sent = _t;
|
|
while (_t - sent < 4900) { _t += 100; May(host); }
|
|
Check.Eq(FakeHost.Turns, 0, "no turn before cycle + 1 s");
|
|
_t += 100; May(host);
|
|
Check.Eq(FakeHost.Turns, 1, "turned at cycle + 1 s");
|
|
Check.Near(FakeHost.HeadingDeg, 90.0, 0.5, "to face the target (east)");
|
|
Check.True(FakeHost.Logs.Any(l => l.Contains("held cast:") && l.Contains("turning 90 deg to face 0x80116781")), "logged");
|
|
while (_t - sent < 5900) { _t += 100; Check.False(May(host), "held"); }
|
|
Check.Eq(FakeHost.TapJumps, 0, "no jump before cycle + 2 s");
|
|
_t += 100; May(host);
|
|
Check.Eq(FakeHost.TapJumps, 1, "the breaker jump at cycle + 2 s");
|
|
Check.True(FakeHost.Logs.Any(l => l.Contains("[Pace] stuck cast broken by jump after 6000 ms")), "logged with the time");
|
|
Run(host, 2000);
|
|
Check.Eq(FakeHost.TapJumps, 1, "one jump");
|
|
Check.Eq(FakeHost.Turns, 1, "one turn");
|
|
|
|
// The fizzle (0x402): free again once landed.
|
|
FakeHost.UseDone(0x402);
|
|
Check.True(May(host), "free after the cast's UseDone");
|
|
}
|
|
finally { Done(); }
|
|
}
|
|
|
|
private static void AfterTheJump()
|
|
{
|
|
var host = Setup();
|
|
try
|
|
{
|
|
Check.True(May(host), "free");
|
|
Cast(host);
|
|
long sent = _t;
|
|
while (FakeHost.TapJumps == 0 && _t - sent < 10_000) { _t += 100; May(host); }
|
|
Check.Eq(_t - sent, ActionPacer.DefaultCycleMs + ActionPacer.JumpAfterMs, "unknown spell cycle: the jump at 3 + 2 s");
|
|
long jumped = _t;
|
|
// In the air: even with the cast's UseDone in, nothing starts.
|
|
FakeHost.PlayerPose = (Me0.Cell, Me0.X, Me0.Y, Me0.Z + 0.6f);
|
|
FakeHost.UseDone(0x402);
|
|
_t += 200;
|
|
Check.False(May(host), "in the air: held even with the UseDone in");
|
|
Check.True(ActionPacer.BreakerAirborne, "airborne");
|
|
_t += 300;
|
|
Check.False(May(host), "still above the take-off height at 500 ms");
|
|
FakeHost.PlayerPose = Me0;
|
|
Check.True(May(host), "landed: free (the cast was answered)");
|
|
|
|
// A second hung cast: jump, land, no answer: Peace mode 3 s after landing, then going on 3 s later.
|
|
Cast(host);
|
|
sent = _t;
|
|
while (FakeHost.TapJumps < 2 && _t - sent < 10_000) { _t += 100; May(host); }
|
|
Check.Eq(FakeHost.TapJumps, 2, "jumped");
|
|
_t += ActionPacer.JumpLandMinMs; May(host); // landed (height unchanged)
|
|
long landed = _t;
|
|
while (_t - landed < ActionPacer.BreakerWaitMaxMs - 100) { _t += 100; Check.False(May(host), "held after landing, no answer"); }
|
|
Check.Eq(FakeHost.CombatModeRequests.Count, 0, "no Peace yet");
|
|
_t += 100; May(host);
|
|
Check.Eq(string.Join(",", FakeHost.CombatModeRequests), ActionPacer.PeaceMode.ToString(), "Peace requested once, 3 s after landing");
|
|
Check.True(FakeHost.Logs.Any(l => l.Contains("stuck cast broken by Peace mode after")), "logged");
|
|
FakeHost.CombatModeValue = ActionPacer.PeaceMode;
|
|
Run(host, ActionPacer.BreakerWaitMaxMs);
|
|
Check.True(FakeHost.Logs.Any(l => l.Contains("no UseDone after the stuck-cast break")), "going on, logged");
|
|
_t += ActionPacer.ModeSettleMs;
|
|
Check.True(May(host), "free after it");
|
|
Check.Eq(FakeHost.CombatModeRequests.Count, 1, "one Peace request");
|
|
}
|
|
finally { Done(); }
|
|
}
|
|
|
|
private static void RefusalWhileOpen()
|
|
{
|
|
var host = Setup();
|
|
try
|
|
{
|
|
Check.True(May(host), "free");
|
|
Cast(host);
|
|
_t += 2000;
|
|
Cast(host, "Rushed Recovery"); // a heal let ahead of it: refused, 2 s in (a recoil refusal is normal)
|
|
FakeHost.UseDone(ActionPacer.TooBusyErr);
|
|
_t += 100; May(host);
|
|
Check.Eq(FakeHost.TapJumps, 0, "a 0x1D at 2 s: no jump");
|
|
_t += 900; May(host);
|
|
Check.Eq(FakeHost.TapJumps, 1, "past RefusalBreakMinMs with a 0x1D in: jump at once (before cycle + 2 s)");
|
|
Check.True(FakeHost.Logs.Any(l => l.Contains("was refused 'too busy' while it was open")), "the reason is logged");
|
|
}
|
|
finally { Done(); }
|
|
}
|
|
|
|
private static void BreakerOffAndNoJump()
|
|
{
|
|
var host = Setup();
|
|
try
|
|
{
|
|
ActionPacer.StuckCastMs = 0;
|
|
Check.True(May(host), "free");
|
|
Cast(host);
|
|
Run(host, 30_000);
|
|
Check.Eq(FakeHost.Turns + FakeHost.TapJumps + FakeHost.CombatModeRequests.Count, 0, "StuckCastMs 0: nothing");
|
|
}
|
|
finally { Done(); }
|
|
|
|
host = Setup(tapJump: false);
|
|
try
|
|
{
|
|
Check.True(May(host), "free");
|
|
Cast(host);
|
|
Run(host, 6000);
|
|
Check.Eq(string.Join(",", FakeHost.CombatModeRequests), ActionPacer.PeaceMode.ToString(), "no TapJump: Peace mode at the jump time");
|
|
Check.True(FakeHost.Logs.Any(l => l.Contains("no TapJump on this engine")), "logged");
|
|
}
|
|
finally { Done(); }
|
|
}
|
|
|
|
private static void MoveSettle()
|
|
{
|
|
var host = Setup();
|
|
try
|
|
{
|
|
FakeHost.AutoRun = true;
|
|
Check.True(May(host), "free");
|
|
host.SetAutoRunBy("Nav", true);
|
|
_t += 1000;
|
|
host.SetAutoRunBy("Nav", false); // nav's stop goes out this tick
|
|
Check.False(May(host), "no cast in the tick of the stop");
|
|
Check.True(ActionPacer.MayStart(host, "Combat", HealNeed.None, out _, animationGate: false, settleGate: false, attackRepeat: true), "an attack repeat is not held");
|
|
_t += MoveAudit.MoveSettleMinMs - 1;
|
|
Check.False(May(host), "held under MoveSettleMinMs");
|
|
_t += 1;
|
|
FakeHost.CastBusy = 1; // the client still animates the stop
|
|
Check.False(May(host), "the motion queue still busy: held");
|
|
FakeHost.CastBusy = 0;
|
|
Check.True(May(host), "settled: free");
|
|
Check.True(FakeHost.Logs.Any(l => l.Contains("SetAutoRun(False) sent") && l.Contains("has not settled")), "logged");
|
|
|
|
host.TurnToHeadingBy("Nav", 45f);
|
|
FakeHost.CastBusy = 1;
|
|
_t += MoveAudit.MoveSettleMaxMs - 1;
|
|
Check.False(May(host), "busy queue: held under MoveSettleMaxMs");
|
|
_t += 1;
|
|
// The gesture gate itself would still hold a busy queue; the settle gate lets go at its max.
|
|
Check.True(!MoveAudit.SettleHolds(host, out _), "the settle gate lets go at MoveSettleMaxMs");
|
|
FakeHost.CastBusy = 0;
|
|
}
|
|
finally { Done(); }
|
|
}
|
|
|
|
private static void ForcedBreak()
|
|
{
|
|
var host = Setup();
|
|
try
|
|
{
|
|
Check.True(ActionPacer.ForceBreak(host, "HP failsafe"), "the forced break goes");
|
|
Check.Eq(FakeHost.TapJumps, 1, "one jump");
|
|
Check.False(ActionPacer.ForceBreak(host, "HP failsafe"), "not twice while in the air");
|
|
FakeHost.PlayerPose = (Me0.Cell, Me0.X, Me0.Y, Me0.Z + 0.5f);
|
|
_t += 300;
|
|
Check.False(May(host), "in the air: held");
|
|
FakeHost.PlayerPose = Me0;
|
|
_t += 200;
|
|
Check.True(May(host), "landed: free (nothing of ours was open)");
|
|
Check.True(FakeHost.Logs.Any(l => l.Contains("stuck cast broken by jump after 0 ms") && l.Contains("HP failsafe")), "logged");
|
|
}
|
|
finally { Done(); }
|
|
}
|
|
}
|