Add TextAdvance ipc
authorLimiana <5073202+Limiana@users.noreply.github.com>
Mon, 30 Sep 2024 20:14:56 +0000 (23:14 +0300)
committerLimiana <5073202+Limiana@users.noreply.github.com>
Mon, 30 Sep 2024 20:14:56 +0000 (23:14 +0300)
Questionable/External/TextAdvanceIpc.cs [new file with mode: 0644]
Questionable/QuestionablePlugin.cs

diff --git a/Questionable/External/TextAdvanceIpc.cs b/Questionable/External/TextAdvanceIpc.cs
new file mode 100644 (file)
index 0000000..bb771b0
--- /dev/null
@@ -0,0 +1,79 @@
+using Dalamud.Plugin;
+using Dalamud.Plugin.Ipc;
+using Dalamud.Plugin.Services;
+using FFXIVClientStructs.FFXIV.Client.Game;
+using Questionable.Controller;
+using Questionable.Data;
+using Questionable.Model.Common;
+using System;
+
+namespace Questionable.External;
+
+internal sealed class TextAdvanceIpc : IDisposable
+{
+    private bool _isExternalControlActivated;
+    private readonly QuestController _questController;
+    private readonly IFramework _framework;
+    private readonly ICallGateSubscriber<bool> _isInExternalControl;
+    private readonly ICallGateSubscriber<string, ExternalTerritoryConfig, bool> _enableExternalControl;
+    private readonly ICallGateSubscriber<string, bool> _disableExternalControl;
+    private readonly string _pluginName;
+    private readonly ExternalTerritoryConfig _externalTerritoryConfig = new();
+
+    public TextAdvanceIpc(IDalamudPluginInterface pluginInterface, IFramework framework, QuestController questController)
+    {
+        _framework = framework;
+        _questController = questController;
+        _isInExternalControl = pluginInterface.GetIpcSubscriber<bool>("TextAdvance.IsInExternalControl");
+        _enableExternalControl = pluginInterface.GetIpcSubscriber<string, ExternalTerritoryConfig, bool>("TextAdvance.EnableExternalControl");
+        _disableExternalControl = pluginInterface.GetIpcSubscriber<string, bool>("TextAdvance.DisableExternalControl");
+        _pluginName = pluginInterface.InternalName;
+        _framework.Update += OnUpdate;
+    }
+
+    public void Dispose()
+    {
+        _framework.Update -= OnUpdate;
+        if(_isExternalControlActivated)
+        {
+            _disableExternalControl.InvokeFunc(_pluginName);
+        }
+    }
+
+    public void OnUpdate(IFramework framework)
+    {
+        if(_questController.IsRunning)
+        {
+            if(!_isInExternalControl.InvokeFunc())
+            {
+                if(_enableExternalControl.InvokeFunc(_pluginName, _externalTerritoryConfig))
+                {
+                    _isExternalControlActivated = true;
+                }
+            }
+        }
+        else
+        {
+            if(_isExternalControlActivated)
+            {
+                if(_disableExternalControl.InvokeFunc(_pluginName) || !_isInExternalControl.InvokeFunc())
+                {
+                    _isExternalControlActivated = false;
+                }
+            }
+        }
+    }
+
+    public class ExternalTerritoryConfig
+    {
+        public bool? EnableQuestAccept = true;
+        public bool? EnableQuestComplete = true;
+        public bool? EnableRewardPick = true;
+        public bool? EnableRequestHandin = true;
+        public bool? EnableCutsceneEsc = true;
+        public bool? EnableCutsceneSkipConfirm = true;
+        public bool? EnableTalkSkip = true;
+        public bool? EnableRequestFill = true;
+        public bool? EnableAutoInteract = false;
+    }
+}
index a3731ed49ceb4c14c2f7711385291a95f0015757..b9a1c54eb8dd06069cb6e8d54403b88f2b8a082d 100644 (file)
@@ -124,6 +124,7 @@ public sealed class QuestionablePlugin : IDalamudPlugin
         serviceCollection.AddSingleton<YesAlreadyIpc>();
         serviceCollection.AddSingleton<ArtisanIpc>();
         serviceCollection.AddSingleton<QuestionableIpc>();
+        serviceCollection.AddSingleton<TextAdvanceIpc>();
     }
 
     private static void AddTaskFactories(ServiceCollection serviceCollection)
@@ -289,6 +290,7 @@ public sealed class QuestionablePlugin : IDalamudPlugin
         serviceProvider.GetRequiredService<QuestionableIpc>();
         serviceProvider.GetRequiredService<DalamudInitializer>();
         serviceProvider.GetRequiredService<AutoSnipeHandler>().Enable();
+        serviceProvider.GetRequiredService<TextAdvanceIpc>();
     }
 
     public void Dispose()