From 86b7009acba332cb0a85c6b2266665ecbc25371a Mon Sep 17 00:00:00 2001 From: Xian55 <367101+Xian55@users.noreply.github.com> Date: Sat, 21 Dec 2024 21:40:11 +0100 Subject: [PATCH] Core: FleeGoal: Add the ability to use custom KeyActions during goal execution. --- Core/Goals/FleeGoal.cs | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/Core/Goals/FleeGoal.cs b/Core/Goals/FleeGoal.cs index 19930e30..0097df7e 100644 --- a/Core/Goals/FleeGoal.cs +++ b/Core/Goals/FleeGoal.cs @@ -21,6 +21,7 @@ public sealed class FleeGoal : GoapGoal, IRouteProvider private readonly PlayerReader playerReader; private readonly Navigation navigation; private readonly AddonBits bits; + private readonly CastingHandler castingHandler; private readonly SafeSpotCollector safeSpotCollector; @@ -28,6 +29,7 @@ public sealed class FleeGoal : GoapGoal, IRouteProvider public FleeGoal(ILogger logger, ConfigurableInput input, Wait wait, PlayerReader playerReader, AddonBits bits, + CastingHandler castingHandler, ClassConfiguration classConfiguration, Navigation playerNavigation, ClassConfiguration classConfig, SafeSpotCollector safeSpotCollector) @@ -40,6 +42,7 @@ public FleeGoal(ILogger logger, ConfigurableInput input, this.playerReader = playerReader; this.navigation = playerNavigation; this.bits = bits; + this.castingHandler = castingHandler; this.classConfig = classConfig; @@ -105,16 +108,37 @@ public override void OnExit() navigation.Stop(); navigation.StopMovement(); - } - public override void Update() - { if (bits.Target()) { input.PressClearTarget(); } + } + public override void Update() + { wait.Update(); navigation.Update(); + + // first element is skipped + // its part of the Goal Custom Condition + ReadOnlySpan span = Keys; + for (int i = 1; i < span.Length; i++) + { + KeyAction keyAction = span[i]; + + if (castingHandler.SpellInQueue() && !keyAction.BaseAction) + { + continue; + } + + if (castingHandler.CastIfReady(keyAction, + keyAction.Interrupts.Count > 0 + ? keyAction.CanBeInterrupted + : bits.Combat)) + { + break; + } + } } }