using System; using System.Collections.Generic; using System.Linq; using RynthCore.Plugin.RynthAi; using RynthCore.Plugin.RynthAi.LegacyUi; using RynthCore.RynthAiTests.Harness; namespace RynthCore.RynthAiHostTests.Tests; // Outdoor hunting (2026-10-23): walk from monster to monster around obstacles on RynthNav's map. // The path function here plays RynthNav: by default a straight walk, with per-monster overrides (a // building in the way makes the walk long; a cliff makes it impossible). internal static class OutdoorHuntTests { public static void Register(Runner r) { r.Add("hunt: the next monster is the shortest walk, not the nearest in a straight line (one behind a building)", ShortestWalk); r.Add("hunt: a higher Priority comes first, whatever the walk", PriorityFirst); r.Add("hunt: no way to a monster (a cliff, water): left out for a while; a walk ending close enough still counts", Unreachable); r.Add("hunt (11-12): a walk ending under a monster on a roof or the floor above doesn't reach it; one up a slope does", AboveTheWalk); r.Add("hunt: it stays within Hunt Radius of where it started (0 = anywhere)", Radius); r.Add("hunt fence (2026-11-17, open-world Threads): a nearer monster outside the fence is passed over; none inside: it waits, and says the fence", FenceHunt); r.Add("hunt fence: /ra hunt fence x y r sets it, combat leaves a monster outside it alone, off clears it; a bad one shows the usage", FenceCommandAndCombat); r.Add("hunt fence (\"here and there nav takes him outside\"): a walk round the outside is no walk; from outside, a walk back in is", FenceWalk); r.Add("hunt: plans again when the monster moves, the walk runs out, or a while passes; not every tick", Replan); r.Add("hunt: nothing in range: it waits where it is (no walk back to the start); Hunt Radius defaults to anywhere", WaitsWhereItIs); r.Add("hunt roam (R-20261127 32e4): nothing in range: walks to the nearest part of the area not seen, keeps walking, a monster ends it", RoamWalks); r.Add("hunt roam: walks the whole Hunt Radius, never outside it, then waits; looks again after 5 min", RoamCoversArea); r.Add("hunt roam: a part no walk gets to, or a walk stopping short, is left out; the rest is still roamed", RoamUnreachable); r.Add("hunt roam: inside the fence only; Hunt Radius anywhere roams Hunt Range round the start; on by default (and the setting)", RoamFenceAndDefaults); r.Add("hunt: /ra hunt range|radius answer and cap; status and stop don't toggle it; panel opens the window", Commands); r.Add("hunt: the target dies: the next one; no pathfinder: it stands", NextAndNoPathfinder); r.Add("hunt: the settings round-trip with the rest (saved, copied, engine payload)", Settings); r.Add("hunt (test 10-23): a monster 12 yd away but a 143 yd walk is too far round; the one being walked to is kept past Hunt Range", FarRound); r.Add("hunt (test 10-23): at a wall with the monster on its far side: no 1 yd walks every half second; left out after NoFightSec", WallBetween); r.Add("hunt (2026-11-16): a walk ending where it stands, its corners round it, is no walk: it stands, then the monster is left out", EndsHereNoWalk); r.Add("hunt (2026-11-16 17:11): the walk over, under a monster on the floor above: left out, not walked again every half second", FloorApartLeftOut); r.Add("hunt (2026-11-17 Thread E74E): under a monster on a building's platform: its cell's other monsters left out too, for 10 min", FloorApartCellLeftOut); r.Add("hunt (2026-11-17 fort Thread 3073): a 425 yd walk to one 68 yd away is too far round", TooFarRoundForIt); r.Add("hunt fence (2026-11-17 Thread 32D9): combat fights beside the character and no farther out than it, even outside the fence", FenceSkipsRule); r.Add("hunt (2026-11-17 fort Thread 3073): stuck again and again at a spot: that monster left out, and no walk by the spot", SnaggedSpot); r.Add("hunt: a monster right beside it that combat doesn't take: stands, then leaves it out", RightHere); r.Add("hunt (test 10-23): in a building it walks back out the way it went in (the loops it made cut out)", WayBackOut); r.Add("hunt: in a building with no way in known, or the walks out ending still inside: it waits", IndoorsWaits); r.Add("hunt pick (11-08): Nearest is the hunt as it was (the lone one 10 yd off, not the pack)", PickNearestUnchanged); r.Add("hunt pick (11-08): Biggest pack goes to a 5-pack 80 yd off over a lone monster 10 yd off; logged", PickPackFar); r.Add("hunt pick (11-08): a lone monster wins when the pack is very far", PickPackTooFar); r.Add("hunt pick (11-08): Most XP prefers 2 high-XP monsters over 4 low-XP ones (Biggest pack the other way)", PickMostXp); r.Add("hunt pick (11-08): Most XP with no XP learned falls back to the pack's size; an unknown name counts as the known average", PickXpUnknown); r.Add("hunt pick (11-08): a higher Priority still comes first; paths only for the top few; the target is kept while walking", PickPriorityAndCost); r.Add("hunt pick (11-08): /ra hunt pick answers with the choice, sets it, and says why not with the usage", PickCommand); r.Add("hunt pick (11-08): OutdoorHuntPick round-trips (saved, copied, engine payload, clamped, an older engine leaves it)", PickSetting); } // ── Pick (2026-11-08, Tom: "a setting to go for nearest spawn or most dense or highest experience") ── /// A pack of round (x, y), ids from , each within a few yd of the others. private static List Pack(int firstId, int n, double x, double y, OutdoorHunt.Vec me, string? name = null, int priority = 1) { var list = new List(); for (int i = 0; i < n; i++) { double a = i * 2 * Math.PI / Math.Max(1, n); double px = x + (i == 0 ? 0 : 4 * Math.Cos(a)), py = y + (i == 0 ? 0 : 4 * Math.Sin(a)); list.Add(C(firstId + i, px, py, me, priority, name)); } return list; } private static List Sorted(IEnumerable c) => c.OrderBy(x => x.Distance).ToList(); private static void PickNearestUnchanged() { var me = V(1000, 1000); var all = Sorted(Pack(10, 5, 1080, 1000, me).Append(C(1, 1010, 1000, me))); var h = new OutdoorHunt(); Check.Eq(h.Pick, OutdoorHunt.PickMode.Nearest, "Nearest by default"); h.Start(T0, me); var d = h.Tick(T0, me, true, all, new Nav().Path); Check.Eq(d.TargetId, 1, "the lone one 10 yd away"); Check.True(h.Note.StartsWith("next: 'Monster 1', a 10 yd walk"), "the same log line as before: " + h.Note); } private static void PickPackFar() { var me = V(1000, 1000); var all = Sorted(Pack(10, 5, 1080, 1000, me).Append(C(1, 1010, 1000, me))); var h = new OutdoorHunt { Pick = OutdoorHunt.PickMode.Pack }; h.Start(T0, me); var d = h.Tick(T0, me, true, all, new Nav().Path); Check.True(d.Act == OutdoorHunt.Act.Walk && d.TargetId >= 10 && d.TargetId < 15, $"to the pack, not the lone one ({d.Act} {d.TargetId})"); var nearestOfPack = all.Where(c => c.Id >= 10).OrderBy(c => c.Distance).First(); Check.Eq(d.TargetId, nearestOfPack.Id, "the pack's member with the shortest walk"); Check.True(h.Note.Contains("pack of 5") && h.Note.Contains("yd walk"), "logged with the pack: " + h.Note); } private static void PickPackTooFar() { var me = V(1000, 1000); // 3 at 180 yd: 3 / (1 + 180/60) = 0.75; one at 10 yd: 1 / (1 + 10/60) = 0.86. var all = Sorted(Pack(10, 3, 1180, 1000, me).Append(C(1, 1010, 1000, me))); var h = new OutdoorHunt { Pick = OutdoorHunt.PickMode.Pack }; h.Start(T0, me); var d = h.Tick(T0, me, true, all, new Nav().Path); Check.Eq(d.TargetId, 1, "the lone one near beats a small pack far away"); Check.True(h.Note.Contains("on its own"), "logged: " + h.Note); // The same pack 80 yd off: 3 / 2.33 = 1.29 wins. var near = Sorted(Pack(10, 3, 1080, 1000, me).Append(C(1, 1010, 1000, me))); var h2 = new OutdoorHunt { Pick = OutdoorHunt.PickMode.Pack }; h2.Start(T0, me); Check.True(h2.Tick(T0, me, true, near, new Nav().Path).TargetId >= 10, "and at 80 yd the pack wins"); } private static Func Xp(params (string Name, double Xp)[] known) { var map = known.ToDictionary(k => k.Name, k => k.Xp); return n => map.TryGetValue(n, out double v) ? v : null; } private static void PickMostXp() { var me = V(1000, 1000); var all = Sorted(Pack(10, 2, 1050, 1000, me, "Olthoi Slayer").Concat(Pack(20, 4, 1000, 1030, me, "Drudge Skulker"))); var lookup = Xp(("Olthoi Slayer", 1000), ("Drudge Skulker", 100)); var h = new OutdoorHunt { Pick = OutdoorHunt.PickMode.Xp, XpLookup = lookup }; h.Start(T0, me); var d = h.Tick(T0, me, true, all, new Nav().Path); Check.True(d.TargetId is 10 or 11, $"the 2 high-XP ones 50 yd off ({d.TargetId})"); Check.True(h.Note.Contains("pack of 2") && h.Note.Contains("(2,000 XP)"), "logged with the pack's XP: " + h.Note); var p = new OutdoorHunt { Pick = OutdoorHunt.PickMode.Pack, XpLookup = lookup }; p.Start(T0, me); Check.True(p.Tick(T0, me, true, all, new Nav().Path).TargetId >= 20, "Biggest pack takes the 4 nearer ones"); } private static void PickXpUnknown() { var me = V(1000, 1000); var all = Sorted(Pack(10, 2, 1050, 1000, me, "Olthoi Slayer").Concat(Pack(20, 4, 1000, 1030, me, "Drudge Skulker"))); var h = new OutdoorHunt { Pick = OutdoorHunt.PickMode.Xp, XpLookup = _ => null }; h.Start(T0, me); Check.True(h.Tick(T0, me, true, all, new Nav().Path).TargetId >= 20, "nothing learned: by size, the 4"); Check.True(h.Note.Contains("no XP learned yet"), "and says so: " + h.Note); var none = new OutdoorHunt { Pick = OutdoorHunt.PickMode.Xp }; // no lookup at all none.Start(T0, me); Check.True(none.Tick(T0, me, true, all, new Nav().Path).TargetId >= 20, "no lookup: by size too"); // Only the Slayers known (1000): the Drudges count as that average, so 4 of them win. var half = new OutdoorHunt { Pick = OutdoorHunt.PickMode.Xp, XpLookup = Xp(("Olthoi Slayer", 1000)) }; half.Start(T0, me); Check.True(half.Tick(T0, me, true, all, new Nav().Path).TargetId >= 20, "an unknown name counts as the known average"); } private static void PickPriorityAndCost() { var me = V(1000, 1000); var all = Sorted(Pack(10, 5, 1020, 1000, me).Append(C(1, 1000, 1050, me, priority: 5))); var h = new OutdoorHunt { Pick = OutdoorHunt.PickMode.Pack }; h.Start(T0, me); var nav = new Nav(); var d = h.Tick(T0, me, true, all, nav.Path); Check.Eq(d.TargetId, 1, "Priority 5 on its own before a Priority 1 pack of 5"); // Twenty monsters about: paths for PickCandidates only. var many = new List(); for (int i = 0; i < 20; i++) many.Add(C(100 + i, 1000 + 5 * i, 1100, me)); var cost = new OutdoorHunt { Pick = OutdoorHunt.PickMode.Pack }; cost.Start(T0, me); var counted = new Nav(); d = cost.Tick(T0, me, true, Sorted(many), counted.Path); Check.Eq(counted.Calls, cost.PickCandidates, "a path for each of the top few only"); int target = d.TargetId; Check.True(target != 0, "one chosen"); // Walking to it: kept, even with a bigger pack turning up. var more = Sorted(many.Concat(Pack(200, 8, 1000, 1010, me))); d = cost.Tick(T0.AddSeconds(2), me, false, more, counted.Path); Check.True(d.Act == OutdoorHunt.Act.None && cost.TargetId == target, $"the target is kept while walking ({d.Act} {cost.TargetId})"); } private static (RynthAiPlugin P, LegacyDashboardRenderer Dash, Action Ra, Func All) HuntRig() { const System.Reflection.BindingFlags Any = System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Public; RynthCore.RynthAiHostTests.Fakes.FakeHost.Reset(); var host = RynthCore.RynthAiHostTests.Fakes.FakeHost.Create(); var p = new RynthAiPlugin(); typeof(RynthCore.PluginCore.RynthPluginBase).GetMethod("Attach", Any)!.Invoke(p, new object[] { RynthCore.RynthAiHostTests.Fakes.FakeHost.LastApi }); var dash = new LegacyDashboardRenderer(host); typeof(RynthAiPlugin).GetField("_dashboard", Any)!.SetValue(p, dash); var chat = RynthCore.RynthAiHostTests.Fakes.FakeHost.Chat; void Ra(string line) { chat.Clear(); string[] parts = line.Split(' ', StringSplitOptions.RemoveEmptyEntries); typeof(RynthAiPlugin).GetMethod("DispatchRaCommand", Any)!.Invoke(p, new object[] { parts[1].ToLowerInvariant(), parts, 0 }); } return (p, dash, Ra, () => string.Join(" | ", chat)); } private static void PickCommand() { var (_, dash, Ra, All) = HuntRig(); Ra("/ra hunt pick"); Check.True(All().Contains("Outdoor hunt pick: Nearest") && All().Contains(RynthAiPlugin.HuntPickUsage), "no word: the choice now and the usage: " + All()); Ra("/ra hunt pick pack"); Check.Eq(dash.Settings.OutdoorHuntPick, 1, "pack = 1"); Check.True(All().Contains("set: Biggest pack"), "and says so: " + All()); Ra("/ra hunt pick xp"); Check.Eq(dash.Settings.OutdoorHuntPick, 2, "xp = 2"); Check.True(All().Contains("set: Most XP"), "and says so: " + All()); Ra("/ra hunt pick most dense"); Check.Eq(dash.Settings.OutdoorHuntPick, 1, "Tom's words work too"); Ra("/ra hunt pick fastest"); Check.Eq(dash.Settings.OutdoorHuntPick, 1, "an unknown word changes nothing"); Check.True(All().Contains("isn't one of nearest, pack or xp") && All().Contains("Biggest pack now") && All().Contains("Usage: /ra hunt pick"), "why, what it is, the usage: " + All()); Ra("/ra hunt pick nearest"); Check.Eq(dash.Settings.OutdoorHuntPick, 0, "back to nearest"); Ra("/ra hunt status"); Check.True(All().Contains("Pick: Nearest"), "status says the pick: " + All()); Ra("/ra hunt nonsense"); Check.True(All().Contains(RynthAiPlugin.HuntPickUsage), "the usage lists it: " + All()); } private static void PickSetting() { Check.Eq(new LegacyUiSettings().OutdoorHuntPick, 0, "Nearest by default"); var ctx = RynthAiJsonContext.Default.LegacyUiSettings; var saved = System.Text.Json.JsonSerializer.Deserialize( System.Text.Json.JsonSerializer.Serialize(new LegacyUiSettings { OutdoorHuntPick = 2 }, ctx), ctx)!; Check.Eq(saved.OutdoorHuntPick, 2, "saved"); var live = new LegacyUiSettings(); typeof(LegacyDashboardRenderer).GetMethod("CopySettings", System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Public)! .Invoke(null, new object[] { saved, live }); Check.Eq(live.OutdoorHuntPick, 2, "copied"); var old = System.Text.Json.JsonSerializer.Deserialize("{\"OutdoorHuntRange\":70}", ctx)!; Check.Eq(old.OutdoorHuntPick, 0, "a profile from before the setting: Nearest"); // The engine's face (SettingsBridgePayload): sent as "OutdoorHuntPick", applied, clamped. var s = new LegacyUiSettings { OutdoorHuntPick = 1 }; var dash = (LegacyDashboardRenderer)System.Runtime.CompilerServices.RuntimeHelpers.GetUninitializedObject(typeof(LegacyDashboardRenderer)); const System.Reflection.BindingFlags F = System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic; typeof(LegacyDashboardRenderer).GetField("_profileLoaded", F)!.SetValue(dash, true); typeof(LegacyDashboardRenderer).GetField("_settings", F)!.SetValue(dash, s); typeof(LegacyDashboardRenderer).GetField("_advancedSettingsUi", F)!.SetValue(dash, new LegacyAdvancedSettingsUi(s)); string json = dash.BuildSettingsJson(); using (var doc = System.Text.Json.JsonDocument.Parse(json)) Check.True(doc.RootElement.TryGetProperty("OutdoorHuntPick", out var pe) && pe.GetInt32() == 1, "sent to the engine as \"OutdoorHuntPick\""); var sent = System.Text.Json.JsonSerializer.Deserialize(json, RynthAiJsonContext.Default.SettingsBridgePayload)!; Check.Eq(sent.OutdoorHuntPick, 1, "in the payload"); dash.ApplySettingsJson("{\"PatrolOnLogin\":false}"); Check.Eq(s.OutdoorHuntPick, 1, "an engine without it leaves it alone"); dash.ApplySettingsJson("{\"OutdoorHuntPick\":2}"); Check.Eq(s.OutdoorHuntPick, 2, "applied: Most XP"); dash.ApplySettingsJson("{\"OutdoorHuntPick\":9}"); Check.Eq(s.OutdoorHuntPick, 2, "9 clamped to 2"); dash.ApplySettingsJson("{\"OutdoorHuntPick\":-3}"); Check.Eq(s.OutdoorHuntPick, 0, "-3 clamped to 0"); } private static void WallBetween() { var me = V(1000, 1000); var h = new OutdoorHunt(); h.Start(T0, me); var nav = new Nav(); nav.Walls[(1010, 1000)] = (V(1008.7, 1000), 1.3); // behind a wall: the walk ends 1.3 yd short, on this side var list = Sorted(C(1, 1010, 1000, me), C(2, 1000, 1030, me)); var d = h.Tick(T0, me, true, list, nav.Path); Check.True(d.Act == OutdoorHunt.Act.Walk && d.TargetId == 1, "walks to the nearer one (its walk ends close enough to count)"); // At the wall: combat can't see through it, so the hunt is asked again and again. var atWall = V(1008.7, 1000); var walks = 0; for (double t = 3; t < 3 + h.NoFightSec - 0.1; t += 0.25) { d = h.Tick(T0.AddSeconds(t), atWall, true, Sorted(C(1, 1010, 1000, atWall), C(2, 1000, 1030, atWall)), nav.Path); if (d.Act == OutdoorHunt.Act.Walk) walks++; } Check.Eq(walks, 0, "no 1 yd walks at the wall"); Check.Eq(h.TargetId, 1, "still its target while combat has the time to take it"); h.ClearNotes(); d = h.Tick(T0.AddSeconds(3.5 + h.NoFightSec), atWall, true, Sorted(C(1, 1010, 1000, atWall), C(2, 1000, 1030, atWall)), nav.Path); Check.True(h.IsSkipped(1, T0.AddSeconds(30)), "left out after NoFightSec"); Check.True(d.Act == OutdoorHunt.Act.Walk && d.TargetId == 2, $"and on to the other one at once: {d.Act} {d.TargetId}"); var notes = string.Join(" | ", h.PendingNotes); Check.True(h.PendingNotes.Count == 2 && h.PendingNotes[0].Contains("wall") && h.PendingNotes[1].StartsWith("next: 'Monster 2'"), "both logged, the why first: " + notes); } private static void RightHere() { var me = V(1000, 1000); var h = new OutdoorHunt(); h.Start(T0, me); var nav = new Nav(); var d = h.Tick(T0, me, true, Sorted(C(1, 1001.5, 1000, me)), nav.Path); Check.True(d.Act == OutdoorHunt.Act.Idle && d.TargetId == 1, $"1.5 yd away: no walk, it stands with it as the target ({d.Act} {d.TargetId})"); d = h.Tick(T0.AddSeconds(1), me, true, Sorted(C(1, 1001.5, 1000, me)), nav.Path); Check.True(d.Act != OutdoorHunt.Act.Walk && !h.IsSkipped(1, T0.AddSeconds(1)), "a second: still waiting for combat"); h.Tick(T0.AddSeconds(h.NoFightSec + 0.6), me, true, Sorted(C(1, 1001.5, 1000, me)), nav.Path); Check.True(h.IsSkipped(1, T0.AddSeconds(h.NoFightSec + 1)), "combat never took it: left out"); } // 2026-11-16, a Thread: under a monster on the floor above, the walk to it was two corners a yard or // so either side of the character, planned again every half second: it turned in circles. private static void EndsHereNoWalk() { var me = V(1000, 1000); var h = new OutdoorHunt(); h.Start(T0, me); var nav = new Nav(); nav.Overrides[(1000.5, 1000)] = new(OutdoorHunt.PathStatus.Ok, new[] { V(1001.2, 1000.8), V(1000.6, 1000.1) }, 2.6, 0); var d = h.Tick(T0, me, true, Sorted(C(1, 1000.5, 1000, me)), nav.Path); Check.True(d.Act != OutdoorHunt.Act.Walk && d.TargetId == 1, $"a 2.6 yd walk ending where it stands: no walk, it stands ({d.Act} {d.TargetId})"); h.Tick(T0.AddSeconds(h.NoFightSec + 0.6), me, true, Sorted(C(1, 1000.5, 1000, me)), nav.Path); Check.True(h.IsSkipped(1, T0.AddSeconds(h.NoFightSec + 1)), "combat never took it: left out, no circling"); } // 2026-11-16 17:11, a Thread: the walk "through its rooms" to a monster on the floor above (3 m up) ended // under it (nav's points count as reached by the flat distance), and the same walk was planned and walked // again every half second for 20 s. private static void FloorApartLeftOut() { var me = V(1000, 1000); var h = new OutdoorHunt { Roam = false }; h.Start(T0, me); var nav = new Nav(); var up = new OutdoorHunt.Vec(1006, 1000, 3.3); nav.Overrides[(1006, 1000)] = new(OutdoorHunt.PathStatus.Ok, new[] { V(1003, 1002), up }, 7.5, 0); // a doorway, then the monster var list = Sorted(new OutdoorHunt.Candidate(1, "Elite Olthoi Ravener", up, up.DistanceTo(me), 1)); var d = h.Tick(T0, me, true, list, nav.Path); Check.Eq(d.Act, OutdoorHunt.Act.Walk, "walks to it"); // Walked: under where it was. It moved 2.5 yd up there, so the walk planned again would end 2 yd off. var under = V(1006.4, 1000.3); var moved = new OutdoorHunt.Vec(1008.5, 1000, 3.3); nav.Overrides[(1008.5, 1000)] = new(OutdoorHunt.PathStatus.Ok, new[] { V(1003, 1002), moved }, 9.5, 0); list = Sorted(new OutdoorHunt.Candidate(1, "Elite Olthoi Ravener", moved, moved.DistanceTo(under), 1)); d = h.Tick(T0.AddSeconds(3), under, true, list, nav.Path); Check.True(d.Act != OutdoorHunt.Act.Walk, $"the walk over, under it: no walk again ({d.Act})"); Check.True(h.IsSkipped(1, T0.AddSeconds(4)), "left out"); var notes = string.Join(" | ", h.PendingNotes); Check.True(notes.Contains("the walk to it ended 3 yd below it"), "says so: " + notes); // Up there with it (the walk took it up the stairs): not left out. var h2 = new OutdoorHunt(); h2.Start(T0, me); h2.Tick(T0, me, true, list, nav.Path); var level = new OutdoorHunt.Vec(1006.4, 1000.3, 3.3); h2.Tick(T0.AddSeconds(3), level, true, Sorted(new OutdoorHunt.Candidate(1, "Elite Olthoi Ravener", up, up.DistanceTo(level), 1)), nav.Path); Check.False(h2.IsSkipped(1, T0.AddSeconds(4)), "level with it: combat's turn, not left out"); } // 2026-11-17 11:13:58, the fort Thread 3073: a Threadbound Rynthid Slayer 68 yd away got a 425 yd walk, up onto // the fort's wall, where the character stuck on a piece of wall and died. private static void TooFarRoundForIt() { var me = V(1000, 1000); var h = new OutdoorHunt { RangeYd = 300, Roam = false }; // Hunt Range big enough that 2x it allows the walk h.Start(T0, me); var nav = new Nav(); nav.Overrides[(1068, 1000)] = new(OutdoorHunt.PathStatus.Ok, new[] { V(1000, 1150), V(1068, 1150), V(1068, 1000) }, 425, 0); var d = h.Tick(T0, me, true, Sorted(C(1, 1068, 1000, me, name: "Threadbound Rynthid Slayer")), nav.Path); Check.True(d.Act != OutdoorHunt.Act.Walk && h.IsSkipped(1, T0.AddSeconds(1)), $"425 yd for 68 yd away: no walk, left out ({d.Act})"); Check.True(string.Join(" | ", h.PendingNotes).Contains("too far round for one 68 yd away"), "says so: " + string.Join(" | ", h.PendingNotes)); // Round a river: 150 yd for one 30 yd away (3 x 30 + 60) is still a walk. var h2 = new OutdoorHunt(); h2.Start(T0, me); nav.Overrides[(1030, 1000)] = new(OutdoorHunt.PathStatus.Ok, new[] { V(1000, 1060), V(1030, 1060), V(1030, 1000) }, 150, 0); d = h2.Tick(T0, me, true, Sorted(C(2, 1030, 1000, me)), nav.Path); Check.True(d.Act == OutdoorHunt.Act.Walk && d.TargetId == 2, $"150 yd round for one 30 yd away: walked ({d.Act} {d.TargetId})"); } // 2026-11-17 11:14, the fort Thread 3073: on the wall top a piece of wall RynthNav's map doesn't hold stuck the walk // five times ("RynthNav sees a clear straight line (the snag isn't on its map)"), and the hunt planned the same // walk through it every 8 s for 90 s. The plugin calls Snagged at the third stuck there. private static void SnaggedSpot() { var me = V(1000, 1000); var h = new OutdoorHunt(); h.Start(T0, me); var nav = new Nav(); var d = h.Tick(T0, me, true, Sorted(C(1, 1050, 1000, me, name: "Threadbound Rynthid Slayer")), nav.Path); Check.True(d.Act == OutdoorHunt.Act.Walk && d.TargetId == 1, "walks to it"); var stuck = V(1020, 1000); h.Snagged(T0.AddSeconds(20), stuck); Check.True(h.IsSkipped(1, T0.AddSeconds(21)) && h.TargetId == 0, "stuck there again and again: left out, no target"); Check.True(string.Join(" | ", h.PendingNotes).Contains("no walk goes by that spot for 10 min"), "says so: " + string.Join(" | ", h.PendingNotes)); // Back from the spot: one beyond it (the walk goes by it) left out; one another way walked to. var back = V(1005, 1000); var list = Sorted(C(2, 1040, 1001, back), C(3, 1005, 1045, back)); d = h.Tick(T0.AddSeconds(22), back, true, list, nav.Path); Check.True(d.Act == OutdoorHunt.Act.Walk && d.TargetId == 3, $"the one beyond the snag left out, the other walked to ({d.Act} {d.TargetId})"); Check.True(h.IsSkipped(2, T0.AddSeconds(23)) && string.Join(" | ", h.PendingNotes).Contains("the walk goes by a spot it got stuck at"), "says why: " + string.Join(" | ", h.PendingNotes)); // Standing at the snag itself: walks from it aren't turned down (it would stand there). var h2 = new OutdoorHunt(); h2.Start(T0, stuck); h2.Snagged(T0, stuck); d = h2.Tick(T0.AddSeconds(1), stuck, true, Sorted(C(4, 1040, 1000, stuck)), nav.Path); Check.True(d.Act == OutdoorHunt.Act.Walk && d.TargetId == 4, $"at the snag: a walk away from it ({d.Act} {d.TargetId})"); // After 10 min the spot is forgotten. var h3 = new OutdoorHunt(); h3.Start(T0, back); h3.Snagged(T0, stuck); d = h3.Tick(T0.AddSeconds(601), back, true, Sorted(C(5, 1040, 1001, back)), nav.Path); Check.True(d.Act == OutdoorHunt.Act.Walk && d.TargetId == 5, $"10 min on: by the spot again ({d.Act} {d.TargetId})"); } // A building whose rooms all join (the walk inside is straight to the goal), for the hunt's own rules. private sealed class OneBuilding : OutdoorHunt.IBuildings { public int BuildingOf(uint cell) => OutdoorHunt.IsIndoorCell(cell) ? 1 : 0; public IReadOnlyList Doors(int building) => new[] { new OutdoorHunt.Door(0xE74E01B8, V(1000, 990), V(1000, 989), V(1000, 988)) }; public OutdoorHunt.PathResult Inside(uint fromCell, OutdoorHunt.Vec from, uint toCell, OutdoorHunt.Vec to) => new(OutdoorHunt.PathStatus.Ok, new[] { to }, from.DistanceTo(to), 0); public string Name(int building) => "building E74E#14"; } // 2026-11-17, Thread E74E: an Elite Umbral Tormentor, an Elite Penumbral Reaver and an Elite Threadbound Shadow // Excruciator on one platform of E74E#14 (cell 01AD) were walked under one after another (10:15 to 10:17), and // each again 120 s later ("It's still trying to chase monsters one floor up, doing circles"). A walk that // ends a floor under a monster in a building's cell now leaves out the cell's other monsters too, for 10 min. private static void FloorApartCellLeftOut() { const uint ground = 0xE74E01B3, platform = 0xE74E01AD, side = 0xE74E01AA; var me = V(1000, 1000); var b = new OneBuilding(); var h = new OutdoorHunt(); h.Start(T0, me); var nav = new Nav(); var up1 = new OutdoorHunt.Vec(1006, 1000, 8.4); var up2 = new OutdoorHunt.Vec(1008, 1001, 8.4); var along = V(1003, 1016); List At(OutdoorHunt.Vec from) => Sorted( new OutdoorHunt.Candidate(1, "Elite Threadbound Shadow Excruciator", up1, up1.DistanceTo(from), 1, platform), new OutdoorHunt.Candidate(2, "Elite Umbral Tormentor", up2, up2.DistanceTo(from), 1, platform), new OutdoorHunt.Candidate(3, "Elite Penumbral Reaver", along, along.DistanceTo(from), 1, side)); var d = h.Tick(T0, me, ground, true, At(me), nav.Path, b); Check.True(d.Act == OutdoorHunt.Act.Walk && d.TargetId == 1, $"walks to the nearest, on the platform ({d.Act} {d.TargetId})"); var under = V(1006.2, 1000.1); d = h.Tick(T0.AddSeconds(3), under, ground, true, At(under), nav.Path, b); Check.True(h.IsSkipped(1, T0.AddSeconds(4)), "the walk ended under it: left out"); Check.True(h.CellSkipped(platform, T0.AddSeconds(4)), "and its cell"); Check.True(string.Join(" | ", h.PendingNotes).Contains("every monster in its cell 01AD for 10 min"), "says so: " + string.Join(" | ", h.PendingNotes)); Check.True(d.TargetId == 3, $"the next is the one on this floor, not the other on the platform ({d.Act} {d.TargetId})"); Check.False(h.CellSkipped(platform, T0.AddSeconds(3 + 601)), "the cell back after 10 min"); // Outdoors (a roof, a ledge): the landscape cell is 24 m across, so only the monster is left out. var h2 = new OutdoorHunt(); h2.Start(T0, me); var roof = new OutdoorHunt.Vec(1006, 1000, 8.4); var list = Sorted(new OutdoorHunt.Candidate(1, "Elite Threadbound Shadow Excruciator", roof, roof.DistanceTo(me), 1, 0xE74E0003)); h2.Tick(T0, me, true, list, nav.Path); h2.Tick(T0.AddSeconds(3), under, true, Sorted(new OutdoorHunt.Candidate(1, "Elite Threadbound Shadow Excruciator", roof, roof.DistanceTo(under), 1, 0xE74E0003)), nav.Path); Check.True(h2.IsSkipped(1, T0.AddSeconds(4)), "outdoors: the monster left out"); Check.False(h2.CellSkipped(0xE74E0003, T0.AddSeconds(4)), "not its landscape cell"); // Circling (10:55:43, 16 s): it moves about up there, each walk planned again is a fresh one and never runs // out. Under it for UnderItSec in all: left out all the same. var h3 = new OutdoorHunt(); h3.Start(T0, me); var plat = new OutdoorHunt.Candidate(1, "Elite Threadbound Shadow Excruciator", up1, up1.DistanceTo(me), 1, platform); h3.Tick(T0, me, ground, true, Sorted(plat), nav.Path, b); bool walkedAgain = false; for (int i = 1; i <= 8; i++) { var at = T0.AddSeconds(1 + i * 0.5); var mon = new OutdoorHunt.Vec(1006 + (i % 2 == 0 ? 2.5 : -2.5), 1000 + (i % 3) * 1.5, 8.4); // moving about up there var mine = new OutdoorHunt.Vec(mon.X + 1, mon.Y - 1, 0); // a step behind it, below var dd = h3.Tick(at, mine, ground, false, Sorted(plat with { Pos = mon, Distance = mon.DistanceTo(mine) }), nav.Path, b); if (i >= 7 && dd.Act == OutdoorHunt.Act.Walk && dd.TargetId == 1) walkedAgain = true; } Check.True(h3.IsSkipped(1, T0.AddSeconds(6)), "circling under it 3 s: left out, the walk not over"); Check.True(h3.CellSkipped(platform, T0.AddSeconds(6)), "and its cell"); Check.False(walkedAgain, "not walked to again after"); } private static void WayBackOut() { var h = new OutdoorHunt(); h.Start(T0, V(990, 1000)); h.Track(V(1000, 1000), indoors: false); // the last spot outdoors, at the doorway for (int x = 1001; x <= 1010; x++) h.Track(V(x, 1000), indoors: true); h.Track(V(1010, 1002), indoors: true); // a fight took it up a side room... h.Track(V(1010, 1004), indoors: true); h.Track(V(1010, 1000.5), indoors: true); // ...and back Check.Eq(h.WayInSteps, 6, "the side room is cut out of the way in (the door and 5 steps)"); var me = V(1010, 1000.5); var d = h.Indoors(T0, me, routeDone: true); Check.Eq(d.Act, OutdoorHunt.Act.Walk, "walks out"); var want = new[] { V(1008, 1000), V(1006, 1000), V(1004, 1000), V(1002, 1000), V(1000, 1000), V(1000 - h.OutPastYd, 1000) }; Check.True(d.Corners!.SequenceEqual(want), "the way in backwards, then out past the doorway: " + string.Join(" ", d.Corners!.Select(c => $"{c.X:0.#},{c.Y:0.#}"))); Check.True(h.WalkingOut && h.Note.Contains("back out"), "walking out: " + h.Note); Check.Eq(h.Indoors(T0.AddSeconds(2), V(1005, 1000), routeDone: false).Act, OutdoorHunt.Act.None, "on the way: keeps walking"); h.Track(V(996, 1000), indoors: false); Check.False(h.WalkingOut, "outdoors again: done"); Check.Eq(h.WayInSteps, 0, "and the way in forgotten"); } private static void IndoorsWaits() { var never = new OutdoorHunt(); never.Start(T0, V(1000, 1000)); never.Track(V(1005, 1000), indoors: true); // never seen outdoors (a reload inside, say) var d = never.Indoors(T0, V(1005, 1000), routeDone: true); Check.Eq(d.Act, OutdoorHunt.Act.Idle, "no way in known: waits"); Check.True(never.Note.Contains("no way out known"), never.Note); var h = new OutdoorHunt(); h.Start(T0, V(990, 1000)); h.Track(V(1000, 1000), indoors: false); h.Track(V(1003, 1000), indoors: true); var t = T0; for (int i = 0; i < h.OutTriesMax; i++) { d = h.Indoors(t, V(1003, 1000), routeDone: true); Check.Eq(d.Act, OutdoorHunt.Act.Walk, $"walk out {i + 1}"); t = t.AddSeconds(5); // It got to the end of the walk and the cell still says indoors. d = h.Indoors(t, d.Corners![^1], routeDone: true); if (i < h.OutTriesMax - 1) Check.Eq(d.Act, OutdoorHunt.Act.Walk, $"ended still inside: again ({i + 2})"); t = t.AddSeconds(5); if (d.Act != OutdoorHunt.Act.Walk) break; } Check.Eq(d.Act, OutdoorHunt.Act.Idle, $"after {h.OutTriesMax} walks out ending inside: waits"); Check.True(h.Note.Contains("ended still inside"), h.Note); } private static readonly DateTime T0 = new(2026, 10, 23, 16, 0, 0); private static OutdoorHunt.Vec V(double x, double y) => new(x, y, 0); private static OutdoorHunt.Candidate C(int id, double x, double y, OutdoorHunt.Vec me, int priority = 1, string? name = null) => new(id, name ?? $"Monster {id}", V(x, y), V(x, y).DistanceTo(me), priority); private sealed class Nav { public readonly Dictionary<(double, double), OutdoorHunt.PathResult> Overrides = new(); /// A wall just in front of a monster: every walk to it ends at end, gap short. public readonly Dictionary<(double, double), (OutdoorHunt.Vec End, double Gap)> Walls = new(); public int Calls; public bool Unavailable; public OutdoorHunt.PathResult Path(OutdoorHunt.Vec a, OutdoorHunt.Vec b) { Calls++; if (Unavailable) return new(OutdoorHunt.PathStatus.Unavailable, Array.Empty(), 0, 0); if (Overrides.TryGetValue((b.X, b.Y), out var o)) return o; if (Walls.TryGetValue((b.X, b.Y), out var w)) return new(OutdoorHunt.PathStatus.Partial, new[] { w.End }, a.DistanceTo(w.End), w.Gap); return new(OutdoorHunt.PathStatus.Ok, new[] { b }, a.DistanceTo(b), 0); } public void Around(double x, double y, double length) => Overrides[(x, y)] = new(OutdoorHunt.PathStatus.Ok, new[] { V(x + 5, y + 5), V(x, y) }, length, 0); } private static List Sorted(params OutdoorHunt.Candidate[] c) => c.OrderBy(x => x.Distance).ToList(); private static void ShortestWalk() { var me = V(1000, 1000); var h = new OutdoorHunt(); h.Start(T0, me); var nav = new Nav(); nav.Around(1010, 1000, 45); // 10 yd away, a building between: a 45 yd walk var list = Sorted(C(1, 1010, 1000, me), C(2, 1000, 1018, me)); var d = h.Tick(T0, me, true, list, nav.Path); Check.Eq(d.Act, OutdoorHunt.Act.Walk, "walks"); Check.Eq(d.TargetId, 2, "to the one 18 yd away in the open, not the one 10 yd away behind the building"); Check.True(h.Note.Contains("18 yd walk"), "logged: " + h.Note); Check.Eq(d.Corners!.Last(), V(1000, 1018), "the walk ends at the monster"); } private static void PriorityFirst() { var me = V(1000, 1000); var h = new OutdoorHunt(); h.Start(T0, me); var nav = new Nav(); var d = h.Tick(T0, me, true, Sorted(C(1, 1005, 1000, me, priority: 1), C(2, 1030, 1000, me, priority: 5)), nav.Path); Check.Eq(d.TargetId, 2, "Priority 5 at 30 yd before Priority 1 at 5 yd"); } private static void Unreachable() { var me = V(1000, 1000); var h = new OutdoorHunt(); h.Start(T0, me); var nav = new Nav(); nav.Overrides[(1008, 1000)] = new(OutdoorHunt.PathStatus.NoPath, Array.Empty(), 0, 0); // up a cliff nav.Overrides[(1012, 1000)] = new(OutdoorHunt.PathStatus.Partial, new[] { V(1004, 1000) }, 4, 8); // in water: the walk ends 8 yd short nav.Overrides[(1020, 1000)] = new(OutdoorHunt.PathStatus.Partial, new[] { V(1018, 1000) }, 18, 2); // on a rock: 2 yd short is close enough var list = Sorted(C(1, 1008, 1000, me), C(2, 1012, 1000, me), C(3, 1020, 1000, me)); var d = h.Tick(T0, me, true, list, nav.Path); Check.Eq(d.TargetId, 3, "the one whose walk ends 2 yd short; the cliff and the water ones are left out"); Check.True(h.IsSkipped(1, T0.AddSeconds(60)) && h.IsSkipped(2, T0.AddSeconds(60)), "left out for a while"); Check.False(h.IsSkipped(1, T0.AddSeconds(h.SkipSec + 1)), "and tried again after SkipSec"); } // 11-12: RynthNav finds the ground up to 64 yd under a goal, so a walk to a monster on a roof ended under it // as an Ok walk, and the character stood there swinging up at it. private static void AboveTheWalk() { var me = V(1000, 1000); var h = new OutdoorHunt(); h.Start(T0, me); var nav = new Nav(); var roof = new OutdoorHunt.Vec(1006, 1000, 8); // on a roof, 8 yd up var below = new OutdoorHunt.Vec(1009, 1000, -6); // the floor below var slope = new OutdoorHunt.Vec(1020, 1000, 8); // up a hillside, 8 yd up nav.Overrides[(1006, 1000)] = new(OutdoorHunt.PathStatus.Ok, new[] { V(1006, 1000) }, 6, 8); nav.Overrides[(1009, 1000)] = new(OutdoorHunt.PathStatus.Ok, new[] { V(1009, 1000) }, 9, 6); nav.Overrides[(1020, 1000)] = new(OutdoorHunt.PathStatus.Ok, new[] { new OutdoorHunt.Vec(1020, 1000, 7.6) }, 22, 0.4); var list = Sorted(new OutdoorHunt.Candidate(1, "Roof", roof, roof.DistanceTo(me), 1), new OutdoorHunt.Candidate(2, "Below", below, below.DistanceTo(me), 1), new OutdoorHunt.Candidate(3, "Hill", slope, slope.DistanceTo(me), 1)); var d = h.Tick(T0, me, true, list, nav.Path); Check.Eq(d.TargetId, 3, "the one up the hillside (the walk ends level with it); not the ones above and below the walk's end"); Check.True(h.IsSkipped(1, T0.AddSeconds(60)) && h.IsSkipped(2, T0.AddSeconds(60)), "the roof and the floor below are left out a while"); var notes = string.Join(" | ", h.PendingNotes); Check.True(notes.Contains("8 yd above the walk's end"), "says it is above: " + notes); Check.True(notes.Contains("6 yd below the walk's end"), "says it is below: " + notes); } private static void Radius() { var start = V(1000, 1000); var h = new OutdoorHunt { RadiusYd = 50, RangeYd = 100 }; h.Start(T0, start); var nav = new Nav(); var me = V(1040, 1000); // hunted out to 40 yd east var d = h.Tick(T0, me, true, Sorted(C(1, 1070, 1000, me), C(2, 1000, 1030, me)), nav.Path); Check.Eq(d.TargetId, 2, "the one 70 yd from the start is outside the 50 yd radius, even though it is closer"); var any = new OutdoorHunt { RadiusYd = 0, RangeYd = 100 }; any.Start(T0, start); Check.Eq(any.Tick(T0, me, true, Sorted(C(1, 1070, 1000, me), C(2, 1000, 1030, me)), nav.Path).TargetId, 1, "radius 0: anywhere, the nearest walk"); } // An open-world Thread's circle, its fence 50 yd round (1000, 1000): a monster past it is no pick, even nearer. private static void FenceHunt() { var h = new OutdoorHunt { Roam = false, RangeYd = 100, Fence = p => (p.X - 1000) * (p.X - 1000) + (p.Y - 1000) * (p.Y - 1000) <= 50 * 50 }; var me = V(1040, 1000); h.Start(T0, me); var nav = new Nav(); var d = h.Tick(T0, me, true, Sorted(C(1, 1060, 1000, me), C(2, 1000, 1030, me)), nav.Path); Check.Eq(d.TargetId, 2, "the one 60 yd from the middle is outside the fence (20 yd off); the one inside is walked to"); var h2 = new OutdoorHunt { Roam = false, RangeYd = 100, Fence = p => (p.X - 1000) * (p.X - 1000) + (p.Y - 1000) * (p.Y - 1000) <= 50 * 50 }; h2.Start(T0, me); var d2 = h2.Tick(T0, me, true, Sorted(C(1, 1060, 1000, me), C(3, 1090, 1000, me)), nav.Path); Check.Eq(d2.TargetId, 0, "every monster outside it: no pick"); Check.True(h2.Note.Contains("inside the fence") && h2.Note.Contains("waiting here"), "it waits and says the fence: " + h2.Note); } // The fence 50 yd round (1000, 1000), walks to 65. The nearer monster's walk swings out to 80 yd from the // middle (round a building): no walk; the other, straight, is walked to. From 70 yd out a walk back in is. private static void FenceWalk() { bool Fence(OutdoorHunt.Vec p) => (p.X - 1000) * (p.X - 1000) + (p.Y - 1000) * (p.Y - 1000) <= 50 * 50; bool WalkFence(OutdoorHunt.Vec me, IReadOnlyList corners) { double Out(OutdoorHunt.Vec v) => Math.Sqrt((v.X - 1000) * (v.X - 1000) + (v.Y - 1000) * (v.Y - 1000)); return corners.All(c => Out(c) <= 65 || Out(c) <= Out(me) + 2); } var me = V(1030, 1000); var h = new OutdoorHunt { RangeYd = 100, Fence = Fence, WalkFence = WalkFence }; h.Start(T0, me); var nav = new Nav(); nav.Overrides[(1040, 1010)] = new(OutdoorHunt.PathStatus.Ok, new[] { V(1080, 1000), V(1040, 1010) }, 70, 0); var d = h.Tick(T0, me, true, Sorted(C(1, 1040, 1010, me), C(2, 1000, 1040, me)), nav.Path); Check.Eq(d.TargetId, 2, "the walk round the outside (80 yd out) is no walk: the other one"); Check.True(string.Join(" | ", h.PendingNotes).Contains("the walk goes out past the fence"), "says why: " + string.Join(" | ", h.PendingNotes)); var outside = V(1070, 1000); // out past the walk radius already var h2 = new OutdoorHunt { RangeYd = 100, Fence = Fence, WalkFence = WalkFence }; h2.Start(T0, outside); var d2 = h2.Tick(T0, outside, true, Sorted(C(3, 1040, 1000, outside)), new Nav().Path); Check.Eq(d2.TargetId, 3, "from outside, the walk back in to one inside is a walk"); } private static void FenceCommandAndCombat() { const System.Reflection.BindingFlags Any = System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Public; RynthCore.RynthAiHostTests.Fakes.FakeHost.Reset(); var host = RynthCore.RynthAiHostTests.Fakes.FakeHost.Create(); var p = new RynthAiPlugin(); typeof(RynthCore.PluginCore.RynthPluginBase).GetMethod("Attach", Any)!.Invoke(p, new object[] { RynthCore.RynthAiHostTests.Fakes.FakeHost.LastApi }); var dash = new LegacyDashboardRenderer(host); typeof(RynthAiPlugin).GetField("_dashboard", Any)!.SetValue(p, dash); var chat = RynthCore.RynthAiHostTests.Fakes.FakeHost.Chat; void Ra(string line) { chat.Clear(); string[] parts = line.Split(' ', StringSplitOptions.RemoveEmptyEntries); typeof(RynthAiPlugin).GetMethod("DispatchRaCommand", Any)!.Invoke(p, new object[] { parts[1].ToLowerInvariant(), parts, 0 }); } string All() => string.Join(" | ", chat); // Landblock 0xA9B4 (x 0xA9 * 192 = 32448, y 0xB4 * 192 = 34560): a fence 80 m round (32500, 34600). RynthCore.RynthAiHostTests.Fakes.FakeHost.PlayerPose = (0xA9B40020, 52f, 40f, 0f); Ra("/ra hunt fence 32500 34600 80"); Check.True(p.HuntFence is { } f && f.X == 32500 && f.Y == 34600 && f.R == 80, "set"); Check.True(All().Contains("Hunt fence: 80.0 m round 32500.0, 34600.0") && All().Contains("you are 0 m from its middle"), "said: " + All()); const uint Inside = 0x7E7E9301, Outside = 0x7E7E9302; RynthCore.RynthAiHostTests.Fakes.FakeHost.Positions[Inside] = (0xA9B40021, 100f, 70f, 0f); // 48, 30 m from the middle RynthCore.RynthAiHostTests.Fakes.FakeHost.Positions[Outside] = (0xA9B40022, 150f, 40f, 0f); // 98 m east Check.False(p.FenceSkipsTarget(unchecked((int)Inside)), "combat: the one inside is a target"); Check.True(p.FenceSkipsTarget(unchecked((int)Outside)), "combat: the one outside is left alone"); Check.True(p.InHuntFence(32500 + 79, 34600) && !p.InHuntFence(32500 + 81, 34600), "the edge at 80 m"); // 2026-11-17 16:40, Thread 32D9: the character outside the fence among the Thread's monsters, all outside it, // fought none and died. Standing 85 m out now: the one beside it, and one no farther out than it (+5 m), are fought. var fieldChecked = typeof(RynthAiPlugin).GetField("_fenceCheckedAt", Any)!; RynthCore.RynthAiHostTests.Fakes.FakeHost.PlayerPose = (0xA9B40020, 137f, 40f, 0f); // 85 m east of the middle fieldChecked.SetValue(p, 0L); const uint Beside = 0x7E7E9303, Level = 0x7E7E9304, FarOut = 0x7E7E9305; RynthCore.RynthAiHostTests.Fakes.FakeHost.Positions[Beside] = (0xA9B40022, 140f, 40f, 0f); // 3 m from it, 88 m out RynthCore.RynthAiHostTests.Fakes.FakeHost.Positions[Level] = (0xA9B40022, 132f, 60f, 0f); // 21 m from it, 82.5 m out RynthCore.RynthAiHostTests.Fakes.FakeHost.Positions[FarOut] = (0xA9B40022, 137f, 80f, 0f); // 40 m from it, 93.9 m out Check.False(p.FenceSkipsTarget(unchecked((int)Beside)), "outside the fence: the one beside it is a target"); Check.False(p.FenceSkipsTarget(unchecked((int)Level)), "and one no farther out than it stands"); Check.True(p.FenceSkipsTarget(unchecked((int)FarOut)), "one farther out is still left alone"); Check.True(p.FenceSkipsTarget(unchecked((int)Outside)), "and one 98 m out, 13 m off"); RynthCore.RynthAiHostTests.Fakes.FakeHost.PlayerPose = (0xA9B40020, 52f, 40f, 0f); Ra("/ra hunt fence"); Check.True(All().Contains("Hunt fence: 80.0 m round"), "no numbers: shows it: " + All()); Ra("/ra hunt fence 1 2"); Check.True(All().Contains("Usage: /ra hunt fence") && p.HuntFence != null, "too few numbers: the usage, the fence kept: " + All()); Ra("/ra hunt fence off"); Check.True(p.HuntFence == null && All().Contains("Hunt fence: off"), "off: cleared: " + All()); Check.False(p.FenceSkipsTarget(unchecked((int)Outside)), "no fence: nothing left alone for it"); // 2026-11-17 16:42: the fence outlived its Thread, and in the next one, a dungeon, every monster was outside it. // In a dungeon, or far from it, the fence is lifted. RynthCore.RynthAiHostTests.Fakes.FakeHost.PlayerPose = (0xA9B40020, 52f, 40f, 0f); Ra("/ra hunt fence 32500 34600 80"); RynthCore.RynthAiHostTests.Fakes.FakeHost.PlayerPose = (0x02890206, 96f, -102f, -42f); // a dungeon's cell fieldChecked.SetValue(p, 0L); Check.False(p.FenceSkipsTarget(unchecked((int)Outside)), "in a dungeon: nothing left alone for the fence"); Check.True(p.HuntFence == null, "and the fence lifted"); Ra("/ra hunt fence 32500 34600 80"); RynthCore.RynthAiHostTests.Fakes.FakeHost.PlayerPose = (0xADB40020, 52f, 40f, 0f); // 768 m east, outdoors fieldChecked.SetValue(p, 0L); Check.True(p.InHuntFence(1, 1) && p.HuntFence == null, "768 m away outdoors: lifted (another place)"); Ra("/ra hunt fence 32500 34600 80"); RynthCore.RynthAiHostTests.Fakes.FakeHost.PlayerPose = (0xAAB40020, 52f, 40f, 0f); // 192 m east: still the place fieldChecked.SetValue(p, 0L); Check.False(p.InHuntFence(1, 1), "192 m away: still fenced (the walk radius and 300 m)"); Check.True(p.HuntFence != null, "the fence kept 192 m away"); } // The fence's combat rule on its own: fought beside the character, or no farther out than it stands (+5 m, up to // the walk radius); left alone farther out. private static void FenceSkipsRule() { var f = (X: 0.0, Y: 0.0, R: 124.4); Check.False(RynthAiPlugin.FenceSkips(f, 139.4, 100, 0, true, 50, 0), "inside the fence: fought"); Check.True(RynthAiPlugin.FenceSkips(f, 139.4, 130, 0, true, 50, 0), "outside, the character well inside: left alone"); Check.False(RynthAiPlugin.FenceSkips(f, 139.4, 130, 0, true, 127, 0), "outside, beside the character (3 m): fought"); Check.False(RynthAiPlugin.FenceSkips(f, 139.4, 125, 30, true, 127, 0), "outside, 30 m off but no farther out (128.5 m): fought"); Check.True(RynthAiPlugin.FenceSkips(f, 139.4, 127, 40, true, 127, 0), "outside, 133 m out with the character at 127: left alone"); Check.False(RynthAiPlugin.FenceSkips(f, 139.4, 20, 137, true, 0, 136), "the character at 136 m: one at 138.4 m, 20 m off, fought"); Check.True(RynthAiPlugin.FenceSkips(f, 139.4, 30, 137, true, 0, 136), "but none past the walk radius (140.2 m), 30 m off"); Check.True(RynthAiPlugin.FenceSkips(f, 139.4, 130, 0, false, 0, 0), "no position for the character: outside is left alone"); } private static void Replan() { var me = V(1000, 1000); var h = new OutdoorHunt(); h.Start(T0, me); var nav = new Nav(); Check.Eq(h.Tick(T0, me, true, Sorted(C(1, 1030, 1000, me)), nav.Path).Act, OutdoorHunt.Act.Walk, "walks to it"); int calls = nav.Calls; // Walking; it moved 2 yd: not worth a new plan. var d = h.Tick(T0.AddSeconds(2), V(1005, 1000), false, Sorted(C(1, 1032, 1000, me)), nav.Path); Check.Eq(d.Act, OutdoorHunt.Act.None, "it moved 2 yd: keep walking"); Check.Eq(nav.Calls, calls, "no path asked for"); // It moved 6 yd: plan again. d = h.Tick(T0.AddSeconds(3), V(1008, 1000), false, Sorted(C(1, 1036, 1000, me)), nav.Path); Check.Eq(d.Act, OutdoorHunt.Act.Walk, "it moved 6 yd: a new walk"); Check.Eq(d.Corners!.Last(), V(1036, 1000), "to where it is now"); // Within a second: not again, even if it moves. d = h.Tick(T0.AddSeconds(3.5), V(1009, 1000), false, Sorted(C(1, 1045, 1000, me)), nav.Path); Check.Eq(d.Act, OutdoorHunt.Act.None, "not twice in a second"); // The walk ran out short of it (the monster still out of combat's reach): plan again. d = h.Tick(T0.AddSeconds(4.2), V(1030, 1000), true, Sorted(C(1, 1036, 1000, me)), nav.Path); Check.Eq(d.Act, OutdoorHunt.Act.Walk, "the walk ran out: again"); // Nothing changed for ReplanMaxSec: again anyway. d = h.Tick(T0.AddSeconds(4.2 + h.ReplanMaxSec + 0.1), V(1030, 1000), false, Sorted(C(1, 1036, 1000, me)), nav.Path); Check.Eq(d.Act, OutdoorHunt.Act.Walk, "a while with no change: again"); } // Tom 10-23: no walk back to the start ("it shouldn't bother"). private static void WaitsWhereItIs() { var start = V(1000, 1000); var h = new OutdoorHunt { RadiusYd = 100, Roam = false }; // roaming off: waits (RoamTests for on) h.Start(T0, start); var nav = new Nav(); var me = V(1060, 1000); h.ClearNotes(); var d = h.Tick(T0, me, true, new List(), nav.Path); Check.Eq(d.Act, OutdoorHunt.Act.Idle, "nothing to hunt, 60 yd from the start: waits there, no walk back"); Check.Eq(nav.Calls, 0, "no path asked for"); Check.True(h.Note.Contains("waiting here") && h.Note.Contains($"({h.RangeYd:0} yd)"), "says why, with Hunt Range: " + h.Note); h.Tick(T0.AddSeconds(2), me, true, new List(), nav.Path); Check.Eq(h.PendingNotes.Count, 1, "said once, not every second"); // A monster comes into range: hunted from there. d = h.Tick(T0.AddSeconds(4), me, true, Sorted(C(7, 1060, 1025, me)), nav.Path); Check.True(d.Act == OutdoorHunt.Act.Walk && d.TargetId == 7, $"a monster turns up: hunted ({d.Act} {d.TargetId})"); Check.Eq(new OutdoorHunt().RadiusYd, 0.0, "Hunt Radius defaults to 0 (anywhere)"); } // ── Roaming (2026-12-01, report R-20261127-181056-32e4: "would be ideal to map out the area and continue // running around the place for more mobs not just stop when it cant see any"; it should move around // the Hunt Radius) ── /// Ticks the hunt with no monsters, walking each walk to its end; the walks' ends, in order. private static List RoamAll(OutdoorHunt h, Nav nav, ref OutdoorHunt.Vec me, ref DateTime t, int maxWalks = 200) { var ends = new List(); bool done = true; for (int i = 0; i < maxWalks * 3 && ends.Count < maxWalks; i++) { t = t.AddSeconds(1.1); var d = h.Tick(t, me, done, new List(), nav.Path); if (d.Act == OutdoorHunt.Act.Walk && d.Corners != null) { me = d.Corners[^1]; ends.Add(me); done = true; // the next tick: arrived } else if (d.Act == OutdoorHunt.Act.Idle) break; } return ends; } private static void RoamWalks() { var start = V(1000, 1000); var h = new OutdoorHunt { RadiusYd = 100 }; h.Start(T0, start); var nav = new Nav(); var d = h.Tick(T0, start, true, new List(), nav.Path); Check.Eq(d.Act, OutdoorHunt.Act.Walk, "nothing in range: it walks on"); Check.True(h.Roaming && d.TargetId == 0, "roaming, no monster target"); Check.True(h.Note.Contains("roaming to"), "says so: " + h.Note); Check.True(d.Corners![^1].FlatDistanceTo(start) <= h.RoamCellYd * 1.5, "to a part right next to the start (nearest first)"); int calls = nav.Calls; d = h.Tick(T0.AddSeconds(0.4), start, false, new List(), nav.Path); Check.Eq(d.Act, OutdoorHunt.Act.None, "on the way: keeps walking (not stopped between picks)"); d = h.Tick(T0.AddSeconds(1.5), start, false, new List(), nav.Path); Check.Eq(d.Act, OutdoorHunt.Act.None, "a pick with still nothing in range: keeps walking, no new walk"); Check.Eq(nav.Calls, calls, "no path asked for while on the way"); var me = V(1010, 990); d = h.Tick(T0.AddSeconds(3), me, false, Sorted(C(7, 1040, 990, me)), nav.Path); Check.True(d.Act == OutdoorHunt.Act.Walk && d.TargetId == 7, $"a monster comes in range: hunted ({d.Act} {d.TargetId})"); Check.False(h.Roaming, "the roam is over"); Check.True(h.PendingNotes.Any(n => n.Contains("the roam ends")), "said so"); } private static void RoamCoversArea() { var start = V(1000, 1000); var h = new OutdoorHunt { RadiusYd = 100 }; h.Start(T0, start); var nav = new Nav(); var me = start; var t = T0; var ends = RoamAll(h, nav, ref me, ref t); Check.True(ends.Count >= 10, $"it walks round the area ({ends.Count} walks)"); Check.True(ends.All(e => e.FlatDistanceTo(start) <= h.RadiusYd), "never outside Hunt Radius"); var seen = new HashSet<(int, int)>(ends.Select(e => h.RoamSquareOf(e))); seen.Add(h.RoamSquareOf(start)); Check.Eq(h.RoamSquaresToSee(t, me).Count, 0, "every part of the area seen"); Check.True(h.Note.Contains("whole area") && h.Note.Contains("waiting here"), "then waits, and says why: " + h.Note); var d = h.Tick(t.AddSeconds(2), me, true, new List(), nav.Path); Check.Eq(d.Act, OutdoorHunt.Act.Idle, "all seen lately: stands"); t = t.AddSeconds(h.RoamRevisitSec + 5); d = h.Tick(t, me, true, new List(), nav.Path); Check.Eq(d.Act, OutdoorHunt.Act.Walk, "5 min on: it looks round again (respawns)"); } private static void RoamUnreachable() { var start = V(1000, 1000); var h = new OutdoorHunt { RadiusYd = 60 }; h.Start(T0, start); var nav = new Nav(); // The nearest part's centre: a wall in the way, every walk to it ends 30 yd short. var first = h.RoamSquaresToSee(T0, start)[0]; var goal = h.RoamSquareCentre(first, start.Z + 30); nav.Walls[(goal.X, goal.Y)] = (V(goal.X - 30, goal.Y), 30); var d = h.Tick(T0, start, true, new List(), nav.Path); Check.Eq(d.Act, OutdoorHunt.Act.Walk, "it still roams"); Check.True(h.RoamSquareOf(d.Corners![^1]) != first, "but not to the part no walk gets to"); Check.False(h.RoamSquaresToSee(T0, start).Contains(first), "that part is left out"); // A walk that stops short (blocked on the way): its part is left out too. var target = d.Corners[^1]; var sq = h.RoamSquareOf(target); var shortOf = V(start.X + (target.X - start.X) * 0.1, start.Y + (target.Y - start.Y) * 0.1); d = h.Tick(T0.AddSeconds(1.2), shortOf, true, new List(), nav.Path); Check.True(h.PendingNotes.Any(n => n.Contains("stopped") && n.Contains("left out")), "said: " + string.Join(" | ", h.PendingNotes)); Check.False(h.RoamSquaresToSee(T0.AddSeconds(1.2), shortOf).Contains(sq), "the part it couldn't get to is left out"); Check.Eq(d.Act, OutdoorHunt.Act.Walk, "and it goes on to another part"); } private static void RoamFenceAndDefaults() { var start = V(1000, 1000); var h = new OutdoorHunt { RadiusYd = 200, Fence = p => p.X >= 1000 }; // only the east half h.Start(T0, start); var nav = new Nav(); var me = start; var t = T0; var ends = RoamAll(h, nav, ref me, ref t); Check.True(ends.Count > 0 && ends.All(e => e.X >= 1000 - h.RoamCellYd * 0.5), "only inside the fence"); var any = new OutdoorHunt { RadiusYd = 0, RangeYd = 150 }; any.Start(T0, start); Check.Eq(any.RoamRadiusYd, 150.0, "Hunt Radius anywhere: it roams Hunt Range round the start"); me = start; t = T0; ends = RoamAll(any, new Nav(), ref me, ref t); Check.True(ends.Count > 0 && ends.All(e => e.FlatDistanceTo(start) <= 150), "and never farther"); var big = new OutdoorHunt { RadiusYd = 2000 }; Check.True(big.RoamCellYd > big.RoamCellMinYd, $"a big area has bigger parts ({big.RoamCellYd:0} yd), not thousands of them"); Check.True(new OutdoorHunt().Roam, "roaming is on by default"); Check.True(new LegacyUiSettings().OutdoorHuntRoam, "and so is the setting"); } // Tom 10-23: "/mt opt set" gave no answer, and "/ra hunt status" toggled the hunt (the command read // the word "hunt" as its argument). The /ra hunt settings answer, and status/stop don't start it. private static void Commands() { const System.Reflection.BindingFlags Any = System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Public; RynthCore.RynthAiHostTests.Fakes.FakeHost.Reset(); var host = RynthCore.RynthAiHostTests.Fakes.FakeHost.Create(); var p = new RynthAiPlugin(); typeof(RynthCore.PluginCore.RynthPluginBase).GetMethod("Attach", Any)!.Invoke(p, new object[] { RynthCore.RynthAiHostTests.Fakes.FakeHost.LastApi }); var dash = new LegacyDashboardRenderer(host); typeof(RynthAiPlugin).GetField("_dashboard", Any)!.SetValue(p, dash); var chat = RynthCore.RynthAiHostTests.Fakes.FakeHost.Chat; void Ra(string line) { chat.Clear(); string[] parts = line.Split(' ', StringSplitOptions.RemoveEmptyEntries); typeof(RynthAiPlugin).GetMethod("DispatchRaCommand", Any)!.Invoke(p, new object[] { parts[1].ToLowerInvariant(), parts, 0 }); } string All() => string.Join(" | ", chat); Ra("/ra hunt range 150"); Check.Eq(dash.Settings.OutdoorHuntRange, 150f, "range set"); Check.True(All().Contains("Outdoor hunt set") && All().Contains("150 yd (Hunt Range)"), "and said: " + All()); Ra("/ra hunt range 2000"); Check.Eq(dash.Settings.OutdoorHuntRange, 2000f, "2000 is allowed (Tom 10-23)"); Ra("/ra hunt range 5000"); Check.Eq(dash.Settings.OutdoorHuntRange, (float)RynthAiPlugin.OutdoorHuntRangeMax, "capped at the most"); Check.True(All().Contains("outside"), "and says it was capped: " + All()); Ra("/ra hunt radius 0"); Check.True(dash.Settings.OutdoorHuntRadius == 0 && All().Contains("anywhere"), "radius 0 = anywhere: " + All()); Ra("/ra hunt range"); Check.True(All().Contains("Hunt Range") && All().Contains("/ra hunt range "), "no number: shows the setting: " + All()); Ra("/ra hunt status"); Check.False(p.HuntActive, "status doesn't start it"); Check.True(All().Contains("Outdoor hunt: off") && All().Contains("Hunt Range"), "status says off, with the distances: " + All()); Ra("/ra hunt stop"); Check.False(p.HuntActive, "stop doesn't start it"); Ra("/ra hunt nonsense"); Check.True(All().Contains("/ra hunt range "), "anything else: the usage: " + All()); Ra("/ra hunt panel"); Check.True((bool)typeof(RynthAiPlugin).GetField("_huntPanelOpen", Any)!.GetValue(p)!, "panel opens the window"); } private static void NextAndNoPathfinder() { var me = V(1000, 1000); var h = new OutdoorHunt(); h.Start(T0, me); var nav = new Nav(); Check.Eq(h.Tick(T0, me, true, Sorted(C(1, 1010, 1000, me), C(2, 1030, 1000, me)), nav.Path).TargetId, 1, "the nearer first"); // It died (combat killed it; it is gone from the list): the next one. var d = h.Tick(T0.AddSeconds(10), V(1009, 1000), true, Sorted(C(2, 1030, 1000, V(1009, 1000))), nav.Path); Check.Eq(d.TargetId, 2, "killed: on to the next"); var none = new OutdoorHunt(); none.Start(T0, me); var gone = new Nav { Unavailable = true }; d = none.Tick(T0, me, true, Sorted(C(1, 1010, 1000, me)), gone.Path); Check.Eq(d.Act, OutdoorHunt.Act.Idle, "RynthNav missing: stands"); Check.Eq(d.Why, "no pathfinder", "and says why"); } private static void FarRound() { var me = V(1000, 1000); var h = new OutdoorHunt { RangeYd = 60 }; h.Start(T0, me); var nav = new Nav(); nav.Around(1012, 1000, 143); // a buff bot inside a building: 12 yd away, a 143 yd walk var d = h.Tick(T0, me, true, Sorted(C(1, 1012, 1000, me), C(2, 1040, 1000, me)), nav.Path); Check.Eq(d.TargetId, 2, "the 143 yd walk (over twice Hunt Range) is too far round: the one 40 yd away instead"); Check.True(h.IsSkipped(1, T0.AddSeconds(30)), "and it is left out for a while (no choosing it again every second)"); Check.True(h.Note.Contains("40 yd walk"), "logged: " + h.Note); // Walking round to the 40 yd one took the character 70 yd from it (past Hunt Range): still its target. var far = V(970, 1000); var c2 = new OutdoorHunt.Candidate(2, "Monster 2", V(1040, 1000), 70, 1); d = h.Tick(T0.AddSeconds(2), far, false, new List { c2 }, nav.Path); Check.True(d.Act != OutdoorHunt.Act.Idle && h.TargetId == 2, $"kept at 70 yd (Hunt Range 60): {d.Act}, target {h.TargetId}"); } private static void Settings() { var s = new LegacyUiSettings(); // 2026-10-25 (Tom: "the entire radar range"): 192, the radar's default range (was 60). Check.Eq(s.OutdoorHuntRange, 192f, "Hunt Range defaults to 192 yd, the radar's range"); Check.Eq(new OutdoorHunt().RangeYd, 192.0, "and the hunt's own default too"); Check.Eq(s.OutdoorHuntRadius, 0f, "Hunt Radius defaults to 0 (anywhere)"); var ctx = RynthAiJsonContext.Default.LegacyUiSettings; var saved = System.Text.Json.JsonSerializer.Deserialize( System.Text.Json.JsonSerializer.Serialize(new LegacyUiSettings { OutdoorHuntRange = 90, OutdoorHuntRadius = 250 }, ctx), ctx)!; var live = new LegacyUiSettings(); typeof(LegacyDashboardRenderer).GetMethod("CopySettings", System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Public)! .Invoke(null, new object[] { saved, live }); Check.True(live.OutdoorHuntRange == 90 && live.OutdoorHuntRadius == 250, "saved and copied"); // A file saved before 10-23 evening still has "OutdoorHuntReturn": it loads (the setting is gone). var old = System.Text.Json.JsonSerializer.Deserialize("{\"OutdoorHuntRange\":70,\"OutdoorHuntRadius\":2000,\"OutdoorHuntReturn\":true}", ctx); Check.True(old != null && old.OutdoorHuntRange == 70 && old.OutdoorHuntRadius == 2000, "an old file with Back To Start loads"); } }