Delay logic when to mount to after using aetherytes/aethernet
authorLiza Carvelli <liza@carvel.li>
Sun, 16 Jun 2024 14:13:52 +0000 (16:13 +0200)
committerLiza Carvelli <liza@carvel.li>
Sun, 16 Jun 2024 14:13:52 +0000 (16:13 +0200)
Questionable/Controller/Steps/BaseFactory/Move.cs
Questionable/Controller/Steps/BaseTasks/MountTask.cs

index 5c71dc72470b89972edc776fb089fc431051227c..a95ba4abcc8f5787ab236458b7640b4f7949ccde 100644 (file)
@@ -77,14 +77,16 @@ internal static class Move
             float actualDistance = (position - Destination).Length();
 
             if (Step.Mount == true)
-                yield return serviceProvider.GetRequiredService<MountTask>().With(Step.TerritoryId);
+                yield return serviceProvider.GetRequiredService<MountTask>()
+                    .With(Step.TerritoryId, MountTask.EMountIf.Always);
             else if (Step.Mount == false)
                 yield return serviceProvider.GetRequiredService<UnmountTask>();
 
             if (!Step.DisableNavmesh)
             {
-                if (Step.Mount == null && actualDistance > 30f)
-                    yield return serviceProvider.GetRequiredService<MountTask>().With(Step.TerritoryId);
+                if (Step.Mount == null)
+                    yield return serviceProvider.GetRequiredService<MountTask>()
+                        .With(Step.TerritoryId, MountTask.EMountIf.AwayFromPosition, Destination);
 
                 if (actualDistance > distance)
                 {
index f1e816e797388b82d32e3632ccdb30a6f1cd3d3f..5e91484fb5371547aca6925c20ac811727e347bb 100644 (file)
@@ -1,4 +1,5 @@
 using System;
+using System.Numerics;
 using Dalamud.Game.ClientState.Conditions;
 using Dalamud.Plugin.Services;
 using Microsoft.Extensions.Logging;
@@ -10,15 +11,24 @@ internal sealed class MountTask(
     GameFunctions gameFunctions,
     ICondition condition,
     TerritoryData territoryData,
+    IClientState clientState,
     ILogger<MountTask> logger) : ITask
 {
     private ushort _territoryId;
+    private EMountIf _mountIf;
+    private Vector3? _position;
+
     private bool _mountTriggered;
     private DateTime _retryAt = DateTime.MinValue;
 
-    public ITask With(ushort territoryId)
+    public ITask With(ushort territoryId, EMountIf mountIf, Vector3? position = null)
     {
         _territoryId = territoryId;
+        _mountIf = mountIf;
+        _position = position;
+
+        if (_mountIf == EMountIf.AwayFromPosition)
+            ArgumentNullException.ThrowIfNull(position);
         return this;
     }
 
@@ -39,7 +49,21 @@ internal sealed class MountTask(
             return false;
         }
 
-        logger.LogInformation("Step wants a mount, trying to mount in territory {Id}...", _territoryId);
+        if (_mountIf == EMountIf.AwayFromPosition)
+        {
+            Vector3 playerPosition = clientState.LocalPlayer?.Position ?? Vector3.Zero;
+            float distance = (playerPosition - _position.GetValueOrDefault()).Length();
+            if (_territoryId == clientState.TerritoryType && distance < 30f)
+            {
+                logger.LogInformation("Not using mount, as we're close to the target");
+                return false;
+            }
+
+            logger.LogInformation("Want to use mount if away from destination ({Distance} yalms), trying (in territory {Id})...", distance, _territoryId);
+        }
+        else
+            logger.LogInformation("Want to use mount, trying (in territory {Id})...", _territoryId);
+
         if (!condition[ConditionFlag.InCombat])
         {
             _retryAt = DateTime.Now.AddSeconds(0.5);
@@ -77,4 +101,10 @@ internal sealed class MountTask(
     }
 
     public override string ToString() => "Mount";
+
+    public enum EMountIf
+    {
+        Always,
+        AwayFromPosition,
+    }
 }