diff --git a/Questionable/Controller/Steps/BaseFactory/Move.cs b/Questionable/Controller/Steps/BaseFactory/Move.cs index 5c71dc724..a95ba4abc 100644 --- a/Questionable/Controller/Steps/BaseFactory/Move.cs +++ b/Questionable/Controller/Steps/BaseFactory/Move.cs @@ -77,14 +77,16 @@ internal static class Move float actualDistance = (position - Destination).Length(); if (Step.Mount == true) - yield return serviceProvider.GetRequiredService().With(Step.TerritoryId); + yield return serviceProvider.GetRequiredService() + .With(Step.TerritoryId, MountTask.EMountIf.Always); else if (Step.Mount == false) yield return serviceProvider.GetRequiredService(); if (!Step.DisableNavmesh) { - if (Step.Mount == null && actualDistance > 30f) - yield return serviceProvider.GetRequiredService().With(Step.TerritoryId); + if (Step.Mount == null) + yield return serviceProvider.GetRequiredService() + .With(Step.TerritoryId, MountTask.EMountIf.AwayFromPosition, Destination); if (actualDistance > distance) { diff --git a/Questionable/Controller/Steps/BaseTasks/MountTask.cs b/Questionable/Controller/Steps/BaseTasks/MountTask.cs index f1e816e79..5e91484fb 100644 --- a/Questionable/Controller/Steps/BaseTasks/MountTask.cs +++ b/Questionable/Controller/Steps/BaseTasks/MountTask.cs @@ -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 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, + } }