RynthSuite as of 2026-12-02 (internal 152e13d): release 2026.12.1.1

This commit is contained in:
Tom Bohar 2026-12-02 06:45:07 -05:00
commit 6b5a9c7e99
65 changed files with 3920 additions and 237 deletions

View file

@ -888,13 +888,21 @@ internal static class AfFileParser
/// Drops empty nav routes (header only, 0 points) from the dict and
/// blanks EmbedNav action data on rules whose referenced nav was empty.
/// Non-empty embedded navs survive in the dict for runtime + save.
/// A rule naming a route the file has NO block for keeps its name (2026-11-30): it is a
/// NavProfiles route (MetaNavEmbedding copies it in on load). It used to be blanked whenever
/// the meta had any block at all, so that rule loaded no route.
/// </summary>
private static void PruneEmbeddedNavs(List<MetaRule> rules,
Dictionary<string, List<string>> navRoutes)
{
if (navRoutes.Count == 0) return;
var toRemove = new List<string>();
// AfFileWriter writes an Embedded Nav Route with no route as "EmbedNav empty": no route,
// unless the meta carries one of that name (the blanking below used to catch it).
if (!navRoutes.ContainsKey(AfFileWriter.EmptyNavName))
ClearPlaceholderRefs(rules);
var toRemove = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
foreach (var kvp in navRoutes)
{
var content = kvp.Value;
@ -904,23 +912,34 @@ internal static class AfFileParser
foreach (string key in toRemove)
navRoutes.Remove(key);
ClearMissingEmbedRefs(rules, navRoutes);
if (toRemove.Count > 0) ClearEmptyEmbedRefs(rules, toRemove);
}
private static void ClearMissingEmbedRefs(List<MetaRule> rules,
Dictionary<string, List<string>> navRoutes)
private static void ClearPlaceholderRefs(List<MetaRule> rules)
{
foreach (var rule in rules)
{
if (rule.Action == MetaActionType.EmbeddedNavRoute &&
string.Equals(rule.ActionData, AfFileWriter.EmptyNavName, StringComparison.Ordinal))
rule.ActionData = "";
if (rule.ActionChildren != null)
ClearPlaceholderRefs(rule.ActionChildren);
}
}
private static void ClearEmptyEmbedRefs(List<MetaRule> rules, HashSet<string> emptyRoutes)
{
foreach (var rule in rules)
{
if (rule.Action == MetaActionType.EmbeddedNavRoute &&
!string.IsNullOrEmpty(rule.ActionData) &&
!navRoutes.ContainsKey(rule.ActionData))
emptyRoutes.Contains(rule.ActionData))
{
rule.ActionData = "";
}
if (rule.ActionChildren != null)
ClearMissingEmbedRefs(rule.ActionChildren, navRoutes);
ClearEmptyEmbedRefs(rule.ActionChildren, emptyRoutes);
}
}

View file

