RynthAi: no false "never reached your hand" weapon ban

A weapon that did reach the hand could be banned for 30 minutes: buffing swapped it out for a wand before combat looked again, and each such wield counted as a failed try. Sample the engine's equipment list while wields are under way; a weapon seen in a main-hand slot during its run of wields has its tries reset and is never banned as 'never reached your hand'.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Daniel Wallace 2026-11-07 08:57:56 -08:00
commit 70941f12d6
5 changed files with 330 additions and 1 deletions

View file

@ -4546,6 +4546,7 @@ public partial class CombatManager : IDisposable
public void OnHeartbeat()
{
NoteSwapPortal();
NoteSwapWieldsSeen();
// The hands swap's steps (weapons back, or the fight's weapons) go before the gates; the macro stopping ends it (freeing the gate).
TickRearmSwap();
@ -5877,7 +5878,7 @@ public partial class CombatManager : IDisposable
// The server's own list (v87) says it never reached the hand: the wield can't work
// (the client refused it unasked). Out of the choice like a "skill too low" answer,
// not retried every 2 minutes with the off hand taken off each time (the Tetsubo, 2026-10-18).
if (SwapTracker.GaveUpId is int gaveUp && EquippedState.TryGet(_host, out _))
if (SwapTracker.GaveUpId is int gaveUp && NeverReachedHand(gaveUp))
NoteSkillTooLow(gaveUp, "it never reached your hand (the client refused the wield)");
}
SwapTracker.GaveUpId = null;
@ -5891,6 +5892,40 @@ public partial class CombatManager : IDisposable
private DateTime _lastSwapHoldLogAt = DateTime.MinValue;
/// <summary>
/// True only when the engine's equipment list can be read, does not hold
/// <paramref name="id"/> now, and the swap tracker never saw it there while its wields were
/// under way (<see cref="NoteSwapWieldsSeen"/>). A readable list alone used to be enough,
/// so a weapon that did reach the hand, and that buffing then swapped out for a wand before
/// combat looked, was banned for 30 min.
/// </summary>
private bool NeverReachedHand(int id)
{
if (SwapTracker.WasSeenWielded(id)) return false;
EquippedState.Invalidate();
return EquippedState.TryGet(_host, out var map) && !map.ContainsKey(id);
}
/// <summary>
/// While a combat wield is in flight or has recent tries counted, read the engine's equipment
/// list (API v87, the server's own wield messages) and tell the swap tracker about every item
/// in a main-hand slot (the slots <see cref="InHandWeaponId"/> reads; a weapon sitting in the
/// shield slot is not the wield combat asked for). Called every tick by the plugin ahead of its
/// buffing hold, because the buffing hold skips <see cref="OnHeartbeat"/>, and from OnHeartbeat
/// itself. No game command.
/// </summary>
internal void NoteSwapWieldsSeen()
{
try
{
if (!SwapTracker.HasAttemptsAt(RynthClock.Now)) return;
if (!EquippedState.TryGet(_host, out var map)) return;
foreach (var kv in map)
if ((kv.Value & MainHandSlots) != 0) SwapTracker.SeenWielded(kv.Key);
}
catch { /* a failed read must never stop the tick */ }
}
/// <summary>
/// Why a swap the tracker allows should not start now (null = start it). Settling: the
/// target was switched to (it replaced another live target) under WeaponSwapSettleMs ago;

View file

