From 57ffc54074eeba2d9b52412da5997d7efa3fdac8 Mon Sep 17 00:00:00 2001 From: Rutherther Date: Sat, 21 Jan 2023 14:30:07 +0100 Subject: [PATCH] feat(combat): prevent NotInRange error --- .../Techniques/SimpleAttackTechnique.cs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/Extensions/NosSmooth.Extensions.Combat/Techniques/SimpleAttackTechnique.cs b/Extensions/NosSmooth.Extensions.Combat/Techniques/SimpleAttackTechnique.cs index f59eae143ce9a5e4a2c289cb1b00586680c3c62f..25f730f92427530425e4120138e872640a81f609 100644 --- a/Extensions/NosSmooth.Extensions.Combat/Techniques/SimpleAttackTechnique.cs +++ b/Extensions/NosSmooth.Extensions.Combat/Techniques/SimpleAttackTechnique.cs @@ -12,6 +12,7 @@ using NosSmooth.Extensions.Combat.Selectors; using NosSmooth.Extensions.Pathfinding; using NosSmooth.Game.Apis.Safe; using NosSmooth.Game.Data.Entities; +using NosSmooth.Game.Errors; using NosSmooth.Game.Extensions; using Remora.Results; @@ -83,13 +84,13 @@ public class SimpleAttackTechnique : ICombatTechnique public Result HandleWaiting(OperationQueueType queueType, ICombatState state, ICombatOperation operation, CannotBeUsedError cannotBeUsedError) { if (cannotBeUsedError.UnderlyingError is TargetDeadError) - { + { // target is dead, that means exiting the technique. For that, remove the operation. state.RemoveCurrentOperation(queueType, true); return Result.FromSuccess(); } if (cannotBeUsedError.Response == CanBeUsedResponse.WontBeUsable) - { + { // Unfortunately we cannot handle that error. return cannotBeUsedError; } @@ -98,7 +99,14 @@ public class SimpleAttackTechnique : ICombatTechnique /// public Result HandleError(ICombatState state, Result result) - { // no handling of errors is done + { + if (result.Error is NotInRangeError) + { // the entity has moved between WalkInRange and UseSkill operations. That is unlikely + // but it's better to be sure in case that happens it gets solved + state.RemoveCurrentOperation(OperationQueueType.TotalControl, true); + return Result.FromSuccess(); + } + return result; }