1
0
forked from liza/Questionable

Update movement logic to handle cases where you're stopped too far away

This commit is contained in:
Liza 2024-08-29 15:45:16 +02:00
parent 25bfb6033b
commit e4b5ccec36
Signed by: liza
GPG Key ID: 7199F8D727D55F67
11 changed files with 47 additions and 19 deletions

View File

@ -50,7 +50,8 @@
}, },
"TerritoryId": 613, "TerritoryId": 613,
"InteractionType": "WalkTo", "InteractionType": "WalkTo",
"$": "Sui-no-Sato, NE inside" "$": "Sui-no-Sato, NE inside",
"RestartNavigationIfCancelled": false
}, },
{ {
"Position": { "Position": {
@ -122,7 +123,8 @@
}, },
"TerritoryId": 613, "TerritoryId": 613,
"InteractionType": "WalkTo", "InteractionType": "WalkTo",
"$": "Sui-no-Sato, NE outside" "$": "Sui-no-Sato, NE outside",
"RestartNavigationIfCancelled": false
}, },
{ {
"DataId": 1023280, "DataId": 1023280,

View File

@ -23,7 +23,8 @@
}, },
"TerritoryId": 613, "TerritoryId": 613,
"InteractionType": "WalkTo", "InteractionType": "WalkTo",
"$": "Sui-no-Sato, NE outside" "$": "Sui-no-Sato, NE outside",
"RestartNavigationIfCancelled": false
}, },
{ {
"DataId": 1023280, "DataId": 1023280,

View File

@ -85,7 +85,8 @@
}, },
"TerritoryId": 613, "TerritoryId": 613,
"InteractionType": "WalkTo", "InteractionType": "WalkTo",
"$": "Sui-no-Sato, NE outside" "$": "Sui-no-Sato, NE outside",
"RestartNavigationIfCancelled": false
}, },
{ {
"DataId": 1023280, "DataId": 1023280,

View File

@ -91,6 +91,7 @@
"TerritoryId": 613, "TerritoryId": 613,
"InteractionType": "WalkTo", "InteractionType": "WalkTo",
"$": "Exile, outside", "$": "Exile, outside",
"RestartNavigationIfCancelled": false,
"Fly": true "Fly": true
}, },
{ {
@ -164,6 +165,7 @@
"TerritoryId": 613, "TerritoryId": 613,
"InteractionType": "WalkTo", "InteractionType": "WalkTo",
"$": "Sui-no-Sato, SW outside", "$": "Sui-no-Sato, SW outside",
"RestartNavigationIfCancelled": false,
"Fly": true "Fly": true
}, },
{ {

View File

@ -49,7 +49,8 @@
}, },
"TerritoryId": 613, "TerritoryId": 613,
"InteractionType": "WalkTo", "InteractionType": "WalkTo",
"$": "Sui-no-Sato, NE outside" "$": "Sui-no-Sato, NE outside",
"RestartNavigationIfCancelled": false
}, },
{ {
"DataId": 1019970, "DataId": 1019970,

View File

@ -28,7 +28,8 @@
}, },
"TerritoryId": 613, "TerritoryId": 613,
"InteractionType": "WalkTo", "InteractionType": "WalkTo",
"$": "Sui-no-Sato, NE inside" "$": "Sui-no-Sato, NE inside",
"RestartNavigationIfCancelled": false
}, },
{ {
"DataId": 1019978, "DataId": 1019978,

View File

@ -92,6 +92,10 @@
"type": "boolean", "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." "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": { "TerritoryId": {
"type": "integer", "type": "integer",
"description": "The territory id associated with the location", "description": "The territory id associated with the location",

View File

@ -36,6 +36,7 @@ public sealed class QuestStep
public bool? Land { get; set; } public bool? Land { get; set; }
public bool? Sprint { get; set; } public bool? Sprint { get; set; }
public bool? IgnoreDistanceToObject { get; set; } public bool? IgnoreDistanceToObject { get; set; }
public bool? RestartNavigationIfCancelled { get; set; }
public string? Comment { get; set; } public string? Comment { get; set; }
/// <summary> /// <summary>

View File

@ -151,7 +151,7 @@ internal sealed class MovementController : IDisposable
if (IsPathRunning && Destination != null) if (IsPathRunning && Destination != null)
{ {
if (_gameFunctions.IsLoadingScreenVisible(false)) if (_gameFunctions.IsLoadingScreenVisible())
{ {
_logger.LogInformation("Stopping movement, loading screen visible"); _logger.LogInformation("Stopping movement, loading screen visible");
Stop(); Stop();

View File

@ -1,5 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Globalization; using System.Globalization;
using System.Numerics; using System.Numerics;
using Dalamud.Game.ClientState.Conditions; using Dalamud.Game.ClientState.Conditions;
@ -67,7 +68,7 @@ internal static class MoveTo
public ITask Move(MoveParams moveParams) public ITask Move(MoveParams moveParams)
{ {
return new MoveInternal(moveParams, movementController, gameFunctions, return new MoveInternal(moveParams, movementController, gameFunctions,
loggerFactory.CreateLogger<MoveInternal>(), condition, dataManager); loggerFactory.CreateLogger<MoveInternal>(), condition, clientState, dataManager);
} }
public ITask Land() public ITask Land()
@ -163,20 +164,24 @@ internal static class MoveTo
private readonly MovementController _movementController; private readonly MovementController _movementController;
private readonly ILogger<MoveInternal> _logger; private readonly ILogger<MoveInternal> _logger;
private readonly ICondition _condition; private readonly ICondition _condition;
private readonly IClientState _clientState;
private readonly Action _startAction; private readonly Action _startAction;
private readonly Vector3 _destination; private readonly Vector3 _destination;
private readonly MoveParams _moveParams;
public MoveInternal(MoveParams moveParams, public MoveInternal(MoveParams moveParams,
MovementController movementController, MovementController movementController,
GameFunctions gameFunctions, GameFunctions gameFunctions,
ILogger<MoveInternal> logger, ILogger<MoveInternal> logger,
ICondition condition, ICondition condition,
IClientState clientState,
IDataManager dataManager) IDataManager dataManager)
{ {
_movementController = movementController; _movementController = movementController;
_logger = logger; _logger = logger;
_condition = condition; _condition = condition;
_clientState = clientState;
_cannotExecuteAtThisTime = dataManager.GetString<LogMessage>(579, x => x.Text)!; _cannotExecuteAtThisTime = dataManager.GetString<LogMessage>(579, x => x.Text)!;
_destination = moveParams.Destination; _destination = moveParams.Destination;
@ -206,6 +211,8 @@ internal static class MoveTo
ignoreDistanceToObject: moveParams.IgnoreDistanceToObject, ignoreDistanceToObject: moveParams.IgnoreDistanceToObject,
land: moveParams.Land); land: moveParams.Land);
} }
_moveParams = moveParams;
} }
public bool Start() public bool Start()
@ -224,6 +231,15 @@ internal static class MoveTo
if (movementStartedAt == DateTime.MaxValue || movementStartedAt.AddSeconds(2) >= DateTime.Now) if (movementStartedAt == DateTime.MaxValue || movementStartedAt.AddSeconds(2) >= DateTime.Now)
return ETaskResult.StillRunning; 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; return ETaskResult.TaskComplete;
} }
@ -248,7 +264,8 @@ internal static class MoveTo
bool Sprint = true, bool Sprint = true,
bool Fly = false, bool Fly = false,
bool Land = false, bool Land = false,
bool IgnoreDistanceToObject = false) bool IgnoreDistanceToObject = false,
bool RestartNavigation = true)
{ {
public MoveParams(QuestStep step, Vector3 destination) public MoveParams(QuestStep step, Vector3 destination)
: this(step.TerritoryId, : this(step.TerritoryId,
@ -259,7 +276,8 @@ internal static class MoveTo
step.Sprint != false, step.Sprint != false,
step.Fly == true, step.Fly == true,
step.Land == true, step.Land == true,
step.IgnoreDistanceToObject == true) step.IgnoreDistanceToObject == true,
step.RestartNavigationIfCancelled != false)
{ {
} }
} }

