RynthAi: stuck-cast breaker, no re-send into a busy server, recovery retry, HP failsafe
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>
This commit is contained in:
parent
7cbc6fdca9
commit
2d8bebb0f4
30 changed files with 3156 additions and 53 deletions
|
|
@ -0,0 +1,266 @@
|
|||
// ============================================================================
|
||||
// RynthSuite - Combat/BuffManager.HpFailsafe.cs
|
||||
// The HP failsafe: at or under Emergency Heal At, a character whose heals keep
|
||||
// failing (refused, fizzled, never sent, or out-healed) must not sit and die.
|
||||
//
|
||||
// Measured by health, not by counting heal attempts: a round of FailsafeRoundMs
|
||||
// with no rise of FailsafeRiseMinPct counts as a failed round (whatever the
|
||||
// reason: a stuck cast, 'too busy', no mana, no kits).
|
||||
// 1. FailsafeRoundsToBreak failed rounds: ActionPacer.ForceBreak (a jump; on
|
||||
// ACE's fast tick it fails the cast in progress, Player.HandleActionJump).
|
||||
// Starts are held until landed, then the vitals step heals again.
|
||||
// 2. FailsafeRoundsToRecall more failed rounds after the break: recall to the
|
||||
// lifestone ("/lifestone", ACE GameAction TeleToLifestone) when
|
||||
// HpFailsafeRecall is on. The macro is switched off first, because ACE
|
||||
// cancels the recall when the character moves during its animation and
|
||||
// refuses it while busy (Player_Location.HandleActionTeleToLifestone).
|
||||
// 3. No "<our name> is recalling to the lifestone." after RecallMaxSends tries
|
||||
// (ACE refuses the recall while busy, under a PK timer or with recalls
|
||||
// disabled, which is just the stuck state this is for): the macro is
|
||||
// switched back on, so the heals and kits run again, and the failsafe
|
||||
// re-arms; the next recall waits RecallCooldownMs. A failed recall must not
|
||||
// leave the character standing at low health with nothing running. Only a
|
||||
// macro the failsafe itself stopped is switched back on, never past a VTank
|
||||
// yield (MayRestartMacro), and a death drops the pending recall (the player's
|
||||
// Stop Macro On Death stands).
|
||||
// Health back over the line (or 100%) ends the episode. Nothing counts in portal space.
|
||||
// ============================================================================
|
||||
|
||||
using System;
|
||||
using RynthCore.Plugin.Shared;
|
||||
|
||||
namespace RynthCore.Plugin.RynthAi;
|
||||
|
||||
public partial class BuffManager
|
||||
{
|
||||
internal const double FailsafeRoundMs = 2500;
|
||||
internal const int FailsafeRoundsToBreak = 3;
|
||||
internal const int FailsafeRoundsToRecall = 3;
|
||||
// A rise this large (health %) means a heal landed; natural regeneration is smaller.
|
||||
private const int FailsafeRiseMinPct = 3;
|
||||
// The recall goes this long after the macro stop (the stop edge runs on the next tick),
|
||||
// and is sent again this often, a few times, until our "is recalling to the lifestone" is seen.
|
||||
private const double RecallFirstDelayMs = 600;
|
||||
private const double RecallResendMs = 1500;
|
||||
private const int RecallMaxSends = 3;
|
||||
/// <summary>After a recall that never started, the next one waits this long (the heals run meanwhile).</summary>
|
||||
internal const double RecallCooldownMs = 30_000;
|
||||
internal const string RecallCommand = "/lifestone";
|
||||
|
||||
private bool _fsActive;
|
||||
private DateTime _fsRoundStart;
|
||||
private int _fsLowHp;
|
||||
private int _fsFailedRounds;
|
||||
private bool _fsBroken;
|
||||
private bool _fsRecallLogged;
|
||||
private DateTime _fsRecallNotBefore = DateTime.MinValue;
|
||||
|
||||
private bool _recallPending;
|
||||
private bool _recallSeen;
|
||||
private int _recallSends;
|
||||
private DateTime _recallNextAt;
|
||||
|
||||
/// <summary>Set by the plugin: the rest of a /ra stop (nav stop, pause cancel) for the recall.</summary>
|
||||
internal Action? MacroStopForRecall { get; set; }
|
||||
/// <summary>Set by the plugin: false when the macro must not be started now (VTank yield). Null = may.</summary>
|
||||
internal Func<bool>? MayRestartMacro { get; set; }
|
||||
|
||||
// The macro is off because the failsafe stopped it for a recall (only then does it switch it back on).
|
||||
private bool _macroStoppedByFailsafe;
|
||||
private bool _recallNameLogged;
|
||||
|
||||
internal int HpFailsafeBreaks { get; private set; }
|
||||
internal int HpFailsafeRecalls { get; private set; }
|
||||
internal int HpFailsafeRecallsFailed { get; private set; }
|
||||
|
||||
private bool Portaling()
|
||||
{
|
||||
try { return _host.HasIsPortaling && _host.IsPortaling(); } catch { return false; }
|
||||
}
|
||||
|
||||
/// <summary>Once per heartbeat while the macro runs, before the pacing gate.</summary>
|
||||
private void TickHpFailsafe()
|
||||
{
|
||||
int at = _settings.EmergencyHealAt;
|
||||
if (at <= 0 || _vitals.MaxHealth <= 0 || _recallPending || Portaling()) { ResetHpFailsafe(); return; }
|
||||
int hp = _vitals.HealthPct;
|
||||
DateTime now = Now;
|
||||
if (hp > at || hp >= 100)
|
||||
{
|
||||
if (_fsActive && (_fsFailedRounds > 0 || _fsBroken))
|
||||
_host.Log($"[Vitals] HP failsafe: health back to {hp}% (over Emergency Heal At {at}%).");
|
||||
ResetHpFailsafe();
|
||||
return;
|
||||
}
|
||||
if (!_fsActive)
|
||||
{
|
||||
_fsActive = true;
|
||||
_fsRoundStart = now;
|
||||
_fsLowHp = hp;
|
||||
_fsFailedRounds = 0;
|
||||
_fsBroken = false;
|
||||
return;
|
||||
}
|
||||
if (hp >= _fsLowHp + FailsafeRiseMinPct)
|
||||
{
|
||||
// A heal landed: the heals work, start counting again from here.
|
||||
_fsLowHp = hp;
|
||||
_fsRoundStart = now;
|
||||
_fsFailedRounds = 0;
|
||||
return;
|
||||
}
|
||||
if (hp < _fsLowHp) _fsLowHp = hp;
|
||||
if ((now - _fsRoundStart).TotalMilliseconds < FailsafeRoundMs) return;
|
||||
|
||||
_fsFailedRounds++;
|
||||
_fsRoundStart = now;
|
||||
double failedSec = _fsFailedRounds * FailsafeRoundMs / 1000.0;
|
||||
if (!_fsBroken)
|
||||
{
|
||||
if (_fsFailedRounds < FailsafeRoundsToBreak) return;
|
||||
string why = $"HP failsafe: health {hp}% at or under Emergency Heal At {at}%, no heal landed in {failedSec:0.#} s";
|
||||
bool jumped = ActionPacer.ForceBreak(_host, why);
|
||||
if (jumped) HpFailsafeBreaks++;
|
||||
_host.Log($"[Vitals] {why}: {(jumped ? "breaking the cast with a jump, then healing again" : "no jump available (or one under way), healing again")}.");
|
||||
_fsBroken = true;
|
||||
_fsFailedRounds = 0;
|
||||
return;
|
||||
}
|
||||
if (_fsFailedRounds < FailsafeRoundsToRecall) return;
|
||||
if (!_settings.HpFailsafeRecall)
|
||||
{
|
||||
if (!_fsRecallLogged)
|
||||
{
|
||||
_fsRecallLogged = true;
|
||||
_host.Log($"[Vitals] HP failsafe: health {hp}%, heals still failing {failedSec:0.#} s after the break; HP Failsafe Recall is off, no recall.");
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (now < _fsRecallNotBefore)
|
||||
{
|
||||
// The last recall never started: heal on and break again, the next recall after the cooldown.
|
||||
_fsBroken = false;
|
||||
_fsFailedRounds = 0;
|
||||
return;
|
||||
}
|
||||
StartFailsafeRecall(now, hp, failedSec);
|
||||
}
|
||||
|
||||
private void ResetHpFailsafe()
|
||||
{
|
||||
_fsActive = false;
|
||||
_fsFailedRounds = 0;
|
||||
_fsBroken = false;
|
||||
_fsRecallLogged = false;
|
||||
}
|
||||
|
||||
private void StartFailsafeRecall(DateTime now, int hp, double failedSec)
|
||||
{
|
||||
HpFailsafeRecalls++;
|
||||
_settings.IsMacroRunning = false;
|
||||
_macroStoppedByFailsafe = true;
|
||||
_recallNameLogged = false;
|
||||
MacroStopForRecall?.Invoke();
|
||||
_recallPending = true;
|
||||
_recallSeen = false;
|
||||
_recallSends = 0;
|
||||
_recallNextAt = now.AddMilliseconds(RecallFirstDelayMs);
|
||||
string line = $"HP failsafe: health {hp}%, heals still failing {failedSec:0.#} s after the break: macro stopped, recalling to the lifestone.";
|
||||
_host.Log("[Vitals] " + line);
|
||||
_host.WriteToChat("[RynthAi] " + line, 2);
|
||||
ResetHpFailsafe();
|
||||
}
|
||||
|
||||
/// <summary>Every heartbeat, macro running or not: sends a pending recall, or gives up on it.</summary>
|
||||
private void TickFailsafeRecall()
|
||||
{
|
||||
if (!_recallPending) return;
|
||||
DateTime now = Now;
|
||||
if (_recallSeen)
|
||||
{
|
||||
_recallPending = false;
|
||||
_macroStoppedByFailsafe = false;
|
||||
_host.Log("[Vitals] HP failsafe: the recall started.");
|
||||
return;
|
||||
}
|
||||
if (_vitals.MaxHealth > 0 && _vitals.CurrentHealth == 0)
|
||||
{
|
||||
CancelPendingRecall("dead");
|
||||
return;
|
||||
}
|
||||
if (_settings.IsMacroRunning)
|
||||
{
|
||||
// Someone switched the macro back on: their call, the recall is dropped.
|
||||
_recallPending = false;
|
||||
_macroStoppedByFailsafe = false;
|
||||
_host.Log("[Vitals] HP failsafe: the macro was started again; the recall is dropped.");
|
||||
return;
|
||||
}
|
||||
if (now < _recallNextAt) return;
|
||||
if (_recallSends >= RecallMaxSends || !_host.HasInvokeChatParser)
|
||||
{
|
||||
_recallPending = false;
|
||||
HpFailsafeRecallsFailed++;
|
||||
_fsRecallNotBefore = now.AddMilliseconds(RecallCooldownMs);
|
||||
string why = _host.HasInvokeChatParser
|
||||
? $"no recall seen after {_recallSends} tries of {RecallCommand} (refused: busy, a PK timer or recalls disabled)"
|
||||
: "this engine has no chat parser, so no recall";
|
||||
string what;
|
||||
if (!_macroStoppedByFailsafe) what = "the macro stays as it is";
|
||||
else if (MayRestartMacro != null && !MayRestartMacro()) what = "the macro stays off (VTank yield)";
|
||||
else
|
||||
{
|
||||
_settings.IsMacroRunning = true; // the heals and kits run again; the failsafe re-arms
|
||||
what = "macro back on to keep healing";
|
||||
}
|
||||
_macroStoppedByFailsafe = false;
|
||||
string line = $"HP failsafe: {why}: {what}; next recall in {RecallCooldownMs / 1000:0} s at the earliest.";
|
||||
_host.Log("[Vitals] " + line);
|
||||
_host.WriteToChat("[RynthAi] " + line, 2);
|
||||
return;
|
||||
}
|
||||
_host.InvokeChatParser(RecallCommand);
|
||||
_recallSends++;
|
||||
_recallNextAt = now.AddMilliseconds(RecallResendMs);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The plugin's death hold (and a 0-health read): a pending recall is dropped and the macro is
|
||||
/// left off, so nothing re-sends /lifestone or restarts the macro after the respawn.
|
||||
/// </summary>
|
||||
internal void CancelPendingRecall(string why)
|
||||
{
|
||||
if (!_recallPending) return;
|
||||
_recallPending = false;
|
||||
_macroStoppedByFailsafe = false;
|
||||
_host.Log($"[Vitals] HP failsafe: the pending recall is dropped ({why}); the macro stays off.");
|
||||
}
|
||||
|
||||
/// <summary>OnChatWindowText: "<our name> is recalling to the lifestone." while a recall is pending.</summary>
|
||||
private void ObserveRecallLine(string lower)
|
||||
{
|
||||
if (!_recallPending || !lower.Contains("is recalling to the lifestone")) return;
|
||||
string me = "";
|
||||
try
|
||||
{
|
||||
uint id = unchecked((uint)_host.GetPlayerId());
|
||||
if (id != 0 && _host.HasGetObjectName && _host.TryGetObjectName(id, out string n)) me = n ?? "";
|
||||
}
|
||||
catch { me = ""; }
|
||||
// Someone else's recall ("Bob is recalling to the lifestone.") is not ours. The chat layer
|
||||
// can drop a line's first letter ("ou cast ..."), so the name may arrive without it.
|
||||
if (me.Length > 0)
|
||||
{
|
||||
string who = lower.Substring(0, lower.IndexOf(" is recalling to the lifestone", StringComparison.Ordinal)).Trim();
|
||||
string mine = me.ToLowerInvariant();
|
||||
bool ours = who == mine || (who.Length == mine.Length - 1 && who.Length > 0 && mine.EndsWith(who, StringComparison.Ordinal));
|
||||
if (!ours) return;
|
||||
}
|
||||
else if (!_recallNameLogged)
|
||||
{
|
||||
_recallNameLogged = true;
|
||||
_host.Log("[Vitals] HP failsafe: our name could not be read; any 'is recalling to the lifestone' line is taken as ours.");
|
||||
}
|
||||
_recallSeen = true;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,184 @@
|
|||
// ============================================================================
|
||||
// RynthSuite - Combat/BuffManager.RecoveryRetry.cs
|
||||
// Fast retry of the recovery vitals (Heal Self, Stamina to Health, Revitalize,
|
||||
// Stamina to Mana) after the server's "not enough mana" answer.
|
||||
//
|
||||
// ACE (origin/master, Creature_Magic.GetManaCost) rolls Mana Conversion on every
|
||||
// cast attempt: a trained caster pays between the full cost and 1 mana. The roll
|
||||
// and the check run before the windup (Player_Magic.CalculateManaUsage), so a
|
||||
// refusal costs nothing: no mana, no busy period, no recoil, only UseDone 0x401.
|
||||
// At low mana the cast goes through on a good roll, so trying again soon is the
|
||||
// way to get it off. Before this, the refusal rested the spell's family (LowManaHealRestSec).
|
||||
//
|
||||
// Bounds (the refusal-spam crash class, see the "too busy" handler): the retry
|
||||
// gap is never under RecoveryRetryMinMs, at most RecoveryRetryMaxPerSecond
|
||||
// recovery casts go out in any second while an episode is open, and an episode
|
||||
// stops after RecoveryRetryMaxRefusals mana refusals in a row (any recovery
|
||||
// spell); the refused family then rests as before (a vital LowManaHealRestSec, 2 s).
|
||||
// ============================================================================
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using RynthCore.Plugin.RynthAi.LegacyUi;
|
||||
|
||||
namespace RynthCore.Plugin.RynthAi;
|
||||
|
||||
public partial class BuffManager
|
||||
{
|
||||
internal const int RecoveryRetryMinMs = 200;
|
||||
internal const int RecoveryRetryMaxMs = 5000;
|
||||
internal const int RecoveryRetryMaxPerSecond = 5;
|
||||
internal const int RecoveryRetryMaxRefusals = 20;
|
||||
// A refusal this long after the last one starts a new episode; an open episode with no refusal
|
||||
// for this long ends. Above the slowest retry gap (the setting's 5000 ms maximum) with room for
|
||||
// the pacing in between, so a slow setting never ends its own episode between two retries.
|
||||
internal const double RecoveryEpisodeStaleMs = RecoveryRetryMaxMs + 2000;
|
||||
// Stamina to Mana is attempted only above this stamina % (the CheckVitals and mana floor gates).
|
||||
private const int RecoveryMinStaminaToConvert = 15;
|
||||
|
||||
private bool _recoveryOpen;
|
||||
private DateTime _recoveryStartedAt;
|
||||
private DateTime _recoveryLastRefusalAt;
|
||||
private int _recoveryRefusals;
|
||||
private readonly Dictionary<int, DateTime> _recoveryNextAt = new();
|
||||
private readonly List<string> _recoveryNames = new();
|
||||
// Recovery casts sent (any time), for the per-second ceiling.
|
||||
private readonly Queue<DateTime> _recoveryAttempts = new();
|
||||
// The base name of the pending vital ("Stamina to Mana Self"...), set by CastVital.
|
||||
private string _pendingVitalBase = "";
|
||||
|
||||
/// <summary>Recovery casts held by the per-second ceiling (tests, status).</summary>
|
||||
internal int RecoveryRateHolds { get; private set; }
|
||||
/// <summary>The last episode summary line (tests, status).</summary>
|
||||
internal string LastRecoverySummary { get; private set; } = "";
|
||||
/// <summary>True while a fast-retry episode is open (tests).</summary>
|
||||
internal bool RecoveryRetryOpen => _recoveryOpen;
|
||||
|
||||
internal static bool IsRecoveryVital(string baseName) =>
|
||||
baseName is "Heal Self" or "Stamina to Health Self" or "Revitalize Self" or "Stamina to Mana Self";
|
||||
|
||||
private int RecoveryRetryMs => Math.Clamp(_settings.RecoveryRetryMs, RecoveryRetryMinMs, RecoveryRetryMaxMs);
|
||||
|
||||
/// <summary>
|
||||
/// Why a fast retry can't help now, or "" when it can. Untrained Mana Conversion pays the full
|
||||
/// cost every time (GetManaCost returns the base cost), so a retry would only be refused again;
|
||||
/// trained, the least a cast can cost is 1 mana.
|
||||
/// </summary>
|
||||
private string RecoveryRetryBlocked(string baseName)
|
||||
{
|
||||
if (!IsSkillUsable(AcSkillType.ManaConversion)) return "Mana Conversion not trained (no cost roll)";
|
||||
if (_vitals.MaxMana > 0 && _vitals.CurrentMana < 1) return "no mana at all";
|
||||
if (baseName == "Stamina to Mana Self" && _vitals.StaminaPct <= RecoveryMinStaminaToConvert)
|
||||
return $"stamina {_vitals.StaminaPct}% too low to convert";
|
||||
if (baseName == "Stamina to Health Self" && _vitals.StaminaPct <= _settings.StaminaToHealthMinStamina)
|
||||
return $"stamina {_vitals.StaminaPct}% too low to convert";
|
||||
return "";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// "Not enough mana" for the pending cast. Returns true when it was a recovery vital that will be
|
||||
/// retried soon (the caller then skips the family rest); false leaves the old handling.
|
||||
/// </summary>
|
||||
private bool OnRecoveryManaRefusal(SpellInfo? pending)
|
||||
{
|
||||
if (pending == null || _pendingSpellId != _pendingVitalSpellId || !IsRecoveryVital(_pendingVitalBase))
|
||||
return false;
|
||||
DateTime now = Now;
|
||||
if (_recoveryOpen && (now - _recoveryLastRefusalAt).TotalMilliseconds > RecoveryEpisodeStaleMs)
|
||||
EndRecoveryEpisode(now, "no refusal for a while", success: false, "");
|
||||
if (!_recoveryOpen)
|
||||
{
|
||||
_recoveryOpen = true;
|
||||
_recoveryStartedAt = now;
|
||||
_recoveryRefusals = 0;
|
||||
_recoveryNames.Clear();
|
||||
}
|
||||
_recoveryRefusals++;
|
||||
_recoveryLastRefusalAt = now;
|
||||
if (!_recoveryNames.Contains(pending.Name)) _recoveryNames.Add(pending.Name);
|
||||
string blocked = RecoveryRetryBlocked(_pendingVitalBase);
|
||||
if (blocked.Length > 0)
|
||||
{
|
||||
EndRecoveryEpisode(now, blocked, success: false, "");
|
||||
return false;
|
||||
}
|
||||
if (_recoveryRefusals >= RecoveryRetryMaxRefusals)
|
||||
{
|
||||
EndRecoveryEpisode(now, $"{_recoveryRefusals} refusals in a row", success: false, "");
|
||||
return false;
|
||||
}
|
||||
_recoveryNextAt[pending.Family] = now.AddMilliseconds(RecoveryRetryMs);
|
||||
if (_recoveryRefusals == 1)
|
||||
_host.Log($"[Vitals] {pending.Name}: not enough mana (mana {_vitals.CurrentMana}); retrying every {RecoveryRetryMs} ms for a Mana Conversion roll (at most {RecoveryRetryMaxPerSecond}/s, {RecoveryRetryMaxRefusals} refusals).");
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>A result line for <paramref name="family"/>: a retried cast went through.</summary>
|
||||
private void OnRecoveryCastResult(int family, string name)
|
||||
{
|
||||
if (_recoveryOpen && _recoveryNextAt.ContainsKey(family))
|
||||
EndRecoveryEpisode(Now, "", success: true, name);
|
||||
}
|
||||
|
||||
private void EndRecoveryEpisode(DateTime now, string why, bool success, string name)
|
||||
{
|
||||
if (!_recoveryOpen) return;
|
||||
_recoveryOpen = false;
|
||||
_recoveryNextAt.Clear();
|
||||
double ms = (now - _recoveryStartedAt).TotalMilliseconds;
|
||||
string names = string.Join(", ", _recoveryNames);
|
||||
LastRecoverySummary = success
|
||||
? $"[Vitals] {name} went through after {_recoveryRefusals + 1} attempts ({_recoveryRefusals} refused for mana: {names}) in {ms:0} ms."
|
||||
: $"[Vitals] stopped retrying {names} after {_recoveryRefusals} mana refusals in {ms:0} ms ({why}).";
|
||||
_host.Log(LastRecoverySummary);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Ends an episode with no refusal for RecoveryEpisodeStaleMs (the cast went through unseen, the
|
||||
/// vital is no longer needed, or something else took over), so a stale one never keeps letting
|
||||
/// casts past Spell Interval. Once per heartbeat.
|
||||
/// </summary>
|
||||
private void ExpireRecoveryEpisode()
|
||||
{
|
||||
if (_recoveryOpen && (Now - _recoveryLastRefusalAt).TotalMilliseconds > RecoveryEpisodeStaleMs)
|
||||
EndRecoveryEpisode(Now, $"no refusal for {RecoveryEpisodeStaleMs / 1000:0} s", success: false, "");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The cast interval gate lets a due recovery retry through: the retry gap (RecoveryRetryMs)
|
||||
/// replaces Spell Interval for it, and the per-second ceiling still applies in CastVital.
|
||||
/// </summary>
|
||||
private bool RecoveryRetryDue()
|
||||
{
|
||||
if (!_recoveryOpen) return false;
|
||||
DateTime now = Now;
|
||||
foreach (var at in _recoveryNextAt.Values)
|
||||
if (now >= at) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>CastVital's gate for a recovery vital while an episode is open: "" to cast, else why it waits.</summary>
|
||||
private string RecoveryRetryHolds(int family)
|
||||
{
|
||||
if (!_recoveryOpen) return "";
|
||||
DateTime now = Now;
|
||||
if (_recoveryNextAt.TryGetValue(family, out DateTime next) && now < next)
|
||||
return $"retrying after a mana refusal in {(next - now).TotalMilliseconds:0} ms";
|
||||
while (_recoveryAttempts.Count > 0 && (now - _recoveryAttempts.Peek()).TotalMilliseconds >= 1000)
|
||||
_recoveryAttempts.Dequeue();
|
||||
if (_recoveryAttempts.Count >= RecoveryRetryMaxPerSecond)
|
||||
{
|
||||
RecoveryRateHolds++;
|
||||
return $"{RecoveryRetryMaxPerSecond} recovery casts in the last second";
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
private void NoteRecoveryAttempt()
|
||||
{
|
||||
DateTime now = Now;
|
||||
while (_recoveryAttempts.Count > 0 && (now - _recoveryAttempts.Peek()).TotalMilliseconds >= 1000)
|
||||
_recoveryAttempts.Dequeue();
|
||||
_recoveryAttempts.Enqueue(now);
|
||||
}
|
||||
}
|
||||
|
|
@ -61,8 +61,9 @@ public partial class BuffManager
|
|||
// than RynthAi's own heals' (Vitality Siphon: 2.42-2.75 s after the incantation, 2026-10-10
|
||||
// log), or never (a resisted or dead target), and an early nudge steps the character.
|
||||
if (sent && _cast.Current is { } sentCast && sentCast.SpellId == (int)spell) sentCast.Script = true;
|
||||
if (sent) ActionPacer.MarkScriptCast((int)spell); // the stuck-cast breaker gives it the same room
|
||||
// Handled: cast, or a swap step to Magic mode is in flight (the next check asks again).
|
||||
CombatHook.Cast(slot, sent ? spell : 0, sent ? target : 0);
|
||||
CombatHook.Cast(slot, sent ? spell : 0, sent ? target : 0, sent ? ActionPacer.LastCastSeqAtSend : -1);
|
||||
if (sent) _host.Log($"[RynthAi] Vitals: script heal id={spell} '{name}' at 0x{target:X8} (owner '{CombatHook.Owner}').");
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1124,11 +1124,18 @@ public partial class BuffManager : IDisposable
|
|||
LogPostCastDiff(diag);
|
||||
}
|
||||
|
||||
// A recall the HP failsafe asked for goes out after the macro stop (BuffManager.HpFailsafe.cs).
|
||||
TickFailsafeRecall();
|
||||
|
||||
if (!_settings.IsMacroRunning) return;
|
||||
|
||||
// Close casts the server reports finished, and say once when one is being held open.
|
||||
PollCastTracker();
|
||||
|
||||
// Heals failing at Emergency Heal At: break the cast, then recall (BuffManager.HpFailsafe.cs).
|
||||
TickHpFailsafe();
|
||||
if (!_settings.IsMacroRunning) return;
|
||||
|
||||
// A Magic stance we asked for: watch the client's mode every tick (see ObserveStance).
|
||||
ObserveStance();
|
||||
|
||||
|
|
@ -1381,7 +1388,11 @@ public partial class BuffManager : IDisposable
|
|||
}
|
||||
}
|
||||
|
||||
if ((DateTime.Now - _lastCastAttempt).TotalMilliseconds < _settings.SpellCastIntervalMs)
|
||||
// A due recovery retry (BuffManager.RecoveryRetry.cs) gets past Spell Interval, for the vitals
|
||||
// step only: the buffs after it still wait (intervalHeld below). A stale episode ends first.
|
||||
ExpireRecoveryEpisode();
|
||||
bool intervalHeld = (DateTime.Now - _lastCastAttempt).TotalMilliseconds < _settings.SpellCastIntervalMs;
|
||||
if (intervalHeld && !RecoveryRetryDue())
|
||||
{
|
||||
Hold("cast interval");
|
||||
return;
|
||||
|
|
@ -1433,6 +1444,13 @@ public partial class BuffManager : IDisposable
|
|||
return;
|
||||
}
|
||||
|
||||
// Only a recovery retry got past Spell Interval; nothing else goes inside it.
|
||||
if (intervalHeld)
|
||||
{
|
||||
Hold("cast interval");
|
||||
return;
|
||||
}
|
||||
|
||||
// The login refresh above held buffs only: the heal had its turn, the buffs wait.
|
||||
if (buffsHeldForRefresh)
|
||||
{
|
||||
|
|
@ -1972,6 +1990,9 @@ public partial class BuffManager : IDisposable
|
|||
&& _buffFailCooldownUntil.TryGetValue(family, out DateTime coolUntil)
|
||||
&& DateTime.Now < coolUntil)
|
||||
return VitalNo($"parked for {(coolUntil - DateTime.Now).TotalSeconds:0} s more after a refusal or no-show");
|
||||
// A recovery vital retried after a mana refusal: its retry gap and the per-second ceiling.
|
||||
if (IsRecoveryVital(what) && RecoveryRetryHolds(family) is { Length: > 0 } recoveryWhy)
|
||||
return VitalNo(recoveryWhy);
|
||||
if (CurrentCombatMode != CombatMode.Magic && DateTime.Now < _vitalSwapBlockedUntil)
|
||||
return VitalNo("wand swap blocked, retrying shortly");
|
||||
bool urgentHeal = label == LabelHealing && HealIsUrgent(_vitals.HealthPct, _vitals.StaminaPct);
|
||||
|
|
@ -1989,6 +2010,7 @@ public partial class BuffManager : IDisposable
|
|||
_pendingSpellId = spellId;
|
||||
_pendingVitalSpellId = spellId; // instant: confirmed by chat, never by the registry
|
||||
_pendingVitalLabel = label;
|
||||
_pendingVitalBase = what;
|
||||
bool castOk = _host.CastSpellFor(targetId, spellId, "Buff",
|
||||
SpellTableStub.GetById(spellId)?.Name ?? what);
|
||||
_lastCastAttempt = DateTime.Now;
|
||||
|
|
@ -1998,6 +2020,7 @@ public partial class BuffManager : IDisposable
|
|||
return VitalNo($"the client refused the cast (spell {spellId})");
|
||||
}
|
||||
sent = true;
|
||||
if (IsRecoveryVital(what)) NoteRecoveryAttempt();
|
||||
NoteCastIssued(spellId);
|
||||
if (_pendingVitalLabel == LabelMana) _manaStarvedLogged = false; // the next starved spell logs again
|
||||
if (_pendingVitalLabel == LabelHealing)
|
||||
|
|
@ -3554,6 +3577,7 @@ public partial class BuffManager : IDisposable
|
|||
public void OnChatWindowText(string text, int chatType)
|
||||
{
|
||||
string lower = text.ToLowerInvariant();
|
||||
ObserveRecallLine(lower);
|
||||
|
||||
|
||||
// Diagnostic: log every chat seen while waiting on a cast confirmation,
|
||||
|
|
@ -3723,6 +3747,15 @@ public partial class BuffManager : IDisposable
|
|||
_lastManaRefusalAt = DateTime.Now; // a combat cast's refusal too: ManaStarved with costs unknown
|
||||
if (_pendingSpellId == 0) return;
|
||||
var pendingSpell = SpellTableStub.GetById(_pendingSpellId);
|
||||
// A recovery vital tries again soon for a better Mana Conversion roll (RecoveryRetry).
|
||||
if (OnRecoveryManaRefusal(pendingSpell))
|
||||
{
|
||||
_host.Log($"[BuffChat] CLEARED pending={_pendingSpellId} - not enough mana; retrying in {RecoveryRetryMs} ms, buffs {LowManaBuffPauseMs / 1000:0}s.");
|
||||
_pendingSpellId = 0;
|
||||
_lowManaPauseUntil = DateTime.Now.AddMilliseconds(LowManaBuffPauseMs);
|
||||
_onCastResolved?.Invoke("not enough mana");
|
||||
return;
|
||||
}
|
||||
double restSec = LowManaFamilyRestSec;
|
||||
if (pendingSpell != null)
|
||||
{
|
||||
|
|
@ -3867,6 +3900,7 @@ public partial class BuffManager : IDisposable
|
|||
// which never fires for instant vitals (Heal/Revitalize/Stamina to Mana), so
|
||||
// two slow confirmations hours apart parked Heal Self for 30 minutes.
|
||||
_silentNoShowCounts.Remove(spellInfo.Family);
|
||||
OnRecoveryCastResult(spellInfo.Family, spellInfo.Name);
|
||||
NoteCastAccepted(); // AC accepted a cast — end any too-busy backoff
|
||||
// Chat-authoritative record: only NOW (AC confirmed "you cast X").
|
||||
// Item/armor enchants live in _itemSpellTimers (what IsBuffActive
|
||||
|
|
|
|||
|
|
@ -74,7 +74,7 @@ public partial class CombatManager
|
|||
CombatHook.Reject(slot, "the client refused the cast", s => _host.Log(s));
|
||||
return false;
|
||||
}
|
||||
CombatHook.Cast(slot, spell, castTarget);
|
||||
CombatHook.Cast(slot, spell, castTarget, ActionPacer.LastCastSeqAtSend);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -134,6 +134,7 @@ public partial class CombatManager
|
|||
try { ok = _host.CastSpellFor(castTarget, spellId, "Combat", name + " (script)"); }
|
||||
catch { ok = false; }
|
||||
if (!ok) return false;
|
||||
ActionPacer.MarkScriptCast(spellId);
|
||||
|
||||
MarkCombatCastIssued();
|
||||
StartCastChatTrace(spellId, unchecked((int)castTarget)); // the server's answers, logged as for RynthAi's own casts
|
||||
|
|
@ -154,6 +155,7 @@ public partial class CombatManager
|
|||
_pendingOffensiveSpellId = spellId;
|
||||
_pendingOffensiveCastAt = DateTime.Now;
|
||||
_pendingOffensiveTargetId = activeTargetId;
|
||||
NoteOffensiveSeq();
|
||||
}
|
||||
// As the native block: a throw here must not fail the cast that already went out (the
|
||||
// slot would stay Decided and the same answer be cast again).
|
||||
|
|
|
|||
|
|
@ -1120,6 +1120,29 @@ public partial class CombatManager : IDisposable
|
|||
// chat-confirmation handler can record the cast against the right target
|
||||
// for blacklist judgement — even if activeTargetId has since changed.
|
||||
private int _pendingOffensiveTargetId = 0;
|
||||
// The UseDone count at the pending offensive cast's send, and its answer (-1 = not seen yet).
|
||||
private int _pendingOffensiveSeqAtSend;
|
||||
private long _pendingOffensiveErr = -1;
|
||||
/// <summary>Casts the server refused 'too busy' that were kept out of the no-damage count (tests, status).</summary>
|
||||
internal int RefusedCastsNotJudged { get; private set; }
|
||||
|
||||
private void NoteOffensiveSeq()
|
||||
{
|
||||
_pendingOffensiveSeqAtSend = _host.HasUseDoneSeq ? _host.GetUseDoneSeq() : 0;
|
||||
_pendingOffensiveErr = -1;
|
||||
}
|
||||
|
||||
/// <summary>The first UseDone after the pending offensive cast's send is its answer.</summary>
|
||||
private void ObserveOffensiveAnswer()
|
||||
{
|
||||
if (_pendingOffensiveErr >= 0 || !_host.HasUseDoneSeq) return;
|
||||
try
|
||||
{
|
||||
if (_host.TryGetLastUseDone(out int seq, out uint err) && seq == _pendingOffensiveSeqAtSend + 1)
|
||||
_pendingOffensiveErr = err;
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
private const double OFFENSIVE_NOCHAT_TIMEOUT_MS = 5000.0;
|
||||
// ACE doesn't emit "You cast X" chat for offensive war magic, so we infer
|
||||
// a successful server cast by NEGATION: if no "You're too busy!" arrives
|
||||
|
|
@ -2007,9 +2030,24 @@ public partial class CombatManager : IDisposable
|
|||
if (_pendingOffensiveSpellId == 0) return;
|
||||
if (_pendingOffensiveTargetId == 0) return;
|
||||
if (_pendingOffensiveCastAt == DateTime.MinValue) return;
|
||||
ObserveOffensiveAnswer();
|
||||
if ((DateTime.Now - _pendingOffensiveCastAt).TotalMilliseconds < OffensiveRefusalWindowMs)
|
||||
return;
|
||||
|
||||
// A refusal is not a cast (in a client log, three healthy targets were blacklisted 'after 3
|
||||
// no-damage casts' whose casts had all come back UseDone 0x1D):
|
||||
// the answer 0x1D, or no answer yet while the server is taken as busy, is not judged.
|
||||
bool refused = _pendingOffensiveErr == ActionPacer.TooBusyErr || (_pendingOffensiveErr < 0 && ActionPacer.ServerBusy);
|
||||
if (refused)
|
||||
{
|
||||
RefusedCastsNotJudged++;
|
||||
_host.Log($"[Blacklist] cast at 0x{(uint)_pendingOffensiveTargetId:X8} {(_pendingOffensiveErr >= 0 ? "refused 'too busy' (UseDone 0x1D)" : "unanswered while the server is busy")}: not counted as a no-damage cast");
|
||||
_pendingOffensiveSpellId = 0;
|
||||
_pendingOffensiveTargetId = 0;
|
||||
_pendingOffensiveCastAt = DateTime.MinValue;
|
||||
return;
|
||||
}
|
||||
|
||||
// Refusal window passed without a "too busy" — the server accepted
|
||||
// the gesture. Queue this cast for blacklist judgement.
|
||||
int targetId = _pendingOffensiveTargetId;
|
||||
|
|
@ -2948,12 +2986,13 @@ public partial class CombatManager : IDisposable
|
|||
// wield, attack or cast while the server is still answering the last action (a kit, a corpse
|
||||
// use, a buff, the last stance change). On ACE a mode change cancels a pending use's walk
|
||||
// and fails a cast in progress; that interleaving began every stuck-use stall on record.
|
||||
// Melee/missile attack repeats skip the animation gate (gestureGate false): the server swings
|
||||
// Melee/missile attack repeats skip the animation and settle gates and the 'too busy' latch (ACE
|
||||
// sends no UseDone for a swing, so a latch set by a refused pickup would starve them): the server swings
|
||||
// on its own timers, a swing can't land inside a use's server turn because the use above holds
|
||||
// every attack until it is answered, and waiting for each swing animation would cost DPS. A
|
||||
// stance change still waits (ChangeCombatModeFor), and so does everything in peace/magic.
|
||||
bool attackRepeat = CurrentCombatMode == CombatMode.Melee || CurrentCombatMode == CombatMode.Missile;
|
||||
if (!ActionPacer.MayStart(_host, "Combat", HealNeed.None, out _, gestureGate: !attackRepeat))
|
||||
if (!ActionPacer.MayStart(_host, "Combat", HealNeed.None, out _, animationGate: !attackRepeat, settleGate: !attackRepeat, attackRepeat: attackRepeat))
|
||||
{
|
||||
LastCombatSkipReason = "server-answering"; // D4 record-only
|
||||
_tickWait = CombatLatencyTracker.Wait.Busy;
|
||||
|
|
@ -5532,6 +5571,7 @@ public partial class CombatManager : IDisposable
|
|||
_pendingOffensiveSpellId = offensiveSpellId;
|
||||
_pendingOffensiveCastAt = DateTime.Now;
|
||||
_pendingOffensiveTargetId = activeTargetId;
|
||||
NoteOffensiveSeq();
|
||||
|
||||
// Tag this cast's weapon + element + tier so the pushed damage event
|
||||
// can be attributed to it, count it for casts-to-kill learning, then
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using RynthCore.Plugin.Shared;
|
||||
|
|
@ -35,6 +36,27 @@ internal static class CombatHook
|
|||
// The last decision consumed (handed back in the next request).
|
||||
public uint LastSeq, LastSpell, LastTarget;
|
||||
public long LastAtMs;
|
||||
// The cast in flight (PendingSpell 0 = none), with the UseDone count at its send, and the
|
||||
// most recent resolved cast with its final answer (ResolvedErr -1 = none could be read).
|
||||
public uint PendingSeq, PendingSpell, PendingTarget;
|
||||
public long PendingAtMs;
|
||||
public int PendingSeqAtSend = -1;
|
||||
// The UseDone count that answers it: one more than its send count, or than the answer of the
|
||||
// cast still in flight before it (both kinds, in send order); -1 = unknown (time limit only).
|
||||
public int PendingExpectSeq = -1;
|
||||
public uint ResolvedSeq, ResolvedSpell, ResolvedTarget;
|
||||
public long ResolvedAtMs;
|
||||
public int ResolvedErr = -1;
|
||||
|
||||
/// <summary>The cast in flight is done: <paramref name="err"/> its answer (-1 = none read).</summary>
|
||||
public void Resolve(int err)
|
||||
{
|
||||
if (PendingSpell == 0) return;
|
||||
ResolvedSeq = PendingSeq; ResolvedSpell = PendingSpell; ResolvedTarget = PendingTarget;
|
||||
ResolvedAtMs = PendingAtMs; ResolvedErr = err;
|
||||
PendingSeq = PendingSpell = PendingTarget = 0; PendingAtMs = 0; PendingSeqAtSend = -1; PendingExpectSeq = -1;
|
||||
InFlight.Remove(this);
|
||||
}
|
||||
|
||||
// Counters for /ra combat and the tests.
|
||||
public int Opened, Casts, Declines, Timeouts, Rejects;
|
||||
|
|
@ -46,6 +68,9 @@ internal static class CombatHook
|
|||
Open = false; Decided = false; Request = default;
|
||||
DecidedSpell = DecidedTarget = DecidedFlags = 0;
|
||||
LastSeq = LastSpell = LastTarget = 0; LastAtMs = 0;
|
||||
PendingSeq = PendingSpell = PendingTarget = 0; PendingAtMs = 0; PendingSeqAtSend = -1; PendingExpectSeq = -1;
|
||||
InFlight.Remove(this);
|
||||
ResolvedSeq = ResolvedSpell = ResolvedTarget = 0; ResolvedAtMs = 0; ResolvedErr = -1;
|
||||
Opened = Casts = Declines = Timeouts = Rejects = 0;
|
||||
LastTimeoutLogMs = LastRejectLogMs = long.MinValue;
|
||||
}
|
||||
|
|
@ -55,6 +80,39 @@ internal static class CombatHook
|
|||
internal static Func<long> Clock = static () => Environment.TickCount64;
|
||||
internal static long Now => Clock();
|
||||
|
||||
/// <summary>
|
||||
/// The last UseDone (count, error), or null when the engine can't say: RynthAi sets it at Init. A
|
||||
/// cast's answer is the first UseDone after its send (ctx.last.err).
|
||||
/// </summary>
|
||||
internal static Func<(int Seq, uint Err)?>? LastUseDone;
|
||||
|
||||
// The casts in flight of both kinds, in send order: the UseDones answer them in that order.
|
||||
private static readonly List<Slot> InFlight = new(2);
|
||||
|
||||
/// <summary>
|
||||
/// Resolves the casts in flight (each tick, at Poll, and before the next cast goes out), in send
|
||||
/// order: each one's answer is the UseDone after its send, or after the answer of the cast sent
|
||||
/// before it (an attack and a heal both in flight). A later count with that one unseen, or no
|
||||
/// UseDone within RynthAiCombat.ResolveTimeoutMs, resolves it with no answer (-1).
|
||||
/// </summary>
|
||||
public static void ObserveUseDone()
|
||||
{
|
||||
if (InFlight.Count == 0) return;
|
||||
(int Seq, uint Err)? last;
|
||||
try { last = LastUseDone?.Invoke(); } catch { last = null; }
|
||||
long now = Now;
|
||||
for (int i = 0; i < InFlight.Count;)
|
||||
{
|
||||
Slot s = InFlight[i];
|
||||
if (last is { } u && s.PendingExpectSeq >= 0 && u.Seq >= s.PendingExpectSeq)
|
||||
{
|
||||
s.Resolve(u.Seq == s.PendingExpectSeq ? unchecked((int)u.Err) : -1); // removes it
|
||||
continue;
|
||||
}
|
||||
if (now - s.PendingAtMs >= RynthAiCombat.ResolveTimeoutMs) { s.Resolve(-1); continue; }
|
||||
i++;
|
||||
}
|
||||
}
|
||||
/// <summary>A timeout is logged at most this often per kind.</summary>
|
||||
internal const long TimeoutLogIntervalMs = 60_000;
|
||||
private const long RejectLogIntervalMs = 5_000;
|
||||
|
|
@ -143,6 +201,16 @@ internal static class CombatHook
|
|||
request.LastSpell = s.LastSpell;
|
||||
request.LastTarget = s.LastTarget;
|
||||
request.LastAtMs = s.LastAtMs;
|
||||
ObserveUseDone();
|
||||
request.ResolvedSeq = s.ResolvedSeq;
|
||||
request.ResolvedSpell = s.ResolvedSpell;
|
||||
request.ResolvedTarget = s.ResolvedTarget;
|
||||
request.ResolvedAtMs = s.ResolvedAtMs;
|
||||
request.ResolvedErr = s.ResolvedSpell != 0 ? s.ResolvedErr : -1;
|
||||
request.PendingSeq = s.PendingSeq;
|
||||
request.PendingSpell = s.PendingSpell;
|
||||
request.PendingTarget = s.PendingTarget;
|
||||
request.PendingAtMs = s.PendingAtMs;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -232,10 +300,14 @@ internal static class CombatHook
|
|||
return Outcome.Wait;
|
||||
}
|
||||
|
||||
/// <summary>The decided spell went out (or was waited on): the request is done.</summary>
|
||||
public static void Cast(Slot slot, uint spellId, uint targetId)
|
||||
/// <summary>
|
||||
/// The decided spell went out (or was waited on): the request is done. <paramref name="seqAtSend"/>
|
||||
/// is the UseDone count read just before the send (ActionPacer.LastCastSeqAtSend); -1 reads the
|
||||
/// last UseDone now instead.
|
||||
/// </summary>
|
||||
public static void Cast(Slot slot, uint spellId, uint targetId, int seqAtSend = -1)
|
||||
{
|
||||
Consume(slot, spellId, targetId);
|
||||
Consume(slot, spellId, targetId, seqAtSend);
|
||||
if (spellId != 0) slot.Casts++; // 0: handled without a cast (a wand swap step in flight)
|
||||
}
|
||||
|
||||
|
|
@ -253,12 +325,31 @@ internal static class CombatHook
|
|||
}
|
||||
}
|
||||
|
||||
private static void Consume(Slot slot, uint spellId, uint targetId)
|
||||
private static void Consume(Slot slot, uint spellId, uint targetId, int seqAtSend = -1)
|
||||
{
|
||||
slot.LastSeq = slot.Request.Seq;
|
||||
slot.LastSpell = spellId;
|
||||
slot.LastTarget = targetId;
|
||||
slot.LastAtMs = Now;
|
||||
if (spellId != 0)
|
||||
{
|
||||
// The cast before it resolves first (its answer if one came, else none).
|
||||
ObserveUseDone();
|
||||
slot.Resolve(-1);
|
||||
slot.PendingSeq = slot.Request.Seq;
|
||||
slot.PendingSpell = spellId;
|
||||
slot.PendingTarget = targetId;
|
||||
slot.PendingAtMs = slot.LastAtMs;
|
||||
// The count read before the send: a UseDone that lands between the send and this call is
|
||||
// then still this cast's answer, not taken as the baseline.
|
||||
if (seqAtSend >= 0) slot.PendingSeqAtSend = seqAtSend;
|
||||
else try { slot.PendingSeqAtSend = LastUseDone?.Invoke()?.Seq ?? -1; } catch { slot.PendingSeqAtSend = -1; }
|
||||
Slot? before = InFlight.Count > 0 ? InFlight[InFlight.Count - 1] : null;
|
||||
if (slot.PendingSeqAtSend < 0) slot.PendingExpectSeq = -1;
|
||||
else if (before != null && before.PendingExpectSeq < 0) slot.PendingExpectSeq = -1; // can't tell which answer is whose
|
||||
else slot.PendingExpectSeq = Math.Max(slot.PendingSeqAtSend, before?.PendingExpectSeq ?? int.MinValue) + 1;
|
||||
InFlight.Add(slot);
|
||||
}
|
||||
slot.Open = false;
|
||||
slot.Decided = false;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -507,6 +507,32 @@ internal sealed class LegacyAdvancedSettingsUi
|
|||
"Lower = faster buff chains. 400ms is a good balance.\n" +
|
||||
"Below 200ms may cause fizzles or dropped casts on laggy servers.");
|
||||
|
||||
ImGui.SetNextItemWidth(180);
|
||||
ImGui.SliderInt("Stuck Cast Break (ms)", ref _settings.StuckCastBreakMs, 0, 20000);
|
||||
if (ImGui.IsItemHovered())
|
||||
ImGui.SetTooltip(
|
||||
"The longest a cast may stay unanswered before it is broken\n" +
|
||||
"with a jump (the server then fails the cast). It fires sooner,\n" +
|
||||
"about 2 s past the spell's normal cycle, when that is shorter.\n" +
|
||||
"After a 'too busy' answer nothing is cast until the server answers.\n" +
|
||||
"0 = never break.");
|
||||
|
||||
ImGui.SetNextItemWidth(180);
|
||||
ImGui.SliderInt("Recovery Retry (ms)", ref _settings.RecoveryRetryMs, 200, 5000);
|
||||
if (ImGui.IsItemHovered())
|
||||
ImGui.SetTooltip(
|
||||
"Heal Self, Stamina to Health, Revitalize and Stamina to Mana refused\n" +
|
||||
"for 'not enough mana' are tried again after this long: each try\n" +
|
||||
"rolls Mana Conversion again, and a refusal costs nothing.\n" +
|
||||
"At most 5 tries a second, 20 in a row.");
|
||||
|
||||
ImGui.Checkbox("HP Failsafe Recall", ref _settings.HpFailsafeRecall);
|
||||
if (ImGui.IsItemHovered())
|
||||
ImGui.SetTooltip(
|
||||
"At or under Emergency Heal At with heals failing: break the\n" +
|
||||
"stuck cast with a jump and heal again; if that fails too,\n" +
|
||||
"recall to the lifestone.");
|
||||
|
||||
ImGui.SetNextItemWidth(180);
|
||||
ImGui.SliderInt("Attack Spell Delay (ms)", ref _settings.AttackSpellIntervalMs, 0, 5000);
|
||||
if (ImGui.IsItemHovered())
|
||||
|
|
|
|||
|
|
@ -1816,6 +1816,9 @@ internal sealed class LegacyDashboardRenderer
|
|||
dst.GiveQueueIntervalMs = tmp.GiveQueueIntervalMs;
|
||||
dst.T11ItemAugsOverride = tmp.T11ItemAugsOverride;
|
||||
dst.SpellCastIntervalMs = tmp.SpellCastIntervalMs;
|
||||
dst.StuckCastBreakMs = tmp.StuckCastBreakMs;
|
||||
dst.RecoveryRetryMs = tmp.RecoveryRetryMs;
|
||||
dst.HpFailsafeRecall = tmp.HpFailsafeRecall;
|
||||
dst.AttackSpellIntervalMs = tmp.AttackSpellIntervalMs;
|
||||
dst.EmbeddedNavs = tmp.EmbeddedNavs;
|
||||
dst.SuppressRetailRadar = tmp.SuppressRetailRadar;
|
||||
|
|
|
|||
|
|
@ -332,6 +332,30 @@ public sealed class LegacyUiSettings
|
|||
|
||||
public int SpellCastIntervalMs = 400;
|
||||
|
||||
/// <summary>
|
||||
/// Stuck-cast breaker (Plugins/Shared/ActionPacer.cs): the longest a cast may stay unanswered
|
||||
/// (ms from the send; no result, no UseDone) before it is broken with a jump (a Peace mode
|
||||
/// request when the engine can't jump). It fires sooner, about 2 s past the spell's normal
|
||||
/// cycle, when that is shorter. Nothing is cast meanwhile once the server says 'too busy'.
|
||||
/// 0 = no breaker.
|
||||
/// </summary>
|
||||
public int StuckCastBreakMs = 8000;
|
||||
|
||||
/// <summary>
|
||||
/// Recovery vitals (Heal Self, Stamina to Health, Revitalize, Stamina to Mana) refused for
|
||||
/// "not enough mana" are tried again after this many ms, for a better Mana Conversion roll
|
||||
/// (ACE rolls the cost on every attempt and a refusal costs nothing). Clamped to 200..5000;
|
||||
/// at most 5 tries a second and 20 refusals in a row, then the old 15 s family rest.
|
||||
/// </summary>
|
||||
public int RecoveryRetryMs = 200;
|
||||
|
||||
/// <summary>
|
||||
/// HP failsafe: at or under Emergency Heal At with heals failing for a while, the stuck-cast
|
||||
/// breaker runs and the heal is tried again; when that fails too, recall to the lifestone.
|
||||
/// Off: the breaker still runs, no recall.
|
||||
/// </summary>
|
||||
public bool HpFailsafeRecall = true;
|
||||
|
||||
/// <summary>
|
||||
/// Minimum delay between offensive (war/void) COMBAT spell casts, in ms.
|
||||
/// Combat magic uses this instead of <see cref="SpellCastIntervalMs"/> so
|
||||
|
|
|
|||
|
|
@ -55,6 +55,16 @@ public sealed partial class RynthAiPlugin
|
|||
/// reloaded the world) came with the bot still casting and dequipping through
|
||||
/// the death. Reads the vitals every tick (the regular poll is every 30).
|
||||
/// </summary>
|
||||
private bool _wasPortalingForPacer;
|
||||
|
||||
/// <summary>Portal space starts: the server dropped what was open (no breaker on a teleport's gap).</summary>
|
||||
private void NotePortalForPacer()
|
||||
{
|
||||
bool portaling = Host.HasIsPortaling && Host.IsPortaling();
|
||||
if (portaling && !_wasPortalingForPacer) RynthCore.Plugin.Shared.ActionPacer.Forget("portal space");
|
||||
_wasPortalingForPacer = portaling;
|
||||
}
|
||||
|
||||
private bool HoldForDeath()
|
||||
{
|
||||
long now = Environment.TickCount64;
|
||||
|
|
@ -82,6 +92,8 @@ public sealed partial class RynthAiPlugin
|
|||
Log("[RynthAi] Died — holding all actions until respawned and out of portal space.");
|
||||
_combatManager?.ReleaseHeldTurn();
|
||||
_navigationEngine?.Stop();
|
||||
RynthCore.Plugin.Shared.ActionPacer.Forget("death"); // the server dropped whatever was open
|
||||
_buffManager?.CancelPendingRecall("death"); // no /lifestone or macro restart after the respawn
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
|||
|
|
@ -185,6 +185,8 @@ public sealed partial class RynthAiPlugin : RynthPluginBase
|
|||
// use-on, cast and combat-mode change waits for the server's answer to the last one.
|
||||
RynthCore.Plugin.Shared.ActionPacer.Reset();
|
||||
RynthCore.Plugin.Shared.ActionPacer.Enabled = true;
|
||||
var hookHost = Host;
|
||||
CombatHook.LastUseDone = () => hookHost.HasUseDoneSeq && hookHost.TryGetLastUseDone(out int s, out uint e) ? (s, e) : null;
|
||||
RynthCore.Plugin.Shared.UseAudit.AfterSend = RecordUseForPacing;
|
||||
_objectCache = new WorldObjectCache(Host); // must exist before CreateObject events fire during login
|
||||
// Items we use (or use something on) get re-identified before a meta reads them.
|
||||
|
|
@ -597,6 +599,15 @@ public sealed partial class RynthAiPlugin : RynthPluginBase
|
|||
_weaponSwapGate.IsWielded = id => RynthCore.Plugin.Shared.ActionPacer.IsWieldedByPlayer(Host, unchecked((uint)id));
|
||||
|
||||
_buffManager = new BuffManager(Host, _dashboard.Settings, _spellManager, _vitals);
|
||||
// The HP failsafe's recall stops the macro as /ra stop does (the macro-stop edge in OnTick
|
||||
// then cancels the attack and stops movement): a move during the recall cancels it.
|
||||
_buffManager.MacroStopForRecall = () =>
|
||||
{
|
||||
_macroResumeAt = 0;
|
||||
_navigationEngine?.Stop();
|
||||
};
|
||||
// The failsafe switching the macro back on after a failed recall is a start like any other.
|
||||
_buffManager.MayRestartMacro = () => !RefuseMacroStartForVTank();
|
||||
_inGameMarkerSet = false;
|
||||
if (IsCarriedOverSession(_playerId))
|
||||
{
|
||||
|
|
@ -887,7 +898,7 @@ public sealed partial class RynthAiPlugin : RynthPluginBase
|
|||
["MeleeAttackPower"] = (-1, 100), ["MissileAttackPower"] = (-1, 100),
|
||||
["MeleeAttackHeight"] = (0, 2), ["MissileAttackHeight"] = (0, 2),
|
||||
["PetMinMonsters"] = (1, 20),
|
||||
["SpellCastIntervalMs"] = (100, 1500), ["AttackSpellIntervalMs"] = (0, 5000), ["MinRingTargets"] = (1, 20), ["MinBlastTargets"] = (1, 20), ["BlastRange"] = (0, 100), ["MinWallTargets"] = (1, 20), ["WallRange"] = (0, 100),
|
||||
["SpellCastIntervalMs"] = (100, 1500), ["StuckCastBreakMs"] = (0, 60000), ["RecoveryRetryMs"] = (200, 5000), ["AttackSpellIntervalMs"] = (0, 5000), ["MinRingTargets"] = (1, 20), ["MinBlastTargets"] = (1, 20), ["BlastRange"] = (0, 100), ["MinWallTargets"] = (1, 20), ["WallRange"] = (0, 100),
|
||||
["MinSkillLevelTier1"] = (1, 500), ["MinSkillLevelTier2"] = (1, 500), ["MinSkillLevelTier3"] = (1, 500), ["MinSkillLevelTier4"] = (1, 500),
|
||||
["MinSkillLevelTier5"] = (1, 500), ["MinSkillLevelTier6"] = (1, 500), ["MinSkillLevelTier7"] = (1, 500), ["MinSkillLevelTier8"] = (1, 500),
|
||||
["MonsterRange"] = (1, 200), ["MonsterDisengageRange"] = (0, 200), ["TargetSelection"] = (0, 3), ["RingRange"] = (1, 50), ["ApproachRange"] = (1, 50),
|
||||
|
|
@ -1248,6 +1259,7 @@ public sealed partial class RynthAiPlugin : RynthPluginBase
|
|||
try
|
||||
{
|
||||
_dashboard?.DrainMetaCommands(); // apply queued meta edits on this (plugin-tick) thread
|
||||
CombatHook.ObserveUseDone(); // ctx.last.err: the answer to the hook's last cast
|
||||
TickDelayedCommands(); // /ub delay
|
||||
if (_loginComplete) _dashboard?.TickPackSetup(_objectCache, _playerId); // new/copied profile items
|
||||
|
||||
|
|
@ -1488,6 +1500,11 @@ public sealed partial class RynthAiPlugin : RynthPluginBase
|
|||
if (_dashboard?.Settings is { } safetySettings) CheckPlayerDeath(safetySettings);
|
||||
// Dead or on the way back from a death: do nothing (HoldForDeath). The
|
||||
// finally below still submits the nav markers.
|
||||
RynthCore.Plugin.Shared.ActionPacer.NoteFrame();
|
||||
// Stuck Cast Break, once per tick: the breaker runs for every subsystem's casts.
|
||||
if (_dashboard?.Settings is { } paceSettings)
|
||||
RynthCore.Plugin.Shared.ActionPacer.StuckCastMs = Math.Max(0, paceSettings.StuckCastBreakMs);
|
||||
NotePortalForPacer();
|
||||
if (HoldForDeath())
|
||||
return;
|
||||
// Standing in acid or lava: nothing but getting out (RynthAiPlugin.HazardEscape.cs).
|
||||
|
|
|
|||
Loading…
Reference in a new issue