using System; 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(); // 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 plugin's own quest guide ("RynthServer.QuestGuide", 2026-11-27): its wiki's quests /// with their steps, shown in the Guide tab over the AC Community Wiki's. None without one. /// public readonly RynthCore.Plugin.Shared.ServerQuestGuideClient ServerGuide = new(); /// The AC Community Wiki feed (off by default; Settings.WikiFeedOn): the Guide tab's quests on every server. public readonly CommunityWikiFeed Wiki = new(); /// Stamps seen in chat this session ("You've stamped X!"), as GuideStamp keys; SessionStampRevision goes up with each. public readonly System.Collections.Generic.HashSet SessionStamps = new(StringComparer.Ordinal); public int SessionStampRevision; /// Kill task lines seen in chat this session. public readonly KillChat Kills = new(); /// Where guide quests stand for this character (the flags, the session's stamps and kill lines). public readonly GuideProgress Progress; /// The seam for running a guide quest later; null in this version (no run controls drawn). public IGuideQuestRunner? GuideRunner; public OracleContext() { Progress = new GuideProgress(Flags, SessionStamps, Kills); } /// A chat line for the guide: a stamp ("You've stamped X!") or a kill task's kill line. True when it was one. public bool OnGuideChatLine(string line, DateTime utcNow) { if (GuideStamp.FromChat(line) is string stamp && line.TrimStart().StartsWith("You've stamped ", StringComparison.OrdinalIgnoreCase)) { if (SessionStamps.Add(GuideStamp.Key(stamp))) SessionStampRevision++; return true; } return Kills.OnChatLine(line, utcNow); } /// /// Turns the AC Community Wiki feed on or off (the About and Guide tabs' buttons, /ro wiki on|off). Turning it on /// says what it reads and from where, then starts the first read. The answer, for the caller to show. /// public (bool Ok, string Text) SetWikiFeed(bool on) { if (Settings.WikiFeedOn == on) return (true, on ? "The AC Community Wiki feed is already on. " + WikiStatus() : "The AC Community Wiki feed is already off: nothing is fetched."); Settings.WikiFeedOn = on; Settings.Save(); if (!on) { Wiki.Stop(); return (true, "AC Community Wiki feed off: nothing more is fetched (the copy already saved stays in the Guide tab)."); } bool started = Wiki.Start(on: true); return (true, "AC Community Wiki feed on. It reads " + CommunityWikiFeed.WhatItReads + (started ? " Reading it now." : " A read is already under way.")); } /// Reads the wiki now (the Guide tab's Read now, /ro wiki read): only with the feed on. public (bool Ok, string Text) ReadWikiNow() { if (!Settings.WikiFeedOn) return (false, "The AC Community Wiki feed is off, so nothing is fetched. Turn it on first (About tab, Guide tab, or /ro wiki on); it reads " + CommunityWikiFeed.WhatItReads); if (Wiki.Running) return (false, "The AC Community Wiki is being read already: " + Wiki.Status); return Wiki.Start(on: true) ? (true, "Reading the AC Community Wiki (" + CommunityWikiFeed.Host + "): only the pages edited since the last read.") : (false, "Couldn't start reading the AC Community Wiki."); } /// "on: 812 quests, ... (read ...)" or "off". public string WikiStatus() => (Settings.WikiFeedOn ? "On: " : "Off (nothing is fetched). Saved copy: ") + Wiki.Status + "."; /// /// 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; /// 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); } }