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
|
|
@ -85,6 +85,7 @@ internal static class Program
|
|||
FloodPerfTests.Register(runner);
|
||||
LootSalvageTests.Register(runner);
|
||||
LootCorpseTests.Register(runner);
|
||||
LootRetryTimingTests.Register(runner);
|
||||
ChestLootTests.Register(runner);
|
||||
OwnCorpseTests.Register(runner);
|
||||
UseRefusalTests.Register(runner);
|
||||
|
|
|
|||
|
|
@ -46,6 +46,7 @@ internal static class ActionPacingTests
|
|||
public static void Register(Runner r)
|
||||
{
|
||||
r.Add("pacing: a use is the server action until its UseDone; a refusal answers it too; a wield answers by wielding", UseAnswers);
|
||||
r.Add("pacing: the player's turn (RynthAi.Yield) holds every start, mode change and move, ends by itself, and lets what is out finish", PlayersTurn);
|
||||
r.Add("pacing: the stall onset replayed - the idle peace swap waits for the corpse use's answer, then goes; no swap to the mode you're in", OnsetModeChangeHeld);
|
||||
r.Add("pacing: moves and turns wait while the server answers; a stop with nothing of ours moving waits too, is never dropped; a real stop and the cast nudge go through", MovesHeld);
|
||||
r.Add("pacing (stop burst, flight 63260): a held stop goes out once the server answers, before the next start", HeldStopSentAfterAnswer);
|
||||
|
|
@ -151,6 +152,65 @@ internal static class ActionPacingTests
|
|||
|
||||
// ── The pacer ───────────────────────────────────────────────────────────────
|
||||
|
||||
private static void PlayersTurn()
|
||||
{
|
||||
PaceOff();
|
||||
var off = World();
|
||||
Check.False(ActionPacer.HoldForPlayer(off, 1500), "pacing off: RynthAi can't hold (it doesn't know what it has in flight)");
|
||||
Check.True(ActionPacer.MayStart(off, "Combat", HealNeed.None, out _), "and nothing is held");
|
||||
|
||||
Paced(() =>
|
||||
{
|
||||
var host = World();
|
||||
Check.True(ActionPacer.MayStart(host, "Buff", HealNeed.None, out _), "free before the ask");
|
||||
Check.True(ActionPacer.HoldForPlayer(host, 1500), "the ask is taken");
|
||||
Check.False(ActionPacer.MayStart(host, "Buff", HealNeed.None, out string why), "a buff cast waits");
|
||||
Check.True(why.Contains("key press"), "and says why: " + why);
|
||||
Check.False(ActionPacer.MayStart(host, "Combat", HealNeed.Emergency, out _), "an emergency heal waits too (the press is the player's choice)");
|
||||
Check.False(ActionPacer.MayStart(host, "Combat", HealNeed.None, out _, animationGate: false, settleGate: false, attackRepeat: true), "an attack repeat waits");
|
||||
Check.True(ActionPacer.GestureHolds(host, "Loot", HealNeed.None, out _), "the item managers' moves wait");
|
||||
FakeHost.CombatModeRequests.Clear();
|
||||
Check.False(host.ChangeCombatModeFor(CombatMode.Magic, "Buff", "wand"), "a stance change is held");
|
||||
Check.Eq(FakeHost.CombatModeRequests.Count, 0, "and not sent");
|
||||
Check.Eq(FakeHost.Logs.Count(l => l.Contains("the player's turn: a key press")), 1, "the hold logged once");
|
||||
Check.Eq(FakeHost.Logs.Count(l => l.Contains("[Pace] Buff waits: the player's key press goes first")), 1, "each subsystem's wait logged once");
|
||||
Check.Eq(FakeHost.Logs.Count(l => l.Contains("[Pace] mode:Buff waits: the player's key press")), 1, "the held stance change its own line");
|
||||
Check.False(ActionPacer.MayStart(host, "Buff", HealNeed.None, out _), "asked again: still held");
|
||||
Check.Eq(FakeHost.Logs.Count(l => l.Contains("[Pace] Buff waits: the player's key press")), 1, "not logged again");
|
||||
|
||||
// Renewed: the newest ask sets the end.
|
||||
_t += 1000;
|
||||
Check.True(ActionPacer.HoldForPlayer(host, 1500), "asked again a second later");
|
||||
Check.Eq(FakeHost.Logs.Count(l => l.Contains("the player's turn: a key press")), 1, "a renewal is the same hold");
|
||||
_t += 1400;
|
||||
Check.False(ActionPacer.MayStart(host, "Buff", HealNeed.None, out _), "2.4 s in, 1.4 s after the renewal: held");
|
||||
_t += 200;
|
||||
Check.True(ActionPacer.MayStart(host, "Buff", HealNeed.None, out _), "the asker stopped asking: the hold ends by itself");
|
||||
Check.Eq(ActionPacer.PlayerHolds, 1L, "one hold counted");
|
||||
|
||||
// Capped at PlayerHoldMaxMs whatever is asked.
|
||||
Check.True(ActionPacer.HoldForPlayer(host, 60_000), "a long ask");
|
||||
_t += ActionPacer.PlayerHoldMaxMs - 1;
|
||||
Check.False(ActionPacer.MayStart(host, "Buff", HealNeed.None, out _), "held up to the cap");
|
||||
_t += 2;
|
||||
Check.True(ActionPacer.MayStart(host, "Buff", HealNeed.None, out _), "free past it");
|
||||
|
||||
// Released early: free at once, logged.
|
||||
Check.True(ActionPacer.HoldForPlayer(host, 1500), "a third hold");
|
||||
ActionPacer.ReleasePlayerHold(host);
|
||||
Check.True(ActionPacer.MayStart(host, "Buff", HealNeed.None, out _), "released: free at once");
|
||||
Check.True(Logged("the player's turn is over"), "the release logged");
|
||||
int lines = FakeHost.Logs.Count;
|
||||
ActionPacer.ReleasePlayerHold(host);
|
||||
Check.Eq(FakeHost.Logs.Count, lines, "a second release says nothing");
|
||||
|
||||
// What is already out finishes: a hold doesn't touch the outstanding action.
|
||||
Check.True(host.UseFor(Corpse, "Loot", "open the claimed corpse"), "a corpse open goes out");
|
||||
Check.True(ActionPacer.HoldForPlayer(host, 1500), "then the press takes the turn");
|
||||
Check.True(ActionPacer.Current(host) != null, "the corpse open is still RynthAi's outstanding action");
|
||||
});
|
||||
}
|
||||
|
||||
private static void UseAnswers() => Paced(() =>
|
||||
{
|
||||
var host = World();
|
||||
|
|
|
|||
|
|
@ -15,6 +15,8 @@ internal static class ActivityInterfaceTests
|
|||
r.Add("activity: each arbiter decision maps to its own bit", ArbiterBits);
|
||||
r.Add("activity: corpse, salvage queue, server wait, crafting and AutoCram add their bits", ExtraBits);
|
||||
r.Add("activity: the table answers only its own name and versions", QueryTable);
|
||||
r.Add("activity: RynthAi's own unanswered action has its own bit (PacedAction), apart from the busy count", PacedBit);
|
||||
r.Add("yield: the RynthAi.Yield table answers only its own name and versions; nothing held before login", YieldTable);
|
||||
}
|
||||
|
||||
private static void ArbiterBits()
|
||||
|
|
@ -70,4 +72,37 @@ internal static class ActivityInterfaceTests
|
|||
ActivityInterface.Release();
|
||||
}
|
||||
}
|
||||
|
||||
private static void PacedBit()
|
||||
{
|
||||
RynthAiActivity f = ActivityInterface.Compose(BotActivity.Buffing, true, false, false, serverWait: true, false, false, pacedWait: true);
|
||||
Check.Eq(f, RynthAiActivity.MacroRunning | RynthAiActivity.Buffing | RynthAiActivity.ServerAction | RynthAiActivity.PacedAction,
|
||||
"a cast of RynthAi's out: waiting on the server, and its own action");
|
||||
f = ActivityInterface.Compose(BotActivity.Idle, false, false, false, serverWait: true, false, false);
|
||||
Check.Eq(f, RynthAiActivity.ServerAction, "only the busy count up (a leftover): no PacedAction");
|
||||
Check.Eq((uint)RynthAiActivity.PacedAction, 1u << 9, "the next free bit, after AutoCram");
|
||||
}
|
||||
|
||||
private static unsafe void YieldTable()
|
||||
{
|
||||
try
|
||||
{
|
||||
Check.True(YieldInterface.Query(RynthAiActivityApiV1.InterfaceName, 1) == IntPtr.Zero, "another interface's name");
|
||||
Check.True(YieldInterface.Query(RynthAiYieldApiV1.InterfaceName, 0) == IntPtr.Zero, "version 0");
|
||||
Check.True(YieldInterface.Query(RynthAiYieldApiV1.InterfaceName, 2) == IntPtr.Zero, "a newer version than RynthAi has");
|
||||
IntPtr p = YieldInterface.Query(RynthAiYieldApiV1.InterfaceName, 1);
|
||||
Check.True(p != IntPtr.Zero, "v1 answers");
|
||||
var t = (RynthAiYieldApiV1*)p;
|
||||
Check.Eq(t->Version, 1u, "table version");
|
||||
Check.Eq(t->StructSize, (uint)sizeof(RynthAiYieldApiV1), "table size");
|
||||
Check.True(t->HoldForPlayer != null && t->ReleaseHold != null, "functions filled in");
|
||||
Check.True(YieldInterface.Query(RynthAiYieldApiV1.InterfaceName, 1) == p, "the same table on every call");
|
||||
Check.Eq(t->HoldForPlayer(1500), 0, "no logged-in plugin: nothing held");
|
||||
Check.Eq(t->ReleaseHold(), 1, "a release with nothing held is fine");
|
||||
}
|
||||
finally
|
||||
{
|
||||
YieldInterface.Release();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -78,6 +78,7 @@ internal static class BuffTests
|
|||
r.Add("buff timers: tier-8 weapon auras last 90 minutes", TierEightAuras); // was a known failure; fixed by 9a317a8
|
||||
r.Add("buff chat: another player's speech can't record a buff timer", SpeechIsNotACast); // was a known failure; fixed by 0e384d2
|
||||
r.Add("buff school: Armor Tinkering Expertise is a Creature Enchantment spell", ArmorTinkeringSchool); // was a known failure
|
||||
r.Add("mana floor: under Get Mana At with nothing to refill mana, buffs go on while a heal's mana is kept (R-20261029-103248-ce48)", ManaFloorNoRefill);
|
||||
r.Add("buff upgrade: in a force run, the priority buffs go first, then the families cast before the skill rose are recast a level higher", UpgradeInRun);
|
||||
r.Add("buff upgrade: the next pass recasts every buff a level higher once the skill allows it; equal level or a lower skill casts nothing", UpgradeNextPass);
|
||||
r.Add("buff upgrade: a higher level learned from a scroll is cast at once (the spellbook is read again)", UpgradeAfterScroll);
|
||||
|
|
@ -1219,6 +1220,85 @@ internal static class BuffTests
|
|||
Check.True(line.Contains("level 6 -> 7 (Incantation of Strength Self)"), "the line says 6 -> 7, the level counted: " + line);
|
||||
}
|
||||
|
||||
// A report (DreamWeave, 2026-10-29: "Buffing seems to be getting stuck"): logged in at
|
||||
// 209/207 mana, the first buffs took max mana to 536, the same 209 read 39% under Get Mana At
|
||||
// 40%, and with no Stamina to Mana known and no mana potion every buff after waited on regen.
|
||||
private static BuffRig FloorRig(bool knowStaminaToMana, uint mana, uint stamina = 383)
|
||||
{
|
||||
FakeHost.Reset();
|
||||
foreach (var row in SpellTable.Rows)
|
||||
if (knowStaminaToMana || !row.Name.StartsWith("Stamina to Mana", StringComparison.Ordinal))
|
||||
FakeHost.Spellbook.Add((uint)row.Id);
|
||||
FakeHost.Skills[(Player, STypeCreature)] = (300, 2);
|
||||
FakeHost.Skills[(Player, STypeLife)] = (300, 2);
|
||||
FakeHost.Skills[(Player, STypeItem)] = (300, 2);
|
||||
FakeHost.WeaponCalls = true;
|
||||
FakeHost.CombatModeValue = CombatMode.Magic;
|
||||
var rig = new BuffRig();
|
||||
rig.B.SetWorldObjectCache(FakeHost.MakeCache(rig.Host, Player, Array.Empty<uint>()));
|
||||
BuffManager.ManaCostOverride = id => LevelOf(id) * 10;
|
||||
rig.S.IsMacroRunning = true;
|
||||
rig.S.SpellCastIntervalMs = 0;
|
||||
rig.S.GetManaAt = 40; rig.S.TopOffMana = 40;
|
||||
rig.S.HealAt = 0; rig.S.TopOffHP = 0; rig.S.EmergencyHealAt = 0; rig.S.StaminaToHealthAt = 0;
|
||||
rig.S.RestamAt = 0; rig.S.TopOffStam = 0; rig.S.UsePotions = false;
|
||||
rig.V.MaxHealth = 400; rig.V.CurrentHealth = 400;
|
||||
rig.V.MaxStamina = 383; rig.V.CurrentStamina = stamina;
|
||||
rig.V.MaxMana = 536; rig.V.CurrentMana = mana;
|
||||
var at = FakeClock(rig);
|
||||
at(0);
|
||||
rig.B.MarkLiveBuffsReadyForTests();
|
||||
rig.Live(("Strength Self I", 3000));
|
||||
rig.B.ForceFullRebuff();
|
||||
return rig;
|
||||
}
|
||||
|
||||
private static int FloorBeats(BuffRig rig, int n)
|
||||
{
|
||||
int before = FakeHost.Casts.Count;
|
||||
for (int i = 0; i < n; i++)
|
||||
{
|
||||
rig.B.OnHeartbeat();
|
||||
if (FakeHost.Casts.Count > before)
|
||||
{
|
||||
int id = FakeHost.Casts.Last().SpellId;
|
||||
rig.B.OnChatWindowText($"You cast {NameOf(id)} on {(BuffManager.IsItemEnchantment(NameOf(id)) ? "Rune Robe" : "yourself")}", 7);
|
||||
SetFld(rig.B, "_lastCastAttempt", DateTime.Now.AddSeconds(-10));
|
||||
SetFld(rig.B, "_lastSelfBuffPollAt", DateTime.MinValue);
|
||||
}
|
||||
}
|
||||
return FakeHost.Casts.Count - before;
|
||||
}
|
||||
|
||||
private static void ManaFloorNoRefill()
|
||||
{
|
||||
// The report: 209/536 (39%), Get Mana At 40%, no Stamina to Mana, no potion. Buffs go.
|
||||
var r = FloorRig(knowStaminaToMana: false, mana: 209);
|
||||
int keep = r.B.ManaFloorHealReserve();
|
||||
Check.True(keep > 0, $"a heal's mana is kept ({keep})");
|
||||
int sent = FloorBeats(r, 6);
|
||||
Check.True(sent > 0, $"buffs are cast under the floor (sent {sent}, last skip: {r.B.LastBuffSkipReason})");
|
||||
Check.True(FakeHost.Casts.All(c => !NameOf(c.SpellId).StartsWith("Stamina to Mana", StringComparison.Ordinal)), "no Stamina to Mana (none is known)");
|
||||
Check.True(FakeHost.Logs.Count(l => l.Contains("nothing can refill it") && l.Contains("buffing goes on")) == 1, "logged once");
|
||||
|
||||
// Down near the heal reserve: buffing waits, and the line names every source's reason.
|
||||
var low = FloorRig(knowStaminaToMana: false, mana: (uint)(keep + 10));
|
||||
Check.Eq(FloorBeats(low, 6), 0, "under a heal's mana plus a buff: buffing waits");
|
||||
string line = FakeHost.Logs.LastOrDefault(l => l.Contains("buffing waits: mana")) ?? "";
|
||||
Check.True(line.Contains("Stamina to Mana: no known") && line.Contains("mana potion: Use Potions is off") && line.Contains("for healing"),
|
||||
"the line gives each reason: " + line);
|
||||
|
||||
// Stamina to Mana known, stamina under its line: the floor still refills first, as before
|
||||
// (Revitalize for stamina, then Stamina to Mana); no buff goes while it can refill.
|
||||
var s2m = FloorRig(knowStaminaToMana: true, mana: 209, stamina: 20);
|
||||
FloorBeats(s2m, 6);
|
||||
var sentNames = FakeHost.Casts.Select(c => NameOf(c.SpellId)).ToList();
|
||||
Check.True(sentNames.Count > 0 && sentNames.All(n => n.StartsWith("Revitalize", StringComparison.Ordinal) || n.StartsWith("Stamina to Mana", StringComparison.Ordinal)
|
||||
|| n.Contains("Revitalize") || n.Contains("Stamina to Mana")),
|
||||
"Stamina to Mana known: only refills go, no buff: " + string.Join(", ", sentNames));
|
||||
Check.Eq(FakeHost.Logs.Count(l => l.Contains("buffing goes on")), 0, "the no-refill path isn't taken");
|
||||
}
|
||||
|
||||
private static T Fld<T>(BuffManager b, string name) => (T)typeof(BuffManager).GetField(name, BindingFlags.NonPublic | BindingFlags.Instance)!.GetValue(b)!;
|
||||
private static void SetFld(BuffManager b, string name, object v) => typeof(BuffManager).GetField(name, BindingFlags.NonPublic | BindingFlags.Instance)!.SetValue(b, v);
|
||||
|
||||
|
|
|
|||
|
|
@ -757,6 +757,7 @@ internal static class LootCorpseTests
|
|||
FakeHost.CastBusy = 0;
|
||||
TickFor(bot, retryWindowMs / 2);
|
||||
Check.Eq(FakeHost.ExternalMoves.Count(m => m.Id == Gem), 1, "the retry window counts from when the character is still");
|
||||
// (Also past the 4 s answer wait from the send by now: R-20261029-122319-321f.)
|
||||
TickFor(bot, retryWindowMs);
|
||||
Check.Eq(FakeHost.ExternalMoves.Count(m => m.Id == Gem), 2, "then one retry");
|
||||
}
|
||||
|
|
@ -765,6 +766,8 @@ internal static class LootCorpseTests
|
|||
// contents unknown to the client), 3 tries each, and every item on every corpse was skipped.
|
||||
// A pack that takes none of an item's tries now counts as full for a while: the item gets one
|
||||
// more round into another pack, and with none left looting stops with the pack-full message.
|
||||
// 2026-10-29 (R-20261029-122319-321f): only the server's refusals mark a pack full, so the
|
||||
// refusals are given here (unanswered tries: LootRetryTimingTests).
|
||||
private static void RefusingPackIsLeftOut()
|
||||
{
|
||||
var refusals = new RynthCore.Plugin.RynthAi.Loot.PackRefusals();
|
||||
|
|
@ -776,6 +779,7 @@ internal static class LootCorpseTests
|
|||
Check.False(refusals.IsRefused(8, 1), "an item landing there ends the hold");
|
||||
|
||||
BaseWorld(corpsePositioned: true);
|
||||
FakeHost.WeenieErrorCalls = true; // the server's refusals (2026-10-29: only they mark a pack full)
|
||||
var host = FakeHost.Create(Player);
|
||||
var bot = new Bot(host);
|
||||
bot.Cache.OnCreateObject(Corpse);
|
||||
|
|
@ -785,10 +789,25 @@ internal static class LootCorpseTests
|
|||
bot.Cache.Tick();
|
||||
bot.P.OnViewObjectContents(Corpse);
|
||||
|
||||
// The main pack (the only destination here) never takes the gem: it stays on the corpse.
|
||||
int retryWindowMs = bot.S.LootRetryTimeoutMs;
|
||||
TickFor(bot, retryWindowMs * 4 + 600);
|
||||
Check.True(FakeHost.ExternalMoves.Count(m => m.Id == Gem) >= 3, "three tries into the main pack");
|
||||
// The main pack (the only destination here) never takes the gem: it stays on the corpse,
|
||||
// and the server refuses each move once its pickup has run (~0.8 s: "Unable to put X into
|
||||
// container" + InventoryServerSaveFailed with no error code).
|
||||
int seen = 0;
|
||||
var refuseAt = new List<long>();
|
||||
long end = Environment.TickCount64 + 6000;
|
||||
while (Environment.TickCount64 < end && !FakeHost.Logs.Any(l => l.Contains("no pack has a free slot")))
|
||||
{
|
||||
for (; seen < FakeHost.ExternalMoves.Count; seen++)
|
||||
if (FakeHost.ExternalMoves[seen].Id == Gem) refuseAt.Add(Environment.TickCount64 + 800);
|
||||
while (refuseAt.Count > 0 && Environment.TickCount64 >= refuseAt[0])
|
||||
{
|
||||
refuseAt.RemoveAt(0);
|
||||
FakeHost.WeenieError(0, 0x00A0, Gem);
|
||||
}
|
||||
bot.Tick(BotActivity.Looting);
|
||||
Thread.Sleep(10);
|
||||
}
|
||||
Check.Eq(FakeHost.ExternalMoves.Count(m => m.Id == Gem), 3, "three tries into the main pack, each after the last one's refusal");
|
||||
Check.True(FakeHost.ExternalMoves.Where(m => m.Id == Gem).All(m => m.Target == Player), "all into the main pack");
|
||||
Check.True(FakeHost.Logs.Any(l => l.Contains("took none of 3 tries") && l.Contains("trying another pack")), "the refusing pack is left out, said once");
|
||||
Check.True(FakeHost.Logs.Any(l => l.Contains("no pack has a free slot")), "no other pack: the corpse is left");
|
||||
|
|
@ -827,9 +846,10 @@ internal static class LootCorpseTests
|
|||
for (int i = 0; i < 100 && !FakeHost.ExternalMoves.Any(m => m.Id == Gem); i++) { t += 50; bot.Tick(BotActivity.Looting); Thread.Sleep(10); }
|
||||
Check.Eq(FakeHost.ExternalMoves.Count(m => m.Id == Gem), 1, "the pickup goes on the cast's UseDone");
|
||||
|
||||
// The item stays on the corpse (refused); the next cast is unanswered when a retry is due.
|
||||
// The item stays on the corpse (no answer); the next cast is unanswered when a retry is
|
||||
// due (after the answer wait, 2026-10-29: R-20261029-122319-321f).
|
||||
ActionPacer.Begin(host, PacedKind.Cast, 0, "Bloodstone Bolt I", "Combat", FakeHost.UseDoneSeq);
|
||||
TickFor(bot, 1_500);
|
||||
TickFor(bot, (int)RynthAiPlugin.PickupAnswerWaitMinMs + bot.S.LootRetryTimeoutMs + 500);
|
||||
Check.Eq(FakeHost.ExternalMoves.Count(m => m.Id == Gem), 1, "no retry while a cast is unanswered");
|
||||
FakeHost.UseDone(0);
|
||||
TickFor(bot, 300);
|
||||
|
|
|
|||
473
Tools/RynthCore.RynthAiHostTests/Tests/LootRetryTimingTests.cs
Normal file
473
Tools/RynthCore.RynthAiHostTests/Tests/LootRetryTimingTests.cs
Normal file
|
|
@ -0,0 +1,473 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using RynthCore.Loot;
|
||||
using RynthCore.Plugin.RynthAi;
|
||||
using RynthCore.Plugin.RynthAi.LegacyUi;
|
||||
using RynthCore.PluginCore;
|
||||
using RynthCore.PluginSdk;
|
||||
using RynthCore.RynthAiHostTests.Fakes;
|
||||
using RynthCore.RynthAiTests.Harness;
|
||||
|
||||
namespace RynthCore.RynthAiHostTests.Tests;
|
||||
|
||||
// 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 answered a
|
||||
// pickup 1.5-2.7 s after the send (one confirmation landed after attempt 3 had gone out), and a
|
||||
// resend while a move is out is dropped by the client (one pending inventory request) or turned
|
||||
// away by ACE as too busy. Side packs were marked full one after another until looting stopped.
|
||||
// Also: a full main pack's refusals (InventoryServerSaveFailed, "error 0x0") were all taken for
|
||||
// "too busy" and resent for free, 6 sends over 18 s.
|
||||
// The server is simulated (SlowAce): a 1.7 s pickup motion, room per pack, refusals for room only
|
||||
// after the motion, "too busy" on arrival, the queued move behind a Return, and the client's own
|
||||
// one-request slot (a move sent while the last is unanswered never leaves the client).
|
||||
// The loot clock (CorpseOpenController.CorpseClock) is moved by hand.
|
||||
internal static class LootRetryTimingTests
|
||||
{
|
||||
private const uint Player = 0x50000D31;
|
||||
private const uint Corpse = 0x80263100;
|
||||
private const uint SidePack = 0x80263001;
|
||||
private const uint ItemTypeContainer = 0x200, ItemTypeGem = 0x800;
|
||||
private const uint LongDescKey = 16, ItemsCapacityKey = 6;
|
||||
private const string Me = "Brannoc Vell";
|
||||
private const BindingFlags Any = BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public;
|
||||
private const long TickMs = 25;
|
||||
private static (uint Cell, float X, float Y, float Z) Me0 => (0x1048002Au, 100f, 100f, 0f);
|
||||
|
||||
public static void Register(Runner r)
|
||||
{
|
||||
r.Add("loot retry (R-20261029-122319-321f): with 1.7 s answers no move is resent while one is out, no pack is marked full, every item lands", SlowServerNoFalseFull);
|
||||
r.Add("loot retry (R-20261029-122319-321f): a full main pack's refusals after the pickup count as tries (no free resends) and mark it full; the items go to the side pack", FullMainPackRefusals);
|
||||
r.Add("loot retry (R-20261029-122319-321f): unanswered moves are retried only after the answer wait; their pack marks end with the item, the next item starts fresh", UnansweredMovesDontPoison);
|
||||
r.Add("loot retry (R-20261029-122319-321f): an item that lands late, after its pack was given up on, un-marks that pack", LateLandingUnmarks);
|
||||
r.Add("loot retry (R-20261029-122319-321f): a refusal on arrival is 'too busy' (free resend), one after the pickup is the pack's answer", RefusalTiming);
|
||||
r.Add("loot retry (R-20261029-122319-321f): the answer wait grows with the server's measured answers, within 4-8 s", AnswerWaitAdapts);
|
||||
r.Add("loot retry (R-20261029-122319-321f): PackRefusals keeps confirmed marks and drops the unconfirmed ones with the item", PackRefusalMarks);
|
||||
}
|
||||
|
||||
// ── Clock and world ───────────────────────────────────────────────────────
|
||||
|
||||
private static long _now;
|
||||
|
||||
private static void Clocked(Action body)
|
||||
{
|
||||
var old = RynthAiPlugin.CorpseClock;
|
||||
_now = 70_000_000;
|
||||
RynthAiPlugin.CorpseClock = () => _now;
|
||||
try { body(); }
|
||||
finally { RynthAiPlugin.CorpseClock = old; }
|
||||
}
|
||||
|
||||
private static void World(bool sidePack, params uint[] gems)
|
||||
{
|
||||
FakeHost.Reset();
|
||||
FakeHost.SalvageCalls = true; // UseObject + MoveItemExternal
|
||||
FakeHost.WeaponCalls = true; // RequestId, HasAppraisalData
|
||||
FakeHost.CloseContainerCalls = true; // CloseContainer + GetGroundContainerId
|
||||
FakeHost.ServerGates = true; // GetCastBusyState (the pickup motions)
|
||||
FakeHost.WeenieErrorCalls = true; // GetLastWeenieError (the refusals)
|
||||
FakeHost.Names[Player] = Me;
|
||||
FakeHost.Positions[Player] = Me0;
|
||||
FakeHost.PlayerPose = Me0;
|
||||
FakeHost.Names[Corpse] = "Corpse of Brier Wasp";
|
||||
FakeHost.ItemTypes[Corpse] = ItemTypeContainer;
|
||||
FakeHost.Strings[(Corpse, LongDescKey)] = $"Killed by {Me}.";
|
||||
FakeHost.NotAttackable.Add(Corpse);
|
||||
FakeHost.Positions[Corpse] = (Me0.Cell, Me0.X + 1.0f, Me0.Y, Me0.Z);
|
||||
if (sidePack)
|
||||
{
|
||||
FakeHost.Names[SidePack] = "Backpack";
|
||||
FakeHost.ItemTypes[SidePack] = ItemTypeContainer;
|
||||
FakeHost.Ints[(SidePack, ItemsCapacityKey)] = 24;
|
||||
FakeHost.Containers[SidePack] = Player;
|
||||
}
|
||||
foreach (uint g in gems)
|
||||
{
|
||||
FakeHost.Names[g] = $"Gem {g & 0xFF}";
|
||||
FakeHost.ItemTypes[g] = ItemTypeGem;
|
||||
FakeHost.Containers[g] = Corpse;
|
||||
FakeHost.Appraised.Add(g);
|
||||
}
|
||||
}
|
||||
|
||||
private sealed class Bot
|
||||
{
|
||||
public readonly RynthAiPlugin P = new();
|
||||
public readonly LegacyUiSettings S = new()
|
||||
{
|
||||
IsMacroRunning = true, EnableLooting = true, EnableCombat = false, LootOwnership = 0,
|
||||
LootContentSettleMs = 0, LootEmptyCorpseMs = 0, StopLootingWhenPackFull = false,
|
||||
};
|
||||
public readonly WorldObjectCache Cache;
|
||||
public SlowAce? Sim;
|
||||
|
||||
public Bot(RynthCoreHost host)
|
||||
{
|
||||
typeof(RynthPluginBase).GetMethod("Attach", Any)!.Invoke(P, new object[] { FakeHost.LastApi });
|
||||
var dash = (LegacyDashboardRenderer)RuntimeHelpers.GetUninitializedObject(typeof(LegacyDashboardRenderer));
|
||||
typeof(LegacyDashboardRenderer).GetField("_settings", Any)!.SetValue(dash, S);
|
||||
Set("_dashboard", dash);
|
||||
Cache = new WorldObjectCache(host);
|
||||
Cache.SetPlayerId(Player);
|
||||
Set("_objectCache", Cache);
|
||||
Set("_playerId", Player);
|
||||
Set("_vitals", new PlayerVitalsCache { MaxHealth = 100, CurrentHealth = 100, MaxStamina = 100, CurrentStamina = 100, MaxMana = 100, CurrentMana = 100 });
|
||||
|
||||
string profile = Path.Combine(Program.TempRoot, "loot-retry-timing.json");
|
||||
var p = new LootProfile { Name = "gems" };
|
||||
var rule = new LootRule { Name = "Gems", Action = LootAction.Keep };
|
||||
rule.Conditions.Add(new ObjectClassCondition { ObjectClass = AcObjectClass.Gem });
|
||||
p.Rules.Add(rule);
|
||||
p.Save(profile);
|
||||
S.CurrentLootPath = profile;
|
||||
}
|
||||
|
||||
public void Set(string f, object? v) => typeof(RynthAiPlugin).GetField(f, Any)!.SetValue(P, v);
|
||||
public T Get<T>(string f) => (T)typeof(RynthAiPlugin).GetField(f, Any)!.GetValue(P)!;
|
||||
public object? Call(string m, params object[] a) => typeof(RynthAiPlugin).GetMethod(m, Any)!.Invoke(P, a);
|
||||
|
||||
/// <summary>One plugin tick: the clock moves on, the simulated server catches up, the looter runs.</summary>
|
||||
public void Tick()
|
||||
{
|
||||
_now += TickMs;
|
||||
Sim?.Step(_now);
|
||||
Set("_activity", BotActivity.Looting);
|
||||
Call("TickCorpseOpening");
|
||||
}
|
||||
|
||||
public void TickUntil(Func<bool> done, long maxMs)
|
||||
{
|
||||
long end = _now + maxMs;
|
||||
while (_now < end && !done()) Tick();
|
||||
}
|
||||
|
||||
public int MovesOf(uint id) => FakeHost.ExternalMoves.Count(m => m.Id == id);
|
||||
|
||||
public RynthCore.Plugin.RynthAi.Loot.PackRefusals Refusals => Get<RynthCore.Plugin.RynthAi.Loot.PackRefusals>("_packRefusals");
|
||||
|
||||
public bool Completed => Get<Dictionary<int, long>>("_completedCorpses").ContainsKey(unchecked((int)Corpse));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// ACE's pickup (Player_Inventory.cs): the move arrives, the pickup motion plays (PickupMs), then
|
||||
/// the item goes into the pack or, with no room there, "Unable to put X into container" +
|
||||
/// InventoryServerSaveFailed(item, no error code); then the Return. A move arriving during the
|
||||
/// Return is queued (NextPickup), one during the motion is "You're too busy". The client keeps
|
||||
/// one pending inventory request: a move sent while one is unanswered never leaves the client.
|
||||
/// <see cref="Lag"/>: extra delay before the server takes up an item's first move (a lag spike);
|
||||
/// <see cref="NeverAnswer"/>: items whose moves the server never answers. The engine empties a
|
||||
/// pending request that has had no answer for 10 s (ClientActionGates.PendingTimeoutMs).
|
||||
/// </summary>
|
||||
private sealed class SlowAce
|
||||
{
|
||||
public long Rtt = 200, PickupMs = 1700, ReturnMs = 740;
|
||||
public readonly Dictionary<uint, int> Room = new(); // the server's free slots per pack (absent: plenty)
|
||||
public readonly Dictionary<uint, long> Lag = new();
|
||||
public readonly HashSet<uint> NeverAnswer = new();
|
||||
public long ClientPendingTimeoutMs = 10_000;
|
||||
public int TooBusy, LocalRefused, Queued, RoomRefusals;
|
||||
public readonly List<(uint Id, uint Pack, long At)> Landed = new();
|
||||
|
||||
private enum St { Idle, Pickup, Return }
|
||||
private St _st;
|
||||
private (uint Id, uint Pack) _next;
|
||||
private int _seenMoves;
|
||||
private uint _clientPending;
|
||||
private long _clientPendingAt;
|
||||
private readonly List<(long At, int Seq, Action Act)> _events = new();
|
||||
private int _seq;
|
||||
|
||||
private void At(long at, Action act) => _events.Add((at, _seq++, act));
|
||||
|
||||
public void Step(long now)
|
||||
{
|
||||
while (_seenMoves < FakeHost.ExternalMoves.Count)
|
||||
{
|
||||
var m = FakeHost.ExternalMoves[_seenMoves++];
|
||||
if (_clientPending != 0 && now - _clientPendingAt >= ClientPendingTimeoutMs) _clientPending = 0; // the engine lets it go
|
||||
if (_clientPending != 0) { LocalRefused++; continue; } // "You can only move or use one item at a time"
|
||||
_clientPending = m.Id;
|
||||
_clientPendingAt = now;
|
||||
if (NeverAnswer.Contains(m.Id)) continue;
|
||||
long arrive = now - TickMs + Rtt / 2;
|
||||
if (Lag.Remove(m.Id, out long lag)) arrive += lag;
|
||||
At(arrive, () => Receive(m.Id, m.Target, arrive));
|
||||
}
|
||||
while (true)
|
||||
{
|
||||
var due = _events.Where(e => e.At <= now).OrderBy(e => e.At).ThenBy(e => e.Seq).ToList();
|
||||
if (due.Count == 0) break;
|
||||
var e = due[0];
|
||||
_events.Remove(e);
|
||||
e.Act();
|
||||
}
|
||||
}
|
||||
|
||||
private void Answered(uint id) { if (_clientPending == id) _clientPending = 0; }
|
||||
|
||||
private void Receive(uint id, uint pack, long ts)
|
||||
{
|
||||
if (_st == St.Idle) { StartPickup(id, pack, ts); return; }
|
||||
if (_st == St.Return && _next.Id == 0) { _next = (id, pack); Queued++; return; }
|
||||
TooBusy++;
|
||||
At(ts + Rtt / 2, () =>
|
||||
{
|
||||
FakeHost.WeenieError(0x1D); // YoureTooBusy
|
||||
FakeHost.WeenieError(0, 0x00A0, id); // InventoryServerSaveFailed(item)
|
||||
Answered(id);
|
||||
});
|
||||
}
|
||||
|
||||
private void StartPickup(uint id, uint pack, long ts)
|
||||
{
|
||||
_st = St.Pickup;
|
||||
At(ts + Rtt / 2, () => FakeHost.CastBusy = 1);
|
||||
At(ts + PickupMs, () => Finish(id, pack, ts + PickupMs));
|
||||
}
|
||||
|
||||
private void Finish(uint id, uint pack, long ts)
|
||||
{
|
||||
_st = St.Return;
|
||||
if (Room.TryGetValue(pack, out int free) && free <= 0)
|
||||
{
|
||||
RoomRefusals++;
|
||||
At(ts + Rtt / 2, () =>
|
||||
{
|
||||
FakeHost.WeenieError(0, 0x00A0, id); // "Unable to put X into container" + save failed, no code
|
||||
Answered(id);
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
if (Room.ContainsKey(pack)) Room[pack] = free - 1;
|
||||
At(ts + Rtt / 2, () =>
|
||||
{
|
||||
FakeHost.Containers[id] = pack;
|
||||
Landed.Add((id, pack, ts + Rtt / 2));
|
||||
Answered(id);
|
||||
});
|
||||
}
|
||||
At(ts + ReturnMs, () => ReturnDone(ts + ReturnMs));
|
||||
}
|
||||
|
||||
private void ReturnDone(long ts)
|
||||
{
|
||||
if (_next.Id != 0)
|
||||
{
|
||||
var n = _next;
|
||||
_next = default;
|
||||
StartPickup(n.Id, n.Pack, ts);
|
||||
return;
|
||||
}
|
||||
_st = St.Idle;
|
||||
At(ts + Rtt / 2, () => FakeHost.CastBusy = 0);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Claims and opens the corpse (the server's ViewContents), with the side pack known to the cache.</summary>
|
||||
private static Bot Open(SlowAce sim, bool sidePack, params uint[] gems)
|
||||
{
|
||||
var host = FakeHost.Create(Player);
|
||||
var bot = new Bot(host) { Sim = sim };
|
||||
var ids = new List<uint> { Corpse };
|
||||
if (sidePack) ids.Add(SidePack);
|
||||
ids.AddRange(gems);
|
||||
foreach (uint id in ids) bot.Cache.OnCreateObject(id);
|
||||
for (int i = 0; i < 50; i++) bot.Cache.Tick();
|
||||
if (sidePack)
|
||||
Check.True(bot.Cache.GetDirectInventory(forceRefresh: true).Any(o => o.Id == unchecked((int)SidePack) && o.ObjectClass == AcObjectClass.Container),
|
||||
"the side pack is in the inventory as a container");
|
||||
bot.Tick();
|
||||
Check.True(FakeHost.Uses.Contains(Corpse), "the corpse is opened");
|
||||
FakeHost.UseDone(0);
|
||||
FakeHost.GroundContainer = Corpse;
|
||||
bot.P.OnViewObjectContents(Corpse);
|
||||
return bot;
|
||||
}
|
||||
|
||||
private static bool Logged(string part) => FakeHost.Logs.Any(l => l.Contains(part, StringComparison.Ordinal));
|
||||
|
||||
/// <summary>Ticks until <paramref name="done"/>, noting the clock at each new move.</summary>
|
||||
private static List<(uint Id, long At)> Run(Bot bot, Func<bool> done, long maxMs)
|
||||
{
|
||||
var sends = new List<(uint, long)>();
|
||||
int seen = FakeHost.ExternalMoves.Count;
|
||||
long end = _now + maxMs;
|
||||
while (_now < end && !done())
|
||||
{
|
||||
bot.Tick();
|
||||
while (seen < FakeHost.ExternalMoves.Count) sends.Add((FakeHost.ExternalMoves[seen++].Id, _now));
|
||||
}
|
||||
return sends;
|
||||
}
|
||||
|
||||
// ── 1. A slow server, room everywhere ─────────────────────────────────────
|
||||
|
||||
private static void SlowServerNoFalseFull() => Clocked(() =>
|
||||
{
|
||||
const uint G1 = 0x80263101, G2 = 0x80263102, G3 = 0x80263103, G4 = 0x80263104;
|
||||
World(sidePack: true, G1, G2, G3, G4);
|
||||
var sim = new SlowAce();
|
||||
var bot = Open(sim, sidePack: true, G1, G2, G3, G4);
|
||||
|
||||
Run(bot, () => bot.Completed, 60_000);
|
||||
|
||||
foreach (uint g in new[] { G1, G2, G3, G4 })
|
||||
{
|
||||
Check.Eq(bot.MovesOf(g), 1, $"0x{g:X8} is sent once: its answer (~1.8 s, or behind the last Return) is waited for");
|
||||
Check.True(sim.Landed.Any(l => l.Id == g), $"0x{g:X8} lands");
|
||||
}
|
||||
Check.Eq(sim.LocalRefused, 0, "no move sent while another was unanswered (the client would drop it)");
|
||||
Check.Eq(sim.TooBusy, 0, "no 'too busy' from the server");
|
||||
Check.False(Logged("took none of"), "no pack judged full");
|
||||
Check.False(Logged("pickup failed"), "nothing given up on");
|
||||
Check.False(Logged("retrying use"), "no retries at all");
|
||||
Check.False(bot.Refusals.IsRefused(unchecked((int)Player), _now), "the main pack is not marked");
|
||||
Check.True(bot.Completed, "the corpse is finished");
|
||||
});
|
||||
|
||||
// ── 2. The main pack is full (the client counts room) ─────────────────────
|
||||
|
||||
private static void FullMainPackRefusals() => Clocked(() =>
|
||||
{
|
||||
const uint Map = 0x80263111, G2 = 0x80263112;
|
||||
World(sidePack: true, Map, G2);
|
||||
var sim = new SlowAce();
|
||||
sim.Room[Player] = 0; // the server's main pack is full; the client's count says room
|
||||
var bot = Open(sim, sidePack: true, Map, G2);
|
||||
|
||||
Run(bot, () => bot.Completed, 60_000);
|
||||
|
||||
var mapMoves = FakeHost.ExternalMoves.Where(m => m.Id == Map).ToList();
|
||||
Check.Eq(mapMoves.Count(m => m.Target == Player), 3, "three tries into the main pack (each refused after the pickup ran), no free resends");
|
||||
Check.False(Logged("as too busy"), "a refusal after the pickup is not taken for 'too busy'");
|
||||
Check.True(Logged("the main pack took none of 3 tries") && Logged("the server refused 3 after the pickup ran") && Logged("treating it as full"),
|
||||
"the main pack is judged full on the server's refusals");
|
||||
Check.True(mapMoves.Last().Target == SidePack && sim.Landed.Any(l => l.Id == Map && l.Pack == SidePack), "then the map goes into the side pack and lands");
|
||||
Check.True(FakeHost.ExternalMoves.Where(m => m.Id == G2).All(m => m.Target == SidePack), "the next item goes straight to the side pack");
|
||||
Check.True(sim.Landed.Any(l => l.Id == G2), "and lands");
|
||||
Check.True(bot.Refusals.IsConfirmed(unchecked((int)Player), _now), "the main pack stays marked (confirmed by the server)");
|
||||
Check.False(bot.Refusals.IsRefused(unchecked((int)SidePack), _now), "the side pack is not marked");
|
||||
Check.Eq(sim.LocalRefused, 0, "no move sent while another was unanswered");
|
||||
});
|
||||
|
||||
// ── 3. Moves the server never answers ─────────────────────────────────────
|
||||
|
||||
private static void UnansweredMovesDontPoison() => Clocked(() =>
|
||||
{
|
||||
const uint Lost = 0x80263121, Next = 0x80263122;
|
||||
World(sidePack: true, Lost, Next);
|
||||
var sim = new SlowAce();
|
||||
sim.NeverAnswer.Add(Lost); // the server never answers the lost item's moves
|
||||
var bot = Open(sim, sidePack: true, Lost, Next);
|
||||
var sends = Run(bot, () => bot.Completed, 90_000).Where(s => s.Id == Lost).ToList();
|
||||
|
||||
var lostMoves = FakeHost.ExternalMoves.Where(m => m.Id == Lost).ToList();
|
||||
Check.Eq(lostMoves.Count, 6, "three tries into the main pack, three into the side pack");
|
||||
var gaps = sends.Zip(sends.Skip(1), (a, b) => b.At - a.At).ToList();
|
||||
Check.True(gaps.Count > 0 && gaps.All(g => g >= RynthAiPlugin.PickupAnswerWaitMinMs - TickMs),
|
||||
$"each retry only after the answer wait ({string.Join(", ", gaps)} ms)");
|
||||
Check.True(Logged("trying another pack for this item only"), "the main pack is left out for this item only");
|
||||
Check.False(Logged("treating it as full"), "no pack is judged full on unanswered tries");
|
||||
Check.True(Logged("pickup failed for 0x80263121"), "the item is given up after the second round");
|
||||
Check.False(bot.Refusals.IsRefused(unchecked((int)Player), _now), "the main pack's mark ended with the item");
|
||||
Check.False(bot.Refusals.IsRefused(unchecked((int)SidePack), _now), "so did the side pack's");
|
||||
Check.True(FakeHost.ExternalMoves.Where(m => m.Id == Next).All(m => m.Target == Player), "the next item goes into the main pack again");
|
||||
Check.True(sim.Landed.Any(l => l.Id == Next && l.Pack == Player), "and lands there");
|
||||
Check.False(Logged("pickup failed for 0x80263122"), "the next item is not given up on");
|
||||
Check.False(Logged("no pack has a free slot"), "looting does not stop for want of a pack");
|
||||
});
|
||||
|
||||
// ── 4. A late landing ─────────────────────────────────────────────────────
|
||||
|
||||
private static void LateLandingUnmarks() => Clocked(() =>
|
||||
{
|
||||
const uint Slow = 0x80263131, Next = 0x80263132;
|
||||
World(sidePack: true, Slow, Next);
|
||||
var sim = new SlowAce();
|
||||
sim.Lag[Slow] = 12_500; // a lag spike: the server takes up the first move 12.5 s late
|
||||
var bot = Open(sim, sidePack: true, Slow, Next);
|
||||
|
||||
Run(bot, () => bot.Completed, 90_000);
|
||||
|
||||
Check.True(sim.Landed.Any(l => l.Id == Slow && l.Pack == Player), "the first move lands in the main pack, late");
|
||||
Check.True(Logged("trying another pack for this item only"), "after three unanswered tries the main pack was left out for the item");
|
||||
Check.True(Logged("0x80263131 landed in the main pack; it has room after all and is no longer treated as full"), "the late landing un-marks the main pack");
|
||||
Check.False(bot.Refusals.IsRefused(unchecked((int)Player), _now), "the main pack is not marked");
|
||||
Check.True(sim.Landed.Any(l => l.Id == Next), "the next item lands too");
|
||||
Check.False(Logged("pickup failed for 0x80263132"), "the next item is not given up on");
|
||||
Check.False(Logged("no pack has a free slot"), "looting does not stop");
|
||||
Check.Eq((long)bot.Call("PickupAnswerWaitMs")!, RynthAiPlugin.PickupAnswerWaitMinMs,
|
||||
"the lag spike's late answer (to an earlier, timed-out send) does not stretch the answer wait");
|
||||
});
|
||||
|
||||
// ── 5. Busy or room ───────────────────────────────────────────────────────
|
||||
|
||||
private static void RefusalTiming() => Clocked(() =>
|
||||
{
|
||||
const uint G1 = 0x80263141;
|
||||
World(sidePack: false, G1);
|
||||
var bot = Open(new SlowAce(), sidePack: false, G1);
|
||||
bot.Sim = null; // the answers are given by hand here
|
||||
bot.TickUntil(() => bot.MovesOf(G1) > 0, 2000);
|
||||
Check.Eq(bot.MovesOf(G1), 1, "the move is sent");
|
||||
|
||||
// Refused on arrival (ACE: YoureTooBusy, then InventoryServerSaveFailed with no code; the
|
||||
// engine keeps the last one, error 0x0): a free resend once still.
|
||||
bot.Tick();
|
||||
FakeHost.WeenieError(0x1D);
|
||||
FakeHost.WeenieError(0, 0x00A0, G1);
|
||||
bot.TickUntil(() => bot.MovesOf(G1) > 1, 1000);
|
||||
Check.Eq(bot.MovesOf(G1), 2, "resent at once");
|
||||
Check.True(Logged("the server refused 0x80263141 as too busy"), "logged as too busy");
|
||||
Check.Eq(bot.Get<int>("_currentLootItemMoveAttempts"), 1, "not one of the 3 tries");
|
||||
|
||||
// Refused after its pickup ran (no room; the same error 0x0): one of the tries.
|
||||
FakeHost.CastBusy = 1;
|
||||
bot.TickUntil(() => false, 1800);
|
||||
FakeHost.WeenieError(0, 0x00A0, G1);
|
||||
bot.Tick();
|
||||
FakeHost.CastBusy = 0;
|
||||
bot.TickUntil(() => bot.MovesOf(G1) > 2, 3000);
|
||||
Check.Eq(bot.MovesOf(G1), 3, "sent again after the retry window");
|
||||
Check.Eq(bot.Get<int>("_currentLootItemMoveAttempts"), 2, "counted as a try");
|
||||
Check.True(Logged("retrying use for 0x80263141 attempt 2 (last: refused"), "logged as refused after its pickup ran");
|
||||
Check.Eq(bot.Get<int>("_currentLootItemDestRefusals"), 1, "and it counts against the main pack (the busy one does not)");
|
||||
});
|
||||
|
||||
// ── 6. The wait itself ────────────────────────────────────────────────────
|
||||
|
||||
private static void AnswerWaitAdapts() => Clocked(() =>
|
||||
{
|
||||
World(sidePack: false);
|
||||
var bot = new Bot(FakeHost.Create(Player));
|
||||
long Wait() => (long)bot.Call("PickupAnswerWaitMs")!;
|
||||
Check.Eq(Wait(), RynthAiPlugin.PickupAnswerWaitMinMs, "4 s with nothing measured");
|
||||
foreach (long ms in new long[] { 1500, 1657, 2735 }) bot.Call("NotePickupAnswerLatency", ms);
|
||||
Check.Eq(Wait(), 2735 + RynthAiPlugin.PickupAnswerWaitMarginMs, "the slowest answer (2.7 s, Conquest's queued pickups) plus 1.5 s");
|
||||
bot.Call("NotePickupAnswerLatency", 20_000L);
|
||||
Check.Eq(Wait(), RynthAiPlugin.PickupAnswerWaitMaxMs, "at most 8 s");
|
||||
for (int i = 0; i < 8; i++) bot.Call("NotePickupAnswerLatency", 800L);
|
||||
Check.Eq(Wait(), RynthAiPlugin.PickupAnswerWaitMinMs, "the last 8 answers only, never under 4 s");
|
||||
});
|
||||
|
||||
private static void PackRefusalMarks()
|
||||
{
|
||||
var r = new RynthCore.Plugin.RynthAi.Loot.PackRefusals();
|
||||
r.Refuse(1, 0, confirmed: true);
|
||||
r.Refuse(2, 0, confirmed: false);
|
||||
Check.True(r.IsRefused(1, 10) && r.IsConfirmed(1, 10), "a confirmed mark");
|
||||
Check.True(r.IsRefused(2, 10) && !r.IsConfirmed(2, 10), "an unconfirmed mark is left out too");
|
||||
r.Refuse(1, 5, confirmed: false);
|
||||
Check.True(r.IsConfirmed(1, 10), "a confirmed mark is not weakened by an unconfirmed one");
|
||||
r.ClearUnconfirmed();
|
||||
Check.True(r.IsRefused(1, 10), "the confirmed mark stays");
|
||||
Check.False(r.IsRefused(2, 10), "the unconfirmed one goes with its item");
|
||||
r.Accepted(1);
|
||||
Check.False(r.IsRefused(1, 10), "an item landing there ends a confirmed mark");
|
||||
}
|
||||
}
|
||||
|
|
@ -54,6 +54,9 @@ internal static class SelfTestMetaTests
|
|||
var cache = FakeHost.MakeCache(host, Player, new[] { buffBot }, new Dictionary<uint, float> { [buffBot] = 1f });
|
||||
var r = new Run(host, cache, "T2 Fight");
|
||||
r.M.SetCombatTargetCount(() => targets);
|
||||
// What the Default state sets before the run reaches the fight. It came from an earlier test's
|
||||
// pvars file, which reached the disk only when its real-time save throttle allowed (a flake).
|
||||
r.M.Expressions.Evaluate("setpvar[rt_fight,`PENDING`]");
|
||||
return r;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -54,6 +54,7 @@ internal static class WeaponTests
|
|||
r.Add("slayer: read through the host (int 166, float 138, monster int 2), cached by wcid", SlayerFromHost);
|
||||
r.Add("refusal: a refused stance change in combat's equip pass sets no backoff and starts no stuck clock", StanceRefusedKeepsBackoff);
|
||||
r.Add("weapon choice: an unlisted wand is never picked (Damage tab, learned, pack, name)", UnlistedNeverPicked);
|
||||
r.Add("cast element: with the plan's wand not in hand (a held swap), the wand in hand casts its own element (R-20261029-125901-e22d)", HeldWandCastsItsElement);
|
||||
r.Add("weapon choice: the Monsters rule's weapon is used (R-20261022-193411-fb72), below this monster's Damage tab pick; the Default row's like the Damage tab default", MonsterRuleWeapon);
|
||||
r.Add("Items list: a listed item no longer carried is reported missing (pack, hand, unknown)", MissingFromPack);
|
||||
r.Add("weapon choice: a listed weapon someone else now has (sold) is skipped, even as this monster's Damage tab pick", SoldWeaponSkipped);
|
||||
|
|
@ -888,6 +889,36 @@ internal static class WeaponTests
|
|||
/// Lightning wand; the rule says the fire wand. Each step uses a new rule object, so PlanFor's
|
||||
/// cache (keyed on the rule by reference) doesn't hand back the previous answer.
|
||||
/// </summary>
|
||||
// Conquest, 2026-10-29: "not swapping 0x80181B46 'Frost Sceptre' for 0x8024231C 'Acid Staff' yet
|
||||
// (target at 23% health)", then Incantation of Acid Blast cast through the Frost Sceptre.
|
||||
private static void HeldWandCastsItsElement()
|
||||
{
|
||||
var rig = new Rig(1535, "Ethereal Wisp");
|
||||
rig.S.ItemRules.Add(new() { Id = unchecked((int)FireWand), Name = "Fire Wand", Element = "Fire", ElementSource = "icon" });
|
||||
var rule = new MonsterRule { Name = "Ethereal" }; // damage type Auto
|
||||
var pref = typeof(CombatManager).GetMethod("GetPreferredElement", BindingFlags.Instance | BindingFlags.NonPublic)!;
|
||||
string Elem() => (string)pref.Invoke(rig.C, new object?[] { rig.Target, rule })!;
|
||||
|
||||
var plan = rig.C.PlanFor(rig.Target, rule);
|
||||
Check.Eq(unchecked((uint)plan.WeaponId), ListedWand, "the plan: the Lightning wand (the weakness)");
|
||||
|
||||
rig.C.InHandOverride = () => unchecked((int)ListedWand);
|
||||
Check.Eq(Elem(), "Lightning", "the plan's wand in hand: its element");
|
||||
|
||||
rig.C.InHandOverride = () => unchecked((int)FireWand); // the swap was held: the fire wand stays
|
||||
Check.Eq(Elem(), "Fire", "the fire wand in hand casts Fire, not the plan's Lightning");
|
||||
Check.True(FakeHost.Logs.Count(l => l.Contains("isn't in hand: casting Fire")) == 1, "logged once");
|
||||
Elem();
|
||||
Check.True(FakeHost.Logs.Count(l => l.Contains("isn't in hand: casting Fire")) == 1, "still once");
|
||||
|
||||
rig.C.CanCastOverride = e => e != "Nether" && e != "Fire"; // a wand whose element can't be cast
|
||||
Check.Eq(Elem(), "Lightning", "an element the character can't cast: the plan's element");
|
||||
|
||||
rig.C.InHandOverride = () => 0; // nothing readable in hand
|
||||
rig.C.CanCastOverride = e => e != "Nether";
|
||||
Check.Eq(Elem(), "Lightning", "nothing in hand: the plan's element");
|
||||
}
|
||||
|
||||
private static void MonsterRuleWeapon()
|
||||
{
|
||||
var rig = new Rig(1535, "Ethereal Wisp");
|
||||
|
|
|
|||
|
|
@ -70,6 +70,9 @@ namespace RynthDefective.Tests
|
|||
Run("busy rule: a leftover count, our own use, animation, a count that just changed", BusyRuleDecisions);
|
||||
Run("use: a busy count left by a death or a login doesn't hold the bar", UseStaleBusy);
|
||||
Run("use: 'You're too busy' from the server: one more try", UseTooBusyRetry);
|
||||
Run("busy rule with RynthAi holding: its own action and our last use hold, the rest of the count doesn't", BusyRulePaced);
|
||||
Run("use: the player's turn - after a death the press goes next, RynthAi holds and is let go", UsePlayersTurn);
|
||||
Run("use: just after a portal the client takes nothing for a few seconds - the press waits and goes when it can", UseAfterPortal);
|
||||
Run("spells: the table's names and flags, the name search", SpellTableAndSearch);
|
||||
Run("spells: whom a cast goes to", SpellCastTarget);
|
||||
Run("spells: a slot casts, Magic mode first, refusals", SpellUse);
|
||||
|
|
@ -219,6 +222,28 @@ namespace RynthDefective.Tests
|
|||
public bool Animating { get; set; }
|
||||
public bool? BotWaitingOnServer { get; set; }
|
||||
public bool? BotMacroRunning { get; set; }
|
||||
/// <summary>RynthAi has RynthAi.Yield with its pacing on (off: a RynthAi from before, as the older tests assume).</summary>
|
||||
public bool YieldOn;
|
||||
/// <summary>RynthAi's own action is unanswered (read only while YieldOn).</summary>
|
||||
public bool BotOwnAction;
|
||||
public bool? BotPaced => YieldOn ? BotOwnAction : null;
|
||||
/// <summary>The asks for the player's turn, the releases, and whether RynthAi holds now.</summary>
|
||||
public int HoldAsks, Releases;
|
||||
public bool BotHeldNow;
|
||||
public long HeldUntil;
|
||||
public bool HoldBot(uint ms)
|
||||
{
|
||||
if (!YieldOn) return false;
|
||||
HoldAsks++;
|
||||
BotHeldNow = true;
|
||||
HeldUntil = NowMs + ms;
|
||||
return true;
|
||||
}
|
||||
public void ReleaseBot()
|
||||
{
|
||||
Releases++;
|
||||
BotHeldNow = false;
|
||||
}
|
||||
public int UseDoneSeq { get; set; } = 1;
|
||||
public int CombatMode { get; set; } = Stance.NonCombat;
|
||||
public int RefusalSeq { get; set; }
|
||||
|
|
|
|||
|
|
@ -35,6 +35,7 @@
|
|||
<ItemGroup>
|
||||
<Compile Include="..\..\Plugins\RynthCore.Plugin.RynthDefective\**\*.cs" Exclude="..\..\Plugins\RynthCore.Plugin.RynthDefective\obj\**;..\..\Plugins\RynthCore.Plugin.RynthDefective\bin\**" Link="RynthDefective\%(RecursiveDir)%(Filename)%(Extension)" />
|
||||
<Compile Include="..\..\Plugins\Shared\RynthAiActivityApi.cs" Link="Shared\RynthAiActivityApi.cs" />
|
||||
<Compile Include="..\..\Plugins\Shared\RynthAiYieldApi.cs" Link="Shared\RynthAiYieldApi.cs" />
|
||||
<Compile Include="..\..\Plugins\Shared\RynthAiStatusApi.cs" Link="Shared\RynthAiStatusApi.cs" />
|
||||
<Compile Include="..\..\Plugins\Shared\RynthInstallPaths.cs" Link="Shared\RynthInstallPaths.cs" />
|
||||
<Compile Include="..\..\Plugins\Shared\CommandReply.cs" Link="Shared\CommandReply.cs" />
|
||||
|
|
|
|||
|
|
@ -174,6 +174,189 @@ namespace RynthDefective.Tests
|
|||
Eq(BusyRule.Decide(Facts(bot: false, botMs: 50), out _), BusyHold.None, "RynthAi idle");
|
||||
}
|
||||
|
||||
// RynthAi holds for the press (RynthAi.Yield, 2026-10-29) and says what it has in flight.
|
||||
private static BusyFacts Paced(int count = 0, long steady = 0, int leftover = 0, long own = long.MaxValue / 4,
|
||||
bool anim = false, long animMs = 0, bool? botWait = null, bool paced = false, long pacedMs = 0) =>
|
||||
new(count, steady, leftover, own, anim, animMs, botWait, 0, paced, pacedMs);
|
||||
|
||||
private static void BusyRulePaced()
|
||||
{
|
||||
Eq(BusyRule.Decide(Paced(), out BusyStale st), BusyHold.None, "idle: send");
|
||||
Eq(BusyRule.Decide(Paced(count: 2, steady: 100), out st), BusyHold.None,
|
||||
"a count that just moved, with nothing of ours or RynthAi's in flight (a death's, a corpse open's): send");
|
||||
Eq(st, BusyStale.Count, "ignored as a leftover");
|
||||
Eq(BusyRule.Decide(Paced(count: 1, steady: 100, own: 500), out _), BusyHold.Busy, "right after our own use: wait");
|
||||
Eq(BusyRule.Decide(Paced(count: 1, steady: 100, own: BusyRule.OwnTrustMs), out _), BusyHold.None, "our own use long enough ago: send");
|
||||
Eq(BusyRule.Decide(Paced(count: 3, steady: 100, leftover: 3, own: 500), out _), BusyHold.None, "our use's count back at the leftover: send");
|
||||
Eq(BusyRule.Decide(Paced(paced: true, pacedMs: 300), out _), BusyHold.Bot, "RynthAi's own action unanswered: wait for its answer");
|
||||
Eq(BusyRule.Decide(Paced(paced: true, pacedMs: BusyRule.BotTrustMs), out st), BusyHold.None, "at most BotTrustMs");
|
||||
Eq(st, BusyStale.Bot, "then ignored");
|
||||
Eq(BusyRule.Decide(Paced(count: 1, steady: 50, botWait: true), out _), BusyHold.None,
|
||||
"RynthAi's 'waiting on the server' bit (its copy of the busy count) holds nothing while it holds for us");
|
||||
Eq(BusyRule.Decide(Paced(anim: true, animMs: 300), out _), BusyHold.Animation, "a gesture still holds");
|
||||
Eq(BusyRule.Decide(Facts(count: 1, steady: 100), out _), BusyHold.Busy, "without the hold (a RynthAi from before): the old rule, a fresh count holds");
|
||||
}
|
||||
|
||||
private static void UsePlayersTurn()
|
||||
{
|
||||
ItemRef kit = ItemRef.From(Kit(0x10));
|
||||
|
||||
// After a death: the death left 2 in the count, and RynthAi's rebuffs keep moving it.
|
||||
Harness h = With(Kit(0x10));
|
||||
h.World.YieldOn = true;
|
||||
h.World.BusyCount = 2;
|
||||
h.Tick();
|
||||
h.World.BusyCount = 3; h.Tick(400); // a cast of RynthAi's, answered
|
||||
h.World.BusyCount = 2; h.Tick(400);
|
||||
Eq(h.World.HoldAsks, 0, "nothing asked while nothing waits");
|
||||
h.Slot(kit);
|
||||
h.Tick(50);
|
||||
Eq(string.Join("|", h.World.Sent), "useon 10 me", "the press goes at once: nothing of ours or RynthAi's is in flight");
|
||||
Check(h.World.HoldAsks == 1 && h.World.BotHeldNow && h.Use.BotHeld, "RynthAi was asked to hold, and holds through the kit's flight");
|
||||
Eq(h.Warned.Count, 0, "no warning");
|
||||
Eq(h.Logged.Count(l => l.Contains("nothing of ours or RynthAi's in flight")), 1, "the leftover is logged once");
|
||||
h.Tick(100);
|
||||
Check(h.World.HoldAsks == 2 && h.World.BotHeldNow, "asked again every tick of the flight");
|
||||
h.World.Answer();
|
||||
h.Tick(100);
|
||||
Check(!h.Use.InFlight && !h.World.BotHeldNow && h.World.Releases == 1 && !h.Use.BotHeld, "answered: RynthAi is let go that tick");
|
||||
h.Tick(100);
|
||||
Eq(h.World.Releases, 1, "and only once");
|
||||
|
||||
// RynthAi's own cast is still out: the press waits for its answer, and goes before anything new of RynthAi's.
|
||||
h = With(Kit(0x10));
|
||||
h.World.YieldOn = true;
|
||||
h.World.BotOwnAction = true;
|
||||
h.World.BusyCount = 1;
|
||||
h.Tick();
|
||||
h.Slot(kit);
|
||||
h.Ticks(3, 500);
|
||||
Eq(h.World.Sent.Count, 0, "RynthAi's cast has no answer yet: the press waits");
|
||||
Check(h.World.BotHeldNow && h.World.HoldAsks == 3, "while RynthAi holds its next one (asked every tick)");
|
||||
h.World.BotOwnAction = false;
|
||||
h.World.BusyCount = 0;
|
||||
h.Tick(100);
|
||||
Eq(h.World.Sent.Count, 1, "answered: the press goes next");
|
||||
|
||||
// A RynthAi action that never gets an answer holds the press at most BotTrustMs.
|
||||
h = With(Kit(0x10));
|
||||
h.World.YieldOn = true;
|
||||
h.World.BotOwnAction = true;
|
||||
h.Tick();
|
||||
h.Slot(kit);
|
||||
h.Ticks(5, 1000);
|
||||
Eq(h.World.Sent.Count, 0, "5 s: still waiting for RynthAi's answer");
|
||||
h.Tick(600);
|
||||
Check(h.World.Sent.Count == 1 && h.Warned.Count == 0, "past 5.5 s the press goes anyway, no warning");
|
||||
Check(h.Logged.Any(l => l.Contains("RynthAi's own action has had no answer")), "and the log says why");
|
||||
|
||||
// Our use gets no answer: RynthAi is let go after FlightHoldMs though the use is still out.
|
||||
h = With(Kit(0x10));
|
||||
h.World.YieldOn = true;
|
||||
h.Tick();
|
||||
h.Slot(kit);
|
||||
h.Tick(50);
|
||||
h.World.BusyCount = 1; // the client holds our kit busy (so it isn't let go as quiet)
|
||||
h.Tick(2000);
|
||||
Check(h.Use.InFlight && h.World.BotHeldNow, "2 s into the flight: RynthAi still holds");
|
||||
h.Tick(1100);
|
||||
Check(h.Use.InFlight && !h.World.BotHeldNow && h.World.Releases == 1, "past 3 s: RynthAi goes on while our use waits for its answer");
|
||||
|
||||
// Portal space drops the press and lets RynthAi go.
|
||||
h = With(Kit(0x10));
|
||||
h.World.YieldOn = true;
|
||||
h.World.BotOwnAction = true;
|
||||
h.Tick();
|
||||
h.Slot(kit);
|
||||
h.Tick(100);
|
||||
Check(h.World.BotHeldNow, "held while the press waits");
|
||||
h.World.InWorld = false;
|
||||
h.Tick(100);
|
||||
Check(!h.Use.HasPending && !h.World.BotHeldNow && h.World.Releases == 1, "portal space: dropped, RynthAi let go");
|
||||
|
||||
// A RynthAi from before RynthAi.Yield: nothing to ask, nothing to let go, the old rule.
|
||||
h = With(Kit(0x10));
|
||||
h.World.BusyCount = 1;
|
||||
h.Tick();
|
||||
h.Slot(kit);
|
||||
h.Tick(100);
|
||||
Check(h.World.Sent.Count == 0 && h.World.HoldAsks == 0 && h.World.Releases == 0 && !h.Use.BotHeld,
|
||||
"no hold taken; a count that may be real still holds the press");
|
||||
}
|
||||
|
||||
// A report (10-29): after portalling in, four presses of a weapon slot in three seconds each said
|
||||
// "the client didn't take the request (nothing was sent)": the engine takes no game action until
|
||||
// 5 s after portal space ends. The press now waits for it.
|
||||
private static Harness OutOfPortal(params CarriedItem[] items)
|
||||
{
|
||||
Harness h = With(items);
|
||||
h.World.InWorld = false; // portal space
|
||||
h.Tick(100);
|
||||
h.World.InWorld = true; // out of it: the engine's gate holds game actions a while yet
|
||||
h.World.RefuseSends = true;
|
||||
h.Tick(100);
|
||||
return h;
|
||||
}
|
||||
|
||||
private static void UseAfterPortal()
|
||||
{
|
||||
ItemRef kit = ItemRef.From(Kit(0x10));
|
||||
Harness h = OutOfPortal(Kit(0x10));
|
||||
h.Slot(kit);
|
||||
h.Tick(50);
|
||||
Check(h.World.Sent.Count == 0 && h.Warned.Count == 0 && h.Use.HasPending, "refused just after the portal: it waits, no warning");
|
||||
Eq(h.Said.Count(s => s.Contains("waiting for the game to finish the portal")), 1, "says what it waits for");
|
||||
h.Ticks(8, 250);
|
||||
Check(h.Warned.Count == 0 && h.Use.HasPending, "2 s more of refusals: still waiting");
|
||||
Eq(h.Said.Count(s => s.Contains("waiting for the game")), 1, "said once");
|
||||
Eq(h.Logged.Count(l => l.Contains("doesn't take") && l.Contains("after the portal")), 1, "logged once");
|
||||
h.World.RefuseSends = false; // the engine's gate opens
|
||||
h.Tick(250);
|
||||
Eq(string.Join("|", h.World.Sent), "useon 10 me", "it goes the moment the client takes it");
|
||||
Check(h.Use.InFlight && h.Warned.Count == 0, "in flight, never a warning");
|
||||
|
||||
// A second press of the same slot while it waits doesn't queue twice.
|
||||
h = OutOfPortal(Kit(0x10));
|
||||
h.Slot(kit);
|
||||
h.Tick(50);
|
||||
Check(!h.Slot(kit), "the same press again: already waiting");
|
||||
|
||||
// The client never takes it: once the portal is 6 s behind, the refusal is said as before.
|
||||
h = OutOfPortal(Kit(0x10));
|
||||
h.Slot(kit);
|
||||
h.Ticks(24, 250);
|
||||
Check(!h.Use.HasPending && h.Warned.Count == 1 && h.Warned[0].Contains("didn't take the request"),
|
||||
"6 s after the portal it gives up and says so: " + string.Join("|", h.Warned));
|
||||
|
||||
// Long after a portal a refusal is said at once, as before.
|
||||
h = OutOfPortal(Kit(0x10));
|
||||
h.Tick(UseController.PortalRetryWindowMs);
|
||||
h.Slot(kit);
|
||||
h.Tick(50);
|
||||
Check(h.Warned.Count == 1 && h.Warned[0].Contains("didn't take the request") && !h.Use.HasPending, "well after the portal: said at once");
|
||||
|
||||
// A plugin loaded in the world saw no arrival: said at once.
|
||||
h = With(Kit(0x10));
|
||||
h.World.RefuseSends = true;
|
||||
h.Tick();
|
||||
h.Slot(kit);
|
||||
h.Tick(50);
|
||||
Check(h.Warned.Count == 1 && !h.Use.HasPending, "no portal seen: said at once");
|
||||
|
||||
// A spell slot: the cast waits the same way, after Magic mode.
|
||||
h = OutOfPortal();
|
||||
h.World.Known = new HashSet<uint> { 6 };
|
||||
h.World.CombatMode = Stance.Magic;
|
||||
Check(h.Use.Request(UseRequest.Cast(6, "Heal Self I", "slot", h.World.NowMs)), "a cast queued");
|
||||
h.Tick(50);
|
||||
h.Ticks(4, 250);
|
||||
Check(h.Use.InFlight && h.World.Sent.Count == 0 && h.Warned.Count == 0, "the cast is refused and waits");
|
||||
Eq(h.Said.Count(s => s.Contains("waiting for the game to finish the portal")), 1, "said once");
|
||||
h.World.RefuseSends = false;
|
||||
h.Tick(250);
|
||||
Eq(string.Join("|", h.World.Sent), "cast 6 me", "cast the moment the client takes it");
|
||||
}
|
||||
|
||||
private static void UseStaleBusy()
|
||||
{
|
||||
ItemRef kit = ItemRef.From(Kit(0x10));
|
||||
|
|
|
|||
Loading…
Reference in a new issue