Interrupts: Add a special case for certain movement tasks
authorLiza Carvelli <liza@carvel.li>
Tue, 21 Jan 2025 20:44:08 +0000 (21:44 +0100)
committerLiza Carvelli <liza@carvel.li>
Tue, 21 Jan 2025 20:44:08 +0000 (21:44 +0100)
Questionable/Controller/Steps/Shared/MoveTo.cs

index 656891080aa982f30bf01abca9ba187fe5c30569..60d83aedd3ad2eee59a4eba88d1dbc8b05534aff 100644 (file)
@@ -228,6 +228,17 @@ internal static class MoveTo
                             }
                         }
                     }
+                    else if (!ShouldResolveCombatBeforeNextInteraction() &&
+                             _movementController is { IsPathfinding: false, IsPathRunning: false } &&
+                             mountExecutor.EvaluateMountState() == Mount.MountResult.DontMount)
+                    {
+                        // except for e.g. jumping which would maybe break if combat navigates us away, if we don't
+                        // need a mount anymore we can just skip combat and assume that the interruption is handled
+                        // later.
+                        //
+                        // without this, the character would just stand around while getting hit
+                        _nestedExecutor = (new NoOpTaskExecutor(), new NoOpTask(), true);
+                    }
                 }
                 else if (nestedExecutor.Executor.Update() == ETaskResult.TaskComplete)
                 {
@@ -286,7 +297,16 @@ internal static class MoveTo
             return base.WasInterrupted();
         }
 
-        public override bool ShouldInterruptOnDamage() => false;
+        public override bool ShouldInterruptOnDamage()
+        {
+            // have we stopped moving, and are we
+            // (a) waiting for a mount to complete, or
+            // (b) want combat to be done before any other interaction?
+            return _movementController is { IsPathfinding: false, IsPathRunning: false } &&
+                   (_nestedExecutor is { Triggered: false, Executor: Mount.MountExecutor } || ShouldResolveCombatBeforeNextInteraction());
+        }
+
+        private bool ShouldResolveCombatBeforeNextInteraction() => Task.InteractionType is EInteractionType.Jump;
 
         public bool OnErrorToast(SeString message)
         {