mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-13 05:27:37 +00:00
AbilityDefend event
This commit is contained in:
1 parent
edf5ff7c73
commit
b989a89889
6 files changed
+59
-2
No files matched your search
@@ -10,9 +10,11 @@ import kamkeel.npcs.controllers.data.telegraph.TelegraphType;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.DamageSource;
|
||||
import noppes.npcs.EventHooks;
|
||||
import noppes.npcs.api.ability.type.IAbilityDefend;
|
||||
import noppes.npcs.client.gui.builder.FieldDef;
|
||||
import noppes.npcs.controllers.data.Animation;
|
||||
import noppes.npcs.scripted.event.AbilityEvent;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -147,8 +149,14 @@ public abstract class AbilityDefend extends Ability implements IAbilityDefend {
|
||||
}
|
||||
}
|
||||
|
||||
//inject defend event
|
||||
AbilityEvent.DefendEvent event = new AbilityEvent.DefendEvent(caster, this, attacker, lastAttacker, amount);
|
||||
if (EventHooks.onAbilityDefend(this, event)) {
|
||||
return event.getDamage();
|
||||
}
|
||||
|
||||
// Always calculate the correct reduction for the caller's damage amount
|
||||
return performDefend(attacker, amount);
|
||||
return performDefend(attacker, event.getDamage());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -975,6 +975,11 @@ public class EventHooks {
|
||||
return postAbilityEvent(ability, event);
|
||||
}
|
||||
|
||||
public static boolean onAbilityDefend(Ability ability, AbilityEvent.DefendEvent event) {
|
||||
if (ability == null || event == null) return false;
|
||||
return postAbilityEvent(ability, event);
|
||||
}
|
||||
|
||||
public static boolean onAbilityToggle(Ability ability, EntityLivingBase entity, int oldState, int newState) {
|
||||
if (ability == null || entity == null) return false;
|
||||
return postAbilityEvent(ability, new AbilityEvent.ToggleEvent(entity, ability, oldState, newState));
|
||||
|
||||
@@ -125,6 +125,7 @@ public enum EnumScriptType {
|
||||
ABILITY_INTERRUPT("abilityInterrupt"),
|
||||
ABILITY_COMPLETE("abilityComplete"),
|
||||
ABILITY_HIT("abilityHit"),
|
||||
ABILITY_DEFEND("abilityDefend"),
|
||||
ABILITY_TICK("abilityTick"),
|
||||
ABILITY_TOGGLE("abilityToggle"),
|
||||
ABILITY_TOGGLE_TICK("abilityToggleTick"),
|
||||
|
||||
@@ -124,6 +124,7 @@ public class ScriptHookController implements IScriptHookHandler {
|
||||
hook(NPC, ABILITY_START, IAbilityEvent.StartEvent.class);
|
||||
hook(NPC, ABILITY_EXECUTE, IAbilityEvent.ExecuteEvent.class);
|
||||
hook(NPC, ABILITY_HIT, IAbilityEvent.HitEvent.class);
|
||||
hook(NPC, ABILITY_DEFEND, IAbilityEvent.DefendEvent.class);
|
||||
hook(NPC, ABILITY_TICK, IAbilityEvent.TickEvent.class);
|
||||
hook(NPC, ABILITY_INTERRUPT, IAbilityEvent.InterruptEvent.class);
|
||||
hook(NPC, ABILITY_COMPLETE, IAbilityEvent.CompleteEvent.class);
|
||||
@@ -259,6 +260,7 @@ public class ScriptHookController implements IScriptHookHandler {
|
||||
hook(PLAYER, ABILITY_START, IAbilityEvent.StartEvent.class);
|
||||
hook(PLAYER, ABILITY_EXECUTE, IAbilityEvent.ExecuteEvent.class);
|
||||
hook(PLAYER, ABILITY_HIT, IAbilityEvent.HitEvent.class);
|
||||
hook(PLAYER, ABILITY_DEFEND, IAbilityEvent.DefendEvent.class);
|
||||
hook(PLAYER, ABILITY_TICK, IAbilityEvent.TickEvent.class);
|
||||
hook(PLAYER, ABILITY_INTERRUPT, IAbilityEvent.InterruptEvent.class);
|
||||
hook(PLAYER, ABILITY_COMPLETE, IAbilityEvent.CompleteEvent.class);
|
||||
@@ -357,6 +359,7 @@ public class ScriptHookController implements IScriptHookHandler {
|
||||
hook(ABILITY, ABILITY_START, IAbilityEvent.StartEvent.class);
|
||||
hook(ABILITY, ABILITY_EXECUTE, IAbilityEvent.ExecuteEvent.class);
|
||||
hook(ABILITY, ABILITY_HIT, IAbilityEvent.HitEvent.class);
|
||||
hook(ABILITY, ABILITY_DEFEND, IAbilityEvent.DefendEvent.class);
|
||||
hook(ABILITY, ABILITY_TICK, IAbilityEvent.TickEvent.class);
|
||||
hook(ABILITY, ABILITY_INTERRUPT, IAbilityEvent.InterruptEvent.class);
|
||||
hook(ABILITY, ABILITY_COMPLETE, IAbilityEvent.CompleteEvent.class);
|
||||
|
||||
@@ -214,6 +214,46 @@ public class AbilityEvent extends CustomNPCsEvent implements IAbilityEvent {
|
||||
}
|
||||
}
|
||||
|
||||
@Cancelable
|
||||
public static class DefendEvent extends AbilityEvent implements IAbilityEvent.DefendEvent {
|
||||
private final IEntityLivingBase attacker;
|
||||
private final IEntityLivingBase lastAttacker;
|
||||
private float damage;
|
||||
|
||||
public DefendEvent(EntityLivingBase entity, Ability ability, EntityLivingBase attacker,
|
||||
EntityLivingBase lastAttacker, float damage) {
|
||||
super(entity, ability, null);
|
||||
this.attacker = attacker != null ? (IEntityLivingBase) NpcAPI.Instance().getIEntity(attacker) : null;
|
||||
this.lastAttacker = lastAttacker != null ? (IEntityLivingBase) NpcAPI.Instance().getIEntity(lastAttacker) : null;
|
||||
this.damage = damage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IEntityLivingBase getAttacker() {
|
||||
return attacker;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IEntityLivingBase getLastAttacker() {
|
||||
return lastAttacker;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getDamage() {
|
||||
return damage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDamage(float damage) {
|
||||
this.damage = damage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHookName() {
|
||||
return EnumScriptType.ABILITY_DEFEND.function;
|
||||
}
|
||||
}
|
||||
|
||||
@Cancelable
|
||||
public static class ToggleEvent extends AbilityEvent implements IAbilityEvent.ToggleEvent {
|
||||
private final int oldState;
|
||||
|
||||
Reference in new issue
Block a user