@ -61,9 +61,44 @@ internal sealed class WeaponSwapTracker
private int _lastFrom, _lastTo;
private DateTime _lastLandedAt = DateTime.MinValue;
private int _askKey, _pendingKey, _lastKey; // the fight (target id) each swap was for; 0 = unknown
// Weapons seen in a wielded slot (the engine's equipment list) during their current run of
// wields. A new run (the first send after the count was cleared) forgets the sighting, so a
// weapon that later stops reaching the hand is given up on again.
private readonly HashSet<int> _seenWielded = new();
private DateTime _lastSentAt = DateTime.MinValue;
/// <summary>How long after the last send counted tries keep the equipment list sampled.</summary>
public double AttemptWatchMs { get; set; } = 120_000;
/// <summary>The weapon a swap is in flight for (0 = none).</summary>
public int PendingId => _pendingId;
/// <summary>
/// True while a wield is in flight, or tries are counted and the last send was under
/// <see cref="AttemptWatchMs"/> before <paramref name="now"/>: the equipment list is worth
/// sampling. A stale count left behind does not keep the sampler reading every tick.
/// </summary>
public bool HasAttemptsAt(DateTime now) =>
_pendingId != 0 || (_tries.Count > 0 && (now - _lastSentAt).TotalMilliseconds < AttemptWatchMs);
/// <summary>True when <paramref name="id"/> was seen wielded while its wields were under way (see <see cref="SeenWielded"/>).</summary>
public bool WasSeenWielded(int id) => _seenWielded.Contains(id);
/// <summary>
/// <paramref name="id"/> is in a wielded slot per the engine's equipment list, sampled every
/// tick while a wield is under way. When it has a wield in flight or tries counted, the wield
/// worked: its try count starts over and it is remembered as seen, so it is never taken for a
/// weapon that "never reached your hand". The swap in flight is left alone (combat lands it
/// when it sees the weapon in hand itself), so a stale hand read can never send a second
/// UseObject that would take the weapon off again. A weapon reached the hand
/// twice, buffing swapped it out to a wand each time before combat looked again, and each of
/// those wields counted as a failed try until it was banned for 30 min.
/// </summary>
public void SeenWielded(int id)
{
if (id == 0 || (_pendingId != id && !_tries.ContainsKey(id))) return;
_seenWielded.Add(id);
_tries.Remove(id);
_busyRefunds.Remove(id);
}
/// <summary>Wields sent for <paramref name="id"/> since it was last in hand.</summary>
public int TriesFor(int id) => _tries.TryGetValue(id, out int t) ? t : 0;
/// <summary>Why the last Hold happened, for the log ("" = none).</summary>
@ -140,6 +175,9 @@ internal sealed class WeaponSwapTracker
_pendingId = id;
_pendingFrom = fromId;
_pendingAt = now;
_lastSentAt = now;
// A fresh run of wields: an earlier sighting says nothing about this one.
if (!_tries.ContainsKey(id)) _seenWielded.Remove(id);
_tries[id] = (_tries.TryGetValue(id, out int t) ? t : 0) + 1;
}
@ -179,6 +217,7 @@ internal sealed class WeaponSwapTracker
_tries.Clear();
_busyRefunds.Clear();
_restUntil.Clear();
_seenWielded.Clear();
_busyUntil = DateTime.MinValue;
}
@ -196,9 +235,11 @@ internal sealed class WeaponSwapTracker
_busyRefunds.Clear();
_busyUntil = DateTime.MinValue;
_restUntil.Clear();
_seenWielded.Clear();
_landed.Clear();
_lastFrom = _lastTo = 0;
_lastLandedAt = DateTime.MinValue;
_lastSentAt = DateTime.MinValue;
_askKey = _pendingKey = _lastKey = 0;
HoldReason = "";
Notice = null;

View file

@ -1739,6 +1739,11 @@ public sealed partial class RynthAiPlugin : RynthPluginBase
// Healing and buffs: essential, never switched off by its guard (TickGuard).
Guard(TickStep.BuffsAndVitals, () => _buffManager?.OnHeartbeat());
if (diag) Host.Log("[RynthAi] OnTick: after buffManager");
// Combat's wields in flight, checked against the equipment list every tick, ahead of
// the buffing hold below (which skips combat's heartbeat): a weapon that reached the
// hand and was swapped out for a wand by buffing is not a failed wield.
// Reads only, and catches its own faults.
_combatManager?.NoteSwapWieldsSeen();
Guard(TickStep.ReloadBlocker, () =>
{
NoteCarriedOverSessionReady();