Snapshot for release 2026.10.29.3 (internal f81a090)
This commit is contained in:
parent
6c15f65e94
commit
aa8bf65897
27 changed files with 1821 additions and 61 deletions
|
|
@ -57,7 +57,7 @@ internal static unsafe class ActivityInterface
|
|||
|
||||
/// <summary>The bits from RynthAi's state (pure, so the host tests check the mapping).</summary>
|
||||
internal static RynthAiActivity Compose(BotActivity activity, bool macroRunning, bool corpseInHand, bool salvageBusy,
|
||||
bool serverWait, bool crafting, bool autoCram)
|
||||
bool serverWait, bool crafting, bool autoCram, bool pacedWait = false)
|
||||
{
|
||||
RynthAiActivity f = RynthAiActivity.None;
|
||||
if (macroRunning) f |= RynthAiActivity.MacroRunning;
|
||||
|
|
@ -74,6 +74,7 @@ internal static unsafe class ActivityInterface
|
|||
if (serverWait) f |= RynthAiActivity.ServerAction;
|
||||
if (crafting) f |= RynthAiActivity.Crafting;
|
||||
if (autoCram) f |= RynthAiActivity.AutoCram;
|
||||
if (pacedWait) f |= RynthAiActivity.PacedAction;
|
||||
return f;
|
||||
}
|
||||
}
|
||||
|
|
@ -85,7 +86,8 @@ public sealed partial class RynthAiPlugin
|
|||
{
|
||||
var st = _dashboard?.Settings;
|
||||
if (st == null || !_loginComplete) return null;
|
||||
bool serverWait = _busyCount > 0 || (ActionPacer.Enabled && ActionPacer.Current(Host) != null);
|
||||
bool pacedWait = ActionPacer.Enabled && ActionPacer.Current(Host) != null;
|
||||
bool serverWait = _busyCount > 0 || pacedWait;
|
||||
return ActivityInterface.Compose(
|
||||
st.IsMacroRunning ? _activity : BotActivity.Idle,
|
||||
st.IsMacroRunning,
|
||||
|
|
@ -93,6 +95,7 @@ public sealed partial class RynthAiPlugin
|
|||
salvageBusy: _salvageManager?.IsBusy == true,
|
||||
serverWait: serverWait,
|
||||
crafting: _missileCraftingManager?.IsCrafting == true,
|
||||
autoCram: st.EnableAutocram);
|
||||
autoCram: st.EnableAutocram,
|
||||
pacedWait: pacedWait);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -400,6 +400,38 @@ public partial class BuffManager : IDisposable
|
|||
return Math.Min(reserve, cost + (max - cost) / 2);
|
||||
}
|
||||
|
||||
/// <summary>Logged once per stretch under Get Mana At: buffing goes on because nothing can refill
|
||||
/// mana (CheckBuffs' mana floor).</summary>
|
||||
private bool _manaFloorNoRefillLogged;
|
||||
|
||||
/// <summary>Heals the mana floor keeps mana for when nothing can refill it.</summary>
|
||||
internal const int ManaFloorHeals = 2;
|
||||
|
||||
/// <summary>
|
||||
/// The mana the Get Mana At floor keeps when nothing can refill it: ManaFloorHeals casts of the
|
||||
/// Heal Self vitals would cast now (0 when none is known or Life Magic isn't usable).
|
||||
/// </summary>
|
||||
internal int ManaFloorHealReserve()
|
||||
{
|
||||
int heal = IsSkillUsable(AcSkillType.LifeMagic)
|
||||
? _spellManager.GetDynamicSelfBuffId("Heal Self", AcSkillType.LifeMagic, LevelLacksComponents)
|
||||
: 0;
|
||||
int cost = heal != 0 ? SpellManaCost(heal) : 0;
|
||||
return cost > 0 ? ManaFloorHeals * cost : 0;
|
||||
}
|
||||
|
||||
/// <summary>True when no mana potion could be drunk at all (Use Potions off, or none listed or
|
||||
/// in the pack); false while one exists but waits (drunk under 2.5 s ago, a cast holds it).</summary>
|
||||
private bool NoManaPotionToDrink()
|
||||
{
|
||||
if (!_settings.UsePotions || _worldObjectCache == null) return true;
|
||||
if (HasListedPotion("ManaPotion")) return false;
|
||||
foreach (var wo in _worldObjectCache.GetDirectInventory(forceRefresh: false))
|
||||
if (!IsKitName(wo.Name) && string.Equals(RynthCore.Plugin.RynthAi.LegacyUi.LegacyWeaponsUi.PotionType(wo), "ManaPotion", StringComparison.OrdinalIgnoreCase))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>Combat fights with magic (CombatManager's chosen weapon is a wand; before it chose,
|
||||
/// the stance). A melee character's attacks don't spend mana, so the reserve doesn't hold them.</summary>
|
||||
private bool FightsWithMagic() => _combatManager?.FightsWithMagic ?? CurrentCombatMode == CombatMode.Magic;
|
||||
|
|
@ -1717,30 +1749,71 @@ public partial class BuffManager : IDisposable
|
|||
// Mana under Get Mana At left buffing waiting on natural regen - one buff every 1-2
|
||||
// minutes (tester, 10-01: 85 minutes of "buffing waits", Stamina to Mana never cast).
|
||||
// A low stamina is topped up first (kit, Revitalize, potion) so Stamina to Mana can run.
|
||||
if (_vitals.StaminaPct > StaminaToManaFloorPct() && AttemptVitalCast("Stamina to Mana Self"))
|
||||
// Each source's reason, for the log line below: it used to show only the last one tried
|
||||
// (the potion's), so a missing Stamina to Mana read as "none in the Items list or the pack".
|
||||
string s2mWhy, stamWhy = "-", potWhy;
|
||||
_vitalWhy = "";
|
||||
if (_vitals.StaminaPct > StaminaToManaFloorPct())
|
||||
{
|
||||
_isRechargingMana = true;
|
||||
return;
|
||||
if (AttemptVitalCast("Stamina to Mana Self"))
|
||||
{
|
||||
_isRechargingMana = true;
|
||||
return;
|
||||
}
|
||||
s2mWhy = Why(_vitalWhy);
|
||||
}
|
||||
if (_vitals.StaminaPct <= 15 && (AttemptStaminaKitUse() || AttemptVitalCast("Revitalize Self")
|
||||
|| AttemptPotion("StaminaPotion", "Stamina")))
|
||||
else s2mWhy = $"stamina {_vitals.StaminaPct}% is under its line ({StaminaToManaFloorPct()}%)";
|
||||
if (_vitals.StaminaPct <= 15)
|
||||
{
|
||||
_isRechargingStamina = true;
|
||||
return;
|
||||
_vitalWhy = "";
|
||||
if (AttemptStaminaKitUse() || AttemptVitalCast("Revitalize Self")
|
||||
|| AttemptPotion("StaminaPotion", "Stamina"))
|
||||
{
|
||||
_isRechargingStamina = true;
|
||||
return;
|
||||
}
|
||||
stamWhy = Why(_vitalWhy);
|
||||
}
|
||||
_vitalWhy = "";
|
||||
if (AttemptPotion("ManaPotion"))
|
||||
{
|
||||
_isRechargingMana = true;
|
||||
return;
|
||||
}
|
||||
LastBuffSkipReason = $"mana {_vitals.ManaPct}% under Get Mana At {manaFloor}%";
|
||||
if ((RynthClock.Now - _lastManaFloorLogAt).TotalSeconds >= 30)
|
||||
potWhy = Why(_vitalWhy);
|
||||
|
||||
// Nothing can ever refill it (no Stamina to Mana known, no mana potion to drink): waiting
|
||||
// only means natural regeneration, so buffing crawled one buff per regen climb. Worse, a
|
||||
// rebuff raises max mana: the character logged in with full mana (209/207), the first
|
||||
// buffs took max mana to 536, the same 209 read 39% under Get Mana At 40%, and every buff
|
||||
// after waited (report R-20261029-103248-ce48, DreamWeave, 2026-10-29: "Buffing seems to
|
||||
// be getting stuck"). The floor is there to keep mana for healing, so with no refill the
|
||||
// buffs go on while mana keeps ManaFloorHealReserve after one (BuffWaitsForMana still
|
||||
// holds any buff mana can't pay for). The same rule as the reserve: "With no Stamina to
|
||||
// Mana at all nothing refills: the buff goes."
|
||||
bool canRefill = TopStaminaToManaId() != 0 || !NoManaPotionToDrink();
|
||||
int keep = ManaFloorHealReserve();
|
||||
if (!canRefill && _vitals.CurrentMana >= keep + EstimatedManaCost(8))
|
||||
{
|
||||
_lastManaFloorLogAt = RynthClock.Now;
|
||||
_host.Log($"[RynthAi] Vitals: buffing waits: mana {_vitals.ManaPct}% is under Get Mana At {manaFloor}%, stamina {_vitals.StaminaPct}%, and nothing refilled it (Stamina to Mana / stamina / potion: {Why(_vitalWhy)})");
|
||||
if (!_manaFloorNoRefillLogged)
|
||||
{
|
||||
_manaFloorNoRefillLogged = true;
|
||||
_host.Log($"[RynthAi] Vitals: mana {_vitals.CurrentMana}/{_vitals.MaxMana} ({_vitals.ManaPct}%) is under Get Mana At {manaFloor}%, but nothing can refill it (Stamina to Mana: {s2mWhy}; mana potion: {potWhy}): buffing goes on, keeping {keep} mana for healing.");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
LastBuffSkipReason = $"mana {_vitals.ManaPct}% under Get Mana At {manaFloor}%";
|
||||
if ((RynthClock.Now - _lastManaFloorLogAt).TotalSeconds >= 30)
|
||||
{
|
||||
_lastManaFloorLogAt = RynthClock.Now;
|
||||
_host.Log($"[RynthAi] Vitals: buffing waits: mana {_vitals.CurrentMana}/{_vitals.MaxMana} ({_vitals.ManaPct}%) is under Get Mana At {manaFloor}%, stamina {_vitals.StaminaPct}%, and nothing refilled it (Stamina to Mana: {s2mWhy}; stamina: {stamWhy}; mana potion: {potWhy})" +
|
||||
(canRefill ? "" : $"; keeping {keep} mana for healing"));
|
||||
}
|
||||
return;
|
||||
}
|
||||
return;
|
||||
}
|
||||
else _manaFloorNoRefillLogged = false;
|
||||
|
||||
// Too-busy backoff gates BUFFING only, and sits after CheckVitals on
|
||||
// purpose: a refused heal is worth retrying hard, a refused buff is not.
|
||||
|
|
|
|||
|
|
@ -7245,6 +7245,13 @@ public partial class CombatManager : IDisposable
|
|||
// table went to Slash (listed first), so a fire wand cast Blades (2026-09-30).
|
||||
if (target == null) return WeaponPlanner.FallbackOrder[0];
|
||||
var plan = PlanFor(target, rule);
|
||||
// The plan's wand isn't the one in hand (the swap was held: the target is nearly dead, a
|
||||
// swap is resting, the off hand blocks it): the wand in hand casts its own element (owner's
|
||||
// rule, 2026-09-30: "the wand should always cast its element"). The plan's element went
|
||||
// out through the other wand: Acid Blasts from a Frost Sceptre while "not swapping Frost
|
||||
// Sceptre for Acid Staff yet (target at 23% health)" (R-20261029-125901-e22d, Conquest).
|
||||
if (HeldWandElement(plan, rule) is string held)
|
||||
return held;
|
||||
if (_autoElemDiagCount < 20)
|
||||
{
|
||||
_autoElemDiagCount++;
|
||||
|
|
@ -7258,6 +7265,32 @@ public partial class CombatManager : IDisposable
|
|||
/// This character can cast <paramref name="element"/> itself (FindBestShapedSpell falls
|
||||
/// back to Fire for anything it can't, so a non-zero result alone doesn't say that).
|
||||
/// </summary>
|
||||
// Logged once per (plan wand, wand in hand, element): the cast follows the wand in hand.
|
||||
private (int Plan, int Hand, string Elem) _heldWandElemLogged;
|
||||
|
||||
/// <summary>
|
||||
/// The element of the wand in hand when it isn't the plan's weapon and the character can cast
|
||||
/// that element (null = cast the plan's element). Only a wand: a melee or missile weapon in
|
||||
/// hand doesn't choose the spell. A wand whose element isn't known yet, or isn't castable
|
||||
/// (Nether without Void), leaves the plan's element.
|
||||
/// </summary>
|
||||
private string? HeldWandElement(WeaponPlan plan, MonsterRule? rule)
|
||||
{
|
||||
int hand = InHandWeaponId();
|
||||
if (hand == 0 || plan.WeaponId == 0 || hand == plan.WeaponId) return null;
|
||||
if (_worldFilter[hand] is not WorldObject wo || !IsWandObject(wo)) return null;
|
||||
var c = ListedCandidates().FirstOrDefault(x => x.Id == hand);
|
||||
string elem = c?.Element ?? WeaponElements.Normalize(ElementTracker.Read(hand, wo.Name).Element);
|
||||
if (elem.Length == 0 || elem.Equals(plan.Element, StringComparison.OrdinalIgnoreCase) || !CanCastElement(elem, rule)) return null;
|
||||
var key = (plan.WeaponId, hand, elem);
|
||||
if (key != _heldWandElemLogged)
|
||||
{
|
||||
_heldWandElemLogged = key;
|
||||
_host.Log($"[CombatCast] the plan's wand 0x{(uint)plan.WeaponId:X8} '{WeaponName(plan.WeaponId)}' ({plan.Element}) isn't in hand: casting {elem}, the element of 0x{(uint)hand:X8} '{wo.Name}' in hand");
|
||||
}
|
||||
return elem;
|
||||
}
|
||||
|
||||
private bool CanCastElement(string element, MonsterRule? rule)
|
||||
{
|
||||
if (CanCastOverride != null) return CanCastOverride(element);
|
||||
|
|
|
|||
|
|
@ -121,6 +121,24 @@ public sealed partial class RynthAiPlugin
|
|||
private bool _currentLootItemPipelined; // sent while the last pickup's Return played (ACE queues it)
|
||||
private int _currentLootItemErrSeqAtSend; // TryGetLastWeenieError seq at the send (0 = unknown)
|
||||
private int _currentLootItemFreeRetries; // resends after a too-busy answer (not counted as attempts)
|
||||
// 2026-10-29 (R-20261029-122319-321f): what the server said to the last send, and what the
|
||||
// tries into the current destination came to (TickPendingCorpsePickup, JudgeLootDest).
|
||||
private bool _currentLootItemAwaitingAnswer; // the last send has had no answer yet
|
||||
private long _currentLootItemRefusedAt; // when a refusal of the last send was first seen (0 = none)
|
||||
private uint _currentLootItemRefusalError;
|
||||
private bool _currentLootItemRefusalBusy; // "too busy": before its pickup could run, not the pack's answer
|
||||
private int _currentLootItemDestRefusals; // tries into _currentLootItemDest refused after the pickup ran
|
||||
private int _currentLootItemDestTimeouts; // tries into it with no answer in PickupAnswerWaitMs
|
||||
private bool _currentLootItemTimedOut; // a send of this item went unanswered: a later answer may be to it
|
||||
private readonly List<int> _currentLootItemDestsTried = new();
|
||||
private long _moveAwaitTickAt; // CorpseNowMs of the previous answer-wait call
|
||||
// How long the server took to answer recent pickups (confirmations and refusals after the
|
||||
// pickup ran): the answer wait is sized from the slowest of them.
|
||||
private readonly long[] _pickupAnswerLatencies = new long[8];
|
||||
private int _pickupAnswerLatencyCount, _pickupAnswerLatencyNext;
|
||||
// Items given up (or dropped by a reset) with a move still possibly at the server: one that
|
||||
// lands in a pack afterwards un-marks that pack (WatchLateLandings).
|
||||
private readonly Dictionary<int, (long Until, long SentAt)> _lateLandings = new();
|
||||
// The last answered pickup, until the character has finished its "Return" (stood up again).
|
||||
// The corpse/chest is closed only after this (2026-10-07), and the next move may go out while
|
||||
// it plays: ACE queues a move that arrives during the Return as its NextPickup.
|
||||
|
|
@ -597,6 +615,7 @@ public sealed partial class RynthAiPlugin
|
|||
return;
|
||||
|
||||
SyncCorpseContainerState();
|
||||
WatchLateLandings(CorpseNowMs);
|
||||
TickDeferredClose(settings);
|
||||
TakeLootThisRequest(settings); // /ra lootthis (RynthAiPlugin.VTankHotkeys.cs)
|
||||
|
||||
|
|
@ -1729,6 +1748,7 @@ public sealed partial class RynthAiPlugin
|
|||
_currentLootItemPipelined = pipelined;
|
||||
_currentLootItemStackable = stackable;
|
||||
_currentLootItemErrSeqAtSend = errSeqAtSend;
|
||||
NoteLootMoveSent();
|
||||
_currentLootItemFreeRetries = 0;
|
||||
_currentLootItemActionLabel = matchActionLabel;
|
||||
_currentLootItemName = matchItemName;
|
||||
|
|
@ -1865,6 +1885,157 @@ public sealed partial class RynthAiPlugin
|
|||
catch { return false; }
|
||||
}
|
||||
|
||||
// ── Waiting for the server's answer to a move (2026-10-29, R-20261029-122319-321f) ──
|
||||
// Conquest, RynthAi 2026.10.29.1, "if max loot attempts are reached it locks up on looting
|
||||
// other items": a pack move was retried every ~0.5 s once the character stood still, and
|
||||
// after 3 tries (~1.6 s) the pack counted as full for 5 min. That server took 1.5-2.7 s to
|
||||
// answer a pickup ("pickup confirmed for 0x8023F05A; merged into a stack in the pack (1657
|
||||
// ms after the send)" came after attempt 3 had gone out), so moves were judged failed while
|
||||
// the server was still on them. A resend while one is out does nothing useful either: the
|
||||
// client drops it (its one pending inventory request, "You can only move or use one item at
|
||||
// a time") or ACE turns it away as too busy. Good side packs were marked full one after
|
||||
// another, each item burning two of them, until no pack was left. Now a send is followed by
|
||||
// another only once it is answered (the item lands, or the server refuses it) or after
|
||||
// PickupAnswerWaitMs with no answer, and only the server's refusals mark a pack full for
|
||||
// longer than the item (PackRefusals).
|
||||
|
||||
/// <summary>The least time a move is given to be answered before it counts as unanswered.</summary>
|
||||
internal const long PickupAnswerWaitMinMs = 4000;
|
||||
|
||||
/// <summary>The most: a slow server's measured answers raise the wait up to this.</summary>
|
||||
internal const long PickupAnswerWaitMaxMs = 8000;
|
||||
|
||||
/// <summary>Added to the slowest recent answer.</summary>
|
||||
internal const long PickupAnswerWaitMarginMs = 1500;
|
||||
|
||||
/// <summary>A pickup given up on is watched this long for a late landing.</summary>
|
||||
internal const long LateLandingWatchMs = 15_000;
|
||||
|
||||
/// <summary>How long a send waits for its answer: the slowest of the last 8 answers plus a margin, 4-8 s.</summary>
|
||||
internal long PickupAnswerWaitMs()
|
||||
{
|
||||
long slowest = 0;
|
||||
for (int i = 0; i < _pickupAnswerLatencyCount; i++)
|
||||
slowest = Math.Max(slowest, _pickupAnswerLatencies[i]);
|
||||
return Math.Clamp(slowest + PickupAnswerWaitMarginMs, PickupAnswerWaitMinMs, PickupAnswerWaitMaxMs);
|
||||
}
|
||||
|
||||
private void NotePickupAnswerLatency(long ms)
|
||||
{
|
||||
if (ms <= 0) return;
|
||||
_pickupAnswerLatencies[_pickupAnswerLatencyNext] = ms;
|
||||
_pickupAnswerLatencyNext = (_pickupAnswerLatencyNext + 1) % _pickupAnswerLatencies.Length;
|
||||
if (_pickupAnswerLatencyCount < _pickupAnswerLatencies.Length) _pickupAnswerLatencyCount++;
|
||||
}
|
||||
|
||||
/// <summary>A move of the current item went out: its answer is awaited afresh.</summary>
|
||||
private void NoteLootMoveSent()
|
||||
{
|
||||
_currentLootItemAwaitingAnswer = true;
|
||||
_currentLootItemRefusedAt = 0;
|
||||
_currentLootItemRefusalError = 0;
|
||||
_currentLootItemRefusalBusy = false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Notes the first refusal of the last send, every tick (so its time is known), and whether
|
||||
/// it was "too busy" or the server's own answer after it ran the pickup. The "error 0x0" of
|
||||
/// the report is a real refusal: the engine keeps only the last refusal message, ACE follows
|
||||
/// a YoureTooBusy (0x1D) with InventoryServerSaveFailed for the item and no error code, and
|
||||
/// a full pack answers with the same InventoryServerSaveFailed, no code ("Unable to put X
|
||||
/// into container", Player.DoHandleActionPutItemInContainer). The old code took every one
|
||||
/// for "too busy" and resent it free: 'Brier Wasp's Treasure Map' went into the full main
|
||||
/// pack 6 times over 18 s. The time tells them apart: ACE turns a busy move away when it
|
||||
/// arrives, and refuses for room only after the pickup motion (longer than PickupAnswerMinMs).
|
||||
/// </summary>
|
||||
private void PollCurrentPickupRefusal(long now)
|
||||
{
|
||||
if (_currentLootItemRefusedAt != 0 || !CurrentPickupRefused(out uint err))
|
||||
return;
|
||||
long after = now - _currentLootItemMoveRequestedAt;
|
||||
_currentLootItemRefusedAt = now;
|
||||
_currentLootItemRefusalError = err;
|
||||
_currentLootItemRefusalBusy = err == WeenieErrorYoureTooBusy || after < PickupAnswerMinMs;
|
||||
if (!_currentLootItemRefusalBusy && !_currentLootItemTimedOut)
|
||||
NotePickupAnswerLatency(after);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// While a move waits for its answer the corpse's timeout clock does not run (as for the
|
||||
/// cast-answer hold, PauseCorpseClockWhileHeld): three unanswered tries take longer than
|
||||
/// the 12 s corpse timeout, which is meant for an idle corpse.
|
||||
/// </summary>
|
||||
private void PauseCorpseClockWhileMoveAwaits(long now)
|
||||
{
|
||||
long last = _moveAwaitTickAt;
|
||||
_moveAwaitTickAt = now;
|
||||
if (last == 0 || _targetCorpseId == 0 || _corpseTargetSince == 0 || _corpseHoldFrozenAge >= 0)
|
||||
return;
|
||||
long gap = now - last;
|
||||
if (gap > 0 && gap <= PickupHoldMaxGapMs)
|
||||
_corpseTargetSince += gap;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// What the tries into the current destination say about it: full (<paramref name="confirmed"/>:
|
||||
/// the server refused at least two after running the pickup), doubtful (at least two failed,
|
||||
/// some only for want of an answer: the item tries another pack, the mark is the item's
|
||||
/// alone), or nothing (the server was only too busy: no pack is to blame).
|
||||
/// </summary>
|
||||
private bool JudgeLootDest(out bool confirmed)
|
||||
{
|
||||
confirmed = _currentLootItemDestRefusals >= 2;
|
||||
return confirmed || _currentLootItemDestRefusals + _currentLootItemDestTimeouts >= 2;
|
||||
}
|
||||
|
||||
private string LootPackName(int packId) =>
|
||||
packId == unchecked((int)_playerId) ? "the main pack" : $"pack 0x{(uint)packId:X8}";
|
||||
|
||||
/// <summary>A pack other than the ones left out could take the item (the client's own counts).</summary>
|
||||
private bool HasOtherLootDestination()
|
||||
{
|
||||
if (_objectCache == null || _playerId == 0) return false;
|
||||
long now = CorpseNowMs;
|
||||
return WorldObjectCache.FindLootDestination(_objectCache.GetDirectInventory(forceRefresh: false),
|
||||
unchecked((int)_playerId), Host, id => _packRefusals.IsRefused(id, now)) != 0;
|
||||
}
|
||||
|
||||
/// <summary>The current item is done without its landing seen: watch for one that comes late.</summary>
|
||||
private void WatchLateLanding(long now)
|
||||
{
|
||||
if (_currentLootItemId == 0 || _currentLootItemDestsTried.Count == 0)
|
||||
return;
|
||||
_lateLandings[_currentLootItemId] = (now + LateLandingWatchMs, _currentLootItemMoveRequestedAt);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// An item given up on that lands in a pack after all: that pack had room, so it is no longer
|
||||
/// treated as full (it may have been marked while the server was still on the item).
|
||||
/// </summary>
|
||||
private void WatchLateLandings(long now)
|
||||
{
|
||||
if (_lateLandings.Count == 0 || _objectCache == null)
|
||||
return;
|
||||
List<int>? done = null;
|
||||
foreach (var kv in _lateLandings)
|
||||
{
|
||||
WorldObject? wo = _objectCache[kv.Key];
|
||||
int container = wo?.Container ?? 0;
|
||||
if (wo != null && InPlayerInventory(container))
|
||||
{
|
||||
bool wasMarked = _packRefusals.IsRefused(container, now);
|
||||
_packRefusals.Accepted(container);
|
||||
LootDiag($"[RynthAi] {LootTag}: 0x{(uint)kv.Key:X8} landed in {LootPackName(container)} {now - kv.Value.SentAt} ms after its last send, after it was given up" +
|
||||
(wasMarked ? $"; {LootPackName(container)} has room after all and is no longer treated as full." : "."));
|
||||
(done ??= new()).Add(kv.Key);
|
||||
}
|
||||
else if (now >= kv.Value.Until)
|
||||
(done ??= new()).Add(kv.Key);
|
||||
}
|
||||
if (done != null)
|
||||
foreach (int id in done) _lateLandings.Remove(id);
|
||||
}
|
||||
|
||||
/// <summary>A stack when its move is sent: it may merge into a stack in the pack and be deleted.</summary>
|
||||
private bool IsStackAtSend(int itemId)
|
||||
{
|
||||
|
|
@ -2033,14 +2204,18 @@ public sealed partial class RynthAiPlugin
|
|||
: mergedAway
|
||||
? "merged into a stack in the pack"
|
||||
: $"off the corpse, not seen in a pack (container=0x{(uint)currentContainer:X8})",
|
||||
answered);
|
||||
answered,
|
||||
inPack ? currentContainer : 0);
|
||||
return;
|
||||
}
|
||||
|
||||
// The server turned the move away ("You're too busy": it arrived during the last
|
||||
// pickup's bend-down, not its Return). Resend it as soon as the character is still,
|
||||
// without counting it as one of the item's 3 tries.
|
||||
bool refused = CurrentPickupRefused(out uint refusal);
|
||||
// The server turned the move away. "Too busy" (it arrived during the last pickup's
|
||||
// bend-down, not its Return): resend it as soon as the character is still, without
|
||||
// counting it as one of the item's 3 tries. Refused after the pickup ran (no room): one
|
||||
// of the tries, and the evidence a pack is full (PollCurrentPickupRefusal).
|
||||
PollCurrentPickupRefusal(now);
|
||||
bool refused = _currentLootItemRefusedAt != 0;
|
||||
bool busyRefusal = refused && _currentLootItemRefusalBusy;
|
||||
|
||||
// Item still on corpse — wait before retrying the UseObject. The window counts from
|
||||
// when the character is still: while a pickup animation plays the engine holds the
|
||||
|
|
@ -2050,35 +2225,81 @@ public sealed partial class RynthAiPlugin
|
|||
if (PickupAnimating(now))
|
||||
{
|
||||
_currentLootItemStillSince = 0;
|
||||
if (_currentLootItemAwaitingAnswer) PauseCorpseClockWhileMoveAwaits(now);
|
||||
return;
|
||||
}
|
||||
if (_currentLootItemStillSince == 0)
|
||||
_currentLootItemStillSince = now;
|
||||
bool freeRetry = refused && _currentLootItemFreeRetries < PickupFreeRetries;
|
||||
bool freeRetry = busyRefusal && _currentLootItemFreeRetries < PickupFreeRetries;
|
||||
|
||||
// No answer yet: no resend before PickupAnswerWaitMs (2026-10-29, R-20261029-122319-321f).
|
||||
// The Loot Retry Timeout alone (0.5-1 s) is shorter than a slow server's answer (1.5-2.7 s
|
||||
// on Conquest), and a resend while the move is out is dropped by the client or refused.
|
||||
long answerWaitMs = PickupAnswerWaitMs();
|
||||
long sinceSend = now - _currentLootItemMoveRequestedAt;
|
||||
if (_currentLootItemAwaitingAnswer && !refused && sinceSend < answerWaitMs)
|
||||
{
|
||||
PauseCorpseClockWhileMoveAwaits(now);
|
||||
return;
|
||||
}
|
||||
long verifyWindowMs = Math.Max(150, settings.LootRetryTimeoutMs);
|
||||
long windowStart = Math.Max(_currentLootItemMoveRequestedAt, _currentLootItemStillSince);
|
||||
if (!freeRetry && now - windowStart < verifyWindowMs)
|
||||
return;
|
||||
|
||||
// The last send failed: what it came to, once per send (a free resend's "too busy" is
|
||||
// not one of the tries). Refused after the pickup ran counts against the pack; no answer
|
||||
// at all only half (JudgeLootDest).
|
||||
string lastTry = "";
|
||||
if (_currentLootItemAwaitingAnswer && !freeRetry)
|
||||
{
|
||||
_currentLootItemAwaitingAnswer = false;
|
||||
long answerMs = refused ? _currentLootItemRefusedAt - _currentLootItemMoveRequestedAt : sinceSend;
|
||||
if (!refused)
|
||||
{
|
||||
_currentLootItemDestTimeouts++;
|
||||
_currentLootItemTimedOut = true;
|
||||
lastTry = $"no answer in {answerMs} ms";
|
||||
}
|
||||
else if (!busyRefusal)
|
||||
{
|
||||
_currentLootItemDestRefusals++;
|
||||
lastTry = $"refused {answerMs} ms after the send, after its pickup ran (error 0x{_currentLootItemRefusalError:X})";
|
||||
}
|
||||
else
|
||||
lastTry = $"too busy, {answerMs} ms after the send";
|
||||
}
|
||||
|
||||
if (!freeRetry && _currentLootItemMoveAttempts >= 3)
|
||||
{
|
||||
// None of the tries landed: the pack they went to is likely full (its contents
|
||||
// unknown to the client). Leave that pack out for a while and give the item one
|
||||
// more round into the next one; with no other pack, the item is left as before.
|
||||
if (_currentLootItemDest != 0)
|
||||
// None of the tries landed. When the server refused them after running the pickup,
|
||||
// the pack they went to is full (its contents unknown to the client): leave it out
|
||||
// for a while and give the item one more round into the next one; with no other
|
||||
// pack, the corpse is left with the pack-full message. When they only went unanswered
|
||||
// the pack is not known to be full: the item may try another pack, but the mark is
|
||||
// dropped with the item, so the next item and corpse start fresh (R-20261029-122319-321f:
|
||||
// those quick marks used up every pack). When the server was only too busy, no pack is
|
||||
// to blame.
|
||||
int dest = _currentLootItemDest;
|
||||
if (dest != 0 && JudgeLootDest(out bool confirmed))
|
||||
{
|
||||
_packRefusals.Refuse(_currentLootItemDest, now);
|
||||
if (!_currentLootItemPackRetried)
|
||||
_packRefusals.Refuse(dest, now, confirmed);
|
||||
if (!_currentLootItemPackRetried && (confirmed || HasOtherLootDestination()))
|
||||
{
|
||||
LootDiag($"[RynthAi] {LootTag}: {(_currentLootItemDest == _playerId ? "the main pack" : $"pack 0x{(uint)_currentLootItemDest:X8}")} took none of {_currentLootItemMoveAttempts} tries for 0x{(uint)_currentLootItemId:X8}; treating it as full for {RynthCore.Plugin.RynthAi.Loot.PackRefusals.HoldMs / 60_000} min and trying another pack.");
|
||||
LootDiag(confirmed
|
||||
? $"[RynthAi] {LootTag}: {LootPackName(dest)} took none of {_currentLootItemMoveAttempts} tries for 0x{(uint)_currentLootItemId:X8} (the server refused {_currentLootItemDestRefusals} after the pickup ran); treating it as full for {RynthCore.Plugin.RynthAi.Loot.PackRefusals.HoldMs / 60_000} min and trying another pack."
|
||||
: $"[RynthAi] {LootTag}: {LootPackName(dest)} took none of {_currentLootItemMoveAttempts} tries for 0x{(uint)_currentLootItemId:X8} ({_currentLootItemDestTimeouts} unanswered in {answerWaitMs} ms, {_currentLootItemDestRefusals} refused); trying another pack for this item only (not known to be full).");
|
||||
_currentLootItemPackRetried = true;
|
||||
_currentLootItemMoveAttempts = 0;
|
||||
_currentLootItemDestRefusals = 0;
|
||||
_currentLootItemDestTimeouts = 0;
|
||||
_currentLootItemStillSince = 0;
|
||||
_lastLootActionAt = now;
|
||||
return;
|
||||
}
|
||||
}
|
||||
LootDiag($"[RynthAi] {LootTag}: pickup failed for 0x{(uint)_currentLootItemId:X8}; container remained 0x{(uint)_openedContainerId:X8} after {_currentLootItemMoveAttempts} attempt(s).");
|
||||
LootDiag($"[RynthAi] {LootTag}: pickup failed for 0x{(uint)_currentLootItemId:X8}; container remained 0x{(uint)_openedContainerId:X8} after {_currentLootItemMoveAttempts} attempt(s)" +
|
||||
(lastTry.Length > 0 ? $" (last: {lastTry})." : "."));
|
||||
_processedCorpseItems.Add(_currentLootItemId);
|
||||
ResetCurrentLootItem();
|
||||
_lastLootActionAt = now;
|
||||
|
|
@ -2093,6 +2314,8 @@ public sealed partial class RynthAiPlugin
|
|||
RynthCore.Plugin.RynthAi.ItemInfo.SelfSelect.Mark(unchecked((uint)_currentLootItemId));
|
||||
Host.SelectItem(unchecked((uint)_currentLootItemId));
|
||||
int errSeqAtSend = LastWeenieErrorSeq();
|
||||
long refusedAfter = refused ? _currentLootItemRefusedAt - _currentLootItemMoveRequestedAt : 0;
|
||||
uint refusal = _currentLootItemRefusalError;
|
||||
LootPickupResult retry = SendLootPickup(_currentLootItemId, _currentLootItemName, _openedContainerId);
|
||||
if (retry == LootPickupResult.NoRoom || retry == LootPickupResult.Refused)
|
||||
return; // SendLootPickup finished the item / corpse
|
||||
|
|
@ -2103,12 +2326,14 @@ public sealed partial class RynthAiPlugin
|
|||
_currentLootItemMoveAttempts++;
|
||||
_currentLootItemErrSeqAtSend = errSeqAtSend;
|
||||
_currentLootItemMoveRequestedAt = now;
|
||||
if (retried) NoteLootMoveSent();
|
||||
_currentLootItemStillSince = 0;
|
||||
_currentLootItemSawAnim = false;
|
||||
_lastLootActionAt = now;
|
||||
LootDiag(freeRetry
|
||||
? $"[RynthAi] {LootTag}: the server refused 0x{(uint)_currentLootItemId:X8} (error 0x{refusal:X}); sending it again now the character is still."
|
||||
: $"[RynthAi] {LootTag}: retrying use for 0x{(uint)_currentLootItemId:X8} attempt {_currentLootItemMoveAttempts}.");
|
||||
? $"[RynthAi] {LootTag}: the server refused 0x{(uint)_currentLootItemId:X8} as too busy ({refusedAfter} ms after the send, before its pickup ran; error 0x{refusal:X}); sending it again now the character is still."
|
||||
: $"[RynthAi] {LootTag}: retrying use for 0x{(uint)_currentLootItemId:X8} attempt {_currentLootItemMoveAttempts}" +
|
||||
(lastTry.Length > 0 ? $" (last: {lastTry})." : "."));
|
||||
|
||||
if (!retried && _currentLootItemMoveAttempts >= 3)
|
||||
{
|
||||
|
|
@ -2149,7 +2374,18 @@ public sealed partial class RynthAiPlugin
|
|||
? SendOwnCorpsePickup(itemId, out dest)
|
||||
: LootPickup.Send(Host, _objectCache, unchecked((uint)itemId), _playerId, out dest,
|
||||
id => _packRefusals.IsRefused(id, CorpseNowMs));
|
||||
if (r == LootPickupResult.Moved) _currentLootItemDest = unchecked((int)dest);
|
||||
if (r == LootPickupResult.Moved)
|
||||
{
|
||||
int to = unchecked((int)dest);
|
||||
if (to != _currentLootItemDest)
|
||||
{
|
||||
// Another pack: what the tries into the last one came to says nothing about it.
|
||||
_currentLootItemDestRefusals = 0;
|
||||
_currentLootItemDestTimeouts = 0;
|
||||
}
|
||||
_currentLootItemDest = to;
|
||||
if (!_currentLootItemDestsTried.Contains(to)) _currentLootItemDestsTried.Add(to);
|
||||
}
|
||||
if (ownCorpse && r == LootPickupResult.NoRoom)
|
||||
{
|
||||
PauseOwnCorpseNoRoom(corpseId, itemName);
|
||||
|
|
@ -2182,13 +2418,32 @@ public sealed partial class RynthAiPlugin
|
|||
/// </summary>
|
||||
private void ConfirmCurrentLootItemMoved(long now, string reason) => ConfirmCurrentLootItem(now, reason, answered: true);
|
||||
|
||||
private void ConfirmCurrentLootItem(long now, string reason, bool answered)
|
||||
/// <param name="landedIn">The pack the item was seen in (0: merged away, or not seen).</param>
|
||||
private void ConfirmCurrentLootItem(long now, string reason, bool answered, int landedIn = 0)
|
||||
{
|
||||
if (_currentLootItemId == 0)
|
||||
return;
|
||||
|
||||
int itemId = _currentLootItemId;
|
||||
if (answered && _currentLootItemDest != 0) _packRefusals.Accepted(_currentLootItemDest);
|
||||
if (answered)
|
||||
{
|
||||
// The pack it landed in has room, whatever it was marked (an earlier send may have
|
||||
// landed after the item moved on to another pack: R-20261029-122319-321f). A stack
|
||||
// that merged needed no slot, so it clears its destination only when no refusal
|
||||
// from there said otherwise.
|
||||
if (landedIn != 0)
|
||||
{
|
||||
if (_packRefusals.IsRefused(landedIn, now))
|
||||
LootDiag($"[RynthAi] {LootTag}: 0x{(uint)itemId:X8} landed in {LootPackName(landedIn)}; it has room after all and is no longer treated as full.");
|
||||
_packRefusals.Accepted(landedIn);
|
||||
}
|
||||
else if (_currentLootItemDest != 0 && _currentLootItemDestRefusals == 0)
|
||||
_packRefusals.Accepted(_currentLootItemDest);
|
||||
// Only an answer that is surely to the last send (a lag spike's answer to an earlier,
|
||||
// timed-out send would stretch the wait for every item after it).
|
||||
if (!_currentLootItemTimedOut) NotePickupAnswerLatency(now - _currentLootItemMoveRequestedAt);
|
||||
}
|
||||
if (answered) _currentLootItemDestsTried.Clear(); // landed: nothing to watch for (ResetCurrentLootItem)
|
||||
_processedCorpseItems.Add(_currentLootItemId);
|
||||
LootDiag($"[RynthAi] {LootTag}: pickup confirmed for 0x{(uint)_currentLootItemId:X8}; {reason}" +
|
||||
$" ({now - _currentLootItemMoveRequestedAt} ms after the send{(_currentLootItemPipelined ? ", queued" : "")}).");
|
||||
|
|
@ -3023,6 +3278,21 @@ public sealed partial class RynthAiPlugin
|
|||
|
||||
private void ResetCurrentLootItem()
|
||||
{
|
||||
// An item done without its landing seen (given up, or dropped by a close / reopen /
|
||||
// stop) may still land: watch for it. Its unanswered-tries pack marks go with it, so
|
||||
// the next item and corpse start fresh (R-20261029-122319-321f).
|
||||
long now = CorpseNowMs;
|
||||
WatchLateLanding(now);
|
||||
_packRefusals.ClearUnconfirmed();
|
||||
_currentLootItemAwaitingAnswer = false;
|
||||
_currentLootItemRefusedAt = 0;
|
||||
_currentLootItemRefusalError = 0;
|
||||
_currentLootItemRefusalBusy = false;
|
||||
_currentLootItemDestRefusals = 0;
|
||||
_currentLootItemDestTimeouts = 0;
|
||||
_currentLootItemTimedOut = false;
|
||||
_currentLootItemDestsTried.Clear();
|
||||
_moveAwaitTickAt = 0;
|
||||
_currentLootItemId = 0;
|
||||
_currentLootItemRequested = false;
|
||||
_currentLootItemRequestedAt = 0;
|
||||
|
|
|
|||
|
|
@ -9,31 +9,61 @@ namespace RynthCore.Plugin.RynthAi.Loot;
|
|||
/// time, and every item on every corpse was skipped (Drakkon, 2026-10-15, 62 items in a row).
|
||||
/// A pack that takes none of an item's tries counts as full for <see cref="HoldMs"/>; the
|
||||
/// destination search skips it, so the next pack is tried. Pure: the caller passes the time.
|
||||
///
|
||||
/// 2026-10-29 (R-20261029-122319-321f, Conquest): a mark is CONFIRMED only when the server
|
||||
/// answered the tries with a refusal after it had run the pickup (ACE's "Unable to put X into
|
||||
/// container" + InventoryServerSaveFailed). Tries that simply had no answer in time mark the
|
||||
/// pack UNCONFIRMED: the item tries another pack, but the mark is the item's alone and is
|
||||
/// dropped when the item is done (<see cref="ClearUnconfirmed"/>). Quick unanswered retries
|
||||
/// on a slow server had marked one good pack after another full for 5 min, until looting
|
||||
/// "locked up" with nothing left to put loot into.
|
||||
/// </summary>
|
||||
internal sealed class PackRefusals
|
||||
{
|
||||
/// <summary>How long a refusing pack is left out (time to free some room, or open it).</summary>
|
||||
public const long HoldMs = 5 * 60_000;
|
||||
|
||||
private readonly Dictionary<int, long> _until = new();
|
||||
private readonly Dictionary<int, (long Until, bool Confirmed)> _until = new();
|
||||
|
||||
/// <summary>The server took none of the tries into <paramref name="packId"/>.</summary>
|
||||
public void Refuse(int packId, long nowMs)
|
||||
/// <summary>
|
||||
/// The server took none of the tries into <paramref name="packId"/>. <paramref name="confirmed"/>:
|
||||
/// it said so (refusals after the pickup ran); false: the tries went unanswered. A confirmed
|
||||
/// mark is never weakened by a later unconfirmed one.
|
||||
/// </summary>
|
||||
public void Refuse(int packId, long nowMs, bool confirmed = true)
|
||||
{
|
||||
if (packId != 0) _until[packId] = nowMs + HoldMs;
|
||||
if (packId == 0) return;
|
||||
if (_until.TryGetValue(packId, out var old) && old.Confirmed && !confirmed && nowMs < old.Until)
|
||||
return;
|
||||
_until[packId] = (nowMs + HoldMs, confirmed);
|
||||
}
|
||||
|
||||
/// <summary>True while <paramref name="packId"/> is left out.</summary>
|
||||
public bool IsRefused(int packId, long nowMs)
|
||||
{
|
||||
if (!_until.TryGetValue(packId, out long until)) return false;
|
||||
if (nowMs < until) return true;
|
||||
if (!_until.TryGetValue(packId, out var mark)) return false;
|
||||
if (nowMs < mark.Until) return true;
|
||||
_until.Remove(packId);
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>True while <paramref name="packId"/> is left out on the server's own refusals.</summary>
|
||||
public bool IsConfirmed(int packId, long nowMs) =>
|
||||
IsRefused(packId, nowMs) && _until.TryGetValue(packId, out var mark) && mark.Confirmed;
|
||||
|
||||
/// <summary>An item landed in <paramref name="packId"/>: it has room after all.</summary>
|
||||
public void Accepted(int packId) => _until.Remove(packId);
|
||||
|
||||
/// <summary>Drops the marks no refusal backed (the item that made them is done).</summary>
|
||||
public void ClearUnconfirmed()
|
||||
{
|
||||
if (_until.Count == 0) return;
|
||||
List<int>? drop = null;
|
||||
foreach (var kv in _until)
|
||||
if (!kv.Value.Confirmed) (drop ??= new()).Add(kv.Key);
|
||||
if (drop != null)
|
||||
foreach (int id in drop) _until.Remove(id);
|
||||
}
|
||||
|
||||
public void Clear() => _until.Clear();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,7 +18,9 @@ public static unsafe class PluginExports
|
|||
// "RynthAi.Activity" v1 for RynthSort (what the bot is doing, so pack moves stay out of its way),
|
||||
// "RynthAi.Combat" v1 for RynthLua (a script choosing attack and heal spells, Shared/RynthAiCombatApi.cs),
|
||||
// "RynthAi.Hub" v1 for RynthILT (the Mini Remote hosting its ILT tabs, /myquests, spell names, loot
|
||||
// matching, the .usd importer, session stats; Shared/RynthAiHubApi.cs, HubInterface.cs).
|
||||
// matching, the .usd importer, session stats; Shared/RynthAiHubApi.cs, HubInterface.cs),
|
||||
// "RynthAi.Yield" v1 for RynthDefective (the player's key press goes before RynthAi's next action;
|
||||
// Shared/RynthAiYieldApi.cs, YieldInterface.cs).
|
||||
// Fixed signature: void* (const char* iface, uint version).
|
||||
[UnmanagedCallersOnly(EntryPoint = "RynthPluginQueryInterface", CallConvs = new[] { typeof(CallConvCdecl) })]
|
||||
private static IntPtr QueryInterface(IntPtr ifaceAnsi, uint version)
|
||||
|
|
@ -30,6 +32,7 @@ public static unsafe class PluginExports
|
|||
if (table == IntPtr.Zero) table = StatusInterface.Query(iface, version);
|
||||
if (table == IntPtr.Zero) table = ActivityInterface.Query(iface, version);
|
||||
if (table == IntPtr.Zero) table = HubInterface.Query(iface, version);
|
||||
if (table == IntPtr.Zero) table = YieldInterface.Query(iface, version);
|
||||
return table != IntPtr.Zero ? table : CombatHookInterface.Query(iface, version);
|
||||
}
|
||||
catch
|
||||
|
|
@ -53,6 +56,8 @@ public static unsafe class PluginExports
|
|||
catch (Exception ex) { LogShutdownError(plugin, "StatusInterface.Release", ex); }
|
||||
try { ActivityInterface.Release(); }
|
||||
catch (Exception ex) { LogShutdownError(plugin, "ActivityInterface.Release", ex); }
|
||||
try { YieldInterface.Release(); }
|
||||
catch (Exception ex) { LogShutdownError(plugin, "YieldInterface.Release", ex); }
|
||||
try { HubInterface.Release(); } // Version 0; the table stays (RynthILT's render thread may hold it)
|
||||
catch (Exception ex) { LogShutdownError(plugin, "HubInterface.Release", ex); }
|
||||
try { CombatHookInterface.Shutdown(); } // the hook goes native at once (RynthLua re-claims after a reload)
|
||||
|
|
|
|||
|
|
@ -247,6 +247,7 @@ public sealed partial class RynthAiPlugin
|
|||
_currentLootItemPipelined = pipelined;
|
||||
_currentLootItemStackable = stackable;
|
||||
_currentLootItemErrSeqAtSend = errSeqAtSend;
|
||||
NoteLootMoveSent();
|
||||
_currentLootItemActionLabel = "Recover";
|
||||
_currentLootItemName = name;
|
||||
_currentLootItemIsSalvage = false; // never salvage your own things
|
||||
|
|
|
|||
|
|
@ -39,6 +39,7 @@
|
|||
<Compile Include="..\Shared\RynthAiStatusApi.cs" Link="Shared\RynthAiStatusApi.cs" />
|
||||
<!-- RynthSort reads what the bot is doing through RynthAi.Activity (read only). -->
|
||||
<Compile Include="..\Shared\RynthAiActivityApi.cs" Link="Shared\RynthAiActivityApi.cs" />
|
||||
<Compile Include="..\Shared\RynthAiYieldApi.cs" Link="Shared\RynthAiYieldApi.cs" />
|
||||
<!-- RynthLua's scripts choose attack and heal spells through RynthAi.Combat. -->
|
||||
<Compile Include="..\Shared\RynthAiCombatApi.cs" Link="Shared\RynthAiCombatApi.cs" />
|
||||
<!-- RynthNav's navmesh path queries (stuck-recovery detours outdoors). -->
|
||||
|
|
|
|||
73
Plugins/RynthCore.Plugin.RynthAi/YieldInterface.cs
Normal file
73
Plugins/RynthCore.Plugin.RynthAi/YieldInterface.cs
Normal file
|
|
@ -0,0 +1,73 @@
|
|||
using System;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using RynthCore.Plugin.Shared;
|
||||
|
||||
namespace RynthCore.Plugin.RynthAi;
|
||||
|
||||
/// <summary>
|
||||
/// RynthAi's side of the "RynthAi.Yield" interface (Shared/RynthAiYieldApi.cs, 2026-10-29): a plugin
|
||||
/// acting for the player (RynthDefective's Shortcuts bar) takes the player's turn, and RynthAi starts
|
||||
/// nothing new until it has gone (ActionPacer.HoldForPlayer). Runs on the plugin pump thread (the
|
||||
/// caller's OnTick), on the current plugin instance.
|
||||
/// </summary>
|
||||
internal static unsafe class YieldInterface
|
||||
{
|
||||
private static RynthAiYieldApiV1* _table;
|
||||
|
||||
public static IntPtr Query(string iface, uint version)
|
||||
{
|
||||
if (iface != RynthAiYieldApiV1.InterfaceName || version == 0 || version > RynthAiYieldApiV1.InterfaceVersion) return IntPtr.Zero;
|
||||
if (_table == null)
|
||||
{
|
||||
var t = (RynthAiYieldApiV1*)NativeMemory.AllocZeroed((nuint)sizeof(RynthAiYieldApiV1));
|
||||
t->Version = RynthAiYieldApiV1.InterfaceVersion;
|
||||
t->StructSize = (uint)sizeof(RynthAiYieldApiV1);
|
||||
t->HoldForPlayer = &HoldForPlayer;
|
||||
t->ReleaseHold = &ReleaseHold;
|
||||
_table = t;
|
||||
}
|
||||
return (IntPtr)_table;
|
||||
}
|
||||
|
||||
/// <summary>Frees the table (plugin shutdown). Callers resolve it every tick.</summary>
|
||||
public static void Release()
|
||||
{
|
||||
var t = _table;
|
||||
_table = null;
|
||||
if (t != null) NativeMemory.Free(t);
|
||||
}
|
||||
|
||||
[UnmanagedCallersOnly(CallConvs = new[] { typeof(CallConvCdecl) })]
|
||||
private static int HoldForPlayer(uint ms)
|
||||
{
|
||||
try { return PluginExports.Runtime.Plugin?.HoldForPlayer(ms) == true ? 1 : 0; }
|
||||
catch { return 0; }
|
||||
}
|
||||
|
||||
[UnmanagedCallersOnly(CallConvs = new[] { typeof(CallConvCdecl) })]
|
||||
private static int ReleaseHold()
|
||||
{
|
||||
try
|
||||
{
|
||||
PluginExports.Runtime.Plugin?.ReleasePlayerHold();
|
||||
return 1;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public sealed partial class RynthAiPlugin
|
||||
{
|
||||
/// <summary>The player's turn for another plugin (RynthAi.Yield); false before login or with pacing off.</summary>
|
||||
internal bool HoldForPlayer(uint ms)
|
||||
{
|
||||
if (!_loginComplete) return false;
|
||||
return ActionPacer.HoldForPlayer(Host, Math.Min(ms, RynthAiYieldApiV1.MaxHoldMs));
|
||||
}
|
||||
|
||||
internal void ReleasePlayerHold() => ActionPacer.ReleasePlayerHold(Host);
|
||||
}
|
||||
|
|
@ -37,6 +37,7 @@
|
|||
<ItemGroup>
|
||||
<!-- What RynthAi is doing (read only), so a weapon swap stays out of its way. -->
|
||||
<Compile Include="..\Shared\RynthAiActivityApi.cs" Link="Shared\RynthAiActivityApi.cs" />
|
||||
<Compile Include="..\Shared\RynthAiYieldApi.cs" Link="Shared\RynthAiYieldApi.cs" />
|
||||
<!-- An older RynthAi without RynthAi.Activity: its RynthAi.Status macro bit instead. -->
|
||||
<Compile Include="..\Shared\RynthAiStatusApi.cs" Link="Shared\RynthAiStatusApi.cs" />
|
||||
<!-- Install-folder resolver (env, HKCU, HKLM, default C:\Games). Read only; same file as RynthCore src\Shared. -->
|
||||
|
|
|
|||
|
|
@ -27,6 +27,16 @@
|
|||
// After that the use is sent: if the server really is busy it answers
|
||||
// "You're too busy" (UseDone 0x1D) and the use controller tries once more.
|
||||
//
|
||||
// With RynthAi holding for the press (RynthAi.Yield, 2026-10-29), RynthAi says
|
||||
// exactly what it has in flight (its pacer's one outstanding action), so the
|
||||
// rule is simpler and doesn't wait seconds for the count to sit still:
|
||||
// * RynthAi's own unanswered action holds, for at most BotTrustMs;
|
||||
// * the count holds only right after our own use (OwnTrustMs);
|
||||
// * anything else in the count is a leftover (a death, a login, a corpse
|
||||
// open's +1) or a click in the game's own windows: the use goes.
|
||||
// After a death or a login RynthAi's stream of rebuffs kept the count moving,
|
||||
// so it never read "steady" and a press waited until it gave up.
|
||||
//
|
||||
// RynthDefective never resets the client's count itself (ForceResetBusyCount):
|
||||
// the count is the engine's (its reconciler and watchdogs own it), RynthAi
|
||||
// stopped resetting it on 2026-10-06 because a reset zeroes actions the server
|
||||
|
|
@ -54,9 +64,15 @@ internal enum BusyStale { None = 0, Count = 1, Animation = 2, Bot = 4 }
|
|||
/// <param name="AnimatingMs">How long it has animated without a break.</param>
|
||||
/// <param name="BotWaiting">RynthAi is waiting on the server (null = RynthAi isn't there).</param>
|
||||
/// <param name="BotSteadyMs">How long that bit has read its current value.</param>
|
||||
/// <param name="BotPaced">
|
||||
/// RynthAi holds for the press and reports its own unanswered action (RynthAi.Yield); null = it
|
||||
/// doesn't (absent, from before, its pacing off): the rules above apply.
|
||||
/// </param>
|
||||
/// <param name="BotPacedMs">How long RynthAi's own action has been unanswered (0 when none).</param>
|
||||
internal readonly record struct BusyFacts(
|
||||
int Count, long CountSteadyMs, int Leftover, long SinceOwnSendMs,
|
||||
bool Animating, long AnimatingMs, bool? BotWaiting, long BotSteadyMs);
|
||||
bool Animating, long AnimatingMs, bool? BotWaiting, long BotSteadyMs,
|
||||
bool? BotPaced = null, long BotPacedMs = 0);
|
||||
|
||||
internal static class BusyRule
|
||||
{
|
||||
|
|
@ -78,6 +94,23 @@ internal static class BusyRule
|
|||
if (f.AnimatingMs < AnimationMaxMs) return BusyHold.Animation;
|
||||
stale |= BusyStale.Animation;
|
||||
}
|
||||
if (f.BotPaced is bool paced)
|
||||
{
|
||||
// RynthAi holds for the press and says what it has in flight: that, and our own last use,
|
||||
// are all that hold it. The rest of the count is a leftover or a click in the game's own
|
||||
// windows; a really busy server answers "You're too busy" (one more try).
|
||||
if (paced)
|
||||
{
|
||||
if (f.BotPacedMs < BotTrustMs) return BusyHold.Bot;
|
||||
stale |= BusyStale.Bot;
|
||||
}
|
||||
if (f.Count > 0)
|
||||
{
|
||||
if (f.Count > f.Leftover && f.SinceOwnSendMs < OwnTrustMs) return BusyHold.Busy;
|
||||
stale |= BusyStale.Count;
|
||||
}
|
||||
return BusyHold.None;
|
||||
}
|
||||
if (f.Count > 0)
|
||||
{
|
||||
bool fresh = f.CountSteadyMs < CountTrustMs || f.SinceOwnSendMs < OwnTrustMs;
|
||||
|
|
@ -110,14 +143,22 @@ internal sealed class BusyGate
|
|||
private long _animatingSinceMs;
|
||||
private bool? _bot;
|
||||
private long _botSinceMs;
|
||||
private bool _paced;
|
||||
private long _pacedSinceMs;
|
||||
private long _ownSendMs = long.MinValue / 4;
|
||||
private BusyStale _logged;
|
||||
|
||||
/// <summary>The count judged a leftover (0 = none).</summary>
|
||||
public int Leftover => _leftover;
|
||||
|
||||
public void Observe(int count, bool animating, bool? botWaiting, long now)
|
||||
public void Observe(int count, bool animating, bool? botWaiting, long now) => Observe(count, animating, botWaiting, null, now);
|
||||
|
||||
/// <param name="botPaced">RynthAi's own action is unanswered (null = it can't say).</param>
|
||||
public void Observe(int count, bool animating, bool? botWaiting, bool? botPaced, long now)
|
||||
{
|
||||
bool paced = botPaced == true;
|
||||
if (paced && !_paced) _pacedSinceMs = now;
|
||||
_paced = paced;
|
||||
if (count < 0) count = 0;
|
||||
if (!_started)
|
||||
{
|
||||
|
|
@ -153,17 +194,24 @@ internal sealed class BusyGate
|
|||
/// <summary>Our own use or cast went out now.</summary>
|
||||
public void NoteOwnSend(long now) => _ownSendMs = now;
|
||||
|
||||
public BusyFacts Facts(long now) => new(
|
||||
public BusyFacts Facts(long now) => Facts(now, false);
|
||||
|
||||
/// <param name="pacedKnown">RynthAi holds for the press (its PacedAction bit is meaningful).</param>
|
||||
public BusyFacts Facts(long now, bool pacedKnown) => new(
|
||||
_count, now - _countSinceMs, _leftover, now - _ownSendMs,
|
||||
_animating, _animating ? now - _animatingSinceMs : 0, _bot, now - _botSinceMs);
|
||||
_animating, _animating ? now - _animatingSinceMs : 0, _bot, now - _botSinceMs,
|
||||
pacedKnown ? _paced : null, pacedKnown && _paced ? now - _pacedSinceMs : 0);
|
||||
|
||||
/// <summary>
|
||||
/// What holds a use back now. A count found to be a leftover becomes the new leftover;
|
||||
/// <paramref name="newlyIgnored"/> names the leftovers not reported before (log them once).
|
||||
/// </summary>
|
||||
public BusyHold Judge(long now, out BusyStale newlyIgnored)
|
||||
public BusyHold Judge(long now, out BusyStale newlyIgnored) => Judge(now, false, out newlyIgnored);
|
||||
|
||||
/// <param name="pacedKnown">RynthAi holds for the press (RynthAi.Yield): its own action is what it says.</param>
|
||||
public BusyHold Judge(long now, bool pacedKnown, out BusyStale newlyIgnored)
|
||||
{
|
||||
BusyHold hold = BusyRule.Decide(Facts(now), out BusyStale stale);
|
||||
BusyHold hold = BusyRule.Decide(Facts(now, pacedKnown), out BusyStale stale);
|
||||
if ((stale & BusyStale.Count) != 0 && _count > _leftover)
|
||||
{
|
||||
_leftover = _count;
|
||||
|
|
@ -175,15 +223,21 @@ internal sealed class BusyGate
|
|||
}
|
||||
|
||||
/// <summary>The words for the log line when a leftover is first ignored.</summary>
|
||||
public string Describe(BusyStale what, long now)
|
||||
public string Describe(BusyStale what, long now) => Describe(what, now, false);
|
||||
|
||||
public string Describe(BusyStale what, long now, bool pacedKnown)
|
||||
{
|
||||
BusyFacts f = Facts(now);
|
||||
BusyFacts f = Facts(now, pacedKnown);
|
||||
var parts = new System.Collections.Generic.List<string>(3);
|
||||
if ((what & BusyStale.Count) != 0)
|
||||
parts.Add($"the client's busy count has read {f.Count} for {f.CountSteadyMs / 1000.0:0.0} s with nothing of ours in flight");
|
||||
parts.Add(f.BotPaced != null
|
||||
? $"the client's busy count reads {f.Count} with nothing of ours or RynthAi's in flight"
|
||||
: $"the client's busy count has read {f.Count} for {f.CountSteadyMs / 1000.0:0.0} s with nothing of ours in flight");
|
||||
if ((what & BusyStale.Animation) != 0)
|
||||
parts.Add($"the character has read 'animating' for {f.AnimatingMs / 1000.0:0.0} s");
|
||||
if ((what & BusyStale.Bot) != 0)
|
||||
if ((what & BusyStale.Bot) != 0 && f.BotPaced != null)
|
||||
parts.Add($"RynthAi's own action has had no answer for {f.BotPacedMs / 1000.0:0.0} s");
|
||||
else if ((what & BusyStale.Bot) != 0)
|
||||
parts.Add($"RynthAi has read 'waiting on the server' for {f.BotSteadyMs / 1000.0:0.0} s"
|
||||
+ ((what & BusyStale.Count) != 0 || (_logged & BusyStale.Count) != 0 ? " (its copy of the same count)" : ""));
|
||||
return "[RynthDefective] " + string.Join("; ", parts)
|
||||
|
|
@ -194,6 +248,7 @@ internal sealed class BusyGate
|
|||
{
|
||||
_started = false;
|
||||
_leftover = 0;
|
||||
_paced = false;
|
||||
_logged = BusyStale.None;
|
||||
_ownSendMs = long.MinValue / 4;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -40,6 +40,9 @@ internal sealed unsafe class HostDefWorld : IDefWorld
|
|||
|
||||
public bool? BotWaitingOnServer => BotActivity.Read(_host) is { } a ? (a & RynthAiActivity.ServerAction) != 0 : null;
|
||||
public bool? BotMacroRunning => BotActivity.Read(_host) is { } a ? (a & RynthAiActivity.MacroRunning) != 0 : null;
|
||||
public bool? BotPaced => BotYield.Available(_host) && BotActivity.Read(_host) is { } a ? (a & RynthAiActivity.PacedAction) != 0 : null;
|
||||
public bool HoldBot(uint ms) => BotYield.Hold(_host, ms);
|
||||
public void ReleaseBot() => BotYield.Release(_host);
|
||||
|
||||
public int RefusalSeq => _host.HasGetLastWeenieError && _host.TryGetLastWeenieError(out int seq, out _, out _, out _) ? seq : 0;
|
||||
|
||||
|
|
@ -149,6 +152,47 @@ internal sealed unsafe class HostDefWorld : IDefWorld
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// RynthAi's "RynthAi.Yield" interface (2026-10-29): the player's key press takes RynthAi's turn, so
|
||||
/// RynthAi starts nothing new until the press has gone. Resolved again every call (a RynthAi reload
|
||||
/// frees the table). Absent on a RynthAi from before it: nothing is held then.
|
||||
/// </summary>
|
||||
internal static unsafe class BotYield
|
||||
{
|
||||
private static RynthAiYieldApiV1* Table(RynthCoreHost host)
|
||||
{
|
||||
if (!host.HasGetPluginInterface) return null;
|
||||
try
|
||||
{
|
||||
var t = (RynthAiYieldApiV1*)host.GetPluginInterface("RynthAi", RynthAiYieldApiV1.InterfaceName, RynthAiYieldApiV1.InterfaceVersion);
|
||||
return t != null && t->Version >= 1 && t->StructSize >= (uint)sizeof(RynthAiYieldApiV1) ? t : null;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return null; // a RynthAi mid-reload
|
||||
}
|
||||
}
|
||||
|
||||
public static bool Available(RynthCoreHost host) => Table(host) != null;
|
||||
|
||||
/// <summary>Asks for the player's turn for <paramref name="ms"/>; true when RynthAi holds (its pacing is on).</summary>
|
||||
public static bool Hold(RynthCoreHost host, uint ms)
|
||||
{
|
||||
var t = Table(host);
|
||||
if (t == null || t->HoldForPlayer == null) return false;
|
||||
try { return t->HoldForPlayer(ms) != 0; }
|
||||
catch { return false; }
|
||||
}
|
||||
|
||||
public static void Release(RynthCoreHost host)
|
||||
{
|
||||
var t = Table(host);
|
||||
if (t == null || t->ReleaseHold == null) return;
|
||||
try { t->ReleaseHold(); }
|
||||
catch { }
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// RynthAi's activity bits: its "RynthAi.Activity" interface; on an older RynthAi without it, the
|
||||
/// macro bit from "RynthAi.Status"; null when RynthAi isn't loaded or not ready. Resolved again every
|
||||
|
|
|
|||
|
|
@ -27,6 +27,18 @@ internal interface IDefWorld
|
|||
bool? BotWaitingOnServer { get; }
|
||||
/// <summary>RynthAi's macro is running (null = RynthAi isn't there).</summary>
|
||||
bool? BotMacroRunning { get; }
|
||||
/// <summary>
|
||||
/// A use, cast or stance change RynthAi sent has no answer yet (its pacer's; not the busy count).
|
||||
/// Null = can't tell: RynthAi isn't there or is from before RynthAi.Yield.
|
||||
/// </summary>
|
||||
bool? BotPaced { get; }
|
||||
/// <summary>
|
||||
/// The player's turn: RynthAi starts nothing new for <paramref name="ms"/> (RynthAi.Yield). True when
|
||||
/// it holds; false when it can't (not there, from before, its pacing off): BotPaced means nothing then.
|
||||
/// </summary>
|
||||
bool HoldBot(uint ms);
|
||||
/// <summary>Ends the player's turn.</summary>
|
||||
void ReleaseBot();
|
||||
/// <summary>Count of the server's UseDone events; 0 when the engine can't report them.</summary>
|
||||
int UseDoneSeq { get; }
|
||||
/// <summary>The error of the server's first UseDone after <paramref name="seqAtSend"/> (0x1D: "You're too busy"); 0 = none or unknown.</summary>
|
||||
|
|
@ -136,6 +148,18 @@ internal static class Stance
|
|||
/// holds nothing (<see cref="BusyGate"/>, logged once); if the server really is busy it answers
|
||||
/// "You're too busy" and the use is tried once more after <see cref="RetryAfterMs"/>. Weapon swaps
|
||||
/// also wait out a running RynthAi macro unless the player allowed them (it would swap straight back).
|
||||
///
|
||||
/// The player's turn (2026-10-29): while a request waits, and for the first <see cref="FlightHoldMs"/>
|
||||
/// of its flight, RynthAi is asked to start nothing new (RynthAi.Yield, renewed every tick, let go
|
||||
/// when done). After a death or a login RynthAi rebuffs and re-wields, and a press used to wait
|
||||
/// behind that stream until it gave up. While RynthAi holds, it also says exactly what it has in
|
||||
/// flight, so only that and our own last use hold a press: the busy count beyond them is a leftover.
|
||||
///
|
||||
/// After a portal (2026-10-29): the engine takes no game action until 5 s after portal space ends
|
||||
/// (its world-transition gate: AC is still loading the new place), so a press then was refused and
|
||||
/// reported as "the client didn't take the request". Within <see cref="PortalRetryWindowMs"/> of
|
||||
/// coming out of portal space a refused use or cast waits instead and is tried again every
|
||||
/// <see cref="RefusedRetryMs"/>; it goes the moment the engine takes it.
|
||||
/// </summary>
|
||||
internal sealed class UseController
|
||||
{
|
||||
|
|
@ -156,6 +180,14 @@ internal sealed class UseController
|
|||
public const long RetryAfterMs = 1000;
|
||||
/// <summary>ACE's YoureTooBusy, as a UseDone error.</summary>
|
||||
public const uint TooBusyError = 0x1D;
|
||||
/// <summary>Each ask for the player's turn lasts this long (asked again every tick while it is wanted).</summary>
|
||||
public const uint BotHoldAskMs = 1500;
|
||||
/// <summary>RynthAi is held this long into our use's flight (a stance change of its own would cancel the use on the server).</summary>
|
||||
public const long FlightHoldMs = 3000;
|
||||
/// <summary>A use or cast the client refuses this soon after portal space ends waits and is tried again (the engine's gate holds 5 s).</summary>
|
||||
public const long PortalRetryWindowMs = 6000;
|
||||
/// <summary>How often a refused use or cast is tried again after a portal.</summary>
|
||||
public const long RefusedRetryMs = 250;
|
||||
|
||||
private enum Stage { Sent, WaitWield, Stance, Magic }
|
||||
|
||||
|
|
@ -175,6 +207,9 @@ internal sealed class UseController
|
|||
// A cast: the spell, its target, and the Magic stance it waits for.
|
||||
public uint SpellId, Target;
|
||||
public bool ModeAsked;
|
||||
/// <summary>A cast the client refused after a portal is tried again from this time.</summary>
|
||||
public long CastRetryAtMs;
|
||||
public bool CastWaitSaid;
|
||||
public long MagicSeenMs;
|
||||
}
|
||||
|
||||
|
|
@ -184,6 +219,20 @@ internal sealed class UseController
|
|||
private long _retryNotBeforeMs = long.MinValue / 4;
|
||||
private string _lastWait = string.Empty;
|
||||
private readonly BusyGate _busy = new();
|
||||
/// <summary>RynthAi holds for us (the last ask was taken): its PacedAction bit is what it has in flight.</summary>
|
||||
private bool _botHeld;
|
||||
// When the character last came out of portal space (or logged in): a refused send soon after waits.
|
||||
// Starts "in the world" so a plugin load in the world doesn't count as an arrival.
|
||||
private bool _wasInWorld = true;
|
||||
private long _worldBackMs = long.MinValue / 4;
|
||||
private long _refusedRetryAtMs = long.MinValue / 4;
|
||||
private UseRequest? _refusedSaid;
|
||||
|
||||
/// <summary>The engine refused sends this soon after the character came out of portal space: they are tried again.</summary>
|
||||
private bool JustArrived(long now) => now - _worldBackMs < PortalRetryWindowMs;
|
||||
|
||||
/// <summary>RynthAi holds its next action for the press now (tests).</summary>
|
||||
internal bool BotHeld => _botHeld;
|
||||
|
||||
/// <summary>The busy readings' clocks (tests look at the leftover).</summary>
|
||||
internal BusyGate Busy => _busy;
|
||||
|
|
@ -227,6 +276,7 @@ internal sealed class UseController
|
|||
_flight = null;
|
||||
_lastWait = string.Empty;
|
||||
_retryNotBeforeMs = long.MinValue / 4;
|
||||
_refusedRetryAtMs = long.MinValue / 4;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -243,8 +293,41 @@ internal sealed class UseController
|
|||
public void Tick(IDefWorld w)
|
||||
{
|
||||
long now = w.NowMs;
|
||||
_busy.Observe(w.BusyCount, w.Animating, w.BotWaitingOnServer, now);
|
||||
if (!w.InWorld)
|
||||
_busy.Observe(w.BusyCount, w.Animating, w.BotWaitingOnServer, w.BotPaced, now);
|
||||
try
|
||||
{
|
||||
TickInner(w, now);
|
||||
}
|
||||
finally
|
||||
{
|
||||
KeepBotHeld(w, now, ask: false); // let RynthAi go the tick the press is done
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The player's turn: asked for while a request waits or its flight is young (ask), let go when
|
||||
/// neither. RynthAi's hold ends by itself within <see cref="BotHoldAskMs"/> if we stop asking.
|
||||
/// </summary>
|
||||
private void KeepBotHeld(IDefWorld w, long now, bool ask)
|
||||
{
|
||||
bool want = _pending != null || (_flight != null && now - _flight.SentMs < FlightHoldMs);
|
||||
if (want)
|
||||
{
|
||||
if (ask) _botHeld = w.HoldBot(BotHoldAskMs);
|
||||
}
|
||||
else if (_botHeld)
|
||||
{
|
||||
w.ReleaseBot();
|
||||
_botHeld = false;
|
||||
}
|
||||
}
|
||||
|
||||
private void TickInner(IDefWorld w, long now)
|
||||
{
|
||||
bool inWorld = w.InWorld;
|
||||
if (inWorld && !_wasInWorld) _worldBackMs = now;
|
||||
_wasInWorld = inWorld;
|
||||
if (!inWorld)
|
||||
{
|
||||
// Portal space (a death's too): what was waiting is dropped, and said so (a key pressed in the
|
||||
// portal did nothing). A use in flight is the server's now; nothing to say about it.
|
||||
|
|
@ -252,6 +335,7 @@ internal sealed class UseController
|
|||
if (_pending != null || _flight != null) Reset();
|
||||
return;
|
||||
}
|
||||
KeepBotHeld(w, now, ask: true);
|
||||
if (_flight != null && !AdvanceFlight(w, now)) return; // still in flight: nothing new goes out
|
||||
if (_pending == null) return;
|
||||
|
||||
|
|
@ -275,6 +359,7 @@ internal sealed class UseController
|
|||
{
|
||||
if (now - _lastDoneMs < MinGapMs) return "the last action just finished";
|
||||
if (now < _retryNotBeforeMs) return "the server said the character was busy";
|
||||
if (now < _refusedRetryAtMs) return "the game is still loading after the portal";
|
||||
return Hold(now) switch
|
||||
{
|
||||
BusyHold.Busy => "the character is busy",
|
||||
|
|
@ -287,8 +372,8 @@ internal sealed class UseController
|
|||
/// <summary>The busy gate's verdict now; a leftover it ignores for the first time is logged.</summary>
|
||||
private BusyHold Hold(long now)
|
||||
{
|
||||
BusyHold hold = _busy.Judge(now, out BusyStale ignored);
|
||||
if (ignored != BusyStale.None) Log?.Invoke(_busy.Describe(ignored, now));
|
||||
BusyHold hold = _busy.Judge(now, _botHeld, out BusyStale ignored);
|
||||
if (ignored != BusyStale.None) Log?.Invoke(_busy.Describe(ignored, now, _botHeld));
|
||||
return hold;
|
||||
}
|
||||
|
||||
|
|
@ -354,6 +439,7 @@ internal sealed class UseController
|
|||
bool sent = target != 0 ? w.UseObjectOn(item.Id, target) : w.UseObject(item.Id);
|
||||
if (!sent)
|
||||
{
|
||||
if (WaitOutRefusal(req, name, now)) return;
|
||||
Warn?.Invoke($"{name}: the client didn't take the request (nothing was sent).");
|
||||
return;
|
||||
}
|
||||
|
|
@ -378,6 +464,25 @@ internal sealed class UseController
|
|||
Say?.Invoke(action == UseAction.Equip ? $"Wielding {name}..." : $"Using {name}...");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The client refused to send <paramref name="req"/>: just after a portal the engine takes no game
|
||||
/// action yet, so the request waits and is tried again (its wait limit still counts from the press).
|
||||
/// Said once per request. False when it isn't just after a portal: a refusal is reported as before.
|
||||
/// </summary>
|
||||
private bool WaitOutRefusal(UseRequest req, string name, long now)
|
||||
{
|
||||
if (!JustArrived(now) || _pending != null) return false; // a newer press waits already: the newest wish wins
|
||||
_pending = req;
|
||||
_refusedRetryAtMs = now + RefusedRetryMs;
|
||||
if (!ReferenceEquals(_refusedSaid, req))
|
||||
{
|
||||
_refusedSaid = req;
|
||||
Log?.Invoke($"[RynthDefective] {req.Source}: the client doesn't take {name} yet ({now - _worldBackMs} ms after the portal); trying again");
|
||||
Say?.Invoke($"{name}: waiting for the game to finish the portal...");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The server answered "You're too busy" (UseDone 0x1D) to <paramref name="f"/>'s use: it is tried
|
||||
/// once more after <see cref="RetryAfterMs"/>, unless a newer request is waiting (the newest wish
|
||||
|
|
@ -475,10 +580,23 @@ internal sealed class UseController
|
|||
|
||||
private bool Cast(IDefWorld w, Flight f, long now)
|
||||
{
|
||||
if (now < f.CastRetryAtMs) return false;
|
||||
f.UseDoneAtSend = w.UseDoneSeq;
|
||||
f.RefusalAtSend = w.RefusalSeq;
|
||||
if (!w.CastSpell(f.Target, f.SpellId))
|
||||
{
|
||||
// Just after a portal the engine takes no game action yet: the cast is tried again.
|
||||
if (JustArrived(now) && now - f.Request.AtMs < WaitLimitMs)
|
||||
{
|
||||
f.CastRetryAtMs = now + RefusedRetryMs;
|
||||
if (!f.CastWaitSaid)
|
||||
{
|
||||
f.CastWaitSaid = true;
|
||||
Log?.Invoke($"[RynthDefective] {f.Request.Source}: the client doesn't take the cast of {f.What} yet ({now - _worldBackMs} ms after the portal); trying again");
|
||||
Say?.Invoke($"{f.Name}: waiting for the game to finish the portal...");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
Warn?.Invoke($"{f.Name}: the client didn't take the cast (nothing was sent).");
|
||||
Finish(now);
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -50,6 +50,12 @@
|
|||
// the character animates, and nothing while a use's turn is unanswered, keeps every
|
||||
// server motion out of every server turn.
|
||||
//
|
||||
// The player's turn (2026-10-29, RynthAi.Yield): another plugin acting for the player (the
|
||||
// Shortcuts bar's key press) holds every start (MayStart, GestureHolds, ChangeCombatModeFor) for
|
||||
// a moment, so the player's action goes next instead of waiting behind RynthAi's own. What is
|
||||
// already out still finishes. Each ask lasts at most PlayerHoldMaxMs; the asker asks again
|
||||
// every tick while its action waits or is in flight.
|
||||
//
|
||||
// Opt-in (Enabled, RynthAi sets it at Init); off = every call goes through as before.
|
||||
// Linked into RynthAi only. UseAudit reports its sends through UseAudit.AfterSend.
|
||||
// ============================================================================
|
||||
|
|
@ -139,6 +145,8 @@ internal static class ActionPacer
|
|||
public const long AttackAfterModeReadMs = 300;
|
||||
/// <summary>An engine without UseDone: an action counts as answered after this (no real pacing).</summary>
|
||||
public const long NoUseDoneFallbackMs = 600;
|
||||
/// <summary>The longest one ask for the player's turn holds RynthAi (RynthAiYieldApiV1.MaxHoldMs).</summary>
|
||||
public const long PlayerHoldMaxMs = 3000;
|
||||
|
||||
private static readonly object Gate = new();
|
||||
private static PacedAction? _cur;
|
||||
|
|
@ -155,6 +163,10 @@ internal static class ActionPacer
|
|||
private static readonly Dictionary<string, int> _holdsByWho = new();
|
||||
private static string _lastTimeout = "";
|
||||
|
||||
// The player's turn (RynthAi.Yield): starts are held until _playerHoldUntil (0 = no hold).
|
||||
private static long _playerHoldUntil, _playerHoldSince, _playerHolds, _playerHeldStarts;
|
||||
private static readonly HashSet<string> _playerHoldLogged = new();
|
||||
|
||||
public static long Started => _started;
|
||||
public static long Answered => _answered;
|
||||
public static long TimedOut => _timedOut;
|
||||
|
|
@ -166,6 +178,9 @@ internal static class ActionPacer
|
|||
public static long HealsAhead => _healsAhead;
|
||||
public static long GestureHoldCount => _gestureHolds;
|
||||
public static long GestureLimits => _gestureLimits;
|
||||
/// <summary>Times another plugin took the player's turn, and the starts it held.</summary>
|
||||
public static long PlayerHolds => _playerHolds;
|
||||
public static long PlayerHeldStarts => _playerHeldStarts;
|
||||
|
||||
/// <summary>Back to a fresh load (Init, logout, tests). Enabled is left as it is.</summary>
|
||||
public static void Reset()
|
||||
|
|
@ -184,6 +199,8 @@ internal static class ActionPacer
|
|||
_maxWaitMs = 0;
|
||||
_maxWaitWhat = "";
|
||||
_holdsByWho.Clear();
|
||||
_playerHoldUntil = _playerHoldSince = _playerHolds = _playerHeldStarts = 0;
|
||||
_playerHoldLogged.Clear();
|
||||
_lastTimeout = "";
|
||||
ClearBusyLocked();
|
||||
_stuckBreaks = 0;
|
||||
|
|
@ -362,6 +379,72 @@ internal static class ActionPacer
|
|||
return action != null;
|
||||
}
|
||||
|
||||
// ── The player's turn ───────────────────────────────────────────────────
|
||||
|
||||
/// <summary>
|
||||
/// Another plugin acting for the player (RynthAi.Yield): no start for <paramref name="ms"/> from now
|
||||
/// (at most <see cref="PlayerHoldMaxMs"/>), the newest ask setting the end. False when pacing is off:
|
||||
/// RynthAi then knows nothing about what it has in flight, so the asker goes by its old rules.
|
||||
/// </summary>
|
||||
public static bool HoldForPlayer(RynthCoreHost host, long ms)
|
||||
{
|
||||
if (!Enabled) return false;
|
||||
long now = NowMs();
|
||||
bool began;
|
||||
lock (Gate)
|
||||
{
|
||||
began = _playerHoldUntil == 0 || now >= _playerHoldUntil;
|
||||
if (began)
|
||||
{
|
||||
_playerHoldSince = now;
|
||||
_playerHolds++;
|
||||
_playerHoldLogged.Clear();
|
||||
}
|
||||
_playerHoldUntil = now + Math.Clamp(ms, 1, PlayerHoldMaxMs);
|
||||
}
|
||||
if (began) Log(host, "[Pace] the player's turn: a key press from another plugin goes first; RynthAi starts nothing new until it has gone");
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>Ends the player's turn now (the asker's action was answered, or dropped).</summary>
|
||||
public static void ReleasePlayerHold(RynthCoreHost host)
|
||||
{
|
||||
long held;
|
||||
lock (Gate)
|
||||
{
|
||||
if (_playerHoldUntil == 0) return;
|
||||
held = NowMs() - _playerHoldSince;
|
||||
_playerHoldUntil = 0;
|
||||
_playerHoldLogged.Clear();
|
||||
}
|
||||
Log(host, $"[Pace] the player's turn is over after {held} ms; RynthAi goes on");
|
||||
}
|
||||
|
||||
/// <summary>True (with why) while another plugin has the player's turn. One log line per hold and subsystem.</summary>
|
||||
private static bool PlayerHoldsStart(RynthCoreHost host, string who, out string why)
|
||||
{
|
||||
why = "";
|
||||
if (!Enabled) return false;
|
||||
long now = NowMs();
|
||||
bool log;
|
||||
lock (Gate)
|
||||
{
|
||||
if (_playerHoldUntil == 0) return false;
|
||||
if (now >= _playerHoldUntil)
|
||||
{
|
||||
// The asker stopped asking (unloaded, stuck): the hold ends by itself.
|
||||
_playerHoldUntil = 0;
|
||||
_playerHoldLogged.Clear();
|
||||
return false;
|
||||
}
|
||||
_playerHeldStarts++;
|
||||
log = _playerHoldLogged.Add(who);
|
||||
}
|
||||
why = "the player's key press goes first";
|
||||
if (log) Log(host, $"[Pace] {who} waits: {why}");
|
||||
return true;
|
||||
}
|
||||
|
||||
// ── Gates ───────────────────────────────────────────────────────────────
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -382,6 +465,7 @@ internal static class ActionPacer
|
|||
bool animationGate = true, bool settleGate = true, bool attackRepeat = false)
|
||||
{
|
||||
if (!Enabled) { why = ""; return true; }
|
||||
if (PlayerHoldsStart(host, who, out why)) return false;
|
||||
if (ServerBusyHolds(host, who, attackRepeat, out why, out bool tryAfterBusy, heal)) return false;
|
||||
// An emergency heal does not wait for the movement settle (150-600 ms): at Emergency Heal At
|
||||
// the heal comes first; it still obeys the in-flight rules below (OutstandingAllows, GestureHolds).
|
||||
|
|
@ -472,6 +556,7 @@ internal static class ActionPacer
|
|||
{
|
||||
why = "";
|
||||
if (!Enabled) return false;
|
||||
if (PlayerHoldsStart(host, who, out why)) return true; // the item managers' moves wait too
|
||||
bool busy;
|
||||
try { busy = host.HasGetCastBusyState && host.GetCastBusyState() != 0; } catch { busy = false; }
|
||||
long now = NowMs();
|
||||
|
|
@ -1165,6 +1250,7 @@ internal static class ActionPacer
|
|||
{
|
||||
lines.Add($" Sent {_started}, answered {_answered}, no answer in time {_timedOut}{(_lastTimeout.Length > 0 ? $" (last: {_lastTimeout})" : "")}");
|
||||
lines.Add($" Starts held {_heldStarts}, moves held {_heldMoves}, heals let ahead {_healsAhead}, sent over an unanswered one {_sentOverOutstanding}");
|
||||
lines.Add($" The player's turn (key presses from other plugins): {_playerHolds}, starts held for them {_playerHeldStarts}");
|
||||
lines.Add($" Mode changes refused while waiting {_modeRefused}, skipped (already in that mode) {_modeSkipped}");
|
||||
lines.Add($" Held while the character was animating {_gestureHolds}, animation time limits {_gestureLimits}");
|
||||
lines.Add($" Held after a 'too busy' answer {_refusalHolds}, held casts turned to {_heldTurns}, stuck casts broken {_stuckBreaks} ({_forcedBreaks} by the HP failsafe; limit {StuckCastMs} ms)");
|
||||
|
|
@ -1244,6 +1330,7 @@ internal static class ActionPacer
|
|||
lock (Gate) _modeSkipped++;
|
||||
return false;
|
||||
}
|
||||
if (PlayerHoldsStart(host, "mode:" + who, out _)) return false;
|
||||
PacedAction? a = Current(host);
|
||||
if (a != null)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -60,4 +60,11 @@ public enum RynthAiActivity : uint
|
|||
Crafting = 1u << 7,
|
||||
/// <summary>The AutoCram setting is on: RynthAi itself moves loose items out of the main pack.</summary>
|
||||
AutoCram = 1u << 8,
|
||||
/// <summary>
|
||||
/// A use, cast or stance change RynthAi sent has no answer from the server yet: its pacer's one
|
||||
/// outstanding action (Shared/ActionPacer.cs). Unlike <see cref="ServerAction"/>, not the client's
|
||||
/// busy count, which can stay up with nothing in flight (a death, a login, a corpse open).
|
||||
/// Reported by a RynthAi that has RynthAi.Yield (2026-10-29), with its pacing on.
|
||||
/// </summary>
|
||||
PacedAction = 1u << 9,
|
||||
}
|
||||
|
|
|
|||
47
Plugins/Shared/RynthAiYieldApi.cs
Normal file
47
Plugins/Shared/RynthAiYieldApi.cs
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
// ============================================================================
|
||||
// RynthSuite - Plugins/Shared/RynthAiYieldApi.cs
|
||||
// The "RynthAi.Yield" interface (2026-10-29): a plugin acting for the player
|
||||
// (RynthDefective's Shortcuts bar: a key press, a click) asks RynthAi to start
|
||||
// nothing new for a moment, so the player's action goes next instead of
|
||||
// waiting behind RynthAi's stream of uses and casts. After a death or a login
|
||||
// RynthAi rebuffs and re-wields, every action of its moves the client's busy
|
||||
// count, and the bar's press waited until it gave up ("not used, the
|
||||
// character is busy"). What RynthAi already sent still finishes; nothing is
|
||||
// cancelled, and its moving and turning are not held.
|
||||
//
|
||||
// Its own interface: RynthAi.Activity stays read only.
|
||||
//
|
||||
// Rules: as RynthAi.Script (Shared/RynthAiScriptApi.cs): append-only, pump
|
||||
// thread only (OnTick and the events it drains), resolve the table again
|
||||
// every tick (a RynthAi reload frees it).
|
||||
// ============================================================================
|
||||
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace RynthCore.Plugin.Shared;
|
||||
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public unsafe struct RynthAiYieldApiV1
|
||||
{
|
||||
public const string InterfaceName = "RynthAi.Yield";
|
||||
public const uint InterfaceVersion = 1;
|
||||
|
||||
/// <summary>
|
||||
/// The longest one ask holds RynthAi, in ms. The asker asks again every tick while the player's
|
||||
/// action waits or is in flight, so one that stops asking (unloaded, stuck) frees RynthAi within this.
|
||||
/// </summary>
|
||||
public const uint MaxHoldMs = 3000;
|
||||
|
||||
public uint Version; // InterfaceVersion of the table RynthAi filled
|
||||
public uint StructSize; // sizeof(RynthAiYieldApiV1) as RynthAi built it
|
||||
|
||||
/// <summary>
|
||||
/// RynthAi starts no use, cast, stance change, attack or item move for <c>ms</c> from now (at most
|
||||
/// <see cref="MaxHoldMs"/>); the newest ask sets the end. 1 = held. 0 = RynthAi can't: not logged in,
|
||||
/// or its action pacing is off (then it doesn't know what it has in flight either).
|
||||
/// </summary>
|
||||
public delegate* unmanaged[Cdecl]<uint, int> HoldForPlayer;
|
||||
|
||||
/// <summary>Ends the hold now (the player's action went and was answered, or was dropped). 1 = ok.</summary>
|
||||
public delegate* unmanaged[Cdecl]<int> ReleaseHold;
|
||||
}
|
||||
Loading…
Reference in a new issue