Health under a heal line holds the arbiter on Buffing by itself. A melee character with a shield was held in Buffing for 17 s with no heal landing (a used-up kit re-sent), stopped attacking the boss and died. Now, in a fight (a monster within Monster Range), 6 s under a heal line with no heal landing (health up 3 points, the HP failsafe's test) hands combat the tick for 5 s, then the vitals hold it again; a heal landing or health over the line ends the episode. 6 s is VirindiTank's give-up for one kit (3 s to start, 3 s for the result). - The vitals step still runs every tick meanwhile (kits and potions go), but makes no stance change or wield for a vital while combat has the tick: no wand swap for Heal Self, and no peace switch for a kit in any stance (Magic included, with Use Kits in Magic Mode). A caster already in Magic stance casts its heal spell as before. - With no peace switch going out, Kit Min Success (and Stamina Kit Min Success) is computed in the current stance, not as if in peace. - A release waits for a heal under way: a kit whose heal motion has played (heal grace's NoteKitProgress), or a wand wield in flight. - The hold resets whenever the macro is off (the stop, and the HP failsafe's recall stop), so a restart in a fight starts a fresh count. Tests: HealHoldTests (new, 6). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
113 lines
5.7 KiB
C#
113 lines
5.7 KiB
C#
// ============================================================================
|
|
// RynthSuite - Combat/BuffManager.HealHold.cs
|
|
// The Buffing hold for a heal, capped when no heal is landing.
|
|
//
|
|
// Health under a heal line wins the arbiter by itself (WantsVitalRecharge, ahead of combat and
|
|
// nav). That is right while heals land, and wrong when none does: a melee character with a shield
|
|
// went to Buffing at 48% health, stopped attacking the boss, and stood there 17 s re-sending a
|
|
// healing kit the server no longer had until it died. Nothing healed, and nothing fought either.
|
|
//
|
|
// VirindiTank's give-up for one kit: re-sent until the heal motion starts, given up after 3 s,
|
|
// then up to 3 s for its result. So: HealHoldGiveUpMs (6 s) under a heal line with no heal landing
|
|
// (health up FailsafeRiseMinPct, the HP failsafe's own test) hands combat the tick for
|
|
// HealHoldReleaseMs (5 s, HealUnavailableMs, the backoff after "nothing could heal"), then the
|
|
// vitals hold it again. A heal landing, or health back over the line, ends the episode. Only in a
|
|
// fight (InCombatNow): with no monster in range there is nothing for combat to do with the tick.
|
|
//
|
|
// The vitals step still runs every tick meanwhile (OnHeartbeat runs whatever the arbiter decides):
|
|
// kits and potions keep going. What it does not do while combat has the tick is change stance or
|
|
// wield for a heal (a wand swap for Heal Self, peace mode for a kit, in any stance): combat would take the weapon
|
|
// back on its next tick and the two would trade the hands for nothing. A caster already in Magic
|
|
// stance casts as before. The cast in flight (PendingSpellId) still holds the arbiter by itself.
|
|
// ============================================================================
|
|
|
|
using System;
|
|
using RynthCore.Plugin.Shared;
|
|
|
|
namespace RynthCore.Plugin.RynthAi;
|
|
|
|
public partial class BuffManager
|
|
{
|
|
internal const double HealHoldGiveUpMs = 6000;
|
|
internal const double HealHoldReleaseMs = 5000;
|
|
|
|
private DateTime _hhSince = DateTime.MinValue;
|
|
private int _hhLow;
|
|
private DateTime _hhReleasedUntil = DateTime.MinValue;
|
|
// Set for one CheckVitals while combat has the tick and the character is out of Magic stance.
|
|
private bool _vitalsNoStanceChange;
|
|
// Set for one CheckVitals while combat has the tick, in any stance: a kit sends no peace switch.
|
|
private bool _vitalsNoPeaceSwitch;
|
|
|
|
/// <summary>Times the hold was handed to combat (tests, status).</summary>
|
|
internal int HealHoldReleases { get; private set; }
|
|
|
|
/// <summary>True while combat has the tick because no heal has been landing (see the header).</summary>
|
|
internal bool HealHoldReleased => _hhReleasedUntil != DateTime.MinValue && Now < _hhReleasedUntil;
|
|
|
|
/// <summary>
|
|
/// A heal already under way that a release would starve: a kit in flight whose heal motion has
|
|
/// played (NoteKitProgress), or the wand swap for a heal spell in flight (TickWandSwap's state, or
|
|
/// the wand's wield sent and not answered).
|
|
/// </summary>
|
|
private bool HealUnderWay() =>
|
|
(_kitUsedAt != DateTime.MinValue && _kitLandedAt == DateTime.MinValue && _kitSawAnimating)
|
|
|| _wandSwap.Active || _pendingWieldId != 0;
|
|
|
|
/// <summary>Ends a hold episode: the next heal line starts a fresh HealHoldGiveUpMs count.</summary>
|
|
private void ResetHealHold()
|
|
{
|
|
_hhSince = DateTime.MinValue;
|
|
_hhReleasedUntil = DateTime.MinValue;
|
|
}
|
|
|
|
/// <summary>Once per heartbeat while the macro runs, before the vitals step.</summary>
|
|
private void TickHealHold()
|
|
{
|
|
DateTime now = Now;
|
|
int hp = _vitals.HealthPct;
|
|
// Only in a fight (a monster within Monster Range): with nothing to fight, handing the tick on
|
|
// would give it to nav or looting at low health, walking on into the next pull.
|
|
// The macro being off is handled by the caller: HeartbeatCore returns before this tick then, and
|
|
// calls ResetHealHold instead, so a restart in a fight starts a fresh count.
|
|
if (_vitals.MaxHealth == 0 || Portaling() || !HealthUnderAnyLine(hp, _vitals.StaminaPct) || !InCombatNow())
|
|
{
|
|
ResetHealHold();
|
|
return;
|
|
}
|
|
if (_hhSince == DateTime.MinValue)
|
|
{
|
|
_hhSince = now;
|
|
_hhLow = hp;
|
|
return;
|
|
}
|
|
if (hp >= _hhLow + FailsafeRiseMinPct)
|
|
{
|
|
// A heal landed: the heals work, the vitals hold the tick again and the count starts over.
|
|
if (HealHoldReleased)
|
|
_host.Log($"[Vitals] Heal hold: a heal landed ({_hhLow}% -> {hp}%): the vitals hold the tick again.");
|
|
_hhSince = now;
|
|
_hhLow = hp;
|
|
_hhReleasedUntil = DateTime.MinValue;
|
|
return;
|
|
}
|
|
if (hp < _hhLow) _hhLow = hp;
|
|
if (_hhReleasedUntil != DateTime.MinValue)
|
|
{
|
|
if (now < _hhReleasedUntil) return;
|
|
// The window is over: hold again, and count the next HealHoldGiveUpMs from here.
|
|
_hhReleasedUntil = DateTime.MinValue;
|
|
_hhSince = now;
|
|
return;
|
|
}
|
|
double heldMs = (now - _hhSince).TotalMilliseconds;
|
|
if (heldMs < HealHoldGiveUpMs) return;
|
|
// A heal the server is playing is not cut off: combat would re-stance or re-wield over it. The
|
|
// release waits for it (a removed kit never animates, so that case still releases).
|
|
if (HealUnderWay()) return;
|
|
_hhReleasedUntil = now.AddMilliseconds(HealHoldReleaseMs);
|
|
HealHoldReleases++;
|
|
_host.Log($"[Vitals] Heal hold: health {hp}% under a heal line and no heal landed in {heldMs / 1000:0.#} s: " +
|
|
$"combat gets the tick for {HealHoldReleaseMs / 1000:0} s (kits and potions keep going; no stance change for a heal).");
|
|
}
|
|
}
|