feat: SK backlog from test through 2026.11.22.48 (Trade Shop, Oracle, quests, loot, nav)
Squash of test/main-merge-2026-10-25 onto aelrynth main 2026.11.19.1 for the standing sk PR. Includes Trade Shop, Oracle wiki/ILT tracker, quest runs, loot checklist, RynthNav, VTank import. HandWrittenVersion remains 0.5.0-legacy-ui. See Changelog/2026-11-22-sk-backlog-test-merge.md.
This commit is contained in:
parent
660e6b5b1c
commit
dc08e1abba
521 changed files with 47247 additions and 795 deletions
143
Tools/RynthNav.RouteTests/CustomPortalTests.cs
Normal file
143
Tools/RynthNav.RouteTests/CustomPortalTests.cs
Normal file
|
|
@ -0,0 +1,143 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using RynthCore.Plugin.RynthNav;
|
||||
using RynthNav.Routing;
|
||||
|
||||
namespace RynthNav.RouteTests;
|
||||
|
||||
// Custom-server portals (CustomPortals.cs, 2026-10-29): a scan writes the portal objects down per
|
||||
// server, taking one learns its landing, and only this server's portals with both ends on the map
|
||||
// reach the route planner.
|
||||
internal static partial class Program
|
||||
{
|
||||
private static void RunCustomPortals()
|
||||
{
|
||||
Run(nameof(CustomScanAddsAndSkipsBuiltIn), CustomScanAddsAndSkipsBuiltIn);
|
||||
Run(nameof(CustomLandingMakesARouteLink), CustomLandingMakesARouteLink);
|
||||
Run(nameof(CustomPortalsArePerServer), CustomPortalsArePerServer);
|
||||
Run(nameof(CustomPortalRoutesATrip), CustomPortalRoutesATrip);
|
||||
Run(nameof(CustomPortalsRoundTrip), CustomPortalsRoundTrip);
|
||||
Run(nameof(CustomForgetAndClear), CustomForgetAndClear);
|
||||
Run(nameof(KnownPortalTakenAgainIsNotRelearned), KnownPortalTakenAgainIsNotRelearned);
|
||||
RunDungeonWalks();
|
||||
RunGems();
|
||||
RunGemDungeons();
|
||||
RunDungeonPaths();
|
||||
RunWalkDoors();
|
||||
}
|
||||
|
||||
private static readonly DateTime T0 = new(2026, 10, 29, 12, 0, 0, DateTimeKind.Utc);
|
||||
private const string Ilt = "Infinite Leaftide", Other = "Coldeve";
|
||||
|
||||
private static List<PortalLink> BuiltIn() => new() { new PortalLink(10.0, 20.0, 50.0, 60.0, "Portal to Holtburg") };
|
||||
|
||||
private static void CustomScanAddsAndSkipsBuiltIn()
|
||||
{
|
||||
var s = new CustomPortalStore();
|
||||
Check(s.Saw(Ilt, "Leaftide Event Portal", 70001, 0xA9B40001, true, 30.0, 40.0, BuiltIn(), T0) == CustomScanResult.Added, "a new portal is added");
|
||||
Check(s.Saw(Ilt, "Leaftide Event Portal", 70001, 0xA9B40001, true, 30.0, 40.01, BuiltIn(), T0) == CustomScanResult.Updated, "seen again a couple of metres off: the same one");
|
||||
Check(s.For(Ilt).Count == 1, "one saved");
|
||||
Check(Math.Abs(s.For(Ilt)[0].Ew - 40.01) < 1e-9, "the live spot replaces the first sighting");
|
||||
Check(s.Saw(Ilt, "Portal to Holtburg", 0, 0xA9B40001, true, 10.0, 20.01, BuiltIn(), T0) == CustomScanResult.BuiltIn, "portals.tsv already routes the Holtburg portal");
|
||||
Check(s.Saw(Ilt, "Mystery Portal", 0, 0xA9B40001, true, 10.01, 20.0, BuiltIn(), T0) == CustomScanResult.BuiltIn, "any portal right on a portals.tsv one is that one");
|
||||
Check(s.Saw(Ilt, "Dungeon Portal", 0, 0x01D90123, false, 0, 0, BuiltIn(), T0) == CustomScanResult.OffMap, "a portal inside a dungeon isn't mapped");
|
||||
Check(s.For(Ilt).Count == 1 && s.Links(Ilt).Count == 0, "scanned only: no landing yet, so no route link");
|
||||
}
|
||||
|
||||
private static void CustomLandingMakesARouteLink()
|
||||
{
|
||||
var s = new CustomPortalStore();
|
||||
s.Saw(Ilt, "Leaftide Event Portal", 70001, 0xA9B40001, true, 30.0, 40.0, BuiltIn(), T0);
|
||||
CustomPortal? p = s.Learned(Ilt, "Leaftide Event Portal", 70001, 0xA9B40001, 30.0, 40.0, true, -12.346, 7.891, 0x7D640012, BuiltIn(), T0);
|
||||
Check(p != null && p.Routable, "a landing on the map: routable");
|
||||
List<PortalLink> links = s.Links(Ilt);
|
||||
Check(links.Count == 1 && links[0].Name == "Leaftide Event Portal", "one route link");
|
||||
Near(links[0].DstNs, -12.35, 1e-9, "landing rounded to the hundredth");
|
||||
|
||||
CustomPortal? d = s.Learned(Ilt, "Hidden Vault Portal", 0, 0xA9B40001, 31.0, 41.0, false, 0, 0, 0x01D90123, BuiltIn(), T0);
|
||||
Check(d != null && d.DestKnown && !d.Routable, "an unscanned portal into a dungeon: added and kept, not routed");
|
||||
Check(s.Links(Ilt).Count == 1, "still one route link");
|
||||
Check(s.Learned(Ilt, "Portal to Holtburg", 0, 0xA9B40001, 10.0, 20.0, true, 50, 60, 0, BuiltIn(), T0) == null, "a portals.tsv portal isn't learned again");
|
||||
}
|
||||
|
||||
private static void CustomPortalsArePerServer()
|
||||
{
|
||||
var s = new CustomPortalStore();
|
||||
s.Learned(Ilt, "Leaftide Event Portal", 0, 0xA9B40001, 30.0, 40.0, true, 1, 2, 0, null, T0);
|
||||
Check(s.Links(Ilt).Count == 1, "on its own server");
|
||||
Check(s.Links(Other).Count == 0 && s.For(Other).Count == 0, "never on another server");
|
||||
Check(s.Links("infinite leaftide").Count == 1, "the server name is matched without case");
|
||||
}
|
||||
|
||||
private static void CustomPortalRoutesATrip()
|
||||
{
|
||||
// Far apart on foot; the custom portal stands beside the start and lands beside the goal.
|
||||
var s = new CustomPortalStore();
|
||||
s.Learned(Ilt, "Leaftide Express", 0, 0, 0.0, 0.05, true, 40.0, 40.0, 0, null, T0);
|
||||
var portals = new List<PortalLink>(BuiltIn());
|
||||
portals.AddRange(s.Links(Ilt));
|
||||
List<RouteStep> steps = PortalRoute.Plan(portals, null, 0, 0, 40.1, 40.0, out double est, out int used);
|
||||
Check(used == 1 && steps.Count >= 2 && steps[0].UsePortal && steps[0].Label == "Leaftide Express", "the plan takes the custom portal");
|
||||
Check(est < NavCoords.Distance(0, 0, 40.1, 40.0) / 4, "and it's far cheaper than the walk");
|
||||
List<RouteStep> without = PortalRoute.Plan(BuiltIn(), null, 0, 0, 40.1, 40.0, out _, out int usedWithout);
|
||||
Check(usedWithout == 0 || without.TrueForAll(x => x.Label != "Leaftide Express"), "another server's plan never has it");
|
||||
}
|
||||
|
||||
private static void CustomPortalsRoundTrip()
|
||||
{
|
||||
var s = new CustomPortalStore();
|
||||
s.Saw(Ilt, "Scanned Only", 123, 0xA9B40001, true, 30.5, 40.25, null, T0);
|
||||
s.Learned(Ilt, "Leaftide Event Portal", 70001, 0xA9B40001, 30.0, 40.0, true, -12.34, 7.89, 0x7D640012, null, T0);
|
||||
s.Learned(Other, "Vault", 0, 0xA9B40001, 31.0, 41.0, false, 0, 0, 0x01D90123, null, T0);
|
||||
var back = CustomPortalStore.Parse(s.Serialize());
|
||||
Check(back.For(Ilt).Count == 2 && back.For(Other).Count == 1, "both servers' portals come back");
|
||||
Check(back.Links(Ilt).Count == 1 && back.Links(Other).Count == 0, "the same route links");
|
||||
CustomPortal p = back.For(Ilt)[1];
|
||||
Check(p.Name == "Leaftide Event Portal" && p.Wcid == 70001 && p.Cell == 0xA9B40001 && p.DestCell == 0x7D640012, "name, wcid and cells");
|
||||
Near(p.DestNs, -12.34, 1e-9, "landing NS");
|
||||
Check(p.LearnedUtc == T0 && back.For(Ilt)[0].LearnedUtc == default, "learned time, and none for the scanned one");
|
||||
Check(!back.For(Ilt)[0].DestKnown, "the scanned one has no landing");
|
||||
Check(CustomPortalStore.Parse("# comment\nbroken line\n\t\t\n").For(Ilt).Count == 0, "junk lines are skipped");
|
||||
}
|
||||
|
||||
private static void CustomForgetAndClear()
|
||||
{
|
||||
var s = new CustomPortalStore();
|
||||
s.Saw(Ilt, "Event Portal A", 0, 0, true, 1, 1, null, T0);
|
||||
s.Saw(Ilt, "Event Portal B", 0, 0, true, 5, 5, null, T0);
|
||||
s.Saw(Ilt, "Vault", 0, 0, true, 9, 9, null, T0);
|
||||
s.Saw(Other, "Event Portal C", 0, 0, true, 1, 1, null, T0);
|
||||
int v = s.Version;
|
||||
Check(s.Forget(Ilt, "event") == 2 && s.For(Ilt).Count == 1, "forget by part of the name");
|
||||
Check(s.Version > v, "a change bumps the version (saved)");
|
||||
Check(s.For(Other).Count == 1, "another server's untouched");
|
||||
Check(s.Clear(Ilt) == 1 && s.For(Ilt).Count == 0, "clear the server");
|
||||
}
|
||||
|
||||
// 2026-11-01: every portal a route took said "learned portal ..." and rewrote the file and the
|
||||
// route hub, though it and its landing were known. Known + same landing: nothing is written.
|
||||
private static void KnownPortalTakenAgainIsNotRelearned()
|
||||
{
|
||||
var s = new CustomPortalStore();
|
||||
CustomPortal? p = s.Learned(Ilt, "Portal to Sanamar", 42835, 0xA9B40001, 30.0, 40.0, true, 72.07, -60.9, 0x33D90015, null, T0);
|
||||
Check(p != null && s.LastLearn == CustomLearnResult.New, "the first time: learned");
|
||||
int v = s.Version;
|
||||
s.Learned(Ilt, "Portal to Sanamar", 42835, 0xA9B40001, 30.0, 40.0, true, 72.08, -60.91, 0x33D90015, null, T0.AddHours(1));
|
||||
Check(s.LastLearn == CustomLearnResult.AlreadyKnown && s.Version == v, "taken again, same landing (a few yards off): already known, nothing written");
|
||||
s.Learned(Ilt, "Portal to Sanamar", 42835, 0xA9B40001, 30.0, 40.0, true, 10.0, 10.0, 0x11110001, null, T0.AddHours(2));
|
||||
Check(s.LastLearn == CustomLearnResult.LandingChanged && s.Version > v && s.For(Ilt).Count == 1, "a new landing: updated, still one portal");
|
||||
|
||||
CustomPortal d = s.LearnedInDungeon(Ilt, "AC Storage Portal", 6844, 0x01C901E2, 79.9, -106.2, -6.06, false, 0, 0, 0x01110108, true, 10, -10, 0, T0);
|
||||
Check(s.LastLearn == CustomLearnResult.New, "a dungeon portal: learned");
|
||||
v = s.Version;
|
||||
s.LearnedInDungeon(Ilt, "AC Storage Portal", 6844, 0x01C901E2, 79.9, -106.2, -6.06, false, 0, 0, 0x01110109, true, 11, -9, 0, T0.AddHours(1));
|
||||
Check(s.LastLearn == CustomLearnResult.AlreadyKnown && s.Version == v, "taken again, landing 1.4 m off in the same dungeon: already known");
|
||||
s.LearnedInDungeon(Ilt, "AC Storage Portal", 6844, 0x01C901E2, 79.9, -106.2, -6.06, false, 0, 0, 0x02220108, true, 11, -9, 0, T0.AddHours(2));
|
||||
Check(s.LastLearn == CustomLearnResult.LandingChanged, "another dungeon: updated");
|
||||
|
||||
s.Saw(Ilt, "Portal to Sanamar", 42835, 0xA9B40001, true, 30.0, 40.0, null, T0.AddHours(3));
|
||||
int before = s.Version;
|
||||
s.Saw(Ilt, "Portal to Sanamar", 42835, 0xA9B40001, true, 30.0, 40.0, null, T0.AddHours(4));
|
||||
Check(s.Version == before, "a scan seeing a saved portal where it was: nothing written");
|
||||
}
|
||||
}
|
||||
79
Tools/RynthNav.RouteTests/DungeonPathTests.cs
Normal file
79
Tools/RynthNav.RouteTests/DungeonPathTests.cs
Normal file
|
|
@ -0,0 +1,79 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using RynthCore.Plugin.RynthNav;
|
||||
using RynthNav.Routing;
|
||||
|
||||
namespace RynthNav.RouteTests;
|
||||
|
||||
// Planned dungeon walks (2026-10-29): with a dungeon pathfinder (RynthAi's, from the dats) the route
|
||||
// hub gets a planned walk from each learned arrival to each portal of that dungeon whose landing is
|
||||
// known, so a route can use a portal nobody walked to from there.
|
||||
internal static partial class Program
|
||||
{
|
||||
private static void RunDungeonPaths()
|
||||
{
|
||||
Run(nameof(PathfinderFillsMissingWalks), PathfinderFillsMissingWalks);
|
||||
Run(nameof(PathfinderMakesEntriesAndChains), PathfinderMakesEntriesAndChains);
|
||||
Run(nameof(TripWalkAfterARecallIntoADungeon), TripWalkAfterARecallIntoADungeon);
|
||||
}
|
||||
|
||||
/// <summary>A fake pathfinder: a dog-leg through (ax, by) - the walls are the test's business.</summary>
|
||||
private static int _pathCalls;
|
||||
private static DungeonWay? DogLeg(uint lb, double ax, double ay, double az, double bx, double by, double bz)
|
||||
{
|
||||
_pathCalls++;
|
||||
return new DungeonWay(new[] { ax, ay, az, ax, by, az, bx, by, bz });
|
||||
}
|
||||
|
||||
private static void PathfinderFillsMissingWalks()
|
||||
{
|
||||
CustomPortalStore s = MineStore();
|
||||
// A second mine portal, taken once from somewhere else (no walk from the arrival): Dark Isle.
|
||||
s.LearnedInDungeon(Ilt, "Dark Isle", 0, 0x01C901F2, 116.4, -32.6, -6.06, true, 84.7, 58.2, 0xC8E9000B, false, 0, 0, 0, T0);
|
||||
TownNet without = TownNet.Merge(null, s, Ilt, MineAtlas);
|
||||
Check(!without.Exits.Exists(x => x.Name == "Dark Isle"), "without the pathfinder: no walk to it, so not routed");
|
||||
_pathCalls = 0;
|
||||
TownNet net = TownNet.Merge(null, s, Ilt, MineAtlas, DogLeg);
|
||||
int dark = net.Exits.FindIndex(x => x.Name == "Dark Isle");
|
||||
int arrival = net.LearnedArrivalByCell(0, MineArrivalCell);
|
||||
TownNetWalk? w = dark >= 0 ? net.Walk(arrival, dark) : null;
|
||||
Check(w != null && w.Planned && w.Points.Length == 3, "a planned walk from the arrival to the Dark Isle portal");
|
||||
Check(net.Walk(arrival, net.Exits.FindIndex(x => x.Name == "Snowy Valley Portal")) is { Planned: false }, "a walked walk stays the walked one");
|
||||
Check(net.PlannedWalks() == 1 && _pathCalls == 1, "only the missing pair is asked for");
|
||||
HubLinks hub = net.Links(0, false, null);
|
||||
List<RouteStep> steps = PortalRoute.Plan(new List<PortalLink>(), null, hub, 34.95, 54.5, 84.8, 58.2, out _, out int used);
|
||||
Check(used == 2 && steps[1].IsHub && net.Exits[steps[1].HubExit].Name == "Dark Isle", "a route through the mine to Dark Isle by the planned walk");
|
||||
}
|
||||
|
||||
private static void PathfinderMakesEntriesAndChains()
|
||||
{
|
||||
CustomPortalStore s = MineStore();
|
||||
// A map portal into the mine landing 40 m from the walked arrival; a mine portal into vault 02AA (landing spot known, never walked there).
|
||||
s.Learned(Ilt, "Side Door", 0, 0xA9B40001, 10.0, 10.0, false, 0, 0, 0x01C90240, true, 40, -60, 0, null, T0);
|
||||
s.LearnedInDungeon(Ilt, "Vault Door", 0, 0x01C90241, 90, -10, 0, false, 0, 0, 0x02AA0105, true, 5, 5, 0, T0);
|
||||
s.LearnedInDungeon(Ilt, "Vault Exit", 0, 0x02AA0106, 25, 5, 0, true, -40.0, -40.0, 0x2A2A0012, false, 0, 0, 0, T0);
|
||||
TownNet net = TownNet.Merge(null, s, Ilt, MineAtlas, DogLeg);
|
||||
Check(net.Entries.Exists(e => e.Name == "Side Door" && e.Arrival >= 0), "the side door is an entry at a new arrival");
|
||||
int vault = net.Exits.FindIndex(x => x.Name == "Vault Door");
|
||||
Check(vault >= 0 && net.Exits[vault].DestArrival >= 0, "the vault door chains to an arrival in the vault");
|
||||
Check(net.Walk(net.Exits[vault].DestArrival, net.Exits.FindIndex(x => x.Name == "Vault Exit")) is { Planned: true }, "and on to the vault's exit, planned");
|
||||
Check(net.Exits.Find(x => x.Name == "Vault Exit")?.Hub == "Vault Door", "a dungeon only reached from another is named by the portal into it");
|
||||
Check(TownNet.PlaceOfPortal("AC Storage Portal") == "AC Storage" && TownNet.PlaceOfPortal("Portal to Lighthouse") == "Lighthouse", "portal names to place names");
|
||||
HubLinks hub = net.Links(0, false, null);
|
||||
List<RouteStep> steps = PortalRoute.Plan(new List<PortalLink>(), null, hub, 10.05, 10.0, -40.1, -40.0, out _, out int used);
|
||||
Check(used == 3 && steps[0].UsePortal && steps[1].IsHub && steps[2].IsHub, $"side door, through the mine, through the vault ({string.Join(" / ", steps.ConvertAll(z => z.Label))})");
|
||||
}
|
||||
|
||||
private static void TripWalkAfterARecallIntoADungeon()
|
||||
{
|
||||
TownNet net = TownNet.Merge(null, MineStore(), Ilt, MineAtlas);
|
||||
int arrival = net.LearnedArrivalByCell(0, MineArrivalCell);
|
||||
var gem = new RecallOption { Name = "Abandoned Mines Portal Sending Gem (gem)", Command = "/mt usei x", CastSeconds = 3, ToArrival = arrival };
|
||||
HubLinks hub = net.Links(0, false, null);
|
||||
List<RouteStep> steps = PortalRoute.Plan(new List<PortalLink>(), new List<RecallLink> { gem.ToLink() }, hub, -60, 60, 85.4, -8.8, out _, out _);
|
||||
var trip = new PlannedTrip(3, steps, "goal", 85.4, -8.8, true, WorldPt.FromMap(-60, 60), 0x11110001,
|
||||
new List<TripRecall> { new(gem.Name, 0, gem.Command, 3, arrival) });
|
||||
Check(steps[0].UseRecall && steps[1].IsHub, "gem then the mine");
|
||||
Check(trip.HubWalk(1, net, out string why) is { Count: 3 }, $"the trip knows the walk from where the gem lands ({why})");
|
||||
}
|
||||
}
|
||||
144
Tools/RynthNav.RouteTests/DungeonWalkTests.cs
Normal file
144
Tools/RynthNav.RouteTests/DungeonWalkTests.cs
Normal file
|
|
@ -0,0 +1,144 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using RynthCore.Plugin.RynthNav;
|
||||
using RynthNav.Routing;
|
||||
|
||||
namespace RynthNav.RouteTests;
|
||||
|
||||
// Walks inside dungeons (2026-10-29): the way walked from a landing to a dungeon portal is kept with
|
||||
// that portal's landing, and TownNet.Merge makes the dungeon a hub the planner routes through, one
|
||||
// dungeon into the next too.
|
||||
internal static partial class Program
|
||||
{
|
||||
private static void RunDungeonWalks()
|
||||
{
|
||||
Run(nameof(TrailCutsLoops), TrailCutsLoops);
|
||||
Run(nameof(DungeonWalksRoundTrip), DungeonWalksRoundTrip);
|
||||
Run(nameof(DungeonWalkKeepsTheShorter), DungeonWalkKeepsTheShorter);
|
||||
Run(nameof(LearnedDungeonRoutesATrip), LearnedDungeonRoutesATrip);
|
||||
Run(nameof(LearnedDungeonsChain), LearnedDungeonsChain);
|
||||
Run(nameof(LearnedDungeonsArePerServer), LearnedDungeonsArePerServer);
|
||||
}
|
||||
|
||||
private const uint HubCell = 0x01D90101, VaultCell = 0x02AA0105;
|
||||
|
||||
private static DungeonWalk Walk(uint cell, double ax, double ay, string exit, double ex, double ey, params double[] mid)
|
||||
{
|
||||
var pts = new List<double> { ax, ay, 0 };
|
||||
for (int i = 0; i + 1 < mid.Length; i += 2) { pts.Add(mid[i]); pts.Add(mid[i + 1]); pts.Add(0); }
|
||||
pts.Add(ex); pts.Add(ey); pts.Add(0);
|
||||
return new DungeonWalk
|
||||
{
|
||||
Landblock = cell >> 16, ArrivalCell = cell, ArrivalX = ax, ArrivalY = ay, FromLanding = true,
|
||||
ExitName = exit, ExitCell = cell, ExitX = ex, ExitY = ey, Points = pts.ToArray(), LearnedUtc = T0,
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>Leaftide Hub: a map portal at 0N 0.05E into dungeon 01D9, landing (10, 10); its "Portal to Far Town" at (30, 10) lands at 40N 40E.</summary>
|
||||
private static CustomPortalStore HubStore(string server = Ilt)
|
||||
{
|
||||
var s = new CustomPortalStore();
|
||||
s.Learned(server, "Portal to Leaftide Hub", 0, 0xA9B40001, 0.0, 0.05, false, 0, 0, HubCell, true, 10, 10, 0, null, T0);
|
||||
s.LearnedInDungeon(server, "Portal to Far Town", 0, HubCell, 30, 10, 0, true, 40.0, 40.0, 0x7D640012, false, 0, 0, 0, T0);
|
||||
Check(s.AddWalk(server, Walk(HubCell, 10, 10, "Portal to Far Town", 30, 10, 20, 12)), "the walk is kept");
|
||||
return s;
|
||||
}
|
||||
|
||||
private static void TrailCutsLoops()
|
||||
{
|
||||
var t = new DungeonTrail();
|
||||
t.Start(HubCell, 0, 0, 0, fromLanding: true);
|
||||
for (int x = 1; x <= 6; x++) t.Add(x, 0, 0);
|
||||
Check(t.Count == 7, "out along a corridor: a point a metre");
|
||||
t.Add(6, 3, 0); t.Add(3, 3, 0);
|
||||
t.Add(2.2, 0.3, 0); // back beside the second point: the loop goes
|
||||
Check(t.Count == 2, $"coming back cuts the loop (left {t.Count})");
|
||||
t.Add(1.5, 0.2, 0);
|
||||
Check(t.Count == 2, "less than a metre on: nothing added");
|
||||
double[] to = t.To(5, 0, 0);
|
||||
Check(to.Length == 9 && to[6] == 5, "the portal's centre ends it");
|
||||
t.Add(0.1, 0.1, 0);
|
||||
Check(t.Count == 2, "beside the first point: within a step of the last one, so nothing changes");
|
||||
}
|
||||
|
||||
private static void DungeonWalksRoundTrip()
|
||||
{
|
||||
CustomPortalStore s = HubStore();
|
||||
s.SawInDungeon(Ilt, "Untried Portal", 5, HubCell, 50, 50, 1.5, T0);
|
||||
CustomPortalStore back = CustomPortalStore.Parse(s.Serialize(), s.SerializeWalks());
|
||||
Check(back.For(Ilt).Count == 3, "portals come back");
|
||||
CustomPortal entry = back.For(Ilt)[0], exit = back.For(Ilt)[1], untried = back.For(Ilt)[2];
|
||||
Check(entry.OnMap && entry.DestKnown && !entry.DestOnMap && entry.DestHasPos && entry.DestX == 10, "the map portal's dungeon landing spot");
|
||||
Check(!exit.OnMap && exit.X == 30 && exit.DestOnMap && exit.DestNs == 40, "the dungeon portal: where it stands, where it lands");
|
||||
Check(!untried.OnMap && !untried.DestKnown && untried.Z == 1.5, "an untried dungeon portal");
|
||||
Check(back.WalksFor(Ilt).Count == 1 && back.WalksFor(Ilt)[0].Count == 3, "the walk and its points");
|
||||
Near(back.WalksFor(Ilt)[0].Length, s.WalksFor(Ilt)[0].Length, 0.05, "its length");
|
||||
Check(CustomPortalStore.Parse("x\ty\t1\t0\t1\t2\t-\n").For("x").Count == 1, "an old line (no dungeon fields) still reads");
|
||||
}
|
||||
|
||||
private static void DungeonWalkKeepsTheShorter()
|
||||
{
|
||||
CustomPortalStore s = HubStore();
|
||||
Check(!s.AddWalk(Ilt, Walk(HubCell, 10.5, 10, "Portal to Far Town", 30, 10, 20, 30, 25, 30)), "a longer walk between the same ends isn't kept");
|
||||
Check(s.AddWalk(Ilt, Walk(HubCell, 10.5, 10, "Portal to Far Town", 30, 10)), "a shorter one replaces it");
|
||||
Check(s.WalksFor(Ilt).Count == 1 && s.WalksFor(Ilt)[0].Count == 2, "one walk, the straight one");
|
||||
Check(s.AddWalk(Ilt, Walk(HubCell, 60, 60, "Portal to Far Town", 30, 10)), "from another arrival: a second walk");
|
||||
Check(s.WalksFor(Ilt).Count == 2, "two walks");
|
||||
}
|
||||
|
||||
private static void LearnedDungeonRoutesATrip()
|
||||
{
|
||||
CustomPortalStore s = HubStore();
|
||||
TownNet net = TownNet.Merge(null, s, Ilt);
|
||||
var (e, x, w) = net.LearnedCounts();
|
||||
Check(e == 1 && x == 1 && w == 1, $"one entry, one exit, one walk ({e}/{x}/{w})");
|
||||
Check(net.Contains(0x01D9), "the dungeon is part of the hub");
|
||||
Check(net.Exits[0].Hub == "Portal to Leaftide Hub", "named by the portal into it");
|
||||
HubLinks hub = net.Links(0, false, null);
|
||||
Check(hub.Entries.Count == 1 && hub.Exits.Count == 1, "the planner sees them");
|
||||
List<RouteStep> steps = PortalRoute.Plan(BuiltIn(), null, hub, 0, 0, 40.1, 40.0, out double est, out int used);
|
||||
Check(used == 2 && steps.Count == 3 && steps[0].UsePortal && steps[1].IsHub && !steps[2].UsePortal,
|
||||
$"walk to the entry, through the dungeon, walk on ({string.Join(" / ", steps.ConvertAll(z => z.Label))})");
|
||||
Check(est < NavCoords.Distance(0, 0, 40.1, 40) / 4, "far cheaper than walking");
|
||||
|
||||
var trip = new PlannedTrip(1, steps, "goal", 40.1, 40.0, true, WorldPt.FromMap(0, 0), 0xA9B40001, null);
|
||||
List<WorldPt>? inside = trip.HubWalk(1, net, out string why);
|
||||
Check(inside != null && inside.Count == 3, $"the trip's walk inside is the learned one ({why})");
|
||||
Check(PlannedTrip.HubExitPoint(net, steps[1]) is WorldPt p && Math.Abs(p.X - (0x01 * 192.0 + 30)) < 1e-6, "its exit portal's spot");
|
||||
|
||||
Check(TownNet.Merge(null, HubStore(), "").Exits.Count == 0, "no server: nothing learned is added");
|
||||
CustomPortalStore noWalk = new();
|
||||
noWalk.Learned(Ilt, "Portal to Leaftide Hub", 0, 0xA9B40001, 0.0, 0.05, false, 0, 0, HubCell, true, 10, 10, 0, null, T0);
|
||||
Check(TownNet.Merge(null, noWalk, Ilt).Entries.Count == 0, "an entry with nothing walked inside isn't routed");
|
||||
}
|
||||
|
||||
private static void LearnedDungeonsChain()
|
||||
{
|
||||
CustomPortalStore s = HubStore();
|
||||
// The hub's "Portal to Deep Vault" at (10, 30) lands in dungeon 02AA at (5, 5); its "Vault Exit" at (25, 5) lands at 40S 40W.
|
||||
s.LearnedInDungeon(Ilt, "Portal to Deep Vault", 0, HubCell, 10, 30, 0, false, 0, 0, VaultCell, true, 5, 5, 0, T0);
|
||||
s.AddWalk(Ilt, Walk(HubCell, 10, 10, "Portal to Deep Vault", 10, 30));
|
||||
s.LearnedInDungeon(Ilt, "Vault Exit", 0, VaultCell, 25, 5, 0, true, -40.0, -40.0, 0x2A2A0012, false, 0, 0, 0, T0);
|
||||
s.AddWalk(Ilt, Walk(VaultCell, 5, 5, "Vault Exit", 25, 5));
|
||||
TownNet net = TownNet.Merge(null, s, Ilt);
|
||||
int deep = net.Exits.FindIndex(z => z.Name == "Portal to Deep Vault");
|
||||
Check(deep >= 0 && net.Exits[deep].DestArrival >= 0, "the portal into the vault lands at the vault's arrival");
|
||||
HubLinks hub = net.Links(0, false, null);
|
||||
Check(hub.Exits.Count == 3, "three exits planned with");
|
||||
List<RouteStep> steps = PortalRoute.Plan(BuiltIn(), null, hub, 0, 0, -40.1, -40.0, out _, out int used);
|
||||
Check(steps.Count == 4 && steps[0].UsePortal && steps[1].IsHub && steps[2].IsHub && double.IsNaN(steps[1].LandNs),
|
||||
$"entry, the hub to the vault, the vault out, walk ({string.Join(" / ", steps.ConvertAll(z => z.Label))})");
|
||||
Check(used == 3, "three teleports");
|
||||
Check(net.Exits[steps[1].HubExit].Name == "Portal to Deep Vault" && net.Exits[steps[2].HubExit].Name == "Vault Exit", "in that order");
|
||||
var trip = new PlannedTrip(2, steps, "goal", -40.1, -40.0, true, WorldPt.FromMap(0, 0), 0xA9B40001, null);
|
||||
Check(trip.HubWalk(2, net, out string why) is { Count: 2 }, $"the chained step's walk starts at the vault's arrival ({why})");
|
||||
}
|
||||
|
||||
private static void LearnedDungeonsArePerServer()
|
||||
{
|
||||
CustomPortalStore s = HubStore(Ilt);
|
||||
Check(TownNet.Merge(null, s, Other).Exits.Count == 0, "another server never routes through them");
|
||||
TownNet t = TownNet.Merge(null, s, "infinite leaftide");
|
||||
Check(t.Exits.Count == 1, "the server matched without case");
|
||||
}
|
||||
}
|
||||
122
Tools/RynthNav.RouteTests/GemDungeonTests.cs
Normal file
122
Tools/RynthNav.RouteTests/GemDungeonTests.cs
Normal file
|
|
@ -0,0 +1,122 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using RynthCore.Plugin.RynthNav;
|
||||
using RynthNav.Routing;
|
||||
|
||||
namespace RynthNav.RouteTests;
|
||||
|
||||
// A gem or recall into a dungeon RynthNav learned walks in (2026-10-29): it lands at that dungeon's
|
||||
// arrival and the route goes on through the dungeon's portals; standing in one, the plan walks to
|
||||
// its portals. The Abandoned Mine (01C9) case from Infinite Leaftide's logs.
|
||||
internal static partial class Program
|
||||
{
|
||||
private static void RunGemDungeons()
|
||||
{
|
||||
Run(nameof(GemNameFindsTheDungeon), GemNameFindsTheDungeon);
|
||||
Run(nameof(GemIntoLearnedDungeonRoutesOut), GemIntoLearnedDungeonRoutesOut);
|
||||
Run(nameof(StartInLearnedDungeonWalksOut), StartInLearnedDungeonWalksOut);
|
||||
Run(nameof(AtlasPortalIntoLearnedDungeonIsAnEntry), AtlasPortalIntoLearnedDungeonIsAnEntry);
|
||||
Run(nameof(RecallSpotKeepsDungeonPosition), RecallSpotKeepsDungeonPosition);
|
||||
}
|
||||
|
||||
private const uint MineArrivalCell = 0x01C9022D;
|
||||
|
||||
private static readonly Atlas MineAtlas = Atlas.Parse(@"{""locations"":[
|
||||
{""name"":""Abandoned Mine"",""type"":""Dungeon"",""ns"":34.9,""ew"":54.51,""cell"":""C3AB0000"",""place"":""outdoor"",""lb"":""01C9"",""id"":296},
|
||||
{""name"":""Abandoned Mine"",""type"":""Portal"",""wcid"":1595,""cell"":""C3AB0000"",""place"":""outdoor"",""ns"":34.9,""ew"":54.51,""dest"":{""cell"":""01C9022D"",""place"":""dungeon"",""name"":""Abandoned Mine""},""id"":4242},
|
||||
{""name"":""Timaru"",""type"":""Town"",""ns"":-47.0,""ew"":-24.0,""cell"":""1A2B0000"",""place"":""outdoor"",""id"":9}
|
||||
],""recalls"":[]}");
|
||||
|
||||
/// <summary>01C9 learned: from its arrival (72.9, -30.2) walks to "Snowy Valley Portal" (lands 85.3N 8.8W) and "Vaulted Dungeons" (into 596A).</summary>
|
||||
private static CustomPortalStore MineStore()
|
||||
{
|
||||
var s = new CustomPortalStore();
|
||||
s.LearnedInDungeon(Ilt, "Snowy Valley Portal", 0, 0x01C901F2, 116.4, -27.5, -6.06, true, 85.3, -8.8, 0x11110001, false, 0, 0, 0, T0);
|
||||
s.AddWalk(Ilt, new DungeonWalk
|
||||
{
|
||||
Landblock = 0x01C9, ArrivalCell = MineArrivalCell, ArrivalX = 72.9, ArrivalY = -30.2, FromLanding = true,
|
||||
ExitName = "Snowy Valley Portal", ExitCell = 0x01C901F2, ExitX = 116.4, ExitY = -27.5, ExitZ = -6.06,
|
||||
Points = new double[] { 72.9, -30.2, 0, 100, -30, -6.06, 116.4, -27.5, -6.06 }, LearnedUtc = T0,
|
||||
});
|
||||
return s;
|
||||
}
|
||||
|
||||
private static void GemNameFindsTheDungeon()
|
||||
{
|
||||
Check(GemPlanner.PlaceInName("Abandoned Mines Portal Sending Gem") == "Abandoned Mines", "the place in the name");
|
||||
Check(GemPlanner.PlaceInName("Unlimited Dark Island Portal Gem") == "Dark Island", "lead and trailing words dropped");
|
||||
Check(GemPlanner.Norm("Abandoned Mines") == GemPlanner.Norm("Abandoned Mine"), "Mines = Mine");
|
||||
Check(GemPlanner.GuessFromName("Abandoned Mines Portal Sending Gem", MineAtlas, out RecallSpot? s, out string what)
|
||||
&& s is { OnMap: false, Cell: MineArrivalCell } && what == "Abandoned Mine", "the Abandoned Mine, landing where its portal does");
|
||||
Check(GemPlanner.GuessFromName("Timaru Portal Sending Gem", MineAtlas, out RecallSpot? t, out _) && t is { OnMap: true, Ns: -47.0 }, "a town by name");
|
||||
Check(!GemPlanner.GuessFromName("Rune of Dispel", MineAtlas, out _, out _), "nothing for a name that matches no place");
|
||||
}
|
||||
|
||||
private static void GemIntoLearnedDungeonRoutesOut()
|
||||
{
|
||||
TownNet net = TownNet.Merge(null, MineStore(), Ilt, MineAtlas);
|
||||
int arrival = net.LearnedArrivalByCell(0, MineArrivalCell);
|
||||
Check(arrival >= 0, "the mine's arrival is learned");
|
||||
Check(net.Exits.Exists(x => x.Hub == "Abandoned Mine"), "the learned dungeon is named from the Atlas");
|
||||
ArrivalResolver of = (cell, hasPos, x, y, z) => hasPos ? net.LearnedArrival(0, cell >> 16, x, y, z) : net.LearnedArrivalByCell(0, cell);
|
||||
var notes = new List<string>();
|
||||
List<RecallOption> gems = GemPlanner.Build(new List<PackGem> { Gem(500, "Abandoned Mines Portal Sending Gem", 0) },
|
||||
MineAtlas, new RecallMemory(), "c", new GemMemory(), Ilt, 240, notes, of);
|
||||
Check(gems.Count == 1 && gems[0].ToArrival == arrival && gems[0].Via.StartsWith("guessed"), $"the gem lands at the mine's arrival ({string.Join("; ", notes)})");
|
||||
HubLinks hub = net.Links(0, false, null);
|
||||
List<RouteStep> steps = PortalRoute.Plan(new List<PortalLink>(), RecallPlanner.Links(gems), hub, -60, 60, 85.4, -8.8, out double est, out int used);
|
||||
Check(steps.Count == 3 && steps[0].UseRecall && steps[1].IsHub && net.Exits[steps[1].HubExit].Name == "Snowy Valley Portal",
|
||||
$"gem, then through the mine to the Snowy Valley Portal ({string.Join(" / ", steps.ConvertAll(z => z.Label))})");
|
||||
Check(used == 2 && est < NavCoords.Distance(-60, 60, 85.4, -8.8) / 10, "and far cheaper than walking");
|
||||
|
||||
// Learned by using it (a landing with a position) beats the guess.
|
||||
var learned = new GemMemory();
|
||||
learned.Set(Ilt, 500, "Abandoned Mines Portal Sending Gem", new RecallSpot { OnMap = false, Cell = MineArrivalCell, HasPos = true, X = 73.1, Y = -30.0, Label = "a dungeon (landblock 01C9)" });
|
||||
List<RecallOption> g2 = GemPlanner.Build(new List<PackGem> { Gem(500, "Abandoned Mines Portal Sending Gem", 0) },
|
||||
MineAtlas, new RecallMemory(), "c", learned, Ilt, 240, null, of);
|
||||
Check(g2.Count == 1 && g2[0].Via == "learned" && g2[0].ToArrival == arrival, "learned landing in the dungeon");
|
||||
|
||||
var none = GemPlanner.Build(new List<PackGem> { Gem(500, "Abandoned Mines Portal Sending Gem", 0) }, MineAtlas, new RecallMemory(), "c", new GemMemory(), Ilt, 240, notes, null);
|
||||
Check(none.Count == 0 && notes.Exists(n => n.Contains("way out")), "with no learned walks: left out, saying a way out is needed");
|
||||
}
|
||||
|
||||
private static void StartInLearnedDungeonWalksOut()
|
||||
{
|
||||
TownNet net = TownNet.Merge(null, MineStore(), Ilt, MineAtlas);
|
||||
HubLinks hub = net.Links(0, false, null);
|
||||
var walks = new double[hub.Exits.Count];
|
||||
for (int i = 0; i < walks.Length; i++)
|
||||
{
|
||||
List<TownNetPoint>? way = net.WayTo(hub.Exits[i].Id, 74, -30, HubWalker.OffRouteUnits, out _);
|
||||
walks[i] = way == null ? double.NaN : TownNet.PathLength(way, 0);
|
||||
}
|
||||
TravelPlan.Result r = TravelPlan.Plan(new List<PortalLink>(), new List<RecallLink>(), hub, true, true, false,
|
||||
0, 0, 85.4, -8.8, null, null, "goal", walks);
|
||||
Check(r.Refusal.Length == 0 && r.Steps != null && r.Steps[0].IsHub, $"no recall needed: walk to the portal and take it ({r.Refusal})");
|
||||
TravelPlan.Result none = TravelPlan.Plan(new List<PortalLink>(), new List<RecallLink>(), hub, true, true, false,
|
||||
0, 0, 85.4, -8.8, null, null, "goal", null);
|
||||
Check(none.Refusal.Length > 0, "without the walks, still refused (the old behaviour)");
|
||||
}
|
||||
|
||||
private static void AtlasPortalIntoLearnedDungeonIsAnEntry()
|
||||
{
|
||||
TownNet net = TownNet.Merge(null, MineStore(), Ilt, MineAtlas);
|
||||
Check(net.Entries.Exists(e => e.Name == "Abandoned Mine" && e.Learned && Math.Abs(e.Ns - 34.9) < 1e-9), "the world data's Abandoned Mine portal enters the learned mine");
|
||||
HubLinks hub = net.Links(0, false, null);
|
||||
List<RouteStep> steps = PortalRoute.Plan(new List<PortalLink>(), null, hub, 34.95, 54.5, 85.4, -8.8, out _, out int used);
|
||||
Check(used == 2 && steps[0].UsePortal && steps[1].IsHub, "walk into it, through the mine, out by Snowy Valley");
|
||||
}
|
||||
|
||||
private static void RecallSpotKeepsDungeonPosition()
|
||||
{
|
||||
var m = new RecallMemory();
|
||||
m.Set("ILT|Kelp", RecallSlot.LastPortal, new RecallSpot { OnMap = false, Label = "a dungeon (landblock 01C9)", Cell = MineArrivalCell, HasPos = true, X = 72.9, Y = -30.2, Z = 0 });
|
||||
RecallSpot? back = RecallMemory.Parse(m.Serialize()).Get("ILT|Kelp", RecallSlot.LastPortal);
|
||||
Check(back is { OnMap: false, Cell: MineArrivalCell, HasPos: true, X: 72.9 }, "a dungeon landing keeps its cell and spot");
|
||||
TownNet net = TownNet.Merge(null, MineStore(), Ilt, MineAtlas);
|
||||
ArrivalResolver of = (cell, hasPos, x, y, z) => hasPos ? net.LearnedArrival(0, cell >> 16, x, y, z) : net.LearnedArrivalByCell(0, cell);
|
||||
var known = new HashSet<int> { RecallPlanner.PortalRecall };
|
||||
List<RecallOption> r = RecallPlanner.Build(MineAtlas, known, m, "ILT|Kelp", null, of);
|
||||
Check(r.Exists(o => o.SpellId == RecallPlanner.PortalRecall && o.ToArrival >= 0), "Portal Recall into the learned mine is routed");
|
||||
}
|
||||
}
|
||||
95
Tools/RynthNav.RouteTests/GemTests.cs
Normal file
95
Tools/RynthNav.RouteTests/GemTests.cs
Normal file
|
|
@ -0,0 +1,95 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using RynthCore.Plugin.RynthNav;
|
||||
using RynthNav.Routing;
|
||||
|
||||
namespace RynthNav.RouteTests;
|
||||
|
||||
// Portal gems in the pack (PackGems.cs, 2026-10-29): a gem is a recall the planner may take, landing
|
||||
// where it was learned to, where its personal recall goes, or where the Atlas's recall of its spell goes.
|
||||
internal static partial class Program
|
||||
{
|
||||
private static void RunGems()
|
||||
{
|
||||
Run(nameof(GemLandingsFromEverySource), GemLandingsFromEverySource);
|
||||
Run(nameof(GemCostsMoreThanTheSpell), GemCostsMoreThanTheSpell);
|
||||
Run(nameof(GemTakenWhenItSavesWalking), GemTakenWhenItSavesWalking);
|
||||
Run(nameof(GemMemoryRoundTrip), GemMemoryRoundTrip);
|
||||
Run(nameof(GemLooksLikeTeleport), GemLooksLikeTeleport);
|
||||
}
|
||||
|
||||
private static readonly Atlas GemAtlas = Atlas.Parse(@"{""locations"":[],""recalls"":[
|
||||
{""spell"":2023,""name"":""Aerlinthe Recall"",""ns"":40.0,""ew"":-40.0},
|
||||
{""spell"":2931,""name"":""Deep Vault Recall"",""in"":""a dungeon""}]}");
|
||||
|
||||
private static PackGem Gem(uint wcid, string name, int spell, int count = 1) => new() { Id = 0x80000000 + wcid, Wcid = wcid, Name = name, SpellId = spell, Count = count };
|
||||
|
||||
private static void GemLandingsFromEverySource()
|
||||
{
|
||||
var mem = new RecallMemory();
|
||||
mem.Set("ILT|Kelp", RecallSlot.Lifestone, new RecallSpot { OnMap = true, Ns = 10, Ew = 10, Label = "Holtburg" });
|
||||
var learned = new GemMemory();
|
||||
learned.Set(Ilt, 900, "Leaftide Town Gem", new RecallSpot { OnMap = true, Ns = -5, Ew = 5, Label = "Leaftide" });
|
||||
var gems = new List<PackGem>
|
||||
{
|
||||
Gem(900, "Leaftide Town Gem", 0, 3),
|
||||
Gem(901, "Gem of Lifestone Recall", RecallPlanner.LifestoneRecall),
|
||||
Gem(902, "Aerlinthe Gem", 2023, 2),
|
||||
Gem(903, "Vault Gem", 2931),
|
||||
Gem(904, "Mystery Gem", 9999),
|
||||
Gem(902, "Aerlinthe Gem", 2023, 5), // a second stack: one option
|
||||
};
|
||||
var notes = new List<string>();
|
||||
List<RecallOption> o = GemPlanner.Build(gems, GemAtlas, mem, "ILT|Kelp", learned, Ilt, 240, notes);
|
||||
Check(o.Count == 3, $"learned, personal and Atlas gems usable ({o.Count})");
|
||||
Check(o.Exists(x => x.ItemWcid == 900 && x.Ns == -5 && x.Via == "learned" && x.ItemCount == 3), "a learned gem");
|
||||
Check(o.Exists(x => x.ItemWcid == 901 && x.Ns == 10), "a lifestone recall gem lands at your lifestone tie");
|
||||
Check(o.Exists(x => x.ItemWcid == 902 && x.Ns == 40 && x.Via == "Aerlinthe Recall"), "an Aerlinthe gem lands where the recall does");
|
||||
Check(o.TrueForAll(x => x.IsGem && x.SpellId == 0 && x.Command.StartsWith("/mt usei ")), "used, not cast; saved routes use /mt usei");
|
||||
Check(notes.Exists(n => n.Contains("Vault Gem") && n.Contains("dungeon")), "a dungeon gem is left out, with a note");
|
||||
Check(notes.Exists(n => n.Contains("Mystery Gem") && n.Contains("use one once")), "an unknown gem says how to learn it");
|
||||
Check(GemPlanner.Build(gems, GemAtlas, mem, "ILT|Kelp", learned, Other, 240, null).Count == 2, "learned landings are per server");
|
||||
}
|
||||
|
||||
private static void GemCostsMoreThanTheSpell()
|
||||
{
|
||||
var spell = new RecallOption { Name = "Aerlinthe Recall", SpellId = 2023, Ns = 40, Ew = -40, CastSeconds = RecallPlanner.SpellCastSeconds };
|
||||
RecallOption gem = GemPlanner.Build(new List<PackGem> { Gem(902, "Aerlinthe Gem", 2023) }, GemAtlas, new RecallMemory(), "c", new GemMemory(), Ilt, 240, null)[0];
|
||||
var links = new List<RecallLink> { gem.ToLink(), spell.ToLink() };
|
||||
List<RouteStep> steps = PortalRoute.Plan(new List<PortalLink>(), links, 0, 0, 40.1, -40, out _, out _);
|
||||
Check(steps.Count > 0 && steps[0].UseRecall && steps[0].RecallIndex == 1, "the spell, which spends nothing, beats the gem to the same place");
|
||||
Check(gem.ToLink().CostUnits > spell.ToLink().CostUnits, "the gem's cost includes what spending it counts as");
|
||||
}
|
||||
|
||||
private static void GemTakenWhenItSavesWalking()
|
||||
{
|
||||
RecallOption gem = GemPlanner.Build(new List<PackGem> { Gem(902, "Aerlinthe Gem", 2023) }, GemAtlas, new RecallMemory(), "c", new GemMemory(), Ilt, 240, null)[0];
|
||||
List<RouteStep> far = PortalRoute.Plan(new List<PortalLink>(), new List<RecallLink> { gem.ToLink() }, 0, 0, 40.1, -40, out _, out int used);
|
||||
Check(used == 1 && far[0].UseRecall && far[0].Label == "Aerlinthe Gem (gem)", "far away: the gem");
|
||||
PortalRoute.Plan(new List<PortalLink>(), new List<RecallLink> { gem.ToLink() }, 40.5, -40, 40.1, -40, out _, out int near);
|
||||
Check(near == 0, "a short walk: the gem is kept");
|
||||
}
|
||||
|
||||
private static void GemMemoryRoundTrip()
|
||||
{
|
||||
var m = new GemMemory();
|
||||
m.Set(Ilt, 900, "Leaftide Town Gem", new RecallSpot { OnMap = true, Ns = -5.5, Ew = 5.25, Label = "Leaftide" });
|
||||
m.Set(Other, 77, "Vault Gem", new RecallSpot { OnMap = false, Label = "a dungeon (landblock 01D9)" });
|
||||
GemMemory back = GemMemory.Parse(m.Serialize());
|
||||
Check(back.Count == 2, "both come back");
|
||||
RecallSpot? a = back.Get("infinite leaftide", 900);
|
||||
Check(a != null && a.OnMap && a.Ns == -5.5 && a.Ew == 5.25 && a.Label == "Leaftide", "a map landing, server matched without case");
|
||||
Check(back.Get(Other, 77) is { OnMap: false }, "a dungeon landing");
|
||||
Check(back.Forget(Ilt, 900) && back.Get(Ilt, 900) == null, "forget");
|
||||
}
|
||||
|
||||
private static void GemLooksLikeTeleport()
|
||||
{
|
||||
var none = new GemMemory();
|
||||
Check(GemPlanner.LooksLikeTeleportItem(GemPlanner.ItemTypeGem, 1234, "Shiny Thing", GemAtlas, none, Ilt, 1), "a gem with a use spell");
|
||||
Check(GemPlanner.LooksLikeTeleportItem(0, 2023, "Odd Stone", GemAtlas, none, Ilt, 2), "anything casting an Atlas recall");
|
||||
Check(GemPlanner.LooksLikeTeleportItem(0, 5555, "Portal Stone to Leaftide", GemAtlas, none, Ilt, 3), "a portal-named item with a spell");
|
||||
Check(!GemPlanner.LooksLikeTeleportItem(0, 5555, "Mana Stone", GemAtlas, none, Ilt, 4), "not a mana stone");
|
||||
Check(!GemPlanner.LooksLikeTeleportItem(GemPlanner.ItemTypeGem, 0, "Diamond", GemAtlas, none, Ilt, 5), "not a plain gem with no spell");
|
||||
}
|
||||
}
|
||||
|
|
@ -56,13 +56,16 @@ internal static partial class Program
|
|||
Run(nameof(DungeonEntrance), DungeonEntrance);
|
||||
Run(nameof(RouteEndsOnAPortalStep), RouteEndsOnAPortalStep);
|
||||
Run(nameof(RealDungeonEntrances), RealDungeonEntrances);
|
||||
Run(nameof(PeopleInsideDungeons), PeopleInsideDungeons);
|
||||
RunTownNet();
|
||||
RunAvoid();
|
||||
RunTravelPlan();
|
||||
RunCustomPortals();
|
||||
RunTripExport();
|
||||
RunAutoRunGate();
|
||||
RunRouteMaker();
|
||||
RunSteering();
|
||||
RunWallStuck();
|
||||
|
||||
Console.WriteLine();
|
||||
Console.WriteLine(_fails == 0 && _asserts > 0
|
||||
|
|
@ -681,6 +684,29 @@ internal static partial class Program
|
|||
}
|
||||
|
||||
// The real location database: dungeons sit at their entrance portal (outside), not inside.
|
||||
/// <summary>2026-11-11: quest people inside dungeons and the Bur: found by name, with the portal or recall in.</summary>
|
||||
private static void PeopleInsideDungeons()
|
||||
{
|
||||
string locs = Path.GetFullPath(Path.Combine(AppContext.BaseDirectory, "..", "..", "..", "..", "..", "..",
|
||||
"RynthCore", "tools", "navdata", "NavData", "locations.json"));
|
||||
if (!File.Exists(locs)) { Console.WriteLine(" (no generated NavData beside this repo: skipped)"); return; }
|
||||
Atlas atlas = Atlas.Load(locs);
|
||||
AtlasLocation? drogur = atlas.FindInside("Drogur");
|
||||
Check(drogur != null && drogur.Cell == "009C0270", $"Drogur is in the Bur ({drogur?.Cell})");
|
||||
AtlasLocation? torg = atlas.FindInside("Torgluuk");
|
||||
Check(torg != null && torg.Name.StartsWith("Torgluuk, High Shaman", StringComparison.Ordinal), $"a first name finds the whole one ({torg?.Name})");
|
||||
Check(atlas.FindInside("Dro") == null || atlas.FindInside("Dro")!.Name.StartsWith("Dro ", StringComparison.OrdinalIgnoreCase), "part of a word is no match");
|
||||
Check(atlas.FindInside("Kor-Gursha") == null, "a portal is never a place inside");
|
||||
Check(atlas.FindInside("Garaena the Emissary") == null, "someone on the map isn't inside");
|
||||
bool burRecall = false;
|
||||
foreach (AtlasRecall r in atlas.Recalls) if (r.Name == "Bur Recall" && !r.OnMap && r.Cell >> 16 == 0x009C) burRecall = true;
|
||||
Check(burRecall, "Bur Recall lands in the Bur's landblock");
|
||||
Check(Entrance.PortalInto(atlas, 0x009C, false, 0, 0) == null, "no portal on the map goes into the Bur (the recall does)");
|
||||
AtlasLocation? cath = Entrance.PortalInto(atlas, 0x02F8, false, 0, 0);
|
||||
Check(cath != null && cath.OnMap && cath.Name == "Burun Cathedral", $"Burun Cathedral's portal leads into 02F8 ({cath?.Name})");
|
||||
Check(Atlas.TryCell("009C0270", out uint c) && c == 0x009C0270u && !Atlas.TryCell("009C", out _), "cells parse");
|
||||
}
|
||||
|
||||
private static void RealDungeonEntrances()
|
||||
{
|
||||
string locs = Path.GetFullPath(Path.Combine(AppContext.BaseDirectory, "..", "..", "..", "..", "..", "..",
|
||||
|
|
|
|||
|
|
@ -24,11 +24,16 @@
|
|||
<Compile Include="..\..\Plugins\RynthCore.Plugin.RynthNav\ArrowGuide.cs" Link="Linked\ArrowGuide.cs" />
|
||||
<Compile Include="..\..\Plugins\RynthCore.Plugin.RynthNav\RecallMemory.cs" Link="Linked\RecallMemory.cs" />
|
||||
<Compile Include="..\..\Plugins\RynthCore.Plugin.RynthNav\RecallPlanner.cs" Link="Linked\RecallPlanner.cs" />
|
||||
<Compile Include="..\..\Plugins\RynthCore.Plugin.RynthNav\PackGems.cs" Link="Linked\PackGems.cs" />
|
||||
<Compile Include="..\..\Plugins\RynthCore.Plugin.RynthNav\NavDataConfig.cs" Link="Linked\NavDataConfig.cs" />
|
||||
<Compile Include="..\..\Plugins\RynthCore.Plugin.RynthNav\Entrance.cs" Link="Linked\Entrance.cs" />
|
||||
<Compile Include="..\..\Plugins\RynthCore.Plugin.RynthNav\TownNet.cs" Link="Linked\TownNet.cs" />
|
||||
<Compile Include="..\..\Plugins\RynthCore.Plugin.RynthNav\WalkDoors.cs" Link="Linked\WalkDoors.cs" />
|
||||
<Compile Include="..\..\Plugins\RynthCore.Plugin.RynthNav\TripFollow.cs" Link="Linked\TripFollow.cs" />
|
||||
<Compile Include="..\..\Plugins\RynthCore.Plugin.RynthNav\WallStuck.cs" Link="Linked\WallStuck.cs" />
|
||||
<Compile Include="..\..\Plugins\RynthCore.Plugin.RynthNav\PortalAvoid.cs" Link="Linked\PortalAvoid.cs" />
|
||||
<Compile Include="..\..\Plugins\RynthCore.Plugin.RynthNav\TravelPlan.cs" Link="Linked\TravelPlan.cs" />
|
||||
<Compile Include="..\..\Plugins\RynthCore.Plugin.RynthNav\CustomPortals.cs" Link="Linked\CustomPortals.cs" />
|
||||
<!-- The goto's autorun, sent when it changes (AutoRunGateTests). -->
|
||||
<Compile Include="..\..\Plugins\RynthCore.Plugin.RynthNav\AutoRunGate.cs" Link="Linked\AutoRunGate.cs" />
|
||||
<!-- The goto's heading servo and path follower (SteeringTests). -->
|
||||
|
|
|
|||
158
Tools/RynthNav.RouteTests/WalkDoorsTests.cs
Normal file
158
Tools/RynthNav.RouteTests/WalkDoorsTests.cs
Normal file
|
|
@ -0,0 +1,158 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using RynthCore.Plugin.RynthNav;
|
||||
|
||||
namespace RynthNav.RouteTests;
|
||||
|
||||
// Dungeon walks through doors, locks, jumps, levels and drops (2026-10-30): which closed door
|
||||
// stands across the walk, which pack items unlock one, the walker's jump before it gives up, a
|
||||
// point on another level not counting as reached, and a drop's edge passed on the way down.
|
||||
internal static partial class Program
|
||||
{
|
||||
private static void RunWalkDoors()
|
||||
{
|
||||
Run(nameof(DoorAcrossTheWalk), DoorAcrossTheWalk);
|
||||
Run(nameof(UnlockersKeysThenPicks), UnlockersKeysThenPicks);
|
||||
Run(nameof(WalkerJumpsBeforeGivingUp), WalkerJumpsBeforeGivingUp);
|
||||
Run(nameof(WalkerKeepsToItsLevel), WalkerKeepsToItsLevel);
|
||||
Run(nameof(WalkerDropsOffALedge), WalkerDropsOffALedge);
|
||||
Run(nameof(DungeonWayCarriesDrops), DungeonWayCarriesDrops);
|
||||
Run(nameof(DoorInFrontWhenBlocked), DoorInFrontWhenBlocked);
|
||||
Run(nameof(FollowKeepsToTheTripPath), FollowKeepsToTheTripPath);
|
||||
Run(nameof(FollowRejoinsAndNeverCutsBack), FollowRejoinsAndNeverCutsBack);
|
||||
}
|
||||
|
||||
// 2026-11-01: a goto over land ran into a town's closed door and only jumped and stepped aside.
|
||||
private static void DoorInFrontWhenBlocked()
|
||||
{
|
||||
// Facing north (0, 1).
|
||||
Check(WalkDoors.InFront(0, 0, 0, 0, 1, 0.5, 3, 0, out double d) && Math.Abs(d - 3.04) < 0.05, "a door 3 m straight ahead");
|
||||
Check(WalkDoors.InFront(0, 0, 0, 0, 1, 2, 2.5, 0, out _), "a door ahead and a little to the side (39 degrees)");
|
||||
Check(!WalkDoors.InFront(0, 0, 0, 0, 1, 3, 1, 0, out _), "a door off to the side (72 degrees) isn't what we ran into");
|
||||
Check(!WalkDoors.InFront(0, 0, 0, 0, 1, 0, -2, 0, out _), "nor one behind");
|
||||
Check(!WalkDoors.InFront(0, 0, 0, 0, 1, 0, 6, 0, out _), "nor one 6 m away");
|
||||
Check(!WalkDoors.InFront(0, 0, 0, 0, 1, 0, 3, 5, out _), "nor one on the floor above");
|
||||
Check(WalkDoors.InFront(0, 0, double.NaN, 0, 1, 0, 3, 5, out _), "height unknown: it counts");
|
||||
Check(WalkDoors.InFront(0, 0, 0, 0, 1, 0.2, -0.2, 0, out _), "standing on it counts");
|
||||
}
|
||||
|
||||
private static WorldPt W(double x, double y) => new(x, y, double.NaN);
|
||||
|
||||
// 2026-11-01: walks planned their own way to the route graph's crossings and wandered off the path the markers drew.
|
||||
private static void FollowKeepsToTheTripPath()
|
||||
{
|
||||
// North 100, then east 100 (an L round a building).
|
||||
var f = new TripFollow(1, 0, new[] { W(0, 0), W(0, 100), W(100, 100) });
|
||||
Near(f.Length, 200, 0.01, "length");
|
||||
var (ax, ay) = f.Aim(0, 10, out double off, out bool end);
|
||||
Check(!end && Math.Abs(off) < 0.01 && Math.Abs(ax) < 0.01 && Math.Abs(ay - (10 + TripFollow.LookAhead)) < 0.01, $"aims {TripFollow.LookAhead} along the path: ({ax:F1}, {ay:F1})");
|
||||
(ax, ay) = f.Aim(0, 90, out _, out _);
|
||||
Check(Math.Abs(ax - (90 + TripFollow.LookAhead - 100)) < 0.01 && Math.Abs(ay - 100) < 0.01, $"round the corner along the path, not across it: ({ax:F1}, {ay:F1})");
|
||||
var f2 = new TripFollow(1, 0, new[] { W(0, 0), W(0, 100), W(100, 100) });
|
||||
(ax, ay) = f2.Aim(3, 50, out off, out _);
|
||||
Check(Math.Abs(off - 3) < 0.01 && Math.Abs(ax) < 0.01 && ay > 50, "3 u to the side still follows the path ahead");
|
||||
f.Aim(90, 100, out _, out end);
|
||||
Check(end, "near the end the aim is the end (the leg's own goal logic takes over)");
|
||||
Near(f.At(150).X, 50, 0.01, "At: half way along the second leg");
|
||||
}
|
||||
|
||||
private static void FollowRejoinsAndNeverCutsBack()
|
||||
{
|
||||
var f = new TripFollow(1, 0, new[] { W(0, 0), W(0, 100), W(100, 100) });
|
||||
f.Aim(0, 40, out _, out _);
|
||||
var (ax, ay) = f.Aim(30, 45, out double off, out _);
|
||||
Check(off > TripFollow.OffPathUnits && Math.Abs(ax) < 0.01 && Math.Abs(ay - (45 + TripFollow.RejoinAhead)) < 0.5, $"30 u off: back to the path just ahead of the nearest point: ({ax:F1}, {ay:F1}), off {off:F0}");
|
||||
Check(f.Progress >= 39.9 && f.Progress < 41, "progress isn't moved by an off-path point");
|
||||
|
||||
// A hairpin: north 100, east 10, south 100. Standing at the start of the way back, the far leg is close by.
|
||||
var h = new TripFollow(2, 0, new[] { W(0, 0), W(0, 100), W(10, 100), W(10, 0) });
|
||||
h.Aim(0, 5, out _, out _);
|
||||
(ax, ay) = h.Aim(5, 6, out off, out _);
|
||||
Check(ay > 6 + 10 && ax < 1, $"halfway between the two legs near the start: still the first leg ahead ({ax:F1}, {ay:F1}), not the way back");
|
||||
Check(h.Progress < 10, "progress stays on the first leg");
|
||||
try { _ = new TripFollow(1, 0, new[] { W(0, 0) }); Check(false, "one point is no walk"); }
|
||||
catch (ArgumentException) { Check(true, ""); }
|
||||
}
|
||||
|
||||
private static TownNetPoint P(double x, double y, double z = 0, bool drop = false) => new() { X = x, Y = y, Z = z, Drop = drop };
|
||||
|
||||
private static void DoorAcrossTheWalk()
|
||||
{
|
||||
// From (0,0) north 6 m, then east 6 m.
|
||||
var ahead = new List<TownNetPoint> { P(0, 6), P(6, 6) };
|
||||
Near(WalkDoors.AlongWalk(0, 0, 0, ahead, false, 0.3, 4, 0), 4, 0.01, "a door in the corridor 4 m ahead");
|
||||
Near(WalkDoors.AlongWalk(0, 0, 0, ahead, false, 3, 6.5, 0), 9, 0.01, "a door round the corner, 9 m along the walk");
|
||||
Check(WalkDoors.AlongWalk(0, 0, 0, ahead, false, 3, 3, 0) < 0, "a door 3 m off to the side isn't across the walk");
|
||||
Check(WalkDoors.AlongWalk(0, 0, 0, new List<TownNetPoint> { P(0, 30) }, false, 0, 20, 0) < 0, "a door 20 m ahead isn't looked at yet");
|
||||
Check(WalkDoors.AlongWalk(0, 0, 0, ahead, true, 0, 4, -8) < 0, "a door on the level below isn't across a walk over levels");
|
||||
Check(WalkDoors.AlongWalk(0, 0, 0, ahead, false, 0, 4, -8) >= 0, "on a one-level walk heights don't count");
|
||||
}
|
||||
|
||||
private static void UnlockersKeysThenPicks()
|
||||
{
|
||||
Check(WalkDoors.UnlockerOf("Key to the Rare Chest") == WalkDoors.Unlocker.Key, "a key");
|
||||
Check(WalkDoors.UnlockerOf("Keyring") == WalkDoors.Unlocker.Key, "a keyring");
|
||||
Check(WalkDoors.UnlockerOf("Reliable Lockpick") == WalkDoors.Unlocker.Lockpick, "a lockpick");
|
||||
Check(WalkDoors.UnlockerOf("Monkey Paw") == WalkDoors.Unlocker.None, "Monkey isn't a key");
|
||||
Check(WalkDoors.UnlockerOf("Keystone Fragment") == WalkDoors.Unlocker.None, "Keystone isn't a key");
|
||||
var order = WalkDoors.TryOrder(new[] { (1u, "Plain Lockpick"), (2u, "Pyreal"), (3u, "Brass Key"), (4u, "Good Lock Pick") });
|
||||
Check(order.Count == 3 && order[0].Id == 3 && order[1].Id == 1 && order[2].Id == 4, "keys first, then lockpicks; other items left out");
|
||||
Check(WalkDoors.IsLockedText("The Iron Door is locked!") && WalkDoors.IsLockedText("The door is locked."), "the server's locked line");
|
||||
Check(!WalkDoors.IsLockedText("Bob says, \"The door is locked!\""), "a player quoting it isn't");
|
||||
}
|
||||
|
||||
private static void WalkerJumpsBeforeGivingUp()
|
||||
{
|
||||
var w = new HubWalker(new List<TownNetPoint> { P(0, 0), P(0, 20) }, -100_000, 0);
|
||||
Check(w.Step(0, 0, 100, out _, out _) == HubWalker.Act.Run, "runs at first");
|
||||
var acts = new List<HubWalker.Act>();
|
||||
for (long t = 200; t <= 9000; t += 100) { var a = w.Step(0, 0, t, out _, out _); if (a != HubWalker.Act.Run) acts.Add(a); if (a == HubWalker.Act.Stop) break; }
|
||||
Check(acts.Count == 3 && acts[0] == HubWalker.Act.Jump && acts[1] == HubWalker.Act.Jump && acts[2] == HubWalker.Act.Stop,
|
||||
$"stuck: jumps twice, then stops ({string.Join(",", acts)})");
|
||||
var w2 = new HubWalker(new List<TownNetPoint> { P(0, 0), P(0, 20) }, -100_000, 0);
|
||||
w2.Step(0, 0, 100, out _, out _);
|
||||
w2.Hold(2000, 2000); // a door opening: not stuck
|
||||
Check(w2.Step(0, 0, 3500, out _, out _) == HubWalker.Act.Run, "holding for a door isn't being stuck");
|
||||
}
|
||||
|
||||
private static void WalkerKeepsToItsLevel()
|
||||
{
|
||||
// Up a ramp that turns back over itself: the second turn is right above the start.
|
||||
var way = new List<TownNetPoint> { P(0, 0, 0), P(0, 10, 3), P(1, 10, 3), P(1, 0, 6), P(1, -5, 6) };
|
||||
var w = new HubWalker(way, -100_000, 0);
|
||||
Check(w.Levels, "a walk over levels");
|
||||
w.Step(0, 9.9, 3, 100, out _, out _); // at the first turn
|
||||
w.Step(1, 9.9, 3, 200, out _, out _); // round it
|
||||
int before = w.Index;
|
||||
// Under the upper turn (1,0,6) at the bottom's height: not reached.
|
||||
w.Step(1, 0.2, 0, 300, out _, out _);
|
||||
Check(w.Index == before, "a point right above isn't reached from the level below");
|
||||
w.Step(1, 0.2, 5.5, 400, out _, out _);
|
||||
Check(w.Index > before, "reached on its own level");
|
||||
var flat = new HubWalker(new List<TownNetPoint> { P(0, 0, 0), P(0, 5, 0.5), P(0, 10, 0) }, -100_000, 0);
|
||||
Check(!flat.Levels, "a one-level walk ignores heights");
|
||||
}
|
||||
|
||||
private static void WalkerDropsOffALedge()
|
||||
{
|
||||
// Walk to a ledge's edge at 10 m high, land 1.5 m on at 2 m, walk on.
|
||||
var way = new List<TownNetPoint> { P(0, 0, 10), P(0, 5, 10, drop: true), P(0, 6.5, 2), P(0, 12, 2) };
|
||||
var w = new HubWalker(way, -100_000, 0);
|
||||
w.Step(0, 4.8, 10, 100, out _, out _);
|
||||
Check(w.Index >= 2, "the edge is reached on the upper level");
|
||||
int i = w.Index;
|
||||
w.Step(0, 6.4, 2.2, 200, out _, out _); // landed below
|
||||
Check(w.Index > i, "the landing is reached on the lower level");
|
||||
var w2 = new HubWalker(way, -100_000, 0);
|
||||
w2.Step(0, 5.2, 4, 100, out _, out _); // falling past the edge
|
||||
Check(w2.Index >= 2, "falling below the edge counts as past it");
|
||||
}
|
||||
|
||||
private static void DungeonWayCarriesDrops()
|
||||
{
|
||||
var dw = new DungeonWay(new double[] { 0, 0, 10, 0, 5, 10, 0, 6.5, 2 }, new[] { false, true, false });
|
||||
TownNetPoint[] pts = dw.ToPoints(0x01230100);
|
||||
Check(pts.Length == 3 && !pts[0].Drop && pts[1].Drop && !pts[2].Drop && pts[2].Z == 2, "the drop's edge is marked on the walker's point");
|
||||
Check(dw.HasDrop && !new DungeonWay(new double[] { 0, 0, 0, 1, 1, 0 }).HasDrop, "HasDrop");
|
||||
}
|
||||
}
|
||||
170
Tools/RynthNav.RouteTests/WallStuckTests.cs
Normal file
170
Tools/RynthNav.RouteTests/WallStuckTests.cs
Normal file
|
|
@ -0,0 +1,170 @@
|
|||
using System;
|
||||
using RynthCore.Plugin.RynthNav;
|
||||
|
||||
namespace RynthNav.RouteTests;
|
||||
|
||||
// Stuck at a wall (2026-11-07, Silentkelpie: "routes are still getting stuck at walls that could be
|
||||
// jumped"). The jump was a tap (the smallest hop) and moved 0.0 u every time; a walk swinging between
|
||||
// headings against a wall never counted as stuck, and then it stood 25 s until the watchdog.
|
||||
internal static partial class Program
|
||||
{
|
||||
private static void RunWallStuck()
|
||||
{
|
||||
Run(nameof(StuckWhileRunning), StuckWhileRunning);
|
||||
Run(nameof(StuckWhileSwingingAgainstAWall), StuckWhileSwingingAgainstAWall);
|
||||
Run(nameof(TurningOnTheSpotIsNotStuckAtOnce), TurningOnTheSpotIsNotStuckAtOnce);
|
||||
Run(nameof(NotTryingToMoveStartsTheWatchAgain), NotTryingToMoveStartsTheWatchAgain);
|
||||
Run(nameof(ChargedJumpThenFullThenStepRound), ChargedJumpThenFullThenStepRound);
|
||||
Run(nameof(TapJumpWithoutChargedJump), TapJumpWithoutChargedJump);
|
||||
Run(nameof(JumpingHardIsFullPowerThreeTimes), JumpingHardIsFullPowerThreeTimes);
|
||||
Run(nameof(JumpFromSkillAndBurden), JumpFromSkillAndBurden);
|
||||
}
|
||||
|
||||
// Runs ticks of 33 ms from t, the character at (x, y), driving each tick (running or turning).
|
||||
private static bool Ticks(StuckWatch w, ref long t, long ms, double x, double y, Func<long, bool> running, out double moved, out long win)
|
||||
{
|
||||
moved = 0; win = 0;
|
||||
for (long end = t + ms; t < end; t += 33)
|
||||
{
|
||||
if (w.Check(t, x, y, out moved, out win)) return true;
|
||||
w.Wanted(t, running(t));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static void StuckWhileRunning()
|
||||
{
|
||||
var w = new StuckWatch();
|
||||
long t = 1000;
|
||||
bool stuck = Ticks(w, ref t, 1500, 10, 10, _ => true, out double moved, out long win);
|
||||
Check(stuck && moved < 0.01 && win >= StuckWatch.RunWindowMs && win < StuckWatch.RunWindowMs + 100, $"running into a wall: stuck after {win} ms");
|
||||
|
||||
// Running on open ground is never stuck.
|
||||
w = new StuckWatch(); t = 1000;
|
||||
bool any = false;
|
||||
for (int i = 0; i < 200; i++, t += 33)
|
||||
{
|
||||
if (w.Check(t, i * 0.15, 0, out _, out _)) any = true; // 4.5 u/s
|
||||
w.Wanted(t, true);
|
||||
}
|
||||
Check(!any, "running on open ground: never stuck");
|
||||
}
|
||||
|
||||
private static void StuckWhileSwingingAgainstAWall()
|
||||
{
|
||||
// 11-07 at Yaraq: run a moment, turn a moment, swinging between headings, not moving. The old
|
||||
// watch started again on every turning tick and never saw it.
|
||||
var w = new StuckWatch();
|
||||
long t = 1000;
|
||||
bool stuck = Ticks(w, ref t, 3500, 5, 5, tt => (tt / 300) % 2 == 0, out double moved, out long win);
|
||||
Check(stuck && win < 2000, $"swinging against a wall (running and turning by turns): stuck after {win} ms, moved {moved:F1}");
|
||||
}
|
||||
|
||||
private static void TurningOnTheSpotIsNotStuckAtOnce()
|
||||
{
|
||||
// A half turn on the spot takes about a second: not stuck. Turning on the spot for 3 s is.
|
||||
var w = new StuckWatch();
|
||||
long t = 1000;
|
||||
bool early = Ticks(w, ref t, 2500, 0, 0, _ => false, out _, out _);
|
||||
Check(!early, "turning on the spot for 2.5 s: not stuck yet");
|
||||
bool late = Ticks(w, ref t, 1000, 0, 0, _ => false, out _, out long win);
|
||||
Check(late && win >= StuckWatch.TurnWindowMs, $"turning on the spot for 3 s: stuck ({win} ms)");
|
||||
}
|
||||
|
||||
private static void NotTryingToMoveStartsTheWatchAgain()
|
||||
{
|
||||
var w = new StuckWatch();
|
||||
long t = 1000;
|
||||
Ticks(w, ref t, 900, 0, 0, _ => true, out _, out _);
|
||||
// Opening a door, waiting for a plan: no drive for half a second.
|
||||
for (long end = t + 600; t < end; t += 33) Check(!w.Check(t, 0, 0, out _, out _), "not driving: never stuck");
|
||||
bool stuck = Ticks(w, ref t, 900, 0, 0, _ => true, out _, out _);
|
||||
Check(!stuck, "running again: a new window (900 ms isn't stuck)");
|
||||
}
|
||||
|
||||
private static void ChargedJumpThenFullThenStepRound()
|
||||
{
|
||||
var j = new WallJump();
|
||||
Check(j.CanTry && !j.Busy, "a new spot: a jump to try");
|
||||
long t = 0;
|
||||
int c1 = j.StartCharged(t);
|
||||
Check(c1 == 700 && j.Now == WallJump.Phase.Charging && j.Tries == 1, $"first jump: charged {c1} ms (a strong jump)");
|
||||
Check(j.Tick(t + 300) == WallJump.Step.Hold, "charging: the key stays down");
|
||||
Check(j.Tick(t + 700) == WallJump.Step.Release && j.Now == WallJump.Phase.Flying, "charged: let go");
|
||||
Check(j.Tick(t + 1100) == WallJump.Step.Hold, "in the air");
|
||||
Check(j.Tick(t + 700 + WallJump.FlightMs) == WallJump.Step.Landed && !j.Busy, "landed: the walk looks again");
|
||||
j.Moved(); // the next window showed progress: it cleared the wall
|
||||
Check(j.Tries == 0 && j.CanTry, "it got over: the next spot gets its jumps again");
|
||||
|
||||
t = 5000;
|
||||
j.StartCharged(t); j.Tick(t + 700); j.Tick(t + 700 + WallJump.FlightMs);
|
||||
int c2 = j.StartCharged(t + 3000);
|
||||
Check(c2 == 1000 && j.Tries == 2, $"still stuck at the same spot: a full jump ({c2} ms)");
|
||||
j.Tick(t + 4000); j.Tick(t + 4000 + WallJump.FlightMs);
|
||||
Check(!j.CanTry, "both jumps tried at this spot: step round it");
|
||||
j.Reset();
|
||||
Check(j.CanTry && j.Tries == 0, "a new leg: jumps again");
|
||||
}
|
||||
|
||||
private static void TapJumpWithoutChargedJump()
|
||||
{
|
||||
var j = new WallJump();
|
||||
j.StartTap(100);
|
||||
Check(j.Now == WallJump.Phase.Flying && j.Charge == 0, "no charged jump in the engine: a tap, already in the air");
|
||||
Check(j.Tick(100 + WallJump.FlightMs) == WallJump.Step.Landed, "the tap lands");
|
||||
}
|
||||
|
||||
// "it should use more power to jump if needed": where the route graph has no walking way on the
|
||||
// same land, every jump is a full one, three at each spot.
|
||||
private static void JumpingHardIsFullPowerThreeTimes()
|
||||
{
|
||||
var j = new WallJump { Hard = true };
|
||||
long t = 0;
|
||||
var charges = new System.Collections.Generic.List<int>();
|
||||
while (j.CanTry)
|
||||
{
|
||||
charges.Add(j.StartCharged(t));
|
||||
j.Tick(t + 1000); j.Tick(t + 1000 + WallJump.FlightMs);
|
||||
t += 3000;
|
||||
}
|
||||
Check(string.Join(",", charges) == "1000,1000,1000", "jumping hard: three full jumps at a spot (" + string.Join(",", charges) + ")");
|
||||
j.Reset();
|
||||
Check(j.Hard && j.CanTry, "a new spot keeps jumping hard; the walk turns it off when a walking way is found");
|
||||
j.Hard = false;
|
||||
Check(j.StartCharged(0) == 700 && j.Plan.Length == 2, "back to walking: a strong jump, then a full one");
|
||||
}
|
||||
|
||||
// "the jump on routes should take your buffed jump into account as well as your burden".
|
||||
private static void JumpFromSkillAndBurden()
|
||||
{
|
||||
var m = new JumpModel(300, 0.5);
|
||||
Near(m.FullHeight, 300 / 1600.0 * 22.2 + 0.05, 1e-9, "Jump 300, half burden: AC's full jump height");
|
||||
Near(m.Height(0.5), m.FullHeight / 2, 1e-9, "half a bar: half the height");
|
||||
Near(new JumpModel(300, 1.5).FullHeight, m.FullHeight * 0.5, 1e-9, "150% burden: half the height");
|
||||
Check(new JumpModel(300, 2.1).TooBurdened && new JumpModel(300, 2.1).PlanFor(1.0, false, out _).Length == 0, "200% burden and over: no jump");
|
||||
Near(new JumpModel(10, 0.1).Height(0.1), 0.35, 1e-9, "never under 0.35 m");
|
||||
|
||||
int c = m.ChargeFor(1.5);
|
||||
Check(c == 450, $"a 1.5 m fence, Jump 300: a 450 ms bar ({c})");
|
||||
int[] p = m.PlanFor(1.5, false, out string why);
|
||||
Check(p.Length == 2 && p[0] == 450 && p[1] == 1000 && why.Contains("1.5 m high"), $"just enough, then a full one ({string.Join(",", p)}: {why})");
|
||||
p = m.PlanFor(5.0, false, out why);
|
||||
Check(p.Length == 0 && why.Contains("your jump clears about"), $"a 5 m wall: no jump, step round ({why})");
|
||||
Check(new JumpModel(300, 1.6).PlanFor(2.0, false, out _).Length == 0 && m.PlanFor(2.0, false, out _).Length == 2,
|
||||
"the same 2 m wall: jumped light, not at 160% burden");
|
||||
p = m.PlanFor(double.NaN, false, out _);
|
||||
Check(p.Length == 2 && p[0] >= 700 && p[1] == 1000, $"height not known: a strong jump, then a full one ({string.Join(",", p)})");
|
||||
Check(string.Join(",", m.PlanFor(double.NaN, true, out _)) == "1000,1000,1000", "not known, jumping hard: three full ones");
|
||||
Check(!new JumpModel(0, 0.2).Known, "no skill read: not known (the default jumps)");
|
||||
|
||||
var j = new WallJump();
|
||||
j.SetSpot(new[] { 450, 1000 });
|
||||
Check(j.StartCharged(0) == 450, "the spot's plan is used");
|
||||
j.Tick(450); j.Tick(450 + WallJump.FlightMs);
|
||||
j.Moved();
|
||||
Check(j.Plan.Length == 2 && j.Plan[0] == 700, "moved on: the next spot plans again");
|
||||
j.SetSpot(System.Array.Empty<int>());
|
||||
Check(!j.CanTry, "nothing clears it: no jump, step round");
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in a new issue