Split 'MoveTo' into separate classes, part 2
authorLiza Carvelli <liza@carvel.li>
Mon, 31 Mar 2025 00:20:13 +0000 (02:20 +0200)
committerLiza Carvelli <liza@carvel.li>
Mon, 31 Mar 2025 00:20:13 +0000 (02:20 +0200)
Questionable/Controller/Steps/Movement/LandExecutor.cs [new file with mode: 0644]
Questionable/Controller/Steps/Movement/LandTask.cs [new file with mode: 0644]
Questionable/Controller/Steps/Movement/MoveTo.cs
Questionable/Controller/Steps/Movement/WaitForNearDataId.cs [new file with mode: 0644]
Questionable/Controller/Steps/Movement/WaitForNearDataIdExecutor.cs [new file with mode: 0644]
Questionable/QuestionablePlugin.cs

diff --git a/Questionable/Controller/Steps/Movement/LandExecutor.cs b/Questionable/Controller/Steps/Movement/LandExecutor.cs
new file mode 100644 (file)
index 0000000..3e2be16
--- /dev/null
@@ -0,0 +1,64 @@
+using System;
+using Dalamud.Game.ClientState.Conditions;
+using Dalamud.Plugin.Services;
+using FFXIVClientStructs.FFXIV.Client.Game;
+using FFXIVClientStructs.FFXIV.Client.Game.Character;
+using Microsoft.Extensions.Logging;
+
+namespace Questionable.Controller.Steps.Movement;
+
+internal sealed class LandExecutor(IClientState clientState, ICondition condition, ILogger<LandExecutor> logger)
+    : TaskExecutor<LandTask>
+{
+    private bool _landing;
+    private DateTime _continueAt;
+
+    protected override bool Start()
+    {
+        if (!condition[ConditionFlag.InFlight])
+        {
+            logger.LogInformation("Not flying, not attempting to land");
+            return false;
+        }
+
+        _landing = AttemptLanding();
+        _continueAt = DateTime.Now.AddSeconds(0.25);
+        return true;
+    }
+
+    public override ETaskResult Update()
+    {
+        if (DateTime.Now < _continueAt)
+            return ETaskResult.StillRunning;
+
+        if (condition[ConditionFlag.InFlight])
+        {
+            if (!_landing)
+            {
+                _landing = AttemptLanding();
+                _continueAt = DateTime.Now.AddSeconds(0.25);
+            }
+
+            return ETaskResult.StillRunning;
+        }
+
+        return ETaskResult.TaskComplete;
+    }
+
+    private unsafe bool AttemptLanding()
+    {
+        var character = (Character*)(clientState.LocalPlayer?.Address ?? 0);
+        if (character != null)
+        {
+            if (ActionManager.Instance()->GetActionStatus(ActionType.GeneralAction, 23) == 0)
+            {
+                logger.LogInformation("Attempting to land");
+                return ActionManager.Instance()->UseAction(ActionType.GeneralAction, 23);
+            }
+        }
+
+        return false;
+    }
+
+    public override bool ShouldInterruptOnDamage() => false;
+}
diff --git a/Questionable/Controller/Steps/Movement/LandTask.cs b/Questionable/Controller/Steps/Movement/LandTask.cs
new file mode 100644 (file)
index 0000000..ada55b8
--- /dev/null
@@ -0,0 +1,7 @@
+namespace Questionable.Controller.Steps.Movement;
+
+internal sealed class LandTask : ITask
+{
+    public bool ShouldRedoOnInterrupt() => true;
+    public override string ToString() => "Land";
+}
index 05d8684..a44bee9 100644 (file)
@@ -1,15 +1,9 @@
-using System;
-using System.Collections.Generic;
+using System.Collections.Generic;
 using System.Numerics;
-using Dalamud.Game.ClientState.Conditions;
-using Dalamud.Game.ClientState.Objects.Types;
 using Dalamud.Plugin.Services;
-using FFXIVClientStructs.FFXIV.Client.Game;
-using FFXIVClientStructs.FFXIV.Client.Game.Character;
 using Microsoft.Extensions.Logging;
 using Questionable.Controller.Steps.Common;
 using Questionable.Data;
-using Questionable.Functions;
 using Questionable.Model;
 using Questionable.Model.Questing;
 
@@ -67,92 +61,4 @@ internal static class MoveTo
                 yield return new LandTask();
         }
     }