@ -43,7 +43,7 @@ internal static class AfFileWriter
.OrderBy(g => g.Key)
.ToList();
// Collect embedded nav routes referenced by rules
// Collect embedded nav routes referenced by rules (cleaned, as the parser and MetaManager read them)
var navNames = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
CollectNavNames(rules, navNames);
@ -69,6 +69,18 @@ internal static class AfFileWriter
{
if (embeddedNavs.TryGetValue(navName, out var content))
WriteNavSection(writer, navName, content);
else
{
// A key kept in another spelling ("None]" from an old settings file): the route still goes in.
foreach (var kv in embeddedNavs)
{
if (string.Equals(EmbedNavName.Clean(kv.Key), navName, StringComparison.OrdinalIgnoreCase))
{
WriteNavSection(writer, navName, kv.Value);
break;
}
}
}
}
}
@ -94,6 +106,9 @@ internal static class AfFileWriter
// ── Rule writing ────────────────────────────────────────────────────────
/// <summary>The name written for an Embedded Nav Route with no route (metaf needs a tag); read back as none.</summary>
internal const string EmptyNavName = "empty";
/// <summary>A rule name on one line (it is written as a "~~ @name" comment line).</summary>
internal static string OneLine(string? text)
{
@ -275,7 +290,7 @@ internal static class AfFileWriter
case MetaActionType.EmbeddedNavRoute:
{
string navName = string.IsNullOrEmpty(data) ? "empty" : data.Split(';')[0];
string navName = string.IsNullOrEmpty(data) ? EmptyNavName : data.Split(';')[0];
writer.Write($"{keyword} {navName} {{[none]}}");
break;
}
@ -354,7 +369,8 @@ internal static class AfFileWriter
if (rule.Action == MetaActionType.EmbeddedNavRoute &&
!string.IsNullOrEmpty(rule.ActionData))
{
navNames.Add(rule.ActionData.Split(';')[0]);
string name = EmbedNavName.Clean(rule.ActionData.Split(';')[0]);
if (name.Length > 0) navNames.Add(name);
}
if (rule.ActionChildren != null)

View file

@ -387,6 +387,7 @@ internal sealed partial class ExpressionEngine
// ── List functions ────────────────────────────────────────────────
"listcreate" => EvalListCreate(rawArgs),
"createlist" => EvalListCreate(rawArgs), // UtilityBelt's own name (R-20261201-211257-d2be)
// These change the list (the reference: "Returns the list object"). A list is text
// here, so the changed list is written back to the variable it came from.
"listadd" => ListOp(rawArgs, A(0), l => EvalListAdd(l, A(1))),
@ -3728,6 +3729,12 @@ internal sealed partial class ExpressionEngine
["StopMacroWhenPackFull"] = (() => B(s.StopMacroWhenPackFull), v => s.StopMacroWhenPackFull = ToDouble(v) != 0),
["SummonPets"] = (() => B(s.SummonPets), v => s.SummonPets = ToDouble(v) != 0),
["MineOnly"] = (() => B(s.MineOnly), v => s.MineOnly = ToDouble(v) != 0),
// 2026-12-01 command audit: settings VTank options map onto (MetaManager.VtOptionMap).
["LootOnlyRareCorpses"] = (() => B(s.LootOnlyRareCorpses), v => s.LootOnlyRareCorpses = ToDouble(v) != 0),
["BlacklistAttempts"] = (() => I(s.BlacklistAttempts), v => { if (double.TryParse(v, NumberStyles.Float, CultureInfo.InvariantCulture, out double d) && double.IsFinite(d)) s.BlacklistAttempts = Math.Clamp((int)Math.Round(d), 1, 20); }),
["ManaTapMinMana"] = (() => I(s.ManaTapMinMana), v => { if (double.TryParse(v, NumberStyles.Float, CultureInfo.InvariantCulture, out double d) && double.IsFinite(d)) s.ManaTapMinMana = Math.Clamp((int)Math.Round(d), 0, 1_000_000); }),
["RestamOthersAt"] = (() => I(s.RestamOthersAt), v => { if (int.TryParse(v, out int i)) s.RestamOthersAt = Math.Clamp(i, 0, 100); }),
["InfuseOthersAt"] = (() => I(s.InfuseOthersAt), v => { if (int.TryParse(v, out int i)) s.InfuseOthersAt = Math.Clamp(i, 0, 100); }),
["UseDispelItems"] = (() => B(s.UseDispelItems), v => s.UseDispelItems = ToDouble(v) != 0),
["CastDispelSelf"] = (() => B(s.CastDispelSelf), v => s.CastDispelSelf = ToDouble(v) != 0),
["AutoFellowMgmt"] = (() => B(s.AutoFellowMgmt), v => s.AutoFellowMgmt = ToDouble(v) != 0),
@ -3796,6 +3803,7 @@ internal sealed partial class ExpressionEngine
["CastBuffsOverItemBuffs"] = (() => B(s.CastBuffsOverItemBuffs), v => s.CastBuffsOverItemBuffs = ToDouble(v) != 0),
["FastBuffChain"] = (() => B(s.FastBuffChain), v => s.FastBuffChain = ToDouble(v) != 0),
["SkipUnusableBuffs"] = (() => B(s.SkipUnusableBuffs), v => s.SkipUnusableBuffs = ToDouble(v) != 0),
["RecastDispelledInFight"] = (() => B(s.RecastDispelledInFight), v => s.RecastDispelledInFight = ToDouble(v) != 0),
["UseFellowshipBuffs"] = (() => B(s.UseFellowshipBuffs), v => s.UseFellowshipBuffs = ToDouble(v) != 0),
["BuffShield"] = (() => B(s.BuffShield), v => s.BuffShield = ToDouble(v) != 0),
// AutoVendor (UB names map here through /ub opt: AutoVendor.Enabled -> AutoVendorEnabled, ...)

View file

@ -53,6 +53,7 @@ internal sealed partial class MetaManager
s.RouteLines = _settings.CurrentRoute != null && _settings.CurrentRoute.Points.Count > 0
? new List<string>(_settings.CurrentRoute.ToLines())
: new List<string>();
s.RouteMadeBy = _settings.CurrentRoute?.MadeBy ?? "";
s.NavIndex = _settings.ActiveNavIndex;
s.NavEnabled = _settings.EnableNavigation;
}
@ -107,6 +108,7 @@ internal sealed partial class MetaManager
_settings.CurrentNavPath = s.NavPath;
_settings.CurrentRoute = s.RouteLines.Count > 0 ? NavRouteParser.LoadFromLines(s.RouteLines) : new NavRouteParser();
_settings.CurrentRoute.MadeBy = s.RouteMadeBy ?? "";
_settings.ActiveNavIndex = Math.Clamp(s.NavIndex, 0, Math.Max(0, _settings.CurrentRoute.Points.Count));
_settings.EnableNavigation = s.NavEnabled;
}

View file