View File

@ -398,7 +398,7 @@ internal sealed unsafe class GameFunctions
if (!_clientState.IsLoggedIn || _clientState.LocalPlayer == null) if (!_clientState.IsLoggedIn || _clientState.LocalPlayer == null)
return true; return true;
if (IsLoadingScreenVisible(true)) if (IsLoadingScreenVisible())
return true; return true;
if (_condition[ConditionFlag.Crafting]) if (_condition[ConditionFlag.Crafting])
@ -438,19 +438,16 @@ internal sealed unsafe class GameFunctions
flags.Contains(ConditionFlag.OccupiedInQuestEvent); flags.Contains(ConditionFlag.OccupiedInQuestEvent);
} }
public bool IsLoadingScreenVisible(bool all) public bool IsLoadingScreenVisible()
{ {
if (_gameGui.TryGetAddonByName("FadeMiddle", out AtkUnitBase* fade) && LAddon.IsAddonReady(fade) && fade->IsVisible) if (_gameGui.TryGetAddonByName("FadeMiddle", out AtkUnitBase* fade) && LAddon.IsAddonReady(fade) && fade->IsVisible)
return true; return true;
if (all)
{
if (_gameGui.TryGetAddonByName("FadeBack", out fade) && LAddon.IsAddonReady(fade) && fade->IsVisible) if (_gameGui.TryGetAddonByName("FadeBack", out fade) && LAddon.IsAddonReady(fade) && fade->IsVisible)
return true; return true;
if (_gameGui.TryGetAddonByName("NowLoading", out fade) && LAddon.IsAddonReady(fade) && fade->IsVisible) if (_gameGui.TryGetAddonByName("NowLoading", out fade) && LAddon.IsAddonReady(fade) && fade->IsVisible)
return true; return true;
}
return false; return false;
} }