2013-03-01 06:52:01 +01:00
|
|
|
package com.gmail.nossr50.skills.unarmed;
|
|
|
|
|
|
|
|
import org.bukkit.Material;
|
2013-03-07 01:19:26 +01:00
|
|
|
import org.bukkit.block.BlockState;
|
2013-03-03 07:31:14 +01:00
|
|
|
import org.bukkit.entity.LivingEntity;
|
2013-03-01 06:52:01 +01:00
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
import org.bukkit.inventory.ItemStack;
|
|
|
|
|
|
|
|
import com.gmail.nossr50.mcMMO;
|
|
|
|
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
|
2013-03-03 07:31:14 +01:00
|
|
|
import com.gmail.nossr50.datatypes.skills.AbilityType;
|
2013-03-01 06:52:01 +01:00
|
|
|
import com.gmail.nossr50.datatypes.skills.SkillType;
|
2013-03-03 07:31:14 +01:00
|
|
|
import com.gmail.nossr50.datatypes.skills.ToolType;
|
2013-03-01 06:52:01 +01:00
|
|
|
import com.gmail.nossr50.events.skills.unarmed.McMMOPlayerDisarmEvent;
|
|
|
|
import com.gmail.nossr50.locale.LocaleLoader;
|
|
|
|
import com.gmail.nossr50.skills.SkillManager;
|
|
|
|
import com.gmail.nossr50.util.Misc;
|
|
|
|
import com.gmail.nossr50.util.Permissions;
|
2013-08-23 16:58:50 +02:00
|
|
|
import com.gmail.nossr50.util.skills.CombatUtils;
|
2013-03-01 06:52:01 +01:00
|
|
|
import com.gmail.nossr50.util.skills.SkillUtils;
|
|
|
|
|
|
|
|
public class UnarmedManager extends SkillManager {
|
|
|
|
public UnarmedManager(McMMOPlayer mcMMOPlayer) {
|
|
|
|
super(mcMMOPlayer, SkillType.UNARMED);
|
|
|
|
}
|
|
|
|
|
2013-03-03 07:31:14 +01:00
|
|
|
public boolean canActivateAbility() {
|
|
|
|
return mcMMOPlayer.getToolPreparationMode(ToolType.FISTS) && Permissions.berserk(getPlayer());
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean canUseIronArm() {
|
|
|
|
return Permissions.bonusDamage(getPlayer(), skill);
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean canUseBerserk() {
|
|
|
|
return mcMMOPlayer.getAbilityMode(AbilityType.BERSERK) && Permissions.berserk(getPlayer());
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean canDisarm(LivingEntity target) {
|
|
|
|
return target instanceof Player && ((Player) target).getItemInHand().getType() != Material.AIR && Permissions.disarm(getPlayer());
|
|
|
|
}
|
|
|
|
|
2013-03-04 15:40:03 +01:00
|
|
|
public boolean canDeflect() {
|
|
|
|
Player player = getPlayer();
|
|
|
|
|
|
|
|
return player.getItemInHand().getType() == Material.AIR && Permissions.arrowDeflect(player);
|
|
|
|
}
|
|
|
|
|
2013-03-07 01:19:26 +01:00
|
|
|
public boolean canUseBlockCracker() {
|
|
|
|
return Permissions.blockCracker(getPlayer());
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean blockCrackerCheck(BlockState blockState) {
|
|
|
|
Material type = blockState.getType();
|
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
case SMOOTH_BRICK:
|
|
|
|
if (Unarmed.blockCrackerSmoothBrick && blockState.getRawData() == (byte) 0x0) {
|
|
|
|
blockState.setRawData((byte) 0x2);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-01 06:52:01 +01:00
|
|
|
/**
|
|
|
|
* Check for disarm.
|
|
|
|
*
|
|
|
|
* @param defender The defending player
|
|
|
|
*/
|
|
|
|
public void disarmCheck(Player defender) {
|
2013-03-04 15:40:03 +01:00
|
|
|
if (SkillUtils.activationSuccessful(getSkillLevel(), getActivationChance(), Unarmed.disarmMaxChance, Unarmed.disarmMaxBonusLevel) && !hasIronGrip(defender)) {
|
2013-03-01 06:52:01 +01:00
|
|
|
McMMOPlayerDisarmEvent disarmEvent = new McMMOPlayerDisarmEvent(defender);
|
|
|
|
mcMMO.p.getServer().getPluginManager().callEvent(disarmEvent);
|
|
|
|
|
|
|
|
if (!disarmEvent.isCancelled()) {
|
|
|
|
Misc.dropItem(defender.getLocation(), defender.getItemInHand());
|
|
|
|
|
|
|
|
defender.setItemInHand(new ItemStack(Material.AIR));
|
|
|
|
defender.sendMessage(LocaleLoader.getString("Skills.Disarmed"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check for arrow deflection.
|
|
|
|
*/
|
|
|
|
public boolean deflectCheck() {
|
2013-03-04 15:40:03 +01:00
|
|
|
if (SkillUtils.activationSuccessful(getSkillLevel(), getActivationChance(), Unarmed.deflectMaxChance, Unarmed.deflectMaxBonusLevel)) {
|
|
|
|
getPlayer().sendMessage(LocaleLoader.getString("Combat.ArrowDeflect"));
|
2013-03-01 06:52:01 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-08-23 17:21:56 +02:00
|
|
|
/**
|
|
|
|
* Handle the effects of the Berserk ability
|
|
|
|
*
|
|
|
|
* @param target The {@link LivingEntity} being affected by the ability
|
|
|
|
* @param damage The amount of damage initially dealt by the event
|
|
|
|
*/
|
2013-08-23 16:58:50 +02:00
|
|
|
public void berserkDamage(LivingEntity target, double damage) {
|
|
|
|
damage = (damage * Unarmed.berserkDamageModifier) - damage;
|
|
|
|
|
|
|
|
CombatUtils.dealDamage(target, damage, getPlayer());
|
2013-03-01 06:52:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle the effects of the Iron Arm 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-08-23 16:58:50 +02:00
|
|
|
public void ironArm(LivingEntity target) {
|
2013-08-18 08:38:40 +02:00
|
|
|
int unarmedBonus = Math.min(Unarmed.ironArmMinBonusDamage + (getSkillLevel() / Unarmed.ironArmIncreaseLevel), Unarmed.ironArmMaxBonusDamage);
|
2013-03-01 06:52:01 +01:00
|
|
|
|
2013-08-23 16:58:50 +02:00
|
|
|
CombatUtils.dealDamage(target, unarmedBonus, getPlayer());
|
2013-03-01 06:52:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check Iron Grip ability success
|
|
|
|
*
|
|
|
|
* @param defender The defending player
|
|
|
|
* @return true if the defender was not disarmed, false otherwise
|
|
|
|
*/
|
|
|
|
private boolean hasIronGrip(Player defender) {
|
|
|
|
if (!Misc.isNPCEntity(defender) && Permissions.ironGrip(defender) && SkillUtils.activationSuccessful(defender, skill, Unarmed.ironGripMaxChance, Unarmed.ironGripMaxBonusLevel)) {
|
|
|
|
defender.sendMessage(LocaleLoader.getString("Unarmed.Ability.IronGrip.Defender"));
|
|
|
|
getPlayer().sendMessage(LocaleLoader.getString("Unarmed.Ability.IronGrip.Attacker"));
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|