RynthSuite/Plugins/RynthCore.Plugin.RynthAi/Combat/CastGateWatchdog.cs
Daniel Wallace 486f72de58 Vitals: heal grace - a heal never waits more than 2 s on pending state
"Stuck in Healing": a healing kit got no result line, and no vitals
action followed for 8 s and more with the label reading Healing; the
character died. The kit wait's timeout was 8 s.

VirindiTank re-sends a kit every 100 ms until the server plays the heal
motion (3 s at most), then waits up to 3 s for the result line. It never
parks on the client's busy state.

ActionPacer.HealGraceMs (2000) bounds what a heal under a heal line waits on:
- the kit wait (KitWaitVerdict): no motion, no UseDone and no line after
  2 s lets the kit go and the next tick sends it again; the kit's own
  UseDone(0) (the first after the send) with no line ends it after 700 ms;
  a started kit waits 3.5 s at most (KitResultTimeoutMs, was 8 s; stamina
  kits share this wait). An engine with neither GetCastBusyState nor the
  UseDone sequence can't show the server took a kit, so there only the
  3.5 s limit applies;
- an item use nobody answered (a lost kit) no longer holds the heal past
  2 s (corpse/door uses and our own casts keep their rules);
- the character's animation: 2 s for a plain heal (was 4 s), logged and
  counted once per busy spell;
- the 'too busy' probe for a waiting heal: at least every 2 s;
- the cast gate: closed 2 s under a heal line opens for the heal only
  (no mana, stamina or buff goes on that tick);
- a busy count: up 2 s (timed from its rise) no longer holds a heal.

Tests: HealGraceTests (new, 10), StuckCastTests' probe test split into the
non-heal doubling and the heal's capped probe.

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

72 lines
3.1 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System;
namespace RynthCore.Plugin.RynthAi;
/// <summary>
/// Stuck-state backstop for the engine's CMotionInterp cast-gesture gate
/// (<c>_host.CanCastNow</c>). That gate reads <c>[CMI+0x80]</c>; if it ever
/// stays non-zero indefinitely — a server-refused "You're too busy!" can leave
/// a one-shot motion node that never pops, and the +0x80 offset was never 100%
/// pinned offline — BOTH the buff (<c>BuffManager.OnHeartbeat</c>) and combat
/// (<c>CombatManager</c> magic) paths hard-return on <c>!CanCastNow</c> every
/// tick and the bot freezes standing in place. The engine has no self-recovery
/// for this and there is no BusyCount-style watchdog.
///
/// Logic: pass the gate through untouched while it behaves; if it has been
/// continuously closed longer than any legitimate cast wind-up+release, declare
/// it stuck and report "clear", then keep reporting clear until the engine gate
/// genuinely recovers (raw == true again). When overriding we are exactly in
/// the documented "engine without the gate" mode (CanCastNow defaults true) —
/// the <c>SpellCastIntervalMs</c> throttle and the "too busy" PARK path remain
/// the anti-spam guarantees, so this cannot reintroduce the 0x00460D1D
/// refusal-loop AV.
/// </summary>
internal static class CastGateWatchdog
{
// Longer than any real AC cast gesture (~1–3s). Continuously closed past
// this ⇒ the gate is stuck, not a legitimate in-progress gesture.
private const double StuckMs = 4000;
private static DateTime _closedSince = DateTime.MinValue;
private static bool _overriding;
/// <summary>How long the raw gate has read closed (0 = open), as of the last CanCastNow call.
/// A heal under a heal line goes past ActionPacer.HealGraceMs of it (BuffManager).</summary>
public static double ClosedMs => _closedSince == DateTime.MinValue ? 0 : (RynthClock.Now - _closedSince).TotalMilliseconds;
/// <summary>
/// Effective "clear to cast": the raw engine gate plus a stuck backstop.
/// Call with <c>_host.CanCastNow</c>; optionally pass a logger for the
/// one-shot stuck/recovered transitions.
/// </summary>
public static bool CanCastNow(bool rawCanCastNow, Action<string>? log = null)
{
if (rawCanCastNow)
{
if (_overriding)
{
log?.Invoke("[CastGate] engine gate recovered — stuck override cleared.");
_overriding = false;
}
_closedSince = DateTime.MinValue;
return true;
}
// Raw gate reports a gesture in progress.
if (_overriding)
return true; // already declared stuck; stay open until the engine gate recovers
if (_closedSince == DateTime.MinValue)
_closedSince = RynthClock.Now;
if ((RynthClock.Now - _closedSince).TotalMilliseconds > StuckMs)
{
_overriding = true;
log?.Invoke($"[CastGate] CanCastNow stuck false >{StuckMs:F0}ms — overriding gate open " +
"(SpellCastIntervalMs throttle + 'too busy' PARK remain the anti-spam backstop).");
return true;
}
return false;
}
}