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;
|
2019-01-14 07:45:16 +01:00
|
|
|
import com.gmail.nossr50.datatypes.interactions.NotificationType;
|
2013-03-01 06:52:01 +01:00
|
|
|
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
|
2019-01-15 07:11:58 +01:00
|
|
|
import com.gmail.nossr50.datatypes.skills.PrimarySkillType;
|
2019-01-09 04:52:52 +01:00
|
|
|
import com.gmail.nossr50.datatypes.skills.SubSkillType;
|
2019-01-13 04:56:54 +01:00
|
|
|
import com.gmail.nossr50.datatypes.skills.SuperAbilityType;
|
2013-03-03 07:31:14 +01:00
|
|
|
import com.gmail.nossr50.datatypes.skills.ToolType;
|
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;
|
2019-01-14 07:45:16 +01:00
|
|
|
import com.gmail.nossr50.util.player.NotificationManager;
|
2013-12-02 00:43:17 +01:00
|
|
|
import com.gmail.nossr50.util.player.UserManager;
|
2019-01-25 05:45:26 +01:00
|
|
|
import com.gmail.nossr50.util.random.RandomChanceUtil;
|
2019-01-28 12:55:30 +01:00
|
|
|
import com.gmail.nossr50.util.skills.RankUtils;
|
2019-01-09 04:52:52 +01:00
|
|
|
import com.gmail.nossr50.util.skills.SkillActivationType;
|
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;
|
2013-03-01 06:52:01 +01:00
|
|
|
|
|
|
|
public class UnarmedManager extends SkillManager {
|
2019-06-30 21:19:45 +02:00
|
|
|
private long lastAttacked;
|
|
|
|
private long attackInterval;
|
|
|
|
|
2013-03-01 06:52:01 +01:00
|
|
|
public UnarmedManager(McMMOPlayer mcMMOPlayer) {
|
2019-01-13 08:54:53 +01:00
|
|
|
super(mcMMOPlayer, PrimarySkillType.UNARMED);
|
2019-06-30 21:19:45 +02:00
|
|
|
initUnarmedPerPlayerVars();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Inits variables used for each player for unarmed
|
|
|
|
*/
|
|
|
|
private void initUnarmedPerPlayerVars() {
|
|
|
|
lastAttacked = 0;
|
|
|
|
attackInterval = 750;
|
2013-03-01 06:52:01 +01:00
|
|
|
}
|
|
|
|
|
2019-06-30 21:19:45 +02:00
|
|
|
|
2013-03-03 07:31:14 +01:00
|
|
|
public boolean canActivateAbility() {
|
|
|
|
return mcMMOPlayer.getToolPreparationMode(ToolType.FISTS) && Permissions.berserk(getPlayer());
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean canUseIronArm() {
|
2019-01-31 20:27:14 +01:00
|
|
|
if(!RankUtils.hasUnlockedSubskill(getPlayer(), SubSkillType.UNARMED_IRON_ARM_STYLE))
|
2019-01-28 12:55:30 +01:00
|
|
|
return false;
|
|
|
|
|
2019-01-09 04:52:52 +01:00
|
|
|
return Permissions.isSubSkillEnabled(getPlayer(), SubSkillType.UNARMED_IRON_ARM_STYLE);
|
2013-03-03 07:31:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public boolean canUseBerserk() {
|
2019-02-05 07:04:50 +01:00
|
|
|
return mcMMOPlayer.getAbilityMode(SuperAbilityType.BERSERK);
|
2013-03-03 07:31:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public boolean canDisarm(LivingEntity target) {
|
2019-01-28 12:55:30 +01:00
|
|
|
if(!RankUtils.hasUnlockedSubskill(getPlayer(), SubSkillType.UNARMED_DISARM))
|
|
|
|
return false;
|
|
|
|
|
2019-01-09 04:52:52 +01:00
|
|
|
return target instanceof Player && ((Player) target).getInventory().getItemInMainHand().getType() != Material.AIR && Permissions.isSubSkillEnabled(getPlayer(), SubSkillType.UNARMED_DISARM);
|
2013-03-03 07:31:14 +01:00
|
|
|
}
|
|
|
|
|
2013-03-04 15:40:03 +01:00
|
|
|
public boolean canDeflect() {
|
2019-01-28 12:55:30 +01:00
|
|
|
if(!RankUtils.hasUnlockedSubskill(getPlayer(), SubSkillType.UNARMED_ARROW_DEFLECT))
|
|
|
|
return false;
|
|
|
|
|
2013-03-04 15:40:03 +01:00
|
|
|
Player player = getPlayer();
|
|
|
|
|
2019-01-09 04:52:52 +01:00
|
|
|
return ItemUtils.isUnarmed(player.getInventory().getItemInMainHand()) && Permissions.isSubSkillEnabled(getPlayer(), SubSkillType.UNARMED_ARROW_DEFLECT);
|
2013-03-04 15:40:03 +01:00
|
|
|
}
|
|
|
|
|
2013-03-07 01:19:26 +01:00
|
|
|
public boolean canUseBlockCracker() {
|
2019-01-28 12:55:30 +01:00
|
|
|
if(!RankUtils.hasUnlockedSubskill(getPlayer(), SubSkillType.UNARMED_BLOCK_CRACKER))
|
|
|
|
return false;
|
|
|
|
|
2019-01-09 04:52:52 +01:00
|
|
|
return Permissions.isSubSkillEnabled(getPlayer(), SubSkillType.UNARMED_BLOCK_CRACKER);
|
2013-03-07 01:19:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public boolean blockCrackerCheck(BlockState blockState) {
|
2019-01-25 05:45:26 +01:00
|
|
|
if (!RandomChanceUtil.isActivationSuccessful(SkillActivationType.ALWAYS_FIRES, SubSkillType.UNARMED_BLOCK_CRACKER, getPlayer())) {
|
2014-05-11 14:58:08 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
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) {
|
2019-01-25 05:45:26 +01:00
|
|
|
if (RandomChanceUtil.isActivationSuccessful(SkillActivationType.RANDOM_LINEAR_100_SCALE_WITH_CAP, SubSkillType.UNARMED_DISARM, getPlayer()) && !hasIronGrip(defender)) {
|
2013-10-18 14:31:00 +02:00
|
|
|
if (EventUtils.callDisarmEvent(defender).isCancelled()) {
|
|
|
|
return;
|
|
|
|
}
|
2013-03-01 06:52:01 +01:00
|
|
|
|
2019-04-13 00:17:05 +02:00
|
|
|
if(UserManager.getPlayer(defender) == null)
|
|
|
|
return;
|
|
|
|
|
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));
|
2019-01-14 07:45:16 +01:00
|
|
|
NotificationManager.sendPlayerInformation(defender, NotificationType.SUBSKILL_MESSAGE, "Skills.Disarmed");
|
2013-03-01 06:52:01 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check for arrow deflection.
|
|
|
|
*/
|
|
|
|
public boolean deflectCheck() {
|
2019-01-25 05:45:26 +01:00
|
|
|
if (RandomChanceUtil.isActivationSuccessful(SkillActivationType.RANDOM_LINEAR_100_SCALE_WITH_CAP, SubSkillType.UNARMED_ARROW_DEFLECT, getPlayer())) {
|
2019-01-14 07:45:16 +01:00
|
|
|
NotificationManager.sendPlayerInformation(getPlayer(), NotificationType.SUBSKILL_MESSAGE, "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() {
|
2019-01-25 05:45:26 +01:00
|
|
|
if (!RandomChanceUtil.isActivationSuccessful(SkillActivationType.ALWAYS_FIRES, SubSkillType.UNARMED_IRON_ARM_STYLE, getPlayer())) {
|
2014-05-11 14:58:08 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-01-25 05:45:26 +01:00
|
|
|
return getIronArmDamage();
|
|
|
|
}
|
|
|
|
|
2019-02-03 22:17:42 +01:00
|
|
|
public boolean isPunchingCooldownOver() {
|
2019-06-30 21:19:45 +02:00
|
|
|
return (lastAttacked + attackInterval) <= System.currentTimeMillis();
|
2019-02-03 22:17:42 +01:00
|
|
|
}
|
|
|
|
|
2019-01-25 05:45:26 +01:00
|
|
|
public double getIronArmDamage() {
|
2019-03-27 19:27:05 +01:00
|
|
|
int rank = RankUtils.getRank(getPlayer(), SubSkillType.UNARMED_IRON_ARM_STYLE);
|
|
|
|
|
|
|
|
if(rank == 1)
|
|
|
|
{
|
|
|
|
return 4;
|
|
|
|
} else {
|
|
|
|
return 3 + (rank * 2);
|
|
|
|
}
|
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) {
|
2019-07-07 11:48:17 +02:00
|
|
|
if (!Misc.isNPCEntityExcludingVillagers(defender)
|
|
|
|
&& Permissions.isSubSkillEnabled(defender, SubSkillType.UNARMED_IRON_GRIP)
|
|
|
|
&& RandomChanceUtil.isActivationSuccessful(SkillActivationType.RANDOM_LINEAR_100_SCALE_WITH_CAP, SubSkillType.UNARMED_IRON_GRIP, defender)) {
|
2019-01-14 07:45:16 +01:00
|
|
|
NotificationManager.sendPlayerInformation(defender, NotificationType.SUBSKILL_MESSAGE, "Unarmed.Ability.IronGrip.Defender");
|
|
|
|
NotificationManager.sendPlayerInformation(getPlayer(), NotificationType.SUBSKILL_MESSAGE, "Unarmed.Ability.IronGrip.Attacker");
|
2013-03-01 06:52:01 +01:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2019-06-30 21:19:45 +02:00
|
|
|
|
|
|
|
public long getLastAttacked() {
|
|
|
|
return lastAttacked;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setLastAttacked(long lastAttacked) {
|
|
|
|
this.lastAttacked = lastAttacked;
|
|
|
|
}
|
|
|
|
|
|
|
|
public long getAttackInterval() {
|
|
|
|
return attackInterval;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setAttackInterval(long attackInterval) {
|
|
|
|
this.attackInterval = attackInterval;
|
|
|
|
}
|
2013-03-01 06:52:01 +01:00
|
|
|
}
|