Snapshot for release 2026.10.15.2 (internal 2d4b0af)

This commit is contained in:
Tom Bohar 2026-10-15 20:32:35 -04:00
commit d5e0b50de7
224 changed files with 17914 additions and 1182 deletions

View file

@ -0,0 +1,309 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Text;
using System.Text.Json;
namespace RynthCore.Plugin.RynthOracle.Data;
/// <summary>
/// One character's quest notes: the quests tracked in the Quest Timers window and the rewards
/// recorded per quest (UtilityBelt ILT's quest_rewards.json, kept by RynthOracle now). Lives in
/// %APPDATA%\RynthCore\RynthOracle\characters\&lt;world&gt;\&lt;character&gt;.json, written by hand and
/// read with JsonDocument (no reflection serializer: it roots plugin types across hot reloads).
///
/// The first time a character has no file, an existing UtilityBelt quest_rewards.json for the
/// same world and character is imported once (Documents\Decal Plugins\UtilityBelt\&lt;world&gt;\&lt;character&gt;).
/// Pump thread only.
/// </summary>
internal sealed class QuestBook
{
public const int SchemaVersion = 1;
private readonly List<string> _tracked = new();
private readonly HashSet<string> _trackedSet = new(StringComparer.OrdinalIgnoreCase);
private readonly Dictionary<string, QuestReward> _rewards = new(StringComparer.OrdinalIgnoreCase);
/// <summary>The character the book belongs to ("" = none loaded: changes are not saved).</summary>
public string Character { get; private set; } = "";
public string World { get; private set; } = "";
/// <summary>Bumps on every change (views rebuild their caches on it).</summary>
public int Revision { get; private set; }
/// <summary>What happened at load ("imported 4 rewards from UtilityBelt"), shown once in chat; "" = nothing to say.</summary>
public string LoadNote { get; private set; } = "";
/// <summary>Overrides the folder (tests).</summary>
internal string? RootOverride { get; set; }
/// <summary>Overrides UtilityBelt's folder (tests); "" turns the import off.</summary>
internal string? UbRootOverride { get; set; }
public bool Loaded => Character.Length > 0;
public IReadOnlyList<string> Tracked => _tracked;
public int RewardCount => _rewards.Count;
public bool IsTracked(string flag) => _trackedSet.Contains(flag);
public bool TryGetReward(string flag, out QuestReward reward) => _rewards.TryGetValue(flag, out reward!);
/// <summary>The recorded rewards' compact text, or "".</summary>
public string RewardText(string flag) => _rewards.TryGetValue(flag, out QuestReward? r) ? r.ShortSummary() : "";
private string Root => RootOverride ?? Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "RynthCore", "RynthOracle", "characters");
private string UbRoot => UbRootOverride ?? Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "Decal Plugins", "UtilityBelt");
/// <summary>The file for a world and character (names made safe for a path).</summary>
public string PathFor(string world, string character) =>
Path.Combine(Root, SafeName(world.Length > 0 ? world : "default"), SafeName(character) + ".json");
/// <summary>Loads (or starts) the book for a character; a no-op when it is already loaded.</summary>
public void Load(string world, string character)
{
world ??= "";
character = (character ?? "").Trim();
if (character.Length == 0) return;
if (string.Equals(character, Character, StringComparison.Ordinal) && string.Equals(world, World, StringComparison.Ordinal)) return;
ResetData();
Character = character;
World = world;
LoadNote = "";
string file = PathFor(world, character);
try
{
if (File.Exists(file)) Read(File.ReadAllText(file));
else if (ImportUb(world, character) is int n and > 0)
{
LoadNote = $"Imported {n} quest reward{(n == 1 ? "" : "s")} from UtilityBelt.";
Save();
}
}
catch (Exception ex) when (ex is IOException or UnauthorizedAccessException or JsonException)
{
// A broken file means an empty book; the next change rewrites it.
LoadNote = "Couldn't read the saved quest notes (" + ex.GetType().Name + "); starting empty.";
}
Revision++;
}
/// <summary>Forgets the character (logout). Changes were saved as they were made.</summary>
public void Clear()
{
ResetData();
Character = "";
World = "";
LoadNote = "";
Revision++;
}
private void ResetData()
{
_tracked.Clear();
_trackedSet.Clear();
_rewards.Clear();
}
/// <summary>Tracks or untracks a quest; returns the new state. Saved at once.</summary>
public bool SetTracked(string flag, bool tracked)
{
if (string.IsNullOrWhiteSpace(flag)) return false;
if (tracked == _trackedSet.Contains(flag)) return tracked;
if (tracked)
{
_trackedSet.Add(flag);
_tracked.Add(flag);
}
else
{
_trackedSet.Remove(flag);
_tracked.RemoveAll(f => string.Equals(f, flag, StringComparison.OrdinalIgnoreCase));
}
Revision++;
Save();
return tracked;
}
public bool ToggleTracked(string flag) => SetTracked(flag, !IsTracked(flag));
/// <summary>Stores a quest's rewards (an empty entry removes them). Saved at once.</summary>
public void SetReward(string flag, QuestReward? reward)
{
if (string.IsNullOrWhiteSpace(flag)) return;
if (reward == null || reward.IsEmpty) _rewards.Remove(flag);
else _rewards[flag] = reward.Clone();
Revision++;
Save();
}
/// <summary>Writes the book (atomic replace). Does nothing with no character loaded.</summary>
public void Save()
{
if (!Loaded) return;
try
{
string file = PathFor(World, Character);
Directory.CreateDirectory(Path.GetDirectoryName(file)!);
string tmp = file + ".tmp";
File.WriteAllText(tmp, ToJson(), new UTF8Encoding(false));
File.Move(tmp, file, overwrite: true);
}
catch (Exception ex) when (ex is IOException or UnauthorizedAccessException)
{
// Notes are a convenience; a failed write keeps the old file.
}
}
/// <summary>The book as JSON (plain ASCII: anything else is escaped).</summary>
internal string ToJson()
{
var sb = new StringBuilder(1024);
sb.Append("{\n");
sb.Append(" \"schemaVersion\": ").Append(SchemaVersion.ToString(CultureInfo.InvariantCulture)).Append(",\n");
sb.Append(" \"character\": ").Append(Q(Character)).Append(",\n");
sb.Append(" \"world\": ").Append(Q(World)).Append(",\n");
sb.Append(" \"savedAtUtc\": ").Append(Q(DateTime.UtcNow.ToString("o", CultureInfo.InvariantCulture))).Append(",\n");
sb.Append(" \"tracked\": [");
for (int i = 0; i < _tracked.Count; i++)
sb.Append(i > 0 ? ", " : "").Append(Q(_tracked[i]));
sb.Append("],\n");
sb.Append(" \"rewards\": {");
bool first = true;
var keys = new List<string>(_rewards.Keys);
keys.Sort(StringComparer.OrdinalIgnoreCase);
foreach (string key in keys)
{
QuestReward r = _rewards[key];
sb.Append(first ? "\n" : ",\n");
first = false;
sb.Append(" ").Append(Q(key)).Append(": {");
sb.Append("\"xpPercent\": ").Append(r.XpPercent.ToString("R", CultureInfo.InvariantCulture));
sb.Append(", \"lumPercent\": ").Append(r.LumPercent.ToString("R", CultureInfo.InvariantCulture));
sb.Append(", \"recordedLevel\": ").Append(r.RecordedLevel.ToString(CultureInfo.InvariantCulture));
sb.Append(", \"coins\": ").Append(r.Coins.ToString(CultureInfo.InvariantCulture));
sb.Append(", \"trinkets\": ").Append(r.Trinkets.ToString(CultureInfo.InvariantCulture));
sb.Append(", \"medallions\": ").Append(r.Medallions.ToString(CultureInfo.InvariantCulture));
sb.Append(", \"yellowPowder\": ").Append(r.YellowPowder.ToString(CultureInfo.InvariantCulture));
sb.Append(", \"redPowder\": ").Append(r.RedPowder.ToString(CultureInfo.InvariantCulture));
sb.Append(", \"bluePowder\": ").Append(r.BluePowder.ToString(CultureInfo.InvariantCulture));
sb.Append(", \"mmd\": ").Append(r.Mmd.ToString(CultureInfo.InvariantCulture));
sb.Append('}');
}
sb.Append(first ? "}\n" : "\n }\n");
sb.Append("}\n");
return sb.ToString();
}
/// <summary>Reads a saved book (RynthOracle's own lower-case keys, or UB's upper-case ones).</summary>
internal void Read(string json)
{
using JsonDocument doc = JsonDocument.Parse(json);
JsonElement root = doc.RootElement;
if (root.ValueKind != JsonValueKind.Object) return;
if (Prop(root, "tracked", out JsonElement tracked) && tracked.ValueKind == JsonValueKind.Array)
{
foreach (JsonElement t in tracked.EnumerateArray())
{
string flag = t.ValueKind == JsonValueKind.String ? (t.GetString() ?? "").Trim() : "";
if (flag.Length > 0 && _trackedSet.Add(flag)) _tracked.Add(flag);
}
}
ReadRewards(root);
}
/// <summary>The "rewards" / "Rewards" object: flag -> entry. Returns how many were kept.</summary>
private int ReadRewards(JsonElement root)
{
if (!Prop(root, "rewards", out JsonElement rewards) || rewards.ValueKind != JsonValueKind.Object) return 0;
int n = 0;
foreach (JsonProperty p in rewards.EnumerateObject())
{
if (p.Value.ValueKind != JsonValueKind.Object || p.Name.Trim().Length == 0) continue;
JsonElement e = p.Value;
var r = new QuestReward
{
XpPercent = Math.Clamp(Dbl(e, "xpPercent"), 0, QuestReward.MaxPercent),
LumPercent = Math.Clamp(Dbl(e, "lumPercent"), 0, QuestReward.MaxPercent),
RecordedLevel = Int(e, "recordedLevel"),
Coins = Int(e, "coins"),
Trinkets = Int(e, "trinkets"),
Medallions = Int(e, "medallions"),
YellowPowder = Int(e, "yellowPowder"),
RedPowder = Int(e, "redPowder"),
BluePowder = Int(e, "bluePowder"),
Mmd = Int(e, "mmd"),
};
if (r.IsEmpty) continue;
_rewards[p.Name.Trim()] = r;
n++;
}
return n;
}
/// <summary>UtilityBelt ILT's quest_rewards.json for this world and character, if there is one. Returns the entries kept.</summary>
private int ImportUb(string world, string character)
{
string ubRoot = UbRoot;
if (ubRoot.Length == 0 || world.Length == 0) return 0;
// UB names the server folder after the world with its spaces removed ("InfiniteLeaftide").
foreach (string w in new[] { world, world.Replace(" ", "") })
{
string file = Path.Combine(ubRoot, SafeName(w), SafeName(character), "quest_rewards.json");
if (!File.Exists(file)) continue;
using JsonDocument doc = JsonDocument.Parse(File.ReadAllText(file));
return doc.RootElement.ValueKind == JsonValueKind.Object ? ReadRewards(doc.RootElement) : 0;
}
return 0;
}
// ── JSON helpers (keys matched without regard to case: UB writes "XpPercent") ──────────────
private static bool Prop(JsonElement o, string name, out JsonElement value)
{
foreach (JsonProperty p in o.EnumerateObject())
{
if (!string.Equals(p.Name, name, StringComparison.OrdinalIgnoreCase)) continue;
value = p.Value;
return true;
}
value = default;
return false;
}
private static double Dbl(JsonElement o, string name) =>
Prop(o, name, out JsonElement v) && v.ValueKind == JsonValueKind.Number && v.TryGetDouble(out double d) && double.IsFinite(d) ? d : 0;
private static int Int(JsonElement o, string name)
{
if (!Prop(o, name, out JsonElement v) || v.ValueKind != JsonValueKind.Number) return 0;
if (v.TryGetInt64(out long l)) return (int)Math.Clamp(l, 0, int.MaxValue);
return v.TryGetDouble(out double d) && double.IsFinite(d) ? (int)Math.Clamp(d, 0, int.MaxValue) : 0;
}
/// <summary>A JSON string literal, ASCII only.</summary>
private static string Q(string s)
{
var sb = new StringBuilder(s.Length + 2);
sb.Append('"');
foreach (char c in s)
{
if (c == '"') sb.Append("\\\"");
else if (c == '\\') sb.Append("\\\\");
else if (c < 0x20 || c > 0x7E) sb.Append("\\u").Append(((int)c).ToString("x4", CultureInfo.InvariantCulture));
else sb.Append(c);
}
return sb.Append('"').ToString();
}
/// <summary>A name safe as one path segment (invalid characters become '_').</summary>
internal static string SafeName(string name)
{
var sb = new StringBuilder(name.Length);
char[] bad = Path.GetInvalidFileNameChars();
foreach (char c in name.Trim()) sb.Append(Array.IndexOf(bad, c) >= 0 ? '_' : c);
string s = sb.ToString().Trim('.', ' ');
return s.Length > 0 ? s : "_";
}
}

