Delay logic when to mount to after using aetherytes/aethernet

arr-p5
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();
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)
{

View 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,
}
}