mirror of
https://github.com/KAMKEEL/CustomNPC-Plus.git
synced 2026-11-26 09:13:06 +00:00
Player Abilities
This commit is contained in:
1 parent
601b0d721e
commit
1b8ad4dd90
92 files changed
+2610
-1025
No files matched your search
@@ -0,0 +1,101 @@
|
||||
package noppes.npcs.scripted.event.player;
|
||||
|
||||
import cpw.mods.fml.common.eventhandler.Cancelable;
|
||||
import kamkeel.npcs.controllers.data.ability.Ability;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import noppes.npcs.api.ability.IAbility;
|
||||
import noppes.npcs.api.entity.IEntityLivingBase;
|
||||
import noppes.npcs.api.entity.IPlayer;
|
||||
import noppes.npcs.api.event.IPlayerAbilityEvent;
|
||||
import noppes.npcs.constants.EnumScriptType;
|
||||
import noppes.npcs.scripted.NpcAPI;
|
||||
|
||||
/**
|
||||
* Events fired during player ability execution lifecycle.
|
||||
*/
|
||||
public class PlayerAbilityEvent extends PlayerEvent implements IPlayerAbilityEvent {
|
||||
protected final Ability ability;
|
||||
protected final IEntityLivingBase target;
|
||||
|
||||
public PlayerAbilityEvent(IPlayer player, Ability ability, EntityLivingBase target) {
|
||||
super(player);
|
||||
this.ability = ability;
|
||||
this.target = target != null ? (IEntityLivingBase) NpcAPI.Instance().getIEntity(target) : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAbility getAbility() {
|
||||
return ability;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IEntityLivingBase getTarget() {
|
||||
return target;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHookName() {
|
||||
return "playerAbilityEvent";
|
||||
}
|
||||
|
||||
/**
|
||||
* Fired when a player's ability hits an entity with damage.
|
||||
* Canceling prevents the damage from being applied.
|
||||
*/
|
||||
@Cancelable
|
||||
public static class HitEvent extends PlayerAbilityEvent implements IPlayerAbilityEvent.HitEvent {
|
||||
private final IEntityLivingBase hitEntity;
|
||||
private float damage;
|
||||
private float knockback;
|
||||
private float knockbackUp;
|
||||
|
||||
public HitEvent(IPlayer player, Ability ability, EntityLivingBase target,
|
||||
EntityLivingBase hitEntity, float damage, float knockback, float knockbackUp) {
|
||||
super(player, ability, target);
|
||||
this.hitEntity = hitEntity != null ? (IEntityLivingBase) NpcAPI.Instance().getIEntity(hitEntity) : null;
|
||||
this.damage = damage;
|
||||
this.knockback = knockback;
|
||||
this.knockbackUp = knockbackUp;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IEntityLivingBase getHitEntity() {
|
||||
return hitEntity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getDamage() {
|
||||
return damage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDamage(float damage) {
|
||||
this.damage = damage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getKnockback() {
|
||||
return knockback;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setKnockback(float knockback) {
|
||||
this.knockback = knockback;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getKnockbackUp() {
|
||||
return knockbackUp;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setKnockbackUp(float knockbackUp) {
|
||||
this.knockbackUp = knockbackUp;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getHookName() {
|
||||
return EnumScriptType.ABILITY_HIT.function;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -43,6 +43,11 @@ public class ScriptDataAbilities implements IDataAbilities {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addAbilityReference(String key) {
|
||||
data.addAbilityReference(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeAbility(String abilityId) {
|
||||
data.removeAbility(abilityId);
|
||||
@@ -58,6 +63,33 @@ public class ScriptDataAbilities implements IDataAbilities {
|
||||
return data.getAbility(abilityId) != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAbilityReference(String abilityId) {
|
||||
List<kamkeel.npcs.controllers.data.ability.AbilitySlot> slots = data.getAbilitySlots();
|
||||
for (int i = 0; i < slots.size(); i++) {
|
||||
kamkeel.npcs.controllers.data.ability.AbilitySlot slot = slots.get(i);
|
||||
if (slot.isReference()) {
|
||||
if (slot.getReferenceId().equals(abilityId)) return true;
|
||||
} else {
|
||||
Ability a = slot.getAbility();
|
||||
if (a != null && a.getId().equals(abilityId)) return false;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean convertToInline(String abilityId) {
|
||||
List<kamkeel.npcs.controllers.data.ability.AbilitySlot> slots = data.getAbilitySlots();
|
||||
for (int i = 0; i < slots.size(); i++) {
|
||||
kamkeel.npcs.controllers.data.ability.AbilitySlot slot = slots.get(i);
|
||||
if (slot.isReference() && slot.getReferenceId().equals(abilityId)) {
|
||||
return data.convertToInline(i);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearAbilities() {
|
||||
data.clearAbilities();
|
||||
@@ -117,17 +149,14 @@ public class ScriptDataAbilities implements IDataAbilities {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean executePresetAbility(String presetName) {
|
||||
return executePresetAbility(presetName, null);
|
||||
public boolean executeAbility(String key) {
|
||||
return executeAbility(key, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean executePresetAbility(String presetName, Object target) {
|
||||
// Resolve target
|
||||
public boolean executeAbility(String key, Object target) {
|
||||
EntityLivingBase targetEntity = resolveTarget(target);
|
||||
|
||||
// Use the direct preset execution method
|
||||
return data.executePresetAbility(presetName, targetEntity);
|
||||
return data.executeAbility(key, targetEntity);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -0,0 +1,112 @@
|
||||
package noppes.npcs.scripted.wrapper;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import noppes.npcs.api.ability.IAbility;
|
||||
import noppes.npcs.api.ability.IPlayerAbilityData;
|
||||
import noppes.npcs.controllers.data.PlayerAbilityData;
|
||||
import noppes.npcs.controllers.data.PlayerData;
|
||||
|
||||
/**
|
||||
* Script wrapper for PlayerAbilityData providing API access to player abilities.
|
||||
*/
|
||||
public class ScriptPlayerAbilityData implements IPlayerAbilityData {
|
||||
|
||||
private final PlayerAbilityData data;
|
||||
private final PlayerData playerData;
|
||||
|
||||
public ScriptPlayerAbilityData(PlayerData playerData) {
|
||||
this.playerData = playerData;
|
||||
this.data = playerData.abilityData;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getUnlockedAbilities() {
|
||||
return data.getUnlockedAbilities().toArray(new String[0]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unlockAbility(String key) {
|
||||
data.unlockAbility(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void lockAbility(String key) {
|
||||
data.lockAbility(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasUnlockedAbility(String key) {
|
||||
return data.hasUnlockedAbility(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSelectedIndex() {
|
||||
return data.getSelectedIndex();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSelectedIndex(int index) {
|
||||
data.setSelectedIndex(index);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSelectedAbilityKey() {
|
||||
return data.getSelectedAbilityKey();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void selectNext() {
|
||||
data.selectNext();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void selectPrevious() {
|
||||
data.selectPrevious();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isExecutingAbility() {
|
||||
return data.isExecutingAbility();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAbility getCurrentAbility() {
|
||||
return data.getCurrentAbility();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void interruptCurrentAbility() {
|
||||
data.interruptCurrentAbility();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOnCooldown(String key) {
|
||||
EntityPlayer player = playerData.player;
|
||||
if (player == null) return false;
|
||||
return data.isOnCooldown(key, player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resetCooldown(String key) {
|
||||
data.resetCooldown(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resetAllCooldowns() {
|
||||
data.resetAllCooldowns();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean activateAbility() {
|
||||
EntityPlayer player = playerData.player;
|
||||
if (player == null) return false;
|
||||
return data.activateAbility(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean activateAbility(String key) {
|
||||
EntityPlayer player = playerData.player;
|
||||
if (player == null) return false;
|
||||
return data.activateAbility(player, key);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user