2013-03-01 06:52:01 +01:00
|
|
|
package com.gmail.nossr50.skills.unarmed;
|
|
|
|
|
2013-12-02 00:43:17 +01:00
|
|
|
import com.gmail.nossr50.config.AdvancedConfig;
|
2013-03-01 06:52:01 +01:00
|
|
|
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
|
2018-12-29 14:24:55 +01:00
|
|
|
import com.gmail.nossr50.datatypes.skills.SuperAbility;
|
|
|
|
import com.gmail.nossr50.datatypes.skills.PrimarySkill;
|
|
|
|
import com.gmail.nossr50.datatypes.skills.SubSkill;
|
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;
|
2018-07-24 04:13:57 +02:00
|
|
|
import com.gmail.nossr50.mcMMO;
|
2013-03-01 06:52:01 +01:00
|
|
|
import com.gmail.nossr50.skills.SkillManager;
|
2013-10-18 14:31:00 +02:00
|
|
|
import com.gmail.nossr50.util.EventUtils;
|
2014-12-29 06:12:46 +01:00
|
|
|
import com.gmail.nossr50.util.ItemUtils;
|
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;
|
2018-12-29 14:24:55 +01:00
|
|
|
import com.gmail.nossr50.util.skills.SubSkillActivationType;
|
2013-03-01 06:52:01 +01:00
|
|
|
import com.gmail.nossr50.util.skills.SkillUtils;
|
2018-07-24 04:13:57 +02:00
|
|
|
import org.bukkit.Material;
|
|
|
|
import org.bukkit.block.BlockState;
|
|
|
|
import org.bukkit.entity.Item;
|
|
|
|
import org.bukkit.entity.LivingEntity;
|
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
import org.bukkit.inventory.ItemStack;
|
2018-07-27 01:53:29 +02:00
|
|
|
import org.bukkit.block.data.BlockData;
|
2013-03-01 06:52:01 +01:00
|
|
|
|
|
|
|
public class UnarmedManager extends SkillManager {
|
|
|
|
public UnarmedManager(McMMOPlayer mcMMOPlayer) {
|
2018-12-29 14:24:55 +01:00
|
|
|
super(mcMMOPlayer, PrimarySkill.UNARMED);
|
2013-03-01 06:52:01 +01:00
|
|
|
}
|
|
|
|
|
2013-03-03 07:31:14 +01:00
|
|
|
public boolean canActivateAbility() {
|
|
|
|
return mcMMOPlayer.getToolPreparationMode(ToolType.FISTS) && Permissions.berserk(getPlayer());
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean canUseIronArm() {
|
2018-12-29 14:24:55 +01:00
|
|
|
return Permissions.isSubSkillEnabled(getPlayer(), SubSkill.UNARMED_IRON_ARM);
|
2013-03-03 07:31:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public boolean canUseBerserk() {
|
2018-12-29 14:24:55 +01:00
|
|
|
return mcMMOPlayer.getAbilityMode(SuperAbility.BERSERK) && Permissions.berserk(getPlayer());
|
2013-03-03 07:31:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public boolean canDisarm(LivingEntity target) {
|
2018-12-29 14:24:55 +01:00
|
|
|
return target instanceof Player && ((Player) target).getInventory().getItemInMainHand().getType() != Material.AIR && Permissions.isSubSkillEnabled(getPlayer(), SubSkill.UNARMED_DISARM);
|
2013-03-03 07:31:14 +01:00
|
|
|
}
|
|
|
|
|
2013-03-04 15:40:03 +01:00
|
|
|
public boolean canDeflect() {
|
|
|
|
Player player = getPlayer();
|
|
|
|
|
2018-12-29 14:24:55 +01:00
|
|
|
return ItemUtils.isUnarmed(player.getInventory().getItemInMainHand()) && Permissions.isSubSkillEnabled(getPlayer(), SubSkill.UNARMED_DEFLECT);
|
2013-03-04 15:40:03 +01:00
|
|
|
}
|
|
|
|
|
2013-03-07 01:19:26 +01:00
|
|
|
public boolean canUseBlockCracker() {
|
2018-12-29 14:24:55 +01:00
|
|
|
return Permissions.isSubSkillEnabled(getPlayer(), SubSkill.UNARMED_BLOCK_CRACKER);
|
2013-03-07 01:19:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public boolean blockCrackerCheck(BlockState blockState) {
|
2018-12-29 14:24:55 +01:00
|
|
|
if (!SkillUtils.isActivationSuccessful(SubSkillActivationType.ALWAYS_FIRES, SubSkill.UNARMED_BLOCK_CRACKER, getPlayer(), null, 0, 0)) {
|
2014-05-11 14:58:08 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-07-27 01:53:29 +02:00
|
|
|
BlockData data = blockState.getBlockData();
|
2013-03-07 01:19:26 +01:00
|
|
|
|
2013-09-05 20:55:08 +02:00
|
|
|
switch (blockState.getType()) {
|
2018-07-24 04:13:57 +02:00
|
|
|
case STONE_BRICKS:
|
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
|
|
|
|
2018-07-24 04:13:57 +02:00
|
|
|
blockState.setType(Material.CRACKED_STONE_BRICKS);
|
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) {
|
2018-12-29 14:24:55 +01:00
|
|
|
if (SkillUtils.isActivationSuccessful(SubSkillActivationType.RANDOM_LINEAR_100_SCALE_WITH_CAP, SubSkill.UNARMED_DISARM, getPlayer(), this.skill, 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
|
|
|
|
2016-03-11 15:20:23 +01:00
|
|
|
Item item = Misc.dropItem(defender.getLocation(), defender.getInventory().getItemInMainHand());
|
2013-12-02 00:43:17 +01:00
|
|
|
|
|
|
|
if (item != null && AdvancedConfig.getInstance().getDisarmProtected()) {
|
|
|
|
item.setMetadata(mcMMO.disarmedItemKey, UserManager.getPlayer(defender).getPlayerMetadata());
|
|
|
|
}
|
2013-03-01 06:52:01 +01:00
|
|
|
|
2016-03-11 15:20:23 +01:00
|
|
|
defender.getInventory().setItemInMainHand(new ItemStack(Material.AIR));
|
2013-10-18 14:31:00 +02:00
|
|
|
defender.sendMessage(LocaleLoader.getString("Skills.Disarmed"));
|
2013-03-01 06:52:01 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check for arrow deflection.
|
|
|
|
*/
|
|
|
|
public boolean deflectCheck() {
|
2018-12-29 14:24:55 +01:00
|
|
|
if (SkillUtils.isActivationSuccessful(SubSkillActivationType.RANDOM_LINEAR_100_SCALE_WITH_CAP, SubSkill.UNARMED_DEFLECT, getPlayer(), this.skill, 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 damage The amount of damage initially dealt by the event
|
|
|
|
*/
|
2014-06-29 16:38:40 +02:00
|
|
|
public double berserkDamage(double damage) {
|
2013-08-23 16:58:50 +02:00
|
|
|
damage = (damage * Unarmed.berserkDamageModifier) - damage;
|
|
|
|
|
2014-06-29 16:38:40 +02:00
|
|
|
return damage;
|
2013-03-01 06:52:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle the effects of the Iron Arm ability
|
|
|
|
*/
|
2014-06-29 16:38:40 +02:00
|
|
|
public double ironArm() {
|
2018-12-29 14:24:55 +01:00
|
|
|
if (!SkillUtils.isActivationSuccessful(SubSkillActivationType.ALWAYS_FIRES, SubSkill.UNARMED_IRON_ARM, getPlayer(), null, 0, 0)) {
|
2014-05-11 14:58:08 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-12-27 12:04:55 +01:00
|
|
|
//linear check no cap
|
2014-06-29 16:38:40 +02:00
|
|
|
return Math.min(Unarmed.ironArmMinBonusDamage + (getSkillLevel() / Unarmed.ironArmIncreaseLevel), Unarmed.ironArmMaxBonusDamage);
|
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) {
|
2018-12-29 14:24:55 +01:00
|
|
|
if (!Misc.isNPCEntity(defender) && Permissions.isSubSkillEnabled(defender, SubSkill.UNARMED_IRON_GRIP) && SkillUtils.isActivationSuccessful(SubSkillActivationType.RANDOM_LINEAR_100_SCALE_NO_CAP, SubSkill.UNARMED_IRON_GRIP, getPlayer(), this.skill, getSkillLevel(), activationChance)) {
|
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;
|
|
|
|
}
|
|
|
|
}
|