RynthSuite as of 2026-11-29 (internal 46bae49): release 2026.11.28.1
This commit is contained in:
parent
25552fa794
commit
598f49c899
131 changed files with 11825 additions and 329 deletions
|
|
@ -34,6 +34,8 @@ internal sealed class AtlasRecall
|
|||
public string Name = "", In = "";
|
||||
public bool OnMap;
|
||||
public double Ns, Ew;
|
||||
/// <summary>The cell it lands in ("" = not given): a landing in a dungeon is known by its landblock.</summary>
|
||||
public string Cell = "";
|
||||
}
|
||||
|
||||
internal sealed class Atlas
|
||||
|
|
@ -140,7 +142,7 @@ internal sealed class Atlas
|
|||
{
|
||||
foreach (JsonElement e in arr.EnumerateArray())
|
||||
{
|
||||
var r = new AtlasRecall { SpellId = Int(e, "spell"), Name = Str(e, "name"), In = Str(e, "in") };
|
||||
var r = new AtlasRecall { SpellId = Int(e, "spell"), Name = Str(e, "name"), In = Str(e, "in"), Cell = Str(e, "cell") };
|
||||
r.OnMap = TryNum(e, "ns", out r.Ns) & TryNum(e, "ew", out r.Ew);
|
||||
recalls.Add(r);
|
||||
}
|
||||
|
|
@ -174,6 +176,42 @@ internal sealed class Atlas
|
|||
return dungeon;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The best place INSIDE a dungeon for a name (2026-11-27): a person, a vendor, a lifestone or a landmark
|
||||
/// in a dungeon cell, with no map position, whose name is the query or starts with it as whole words
|
||||
/// ("Brannoc" for "Brannoc the Smith"). Never a portal or a dungeon (those are ways in, Entrance.cs). Ties: one
|
||||
/// in <paramref name="hereLb"/> (the landblock you're in) first, then the exact name. Null when none answers.
|
||||
/// The Atlas has about 3,100 such people and places; a go by their name used to say "no place on the map".
|
||||
/// Spotted by SilentKelpie (Forgejo rynth PR #12); re-implemented here.
|
||||
/// </summary>
|
||||
public AtlasLocation? FindInside(string query, uint hereLb = 0)
|
||||
{
|
||||
string q = query.Trim();
|
||||
if (q.Length < 3) return null;
|
||||
AtlasLocation? best = null;
|
||||
int bestScore = 0;
|
||||
foreach (AtlasLocation l in Locations)
|
||||
{
|
||||
if (l.OnMap || !l.Place.Equals("dungeon", StringComparison.Ordinal)) continue;
|
||||
if (l.Type.Equals("Portal", StringComparison.Ordinal) || l.Type.Equals("Dungeon", StringComparison.Ordinal)) continue;
|
||||
if (!TryCell(l.Cell, out uint cell) || (cell & 0xFFFF) < 0x100) continue;
|
||||
int s = l.Name.Equals(q, StringComparison.OrdinalIgnoreCase) ? 2
|
||||
: l.Name.Length > q.Length && l.Name.StartsWith(q, StringComparison.OrdinalIgnoreCase) && !char.IsLetterOrDigit(l.Name[q.Length]) ? 1 : 0;
|
||||
if (s == 0) continue;
|
||||
if (hereLb != 0 && cell >> 16 == hereLb) s += 10;
|
||||
if (s <= bestScore) continue;
|
||||
best = l; bestScore = s;
|
||||
}
|
||||
return best;
|
||||
}
|
||||
|
||||
/// <summary>An 8-digit hex cell ("009C0270").</summary>
|
||||
public static bool TryCell(string text, out uint cell)
|
||||
{
|
||||
cell = 0;
|
||||
return text.Length == 8 && uint.TryParse(text, NumberStyles.HexNumber, CultureInfo.InvariantCulture, out cell);
|
||||
}
|
||||
|
||||
private static bool TryLandblock(string cell, out uint lb)
|
||||
{
|
||||
lb = 0;
|
||||
|
|
|
|||
326
Plugins/RynthCore.Plugin.RynthNav/CustomPortals.cs
Normal file
326
Plugins/RynthCore.Plugin.RynthNav/CustomPortals.cs
Normal file
|
|
@ -0,0 +1,326 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Text;
|
||||
using RynthNav.Routing;
|
||||
|
||||
namespace RynthCore.Plugin.RynthNav;
|
||||
|
||||
// Portals a server added that the world data (NavData's portals.tsv) doesn't have (2026-11-27). Custom servers
|
||||
// add their own, so routes never used them. Found two ways:
|
||||
// * /rnav portals scan [yd] (or the panel's Scan): every portal object the client knows around you is written
|
||||
// down where it stands;
|
||||
// * taking one: the teleport that follows says where it lands. A scanned portal becomes a route link the first
|
||||
// time it's used; one you take without scanning is added then.
|
||||
// Kept per server (the world name the client logged into), so one server's portals never route a character on
|
||||
// another. A portal on the map that lands on the map is a plain PortalLink for the route planner (PortalRoute,
|
||||
// our own graph: the same Dijkstra and costs as portals.tsv's). A landing inside a dungeon is kept and listed but
|
||||
// not routed: there is no map to walk on from it. Portals standing inside dungeons aren't written down.
|
||||
// Saved in NavData\custom-portals.txt, one tab-separated line per portal, the server first. No host calls: the
|
||||
// route tests compile this file. Spotted by SilentKelpie (Forgejo rynth PR #12); re-implemented here.
|
||||
|
||||
/// <summary>One server's portal that the world data doesn't have.</summary>
|
||||
internal sealed class CustomPortal
|
||||
{
|
||||
public string Server = "", Name = "";
|
||||
public uint Wcid;
|
||||
/// <summary>Where it stands: its cell and landblock-local x, y, z, and the map coordinates.</summary>
|
||||
public uint Cell;
|
||||
public double X, Y, Z;
|
||||
public double Ns, Ew;
|
||||
/// <summary>Where it lands, learned by taking it. DestKnown false = only scanned.</summary>
|
||||
public bool DestKnown, DestOnMap;
|
||||
public double DestNs, DestEw;
|
||||
public uint DestCell;
|
||||
public DateTime SeenUtc, LearnedUtc;
|
||||
|
||||
/// <summary>Both ends on the map: a route link.</summary>
|
||||
public bool Routable => DestKnown && DestOnMap;
|
||||
|
||||
/// <summary>The route planner's link: open to anyone (the server's rules aren't known; a refusal is learned as for any portal).</summary>
|
||||
public PortalLink ToLink() => new(Ns, Ew, DestNs, DestEw, Name, 0, 0, PortalRules.Unrestricted, Cell, X, Y, Z);
|
||||
|
||||
public string Where => DestKnown
|
||||
? DestOnMap ? NavCoords.Fmt(DestNs, DestEw) : string.Create(CultureInfo.InvariantCulture, $"a dungeon (landblock {DestCell >> 16:X4}, not routed)")
|
||||
: "not taken yet";
|
||||
|
||||
internal string Key => CustomPortalStore.KeyOf(Server, Name, Ns, Ew);
|
||||
}
|
||||
|
||||
/// <summary>What a scan did with one portal object.</summary>
|
||||
internal enum CustomSeen { Added, Refreshed, BuiltIn }
|
||||
|
||||
/// <summary>What taking a portal told the store.</summary>
|
||||
internal enum CustomLearn { New, LandingChanged, AlreadyKnown, BuiltIn, NotAPortal }
|
||||
|
||||
internal sealed class CustomPortalStore
|
||||
{
|
||||
/// <summary>A portal object of the same name this close (yards) to a saved one is that one.</summary>
|
||||
public const double SameUnits = 8.0;
|
||||
/// <summary>A portals.tsv portal this close already routes it (any name within half of it).</summary>
|
||||
public const double BuiltInUnits = 12.0;
|
||||
/// <summary>A map landing this close (yards) to the known one is the same landing (landings scatter a little).</summary>
|
||||
public const double SameLandingUnits = 30.0;
|
||||
/// <summary>A "landing" this close to where the portal stands isn't a teleport through it.</summary>
|
||||
public const double TooCloseUnits = 30.0;
|
||||
public const int MaxPerServer = 2000;
|
||||
|
||||
private readonly List<CustomPortal> _all = new();
|
||||
private readonly HashSet<string> _forgotten = new(StringComparer.OrdinalIgnoreCase);
|
||||
|
||||
/// <summary>Bumped on every change (the plugin saves and rebuilds its route links when it moves).</summary>
|
||||
public int Version { get; private set; }
|
||||
|
||||
public IReadOnlyList<CustomPortal> All => _all;
|
||||
|
||||
public List<CustomPortal> For(string server)
|
||||
{
|
||||
string k = Server(server);
|
||||
return _all.FindAll(p => p.Server.Equals(k, StringComparison.OrdinalIgnoreCase));
|
||||
}
|
||||
|
||||
/// <summary>This server's route links (both ends on the map).</summary>
|
||||
public List<PortalLink> Links(string server)
|
||||
{
|
||||
var links = new List<PortalLink>();
|
||||
foreach (CustomPortal p in For(server)) if (p.Routable) links.Add(p.ToLink());
|
||||
return links;
|
||||
}
|
||||
|
||||
public (int Saved, int Routable) Counts(string server)
|
||||
{
|
||||
int saved = 0, routable = 0;
|
||||
foreach (CustomPortal p in For(server)) { saved++; if (p.Routable) routable++; }
|
||||
return (saved, routable);
|
||||
}
|
||||
|
||||
public static string Server(string server) => string.IsNullOrWhiteSpace(server) ? "?" : server.Trim();
|
||||
|
||||
internal static string KeyOf(string server, string name, double ns, double ew) =>
|
||||
string.Create(CultureInfo.InvariantCulture, $"{Server(server)}|{name}|{Math.Round(ns, 1):0.0}|{Math.Round(ew, 1):0.0}");
|
||||
|
||||
/// <summary>The saved portal of that name standing within SameUnits of (ns, ew), or null.</summary>
|
||||
public CustomPortal? Find(string server, string name, double ns, double ew)
|
||||
{
|
||||
string k = Server(server);
|
||||
foreach (CustomPortal p in _all)
|
||||
if (p.Server.Equals(k, StringComparison.OrdinalIgnoreCase) && p.Name.Equals(name, StringComparison.OrdinalIgnoreCase)
|
||||
&& NavCoords.Distance(p.Ns, p.Ew, ns, ew) <= SameUnits) return p;
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>A portals.tsv portal at that spot: the same name within BuiltInUnits, or any within half of it.</summary>
|
||||
public static bool IsBuiltIn(IReadOnlyList<PortalLink>? builtIn, string name, double ns, double ew)
|
||||
{
|
||||
if (builtIn == null) return false;
|
||||
foreach (PortalLink b in builtIn)
|
||||
{
|
||||
double d = NavCoords.Distance(b.SrcNs, b.SrcEw, ns, ew);
|
||||
if (d > BuiltInUnits) continue;
|
||||
if (d <= BuiltInUnits / 2) return true;
|
||||
if (b.Name.Length > 0 && name.Length > 0
|
||||
&& (b.Name.Contains(name, StringComparison.OrdinalIgnoreCase) || name.Contains(b.Name, StringComparison.OrdinalIgnoreCase)))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>A portal object on the map, seen by a scan: written down, or its sighting refreshed.</summary>
|
||||
public CustomSeen Saw(string server, string name, uint wcid, uint cell, double x, double y, double z, double ns, double ew,
|
||||
IReadOnlyList<PortalLink>? builtIn, DateTime nowUtc)
|
||||
{
|
||||
name = Clean(name);
|
||||
CustomPortal? p = Find(server, name, ns, ew);
|
||||
if (p == null && IsBuiltIn(builtIn, name, ns, ew)) return CustomSeen.BuiltIn;
|
||||
if (p != null)
|
||||
{
|
||||
bool moved = p.Cell != cell || Math.Abs(p.X - x) > 0.05 || Math.Abs(p.Y - y) > 0.05 || Math.Abs(p.Z - z) > 0.05 || (wcid != 0 && p.Wcid != wcid);
|
||||
p.SeenUtc = nowUtc;
|
||||
if (moved) { Place(p, wcid, cell, x, y, z, ns, ew); Version++; }
|
||||
return CustomSeen.Refreshed;
|
||||
}
|
||||
p = new CustomPortal { Server = Server(server), Name = name, SeenUtc = nowUtc };
|
||||
Place(p, wcid, cell, x, y, z, ns, ew);
|
||||
Add(p);
|
||||
return CustomSeen.Added;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The map portal you stood at (name, where it stands) took you to the landing given (on the map, or a
|
||||
/// dungeon cell). A portals.tsv portal is left alone (BuiltIn); a "landing" right beside it isn't a teleport
|
||||
/// through it (NotAPortal). Otherwise it is added if new and its landing set; AlreadyKnown when the landing is
|
||||
/// the one it had (nothing written: taking a known portal says nothing).
|
||||
/// </summary>
|
||||
public CustomLearn Learned(string server, string name, uint wcid, uint cell, double x, double y, double z, double ns, double ew,
|
||||
bool destOnMap, double destNs, double destEw, uint destCell, IReadOnlyList<PortalLink>? builtIn, DateTime nowUtc,
|
||||
out CustomPortal? portal)
|
||||
{
|
||||
portal = null;
|
||||
name = Clean(name);
|
||||
if (destOnMap && NavCoords.Distance(ns, ew, destNs, destEw) < TooCloseUnits) return CustomLearn.NotAPortal;
|
||||
CustomPortal? p = Find(server, name, ns, ew);
|
||||
bool added = false;
|
||||
if (p == null)
|
||||
{
|
||||
if (IsBuiltIn(builtIn, name, ns, ew)) return CustomLearn.BuiltIn;
|
||||
p = new CustomPortal { Server = Server(server), Name = name, SeenUtc = nowUtc };
|
||||
Place(p, wcid, cell, x, y, z, ns, ew);
|
||||
Add(p);
|
||||
added = true;
|
||||
}
|
||||
portal = p;
|
||||
p.SeenUtc = nowUtc;
|
||||
if (!added && SameLanding(p, destOnMap, destNs, destEw, destCell)) return CustomLearn.AlreadyKnown;
|
||||
CustomLearn result = added || !p.DestKnown ? CustomLearn.New : CustomLearn.LandingChanged;
|
||||
p.DestKnown = true;
|
||||
p.DestOnMap = destOnMap;
|
||||
p.DestNs = destOnMap ? Math.Round(destNs, 2) : 0;
|
||||
p.DestEw = destOnMap ? Math.Round(destEw, 2) : 0;
|
||||
p.DestCell = destCell;
|
||||
p.LearnedUtc = nowUtc;
|
||||
Version++;
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>The landing <paramref name="p"/> has is this one: map, within SameLandingUnits; a dungeon, the same landblock.</summary>
|
||||
internal static bool SameLanding(CustomPortal p, bool destOnMap, double destNs, double destEw, uint destCell)
|
||||
{
|
||||
if (!p.DestKnown || p.DestOnMap != destOnMap) return false;
|
||||
return destOnMap ? NavCoords.Distance(p.DestNs, p.DestEw, destNs, destEw) <= SameLandingUnits : (p.DestCell >> 16) == (destCell >> 16);
|
||||
}
|
||||
|
||||
/// <summary>Forgets this server's portals whose name is <paramref name="name"/> (or, with none exact, contains it). How many.</summary>
|
||||
public int Forget(string server, string name)
|
||||
{
|
||||
string k = Server(server), n = name.Trim();
|
||||
if (n.Length == 0) return 0;
|
||||
bool exact = _all.Exists(p => p.Server.Equals(k, StringComparison.OrdinalIgnoreCase) && p.Name.Equals(n, StringComparison.OrdinalIgnoreCase));
|
||||
int removed = 0;
|
||||
for (int i = _all.Count - 1; i >= 0; i--)
|
||||
{
|
||||
CustomPortal p = _all[i];
|
||||
if (!p.Server.Equals(k, StringComparison.OrdinalIgnoreCase)) continue;
|
||||
if (exact ? !p.Name.Equals(n, StringComparison.OrdinalIgnoreCase) : !p.Name.Contains(n, StringComparison.OrdinalIgnoreCase)) continue;
|
||||
_forgotten.Add(p.Key);
|
||||
_all.RemoveAt(i);
|
||||
removed++;
|
||||
}
|
||||
if (removed > 0) Version++;
|
||||
return removed;
|
||||
}
|
||||
|
||||
/// <summary>Forgets every portal of this server. How many.</summary>
|
||||
public int Clear(string server)
|
||||
{
|
||||
string k = Server(server);
|
||||
int removed = 0;
|
||||
for (int i = _all.Count - 1; i >= 0; i--)
|
||||
{
|
||||
if (!_all[i].Server.Equals(k, StringComparison.OrdinalIgnoreCase)) continue;
|
||||
_forgotten.Add(_all[i].Key);
|
||||
_all.RemoveAt(i);
|
||||
removed++;
|
||||
}
|
||||
if (removed > 0) Version++;
|
||||
return removed;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Every client writes the one file: what another client saved since is taken in before a save (a portal this
|
||||
/// client doesn't have, or a landing learned later than ours), except what this client forgot.
|
||||
/// </summary>
|
||||
public void MergeFrom(CustomPortalStore disk)
|
||||
{
|
||||
foreach (CustomPortal d in disk._all)
|
||||
{
|
||||
if (_forgotten.Contains(d.Key)) continue;
|
||||
CustomPortal? mine = Find(d.Server, d.Name, d.Ns, d.Ew);
|
||||
if (mine == null) { Add(d); continue; }
|
||||
if (d.DestKnown && (!mine.DestKnown || d.LearnedUtc > mine.LearnedUtc))
|
||||
{
|
||||
mine.DestKnown = true; mine.DestOnMap = d.DestOnMap; mine.DestNs = d.DestNs; mine.DestEw = d.DestEw;
|
||||
mine.DestCell = d.DestCell; mine.LearnedUtc = d.LearnedUtc;
|
||||
Version++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void Add(CustomPortal p)
|
||||
{
|
||||
if (For(p.Server).Count >= MaxPerServer)
|
||||
{
|
||||
int oldest = _all.FindIndex(o => o.Server.Equals(p.Server, StringComparison.OrdinalIgnoreCase));
|
||||
if (oldest >= 0) _all.RemoveAt(oldest);
|
||||
}
|
||||
_all.Add(p);
|
||||
_forgotten.Remove(p.Key);
|
||||
Version++;
|
||||
}
|
||||
|
||||
private static void Place(CustomPortal p, uint wcid, uint cell, double x, double y, double z, double ns, double ew)
|
||||
{
|
||||
if (wcid != 0) p.Wcid = wcid;
|
||||
p.Cell = cell; p.X = Math.Round(x, 2); p.Y = Math.Round(y, 2); p.Z = Math.Round(z, 2);
|
||||
p.Ns = Math.Round(ns, 3); p.Ew = Math.Round(ew, 3);
|
||||
}
|
||||
|
||||
/// <summary>A name as one field: no tabs or line breaks, trimmed.</summary>
|
||||
internal static string Clean(string name)
|
||||
{
|
||||
var sb = new StringBuilder(name.Length);
|
||||
foreach (char c in name) sb.Append(c is '\t' or '\r' or '\n' ? ' ' : c);
|
||||
return sb.ToString().Trim();
|
||||
}
|
||||
|
||||
// ── custom-portals.txt ───────────────────────────────────────────────
|
||||
// server, name, wcid, cell (hex), x, y, z, ns, ew, landing ("map" | "dungeon" | "-"), destNs, destEw,
|
||||
// destCell (hex), seen, learned (UTC, round-trip). Lines starting with # are notes.
|
||||
|
||||
public string Serialize()
|
||||
{
|
||||
var ci = CultureInfo.InvariantCulture;
|
||||
var sb = new StringBuilder();
|
||||
sb.Append("# RynthNav: custom servers' own portals (server, name, wcid, cell, x, y, z, ns, ew, landing, destNs, destEw, destCell, seen, learned)\n");
|
||||
foreach (CustomPortal p in _all)
|
||||
{
|
||||
string landing = !p.DestKnown ? "-" : p.DestOnMap ? "map" : "dungeon";
|
||||
sb.Append(p.Server).Append('\t').Append(p.Name).Append('\t').Append(p.Wcid.ToString(ci)).Append('\t')
|
||||
.Append(p.Cell.ToString("X8", ci)).Append('\t').Append(p.X.ToString("0.##", ci)).Append('\t')
|
||||
.Append(p.Y.ToString("0.##", ci)).Append('\t').Append(p.Z.ToString("0.##", ci)).Append('\t')
|
||||
.Append(p.Ns.ToString("0.###", ci)).Append('\t').Append(p.Ew.ToString("0.###", ci)).Append('\t')
|
||||
.Append(landing).Append('\t').Append(p.DestNs.ToString("0.##", ci)).Append('\t').Append(p.DestEw.ToString("0.##", ci)).Append('\t')
|
||||
.Append(p.DestCell.ToString("X8", ci)).Append('\t').Append(p.SeenUtc.ToString("o", ci)).Append('\t')
|
||||
.Append(p.LearnedUtc.ToString("o", ci)).Append('\n');
|
||||
}
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
public static CustomPortalStore Parse(string text)
|
||||
{
|
||||
var store = new CustomPortalStore();
|
||||
var ci = CultureInfo.InvariantCulture;
|
||||
const NumberStyles num = NumberStyles.Float;
|
||||
foreach (string raw in text.Split('\n'))
|
||||
{
|
||||
string line = raw.TrimEnd('\r');
|
||||
if (line.Length == 0 || line[0] == '#') continue;
|
||||
string[] f = line.Split('\t');
|
||||
if (f.Length < 15) continue;
|
||||
var p = new CustomPortal { Server = Server(f[0]), Name = Clean(f[1]) };
|
||||
if (p.Name.Length == 0
|
||||
|| !uint.TryParse(f[2], NumberStyles.Integer, ci, out p.Wcid)
|
||||
|| !uint.TryParse(f[3], NumberStyles.HexNumber, ci, out p.Cell)
|
||||
|| !double.TryParse(f[4], num, ci, out p.X) || !double.TryParse(f[5], num, ci, out p.Y) || !double.TryParse(f[6], num, ci, out p.Z)
|
||||
|| !double.TryParse(f[7], num, ci, out p.Ns) || !double.TryParse(f[8], num, ci, out p.Ew)
|
||||
|| !double.TryParse(f[10], num, ci, out p.DestNs) || !double.TryParse(f[11], num, ci, out p.DestEw)
|
||||
|| !uint.TryParse(f[12], NumberStyles.HexNumber, ci, out p.DestCell)) continue;
|
||||
p.DestKnown = f[9] is "map" or "dungeon";
|
||||
p.DestOnMap = f[9] == "map";
|
||||
DateTime.TryParse(f[13], ci, DateTimeStyles.RoundtripKind, out p.SeenUtc);
|
||||
DateTime.TryParse(f[14], ci, DateTimeStyles.RoundtripKind, out p.LearnedUtc);
|
||||
if (store.Find(p.Server, p.Name, p.Ns, p.Ew) != null) continue; // one line per portal
|
||||
store._all.Add(p);
|
||||
}
|
||||
return store;
|
||||
}
|
||||
}
|
||||
|
|
@ -64,6 +64,29 @@ internal static class Entrance
|
|||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A portal on the map that leads into landblock <paramref name="lb"/> (a dungeon): the nearest open one,
|
||||
/// one that needs no quest first when there is a choice; never a destroyed one. Null when none does.
|
||||
/// For a go to someone inside that dungeon (Atlas.FindInside).
|
||||
/// </summary>
|
||||
public static AtlasLocation? PortalInto(Atlas atlas, uint lb, bool hasPos, double ns, double ew)
|
||||
{
|
||||
AtlasLocation? best = null;
|
||||
double bestD = double.MaxValue;
|
||||
bool bestQuest = true;
|
||||
foreach (AtlasLocation l in atlas.Locations)
|
||||
{
|
||||
if (!l.OnMap || l.Closed || !l.HasDest || l.DestOnMap) continue;
|
||||
if (!l.Type.Equals("Portal", StringComparison.Ordinal) || IsDestroyed(l.Name)) continue;
|
||||
if (!Atlas.TryCell(l.DestCell, out uint dc) || dc >> 16 != lb) continue;
|
||||
double d = hasPos ? NavCoords.Distance(ns, ew, l.Ns, l.Ew) : 0;
|
||||
bool better = best == null || (bestQuest && !l.Quest) || (bestQuest == l.Quest && d < bestD);
|
||||
if (!better) continue;
|
||||
best = l; bestD = d; bestQuest = l.Quest;
|
||||
}
|
||||
return best;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The route, ending with walking into the portal at (<paramref name="ns"/>, <paramref name="ew"/>):
|
||||
/// a plain walk becomes one portal step; a route (portals, recalls) whose last leg walks there
|
||||
|
|
|
|||
142
Plugins/RynthCore.Plugin.RynthNav/InsidePlaces.cs
Normal file
142
Plugins/RynthCore.Plugin.RynthNav/InsidePlaces.cs
Normal file
|
|
@ -0,0 +1,142 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
|
||||
namespace RynthCore.Plugin.RynthNav;
|
||||
|
||||
/// <summary>How a go gets to someone inside a dungeon.</summary>
|
||||
internal enum InsideWayKind
|
||||
{
|
||||
/// <summary>No way in is known (no portal on the map leads there, no recall you know lands there).</summary>
|
||||
None,
|
||||
/// <summary>Already in that dungeon.</summary>
|
||||
Here,
|
||||
/// <summary>A portal on the map into the dungeon: walked to (a route, when it's far) and into.</summary>
|
||||
Portal,
|
||||
/// <summary>A recall in your spellbook that lands in the dungeon (Bur Recall into the Bur).</summary>
|
||||
Recall,
|
||||
}
|
||||
|
||||
/// <summary>The way into the dungeon a place inside it is in.</summary>
|
||||
internal sealed class InsideWay
|
||||
{
|
||||
public InsideWayKind Kind;
|
||||
public AtlasLocation Place = null!;
|
||||
public uint Cell;
|
||||
public string Dungeon = "";
|
||||
public AtlasLocation? Portal;
|
||||
public AtlasRecall? Recall;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Going to someone (or something) INSIDE a dungeon (2026-11-27). The Atlas has about 3,100 people, vendors,
|
||||
/// lifestones and landmarks in dungeon cells, with no map position; a go by their name used to say "no place
|
||||
/// called ... on the map". This finds the way in: already there, a portal on the map into that dungeon's
|
||||
/// landblock, or a recall you know that lands in it. The walk inside, to the person's cell, is RynthAi's
|
||||
/// dungeon map (/ra dunnav-to cell): RynthNav has no navmesh in dungeons. Host-free: the route tests compile it.
|
||||
/// Spotted by SilentKelpie (Forgejo rynth PR #12); re-implemented here.
|
||||
/// </summary>
|
||||
internal static class InsidePlaces
|
||||
{
|
||||
/// <summary>A landblock's dungeon cells start here; below are the outdoor cells.</summary>
|
||||
public const uint FirstDungeonCell = 0x100;
|
||||
|
||||
/// <summary>
|
||||
/// The place inside a dungeon <paramref name="name"/> means, or null when the map answers it as well or
|
||||
/// better: a place on the map with the exact name always wins; someone inside wins over a map place that
|
||||
/// only half matches when their name is exact, and over no whole-word match on the map at all.
|
||||
/// <paramref name="onMap"/>: the map has a whole-word match (an "a || b" list stops there).
|
||||
/// </summary>
|
||||
public static AtlasLocation? Prefer(Atlas atlas, string name, bool hasPos, double ns, double ew, uint hereLb, out bool onMap)
|
||||
{
|
||||
AtlasLocation? map = atlas.FindBest(name, hasPos, ns, ew);
|
||||
int mapScore = map == null ? 0 : Atlas.MatchScore(map.Name, name.Trim());
|
||||
onMap = mapScore >= 60;
|
||||
if (mapScore >= 100) return null;
|
||||
AtlasLocation? inside = atlas.FindInside(name, hereLb);
|
||||
if (inside == null) return null;
|
||||
bool exact = inside.Name.Equals(name.Trim(), StringComparison.OrdinalIgnoreCase);
|
||||
if (onMap && !exact) return null;
|
||||
return inside;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// "a || b || c" for a go: the candidates in order. Coordinates, or a place the map answers, leave it to
|
||||
/// the usual go (null); the first candidate that is someone inside a dungeon (by <see cref="Prefer"/>) is it.
|
||||
/// </summary>
|
||||
public static AtlasLocation? FromAlternatives(Atlas atlas, string text, bool hasPos, double ns, double ew, uint hereLb)
|
||||
{
|
||||
foreach (string raw in text.Split("||", StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries))
|
||||
{
|
||||
if (NavCoords.TrySplitCoordsAndName(raw, out _, out _, out _)) return null;
|
||||
AtlasLocation? inside = Prefer(atlas, raw, hasPos, ns, ew, hereLb, out bool onMap);
|
||||
if (inside != null) return inside;
|
||||
if (onMap) return null;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The way into <paramref name="place"/>'s dungeon from where you are (<paramref name="hereCell"/>; your map
|
||||
/// position when <paramref name="hasPos"/>). Already there first; then, standing on the map, a portal into
|
||||
/// it; then a recall you know that lands there (<paramref name="known"/>: your spellbook; null = not read
|
||||
/// yet); then, from inside another dungeon, a portal (the route out starts with a recall). Kind None when
|
||||
/// none is known, or the place has no cell.
|
||||
/// </summary>
|
||||
public static InsideWay WayIn(Atlas atlas, AtlasLocation place, uint hereCell, bool hasPos, double ns, double ew,
|
||||
ISet<int>? known, bool recallsOn)
|
||||
{
|
||||
var way = new InsideWay { Place = place };
|
||||
if (!Atlas.TryCell(place.Cell, out uint cell)) return way;
|
||||
uint lb = cell >> 16;
|
||||
way.Cell = cell;
|
||||
way.Dungeon = DungeonName(atlas, lb);
|
||||
if (hereCell >> 16 == lb && (hereCell & 0xFFFF) >= FirstDungeonCell) { way.Kind = InsideWayKind.Here; return way; }
|
||||
AtlasLocation? portal = Entrance.PortalInto(atlas, lb, hasPos, ns, ew);
|
||||
way.Portal = portal;
|
||||
if (portal != null && hasPos) { way.Kind = InsideWayKind.Portal; return way; }
|
||||
AtlasRecall? recall = recallsOn ? RecallInto(atlas, lb, known) : null;
|
||||
if (recall != null) { way.Kind = InsideWayKind.Recall; way.Recall = recall; return way; }
|
||||
if (portal != null) way.Kind = InsideWayKind.Portal;
|
||||
return way;
|
||||
}
|
||||
|
||||
/// <summary>A fixed recall in <paramref name="known"/> (the spellbook) that lands in landblock <paramref name="lb"/>, or null.</summary>
|
||||
public static AtlasRecall? RecallInto(Atlas atlas, uint lb, ISet<int>? known)
|
||||
{
|
||||
if (known == null) return null;
|
||||
foreach (AtlasRecall r in atlas.Recalls)
|
||||
if (!r.OnMap && Atlas.TryCell(r.Cell, out uint c) && c >> 16 == lb && known.Contains(r.SpellId)) return r;
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A dungeon's name: where the portals into it say they lead, else what a recall into it says, else the
|
||||
/// recall's own name ("where Bur Recall lands"), else "dungeon 009C".
|
||||
/// </summary>
|
||||
public static string DungeonName(Atlas atlas, uint lb)
|
||||
{
|
||||
foreach (AtlasLocation l in atlas.Locations)
|
||||
if (l.HasDest && !l.DestOnMap && l.DestName.Length > 0 && Atlas.TryCell(l.DestCell, out uint dc) && dc >> 16 == lb) return l.DestName;
|
||||
foreach (AtlasRecall r in atlas.Recalls)
|
||||
if (!r.OnMap && Atlas.TryCell(r.Cell, out uint c) && c >> 16 == lb)
|
||||
return r.In.Length > 0 ? r.In : $"where {r.Name} lands";
|
||||
return string.Create(CultureInfo.InvariantCulture, $"dungeon {lb:X4}");
|
||||
}
|
||||
|
||||
/// <summary>" (Brannoc is in cell 009C0270)": the end of the arrival line for someone inside.</summary>
|
||||
public static string Tail(string name, uint cell) =>
|
||||
string.Create(CultureInfo.InvariantCulture, $" ({name} is in cell {cell:X8})");
|
||||
|
||||
/// <summary>
|
||||
/// The RynthAi command that walks the dungeon map to that cell. Walk only (the default, 2026-11-27): RynthAi turns
|
||||
/// fighting, looting, buffing and the meta off for the walk and puts them back after; <paramref name="fight"/>
|
||||
/// (RynthNav "Fight on the way in") walks with the macro as set, fighting and looting on the way.
|
||||
/// </summary>
|
||||
public static string WalkCommand(uint cell, string name, bool fight = false) =>
|
||||
string.Create(CultureInfo.InvariantCulture, $"/ra dunnav-to cell {cell:X8}{(fight ? "" : " walkonly")} {name}").TrimEnd();
|
||||
|
||||
/// <summary>The line for a go that has no way in.</summary>
|
||||
public static string NoWayText(InsideWay w) =>
|
||||
$"{w.Place.Name} is inside {w.Dungeon}, and no portal on the map or recall you know leads in there";
|
||||
}
|
||||
|
|
@ -42,6 +42,8 @@
|
|||
<Compile Include="..\Shared\RynthNavPathApi.cs" Link="Shared\RynthNavPathApi.cs" />
|
||||
<!-- The route maker for other plugins (2026-10-30): JSON jobs to make nav routes, plan, walk. -->
|
||||
<Compile Include="..\Shared\RynthNavRoutesApi.cs" Link="Shared\RynthNavRoutesApi.cs" />
|
||||
<!-- RynthAi's script interface: a go to someone inside a dungeon hands the walk inside to RynthAi (2026-11-27). -->
|
||||
<Compile Include="..\Shared\RynthAiScriptApi.cs" Link="Shared\RynthAiScriptApi.cs" />
|
||||
<!-- One logged, guarded way to use an object (who used what, and why). -->
|
||||
<Compile Include="..\Shared\UseAudit.cs" Link="Shared\UseAudit.cs" />
|
||||
<!-- Text in the world on the Nav3D buffer (the path markers' labels; RynthAi's waypoint labels use it too). -->
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ namespace RynthCore.Plugin.RynthNav;
|
|||
// little islands (Shoushi's plaza, where the Town Network drops you, 10-08); where the plan runs
|
||||
// out the walk heads straight for its goal for a moment (BlindPushTicks), and that, or a wall the
|
||||
// mesh doesn't show, used to mean running into it until the 30 s progress watchdog. Now: blocked
|
||||
// for StuckWindowMs = turn away toward open ground (WalkSteer.UnstickHeading), remember the spot as
|
||||
// (StuckWatch) = turn away toward open ground (WalkSteer.UnstickHeading), remember the spot as
|
||||
// something to keep out of (the next plan bends round it, like round a portal), plan again, and
|
||||
// after StuckMaxTries on one leg without progress stop and say where.
|
||||
//
|
||||
|
|
@ -19,10 +19,11 @@ namespace RynthCore.Plugin.RynthNav;
|
|||
// it turned 120 degrees off, alternating sides, ran 1.6 s, planned the same path again and ran back
|
||||
// into the same spot, four times in 20 s, then stopped. The remembered spots now make each new
|
||||
// plan go round what it ran into.
|
||||
//
|
||||
// 11-27: a walk swinging between headings against a wall (run a moment, turn a moment) was never
|
||||
// blocked, as a tick turning in place started the watch again. StuckWatch counts turning too.
|
||||
public sealed partial class RynthNavPlugin
|
||||
{
|
||||
private const long StuckWindowMs = 1200; // running this long...
|
||||
private const double StuckMoveUnits = 0.6; // ...and moved less than this = blocked (a run covers 4+ u/s)
|
||||
private const long UnstickMs = 1600; // then turn away from it and run this long (~0.5 s of it turning)
|
||||
private const int StuckMaxTries = 4; // blocked this often on a leg without progress = stop
|
||||
private const double BlockedAheadUnits = 3.5; // the remembered spot: this far ahead of where it stuck...
|
||||
|
|
@ -30,20 +31,20 @@ public sealed partial class RynthNavPlugin
|
|||
private const int BlockedMaxSpots = 12;
|
||||
private const double UnstickOpenUnits = 6.0; // a way out is open ground this far along it
|
||||
|
||||
private bool _ranLastTick; // the walk asked to run last tick (not standing, not turning in place)
|
||||
private double _lastDriveDeg;
|
||||
private long _stuckWinMs, _unstickUntilMs;
|
||||
private double _stuckWx, _stuckWy, _unstickDeg;
|
||||
private long _unstickUntilMs;
|
||||
private double _unstickDeg;
|
||||
private int _stuckTries, _stuckSide = 1;
|
||||
private readonly StuckWatch _stuck = new();
|
||||
private readonly List<PortalAvoid.Spot> _blockedSpots = new();
|
||||
|
||||
/// <summary>DriveTo for the walk's own steering: remembers that it ran and which way.</summary>
|
||||
/// <summary>DriveTo for the walk's own steering: remembers which way, and that it drove (running or turning).</summary>
|
||||
private void WalkDrive(double deg, bool tight = false)
|
||||
{
|
||||
WalkSteer servo = tight ? _steerTight : _steerOpen;
|
||||
DriveTo(deg, servo);
|
||||
_lastDriveDeg = deg;
|
||||
_ranLastTick = !servo.TurnInPlace;
|
||||
_stuck.Drove(running: !servo.TurnInPlace);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -93,8 +94,8 @@ public sealed partial class RynthNavPlugin
|
|||
/// <summary>A new leg (or goto): nothing blocked yet.</summary>
|
||||
private void ResetBlocked()
|
||||
{
|
||||
_ranLastTick = false;
|
||||
_stuckWinMs = 0; _unstickUntilMs = 0; _stuckTries = 0;
|
||||
_stuck.Reset();
|
||||
_unstickUntilMs = 0; _stuckTries = 0;
|
||||
_blockedSpots.Clear();
|
||||
}
|
||||
|
||||
|
|
@ -105,8 +106,6 @@ public sealed partial class RynthNavPlugin
|
|||
private bool StepBlocked()
|
||||
{
|
||||
long now = NowMs;
|
||||
bool ran = _ranLastTick;
|
||||
_ranLastTick = false;
|
||||
if (_unstickUntilMs > now)
|
||||
{
|
||||
DriveTo(_unstickDeg, _steerOpen);
|
||||
|
|
@ -119,14 +118,10 @@ public sealed partial class RynthNavPlugin
|
|||
_unstickUntilMs = 0;
|
||||
lock (_gotoGate) _gotoPath = null;
|
||||
_blindTicks = 0; _replanTick = 0;
|
||||
_stuckWinMs = 0;
|
||||
_stuck.Reset();
|
||||
return false;
|
||||
}
|
||||
if (!ran || _stuckWinMs == 0) { _stuckWinMs = now; _stuckWx = _wx; _stuckWy = _wy; return false; }
|
||||
if (now - _stuckWinMs < StuckWindowMs) return false;
|
||||
double moved = Math.Sqrt((_wx - _stuckWx) * (_wx - _stuckWx) + (_wy - _stuckWy) * (_wy - _stuckWy));
|
||||
_stuckWinMs = now; _stuckWx = _wx; _stuckWy = _wy;
|
||||
if (moved >= StuckMoveUnits) return false;
|
||||
if (!_stuck.Check(now, _wx, _wy, out double moved, out long windowMs)) return false;
|
||||
|
||||
string at = NavCoords.Fmt(NavCoords.NsFromWorld(_wy), NavCoords.EwFromWorld(_wx));
|
||||
if (++_stuckTries > StuckMaxTries)
|
||||
|
|
@ -149,7 +144,7 @@ public sealed partial class RynthNavPlugin
|
|||
return WalkableStraight(_wx, _wy, _wx + Math.Sin(r) * UnstickOpenUnits, _wy + Math.Cos(r) * UnstickOpenUnits);
|
||||
});
|
||||
_unstickUntilMs = now + UnstickMs;
|
||||
Host.Log($"[RynthNav] walk: blocked at {at} heading {_lastDriveDeg:F0} (moved {moved:F1}u in {StuckWindowMs / 1000.0:F1} s); "
|
||||
Host.Log($"[RynthNav] walk: blocked at {at} heading {_lastDriveDeg:F0} (moved {moved:F1}u in {windowMs / 1000.0:F1} s); "
|
||||
+ $"turning to {_unstickDeg:F0}, keeping out of that spot ({_blockedSpots.Count} so far) and planning again ({_stuckTries}/{StuckMaxTries})");
|
||||
DriveTo(_unstickDeg, _steerOpen);
|
||||
lock (_gate) _status = $"blocked: stepping round it ({_stuckTries}/{StuckMaxTries})";
|
||||
|
|
|
|||
|
|
@ -0,0 +1,301 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using RynthNav.Routing;
|
||||
|
||||
namespace RynthCore.Plugin.RynthNav;
|
||||
|
||||
// This server's own portals (CustomPortals.cs, 2026-11-27): written down by a scan or when you take one, and given
|
||||
// to the route planner as plain portal links next to portals.tsv's, so go / route / the arrow use them. Our graph is
|
||||
// PortalRoute's (the same plan, costs and rules as every other portal); the walk to a custom portal aims at the
|
||||
// spot the live object stood on, as for a portals.tsv portal with a spot. Tick thread.
|
||||
// /rnav portals scan [yd] | list | forget <name> | clear confirm | custom on|off
|
||||
// Spotted by SilentKelpie (Forgejo rynth PR #12); re-implemented here.
|
||||
public sealed partial class RynthNavPlugin
|
||||
{
|
||||
private const string CustomPortalsFile = "custom-portals.txt";
|
||||
private const long NearPortalEveryMs = 400;
|
||||
/// <summary>A live portal this close to you (yards) is the one you'd be taking.</summary>
|
||||
private const double NearPortalUnits = 6.0;
|
||||
/// <summary>The portal seen beside you counts for a teleport this long after it was seen.</summary>
|
||||
private const long NearPortalFreshMs = 5000;
|
||||
public const double ScanDefaultUnits = 250.0;
|
||||
|
||||
private CustomPortalStore _custom = new();
|
||||
private volatile CustomPortalStore? _loadedCustom;
|
||||
private bool _customLoaded;
|
||||
private int _savedCustomVersion = -1;
|
||||
private volatile bool _customOn = true; // rynthnav.json customPortals
|
||||
private string _server = "";
|
||||
private List<PortalLink>? _tsvPortals; // portals.tsv only (the "built in" ones)
|
||||
private string _routeLinksKey = "";
|
||||
private string _customLast = ""; // the panel's line: what the last scan or learn did
|
||||
private volatile int _customSaved, _customRoutable; // this server's counts, for the panel (counted on the tick)
|
||||
private string _countedKey = "";
|
||||
private long _lastDeadMs; // HP 0 seen: the trip to the lifestone that follows isn't a portal
|
||||
|
||||
// The live portal right beside you, looked for every NearPortalEveryMs on the map (a teleport then is that portal).
|
||||
private long _nextNearPortalMs;
|
||||
private (string Name, uint Wcid, uint Cell, double X, double Y, double Z, double Wx, double Wy, long Ms)? _nearPortal;
|
||||
|
||||
private void LoadCustomPortals()
|
||||
{
|
||||
_customOn = NavDataConfig.ReadSwitch("customPortals", true);
|
||||
string path = NavFile(CustomPortalsFile);
|
||||
Task.Run(() =>
|
||||
{
|
||||
CustomPortalStore s = new();
|
||||
try { if (File.Exists(path)) s = CustomPortalStore.Parse(File.ReadAllText(path)); }
|
||||
catch (Exception ex) { Host.Log($"[RynthNav] {CustomPortalsFile}: {ex.Message}"); }
|
||||
_loadedCustom = s;
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>Every tick: the loaded file taken in, the server, the portal beside you, the route links, the save.</summary>
|
||||
private void TickCustomPortals(long now, bool save)
|
||||
{
|
||||
if (!_customLoaded && _loadedCustom is CustomPortalStore loaded)
|
||||
{
|
||||
_custom = loaded; _customLoaded = true; _savedCustomVersion = loaded.Version;
|
||||
int n = loaded.All.Count;
|
||||
if (n > 0) Host.Log($"[RynthNav] {CustomPortalsFile}: {n} custom portal(s)");
|
||||
}
|
||||
if (_server.Length == 0 && Host.TryGetWorldName(out string world) && world.Trim().Length > 0) _server = world.Trim();
|
||||
if (now >= _nextNearPortalMs) { _nextNearPortalMs = now + NearPortalEveryMs; NoteNearPortal(now); }
|
||||
RefreshRoutePortals();
|
||||
string ck = $"{_server}|{_custom.Version}|{_customLoaded}";
|
||||
if (ck != _countedKey)
|
||||
{
|
||||
_countedKey = ck;
|
||||
var (saved, routable) = _server.Length > 0 && _customLoaded ? _custom.Counts(_server) : (0, 0);
|
||||
_customSaved = saved; _customRoutable = routable;
|
||||
}
|
||||
if (save && _customLoaded && _custom.Version != _savedCustomVersion) SaveCustomPortals();
|
||||
}
|
||||
|
||||
private void OnLogoutCustom()
|
||||
{
|
||||
if (_customLoaded && _custom.Version != _savedCustomVersion) SaveCustomPortals();
|
||||
_server = ""; _nearPortal = null;
|
||||
}
|
||||
|
||||
private void SaveCustomPortals()
|
||||
{
|
||||
// Every client writes the one file: take in what the others saved since, then write.
|
||||
try
|
||||
{
|
||||
string path = NavFile(CustomPortalsFile);
|
||||
if (File.Exists(path)) _custom.MergeFrom(CustomPortalStore.Parse(File.ReadAllText(path)));
|
||||
}
|
||||
catch (Exception ex) { Host.Log($"[RynthNav] {CustomPortalsFile} (merging before a save): {ex.Message}"); }
|
||||
_savedCustomVersion = _custom.Version;
|
||||
WriteLater(CustomPortalsFile, _custom.Serialize());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The route planner's portals: portals.tsv's, then this server's custom ones with both ends on the map (custom
|
||||
/// on). Rebuilt when they change; the tsv ones keep their place, so a trip's portal keys stay the same.
|
||||
/// </summary>
|
||||
private void RefreshRoutePortals()
|
||||
{
|
||||
if (_tsvPortals == null) return;
|
||||
string key = _customOn ? $"{_server}|{_custom.Version}" : "off";
|
||||
if (key == _routeLinksKey && _portals != null) return;
|
||||
_routeLinksKey = key;
|
||||
var all = new List<PortalLink>(_tsvPortals);
|
||||
if (_customOn && _server.Length > 0)
|
||||
{
|
||||
List<PortalLink> mine = _custom.Links(_server);
|
||||
all.AddRange(mine);
|
||||
if (mine.Count > 0) Host.Log($"[RynthNav] routes: {mine.Count} custom portal(s) for {_server} with the {_tsvPortals.Count} of portals.tsv");
|
||||
}
|
||||
_portals = all;
|
||||
}
|
||||
|
||||
/// <summary>The nearest live portal object within NearPortalUnits, on the map, noted with its spot.</summary>
|
||||
private void NoteNearPortal(long now)
|
||||
{
|
||||
if (Host.TryGetPlayerVitals(out uint hp, out uint maxHp, out _, out _, out _, out _) && maxHp > 0 && hp == 0) _lastDeadMs = now;
|
||||
if (!_hasPose || !IsOnMap(_cellId) || !Host.HasGetLiveObjectIds || (Host.HasIsPortaling && Host.IsPortaling())) return;
|
||||
double best = NearPortalUnits * NearPortalUnits;
|
||||
uint bestId = 0, bestCell = 0; float bx = 0, by = 0, bz = 0;
|
||||
foreach (uint id in Host.GetLiveObjectIds())
|
||||
{
|
||||
if (!Host.TryGetItemType(id, out uint type) || (type & ItemTypePortal) == 0) continue;
|
||||
if (!Host.TryGetObjectPosition(id, out uint cell, out float x, out float y, out float z) || cell == 0 || !IsOnMap(cell)) continue;
|
||||
double ox = ((cell >> 24) & 0xFF) * 192.0 + x, oy = ((cell >> 16) & 0xFF) * 192.0 + y;
|
||||
double d2 = (ox - _wx) * (ox - _wx) + (oy - _wy) * (oy - _wy);
|
||||
if (d2 >= best) continue;
|
||||
best = d2; bestId = id; bestCell = cell; bx = x; by = y; bz = z;
|
||||
}
|
||||
if (bestId == 0) return; // the last one stays until it is too old to count
|
||||
Host.TryGetObjectName(bestId, out string name);
|
||||
Host.TryGetObjectWcid(bestId, out uint wcid);
|
||||
if (name.Length == 0) return;
|
||||
_nearPortal = (name, wcid, bestCell, bx, by, bz, ((bestCell >> 24) & 0xFF) * 192.0 + bx, ((bestCell >> 16) & 0xFF) * 192.0 + by, now);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// OnTeleported, a portal (not a recall): the live portal seen right beside where you stood before the jump
|
||||
/// was the one taken; its landing is learned (CustomPortalStore.Learned). portals.tsv's are left alone.
|
||||
/// </summary>
|
||||
/// <paramref name="spellWords"/>: your own spell words just before (a recall cast beside a portal isn't the portal).
|
||||
private void LearnCustomPortal(bool havePre, uint preCell, double preWx, double preWy, long startMs, RecallSpot landing, bool spellWords)
|
||||
{
|
||||
if (!_customLoaded || _server.Length == 0 || !havePre || !IsOnMap(preCell) || _nearPortal is not { } near) return;
|
||||
if (spellWords || (_lastDeadMs != 0 && startMs - _lastDeadMs < 60000)) { _nearPortal = null; return; }
|
||||
if (startMs - near.Ms > NearPortalFreshMs || near.Ms > startMs + 500) return;
|
||||
if ((near.Cell >> 16) != (preCell >> 16) && Math.Abs(near.Wx - preWx) + Math.Abs(near.Wy - preWy) > 2 * NearPortalUnits) return;
|
||||
double dx = near.Wx - preWx, dy = near.Wy - preWy;
|
||||
if (dx * dx + dy * dy > NearPortalUnits * NearPortalUnits) return;
|
||||
_nearPortal = null;
|
||||
double ns = NavCoords.NsFromWorld(near.Wy), ew = NavCoords.EwFromWorld(near.Wx);
|
||||
CustomLearn r = _custom.Learned(_server, near.Name, near.Wcid, near.Cell, near.X, near.Y, near.Z, ns, ew,
|
||||
landing.OnMap, landing.Ns, landing.Ew, landing.OnMap ? 0 : _cellId, _tsvPortals, DateTime.UtcNow, out CustomPortal? p);
|
||||
switch (r)
|
||||
{
|
||||
case CustomLearn.New:
|
||||
case CustomLearn.LandingChanged:
|
||||
string what = r == CustomLearn.New ? "learned" : "updated";
|
||||
_customLast = $"{what} {p!.Name} → {p.Where}";
|
||||
Host.Log($"[RynthNav] custom portal {what}: {p.Name} at {NavCoords.Fmt(ns, ew)} → {p.Where} ({_server})");
|
||||
Say($"{what} portal {p.Name}: it goes to {p.Where}" + (p.Routable ? "; routes can use it now" : ""));
|
||||
break;
|
||||
case CustomLearn.AlreadyKnown:
|
||||
Host.Log($"[RynthNav] custom portal {near.Name}: already known ({p?.Where})");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// ── /rnav portals ... ────────────────────────────────────────────────
|
||||
|
||||
private void CmdPortals(string rest)
|
||||
{
|
||||
string[] a = rest.Trim().Split(' ', 2, StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries);
|
||||
string verb = a.Length > 0 ? a[0].ToLowerInvariant() : "";
|
||||
string arg = a.Length > 1 ? a[1] : "";
|
||||
switch (verb)
|
||||
{
|
||||
case "on":
|
||||
case "off":
|
||||
_portalsEnabled = verb == "on";
|
||||
NavDataConfig.WriteSwitch("portals", _portalsEnabled);
|
||||
Say($"portal and recall routing {(_portalsEnabled ? "ON" : "OFF")} for walking (go/goto)");
|
||||
return;
|
||||
case "":
|
||||
Say($"portal and recall routing {(_portalsEnabled ? "ON" : "OFF")}; {CustomSummary()} — /rnav portals on|off | scan [yd] | list | forget <name> | clear confirm | custom on|off");
|
||||
return;
|
||||
case "custom":
|
||||
string v = arg.ToLowerInvariant();
|
||||
if (v is "on" or "off") { _customOn = v == "on"; NavDataConfig.WriteSwitch("customPortals", _customOn); }
|
||||
else if (v.Length > 0) { SayFail("/rnav portals custom on|off — this server's own portals in routes"); return; }
|
||||
Say($"custom portals in routes: {(_customOn ? "ON" : "OFF")}; {CustomSummary()}");
|
||||
return;
|
||||
case "scan": CmdPortalScan(arg); return;
|
||||
case "list": CmdPortalList(); return;
|
||||
case "forget":
|
||||
if (!CustomReady(out string server)) return;
|
||||
if (arg.Length == 0) { SayFail("/rnav portals forget <name>"); return; }
|
||||
int n = _custom.Forget(server, arg);
|
||||
if (n == 0) SayFail($"portals: no custom portal called {arg} on {server}");
|
||||
else Say($"portals: forgot {n} custom portal(s) called {arg} on {server}");
|
||||
return;
|
||||
case "clear":
|
||||
if (!CustomReady(out server)) return;
|
||||
if (!arg.Equals("confirm", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
var (saved, _) = _custom.Counts(server);
|
||||
SayFail($"portals: /rnav portals clear confirm forgets all {saved} custom portal(s) of {server}");
|
||||
return;
|
||||
}
|
||||
Say($"portals: forgot all {_custom.Clear(server)} custom portal(s) of {server}");
|
||||
_customLast = "cleared";
|
||||
return;
|
||||
default:
|
||||
SayFail("/rnav portals on|off | scan [yd] | list | forget <name> | clear confirm | custom on|off");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
private bool CustomReady(out string server)
|
||||
{
|
||||
server = _server;
|
||||
if (!_customLoaded) { SayFail($"portals: {CustomPortalsFile} isn't loaded yet"); return false; }
|
||||
if (server.Length == 0) { SayFail("portals: not logged in to a server yet"); return false; }
|
||||
return true;
|
||||
}
|
||||
|
||||
private string CustomSummary()
|
||||
{
|
||||
if (_server.Length == 0) return "custom portals: not logged in yet";
|
||||
var (saved, routable) = _custom.Counts(_server);
|
||||
return $"{saved} custom portal(s) saved for {_server}, {routable} routable{(_customOn ? "" : " (not used: custom off)")}";
|
||||
}
|
||||
|
||||
/// <summary>/rnav portals scan [yd]: every live portal object on the map within that range, written down.</summary>
|
||||
private void CmdPortalScan(string arg)
|
||||
{
|
||||
if (!CustomReady(out string server)) return;
|
||||
if (!_hasPose) { SayFail("portals scan: no player position yet"); return; }
|
||||
double range = ScanDefaultUnits;
|
||||
if (arg.Length > 0 && (!double.TryParse(arg, System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture, out range) || range <= 0))
|
||||
{ SayFail("/rnav portals scan [yards] — e.g. /rnav portals scan 200"); return; }
|
||||
range = Math.Clamp(range, 10, 2000);
|
||||
if (!Host.HasGetLiveObjectIds) { SayFail("portals scan: this RynthCore can't list objects"); return; }
|
||||
EnsurePortalsLoaded();
|
||||
int added = 0, refreshed = 0, builtIn = 0, inDungeon = 0;
|
||||
var names = new List<string>();
|
||||
DateTime now = DateTime.UtcNow;
|
||||
foreach (uint id in Host.GetLiveObjectIds())
|
||||
{
|
||||
if (!Host.TryGetItemType(id, out uint type) || (type & ItemTypePortal) == 0) continue;
|
||||
if (!Host.TryGetObjectPosition(id, out uint cell, out float x, out float y, out float z) || cell == 0) continue;
|
||||
if (!IsOnMap(cell)) { inDungeon++; continue; }
|
||||
double wx = ((cell >> 24) & 0xFF) * 192.0 + x, wy = ((cell >> 16) & 0xFF) * 192.0 + y;
|
||||
if (Math.Sqrt((wx - _wx) * (wx - _wx) + (wy - _wy) * (wy - _wy)) > range) continue;
|
||||
if (!Host.TryGetObjectName(id, out string name) || name.Length == 0 || Entrance.IsDestroyed(name)) continue;
|
||||
Host.TryGetObjectWcid(id, out uint wcid);
|
||||
switch (_custom.Saw(server, name, wcid, cell, x, y, z, NavCoords.NsFromWorld(wy), NavCoords.EwFromWorld(wx), _tsvPortals, now))
|
||||
{
|
||||
case CustomSeen.Added: added++; if (names.Count < 6) names.Add(name); break;
|
||||
case CustomSeen.Refreshed: refreshed++; break;
|
||||
default: builtIn++; break;
|
||||
}
|
||||
}
|
||||
var (saved, routable) = _custom.Counts(server);
|
||||
_customLast = $"scan: {added} new, {refreshed} known, {builtIn} in the world data";
|
||||
Host.Log($"[RynthNav] portals scan ({range:F0} yd, {server}): {added} new, {refreshed} known, {builtIn} in portals.tsv, {inDungeon} in dungeons (not mapped)");
|
||||
Say($"portals scan ({range:F0} yd): {added} new{(names.Count > 0 ? " (" + string.Join(", ", names) + (added > names.Count ? ", …" : "") + ")" : "")}, "
|
||||
+ $"{refreshed} already saved, {builtIn} already in the world data. {saved} saved for {server}, {routable} routable"
|
||||
+ (added > 0 ? "; take each once and routes can use it" : ""));
|
||||
}
|
||||
|
||||
private void CmdPortalList()
|
||||
{
|
||||
if (!CustomReady(out string server)) return;
|
||||
List<CustomPortal> list = _custom.For(server);
|
||||
if (list.Count == 0) { Say($"portals: no custom portals saved for {server} — /rnav portals scan writes down the ones around you"); return; }
|
||||
Say($"portals: {CustomSummary()}:");
|
||||
bool hasPos = PlayerMapPos(out double pns, out double pew);
|
||||
list.Sort((x, y) => (hasPos ? NavCoords.Distance(pns, pew, x.Ns, x.Ew) : 0).CompareTo(hasPos ? NavCoords.Distance(pns, pew, y.Ns, y.Ew) : 0));
|
||||
int shown = 0;
|
||||
foreach (CustomPortal p in list)
|
||||
{
|
||||
if (++shown > 20) { Say($" … and {list.Count - 20} more"); break; }
|
||||
Say($" {p.Name} at {NavCoords.Fmt(p.Ns, p.Ew)}{(hasPos ? ", " + NavCoords.FmtDistance(NavCoords.Distance(pns, pew, p.Ns, p.Ew)) : "")} → {p.Where}");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>The panel's custom portals fields (status JSON "custom"). Any thread: the counts are the tick's.</summary>
|
||||
private void AppendCustomJson(StringBuilder sb)
|
||||
{
|
||||
string server = _server;
|
||||
int saved = _customSaved, routable = _customRoutable;
|
||||
sb.Append(",\"custom\":{\"on\":").Append(_customOn ? 1 : 0).Append(",\"server\":\"").Append(Esc(server))
|
||||
.Append("\",\"saved\":").Append(saved).Append(",\"routable\":").Append(routable)
|
||||
.Append(",\"range\":").Append(((int)ScanDefaultUnits).ToString(System.Globalization.CultureInfo.InvariantCulture))
|
||||
.Append(",\"last\":\"").Append(Esc(_customLast)).Append("\"}");
|
||||
}
|
||||
}
|
||||
74
Plugins/RynthCore.Plugin.RynthNav/RynthNavPlugin.Follow.cs
Normal file
74
Plugins/RynthCore.Plugin.RynthNav/RynthNavPlugin.Follow.cs
Normal file
|
|
@ -0,0 +1,74 @@
|
|||
using System;
|
||||
|
||||
namespace RynthCore.Plugin.RynthNav;
|
||||
|
||||
// Walks keep to the trip's own path (TripFollow.cs, 2026-11-27): each re-plan of a walking step aims a few yards
|
||||
// along the walk the path markers draw, rather than at the route graph's next crossing. On by default;
|
||||
// /rnav follow on|off (rynthnav.json followTrip; the status JSON's "follow"). The trip's path is worked out for a
|
||||
// goto with follow on even when the markers are off. Tick thread.
|
||||
// Spotted by SilentKelpie (Forgejo rynth PR #12); re-implemented here.
|
||||
public sealed partial class RynthNavPlugin
|
||||
{
|
||||
private volatile bool _followTrip = true;
|
||||
private TripFollow? _follow;
|
||||
private bool _offTripSaid;
|
||||
|
||||
private void LoadFollowSettings() => _followTrip = NavDataConfig.ReadSwitch("followTrip", true);
|
||||
|
||||
/// <summary>The trip's path is wanted for walking (follow on, a goto's own trip).</summary>
|
||||
private bool FollowWantsPath(PlannedTrip? trip) => _followTrip && trip != null && trip.Live;
|
||||
|
||||
/// <summary>/rnav follow [on|off]</summary>
|
||||
private void CmdFollow(string rest)
|
||||
{
|
||||
string a = rest.Trim().ToLowerInvariant();
|
||||
if (a is "on" or "off")
|
||||
{
|
||||
_followTrip = a == "on";
|
||||
NavDataConfig.WriteSwitch("followTrip", _followTrip);
|
||||
_follow = null;
|
||||
lock (_gotoGate) _gotoPath = null; // re-plan the walk in hand the new way
|
||||
if (_followTrip && _gotoActive) StartPathBuild();
|
||||
}
|
||||
else if (a.Length > 0) { SayFail("/rnav follow on|off — walks keep to the trip's path (the markers), or plan their own way"); return; }
|
||||
Say(_followTrip ? "follow ON: walks keep to the trip's path (the markers)"
|
||||
: "follow OFF: walks plan their own way to the route's crossings");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The walk to follow for the running goto's step, or null: follow off, no live trip, its path not worked out
|
||||
/// yet, not on the map, no walk for this step, or a walk that is only a straight line (nothing to keep to).
|
||||
/// </summary>
|
||||
private TripFollow? CurrentFollow()
|
||||
{
|
||||
PlannedTrip? trip = _trip;
|
||||
TripPath? path = _tripPath;
|
||||
if (!_followTrip || trip == null || !trip.Live || path == null || path.TripId != trip.Id || !IsOnMap(_cellId)) return null;
|
||||
int step = _route != null ? _routeIdx : 0;
|
||||
if (step < 0 || step >= path.Walks.Length || path.Walks[step] is not { Length: >= 2 } walk) return null;
|
||||
if (_follow != null && _follow.TripId == trip.Id && _follow.Step == step) return _follow;
|
||||
string tag = $"step {step + 1}:";
|
||||
foreach (string n in path.Notes)
|
||||
if (n.StartsWith(tag, StringComparison.Ordinal) && n.Contains("straight line", StringComparison.Ordinal)) return null;
|
||||
_follow = new TripFollow(trip.Id, step, walk);
|
||||
_offTripSaid = false;
|
||||
Host.Log($"[RynthNav] walk: keeping to the trip's path for step {step + 1} ({_follow.Length:F0}u, {walk.Length} points)");
|
||||
return _follow;
|
||||
}
|
||||
|
||||
/// <summary>Replan: the steer along the trip's path, when this step has one and its end isn't next. Null = plan as before.</summary>
|
||||
private (float Ew, float Up, float Ns)? FollowSteer()
|
||||
{
|
||||
if (CurrentFollow() is not TripFollow follow) return null;
|
||||
WorldPt aim = follow.Aim(_wx, _wy, out double off, out bool atEnd);
|
||||
if (atEnd) return null;
|
||||
if (off > TripFollow.OffUnits && !_offTripSaid)
|
||||
{
|
||||
_offTripSaid = true;
|
||||
Host.Log($"[RynthNav] walk: {off:F0}u off the trip's path at {NavCoords.Fmt(NavCoords.NsFromWorld(_wy), NavCoords.EwFromWorld(_wx))}: heading back to it");
|
||||
}
|
||||
else if (off <= TripFollow.OffUnits) _offTripSaid = false;
|
||||
double up = double.IsNaN(aim.H) ? _wz : aim.H;
|
||||
return ((float)aim.X, (float)up, (float)aim.Y);
|
||||
}
|
||||
}
|
||||
237
Plugins/RynthCore.Plugin.RynthNav/RynthNavPlugin.Inside.cs
Normal file
237
Plugins/RynthCore.Plugin.RynthNav/RynthNavPlugin.Inside.cs
Normal file
|
|
@ -0,0 +1,237 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using RynthCore.Plugin.Shared;
|
||||
using RynthNav.Routing;
|
||||
|
||||
namespace RynthCore.Plugin.RynthNav;
|
||||
|
||||
// Going to someone INSIDE a dungeon (2026-11-27; InsidePlaces.cs has the choices). /rnav go <name> for a person,
|
||||
// vendor, lifestone or landmark the Atlas has in a dungeon cell:
|
||||
// * already in that dungeon: arrived;
|
||||
// * a portal on the map into it: the usual go into that portal (a route with portals and recalls when far);
|
||||
// * a recall you know that lands in it: cast, as a one-step route.
|
||||
// Arriving, the line ends "(<name> is in cell XXXXXXXX)", and (Walk inside on, the default) the walk to that
|
||||
// cell is handed to RynthAi's dungeon map: /ra dunnav-to cell <cell> walkonly <name>, a walk with fighting,
|
||||
// looting, buffing and the meta off, put back after (2026-11-27). "Fight on the way in" (/rnav inside fight on,
|
||||
// off by default) hands it over without walkonly: the macro as set, fighting and looting on the way, as its
|
||||
// other dungeon walks do. RynthNav has no navmesh in dungeons. "/rnav inside a || b" says which of those
|
||||
// people is in the dungeon you're in, and never travels. Tick thread.
|
||||
// Spotted by SilentKelpie (Forgejo rynth PR #12); re-implemented here.
|
||||
public sealed partial class RynthNavPlugin
|
||||
{
|
||||
/// <summary>The go's target inside a dungeon: the name (the goto's own name) and its cell (0 = none).</summary>
|
||||
private string _insideName = "";
|
||||
private uint _insideCell;
|
||||
/// <summary>Hand the walk inside to RynthAi on arrival (rynthnav.json insideWalk).</summary>
|
||||
private volatile bool _insideWalkOn = true;
|
||||
/// <summary>The walk inside fights, loots and buffs on the way, the macro as set (rynthnav.json insideFight, off:
|
||||
/// a walk only).</summary>
|
||||
private volatile bool _insideFightOn;
|
||||
/// <summary>A walk inside waiting to go to RynthAi: once the landing has settled.</summary>
|
||||
private string _handoffName = "";
|
||||
private uint _handoffCell;
|
||||
private long _handoffDueMs, _handoffGiveUpMs;
|
||||
|
||||
private const long HandoffSettleMs = 2500, HandoffGiveUpMs = 30000;
|
||||
|
||||
private void LoadInsideSettings()
|
||||
{
|
||||
_insideWalkOn = NavDataConfig.ReadSwitch("insideWalk", true);
|
||||
_insideFightOn = NavDataConfig.ReadSwitch("insideFight", false);
|
||||
}
|
||||
|
||||
/// <summary>"a || b" for go: someone inside a dungeon, when no earlier candidate is on the map. True when handled.</summary>
|
||||
private bool TryGoInsideAlternative(string text)
|
||||
{
|
||||
bool hasPos = PlayerMapPos(out double pns, out double pew);
|
||||
AtlasLocation? inside = InsidePlaces.FromAlternatives(_atlas, text, hasPos, pns, pew, CurrentLandblock);
|
||||
return inside != null && GoInside(inside);
|
||||
}
|
||||
|
||||
/// <summary>One name for go: someone inside a dungeon when the map has nothing better for it. True when handled.</summary>
|
||||
private bool TryGoInside(string text)
|
||||
{
|
||||
if (text.Length == 0 || _store.FindFavorite(text) != null || NavCoords.TrySplitCoordsAndName(text, out _, out _, out _)) return false;
|
||||
bool hasPos = PlayerMapPos(out double pns, out double pew);
|
||||
AtlasLocation? inside = InsidePlaces.Prefer(_atlas, text, hasPos, pns, pew, CurrentLandblock, out _);
|
||||
return inside != null && GoInside(inside);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// route / arrow for someone inside a dungeon: the portal into it, as the target (its name says who for).
|
||||
/// False when the name isn't someone inside, or there's no portal on the map into their dungeon (said).
|
||||
/// </summary>
|
||||
private bool InsideTarget(string text, out string name, out string type, out double ns, out double ew, out bool handled)
|
||||
{
|
||||
name = ""; type = ""; ns = 0; ew = 0; handled = false;
|
||||
if (text.Length == 0 || _store.FindFavorite(text) != null || NavCoords.TrySplitCoordsAndName(text, out _, out _, out _)) return false;
|
||||
bool hasPos = PlayerMapPos(out double pns, out double pew);
|
||||
AtlasLocation? inside = InsidePlaces.Prefer(_atlas, text, hasPos, pns, pew, CurrentLandblock, out _);
|
||||
if (inside == null) return false;
|
||||
handled = true;
|
||||
InsideWay w = InsidePlaces.WayIn(_atlas, inside, _cellId, hasPos, pns, pew, _known, _recallsEnabled);
|
||||
if (w.Portal == null)
|
||||
{
|
||||
Note(w.Kind == InsideWayKind.Here ? $"{inside.Name} is inside {w.Dungeon}, where you are{InsidePlaces.Tail(inside.Name, w.Cell)}"
|
||||
: w.Kind == InsideWayKind.Recall ? $"{inside.Name} is inside {w.Dungeon}; no portal on the map leads there, but {w.Recall!.Name} does: /rnav go {inside.Name}"
|
||||
: InsidePlaces.NoWayText(w));
|
||||
return false;
|
||||
}
|
||||
name = $"{w.Portal.Name} (into {w.Dungeon}, for {inside.Name})"; type = "Portal"; ns = w.Portal.Ns; ew = w.Portal.Ew;
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>The way into <paramref name="place"/>'s dungeon, started. True when handled (gone, or why not said).</summary>
|
||||
private bool GoInside(AtlasLocation place)
|
||||
{
|
||||
if (!_hasPose) { Note("goto: no player position yet"); return true; }
|
||||
bool hasPos = PlayerMapPos(out double pns, out double pew);
|
||||
InsideWay w = InsidePlaces.WayIn(_atlas, place, _cellId, hasPos, pns, pew, _known, _recallsEnabled);
|
||||
if (w.Cell == 0) return false;
|
||||
switch (w.Kind)
|
||||
{
|
||||
case InsideWayKind.Here:
|
||||
_insideName = place.Name; _insideCell = w.Cell;
|
||||
_gotoName = place.Name;
|
||||
Host.Log($"[RynthNav] goto {place.Name}: already in {w.Dungeon} (cell {w.Cell:X8})");
|
||||
Say($"goto: you're in {w.Dungeon}: {place.Name} is inside{InsidePlaces.Tail(place.Name, w.Cell)}");
|
||||
QueueHandoff(place.Name, w.Cell, 0);
|
||||
return true;
|
||||
case InsideWayKind.Portal:
|
||||
_insideName = place.Name; _insideCell = w.Cell;
|
||||
_nextEnterPortal = w.Portal!.Name; // the portal object a saved nav route names (RynthNavPlugin.SaveRoute.cs)
|
||||
Say($"goto: {place.Name} is inside {w.Dungeon}: going in by {w.Portal.Name} at {NavCoords.Fmt(w.Portal.Ns, w.Portal.Ew)}");
|
||||
StartGoto(place.Name, place.Type, w.Portal.Ns, w.Portal.Ew, w.Dungeon, "Dungeon");
|
||||
return true;
|
||||
case InsideWayKind.Recall:
|
||||
StartRecallInto(place, w);
|
||||
return true;
|
||||
default:
|
||||
Note("goto: " + InsidePlaces.NoWayText(w));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>A goto of one recall step into the dungeon: cast, wait for the teleport, arrive (the usual recall step and settle).</summary>
|
||||
private void StartRecallInto(AtlasLocation place, InsideWay w)
|
||||
{
|
||||
AtlasRecall r = w.Recall!;
|
||||
if (_gotoActive) { _gotoActive = false; _route = null; _portalWait = false; ResetHub(); AutoRun.Stop(); HideMarkers("a new goto"); }
|
||||
if (_recallWait) EndRecall();
|
||||
_goJobId = 0; _paused = false;
|
||||
_landReplanned = false; _tripReplans = 0; _enterPortal = ""; _nextEnterPortal = "";
|
||||
_portalWait = false; _portalWaitTicks = 0; _wasPortaling = false; _settling = false;
|
||||
_enterName = ""; _enterType = "";
|
||||
_finalTew = _wx; _finalTns = _wy;
|
||||
ResetHub();
|
||||
_routeRecalls = new List<RecallOption> { new() { Name = r.Name, SpellId = r.SpellId, CastSeconds = RecallPlanner.SpellCastSeconds } };
|
||||
bool hasPos = PlayerMapPos(out double pns, out double pew);
|
||||
_route = new List<RouteStep> { new(hasPos ? pns : 0, hasPos ? pew : 0, usePortal: false, useRecall: true, r.Name, 0, double.NaN, double.NaN) };
|
||||
_routeIdx = 0;
|
||||
_tripEst = double.NaN;
|
||||
_shownRoute = _route; _shownRouteFor = place.Name; _shownRouteEst = 0; _shownRouteLive = true; _routeVersion++;
|
||||
_insideName = place.Name; _insideCell = w.Cell;
|
||||
_gotoActive = true;
|
||||
_gotoName = place.Name; _gotoType = place.Type;
|
||||
_walkHaveLast = false;
|
||||
AutoRun.Forget();
|
||||
Host.Log($"[RynthNav] goto {place.Name} (inside {w.Dungeon}, cell {w.Cell:X8}) by {r.Name}");
|
||||
Say($"goto: {place.Name} is inside {w.Dungeon}: casting {r.Name} — /rnav stop to cancel");
|
||||
BeginRecallStep();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// FinishGoto: the arrival line's tail for a target inside a dungeon, and the walk inside queued for RynthAi.
|
||||
/// The target is forgotten either way. "" when this goto wasn't for someone inside, or didn't get there.
|
||||
/// </summary>
|
||||
private string TakeInsideTail(string status)
|
||||
{
|
||||
string name = _insideName;
|
||||
uint cell = _insideCell;
|
||||
_insideName = ""; _insideCell = 0;
|
||||
if (cell == 0 || !status.StartsWith("arrived", StringComparison.Ordinal) || !name.Equals(_gotoName, StringComparison.Ordinal)) return "";
|
||||
if (CurrentLandblock != cell >> 16) return "";
|
||||
QueueHandoff(name, cell, HandoffSettleMs);
|
||||
return InsidePlaces.Tail(name, cell);
|
||||
}
|
||||
|
||||
private void QueueHandoff(string name, uint cell, long settleMs)
|
||||
{
|
||||
if (!_insideWalkOn) return;
|
||||
_handoffName = name; _handoffCell = cell;
|
||||
_handoffDueMs = NowMs + settleMs; _handoffGiveUpMs = NowMs + HandoffGiveUpMs;
|
||||
}
|
||||
|
||||
/// <summary>The walk inside, handed to RynthAi once the landing has settled (out of portal space). Tick thread.</summary>
|
||||
private void TickInsideHandoff()
|
||||
{
|
||||
if (_handoffCell == 0) return;
|
||||
long now = NowMs;
|
||||
if (now > _handoffGiveUpMs || (_hasPose && CurrentLandblock != _handoffCell >> 16 && now > _handoffDueMs)) { _handoffCell = 0; return; }
|
||||
if (now < _handoffDueMs || !_hasPose || (Host.HasIsPortaling && Host.IsPortaling())) return;
|
||||
if (_gotoActive) { _handoffCell = 0; return; } // another goto started meanwhile: it wins
|
||||
string cmd = InsidePlaces.WalkCommand(_handoffCell, _handoffName, _insideFightOn);
|
||||
string name = _handoffName;
|
||||
_handoffCell = 0;
|
||||
if (SubmitToRynthAi(cmd)) Host.Log($"[RynthNav] inside: handed the walk to RynthAi: {cmd}");
|
||||
else Note($"goto: {name} is further in; RynthAi isn't loaded to walk the dungeon map there ({cmd})");
|
||||
}
|
||||
|
||||
/// <summary>A command line through RynthAi's "RynthAi.Script" interface (its own commands run at once). False when RynthAi isn't there.</summary>
|
||||
private unsafe bool SubmitToRynthAi(string line)
|
||||
{
|
||||
if (!Host.HasGetPluginInterface) return false;
|
||||
var t = (RynthAiScriptApiV1*)Host.GetPluginInterface("RynthAi", RynthAiScriptApiV1.InterfaceName, RynthAiScriptApiV1.InterfaceVersion);
|
||||
if (t == null || t->Version < 1 || t->StructSize < (uint)sizeof(RynthAiScriptApiV1) || t->SubmitCommand == null) return false;
|
||||
byte[] utf8 = new byte[Encoding.UTF8.GetByteCount(line) + 1];
|
||||
Encoding.UTF8.GetBytes(line, 0, line.Length, utf8, 0);
|
||||
fixed (byte* p = utf8) return t->SubmitCommand(p) != 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// /rnav inside a || b: which of these people is in THIS dungeon, and in which cell (a script, already inside,
|
||||
/// before it walks the dungeon). Never travels. /rnav inside walk on|off: hand the walk inside to RynthAi.
|
||||
/// </summary>
|
||||
private void CmdInside(string text)
|
||||
{
|
||||
string t = text.Trim();
|
||||
if (t.StartsWith("walk", StringComparison.OrdinalIgnoreCase) && (t.Length == 4 || t[4] == ' '))
|
||||
{
|
||||
string a = t.Substring(4).Trim().ToLowerInvariant();
|
||||
if (a is "on" or "off") { _insideWalkOn = a == "on"; NavDataConfig.WriteSwitch("insideWalk", _insideWalkOn); }
|
||||
else if (a.Length > 0) { SayFail("/rnav inside walk on|off — hand the walk inside a dungeon to RynthAi's dungeon map"); return; }
|
||||
Say(_insideWalkOn ? "walk inside: ON — a go to someone inside a dungeon hands the last stretch to RynthAi's dungeon map ("
|
||||
+ (_insideFightOn ? "fighting on the way in: the macro as set)" : "a walk only: no fighting, looting or buffing)")
|
||||
: "walk inside: OFF — a go to someone inside a dungeon stops at the way in");
|
||||
return;
|
||||
}
|
||||
// /rnav inside fight on|off (2026-11-27): the walk inside fights, loots and buffs on the way (off: a walk only).
|
||||
if (t.StartsWith("fight", StringComparison.OrdinalIgnoreCase) && (t.Length == 5 || t[5] == ' '))
|
||||
{
|
||||
string a = t.Substring(5).Trim().ToLowerInvariant();
|
||||
if (a is "on" or "off") { _insideFightOn = a == "on"; NavDataConfig.WriteSwitch("insideFight", _insideFightOn); }
|
||||
else if (a.Length > 0) { SayFail("/rnav inside fight on|off — the walk inside a dungeon fights, loots and buffs on the way (off: a walk only)"); return; }
|
||||
Say(_insideFightOn ? "fight on the way in: ON — RynthAi's walk inside a dungeon runs its macro as set (fights, loots and buffs on the way)"
|
||||
: "fight on the way in: OFF — RynthAi's walk inside a dungeon is a walk only (fighting, looting, buffing and the meta off, put back after)");
|
||||
return;
|
||||
}
|
||||
if (t.Length == 0) { SayFail("/rnav inside <name> [|| <name> ...] — which of these is in this dungeon | inside walk on|off | inside fight on|off"); return; }
|
||||
uint here = CurrentLandblock;
|
||||
bool inDungeon = (_cellId & 0xFFFF) >= InsidePlaces.FirstDungeonCell;
|
||||
string elsewhere = "";
|
||||
foreach (string raw in t.Split("||", StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries))
|
||||
{
|
||||
AtlasLocation? l = _atlas.FindInside(raw, here);
|
||||
if (l == null || !Atlas.TryCell(l.Cell, out uint cell)) continue;
|
||||
if (inDungeon && cell >> 16 == here)
|
||||
{
|
||||
Say($"inside: {l.Name} is here{InsidePlaces.Tail(l.Name, cell)}");
|
||||
return;
|
||||
}
|
||||
if (elsewhere.Length == 0) elsewhere = $"{l.Name} is in {InsidePlaces.DungeonName(_atlas, cell >> 16)}, not here";
|
||||
}
|
||||
SayFail("inside: " + (elsewhere.Length > 0 ? elsewhere : "none of these is someone inside a dungeon: " + t.Replace("||", ",")));
|
||||
}
|
||||
}
|
||||
|
|
@ -117,7 +117,7 @@ public sealed partial class RynthNavPlugin
|
|||
_markLb = CurrentLandblock;
|
||||
_saveConflict = "";
|
||||
_saveDefault = NavRouteExport.SafeName("To " + goal);
|
||||
if (_markersOn && buildPath) StartPathBuild();
|
||||
if ((_markersOn || FollowWantsPath(trip)) && buildPath) StartPathBuild(); // a goto keeps to it (RynthNavPlugin.Follow.cs)
|
||||
_markerStatus = "working out the path…";
|
||||
return trip;
|
||||
}
|
||||
|
|
@ -176,7 +176,7 @@ public sealed partial class RynthNavPlugin
|
|||
return;
|
||||
}
|
||||
var (path, ms, tiles) = task.Result;
|
||||
if (_trip == null || path.TripId != _trip.Id) { if (_markersOn || _pendingSave != null) StartPathBuild(); return; } // planned for an older trip
|
||||
if (_trip == null || path.TripId != _trip.Id) { if (_markersOn || _pendingSave != null || FollowWantsPath(_trip)) StartPathBuild(); return; } // planned for an older trip
|
||||
_tripPath = path;
|
||||
int points = 0;
|
||||
foreach (WorldPt[]? w in path.Walks) points += w?.Length ?? 0;
|
||||
|
|
|
|||
|
|
@ -170,6 +170,13 @@ public sealed partial class RynthNavPlugin
|
|||
sb.Append(",\"markers\":{\"on\":").Append(_markersOn ? 1 : 0).Append(",\"labels\":").Append(_markerLabels ? 1 : 0)
|
||||
.Append(",\"guide\":").Append(_markerGuide ? 1 : 0).Append(",\"shown\":").Append(trip != null && _tripShown ? 1 : 0)
|
||||
.Append(",\"status\":\"").Append(Esc(_markerStatus)).Append("\"}");
|
||||
// Someone inside a dungeon (RynthNavPlugin.Inside.cs): the walk inside handed to RynthAi, on or off, and
|
||||
// whether it fights on the way (off: a walk only).
|
||||
sb.Append(",\"inside\":{\"walk\":").Append(_insideWalkOn ? 1 : 0).Append(",\"fight\":").Append(_insideFightOn ? 1 : 0).Append('}');
|
||||
// This server's own portals (RynthNavPlugin.CustomPortals.cs).
|
||||
AppendCustomJson(sb);
|
||||
// Walks keep to the trip's path (RynthNavPlugin.Follow.cs).
|
||||
sb.Append(",\"follow\":{\"on\":").Append(_followTrip ? 1 : 0).Append('}');
|
||||
string pathJson = PathJson(); // the walking path, for the engine's World Map
|
||||
if (pathJson.Length > 0) sb.Append(",\"path\":").Append(pathJson);
|
||||
sb.Append(",\"save\":{\"can\":").Append(trip != null ? 1 : 0).Append(",\"for\":\"").Append(Esc(trip?.Goal ?? ""))
|
||||
|
|
|
|||
|
|
@ -120,6 +120,7 @@ public sealed partial class RynthNavPlugin
|
|||
|
||||
private void InitTravel()
|
||||
{
|
||||
LoadCustomPortals(); // this server's own portals (RynthNavPlugin.CustomPortals.cs)
|
||||
string path = NavFile("locations.json");
|
||||
Task.Run(() =>
|
||||
{
|
||||
|
|
@ -156,7 +157,7 @@ public sealed partial class RynthNavPlugin
|
|||
|
||||
private void OnLoginTravel()
|
||||
{
|
||||
_charKey = ""; _playerName = ""; _known = null; _nextKnownMs = 0;
|
||||
_charKey = ""; _playerName = ""; _known = null; _nextKnownMs = 0; _server = ""; _nearPortal = null;
|
||||
_pendingRecallSlot = null; _castRecallSpell = 0; _pendingTie = null; _selfCastMs = 0;
|
||||
_trkHaveLast = false; _trkPortaling = false;
|
||||
}
|
||||
|
|
@ -168,6 +169,7 @@ public sealed partial class RynthNavPlugin
|
|||
_trkHaveLast = false; _trkPortaling = false;
|
||||
_known = null; _charKey = "";
|
||||
SaveStores(force: true);
|
||||
OnLogoutCustom();
|
||||
}
|
||||
|
||||
// ── Tick ─────────────────────────────────────────────────────────────────
|
||||
|
|
@ -203,7 +205,9 @@ public sealed partial class RynthNavPlugin
|
|||
|
||||
bool teleported = TrackTeleport(now);
|
||||
UpdateArrow(teleported);
|
||||
TickInsideHandoff(); // the walk inside a dungeon, handed to RynthAi (RynthNavPlugin.Inside.cs)
|
||||
|
||||
TickCustomPortals(now, save: now >= _nextSaveMs); // RynthNavPlugin.CustomPortals.cs
|
||||
if (now >= _nextSaveMs) { _nextSaveMs = now + 3000; SaveStores(force: false); }
|
||||
RebuildTravelJson();
|
||||
}
|
||||
|
|
@ -321,6 +325,7 @@ public sealed partial class RynthNavPlugin
|
|||
// Your spell words shortly before portal space, standing still since, not dead, no portal
|
||||
// right beside you: a recall cast by hand (walking into a portal moves you; using one you
|
||||
// stand at doesn't, hence the portal check; dying is a trip, not a recall).
|
||||
bool spellWords = _selfCastMs != 0 && startMs - _selfCastMs >= 0 && startMs - _selfCastMs < HandCastWindowMs;
|
||||
bool handCast = _selfCastMs != 0 && startMs - _selfCastMs >= 0 && startMs - _selfCastMs < HandCastWindowMs
|
||||
&& !_selfCastDied && havePre && !portalBeside
|
||||
&& Math.Sqrt((preWx - _selfCastWx) * (preWx - _selfCastWx) + (preWy - _selfCastWy) * (preWy - _selfCastWy)) < HandCastStillUnits;
|
||||
|
|
@ -364,6 +369,9 @@ public sealed partial class RynthNavPlugin
|
|||
// Not a recall we know of: a portal, most likely. Portal Recall goes back to where
|
||||
// the last portal dropped you. A landing at a known recall's spot (a recall cast by
|
||||
// hand, or dying and waking at the lifestone) isn't a portal.
|
||||
// A custom server's own portal you stood beside: its landing (RynthNavPlugin.CustomPortals.cs). Before the
|
||||
// recall check: a portal into a town lands beside its recall spot.
|
||||
LearnCustomPortal(havePre, preCell, preWx, preWy, startMs, landing, spellWords);
|
||||
if (landing.OnMap && LandsLikeARecall(landing)) return;
|
||||
string label = landing.Label;
|
||||
int? bitmask = null;
|
||||
|
|
@ -1062,11 +1070,14 @@ public sealed partial class RynthNavPlugin
|
|||
private const string HelpText =
|
||||
"/rnav arrow <place|coords> | arrow off | arrow route <place> — the arrow (one target: a new one replaces the route, and a walk elsewhere)\n" +
|
||||
"/rnav clear — no target: the walk stops, the route goes, the arrow goes off\n" +
|
||||
"/rnav go <place|coords> — walk there (route with portals/recalls when /rnav portals on)\n" +
|
||||
"/rnav go <place|coords> — walk there (route with portals/recalls when /rnav portals on); someone inside a dungeon: the way in, then RynthAi's dungeon map to them\n" +
|
||||
"/rnav inside <name> [|| <name>] — which of these is in this dungeon | inside walk on|off — hand the walk inside to RynthAi\n" +
|
||||
"/rnav route <place|coords> — plan a route (portals and recalls), no walking\n" +
|
||||
"/rnav route next — another way to the same place (switches a running goto) | route go — walk the way shown\n" +
|
||||
"/rnav atlas <search> — find places | fav [place] — favorite | recalls [on|off] | tie 1|2|lifestone\n" +
|
||||
"/rnav goto <coords> | preview <coords> | portals on|off | stop | here | load | test | navdata\n" +
|
||||
"/rnav portals scan [yd] | list | forget <name> | clear confirm | custom on|off — this server's own portals (a landing is learned the first time you take one)\n" +
|
||||
"/rnav follow on|off — walks keep to the trip's path (the markers), or plan their own way to the route's crossings\n" +
|
||||
"/rnav pause — stop walking, keep the trip on the map (drive by hand meanwhile) | resume — carry on\n" +
|
||||
"/rnav times — how long this character's trips take (run speed, portals, recalls, portal space)\n" +
|
||||
"/rnav avoid — show; avoid portals on|off|<m> | walls on|off|<m> | corners <m>\n" +
|
||||
|
|
@ -1087,6 +1098,8 @@ public sealed partial class RynthNavPlugin
|
|||
// "go a || b || c" (Oracle's Dynamic Stamps, any caller): the first candidate on the map.
|
||||
if (cmd is "go" or "goto" or "route" or "arrow" && rest.Contains("||", StringComparison.Ordinal))
|
||||
{
|
||||
// Someone inside a dungeon (RynthNavPlugin.Inside.cs), when no earlier candidate is on the map: the way in.
|
||||
if (cmd is "go" or "goto") { _insideName = ""; _insideCell = 0; if (TryGoInsideAlternative(rest)) return; }
|
||||
if (!PickAlternative(rest, out string picked, out string why)) { Note(why); return; }
|
||||
rest = picked;
|
||||
}
|
||||
|
|
@ -1105,11 +1118,7 @@ public sealed partial class RynthNavPlugin
|
|||
case "navdata": Say($"tiles and Atlas folder: {NavDataDir} ({NavConfig.Source}); route graph: {_graphStatus}; Town Network: {_townNetStatus}"); break;
|
||||
case "avoid": CmdAvoid(rest); break;
|
||||
case "aphus": CmdAphus(rest.Trim().ToLowerInvariant()); break;
|
||||
case "portals":
|
||||
_portalsEnabled = !rest.Equals("off", StringComparison.OrdinalIgnoreCase);
|
||||
NavDataConfig.WriteSwitch("portals", _portalsEnabled);
|
||||
Say($"portal and recall routing {(_portalsEnabled ? "ON" : "OFF")} for walking (go/goto)");
|
||||
break;
|
||||
case "portals": CmdPortals(rest); break; // on|off, and this server's own portals (RynthNavPlugin.CustomPortals.cs)
|
||||
case "stop": DoMove(5); Say("stopped"); break;
|
||||
case "pause": CmdPause(); break; // RynthNavPlugin.Pause.cs
|
||||
case "times": CmdTimes(); break; // RynthNavPlugin.TripTime.cs
|
||||
|
|
@ -1119,6 +1128,8 @@ public sealed partial class RynthNavPlugin
|
|||
CmdGo(rest);
|
||||
break;
|
||||
case "route": CmdRoute(rest); break;
|
||||
case "inside": CmdInside(rest); break; // RynthNavPlugin.Inside.cs
|
||||
case "follow": CmdFollow(rest); break; // RynthNavPlugin.Follow.cs
|
||||
case "arrow": CmdArrow(rest); break;
|
||||
case "clear": CmdClear(); break; // RynthNavPlugin.Target.cs
|
||||
case "atlas": CmdAtlas(rest); break;
|
||||
|
|
@ -1180,7 +1191,11 @@ public sealed partial class RynthNavPlugin
|
|||
Say($"arrow route to {n}: {used} teleport(s). First: {StepText(_arrow.Current!)}{(rended.Length > 0 ? $" ({rended})" : "")}.");
|
||||
return;
|
||||
}
|
||||
if (!ResolveTarget(rest, out string name, out string type, out double ns, out double ew, out string error)) { Note(error); return; }
|
||||
string name, type; double ns, ew;
|
||||
// Someone inside a dungeon: the arrow points at the portal into it (RynthNavPlugin.Inside.cs).
|
||||
if (InsideTarget(rest, out name, out type, out ns, out ew, out bool inside)) { }
|
||||
else if (inside) return;
|
||||
else if (!ResolveTarget(rest, out name, out type, out ns, out ew, out string error)) { Note(error); return; }
|
||||
HeldTarget held = Held();
|
||||
TargetChange c = TargetSwitch.For(NewTarget.Arrow, held, ns, ew);
|
||||
if (c.KeepArrow)
|
||||
|
|
@ -1195,6 +1210,9 @@ public sealed partial class RynthNavPlugin
|
|||
|
||||
private void CmdGo(string rest)
|
||||
{
|
||||
// Someone inside a dungeon, when the map has nothing better for the name (RynthNavPlugin.Inside.cs).
|
||||
_insideName = ""; _insideCell = 0;
|
||||
if (TryGoInside(rest)) return;
|
||||
if (!ResolveGo(rest, out string name, out string type, out double ns, out double ew, out string enter, out string enterType, out string error))
|
||||
{
|
||||
Note(error);
|
||||
|
|
@ -1253,7 +1271,11 @@ public sealed partial class RynthNavPlugin
|
|||
// "route next": another way to the last place planned for; "route go": walk the way shown.
|
||||
if (rest.Equals("next", StringComparison.OrdinalIgnoreCase) || rest.Equals("another", StringComparison.OrdinalIgnoreCase)) { CmdRouteNext(); return; }
|
||||
if (rest.Equals("go", StringComparison.OrdinalIgnoreCase)) { CmdRouteGo(); return; }
|
||||
if (!ResolveTarget(rest, out string name, out string type, out double ns, out double ew, out string error)) { Note(error); return; }
|
||||
string name, type; double ns, ew;
|
||||
// Someone inside a dungeon: the route to the portal into it (RynthNavPlugin.Inside.cs).
|
||||
if (InsideTarget(rest, out name, out type, out ns, out ew, out bool inside)) { }
|
||||
else if (inside) return;
|
||||
else if (!ResolveTarget(rest, out name, out type, out ns, out ew, out string error)) { Note(error); return; }
|
||||
if (!_hasPose) { Note("no player pose yet"); return; }
|
||||
ShowRoute(name, type, ns, ew);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -155,6 +155,8 @@ public sealed partial class RynthNavPlugin : RynthPluginBase
|
|||
_portalsEnabled = NavDataConfig.ReadSwitch("portals", true);
|
||||
_recallsEnabled = NavDataConfig.ReadSwitch("recalls", true);
|
||||
LoadAvoidSettings();
|
||||
LoadInsideSettings(); // RynthNavPlugin.Inside.cs
|
||||
LoadFollowSettings(); // RynthNavPlugin.Follow.cs
|
||||
LoadMarkerSettings();
|
||||
LoadMeshSettings();
|
||||
Host.Log($"[RynthNav] Initialized v{PluginVersion} (tiled streaming + long-range goto + portal/recall routing + arrow + atlas + route maker). Panel: RynthNav. Tiles: {NavDataDir} ({NavConfig.Source})");
|
||||
|
|
@ -899,8 +901,10 @@ public sealed partial class RynthNavPlugin : RynthPluginBase
|
|||
AutoRun.Stop();
|
||||
lock (_gate) _status = status;
|
||||
_gotoEndStatus = status; _gotoEndSeq++; // a route maker go job reads how it ended (RynthNavPlugin.RouteMaker.cs)
|
||||
Host.Log($"[RynthNav] goto: {status}");
|
||||
Say(status == "arrived" && _gotoName.Length > 0 ? $"goto: arrived at {_gotoName}" : $"goto: {status}");
|
||||
// Someone inside a dungeon (RynthNavPlugin.Inside.cs): where in it, and the walk there handed on.
|
||||
string inside = TakeInsideTail(status);
|
||||
Host.Log($"[RynthNav] goto: {status}{inside}");
|
||||
Say((status == "arrived" && _gotoName.Length > 0 ? $"goto: arrived at {_gotoName}" : $"goto: {status}") + inside);
|
||||
_goNote = status == "arrived" && _gotoName.Length > 0 ? $"arrived at {_gotoName}" : status;
|
||||
if (status == "arrived") _wayChosenMs = 0; // there: the next trip there is planned afresh (RynthNavPlugin.Ways.cs)
|
||||
_enterName = ""; _enterType = "";
|
||||
|
|
@ -979,7 +983,7 @@ public sealed partial class RynthNavPlugin : RynthPluginBase
|
|||
|
||||
private void EnsurePortalsLoaded()
|
||||
{
|
||||
if (_portals != null) return;
|
||||
if (_tsvPortals != null) return;
|
||||
var list = new List<PortalLink>();
|
||||
int withRules = 0;
|
||||
try
|
||||
|
|
@ -1003,7 +1007,9 @@ public sealed partial class RynthNavPlugin : RynthPluginBase
|
|||
else Host.Log("[RynthNav] portals.tsv not found — portal routing off");
|
||||
}
|
||||
catch (Exception ex) { Host.Log($"[RynthNav] portals load failed: {ex.Message}"); }
|
||||
_portals = list;
|
||||
// The route planner's list: these, then this server's custom portals (RynthNavPlugin.CustomPortals.cs).
|
||||
_tsvPortals = list; _routeLinksKey = "";
|
||||
RefreshRoutePortals();
|
||||
}
|
||||
|
||||
// Returns the leg list if portals or recalls beat walking, else null (pure navmesh goto).
|
||||
|
|
@ -1103,6 +1109,9 @@ public sealed partial class RynthNavPlugin : RynthPluginBase
|
|||
bool loadedMore = false;
|
||||
var steer = CoarseSteer(sRef, sPt, ref loadedMore);
|
||||
if (loadedMore) _query = new DtNavMeshQuery(_navMesh!);
|
||||
// The trip's own path (RynthNavPlugin.Follow.cs): a few yards along the walk the markers draw, so the
|
||||
// walk keeps to it instead of finding its own way to the route graph's next crossing.
|
||||
if (FollowSteer() is { } along) steer = along;
|
||||
|
||||
// Prefer a DIRECT path to the actual target when its tile is loaded — one stable
|
||||
// corridor we follow steadily. Only fall back to the 500u line-probe leapfrog when
|
||||
|
|
|
|||
72
Plugins/RynthCore.Plugin.RynthNav/StuckWatch.cs
Normal file
72
Plugins/RynthCore.Plugin.RynthNav/StuckWatch.cs
Normal file
|
|
@ -0,0 +1,72 @@
|
|||
using System;
|
||||
|
||||
namespace RynthCore.Plugin.RynthNav;
|
||||
|
||||
/// <summary>
|
||||
/// Is the walk blocked? Until 2026-11-27 only a tick that ran counted, and a tick turning in place
|
||||
/// started the watch again. A walk swinging between headings against a wall (run a moment, turn a
|
||||
/// moment) never ran <see cref="RunWindowMs"/> in a row, so it was never seen as blocked and stood
|
||||
/// there until the 30 s progress watchdog stopped the goto. Now every tick the walk drives counts,
|
||||
/// running or turning: moved less than <see cref="MoveUnits"/> over <see cref="RunWindowMs"/> with
|
||||
/// some running in it, or over <see cref="TurnWindowMs"/> of turning only, is blocked. A tick that
|
||||
/// doesn't drive (standing, waiting for a plan) starts the watch again. Host-free: the route tests
|
||||
/// drive it.
|
||||
/// </summary>
|
||||
internal sealed class StuckWatch
|
||||
{
|
||||
/// <summary>A window with running in it: this long...</summary>
|
||||
public const long RunWindowMs = 1200;
|
||||
/// <summary>...or this long turning only (a half turn on the spot takes about a second)...</summary>
|
||||
public const long TurnWindowMs = 3000;
|
||||
/// <summary>...and moved less than this = blocked (a run covers 4+ u/s).</summary>
|
||||
public const double MoveUnits = 0.6;
|
||||
|
||||
private long _winMs;
|
||||
private double _x, _y;
|
||||
private bool _drove, _ranInWindow;
|
||||
|
||||
/// <summary>The walk drove this tick: running, or turning in place (<paramref name="running"/> false).</summary>
|
||||
public void Drove(bool running)
|
||||
{
|
||||
_drove = true;
|
||||
if (running) _ranInWindow = true;
|
||||
}
|
||||
|
||||
public void Reset()
|
||||
{
|
||||
_winMs = 0;
|
||||
_drove = false;
|
||||
_ranInWindow = false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Once a walking tick, before steering: true when blocked (a window ended and the character
|
||||
/// moved less than <see cref="MoveUnits"/> in it). <paramref name="moved"/> and
|
||||
/// <paramref name="windowMs"/> describe the window that ended; both 0 when none did.
|
||||
/// </summary>
|
||||
public bool Check(long now, double x, double y, out double moved, out long windowMs)
|
||||
{
|
||||
moved = 0;
|
||||
windowMs = 0;
|
||||
bool drove = _drove;
|
||||
_drove = false;
|
||||
if (!drove || _winMs == 0)
|
||||
{
|
||||
Start(now, x, y);
|
||||
return false;
|
||||
}
|
||||
long elapsed = now - _winMs;
|
||||
if (elapsed < (_ranInWindow ? RunWindowMs : TurnWindowMs)) return false;
|
||||
windowMs = elapsed;
|
||||
moved = Math.Sqrt((x - _x) * (x - _x) + (y - _y) * (y - _y));
|
||||
Start(now, x, y);
|
||||
return moved < MoveUnits;
|
||||
}
|
||||
|
||||
private void Start(long now, double x, double y)
|
||||
{
|
||||
_winMs = now;
|
||||
_x = x; _y = y;
|
||||
_ranInWindow = false;
|
||||
}
|
||||
}
|
||||
104
Plugins/RynthCore.Plugin.RynthNav/TripFollow.cs
Normal file
104
Plugins/RynthCore.Plugin.RynthNav/TripFollow.cs
Normal file
|
|
@ -0,0 +1,104 @@
|
|||
using System;
|
||||
|
||||
namespace RynthCore.Plugin.RynthNav;
|
||||
|
||||
/// <summary>
|
||||
/// Keeps a goto on its trip's own path (2026-11-27). The trip's ground (TripPath: the walk the path markers draw
|
||||
/// and "save as nav route" writes) is worked out once per step, but the walker never used it: every re-plan aimed
|
||||
/// at the route graph's next border crossing (or straight at the step's point), so the walk took its own way,
|
||||
/// across a field or round the far side of a building, away from the markers.
|
||||
///
|
||||
/// Now each re-plan aims <see cref="AheadUnits"/> along the step's walk past where you are on it, and the navmesh
|
||||
/// plans just those yards, so walls and the portal circles are kept out of as before. More than
|
||||
/// <see cref="OffUnits"/> off the walk (knocked off it, stepped round something), the aim is the walk again, a
|
||||
/// little past its nearest point. How far along you are only ever grows, and the nearest point is looked for only
|
||||
/// a little behind it, so a walk that comes back close to itself is never cut across.
|
||||
/// Host-free: the route tests drive it. Spotted by SilentKelpie (Forgejo rynth PR #12); re-implemented here.
|
||||
/// </summary>
|
||||
internal sealed class TripFollow
|
||||
{
|
||||
/// <summary>How far along the walk past where you are each re-plan aims (yards).</summary>
|
||||
public const double AheadUnits = 28.0;
|
||||
/// <summary>Farther than this from the walk is off it: aim back at it.</summary>
|
||||
public const double OffUnits = 14.0;
|
||||
/// <summary>Off the walk: aim this far past its nearest point.</summary>
|
||||
public const double RejoinUnits = 6.0;
|
||||
/// <summary>The nearest point on the walk is looked for this far behind the progress so far...</summary>
|
||||
public const double BackUnits = 12.0;
|
||||
/// <summary>...and this far ahead of it.</summary>
|
||||
public const double ForwardUnits = 90.0;
|
||||
|
||||
private readonly WorldPt[] _pts;
|
||||
private readonly double[] _along; // yards from the start to each point
|
||||
private double _progress;
|
||||
|
||||
public int TripId { get; }
|
||||
public int Step { get; }
|
||||
public double Length => _along[^1];
|
||||
/// <summary>How far along the walk you are (yards; never goes back).</summary>
|
||||
public double Progress => _progress;
|
||||
|
||||
public TripFollow(int tripId, int step, WorldPt[] pts)
|
||||
{
|
||||
if (pts == null || pts.Length < 2) throw new ArgumentException("a walk needs two points", nameof(pts));
|
||||
TripId = tripId; Step = step;
|
||||
_pts = pts;
|
||||
_along = new double[pts.Length];
|
||||
for (int i = 1; i < pts.Length; i++) _along[i] = _along[i - 1] + pts[i].FlatDistance(pts[i - 1]);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Where to plan to from (x, y): <see cref="AheadUnits"/> along the walk past where you are, or (more than
|
||||
/// <see cref="OffUnits"/> from it) a little past its nearest point. <paramref name="off"/>: yards from the walk.
|
||||
/// <paramref name="atEnd"/>: the aim is the walk's end (the step's own point: plan to it as before).
|
||||
/// </summary>
|
||||
public WorldPt Aim(double x, double y, out double off, out bool atEnd)
|
||||
{
|
||||
double s = NearestAlong(x, y, out off);
|
||||
double aim;
|
||||
if (off > OffUnits) aim = s + RejoinUnits;
|
||||
else
|
||||
{
|
||||
if (s > _progress) _progress = s;
|
||||
aim = _progress + AheadUnits;
|
||||
}
|
||||
atEnd = aim >= Length;
|
||||
return atEnd ? _pts[^1] : At(aim);
|
||||
}
|
||||
|
||||
/// <summary>The point <paramref name="s"/> yards along the walk (its height between the points' heights).</summary>
|
||||
public WorldPt At(double s)
|
||||
{
|
||||
s = Math.Clamp(s, 0, Length);
|
||||
int i = 1;
|
||||
while (i < _pts.Length - 1 && _along[i] < s) i++;
|
||||
double seg = _along[i] - _along[i - 1];
|
||||
double t = seg < 1e-9 ? 0 : (s - _along[i - 1]) / seg;
|
||||
WorldPt a = _pts[i - 1], b = _pts[i];
|
||||
return new WorldPt(a.X + (b.X - a.X) * t, a.Y + (b.Y - a.Y) * t, a.H + (b.H - a.H) * t);
|
||||
}
|
||||
|
||||
/// <summary>How far along the walk its nearest point to (x, y) is, within BackUnits behind and ForwardUnits ahead of the progress.</summary>
|
||||
private double NearestAlong(double x, double y, out double dist)
|
||||
{
|
||||
double lo = Math.Max(0, _progress - BackUnits), hi = _progress + ForwardUnits;
|
||||
double best = double.MaxValue, bestS = _progress;
|
||||
for (int i = 1; i < _pts.Length; i++)
|
||||
{
|
||||
double s0 = _along[i - 1], s1 = _along[i];
|
||||
if (s1 < lo) continue;
|
||||
if (s0 > hi) break;
|
||||
double ax = _pts[i - 1].X, ay = _pts[i - 1].Y, vx = _pts[i].X - ax, vy = _pts[i].Y - ay;
|
||||
double len = s1 - s0;
|
||||
double t = len < 1e-9 ? 0 : Math.Clamp(((x - ax) * vx + (y - ay) * vy) / (len * len), 0, 1);
|
||||
// Only the part of the segment inside the window counts.
|
||||
double tLo = len < 1e-9 ? 0 : Math.Clamp((lo - s0) / len, 0, 1), tHi = len < 1e-9 ? 1 : Math.Clamp((hi - s0) / len, 0, 1);
|
||||
t = Math.Clamp(t, tLo, tHi);
|
||||
double px = ax + vx * t - x, py = ay + vy * t - y;
|
||||
double d = Math.Sqrt(px * px + py * py);
|
||||
if (d < best) { best = d; bestS = s0 + len * t; }
|
||||
}
|
||||
dist = best;
|
||||
return bestS;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue