From c9dc65ebc01e018400f43dca2cf46b4e920b4d65 Mon Sep 17 00:00:00 2001 From: Rutherther Date: Fri, 20 Jan 2023 18:41:15 +0100 Subject: [PATCH] feat(combat): add method for removing current operation from combat state --- .../NosSmooth.Extensions.Combat/CombatState.cs | 18 ++++++++++++++++++ .../ICombatState.cs | 8 ++++++++ 2 files changed, 26 insertions(+) diff --git a/Extensions/NosSmooth.Extensions.Combat/CombatState.cs b/Extensions/NosSmooth.Extensions.Combat/CombatState.cs index 1832e19..e1c482b 100644 --- a/Extensions/NosSmooth.Extensions.Combat/CombatState.cs +++ b/Extensions/NosSmooth.Extensions.Combat/CombatState.cs @@ -84,6 +84,24 @@ internal class CombatState : ICombatState return _currentOperations.Values.Where(x => !x.IsExecuting()).ToList(); } + /// + public ICombatOperation? RemoveCurrentOperation(OperationQueueType queueType, bool emptyQueue = false) + { + if (emptyQueue && _operations.TryGetValue(queueType, out var queue)) + { + queue.Clear(); + } + + if (_currentOperations.TryGetValue(queueType, out var operation)) + { + operation.Dispose(); + _currentOperations.Remove(queueType); + return operation; + } + + return null; + } + /// public ICombatOperation? GetCurrentOperation(OperationQueueType queueType) => _currentOperations.GetValueOrDefault(queueType); diff --git a/Extensions/NosSmooth.Extensions.Combat/ICombatState.cs b/Extensions/NosSmooth.Extensions.Combat/ICombatState.cs index 0397f62..b25ea61 100644 --- a/Extensions/NosSmooth.Extensions.Combat/ICombatState.cs +++ b/Extensions/NosSmooth.Extensions.Combat/ICombatState.cs @@ -43,6 +43,14 @@ public interface ICombatState /// The operations needed to wait for. public IReadOnlyList GetWaitingForOperations(); + /// + /// Remove the current operation for the given queue. + /// + /// The queue type to get the current operation of. + /// Whether to empty the rest of the queue. + /// The operation of the given queue, if any. + public ICombatOperation? RemoveCurrentOperation(OperationQueueType queueType, bool emptyQueue = false); + /// /// Gets the current operation of the given queue type. /// -- 2.49.0