@ -1405,6 +1405,32 @@ internal sealed partial class MetaManager
return true;
}
// /vt meta save <name> — the loaded meta saved under that name, which is then its file (2026-12-01
// command audit: it answered with the usage). /ra meta saveas: the same file again saves it, another
// existing one is refused (a command never replaces a file).
if (sub == "meta" && parts.Length >= 4 &&
parts[2].Equals("save", StringComparison.OrdinalIgnoreCase))
{
_raCommandHandler?.Invoke("/ra meta saveas " + string.Join(" ", parts, 3, parts.Length - 3));
return true;
}
// /vt loot save <name> — a copy of the loot profile in use under that name, then looted with (as
// VTank's save does; 2026-12-01 command audit). The profile in use itself is already saved.
if ((sub == "loot" || sub == "lootprofile" || sub == "looting") && parts.Length >= 4 &&
parts[2].Equals("save", StringComparison.OrdinalIgnoreCase))
{
string name = string.Join(" ", parts, 3, parts.Length - 3).Trim().Trim('"');
string current = _settings.CurrentLootPath ?? string.Empty;
if (current.Length > 0 && IsLootProfileNamed(current, name))
{
Reply.Ok($"[RynthAi] {Path.GetFileName(current)} is the loot profile in use; it is saved (the Loot Editor saves its changes).");
return true;
}
_raCommandHandler?.Invoke("/ra loot saveas " + name);
return true;
}
// /vt nav load <name> — load a nav route
// It used to store only the bare name as the nav path, so nothing loaded.
// /vt nav save <name> saves the current route under that name.
@ -1461,15 +1487,20 @@ internal sealed partial class MetaManager
return true;
}
// /vt settings loadchar|savechar <name> — RynthAi's settings profiles (/ra settings ...);
// universalremote.met switches profiles this way. Any other /vt settings verb is ignored.
// /vt settings loadchar|savechar|load|save <name> — RynthAi's settings profiles (/ra settings ...);
// universalremote.met switches profiles this way. VTank's load|save are its shared profiles and
// loadchar|savechar this character's; RynthAi's profiles are all the character's, so both pairs are
// the same here (load|save answered with the usage until the 2026-12-01 command audit).
if (sub == "settings")
{
if (parts.Length >= 4 && (parts[2].Equals("loadchar", StringComparison.OrdinalIgnoreCase)
|| parts[2].Equals("savechar", StringComparison.OrdinalIgnoreCase)))
_raCommandHandler?.Invoke($"/ra settings {parts[2].ToLowerInvariant()} {string.Join(" ", parts, 3, parts.Length - 3)}");
string verb = parts.Length >= 4 ? parts[2].ToLowerInvariant() : "";
if (verb is "loadchar" or "load") verb = "loadchar";
else if (verb is "savechar" or "save") verb = "savechar";
else verb = "";
if (verb.Length > 0)
_raCommandHandler?.Invoke($"/ra settings {verb} {string.Join(" ", parts, 3, parts.Length - 3)}");
else
Reply.Ignored("[RynthAi] Usage: /vt settings loadchar|savechar <name> (other /vt settings verbs are VTank's own; ignored).");
Reply.Ignored("[RynthAi] Usage: /vt settings load|save|loadchar|savechar <name> (other /vt settings verbs are VTank's own; ignored).");
return true;
}
@ -1515,19 +1546,58 @@ internal sealed partial class MetaManager
return true;
}
// /vt reverseroute — reverse the active nav route in place (shared settings;
// the engine re-reads CurrentRoute each tick, so the flip takes effect next tick).
// /vt reverseroute [true|false] — the route's direction (shared settings; the engine re-reads
// CurrentRoute each tick). VTank sets it from the argument: true = reversed, false = the file's own
// order, none = the other way. It flipped on every call before (2026-12-01 command audit: a meta
// sending "reverseroute true" on each state entry ran the route the wrong way every other time).
// A route newly loaded is the file's way round. /vt reverseroutequery says which way it is.
if (sub == "reverseroute")
{
var route = _settings.CurrentRoute;
if (route?.Points != null && route.Points.Count > 0)
if (route?.Points == null || route.Points.Count == 0)
{
Reply.Fail("[RynthAi] /vt reverseroute: no route is loaded.");
return true;
}
bool reversedNow = RouteReversed;
bool? asked = parts.Length >= 3 ? ParseVtBool(parts[2]) : null;
if (parts.Length >= 3 && asked == null)
{
Reply.Fail("[RynthAi] Usage: /vt reverseroute [true|false]");
return true;
}
bool want = asked ?? !reversedNow;
int n = route.Points.Count;
if (want != reversedNow)
{
int n = route.Points.Count;
route.Points.Reverse();
_settings.ActiveNavIndex = Math.Clamp(n - 1 - _settings.ActiveNavIndex, 0, n - 1);
Reply.Ok($"[RynthAi] Route reversed ({n} pts).");
}
else Reply.Fail("[RynthAi] /vt reverseroute: no route is loaded.");
_reversedRoute = route;
_routeReversed = want;
Reply.Ok(want == reversedNow
? $"[RynthAi] Route already {(want ? "reversed" : "in its own order")} ({n} pts)."
: $"[RynthAi] Route {(want ? "reversed" : "back in its own order")} ({n} pts).");
return true;
}
// /vt addnavjump <heading> <shift true|false> <milliseconds> [...]: a jump step at the end of the route
// (VTank's form), as /ra nav addjump does with a given heading (2026-12-01 command audit).
if (sub == "addnavjump")
{
if (parts.Length < 5
|| !float.TryParse(parts[2], System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture, out float jh)
|| ParseVtBool(parts[3]) is not bool jshift
|| !int.TryParse(parts[4], System.Globalization.NumberStyles.Integer, System.Globalization.CultureInfo.InvariantCulture, out int jms))
{
Reply.Fail("[RynthAi] Usage: /vt addnavjump <heading> <shift true|false> <milliseconds>");
return true;
}
_raCommandHandler?.Invoke(FormattableString.Invariant($"/ra nav addjump {Math.Clamp(jms, 0, 1000)}{(jshift ? " shift" : "")} heading {jh}"));
return true;
}
if (sub == "reverseroutequery")
{
Reply.Ok($"[RynthAi] Route reversed: {(RouteReversed ? "true" : "false")}.");
return true;
}
@ -1566,8 +1636,8 @@ internal sealed partial class MetaManager
/// <summary>The /vt verbs RynthAi takes, for the usage line.</summary>
internal const string VtVerbList = "opt set|get|list, <option> <value>, start, stop, e, jump, tapjump, equipitemsfor, "
+ "meta load, nav load|save, loot load, setmetastate, settings loadchar|savechar, setattackbar, forcebuff, "
+ "cancelforcebuff, cancelbuff, addnavpt, mexec, clearbusy, testitem, propertydump, reverseroute, echo";
+ "meta load|save, nav load|save, loot load|save, setmetastate, settings load|save|loadchar|savechar, setattackbar, forcebuff, "
+ "cancelforcebuff, cancelbuff, addnavpt, addnavjump, mexec, clearbusy, testitem, propertydump, reverseroute [true|false], reverseroutequery, echo";
/// <summary>The usage line for a /vt line RynthAi didn't take (an unknown verb or the wrong arguments).</summary>
internal static string VtUsageFor(string line)
@ -1577,9 +1647,9 @@ internal sealed partial class MetaManager
string? usage = verb switch
{
"opt" => "/vt opt set <option> <value> | /vt opt get <option> | /vt opt list",
"meta" => "/vt meta load <name>",
"meta" => "/vt meta load|save <name>",
"nav" => "/vt nav load <name> | /vt nav save <name>",
"loot" or "lootprofile" or "looting" => "/vt loot load <profile>",
"loot" or "lootprofile" or "looting" => "/vt loot load|save <profile>",
"setmetastate" => "/vt setmetastate <state>",
"equipitemsfor" => "/vt equipitemsfor <monster name>",
"setattackbar" => "/vt setattackbar <0 to 1>",
@ -1591,6 +1661,19 @@ internal sealed partial class MetaManager
: $"[RynthAi] Unknown /vt command{(verb.Length > 0 ? $" '{verb}'" : "")}. RynthAi takes: {VtVerbList}.";
}
/// <summary>
/// <paramref name="path"/> is the loot profile <paramref name="name"/> names: its file name, or its file
/// name without the extension (any case).
/// </summary>
internal static bool IsLootProfileNamed(string path, string name)
{
string n = name.Trim().Trim('"');
if (n.Length == 0) return false;
string file = Path.GetFileName(path);
return file.Equals(Path.GetFileName(n), StringComparison.OrdinalIgnoreCase)
|| Path.GetFileNameWithoutExtension(file).Equals(Path.GetFileName(n), StringComparison.OrdinalIgnoreCase);
}
/// <summary>The RynthAi setting a VTank option name maps to (EnableNav → EnableNavigation).</summary>
internal static bool TryMapVtOption(string vtName, out string raName)
{
@ -1633,8 +1716,13 @@ internal sealed partial class MetaManager
["lootnearbychests"] = "LootNearbyChests", // Settings > Looting > Loot Nearby Chests
["dooropenrange"] = "OpenDoorRange",
["autofellowmanagement"] = "AutoFellowMgmt",
["switchwandstodebuff"] = "UseDispelItems",
["lootonlyrarecorpses"] = "MineOnly",
// "SwitchWandToDebuff" (VTank: switch to the monster's wand even just to debuff it) was mapped here, as
// "switchwandstodebuff", to UseDispelItems: a meta setting it turned dispel items on (2026-12-01 command
// audit). RynthAi has no such switch; the option is kept for metas to read back, nothing else.
// VTank's Loot Only Rare Corpses is RynthAi's setting of that name (2026-11-22). It was mapped to
// MineOnly, a setting nothing reads, so a meta asking for rare corpses only looted every corpse
// (2026-12-01 command audit).
["lootonlyrarecorpses"] = "LootOnlyRareCorpses",
// Phase 1.2 VTank-meta migration aliases (targets verified in BuildSettingsMap)
["autocram"] = "EnableAutocram",
["autostack"] = "EnableAutostack",
@ -1674,6 +1762,15 @@ internal sealed partial class MetaManager
["rebufftimeremainingseconds"] = "RebuffSecondsRemaining", // VTank's spelling (the one above is a typo)
["petcustomrange"] = "CustomPetRange", // landblock units -> whole yards
["blacklistmonstertimeoutseconds"] = "BlacklistTimeoutSec",
// 2026-12-01 command audit: VTank options that were only stored though RynthAi has the same setting.
["corpeapproachrange-min"] = "CorpseApproachRangeMin", // VTank's own spelling in its option list
["blacklistmonsterattemptcount"] = "BlacklistAttempts", // misses (no damage) before a monster is blacklisted
["manachargeswhenoff"] = "ManaTapMacroOff", // stones keep worn gear filled with the macro off too
["manatankminimummana"] = "ManaTapMinMana", // an item must hold this much mana to be drained into a stone
// Fellow vitals (Recharge-Helper-*): RynthAi keeps these percents but doesn't heal others yet.
["recharge-helper-hitp"] = "HealOthersAt",
["recharge-helper-stam"] = "RestamOthersAt",
["recharge-helper-mana"] = "InfuseOthersAt",
};
/// <summary>VTank options given in landblock units (x240 = yards) whose RynthAi setting is yards.
@ -1682,6 +1779,7 @@ internal sealed partial class MetaManager
{
"attackdistance", "attackrange", "approachdistance", "dooropenrange", "opendoorrange", "ringdistance",
"corpseapproachrange", "corpseapproachrange-max", "corpseapproachrange-min", "petcustomrange",
"corpeapproachrange-min",
};
/// <summary>RynthAi distance settings kept in whole yards (their setter refuses a decimal).</summary>
@ -1715,12 +1813,28 @@ internal sealed partial class MetaManager
/// <summary>VTank options handled by <see cref="TrySetSpecialVtOption"/> (no 1:1 RynthAi setting).</summary>
private static bool IsSpecialVtOption(string vtName) => vtName.ToLowerInvariant() is
"defaultmeleeattackheight" or "lootfellowcorpses" or "lootallcorpses" or "usearcs" or "minimumhealkitsuccesschance"
or "autoattackpower";
or "autoattackpower" or "targetselectmethod" or "debuffeachfirst";
// The last /vt setattackbar power (percent), for AutoAttackPower false after it was on (-1 = none yet).
private int _lastAttackBarPct = -1;
private bool _deleteMonsterLogged;
// /vt reverseroute: the route the direction was set for, and whether it runs reversed. Another
// route loaded (a new object) is in its own order.
private NavRouteParser? _reversedRoute;
private bool _routeReversed;
/// <summary>The loaded route runs reversed (set by /vt reverseroute; a new route starts in its own order).</summary>
internal bool RouteReversed => _routeReversed && ReferenceEquals(_reversedRoute, _settings.CurrentRoute);
/// <summary>true/false, on/off, 1/0, yes/no (any case); null for anything else.</summary>
private static bool? ParseVtBool(string s) => s.Trim().ToLowerInvariant() switch
{
"true" or "on" or "1" or "yes" => true,
"false" or "off" or "0" or "no" => false,
_ => null,
};
/// <summary>
/// The VTank options whose value means something else in RynthAi:
/// DefaultMeleeAttackHeight 1-3 (low/medium/high) is RynthAi's 0-2; LootFellowCorpses /
@ -1756,6 +1870,22 @@ internal sealed partial class MetaManager
if (!num) return true;
_settings.KitMinSuccessPct = Math.Clamp((int)Math.Round(n > 0 && n <= 1 ? n * 100 : n), 0, 100);
return true;
case "targetselectmethod":
// VTank 1 By Range, 2 By Angle, 3 Both (near by angle, far by range). RynthAi's Targeting has
// Closest (1) and Least turning (3); it has no "both", so 3 is only kept (2026-12-01 command audit).
if (!num) return true;
Expressions.SetOption("TargetSelectMethod", value);
if ((int)Math.Round(n) == 1) _settings.TargetSelection = 1;
else if ((int)Math.Round(n) == 2) _settings.TargetSelection = 3;
return true;
case "debuffeachfirst":
// VTank 1 One (debuff one, attack it), 2 Priority (debuff the same priority first), 3 All. RynthAi's
// Debuff every monster in range before attacking is All on, One off; Priority is only kept.
if (!num) return true;
Expressions.SetOption("DebuffEachFirst", value);
if ((int)Math.Round(n) == 1) _settings.DebuffAllBeforeAttacking = false;
else if ((int)Math.Round(n) == 3) _settings.DebuffAllBeforeAttacking = true;
return true;
case "autoattackpower":
// On: RynthAi picks the power itself (-1, its "auto"). Off: the attack bar's value,
// the last /vt setattackbar (a power already set by hand stays as it is).
@ -1786,9 +1916,19 @@ internal sealed partial class MetaManager
"usearcs" => _settings.UseArcs ? "true" : "false",
"minimumhealkitsuccesschance" => _settings.KitMinSuccessPct.ToString(System.Globalization.CultureInfo.InvariantCulture),
"autoattackpower" => _settings.MeleeAttackPower < 0 ? "true" : "false",
// RynthAi's Targeting as VTank's number; another RynthAi choice reads the value a meta last set.
"targetselectmethod" => _settings.TargetSelection switch { 1 => "1", 3 => "2", _ => StoredVtOption("TargetSelectMethod") },
"debuffeachfirst" => _settings.DebuffAllBeforeAttacking ? "3" : StoredVtOption("DebuffEachFirst") == "2" ? "2" : "1",
_ => null,
};
/// <summary>A VTank option a meta set that is only kept, or null when none was.</summary>
private string? StoredVtOption(string name)
{
string v = Expressions.GetOption(name);
return v.Length == 0 || v == "0" ? null : v;
}
/// <summary>A VTank option's current value (mapped setting, else a stored generic option).</summary>
private string? GetVtOption(string vtName)
{

View file

@ -0,0 +1,250 @@
using System;
using System.Collections.Generic;
using System.IO;
using RynthCore.Plugin.RynthAi.LegacyUi;
namespace RynthCore.Plugin.RynthAi.Meta;
/// <summary>
/// An Embedded Nav Route carries its route inside the meta (2026-11-30: the route is embedded,
/// so the meta still works with the .nav file deleted from the drive).
///
/// It didn't: the Meta panel's route picker stores the name of a NavProfiles file, and the meta was
/// saved with only the routes it already held in memory (those that came in a .met or a NAVDATA
/// block), so a route picked from NavProfiles stayed a file the meta read at run time. Now:
/// - picking a route (a new rule, or a rule whose route changed) copies that file in, replacing an
/// older copy of the same name (<see cref="EmbedPicked"/>);
/// - every meta save copies in any route a rule names that the meta doesn't carry yet
/// (<see cref="EmbedMissing"/>), so an older meta becomes self-contained on its next save or load.
/// Once a route is in the meta, the meta's copy is the one that runs; the file can go.
/// "[None]", "Patrol" and "Camp" with no file behind them are not routes (MetaManager), and a file
/// with no points is not copied (the parser drops an empty route and clears the rules naming it).
/// </summary>
internal static class MetaNavEmbedding
{
/// <summary>The route names the Embedded Nav Route actions of <paramref name="rules"/> (and their DoAll steps) use.</summary>
public static HashSet<string> RouteNames(IEnumerable<MetaRule> rules)
{
var names = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
foreach (MetaRule r in rules) Collect(r, names);
return names;
}
/// <summary>The route names one rule's Embedded Nav Route actions use.</summary>
public static HashSet<string> RouteNames(MetaRule? rule)
{
var names = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
if (rule != null) Collect(rule, names);
return names;
}
/// <summary>
/// Copies into <paramref name="embedded"/> every route <paramref name="rules"/> name that it has no
/// route for yet, from <paramref name="navFolder"/>. Returns the names copied (empty: nothing to do).
/// </summary>
public static List<string> EmbedMissing(IEnumerable<MetaRule> rules, IDictionary<string, List<string>> embedded,
string navFolder, Action<string>? log = null)
{
var done = new List<string>();
foreach (string name in RouteNames(rules))
{
if (FindKey(embedded, name) != null) continue;
if (TryRead(navFolder, name, out List<string> lines))
{
embedded[name] = lines;
done.Add(name);
log?.Invoke($"[RynthAi] Meta: embedded route '{name}' from {Path.Combine(navFolder, name + ".nav")} ({PointCount(lines)} pts)");
}
}
return done;
}
/// <summary>
/// A rule edit picked a route: each route <paramref name="after"/> names that <paramref name="before"/>
/// didn't (a new rule: all of them) is copied in from its NavProfiles file, replacing the meta's older
/// copy of that name. A route with no file keeps the meta's copy. Returns the names copied.
/// </summary>
public static List<string> EmbedPicked(MetaRule after, MetaRule? before, IDictionary<string, List<string>> embedded,
string navFolder, Action<string>? log = null, ISet<string>? fromMemory = null)
{
var done = new List<string>();
HashSet<string> had = RouteNames(before);
foreach (string name in RouteNames(after))
{
if (had.Contains(name)) continue;
if (fromMemory != null && fromMemory.Contains(name)) continue; // "Embed loaded" just copied it
if (!TryRead(navFolder, name, out List<string> lines)) continue;
string? old = FindKey(embedded, name);
if (old != null) embedded.Remove(old);
embedded[name] = lines;
done.Add(name);
log?.Invoke($"[RynthAi] Meta: embedded route '{name}' from {Path.Combine(navFolder, name + ".nav")} ({PointCount(lines)} pts){(old != null ? ", replacing the meta's older copy" : "")}");
}
return done;
}
// ── "Embed loaded" (the Meta panel's button, VTank's way) ───────────────────────────────────
// 2026-11-30: with a nav route loaded, a click on the Meta panel's button embeds that route. The snapshot tells the panel the loaded route's name (or why it
// can't be embedded: DescribeLoaded); the button sets the action to that name with LoadedMarker
// after it; the rule's save carries the marker here once (TakeLoadedMarkers), the route in memory
// is copied in under that name (EmbedLoaded), and the rule keeps the plain name.
/// <summary>After an Embedded Nav Route's name in a rule the panel sends: "copy the loaded route in under this name".</summary>
public const string LoadedMarker = ";loaded";
/// <summary>
/// The loaded route as "Embed loaded" would take it: its name (the meta's own name for a route from
/// the meta, the file's name relative to <paramref name="navFolder"/> for a .nav, a new "Route N"
/// for one made in the nav editor or recorded), its point count, and a note that is empty when it
/// can be embedded, else why not (no route; a route a feature built, <see cref="NavRouteParser.MadeBy"/>).
/// </summary>
public static (string Name, int Points, string Note) DescribeLoaded(NavRouteParser? route, string? navPath,
string navFolder, IDictionary<string, List<string>> embedded)
{
int points = route?.Points.Count ?? 0;
bool follow = route != null && route.RouteType == NavRouteType.Follow && route.FollowTargetName.Length > 0;
if (route == null || (points == 0 && !follow))
return (string.Empty, 0, "No nav route is loaded. Load or record one, then embed it.");
if (route.MadeBy.Length > 0)
return (string.Empty, points, $"The loaded route was made by {route.MadeBy}, not loaded or recorded, so it isn't embedded. Load or record a route.");
string path = navPath ?? string.Empty;
if (path.StartsWith("<embedded:", StringComparison.OrdinalIgnoreCase) && path.EndsWith(">", StringComparison.Ordinal))
{
string key = EmbedNavName.Clean(path.Substring(10, path.Length - 11));
if (key.Length > 0 && !EmbedNavName.IsNone(key)) return (key, points, string.Empty);
return (UniqueName(navFolder, embedded), points, string.Empty);
}
if (path.StartsWith("<", StringComparison.Ordinal))
return (string.Empty, points, $"The loaded route isn't a nav route ({path}), so it isn't embedded.");
if (path.Length > 0)
{
string name = FileRouteName(path, navFolder);
if (name.Length > 0 && !EmbedNavName.IsNone(name)) return (name, points, string.Empty);
}
return (UniqueName(navFolder, embedded), points, string.Empty);
}
/// <summary>
/// Strips <see cref="LoadedMarker"/> from <paramref name="rule"/>'s Embedded Nav Route actions (and its
/// DoAll steps) and returns the names that carried it.
/// </summary>
public static List<string> TakeLoadedMarkers(MetaRule rule)
{
var names = new List<string>();
Take(rule, names);
return names;
static void Take(MetaRule r, List<string> into)
{
if (r.Action == MetaActionType.EmbeddedNavRoute && r.ActionData != null
&& r.ActionData.EndsWith(LoadedMarker, StringComparison.OrdinalIgnoreCase))
{
string name = EmbedNavName.Clean(r.ActionData.Substring(0, r.ActionData.Length - LoadedMarker.Length));
r.ActionData = name;
if (name.Length > 0) into.Add(name);
}
if (r.ActionChildren != null)
foreach (MetaRule c in r.ActionChildren) Take(c, into);
}
}
/// <summary>
/// Copies the loaded <paramref name="route"/> into <paramref name="embedded"/> as <paramref name="name"/>,
/// replacing the meta's copy of that name. Null when it was copied, else why not (DescribeLoaded's note).
/// </summary>
public static string? EmbedLoaded(string name, NavRouteParser? route, string? navPath, string navFolder,
IDictionary<string, List<string>> embedded, Action<string>? log = null)
{
var (_, points, note) = DescribeLoaded(route, navPath, navFolder, embedded);
if (note.Length > 0) return note;
if (string.IsNullOrWhiteSpace(name) || EmbedNavName.IsNone(name)) return "the route has no name to keep it under";
List<string> lines = route!.ToLines();
if (lines.Count < 3) return "the loaded route didn't write out";
string? old = FindKey(embedded, name);
if (old != null) embedded.Remove(old);
embedded[name] = lines;
log?.Invoke($"[RynthAi] Meta: embedded the loaded route as '{name}' ({points} pts{(string.IsNullOrEmpty(navPath) ? ", never saved to a file" : ", from " + navPath)}){(old != null ? ", replacing the meta's older copy" : "")}");
return null;
}
/// <summary>A .nav file's route name: relative to NavProfiles without ".nav" (as the nav list shows it), else the file name.</summary>
internal static string FileRouteName(string path, string navFolder)
{
try
{
string full = Path.GetFullPath(path);
string root = Path.GetFullPath(navFolder).TrimEnd('\\', '/') + Path.DirectorySeparatorChar;
string rel = full.StartsWith(root, StringComparison.OrdinalIgnoreCase) ? full.Substring(root.Length) : Path.GetFileName(full);
if (rel.EndsWith(".nav", StringComparison.OrdinalIgnoreCase)) rel = rel.Substring(0, rel.Length - 4);
return EmbedNavName.Clean(rel);
}
catch { return string.Empty; }
}
/// <summary>"Route N", the first N with no route of that name in the meta or NavProfiles.</summary>
internal static string UniqueName(string navFolder, IDictionary<string, List<string>> embedded)
{
for (int n = 1; ; n++)
{
string name = "Route " + n.ToString(System.Globalization.CultureInfo.InvariantCulture);
if (FindKey(embedded, name) != null) continue;
try { if (!string.IsNullOrEmpty(navFolder) && File.Exists(Path.Combine(navFolder, name + ".nav"))) continue; }
catch { }
return name;
}
}
/// <summary>The key <paramref name="embedded"/> files <paramref name="name"/> under (any case, stray brackets), or null.</summary>
public static string? FindKey(IDictionary<string, List<string>> embedded, string name)
{
if (embedded.ContainsKey(name))
{
foreach (string k in embedded.Keys)
if (string.Equals(k, name, StringComparison.OrdinalIgnoreCase)) return k;
}
foreach (string k in embedded.Keys)
if (string.Equals(EmbedNavName.Clean(k), name, StringComparison.OrdinalIgnoreCase)) return k;
return null;
}
/// <summary>
/// NavProfiles\&lt;name&gt;.nav as the meta keeps it (canonical uTank2 lines), when the file is a route
/// with points (or a Follow nav). A name that leaves the folder, "[None]" and an unreadable file give false.
/// </summary>
public static bool TryRead(string navFolder, string name, out List<string> lines)
{
lines = new List<string>();
if (string.IsNullOrWhiteSpace(navFolder) || string.IsNullOrWhiteSpace(name) || EmbedNavName.IsNone(name)) return false;
string path;
try
{
string root = Path.GetFullPath(navFolder).TrimEnd('\\', '/');
path = Path.GetFullPath(Path.Combine(root, name + ".nav"));
if (!path.StartsWith(root + Path.DirectorySeparatorChar, StringComparison.OrdinalIgnoreCase)) return false;
}
catch { return false; }
if (!File.Exists(path)) return false;
NavRouteParser route = NavRouteParser.Load(path);
if (route.LoadWarning?.Length > 0) return false;
bool follow = route.RouteType == NavRouteType.Follow && route.FollowTargetName.Length > 0;
if (route.Points.Count == 0 && !follow) return false;
lines = route.ToLines();
return lines.Count >= 3;
}
private static int PointCount(List<string> lines) => NavRouteParser.LoadFromLines(lines).Points.Count;
private static void Collect(MetaRule rule, HashSet<string> names)
{
if (rule.Action == MetaActionType.EmbeddedNavRoute && !string.IsNullOrWhiteSpace(rule.ActionData))
{
string name = EmbedNavName.Clean(rule.ActionData.Split(';')[0]);
if (name.Length > 0) names.Add(name);
}
if (rule.ActionChildren != null)
foreach (MetaRule c in rule.ActionChildren) Collect(c, names);
if (rule.Children != null) // as AfFileWriter collects them
foreach (MetaRule c in rule.Children) Collect(c, names);
}
}

View file

@ -71,6 +71,8 @@ internal sealed class MetaResumeState
public string NavPath = "";
public List<string> RouteLines = new();
/// <summary>NavRouteParser.MadeBy of the running route (a patrol's, a hunt's...): kept so "Embed loaded" still refuses it after the reload.</summary>
public string RouteMadeBy = "";
public int NavIndex;
public bool NavEnabled;
}
@ -152,6 +154,7 @@ internal static class MetaResumeStore
Line(sb, "nextsw", s.NextStopwatchId.ToString(Ic));
Line(sb, "navpath", Esc(s.NavPath));
foreach (string l in s.RouteLines) Line(sb, "route", Esc(l));
if (s.RouteMadeBy.Length > 0) Line(sb, "routemadeby", Esc(s.RouteMadeBy));
Line(sb, "navindex", s.NavIndex.ToString(Ic));
Line(sb, "navon", s.NavEnabled ? "1" : "0");
Line(sb, "end", "1"); // a torn write never parses
@ -244,6 +247,7 @@ internal static class MetaResumeStore
case "nextsw": s.NextStopwatchId = int.Parse(v, Ic); break;
case "navpath": s.NavPath = Un(v); break;
case "route": s.RouteLines.Add(Un(v)); break;
case "routemadeby": s.RouteMadeBy = Un(v); break;
case "navindex": s.NavIndex = int.Parse(v, Ic); break;
case "navon": s.NavEnabled = v == "1"; break;
case "end": end = v == "1"; break;