Snapshot for release 2026.10.28.2 (internal 48c46bd)

This commit is contained in:
Tom Bohar 2026-10-28 19:47:19 -04:00
commit 636adfcef2
41 changed files with 3402 additions and 120 deletions

View file

@ -76,6 +76,22 @@ internal sealed class MetaManager
private long _evalChatSeq; // newest chat line its condition matched
private Match? _lastChatMatch;
// ── Macro stop/start replay ──────────────────────────────────────────────
// Starting the macro re-arms every rule of the state it is in (so a meta puts back a
// route the player changed or cleared while it was stopped). The rules that had already
// fired in that state before the stop "replay" when they fire again. A replayed nav load
// (EmbedNav, /vt nav load, /ra nav load) of the route that is still loaded and unchanged
// keeps the route where it was: its waypoint, a Linear route's direction, a finished
// Once route finished; a replayed "/ra nav restart" is skipped. Reloading here restarted
// Once routes on every stop/start (2026-10-28). Cleared by the next real state entry; a
// rule that first fires after the start is not a replay, and its nav load starts the
// route fresh as before.
private readonly HashSet<MetaRule> _replayRules = new(ReferenceEqualityComparer.Instance);
private bool _replaying; // the action running now belongs to a replayed rule
/// <summary>Where a meta's nav names are looked for as .nav files. Tests point it at a scratch folder.</summary>
internal string NavFolder { get; set; } = Path.Combine(RynthCore.Install.RynthInstallPaths.RynthAiDir, "NavProfiles");
// ── Call stack (CallMetaState / ReturnFromCall) ──────────────────────────
private readonly Stack<string> _stateStack = new();
@ -236,6 +252,73 @@ internal sealed class MetaManager
? 0
: FindNearestWaypoint(route);
/// <summary>
/// A replayed nav load (see <see cref="_replayRules"/>): true, and nothing reloaded, when
/// <paramref name="path"/> is the route loaded now and it still has the points of its source
/// <paramref name="source"/> (not edited, reversed or swapped for another since). The route
/// keeps its waypoint and a Linear route its direction (the engine sees the same route
/// object); nav is switched on as the load would, except for a finished Once route, which
/// stays finished. False: the caller loads the route fresh, as before.
/// </summary>
private bool KeepRunningRoute(string path, NavRouteParser source, string what)
{
var cur = _settings.CurrentRoute;
if (cur == null || cur.Points.Count == 0 || source.Points.Count == 0) return false;
if (!SameNavPath(_settings.CurrentNavPath, path)) return false;
if (!SameLines(cur.ToLines(), source.ToLines())) return false;
bool finished = _settings.NavRouteFinished();
if (!finished) _settings.EnableNavigation = true;
RynthLog.Write(LogCat.Meta, finished
? $"[Meta] {what}: the macro started again on the same route, which is finished - it stays finished (/ra nav restart re-runs it)"
: $"[Meta] {what}: the macro started again on the same route - it carries on at [{_settings.ActiveNavIndex}] instead of starting over");
return true;
}
/// <summary>A replayed "/vt nav load" or "/ra nav load" of the .nav file that is still the loaded, unchanged route.</summary>
private bool KeepRunningNavFile(string rawName)
{
string name = NewProfileFiles.Tidy(rawName, NewProfileFiles.NavExtensions, out _);
if (NewProfileFiles.Validate(name) != null) return false;
string path = Path.Combine(NavFolder, name + ".nav");
if (!File.Exists(path)) return false;
return KeepRunningRoute(path, NavRouteParser.Load(path), $"nav load '{name}'");
}
/// <summary>
/// A replayed /ra nav command that would start the route over: "/ra nav load" of the running,
/// unchanged route, or "/ra nav restart". True: skipped, the nav stays where it was.
/// </summary>
private bool SkipReplayedNavCommand(string cmd)
{
string[] parts = cmd.Split(' ', StringSplitOptions.RemoveEmptyEntries);
if (parts.Length < 3 || !parts[1].Equals("nav", StringComparison.OrdinalIgnoreCase)) return false;
if (parts[2].Equals("restart", StringComparison.OrdinalIgnoreCase))
{
RynthLog.Write(LogCat.Meta, "[Meta] /ra nav restart: not run again for the macro start (it ran when the rule first fired)");
return true;
}
return parts[2].Equals("load", StringComparison.OrdinalIgnoreCase) && parts.Length >= 4
&& KeepRunningNavFile(string.Join(" ", parts, 3, parts.Length - 3));
}
private static bool SameNavPath(string? a, string? b)
{
if (string.IsNullOrEmpty(a) || string.IsNullOrEmpty(b)) return false;
if (string.Equals(a, b, StringComparison.OrdinalIgnoreCase)) return true;
if (a.StartsWith('<') || b.StartsWith('<')) return false; // "<embedded:...>" is not a file
try { return string.Equals(Path.GetFullPath(a), Path.GetFullPath(b), StringComparison.OrdinalIgnoreCase); }
catch { return false; }
}
private static bool SameLines(List<string> a, List<string> b)
{
if (a.Count != b.Count) return false;
for (int i = 0; i < a.Count; i++)
if (!string.Equals(a[i], b[i], StringComparison.Ordinal)) return false;
return true;
}
public ExpressionEngine Expressions => _expressions ??= CreateExpressionEngine();
private ExpressionEngine CreateExpressionEngine()
@ -312,7 +395,10 @@ internal sealed class MetaManager
// Macro just started — force reset so rules re-evaluate even if state
// name matches where we stopped. Otherwise HasFired stays latched across
// a stop/start cycle and IF:Always rules like EmbedNav never re-fire.
if (!_lastMacroRunning)
// The rules that had already fired replay (see _replayRules): a replayed nav
// load of the route still running keeps its place instead of starting it over.
bool macroStarted = !_lastMacroRunning;
if (macroStarted)
_settings.ForceStateReset = true;
_lastMacroRunning = true;
@ -343,9 +429,21 @@ internal sealed class MetaManager
_statePStartTime = _statePResume is double resumed ? Clock().AddSeconds(-resumed) : Clock();
_statePResume = null;
_settings.ForceStateReset = false;
// A bare stop/start (no state entry, no meta load pending) replays the rules that
// had fired; any other reset is a real state entry and nothing is a replay.
bool replay = macroStarted && !realStateEntry && !metaReloaded;
lock (_settings.MetaRulesLock)
foreach (var r in _settings.MetaRules) r.HasFired = false;
{
_replayRules.Clear();
foreach (var r in _settings.MetaRules)
{
if (replay && r.HasFired) _replayRules.Add(r);
r.HasFired = false;
}
}
}
else if (stateChanged)
_replayRules.Clear();
_lastState = _settings.CurrentState;
double secondsInState = (Clock() - _stateStartTime).TotalSeconds;
@ -434,7 +532,9 @@ internal sealed class MetaManager
if (_settings.MetaDebug)
_host.WriteToChat($"[Meta] {rule.State} | {DescribeCondition(rule)} → {DescribeAction(rule)}", 1);
ExecuteAction(rule);
_replaying = _replayRules.Contains(rule);
try { ExecuteAction(rule); }
finally { _replaying = false; }
// If state changed during this action, stop evaluating further rules this tick
if (_settings.CurrentState != _lastState || _settings.ForceStateReset)
@ -888,7 +988,10 @@ internal sealed class MetaManager
if (cmd.StartsWith("/ra ", StringComparison.OrdinalIgnoreCase)
|| cmd.Equals("/ra", StringComparison.OrdinalIgnoreCase))
{
_raCommandHandler?.Invoke(cmd);
// A replayed "/ra nav load" of the route still running, or "/ra nav restart",
// would start the route over: skipped.
if (!(_replaying && SkipReplayedNavCommand(cmd)))
_raCommandHandler?.Invoke(cmd);
}
else if (_host.HasInvokeChatParser)
_host.InvokeChatParser(cmd);
@ -977,7 +1080,7 @@ internal sealed class MetaManager
// circular hunt through every cell of this dungeon, no nav file). The Meta panel
// offers it first in Embedded Nav Route's list. A real route called Patrol wins.
if (IsPatrolRoute(routeName) && !_settings.EmbeddedNavs.ContainsKey(routeName)
&& !File.Exists(Path.Combine(RynthCore.Install.RynthInstallPaths.RynthAiDir, "NavProfiles", routeName + ".nav")))
&& !File.Exists(Path.Combine(NavFolder, routeName + ".nav")))
{
_host.Log("[Meta] EmbedNav: Patrol -> /ra dunnav-patrol");
if (_raCommandHandler != null) _raCommandHandler("/ra dunnav-patrol");
@ -1002,6 +1105,8 @@ internal sealed class MetaManager
if (_settings.EmbeddedNavs.TryGetValue(routeName, out var embedded))
{
var newRoute = NavRouteParser.LoadFromLines(embedded);
// The macro was started again: the route still running keeps its place.
if (_replaying && KeepRunningRoute($"<embedded:{routeName}>", newRoute, $"EmbedNav '{routeName}'")) break;
_settings.CurrentNavPath = $"<embedded:{routeName}>";
_settings.CurrentRoute = newRoute;
_settings.ActiveNavIndex = StartIndexForRoute(newRoute);
@ -1012,11 +1117,11 @@ internal sealed class MetaManager
}
// Fallback: a standalone .nav file in NavProfiles.
string navFolder = System.IO.Path.Combine(RynthCore.Install.RynthInstallPaths.RynthAiDir, "NavProfiles");
string fullPath = Path.Combine(navFolder, routeName + ".nav");
string fullPath = Path.Combine(NavFolder, routeName + ".nav");
if (File.Exists(fullPath))
{
var newRoute = NavRouteParser.Load(fullPath);
if (_replaying && KeepRunningRoute(fullPath, newRoute, $"EmbedNav file '{routeName}'")) break;
_settings.CurrentNavPath = fullPath;
_settings.CurrentRoute = newRoute;
_settings.ActiveNavIndex = StartIndexForRoute(newRoute);
@ -1257,6 +1362,9 @@ internal sealed class MetaManager
|| parts[2].Equals("save", StringComparison.OrdinalIgnoreCase)))
{
string name = string.Join(" ", parts, 3, parts.Length - 3);
// The macro was started again: the route still running keeps its place.
if (_replaying && parts[2].Equals("load", StringComparison.OrdinalIgnoreCase) && KeepRunningNavFile(name))
return true;
_raCommandHandler?.Invoke($"/ra nav {parts[2].ToLowerInvariant()} {name}");
return true;
}