using System; using System.Collections.Generic; using System.Linq; using RynthCore.Plugin.RynthAi; using RynthCore.Plugin.RynthAi.LegacyUi; using RynthCore.RynthAiHostTests.Fakes; using RynthCore.RynthAiTests.Harness; namespace RynthCore.RynthAiHostTests.Tests; // /ra dunnav-to (2026-11-15): a walk on the dungeon map to an object's own cell (any // floor), for a script's walks to the monsters still to be killed after an explore. // On DunRouteTests' sample dungeon (the start in the hall's middle, the west room two rooms away). internal static class DunNavToTests { public static void Register(Runner r) { r.Add("dunnav-to: walks to an object's cell on the dungeon map, the macro on; refuses an unknown one or one outside the dungeon", WalksToObject); r.Add("dunnav-to cell: walks to a cell of the dungeon by its number (a person the client hasn't been sent yet), labelled; refuses another dungeon's or a bad cell", WalksToCell); r.Add("dunnav-to walkonly: fighting, looting, buffing and the meta off for the walk, put back exactly as they were when it ends, stops or fails", WalkOnlyTrip); } // RynthNav's go to someone inside a dungeon hands the walk on as "/ra dunnav-to cell walkonly " // by default (2026-11-27): a run to the target with no fighting, looting or buffing on the way. private static void WalkOnlyTrip() { var rig = new DunRouteTests.Rig("NavProfiles-dunnav-to-walkonly"); string cell = rig.D.West.ToString("X8"); void Switches(bool combat, bool loot, bool buff, bool meta) { rig.S.EnableCombat = combat; rig.S.EnableLooting = loot; rig.S.EnableBuffing = buff; rig.S.EnableMeta = meta; } string Now() => $"combat {rig.S.EnableCombat} loot {rig.S.EnableLooting} buff {rig.S.EnableBuffing} meta {rig.S.EnableMeta} macro {rig.S.IsMacroRunning}"; List Tick() { int before = FakeHost.Chat.Count; rig.Call("TickWalkTrip"); return FakeHost.Chat.Skip(before).ToList(); } // 1. Arrives: everything back, and the macro off again (it was off). rig.S.IsMacroRunning = false; Switches(true, true, true, true); var said = rig.Typed($"/ra dunnav-to cell {cell} walkonly Hall Keeper"); Check.True(said.Count == 1 && said[0].StartsWith("[RynthAi] DunNav-To: 'Hall Keeper' in " + cell) && said[0].Contains("walk only"), "it answers, the label without the word walkonly: " + string.Join(" | ", said)); Check.True(rig.S.IsMacroRunning && rig.S.EnableNavigation, "macro and navigation on for the walk"); Check.False(rig.S.EnableCombat || rig.S.EnableLooting || rig.S.EnableBuffing || rig.S.EnableMeta, "no fighting, looting, buffing or meta on the way: " + Now()); Check.True(Tick().Count == 0, "walking: nothing said"); Check.False(rig.S.EnableCombat, "still walking: combat stays off"); rig.S.ActiveNavIndex = rig.S.CurrentRoute.Points.Count; // the nav engine walked off the last point rig.S.EnableNavigation = false; said = Tick(); Check.True(said.Count == 1 && said[0].Contains("ended (arrived)") && said[0].Contains("macro off again"), "arrived: said: " + string.Join(" | ", said)); Check.True(rig.S.EnableCombat && rig.S.EnableLooting && rig.S.EnableBuffing && rig.S.EnableMeta && !rig.S.IsMacroRunning, "all back as before: " + Now()); Check.True(Tick().Count == 0, "over: nothing more"); // 2. The player stops the macro mid-walk: a mixed set back as it was, the macro stays off. rig.S.IsMacroRunning = true; Switches(false, true, false, true); rig.Typed($"/ra dunnav-to cell {cell} walkonly"); Check.False(rig.S.EnableLooting || rig.S.EnableMeta, "off for the walk"); rig.S.IsMacroRunning = false; said = Tick(); Check.True(said.Count == 1 && said[0].Contains("the macro was stopped"), "stopped: said: " + string.Join(" | ", said)); Check.True(!rig.S.EnableCombat && rig.S.EnableLooting && !rig.S.EnableBuffing && rig.S.EnableMeta && !rig.S.IsMacroRunning, "back exactly: " + Now()); // 3. The macro was on before: it stays on at the end; nav switched off counts as the end. rig.S.IsMacroRunning = true; Switches(true, false, true, false); rig.Typed($"/ra dunnav-to cell {cell} walkonly"); rig.S.EnableNavigation = false; said = Tick(); Check.True(said.Count == 1 && said[0].Contains("navigation was turned off") && !said[0].Contains("macro off"), "nav off: " + string.Join(" | ", said)); Check.True(rig.S.EnableCombat && !rig.S.EnableLooting && rig.S.EnableBuffing && !rig.S.EnableMeta && rig.S.IsMacroRunning, "back, the macro still on: " + Now()); // 4. Another route loaded (a meta, a script, the player): the switches back, the macro left to its new owner. rig.S.IsMacroRunning = false; Switches(true, true, true, true); rig.Typed($"/ra dunnav-to cell {cell} walkonly"); rig.S.CurrentRoute = new NavRouteParser { RouteType = NavRouteType.Circular }; said = Tick(); Check.True(said.Count == 1 && said[0].Contains("another route was loaded"), "another route: " + string.Join(" | ", said)); Check.True(rig.S.EnableCombat && rig.S.EnableLooting && rig.S.EnableBuffing && rig.S.EnableMeta && rig.S.IsMacroRunning, "switches back, macro left on: " + Now()); // 5. Out of the dungeon mid-walk (a portal, a recall, a death): back, the macro off again. rig.S.IsMacroRunning = false; Switches(true, true, true, true); rig.Typed($"/ra dunnav-to cell {cell} walkonly"); rig.At(10, 10, 0xA9B40020); said = Tick(); Check.True(said.Count == 1 && said[0].Contains("you left the dungeon"), "left: " + string.Join(" | ", said)); Check.True(rig.S.EnableCombat && rig.S.EnableLooting && rig.S.EnableBuffing && rig.S.EnableMeta && !rig.S.IsMacroRunning, "back: " + Now()); rig.At(15, 15, rig.D.Start); // 6. A second walk-only trip over the first: the player's switches are kept, not the first trip's offs. rig.S.IsMacroRunning = false; Switches(true, true, false, true); rig.Typed($"/ra dunnav-to cell {cell} walkonly"); rig.Typed($"/ra dunnav-to cell {cell} walkonly"); rig.S.IsMacroRunning = false; Tick(); Check.True(rig.S.EnableCombat && rig.S.EnableLooting && !rig.S.EnableBuffing && rig.S.EnableMeta, "the player's own, after two trips: " + Now()); // 7. Unloaded or logged out mid-walk: the switches back before the profile is saved. Switches(true, true, true, true); rig.S.IsMacroRunning = false; rig.Typed($"/ra dunnav-to cell {cell} walkonly"); rig.Call("ForgetWalkTrip"); Check.True(rig.S.EnableCombat && rig.S.EnableLooting && rig.S.EnableBuffing && rig.S.EnableMeta, "back for the save: " + Now()); Check.True(rig.Get("_walkTrip") == null, "the trip is forgotten"); // Without walkonly the walk runs the macro as set (fight on the way in), the switches untouched. rig.S.IsMacroRunning = false; Switches(true, true, true, false); rig.Typed($"/ra dunnav-to cell {cell} Hall Keeper"); Check.True(rig.S.EnableCombat && rig.S.EnableLooting && rig.S.EnableBuffing && rig.S.IsMacroRunning, "no walkonly: as set: " + Now()); Check.True(rig.Get("_walkTrip") == null, "no trip"); } // RynthNav's go to someone inside a dungeon hands the walk on as "/ra dunnav-to cell " (2026-11-27). // Spotted by SilentKelpie (Forgejo rynth PR #12); re-implemented here. private static void WalksToCell() { var rig = new DunRouteTests.Rig("NavProfiles-dunnav-to-cell"); rig.S.IsMacroRunning = false; string cell = rig.D.West.ToString("X8"); var said = rig.Typed($"/ra dunnav-to cell {cell} Hall Keeper"); Check.True(said.Count == 1 && said[0].StartsWith("[RynthAi] DunNav-To: 'Hall Keeper' in " + cell) && said[0].Contains("walking there"), "it answers with the label: " + string.Join(" | ", said)); var pts = rig.S.CurrentRoute.Points; Check.True(pts.Count >= 2, $"a walk ({pts.Count} points)"); Check.True(rig.S.IsMacroRunning && rig.S.EnableNavigation, "macro and navigation on"); var last = pts[^1]; double lx = DungeonGeometry.NavToWorld(last.EW) - DunRouteTests.Ox, ly = DungeonGeometry.NavToWorld(last.NS) - DunRouteTests.Oy; Check.True(Math.Abs(lx - -17.5) < 3 && Math.Abs(ly - 25) < 3, $"it ends in the west room's middle ({lx:F1}, {ly:F1})"); // No label: the cell names itself. Lower case and 0x work. rig.S.IsMacroRunning = false; said = rig.Typed($"/ra dunnav-to cell 0x{cell.ToLowerInvariant()}"); Check.True(said.Count == 1 && said[0].Contains($"'cell {cell}'"), "unlabelled: " + string.Join(" | ", said)); var before = rig.S.CurrentRoute; said = rig.Typed("/ra dunnav-to cell 009C0270 Someone"); Check.True(said.Count == 1 && said[0].Contains("isn't in this dungeon"), "another dungeon's cell: " + string.Join(" | ", said)); said = rig.Typed($"/ra dunnav-to cell {(DunRouteTests.Lb << 16 | 0x0F00):X8}"); Check.True(said.Count == 1 && said[0].Contains("isn't on this dungeon's map"), "a cell the map hasn't: " + string.Join(" | ", said)); said = rig.Typed("/ra dunnav-to cell 12"); Check.True(said.Count == 1 && said[0].Contains("Usage: /ra dunnav-to"), "a bad cell: the usage"); said = rig.Typed($"/ra dunnav-to cell {(DunRouteTests.Lb << 16 | 0x0020):X8}"); Check.True(said.Count == 1 && said[0].Contains("Usage: /ra dunnav-to"), "an outdoor cell: the usage"); Check.True(ReferenceEquals(rig.S.CurrentRoute, before), "the walk in hand is left alone"); // Standing in that cell already: said so, nothing laid. rig.At(-17.5, 25, rig.D.West); said = rig.Typed($"/ra dunnav-to cell {cell}"); Check.True(said.Count == 1 && said[0].Contains("already in"), "there already: " + string.Join(" | ", said)); Check.True(ReferenceEquals(rig.S.CurrentRoute, before), "nothing laid when there"); } private const uint Rat = 0x7E7E9101, Outside = 0x7E7E9102, Unknown = 0x7E7E9103; private static void WalksToObject() { var rig = new DunRouteTests.Rig("NavProfiles-dunnav-to"); FakeHost.Names[Rat] = "Threadbound Rat"; FakeHost.Positions[Rat] = (rig.D.West, -17f, 25f, 0f); rig.S.IsMacroRunning = false; var said = rig.Typed("/ra dunnav-to 0x7E7E9101"); Check.True(said.Count == 1 && said[0].StartsWith("[RynthAi] DunNav-To: 'Threadbound Rat' 0x7E7E9101") && said[0].Contains("walking there"), "it answers: " + string.Join(" | ", said)); var pts = rig.S.CurrentRoute.Points; Check.True(pts.Count >= 2, $"a walk ({pts.Count} points)"); Check.Eq(rig.S.CurrentRoute.RouteType, NavRouteType.Once, "a Once walk"); Check.True(rig.S.IsMacroRunning && rig.S.EnableNavigation && rig.S.ActiveNavIndex == 0, "macro and navigation on, from its start"); var last = pts[^1]; double lx = DungeonGeometry.NavToWorld(last.EW) - DunRouteTests.Ox, ly = DungeonGeometry.NavToWorld(last.NS) - DunRouteTests.Oy; Check.True(Math.Abs(lx - -17) < 3 && Math.Abs(ly - 25) < 3, $"it ends at the rat ({lx:F1}, {ly:F1})"); // Through w1 (x -10..0, y 22.35..27.65), the one way into the west room: a leg crosses x = -5 inside it. bool throughW1 = false; double X(NavPoint p) => DungeonGeometry.NavToWorld(p.EW) - DunRouteTests.Ox; double Y(NavPoint p) => DungeonGeometry.NavToWorld(p.NS) - DunRouteTests.Oy; for (int i = 0; i + 1 < pts.Count; i++) { double ax = X(pts[i]), bx = X(pts[i + 1]); if ((ax - -5) * (bx - -5) > 0 || Math.Abs(bx - ax) < 1e-6) continue; double y = Y(pts[i]) + (Y(pts[i + 1]) - Y(pts[i])) * ((-5 - ax) / (bx - ax)); throughW1 |= y > 22.35 && y < 27.65; } Check.True(throughW1, "through w1, the way to the west room"); // Decimal ids work too; an unknown object, or one outside the dungeon, is refused (nothing changed). var before = rig.S.CurrentRoute; said = rig.Typed("/ra dunnav-to " + Unknown.ToString()); Check.True(said.Count == 1 && said[0].Contains("has no position the client knows"), "unknown: " + string.Join(" | ", said)); FakeHost.Positions[Outside] = (0xA9B40020, 10f, 10f, 0f); said = rig.Typed("/ra dunnav-to 0x7E7E9102"); Check.True(said.Count == 1 && said[0].Contains("isn't in this dungeon"), "outside: " + string.Join(" | ", said)); said = rig.Typed("/ra dunnav-to"); Check.True(said.Count == 1 && said[0].Contains("Usage: /ra dunnav-to "), "no id: the usage"); Check.True(ReferenceEquals(rig.S.CurrentRoute, before), "the walk in hand is left alone"); // In a Thread on DreamWeave it is off, as the patrol and the explore are. var thread = new DunRouteTests.Rig("NavProfiles-dunnav-to-thread", world: "DreamWeave"); FakeHost.Names[Rat] = "Threadbound Rat"; FakeHost.Positions[Rat] = (thread.D.West, -17f, 25f, 0f); thread.S.IsMacroRunning = false; ServerPolicy.NoteChat("[REALM] id=0 inst=7841 eph=1 name=Base World", thread.D.Start); var routeBefore = thread.S.CurrentRoute; said = thread.Typed("/ra dunnav-to 0x7E7E9101"); Check.True(said.Count == 1 && said[0].Contains("turned off in Threads"), "in a Thread on DreamWeave: refused: " + string.Join(" | ", said)); Check.False(thread.S.IsMacroRunning || thread.S.EnableNavigation, "nothing started"); Check.True(ReferenceEquals(thread.S.CurrentRoute, routeBefore), "no walk laid"); ServerPolicy.Forget(); } }