using System; using System.Collections.Generic; using RynthCore.Plugin.RynthAi; using RynthCore.Plugin.RynthOracle.Data; using RynthCore.Plugin.Shared; using RynthCore.PluginSdk; namespace RynthCore.Plugin.RynthOracle; /// Everything the views read and the actions they can take. Pump thread only. internal sealed class OracleContext { public RynthCoreHost Host; public readonly OracleSettings Settings = new(); public readonly QuestFlagStore Flags = new(); public readonly QuestCatalog Catalog = new(); public readonly QuestTimerWatcher Timers = new(); public readonly QuestCatalogUpdater Updater = new(); /// This character's tracked quests and recorded rewards (loaded once the name is known). public readonly QuestBook Book = new(); public readonly CharacterSnapshot Character = new(); public readonly VoidTracker Void = new(); public readonly FellowshipTracker Fellowship = new(); public readonly ServerIdentity Server = new(); /// RynthILT's profile with the /qb lists (Infinite Leaftide only: polled while Server.IsIlt). public readonly IltServerLink Ilt = new(); /// The Leaftide wiki quest guide RynthILT keeps (Infinite Leaftide only: polled while Server.IsIlt). public readonly QuestGuideClient Guide = new(); /// /// RynthOracle's own quest guide from the AC Community Wiki (asheron.fandom.com), on every server (2026-11-21). /// Settable for the tests (a file of their own). /// public FandomFeed Fandom = new(); /// /// The wiki guide in use: on Infinite Leaftide RynthILT's (its own wiki) once it has quests, else the AC /// Community Wiki's. /// public QuestGuide Wiki { get { if (Server.IsIlt && Guide.Guide.Quests.Count > 0) return Guide.Guide; QuestGuide sg = ServerGuide.Client.Guide; if (sg.Quests.Count == 0) return Fandom.Guide; // The active server's own wiki quests (RynthConquest's Conquest wiki, 2026-11-21) over the AC // Community Wiki's: its quests first, then the retail ones it doesn't have; the kill tasks, society // quests and contracts are the AC Community Wiki's. int key = unchecked(ServerGuide.Client.Revision * 7919 + Fandom.Revision); if (_merged == null || _mergedKey != key || !ReferenceEquals(_mergedFrom, sg)) { var g = new QuestGuide { Source = sg.Source + "+fandom", Parser = Math.Min(sg.Parser, Fandom.Guide.Parser), UpdatedUtc = sg.UpdatedUtc, KillTasks = Fandom.Guide.KillTasks, Society = Fandom.Guide.Society, Contracts = Fandom.Guide.Contracts, }; var titles = new HashSet(StringComparer.OrdinalIgnoreCase); foreach (GuideQuest q in sg.Quests) if (titles.Add(q.Title)) g.Quests.Add(q); foreach (GuideQuest q in Fandom.Guide.Quests) if (titles.Add(q.Title)) g.Quests.Add(q); _merged = g; _mergedKey = key; _mergedFrom = sg; } return _merged; } } private QuestGuide? _merged, _mergedFrom; private int _mergedKey; /// The active server's own wiki quest guide (RynthServer.QuestGuide; RynthConquest's), on any server but ILT. public readonly ServerGuideClient ServerGuide = new(); /// The wiki tab's name: "ILT Wiki", "<server> Wiki" for a server's own guide, else "AC Wiki". public string WikiLabel => Server.IsIlt && Guide.Guide.Quests.Count > 0 ? "ILT Wiki" : ServerGuide.Client.Guide.Quests.Count > 0 ? (ServerGuide.Client.Tag.Length > 0 ? ServerGuide.Client.Tag : "Server") + " Wiki" : "AC Wiki"; /// The wiki in use is the AC Community Wiki's. public bool WikiIsFandom => ReferenceEquals(Wiki, Fandom.Guide); /// Goes up when either guide changes. public int WikiRevision => unchecked((Guide.Revision * 7919 + Fandom.Revision) * 31 + ServerGuide.Client.Revision); /// A wiki quest by title: the guide in use, else the AC Community Wiki's (a contract's quest, a society quest). public GuideQuest? FindWiki(string title) => Wiki.Find(title) ?? (WikiIsFandom ? null : Fandom.Guide.Find(title)); /// "Run this quest": the wiki quest RynthNav is walking (set up by the plugin's Initialize). public QuestRunner? Runner; /// Stamps the server gave this session ("You've stamped X!"), as GuideStamp keys: done before /myquests says so. public readonly System.Collections.Generic.HashSet SessionStamps = new(StringComparer.Ordinal); /// Goes up when grows. public int SessionStampRevision; /// Kill tasks' kill lines this session (the Kill Tasks tab, 2026-11-21). public readonly KillChat Kills = new(); /// Sends a RynthAi command through the plugin-command broker (action, value); false without RynthAi. public Func SendAi = (_, _) => false; /// RynthILT's data interface: the Temple guardians (Infinite Leaftide only). public readonly RynthCore.Plugin.Shared.RynthIltDataClient IltData = new(); /// The Temple guardians as RynthILT last reported them (None off Infinite Leaftide). public RynthCore.Plugin.Shared.IltGuardianView Guardian = RynthCore.Plugin.Shared.IltGuardianView.None; /// Goes up when changes (the Quests list rebuilds its guardian rows). public int GuardianRevision; /// The last guardian command's problem, or "". public string GuardianMessage = ""; /// A verb for RynthILT's Temple guardians (handin, stop, refresh, chat/auto/buy on|off). public Func GuardianCommand = _ => false; // A server's own screens are its server plugin's (2026-10-20, 2026-10-21): nothing here is one server's. /// RynthAi's session (the one session every tracker shows); read while the Character tab shows. public readonly RynthCore.Plugin.Shared.RynthAiSessionClient AiSession = new(); /// The last session RynthAi reported; SessionKnown false without RynthAi. public RynthCore.Plugin.Shared.SessionStatsV1 Session; public bool SessionKnown; /// RynthCore's server list (API v86) and the active server owner's settings; State null on older engines. public readonly RynthCore.Plugin.Shared.ServerStateClient ServerState = new(); /// /// The active server plugin's quest pack ("RynthServer.QuestPack"): whatever the plugin RynthCore names /// as the active server's owner offers; none without one (retail quests only). /// public readonly RynthCore.Plugin.Shared.ServerQuestPackClient QuestPacks = new(); /// /// The active server's Void DoT duration rule: its plugin's profile value "voidDotDurationScale" /// (RynthConquest publishes Conquest's), 1 on every other server or without the plugin. /// public double VoidDotScale = 1.0; /// The Gear tab's Check (worn gear's spells, wards and banes, ratings); every server. public readonly GearScanner Gear = new(); /// The ILT Tracker window's packs and bounty slots (Infinite Leaftide only): read while that window shows. public readonly T11Scanner T11 = new(); /// The ILT Tracker's quest bonus: the "/bonus" multipliers and a "/qb" count from chat (2026-11-21). public readonly QuestBonus QuestBonus = new(); /// Set by the plugin: reads the packs and bounty slots for the ILT Tracker tab now. public Action RescanT11 = () => { }; /// Titles the character holds (engine API v75); TitlesKnown false until the engine has the list. public readonly System.Collections.Generic.HashSet EarnedTitles = new(); public bool TitlesKnown; public uint CurrentTitle; public bool InWorld; public long NowMs; public DateTime UtcNow; /// The last thing the quest list check said, shown on the About tab. public string UpdaterMessage = ""; /// Set by the plugin: sends /myquests (reply hidden when the setting says so). False when nothing was sent (not in world, or one went out moments ago). public Func RequestQuests = () => false; /// Set by the plugin (the Refresh buttons): re-reads the character's stats and buffs, and RynthAi's session, at once. public Action RereadCharacter = () => { }; /// Set by the plugin: re-reads the titles the engine holds for the character. public Action RereadTitles = () => { }; /// Set by the plugin: reloads the quest list and server pack from their files and re-asks RynthCore which server this is. public Action ReloadQuestList = () => { }; /// Where goes instead of the chat window (the offline tests). public Action? PrintSink = null; /// Set by the plugin: sends a chat command to the server as if typed (the views' buttons). public Func Send = _ => false; /// Set by the plugin: runs a chat command through RynthCore's plugin dispatch (another plugin's window). public Func RunCommand = _ => false; /// Set by the plugin: "<verb> <targets>" for RynthNav's /rnav (go, route, arrow); false when RynthNav isn't there. public Func SendNav = _ => false; /// Set by the plugin: shows or hides the Quest Timers window. public Action SetQuestTimersWindow = _ => { }; /// Set by the plugin: whether the Quest Timers window is showing. public Func QuestTimersWindowVisible = () => false; public Func Props => id => Character.Int(Host, id); /// /// The plugin's chat lines, queued and written by the tick (Plugins/Shared/CommandReply.cs: the host /// drops a line within 100 ms of another plugin's, so a quest's several lines used to go missing). /// Null before Initialize (and in the offline tests, which use ). /// public CommandReply? Reply; /// A line in the player's chat window only (nothing is sent to the server). public void Print(string text) => Print(text, ok: true); /// A line saying a command didn't work (the failure colour). public void PrintFail(string text) => Print(text, ok: false); private void Print(string text, bool ok) { if (PrintSink != null) { PrintSink(text); return; } if (Reply != null) { Reply.Say(ok, text); return; } if (!Host.WriteToChat("[RynthOracle] " + text, ok ? CommandReply.OkChatType : CommandReply.FailChatType)) Host.Log("[RynthOracle] " + text); } /// A click on a quest: its info and hint text, link and flag history in chat (upstream "thinks" them). public void PrintQuest(Quest q) { foreach (string line in QuestText.Lines(q, Flags, Book, UtcNow)) Print(line); } }