Snapshot for release 2026.10.8.1 (internal f3d67ec)
This commit is contained in:
parent
e5950ddb04
commit
0daf0a44a3
49 changed files with 2802 additions and 121 deletions
|
|
@ -22,7 +22,7 @@ internal sealed class AtlasLocation
|
|||
// A portal's destination.
|
||||
public bool HasDest, DestOnMap;
|
||||
public double DestNs, DestEw;
|
||||
public string DestName = "", DestPlace = "";
|
||||
public string DestName = "", DestPlace = "", DestCell = "";
|
||||
public int MinLevel, MaxLevel;
|
||||
public bool Quest, Closed;
|
||||
}
|
||||
|
|
@ -92,6 +92,7 @@ internal sealed class Atlas
|
|||
l.DestOnMap = TryNum(d, "ns", out l.DestNs) & TryNum(d, "ew", out l.DestEw);
|
||||
l.DestName = Str(d, "name");
|
||||
l.DestPlace = Str(d, "place");
|
||||
l.DestCell = Str(d, "cell");
|
||||
}
|
||||
locs.Add(l);
|
||||
}
|
||||
|
|
@ -110,6 +111,36 @@ internal sealed class Atlas
|
|||
|
||||
public AtlasLocation? ById(int id) => _byId.TryGetValue(id, out var l) ? l : null;
|
||||
|
||||
/// <summary>
|
||||
/// Landblocks that are dungeons: places (and portal destinations) the Atlas has in "dungeon"
|
||||
/// cells, less any landblock with places on the map. A dungeon's nav_XXXX.tile holds only that
|
||||
/// landblock's surface (a flat sheet; RynthNav.Baker leaves dungeon cells out), so it isn't
|
||||
/// a navmesh for walking inside the dungeon.
|
||||
/// </summary>
|
||||
public HashSet<uint> DungeonLandblocks()
|
||||
{
|
||||
var dungeon = new HashSet<uint>();
|
||||
var map = new HashSet<uint>();
|
||||
foreach (AtlasLocation l in Locations)
|
||||
{
|
||||
if (TryLandblock(l.Cell, out uint lb))
|
||||
{
|
||||
if (l.OnMap) map.Add(lb);
|
||||
else if (l.Place.Equals("dungeon", StringComparison.Ordinal)) dungeon.Add(lb);
|
||||
}
|
||||
if (l.HasDest && !l.DestOnMap && l.DestPlace.Equals("dungeon", StringComparison.Ordinal) && TryLandblock(l.DestCell, out uint dlb))
|
||||
dungeon.Add(dlb);
|
||||
}
|
||||
dungeon.ExceptWith(map);
|
||||
return dungeon;
|
||||
}
|
||||
|
||||
private static bool TryLandblock(string cell, out uint lb)
|
||||
{
|
||||
lb = 0;
|
||||
return cell.Length == 8 && uint.TryParse(cell.AsSpan(0, 4), NumberStyles.HexNumber, CultureInfo.InvariantCulture, out lb);
|
||||
}
|
||||
|
||||
// ── Search ───────────────────────────────────────────────────────────────
|
||||
|
||||
/// <summary>How well <paramref name="name"/> matches <paramref name="q"/> (lower case): 0 = not at all.</summary>
|
||||
|
|
|
|||
|
|
@ -8,7 +8,11 @@ namespace RynthCore.Plugin.RynthNav;
|
|||
// Where a character's personal recalls land. The client is never told (the server keeps
|
||||
// a character's lifestone, ties, last portal and house), so RynthNav learns them from what
|
||||
// it sees: the server's messages ("You have attuned your spirit to this Lifestone.", "X is
|
||||
// recalling home.") and the teleport that follows. Saved per character in
|
||||
// recalling home.") and the teleport that follows, and a teleport right after your own spell
|
||||
// words (a recall cast by hand: RecallPlanner.GuessHandCast). ACE sends a character neither
|
||||
// its tie positions (PlayerDescription carries only LastOutsideDeath) nor the tied portals'
|
||||
// data ids (LinkedPortalOne/Two aren't SendOnLogin and change silently), so a tie made
|
||||
// before RynthNav was there is learned on the first cast of its recall. Saved per character in
|
||||
// NavData\recalls.txt. No host calls: the offline tests compile this file.
|
||||
// (GoArrow kept the same kind of per-character recall list; Digero 2006, Virindi 2011, MIT.)
|
||||
|
||||
|
|
@ -61,6 +65,9 @@ internal enum RecallEvent
|
|||
RecallingHometown,
|
||||
/// <summary>"Name is recalling to the marketplace." (lands in a dungeon: never used for routes).</summary>
|
||||
RecallingMarketplace,
|
||||
/// <summary>"You say, "Zojak Ququ"" on the spellcasting channel: you started casting a spell
|
||||
/// (a recall cast by hand teleports a few seconds later).</summary>
|
||||
OwnSpellWords,
|
||||
}
|
||||
|
||||
internal sealed class RecallMemory
|
||||
|
|
@ -108,15 +115,21 @@ internal sealed class RecallMemory
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>ChatMessageType.Spellcasting: the words a caster speaks (yours: "You say, "...").</summary>
|
||||
public const int ChatTypeSpellcasting = 17;
|
||||
|
||||
/// <summary>
|
||||
/// Reads a chat line (the server's own wording, ACE's Player_Location / Lifestone /
|
||||
/// WorldObject_Magic). <paramref name="playerName"/> picks out your own "is recalling"
|
||||
/// lines from other players' nearby.
|
||||
/// lines from other players' nearby. <paramref name="chatType"/> tells your spell words
|
||||
/// (Spellcasting, 17) from something you typed in local chat (Speech, 2).
|
||||
/// </summary>
|
||||
public static RecallEvent Classify(string? text, string? playerName)
|
||||
public static RecallEvent Classify(string? text, string? playerName, int chatType = -1)
|
||||
{
|
||||
if (string.IsNullOrEmpty(text)) return RecallEvent.None;
|
||||
string t = text.Trim();
|
||||
if (chatType == ChatTypeSpellcasting && t.StartsWith("You say, \"", StringComparison.Ordinal))
|
||||
return RecallEvent.OwnSpellWords;
|
||||
if (t.StartsWith("You have attuned your spirit to this Lifestone", StringComparison.OrdinalIgnoreCase))
|
||||
return RecallEvent.AttunedLifestone;
|
||||
if (t.StartsWith("You have successfully linked with the life stone", StringComparison.OrdinalIgnoreCase))
|
||||
|
|
|
|||
|
|
@ -71,13 +71,13 @@ internal static class RecallPlanner
|
|||
if (known != null)
|
||||
{
|
||||
AddLearnedSpell(list, notes, known, memory, charKey, LifestoneRecall, "Lifestone Recall", RecallSlot.Lifestone,
|
||||
"cast Lifestone Tie on a lifestone");
|
||||
"cast Lifestone Tie on a lifestone, cast Lifestone Recall once, or /rnav tie lifestone at the tied lifestone");
|
||||
AddLearnedSpell(list, notes, known, memory, charKey, PortalRecall, "Portal Recall", RecallSlot.LastPortal,
|
||||
"walk through a portal");
|
||||
AddLearnedSpell(list, notes, known, memory, charKey, PrimaryPortalTieRecall, "Primary Portal Tie Recall", RecallSlot.Tie1,
|
||||
"cast Primary Portal Tie on a portal");
|
||||
"cast Primary Portal Tie on a portal, cast Primary Portal Tie Recall once, or /rnav tie 1 at the tied portal");
|
||||
AddLearnedSpell(list, notes, known, memory, charKey, SecondaryPortalTieRecall, "Secondary Portal Tie Recall", RecallSlot.Tie2,
|
||||
"cast Secondary Portal Tie on a portal");
|
||||
"cast Secondary Portal Tie on a portal, cast Secondary Portal Tie Recall once, or /rnav tie 2 at the tied portal");
|
||||
}
|
||||
|
||||
// Command recalls (no spell): @lifestone always; house, mansion and hometown
|
||||
|
|
@ -123,6 +123,115 @@ internal static class RecallPlanner
|
|||
|
||||
private static string Where(RecallSpot s) => s.Label.Length > 0 ? "in " + s.Label : "in a dungeon";
|
||||
|
||||
// ── Learning from a recall cast by hand ──────────────────────────────────
|
||||
|
||||
/// <summary>Recall the Sanctuary (Lifestone Sending): lands where @lifestone does.</summary>
|
||||
public const int RecallTheSanctuary = 2023;
|
||||
/// <summary>WeenieError YouMustLinkToLifestoneToRecall / YouMustLinkToPortalToRecall.</summary>
|
||||
public const uint ErrorMustLinkLifestone = 0x049E, ErrorMustLinkPortal = 0x04A3;
|
||||
|
||||
/// <summary>What a teleport right after your own spell words teaches.</summary>
|
||||
public enum HandCast
|
||||
{
|
||||
/// <summary>Nothing new (already known, a fixed recall, or can't tell); <c>why</c> says which.</summary>
|
||||
Nothing,
|
||||
/// <summary>The landing of <c>slot</c>.</summary>
|
||||
Learn,
|
||||
/// <summary>A portal tie recall, but not which: ask (/rnav tie 1|2).</summary>
|
||||
AskTie,
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// You spoke spell words, stood still and were teleported: a recall cast by hand. Which
|
||||
/// one, from where it landed: on a lifestone, Lifestone Recall; anywhere else, a portal tie
|
||||
/// recall (Portal Recall's landing is the last portal's, already known). A landing that
|
||||
/// matches a recall already known teaches nothing. When the spellbook leaves more than one
|
||||
/// tie recall (or Portal Recall with no last portal known), ask. No host calls.
|
||||
/// </summary>
|
||||
/// <param name="atLifestone">The landing is on a lifestone (the Atlas's).</param>
|
||||
/// <param name="nearUnits">Two landings this close are the same place.</param>
|
||||
public static HandCast GuessHandCast(RecallSpot landing, bool atLifestone, ISet<int>? known, RecallMemory memory,
|
||||
string charKey, double nearUnits, out RecallSlot slot, out string why)
|
||||
{
|
||||
slot = RecallSlot.Lifestone;
|
||||
if (known == null) { why = "the spellbook isn't read yet"; return HandCast.Nothing; }
|
||||
if (atLifestone)
|
||||
{
|
||||
if (!known.Contains(LifestoneRecall)) { why = "on a lifestone, but Lifestone Recall isn't in the spellbook"; return HandCast.Nothing; }
|
||||
if (Same(memory.Get(charKey, RecallSlot.Lifestone), landing, nearUnits)) { why = "Lifestone Recall, already known"; return HandCast.Nothing; }
|
||||
if (known.Contains(RecallTheSanctuary) && Same(memory.Get(charKey, RecallSlot.Sanctuary), landing, nearUnits))
|
||||
{ why = "on your @lifestone lifestone: Lifestone Recall or Recall the Sanctuary, can't tell"; return HandCast.Nothing; }
|
||||
why = "on a lifestone: Lifestone Recall";
|
||||
return HandCast.Learn;
|
||||
}
|
||||
if (Same(memory.Get(charKey, RecallSlot.LastPortal), landing, nearUnits)) { why = "where the last portal went: Portal Recall"; return HandCast.Nothing; }
|
||||
var ties = new List<RecallSlot>(2);
|
||||
if (known.Contains(PrimaryPortalTieRecall)) ties.Add(RecallSlot.Tie1);
|
||||
if (known.Contains(SecondaryPortalTieRecall)) ties.Add(RecallSlot.Tie2);
|
||||
foreach (RecallSlot t in ties)
|
||||
if (Same(memory.Get(charKey, t), landing, nearUnits)) { slot = t; why = RecallMemory.SlotName(t) + ", already known"; return HandCast.Nothing; }
|
||||
if (ties.Count == 0) { why = "no portal tie recall in the spellbook (a spell's teleport RynthNav doesn't know)"; return HandCast.Nothing; }
|
||||
bool maybePortalRecall = known.Contains(PortalRecall) && memory.Get(charKey, RecallSlot.LastPortal) == null;
|
||||
if (ties.Count == 1 && !maybePortalRecall)
|
||||
{
|
||||
slot = ties[0];
|
||||
why = "the only portal tie recall in the spellbook";
|
||||
return HandCast.Learn;
|
||||
}
|
||||
slot = ties[0];
|
||||
why = maybePortalRecall ? "a portal tie recall or Portal Recall (no last portal known yet)" : "a portal tie recall, primary or secondary";
|
||||
return HandCast.AskTie;
|
||||
}
|
||||
|
||||
/// <summary>Two landings are the same place: on the map within <paramref name="nearUnits"/>; off it, the same label.</summary>
|
||||
public static bool Same(RecallSpot? a, RecallSpot b, double nearUnits)
|
||||
{
|
||||
if (a == null || a.OnMap != b.OnMap) return false;
|
||||
if (a.OnMap) return NavCoords.Distance(a.Ns, a.Ew, b.Ns, b.Ew) < nearUnits;
|
||||
return a.Label.Equals(b.Label, StringComparison.OrdinalIgnoreCase);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The recall the server says isn't linked: "You must link to a lifestone to recall it" is
|
||||
/// always Lifestone Recall; "...to a portal..." is whichever portal recall was just cast
|
||||
/// (<paramref name="castSpell"/>, 0 = not known: nothing).
|
||||
/// </summary>
|
||||
public static RecallSlot? SlotUnlinked(uint error, int castSpell) => error switch
|
||||
{
|
||||
ErrorMustLinkLifestone => RecallSlot.Lifestone,
|
||||
ErrorMustLinkPortal => castSpell switch
|
||||
{
|
||||
PrimaryPortalTieRecall => RecallSlot.Tie1,
|
||||
SecondaryPortalTieRecall => RecallSlot.Tie2,
|
||||
PortalRecall => RecallSlot.LastPortal,
|
||||
_ => null,
|
||||
},
|
||||
_ => null,
|
||||
};
|
||||
|
||||
/// <summary>The recall spell whose landing a slot holds (0 for the command recalls).</summary>
|
||||
public static int SpellFor(RecallSlot slot) => slot switch
|
||||
{
|
||||
RecallSlot.Lifestone => LifestoneRecall,
|
||||
RecallSlot.LastPortal => PortalRecall,
|
||||
RecallSlot.Tie1 => PrimaryPortalTieRecall,
|
||||
RecallSlot.Tie2 => SecondaryPortalTieRecall,
|
||||
_ => 0,
|
||||
};
|
||||
|
||||
/// <summary>A slot's name for players ("Primary Portal Tie Recall", "@lifestone").</summary>
|
||||
public static string Title(RecallSlot slot) => slot switch
|
||||
{
|
||||
RecallSlot.Sanctuary => "@lifestone",
|
||||
RecallSlot.Lifestone => "Lifestone Recall",
|
||||
RecallSlot.LastPortal => "Portal Recall",
|
||||
RecallSlot.Tie1 => "Primary Portal Tie Recall",
|
||||
RecallSlot.Tie2 => "Secondary Portal Tie Recall",
|
||||
RecallSlot.House => "House recall",
|
||||
RecallSlot.Mansion => "Allegiance mansion recall",
|
||||
_ => "Allegiance hometown recall",
|
||||
};
|
||||
|
||||
public static List<RecallLink> Links(List<RecallOption> options)
|
||||
{
|
||||
var links = new List<RecallLink>(options.Count);
|
||||
|
|
|
|||
109
Plugins/RynthCore.Plugin.RynthNav/RynthNavPlugin.Blocked.cs
Normal file
109
Plugins/RynthCore.Plugin.RynthNav/RynthNavPlugin.Blocked.cs
Normal file
|
|
@ -0,0 +1,109 @@
|
|||
using System;
|
||||
using DotRecast.Core.Numerics;
|
||||
using DotRecast.Detour;
|
||||
|
||||
namespace RynthCore.Plugin.RynthNav;
|
||||
|
||||
// Running into a wall: the walk is running but the character isn't moving. The navmesh is baked
|
||||
// with a 2 m agent radius (RynthNav.Baker), which seals gaps under ~4 m and leaves some ground in
|
||||
// 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 at an angle (alternating sides), plan again, and after
|
||||
// StuckMaxTries on one leg without progress stop and say where.
|
||||
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 double UnstickAngleDeg = 120.0; // away from where it was heading, off to one side
|
||||
private const int StuckMaxTries = 4; // blocked this often on a leg without progress = stop
|
||||
|
||||
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 int _stuckTries, _stuckSide = 1;
|
||||
|
||||
/// <summary>DriveTo for the walk's own steering: remembers that it ran and which way.</summary>
|
||||
private void WalkDrive(double deg)
|
||||
{
|
||||
DriveTo(deg);
|
||||
_lastDriveDeg = deg;
|
||||
_ranLastTick = !_turnInPlace;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Nothing between here and (<paramref name="tx"/>, <paramref name="ty"/>) as far as the navmesh
|
||||
/// shows: every metre of the line, bar 2 m at each end (we and a portal stand off the eroded
|
||||
/// mesh), is within 1.5 m of walkable ground. A wall leaves a gap of twice the agent radius plus
|
||||
/// its thickness, over 4 m, so its middle fails. No query (no tiles): true, as before.
|
||||
/// </summary>
|
||||
private bool StraightOnMesh(double tx, double ty)
|
||||
{
|
||||
if (_query == null) return true;
|
||||
var filter = new DtQueryDefaultFilter();
|
||||
double dx = tx - _wx, dy = ty - _wy, len = Math.Sqrt(dx * dx + dy * dy);
|
||||
for (double s = 2.0; s < len - 2.0; s += 1.0)
|
||||
{
|
||||
var pt = new RcVec3f((float)(_wx + dx * s / len), (float)_wz, (float)(_wy + dy * s / len));
|
||||
_query.FindNearestPoly(pt, new RcVec3f(1.5f, 4, 1.5f), filter, out long r, out _, out _);
|
||||
if (r == 0) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>A new leg (or goto): nothing blocked yet.</summary>
|
||||
private void ResetBlocked()
|
||||
{
|
||||
_ranLastTick = false;
|
||||
_stuckWinMs = 0; _unstickUntilMs = 0; _stuckTries = 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Once per walking tick, before steering. True when it drove this tick (stepping round
|
||||
/// something) or finished the goto; the caller returns.
|
||||
/// </summary>
|
||||
private bool StepBlocked()
|
||||
{
|
||||
long now = NowMs;
|
||||
bool ran = _ranLastTick;
|
||||
_ranLastTick = false;
|
||||
if (_unstickUntilMs > now)
|
||||
{
|
||||
DriveTo(_unstickDeg);
|
||||
lock (_gate) _status = $"blocked: stepping round it ({_stuckTries}/{StuckMaxTries})";
|
||||
return true;
|
||||
}
|
||||
if (_unstickUntilMs != 0)
|
||||
{
|
||||
// Stepped aside: plan again from here (and allow one more push where the plan ends).
|
||||
_unstickUntilMs = 0;
|
||||
lock (_gotoGate) _gotoPath = null;
|
||||
_blindTicks = 0; _replanTick = 0;
|
||||
_stuckWinMs = 0;
|
||||
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;
|
||||
|
||||
string at = NavCoords.Fmt(NavCoords.NsFromWorld(_wy), NavCoords.EwFromWorld(_wx));
|
||||
if (++_stuckTries > StuckMaxTries)
|
||||
{
|
||||
string why; lock (_gate) why = _status;
|
||||
FinishGoto($"stopped: blocked at {at} ({StuckMaxTries} tries to get round it; something in the way the map doesn't show) ({why})");
|
||||
return true;
|
||||
}
|
||||
_stuckSide = -_stuckSide;
|
||||
_unstickDeg = ((_lastDriveDeg + 180.0 - _stuckSide * (180.0 - UnstickAngleDeg)) % 360.0 + 360.0) % 360.0;
|
||||
_unstickUntilMs = now + UnstickMs;
|
||||
Host.Log($"[RynthNav] walk: blocked at {at} heading {_lastDriveDeg:F0} (moved {moved:F1}u in {StuckWindowMs / 1000.0:F1} s); "
|
||||
+ $"turning to {_unstickDeg:F0} and planning again ({_stuckTries}/{StuckMaxTries})");
|
||||
DriveTo(_unstickDeg);
|
||||
lock (_gate) _status = $"blocked: stepping round it ({_stuckTries}/{StuckMaxTries})";
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
@ -114,13 +114,14 @@ public sealed partial class RynthNavPlugin
|
|||
long now = NowMs;
|
||||
if (landblockChanged && _hasPose)
|
||||
{
|
||||
try { _tileHere = File.Exists(Path.Combine(NavDataDir, $"nav_{CurrentLandblock:X4}.tile")) ? 1 : 0; } catch { _tileHere = -1; }
|
||||
// A dungeon's tile is its landblock's surface: no navmesh here (RynthNavPlugin.InDungeon).
|
||||
try { _tileHere = !InDungeon(_cellId) && File.Exists(Path.Combine(NavDataDir, $"nav_{CurrentLandblock:X4}.tile")) ? 1 : 0; } catch { _tileHere = -1; }
|
||||
}
|
||||
if (now < _nextInfoMs || now - Interlocked.Read(ref _lastStatusPollMs) > PanelPollWindowMs) return;
|
||||
_nextInfoMs = now + InfoRefreshMs;
|
||||
if (Interlocked.Exchange(ref _infoBusy, 1) != 0) return;
|
||||
uint lb = CurrentLandblock;
|
||||
bool hasPose = _hasPose;
|
||||
bool hasPose = _hasPose, dungeon = InDungeon(_cellId);
|
||||
Task.Run(() =>
|
||||
{
|
||||
try
|
||||
|
|
@ -129,7 +130,7 @@ public sealed partial class RynthNavPlugin
|
|||
if (Directory.Exists(NavDataDir))
|
||||
foreach (string _ in Directory.EnumerateFiles(NavDataDir, "nav_*.tile")) n++;
|
||||
_tilesOnDisk = n;
|
||||
if (hasPose) _tileHere = File.Exists(Path.Combine(NavDataDir, $"nav_{lb:X4}.tile")) ? 1 : 0;
|
||||
if (hasPose) _tileHere = !dungeon && File.Exists(Path.Combine(NavDataDir, $"nav_{lb:X4}.tile")) ? 1 : 0;
|
||||
}
|
||||
catch { }
|
||||
finally { Interlocked.Exchange(ref _infoBusy, 0); }
|
||||
|
|
|
|||
|
|
@ -29,6 +29,10 @@ public sealed partial class RynthNavPlugin
|
|||
private const long RecallCastWindowMs = 40000; // our own recall cast -> the teleport within this
|
||||
private const long RecallStepTimeoutMs = 45000; // a route's recall step gives up after this
|
||||
private const long RecallRecastMs = 4500; // re-cast a recall spell this often while waiting
|
||||
private const long HandCastWindowMs = 12000; // your spell words -> portal space within this = a recall cast by hand
|
||||
private const double HandCastStillUnits = 2.0; // ...standing still meanwhile (walking into a portal moves you)
|
||||
private const double LifestoneLandUnits = 10.0; // a landing this close to a lifestone = on it (Lifestone Recall)
|
||||
private const double PortalBesideUnits = 4.0; // a live portal this close as portal space begins: maybe that portal, not a recall
|
||||
private const long StanceRetryMs = 1500;
|
||||
private const long WandAfterMs = 6000; // no magic stance by then: try wielding a wand
|
||||
private const int CombatModeNonCombat = 1, CombatModeMagic = 8;
|
||||
|
|
@ -37,6 +41,7 @@ public sealed partial class RynthNavPlugin
|
|||
private volatile Atlas _atlas = Atlas.Empty;
|
||||
private volatile string _atlasStatus = "loading…";
|
||||
private HashSet<uint> _mapLandblocks = new(); // landblocks with Atlas places on the map (tick thread)
|
||||
private volatile HashSet<uint> _dungeonLandblocks = new(); // dungeon landblocks the Atlas knows (Atlas.DungeonLandblocks; read-only once built)
|
||||
private AtlasStore _store = new();
|
||||
private RecallMemory _memory = new();
|
||||
private bool _storesLoaded;
|
||||
|
|
@ -67,12 +72,18 @@ public sealed partial class RynthNavPlugin
|
|||
private int _castRecallSpell;
|
||||
private long _castRecallMs;
|
||||
private RecallSpot? _pendingTie;
|
||||
// Your own spell words (a recall cast by hand teleports a few seconds later): when and where.
|
||||
private long _selfCastMs;
|
||||
private double _selfCastWx, _selfCastWy;
|
||||
private bool _selfCastDied;
|
||||
private int _weenieSeq = -1; // the last server refusal looked at (-1 = none yet)
|
||||
|
||||
// Teleport tracking (tick thread).
|
||||
private bool _trkPortaling, _trkHaveLast, _trkHavePre;
|
||||
private uint _trkLastCell, _trkPreCell;
|
||||
private double _trkLastWx, _trkLastWy, _trkPreWx, _trkPreWy;
|
||||
private long _trkLastTeleportMs;
|
||||
private long _trkLastTeleportMs, _trkPortalStartMs;
|
||||
private bool _trkPortalBeside; // a live portal stood right beside you as portal space began
|
||||
|
||||
// Route planning with recalls: the recalls the current route can use (by RouteStep.RecallIndex).
|
||||
private List<RecallOption> _routeRecalls = new();
|
||||
|
|
@ -146,7 +157,7 @@ public sealed partial class RynthNavPlugin
|
|||
private void OnLoginTravel()
|
||||
{
|
||||
_charKey = ""; _playerName = ""; _known = null; _nextKnownMs = 0;
|
||||
_pendingRecallSlot = null; _castRecallSpell = 0; _pendingTie = null;
|
||||
_pendingRecallSlot = null; _castRecallSpell = 0; _pendingTie = null; _selfCastMs = 0;
|
||||
_trkHaveLast = false; _trkPortaling = false;
|
||||
}
|
||||
|
||||
|
|
@ -175,6 +186,7 @@ public sealed partial class RynthNavPlugin
|
|||
foreach (var l in atlas.Locations)
|
||||
if (l.OnMap && l.Cell.Length == 8 && uint.TryParse(l.Cell.AsSpan(0, 4), NumberStyles.HexNumber, null, out uint lb)) lbs.Add(lb);
|
||||
_mapLandblocks = lbs;
|
||||
_dungeonLandblocks = atlas.DungeonLandblocks();
|
||||
_indexedAtlas = atlas;
|
||||
if (_known != null && atlas.Recalls.Count > 0) LogKnownRecalls(_known);
|
||||
}
|
||||
|
|
@ -183,6 +195,10 @@ public sealed partial class RynthNavPlugin
|
|||
|
||||
while (_commands.TryDequeue(out string? cmd)) RunCommand(cmd, fromPanel: false);
|
||||
while (_recallEvents.TryDequeue(out var ev)) OnRecallEvent(ev.Event, ev.Ms);
|
||||
PollRecallRefusal();
|
||||
if (_selfCastMs != 0 && !_selfCastDied && now - _selfCastMs < HandCastWindowMs + 30000
|
||||
&& Host.TryGetPlayerVitals(out uint hp, out uint maxHp, out _, out _, out _, out _) && maxHp > 0 && hp == 0)
|
||||
_selfCastDied = true; // died mid-cast: the trip to the lifestone that follows isn't a recall
|
||||
|
||||
bool teleported = TrackTeleport(now);
|
||||
UpdateArrow(teleported);
|
||||
|
|
@ -250,6 +266,12 @@ public sealed partial class RynthNavPlugin
|
|||
/// <summary>Outdoors, or in a building of a landblock that has Atlas places on the map.</summary>
|
||||
private bool IsOnMap(uint cell) => (cell & 0xFFFF) < 0x100 || _mapLandblocks.Contains(cell >> 16);
|
||||
|
||||
/// <summary>
|
||||
/// In a dungeon the Atlas knows. Its landblock's tile is the surface's (dungeon cells aren't
|
||||
/// baked), so there is no navmesh to walk here even though nav_XXXX.tile exists.
|
||||
/// </summary>
|
||||
private bool InDungeon(uint cell) => (cell & 0xFFFF) >= 0x100 && _dungeonLandblocks.Contains(cell >> 16);
|
||||
|
||||
// ── Teleports: the arrow's portal/recall steps and learning recall landings ──
|
||||
|
||||
private bool TrackTeleport(long now)
|
||||
|
|
@ -260,6 +282,9 @@ public sealed partial class RynthNavPlugin
|
|||
if (!_trkPortaling)
|
||||
{
|
||||
_trkPortaling = true;
|
||||
_trkPortalStartMs = now;
|
||||
// Only worth the look after your own spell words (a hand-cast recall, or a portal used standing at it?).
|
||||
_trkPortalBeside = _selfCastMs != 0 && now - _selfCastMs < HandCastWindowMs && _trkHaveLast && LivePortalWithin(_trkLastWx, _trkLastWy, PortalBesideUnits);
|
||||
_trkHavePre = _trkHaveLast;
|
||||
_trkPreCell = _trkLastCell; _trkPreWx = _trkLastWx; _trkPreWy = _trkLastWy;
|
||||
}
|
||||
|
|
@ -273,23 +298,32 @@ public sealed partial class RynthNavPlugin
|
|||
bool havePre = _trkPortaling ? _trkHavePre : _trkHaveLast;
|
||||
uint preCell = _trkPortaling ? _trkPreCell : _trkLastCell;
|
||||
double preWx = _trkPortaling ? _trkPreWx : _trkLastWx, preWy = _trkPortaling ? _trkPreWy : _trkLastWy;
|
||||
long startMs = _trkPortaling ? _trkPortalStartMs : now;
|
||||
bool portalBeside = _trkPortaling && _trkPortalBeside;
|
||||
_trkPortaling = false;
|
||||
if (now - _trkLastTeleportMs > 2000)
|
||||
{
|
||||
teleported = true;
|
||||
_trkLastTeleportMs = now;
|
||||
OnTeleported(havePre, preCell, preWx, preWy);
|
||||
OnTeleported(havePre, preCell, preWx, preWy, startMs, portalBeside);
|
||||
}
|
||||
}
|
||||
_trkHaveLast = true; _trkLastCell = _cellId; _trkLastWx = _wx; _trkLastWy = _wy;
|
||||
return teleported;
|
||||
}
|
||||
|
||||
private void OnTeleported(bool havePre, uint preCell, double preWx, double preWy)
|
||||
private void OnTeleported(bool havePre, uint preCell, double preWx, double preWy, long startMs, bool portalBeside)
|
||||
{
|
||||
long now = NowMs;
|
||||
RecallSpot landing = SpotHere();
|
||||
string who = _charKey;
|
||||
// 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 handCast = _selfCastMs != 0 && startMs - _selfCastMs >= 0 && startMs - _selfCastMs < HandCastWindowMs
|
||||
&& !_selfCastDied && havePre && !portalBeside
|
||||
&& Math.Sqrt((preWx - _selfCastWx) * (preWx - _selfCastWx) + (preWy - _selfCastWy) * (preWy - _selfCastWy)) < HandCastStillUnits;
|
||||
_selfCastMs = 0; _selfCastDied = false;
|
||||
if (who.Length == 0) return;
|
||||
|
||||
if (_pendingRecallSlot is RecallSlot slot && now - _pendingRecallMs < RecallAnnounceWindowMs)
|
||||
|
|
@ -312,7 +346,17 @@ public sealed partial class RynthNavPlugin
|
|||
RecallPlanner.SecondaryPortalTieRecall => RecallSlot.Tie2,
|
||||
_ => null,
|
||||
};
|
||||
if (learned is RecallSlot ls) _memory.Set(who, ls, landing);
|
||||
if (learned is RecallSlot ls)
|
||||
{
|
||||
_memory.Set(who, ls, landing);
|
||||
Host.Log($"[RynthNav] learned {RecallMemory.SlotName(ls)} lands at {Describe(landing)}");
|
||||
}
|
||||
return;
|
||||
}
|
||||
// A recall cast by hand (or by another plugin): never the last portal's landing.
|
||||
if (handCast && !CameThroughAtlasPortal(havePre, preCell, preWx, preWy, landing))
|
||||
{
|
||||
LearnHandCast(landing);
|
||||
return;
|
||||
}
|
||||
// Not a recall we know of: a portal, most likely. Portal Recall goes back to where
|
||||
|
|
@ -341,6 +385,101 @@ public sealed partial class RynthNavPlugin
|
|||
return false;
|
||||
}
|
||||
|
||||
/// <summary>A live portal object within <paramref name="units"/> of a world point (this landblock's objects).</summary>
|
||||
private bool LivePortalWithin(double wx, double wy, double units)
|
||||
{
|
||||
if (!Host.HasGetLiveObjectIds) return false;
|
||||
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 _) || cell == 0) continue;
|
||||
double ox = ((cell >> 24) & 0xFF) * 192.0 + x, oy = ((cell >> 16) & 0xFF) * 192.0 + y;
|
||||
if ((ox - wx) * (ox - wx) + (oy - wy) * (oy - wy) < units * units) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A known portal stood where you were, and goes where you landed: the teleport was that
|
||||
/// portal (used standing at it), not the spell you'd just cast.
|
||||
/// </summary>
|
||||
private bool CameThroughAtlasPortal(bool havePre, uint preCell, double preWx, double preWy, RecallSpot landing)
|
||||
{
|
||||
if (!havePre || !IsOnMap(preCell) || !landing.OnMap) return false;
|
||||
double pns = NavCoords.NsFromWorld(preWy), pew = NavCoords.EwFromWorld(preWx);
|
||||
foreach (AtlasLocation l in _atlas.Locations)
|
||||
{
|
||||
if (!l.OnMap || !l.HasDest || !l.DestOnMap || !l.Type.Equals("Portal", StringComparison.Ordinal)) continue;
|
||||
if (NavCoords.Distance(pns, pew, l.Ns, l.Ew) < PortalNearUnits
|
||||
&& NavCoords.Distance(landing.Ns, landing.Ew, l.DestNs, l.DestEw) < RecallNearUnits) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A recall cast by hand (RynthNav didn't cast it): learn which one from where it landed
|
||||
/// (RecallPlanner.GuessHandCast), so ties made before RynthNav was there, or cast from the
|
||||
/// spell bar, are planned from now on.
|
||||
/// </summary>
|
||||
private void LearnHandCast(RecallSpot landing)
|
||||
{
|
||||
if (landing.OnMap)
|
||||
foreach (AtlasRecall r in _atlas.Recalls)
|
||||
if (r.OnMap && NavCoords.Distance(landing.Ns, landing.Ew, r.Ns, r.Ew) < RecallNearUnits)
|
||||
{
|
||||
Host.Log($"[RynthNav] recall cast by hand landed at {Describe(landing)}: {r.Name}'s landing, nothing to learn");
|
||||
return;
|
||||
}
|
||||
AtlasLocation? ls = landing.OnMap ? _atlas.Nearest("Lifestone", landing.Ns, landing.Ew, LifestoneLandUnits) : null;
|
||||
RecallPlanner.HandCast kind = RecallPlanner.GuessHandCast(landing, ls != null, _known, _memory, _charKey, RecallNearUnits,
|
||||
out RecallSlot slot, out string why);
|
||||
switch (kind)
|
||||
{
|
||||
case RecallPlanner.HandCast.Learn:
|
||||
if (ls != null) landing.Label = ls.Name + (landing.Label.Length > 0 ? " (" + landing.Label + ")" : "");
|
||||
_memory.Set(_charKey, slot, landing);
|
||||
Host.Log($"[RynthNav] learned {RecallMemory.SlotName(slot)} lands at {Describe(landing)} (a recall cast by hand: {why})");
|
||||
Say($"{RecallPlanner.Title(slot)} takes you to {Describe(landing)}: routes can use it now.");
|
||||
break;
|
||||
case RecallPlanner.HandCast.AskTie:
|
||||
_pendingTie = landing;
|
||||
Host.Log($"[RynthNav] recall cast by hand landed at {Describe(landing)}: {why}; asking which tie");
|
||||
Say($"Recalled to {Describe(landing)}. If that was a portal tie recall: /rnav tie 1 (primary) or /rnav tie 2 (secondary).");
|
||||
break;
|
||||
default:
|
||||
Host.Log($"[RynthNav] recall cast by hand landed at {Describe(landing)}: {why}");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The server's "You must link to a lifestone / portal to recall it": that recall has no
|
||||
/// tie (any more), so forget its landing; a route waiting on it plans again without it.
|
||||
/// </summary>
|
||||
private void PollRecallRefusal()
|
||||
{
|
||||
if (!Host.HasGetLastWeenieError || !Host.TryGetLastWeenieError(out int seq, out uint error, out _, out _)) return;
|
||||
if (_weenieSeq < 0 || seq == _weenieSeq) { _weenieSeq = seq; return; } // the first look only notes where the count stands
|
||||
_weenieSeq = seq;
|
||||
int cast = _castRecallSpell != 0 && NowMs - _castRecallMs < RecallCastWindowMs ? _castRecallSpell : 0;
|
||||
if (RecallPlanner.SlotUnlinked(error, cast) is not RecallSlot slot || _charKey.Length == 0) return;
|
||||
bool had = _memory.Get(_charKey, slot) != null;
|
||||
_memory.Clear(_charKey, slot);
|
||||
if (slot == RecallSlot.Tie1 || slot == RecallSlot.Tie2) _pendingTie = null;
|
||||
string name = RecallPlanner.Title(slot);
|
||||
Host.Log($"[RynthNav] {name}: the server says it isn't linked (0x{error:X4}){(had ? "; its landing is forgotten" : "")}");
|
||||
RecallOption? o = _recallWait ? CurrentRecallOption() : null;
|
||||
if (o != null && o.SpellId == RecallPlanner.SpellFor(slot) && _gotoActive)
|
||||
{
|
||||
string goal = _gotoName, type = _gotoType, enter = _enterName, enterType = _enterType;
|
||||
double gns = NavCoords.NsFromWorld(_finalTns), gew = NavCoords.EwFromWorld(_finalTew);
|
||||
Say($"goto: {name} isn't tied to anything; planning again without it");
|
||||
EndRecall();
|
||||
StartWalk(goal.Length > 0 ? goal : NavCoords.Fmt(gns, gew), type, gns, gew, enter, enterType);
|
||||
}
|
||||
else if (had) Say($"{name} isn't tied to anything: routes won't use it until you tie it again.");
|
||||
}
|
||||
|
||||
/// <summary>Where you stand now, as a recall landing: on the map or not, and a label.</summary>
|
||||
private RecallSpot SpotHere()
|
||||
{
|
||||
|
|
@ -362,7 +501,7 @@ public sealed partial class RynthNavPlugin
|
|||
|
||||
public override void OnChatWindowText(string? text, int chatType, ref int eat)
|
||||
{
|
||||
RecallEvent e = RecallMemory.Classify(text, _playerName);
|
||||
RecallEvent e = RecallMemory.Classify(text, _playerName, chatType);
|
||||
if (e != RecallEvent.None) _recallEvents.Enqueue((e, NowMs));
|
||||
}
|
||||
|
||||
|
|
@ -396,6 +535,11 @@ public sealed partial class RynthNavPlugin
|
|||
case RecallEvent.RecallingMarketplace:
|
||||
_pendingRecallSlot = null;
|
||||
break;
|
||||
case RecallEvent.OwnSpellWords:
|
||||
// Any spell: only a teleport soon after, standing here, makes it a recall (OnTeleported).
|
||||
if (!_hasPose) break;
|
||||
_selfCastMs = ms; _selfCastWx = _wx; _selfCastWy = _wy; _selfCastDied = false;
|
||||
break;
|
||||
default:
|
||||
if (RecallMemory.SlotFor(e, out RecallSlot slot))
|
||||
{
|
||||
|
|
@ -428,23 +572,42 @@ public sealed partial class RynthNavPlugin
|
|||
return l == null ? null : new RecallSpot { OnMap = true, Ns = l.Ns, Ew = l.Ew, Label = l.Name };
|
||||
}
|
||||
|
||||
private void OnPortalTied()
|
||||
/// <summary>
|
||||
/// The tied portal: the selected portal, looked up in the Atlas by its weenie class (ACE
|
||||
/// ties the portal's class), else the nearest portal in the Atlas within <paramref name="nearUnits"/>.
|
||||
/// </summary>
|
||||
private AtlasLocation? TiePortal(double nearUnits)
|
||||
{
|
||||
// The tied portal's destination: the selected portal, looked up in the Atlas by its
|
||||
// weenie class (ACE ties the portal's class), else the nearest portal in the Atlas.
|
||||
AtlasLocation? portal = null;
|
||||
uint sel = Host.HasGetSelectedItemId ? Host.GetSelectedItemId() : 0;
|
||||
PlayerMapPos(out double pns, out double pew);
|
||||
if (sel != 0 && Host.TryGetObjectWcid(sel, out uint wcid)) portal = _atlas.PortalByWcid(wcid, pns, pew);
|
||||
portal ??= _hasPose ? _atlas.Nearest("Portal", pns, pew, 60) : null;
|
||||
portal ??= _hasPose ? _atlas.Nearest("Portal", pns, pew, nearUnits) : null;
|
||||
return portal;
|
||||
}
|
||||
|
||||
private static RecallSpot TieLanding(AtlasLocation portal) => portal.DestOnMap
|
||||
? new RecallSpot { OnMap = true, Ns = portal.DestNs, Ew = portal.DestEw, Label = portal.Name }
|
||||
: new RecallSpot { OnMap = false, Label = portal.DestName.Length > 0 ? portal.DestName : portal.Name };
|
||||
|
||||
/// <summary>/rnav tie 1|2 with no tie waiting: where the portal you've selected or stand at goes.</summary>
|
||||
private RecallSpot? TiedPortalSpot(out string why)
|
||||
{
|
||||
AtlasLocation? portal = TiePortal(PortalNearUnits);
|
||||
why = portal == null ? "select the tied portal, or stand at it, first"
|
||||
: !portal.HasDest ? $"{portal.Name} isn't in the Atlas with a destination" : "";
|
||||
return portal != null && portal.HasDest ? TieLanding(portal) : null;
|
||||
}
|
||||
|
||||
private void OnPortalTied()
|
||||
{
|
||||
AtlasLocation? portal = TiePortal(60);
|
||||
if (portal == null || !portal.HasDest)
|
||||
{
|
||||
Say("Portal tie noted, but the portal isn't in the Atlas: its recall won't be used for routes.");
|
||||
return;
|
||||
}
|
||||
var spot = portal.DestOnMap
|
||||
? new RecallSpot { OnMap = true, Ns = portal.DestNs, Ew = portal.DestEw, Label = portal.Name }
|
||||
: new RecallSpot { OnMap = false, Label = portal.DestName.Length > 0 ? portal.DestName : portal.Name };
|
||||
RecallSpot spot = TieLanding(portal);
|
||||
bool k1 = _known?.Contains(RecallPlanner.PrimaryPortalTie) ?? false, k2 = _known?.Contains(RecallPlanner.SecondaryPortalTie) ?? false;
|
||||
if (k1 && !k2) { _memory.Set(_charKey, RecallSlot.Tie1, spot); Say($"Primary portal tie: {portal.Name}."); return; }
|
||||
if (k2 && !k1) { _memory.Set(_charKey, RecallSlot.Tie2, spot); Say($"Secondary portal tie: {portal.Name}."); return; }
|
||||
|
|
@ -819,7 +982,7 @@ public sealed partial class RynthNavPlugin
|
|||
"/rnav arrow <place|coords> | arrow off | arrow route <place> — the arrow\n" +
|
||||
"/rnav go <place|coords> — walk there (route with portals/recalls when /rnav portals on)\n" +
|
||||
"/rnav route <place|coords> — plan a route (portals and recalls), no walking\n" +
|
||||
"/rnav atlas <search> — find places | fav [place] — favorite | recalls [on|off] | tie 1|2\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 avoid — show; avoid portals on|off|<m> | walls on|off|<m> | corners <m>\n" +
|
||||
"/rnav markers on|off | markers labels on|off | markers guide on|off — the trip on the ground\n" +
|
||||
|
|
@ -1026,14 +1189,46 @@ public sealed partial class RynthNavPlugin
|
|||
foreach (string n in notes) Say(" " + n);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// /rnav tie 1|2: which portal tie the last one (or the last tie recall cast by hand) was;
|
||||
/// with none waiting, the portal you have selected or stand at is that tie (a tie made
|
||||
/// before RynthNav was there). /rnav tie lifestone: the lifestone you have selected or
|
||||
/// stand at is the one Lifestone Recall is tied to. /rnav tie clear 1|2|lifestone forgets one.
|
||||
/// </summary>
|
||||
private void CmdTie(string rest)
|
||||
{
|
||||
if (_pendingTie == null || _charKey.Length == 0) { Note("no portal tie waiting — cast a Portal Tie on a portal first"); return; }
|
||||
RecallSlot slot = rest.Trim() == "2" ? RecallSlot.Tie2 : rest.Trim() == "1" ? RecallSlot.Tie1 : (RecallSlot)(-1);
|
||||
if ((int)slot < 0) { Say("/rnav tie 1 (primary) or /rnav tie 2 (secondary)"); return; }
|
||||
_memory.Set(_charKey, slot, _pendingTie);
|
||||
Note($"{(slot == RecallSlot.Tie1 ? "Primary" : "Secondary")} portal tie: {Describe(_pendingTie)}");
|
||||
_pendingTie = null;
|
||||
if (_charKey.Length == 0) { Note("not logged in yet"); return; }
|
||||
string arg = rest.Trim().ToLowerInvariant();
|
||||
bool clear = arg.StartsWith("clear", StringComparison.Ordinal);
|
||||
if (clear) arg = arg.Substring(5).Trim();
|
||||
RecallSlot slot = arg switch
|
||||
{
|
||||
"1" => RecallSlot.Tie1,
|
||||
"2" => RecallSlot.Tie2,
|
||||
"lifestone" or "ls" => RecallSlot.Lifestone,
|
||||
_ => (RecallSlot)(-1),
|
||||
};
|
||||
if ((int)slot < 0) { Say("/rnav tie 1 (primary) | 2 (secondary) | lifestone, or /rnav tie clear 1|2|lifestone"); return; }
|
||||
string name = RecallPlanner.Title(slot);
|
||||
if (clear)
|
||||
{
|
||||
_memory.Clear(_charKey, slot);
|
||||
Note($"{name}: landing forgotten (routes won't use it until it's learned again)");
|
||||
return;
|
||||
}
|
||||
RecallSpot? spot;
|
||||
if (slot == RecallSlot.Lifestone)
|
||||
{
|
||||
// The Atlas lifestone at the selected object (anything else selected doesn't count), else the nearest one.
|
||||
RecallSpot? sel = SelectedObjectSpot(out _);
|
||||
AtlasLocation? ls = sel != null && sel.OnMap ? _atlas.Nearest("Lifestone", sel.Ns, sel.Ew, LifestoneLandUnits) : null;
|
||||
spot = ls != null ? new RecallSpot { OnMap = true, Ns = ls.Ns, Ew = ls.Ew, Label = ls.Name } : NearestAtlasSpot("Lifestone", 40);
|
||||
if (spot == null) { Note("tie lifestone: select your tied lifestone, or stand at it, first"); return; }
|
||||
}
|
||||
else if (_pendingTie != null) { spot = _pendingTie; _pendingTie = null; }
|
||||
else if ((spot = TiedPortalSpot(out string why)) == null) { Note($"tie {arg}: {why}"); return; }
|
||||
_memory.Set(_charKey, slot, spot);
|
||||
Note($"{name}: {Describe(spot)}");
|
||||
}
|
||||
|
||||
/// <summary>Plans a route (portals and, unless off, recalls) and shows it in the panel. Tick thread.</summary>
|
||||
|
|
|
|||
|
|
@ -496,6 +496,15 @@ public sealed partial class RynthNavPlugin : RynthPluginBase
|
|||
// needs no navmesh here.
|
||||
bool recallFirst = _route != null && _route.Count > 0 && (_route[0].UseRecall || _route[0].IsHub);
|
||||
uint hereLb = CurrentLandblock;
|
||||
// A dungeon's landblock has a tile too, but it's the surface's (dungeon cells aren't
|
||||
// baked): walking on it inside the dungeon runs into walls. Say so instead.
|
||||
if (!recallFirst && InDungeon(_cellId))
|
||||
{
|
||||
_route = null;
|
||||
lock (_gate) { _status = $"in a dungeon (0x{hereLb:X4}): no navmesh"; _lastPath = ""; }
|
||||
Note($"goto: no navmesh inside dungeons yet (landblock 0x{hereLb:X4}); walk out through its portal, or turn on recalls so the route can start with one");
|
||||
return;
|
||||
}
|
||||
if (!recallFirst && !File.Exists(Path.Combine(NavDataDir, $"nav_{hereLb:X4}.tile")))
|
||||
{
|
||||
_route = null;
|
||||
|
|
@ -638,6 +647,15 @@ public sealed partial class RynthNavPlugin : RynthPluginBase
|
|||
// ArrivalUnits from the typed point. Standing on that spot is arriving.
|
||||
bool atMeshGoal = !isPortalLeg && _goalOnMesh &&
|
||||
Math.Sqrt((_goalMeshEw - _wx) * (_goalMeshEw - _wx) + (_goalMeshNs - _wy) * (_goalMeshNs - _wy)) < ArrivalUnits;
|
||||
// A portal is run into straight from PortalArriveUnits: only with nothing between, as far as
|
||||
// the navmesh shows. A portal round a corner (a wall within 14 u of it) is reached along
|
||||
// the path first; it used to be run at through the wall, 12 s a try, five tries.
|
||||
if (isPortalLeg && toGoal < arrive && toGoal > PortalContactUnits && !atMeshGoal)
|
||||
{
|
||||
bool pathLeft;
|
||||
lock (_gotoGate) pathLeft = _gotoPath != null && _gotoIdx < _gotoPath.Count;
|
||||
if (pathLeft && !StraightOnMesh(_gotoTew, _gotoTns)) arrive = PortalContactUnits;
|
||||
}
|
||||
if (toGoal < arrive || atMeshGoal)
|
||||
{
|
||||
OnSubGoalReached();
|
||||
|
|
@ -650,7 +668,7 @@ public sealed partial class RynthNavPlugin : RynthPluginBase
|
|||
// Following a route over land, progress is what's left of the route (it can lead away
|
||||
// from the target for a while); otherwise the straight distance.
|
||||
double left = _coarse != null ? _coarse.Remaining(_wx, _wy) : toGoal;
|
||||
if (left < _bestDist - ProgressUnits) { _bestDist = left; _bestTick = _legTicks; }
|
||||
if (left < _bestDist - ProgressUnits) { _bestDist = left; _bestTick = _legTicks; _stuckTries = 0; }
|
||||
else if (_coarse != null && left > _bestDist + RouteLostUnits)
|
||||
{
|
||||
// Following a route but getting ever farther from it: stop rather than wander.
|
||||
|
|
@ -664,6 +682,8 @@ public sealed partial class RynthNavPlugin : RynthPluginBase
|
|||
FinishGoto($"stopped: no progress for 30 s, {toGoal:F0}u short ({why})");
|
||||
return;
|
||||
}
|
||||
// Running into something (RynthNavPlugin.Blocked.cs): turn away, plan again, or stop and say where.
|
||||
if (StepBlocked()) return;
|
||||
|
||||
// Plan at once, re-plan every 20 ticks, and every 5 while there is no plan.
|
||||
bool due = _gotoPath == null ? (_replanTick++ % 5) == 0 : (++_replanTick % 20) == 0;
|
||||
|
|
@ -709,7 +729,7 @@ public sealed partial class RynthNavPlugin : RynthPluginBase
|
|||
// Straight at the goal, or along the route at its next crossing.
|
||||
double bh = (_coarse != null ? Math.Atan2(_aimEw - _wx, _aimNs - _wy) : Math.Atan2(fdew, fdns)) * 180.0 / Math.PI;
|
||||
bh = SteerRoundPortals(bh < 0 ? bh + 360.0 : bh, 10.0);
|
||||
DriveTo(bh);
|
||||
WalkDrive(bh);
|
||||
if (_blindTicks % 10 == 0) lock (_gotoGate) _gotoPath = null; // re-plan soon
|
||||
}
|
||||
else if (_blindTicks++ == BlindPushTicks)
|
||||
|
|
@ -728,7 +748,7 @@ public sealed partial class RynthNavPlugin : RynthPluginBase
|
|||
// hub portals' circles, a wall beside), it held 234 deg into the wall while the path wanted
|
||||
// 301 and re-planned every 0.6 s (10-01 20:07, "just spazzing"). Steering is for the
|
||||
// blind push and the last steps onto a portal, where there is no path.
|
||||
DriveTo(desired);
|
||||
WalkDrive(desired);
|
||||
}
|
||||
|
||||
// ── Portal routing ───────────────────────────────────────────────────────────
|
||||
|
|
@ -776,6 +796,7 @@ public sealed partial class RynthNavPlugin : RynthPluginBase
|
|||
else { _gotoTew = _finalTew; _gotoTns = _finalTns; }
|
||||
// New leg: fresh progress watchdog, and the old leg's walkable end no longer counts.
|
||||
ResetHub();
|
||||
ResetBlocked();
|
||||
_coarseHoldTicks = _graph != null ? CoarseHoldMaxTicks : 0;
|
||||
_nextAvoidMs = 0;
|
||||
_walkHaveLast = false; // a new leg starts where the last step's teleport put us
|
||||
|
|
@ -790,6 +811,7 @@ public sealed partial class RynthNavPlugin : RynthPluginBase
|
|||
_gotoActive = false; _route = null; _portalWait = false;
|
||||
ResetHub();
|
||||
_avoid.Clear(); _coarseHoldTicks = 0;
|
||||
ResetBlocked();
|
||||
Host.SetAutoRun(false); Host.StopCompletely();
|
||||
lock (_gate) _status = status;
|
||||
Host.Log($"[RynthNav] goto: {status}");
|
||||
|
|
@ -942,7 +964,11 @@ public sealed partial class RynthNavPlugin : RynthPluginBase
|
|||
|
||||
var filter = new DtQueryDefaultFilter();
|
||||
var startP = new RcVec3f((float)_wx, (float)_wz, (float)_wy);
|
||||
_query.FindNearestPoly(startP, new RcVec3f(8, 64, 8), filter, out long sRef, out RcVec3f sPt, out _);
|
||||
// The ground we stand on first: the mesh keeps the agent radius (2 m) from walls, so close
|
||||
// up it's within that, at our height. Only then the wide search, which can pick ground on
|
||||
// the far side of a thin wall or a roof overhead, and the walk then runs into that wall.
|
||||
_query.FindNearestPoly(startP, new RcVec3f(2.5f, 4, 2.5f), filter, out long sRef, out RcVec3f sPt, out _);
|
||||
if (sRef == 0) _query.FindNearestPoly(startP, new RcVec3f(8, 64, 8), filter, out sRef, out sPt, out _);
|
||||
// A failed plan drops the old one: StepGoto must not keep following a stale path.
|
||||
if (sRef == 0) { lock (_gate) _status = "off navmesh"; lock (_gotoGate) _gotoPath = null; return; }
|
||||
|
||||
|
|
@ -1025,8 +1051,10 @@ public sealed partial class RynthNavPlugin : RynthPluginBase
|
|||
double ox = -(ux / ul + vx / vl), oy = -(uy / ul + vy / vl), ol = Math.Sqrt(ox * ox + oy * oy);
|
||||
if (ol < 0.05) continue; // straight on: no corner to clear
|
||||
double nx = px + ox / ol * _wallClearance, ny = py + oy / ol * _wallClearance;
|
||||
q2.FindNearestPoly(new RcVec3f((float)nx, (float)_wz, (float)ny), new RcVec3f(0.3f, 24, 0.3f), filter, out long rr, out _, out _);
|
||||
if (rr != 0) wps[i] = (nx, ny);
|
||||
// Only onto walkable ground itself (inside a polygon), not merely near it: near it,
|
||||
// the moved corner could sit closer to the wall than the body is wide.
|
||||
q2.FindNearestPoly(new RcVec3f((float)nx, (float)_wz, (float)ny), new RcVec3f(0.3f, 24, 0.3f), filter, out long rr, out RcVec3f rp, out _);
|
||||
if (rr != 0 && Math.Abs(rp.X - nx) < 0.05 && Math.Abs(rp.Z - ny) < 0.05) wps[i] = (nx, ny);
|
||||
}
|
||||
}
|
||||
lock (_gotoGate) { _gotoPath = wps; _gotoIdx = 0; }
|
||||
|
|
@ -1161,9 +1189,10 @@ public sealed partial class RynthNavPlugin : RynthPluginBase
|
|||
bool exists = File.Exists(Path.Combine(NavDataDir, $"nav_{lb:X4}.tile"));
|
||||
int onDisk = 0;
|
||||
try { if (Directory.Exists(NavDataDir)) onDisk = Directory.GetFiles(NavDataDir, "nav_*.tile").Length; } catch { }
|
||||
bool indoors = (_cellId & 0xFFFF) >= 0x0100;
|
||||
bool indoors = (_cellId & 0xFFFF) >= 0x0100, dungeon = InDungeon(_cellId);
|
||||
string status; lock (_gate) status = _status;
|
||||
return $"landblock 0x{lb:X4}{(indoors ? " (indoors)" : "")} — tile {(exists ? "FOUND" : "MISSING")}, {_tileCount} loaded, "
|
||||
return $"landblock 0x{lb:X4}{(dungeon ? " (a dungeon)" : indoors ? " (indoors)" : "")} — tile "
|
||||
+ $"{(dungeon ? (exists ? "surface only, no dungeon navmesh" : "MISSING") : exists ? "FOUND" : "MISSING")}, {_tileCount} loaded, "
|
||||
+ $"{onDisk} tile(s) in {NavDataDir}; route graph: {_graphStatus}; Town Network: {_townNetStatus}; goto {(_gotoActive ? "ACTIVE" : "off")}"
|
||||
+ $"{(_coarse != null ? $" (route {_coarse.Crossed}/{_coarse.Count})" : "")}, portals {(_portalsEnabled ? "on" : "off")}; status: {status}";
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue