From b92531f2ec4ee5ec4276968c51899892d3503451 Mon Sep 17 00:00:00 2001 From: Liza Carvelli Date: Wed, 4 Sep 2024 23:18:25 +0200 Subject: [PATCH] Restart movement if you're unmounted while moving (Logistics of War) --- Questionable/Controller/MovementController.cs | 39 ++++++++++++------- 1 file changed, 24 insertions(+), 15 deletions(-) diff --git a/Questionable/Controller/MovementController.cs b/Questionable/Controller/MovementController.cs index 676d51d0..95950e14 100644 --- a/Questionable/Controller/MovementController.cs +++ b/Questionable/Controller/MovementController.cs @@ -120,7 +120,8 @@ internal sealed class MovementController : IDisposable { Destination.NavmeshCalculations++; Destination.PartialRoute.AddRange(navPoints); - _logger.LogInformation("Running navmesh recalculation with fudged point ({From} to {To})", navPoints.Last(), Destination.Position); + _logger.LogInformation("Running navmesh recalculation with fudged point ({From} to {To})", + navPoints.Last(), Destination.Position); _cancellationTokenSource = new(); _cancellationTokenSource.CancelAfter(TimeSpan.FromSeconds(30)); @@ -161,20 +162,12 @@ internal sealed class MovementController : IDisposable 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, - dest.IgnoreDistanceToObject); - } - else - { - NavigateTo(EMovementType.None, dest.DataId, [dest.Position], false, false, dest.StopDistance, - dest.IgnoreDistanceToObject); - } - + Restart(Destination); + } + else if (Destination is { IsFlying: true } && !_condition[ConditionFlag.Mounted]) + { + _logger.LogInformation("Flying but not mounted, restarting as non-flying path..."); + Restart(Destination); return; } @@ -260,6 +253,22 @@ internal sealed class MovementController : IDisposable } } + private void Restart(DestinationData destination) + { + Stop(); + + if (destination.UseNavmesh) + { + NavigateTo(EMovementType.None, destination.DataId, destination.Position, false, false, + destination.StopDistance, destination.IgnoreDistanceToObject); + } + else + { + NavigateTo(EMovementType.None, destination.DataId, [destination.Position], false, false, + destination.StopDistance, destination.IgnoreDistanceToObject); + } + } + private bool IsOnFlightPath(Vector3 p) { Vector3? pointOnFloor = _navmeshIpc.GetPointOnFloor(p, true);