mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-01 16:19:53 +01:00
Cleaning up our UnarmedManager
This commit is contained in:
parent
10e7fe5560
commit
fbd016f86d
@ -1,31 +0,0 @@
|
||||
package com.gmail.nossr50.skills.unarmed;
|
||||
|
||||
import org.bukkit.event.entity.EntityDamageEvent;
|
||||
|
||||
import com.gmail.nossr50.locale.LocaleLoader;
|
||||
import com.gmail.nossr50.skills.utilities.SkillTools;
|
||||
|
||||
public class DeflectEventHandler {
|
||||
private UnarmedManager manager;
|
||||
private EntityDamageEvent event;
|
||||
protected int skillModifier;
|
||||
|
||||
protected DeflectEventHandler(UnarmedManager manager, EntityDamageEvent event) {
|
||||
this.manager = manager;
|
||||
this.event = event;
|
||||
|
||||
calculateSkillModifier();
|
||||
}
|
||||
|
||||
protected void calculateSkillModifier() {
|
||||
this.skillModifier = SkillTools.skillCheck(manager.getSkillLevel(), Unarmed.deflectMaxBonusLevel);
|
||||
}
|
||||
|
||||
protected void sendAbilityMessage() {
|
||||
manager.getMcMMOPlayer().getPlayer().sendMessage(LocaleLoader.getString("Combat.ArrowDeflect"));
|
||||
}
|
||||
|
||||
protected void cancelEvent() {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
@ -1,48 +0,0 @@
|
||||
package com.gmail.nossr50.skills.unarmed;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import com.gmail.nossr50.events.skills.McMMOPlayerDisarmEvent;
|
||||
import com.gmail.nossr50.locale.LocaleLoader;
|
||||
import com.gmail.nossr50.skills.utilities.SkillTools;
|
||||
import com.gmail.nossr50.util.Misc;
|
||||
|
||||
public class DisarmEventHandler {
|
||||
private UnarmedManager manager;
|
||||
private Player defender;
|
||||
private ItemStack inHand;
|
||||
protected int skillModifier;
|
||||
|
||||
protected DisarmEventHandler(UnarmedManager manager, Player defender) {
|
||||
this.manager = manager;
|
||||
this.defender = defender;
|
||||
this.inHand = defender.getItemInHand();
|
||||
}
|
||||
|
||||
protected boolean isHoldingItem() {
|
||||
return (inHand.getType() != Material.AIR);
|
||||
}
|
||||
|
||||
protected void calculateSkillModifier() {
|
||||
this.skillModifier = SkillTools.skillCheck(manager.getSkillLevel(), Unarmed.disarmMaxBonusLevel);
|
||||
}
|
||||
|
||||
private void sendAbilityMessage() {
|
||||
defender.sendMessage(LocaleLoader.getString("Skills.Disarmed"));
|
||||
}
|
||||
|
||||
protected void handleDisarm() {
|
||||
McMMOPlayerDisarmEvent event = new McMMOPlayerDisarmEvent(defender);
|
||||
mcMMO.p.getServer().getPluginManager().callEvent(event);
|
||||
|
||||
if(!event.isCancelled()) {
|
||||
Misc.dropItem(defender.getLocation(), inHand);
|
||||
defender.setItemInHand(new ItemStack(Material.AIR));
|
||||
|
||||
sendAbilityMessage();
|
||||
}
|
||||
}
|
||||
}
|
@ -1,30 +0,0 @@
|
||||
package com.gmail.nossr50.skills.unarmed;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.gmail.nossr50.locale.LocaleLoader;
|
||||
import com.gmail.nossr50.skills.utilities.SkillTools;
|
||||
import com.gmail.nossr50.skills.utilities.SkillType;
|
||||
import com.gmail.nossr50.util.Users;
|
||||
|
||||
public class IronGripEventHandler {
|
||||
private UnarmedManager manager;
|
||||
private Player defender;
|
||||
protected int skillModifier;
|
||||
|
||||
protected IronGripEventHandler(UnarmedManager manager, Player defender) {
|
||||
this.manager = manager;
|
||||
this.defender = defender;
|
||||
|
||||
calculateSkillModifier();
|
||||
}
|
||||
|
||||
protected void calculateSkillModifier() {
|
||||
this.skillModifier = SkillTools.skillCheck(Users.getPlayer(defender).getProfile().getSkillLevel(SkillType.UNARMED), Unarmed.ironGripMaxBonusLevel);
|
||||
}
|
||||
|
||||
protected void sendAbilityMessages() {
|
||||
defender.sendMessage(LocaleLoader.getString("Unarmed.Ability.IronGrip.Defender"));
|
||||
manager.getMcMMOPlayer().getPlayer().sendMessage(LocaleLoader.getString("Unarmed.Ability.IronGrip.Attacker"));
|
||||
}
|
||||
}
|
@ -1,32 +0,0 @@
|
||||
package com.gmail.nossr50.skills.unarmed;
|
||||
|
||||
import org.bukkit.event.entity.EntityDamageEvent;
|
||||
|
||||
public class UnarmedBonusDamageEventHandler {
|
||||
private UnarmedManager manager;
|
||||
private EntityDamageEvent event;
|
||||
|
||||
protected int damageBonus;
|
||||
|
||||
protected UnarmedBonusDamageEventHandler(UnarmedManager manager, EntityDamageEvent event) {
|
||||
this.manager = manager;
|
||||
this.event = event;
|
||||
}
|
||||
|
||||
protected void calculateDamageBonus() {
|
||||
int damageBonus = 3 + (manager.getSkillLevel() / Unarmed.ironArmIncreaseLevel);
|
||||
|
||||
if (damageBonus > Unarmed.ironArmMaxBonusDamage) {
|
||||
damageBonus = Unarmed.ironArmMaxBonusDamage;
|
||||
}
|
||||
|
||||
this.damageBonus = damageBonus;
|
||||
}
|
||||
|
||||
protected void modifyEventDamage() {
|
||||
int damage = event.getDamage();
|
||||
int unarmedBonus = damage + damageBonus;
|
||||
|
||||
event.setDamage(damage + unarmedBonus);
|
||||
}
|
||||
}
|
@ -1,12 +1,15 @@
|
||||
package com.gmail.nossr50.skills.unarmed;
|
||||
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.entity.EntityDamageEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import com.gmail.nossr50.datatypes.McMMOPlayer;
|
||||
import com.gmail.nossr50.events.skills.McMMOPlayerDisarmEvent;
|
||||
import com.gmail.nossr50.locale.LocaleLoader;
|
||||
import com.gmail.nossr50.skills.SkillManager;
|
||||
import com.gmail.nossr50.skills.utilities.PerksUtils;
|
||||
import com.gmail.nossr50.skills.utilities.SkillTools;
|
||||
import com.gmail.nossr50.skills.utilities.SkillType;
|
||||
import com.gmail.nossr50.util.Misc;
|
||||
import com.gmail.nossr50.util.Permissions;
|
||||
@ -21,55 +24,48 @@ public class UnarmedManager extends SkillManager {
|
||||
*
|
||||
* @param defender The defending player
|
||||
*/
|
||||
public void disarmCheck(LivingEntity defender) {
|
||||
Player defendingPlayer = (Player) defender;
|
||||
DisarmEventHandler eventHandler = new DisarmEventHandler(this, defendingPlayer);
|
||||
public void disarmCheck(Player defender) {
|
||||
if (SkillTools.activationSuccessful(getPlayer(), skill, Unarmed.disarmMaxChance, Unarmed.disarmMaxBonusLevel) && !hasIronGrip(defender)) {
|
||||
McMMOPlayerDisarmEvent disarmEvent = new McMMOPlayerDisarmEvent(defender);
|
||||
mcMMO.p.getServer().getPluginManager().callEvent(disarmEvent);
|
||||
|
||||
if (eventHandler.isHoldingItem()) {
|
||||
eventHandler.calculateSkillModifier();
|
||||
if (!disarmEvent.isCancelled()) {
|
||||
Misc.dropItem(defender.getLocation(), defender.getItemInHand());
|
||||
|
||||
float chance = (float) ((Unarmed.disarmMaxChance / Unarmed.disarmMaxBonusLevel) * getSkillLevel());
|
||||
if (chance > Unarmed.disarmMaxChance) chance = (float) Unarmed.disarmMaxChance;
|
||||
|
||||
if (chance > Misc.getRandom().nextInt(activationChance)) {
|
||||
if (!hasIronGrip(defendingPlayer)) {
|
||||
eventHandler.handleDisarm();
|
||||
}
|
||||
defender.setItemInHand(new ItemStack(Material.AIR));
|
||||
defender.sendMessage(LocaleLoader.getString("Skills.Disarmed"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check for arrow deflection.
|
||||
*
|
||||
* @param event The event to modify
|
||||
*/
|
||||
public void deflectCheck(EntityDamageEvent event) {
|
||||
DeflectEventHandler eventHandler = new DeflectEventHandler(this, event);
|
||||
public boolean deflectCheck() {
|
||||
Player player = getPlayer();
|
||||
|
||||
float chance = (float) ((Unarmed.deflectMaxChance / Unarmed.deflectMaxBonusLevel) * getSkillLevel());
|
||||
if (chance > Unarmed.deflectMaxChance) chance = (float) Unarmed.deflectMaxChance;
|
||||
|
||||
if (chance > Misc.getRandom().nextInt(activationChance)) {
|
||||
eventHandler.cancelEvent();
|
||||
eventHandler.sendAbilityMessage();
|
||||
if (SkillTools.activationSuccessful(player, skill, Unarmed.deflectMaxChance, Unarmed.deflectMaxBonusLevel)) {
|
||||
player.sendMessage(LocaleLoader.getString("Combat.ArrowDeflect"));
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public void berserkDamage(EntityDamageEvent event) {
|
||||
event.setDamage((int) (event.getDamage() * Unarmed.berserkDamageModifier));
|
||||
public int berserkDamage(int damage) {
|
||||
return (int) (damage * Unarmed.berserkDamageModifier);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle Unarmed bonus damage.
|
||||
* Handle the effects of the Iron Arm ability
|
||||
*
|
||||
* @param event The event to modify.
|
||||
* @param damage The amount of damage initially dealt by the event
|
||||
* @return the modified event damage
|
||||
*/
|
||||
public void bonusDamage(EntityDamageEvent event) {
|
||||
UnarmedBonusDamageEventHandler eventHandler = new UnarmedBonusDamageEventHandler(this, event);
|
||||
public int ironArmCheck(int damage) {
|
||||
int unarmedBonus = Math.min(3 + (getSkillLevel() / Unarmed.ironArmIncreaseLevel), Unarmed.ironArmMaxBonusDamage);
|
||||
|
||||
eventHandler.calculateDamageBonus();
|
||||
eventHandler.modifyEventDamage();
|
||||
return damage + unarmedBonus;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -79,16 +75,10 @@ public class UnarmedManager extends SkillManager {
|
||||
* @return true if the defender was not disarmed, false otherwise
|
||||
*/
|
||||
private boolean hasIronGrip(Player defender) {
|
||||
if (Misc.isNPCEntity(defender) || !Permissions.ironGrip(defender)) {
|
||||
return false;
|
||||
}
|
||||
if (!Misc.isNPCEntity(defender) && Permissions.ironGrip(defender) && SkillTools.activationSuccessful(defender, skill, Unarmed.ironGripMaxChance, Unarmed.ironGripMaxBonusLevel)) {
|
||||
defender.sendMessage(LocaleLoader.getString("Unarmed.Ability.IronGrip.Defender"));
|
||||
getPlayer().sendMessage(LocaleLoader.getString("Unarmed.Ability.IronGrip.Attacker"));
|
||||
|
||||
IronGripEventHandler eventHandler = new IronGripEventHandler(this, defender);
|
||||
|
||||
double chance = (Unarmed.ironGripMaxChance / Unarmed.ironGripMaxBonusLevel) * eventHandler.skillModifier;
|
||||
|
||||
if (chance > Misc.getRandom().nextInt(PerksUtils.handleLuckyPerks(defender, skill))) {
|
||||
eventHandler.sendAbilityMessages();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -152,15 +152,19 @@ public final class CombatTools {
|
||||
}
|
||||
|
||||
if (Permissions.bonusDamage(player, SkillType.UNARMED)) {
|
||||
SkillManagerStore.getInstance().getUnarmedManager(playerName).bonusDamage(event);
|
||||
event.setDamage(SkillManagerStore.getInstance().getUnarmedManager(playerName).ironArmCheck(event.getDamage()));
|
||||
}
|
||||
|
||||
if (profile.getAbilityMode(AbilityType.BERSERK) && canBerserk) {
|
||||
SkillManagerStore.getInstance().getUnarmedManager(playerName).berserkDamage(event);
|
||||
event.setDamage(SkillManagerStore.getInstance().getUnarmedManager(playerName).berserkDamage(event.getDamage()));
|
||||
}
|
||||
|
||||
if (target instanceof Player && Permissions.disarm(player)) {
|
||||
SkillManagerStore.getInstance().getUnarmedManager(playerName).disarmCheck(target);
|
||||
Player defender = (Player) target;
|
||||
|
||||
if (defender.getItemInHand().getType() != Material.AIR) {
|
||||
SkillManagerStore.getInstance().getUnarmedManager(playerName).disarmCheck((Player) target);
|
||||
}
|
||||
}
|
||||
|
||||
startGainXp(mcMMOPlayer, target, SkillType.UNARMED);
|
||||
@ -283,7 +287,11 @@ public final class CombatTools {
|
||||
}
|
||||
|
||||
if (target instanceof Player && SkillType.UNARMED.getPVPEnabled() && ((Player) target).getItemInHand().getType() == Material.AIR && Permissions.arrowDeflect((Player) target)) {
|
||||
SkillManagerStore.getInstance().getUnarmedManager(((Player) target).getName()).deflectCheck(event);
|
||||
event.setCancelled(SkillManagerStore.getInstance().getUnarmedManager(((Player) target).getName()).deflectCheck());
|
||||
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (SkillManagerStore.getInstance().getArcheryManager(playerName).canDaze(target)) {
|
||||
|
Loading…
Reference in New Issue
Block a user