2013-03-01 06:52:01 +01:00
|
|
|
package com.gmail.nossr50.skills.axes;
|
|
|
|
|
|
|
|
import org.bukkit.entity.LivingEntity;
|
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
import org.bukkit.inventory.ItemStack;
|
|
|
|
|
2013-11-22 18:32:23 +01:00
|
|
|
import com.gmail.nossr50.mcMMO;
|
2013-03-01 06:52:01 +01:00
|
|
|
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
|
|
|
|
import com.gmail.nossr50.datatypes.skills.AbilityType;
|
2013-11-22 18:32:23 +01:00
|
|
|
import com.gmail.nossr50.datatypes.skills.SecondaryAbilityType;
|
2013-03-01 06:52:01 +01:00
|
|
|
import com.gmail.nossr50.datatypes.skills.SkillType;
|
|
|
|
import com.gmail.nossr50.datatypes.skills.ToolType;
|
2013-11-22 18:32:23 +01:00
|
|
|
import com.gmail.nossr50.events.skills.secondaryabilities.SecondaryAbilityWeightedActivationCheckEvent;
|
2013-03-01 06:52:01 +01:00
|
|
|
import com.gmail.nossr50.locale.LocaleLoader;
|
|
|
|
import com.gmail.nossr50.skills.SkillManager;
|
|
|
|
import com.gmail.nossr50.util.ItemUtils;
|
2013-03-05 04:45:37 +01:00
|
|
|
import com.gmail.nossr50.util.Misc;
|
2013-03-01 06:52:01 +01:00
|
|
|
import com.gmail.nossr50.util.Permissions;
|
|
|
|
import com.gmail.nossr50.util.player.UserManager;
|
|
|
|
import com.gmail.nossr50.util.skills.CombatUtils;
|
|
|
|
import com.gmail.nossr50.util.skills.ParticleEffectUtils;
|
|
|
|
import com.gmail.nossr50.util.skills.SkillUtils;
|
|
|
|
|
2013-03-03 16:09:41 +01:00
|
|
|
public class AxesManager extends SkillManager {
|
|
|
|
public AxesManager(McMMOPlayer mcMMOPlayer) {
|
2013-03-01 06:52:01 +01:00
|
|
|
super(mcMMOPlayer, SkillType.AXES);
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean canUseAxeMastery() {
|
2013-11-22 18:32:23 +01:00
|
|
|
return Permissions.secondaryAbilityEnabled(getPlayer(), SecondaryAbilityType.AXE_MASTERY);
|
2013-03-01 06:52:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public boolean canCriticalHit(LivingEntity target) {
|
2013-11-22 18:32:23 +01:00
|
|
|
return target.isValid() && Permissions.secondaryAbilityEnabled(getPlayer(), SecondaryAbilityType.CRITICAL_HIT);
|
2013-03-01 06:52:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public boolean canImpact(LivingEntity target) {
|
2013-11-22 18:32:23 +01:00
|
|
|
return target.isValid() && Permissions.secondaryAbilityEnabled(getPlayer(), SecondaryAbilityType.ARMOR_IMPACT) && Axes.hasArmor(target);
|
2013-03-01 06:52:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public boolean canGreaterImpact(LivingEntity target) {
|
2013-11-22 18:32:23 +01:00
|
|
|
return target.isValid() && Permissions.secondaryAbilityEnabled(getPlayer(), SecondaryAbilityType.GREATER_IMPACT) && !Axes.hasArmor(target);
|
2013-03-01 06:52:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public boolean canUseSkullSplitter(LivingEntity target) {
|
2013-03-03 17:06:05 +01:00
|
|
|
return target.isValid() && mcMMOPlayer.getAbilityMode(AbilityType.SKULL_SPLITTER) && Permissions.skullSplitter(getPlayer());
|
2013-03-01 06:52:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public boolean canActivateAbility() {
|
2013-03-03 17:06:05 +01:00
|
|
|
return mcMMOPlayer.getToolPreparationMode(ToolType.AXE) && Permissions.skullSplitter(getPlayer());
|
2013-03-01 06:52:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle the effects of the Axe Mastery ability
|
|
|
|
*
|
2013-08-23 17:21:56 +02:00
|
|
|
* @param target The {@link LivingEntity} being affected by the ability
|
2013-03-01 06:52:01 +01:00
|
|
|
*/
|
2013-09-12 17:52:34 +02:00
|
|
|
public double axeMastery(LivingEntity target) {
|
2013-11-22 18:32:23 +01:00
|
|
|
double axeBonus = Math.min(getSkillLevel() / (Axes.axeMasteryMaxBonusLevel / Axes.axeMasteryMaxBonus), Axes.axeMasteryMaxBonus);
|
2013-03-01 06:52:01 +01:00
|
|
|
|
2013-09-12 17:52:34 +02:00
|
|
|
return CombatUtils.callFakeDamageEvent(getPlayer(), target, axeBonus);
|
2013-03-01 06:52:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle the effects of the Critical Hit ability
|
|
|
|
*
|
|
|
|
* @param target The {@link LivingEntity} being affected by the ability
|
|
|
|
* @param damage The amount of damage initially dealt by the event
|
|
|
|
*/
|
2013-09-12 17:52:34 +02:00
|
|
|
public double criticalHit(LivingEntity target, double damage) {
|
2013-11-22 18:32:23 +01:00
|
|
|
if (!SkillUtils.activationSuccessful(SecondaryAbilityType.CRITICAL_HIT, getPlayer(), getSkillLevel(), activationChance)) {
|
2013-09-12 17:52:34 +02:00
|
|
|
return 0;
|
2013-08-23 16:58:50 +02:00
|
|
|
}
|
2013-03-01 06:52:01 +01:00
|
|
|
|
2013-08-23 16:58:50 +02:00
|
|
|
Player player = getPlayer();
|
2013-03-01 06:52:01 +01:00
|
|
|
|
2013-08-23 16:58:50 +02:00
|
|
|
player.sendMessage(LocaleLoader.getString("Axes.Combat.CriticalHit"));
|
|
|
|
|
|
|
|
if (target instanceof Player) {
|
|
|
|
((Player) target).sendMessage(LocaleLoader.getString("Axes.Combat.CritStruck"));
|
2013-03-01 06:52:01 +01:00
|
|
|
|
2013-08-23 16:58:50 +02:00
|
|
|
damage = (damage * Axes.criticalHitPVPModifier) - damage;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
damage = (damage * Axes.criticalHitPVEModifier) - damage;
|
2013-03-01 06:52:01 +01:00
|
|
|
}
|
|
|
|
|
2013-09-12 17:52:34 +02:00
|
|
|
return CombatUtils.callFakeDamageEvent(player, target, damage);
|
2013-03-01 06:52:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle the effects of the Impact ability
|
|
|
|
*
|
|
|
|
* @param target The {@link LivingEntity} being affected by Impact
|
|
|
|
*/
|
|
|
|
public void impactCheck(LivingEntity target) {
|
|
|
|
int durabilityDamage = 1 + (getSkillLevel() / Axes.impactIncreaseLevel);
|
|
|
|
|
|
|
|
for (ItemStack armor : target.getEquipment().getArmorContents()) {
|
2013-11-22 18:32:23 +01:00
|
|
|
if (ItemUtils.isArmor(armor)) {
|
|
|
|
double chance = Axes.impactChance / activationChance;
|
|
|
|
SecondaryAbilityWeightedActivationCheckEvent event = new SecondaryAbilityWeightedActivationCheckEvent(getPlayer(), SecondaryAbilityType.ARMOR_IMPACT, chance);
|
|
|
|
mcMMO.p.getServer().getPluginManager().callEvent(event);
|
|
|
|
if ((event.getChance() * activationChance) > Misc.getRandom().nextInt(activationChance)) {
|
|
|
|
SkillUtils.handleDurabilityChange(armor, durabilityDamage, Axes.impactMaxDurabilityModifier);
|
|
|
|
}
|
2013-03-01 06:52:01 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle the effects of the Greater Impact ability
|
|
|
|
*
|
|
|
|
* @param target The {@link LivingEntity} being affected by the ability
|
|
|
|
*/
|
2013-09-12 17:52:34 +02:00
|
|
|
public double greaterImpact(LivingEntity target) {
|
2013-11-22 18:32:23 +01:00
|
|
|
double chance = Axes.greaterImpactChance / activationChance;
|
|
|
|
SecondaryAbilityWeightedActivationCheckEvent event = new SecondaryAbilityWeightedActivationCheckEvent(getPlayer(), SecondaryAbilityType.GREATER_IMPACT, chance);
|
|
|
|
mcMMO.p.getServer().getPluginManager().callEvent(event);
|
|
|
|
if ((event.getChance() * activationChance) <= Misc.getRandom().nextInt(activationChance)) {
|
2013-09-12 17:52:34 +02:00
|
|
|
return 0;
|
2013-08-23 16:58:50 +02:00
|
|
|
}
|
2013-03-01 06:52:01 +01:00
|
|
|
|
2013-08-23 16:58:50 +02:00
|
|
|
Player player = getPlayer();
|
2013-03-01 06:52:01 +01:00
|
|
|
|
2013-08-23 16:58:50 +02:00
|
|
|
ParticleEffectUtils.playGreaterImpactEffect(target);
|
|
|
|
target.setVelocity(player.getLocation().getDirection().normalize().multiply(Axes.greaterImpactKnockbackMultiplier));
|
|
|
|
|
|
|
|
if (mcMMOPlayer.useChatNotifications()) {
|
|
|
|
player.sendMessage(LocaleLoader.getString("Axes.Combat.GI.Proc"));
|
|
|
|
}
|
2013-03-01 06:52:01 +01:00
|
|
|
|
2013-08-23 16:58:50 +02:00
|
|
|
if (target instanceof Player) {
|
|
|
|
Player defender = (Player) target;
|
2013-03-01 06:52:01 +01:00
|
|
|
|
2013-08-23 16:58:50 +02:00
|
|
|
if (UserManager.getPlayer(defender).useChatNotifications()) {
|
|
|
|
defender.sendMessage(LocaleLoader.getString("Axes.Combat.GI.Struck"));
|
2013-03-01 06:52:01 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-12 17:52:34 +02:00
|
|
|
return CombatUtils.callFakeDamageEvent(player, target, Axes.greaterImpactBonusDamage);
|
2013-03-01 06:52:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle the effects of the Skull Splitter ability
|
|
|
|
*
|
|
|
|
* @param target The {@link LivingEntity} being affected by the ability
|
|
|
|
* @param damage The amount of damage initially dealt by the event
|
|
|
|
*/
|
2013-07-11 18:43:36 +02:00
|
|
|
public void skullSplitterCheck(LivingEntity target, double damage) {
|
2013-03-01 06:52:01 +01:00
|
|
|
CombatUtils.applyAbilityAoE(getPlayer(), target, damage / Axes.skullSplitterModifier, skill);
|
|
|
|
}
|
|
|
|
}
|