View file

@ -34,6 +34,9 @@ internal sealed class Quest
/// <summary>The Name column: the curated name, else the one-line info, else "Unknown quest" (upstream's rule).</summary>
public string DisplayName => Name.Length > 0 ? Name : Info.Length > 0 ? Info : "Unknown quest";
/// <summary>The list label: the display name, or for a flag no list knows "(new)" and its description or flag.</summary>
public string Label => IsNew ? "(new) " + (Name.Length > 0 ? Name : Flag) : DisplayName;
/// <summary>The server is the source of truth where it has spoken (the flag's timer); else the lists.</summary>
public bool IsRepeatable(QuestFlagStore flags) =>
flags.TryGet(Flag, out QuestFlag q) ? q.RepeatTime != TimeSpan.Zero : Repeatable;

View file

@ -0,0 +1,105 @@
using System;
using System.Collections.Generic;
using System.Globalization;
namespace RynthCore.Plugin.RynthOracle.Data;
/// <summary>
/// What one quest pays this character, as the player recorded it (UtilityBelt ILT's
/// QuestRewardEntry, Lib/Quests/QuestRewardsFile.cs). XP and luminance are percentages of a
/// level's worth, so they are kept with the level they were noted at.
/// </summary>
internal sealed class QuestReward
{
/// <summary>The largest percentage accepted (UB's clamp).</summary>
public const double MaxPercent = 1000;
public double XpPercent;
public double LumPercent;
/// <summary>The character level the percentages were noted at; 0 = not recorded.</summary>
public int RecordedLevel;
public int Coins;
public int Trinkets;
public int Medallions;
public int YellowPowder;
public int RedPowder;
public int BluePowder;
public int Mmd;
/// <summary>Nothing recorded (an empty entry is dropped instead of saved).</summary>
public bool IsEmpty =>
XpPercent <= 0 && LumPercent <= 0 && Coins <= 0 && Trinkets <= 0 && Medallions <= 0
&& YellowPowder <= 0 && RedPowder <= 0 && BluePowder <= 0 && Mmd <= 0;
public QuestReward Clone() => (QuestReward)MemberwiseClone();
/// <summary>
/// The compact column text, UB's format: "1.5%XP 2%Lum 3C 1T 2M 1Y 1R 1B 2D L275". Zero fields
/// are left out; " L&lt;level&gt;" follows when XP or luminance is set and the level is known.
/// </summary>
public string ShortSummary()
{
var parts = new List<string>(10);
if (XpPercent > 0) parts.Add(Percent(XpPercent) + "%XP");
if (LumPercent > 0) parts.Add(Percent(LumPercent) + "%Lum");
if (Coins > 0) parts.Add(Coins.ToString(CultureInfo.InvariantCulture) + "C");
if (Trinkets > 0) parts.Add(Trinkets.ToString(CultureInfo.InvariantCulture) + "T");
if (Medallions > 0) parts.Add(Medallions.ToString(CultureInfo.InvariantCulture) + "M");
if (YellowPowder > 0) parts.Add(YellowPowder.ToString(CultureInfo.InvariantCulture) + "Y");
if (RedPowder > 0) parts.Add(RedPowder.ToString(CultureInfo.InvariantCulture) + "R");
if (BluePowder > 0) parts.Add(BluePowder.ToString(CultureInfo.InvariantCulture) + "B");
if (Mmd > 0) parts.Add(Mmd.ToString(CultureInfo.InvariantCulture) + "D");
if ((XpPercent > 0 || LumPercent > 0) && RecordedLevel > 0) parts.Add("L" + RecordedLevel.ToString(CultureInfo.InvariantCulture));
return string.Join(" ", parts);
}
/// <summary>The long form for tooltips and chat: "1.5% XP, 2% luminance (at level 275), 3 coins, ...".</summary>
public string LongSummary()
{
var parts = new List<string>(10);
if (XpPercent > 0) parts.Add(Percent(XpPercent) + "% XP");
if (LumPercent > 0) parts.Add(Percent(LumPercent) + "% luminance");
if ((XpPercent > 0 || LumPercent > 0) && RecordedLevel > 0) parts[parts.Count - 1] += $" (at level {RecordedLevel})";
Add(parts, Coins, "coin");
Add(parts, Trinkets, "trinket");
Add(parts, Medallions, "medallion");
Add(parts, YellowPowder, "yellow powder");
Add(parts, RedPowder, "red powder");
Add(parts, BluePowder, "blue powder");
Add(parts, Mmd, "MMD");
return parts.Count == 0 ? "no rewards recorded" : string.Join(", ", parts);
static void Add(List<string> list, int n, string what)
{
if (n <= 0) return;
bool noPlural = what.EndsWith("powder", StringComparison.Ordinal) || what == "MMD";
list.Add($"{n} {what}{(n == 1 || noPlural ? "" : "s")}");
}
}
/// <summary>UB's percent format: one decimal from 10 up, two from 1 up, three below 1.</summary>
public static string Percent(double v) =>
v.ToString(v >= 10 ? "0.#" : v >= 1 ? "0.##" : "0.###", CultureInfo.InvariantCulture);
/// <summary>A typed percentage ("1.5", "1,5", "2%"); blank = 0. Clamped to 0..<see cref="MaxPercent"/>. False when it isn't a number.</summary>
public static bool TryParsePercent(string? text, out double value)
{
value = 0;
string t = (text ?? "").Trim().TrimEnd('%').Trim().Replace(',', '.');
if (t.Length == 0) return true;
if (!double.TryParse(t, NumberStyles.Float, CultureInfo.InvariantCulture, out double v) || !double.IsFinite(v)) return false;
value = Math.Clamp(v, 0, MaxPercent);
return true;
}
/// <summary>A typed count; blank = 0, negatives become 0. False when it isn't a whole number.</summary>
public static bool TryParseCount(string? text, out int value)
{
value = 0;
string t = (text ?? "").Trim().Replace(",", "");
if (t.Length == 0) return true;
if (!long.TryParse(t, NumberStyles.Integer, CultureInfo.InvariantCulture, out long v)) return false;
value = (int)Math.Clamp(v, 0, int.MaxValue);
return true;
}
}

