Ensure that AD duty mode is set to 'Support'
authorLiza Carvelli <liza@carvel.li>
Fri, 7 Feb 2025 23:21:00 +0000 (00:21 +0100)
committerLiza Carvelli <liza@carvel.li>
Fri, 7 Feb 2025 23:21:00 +0000 (00:21 +0100)
Questionable/External/AutoDutyIpc.cs

index 9d049062959bf74266e851020f091495e602e6fe..8d9a84828ca0783c8cedd540bee2603046d351af 100644 (file)
@@ -12,18 +12,23 @@ internal sealed class AutoDutyIpc
     private readonly Configuration _configuration;
     private readonly TerritoryData _territoryData;
     private readonly ILogger<AutoDutyIpc> _logger;
-    private readonly ICallGateSubscriber<uint,bool> _contentHasPath;
-    private readonly ICallGateSubscriber<uint,int,bool,object> _run;
+    private readonly ICallGateSubscriber<uint, bool> _contentHasPath;
+    private readonly ICallGateSubscriber<string, string, object> _setConfig;
+    private readonly ICallGateSubscriber<uint, int, bool, object> _run;
     private readonly ICallGateSubscriber<bool> _isStopped;
+    private readonly ICallGateSubscriber<object> _stop;
 
-    public AutoDutyIpc(IDalamudPluginInterface pluginInterface, Configuration configuration, TerritoryData territoryData, ILogger<AutoDutyIpc> logger)
+    public AutoDutyIpc(IDalamudPluginInterface pluginInterface, Configuration configuration,
+        TerritoryData territoryData, ILogger<AutoDutyIpc> logger)
     {
         _configuration = configuration;
         _territoryData = territoryData;
         _logger = logger;
         _contentHasPath = pluginInterface.GetIpcSubscriber<uint, bool>("AutoDuty.ContentHasPath");
+        _setConfig = pluginInterface.GetIpcSubscriber<string, string, object>("AutoDuty.SetConfig");
         _run = pluginInterface.GetIpcSubscriber<uint, int, bool, object>("AutoDuty.Run");
         _isStopped = pluginInterface.GetIpcSubscriber<bool>("AutoDuty.IsStopped");
+        _stop = pluginInterface.GetIpcSubscriber<object>("AutoDuty.Stop");
     }
 
     public bool IsConfiguredToRunContent(uint? cfcId, bool autoDutyEnabled)
@@ -55,7 +60,8 @@ internal sealed class AutoDutyIpc
         }
         catch (IpcError e)
         {
-            _logger.LogWarning("Unable to query AutoDuty for path in territory {TerritoryType}: {Message}", cfcData.TerritoryId, e.Message);
+            _logger.LogWarning("Unable to query AutoDuty for path in territory {TerritoryType}: {Message}",
+                cfcData.TerritoryId, e.Message);
             return false;
         }
     }
@@ -67,6 +73,7 @@ internal sealed class AutoDutyIpc
 
         try
         {
+            _setConfig.InvokeAction("dutyModeEnum", "Support");
             _run.InvokeAction(cfcData.TerritoryId, 1, true);
         }
         catch (IpcError e)
@@ -86,4 +93,17 @@ internal sealed class AutoDutyIpc
             return true;
         }
     }
+
+    public void Stop()
+    {
+        try
+        {
+            _logger.LogInformation("Calling AutoDuty.Stop");
+            _stop.InvokeAction();
+        }
+        catch (IpcError e)
+        {
+            throw new TaskException($"Unable to stop AutoDuty: {e.Message}", e);
+        }
+    }
 }