mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-17 19:15:11 +00:00
Player Ability Checking
Enhance ability validation: add method to check if an ability can be resolved without deep copy and prune invalid unlocked abilities during load
This commit is contained in:
commit
f4ad421c2e
26 files changed
+1387
-97
No files matched your search
@@ -16,9 +16,14 @@ import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraft.nbt.NBTTagString;
|
||||
import net.minecraft.util.DamageSource;
|
||||
import noppes.npcs.LogWriter;
|
||||
import noppes.npcs.EventHooks;
|
||||
import noppes.npcs.api.ability.IPlayerAbilityData;
|
||||
import noppes.npcs.api.entity.IPlayer;
|
||||
import noppes.npcs.controllers.AnimationController;
|
||||
import noppes.npcs.controllers.ScriptController;
|
||||
import noppes.npcs.controllers.data.Animation;
|
||||
import noppes.npcs.scripted.NpcAPI;
|
||||
import noppes.npcs.scripted.event.player.PlayerAbilityEvent;
|
||||
|
||||
import kamkeel.npcs.network.packets.data.ability.PlayerAbilityStatePacket;
|
||||
import kamkeel.npcs.network.packets.data.ability.PlayerAbilitySyncPacket;
|
||||
@@ -156,6 +161,9 @@ public class PlayerAbilityData implements IPlayerAbilityData {
|
||||
// Tick advances time and possibly changes phase
|
||||
boolean phaseChanged = currentAbility.tick();
|
||||
|
||||
// Fire tick event for scripts
|
||||
firePlayerTickEvent(player, currentAbility, currentTarget);
|
||||
|
||||
// Fire extender tick hook (e.g., per-tick resource drain)
|
||||
if (!AbilityController.Instance.fireOnAbilityTick(currentAbility, player, currentTarget,
|
||||
currentAbility.getPhase(), currentAbility.getCurrentTick())) {
|
||||
@@ -213,6 +221,11 @@ public class PlayerAbilityData implements IPlayerAbilityData {
|
||||
playAbilitySound(player, currentAbility.getActiveSound());
|
||||
playAbilityAnimation(currentAbility.getActiveAnimation());
|
||||
|
||||
// Fire execute event (cancelable)
|
||||
if (firePlayerExecuteEvent(player, currentAbility, currentTarget)) {
|
||||
return; // Cancelled
|
||||
}
|
||||
|
||||
// Call onExecute
|
||||
currentAbility.onExecute(player, currentTarget);
|
||||
|
||||
@@ -270,6 +283,9 @@ public class PlayerAbilityData implements IPlayerAbilityData {
|
||||
|
||||
currentAbility.onComplete(player, currentTarget);
|
||||
|
||||
// Fire complete event
|
||||
firePlayerCompleteEvent(player, currentAbility, currentTarget);
|
||||
|
||||
// Release all locks
|
||||
releaseRotationControl();
|
||||
releaseLockedPosition();
|
||||
@@ -342,6 +358,11 @@ public class PlayerAbilityData implements IPlayerAbilityData {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Fire start event (cancelable)
|
||||
if (firePlayerStartEvent(player, ability)) {
|
||||
return false; // Cancelled
|
||||
}
|
||||
|
||||
// Start the ability
|
||||
currentAbility = ability;
|
||||
currentAbilityKey = key;
|
||||
@@ -382,6 +403,11 @@ public class PlayerAbilityData implements IPlayerAbilityData {
|
||||
playAbilitySound(player, ability.getActiveSound());
|
||||
playAbilityAnimation(ability.getActiveAnimation());
|
||||
|
||||
// Fire execute event (cancelable)
|
||||
if (firePlayerExecuteEvent(player, ability, currentTarget)) {
|
||||
return; // Cancelled
|
||||
}
|
||||
|
||||
// Call onExecute
|
||||
ability.onExecute(player, currentTarget);
|
||||
|
||||
@@ -540,10 +566,17 @@ public class PlayerAbilityData implements IPlayerAbilityData {
|
||||
}
|
||||
|
||||
public void interruptCurrentAbility() {
|
||||
interruptCurrentAbility(null, 0);
|
||||
}
|
||||
|
||||
public void interruptCurrentAbility(DamageSource source, float damage) {
|
||||
if (currentAbility != null && currentAbility.isExecuting()) {
|
||||
// Fire extender complete hook (interrupted)
|
||||
AbilityController.Instance.fireOnAbilityComplete(currentAbility, playerData.player, currentTarget, true);
|
||||
|
||||
// Fire interrupt event
|
||||
firePlayerInterruptEvent(playerData.player, currentAbility, currentTarget, source, damage);
|
||||
|
||||
currentAbility.interrupt();
|
||||
stopAbilityAnimation();
|
||||
releaseRotationControl();
|
||||
@@ -596,7 +629,7 @@ public class PlayerAbilityData implements IPlayerAbilityData {
|
||||
|
||||
// Check for ability interruption
|
||||
if (currentAbility != null && currentAbility.canInterrupt(source)) {
|
||||
interruptCurrentAbility();
|
||||
interruptCurrentAbility(source, amount);
|
||||
}
|
||||
|
||||
return amount;
|
||||
@@ -836,6 +869,73 @@ public class PlayerAbilityData implements IPlayerAbilityData {
|
||||
}
|
||||
}
|
||||
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
// SCRIPT EVENTS
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
|
||||
/**
|
||||
* Fire the ability start event. Returns true if cancelled.
|
||||
*/
|
||||
private boolean firePlayerStartEvent(EntityPlayer player, Ability ability) {
|
||||
if (ScriptController.Instance == null) return false;
|
||||
PlayerDataScript handler = ScriptController.Instance.getPlayerScripts(player);
|
||||
if (handler == null) return false;
|
||||
IPlayer iPlayer = (IPlayer) NpcAPI.Instance().getIEntity(player);
|
||||
PlayerAbilityEvent.StartEvent event = new PlayerAbilityEvent.StartEvent(iPlayer, ability, null);
|
||||
return EventHooks.onPlayerAbilityStart(handler, event);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fire the ability execute event. Returns true if cancelled.
|
||||
*/
|
||||
private boolean firePlayerExecuteEvent(EntityPlayer player, Ability ability, EntityLivingBase target) {
|
||||
if (ScriptController.Instance == null) return false;
|
||||
PlayerDataScript handler = ScriptController.Instance.getPlayerScripts(player);
|
||||
if (handler == null) return false;
|
||||
IPlayer iPlayer = (IPlayer) NpcAPI.Instance().getIEntity(player);
|
||||
PlayerAbilityEvent.ExecuteEvent event = new PlayerAbilityEvent.ExecuteEvent(iPlayer, ability, target);
|
||||
return EventHooks.onPlayerAbilityExecute(handler, event);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fire the ability tick event.
|
||||
*/
|
||||
private void firePlayerTickEvent(EntityPlayer player, Ability ability, EntityLivingBase target) {
|
||||
if (ScriptController.Instance == null) return;
|
||||
PlayerDataScript handler = ScriptController.Instance.getPlayerScripts(player);
|
||||
if (handler == null) return;
|
||||
IPlayer iPlayer = (IPlayer) NpcAPI.Instance().getIEntity(player);
|
||||
PlayerAbilityEvent.TickEvent event = new PlayerAbilityEvent.TickEvent(
|
||||
iPlayer, ability, target, ability.getPhase().ordinal(), ability.getCurrentTick());
|
||||
EventHooks.onPlayerAbilityTick(handler, event);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fire the ability interrupt event.
|
||||
*/
|
||||
private void firePlayerInterruptEvent(EntityPlayer player, Ability ability, EntityLivingBase target,
|
||||
DamageSource source, float damage) {
|
||||
if (ScriptController.Instance == null) return;
|
||||
PlayerDataScript handler = ScriptController.Instance.getPlayerScripts(player);
|
||||
if (handler == null) return;
|
||||
IPlayer iPlayer = (IPlayer) NpcAPI.Instance().getIEntity(player);
|
||||
PlayerAbilityEvent.InterruptEvent event = new PlayerAbilityEvent.InterruptEvent(
|
||||
iPlayer, ability, target, source, damage);
|
||||
EventHooks.onPlayerAbilityInterrupt(handler, event);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fire the ability complete event.
|
||||
*/
|
||||
private void firePlayerCompleteEvent(EntityPlayer player, Ability ability, EntityLivingBase target) {
|
||||
if (ScriptController.Instance == null) return;
|
||||
PlayerDataScript handler = ScriptController.Instance.getPlayerScripts(player);
|
||||
if (handler == null) return;
|
||||
IPlayer iPlayer = (IPlayer) NpcAPI.Instance().getIEntity(player);
|
||||
PlayerAbilityEvent.CompleteEvent event = new PlayerAbilityEvent.CompleteEvent(iPlayer, ability, target);
|
||||
EventHooks.onPlayerAbilityComplete(handler, event);
|
||||
}
|
||||
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
// NBT SERIALIZATION
|
||||
// ═══════════════════════════════════════════════════════════════════
|
||||
|
||||
Reference in new issue
Block a user