View file

@ -0,0 +1,94 @@
using System;
using System.Text.RegularExpressions;
namespace RynthCore.Plugin.RynthOracle.Data;
/// <summary>How a quest stands right now, for the timer columns and the Quest Timers window.</summary>
internal enum QuestTimerState
{
/// <summary>Can be done now (never done, or the timer ran out).</summary>
Ready,
/// <summary>Waiting on its repeat timer.</summary>
Waiting,
/// <summary>A kill task still collecting kills.</summary>
InProgress,
/// <summary>Done for good: a one-time quest, a solve limit reached, or a finished kill task with no timer.</summary>
Done,
}
/// <summary>
/// Quest timer text shared by the Quests tab and the Quest Timers window. Kill tasks follow
/// UtilityBelt ILT's rule (QuestTracker.GetKTStatusText): "N left" while counting, then the reset
/// countdown, then "done". Kill-task flags are recognised by name as RynthAi's tracker did.
/// </summary>
internal static class QuestTimer
{
// RynthAi's / UtilityBelt's kill-task pattern (counter flags), with a solve limit set.
private static readonly Regex KillTaskRegex = new(@"(killtask|killcount|slayerquest|totalgolem.*dead|(kills$))",
RegexOptions.Compiled | RegexOptions.IgnoreCase | RegexOptions.CultureInvariant);
/// <summary>A kill-task counter flag (its name says so and it has a solve limit).</summary>
public static bool IsKillTask(QuestFlag f) => f.MaxSolves > 0 && KillTaskRegex.IsMatch(f.Key);
/// <summary>A quest's state; <paramref name="text"/> is what the column shows.</summary>
public static QuestTimerState State(Quest q, QuestFlagStore flags, DateTime utcNow, out string text)
{
if (!flags.TryGet(q.Flag, out QuestFlag f))
{
text = "ready";
return QuestTimerState.Ready;
}
return State(f, q.IsRepeatable(flags), utcNow, out text);
}
/// <summary>A held flag's state (<paramref name="repeatable"/>: the quest can be done again at all).</summary>
public static QuestTimerState State(QuestFlag f, bool repeatable, DateTime utcNow, out string text)
{
TimeSpan left = f.NextAvailableTime(utcNow);
if (IsKillTask(f))
{
if (f.Solves < f.MaxSolves)
{
text = $"{f.MaxSolves - f.Solves} left";
return QuestTimerState.InProgress;
}
if (f.RepeatTime > TimeSpan.Zero && left > TimeSpan.Zero)
{
text = TimeText.Friendly(left);
return QuestTimerState.Waiting;
}
text = "done";
return QuestTimerState.Done;
}
if (!repeatable)
{
text = "completed";
return QuestTimerState.Done;
}
if (f.AtSolveLimit)
{
text = "maxed";
return QuestTimerState.Done;
}
if (left > TimeSpan.Zero)
{
text = TimeText.Friendly(left);
return QuestTimerState.Waiting;
}
text = "ready";
return QuestTimerState.Ready;
}
/// <summary>Sort key: ready first, then by time left, then kill tasks in progress, then done.</summary>
public static double SortKey(Quest q, QuestFlagStore flags, DateTime utcNow)
{
QuestTimerState s = State(q, flags, utcNow, out _);
return s switch
{
QuestTimerState.Ready => 0,
QuestTimerState.Waiting when flags.TryGet(q.Flag, out QuestFlag f) => 1 + Math.Max(0, f.NextAvailableTime(utcNow).TotalSeconds),
QuestTimerState.InProgress => 1e12,
_ => 2e12,
};
}
}

