Hold corpse opens and automatic world uses while the salvage panel is pending
A corpse use sent between the salvage UST use and the salvage execute is swallowed by the client, and the corpse loop then waits for an open that never comes. - SalvageManager.PanelPending: the UST was used and the execute is not sent yet (main cycle and the combine sweep). - Corpse open waits while it is true, with the claim's timeout clock stopped, and logs the wait once. - UseAudit.WorldUseHold: automatic door/corpse uses are held (logged HELD, return false) while RynthAi says so; uses the player asks for are never held. Cleared by Reset; RynthAi wires it at init and clears it at shutdown. - Test: LootPacingTests (panel pending 20 s: no corpse use, claim kept, auto world use held; after the execute the corpse opens). Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
bef9b2b1a3
commit
316527227f
7 changed files with 232 additions and 0 deletions
|
|
@ -695,6 +695,20 @@ public sealed partial class RynthAiPlugin
|
|||
FreezeCorpseTimeout(now);
|
||||
return;
|
||||
}
|
||||
// The salvage panel is opening (UST used, execute not sent yet): the client would swallow
|
||||
// the use (SalvageManager.PanelPending). Wait, with the claim's timeout clock stopped (this
|
||||
// sits before the freeze reset below so the frozen age carries across held ticks).
|
||||
if (_salvageManager?.PanelPending == true)
|
||||
{
|
||||
FreezeCorpseTimeout(now);
|
||||
if (!_openHeldBySalvageLogged)
|
||||
{
|
||||
_openHeldBySalvageLogged = true;
|
||||
LootDiag($"[RynthAi] Corpse loot: open of 0x{(uint)_targetCorpseId:X8} waits for the salvage panel (UST used, salvage not sent yet).");
|
||||
}
|
||||
return;
|
||||
}
|
||||
_openHeldBySalvageLogged = false;
|
||||
_corpseHoldFrozenAge = -1;
|
||||
|
||||
// One server action at a time (2026-10-06, ActionPacer): no open while the server is still
|
||||
|
|
@ -761,6 +775,7 @@ public sealed partial class RynthAiPlugin
|
|||
}
|
||||
|
||||
private long _corpseOpenBusyWaitSince;
|
||||
private bool _openHeldBySalvageLogged;
|
||||
|
||||
// Peace before the open: one request per claimed corpse, only with no monster within
|
||||
// LootStarveCloseYards (the same test that gives looting its turn while combat still has a
|
||||
|
|
|
|||
|
|
@ -196,6 +196,18 @@ public sealed class SalvageManager
|
|||
/// <summary>Returns true while a salvage operation is in flight.</summary>
|
||||
public bool IsBusy => _phase != Phase.Idle || _queue.Count > 0;
|
||||
|
||||
/// <summary>
|
||||
/// True from the UST use until the salvage execute has gone out (a batch or a bag combine).
|
||||
/// Meanwhile the client swallows a door or corpse use: no Use packet, no busy count, and the
|
||||
/// open waited out its 5 s limit (in one log, 6 of 6 corpse opens sent 0-155 ms after the UST
|
||||
/// use were lost; 4 of 4 sent after the execute were answered). Narrower than IsBusy, which
|
||||
/// also covers a queued batch whose panel isn't open yet.
|
||||
/// </summary>
|
||||
public bool PanelPending =>
|
||||
_phase is Phase.OpeningPanel or Phase.AddingItems or Phase.ReadyToExecute
|
||||
|| (_phase == Phase.CombiningSalvage
|
||||
&& _combinePhase is CombinePhase.OpeningPanel or CombinePhase.AddingBags or CombinePhase.Salvaging);
|
||||
|
||||
/// <summary>
|
||||
/// Looting sent the pickup of an item whose rule says Salvage. Tracks it without queueing:
|
||||
/// the sweep queues it once it is in the pack, even if the pickup confirm never comes.
|
||||
|
|
|
|||
|
|
@ -13,6 +13,14 @@ namespace RynthCore.Plugin.RynthAi;
|
|||
// ============================================================================
|
||||
public sealed partial class RynthAiPlugin
|
||||
{
|
||||
/// <summary>
|
||||
/// UseAudit.WorldUseHold: an automatic door or corpse use waits while the salvage panel is
|
||||
/// between the Ust use and the salvage send. A world use in that window is swallowed by the
|
||||
/// client, and the corpse loop then sat waiting for an open that never came.
|
||||
/// </summary>
|
||||
private string? SalvagePanelHold() =>
|
||||
_salvageManager?.PanelPending == true ? "the salvage panel is opening; the use waits for the salvage to go out" : null;
|
||||
|
||||
/// <summary>UseAudit.AfterSend: a use or use-on went out - record it as the action the server is answering.</summary>
|
||||
private static void RecordUseForPacing(RynthCoreHost host, UseAudit.SentUse use)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -186,6 +186,7 @@ public sealed partial class RynthAiPlugin : RynthPluginBase
|
|||
RynthCore.Plugin.Shared.ActionPacer.Reset();
|
||||
RynthCore.Plugin.Shared.ActionPacer.Enabled = true;
|
||||
RynthCore.Plugin.Shared.UseAudit.AfterSend = RecordUseForPacing;
|
||||
RynthCore.Plugin.Shared.UseAudit.WorldUseHold = SalvagePanelHold;
|
||||
_objectCache = new WorldObjectCache(Host); // must exist before CreateObject events fire during login
|
||||
// Items we use (or use something on) get re-identified before a meta reads them.
|
||||
// ObjectUsed is a static event and Shutdown never unsubscribes: when the engine
|
||||
|
|
@ -234,6 +235,7 @@ public sealed partial class RynthAiPlugin : RynthPluginBase
|
|||
// Don't let the static audit hold this instance once it's gone (a reused module).
|
||||
RynthCore.Plugin.Shared.UseAudit.MacroOn = static () => false;
|
||||
RynthCore.Plugin.Shared.UseAudit.AfterSend = null;
|
||||
RynthCore.Plugin.Shared.UseAudit.WorldUseHold = null;
|
||||
RynthCore.Plugin.Shared.ActionPacer.Enabled = false;
|
||||
RynthCore.Plugin.Shared.ActionPacer.Forget("shutdown");
|
||||
|
||||
|
|
|
|||
|
|
@ -84,6 +84,7 @@ internal static class UseAudit
|
|||
_worldUseSentMs = 0;
|
||||
_worldUseSeqAtSend = 0;
|
||||
AfterSend = null;
|
||||
WorldUseHold = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -96,6 +97,16 @@ internal static class UseAudit
|
|||
Write(host, objectId, subsystem, $"BLOCKED 0x{objectId:X8} {what} macro=off auto - {why} (with the macro off nothing opens a door or corpse unless you ask)", force: true);
|
||||
return false;
|
||||
}
|
||||
if (kind == UseKind.Auto && doorOrCorpse)
|
||||
{
|
||||
string? hold = null;
|
||||
try { hold = WorldUseHold?.Invoke(); } catch { hold = null; }
|
||||
if (!string.IsNullOrEmpty(hold))
|
||||
{
|
||||
Write(host, objectId, subsystem, $"HELD 0x{objectId:X8} {what} auto - {why} ({hold})", force: false);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
Write(host, objectId, subsystem, $"0x{objectId:X8} {what} macro={MacroText} {KindText(kind)} - {why}", force: false);
|
||||
int seqBefore = 0;
|
||||
bool track = TrackWorldUses && doorOrCorpse;
|
||||
|
|
@ -124,6 +135,13 @@ internal static class UseAudit
|
|||
/// </summary>
|
||||
public static Action<RynthCoreHost, SentUse>? AfterSend;
|
||||
|
||||
/// <summary>
|
||||
/// Asked before an automatic door or corpse use: a reason to hold it back (nothing is sent, the
|
||||
/// call returns false), or null/empty to send. RynthAi holds them while the salvage panel opens
|
||||
/// (the client swallows the use then). A use the player asked for is never held. Cleared by Reset.
|
||||
/// </summary>
|
||||
public static Func<string?>? WorldUseHold;
|
||||
|
||||
// ── A door or corpse use the server hasn't answered yet (2026-10-06) ──────────
|
||||
// The server walks/turns the character to a used door or corpse, and any movement packet
|
||||
// from the client cancels that (ACE: a MoveToState stops the move-to chain, and a combat
|
||||
|
|
|
|||
|
|
@ -99,6 +99,7 @@ internal static class Program
|
|||
CastNoDamageTests.Register(runner);
|
||||
ManaReserveTests.Register(runner);
|
||||
DamageRowsTests.Register(runner);
|
||||
LootPacingTests.Register(runner);
|
||||
return runner.Run("RynthAi host tests", args.Length > 0 ? args[0] : null);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
176
Tools/RynthCore.RynthAiHostTests/Tests/LootPacingTests.cs
Normal file
176
Tools/RynthCore.RynthAiHostTests/Tests/LootPacingTests.cs
Normal file
|
|
@ -0,0 +1,176 @@
|
|||
using System;
|
||||
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.Plugin.RynthAi.Loot;
|
||||
using RynthCore.Plugin.Shared;
|
||||
using RynthCore.PluginCore;
|
||||
using RynthCore.PluginSdk;
|
||||
using RynthCore.RynthAiHostTests.Fakes;
|
||||
using RynthCore.RynthAiTests.Harness;
|
||||
|
||||
namespace RynthCore.RynthAiHostTests.Tests;
|
||||
|
||||
// Loot findings:
|
||||
// H. A corpse use sent between the salvage UST use and the salvage execute is swallowed by the
|
||||
// client (the salvage panel open wins), and the corpse loop then waits for an open that never
|
||||
// comes. Corpse opens (and every automatic door/corpse use, via UseAudit.WorldUseHold) wait
|
||||
// while the salvage panel is pending; the corpse claim's timeout is not charged meanwhile.
|
||||
internal static class LootPacingTests
|
||||
{
|
||||
private const uint Player = 0x50000E01;
|
||||
private const uint CorpseA = 0x80069ACE;
|
||||
private const uint CorpseB = 0x80073023;
|
||||
private const uint Ust = 0x80000E11;
|
||||
private const uint Junk = 0x80000E12;
|
||||
private const uint UstWcid = 20646;
|
||||
private const uint ItemTypeContainer = 0x200, ItemTypeArmor = 0x2;
|
||||
private const uint LongDescKey = 16;
|
||||
private const string Me = "Drakkon";
|
||||
private const BindingFlags Any = BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public;
|
||||
private static (uint Cell, float X, float Y, float Z) Me0 => (0x6347028Au, 100f, 100f, 0f);
|
||||
|
||||
public static void Register(Runner r)
|
||||
{
|
||||
r.Add("salvage/loot: no corpse open (or auto door/corpse use) while the salvage panel is pending; the claim is kept and opened after the execute", CorpseOpenWaitsForSalvagePanel);
|
||||
}
|
||||
|
||||
private static void World()
|
||||
{
|
||||
FakeHost.Reset();
|
||||
FakeHost.SalvageCalls = true; // UseObject + MoveItemExternal + salvage panel
|
||||
FakeHost.WeaponCalls = true;
|
||||
FakeHost.ServerGates = true;
|
||||
FakeHost.LastUseDoneCalls = true;
|
||||
FakeHost.StopCalls = true;
|
||||
FakeHost.Names[Player] = Me;
|
||||
FakeHost.Positions[Player] = Me0;
|
||||
FakeHost.PlayerPose = Me0;
|
||||
foreach ((uint id, float dx) in new[] { (CorpseA, 1.0f), (CorpseB, 1.5f) })
|
||||
{
|
||||
FakeHost.Names[id] = "Corpse of Olthoi Swarm Worker";
|
||||
FakeHost.ItemTypes[id] = ItemTypeContainer;
|
||||
FakeHost.Strings[(id, LongDescKey)] = $"Killed by {Me}.";
|
||||
FakeHost.NotAttackable.Add(id);
|
||||
FakeHost.Positions[id] = (Me0.Cell, Me0.X + dx, Me0.Y, Me0.Z);
|
||||
}
|
||||
FakeHost.Names[Ust] = "Salvaging Ust";
|
||||
FakeHost.Wcids[Ust] = UstWcid;
|
||||
FakeHost.Names[Junk] = "Iron Breastplate";
|
||||
FakeHost.ItemTypes[Junk] = ItemTypeArmor;
|
||||
FakeHost.Ints[(Junk, 131)] = 64; // MaterialType
|
||||
}
|
||||
|
||||
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,
|
||||
EnableCombineSalvage = false,
|
||||
SalvageOpenDelayFirstMs = 400, SalvageOpenDelayFastMs = 50,
|
||||
SalvageAddDelayFirstMs = 600, SalvageAddDelayFastMs = 50,
|
||||
SalvageSalvageDelayMs = 50,
|
||||
SalvageResultDelayFirstMs = 1000, SalvageResultDelayFastMs = 250,
|
||||
};
|
||||
public readonly WorldObjectCache Cache;
|
||||
|
||||
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);
|
||||
Cache.OnCreateObject(CorpseA);
|
||||
Cache.OnCreateObject(CorpseB);
|
||||
_ = Cache[unchecked((int)Ust)]; // filed as the indexer does (FakeHost.MakeCache)
|
||||
_ = Cache[unchecked((int)Junk)];
|
||||
Cache.Tick();
|
||||
|
||||
string profile = Path.Combine(Program.TempRoot, "loot-pacing-test.json");
|
||||
var p = new LootProfile { Name = "nothing" };
|
||||
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);
|
||||
public void Tick()
|
||||
{
|
||||
Set("_activity", BotActivity.Looting);
|
||||
Call("TickCorpseOpening");
|
||||
}
|
||||
}
|
||||
|
||||
private static int CorpseUses() => FakeHost.Uses.Count(u => u == CorpseA || u == CorpseB);
|
||||
|
||||
private static void CorpseOpenWaitsForSalvagePanel()
|
||||
{
|
||||
World();
|
||||
var host = FakeHost.Create(Player);
|
||||
var bot = new Bot(host);
|
||||
long now = 60_000_000;
|
||||
var savedClock = RynthAiPlugin.CorpseClock;
|
||||
RynthAiPlugin.CorpseClock = () => now;
|
||||
try
|
||||
{
|
||||
UseAudit.Reset("RynthAi", () => true);
|
||||
// As RynthAiPlugin's init wires it.
|
||||
UseAudit.WorldUseHold = (Func<string?>)Delegate.CreateDelegate(typeof(Func<string?>), bot.P,
|
||||
typeof(RynthAiPlugin).GetMethod("SalvagePanelHold", Any)!);
|
||||
|
||||
var mgr = new SalvageManager(host, bot.S, bot.Cache) { Clock = () => now };
|
||||
bot.Set("_salvageManager", mgr);
|
||||
FakeHost.OnSalvageExecute = added =>
|
||||
{
|
||||
foreach (uint id in added) { FakeHost.Names.Remove(id); bot.Cache.OnDeleteObject(id); }
|
||||
};
|
||||
mgr.EnqueueItem(Junk);
|
||||
|
||||
// The salvage cycle starts: UST used, panel not executed yet.
|
||||
for (int i = 0; i < 200 && !FakeHost.Uses.Contains(Ust); i++) { now += 50; mgr.OnTick(0); }
|
||||
Check.True(FakeHost.Uses.Contains(Ust), "the UST is used");
|
||||
FakeHost.UseDone(0); // the server answers the UST use (the panel opens)
|
||||
Check.True(mgr.PanelPending, "the salvage panel is pending (UST used, no execute yet)");
|
||||
|
||||
// 20 s with the panel pending (longer than the 12 s claim timeout): looting ticks on.
|
||||
for (int i = 0; i < 200; i++) { bot.Tick(); now += 100; }
|
||||
Check.Eq(CorpseUses(), 0, "no corpse use while the salvage panel is pending");
|
||||
Check.Eq(bot.Get<int>("_targetCorpseId"), unchecked((int)CorpseA), "the claim is kept, not abandoned on timeout");
|
||||
Check.Eq(FakeHost.Logs.Count(l => l.Contains("waits for the salvage panel")), 1, "the wait is logged once");
|
||||
|
||||
// Any other automatic door/corpse use is held too (nav doors, the use check's probes).
|
||||
Check.False(host.UseFor(CorpseB, "Nav", "test: an automatic world use"), "an automatic world use is held");
|
||||
Check.Eq(CorpseUses(), 0, "and not sent");
|
||||
Check.True(FakeHost.Logs.Any(l => l.Contains("HELD 0x80073023")), "the hold is logged");
|
||||
|
||||
// The panel executes; the corpse opens on the next looting tick.
|
||||
for (int i = 0; i < 200 && FakeHost.SalvageExecutes.Count == 0; i++) { now += 50; mgr.OnTick(0); }
|
||||
Check.Eq(FakeHost.SalvageExecutes.Count, 1, "the salvage goes out");
|
||||
Check.False(mgr.PanelPending, "the panel is no longer pending once the execute is sent");
|
||||
for (int i = 0; i < 5 && CorpseUses() == 0; i++) { bot.Tick(); now += 100; }
|
||||
Check.Eq(CorpseUses(), 1, "the corpse is opened after the execute");
|
||||
Check.True(FakeHost.Uses.Contains(CorpseA), "the claimed corpse");
|
||||
}
|
||||
finally
|
||||
{
|
||||
RynthAiPlugin.CorpseClock = savedClock;
|
||||
UseAudit.Reset("?", null);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue