1
0
forked from liza/Questionable

Hopefully fix diving to swimming transition

This commit is contained in:
Liza 2024-06-11 17:35:30 +02:00
parent 97289c647f
commit 2327426ae5
Signed by: liza
GPG Key ID: 7199F8D727D55F67

View File

@ -118,6 +118,19 @@ internal sealed class MovementController : IDisposable
return; return;
} }
if (Destination is { IsFlying: true } && _condition[ConditionFlag.Swimming])
{
_logger.LogInformation("Flying but swimming, restarting as non-flying path...");
var dest = Destination;
Stop();
if (dest.UseNavmesh)
NavigateTo(EMovementType.None, dest.DataId, dest.Position, false, false, dest.StopDistance);
else
NavigateTo(EMovementType.None, dest.DataId, [dest.Position], false, false, dest.StopDistance);
return;
}
Vector3 localPlayerPosition = _clientState.LocalPlayer?.Position ?? Vector3.Zero; Vector3 localPlayerPosition = _clientState.LocalPlayer?.Position ?? Vector3.Zero;
if ((localPlayerPosition - Destination.Position).Length() < Destination.StopDistance) if ((localPlayerPosition - Destination.Position).Length() < Destination.StopDistance)
{ {
@ -174,7 +187,7 @@ internal sealed class MovementController : IDisposable
} }
private void PrepareNavigation(EMovementType type, uint? dataId, Vector3 to, bool fly, bool sprint, private void PrepareNavigation(EMovementType type, uint? dataId, Vector3 to, bool fly, bool sprint,
float? stopDistance) float? stopDistance, bool useNavmesh)
{ {
ResetPathfinding(); ResetPathfinding();
@ -184,7 +197,8 @@ internal sealed class MovementController : IDisposable
_gameFunctions.ExecuteCommand("/automove off"); _gameFunctions.ExecuteCommand("/automove off");
} }
Destination = new DestinationData(dataId, to, stopDistance ?? (DefaultStopDistance - 0.2f), fly, sprint); Destination = new DestinationData(dataId, to, stopDistance ?? (DefaultStopDistance - 0.2f), fly, sprint,
useNavmesh);
MovementStartedAt = DateTime.MaxValue; MovementStartedAt = DateTime.MaxValue;
} }
@ -192,7 +206,7 @@ internal sealed class MovementController : IDisposable
float? stopDistance = null) float? stopDistance = null)
{ {
fly |= _condition[ConditionFlag.Diving]; fly |= _condition[ConditionFlag.Diving];
PrepareNavigation(type, dataId, to, fly, sprint, stopDistance); PrepareNavigation(type, dataId, to, fly, sprint, stopDistance, true);
_logger.LogInformation("Pathfinding to {Destination}", Destination); _logger.LogInformation("Pathfinding to {Destination}", Destination);
_cancellationTokenSource = new(); _cancellationTokenSource = new();
@ -205,7 +219,7 @@ internal sealed class MovementController : IDisposable
float? stopDistance) float? stopDistance)
{ {
fly |= _condition[ConditionFlag.Diving]; fly |= _condition[ConditionFlag.Diving];
PrepareNavigation(type, dataId, to.Last(), fly, sprint, stopDistance); PrepareNavigation(type, dataId, to.Last(), fly, sprint, stopDistance, false);
_logger.LogInformation("Moving to {Destination}", Destination); _logger.LogInformation("Moving to {Destination}", Destination);
_navmeshIpc.MoveTo(to, fly); _navmeshIpc.MoveTo(to, fly);
@ -252,7 +266,8 @@ internal sealed class MovementController : IDisposable
Vector3 Position, Vector3 Position,
float StopDistance, float StopDistance,
bool IsFlying, bool IsFlying,
bool CanSprint); bool CanSprint,
bool UseNavmesh);
public sealed class PathfindingFailedException : Exception public sealed class PathfindingFailedException : Exception
{ {