Delay logic when to mount to after using aetherytes/aethernet

This commit is contained in:
Liza 2024-06-16 16:13:52 +02:00
parent 8e12b28f93
commit 65187cdaee
Signed by: liza
GPG Key ID: 7199F8D727D55F67
2 changed files with 37 additions and 5 deletions

View File

@ -77,14 +77,16 @@ internal static class Move
float actualDistance = (position - Destination).Length(); float actualDistance = (position - Destination).Length();
if (Step.Mount == true) 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) else if (Step.Mount == false)
yield return serviceProvider.GetRequiredService<UnmountTask>(); yield return serviceProvider.GetRequiredService<UnmountTask>();
if (!Step.DisableNavmesh) if (!Step.DisableNavmesh)
{ {
if (Step.Mount == null && actualDistance > 30f) if (Step.Mount == null)
yield return serviceProvider.GetRequiredService<MountTask>().With(Step.TerritoryId); yield return serviceProvider.GetRequiredService<MountTask>()
.With(Step.TerritoryId, MountTask.EMountIf.AwayFromPosition, Destination);
if (actualDistance > distance) if (actualDistance > distance)
{ {

View File

@ -1,4 +1,5 @@
using System; using System;
using System.Numerics;
using Dalamud.Game.ClientState.Conditions; using Dalamud.Game.ClientState.Conditions;
using Dalamud.Plugin.Services; using Dalamud.Plugin.Services;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
@ -10,15 +11,24 @@ internal sealed class MountTask(
GameFunctions gameFunctions, GameFunctions gameFunctions,
ICondition condition, ICondition condition,
TerritoryData territoryData, TerritoryData territoryData,
IClientState clientState,
ILogger<MountTask> logger) : ITask ILogger<MountTask> logger) : ITask
{ {
private ushort _territoryId; private ushort _territoryId;
private EMountIf _mountIf;
private Vector3? _position;
private bool _mountTriggered; private bool _mountTriggered;
private DateTime _retryAt = DateTime.MinValue; private DateTime _retryAt = DateTime.MinValue;
public ITask With(ushort territoryId) public ITask With(ushort territoryId, EMountIf mountIf, Vector3? position = null)
{ {
_territoryId = territoryId; _territoryId = territoryId;
_mountIf = mountIf;
_position = position;
if (_mountIf == EMountIf.AwayFromPosition)
ArgumentNullException.ThrowIfNull(position);
return this; return this;
} }
@ -39,7 +49,21 @@ internal sealed class MountTask(
return false; 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]) if (!condition[ConditionFlag.InCombat])
{ {
_retryAt = DateTime.Now.AddSeconds(0.5); _retryAt = DateTime.Now.AddSeconds(0.5);
@ -77,4 +101,10 @@ internal sealed class MountTask(
} }
public override string ToString() => "Mount"; public override string ToString() => "Mount";
public enum EMountIf
{
Always,
AwayFromPosition,
}
} }