using System.Globalization; using System.Linq; using System.Numerics; using Dalamud.Game.ClientState.Objects.Enums; using Dalamud.Game.ClientState.Objects.Types; using Dalamud.Game.Text.SeStringHandling; using Dalamud.Plugin.Services; using Microsoft.Extensions.Logging; using Questionable.Controller.Steps.Movement; using Questionable.Functions; using Questionable.Model; using Questionable.Model.Gathering; using Questionable.Model.Questing; namespace Questionable.Controller.Steps.Gathering; internal static class MoveToLandingLocation { internal sealed record Task(ushort TerritoryId, bool FlyBetweenNodes, GatheringNode GatheringNode) : ITask { public override string ToString() { return $"Land/{FlyBetweenNodes}"; } } internal sealed class MoveToLandingLocationExecutor(MoveExecutor moveExecutor, GameFunctions gameFunctions, IObjectTable objectTable, ILogger logger) : TaskExecutor(), IToastAware, ITaskExecutor { private ITask _moveTask; protected override bool Start() { GatheringLocation location = base.Task.GatheringNode.Locations.First(); if (base.Task.GatheringNode.Locations.Count > 1) { IGameObject gameObject = objectTable.SingleOrDefault((IGameObject x) => x.ObjectKind == ObjectKind.GatheringPoint && x.BaseId == base.Task.GatheringNode.DataId && x.IsTargetable); if (gameObject == null) { return false; } location = base.Task.GatheringNode.Locations.Single((GatheringLocation x) => Vector3.Distance(x.Position, gameObject.Position) < 0.1f); } var (vector, num, num2) = GatheringMath.CalculateLandingLocation(location); logger.LogInformation("Preliminary landing location: {Location}, with degrees = {Degrees}, range = {Range}", vector.ToString("G", CultureInfo.InvariantCulture), num, num2); bool flag = base.Task.FlyBetweenNodes && gameFunctions.IsFlyingUnlocked(base.Task.TerritoryId); ushort territoryId = base.Task.TerritoryId; Vector3 destination = vector; float? stopDistance = 0.25f; uint? dataId = base.Task.GatheringNode.DataId; bool fly = flag; _moveTask = new MoveTask(territoryId, destination, null, stopDistance, dataId, DisableNavmesh: false, null, fly, Land: false, IgnoreDistanceToObject: true, RestartNavigation: true, EInteractionType.Gather); return moveExecutor.Start(_moveTask); } public override ETaskResult Update() { return moveExecutor.Update(); } public bool OnErrorToast(SeString message) { return moveExecutor.OnErrorToast(message); } public override bool ShouldInterruptOnDamage() { return moveExecutor.ShouldInterruptOnDamage(); } } }