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>
This commit is contained in:
parent
7166d256ce
commit
486f72de58
6 changed files with 553 additions and 18 deletions
|
|
@ -839,6 +839,7 @@ public partial class BuffManager : IDisposable
|
|||
get => _busyCount;
|
||||
set
|
||||
{
|
||||
if (value > 0 && _busyCount <= 0) _busyRoseAt = Now; // heal grace counts from the rise (BusyHoldsHeal)
|
||||
_busyCount = value;
|
||||
_busyGate.NoteCount(value, UseDoneSeqNow());
|
||||
}
|
||||
|
|
@ -868,16 +869,32 @@ public partial class BuffManager : IDisposable
|
|||
{
|
||||
if (BusyCount <= 0) return false;
|
||||
bool gesture = _host.HasGetCastBusyState && !_host.CanCastNow;
|
||||
if (!_busyGate.IsStale(BusyCount, _host.HasUseDoneSeq, UseDoneSeqNow(), gesture)) return true;
|
||||
string why;
|
||||
if (_busyGate.IsStale(BusyCount, _host.HasUseDoneSeq, UseDoneSeqNow(), gesture))
|
||||
why = "the server finished the action (UseDone)";
|
||||
else
|
||||
{
|
||||
// Heal grace (ActionPacer.HealGraceMs): a count up this long goes too, timed from its rise so
|
||||
// it does not stack on top of the pacer's own hold. The count can't say what it is waiting for
|
||||
// (a lost UseDone leaves it up until the 5 s force-clear), and the cast gate and the pacer still
|
||||
// hold a gesture that is really animating.
|
||||
double upMs = (Now - _busyRoseAt).TotalMilliseconds;
|
||||
if (upMs < ActionPacer.HealGraceMs) return true;
|
||||
why = $"the count has been up {upMs:0} ms (heal grace)";
|
||||
}
|
||||
int was = BusyCount;
|
||||
StaleBusyClears++;
|
||||
_onStaleBusy?.Invoke($"vitals: health is under a heal line and the server finished the action (UseDone) — was {was}");
|
||||
_onStaleBusy?.Invoke($"vitals: health is under a heal line and {why} - was {was}");
|
||||
if (BusyCount > 0) BusyCount = 0; // no callback, or the shared mirror was already 0
|
||||
_busyGate.Reset();
|
||||
return false;
|
||||
}
|
||||
/// <summary>Times a heal found the busy count was a leftover and went ahead (tests, status).</summary>
|
||||
internal int StaleBusyClears { get; private set; }
|
||||
// When the busy count last rose from 0 (heal grace, BusyHoldsHeal).
|
||||
private DateTime _busyRoseAt = DateTime.MinValue;
|
||||
// This tick's cast gate was opened by the heal grace only: CheckVitals does the health block, nothing after it.
|
||||
private bool _gateGraceTick;
|
||||
|
||||
/// <summary>
|
||||
/// Record-only diagnostic (D4): the reason the most recent buff-decision cycle
|
||||
|
|
@ -1336,6 +1353,8 @@ public partial class BuffManager : IDisposable
|
|||
public void OnHeartbeat()
|
||||
{
|
||||
bool track = _settings.IsMacroRunning && _vitals.MaxHealth > 0;
|
||||
_gateGraceTick = false;
|
||||
NoteKitProgress();
|
||||
_healHold = "";
|
||||
_healHoldDetail = "";
|
||||
_healWaitKind = "";
|
||||
|
|
@ -1742,10 +1761,16 @@ public partial class BuffManager : IDisposable
|
|||
// NeedsAnyBuff and is the sole writer of the "Buffing" string.
|
||||
// A heal goes ahead of a busy count the server has already finished (BusyHoldsHeal);
|
||||
// everything else still waits for the count to drop.
|
||||
// Heal grace (ActionPacer.HealGraceMs): with health under a heal line, a gate closed this long opens
|
||||
// for the vitals step (CastGateWatchdog's own backstop is 4 s, for every cast).
|
||||
bool healLine = ActiveHealLine(_vitals.HealthPct, _vitals.StaminaPct, out _, out _).Length > 0;
|
||||
bool gateOpen = _fastChainTick || CastGateWatchdog.CanCastNow(_host.CanCastNow, s => _host.Log(s));
|
||||
bool gateGrace = !gateOpen && healLine && CastGateWatchdog.ClosedMs >= ActionPacer.HealGraceMs;
|
||||
if (gateGrace) gateOpen = true; // the heal only: no mana, stamina or buff goes this tick
|
||||
_gateGraceTick = gateGrace;
|
||||
bool busyHolds = BusyCount > 0
|
||||
&& !_pacerLetHealAhead // the pacing let this heal go ahead of an unanswered corpse use (its rules)
|
||||
&& (ActiveHealLine(_vitals.HealthPct, _vitals.StaminaPct, out _, out _).Length == 0 || BusyHoldsHeal());
|
||||
&& (!healLine || BusyHoldsHeal());
|
||||
if (!gateOpen || busyHolds)
|
||||
{
|
||||
LastBuffSkipReason = busyHolds ? "busy (BusyCount>0)" : "cast gate closed (CanCastNow=false / gesture animating)";
|
||||
|
|
@ -1759,6 +1784,11 @@ public partial class BuffManager : IDisposable
|
|||
if (_healHold.Length == 0) Hold(_healWaitKind.Length > 0 ? _healWaitKind : "vitals step busy", _vitalWhy);
|
||||
return;
|
||||
}
|
||||
if (gateGrace)
|
||||
{
|
||||
Hold("cast gate (a gesture is animating)");
|
||||
return;
|
||||
}
|
||||
|
||||
// /ra swaptest: the wand swap and one cast, timed (BuffManager.SwapTest.cs). After the vitals.
|
||||
if (TickSwapTest())
|
||||
|
|
@ -2120,6 +2150,10 @@ public partial class BuffManager : IDisposable
|
|||
if (HealthUnderAnyLine(curHealthPct, curStamPct))
|
||||
_healUnavailableUntil = RynthClock.Now.AddMilliseconds(HealUnavailableMs);
|
||||
|
||||
// The cast gate was opened for the heal only (heal grace, OnHeartbeat): the character may still
|
||||
// be mid-gesture, so no mana or stamina action goes out on this tick.
|
||||
if (_gateGraceTick) return false;
|
||||
|
||||
// Mana: under Get Mana At / Top Off Mana, or (a caster) under the reserve kept for Stamina
|
||||
// to Mana (ManaUnderLine; see "Mana reserve" at the top).
|
||||
bool manaLow = curManaPct < manaThreshold || ManaUnderLine(inCombat, out _);
|
||||
|
|
@ -2753,10 +2787,44 @@ public partial class BuffManager : IDisposable
|
|||
// and used a second kit, every time (2026-10-03). After a kit, vitals wait for the
|
||||
// kit's own result line (heal, fail, movement disrupted, already at full), plus
|
||||
// KitLandGraceMs for the vitals to catch up, or KitResultTimeoutMs with no line at all.
|
||||
//
|
||||
// Heal grace ("stuck in Healing"): a kit that got no result line left the vitals waiting 8 s and
|
||||
// more with the label reading Healing and nothing else healing, long enough for the character to die.
|
||||
// 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. Here (KitWaitVerdict): a kit the server shows no sign
|
||||
// of having taken (no animation since the send, no UseDone, no line) is let go after
|
||||
// ActionPacer.HealGraceMs and the next tick sends it again; a UseDone(0) with no line ends the
|
||||
// wait after KitLandGraceMs (ACE sends the line before the UseDone, so none is coming); and a
|
||||
// started kit is waited for KitResultTimeoutMs at most (3.5 s; a healthy kit answers in 2.5 s).
|
||||
private DateTime _kitUsedAt = DateTime.MinValue;
|
||||
private DateTime _kitLandedAt = DateTime.MinValue;
|
||||
private const double KitResultTimeoutMs = 8000;
|
||||
private DateTime _kitAnsweredAt = DateTime.MinValue; // a UseDone(0) since the send (no line yet)
|
||||
private bool _kitSawAnimating; // the motion queue read busy since the send
|
||||
// 3.5 s: the longest healthy kit answer is 2.5 s (ActionPacer's header). The same value as
|
||||
// ActionPacer.ItemUseMaxMs today, but its own number: a change to the pacer's limit is not one here.
|
||||
// Stamina kits share this wait (KitPending).
|
||||
internal const double KitResultTimeoutMs = 3500;
|
||||
private const double KitLandGraceMs = 700;
|
||||
/// <summary>Kits let go with no result (heal grace or the time limit) and sent again (tests, status).</summary>
|
||||
internal int KitRetries { get; private set; }
|
||||
|
||||
internal enum KitWaitEnd { Waiting, Landed, Answered, NotTaken, TimedOut }
|
||||
|
||||
/// <summary>
|
||||
/// The kit wait, from what has been seen since the send (pure; ms values below 0 = not seen):
|
||||
/// the result line plus KitLandGraceMs; a UseDone(0) with no line plus KitLandGraceMs; nothing
|
||||
/// at all from the server (<paramref name="serverTookIt"/> false) and not animating now after
|
||||
/// ActionPacer.HealGraceMs; or KitResultTimeoutMs whatever happened.
|
||||
/// </summary>
|
||||
internal static KitWaitEnd KitWaitVerdict(double msSinceUse, double msSinceLanded, double msSinceAnswered,
|
||||
bool serverTookIt, bool animatingNow)
|
||||
{
|
||||
if (msSinceLanded >= 0) return msSinceLanded >= KitLandGraceMs ? KitWaitEnd.Landed : KitWaitEnd.Waiting;
|
||||
if (msSinceAnswered >= KitLandGraceMs) return KitWaitEnd.Answered;
|
||||
if (!serverTookIt && !animatingNow && msSinceUse >= ActionPacer.HealGraceMs) return KitWaitEnd.NotTaken;
|
||||
if (msSinceUse >= KitResultTimeoutMs) return KitWaitEnd.TimedOut;
|
||||
return KitWaitEnd.Waiting;
|
||||
}
|
||||
|
||||
// A refused kit (2026-10-05): ACE answers a kit used while the character is busy (a swing, a
|
||||
// cast still resolving), in the air, or on something it can't heal with a UseDone error and
|
||||
|
|
@ -2777,10 +2845,36 @@ public partial class BuffManager : IDisposable
|
|||
{
|
||||
_kitUsedAt = RynthClock.Now;
|
||||
_kitLandedAt = DateTime.MinValue;
|
||||
_kitAnsweredAt = DateTime.MinValue;
|
||||
_kitSawAnimating = false;
|
||||
_kitIsStamina = stamina;
|
||||
_kitSeqAtUse = UseDoneSeqNow();
|
||||
}
|
||||
|
||||
private bool MotionQueueBusy => _host.HasGetCastBusyState && !_host.CanCastNow;
|
||||
|
||||
/// <summary>
|
||||
/// The server has shown it took the kit in flight (its heal motion, or its UseDone(0)). An engine with
|
||||
/// neither GetCastBusyState nor the UseDone sequence can show neither, so the kit counts as taken and
|
||||
/// only KitResultTimeoutMs ends the wait (no retry at the heal grace for a kit that may be playing).
|
||||
/// </summary>
|
||||
private bool KitServerTookIt() =>
|
||||
(!_host.HasGetCastBusyState && !_host.HasUseDoneSeq) || _kitSawAnimating || _kitAnsweredAt != DateTime.MinValue;
|
||||
|
||||
/// <summary>
|
||||
/// Records what the server has done with the kit in flight: the heal motion playing (the client's
|
||||
/// motion queue busy) or a UseDone(0). Every heartbeat (the vitals step is not reached while the
|
||||
/// character animates) and from KitPending.
|
||||
/// </summary>
|
||||
private void NoteKitProgress()
|
||||
{
|
||||
if (_kitUsedAt == DateTime.MinValue || _kitLandedAt != DateTime.MinValue) return;
|
||||
if (!_kitSawAnimating && MotionQueueBusy) _kitSawAnimating = true;
|
||||
if (_kitAnsweredAt == DateTime.MinValue && _host.HasUseDoneSeq && _host.TryGetLastUseDone(out int seq, out uint err)
|
||||
&& seq == _kitSeqAtUse + 1 && err == 0) // the first UseDone after the send (as the pacer pairs a cast)
|
||||
_kitAnsweredAt = RynthClock.Now;
|
||||
}
|
||||
|
||||
internal bool KitPending()
|
||||
{
|
||||
if (_kitUsedAt == DateTime.MinValue) return false;
|
||||
|
|
@ -2791,12 +2885,30 @@ public partial class BuffManager : IDisposable
|
|||
KitRefused($"UseDone error 0x{err:X}");
|
||||
return false;
|
||||
}
|
||||
NoteKitProgress();
|
||||
DateTime now = RynthClock.Now;
|
||||
bool done = _kitLandedAt != DateTime.MinValue
|
||||
? (now - _kitLandedAt).TotalMilliseconds >= KitLandGraceMs
|
||||
: (now - _kitUsedAt).TotalMilliseconds >= KitResultTimeoutMs;
|
||||
if (done) { _kitUsedAt = DateTime.MinValue; _kitLandedAt = DateTime.MinValue; }
|
||||
return !done;
|
||||
double sinceUse = (now - _kitUsedAt).TotalMilliseconds;
|
||||
var end = KitWaitVerdict(sinceUse,
|
||||
_kitLandedAt != DateTime.MinValue ? (now - _kitLandedAt).TotalMilliseconds : -1,
|
||||
_kitAnsweredAt != DateTime.MinValue ? (now - _kitAnsweredAt).TotalMilliseconds : -1,
|
||||
KitServerTookIt(), MotionQueueBusy);
|
||||
if (end == KitWaitEnd.Waiting) return true;
|
||||
if (end != KitWaitEnd.Landed)
|
||||
{
|
||||
KitRetries++;
|
||||
string what = end switch
|
||||
{
|
||||
KitWaitEnd.Answered => "was answered (UseDone) with no result line",
|
||||
KitWaitEnd.NotTaken => "shows no sign the server took it (no motion, no UseDone, no result line)",
|
||||
_ => "has no result line yet",
|
||||
};
|
||||
_host.Log($"[RynthAi] Vitals: the {(_kitIsStamina ? "stamina" : "healing")} kit {what} {sinceUse:0} ms after use: " +
|
||||
"vitals carry on (heal grace), the next tick may send it again.");
|
||||
}
|
||||
_kitUsedAt = DateTime.MinValue;
|
||||
_kitLandedAt = DateTime.MinValue;
|
||||
_kitAnsweredAt = DateTime.MinValue;
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>The kit in flight was refused: no result line will come, so stop waiting for one.</summary>
|
||||
|
|
|
|||
|
|
@ -30,6 +30,10 @@ internal static class CastGateWatchdog
|
|||
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
|
||||
|
|
|
|||
|
|
@ -147,6 +147,14 @@ internal static class ActionPacer
|
|||
public const long NoUseDoneFallbackMs = 600;
|
||||
/// <summary>The longest one ask for the player's turn holds RynthAi (RynthAiYieldApiV1.MaxHoldMs).</summary>
|
||||
public const long PlayerHoldMaxMs = 3000;
|
||||
/// <summary>
|
||||
/// Heal grace (the "stuck in Healing" report): the longest a heal under a heal line waits on
|
||||
/// an item use nobody answered, on the character's animation, or on the 'too busy' probe. Past it the heal
|
||||
/// goes (a refusal is an answer too, and the next heal retries), as VirindiTank does: it re-sends a kit
|
||||
/// until the server starts it and never parks on the client's busy state. Corpse/door uses and our own
|
||||
/// casts keep their rules (a server turn to stop; a cast the server would refuse).
|
||||
/// </summary>
|
||||
public const long HealGraceMs = 2000;
|
||||
|
||||
private static readonly object Gate = new();
|
||||
private static PacedAction? _cur;
|
||||
|
|
@ -157,6 +165,7 @@ internal static class ActionPacer
|
|||
private static long _gestureHolds, _gestureLimits;
|
||||
private static long _gestureBusySince; // when the client's motion queue was first seen busy (0 = clear)
|
||||
private static bool _gestureOverride; // the hold limit passed: open until the queue reads clear
|
||||
private static bool _gestureHealGrace; // the heal grace let a heal through this busy spell (logged once)
|
||||
private static readonly HashSet<string> _gestureLogged = new();
|
||||
private static long _maxWaitMs;
|
||||
private static string _maxWaitWhat = "";
|
||||
|
|
@ -195,6 +204,7 @@ internal static class ActionPacer
|
|||
_swingSentMs = 0; _swingSeenBusy = false; _swingHolds = 0; _swingLogged.Clear();
|
||||
_gestureBusySince = 0;
|
||||
_gestureOverride = false;
|
||||
_gestureHealGrace = false;
|
||||
_gestureLogged.Clear();
|
||||
_maxWaitMs = 0;
|
||||
_maxWaitWhat = "";
|
||||
|
|
@ -529,6 +539,15 @@ internal static class ActionPacer
|
|||
lock (Gate) _healsAhead++;
|
||||
return true;
|
||||
}
|
||||
// An item use (a kit, a potion, a wield) still unanswered after HealGraceMs: the heal goes (see
|
||||
// HealGraceMs). Its own pack has no server turn to stop; a lost or swallowed kit is re-sent here.
|
||||
if (a.Kind == PacedKind.ItemUse && age >= HealGraceMs)
|
||||
{
|
||||
bool logAhead;
|
||||
lock (Gate) { _healsAhead++; logAhead = a.LoggedWaits.Add(who + "/heal-grace"); }
|
||||
if (logAhead) Log(host, $"[Pace] {who}: the heal goes ahead of {Describe(a.Kind, a.Label)} (unanswered for {age} ms, heal grace {HealGraceMs} ms)");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
why = $"{Describe(a.Kind, a.Label)} sent {age} ms ago by {a.Who} has no answer yet";
|
||||
|
|
@ -570,6 +589,7 @@ internal static class ActionPacer
|
|||
line = "[Pace] the character's animation queue reads clear again";
|
||||
_gestureBusySince = 0;
|
||||
_gestureOverride = false;
|
||||
_gestureHealGrace = false;
|
||||
_gestureLogged.Clear();
|
||||
}
|
||||
else
|
||||
|
|
@ -592,6 +612,17 @@ internal static class ActionPacer
|
|||
line = $"[Pace] {who}: emergency heal after {age} ms of animation - going on";
|
||||
busy = false;
|
||||
}
|
||||
else if (heal == HealNeed.Heal && age >= HealGraceMs)
|
||||
{
|
||||
// Once per busy spell: logged and counted when the grace first lets a heal through.
|
||||
if (!_gestureHealGrace)
|
||||
{
|
||||
_gestureHealGrace = true;
|
||||
_gestureLimits++;
|
||||
line = $"[Pace] {who}: heal after {age} ms of animation (heal grace) - going on";
|
||||
}
|
||||
busy = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
_gestureHolds++;
|
||||
|
|
@ -915,8 +946,11 @@ internal static class ActionPacer
|
|||
// use would send first every time and the heal would see the next slot, up to BusyProbeMaxMs later).
|
||||
if (heal == HealNeed.Heal && _busySince != 0) _healWaitAt = now;
|
||||
bool healWaiting = heal != HealNeed.Heal && _healWaitAt != 0 && now - _healWaitAt < HealWaitFreshMs;
|
||||
// A waiting heal's probe comes at least every HealGraceMs (the doubling would reach BusyProbeMaxMs).
|
||||
long probeWait = Math.Min(BusyProbeMs << Math.Min(_probes, 8), BusyProbeMaxMs);
|
||||
if (heal == HealNeed.Heal) probeWait = Math.Min(probeWait, HealGraceMs);
|
||||
if (!attackRepeat && stuck == null && _busySince != 0 && _stage == BreakStage.None && !healWaiting
|
||||
&& now - Math.Max(_busySince, _lastProbeAt) >= Math.Min(BusyProbeMs << Math.Min(_probes, 8), BusyProbeMaxMs))
|
||||
&& now - Math.Max(_busySince, _lastProbeAt) >= probeWait)
|
||||
{
|
||||
probe = true; // spent in MayStart once the start passes its other checks (SpendTryAfterBusy)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue