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-12-02 00:43:17 +01:00
|
|
|
import org.bukkit.entity.Item;
|
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;
|
2013-09-05 20:55:08 +02:00
|
|
|
import org.bukkit.material.MaterialData;
|
|
|
|
import org.bukkit.material.SmoothBrick;
|
2013-12-02 00:43:17 +01:00
|
|
|
import com.gmail.nossr50.mcMMO;
|
|
|
|
import com.gmail.nossr50.config.AdvancedConfig;
|
2013-03-01 06:52:01 +01:00
|
|
|
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
|
2013-03-03 07:31:14 +01:00
|
|
|
import com.gmail.nossr50.datatypes.skills.AbilityType;
|
2013-11-22 18:48:53 +01:00
|
|
|
import com.gmail.nossr50.datatypes.skills.SecondaryAbility;
|
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.locale.LocaleLoader;
|
|
|
|
import com.gmail.nossr50.skills.SkillManager;
|
2013-10-18 14:31:00 +02:00
|
|
|
import com.gmail.nossr50.util.EventUtils;
|
2013-03-01 06:52:01 +01:00
|
|
|
import com.gmail.nossr50.util.Misc;
|
|
|
|
import com.gmail.nossr50.util.Permissions;
|
2013-12-02 00:43:17 +01:00
|
|
|
import com.gmail.nossr50.util.player.UserManager;
|
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() {
|
2013-11-22 18:48:53 +01:00
|
|
|
return Permissions.secondaryAbilityEnabled(getPlayer(), SecondaryAbility.IRON_ARM);
|
2013-03-03 07:31:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public boolean canUseBerserk() {
|
|
|
|
return mcMMOPlayer.getAbilityMode(AbilityType.BERSERK) && Permissions.berserk(getPlayer());
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean canDisarm(LivingEntity target) {
|
2013-11-22 18:48:53 +01:00
|
|
|
return target instanceof Player && ((Player) target).getItemInHand().getType() != Material.AIR && Permissions.secondaryAbilityEnabled(getPlayer(), SecondaryAbility.DISARM);
|
2013-03-03 07:31:14 +01:00
|
|
|
}
|
|
|
|
|
2013-03-04 15:40:03 +01:00
|
|
|
public boolean canDeflect() {
|
|
|
|
Player player = getPlayer();
|
|
|
|
|
2013-11-22 18:48:53 +01:00
|
|
|
return player.getItemInHand().getType() == Material.AIR && Permissions.secondaryAbilityEnabled(getPlayer(), SecondaryAbility.DEFLECT);
|
2013-03-04 15:40:03 +01:00
|
|
|
}
|
|
|
|
|
2013-03-07 01:19:26 +01:00
|
|
|
public boolean canUseBlockCracker() {
|
2013-11-22 18:48:53 +01:00
|
|
|
return Permissions.secondaryAbilityEnabled(getPlayer(), SecondaryAbility.BLOCK_CRACKER);
|
2013-03-07 01:19:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public boolean blockCrackerCheck(BlockState blockState) {
|
2013-09-05 20:55:08 +02:00
|
|
|
MaterialData data = blockState.getData();
|
2013-03-07 01:19:26 +01:00
|
|
|
|
2013-09-05 20:55:08 +02:00
|
|
|
switch (blockState.getType()) {
|
2013-03-07 01:19:26 +01:00
|
|
|
case SMOOTH_BRICK:
|
2013-09-05 20:55:08 +02:00
|
|
|
if (!Unarmed.blockCrackerSmoothBrick) {
|
|
|
|
return false;
|
2013-03-07 01:19:26 +01:00
|
|
|
}
|
2013-09-05 20:55:08 +02:00
|
|
|
|
|
|
|
// Yes, this is awkward, but it's the *right* way to do it.
|
|
|
|
SmoothBrick smoothBrick = (SmoothBrick) data;
|
|
|
|
|
|
|
|
if (smoothBrick.getMaterial() != Material.STONE) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
smoothBrick.setMaterial(Material.COBBLESTONE);
|
2013-03-07 01:19:26 +01:00
|
|
|
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-11-22 18:48:53 +01:00
|
|
|
if (SkillUtils.activationSuccessful(SecondaryAbility.DISARM, getPlayer(), getSkillLevel(), activationChance) && !hasIronGrip(defender)) {
|
2013-10-18 14:31:00 +02:00
|
|
|
if (EventUtils.callDisarmEvent(defender).isCancelled()) {
|
|
|
|
return;
|
|
|
|
}
|
2013-03-01 06:52:01 +01:00
|
|
|
|
2013-12-02 00:43:17 +01:00
|
|
|
Item item = Misc.dropItem(defender.getLocation(), defender.getItemInHand());
|
|
|
|
|
|
|
|
if (item != null && AdvancedConfig.getInstance().getDisarmProtected()) {
|
|
|
|
item.setMetadata(mcMMO.disarmedItemKey, UserManager.getPlayer(defender).getPlayerMetadata());
|
|
|
|
}
|
2013-03-01 06:52:01 +01:00
|
|
|
|
2013-10-18 14:31:00 +02:00
|
|
|
defender.setItemInHand(new ItemStack(Material.AIR));
|
|
|
|
defender.sendMessage(LocaleLoader.getString("Skills.Disarmed"));
|
2013-03-01 06:52:01 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check for arrow deflection.
|
|
|
|
*/
|
|
|
|
public boolean deflectCheck() {
|
2013-11-22 18:48:53 +01:00
|
|
|
if (SkillUtils.activationSuccessful(SecondaryAbility.DEFLECT, getPlayer(), getSkillLevel(), activationChance)) {
|
2013-03-04 15:40:03 +01:00
|
|
|
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-09-12 17:52:34 +02:00
|
|
|
public double berserkDamage(LivingEntity target, double damage) {
|
2013-08-23 16:58:50 +02:00
|
|
|
damage = (damage * Unarmed.berserkDamageModifier) - damage;
|
|
|
|
|
2013-09-12 17:52:34 +02:00
|
|
|
return CombatUtils.callFakeDamageEvent(getPlayer(), target, damage);
|
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-09-12 17:52:34 +02:00
|
|
|
public double ironArm(LivingEntity target) {
|
2013-09-12 20:18:13 +02:00
|
|
|
double unarmedBonus = Math.min(Unarmed.ironArmMinBonusDamage + (getSkillLevel() / Unarmed.ironArmIncreaseLevel), Unarmed.ironArmMaxBonusDamage);
|
2013-03-01 06:52:01 +01:00
|
|
|
|
2013-09-12 17:52:34 +02:00
|
|
|
return CombatUtils.callFakeDamageEvent(getPlayer(), target, unarmedBonus);
|
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) {
|
2013-11-22 18:48:53 +01:00
|
|
|
if (!Misc.isNPCEntity(defender) && Permissions.secondaryAbilityEnabled(defender, SecondaryAbility.IRON_GRIP) && SkillUtils.activationSuccessful(SecondaryAbility.IRON_GRIP, defender, skill)) {
|
2013-03-01 06:52:01 +01:00
|
|
|
defender.sendMessage(LocaleLoader.getString("Unarmed.Ability.IronGrip.Defender"));
|
|
|
|
getPlayer().sendMessage(LocaleLoader.getString("Unarmed.Ability.IronGrip.Attacker"));
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|