using System; using RynthCore.Plugin.RynthAi; using RynthCore.Plugin.RynthOracle.Data; 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 server profile (Leaftide features, fellowship rules, the /qb list); None without RynthILT. public readonly IltServerLink Ilt = new(); /// RynthILT's "RynthILT.Data" (charms, pet breeding, the Temple guardians). public readonly RynthCore.Plugin.Shared.RynthIltDataClient IltData = new(); /// The charms RynthILT last reported (None without RynthILT); read while the Character tab shows. public RynthCore.Plugin.Shared.IltCharmsView Charms = RynthCore.Plugin.Shared.IltCharmsView.None; /// The last charm Toggle's outcome, shown under the charms list. public string CharmMessage = ""; /// RynthILT's pet breeding tracker (None without it); read while the Pet Breeding tab shows. public RynthCore.Plugin.Shared.IltBreedingView Breeding = RynthCore.Plugin.Shared.IltBreedingView.None; /// The last breeding button's outcome, shown under the tab's buttons. public string BreedingMessage = ""; /// RynthILT's Temple guardians (None without RynthILT 0.3.3+); read while the Quests tab shows on Infinite Leaftide. public RynthCore.Plugin.Shared.IltGuardianView Guardian = RynthCore.Plugin.Shared.IltGuardianView.None; /// Goes up each time changes, so the Quests list rebuilds its guardian rows. public int GuardianRevision; /// The last guardian button's outcome, shown under the guardian controls. public string GuardianMessage = ""; /// 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'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: asks RynthILT to use a carried charm or Guardian Hand (its toggle id). public Func ToggleCharm = _ => false; /// Set by the plugin: sends a verb to RynthILT's breeding tracker (RynthIltDataApi PetBreedingCommand). public Func BreedingCommand = _ => false; /// Set by the plugin: sends a verb to RynthILT's guardians (RynthIltDataApi GuardianCommand). public Func GuardianCommand = _ => 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: the name of a Parchment carried (null when none). Null here: the Quests tab doesn't look. public Func? ParchmentFinder; /// /// Set by the plugin: RynthAi is loaded and so can take the Quests tab's "/ub give" (the Give /// Parchment button). False disables the button with a tooltip. /// public Func UbGiveAvailable = () => false; /// /// The loaded RynthAi answered a "/ub give" with "Unrecognized /ub command": it has no such verb, /// so the Give Parchment button stays disabled (set by the plugin from the chat line). /// public bool UbGiveMissing; /// When the Give Parchment button last sent "/ub give" (NowMs), so a rejection in chat can be tied to it. public long UbGiveSentMs = long.MinValue / 2; /// 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); /// /// A chat line seen just after the Give Parchment button sent "/ub give": RynthAi's "Unrecognized /// /ub command" means this RynthAi has no such verb, so the button stays off. True when it did. /// public bool NoteChatLineForGive(string line, long nowMs) { if (nowMs - UbGiveSentMs >= 5000 || UbGiveMissing) return false; if (line.IndexOf("Unrecognized /ub", StringComparison.OrdinalIgnoreCase) < 0) return false; UbGiveMissing = true; return true; } /// A line in the player's chat window only (nothing is sent to the server). public void Print(string text) { if (PrintSink != null) { PrintSink(text); return; } if (!Host.WriteToChat("[RynthOracle] " + text, 1)) 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); } }