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>
108 lines
5.5 KiB
C#
108 lines
5.5 KiB
C#
using System;
|
|
using RynthCore.PluginSdk;
|
|
using RynthCore.Plugin.RynthAi.LegacyUi;
|
|
using RynthCore.Plugin.Shared;
|
|
|
|
namespace RynthCore.Plugin.RynthAi;
|
|
|
|
// The heal seam of the script-provided combat hook (RynthAi.Combat, CombatHookInterface.cs):
|
|
// CheckVitals asks the script for the heal spell (and its target: the player, or a monster for a
|
|
// drain) before kits. The cast itself goes through CastVital, the same steps as Heal Self.
|
|
public partial class BuffManager
|
|
{
|
|
/// <summary>
|
|
/// True when the hook handled this vitals check: waiting for the answer, or the answer was
|
|
/// cast (or its wand swap is in flight). False = the native order (kit, Heal Self, potion).
|
|
/// </summary>
|
|
private bool TryScriptHeal(int healLine, bool inCombat)
|
|
{
|
|
// AC just said "You're too busy!": the same pacing as a Heal Self (AttemptVitalCast).
|
|
if (DateTime.Now < _busyBackoffUntil && (DateTime.Now - _lastCastAttempt).TotalMilliseconds < BusyHealRetryMs)
|
|
{
|
|
_vitalWhy = $"AC too busy, waiting {(_busyBackoffUntil - DateTime.Now).TotalMilliseconds:0} ms";
|
|
_healWaitKind = "too-busy backoff";
|
|
return true;
|
|
}
|
|
|
|
var slot = CombatHook.Heal;
|
|
// The request names RynthAi's current fight target (informational: the monster with live
|
|
// health data, e.g. for a drain); a fight target change re-asks. The answer's target 0
|
|
// still means the player.
|
|
var cm = _combatManager;
|
|
uint fight = cm == null ? 0u : unchecked((uint)cm.activeTargetId);
|
|
var outcome = CombatHook.Step(slot, fight, () => BuildHealRequest(healLine, inCombat), s => _host.Log(s),
|
|
out uint spell, out uint target, out _);
|
|
switch (outcome)
|
|
{
|
|
case CombatHook.Outcome.Native:
|
|
return false;
|
|
case CombatHook.Outcome.Wait:
|
|
_vitalWhy = $"waiting for '{CombatHook.Owner}' to choose the heal";
|
|
_healWaitKind = "script choosing the heal";
|
|
return true;
|
|
}
|
|
|
|
uint player = (uint)_host.GetPlayerId();
|
|
if (target == 0) target = player;
|
|
string? why = ScriptHealProblem(spell, target, player);
|
|
if (why != null)
|
|
{
|
|
CombatHook.Reject(slot, why, s => _host.Log(s));
|
|
return false;
|
|
}
|
|
string name = SpellTableStub.GetById((int)spell)?.Name ?? $"spell {spell}";
|
|
bool handled = CastVital((int)spell, target, LabelHealing, name + " (script)", out bool sent);
|
|
if (!handled)
|
|
{
|
|
CombatHook.Reject(slot, _vitalWhy.Length > 0 ? _vitalWhy : "it couldn't be cast", s => _host.Log(s));
|
|
return false;
|
|
}
|
|
// A script-chosen heal takes no early nudge (HeldNudgeUrgent): its result can come later
|
|
// 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, sent ? ActionPacer.LastCastSeqAtSend : -1);
|
|
if (sent) _host.Log($"[RynthAi] Vitals: script heal id={spell} '{name}' at 0x{target:X8} (owner '{CombatHook.Owner}').");
|
|
return true;
|
|
}
|
|
|
|
/// <summary>Why the script's heal can't be cast, or null when it can.</summary>
|
|
private string? ScriptHealProblem(uint spell, uint target, uint player)
|
|
{
|
|
if (!_spellManager.IsKnownSpellId((int)spell)) return $"spell {spell} isn't known";
|
|
// The refusal memory RynthAi's own heal honours (AttemptVitalCast): a level the server
|
|
// said there are no components for.
|
|
if (LevelLacksComponents((int)spell)) return $"spell {spell} has no components (refused by the server; RynthAi uses a lower level)";
|
|
if (target == player) return null;
|
|
var cm = _combatManager;
|
|
// Monster rule Priority 0 = never attacked: a drain at one is refused too, even when it is
|
|
// still the fight target (its rule changed before Think dropped it) or still scanned.
|
|
if (cm != null && cm.IsIgnored(unchecked((int)target))) return "the target is ignored (monster rule Priority 0)";
|
|
bool listed = cm != null && unchecked((uint)cm.activeTargetId) == target;
|
|
if (!listed && cm != null)
|
|
foreach (var t in cm.ScannedTargets)
|
|
if (unchecked((uint)t.Id) == target) { listed = true; break; }
|
|
if (!listed) return "the target is not the player, the fight target or a scanned monster";
|
|
if (_host.HasObjectIsAttackable && !_host.ObjectIsAttackable(target)) return "the target is not attackable";
|
|
return null;
|
|
}
|
|
|
|
private CombatRequestV1 BuildHealRequest(int healLine, bool inCombat)
|
|
{
|
|
bool known = _vitals.MaxHealth > 0;
|
|
var cm = _combatManager;
|
|
float fightHealth = cm?.FightTargetHealthRatio ?? -1f;
|
|
return new CombatRequestV1
|
|
{
|
|
TargetHealth = fightHealth,
|
|
HealthPct = known ? _vitals.HealthPct : -1,
|
|
StaminaPct = _vitals.MaxStamina > 0 ? _vitals.StaminaPct : -1,
|
|
ManaPct = _vitals.MaxMana > 0 ? _vitals.ManaPct : -1,
|
|
HealLine = healLine,
|
|
InCombat = inCombat ? 1 : 0,
|
|
CombatMode = CurrentCombatMode,
|
|
};
|
|
}
|
|
}
|