From e4b5ccec366a46b723774800817700b9530eb6ca Mon Sep 17 00:00:00 2001 From: Liza Carvelli Date: Thu, 29 Aug 2024 15:45:16 +0200 Subject: [PATCH] Update movement logic to handle cases where you're stopped too far away --- .../2632_The Palace of Lost Souls.json | 6 +++-- .../Kurenai/2704_Fathoms Below.json | 3 ++- .../Kurenai/2705_A Part of Your World.json | 3 ++- .../Kurenai/2706_The Elixir of Life.json | 2 ++ .../2484_In Soroban We Trust.json | 3 ++- .../2486_In Darkness the Magatama Dreams.json | 3 ++- QuestPaths/quest-v1.json | 4 ++++ Questionable.Model/Questing/QuestStep.cs | 1 + Questionable/Controller/MovementController.cs | 2 +- .../Controller/Steps/Shared/MoveTo.cs | 24 ++++++++++++++++--- Questionable/Functions/GameFunctions.cs | 15 +++++------- 11 files changed, 47 insertions(+), 19 deletions(-) diff --git a/QuestPaths/4.x - Stormblood/Aether Currents/The Ruby Sea/2632_The Palace of Lost Souls.json b/QuestPaths/4.x - Stormblood/Aether Currents/The Ruby Sea/2632_The Palace of Lost Souls.json index 7425f2d3..fe72918a 100644 --- a/QuestPaths/4.x - Stormblood/Aether Currents/The Ruby Sea/2632_The Palace of Lost Souls.json +++ b/QuestPaths/4.x - Stormblood/Aether Currents/The Ruby Sea/2632_The Palace of Lost Souls.json @@ -50,7 +50,8 @@ }, "TerritoryId": 613, "InteractionType": "WalkTo", - "$": "Sui-no-Sato, NE inside" + "$": "Sui-no-Sato, NE inside", + "RestartNavigationIfCancelled": false }, { "Position": { @@ -122,7 +123,8 @@ }, "TerritoryId": 613, "InteractionType": "WalkTo", - "$": "Sui-no-Sato, NE outside" + "$": "Sui-no-Sato, NE outside", + "RestartNavigationIfCancelled": false }, { "DataId": 1023280, diff --git a/QuestPaths/4.x - Stormblood/Custom Deliveries/Kurenai/2704_Fathoms Below.json b/QuestPaths/4.x - Stormblood/Custom Deliveries/Kurenai/2704_Fathoms Below.json index ef577617..75966772 100644 --- a/QuestPaths/4.x - Stormblood/Custom Deliveries/Kurenai/2704_Fathoms Below.json +++ b/QuestPaths/4.x - Stormblood/Custom Deliveries/Kurenai/2704_Fathoms Below.json @@ -23,7 +23,8 @@ }, "TerritoryId": 613, "InteractionType": "WalkTo", - "$": "Sui-no-Sato, NE outside" + "$": "Sui-no-Sato, NE outside", + "RestartNavigationIfCancelled": false }, { "DataId": 1023280, diff --git a/QuestPaths/4.x - Stormblood/Custom Deliveries/Kurenai/2705_A Part of Your World.json b/QuestPaths/4.x - Stormblood/Custom Deliveries/Kurenai/2705_A Part of Your World.json index 834a2cc1..1fe63872 100644 --- a/QuestPaths/4.x - Stormblood/Custom Deliveries/Kurenai/2705_A Part of Your World.json +++ b/QuestPaths/4.x - Stormblood/Custom Deliveries/Kurenai/2705_A Part of Your World.json @@ -85,7 +85,8 @@ }, "TerritoryId": 613, "InteractionType": "WalkTo", - "$": "Sui-no-Sato, NE outside" + "$": "Sui-no-Sato, NE outside", + "RestartNavigationIfCancelled": false }, { "DataId": 1023280, diff --git a/QuestPaths/4.x - Stormblood/Custom Deliveries/Kurenai/2706_The Elixir of Life.json b/QuestPaths/4.x - Stormblood/Custom Deliveries/Kurenai/2706_The Elixir of Life.json index fed711ae..738d856d 100644 --- a/QuestPaths/4.x - Stormblood/Custom Deliveries/Kurenai/2706_The Elixir of Life.json +++ b/QuestPaths/4.x - Stormblood/Custom Deliveries/Kurenai/2706_The Elixir of Life.json @@ -91,6 +91,7 @@ "TerritoryId": 613, "InteractionType": "WalkTo", "$": "Exile, outside", + "RestartNavigationIfCancelled": false, "Fly": true }, { @@ -164,6 +165,7 @@ "TerritoryId": 613, "InteractionType": "WalkTo", "$": "Sui-no-Sato, SW outside", + "RestartNavigationIfCancelled": false, "Fly": true }, { diff --git a/QuestPaths/4.x - Stormblood/MSQ/A3.1-Ruby Sea/2484_In Soroban We Trust.json b/QuestPaths/4.x - Stormblood/MSQ/A3.1-Ruby Sea/2484_In Soroban We Trust.json index b3a2e566..6664fb25 100644 --- a/QuestPaths/4.x - Stormblood/MSQ/A3.1-Ruby Sea/2484_In Soroban We Trust.json +++ b/QuestPaths/4.x - Stormblood/MSQ/A3.1-Ruby Sea/2484_In Soroban We Trust.json @@ -49,7 +49,8 @@ }, "TerritoryId": 613, "InteractionType": "WalkTo", - "$": "Sui-no-Sato, NE outside" + "$": "Sui-no-Sato, NE outside", + "RestartNavigationIfCancelled": false }, { "DataId": 1019970, diff --git a/QuestPaths/4.x - Stormblood/MSQ/A3.1-Ruby Sea/2486_In Darkness the Magatama Dreams.json b/QuestPaths/4.x - Stormblood/MSQ/A3.1-Ruby Sea/2486_In Darkness the Magatama Dreams.json index 9b97dfe0..933b8b9e 100644 --- a/QuestPaths/4.x - Stormblood/MSQ/A3.1-Ruby Sea/2486_In Darkness the Magatama Dreams.json +++ b/QuestPaths/4.x - Stormblood/MSQ/A3.1-Ruby Sea/2486_In Darkness the Magatama Dreams.json @@ -28,7 +28,8 @@ }, "TerritoryId": 613, "InteractionType": "WalkTo", - "$": "Sui-no-Sato, NE inside" + "$": "Sui-no-Sato, NE inside", + "RestartNavigationIfCancelled": false }, { "DataId": 1019978, diff --git a/QuestPaths/quest-v1.json b/QuestPaths/quest-v1.json index 93efd3c0..09e47075 100644 --- a/QuestPaths/quest-v1.json +++ b/QuestPaths/quest-v1.json @@ -92,6 +92,10 @@ "type": "boolean", "description": "Most interactions with objects are checked for a Y (height) difference of 2 in-game units. If set to true, the game won't attempt to get any closer if the height difference is larger than this." }, + "RestartNavigationIfCancelled": { + "type": "boolean", + "description": "For some specific loading screen transitions (e.g. when entering/leaving the water through the portals in the ruby sea), setting this to 'false' means it won't re-attempt to move to the portal after the loading animation" + }, "TerritoryId": { "type": "integer", "description": "The territory id associated with the location", diff --git a/Questionable.Model/Questing/QuestStep.cs b/Questionable.Model/Questing/QuestStep.cs index a09386bc..5a23e6e4 100644 --- a/Questionable.Model/Questing/QuestStep.cs +++ b/Questionable.Model/Questing/QuestStep.cs @@ -36,6 +36,7 @@ public sealed class QuestStep public bool? Land { get; set; } public bool? Sprint { get; set; } public bool? IgnoreDistanceToObject { get; set; } + public bool? RestartNavigationIfCancelled { get; set; } public string? Comment { get; set; } /// diff --git a/Questionable/Controller/MovementController.cs b/Questionable/Controller/MovementController.cs index 6809c9f1..676d51d0 100644 --- a/Questionable/Controller/MovementController.cs +++ b/Questionable/Controller/MovementController.cs @@ -151,7 +151,7 @@ internal sealed class MovementController : IDisposable if (IsPathRunning && Destination != null) { - if (_gameFunctions.IsLoadingScreenVisible(false)) + if (_gameFunctions.IsLoadingScreenVisible()) { _logger.LogInformation("Stopping movement, loading screen visible"); Stop(); diff --git a/Questionable/Controller/Steps/Shared/MoveTo.cs b/Questionable/Controller/Steps/Shared/MoveTo.cs index a24fb2f0..33192674 100644 --- a/Questionable/Controller/Steps/Shared/MoveTo.cs +++ b/Questionable/Controller/Steps/Shared/MoveTo.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; using System.Globalization; using System.Numerics; using Dalamud.Game.ClientState.Conditions; @@ -67,7 +68,7 @@ internal static class MoveTo public ITask Move(MoveParams moveParams) { return new MoveInternal(moveParams, movementController, gameFunctions, - loggerFactory.CreateLogger(), condition, dataManager); + loggerFactory.CreateLogger(), condition, clientState, dataManager); } public ITask Land() @@ -163,20 +164,24 @@ internal static class MoveTo private readonly MovementController _movementController; private readonly ILogger _logger; private readonly ICondition _condition; + private readonly IClientState _clientState; private readonly Action _startAction; private readonly Vector3 _destination; + private readonly MoveParams _moveParams; public MoveInternal(MoveParams moveParams, MovementController movementController, GameFunctions gameFunctions, ILogger logger, ICondition condition, + IClientState clientState, IDataManager dataManager) { _movementController = movementController; _logger = logger; _condition = condition; + _clientState = clientState; _cannotExecuteAtThisTime = dataManager.GetString(579, x => x.Text)!; _destination = moveParams.Destination; @@ -206,6 +211,8 @@ internal static class MoveTo ignoreDistanceToObject: moveParams.IgnoreDistanceToObject, land: moveParams.Land); } + + _moveParams = moveParams; } public bool Start() @@ -224,6 +231,15 @@ internal static class MoveTo if (movementStartedAt == DateTime.MaxValue || movementStartedAt.AddSeconds(2) >= DateTime.Now) return ETaskResult.StillRunning; + if (_moveParams.RestartNavigation && + Vector3.Distance(_clientState.LocalPlayer!.Position, _destination) > + (_moveParams.StopDistance ?? QuestStep.DefaultStopDistance) + 5f) + { + _logger.LogInformation("Looks like movement was interrupted, re-attempting to move"); + _startAction(); + return ETaskResult.StillRunning; + } + return ETaskResult.TaskComplete; } @@ -248,7 +264,8 @@ internal static class MoveTo bool Sprint = true, bool Fly = false, bool Land = false, - bool IgnoreDistanceToObject = false) + bool IgnoreDistanceToObject = false, + bool RestartNavigation = true) { public MoveParams(QuestStep step, Vector3 destination) : this(step.TerritoryId, @@ -259,7 +276,8 @@ internal static class MoveTo step.Sprint != false, step.Fly == true, step.Land == true, - step.IgnoreDistanceToObject == true) + step.IgnoreDistanceToObject == true, + step.RestartNavigationIfCancelled != false) { } } diff --git a/Questionable/Functions/GameFunctions.cs b/Questionable/Functions/GameFunctions.cs index 360e882d..51795705 100644 --- a/Questionable/Functions/GameFunctions.cs +++ b/Questionable/Functions/GameFunctions.cs @@ -398,7 +398,7 @@ internal sealed unsafe class GameFunctions if (!_clientState.IsLoggedIn || _clientState.LocalPlayer == null) return true; - if (IsLoadingScreenVisible(true)) + if (IsLoadingScreenVisible()) return true; if (_condition[ConditionFlag.Crafting]) @@ -438,19 +438,16 @@ internal sealed unsafe class GameFunctions flags.Contains(ConditionFlag.OccupiedInQuestEvent); } - public bool IsLoadingScreenVisible(bool all) + public bool IsLoadingScreenVisible() { if (_gameGui.TryGetAddonByName("FadeMiddle", out AtkUnitBase* fade) && LAddon.IsAddonReady(fade) && fade->IsVisible) return true; - if (all) - { - if (_gameGui.TryGetAddonByName("FadeBack", out fade) && LAddon.IsAddonReady(fade) && fade->IsVisible) - return true; + if (_gameGui.TryGetAddonByName("FadeBack", out fade) && LAddon.IsAddonReady(fade) && fade->IsVisible) + return true; - if (_gameGui.TryGetAddonByName("NowLoading", out fade) && LAddon.IsAddonReady(fade) && fade->IsVisible) - return true; - } + if (_gameGui.TryGetAddonByName("NowLoading", out fade) && LAddon.IsAddonReady(fade) && fade->IsVisible) + return true; return false; }