Snapshot for release 2026.10.20.1 (internal 7116fab)
This commit is contained in:
parent
2a20c7acd6
commit
bfcd48950d
215 changed files with 16200 additions and 2838 deletions
|
|
@ -1,265 +0,0 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace RynthCore.Plugin.RynthOracle.Data;
|
||||
|
||||
/// <summary>A board in Aelrynth's /top overview.</summary>
|
||||
internal sealed class AelrynthBoardSummary
|
||||
{
|
||||
public string Key = "", Title = "", Leader = "", Value = "";
|
||||
}
|
||||
|
||||
/// <summary>Your standing on one board ("/top me").</summary>
|
||||
internal sealed class AelrynthStanding
|
||||
{
|
||||
public string Title = "";
|
||||
public int Rank;
|
||||
public int Of;
|
||||
public string Value = "";
|
||||
}
|
||||
|
||||
/// <summary>A line of the "/trial" overview: a dungeon's record, yours and this week's best.</summary>
|
||||
internal sealed class TrialDungeon
|
||||
{
|
||||
public string Name = "", Landblock = "", Record = "", You = "", Week = "";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Aelrynth's leaderboards (tag Aelrynth), read from the replies of the server's own commands
|
||||
/// (ACEPublic Mods: Aeshnidae.Leaderboard /top, Aeshnidae.Trials /trial; one Broadcast line
|
||||
/// each, numbers with thousands separators). Formats (Commands.cs):
|
||||
/// /top "Leaderboards - N characters, refreshed X. /top <board> ..."
|
||||
/// then " key Title: Leader, value" (or ": nobody yet")
|
||||
/// /top <board> "Title - top K of N[, counted since ...][, per account]:"
|
||||
/// then " r. Name value[ extra][ <- you]", " ... you: #r with v", " nobody yet."
|
||||
/// /top me "Name on the boards:" then " Title #r of N, value" or " Title -"
|
||||
/// /trial a few intro lines, then " Dungeon (LLLL): records | you: ... | this week: ..."
|
||||
/// /trial <dungeon> "Dungeon (LLLL) - top 10, best per character, any tier:"
|
||||
/// then " r. m:ss Name (tier T, K kills, d MMM)" and " records per tier/you/this week" lines
|
||||
/// Entry lines only count right after their header (within a few seconds), so ordinary chat
|
||||
/// can't add rows. The two commands share /top with ConquestAC's very different reply, which is
|
||||
/// why each parser only runs on its own server.
|
||||
/// </summary>
|
||||
internal sealed class AelrynthBoards
|
||||
{
|
||||
private const long BlockMs = 4000;
|
||||
|
||||
private static readonly Regex OverviewHeader = new(@"^\s*Leaderboards - ([\d,]+) characters, refreshed (.+?)\.\s");
|
||||
private static readonly Regex OverviewEntry = new(@"^\s*(\S+)\s+(.+?): (?:(.+), ([\d,]+)|nobody yet)\s*$");
|
||||
private static readonly Regex BoardHeader = new(@"^\s*(.+?) - top (\d+) of (\d+)(.*):\s*$");
|
||||
private static readonly Regex BoardEntry = new(@"^\s*(\d+)\.\s+(.+?)\s+([\d,]+)(?:\s{2,}(?!<-)(.+?))?(\s{2,}<- you)?\s*$");
|
||||
private static readonly Regex BoardYouBelow = new(@"^\s*\.\.\.\s+you: #(\d+) with ([\d,]+)\s*$");
|
||||
private static readonly Regex MeHeader = new(@"^\s*(.+?) on the boards:\s*$");
|
||||
private static readonly Regex MeEntry = new(@"^\s*(.+?)\s+#(\d+) of (\d+), ([\d,]+)\s*$");
|
||||
private static readonly Regex MeNone = new(@"^\s*(.+?)\s+-\s*$");
|
||||
private static readonly Regex OneMe = new(@"^\s*(.+?): you are #(\d+) of (\d+) with ([\d,]+)");
|
||||
private static readonly Regex TopError = new(@"^\s*(?:No board called '|Leaderboards are unavailable|The boards are still being built)");
|
||||
private static readonly Regex TrialDungeonLine = new(@"^\s*(.+?) \(([0-9A-Fa-f]{4})\): (.+?) \| you: (.+?) \| this week: (.+?)\s*$");
|
||||
private static readonly Regex TrialBoardHeader = new(@"^\s*(.+?) \(([0-9A-Fa-f]{4})\) - top 10, best per character, any tier:\s*$");
|
||||
private static readonly Regex TrialEntry = new(@"^\s*(\d+)\.\s+(\d+:\d{2}(?::\d{2})?)\s+(.+?) \((.+)\)\s*$");
|
||||
private static readonly Regex TrialNote = new(@"^\s*(?:records per tier|you|this week \([^)]*\)):\s");
|
||||
private static readonly Regex TrialError = new(@"^\s*(?:No Trial matches '|The Trials are switched off|The Trials could not be read)");
|
||||
private static readonly Regex TrialIntro = new(@"^\s*Trials - a fresh personal copy of a listed dungeon");
|
||||
private static readonly Regex TrialExtra = new(@"^\s*(?:your next attempt here: in \d+ min|running now: .+|Trophy: the week's fastest clear .+)$");
|
||||
|
||||
private enum Block { None, Overview, Board, Me, TrialList, TrialBoard }
|
||||
|
||||
public readonly List<AelrynthBoardSummary> Overview = new();
|
||||
public string OverviewNote = "";
|
||||
public string BoardTitle = "", BoardNote = "";
|
||||
public readonly List<BoardRow> BoardRows = new();
|
||||
public string BoardYou = "";
|
||||
public readonly List<AelrynthStanding> Standings = new();
|
||||
public readonly List<TrialDungeon> Trials = new();
|
||||
public readonly List<string> TrialLines = new();
|
||||
public string TrialBoardTitle = "";
|
||||
public readonly List<BoardRow> TrialRows = new();
|
||||
public readonly List<string> TrialNotes = new();
|
||||
public string LastError = "";
|
||||
public int Revision { get; private set; }
|
||||
|
||||
private Block _block;
|
||||
private long _blockMs;
|
||||
private readonly ChatRequest _topReq = new(), _trialReq = new();
|
||||
|
||||
public void Clear()
|
||||
{
|
||||
Overview.Clear(); BoardRows.Clear(); Standings.Clear(); Trials.Clear(); TrialLines.Clear(); TrialRows.Clear(); TrialNotes.Clear();
|
||||
OverviewNote = BoardTitle = BoardNote = BoardYou = TrialBoardTitle = LastError = "";
|
||||
_block = Block.None;
|
||||
Revision++;
|
||||
}
|
||||
|
||||
public string RequestTop(string arg, long now)
|
||||
{
|
||||
_topReq.Sent(now);
|
||||
LastError = "";
|
||||
if (string.IsNullOrWhiteSpace(arg)) { BoardTitle = ""; BoardRows.Clear(); }
|
||||
return string.IsNullOrWhiteSpace(arg) ? "/top" : "/top " + arg.Trim();
|
||||
}
|
||||
|
||||
public string RequestTrial(string arg, long now)
|
||||
{
|
||||
_trialReq.Sent(now);
|
||||
LastError = "";
|
||||
return string.IsNullOrWhiteSpace(arg) ? "/trial" : "/trial " + arg.Trim();
|
||||
}
|
||||
|
||||
private bool InBlock(Block b, long now) => _block == b && now - _blockMs < BlockMs;
|
||||
|
||||
private void Start(Block b, long now) { _block = b; _blockMs = now; }
|
||||
|
||||
/// <summary>A chat line: true when it was a leaderboard reply; <paramref name="ours"/> = it answers RynthOracle's request.</summary>
|
||||
public bool OnChatLine(string text, long now, out bool ours)
|
||||
{
|
||||
ours = false;
|
||||
Match m;
|
||||
|
||||
if ((m = OverviewHeader.Match(text)).Success)
|
||||
{
|
||||
Overview.Clear();
|
||||
OverviewNote = $"{m.Groups[1].Value} characters, refreshed {m.Groups[2].Value}";
|
||||
Start(Block.Overview, now);
|
||||
return Mine(_topReq, now, out ours);
|
||||
}
|
||||
if ((m = TrialBoardHeader.Match(text)).Success)
|
||||
{
|
||||
TrialBoardTitle = $"{m.Groups[1].Value} ({m.Groups[2].Value.ToUpperInvariant()})";
|
||||
TrialRows.Clear();
|
||||
TrialNotes.Clear();
|
||||
Start(Block.TrialBoard, now);
|
||||
return Mine(_trialReq, now, out ours);
|
||||
}
|
||||
if ((m = BoardHeader.Match(text)).Success && !text.Contains(" on the boards", StringComparison.Ordinal))
|
||||
{
|
||||
BoardTitle = m.Groups[1].Value.Trim();
|
||||
BoardNote = $"top {m.Groups[2].Value} of {m.Groups[3].Value}{m.Groups[4].Value}";
|
||||
BoardRows.Clear();
|
||||
BoardYou = "";
|
||||
Start(Block.Board, now);
|
||||
return Mine(_topReq, now, out ours);
|
||||
}
|
||||
if ((m = MeHeader.Match(text)).Success)
|
||||
{
|
||||
Standings.Clear();
|
||||
Start(Block.Me, now);
|
||||
return Mine(_topReq, now, out ours);
|
||||
}
|
||||
if ((m = OneMe.Match(text)).Success)
|
||||
{
|
||||
BoardYou = $"{m.Groups[1].Value}: #{m.Groups[2].Value} of {m.Groups[3].Value} with {m.Groups[4].Value}";
|
||||
return Mine(_topReq, now, out ours);
|
||||
}
|
||||
if (TopError.IsMatch(text))
|
||||
{
|
||||
LastError = text.Trim();
|
||||
return Mine(_topReq, now, out ours);
|
||||
}
|
||||
if (TrialError.IsMatch(text))
|
||||
{
|
||||
LastError = text.Trim();
|
||||
return Mine(_trialReq, now, out ours);
|
||||
}
|
||||
if ((m = TrialDungeonLine.Match(text)).Success)
|
||||
{
|
||||
if (!InBlock(Block.TrialList, now)) { Trials.Clear(); TrialLines.Clear(); }
|
||||
Trials.Add(new TrialDungeon
|
||||
{
|
||||
Name = m.Groups[1].Value.Trim(), Landblock = m.Groups[2].Value.ToUpperInvariant(),
|
||||
Record = m.Groups[3].Value.Trim(), You = m.Groups[4].Value.Trim(), Week = m.Groups[5].Value.Trim(),
|
||||
});
|
||||
Start(Block.TrialList, now);
|
||||
return Mine(_trialReq, now, out ours);
|
||||
}
|
||||
|
||||
if (InBlock(Block.Overview, now) && (m = OverviewEntry.Match(text)).Success)
|
||||
{
|
||||
Overview.Add(new AelrynthBoardSummary
|
||||
{
|
||||
Key = m.Groups[1].Value, Title = m.Groups[2].Value.Trim(),
|
||||
Leader = m.Groups[3].Success ? m.Groups[3].Value.Trim() : "nobody yet",
|
||||
Value = m.Groups[4].Success ? m.Groups[4].Value : "",
|
||||
});
|
||||
_blockMs = now;
|
||||
return Mine(_topReq, now, out ours);
|
||||
}
|
||||
if (InBlock(Block.Board, now))
|
||||
{
|
||||
if ((m = BoardEntry.Match(text)).Success)
|
||||
{
|
||||
int.TryParse(m.Groups[1].Value, out int rank);
|
||||
BoardRows.Add(new BoardRow
|
||||
{
|
||||
Rank = rank, Name = m.Groups[2].Value.Trim(), Value = m.Groups[3].Value,
|
||||
Extra = m.Groups[4].Success ? m.Groups[4].Value.Trim() : "", IsYou = m.Groups[5].Success,
|
||||
});
|
||||
_blockMs = now;
|
||||
return Mine(_topReq, now, out ours);
|
||||
}
|
||||
if ((m = BoardYouBelow.Match(text)).Success)
|
||||
{
|
||||
BoardYou = $"you: #{m.Groups[1].Value} with {m.Groups[2].Value}";
|
||||
return Mine(_topReq, now, out ours);
|
||||
}
|
||||
if (text.Trim() == "nobody yet.") return Mine(_topReq, now, out ours);
|
||||
}
|
||||
if (InBlock(Block.Me, now))
|
||||
{
|
||||
if ((m = MeEntry.Match(text)).Success)
|
||||
{
|
||||
int.TryParse(m.Groups[2].Value, out int r);
|
||||
int.TryParse(m.Groups[3].Value, out int of);
|
||||
Standings.Add(new AelrynthStanding { Title = m.Groups[1].Value.Trim(), Rank = r, Of = of, Value = m.Groups[4].Value });
|
||||
_blockMs = now;
|
||||
return Mine(_topReq, now, out ours);
|
||||
}
|
||||
if ((m = MeNone.Match(text)).Success)
|
||||
{
|
||||
Standings.Add(new AelrynthStanding { Title = m.Groups[1].Value.Trim() });
|
||||
_blockMs = now;
|
||||
return Mine(_topReq, now, out ours);
|
||||
}
|
||||
}
|
||||
if (InBlock(Block.TrialBoard, now))
|
||||
{
|
||||
if ((m = TrialEntry.Match(text)).Success)
|
||||
{
|
||||
int.TryParse(m.Groups[1].Value, out int rank);
|
||||
TrialRows.Add(new BoardRow { Rank = rank, Value = m.Groups[2].Value, Name = m.Groups[3].Value.Trim(), Extra = m.Groups[4].Value.Trim() });
|
||||
_blockMs = now;
|
||||
return Mine(_trialReq, now, out ours);
|
||||
}
|
||||
if (TrialNote.IsMatch(text) || text.Trim() == "no clear yet")
|
||||
{
|
||||
TrialNotes.Add(text.Trim());
|
||||
_blockMs = now;
|
||||
return Mine(_trialReq, now, out ours);
|
||||
}
|
||||
}
|
||||
// The rest of a /trial overview: the intro, "next attempt", "running now" and trophy lines.
|
||||
if (TrialIntro.IsMatch(text))
|
||||
{
|
||||
Trials.Clear();
|
||||
TrialLines.Clear();
|
||||
TrialLines.Add(text.Trim());
|
||||
Start(Block.TrialList, now);
|
||||
return Mine(_trialReq, now, out ours);
|
||||
}
|
||||
if (InBlock(Block.TrialList, now) && TrialExtra.IsMatch(text))
|
||||
{
|
||||
TrialLines.Add(text.Trim());
|
||||
_blockMs = now;
|
||||
return Mine(_trialReq, now, out ours);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private bool Mine(ChatRequest req, long now, out bool ours)
|
||||
{
|
||||
ours = req.Awaiting(now);
|
||||
req.Extend(now);
|
||||
Revision++;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,24 +0,0 @@
|
|||
// Ported from Oracle of Dereth by Advis Eveldan (advis61), MIT. See THIRD_PARTY_NOTICES.md.
|
||||
namespace RynthCore.Plugin.RynthOracle.Data;
|
||||
|
||||
/// <summary>
|
||||
/// RynthOracle sent a server command and expects its reply for a few seconds, so the chat
|
||||
/// handler can tell its own reply from the same command typed by hand (only ours may be hidden).
|
||||
/// A time window, as upstream: these replies carry nothing tying them to the request. Each line
|
||||
/// of the reply extends it, so a long reply stays ours to its end.
|
||||
/// </summary>
|
||||
internal sealed class ChatRequest
|
||||
{
|
||||
private const long WindowMs = 5000;
|
||||
private long _untilMs;
|
||||
|
||||
public void Sent(long nowMs) => _untilMs = nowMs + WindowMs;
|
||||
public void Clear() => _untilMs = 0;
|
||||
public bool Awaiting(long nowMs) => nowMs < _untilMs;
|
||||
|
||||
/// <summary>A reply line arrived: keep the window open a little longer.</summary>
|
||||
public void Extend(long nowMs)
|
||||
{
|
||||
if (Awaiting(nowMs)) _untilMs = nowMs + 2000 > _untilMs ? nowMs + 2000 : _untilMs;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,426 +0,0 @@
|
|||
// Ported from Oracle of Dereth by Advis Eveldan (advis61), MIT. See THIRD_PARTY_NOTICES.md.
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace RynthCore.Plugin.RynthOracle.Data;
|
||||
|
||||
/// <summary>A labelled value from a server reply ("Pyreals" = "1,039,678,533 (4,158 MMDs)").</summary>
|
||||
internal sealed class NamedValue
|
||||
{
|
||||
public string Name = "";
|
||||
public string Value = "";
|
||||
}
|
||||
|
||||
/// <summary>One of ConquestAC's advanced augmentations (counts from "/augs").</summary>
|
||||
internal sealed class ConquestAug
|
||||
{
|
||||
public readonly string Name;
|
||||
public readonly int CoinCost;
|
||||
public readonly double LumBase, LumPercent;
|
||||
public int Count;
|
||||
|
||||
public ConquestAug(string name, int coinCost, double lumBase, double lumPercent)
|
||||
{
|
||||
Name = name; CoinCost = coinCost; LumBase = lumBase; LumPercent = lumPercent;
|
||||
}
|
||||
|
||||
/// <summary>The next purchase's luminance (Conquest-ACE's tiered cost, as upstream mirrors it).</summary>
|
||||
public long NextLuminanceCost()
|
||||
{
|
||||
long idx = Count;
|
||||
(double tierBase, long pos) = idx >= 65 ? (LumBase * 30.0, idx - 65)
|
||||
: idx >= 60 ? (LumBase * 12.0, idx - 60)
|
||||
: idx >= 30 ? (LumBase * 4.8, idx - 30)
|
||||
: idx >= 15 ? (LumBase * 2.4, idx - 15)
|
||||
: (LumBase, idx);
|
||||
// The server truncates to long; the epsilon keeps 6,229,499.9999 (binary floating point) at the
|
||||
// confirmed in-game 6,229,500 (Creature at 25).
|
||||
return (long)(tierBase * (1.0 + pos * LumPercent) + 1e-6);
|
||||
}
|
||||
|
||||
public string NextCostText() =>
|
||||
$"{CoinCost} coins, {(NextLuminanceCost() / 1_000_000.0).ToString("0.##", CultureInfo.InvariantCulture)}M lum";
|
||||
|
||||
private double ResistPercent()
|
||||
{
|
||||
const double MaxBonus = 0.32, LinearRate = 0.003, Tuning = 0.0034597;
|
||||
const int LinearCap = 10;
|
||||
if (Count <= 0) return 0.0;
|
||||
double bonus = Count <= LinearCap
|
||||
? Count * LinearRate
|
||||
: LinearCap * LinearRate + (MaxBonus - LinearCap * LinearRate) * (1.0 - Math.Pow(1.0 - Tuning, Count - LinearCap));
|
||||
return Math.Min(bonus, MaxBonus) * 100.0;
|
||||
}
|
||||
|
||||
/// <summary>The effect at the current count (upstream's reading of the Conquest-ACE source).</summary>
|
||||
public string Effect() => Name switch
|
||||
{
|
||||
"Creature" => $"+{Count} to creature buffs, -{Count} to debuffs",
|
||||
"Item" => $"+{Count}% attack/melee, +{Count * 0.5:0.#} blood/spirit, +{Count} AL",
|
||||
"Life" => $"+{ResistPercent():0.##}% prot, +{ResistPercent():0.##}% vuln, +{Count * 0.10:0.##} regen, +{Count / 10} surge rating",
|
||||
"War" => $"+{Count * 2}% war magic potency",
|
||||
"Void" => $"+{Count * 1.5:0.##}% void magic potency",
|
||||
"Melee" => $"+{Count} melee damage, +{Count * 1.5:0.#}% crit damage",
|
||||
"Missile" => $"+{Count} missile damage, +{Count * 1.5:0.#}% crit damage",
|
||||
"Duration" => $"+{Count * 5}% spell duration",
|
||||
"Specialization" => $"+{Count} skill spec cap (now {70 + Count})",
|
||||
_ => "",
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>A fellowship from "/fship list".</summary>
|
||||
internal sealed class ConquestFellowship
|
||||
{
|
||||
public string Name = "", Leader = "", Members = "", Location = "";
|
||||
|
||||
public int MemberCount
|
||||
{
|
||||
get
|
||||
{
|
||||
int slash = Members.IndexOf('/');
|
||||
return int.TryParse(slash >= 0 ? Members[..slash] : Members, out int n) ? n : 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>A row of a leaderboard.</summary>
|
||||
internal sealed class BoardRow
|
||||
{
|
||||
public int Rank;
|
||||
public string Name = "";
|
||||
public string Value = "";
|
||||
public string Extra = "";
|
||||
public bool IsYou;
|
||||
}
|
||||
|
||||
/// <summary>One of ConquestAC's /top boards.</summary>
|
||||
internal sealed class ConquestBoard
|
||||
{
|
||||
public readonly string Key, Label, Header;
|
||||
public readonly List<BoardRow> Rows = new();
|
||||
public BoardRow? You;
|
||||
public DateTime UpdatedUtc = DateTime.MinValue;
|
||||
|
||||
public ConquestBoard(string key, string label, string header) { Key = key; Label = label; Header = header; }
|
||||
|
||||
public string Command => "/top " + Key;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Everything ConquestAC-only (tag Conquest): bank balances and bank commands ("/b", "/bank"),
|
||||
/// advanced augmentations ("/augs"), enlightenment augmentations ("/enl augs"), the XP bonus
|
||||
/// breakdown ("/bonus"), fellowships looking for members ("/fship list"), the /top boards, and
|
||||
/// the void damage-over-time duration scaling. The plugin only feeds it chat and only shows it
|
||||
/// while the server is ConquestAC; every reply regex is anchored at the start of the line (after
|
||||
/// an optional chat timestamp), as upstream does, so a pasted copy in a chat channel can't
|
||||
/// overwrite your values.
|
||||
/// </summary>
|
||||
internal sealed class ConquestData
|
||||
{
|
||||
private const string Ts = @"^\s*(?:\[[^\]]*\][\s:]*)?";
|
||||
|
||||
// /b balances
|
||||
private static readonly Regex BankLine = new(Ts + @"\[BANK\]\s+(.+?):\s*(.*\S)\s*$");
|
||||
private static readonly Regex BankChrome = new(Ts + @"\[BANK\]\s+[^:]*:\s*$");
|
||||
private static readonly Regex EventToken = new(@"Event Tokens \[(.+?)\]");
|
||||
private static readonly Regex DepositReply = new(Ts + @"(?:No .+? (?:found|available) to deposit|Deposited\b.*)\s*$", RegexOptions.IgnoreCase);
|
||||
// /augs
|
||||
private static readonly Regex AugLine = new(Ts + @"(Creature|Item|Life|War|Void|Duration|Specialization|Melee|Missile):\s*([\d,]+)\b");
|
||||
private static readonly Regex AugChrome = new(Ts + @"(?:-{3,}|Advanced Augmentation Levels:|Use /aug info for per-level effect details\.)\s*$", RegexOptions.IgnoreCase);
|
||||
// /enl augs
|
||||
private static readonly Regex EnlLine = new(Ts + @"([A-Za-z][A-Za-z '\-]*?):\s*(([\d,]+)\s*\(\s*[\d,]+\s+max\s*\))\s*$");
|
||||
private static readonly Regex EnlChrome = new(Ts + @"Enlightenment Augmentations:\s*$");
|
||||
// /bonus
|
||||
private static readonly Regex BonusLine = new(Ts + @"(Quest|Enlightenment|PK Dungeon|Augmentation|Equipment|Total) Bonus(?:\s*\(([^)]+)\))?:\s*(.+\S)\s*$");
|
||||
private static readonly Regex BonusChrome = new(Ts + @"={2,}\s*XP Bonuses\s*={2,}\s*$");
|
||||
// /fship list
|
||||
private static readonly Regex FshipHeader = new(Ts + @"Fellowships looking for members");
|
||||
private static readonly Regex FshipLine = new(Ts + @"-\s+(.+?)\s+\(Leader:\s+(.+?)\)\s+\[(\d+/\d+)\](?:\s+@\s+(.+?))?\s*$");
|
||||
// /top
|
||||
private static readonly Regex TopHeader = new(Ts + @"Top\s+(\d+)\s+Players?\s+by\s+(.+?):\s*$");
|
||||
private static readonly Regex TopEntry = new(Ts + @"(\d+):\s+([\d,]+)\s+-\s+(.+?)\s*$");
|
||||
private static readonly Regex TopSeparator = new(Ts + @"\.\.\.\s*$");
|
||||
|
||||
private static readonly string[] EnlOrder =
|
||||
{
|
||||
"Damage", "Damage Reduction", "Crit Damage", "Crit Damage Reduction", "Imbue", "Salvage", "Skill Credits",
|
||||
"Stamina Benediction", "Mana Benediction", "Cleave", "Arrow Split", "Spell Chain", "Aetheria Surge", "Void Contagion",
|
||||
};
|
||||
private static readonly Dictionary<string, string> EnlCosts = new(StringComparer.OrdinalIgnoreCase)
|
||||
{
|
||||
["Cleave"] = "1 Pristine Token", ["Arrow Split"] = "1 Pristine Token", ["Spell Chain"] = "1 Pristine Token",
|
||||
["Aetheria Surge"] = "1 Pristine Token", ["Void Contagion"] = "1 Pristine Token",
|
||||
["Damage"] = "2 Tokens", ["Damage Reduction"] = "2 Tokens", ["Crit Damage"] = "2 Tokens",
|
||||
["Crit Damage Reduction"] = "2 Tokens", ["Imbue"] = "2 Tokens", ["Salvage"] = "2 Tokens",
|
||||
["Skill Credits"] = "4 Tokens", ["Stamina Benediction"] = "4 Tokens", ["Mana Benediction"] = "4 Tokens",
|
||||
};
|
||||
|
||||
public const int PyrealsPerMmd = 250_000;
|
||||
|
||||
public readonly List<NamedValue> Bank = new();
|
||||
public readonly List<ConquestAug> Augs = new()
|
||||
{
|
||||
new("Creature", 25, 2_500_000, 0.003825), new("Item", 100, 3_000_000, 0.006825), new("Life", 75, 2_500_000, 0.0095),
|
||||
new("War", 50, 1_750_000, 0.00425), new("Void", 50, 1_800_000, 0.00425), new("Duration", 30, 1_400_000, 0.00625),
|
||||
new("Specialization", 125, 3_000_000, 0.02), new("Melee", 50, 1_750_000, 0.00425), new("Missile", 50, 1_750_000, 0.00425),
|
||||
};
|
||||
public List<NamedValue> EnlAugs { get; private set; } = new();
|
||||
public readonly List<NamedValue> Bonuses = new()
|
||||
{
|
||||
new() { Name = "Quest" }, new() { Name = "Enlightenment" }, new() { Name = "PK Dungeon" }, new() { Name = "Augmentation" },
|
||||
new() { Name = "Equipment" }, new() { Name = "Total (Kills)" }, new() { Name = "Total (Quest/Lum)" },
|
||||
};
|
||||
public readonly List<ConquestFellowship> Fellowships = new();
|
||||
public readonly List<ConquestBoard> Boards = new()
|
||||
{
|
||||
new("augs", "Augs", "Total Augmentations"), new("deaths", "Deaths", "Deaths"), new("enl", "Enlightens", "Enlightenment"),
|
||||
new("level", "Levels", "Level"), new("lum", "Luminance", "Banked Luminance"), new("bank", "Pyreals", "Banked Pyreals"),
|
||||
new("qb", "QB", "Quest Bonus"), new("titles", "Titles", "Titles"),
|
||||
};
|
||||
|
||||
public DateTime BankUtc = DateTime.MinValue, AugsUtc = DateTime.MinValue, EnlUtc = DateTime.MinValue,
|
||||
BonusUtc = DateTime.MinValue, FshipUtc = DateTime.MinValue;
|
||||
public int Revision { get; private set; }
|
||||
|
||||
private readonly ChatRequest _bankReq = new(), _augReq = new(), _enlReq = new(), _bonusReq = new(), _fshipReq = new(),
|
||||
_topReq = new(), _depositReq = new();
|
||||
private ConquestBoard? _collecting;
|
||||
private long _collectingMs;
|
||||
private int _collectingExpected = int.MaxValue;
|
||||
private bool _collectingCleared;
|
||||
|
||||
public static string EnlCost(string name) => EnlCosts.TryGetValue(name, out string? c) ? c : "";
|
||||
|
||||
public int AugTotal => Augs.Sum(a => a.Count);
|
||||
public int DurationAugs => Augs.First(a => a.Name == "Duration").Count;
|
||||
|
||||
public void Clear()
|
||||
{
|
||||
Bank.Clear();
|
||||
foreach (ConquestAug a in Augs) a.Count = 0;
|
||||
EnlAugs = new List<NamedValue>();
|
||||
foreach (NamedValue b in Bonuses) b.Value = "";
|
||||
Fellowships.Clear();
|
||||
foreach (ConquestBoard b in Boards) { b.Rows.Clear(); b.You = null; b.UpdatedUtc = DateTime.MinValue; }
|
||||
BankUtc = AugsUtc = EnlUtc = BonusUtc = FshipUtc = DateTime.MinValue;
|
||||
_collecting = null;
|
||||
Revision++;
|
||||
}
|
||||
|
||||
// ── Requests (the plugin sends the command; each returns the command text) ──
|
||||
|
||||
public string RequestBank(long now) { _bankReq.Sent(now); return "/b"; }
|
||||
public string RequestAugs(long now) { _augReq.Sent(now); return "/augs"; }
|
||||
public string RequestEnl(long now) { _enlReq.Sent(now); return "/enl augs"; }
|
||||
public string RequestBonus(long now) { _bonusReq.Sent(now); return "/bonus"; }
|
||||
public string RequestFships(long now) { _fshipReq.Sent(now); Fellowships.Clear(); Revision++; return "/fship list"; }
|
||||
|
||||
public string RequestBoard(ConquestBoard board, long now)
|
||||
{
|
||||
_topReq.Sent(now);
|
||||
Open(board, now);
|
||||
return "/top " + board.Key;
|
||||
}
|
||||
|
||||
/// <summary>An automatic deposit: its reply is ours to hide.</summary>
|
||||
public string AutoDeposit(long now) { _depositReq.Sent(now); return "/bank deposit"; }
|
||||
|
||||
/// <summary>
|
||||
/// A chat line: true when it was a reply this module reads; <paramref name="ours"/> = it
|
||||
/// answers a request RynthOracle sent (eligible to be hidden).
|
||||
/// </summary>
|
||||
public bool OnChatLine(string text, long now, out bool ours)
|
||||
{
|
||||
ours = false;
|
||||
Match m;
|
||||
|
||||
if (_depositReq.Awaiting(now) && DepositReply.IsMatch(text)) { ours = true; _depositReq.Extend(now); return true; }
|
||||
|
||||
if ((m = BankLine.Match(text)).Success)
|
||||
{
|
||||
string name = EventToken.Replace(m.Groups[1].Value.Trim(), "$1");
|
||||
string value = m.Groups[2].Value.Trim();
|
||||
if (name == "Pyreals" && long.TryParse(value.Replace(",", ""), out long py))
|
||||
value += $" ({(py / PyrealsPerMmd).ToString("N0", CultureInfo.InvariantCulture)} MMDs)";
|
||||
NamedValue? e = Bank.FirstOrDefault(b => b.Name == name);
|
||||
if (e != null) e.Value = value; else Bank.Add(new NamedValue { Name = name, Value = value });
|
||||
BankUtc = DateTime.UtcNow;
|
||||
return Done(_bankReq, now, out ours);
|
||||
}
|
||||
if (_bankReq.Awaiting(now) && BankChrome.IsMatch(text)) return Done(_bankReq, now, out ours);
|
||||
|
||||
if ((m = AugLine.Match(text)).Success)
|
||||
{
|
||||
ConquestAug? a = Augs.FirstOrDefault(x => x.Name == m.Groups[1].Value);
|
||||
if (a != null && int.TryParse(m.Groups[2].Value.Replace(",", ""), out int c)) a.Count = c;
|
||||
AugsUtc = DateTime.UtcNow;
|
||||
return Done(_augReq, now, out ours);
|
||||
}
|
||||
if (_augReq.Awaiting(now) && AugChrome.IsMatch(text)) return Done(_augReq, now, out ours);
|
||||
|
||||
if (EnlChrome.IsMatch(text))
|
||||
{
|
||||
EnlAugs = new List<NamedValue>();
|
||||
return Done(_enlReq, now, out ours);
|
||||
}
|
||||
if ((m = EnlLine.Match(text)).Success)
|
||||
{
|
||||
// "Label: N (M max)" is specific to the "/enl augs" reply (its header starts a fresh list).
|
||||
string name = m.Groups[1].Value.Trim();
|
||||
var list = new List<NamedValue>(EnlAugs.Where(x => x.Name != name)) { new() { Name = name, Value = m.Groups[2].Value.Trim() } };
|
||||
list.Sort((x, y) => Rank(x.Name).CompareTo(Rank(y.Name)));
|
||||
EnlAugs = list;
|
||||
EnlUtc = DateTime.UtcNow;
|
||||
return Done(_enlReq, now, out ours);
|
||||
}
|
||||
|
||||
if ((m = BonusLine.Match(text)).Success)
|
||||
{
|
||||
string q = m.Groups[2].Value.Trim();
|
||||
string name = q.Length > 0 ? $"{m.Groups[1].Value} ({q})" : m.Groups[1].Value;
|
||||
NamedValue? b = Bonuses.FirstOrDefault(x => x.Name == name);
|
||||
if (b != null) b.Value = m.Groups[3].Value.Trim();
|
||||
BonusUtc = DateTime.UtcNow;
|
||||
return Done(_bonusReq, now, out ours);
|
||||
}
|
||||
if (_bonusReq.Awaiting(now) && BonusChrome.IsMatch(text)) return Done(_bonusReq, now, out ours);
|
||||
|
||||
if (FshipHeader.IsMatch(text))
|
||||
{
|
||||
if (!_fshipReq.Awaiting(now)) Fellowships.Clear();
|
||||
FshipUtc = DateTime.UtcNow;
|
||||
return Done(_fshipReq, now, out ours);
|
||||
}
|
||||
if ((m = FshipLine.Match(text)).Success)
|
||||
{
|
||||
Fellowships.Add(new ConquestFellowship
|
||||
{
|
||||
Name = m.Groups[1].Value.Trim(), Leader = m.Groups[2].Value.Trim(), Members = m.Groups[3].Value.Trim(),
|
||||
Location = m.Groups[4].Success ? m.Groups[4].Value.Trim() : "",
|
||||
});
|
||||
FshipUtc = DateTime.UtcNow;
|
||||
return Done(_fshipReq, now, out ours);
|
||||
}
|
||||
|
||||
if ((m = TopHeader.Match(text)).Success)
|
||||
{
|
||||
ConquestBoard? board = Active(now) ?? Boards.FirstOrDefault(b => b.Header.Equals(m.Groups[2].Value.Trim(), StringComparison.OrdinalIgnoreCase));
|
||||
if (board == null) return false;
|
||||
Open(board, now);
|
||||
ClearOnce();
|
||||
_collectingExpected = int.TryParse(m.Groups[1].Value, out int n) ? n : int.MaxValue;
|
||||
return Done(_topReq, now, out ours);
|
||||
}
|
||||
if ((m = TopEntry.Match(text)).Success && Active(now) is ConquestBoard cb)
|
||||
{
|
||||
ClearOnce();
|
||||
int.TryParse(m.Groups[1].Value, out int rank);
|
||||
string name = m.Groups[3].Value.Trim();
|
||||
var row = new BoardRow { Rank = rank, Value = m.Groups[2].Value.Trim(), Name = name };
|
||||
if (name.EndsWith("(You)", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
row.IsYou = true;
|
||||
row.Name = name[..^5].Trim();
|
||||
cb.You = row;
|
||||
}
|
||||
if (rank <= _collectingExpected && cb.Rows.All(r => r.Rank != rank)) cb.Rows.Add(row);
|
||||
cb.Rows.Sort((x, y) => x.Rank.CompareTo(y.Rank));
|
||||
cb.UpdatedUtc = DateTime.UtcNow;
|
||||
_collectingMs = now;
|
||||
return Done(_topReq, now, out ours);
|
||||
}
|
||||
if (Active(now) != null && TopSeparator.IsMatch(text)) return Done(_topReq, now, out ours);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private bool Done(ChatRequest req, long now, out bool ours)
|
||||
{
|
||||
ours = req.Awaiting(now);
|
||||
req.Extend(now);
|
||||
Revision++;
|
||||
return true;
|
||||
}
|
||||
|
||||
private static int Rank(string name)
|
||||
{
|
||||
int i = Array.FindIndex(EnlOrder, n => n.Equals(name, StringComparison.OrdinalIgnoreCase));
|
||||
return i < 0 ? EnlOrder.Length : i;
|
||||
}
|
||||
|
||||
private void Open(ConquestBoard board, long now)
|
||||
{
|
||||
if (_collecting == board && now - _collectingMs < 15_000) return;
|
||||
_collecting = board;
|
||||
_collectingMs = now;
|
||||
_collectingExpected = int.MaxValue;
|
||||
_collectingCleared = false;
|
||||
}
|
||||
|
||||
private ConquestBoard? Active(long now) => _collecting != null && now - _collectingMs < 15_000 ? _collecting : null;
|
||||
|
||||
private void ClearOnce()
|
||||
{
|
||||
if (_collectingCleared || _collecting == null) return;
|
||||
_collecting.Rows.Clear();
|
||||
_collecting.You = null;
|
||||
_collectingCleared = true;
|
||||
}
|
||||
|
||||
// ── Bank commands (Conquest-ACE's /bank; tokens are its one-letter currency codes) ──
|
||||
|
||||
public sealed record Currency(string Label, string Token, long Multiplier = 1, long Max = long.MaxValue);
|
||||
|
||||
public static readonly Currency[] Withdrawable =
|
||||
{
|
||||
new("Conquest Coins", "c"), new("Event Tokens", "e"), new("Legendary Keys", "k"), new("Pyreals", "p"),
|
||||
new("Soul Fragments", "s"), new("MMD Notes (250k)", "n"), new("MM Notes (200k)", "n MM"), new("M Notes (100k)", "n M"),
|
||||
new("D Notes (50k)", "n D"), new("C Notes (10k)", "n C"), new("L Notes (5k)", "n L"), new("X Notes (1k)", "n X"),
|
||||
new("V Notes (500)", "n V"), new("I Notes (100)", "n I"),
|
||||
};
|
||||
public const int DefaultWithdraw = 5; // MMD notes
|
||||
|
||||
public static readonly Currency[] Transferable =
|
||||
{
|
||||
new("Legendary Keys", "k"), new("Luminance", "l"), new("MMD Notes (250k)", "p", 250_000, 1_000), new("Pyreals", "p"),
|
||||
};
|
||||
public const int DefaultTransfer = 1; // Luminance
|
||||
|
||||
/// <summary>"/bank withdraw <token> <n>", or null when the amount isn't a whole number above 0.</summary>
|
||||
public static string? WithdrawCommand(Currency c, string amount) =>
|
||||
long.TryParse((amount ?? "").Replace(",", "").Trim(), out long n) && n > 0 ? $"/bank withdraw {c.Token} {n}" : null;
|
||||
|
||||
/// <summary>"/bank transfer <token> <n> "name"", or null when the amount or name isn't usable.</summary>
|
||||
public static string? TransferCommand(Currency c, string amount, string target)
|
||||
{
|
||||
target = (target ?? "").Trim().Replace("\"", "");
|
||||
if (target.Length == 0 || !long.TryParse((amount ?? "").Replace(",", "").Trim(), out long n) || n <= 0 || n > c.Max) return null;
|
||||
try { return $"/bank transfer {c.Token} {checked(n * c.Multiplier)} \"{target}\""; }
|
||||
catch (OverflowException) { return null; }
|
||||
}
|
||||
|
||||
// ── Levels and enlightenment (ConquestAC's levels 276-300, upstream's table) ──
|
||||
|
||||
private static readonly long[] Levels276To300 =
|
||||
{
|
||||
194665023377, 198152685223, 201689992550, 205277652043, 208916380445,
|
||||
212606904701, 216349962105, 220146300445, 223996678153, 227901864460,
|
||||
231862639544, 235879794689, 239954132442, 244086466776, 248277623248,
|
||||
252528439169, 256839763767, 261212458359, 265647396522, 270145464270,
|
||||
274707560226, 279334595807, 284027495403, 288787196561, 293614650176,
|
||||
};
|
||||
public const int MaxLevel = 300;
|
||||
|
||||
/// <summary>Total XP to reach a level 276-300 (0 otherwise).</summary>
|
||||
public static long XpForLevel(int level) => level >= 276 && level <= 300 ? Levels276To300[level - 276] : 0;
|
||||
|
||||
private static double EnlMultiplier(int target) => target >= 75 ? 7.5 : target >= 50 ? 5.0 : target >= 25 ? 2.5 : 1.0;
|
||||
public static long EnlCoinCost(int target) => (long)(target * 100 * EnlMultiplier(target));
|
||||
public static long EnlLuminanceCost(int target) => (long)(target * 1_000_000L * EnlMultiplier(target));
|
||||
|
||||
/// <summary>Void DoT duration on ConquestAC: × (1 + Archmage's Endurance × 0.2 + Duration augs × 0.05).</summary>
|
||||
public double VoidDurationMultiplier(int archmagesEndurance) => 1.0 + archmagesEndurance * 0.2 + DurationAugs * 0.05;
|
||||
}
|
||||
|
|
@ -1,59 +0,0 @@
|
|||
// Ported from Oracle of Dereth by Advis Eveldan (advis61), MIT. See THIRD_PARTY_NOTICES.md.
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
|
||||
namespace RynthCore.Plugin.RynthOracle.Data;
|
||||
|
||||
/// <summary>
|
||||
/// A server's custom quest worklist (customquests.csv: Server, Name, QuestFlag, Url, Hint). Each
|
||||
/// row carries its server tag, so only the current server's rows show (today: ConquestAC's).
|
||||
/// A repeatable counts as done only while on cooldown (upstream's rule).
|
||||
/// </summary>
|
||||
internal sealed class CustomQuest
|
||||
{
|
||||
public string Server = "", Name = "", Flag = "", Url = "", Hint = "";
|
||||
|
||||
public bool IsComplete(QuestFlagStore flags, DateTime utcNow)
|
||||
{
|
||||
if (!flags.TryGet(Flag, out QuestFlag q)) return false;
|
||||
if (q.RepeatTime == TimeSpan.Zero) return q.Solves > 0;
|
||||
return !q.Ready(utcNow);
|
||||
}
|
||||
|
||||
public string Status(QuestFlagStore flags, DateTime utcNow)
|
||||
{
|
||||
if (!flags.TryGet(Flag, out QuestFlag q)) return "ready";
|
||||
if (q.RepeatTime == TimeSpan.Zero) return q.Solves > 0 ? "completed" : "ready";
|
||||
return q.NextAvailable(utcNow);
|
||||
}
|
||||
}
|
||||
|
||||
internal static class CustomQuestList
|
||||
{
|
||||
public static List<CustomQuest> All { get; } = Load();
|
||||
|
||||
public static IEnumerable<CustomQuest> For(ServerIdentity server)
|
||||
{
|
||||
foreach (CustomQuest q in All)
|
||||
if (server.Is(q.Server)) yield return q;
|
||||
}
|
||||
|
||||
private static List<CustomQuest> Load()
|
||||
{
|
||||
var list = new List<CustomQuest>();
|
||||
using StreamReader r = Csv.OpenEmbedded("customquests.csv");
|
||||
r.ReadLine(); // Server,Name,QuestFlag,Url,Hint
|
||||
while (r.ReadLine() is string line)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(line)) continue;
|
||||
string[] f = Csv.ParseLine(line);
|
||||
list.Add(new CustomQuest
|
||||
{
|
||||
Server = Csv.Field(f, 0), Name = Csv.Field(f, 1), Flag = Csv.Field(f, 2).ToLowerInvariant(),
|
||||
Url = Csv.Field(f, 3), Hint = Csv.Field(f, 4),
|
||||
});
|
||||
}
|
||||
return list;
|
||||
}
|
||||
}
|
||||
170
Plugins/RynthCore.Plugin.RynthOracle/Data/DynamicStamps.cs
Normal file
170
Plugins/RynthCore.Plugin.RynthOracle/Data/DynamicStamps.cs
Normal file
|
|
@ -0,0 +1,170 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
|
||||
namespace RynthCore.Plugin.RynthOracle.Data;
|
||||
|
||||
/// <summary>
|
||||
/// One Infinite Leaftide Dynamic Stamp (dynstamps.csv): an NPC hand-in that puts a
|
||||
/// "Dynamic_N_..." quest flag on the character. List from the players' "ExtraDyn" sheet
|
||||
/// (10.13.2026, one sheet per area, the wiki's Dynamic Stamps page); NPCs that give no stamp
|
||||
/// are left out. A stamp is a one-time flag: having it in /myquests means it's done.
|
||||
/// </summary>
|
||||
internal sealed class DynamicStamp
|
||||
{
|
||||
public string Area = "";
|
||||
/// <summary>Where in the area (a town, a dungeon, coordinates), or "".</summary>
|
||||
public string Place = "";
|
||||
public string Npc = "";
|
||||
/// <summary>What the NPC gives back (the sheet's "X gives you Y"), or "".</summary>
|
||||
public string Reward = "";
|
||||
/// <summary>The quest flag, lower case (as QuestFlagStore keys it).</summary>
|
||||
public string Stamp = "";
|
||||
public string Note = "";
|
||||
|
||||
/// <summary>The NPC, else the place (a few sheet rows only name the spot).</summary>
|
||||
public string Label => Npc.Length > 0 ? Npc : Place;
|
||||
|
||||
/// <summary>
|
||||
/// The flag this character has for the stamp, or null. The sheet has a few stamps copied
|
||||
/// without their closing "!" or cut short: those also match with "!" added and, when at
|
||||
/// least <see cref="MinPrefixLength"/> long, the one Dynamic flag on the character starting
|
||||
/// with them.
|
||||
/// </summary>
|
||||
public string? MatchedFlag(QuestFlagStore flags)
|
||||
{
|
||||
if (flags.TryGet(Stamp, out _)) return Stamp;
|
||||
if (Stamp.EndsWith('!')) return null;
|
||||
if (flags.TryGet(Stamp + "!", out _)) return Stamp + "!";
|
||||
if (Stamp.Length < MinPrefixLength) return null;
|
||||
string? only = null;
|
||||
foreach (string key in flags.Flags.Keys)
|
||||
{
|
||||
if (!key.StartsWith(Stamp, StringComparison.OrdinalIgnoreCase)) continue;
|
||||
if (only != null) return null; // more than one: can't tell which
|
||||
only = key;
|
||||
}
|
||||
return only;
|
||||
}
|
||||
|
||||
public bool Have(QuestFlagStore flags) => MatchedFlag(flags) != null;
|
||||
|
||||
// Sheet areas that are groupings, not places on the map.
|
||||
private static readonly HashSet<string> NotPlaces = new(StringComparer.OrdinalIgnoreCase)
|
||||
{
|
||||
"Looking Around", "Odd Stamps", "Odd Stamps 2",
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Where RynthNav should go for this stamp, best first (RynthNav takes the first that is on its
|
||||
/// map): the coordinates in the note or the place, the place and its parts ("Mhoire Castle -
|
||||
/// Great Hall" also tries "Mhoire Castle"), the NPC, then the area. Empty when there is nothing.
|
||||
/// </summary>
|
||||
public List<string> NavCandidates()
|
||||
{
|
||||
var list = new List<string>();
|
||||
void Add(string s)
|
||||
{
|
||||
s = s.Trim().Trim('.', ',', ';', ':').Trim();
|
||||
if (s.Length >= 4 && !char.IsDigit(s[0]) && !list.Contains(s, StringComparer.OrdinalIgnoreCase)) list.Add(s);
|
||||
}
|
||||
|
||||
foreach (string text in new[] { Note, Place })
|
||||
if (NavTargets.FirstCoords(text) is string c && !list.Contains(c)) list.Add(c);
|
||||
|
||||
string place = NavTargets.WithoutCoords(Place);
|
||||
place = System.Text.RegularExpressions.Regex.Replace(place, @"\b(at|in the|nearby)\b", " ", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
|
||||
place = System.Text.RegularExpressions.Regex.Replace(place, @"\s+", " ").Trim();
|
||||
Add(place);
|
||||
foreach (string part in place.Split(new[] { " - ", " / ", "(", ")" }, StringSplitOptions.RemoveEmptyEntries))
|
||||
Add(part);
|
||||
Add(Npc);
|
||||
if (!NotPlaces.Contains(Area)) Add(Area);
|
||||
return list;
|
||||
}
|
||||
|
||||
/// <summary>A truncated stamp shorter than this is matched exactly only (too many flags share a short stem).</summary>
|
||||
public const int MinPrefixLength = 14;
|
||||
}
|
||||
|
||||
internal static class DynamicStampList
|
||||
{
|
||||
/// <summary>Dynamic stamp quest flags start with this (lower case).</summary>
|
||||
public const string FlagPrefix = "dynamic_";
|
||||
|
||||
public static List<DynamicStamp> All { get; } = Load();
|
||||
|
||||
/// <summary>The areas in list order (Facility Hub, Looking Around, ...).</summary>
|
||||
public static List<string> Areas { get; } = BuildAreas();
|
||||
|
||||
/// <summary>
|
||||
/// Dynamic stamps on this character that the list doesn't have (new or unlisted NPCs), so the
|
||||
/// tab can show them and the count isn't only what the sheet knows.
|
||||
/// </summary>
|
||||
public static List<string> Unlisted(QuestFlagStore flags)
|
||||
{
|
||||
var matched = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
|
||||
foreach (DynamicStamp s in All)
|
||||
if (s.MatchedFlag(flags) is string f) matched.Add(f);
|
||||
var extra = new List<string>();
|
||||
foreach (string key in flags.Flags.Keys)
|
||||
if (key.StartsWith(FlagPrefix, StringComparison.OrdinalIgnoreCase) && !matched.Contains(key))
|
||||
extra.Add(key);
|
||||
extra.Sort(StringComparer.OrdinalIgnoreCase);
|
||||
return extra;
|
||||
}
|
||||
|
||||
private static List<DynamicStamp> Load()
|
||||
{
|
||||
try
|
||||
{
|
||||
using StreamReader r = Csv.OpenEmbedded("dynstamps.csv");
|
||||
return Parse(r);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
// A missing or unreadable list must not take the Quests page down with it.
|
||||
return new List<DynamicStamp>();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads a dynstamps.csv (a header row, then one NPC hand-in a row). A row whose stamp isn't a
|
||||
/// "dynamic_" flag, or repeats one already read, is skipped; a missing column reads as empty.
|
||||
/// Internal for the tests.
|
||||
/// </summary>
|
||||
internal static List<DynamicStamp> Parse(TextReader r)
|
||||
{
|
||||
var list = new List<DynamicStamp>();
|
||||
Dictionary<string, int> col = Csv.MapColumns(r.ReadLine() ?? "");
|
||||
int cArea = Csv.Column(col, "Area"), cPlace = Csv.Column(col, "Place"), cNpc = Csv.Column(col, "Npc"),
|
||||
cReward = Csv.Column(col, "Reward"), cStamp = Csv.Column(col, "Stamp"), cNote = Csv.Column(col, "Note");
|
||||
var seen = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
|
||||
while (r.ReadLine() is string line)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(line)) continue;
|
||||
string[] f = Csv.ParseLine(line);
|
||||
string stamp = Csv.Field(f, cStamp).Trim().ToLowerInvariant();
|
||||
if (!stamp.StartsWith(FlagPrefix, StringComparison.Ordinal) || !seen.Add(stamp)) continue;
|
||||
list.Add(new DynamicStamp
|
||||
{
|
||||
Area = Csv.Field(f, cArea),
|
||||
Place = Csv.Field(f, cPlace),
|
||||
Npc = Csv.Field(f, cNpc),
|
||||
Reward = Csv.Field(f, cReward),
|
||||
Stamp = stamp,
|
||||
Note = Csv.Field(f, cNote),
|
||||
});
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
private static List<string> BuildAreas()
|
||||
{
|
||||
var areas = new List<string>();
|
||||
foreach (DynamicStamp s in All)
|
||||
if (!areas.Contains(s.Area)) areas.Add(s.Area);
|
||||
return areas;
|
||||
}
|
||||
}
|
||||
232
Plugins/RynthCore.Plugin.RynthOracle/Data/IltServerProfile.cs
Normal file
232
Plugins/RynthCore.Plugin.RynthOracle/Data/IltServerProfile.cs
Normal file
|
|
@ -0,0 +1,232 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
using RynthCore.Plugin.Shared;
|
||||
using RynthCore.PluginSdk;
|
||||
|
||||
namespace RynthCore.Plugin.RynthOracle.Data;
|
||||
|
||||
/// <summary>One Leaftide feature from RynthILT's profile: its state on this server and where it lives.</summary>
|
||||
internal sealed record IltFeature(string Key, string Label, string Group, int State, string Where);
|
||||
|
||||
/// <summary>
|
||||
/// The ACECustom quest bonus list ("/qb list") as RynthILT last read it (the profile's "questBonus"
|
||||
/// object). <see cref="Generation"/> 0 = not loaded this session; <see cref="Count"/> -1 = unknown.
|
||||
/// </summary>
|
||||
internal sealed record IltQuestBonusList(bool Disabled, int Generation, long Count, string Status,
|
||||
IReadOnlyList<string> Completed, IReadOnlyList<string> Incomplete);
|
||||
|
||||
/// <summary>
|
||||
/// What RynthILT reports about the Infinite Leaftide server (the "RynthILT.Server" profile JSON,
|
||||
/// Plugins/Shared/RynthIltServerApi.cs): whether this is an ILT world, the Leaftide features with
|
||||
/// their server state, and the fellowship rules. <see cref="None"/> without RynthILT; every field is
|
||||
/// read leniently so an older or newer RynthILT still parses.
|
||||
/// </summary>
|
||||
internal sealed class IltServerProfile
|
||||
{
|
||||
/// <summary>No RynthILT (or nothing parsed): a retail fellowship and no features.</summary>
|
||||
public static readonly IltServerProfile None = new();
|
||||
|
||||
/// <summary>RynthILT answered with a profile.</summary>
|
||||
public bool Available { get; private init; }
|
||||
public bool Ilt { get; private init; }
|
||||
public string World { get; private init; } = "";
|
||||
public bool Forced { get; private init; }
|
||||
public string Source { get; private init; } = "";
|
||||
/// <summary>Last server-options check (UTC); MinValue = never.</summary>
|
||||
public DateTime CheckedUtc { get; private init; } = DateTime.MinValue;
|
||||
public IReadOnlyList<IltFeature> Features { get; private init; } = Array.Empty<IltFeature>();
|
||||
|
||||
/// <summary>The server's fellowship size limit (retail 9 without RynthILT or off ILT).</summary>
|
||||
public int FellowshipMax { get; private init; } = RynthIltServer.RetailFellowshipMax;
|
||||
/// <summary>Fellowship feature states (RynthIltServer.State*): Zone Share, Fellowship Blackjack, luminance share.</summary>
|
||||
public int ZoneShare { get; private init; } = RynthIltServer.StateUnknown;
|
||||
public int Blackjack { get; private init; } = RynthIltServer.StateUnknown;
|
||||
public int LuminanceShare { get; private init; } = RynthIltServer.StateUnknown;
|
||||
|
||||
/// <summary>The /qb list (ILT worlds with RynthILT 0.2.3 or later); null = none offered.</summary>
|
||||
public IltQuestBonusList? QuestBonus { get; private init; }
|
||||
|
||||
/// <summary>The features in one group, in RynthILT's order.</summary>
|
||||
public IEnumerable<IltFeature> InGroup(string group)
|
||||
{
|
||||
foreach (IltFeature f in Features)
|
||||
if (string.Equals(f.Group, group, StringComparison.OrdinalIgnoreCase)) yield return f;
|
||||
}
|
||||
|
||||
/// <summary>Parses the profile JSON; <see cref="None"/> when it is empty or not JSON.</summary>
|
||||
public static IltServerProfile Parse(string? json)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(json)) return None;
|
||||
try
|
||||
{
|
||||
using JsonDocument doc = JsonDocument.Parse(json);
|
||||
JsonElement root = doc.RootElement;
|
||||
if (root.ValueKind != JsonValueKind.Object) return None;
|
||||
|
||||
var features = new List<IltFeature>();
|
||||
if (root.TryGetProperty("features", out JsonElement fs) && fs.ValueKind == JsonValueKind.Array)
|
||||
{
|
||||
foreach (JsonElement f in fs.EnumerateArray())
|
||||
{
|
||||
if (f.ValueKind != JsonValueKind.Object) continue;
|
||||
string key = Str(f, "key");
|
||||
if (key.Length == 0) continue;
|
||||
string label = Str(f, "label");
|
||||
features.Add(new IltFeature(key, label.Length > 0 ? label : key, Str(f, "group"),
|
||||
Int(f, "state", RynthIltServer.StateUnknown), Str(f, "where")));
|
||||
}
|
||||
}
|
||||
|
||||
bool ilt = Bool(root, "ilt");
|
||||
int max = RynthIltServer.RetailFellowshipMax;
|
||||
int zone = RynthIltServer.StateUnknown, bj = RynthIltServer.StateUnknown, lum = RynthIltServer.StateUnknown;
|
||||
if (root.TryGetProperty("fellowship", out JsonElement fel) && fel.ValueKind == JsonValueKind.Object)
|
||||
{
|
||||
max = Int(fel, "maxMembers", max);
|
||||
zone = Int(fel, "zoneShare", zone);
|
||||
bj = Int(fel, "blackjack", bj);
|
||||
lum = Int(fel, "luminanceShare", lum);
|
||||
}
|
||||
// A bogus size would let the tab claim room nobody has; stay within what the reader handles.
|
||||
if (max < 1 || max > 64) max = RynthIltServer.RetailFellowshipMax;
|
||||
|
||||
DateTime checkedUtc = DateTime.MinValue;
|
||||
string when = Str(root, "checked");
|
||||
if (when.Length > 0
|
||||
&& DateTime.TryParse(when, CultureInfo.InvariantCulture, DateTimeStyles.AdjustToUniversal | DateTimeStyles.AssumeUniversal, out DateTime t))
|
||||
checkedUtc = t;
|
||||
|
||||
return new IltServerProfile
|
||||
{
|
||||
Available = true,
|
||||
Ilt = ilt,
|
||||
World = Str(root, "world"),
|
||||
Forced = Bool(root, "forced"),
|
||||
Source = Str(root, "source"),
|
||||
CheckedUtc = checkedUtc,
|
||||
Features = features,
|
||||
FellowshipMax = max,
|
||||
ZoneShare = zone,
|
||||
Blackjack = bj,
|
||||
LuminanceShare = lum,
|
||||
QuestBonus = ParseQuestBonus(root),
|
||||
};
|
||||
}
|
||||
catch (JsonException)
|
||||
{
|
||||
return None;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>The "questBonus" object, or null when the profile has none.</summary>
|
||||
private static IltQuestBonusList? ParseQuestBonus(JsonElement root)
|
||||
{
|
||||
if (!root.TryGetProperty("questBonus", out JsonElement q) || q.ValueKind != JsonValueKind.Object) return null;
|
||||
long count = q.TryGetProperty("count", out JsonElement c) && c.ValueKind == JsonValueKind.Number && c.TryGetInt64(out long n) ? n : -1;
|
||||
return new IltQuestBonusList(Bool(q, "disabled"), Int(q, "generation", 0), count, Str(q, "status"),
|
||||
Strings(q, "completed"), Strings(q, "incomplete"));
|
||||
}
|
||||
|
||||
private static string[] Strings(JsonElement o, string name)
|
||||
{
|
||||
if (!o.TryGetProperty(name, out JsonElement a) || a.ValueKind != JsonValueKind.Array) return Array.Empty<string>();
|
||||
var list = new List<string>(a.GetArrayLength());
|
||||
foreach (JsonElement e in a.EnumerateArray())
|
||||
if (e.ValueKind == JsonValueKind.String && e.GetString() is { Length: > 0 } s) list.Add(s);
|
||||
return list.ToArray();
|
||||
}
|
||||
|
||||
/// <summary>"on", "off" or "checking" for a feature state.</summary>
|
||||
public static string StateText(int state) => state switch
|
||||
{
|
||||
RynthIltServer.StateOn => "on",
|
||||
RynthIltServer.StateOff => "off",
|
||||
_ => "checking",
|
||||
};
|
||||
|
||||
private static string Str(JsonElement o, string name) =>
|
||||
o.TryGetProperty(name, out JsonElement v) && v.ValueKind == JsonValueKind.String ? v.GetString() ?? "" : "";
|
||||
|
||||
private static bool Bool(JsonElement o, string name) =>
|
||||
o.TryGetProperty(name, out JsonElement v) && v.ValueKind == JsonValueKind.True;
|
||||
|
||||
private static int Int(JsonElement o, string name, int fallback) =>
|
||||
o.TryGetProperty(name, out JsonElement v) && v.ValueKind == JsonValueKind.Number && v.TryGetInt32(out int i) ? i : fallback;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads RynthILT's "RynthILT.Server" interface on the plugin pump. Looks the table up through the
|
||||
/// host (re-checked while RynthILT is missing or after it unloads, Version 0) and copies the JSON
|
||||
/// out every <see cref="PollMs"/>; <see cref="Revision"/> goes up when the profile changes.
|
||||
/// </summary>
|
||||
internal sealed unsafe class IltServerLink
|
||||
{
|
||||
private const long PollMs = 2000;
|
||||
private const long RequeryMs = 10_000;
|
||||
// Room for the /qb list (hundreds of flags) on top of the features.
|
||||
private const int MaxBuffer = 512 * 1024;
|
||||
|
||||
private RynthIltServerApiV1* _table;
|
||||
private long _nextPollAt, _nextQueryAt;
|
||||
private byte[] _buffer = new byte[8192];
|
||||
private string _lastJson = "";
|
||||
|
||||
public IltServerProfile Profile { get; private set; } = IltServerProfile.None;
|
||||
public int Revision { get; private set; }
|
||||
|
||||
/// <summary>Forget the profile (logout); the next poll reads it again.</summary>
|
||||
public void Clear()
|
||||
{
|
||||
_nextPollAt = 0;
|
||||
SetJson("");
|
||||
}
|
||||
|
||||
/// <summary>Pump thread. Cheap when not due.</summary>
|
||||
public void Poll(RynthCoreHost host, long now)
|
||||
{
|
||||
if (now < _nextPollAt) return;
|
||||
_nextPollAt = now + PollMs;
|
||||
RynthIltServerApiV1* t = Table(host, now);
|
||||
SetJson(t == null ? "" : Read(t));
|
||||
}
|
||||
|
||||
/// <summary>The table, re-queried when it is missing or RynthILT has shut down (Version 0).</summary>
|
||||
private RynthIltServerApiV1* Table(RynthCoreHost host, long now)
|
||||
{
|
||||
if (_table != null && _table->Version >= 1) return _table;
|
||||
_table = null;
|
||||
if (now < _nextQueryAt || !host.HasGetPluginInterface) return null;
|
||||
_nextQueryAt = now + RequeryMs;
|
||||
var p = (RynthIltServerApiV1*)host.GetPluginInterface(RynthIltServer.PluginName, RynthIltServerApiV1.InterfaceName, RynthIltServerApiV1.InterfaceVersion);
|
||||
if (p != null && p->Version >= 1 && p->StructSize >= (uint)sizeof(RynthIltServerApiV1) && p->GetProfileJson != null)
|
||||
_table = p;
|
||||
return _table;
|
||||
}
|
||||
|
||||
/// <summary>Copies the JSON out, growing the buffer once when RynthILT says it didn't fit.</summary>
|
||||
private string Read(RynthIltServerApiV1* t)
|
||||
{
|
||||
for (int attempt = 0; attempt < 2; attempt++)
|
||||
{
|
||||
int len;
|
||||
fixed (byte* b = _buffer) len = t->GetProfileJson(b, _buffer.Length);
|
||||
if (len <= 0) return "";
|
||||
if (len < _buffer.Length) return Encoding.UTF8.GetString(_buffer, 0, len);
|
||||
if (len + 1 > MaxBuffer) return "";
|
||||
_buffer = new byte[len + 1024];
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
/// <summary>Takes a profile JSON (internal: the tests feed one without RynthILT).</summary>
|
||||
internal void SetJson(string json)
|
||||
{
|
||||
if (json == _lastJson) return;
|
||||
_lastJson = json;
|
||||
Profile = IltServerProfile.Parse(json);
|
||||
Revision++;
|
||||
}
|
||||
}
|
||||
135
Plugins/RynthCore.Plugin.RynthOracle/Data/Legendary.cs
Normal file
135
Plugins/RynthCore.Plugin.RynthOracle/Data/Legendary.cs
Normal file
|
|
@ -0,0 +1,135 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
|
||||
namespace RynthCore.Plugin.RynthOracle.Data;
|
||||
|
||||
/// <summary>
|
||||
/// One Legendary Key quest (legendary.csv; list and notes from the "Arwic John Route" sheet).
|
||||
/// The quest's own /myquests flags say whether it was ever done and when it can be run again:
|
||||
/// the first flag is its completion stamp, any others only add their repeat timers (a key pickup
|
||||
/// timer, say). John in Arwic counts 30 different ones (legendaryquestcounter_0913).
|
||||
/// </summary>
|
||||
internal sealed class LegendaryQuest
|
||||
{
|
||||
public string Group = "";
|
||||
public string Name = "";
|
||||
/// <summary>The short name players use ("RTW", "HMD"), or "".</summary>
|
||||
public string CommonName = "";
|
||||
public int Luminance;
|
||||
public string[] Flags = Array.Empty<string>();
|
||||
public string Url = "";
|
||||
public string Note = "";
|
||||
public string Video = "";
|
||||
|
||||
/// <summary>The short name when the sheet has one, else the quest name.</summary>
|
||||
public string Label => CommonName.Length > 0 ? $"{Name} ({CommonName})" : Name;
|
||||
|
||||
/// <summary>Done at least once: any of its flags is on this character.</summary>
|
||||
public bool Have(QuestFlagStore flags)
|
||||
{
|
||||
foreach (string f in Flags)
|
||||
if (flags.TryGet(f, out _)) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Time until it can be run again: the longest wait among its flags that have a repeat timer;
|
||||
/// zero when every timer is up (or it has none). Null when it was never done.
|
||||
/// </summary>
|
||||
public TimeSpan? TimeLeft(QuestFlagStore flags, DateTime utcNow)
|
||||
{
|
||||
bool any = false;
|
||||
TimeSpan left = TimeSpan.Zero;
|
||||
foreach (string f in Flags)
|
||||
{
|
||||
if (!flags.TryGet(f, out QuestFlag q)) continue;
|
||||
any = true;
|
||||
if (q.RepeatTime <= TimeSpan.Zero || q.CompletedOnUtc == DateTime.MinValue) continue;
|
||||
TimeSpan d = q.NextAvailableTime(utcNow);
|
||||
if (d > left) left = d;
|
||||
}
|
||||
return any ? left : null;
|
||||
}
|
||||
|
||||
/// <summary>"missing", "ready" or the time left ("14h 3m").</summary>
|
||||
public string Status(QuestFlagStore flags, DateTime utcNow)
|
||||
{
|
||||
TimeSpan? left = TimeLeft(flags, utcNow);
|
||||
if (left == null) return "missing";
|
||||
return left.Value.TotalSeconds > 0 ? TimeText.Friendly(left.Value) : "ready";
|
||||
}
|
||||
}
|
||||
|
||||
internal static class LegendaryList
|
||||
{
|
||||
/// <summary>John's count of different Legendary Key quests done (needs 30).</summary>
|
||||
public const string CounterFlag = "legendaryquestcounter_0913";
|
||||
/// <summary>Legendary Key quests John asks for.</summary>
|
||||
public const int JohnTarget = 30;
|
||||
|
||||
public static List<LegendaryQuest> All { get; } = Load();
|
||||
|
||||
/// <summary>The groups in list order (Graveyard, Rynthid, ...).</summary>
|
||||
public static List<string> Groups { get; } = BuildGroups();
|
||||
|
||||
/// <summary>John's counter for this character; null when /myquests doesn't have it (not started).</summary>
|
||||
public static int? JohnCount(QuestFlagStore flags) =>
|
||||
flags.TryGet(CounterFlag, out QuestFlag q) ? q.Solves : null;
|
||||
|
||||
private static List<LegendaryQuest> Load()
|
||||
{
|
||||
try
|
||||
{
|
||||
using StreamReader r = Csv.OpenEmbedded("legendary.csv");
|
||||
return Parse(r);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
// A missing or unreadable list must not take the Quests page down with it.
|
||||
return new List<LegendaryQuest>();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads a legendary.csv (a header row, then one quest a row). A row without a quest name is
|
||||
/// skipped; a missing column or a luminance that isn't a number reads as empty / 0, so one bad
|
||||
/// line never costs the rest of the list. Internal for the tests.
|
||||
/// </summary>
|
||||
internal static List<LegendaryQuest> Parse(TextReader r)
|
||||
{
|
||||
var list = new List<LegendaryQuest>();
|
||||
Dictionary<string, int> col = Csv.MapColumns(r.ReadLine() ?? "");
|
||||
int cGroup = Csv.Column(col, "Group"), cName = Csv.Column(col, "Quest"), cCommon = Csv.Column(col, "CommonName"),
|
||||
cLum = Csv.Column(col, "Luminance"), cFlags = Csv.Column(col, "Flags"), cUrl = Csv.Column(col, "Url"),
|
||||
cNote = Csv.Column(col, "Note"), cVideo = Csv.Column(col, "Video");
|
||||
while (r.ReadLine() is string line)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(line)) continue;
|
||||
string[] f = Csv.ParseLine(line);
|
||||
string name = Csv.Field(f, cName);
|
||||
if (name.Length == 0) continue;
|
||||
list.Add(new LegendaryQuest
|
||||
{
|
||||
Group = Csv.Field(f, cGroup),
|
||||
Name = name,
|
||||
CommonName = Csv.Field(f, cCommon),
|
||||
Luminance = int.TryParse(Csv.Field(f, cLum), out int lum) ? lum : 0,
|
||||
Flags = Csv.Field(f, cFlags).ToLowerInvariant()
|
||||
.Split(';', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries),
|
||||
Url = Csv.Field(f, cUrl),
|
||||
Note = Csv.Field(f, cNote),
|
||||
Video = Csv.Field(f, cVideo),
|
||||
});
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
private static List<string> BuildGroups()
|
||||
{
|
||||
var groups = new List<string>();
|
||||
foreach (LegendaryQuest q in All)
|
||||
if (!groups.Contains(q.Group)) groups.Add(q.Group);
|
||||
return groups;
|
||||
}
|
||||
}
|
||||
86
Plugins/RynthCore.Plugin.RynthOracle/Data/NavTargets.cs
Normal file
86
Plugins/RynthCore.Plugin.RynthOracle/Data/NavTargets.cs
Normal file
|
|
@ -0,0 +1,86 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace RynthCore.Plugin.RynthOracle.Data;
|
||||
|
||||
/// <summary>
|
||||
/// Coordinates in Oracle's text (quest walkthroughs, Dynamic Stamp notes) as RynthNav targets.
|
||||
/// The lists write them every which way: "59.6S 88.0W", "8.8S, 53.1E", "42.6n 62.4e".
|
||||
/// </summary>
|
||||
internal static class NavTargets
|
||||
{
|
||||
private static readonly Regex CoordsRx = new(
|
||||
@"(?<ns>\d+(?:\.\d+)?)\s*(?<nsc>[NnSs])[\s,]*(?<ew>\d+(?:\.\d+)?)\s*(?<ewc>[EeWw])\b",
|
||||
RegexOptions.CultureInvariant);
|
||||
|
||||
/// <summary>One place to go: what the text calls it (may be empty) and its coordinates ("59.6S, 88.0W").</summary>
|
||||
internal readonly record struct Stop(string Label, string Coords)
|
||||
{
|
||||
/// <summary>The RynthNav target: the coordinates, then the label (RynthNav uses an Atlas
|
||||
/// place of that name there, e.g. a dungeon's entrance).</summary>
|
||||
public string Target => Label.Length > 0 ? Coords + " " + Label : Coords;
|
||||
|
||||
/// <summary>How a picker shows it: "Kill Mukkir Progenitor - 86.5N, 57.3E".</summary>
|
||||
public string Display => Label.Length > 0 ? Label + " - " + Coords : Coords;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A named place with no coordinates (an exploration marker's location): its name is the whole
|
||||
/// RynthNav target, and RynthNav finds it on its Atlas.
|
||||
/// </summary>
|
||||
public static Stop Place(string name) => new("", name.Trim());
|
||||
|
||||
/// <summary>The first coordinates in <paramref name="text"/>, written "8.8S, 53.1E", or null.</summary>
|
||||
public static string? FirstCoords(string? text)
|
||||
{
|
||||
if (string.IsNullOrEmpty(text)) return null;
|
||||
Match m = CoordsRx.Match(text);
|
||||
return m.Success ? Format(m) : null;
|
||||
}
|
||||
|
||||
/// <summary><paramref name="text"/> with its coordinates taken out.</summary>
|
||||
public static string WithoutCoords(string? text) => string.IsNullOrEmpty(text) ? "" : CoordsRx.Replace(text, " ");
|
||||
|
||||
/// <summary>
|
||||
/// Every coordinate pair in <paramref name="text"/>, in order, each labelled with the words just
|
||||
/// before it in its step (walkthroughs separate steps with " - "): "Speak with Hoshar ibn Jalaq
|
||||
/// 59.6S 88.0W - Kill Mukkir Progenitor 86.5N 57.3E" gives two stops. The same coordinates
|
||||
/// twice are one stop.
|
||||
/// </summary>
|
||||
public static List<Stop> Stops(string? text)
|
||||
{
|
||||
var stops = new List<Stop>();
|
||||
if (string.IsNullOrEmpty(text)) return stops;
|
||||
foreach (Match m in CoordsRx.Matches(text))
|
||||
{
|
||||
string coords = Format(m);
|
||||
if (stops.Exists(s => s.Coords == coords)) continue;
|
||||
stops.Add(new Stop(LabelBefore(text, m.Index), coords));
|
||||
}
|
||||
return stops;
|
||||
}
|
||||
|
||||
/// <summary>The words between the previous step break (" - ", ". ", "; ", "|") or coordinates and <paramref name="at"/>.</summary>
|
||||
private static string LabelBefore(string text, int at)
|
||||
{
|
||||
int from = 0;
|
||||
foreach (string sep in new[] { " - ", ". ", "; ", "|", "(" })
|
||||
{
|
||||
int i = text.LastIndexOf(sep, Math.Max(0, at - 1), StringComparison.Ordinal);
|
||||
if (i >= 0 && i + sep.Length <= at) from = Math.Max(from, i + sep.Length);
|
||||
}
|
||||
// Not back past the previous coordinates ("Cragstone 26.0N 47.0E Speak with ...").
|
||||
foreach (Match m in CoordsRx.Matches(text.Substring(0, at)))
|
||||
from = Math.Max(from, m.Index + m.Length);
|
||||
string label = text.Substring(from, at - from).Trim(' ', ',', ':', '-', '.', '(', ')');
|
||||
// "at 42.1N ..." and "Meet at 42.1N ...": the little words around the coordinates aren't the place.
|
||||
label = Regex.Replace(label, @"^(at|in|near|to)\s+|\s+(at|in|near|to)$", "", RegexOptions.IgnoreCase).Trim();
|
||||
return label.Length > 60 ? label.Substring(0, 60).TrimEnd() : label;
|
||||
}
|
||||
|
||||
private static string Format(Match m) =>
|
||||
string.Create(CultureInfo.InvariantCulture,
|
||||
$"{m.Groups["ns"].Value}{char.ToUpperInvariant(m.Groups["nsc"].Value[0])}, {m.Groups["ew"].Value}{char.ToUpperInvariant(m.Groups["ewc"].Value[0])}");
|
||||
}
|
||||
|
|
@ -33,7 +33,7 @@ internal sealed class QuestFlag
|
|||
}
|
||||
|
||||
/// <summary>What one chat line is, as far as /myquests goes.</summary>
|
||||
internal enum MyQuestsLine { None, Quest, Empty, Disabled }
|
||||
internal enum MyQuestsLine { None, Quest, Empty, Disabled, Throttled }
|
||||
|
||||
/// <summary>
|
||||
/// The character's quest flags, read from the server's /myquests reply (ACE: one Broadcast line
|
||||
|
|
@ -55,10 +55,21 @@ internal sealed class QuestFlagStore
|
|||
|
||||
public const string EmptyText = "Quest list is empty.";
|
||||
public const string DisabledText = "The command \"myquests\" is not currently enabled on this server.";
|
||||
/// <summary>ACECustom's per-session throttle reply ("... may only be run once every 60 seconds.").</summary>
|
||||
public const string ThrottledText = "[MyQuests] This command may only be run once every";
|
||||
|
||||
private const int QuietMs = 1500; // a reply is complete once no line came for this long
|
||||
private const int RequestTimeoutMs = 10_000;
|
||||
private const int MinRequestGapMs = 5_000;
|
||||
/// <summary>ACECustom answers one /myquests a minute per session (whoever sent the last one).</summary>
|
||||
private const int ServerThrottleMs = 60_000;
|
||||
/// <summary>
|
||||
/// A reply this much smaller than the flags already held is taken as cut short (chat lines
|
||||
/// dropped before they reached the plugin), so it updates the flags instead of replacing them.
|
||||
/// </summary>
|
||||
private const double PartialReplyRatio = 0.8;
|
||||
/// <summary>Below this many flags held, a smaller reply always replaces (nothing much to lose).</summary>
|
||||
private const int PartialReplyMinHeld = 20;
|
||||
|
||||
public Dictionary<string, QuestFlag> Flags { get; private set; } = new(StringComparer.OrdinalIgnoreCase);
|
||||
private Dictionary<string, QuestFlag>? _pending;
|
||||
|
|
@ -66,6 +77,15 @@ internal sealed class QuestFlagStore
|
|||
|
||||
public DateTime LastReadUtc { get; private set; } = DateTime.MinValue;
|
||||
public bool ServerDisabled { get; private set; }
|
||||
/// <summary>The server refused the last /myquests (its once-a-minute limit) until this tick.</summary>
|
||||
public long ThrottledUntilMs { get; private set; } = long.MinValue / 2;
|
||||
/// <summary>This server has shown its throttle line this session, so every reply starts its minute.</summary>
|
||||
private bool _serverThrottles;
|
||||
/// <summary>
|
||||
/// Set when the last reply looked cut short and was merged into the held flags (lines in the
|
||||
/// reply, flags held before it). The plugin logs it once and clears it.
|
||||
/// </summary>
|
||||
public (int Got, int Had)? LastPartialReply { get; set; }
|
||||
/// <summary>Bumps whenever the flags change (views rebuild their caches on it).</summary>
|
||||
public int Revision { get; private set; }
|
||||
|
||||
|
|
@ -77,10 +97,16 @@ internal sealed class QuestFlagStore
|
|||
|
||||
public bool Loading => _pending != null || AwaitingOurs;
|
||||
|
||||
/// <summary>Seconds left on the server's /myquests limit (0 when a request would be answered).</summary>
|
||||
public int ThrottleSecondsLeft(long nowMs) =>
|
||||
nowMs < ThrottledUntilMs ? (int)((ThrottledUntilMs - nowMs + 999) / 1000) : 0;
|
||||
|
||||
/// <summary>Sends /myquests unless one went out moments ago. Returns false if nothing was sent.</summary>
|
||||
public bool Request(Func<string, bool> invokeChat, long nowMs)
|
||||
{
|
||||
if (nowMs - _requestedMs < MinRequestGapMs) return false;
|
||||
// The server would only answer with its throttle line; don't spend the request.
|
||||
if (nowMs < ThrottledUntilMs) return false;
|
||||
_requestedMs = nowMs;
|
||||
Interlocked.Increment(ref _selfSends);
|
||||
if (!invokeChat("/myquests"))
|
||||
|
|
@ -120,6 +146,16 @@ internal sealed class QuestFlagStore
|
|||
Revision++;
|
||||
return MyQuestsLine.Disabled;
|
||||
}
|
||||
if (line.Contains(ThrottledText, StringComparison.Ordinal))
|
||||
{
|
||||
// No reply is coming: stop "Reading..." and keep the flags already held. The minute
|
||||
// really started at the last answered request; a full minute from now is the safe side.
|
||||
_serverThrottles = true;
|
||||
ThrottledUntilMs = nowMs + ServerThrottleMs;
|
||||
AwaitingOurs = false;
|
||||
Revision++;
|
||||
return MyQuestsLine.Throttled;
|
||||
}
|
||||
if (line.IndexOf(" solves (", StringComparison.Ordinal) < 0) return MyQuestsLine.None;
|
||||
|
||||
QuestFlag? flag = Parse(line);
|
||||
|
|
@ -139,9 +175,27 @@ internal sealed class QuestFlagStore
|
|||
|
||||
if (_pending != null && nowMs - _lastLineMs >= QuietMs)
|
||||
{
|
||||
Flags = _pending;
|
||||
Dictionary<string, QuestFlag> reply = _pending;
|
||||
_pending = null;
|
||||
int had = Flags.Count;
|
||||
// A full reply replaces the list (a flag the server dropped goes away). One much
|
||||
// smaller than what is held lost lines on the way (the engine's chat queue drops the
|
||||
// oldest of a long burst): update what came and keep the rest, rather than blanking.
|
||||
if (had >= PartialReplyMinHeld && reply.Count > 0 && reply.Count < had * PartialReplyRatio)
|
||||
{
|
||||
var merged = new Dictionary<string, QuestFlag>(Flags, StringComparer.OrdinalIgnoreCase);
|
||||
foreach (KeyValuePair<string, QuestFlag> kv in reply) merged[kv.Key] = kv.Value;
|
||||
Flags = merged;
|
||||
LastPartialReply = (reply.Count, had);
|
||||
}
|
||||
else
|
||||
{
|
||||
Flags = reply;
|
||||
}
|
||||
LastReadUtc = DateTime.UtcNow;
|
||||
// On a throttling server any reply (ours, the player's, RynthAi's poll) starts its minute.
|
||||
if (_serverThrottles)
|
||||
ThrottledUntilMs = nowMs + ServerThrottleMs - QuietMs;
|
||||
AwaitingOurs = false;
|
||||
Revision++;
|
||||
}
|
||||
|
|
@ -158,6 +212,9 @@ internal sealed class QuestFlagStore
|
|||
AwaitingOurs = false;
|
||||
LastReadUtc = DateTime.MinValue;
|
||||
ServerDisabled = false;
|
||||
ThrottledUntilMs = long.MinValue / 2;
|
||||
_serverThrottles = false;
|
||||
LastPartialReply = null;
|
||||
Revision++;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -10,9 +10,11 @@ internal static class ServerTags
|
|||
public const string Aelrynth = "Aelrynth";
|
||||
public const string Conquest = "Conquest";
|
||||
public const string Levistras = "Levistras";
|
||||
/// <summary>Infinite Leaftide (ACECustom). Its server rules come from RynthILT ("RynthILT.Server").</summary>
|
||||
public const string InfiniteLeaftide = "InfiniteLeaftide";
|
||||
|
||||
/// <summary>Tags with a quest pack (Resources\quests.<tag>.csv) or features.</summary>
|
||||
public static readonly string[] Known = { Aelrynth, Conquest, Levistras };
|
||||
public static readonly string[] Known = { Aelrynth, Conquest, Levistras, InfiniteLeaftide };
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -31,8 +33,9 @@ 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). Infinite Leaftide has no RynthOracle pages: its screens are
|
||||
/// RynthILT's, so RynthCore's "ilt" server gives no tag here.
|
||||
/// (Decal's CharacterFilter.Server). Infinite Leaftide is matched on a world name containing
|
||||
/// "Leaftide", or on RynthILT's own verdict (its world list or the character's override) when
|
||||
/// RynthILT is loaded.
|
||||
/// </summary>
|
||||
internal sealed class ServerIdentity
|
||||
{
|
||||
|
|
@ -55,11 +58,12 @@ internal sealed class ServerIdentity
|
|||
Set("", "", "not logged in");
|
||||
}
|
||||
|
||||
/// <param name="rynthIltSaysIlt">RynthILT's profile reports an ILT world (IltServerLink); false without RynthILT.</param>
|
||||
/// <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)
|
||||
public void Refresh(RynthCoreHost host, uint playerId, bool rynthIltSaysIlt = false, EngineServerState? engine = null)
|
||||
{
|
||||
if (engine != null)
|
||||
{
|
||||
|
|
@ -98,6 +102,11 @@ internal sealed class ServerIdentity
|
|||
source = "the Aelrynth Bank properties (older engine)";
|
||||
}
|
||||
}
|
||||
if (tag.Length == 0 && rynthIltSaysIlt)
|
||||
{
|
||||
tag = ServerTags.InfiniteLeaftide;
|
||||
source = "RynthILT: an Infinite Leaftide world";
|
||||
}
|
||||
Set(tag, world, source);
|
||||
}
|
||||
|
||||
|
|
@ -139,6 +148,7 @@ internal sealed class ServerIdentity
|
|||
/// <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.IltId => ServerTags.InfiniteLeaftide,
|
||||
EngineServerState.AelrynthId => ServerTags.Aelrynth,
|
||||
"conquest" => ServerTags.Conquest,
|
||||
"levistras" => ServerTags.Levistras,
|
||||
|
|
@ -148,6 +158,7 @@ internal sealed class ServerIdentity
|
|||
/// <summary>The RynthCore server id for a tag; "" for none.</summary>
|
||||
public static string EngineIdForTag(string? tag) => tag switch
|
||||
{
|
||||
ServerTags.InfiniteLeaftide => EngineServerState.IltId,
|
||||
ServerTags.Aelrynth => EngineServerState.AelrynthId,
|
||||
ServerTags.Conquest => "conquest",
|
||||
ServerTags.Levistras => "levistras",
|
||||
|
|
@ -165,6 +176,9 @@ internal sealed class ServerIdentity
|
|||
return ServerTags.Conquest;
|
||||
if (w.Equals(ServerTags.Levistras, StringComparison.OrdinalIgnoreCase))
|
||||
return ServerTags.Levistras;
|
||||
// "InfiniteLeaftide", "Infinite Leaftide", staging copies: RynthILT's own world rule.
|
||||
if (w.IndexOf("Leaftide", StringComparison.OrdinalIgnoreCase) >= 0)
|
||||
return ServerTags.InfiniteLeaftide;
|
||||
return "";
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ internal sealed class VoidDot
|
|||
/// <summary>Cast while Surge of Destruction was up (shown highlighted).</summary>
|
||||
public bool Destruction;
|
||||
|
||||
/// <summary>ConquestAC scales void DoT duration by the caster's augs (1.0 elsewhere).</summary>
|
||||
/// <summary>A server's own rule scales void DoT duration (Conquest's, from RynthConquest's profile; 1.0 elsewhere).</summary>
|
||||
public double DurationScale = 1.0;
|
||||
|
||||
/// <summary>Corrosion 15 s, Corruption and Destructive Curse 30 s (upstream's retail values), times the server's scale.</summary>
|
||||
|
|
|
|||
Loading…
Reference in a new issue