RynthSuite/Tools/RynthNav.RouteTests/InsideTests.cs

133 lines
9.3 KiB
C#

using System;
using System.Collections.Generic;
using RynthCore.Plugin.RynthNav;
namespace RynthNav.RouteTests;
// A go to someone INSIDE a dungeon (InsidePlaces.cs, Atlas.FindInside, Entrance.PortalInto; 2026-11-27):
// which name means someone inside, and the way in: already there, a portal on the map, a recall you know.
// Spotted by SilentKelpie (Forgejo rynth PR #12); re-implemented here.
internal static partial class Program
{
private static void RunInside()
{
Run(nameof(InsideFindsPeopleInDungeons), InsideFindsPeopleInDungeons);
Run(nameof(InsideMapWinsWhenItAnswers), InsideMapWinsWhenItAnswers);
Run(nameof(InsideWayIn), InsideWayIn);
Run(nameof(InsideAlternatives), InsideAlternatives);
Run(nameof(InsideLines), InsideLines);
}
// Landblock 0x0A0B: the Deep Vault (two portals in on the map, one needs a quest; a third is destroyed).
// Landblock 0x0C0D: reached only by Vault Recall. Holtburg is on the map; "Gate Keeper" is both a map NPC
// in Holtburg and a person inside.
private const string InsideJson = """
{"generated":"test","locations":[
{"id":1,"name":"Holtburg","type":"Town","cell":"A9B40001","place":"outdoor","ns":42.1,"ew":33.6},
{"id":2,"name":"Quest Portal to the Deep Vault","type":"Portal","cell":"A9B30001","place":"outdoor","ns":41.9,"ew":33.5,"quest":true,
"dest":{"cell":"0A0B0110","place":"dungeon","name":"Deep Vault"}},
{"id":3,"name":"Deep Vault Portal","type":"Portal","cell":"A8B30001","place":"outdoor","ns":40.0,"ew":32.0,
"dest":{"cell":"0A0B0110","place":"dungeon","name":"Deep Vault"}},
{"id":4,"name":"Destroyed Deep Vault Portal","type":"Portal","cell":"A9B40002","place":"outdoor","ns":42.0,"ew":33.6,
"dest":{"cell":"0A0B0110","place":"dungeon","name":"Deep Vault"}},
{"id":5,"name":"Brannoc the Smith","type":"NPC","cell":"0A0B0123","place":"dungeon"},
{"id":6,"name":"Brannoc","type":"Vendor","cell":"0C0D0101","place":"dungeon"},
{"id":7,"name":"Ulla","type":"NPC","cell":"0C0D0140","place":"dungeon"},
{"id":8,"name":"Inner Portal","type":"Portal","cell":"0A0B0130","place":"dungeon"},
{"id":9,"name":"Gate Keeper","type":"NPC","cell":"A9B40003","place":"outdoor","ns":42.2,"ew":33.7},
{"id":10,"name":"Gate Keeper","type":"NPC","cell":"0A0B0150","place":"dungeon"},
{"id":11,"name":"Brannocka","type":"NPC","cell":"0A0B0151","place":"dungeon"},
{"id":12,"name":"Holtburg Guard","type":"NPC","cell":"0A0B0152","place":"dungeon"},
{"id":13,"name":"Holtburg Guard Tower","type":"Landmark","cell":"A9B40004","place":"outdoor","ns":42.3,"ew":33.8}
],"recalls":[
{"spell":4084,"name":"Vault Recall","cell":"0C0D0101","place":"dungeon"},
{"spell":2020,"name":"Recall Holtburg","cell":"A9B40001","place":"outdoor","ns":42.1,"ew":33.6}
]}
""";
private static void InsideFindsPeopleInDungeons()
{
Atlas atlas = Atlas.Parse(InsideJson);
Check(atlas.Recalls[0].Cell == "0C0D0101", "a recall's landing cell is read");
AtlasLocation? d = atlas.FindInside("Brannoc the Smith");
Check(d?.Id == 5, $"the exact name (got {d?.Id})");
d = atlas.FindInside("brannoc");
Check(d?.Id == 6, $"exact beats starts-with (got {d?.Id})");
d = atlas.FindInside("Brannoc", hereLb: 0x0A0B);
Check(d?.Id == 5, $"one in the landblock you're in wins (got {d?.Id})");
Check(atlas.FindInside("Bran") == null, "a part of a word isn't a name (Bran, not Brannoc / Brannocka)");
Check(atlas.FindInside("Inner Portal") == null, "a portal inside isn't someone to go to");
Check(atlas.FindInside("Ul") == null, "two letters are too few");
Check(atlas.FindInside("Holtburg")?.Id == 12, "a whole-word start counts inside (Holtburg Guard); Prefer leaves a map place to the map");
AtlasLocation? p = Entrance.PortalInto(atlas, 0x0A0B, true, 42.1, 33.6);
Check(p?.Id == 3, $"the portal in: no quest first beats nearer, never the destroyed one (got {p?.Id})");
Check(Entrance.PortalInto(atlas, 0x0C0D, true, 42, 33) == null, "no portal on the map into the other dungeon");
}
private static void InsideMapWinsWhenItAnswers()
{
Atlas atlas = Atlas.Parse(InsideJson);
// The map's exact name wins: Gate Keeper is in Holtburg as well as inside.
Check(InsidePlaces.Prefer(atlas, "Gate Keeper", true, 42, 33, 0, out bool onMap) == null && onMap, "an exact map name wins");
// Someone inside by their exact name beats a map place that only half matches ("Holtburg Guard" vs Holtburg).
AtlasLocation? g = InsidePlaces.Prefer(atlas, "Holtburg Guard", true, 42, 33, 0, out onMap);
Check(g?.Id == 12 && onMap, $"an exact inside name beats a part-match on the map, Holtburg Guard Tower (got {g?.Id})");
// Only a starts-with match inside, and a whole-word match on the map: the map.
Check(InsidePlaces.Prefer(atlas, "Holtburg Gu", true, 42, 33, 0, out onMap) == null, "a partial name inside loses to the map's match");
g = InsidePlaces.Prefer(atlas, "Ulla", true, 42, 33, 0, out onMap);
Check(g?.Id == 7 && !onMap, $"nothing on the map: the one inside (got {g?.Id})");
Check(InsidePlaces.Prefer(atlas, "Holtburg", true, 42, 33, 0, out onMap) == null && onMap, "a town is the town");
Check(InsidePlaces.Prefer(atlas, "Nobody Here", true, 42, 33, 0, out onMap) == null && !onMap, "no one: null, nothing on the map");
}
private static void InsideWayIn()
{
Atlas atlas = Atlas.Parse(InsideJson);
AtlasLocation smith = atlas.ById(5)!, ulla = atlas.ById(7)!;
var known = new HashSet<int> { 4084 };
const uint outdoors = 0xA9B4001A, inVault = 0x0A0B0105, inOther = 0x0C0D0120;
InsideWay w = InsidePlaces.WayIn(atlas, smith, outdoors, true, 42.1, 33.6, known, true);
Check(w.Kind == InsideWayKind.Portal && w.Portal?.Id == 3 && w.Cell == 0x0A0B0123 && w.Dungeon == "Deep Vault",
$"on the map: the portal into the Deep Vault ({w.Kind}, {w.Portal?.Id}, {w.Cell:X8}, {w.Dungeon})");
w = InsidePlaces.WayIn(atlas, smith, inVault, false, 0, 0, known, true);
Check(w.Kind == InsideWayKind.Here, "in that dungeon already: here");
w = InsidePlaces.WayIn(atlas, smith, inOther, false, 0, 0, known, true);
Check(w.Kind == InsideWayKind.Portal && w.Portal?.Id == 3, "in another dungeon with no recall in: still the portal (the route out starts with a recall)");
w = InsidePlaces.WayIn(atlas, ulla, outdoors, true, 42, 33, known, true);
Check(w.Kind == InsideWayKind.Recall && w.Recall?.SpellId == 4084 && w.Dungeon == "where Vault Recall lands",
$"no portal in: the recall you know ({w.Kind}, {w.Dungeon})");
w = InsidePlaces.WayIn(atlas, ulla, outdoors, true, 42, 33, new HashSet<int>(), true);
Check(w.Kind == InsideWayKind.None && InsidePlaces.NoWayText(w).Contains("no portal on the map or recall you know"), "a recall you don't know: none");
w = InsidePlaces.WayIn(atlas, ulla, outdoors, true, 42, 33, known, recallsOn: false);
Check(w.Kind == InsideWayKind.None, "recalls off: none");
w = InsidePlaces.WayIn(atlas, ulla, outdoors, true, 42, 33, null, true);
Check(w.Kind == InsideWayKind.None, "the spellbook not read yet: none");
w = InsidePlaces.WayIn(atlas, ulla, inOther, false, 0, 0, known, true);
Check(w.Kind == InsideWayKind.Here && w.Cell == 0x0C0D0140, "Ulla's dungeon, where you are: here");
}
private static void InsideAlternatives()
{
Atlas atlas = Atlas.Parse(InsideJson);
Check(InsidePlaces.FromAlternatives(atlas, "Nobody || Ulla || Holtburg", true, 42, 33, 0)?.Id == 7, "the first inside candidate, before a later map one");
Check(InsidePlaces.FromAlternatives(atlas, "Holtburg || Ulla", true, 42, 33, 0) == null, "a map place first: the usual go");
Check(InsidePlaces.FromAlternatives(atlas, "10.0N, 20.0E || Ulla", true, 42, 33, 0) == null, "coordinates first: the usual go");
Check(InsidePlaces.FromAlternatives(atlas, "Nobody || Nothing", true, 42, 33, 0) == null, "none at all: the usual go says why");
}
private static void InsideLines()
{
Check(InsidePlaces.Tail("Brannoc", 0x009C0270) == " (Brannoc is in cell 009C0270)", "the arrival line's tail");
// A walk only by default (2026-11-27): RynthAi turns fighting, looting, buffing and the meta off for it.
Check(InsidePlaces.WalkCommand(0x009C0270, "Brannoc the Smith") == "/ra dunnav-to cell 009C0270 walkonly Brannoc the Smith", "RynthAi's walk to the cell, a walk only");
Check(InsidePlaces.WalkCommand(0x009C0270, "") == "/ra dunnav-to cell 009C0270 walkonly", "no name: just the cell, a walk only");
// Fight on the way in: the macro as set, as before.
Check(InsidePlaces.WalkCommand(0x009C0270, "Brannoc the Smith", fight: true) == "/ra dunnav-to cell 009C0270 Brannoc the Smith", "fight on the way in: no walkonly");
Check(InsidePlaces.WalkCommand(0x009C0270, "", fight: true) == "/ra dunnav-to cell 009C0270", "fight, no name: just the cell");
Atlas atlas = Atlas.Parse(InsideJson);
Check(InsidePlaces.DungeonName(atlas, 0x0A0B) == "Deep Vault", "named by the portals into it");
Check(InsidePlaces.DungeonName(atlas, 0x0E0F) == "dungeon 0E0F", "unknown: its landblock");
}
}