-
-    internal sealed record WaitForNearDataId(uint DataId, float StopDistance) : ITask
-    {
-        public bool ShouldRedoOnInterrupt() => true;
-    }
-
-    internal sealed class WaitForNearDataIdExecutor(
-        GameFunctions gameFunctions,
-        IClientState clientState) : TaskExecutor<WaitForNearDataId>
-    {
-        protected override bool Start() => true;
-
-        public override ETaskResult Update()
-        {
-            IGameObject? gameObject = gameFunctions.FindObjectByDataId(Task.DataId);
-            if (gameObject == null ||
-                (gameObject.Position - clientState.LocalPlayer!.Position).Length() > Task.StopDistance)
-            {
-                throw new TaskException("Object not found or too far away, no position so we can't move");
-            }
-
-            return ETaskResult.TaskComplete;
-        }
-
-        public override bool ShouldInterruptOnDamage() => false;
-    }
-
-    internal sealed class LandTask : ITask
-    {
-        public bool ShouldRedoOnInterrupt() => true;
-        public override string ToString() => "Land";
-    }
-
-    internal sealed class LandExecutor(IClientState clientState, ICondition condition, ILogger<LandExecutor> logger)
-        : TaskExecutor<LandTask>
-    {
-        private bool _landing;
-        private DateTime _continueAt;
-
-        protected override bool Start()
-        {
-            if (!condition[ConditionFlag.InFlight])
-            {
-                logger.LogInformation("Not flying, not attempting to land");
-                return false;
-            }
-
-            _landing = AttemptLanding();
-            _continueAt = DateTime.Now.AddSeconds(0.25);
-            return true;
-        }
-
-        public override ETaskResult Update()
-        {
-            if (DateTime.Now < _continueAt)
-                return ETaskResult.StillRunning;
-
-            if (condition[ConditionFlag.InFlight])
-            {
-                if (!_landing)
-                {
-                    _landing = AttemptLanding();
-                    _continueAt = DateTime.Now.AddSeconds(0.25);
-                }
-
-                return ETaskResult.StillRunning;
-            }
-
-            return ETaskResult.TaskComplete;
-        }
-
-        private unsafe bool AttemptLanding()
-        {
-            var character = (Character*)(clientState.LocalPlayer?.Address ?? 0);
-            if (character != null)
-            {
-                if (ActionManager.Instance()->GetActionStatus(ActionType.GeneralAction, 23) == 0)
-                {
-                    logger.LogInformation("Attempting to land");
-                    return ActionManager.Instance()->UseAction(ActionType.GeneralAction, 23);
-                }
-            }
-
-            return false;
-        }
-
-        public override bool ShouldInterruptOnDamage() => false;
-    }
 }
diff --git a/Questionable/Controller/Steps/Movement/WaitForNearDataId.cs b/Questionable/Controller/Steps/Movement/WaitForNearDataId.cs
new file mode 100644 (file)
index 0000000..a08c8a9
--- /dev/null
@@ -0,0 +1,7 @@
+
+namespace Questionable.Controller.Steps.Movement;
+
+internal sealed record WaitForNearDataId(uint DataId, float StopDistance) : ITask
+{
+    public bool ShouldRedoOnInterrupt() => true;
+}
diff --git a/Questionable/Controller/Steps/Movement/WaitForNearDataIdExecutor.cs b/Questionable/Controller/Steps/Movement/WaitForNearDataIdExecutor.cs
new file mode 100644 (file)
index 0000000..a958a2e
--- /dev/null
@@ -0,0 +1,26 @@
+using Dalamud.Game.ClientState.Objects.Types;
+using Dalamud.Plugin.Services;
+using Questionable.Functions;
+
+namespace Questionable.Controller.Steps.Movement;
+
+internal sealed class WaitForNearDataIdExecutor(
+    GameFunctions gameFunctions,
+    IClientState clientState) : TaskExecutor<WaitForNearDataId>
+{
+    protected override bool Start() => true;
+
+    public override ETaskResult Update()
+    {
+        IGameObject? gameObject = gameFunctions.FindObjectByDataId(Task.DataId);
+        if (gameObject == null ||
+            (gameObject.Position - clientState.LocalPlayer!.Position).Length() > Task.StopDistance)
+        {
+            throw new TaskException("Object not found or too far away, no position so we can't move");
+        }
+
+        return ETaskResult.TaskComplete;
+    }
+
+    public override bool ShouldInterruptOnDamage() => false;
+}
index ef15310..82d3e40 100644 (file)
@@ -176,8 +176,8 @@ public sealed class QuestionablePlugin : IDalamudPlugin
         serviceCollection
             .AddTaskFactoryAndExecutor<WaitAtStart.WaitDelay, WaitAtStart.Factory, WaitAtStart.WaitDelayExecutor>();
         serviceCollection.AddTaskFactoryAndExecutor<MoveTask, MoveTo.Factory, MoveExecutor>();
-        serviceCollection.AddTaskExecutor<MoveTo.WaitForNearDataId, MoveTo.WaitForNearDataIdExecutor>();
-        serviceCollection.AddTaskExecutor<MoveTo.LandTask, MoveTo.LandExecutor>();
+        serviceCollection.AddTaskExecutor<WaitForNearDataId, WaitForNearDataIdExecutor>();
+        serviceCollection.AddTaskExecutor<LandTask, LandExecutor>();
         serviceCollection
             .AddTaskFactoryAndExecutor<SendNotification.Task, SendNotification.Factory, SendNotification.Executor>();