diff --git a/java/noppes/npcs/api/ability/IAbility.java b/java/noppes/npcs/api/ability/IAbility.java index e66ab3f..1adf685 100644 --- a/java/noppes/npcs/api/ability/IAbility.java +++ b/java/noppes/npcs/api/ability/IAbility.java @@ -257,4 +257,29 @@ public interface IAbility extends IAbilityAction { boolean isBurstOverlap(); void setBurstOverlap(boolean overlap); + + // Toggle system + + /** + * Check if this ability is toggleable (has at least 1 toggle state). + */ + boolean isToggleable(); + + /** + * Get the number of toggle states. + * 0 = not toggleable, 1 = binary on/off, 2+ = multi-state cycling. + */ + int getToggleStates(); + + /** + * Set the number of toggle states. + * 0 = not toggleable, 1 = binary on/off, 2+ = multi-state cycling. + */ + void setToggleStates(int states); + + /** + * Get the display label for a specific toggle state (1-indexed). + * @return the label, or null if none set + */ + String getToggleStateLabel(int state); } diff --git a/java/noppes/npcs/api/ability/IPlayerAbilityData.java b/java/noppes/npcs/api/ability/IPlayerAbilityData.java index ed3be8b..7c5ea64 100644 --- a/java/noppes/npcs/api/ability/IPlayerAbilityData.java +++ b/java/noppes/npcs/api/ability/IPlayerAbilityData.java @@ -109,4 +109,29 @@ public interface IPlayerAbilityData { * Activate a specific ability by key. */ boolean activateAbility(String key); + + // Toggle system + + /** + * Cycle a toggle ability to its next state. + * Off -> State 1 -> State 2 -> ... -> State N -> Off + * @return The new state (0 = off, 1+ = active state number) + */ + int toggleAbility(String key); + + /** + * Get the current toggle state for an ability. + * @return 0 if not active, 1+ for active state + */ + int getToggleState(String key); + + /** + * Set a toggle to a specific state. 0 = deactivate, 1+ = specific state. + */ + void setToggleState(String key, int state); + + /** + * Check if a toggle ability is currently active (any state > 0). + */ + boolean isAbilityToggled(String key); } diff --git a/java/noppes/npcs/api/event/IAbilityEvent.java b/java/noppes/npcs/api/event/IAbilityEvent.java index 21c9cd3..1c43278 100644 --- a/java/noppes/npcs/api/event/IAbilityEvent.java +++ b/java/noppes/npcs/api/event/IAbilityEvent.java @@ -58,6 +58,28 @@ public interface IAbilityEvent extends INpcEvent { interface CompleteEvent extends IAbilityEvent { } + /** + * Fired when a toggle ability is switched ON or OFF. + * Canceling prevents the toggle from changing state. + */ + @Cancelable + interface ToggleEvent extends IAbilityEvent { + boolean isTogglingOn(); + int getOldState(); + int getNewState(); + } + + /** + * Fired every 10 ticks for each active toggle ability. + * Scripts can call setEnabled(false) to force-deactivate. + */ + interface ToggleUpdateEvent extends IAbilityEvent { + int getTick(); + int getState(); + boolean isEnabled(); + void setEnabled(boolean enabled); + } + /** * Fired when an ability hits an entity with damage. * Canceling this event prevents the damage from being applied. diff --git a/java/noppes/npcs/api/event/IPlayerAbilityEvent.java b/java/noppes/npcs/api/event/IPlayerAbilityEvent.java index 00c7a6b..6162f87 100644 --- a/java/noppes/npcs/api/event/IPlayerAbilityEvent.java +++ b/java/noppes/npcs/api/event/IPlayerAbilityEvent.java @@ -85,6 +85,58 @@ public interface IPlayerAbilityEvent extends IPlayerEvent { int getTick(); } + /** + * Fired when a toggle ability is switched ON or OFF. + * Canceling prevents the toggle from changing state. + * + * @hookName abilityToggle + */ + @Cancelable + interface ToggleEvent extends IPlayerAbilityEvent { + /** + * @return true if the toggle is being turned ON (any state), false if being turned OFF + */ + boolean isTogglingOn(); + + /** + * @return the previous state (0 = was off, 1+ = previous active state) + */ + int getOldState(); + + /** + * @return the new state (0 = turning off, 1+ = new active state) + */ + int getNewState(); + } + + /** + * Fired every 10 ticks for each active toggle ability. + * Scripts can call {@link #setEnabled(boolean)} with false to force-deactivate the toggle. + * + * @hookName abilityToggleUpdate + */ + interface ToggleUpdateEvent extends IPlayerAbilityEvent { + /** + * @return the tick count since the toggle was activated + */ + int getTick(); + + /** + * @return the current toggle state (1+) + */ + int getState(); + + /** + * @return whether the toggle should remain active + */ + boolean isEnabled(); + + /** + * Set to false to force-deactivate the toggle after this event completes. + */ + void setEnabled(boolean enabled); + } + /** * Fired when a player's ability hits an entity with damage. * Canceling this event prevents the damage from being applied.