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);
|
||||
}
|
||||
Loading…
Reference in a new issue