Vitals: hand combat the tick when no heal is landing in a fight
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>
This commit is contained in:
parent
486f72de58
commit
ebeec58ee7
4 changed files with 435 additions and 7 deletions
113
Plugins/RynthCore.Plugin.RynthAi/Combat/BuffManager.HealHold.cs
Normal file
113
Plugins/RynthCore.Plugin.RynthAi/Combat/BuffManager.HealHold.cs
Normal file
|
|
@ -0,0 +1,113 @@
|
|||
// ============================================================================
|
||||
// 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).");
|
||||
}
|
||||
}
|
||||
|
|
@ -1168,7 +1168,8 @@ public partial class BuffManager : IDisposable
|
|||
/// and they need the same mid-cast protection a buff gets. Side-effect free:
|
||||
/// CheckVitals repopulates these flags every cycle it reaches.
|
||||
/// </summary>
|
||||
public bool WantsVitalRecharge => _isHealingSelf || _isRechargingMana || _isRechargingStamina || WantsHealNow() || WantsManaNow();
|
||||
public bool WantsVitalRecharge => (!HealHoldReleased && (_isHealingSelf || WantsHealNow()))
|
||||
|| _isRechargingMana || _isRechargingStamina || WantsManaNow();
|
||||
|
||||
// Health below a heal line wins the arbiter's tick by itself. The flags above are only set on
|
||||
// a tick where CheckVitals actually ran and acted, and it doesn't run while the client is busy
|
||||
|
|
@ -1402,7 +1403,7 @@ public partial class BuffManager : IDisposable
|
|||
TickRechargeRequest(); // /ra recharge: one vitals pass, macro on or off (BuffManager.Recharge.cs)
|
||||
TickOneTouchRequest(); // /ra heal, /ra stam, /ra mana: one-touch recharge, macro on or off (BuffManager.OneTouch.cs)
|
||||
|
||||
if (!_settings.IsMacroRunning) { DropWandSwap("the macro stopped"); return; }
|
||||
if (!_settings.IsMacroRunning) { DropWandSwap("the macro stopped"); ResetHealHold(); return; }
|
||||
|
||||
// A wand swap's next step goes as soon as the server has answered the last (before the cast gates).
|
||||
NoteModeChange();
|
||||
|
|
@ -1415,7 +1416,9 @@ public partial class BuffManager : IDisposable
|
|||
|
||||
// Heals failing at Emergency Heal At: break the cast, then recall (BuffManager.HpFailsafe.cs).
|
||||
TickHpFailsafe();
|
||||
if (!_settings.IsMacroRunning) return;
|
||||
if (!_settings.IsMacroRunning) { ResetHealHold(); return; } // the failsafe stopped it for a recall
|
||||
// No heal landing under a heal line: combat gets the tick for a while (BuffManager.HealHold.cs).
|
||||
TickHealHold();
|
||||
|
||||
// A Magic stance we asked for: watch the client's mode every tick (see ObserveStance).
|
||||
ObserveStance();
|
||||
|
|
@ -2059,6 +2062,15 @@ public partial class BuffManager : IDisposable
|
|||
}
|
||||
|
||||
internal bool CheckVitals() // internal for the host tests (VitalsTests)
|
||||
{
|
||||
// Combat has the tick (BuffManager.HealHold.cs): no stance change or wield for a vital this pass.
|
||||
_vitalsNoStanceChange = HealHoldReleased && CurrentCombatMode != CombatMode.Magic;
|
||||
_vitalsNoPeaceSwitch = HealHoldReleased; // no peace switch for a kit either, Magic stance included
|
||||
try { return CheckVitalsCore(); }
|
||||
finally { _vitalsNoStanceChange = false; _vitalsNoPeaceSwitch = false; }
|
||||
}
|
||||
|
||||
private bool CheckVitalsCore()
|
||||
{
|
||||
int curHealthPct = _vitals.HealthPct;
|
||||
int curManaPct = _vitals.ManaPct;
|
||||
|
|
@ -2474,6 +2486,8 @@ public partial class BuffManager : IDisposable
|
|||
return VitalNo(recoveryWhy);
|
||||
if (CurrentCombatMode != CombatMode.Magic && RynthClock.Now < _vitalSwapBlockedUntil)
|
||||
return VitalNo("wand swap blocked, retrying shortly");
|
||||
if (_vitalsNoStanceChange)
|
||||
return VitalNo("combat has the tick (no heal landed): no wand swap for a spell");
|
||||
bool urgentHeal = label == LabelHealing && (_oneTouchHealthScope || HealIsUrgent(_vitals.HealthPct, _vitals.StaminaPct));
|
||||
if (!EnsureMagicMode(urgentHeal: urgentHeal))
|
||||
{
|
||||
|
|
@ -2725,8 +2739,9 @@ public partial class BuffManager : IDisposable
|
|||
if (KitRetryWait(out string kitWait)) return VitalNo(kitWait);
|
||||
// Too likely to fail on what's missing (KitMinSuccessPct): let the spell have it.
|
||||
uint missing = _vitals.MaxHealth > _vitals.CurrentHealth ? _vitals.MaxHealth - _vitals.CurrentHealth : 0;
|
||||
if (!ignoreMinSuccess && !KitChanceOk(kit.Id, kit.Name ?? "", missing, _settings.PeaceModeForKits, _settings.KitMinSuccessPct)) return VitalNo($"{kit.Name} under Kit Min Success %");
|
||||
if (_settings.PeaceModeForKits && mode != CombatMode.NonCombat && _host.HasChangeCombatMode)
|
||||
// Released (BuffManager.HealHold.cs): no peace switch goes out, so the chance is the stance it is in.
|
||||
if (!ignoreMinSuccess && !KitChanceOk(kit.Id, kit.Name ?? "", missing, _settings.PeaceModeForKits && !_vitalsNoPeaceSwitch, _settings.KitMinSuccessPct)) return VitalNo($"{kit.Name} under Kit Min Success %");
|
||||
if (_settings.PeaceModeForKits && mode != CombatMode.NonCombat && _host.HasChangeCombatMode && !_vitalsNoPeaceSwitch)
|
||||
{
|
||||
// Only a request that went out starts the wait: a refusal (the engine turns stance changes away
|
||||
// around a teleport) leaves no pacing state, so the next tick asks again.
|
||||
|
|
@ -2763,8 +2778,9 @@ public partial class BuffManager : IDisposable
|
|||
if (KitRetryWait(out _)) return false;
|
||||
uint missing = _vitals.MaxStamina > _vitals.CurrentStamina ? _vitals.MaxStamina - _vitals.CurrentStamina : 0;
|
||||
// Its own line (Stamina Kit Min Success %): below it Revitalize Self or a potion goes.
|
||||
if (!KitChanceOk(kit.Id, kit.Name ?? "", missing, _settings.PeaceModeForKits, _settings.StaminaKitMinSuccessPct)) return false;
|
||||
if (_settings.PeaceModeForKits && mode != CombatMode.NonCombat && _host.HasChangeCombatMode)
|
||||
// Released (BuffManager.HealHold.cs): no peace switch goes out, so the chance is the stance it is in.
|
||||
if (!KitChanceOk(kit.Id, kit.Name ?? "", missing, _settings.PeaceModeForKits && !_vitalsNoPeaceSwitch, _settings.StaminaKitMinSuccessPct)) return false;
|
||||
if (_settings.PeaceModeForKits && mode != CombatMode.NonCombat && _host.HasChangeCombatMode && !_vitalsNoPeaceSwitch)
|
||||
{
|
||||
if (_host.ChangeCombatModeFor(CombatMode.NonCombat, "Buff", "peace mode for the stamina kit"))
|
||||
_lastCastAttempt = RynthClock.Now;
|
||||
|
|
|
|||
Loading…
Reference in a new issue