mcMMO/src/main/java/com/gmail/nossr50/skills/axes/AxeManager.java

149 lines
6.1 KiB
Java
Raw Normal View History

2013-01-10 15:26:28 +01:00
package com.gmail.nossr50.skills.axes;
2013-02-26 21:59:16 +01:00
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.LivingEntity;
2013-02-26 21:59:16 +01:00
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
2013-01-10 15:26:28 +01:00
import com.gmail.nossr50.datatypes.McMMOPlayer;
2013-02-26 21:59:16 +01:00
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.mods.ModChecks;
2013-01-11 04:39:08 +01:00
import com.gmail.nossr50.skills.SkillManager;
2013-02-26 21:59:16 +01:00
import com.gmail.nossr50.skills.utilities.AbilityType;
import com.gmail.nossr50.skills.utilities.CombatTools;
import com.gmail.nossr50.skills.utilities.SkillTools;
import com.gmail.nossr50.skills.utilities.SkillType;
2013-02-26 21:59:16 +01:00
import com.gmail.nossr50.skills.utilities.ToolType;
import com.gmail.nossr50.util.ItemChecks;
import com.gmail.nossr50.util.ParticleEffectUtils;
import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.Users;
2013-01-11 04:39:08 +01:00
public class AxeManager extends SkillManager {
public AxeManager(McMMOPlayer mcMMOPlayer) {
super(mcMMOPlayer, SkillType.AXES);
2013-01-11 04:39:08 +01:00
}
2013-02-26 21:59:16 +01:00
public boolean canUseAxeMastery() {
return Permissions.bonusDamage(getPlayer(), skill);
}
public boolean canCriticalHit(LivingEntity target) {
return target.isValid() && Permissions.criticalStrikes(getPlayer());
}
public boolean canImpact(LivingEntity target) {
return target.isValid() && Permissions.armorImpact(getPlayer()) && Axes.hasArmor(target);
}
public boolean canGreaterImpact(LivingEntity target) {
return target.isValid() && Permissions.greaterImpact(getPlayer()) && !Axes.hasArmor(target);
}
public boolean canUseSkullSplitter(LivingEntity target) {
return target.isValid() && getProfile().getAbilityMode(AbilityType.SKULL_SPLITTER) && Permissions.skullSplitter(getPlayer());
}
public boolean canActivateAbility() {
return getProfile().getToolPreparationMode(ToolType.AXE) && Permissions.skullSplitter(getPlayer());
}
/**
* Handle the effects of the Axe Mastery ability
*
* @param damage The amount of damage initially dealt by the event
* @return the modified event damage
*/
public int axeMasteryCheck(int damage) {
int axeBonus = Math.min(getSkillLevel() / (Axes.bonusDamageMaxBonusLevel / Axes.bonusDamageMaxBonus), Axes.bonusDamageMaxBonus);
return damage + axeBonus;
}
2013-01-11 04:39:08 +01:00
/**
2013-02-26 21:59:16 +01:00
* Handle the effects of the Critical Hit ability
2013-01-11 04:39:08 +01:00
*
2013-02-26 21:59:16 +01:00
* @param target The {@link LivingEntity} being affected by the ability
* @param damage The amount of damage initially dealt by the event
* @return the modified event damage if the ability was successful, the original event damage otherwise
2013-01-11 04:39:08 +01:00
*/
2013-02-26 21:59:16 +01:00
public int criticalHitCheck(LivingEntity target, int damage) {
Player player = getPlayer();
if (SkillTools.activationSuccessful(player, skill, Axes.criticalHitMaxChance, Axes.criticalHitMaxBonusLevel)) {
player.sendMessage(LocaleLoader.getString("Axes.Combat.CriticalHit"));
if (target instanceof Player) {
((Player) target).sendMessage(LocaleLoader.getString("Axes.Combat.CritStruck"));
return (int) (damage * Axes.criticalHitPVPModifier);
}
2013-01-11 04:39:08 +01:00
2013-02-26 21:59:16 +01:00
return (int) (damage * Axes.criticalHitPVEModifier);
}
return damage;
2013-01-11 04:39:08 +01:00
}
/**
2013-02-26 21:59:16 +01:00
* Handle the effects of the Impact ability
*
2013-02-26 21:59:16 +01:00
* @param target The {@link LivingEntity} being affected by Impact
*/
2013-02-26 21:59:16 +01:00
public void impactCheck(LivingEntity target) {
int durabilityDamage = 1 + (getSkillLevel() / Axes.impactIncreaseLevel);
2013-02-26 21:59:16 +01:00
for (ItemStack armor : target.getEquipment().getArmorContents()) {
if (ItemChecks.isArmor(armor) && SkillTools.activationSuccessful(getPlayer(), skill, Axes.impactChance)) {
double durabilityModifier = 1 / (armor.getEnchantmentLevel(Enchantment.DURABILITY) + 1); // Modifier to simulate the durability enchantment behavior
double modifiedDurabilityDamage = durabilityDamage * durabilityModifier;
double maxDurabilityDamage = (ModChecks.isCustomArmor(armor) ? ModChecks.getArmorFromItemStack(armor).getDurability() : armor.getType().getMaxDurability()) * Axes.impactMaxDurabilityDamageModifier;
2013-02-26 21:59:16 +01:00
armor.setDurability((short) (Math.min(modifiedDurabilityDamage, maxDurabilityDamage) + armor.getDurability()));
}
}
}
2013-01-15 22:16:46 +01:00
/**
2013-02-26 21:59:16 +01:00
* Handle the effects of the Greater Impact ability
2013-01-15 22:16:46 +01:00
*
2013-02-26 21:59:16 +01:00
* @param target The {@link LivingEntity} being affected by the ability
* @param damage The amount of damage initially dealt by the event
* @return the modified event damage if the ability was successful, the original event damage otherwise
2013-01-15 22:16:46 +01:00
*/
2013-02-26 21:59:16 +01:00
public int greaterImpactCheck(LivingEntity target, int damage) {
Player player = getPlayer();
if (SkillTools.activationSuccessful(player, skill, Axes.greaterImpactChance)) {
ParticleEffectUtils.playGreaterImpactEffect(target);
target.setVelocity(player.getLocation().getDirection().normalize().multiply(Axes.greaterImpactKnockbackMultiplier));
if (getProfile().useChatNotifications()) {
player.sendMessage(LocaleLoader.getString("Axes.Combat.GI.Proc"));
}
2013-01-15 22:16:46 +01:00
2013-02-26 21:59:16 +01:00
if (target instanceof Player) {
Player defender = (Player) target;
if (Users.getPlayer(defender).getProfile().useChatNotifications()) {
defender.sendMessage(LocaleLoader.getString("Axes.Combat.GI.Struck"));
}
}
return damage + Axes.greaterImpactBonusDamage;
2013-01-15 22:16:46 +01:00
}
2013-02-26 21:59:16 +01:00
return damage;
2013-01-15 22:16:46 +01:00
}
/**
2013-02-26 21:59:16 +01:00
* Handle the effects of the Skull Splitter ability
*
2013-02-26 21:59:16 +01:00
* @param target The {@link LivingEntity} being affected by the ability
* @param damage The amount of damage initially dealt by the event
*/
2013-02-26 21:59:16 +01:00
public void skullSplitterCheck(LivingEntity target, int damage) {
CombatTools.applyAbilityAoE(getPlayer(), target, damage / Axes.skullSplitterModifier, skill);
}
2013-01-10 15:26:28 +01:00
}