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>
180 lines
7.5 KiB
C#
180 lines
7.5 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using RynthCore.Plugin.RynthAi.LegacyUi;
|
|
|
|
namespace RynthCore.Plugin.RynthAi;
|
|
|
|
/// <summary>
|
|
/// Safety stops for bots running unattended. Every stop is an option; each one
|
|
/// says in chat why the macro stopped. Most metas handle a death themselves (run
|
|
/// back from the lifestone), so Stop Macro On Death is off by default.
|
|
/// </summary>
|
|
public sealed partial class RynthAiPlugin
|
|
{
|
|
private bool _deathSeen;
|
|
private readonly Queue<long> _noComponentFails = new();
|
|
private long _packFullCheckedAt;
|
|
private bool _packFull;
|
|
private bool _packFullAnnounced;
|
|
|
|
private const int NoComponentFailsToStop = 3;
|
|
private const long NoComponentWindowMs = 60_000;
|
|
private const long PackFullCheckMs = 3_000;
|
|
|
|
/// <summary>Death = health read as 0 (edge). Runs every tick after the vitals poll.</summary>
|
|
private void CheckPlayerDeath(LegacyUiSettings s)
|
|
{
|
|
bool dead = _vitals.MaxHealth > 0 && _vitals.CurrentHealth == 0;
|
|
if (dead && !_deathSeen)
|
|
{
|
|
_deathSeen = true;
|
|
Log("[RynthAi] Death detected (health 0).");
|
|
try { RecordDeathSpot(); } // where the corpse will be (RynthAiPlugin.OwnCorpse.cs)
|
|
catch (Exception ex) { Log($"[RynthAi] Death spot not recorded: {ex.Message}"); }
|
|
if (s.StopMacroOnDeath && s.IsMacroRunning)
|
|
{
|
|
HandleMacroRunCommand("stop", Array.Empty<string>());
|
|
ChatLine("[RynthAi] You died — macro stopped (Stop Macro On Death is on).");
|
|
}
|
|
}
|
|
else if (!dead && _vitals.CurrentHealth > 0)
|
|
{
|
|
_deathSeen = false;
|
|
}
|
|
}
|
|
|
|
private long _deathHoldUntil;
|
|
private bool _deathHolding;
|
|
private const long DeathSettleMs = 5_000;
|
|
|
|
/// <summary>
|
|
/// True from a death until the character is alive, out of portal space and
|
|
/// has had 5 s to settle. While it holds, the bot does nothing: no buffing,
|
|
/// combat, weapon swaps, looting, busy clears or navigation. Both death-portal
|
|
/// crashes (2026-09-28 12:04 and 18:06, inside AC's code while it tore down and
|
|
/// 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;
|
|
bool dead = Host.HasGetPlayerVitals
|
|
&& Host.TryGetPlayerVitals(out uint hp, out uint maxHp, out _, out _, out _, out _)
|
|
&& maxHp > 0 && hp == 0;
|
|
if (dead)
|
|
{
|
|
_deathHoldUntil = long.MaxValue;
|
|
_metaManager?.OnPlayerDeath(); // the meta's Death condition sees it after the hold
|
|
}
|
|
else if (_deathHoldUntil == long.MaxValue)
|
|
{
|
|
// Alive again: wait out the portal to the lifestone, then settle.
|
|
if (!(Host.HasIsPortaling && Host.IsPortaling()))
|
|
_deathHoldUntil = now + DeathSettleMs;
|
|
}
|
|
|
|
bool hold = now < _deathHoldUntil;
|
|
if (hold != _deathHolding)
|
|
{
|
|
_deathHolding = hold;
|
|
if (hold)
|
|
{
|
|
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
|
|
{
|
|
Log("[RynthAi] Respawned — resuming.");
|
|
try { OnRespawnedForOwnCorpse(); } // Travel Back To My Corpse
|
|
catch (Exception ex) { Log($"[RynthAi] Own corpse travel not started: {ex.Message}"); }
|
|
}
|
|
}
|
|
return hold;
|
|
}
|
|
|
|
/// <summary>Chat hook: repeated "don't have all the components" stops the macro when enabled.</summary>
|
|
private void CheckChatForSafetyStops(string text)
|
|
{
|
|
var s = _dashboard?.Settings;
|
|
if (s == null || !s.StopMacroOnNoComponents || !s.IsMacroRunning) return;
|
|
if (text.IndexOf("have all the components for this spell", StringComparison.OrdinalIgnoreCase) < 0) return;
|
|
|
|
long now = Environment.TickCount64;
|
|
_noComponentFails.Enqueue(now);
|
|
while (_noComponentFails.Count > 0 && now - _noComponentFails.Peek() > NoComponentWindowMs)
|
|
_noComponentFails.Dequeue();
|
|
if (_noComponentFails.Count < NoComponentFailsToStop) return;
|
|
|
|
_noComponentFails.Clear();
|
|
HandleMacroRunCommand("stop", Array.Empty<string>());
|
|
ChatLine("[RynthAi] Out of spell components — macro stopped (Stop Macro On No Components is on).");
|
|
}
|
|
|
|
/// <summary>
|
|
/// True when no pack (main pack included) has a free slot. Checked at most
|
|
/// every 3 s. The first time it turns true: a chat notice, and the macro
|
|
/// stops if Stop Macro When Pack Full is on.
|
|
/// </summary>
|
|
internal bool IsPackFull()
|
|
{
|
|
long now = Environment.TickCount64;
|
|
if (now - _packFullCheckedAt < PackFullCheckMs) return _packFull;
|
|
_packFullCheckedAt = now;
|
|
|
|
bool full = _objectCache != null && _playerId != 0
|
|
&& WorldObjectCache.FindPackFor(Host, _objectCache, includeMainPack: true, requireFree: 1) == 0;
|
|
_packFull = full;
|
|
if (!full) { _packFullAnnounced = false; return false; }
|
|
|
|
if (!_packFullAnnounced)
|
|
{
|
|
_packFullAnnounced = true;
|
|
var s = _dashboard?.Settings;
|
|
if (s != null && s.StopMacroWhenPackFull && s.IsMacroRunning)
|
|
{
|
|
HandleMacroRunCommand("stop", Array.Empty<string>());
|
|
ChatLine("[RynthAi] Your packs are full — macro stopped (Stop Macro When Pack Full is on).");
|
|
}
|
|
else
|
|
{
|
|
ChatLine("[RynthAi] Your packs are full — not looting until there's room.");
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
|
|
private long _lootReserveCheckedAt;
|
|
private bool _belowLootReserve;
|
|
|
|
/// <summary>
|
|
/// True when fewer slots are free than looting keeps for weapon swaps
|
|
/// (LootReserveFreeSlots). The pickup gate refuses every item then, so a new
|
|
/// corpse would only be walked to, opened and given up on. Checked at most every
|
|
/// 3 s; -1 (side-pack capacity unknown) is not treated as low.
|
|
/// </summary>
|
|
internal bool IsBelowLootReserve()
|
|
{
|
|
long now = Environment.TickCount64;
|
|
if (now - _lootReserveCheckedAt < PackFullCheckMs) return _belowLootReserve;
|
|
_lootReserveCheckedAt = now;
|
|
|
|
int free = _playerId != 0 ? WorldObjectCache.CountFreeItemSlots(Host, _objectCache) : -1;
|
|
_belowLootReserve = free >= 0 && free < WorldObjectCache.LootReserveFreeSlots;
|
|
if (_belowLootReserve)
|
|
WorldObjectCache.WarnPackFull(Host, $"not looting with {free} free slot(s) so weapon swaps still work");
|
|
return _belowLootReserve;
|
|
}
|
|
}
|