RynthSuite as of 2026-11-30 (internal 805a055): release 2026.11.30.1

This commit is contained in:
Tom Bohar 2026-11-30 15:26:56 -05:00
commit e8e4228d15
19 changed files with 983 additions and 315 deletions

View file

@ -199,6 +199,7 @@ internal static class Program
DamageRowsTests.Register(runner);
ShieldFacingTests.Register(runner);
NavMapEditTests.Register(runner);
NavPanelTests.Register(runner);
LootSpeedTests.Register(runner);
MeleeStallTests.Register(runner);
NativeAttackTests.Register(runner);

View file

@ -58,7 +58,7 @@ internal static class ItemToolTests
// Plugin glue
r.Add("item tool: the chest looter picks the selected chest and key, unlocks, opens and loots with the macro off, stops when out of keys", PluginChestRun);
r.Add("item tool: chest/key picks refuse the wrong things (a pack item as chest, a world object as key, house storage)", PluginChestPicks);
r.Add("item tool: a full main pack holds no key while a side pack has room (the looter makes room); every pack full or under the 2-slot reserve holds it (2026-11-28)", PluginNoRoomOnlyWhenAllFull);
r.Add("item tool: a full main pack holds no key while a side pack has room (loot goes straight into it, 2026-11-30); every pack full, the 2-slot reserve, or no raw move holds it (2026-11-28)", PluginNoRoomOnlyWhenAllFull);
r.Add("item tool: Quick give hands over exactly the picked item to the picked NPC, never worn gear or other names", PluginQuickGive);
r.Add("item tool: Quick give starts only from the panel or a typed line, never from a meta, a script or a remote line; stop works from anywhere", PluginGiveTrust);
r.Add("item tool: Quick give targets are players or NPCs only", PluginGiveTargets);
@ -1178,9 +1178,10 @@ internal static class ItemToolTests
private const uint SidePack = 0x80290200, JunkBase = 0x80291000, SideJunkBase = 0x80292000;
/// <summary>The chest looter's room check with the main pack full and <paramref name="sideUsed"/> of a 24-slot side pack's slots used.</summary>
private static string? NoRoomWithFullMain(int sideUsed, bool mainFull = true)
private static string? NoRoomWithFullMain(int sideUsed, bool mainFull = true, bool rawMove = true)
{
BaseWorld();
FakeHost.PutCalls = rawMove; // the raw 0x19 packet the looter puts side-pack loot through (v80)
FakeHost.Names[SidePack] = "Backpack";
FakeHost.ItemTypes[SidePack] = 0x200;
FakeHost.Ints[(SidePack, 6u)] = 24; // ItemsCapacity
@ -1206,11 +1207,13 @@ internal static class ItemToolTests
}
// 2026-11-28: looting stopped with a full main pack although the side packs had room; it should
// fill the side packs (the looter makes room since e026c97c).
// fill the side packs (since 2026-11-30 the looter puts the loot straight into a side pack by the raw packet).
private static void PluginNoRoomOnlyWhenAllFull()
{
Check.Eq(NoRoomWithFullMain(0, mainFull: false), null, "room in the main pack: keys go");
Check.Eq(NoRoomWithFullMain(0), null, "main pack full, an empty side pack: keys go (the looter moves one item to the side pack, then picks up)");
Check.Eq(NoRoomWithFullMain(0), null, "main pack full, an empty side pack: keys go (the loot goes straight into the side pack)");
string? old = NoRoomWithFullMain(0, rawMove: false);
Check.True(old != null && old.Contains("the main pack is full"), "main pack full on an engine with no raw move: held, nothing could take the loot: " + old);
Check.Eq(NoRoomWithFullMain(22), null, "2 side slots left: still goes");
string? one = NoRoomWithFullMain(23);
Check.True(one != null && one.Contains("1 free slot(s) left in all your packs"), "1 slot left in all: held (looting keeps 2 for weapon swaps): " + one);

View file

@ -71,7 +71,7 @@ internal static class LootCorpseTests
r.Add("corpse close: an abandoned open corpse is closed once", AbandonedCorpseClosed);
r.Add("corpse close: stopping the macro mid-loot closes the open corpse, not marked completed", MacroStopClosesCorpse);
r.Add("loot pacing: a pickup waits for the last bend-down, and no retry is timed while it plays", PickupWaitsForAnimation);
r.Add("loot: the main pack, the only place loot can go, takes none of an item's tries: judged full, the item given up, and one item's mark goes with it", RefusingPackIsLeftOut);
r.Add("loot: the main pack, the only place loot can go on an engine with no raw move, takes none of an item's tries: judged full, the item given up, and one item's mark goes with it", RefusingPackIsLeftOut);
r.Add("loot pacing: no pickup (first or retry) while the server owes an answer to a cast; it goes on the UseDone", PickupWaitsForCastAnswer);
r.Add("corpse close: not while the last item is between the corpse and the pack - it closes once the item is in the inventory", CloseWaitsForInventory);
r.Add("loot pacing: an item merged into a stack in the pack is confirmed without the 4 s arrival wait", MergedPickupConfirmedQuickly);

View file

@ -43,8 +43,10 @@ internal static class LootRetryTimingTests
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); a second item refused there keeps it marked full; nothing goes to a side pack", FullMainPackRefusals);
r.Add("loot retry (R-20261029-122319-321f): unanswered moves are retried only after the answer wait, three tries, then given up (no side-pack round); their pack marks end with the item, the next item starts fresh", UnansweredMovesDontPoison);
r.Add("loot pickup, main pack full (2026-11-12 'You must first pick up the Silver Pea'): a pea joins the stack you carry, a gem is left at once with one chat line, nothing is aimed at a side pack, the corpse completes", FullMainPackPeaJoinsGemLeft);
r.Add("loot pickup, main pack full, a side pack with room (2026-11-28): one main-pack item moves to the side pack per pickup (loot it brought in first), the pickup waits for that move's answer, every gem lands in the main pack, nothing is left", FullMainPackMakesRoom);
r.Add("loot pickup, main pack full, an engine with no raw move (2026-11-12 'You must first pick up the Silver Pea'): the gem and a pea with a stack to join are left at once with one chat line, nothing is sent, the corpse completes", FullMainPackPeaJoinsGemLeft);
r.Add("loot pickup, main pack full, a side pack with room (2026-11-30: loot into side packs): every gem goes straight into the side pack by the raw packet, no room moves, the client drops nothing, nothing is left", FullMainPackLootsIntoSidePack);
r.Add("loot pickup, main pack full (2026-11-30 Heartstones): a stacking item with a carried stack to join goes to the side pack too, not to the full main pack; it lands", FullMainPackStackGoesToSidePack);
r.Add("loot pickup, main pack full (2026-11-30 03:22): with no timed re-walk of the inventory, the gem after the one that took the last main-pack slot sees it full and goes to the side pack (a landed pickup marks the list stale)", FullMainPackQuickPickupsSeeTheLastLanding);
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);
@ -202,6 +204,17 @@ internal static class LootRetryTimingTests
public int QuestRefusals, Unlocks;
public long ClientPendingTimeoutMs = 10_000;
public int TooBusy, LocalRefused, Queued, RoomRefusals;
/// <summary>
/// The client's own checks on its own move (MoveItemExternal), which nothing passes on the wire:
/// a corpse item aimed at a side pack ("You must first pick up the X", 2026-11-12;
/// <see cref="SidePackDropped"/>), and a pickup aimed at the main pack while 102 loose items are
/// in it, a stackable one with a carried stack to join included (2026-11-30, DreamWeave
/// 'Obsidian Heartstone's; <see cref="MainPackDropped"/>). No answer comes to either. The raw
/// 0x19 packet (PutItemInContainer, <see cref="FakeHost.Puts"/>) skips these checks and the
/// client's one-request slot: it goes straight to the server.
/// </summary>
public bool ClientChecks;
public int MainPackDropped, SidePackDropped;
public readonly List<(uint Id, uint Pack, long At)> Landed = new();
/// <summary>Pack-to-pack moves (MoveItemInternal) the server carried out: they take the client's one pending request too.</summary>
public readonly List<(uint Id, uint Pack, long At)> PackMoves = new();
@ -210,7 +223,9 @@ internal static class LootRetryTimingTests
private enum St { Idle, Pickup, Return }
private St _st;
private (uint Id, uint Pack) _next;
private int _seenMoves;
private int _seenMoves, _seenPuts;
/// <summary>Raw PutItemInContainer packets that reached the server.</summary>
public int RawPuts;
private uint _clientPending;
private long _clientPendingAt;
private int _seenCommands;
@ -228,6 +243,8 @@ internal static class LootRetryTimingTests
var m = FakeHost.ExternalMoves[_seenMoves++];
if (Attacking) { AttackRefused++; continue; } // "You cannot move or use an item while attacking"
if (LoseFirst.Remove(m.Id)) { Lost++; continue; } // never left the client
if (ClientChecks && m.Target != Player) { SidePackDropped++; continue; }
if (ClientChecks && m.Target == Player && ClientMainPackLoose() >= 102) { MainPackDropped++; continue; }
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;
@ -237,6 +254,17 @@ internal static class LootRetryTimingTests
if (Lag.Remove(m.Id, out long lag)) arrive += lag;
At(arrive, () => Receive(m.Id, m.Target, arrive));
}
while (_seenPuts < FakeHost.Puts.Count)
{
// The raw packet: no client check, no pending slot; the server takes it as any pickup.
var p = FakeHost.Puts[_seenPuts++];
if (Attacking) { AttackRefused++; continue; }
if (NeverAnswer.Contains(p.Id)) continue;
long arrive = now - TickMs + Rtt / 2;
if (Lag.Remove(p.Id, out long lag)) arrive += lag;
RawPuts++;
At(arrive, () => Receive(p.Id, p.Container, arrive));
}
while (_seenPackMoves < FakeHost.Moves.Count)
{
var m = FakeHost.Moves[_seenPackMoves++];
@ -267,6 +295,10 @@ internal static class LootRetryTimingTests
private void Answered(uint id) { if (_clientPending == id) _clientPending = 0; }
private static int ClientMainPackLoose() =>
FakeHost.Containers.Count(kv => kv.Value == Player
&& !(FakeHost.ItemTypes.TryGetValue(kv.Key, out uint t) && t == ItemTypeContainer));
private void Receive(uint id, uint pack, long ts)
{
if (_st == St.Idle) { StartPickup(id, pack, ts); return; }
@ -461,12 +493,33 @@ internal static class LootRetryTimingTests
Check.False(Logged("no pack has a free slot"), "looting does not stop for want of a pack");
});
// ── 3b. The main pack is full by the client's own count ───────────────────
// 2026-11-12, Drakkon on DreamWeave (and R-20261112-110130-5d71): the main pack filled at 07:35,
// the looter aimed every pickup at a side pack, the client refused each one ("You must first
// pick up the Silver Pea", nothing sent), and each item waited out 3 + 3 unanswered tries and
// was left: 48 peas and maps in two hours, the bot stuck on one corpse after another.
// ── 3. A full main pack (2026-11-12, 2026-11-28, 2026-11-30) ──────────────
// 2026-11-12 (R-20261112-110130-5d71, DreamWeave): with the main pack full the looter aimed each
// pickup at a side pack through the client's own move; the client refused every one ("You must first
// pick up the Silver Pea", nothing sent), and each item waited out 3 + 3 tries and was left. Then
// loot went only to the main pack, so with it full everything was left (11-28: "it should continue
// looting and fill the side packs"); a room move (one main-pack item to a side pack, then the pickup)
// followed, and on 2026-11-30 it still lost every stacking 'Obsidian Heartstone' and, on quick
// pickups, a second keep on a corpse. A room move was never the way: loot should go into the side
// packs. Now a side pack gets the raw 0x19 packet, which skips the client's
// check, and the server takes it as any pickup into that pack. No room moves.
private static List<uint> FullMainPack(uint junkBase)
{
var ids = new List<uint>();
for (uint i = 0; i < 102; i++)
{
uint j = junkBase + i;
FakeHost.Names[j] = $"Junk {i}";
FakeHost.ItemTypes[j] = 0x80;
FakeHost.Containers[j] = Player;
ids.Add(j);
}
return ids;
}
// 3a. An engine without the raw packet (plugin API before v80): with the main pack full nothing can
// take the loot, so it is left at once (a pea with a stack to join too), one chat line says so.
private static void FullMainPackPeaJoinsGemLeft() => Clocked(() =>
{
const uint Gem = 0x80263171, Pea = 0x80263172, PeaStack = 0x80263173, JunkBase = 0x80264000;
@ -480,26 +533,16 @@ internal static class LootRetryTimingTests
FakeHost.Ints[(PeaStack, 12)] = 40;
FakeHost.Containers[PeaStack] = SidePack;
var ids = new List<uint> { Gem, Pea, PeaStack };
for (uint i = 0; i < 102; i++) // a full main pack
{
uint j = JunkBase + i;
FakeHost.Names[j] = $"Junk {i}";
FakeHost.ItemTypes[j] = 0x80;
FakeHost.Containers[j] = Player;
ids.Add(j);
}
var sim = new SlowAce();
ids.AddRange(FullMainPack(JunkBase));
var sim = new SlowAce { ClientChecks = true };
var bot = Open(sim, sidePack: true, ids.ToArray());
long started = _now;
Run(bot, () => bot.Completed, 60_000);
Check.True(FakeHost.ExternalMoves.All(m => m.Target != SidePack), "no pickup is aimed at the side pack (the client would refuse it)");
Check.Eq(FakeHost.ExternalMoves.Count(m => m.Id == Gem), 0, "the gem is not sent at all: the main pack has no slot and it joins no stack");
Check.True(Logged("leaving 'Gem 113' 0x80263171") && Logged("the main pack is full"), "the gem is left, and the log says why");
Check.Eq(FakeHost.ExternalMoves.Count(m => m.Id == Pea), 1, "the pea is sent once");
Check.True(FakeHost.ExternalMoves.Where(m => m.Id == Pea).All(m => m.Target == Player), "aimed at the main pack: the client joins it to your stack");
Check.True(sim.Landed.Any(l => l.Id == Pea), "and it lands");
Check.Eq(FakeHost.ExternalMoves.Count, 0, "nothing is sent: the client would drop it into the side pack or the full main pack");
Check.True(Logged("leaving 'Gem 113' 0x80263171") && Logged("no raw move"), "the gem is left, and the log says why");
Check.True(Logged("leaving 'Silver Pea' 0x80263172"), "the pea is left at once too");
Check.Eq(FakeHost.Chat.Count(c => c.Contains("Main pack full")), 1, "one chat line says the main pack is full and loot is left");
Check.False(Logged("pickup failed"), "nothing is waited out and given up");
Check.False(Logged("no pack has a free slot"), "and looting doesn't stop: the side pack has room");
@ -507,55 +550,108 @@ internal static class LootRetryTimingTests
Check.True(_now - started < 10_000, $"quickly ({_now - started} ms), not after 3 + 3 tries per item");
});
// ── 3c. A full main pack, room in a side pack (2026-11-28) ────────────────
// "Why does Rynth stop looting when the main pack is full? It should continue looting and fill the
// side packs." Since 3b every item that joined no stack was left once the main pack was full, side
// packs empty or not. Now the looter first moves one loose item from the main pack to the side pack
// (a pack-to-pack move, which the client sends), waits for its answer (the client refuses a pickup
// while it is out), then picks the item up into the freed slot. 3b runs with no inventory manager,
// so it still shows what happens when no room move can be made.
private static void FullMainPackMakesRoom() => Clocked(() =>
// 3b. The raw packet: with the main pack full every gem goes straight into the side pack.
private static void FullMainPackLootsIntoSidePack() => Clocked(() =>
{
const uint G1 = 0x80263181, G2 = 0x80263182, G3 = 0x80263183, JunkBase = 0x80264100;
World(sidePack: true, G1, G2, G3);
FakeHost.PutCalls = true;
var ids = new List<uint> { G1, G2, G3 };
for (uint i = 0; i < 102; i++) // a full main pack
{
uint j = JunkBase + i;
FakeHost.Names[j] = $"Junk {i}";
FakeHost.ItemTypes[j] = 0x80;
FakeHost.Containers[j] = Player;
ids.Add(j);
}
ids.AddRange(FullMainPack(JunkBase));
var sim = new SlowAce { ClientChecks = true };
sim.Room[Player] = 0; // the server's main pack is full too
var bot = Open(sim, sidePack: true, ids.ToArray());
bot.Set("_inventoryManager", new RynthCore.Plugin.RynthAi.Loot.InventoryManager(bot.Host, bot.S, bot.Cache));
long started = _now;
Run(bot, () => bot.Completed, 60_000);
foreach (uint g in new[] { G1, G2, G3 })
Check.True(sim.Landed.Any(l => l.Id == g && l.Pack == SidePack), $"0x{g:X8} is looted into the side pack");
Check.Eq(FakeHost.Puts.Count, 3, "one raw pickup per gem");
Check.True(FakeHost.Puts.All(p => p.Container == SidePack), "each aimed at the side pack");
Check.Eq(FakeHost.ExternalMoves.Count, 0, "nothing goes through the client's own move (it would drop them)");
Check.Eq(FakeHost.Moves.Count, 0, "no room moves: nothing in the main pack is touched");
Check.Eq(sim.SidePackDropped + sim.MainPackDropped, 0, "the client drops nothing");
Check.Eq(sim.RoomRefusals, 0, "and the server refuses none for room");
Check.False(Logged("leaving 'Gem"), "nothing is left on the corpse");
Check.Eq(FakeHost.Chat.Count(c => c.Contains("Main pack full")), 0, "no main-pack-full chat line");
Check.True(Logged("into pack 0x80263001"), "the log names the side pack");
Check.False(Logged("pickup failed"), "nothing is waited out and given up");
Check.True(bot.Completed, "the corpse completes");
Check.True(_now - started < 20_000, $"in good time ({_now - started} ms)");
});
// 3c. DreamWeave, 2026-11-30 03:27 to 05:02: every 'Obsidian Heartstone' (a stacking custom weenie)
// was left once the main pack was full: a Heartstone stack with room was carried, so the pickup went
// to the full main pack ("a stack joins anywhere", 3d76e08d, never seen in a client) and the client
// dropped each one, 3 unanswered tries of 4 s, then left. One corpse was opened 13 times in 90 s.
private static void FullMainPackStackGoesToSidePack() => Clocked(() =>
{
const uint Stone = 0x80263191, StoneStack = 0x80263192, JunkBase = 0x80264200;
World(sidePack: true, Stone);
FakeHost.PutCalls = true;
FakeHost.Names[Stone] = "Obsidian Heartstone";
FakeHost.Ints[(Stone, 11)] = 100; // MaxStackSize
FakeHost.Ints[(Stone, 12)] = 1; // StackCount
FakeHost.Names[StoneStack] = "Obsidian Heartstone"; // the stack you carry, in the side pack
FakeHost.ItemTypes[StoneStack] = ItemTypeGem;
FakeHost.Ints[(StoneStack, 11)] = 100;
FakeHost.Ints[(StoneStack, 12)] = 40;
FakeHost.Containers[StoneStack] = SidePack;
var ids = new List<uint> { Stone, StoneStack };
ids.AddRange(FullMainPack(JunkBase));
var sim = new SlowAce { ClientChecks = true };
sim.Room[Player] = 0;
var bot = Open(sim, sidePack: true, ids.ToArray());
long started = _now;
Run(bot, () => bot.Completed, 60_000);
Check.Eq(FakeHost.ExternalMoves.Count, 0, "no pickup is aimed at the full main pack (the client would drop it)");
Check.True(FakeHost.Puts.Any(p => p.Id == Stone && p.Container == SidePack), "the Heartstone goes to the side pack by the raw packet");
Check.True(sim.Landed.Any(l => l.Id == Stone && l.Pack == SidePack), "and is looted");
Check.Eq(sim.SidePackDropped + sim.MainPackDropped, 0, "the client drops nothing");
Check.False(Logged("pickup failed"), "nothing is waited out and given up");
Check.False(Logged("leaving 'Obsidian Heartstone'"), "nothing is left");
Check.True(bot.Completed, "the corpse completes");
Check.True(_now - started < 10_000, $"quickly ({_now - started} ms), not after 3 tries of 4 s");
});
// 3d. DreamWeave, 2026-11-30 03:22:01: right after a quick pickup (jump-loot, 203 ms, no bend-down)
// the next item's check read an inventory list from before that pickup landed (reused for up to 1 s)
// and saw a free main-pack slot that was gone. Here the main pack has one slot: the first gem takes
// it, and with no timed re-walk of the inventory the next two must still see it full and go to the
// side pack (a landed pickup marks the list stale, WorldObjectCache.ExpireDirectInventory).
private static void FullMainPackQuickPickupsSeeTheLastLanding() => Clocked(() =>
{
const uint G1 = 0x802631A1, G2 = 0x802631A2, G3 = 0x802631A3, JunkBase = 0x80264300;
World(sidePack: true, G1, G2, G3);
FakeHost.PutCalls = true;
FakeHost.ContentsCalls = true; // the client's container walk, as live (the list is reused between walks)
var ids = new List<uint> { G1, G2, G3 };
ids.AddRange(FullMainPack(JunkBase));
FakeHost.Containers.Remove(JunkBase + 101); // one free main-pack slot
ids.Remove(JunkBase + 101);
var oldClock = RynthClock.TestNow;
var t0 = new DateTime(2026, 11, 28, 12, 0, 0);
var t0 = new DateTime(2026, 11, 30, 3, 22, 0);
RynthClock.TestNow = () => t0.AddMilliseconds(_now);
try
{
var sim = new SlowAce();
sim.Room[Player] = 0; // the server's main pack is full too
var sim = new SlowAce { ClientChecks = true };
var bot = Open(sim, sidePack: true, ids.ToArray());
bot.Set("_inventoryManager", new RynthCore.Plugin.RynthAi.Loot.InventoryManager(bot.Host, bot.S, bot.Cache));
var frozen = t0.AddMilliseconds(_now);
bot.Cache.WalkClock = () => frozen;
long started = _now;
Run(bot, () => bot.Completed, 60_000);
foreach (uint g in new[] { G1, G2, G3 })
Check.True(sim.Landed.Any(l => l.Id == g && l.Pack == Player), $"0x{g:X8} is looted into the main pack");
Check.True(FakeHost.ExternalMoves.All(m => m.Target == Player), "every pickup is aimed at the main pack");
Check.Eq(FakeHost.Moves.Count, 3, "one room move per gem");
Check.True(FakeHost.Moves.All(m => m.Pack == SidePack), "each into the side pack");
Check.Eq(sim.PackMoves.Count, 3, "and the server carries each out");
Check.Eq(FakeHost.Moves[0].Id, JunkBase + 101, "the first room move takes the newest loose item (nothing looted yet)");
Check.Eq(FakeHost.Moves[1].Id, sim.Landed[0].Id, "the next takes the loot just brought in");
Check.Eq(sim.LocalRefused, 0, "no pickup goes out while a room move has no answer");
Check.Eq(sim.RoomRefusals, 0, "and the server refuses none for room");
Check.True(sim.Landed.Any(l => l.Id == G1 && l.Pack == Player), "the first gem takes the main pack's last slot");
Check.True(sim.Landed.Any(l => l.Id == G2 && l.Pack == SidePack), "the second sees the main pack full and goes to the side pack");
Check.True(sim.Landed.Any(l => l.Id == G3 && l.Pack == SidePack), "so does the third");
Check.Eq(sim.MainPackDropped, 0, "no pickup is aimed at the full main pack");
Check.False(Logged("leaving 'Gem"), "nothing is left on the corpse");
Check.Eq(FakeHost.Chat.Count(c => c.Contains("Main pack full")), 0, "no main-pack-full chat line");
Check.True(Logged("the main pack is full: moving"), "the log says why each room move went");
Check.False(Logged("pickup failed"), "nothing is waited out and given up");
Check.True(bot.Completed, "the corpse completes");
Check.True(_now - started < 20_000, $"in good time ({_now - started} ms)");
}
finally { RynthClock.TestNow = oldClock; }
});

View file

@ -35,7 +35,7 @@ internal static class LootSalvageTests
public static void Register(Runner r)
{
r.Add("loot pickup: a corpse item is moved into the main pack, never used (no get-and-wield)", PickupMovesNeverUses);
r.Add("loot pickup: a full main pack never sends an item to a side pack (the client refuses that from a corpse); a stack you carry is still joined, anything else is left", PickupFullMainPackNeverSidePack);
r.Add("loot pickup: with the main pack full the client's own move never goes to a side pack or (a stackable item included) to the full main pack; with the raw move (v80) the item goes straight into the side pack", PickupFullMainPackNeverSidePack);
r.Add("loot pickup: no move call -> wearables are left, other items are used", PickupWithoutMoveCall);
r.Add("salvage: a worn item is left alone and never taken off", SalvageLeavesWornItem);
r.Add("salvage: a corpse's items go in one batch and all are salvaged", SalvageOneBatch);
@ -88,10 +88,12 @@ internal static class LootSalvageTests
// logs, none landed, each item waited out 3 + 3 tries and was left.
private const uint PeaInPack = 0x80262E01, Pea = 0x80262E02, SpareMain = 0x80262E03;
private static (RynthCoreHost Host, WorldObjectCache Cache) FullMainPack(bool sideRoom, bool peaStack)
/// <param name="rawMove">The engine has the raw 0x19 packet (plugin API v80, PutItemInContainer).</param>
private static (RynthCoreHost Host, WorldObjectCache Cache) FullMainPack(bool sideRoom, bool peaStack, bool rawMove = false)
{
FakeHost.Reset();
FakeHost.SalvageCalls = true;
FakeHost.PutCalls = rawMove;
var ids = new List<uint>();
for (uint i = 0; i < 102; i++)
{
@ -137,26 +139,40 @@ internal static class LootSalvageTests
private static void PickupFullMainPackNeverSidePack()
{
// An engine without the raw packet (plugin API before v80): nothing can take the loot.
var (host, cache) = FullMainPack(sideRoom: true, peaStack: true);
Check.Eq(LootPickup.Send(host, cache, Ring, Player, out uint dest), LootPickupResult.MainPackFull,
"a ring with the main pack full and room in a side pack: left (MainPackFull)");
"no raw move: a ring with the main pack full and room in a side pack is left (MainPackFull)");
Check.Eq(dest, 0u, "no destination");
Check.Eq(FakeHost.ExternalMoves.Count, 0, "and no move sent, least of all into the side pack");
Check.Eq(FakeHost.ExternalMoves.Count, 0, "and no move sent, least of all the client's own move into the side pack");
Check.Eq(LootPickup.Send(host, cache, Pea, Player, out dest), LootPickupResult.Moved,
"a Silver Pea joins the stack you carry: sent");
Check.Eq(dest, Player, "aimed at the main pack: the client joins it to the stack in the side pack");
Check.True(FakeHost.ExternalMoves.All(m => m.Target != SidePack), "never aimed at the side pack");
// 2026-11-30 (DreamWeave, 'Obsidian Heartstone' x many): a pickup aimed at a full main pack is
// dropped by the client even when a stack you carry has room for it; no answer ever came.
Check.Eq(LootPickup.Send(host, cache, Pea, Player, out dest), LootPickupResult.MainPackFull,
"a Silver Pea with a stack you carry in the side pack, main pack full: not sent at the main pack either (the client drops it)");
Check.Eq(FakeHost.ExternalMoves.Count, 0, "no move sent");
Check.Eq(FakeHost.Uses.Count, 0, "no UseObject");
var (host2, cache2) = FullMainPack(sideRoom: true, peaStack: false);
Check.Eq(LootPickup.Send(host2, cache2, Pea, Player, out _), LootPickupResult.MainPackFull,
"a pea with no stack to join, main pack full: left too");
var (host3, cache3) = FullMainPack(sideRoom: false, peaStack: false);
Check.Eq(LootPickup.Send(host3, cache3, Ring, Player, out _), LootPickupResult.NoRoom,
"no room in any pack: NoRoom, as before");
// The raw packet (v80; 2026-11-30, loot into side packs): the side pack.
var (host4, cache4) = FullMainPack(sideRoom: true, peaStack: true, rawMove: true);
Check.Eq(LootPickup.Send(host4, cache4, Ring, Player, out dest), LootPickupResult.Moved,
"with the raw move: the ring goes to the side pack");
Check.Eq(dest, SidePack, "aimed at the side pack");
Check.True(FakeHost.Puts.Any(p => p.Id == Ring && p.Container == SidePack), "by the raw 0x19 packet");
Check.Eq(LootPickup.Send(host4, cache4, Pea, Player, out dest), LootPickupResult.Moved,
"the pea with a stack to join goes there too, not to the full main pack");
Check.Eq(dest, SidePack, "aimed at the side pack");
Check.Eq(FakeHost.ExternalMoves.Count, 0, "nothing through the client's own move, which would drop both");
var (host5, cache5) = FullMainPack(sideRoom: false, peaStack: false, rawMove: true);
Check.Eq(LootPickup.Send(host5, cache5, Ring, Player, out _), LootPickupResult.NoRoom,
"with the raw move and every pack full: NoRoom");
Check.Eq(FakeHost.Puts.Count, 0, "nothing sent");
}
private static void PickupWithoutMoveCall()

View file

@ -0,0 +1,287 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Text.Json;
using RynthCore.Plugin.RynthAi;
using RynthCore.Plugin.RynthAi.LegacyUi;
using RynthCore.RynthAiHostTests.Fakes;
using RynthCore.RynthAiTests.Harness;
using T = RynthCore.Plugin.RynthAi.LegacyUi.NavPointType;
namespace RynthCore.RynthAiHostTests.Tests;
// The new engine Nav panel (2026-11-29, NavFace.cs): its buttons beside Add waypoint here (Jump, Vendor,
// NPC), a Jump step edited in place (facing, power, walk), Undo after a delete or clear, New route, and
// what the nav JSON now says about each step and where the character stands.
internal static class NavPanelTests
{
private const BindingFlags Any = BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public;
public static void Register(Runner r)
{
r.Add("nav panel: setJump changes a Jump step's facing, power and walk, and the file keeps them", SetJumpEdits);
r.Add("nav panel: addJump adds a jump where you stand, facing your way at 30% unless told", AddJump);
r.Add("nav panel: addVendor and addNpc take the selected object", AddVendorAndNpc);
r.Add("nav panel: Undo puts deleted steps back in their places (delete, multi-delete, clear)", UndoPutsBack);
r.Add("nav panel: newRoute starts an empty, unsaved route", NewRoute);
r.Add("nav panel: the nav JSON has each step's name, seconds and jump, where you stand, and the Undo count", JsonFields);
r.Add("nav panel: the engine's jump fields read; left out they mean unchanged", CommandJson);
}
private sealed class Rig
{
public readonly LegacyUiSettings S = new();
public readonly LegacyDashboardRenderer Dash;
public readonly string Root;
public Rig(string name, params NavPoint[] pts)
{
FakeHost.Reset();
Root = Path.Combine(Program.TempRoot, "nav-panel", name);
if (Directory.Exists(Root)) Directory.Delete(Root, recursive: true);
Directory.CreateDirectory(Root);
S.CurrentRoute = new NavRouteParser { RouteType = NavRouteType.Circular };
S.CurrentRoute.Points.AddRange(pts);
var nav = (LegacyNavigationUi)RuntimeHelpers.GetUninitializedObject(typeof(LegacyNavigationUi));
typeof(LegacyNavigationUi).GetField("_settings", Any)!.SetValue(nav, S);
Dash = (LegacyDashboardRenderer)RuntimeHelpers.GetUninitializedObject(typeof(LegacyDashboardRenderer));
Set("_profileLoaded", true); // a stand-in with its profile in memory
Set("_settings", S);
Set("_host", FakeHost.Create());
Set("_navigationUi", nav);
Set("_navFiles", new List<string>());
Set("_navFolder", Root);
Set("_profileListsLock", new object());
Set("_navEditStatus", string.Empty); // field initializers don't run on an uninitialized object
// _settingsFilePath stays null: SaveSettings writes nothing.
}
private void Set(string f, object v) => typeof(LegacyDashboardRenderer).GetField(f, Any)!.SetValue(Dash, v);
public void Cmd(string json) => Dash.HandleNavCommand(json);
public NavBridgePayload Nav() =>
JsonSerializer.Deserialize(Dash.BuildNavJson(), RynthAiJsonContext.Default.NavBridgePayload)!;
public string Status() => Nav().EditStatus;
}
private static NavPoint P(double ns, double ew, T type = T.Point) => new() { Type = type, NS = ns, EW = ew, Z = -0.1 };
private static NavPoint Jump(double heading, double ms, bool shift) =>
new() { Type = T.Jump, NS = 1, EW = 1, Z = 0, JumpHeading = heading, JumpMs = ms, JumpShift = shift };
private static void SetJumpEdits()
{
var rig = new Rig("setjump", P(1, 1), Jump(90, 300, false), P(2, 2));
string path = Path.Combine(rig.Root, "jumps.nav");
rig.S.CurrentRoute.Save(path);
rig.S.CurrentNavPath = path;
rig.Cmd("{\"Cmd\":\"setJump\",\"Index\":1,\"Heading\":212,\"Ms\":-1,\"Shift\":false}");
NavPoint j = rig.S.CurrentRoute.Points[1];
Check.Near(j.JumpHeading, 212, 1e-9, "facing set");
Check.Near(j.JumpMs, 300, 1e-9, "power unchanged (Ms -1)");
rig.Cmd("{\"Cmd\":\"setJump\",\"Index\":1,\"Heading\":-1,\"Ms\":600,\"Shift\":true}");
Check.Near(j.JumpHeading, 212, 1e-9, "facing unchanged (Heading -1)");
Check.Near(j.JumpMs, 600, 1e-9, "power 60%");
Check.True(j.JumpShift, "walking jump");
rig.Cmd("{\"Cmd\":\"setJump\",\"Index\":1,\"Heading\":-450,\"Ms\":5000,\"Shift\":true}");
Check.Near(j.JumpHeading, 212, 1e-9, "a negative facing changes nothing");
Check.Near(j.JumpMs, 1000, 1e-9, "power capped at 100%");
rig.Cmd("{\"Cmd\":\"setJump\",\"Index\":1,\"Heading\":450,\"Ms\":-1,\"Shift\":true}");
Check.Near(j.JumpHeading, 90, 1e-9, "450° is 90°");
// Not a jump, or out of range: nothing changes.
rig.Cmd("{\"Cmd\":\"setJump\",\"Index\":0,\"Heading\":10,\"Ms\":10,\"Shift\":true}");
Check.Near(rig.S.CurrentRoute.Points[0].JumpHeading, 0, 0, "a Point isn't made a jump");
rig.Cmd("{\"Cmd\":\"setJump\",\"Index\":9,\"Heading\":10,\"Ms\":10,\"Shift\":true}");
NavRouteParser reread = NavRouteParser.Load(path);
Check.Eq(reread.Points[1].Type, T.Jump, "still a jump in the file");
Check.Near(reread.Points[1].JumpHeading, 90, 1e-6, "file: facing");
Check.Near(reread.Points[1].JumpMs, 1000, 1e-6, "file: power");
Check.True(reread.Points[1].JumpShift, "file: walking");
}
private static void AddJump()
{
var rig = new Rig("addjump", P(1, 1), P(2, 2));
FakeHost.SetNavPosition(10.5, -20.25);
FakeHost.HeadingDeg = 135;
rig.Cmd("{\"Cmd\":\"addJump\",\"AddMode\":0,\"InsertAt\":-1,\"Heading\":-1,\"Ms\":-1,\"Shift\":false}");
Check.Eq(rig.S.CurrentRoute.Points.Count, 3, "a step added");
NavPoint j = rig.S.CurrentRoute.Points[2];
Check.Eq(j.Type, T.Jump, "a Jump step");
Check.Near(j.NS, 10.5, 1e-4, "where you stand (NS)");
Check.Near(j.EW, -20.25, 1e-4, "where you stand (EW)");
Check.Near(j.JumpHeading, 135, 0.5, "facing your way");
Check.Near(j.JumpMs, 300, 1e-9, "30% power");
Check.False(j.JumpShift, "not walking");
// Told: after step 0, facing 270, full power, walking.
rig.Cmd("{\"Cmd\":\"addJump\",\"AddMode\":2,\"InsertAt\":0,\"Heading\":270,\"Ms\":1000,\"Shift\":true}");
NavPoint k = rig.S.CurrentRoute.Points[1];
Check.Eq(k.Type, T.Jump, "after step 0");
Check.Near(k.JumpHeading, 270, 1e-9, "facing as told");
Check.Near(k.JumpMs, 1000, 1e-9, "power as told");
Check.True(k.JumpShift, "walking as told");
}
private static void AddVendorAndNpc()
{
var rig = new Rig("vendor-npc", P(1, 1));
FakeHost.SetNavPosition(5, 5);
// Nothing selected: nothing added, and the panel says why.
rig.Cmd("{\"Cmd\":\"addVendor\",\"AddMode\":0,\"InsertAt\":-1}");
Check.Eq(rig.S.CurrentRoute.Points.Count, 1, "no selection: nothing added");
Check.True(rig.Status().Contains("Select"), "says to select: " + rig.Status());
const uint Vendor = 0x7A000010, Npc = 0x7A000011;
uint cell = FakeHost.NavCell(5.01, 5.01, out float vx, out float vy);
FakeHost.Names[Vendor] = "Renald the Grocer";
FakeHost.Positions[Vendor] = (cell, vx, vy, 0);
FakeHost.Names[Npc] = "Town Crier";
FakeHost.Positions[Npc] = (cell, vx, vy, 0);
FakeHost.SelectedItem = Vendor;
rig.Cmd("{\"Cmd\":\"addVendor\",\"AddMode\":0,\"InsertAt\":-1}");
NavPoint v = rig.S.CurrentRoute.Points[^1];
Check.Eq(v.Type, T.OpenVendor, "a Vendor step");
Check.Eq(v.TargetName, "Renald the Grocer", "the vendor's name");
Check.Eq(v.VendorId, Vendor, "the vendor's id");
Check.Near(v.NS, 5, 1e-4, "where you stand");
FakeHost.SelectedItem = Npc;
rig.Cmd("{\"Cmd\":\"addNpc\",\"AddMode\":1,\"InsertAt\":0}");
NavPoint n = rig.S.CurrentRoute.Points[0];
Check.Eq(n.Type, T.Npc, "an NPC step, before step 0");
Check.Eq(n.TargetName, "Town Crier", "the NPC's name");
Check.Near(n.PortalExitNS, 5.01, 1e-3, "the NPC's own spot");
// Saved and read back: both keep their names (the file format's trailers).
string path = Path.Combine(rig.Root, "stops.nav");
rig.S.CurrentRoute.Save(path);
NavRouteParser reread = NavRouteParser.Load(path);
Check.Eq(reread.Points.Count, 3, "three steps in the file");
Check.Eq(reread.Points[0].TargetName, "Town Crier", "file: NPC");
Check.Eq(reread.Points[2].TargetName, "Renald the Grocer", "file: vendor");
Check.Eq(reread.Points[2].VendorId, Vendor, "file: vendor id");
}
private static void UndoPutsBack()
{
NavPoint a = P(1, 1), b = P(2, 2), c = P(3, 3), d = P(4, 4);
var rig = new Rig("undo", a, b, c, d);
Check.Eq(rig.Nav().UndoCount, 0, "nothing to undo yet");
rig.Cmd("{\"Cmd\":\"deletePoints\",\"Indices\":[1,3]}");
Check.Eq(rig.S.CurrentRoute.Points.Count, 2, "two deleted");
var nav = rig.Nav();
Check.Eq(nav.UndoCount, 2, "Undo can put two back");
Check.True(nav.EditStatus.StartsWith("Deleted"), "the panel's Undo shows after 'Deleted...': " + nav.EditStatus);
rig.Cmd("{\"Cmd\":\"undoDelete\"}");
var pts = rig.S.CurrentRoute.Points;
Check.Eq(pts.Count, 4, "both back");
Check.True(ReferenceEquals(pts[1], b) && ReferenceEquals(pts[3], d), "each in its place");
Check.Eq(rig.Nav().UndoCount, 0, "and Undo is used up");
rig.Cmd("{\"Cmd\":\"deletePoint\",\"Index\":0}");
Check.True(rig.Status().StartsWith("Deleted step 0"), "the row's X says so: " + rig.Status());
rig.Cmd("{\"Cmd\":\"undoDelete\"}");
Check.True(ReferenceEquals(rig.S.CurrentRoute.Points[0], a), "the X's step is back first");
rig.Cmd("{\"Cmd\":\"clearRoute\"}");
Check.Eq(rig.S.CurrentRoute.Points.Count, 0, "cleared");
Check.True(rig.Status().StartsWith("Cleared"), "says cleared: " + rig.Status());
rig.Cmd("{\"Cmd\":\"undoDelete\"}");
Check.Eq(rig.S.CurrentRoute.Points.Count, 4, "all four back");
Check.True(ReferenceEquals(rig.S.CurrentRoute.Points[2], c), "in order");
// Another route loaded: Undo has nothing to put into it.
rig.Cmd("{\"Cmd\":\"deletePoint\",\"Index\":0}");
rig.S.CurrentRoute = new NavRouteParser { RouteType = NavRouteType.Once };
Check.Eq(rig.Nav().UndoCount, 0, "a different route: nothing to undo");
rig.Cmd("{\"Cmd\":\"undoDelete\"}");
Check.Eq(rig.S.CurrentRoute.Points.Count, 0, "nothing put into the other route");
}
private static void NewRoute()
{
var rig = new Rig("newroute", P(1, 1), P(2, 2));
rig.S.CurrentNavPath = Path.Combine(rig.Root, "kept.nav");
rig.S.ActiveNavIndex = 1;
rig.S.IsRecordingNav = true;
rig.Cmd("{\"Cmd\":\"newRoute\"}");
Check.Eq(rig.S.CurrentRoute.Points.Count, 0, "empty");
Check.Eq(rig.S.CurrentRoute.RouteType, NavRouteType.Once, "Run once");
Check.Eq(rig.S.CurrentNavPath, string.Empty, "unsaved: no file");
Check.Eq(rig.S.ActiveNavIndex, 0, "from step 0");
Check.False(rig.S.IsRecordingNav, "recording stopped");
Check.False(File.Exists(Path.Combine(rig.Root, "kept.nav")), "no file written");
}
private static void JsonFields()
{
var rig = new Rig("json",
P(1, 1),
new NavPoint { Type = T.Pause, NS = 1, EW = 1, PauseTimeMs = 5000 },
new NavPoint { Type = T.OpenVendor, NS = 1, EW = 1, TargetName = "Renald the Grocer", VendorId = 7 },
new NavPoint { Type = T.PortalNPC, NS = 1, EW = 1, TargetName = "Portal to Holtburg" },
new NavPoint { Type = T.Npc, NS = 1, EW = 1, TargetName = "Town Crier" },
Jump(212, 600, true),
new NavPoint { Type = T.Chat, NS = 1, EW = 1, ChatCommand = "/ub usei Healing Kit" });
rig.S.ActiveNavIndex = 0;
var nav = rig.Nav();
Check.Near(nav.Points[1].Seconds, 5, 1e-9, "Pause: seconds");
Check.Eq(nav.Points[2].Name, "Renald the Grocer", "Vendor: name");
Check.Eq(nav.Points[3].Name, "Portal to Holtburg", "Portal: name");
Check.Eq(nav.Points[4].Name, "Town Crier", "NPC: name");
Check.Near(nav.Points[5].Heading, 212, 1e-9, "Jump: facing");
Check.Near(nav.Points[5].Ms, 600, 1e-9, "Jump: power");
Check.True(nav.Points[5].Shift, "Jump: walking");
Check.Eq(nav.Points[6].Text, "/ub usei Healing Kit", "Chat: the command (as before)");
Check.Eq(nav.Points[0].Name, string.Empty, "Point: no name");
// Where you stand, and how far the next step is (yd = nav units x 240).
FakeHost.SetNavPosition(1.1, 1);
nav = rig.Nav();
Check.True(nav.HereKnown, "position known");
Check.Near(nav.HereNS, 1.1, 1e-4, "here NS");
Check.Near(nav.ActiveDist, 24, 0.05, "step 0 is 24 yd away");
// No plugin hook (a stand-in renderer): the mode fields stay at their defaults.
Check.Eq(nav.Mode, string.Empty, "no mode without the plugin");
Check.False(nav.HuntAvailable, "no Hunt tab without the plugin");
// The plugin's hook fills the mode fields.
rig.Dash.NavPanelState = p => { p.Mode = "follow"; p.FollowName = "Leader"; p.HuntAvailable = true; };
nav = rig.Nav();
Check.Eq(nav.Mode, "follow", "the hook's mode");
Check.Eq(nav.FollowName, "Leader", "the hook's follow name");
Check.True(nav.HuntAvailable, "the hook's Hunt tab");
// A hook that throws doesn't take the panel's data with it.
rig.Dash.NavPanelState = _ => throw new InvalidOperationException("test");
nav = rig.Nav();
Check.Eq(nav.Points.Count, 7, "points still there");
}
private static void CommandJson()
{
NavCommand? c = JsonSerializer.Deserialize("{\"Cmd\":\"setJump\",\"Index\":2,\"Heading\":90.5,\"Ms\":450,\"Shift\":true,\"Text\":\"face\"}",
RynthAiJsonContext.Default.NavCommand);
Check.Near(c!.Heading, 90.5, 1e-9, "Heading");
Check.Near(c.Ms, 450, 1e-9, "Ms");
Check.True(c.Shift, "Shift");
Check.Eq(c.Text, "face", "Text");
NavCommand? old = JsonSerializer.Deserialize("{\"Cmd\":\"addJump\"}", RynthAiJsonContext.Default.NavCommand);
Check.Near(old!.Heading, -1, 0, "no Heading: -1 (your facing / unchanged)");
Check.Near(old.Ms, -1, 0, "no Ms: -1 (30% / unchanged)");
}
}