View file

@ -1,4 +1,5 @@
using System;
using RynthCore.Plugin.Shared;
using RynthCore.PluginSdk;
namespace RynthCore.Plugin.RynthOracle.Data;
@ -20,6 +21,8 @@ internal static class ServerTags
/// only load or show where <see cref="Allows"/> says so; untagged (retail) ones work anywhere.
///
/// Sources, best first:
/// 0. Engine API v86 GetServerStateJson (ServerStateClient): RynthCore's active server, with
/// this character's overrides and the Diagnostics page's server pick applied (FromEngine).
/// 1. Engine API v75 GetServerInfo: the engine's own verdict for Aelrynth (connect host,
/// announced world name, Bank mod properties) and the world name the server announced
/// at login. Never the launcher profile name.
@ -28,7 +31,8 @@ internal static class ServerTags
/// mod's player properties 9101-9103, which only Aelrynth sends.
/// Aelrynth's live config still names the world "Aeshnidae" (its earlier name); both count.
/// ConquestAC and Levistras are matched on their world names, as upstream does
/// (Decal's CharacterFilter.Server).
/// (Decal's CharacterFilter.Server). Infinite Leaftide has no RynthOracle pages: its screens are
/// RynthILT's, so RynthCore's "ilt" server gives no tag here.
/// </summary>
internal sealed class ServerIdentity
{
@ -51,8 +55,20 @@ internal sealed class ServerIdentity
Set("", "", "not logged in");
}
public void Refresh(RynthCoreHost host, uint playerId)
/// <param name="engine">
/// RynthCore's server list (plugin API v86, ServerStateClient); null on older engines. When there,
/// it decides: it already applies this character's overrides and the Diagnostics page's pick.
/// </param>
public void Refresh(RynthCoreHost host, uint playerId, EngineServerState? engine = null)
{
if (engine != null)
{
string fallbackWorld = host.TryGetWorldName(out string fw) ? fw.Trim() : "";
FromEngine(engine, fallbackWorld, out string t, out string wn, out string src);
Set(t, wn, src);
return;
}
string tag, world, source;
if (host.TryGetServerInfo(out bool aelrynth, out bool staging, out string announced))
{
@ -85,6 +101,59 @@ internal sealed class ServerIdentity
Set(tag, world, source);
}
/// <summary>
/// The identity from RynthCore's server list. An active server decides the tag (its own, or ""
/// for a server RynthOracle has nothing for). With none active, the world name may still tag a
/// server the engine doesn't know (Conquest without RynthConquest loaded), but never one the
/// engine lists: that one is off on purpose (not detected, or this character's override).
/// Pure: the tests drive it.
/// </summary>
internal static void FromEngine(EngineServerState engine, string fallbackWorld, out string tag, out string world, out string source)
{
world = engine.World.Length > 0 ? engine.World : (fallbackWorld ?? "").Trim();
if (engine.HasActive)
{
tag = TagForEngineId(engine.Active);
EngineServer? s = engine.Find(engine.Active);
string how = engine.Picked ? "picked by hand"
: s != null && s.Force.Equals("on", StringComparison.OrdinalIgnoreCase) ? "forced on for this character"
: s != null && s.Reason.Length > 0 ? s.Reason : "detected";
string name = engine.ActiveName.Length > 0 ? engine.ActiveName : engine.Active;
source = $"RynthCore: {name} ({how})" + (tag.Length == 0 ? " - no RynthOracle pages for it" : "");
return;
}
tag = TagForWorld(world);
string id = EngineIdForTag(tag);
if (tag.Length > 0 && id.Length > 0 && engine.Find(id) != null)
{
source = $"RynthCore: {tag} is off for this world (not detected, or overridden)";
tag = "";
return;
}
source = tag.Length > 0
? $"world name \"{world}\" (RynthCore has no {tag} server loaded)"
: "RynthCore: no server active (retail features only)";
}
/// <summary>The tag for a RynthCore server id; "" for servers without RynthOracle features.</summary>
public static string TagForEngineId(string? id) => (id ?? "").Trim().ToLowerInvariant() switch
{
EngineServerState.AelrynthId => ServerTags.Aelrynth,
"conquest" => ServerTags.Conquest,
"levistras" => ServerTags.Levistras,
_ => "",
};
/// <summary>The RynthCore server id for a tag; "" for none.</summary>
public static string EngineIdForTag(string? tag) => tag switch
{
ServerTags.Aelrynth => EngineServerState.AelrynthId,
ServerTags.Conquest => "conquest",
ServerTags.Levistras => "levistras",
_ => "",
};
/// <summary>The tag for a world name; "" for servers without their own features.</summary>
public static string TagForWorld(string? world)
{