mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-25 20:24:30 +00:00
Counter, Dodge, Guard Abilities
This commit is contained in:
1 parent
fc71fb5a33
commit
b49316d9bb
7 files changed
+99
-4
No files matched your search
@@ -2,6 +2,7 @@ package noppes.npcs;
|
||||
|
||||
import kamkeel.npcs.controllers.AbilityController;
|
||||
import kamkeel.npcs.controllers.data.ability.Ability;
|
||||
import kamkeel.npcs.controllers.data.ability.type.AbilityDefend;
|
||||
import kamkeel.npcs.controllers.data.ability.enums.AbilityPhase;
|
||||
import kamkeel.npcs.controllers.data.ability.data.ChainedAbility;
|
||||
import kamkeel.npcs.controllers.data.ability.data.entry.ChainedAbilityEntry;
|
||||
@@ -317,6 +318,19 @@ public abstract class AbstractDataAbilities {
|
||||
return currentAbility;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the active defend ability if one is currently defending.
|
||||
*/
|
||||
public AbilityDefend getActiveDefend() {
|
||||
if (currentAbility instanceof AbilityDefend) {
|
||||
AbilityDefend defend = (AbilityDefend) currentAbility;
|
||||
if (defend.isDefending()) {
|
||||
return defend;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a chained ability is currently executing.
|
||||
*/
|
||||
|
||||
@@ -10,10 +10,15 @@ import kamkeel.npcs.controllers.AbilityController;
|
||||
import kamkeel.npcs.controllers.AttributeController;
|
||||
import kamkeel.npcs.controllers.SyncController;
|
||||
import kamkeel.npcs.controllers.data.ability.Ability;
|
||||
import kamkeel.npcs.controllers.data.ability.type.AbilityCounter;
|
||||
import kamkeel.npcs.controllers.data.ability.type.AbilityDefend;
|
||||
import kamkeel.npcs.controllers.data.ability.type.AbilityDodge;
|
||||
import kamkeel.npcs.controllers.data.ability.type.AbilityGuard;
|
||||
import kamkeel.npcs.network.packets.data.ability.PlayerAbilitySyncPacket;
|
||||
import kamkeel.npcs.controllers.data.ability.enums.AbilityPhase;
|
||||
import kamkeel.npcs.util.AttributeAttackUtil;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.inventory.ContainerPlayer;
|
||||
@@ -624,6 +629,22 @@ public class ScriptPlayerEventHandler {
|
||||
noppes.npcs.scripted.event.player.PlayerEvent.AttackEvent pevent1 = new noppes.npcs.scripted.event.player.PlayerEvent.AttackEvent((IPlayer) NpcAPI.Instance().getIEntity((EntityPlayer) event.source.getEntity()), event.entityLiving, attackAmount, event.source);
|
||||
cancel = cancel || EventHooks.onPlayerAttack(handler, pevent1);
|
||||
}
|
||||
|
||||
// Dodge & Counter: cancel attack entirely
|
||||
if (!cancel && event.entityLiving instanceof EntityPlayerMP) {
|
||||
PlayerData pData = PlayerData.get((EntityPlayer) event.entityLiving);
|
||||
if (pData != null && pData.abilityData != null) {
|
||||
AbilityDefend defend = pData.abilityData.getActiveDefend();
|
||||
if (defend instanceof AbilityDodge || defend instanceof AbilityCounter) {
|
||||
EntityLivingBase attacker = source instanceof EntityLivingBase ? (EntityLivingBase) source : null;
|
||||
float result = defend.onDefend(attacker, event.source, event.ammount);
|
||||
if (result != event.ammount) {
|
||||
cancel = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
event.setCanceled(cancel);
|
||||
}
|
||||
}
|
||||
@@ -653,6 +674,13 @@ public class ScriptPlayerEventHandler {
|
||||
event.ammount = 0;
|
||||
cancel = true;
|
||||
} else {
|
||||
// Guard: reduce damage
|
||||
AbilityDefend defend = pData.abilityData.getActiveDefend();
|
||||
if (defend instanceof AbilityGuard) {
|
||||
EntityLivingBase attacker = source instanceof EntityLivingBase ? (EntityLivingBase) source : null;
|
||||
event.ammount = defend.onDefend(attacker, event.source, event.ammount);
|
||||
}
|
||||
|
||||
float modified = pData.abilityData.onDamage(event.source, event.ammount);
|
||||
event.ammount = modified;
|
||||
}
|
||||
|
||||
@@ -6,6 +6,9 @@ import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import kamkeel.npcs.addon.DBCAddon;
|
||||
import kamkeel.npcs.controllers.data.ability.type.AbilityCounter;
|
||||
import kamkeel.npcs.controllers.data.ability.type.AbilityDefend;
|
||||
import kamkeel.npcs.controllers.data.ability.type.AbilityDodge;
|
||||
import kamkeel.npcs.addon.client.DBCClient;
|
||||
import kamkeel.npcs.network.PacketHandler;
|
||||
import kamkeel.npcs.network.enums.EnumSoundOperation;
|
||||
@@ -709,6 +712,21 @@ public abstract class EntityNPCInterface extends EntityCreature implements IEnti
|
||||
// Resistances
|
||||
i = stats.resistances.applyResistance(damagesource, i);
|
||||
|
||||
// Defend abilities
|
||||
AbilityDefend defend = this.abilities != null ? this.abilities.getActiveDefend() : null;
|
||||
if (defend != null) {
|
||||
// Dodge & Counter: cancel attack entirely
|
||||
if (defend instanceof AbilityDodge || defend instanceof AbilityCounter) {
|
||||
float result = defend.onDefend(attackingEntity, damagesource, i);
|
||||
if (result != i) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
// Guard: reduce damage
|
||||
i = defend.onDefend(attackingEntity, damagesource, i);
|
||||
}
|
||||
}
|
||||
|
||||
NpcEvent.DamagedEvent event = new NpcEvent.DamagedEvent(this.wrappedNPC, attackingEntity, i, damagesource);
|
||||
if (EventHooks.onNPCDamaged(this, event) || isKilled())
|
||||
return false;
|
||||
|
||||
Reference in new issue
Block a user