add StartQuest
authorJackson <9527380+Jaksuhn@users.noreply.github.com>
Wed, 5 Feb 2025 15:57:33 +0000 (16:57 +0100)
committerJackson <9527380+Jaksuhn@users.noreply.github.com>
Wed, 5 Feb 2025 15:57:33 +0000 (16:57 +0100)
Questionable/External/QuestionableIpc.cs

index 760a76cd97210c2cc4d4b7bf26635b30682ebf66..cd9952594da7d7f8618ca3c1c151f321dfcf8a05 100644 (file)
@@ -4,6 +4,7 @@ using System.Linq;
 using Dalamud.Plugin;
 using Dalamud.Plugin.Ipc;
 using Questionable.Controller;
+using Questionable.Model.Questing;
 using Questionable.Windows.QuestComponents;
 
 namespace Questionable.External;
@@ -17,10 +18,11 @@ internal sealed class QuestionableIpc : IDisposable
     private readonly ICallGateProvider<bool> _isRunning;
     private readonly ICallGateProvider<string?> _getCurrentQuestId;
     private readonly ICallGateProvider<List<string>> _getCurrentlyActiveEventQuests;
+    private readonly ICallGateProvider<string, bool> _startQuest;
 
     public QuestionableIpc(
         QuestController questController,
-        EventInfoComponent eventInfoComponent,
+        EventInfoComponent eventInfoComponent, QuestRegistry questRegistry,
         IDalamudPluginInterface pluginInterface)
     {
         _isRunning = pluginInterface.GetIpcProvider<bool>(IpcIsRunning);
@@ -34,11 +36,25 @@ internal sealed class QuestionableIpc : IDisposable
             pluginInterface.GetIpcProvider<List<string>>(IpcGetCurrentlyActiveEventQuests);
         _getCurrentlyActiveEventQuests.RegisterFunc(() =>
             eventInfoComponent.GetCurrentlyActiveEventQuests().Select(q => q.ToString()).ToList());
+
+        _startQuest = pluginInterface.GetIpcProvider<string, bool>("Questionable.StartQuest");
+        _startQuest.RegisterFunc((string questId) => StartQuest(questController, questRegistry, questId));
     }
 
+    private static bool StartQuest(QuestController qc, QuestRegistry qr, string questId)
+    {
+        if (ElementId.TryFromString(questId, out var elementId) && elementId != null && qr.TryGetQuest(elementId, out var quest))
+        {
+            qc.SetNextQuest(quest);
+            qc.Start("IPCQuestSelection");
+            return true;
+        }
+        return false;
+    }
 
     public void Dispose()
     {
+        _startQuest.UnregisterFunc();
         _getCurrentlyActiveEventQuests.UnregisterFunc();
         _getCurrentQuestId.UnregisterFunc();
         _isRunning.UnregisterFunc();