From 6af66b8883d10b6a74f51be9e63925c76c6ea7a1 Mon Sep 17 00:00:00 2001 From: KAMKEEL <28842281+KAMKEEL@users.noreply.github.com> Date: Tue, 11 Aug 2026 03:25:51 -0400 Subject: [PATCH] Fix NPCs getting stuck after using one ability The terminal DAZED to IDLE transition was swallowed before the completion switch ran, so the finished ability stayed set as the current one and the NPC never started another until it died and reset. Guard abilities compounded it: NPCs reuse a single ability instance and onExecute left pendingCompletion set, ending every later activation on its first tick. --- .../controllers/data/ability/type/AbilityDefend.java | 6 ++++++ src/main/java/noppes/npcs/AbstractDataAbilities.java | 10 +++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/main/java/kamkeel/npcs/controllers/data/ability/type/AbilityDefend.java b/src/main/java/kamkeel/npcs/controllers/data/ability/type/AbilityDefend.java index 376c4ad4c..4826daee4 100644 --- a/src/main/java/kamkeel/npcs/controllers/data/ability/type/AbilityDefend.java +++ b/src/main/java/kamkeel/npcs/controllers/data/ability/type/AbilityDefend.java @@ -74,6 +74,12 @@ public abstract class AbilityDefend extends Ability implements IAbilityDefend { hitCount = 0; lastAttacker = null; lastDamageTaken = 0.0f; + // NPCs reuse one ability instance, so every transient field has to be cleared here. + // A leftover pendingCompletion would end the next activation on its first tick. + pendingDefendAnimation = null; + defendAnimEndTick = -1; + lastDefendTick = -1; + pendingCompletion = false; } @Override diff --git a/src/main/java/noppes/npcs/AbstractDataAbilities.java b/src/main/java/noppes/npcs/AbstractDataAbilities.java index 244ed91d1..12f1fd793 100644 --- a/src/main/java/noppes/npcs/AbstractDataAbilities.java +++ b/src/main/java/noppes/npcs/AbstractDataAbilities.java @@ -786,7 +786,15 @@ public abstract class AbstractDataAbilities { fireTickEvent(currentAbility, target); // Script may have completed/cancelled the ability during the tick event - if (currentAbility == null || !currentAbility.isExecuting()) return; + if (currentAbility == null) return; + if (!currentAbility.isExecuting()) { + // tick() itself can end the ability (DAZED -> IDLE). Run its completion here, + // otherwise it stays the current ability forever and nothing else can start. + if (phaseChanged && currentAbility.getPhase() == AbilityPhase.IDLE) { + handleAbilityCompletion(target); + } + return; + } // Fire extender tick hook (e.g., per-tick resource drain) if (!AbilityController.Instance.fireOnAbilityTick(currentAbility, entity, target,