From 8fb8c67148c2820373c5ac1f5888ace05e530444 Mon Sep 17 00:00:00 2001 From: GJ Date: Wed, 27 Feb 2013 23:18:17 -0500 Subject: [PATCH] SwordsManager cleaning --- .../skills/swords/BleedEventHandler.java | 56 ------------------- .../swords/CounterAttackEventHandler.java | 37 ------------ .../swords/SerratedStrikesEventHandler.java | 24 -------- .../nossr50/skills/swords/SwordsManager.java | 54 ++++++++++++------ 4 files changed, 36 insertions(+), 135 deletions(-) delete mode 100644 src/main/java/com/gmail/nossr50/skills/swords/BleedEventHandler.java delete mode 100644 src/main/java/com/gmail/nossr50/skills/swords/CounterAttackEventHandler.java delete mode 100644 src/main/java/com/gmail/nossr50/skills/swords/SerratedStrikesEventHandler.java diff --git a/src/main/java/com/gmail/nossr50/skills/swords/BleedEventHandler.java b/src/main/java/com/gmail/nossr50/skills/swords/BleedEventHandler.java deleted file mode 100644 index 36fccd9ca..000000000 --- a/src/main/java/com/gmail/nossr50/skills/swords/BleedEventHandler.java +++ /dev/null @@ -1,56 +0,0 @@ -package com.gmail.nossr50.skills.swords; - -import org.bukkit.entity.LivingEntity; -import org.bukkit.entity.Player; - -import com.gmail.nossr50.datatypes.McMMOPlayer; -import com.gmail.nossr50.locale.LocaleLoader; -import com.gmail.nossr50.skills.runnables.BleedTimer; -import com.gmail.nossr50.skills.utilities.SkillTools; -import com.gmail.nossr50.util.Users; - -public class BleedEventHandler { - private McMMOPlayer mcMMOPlayer; - private int skillLevel; - private LivingEntity defender; - protected int skillModifier; - - protected BleedEventHandler(SwordsManager manager, LivingEntity defender) { - this.mcMMOPlayer = manager.getMcMMOPlayer(); - this.skillLevel = manager.getSkillLevel(); - this.defender = defender; - - calculateSkillModifier(); - } - - protected void calculateSkillModifier() { - this.skillModifier = SkillTools.skillCheck(skillLevel, Swords.bleedMaxBonusLevel); - } - - protected void addBleedTicks() { - int bleedTicks; - - if (skillLevel >= Swords.bleedMaxBonusLevel) { - bleedTicks = Swords.bleedMaxTicks; - } - else { - bleedTicks = Swords.bleedBaseTicks; - } - - BleedTimer.add(defender, bleedTicks); - } - - protected void sendAbilityMessages() { - if (mcMMOPlayer.getProfile().useChatNotifications()) { - mcMMOPlayer.getPlayer().sendMessage(LocaleLoader.getString("Swords.Combat.Bleeding")); - } - - if (defender instanceof Player) { - Player defendingPlayer = (Player) defender; - - if (Users.getPlayer(defendingPlayer).getProfile().useChatNotifications()) { - defendingPlayer.sendMessage(LocaleLoader.getString("Swords.Combat.Bleeding.Started")); - } - } - } -} diff --git a/src/main/java/com/gmail/nossr50/skills/swords/CounterAttackEventHandler.java b/src/main/java/com/gmail/nossr50/skills/swords/CounterAttackEventHandler.java deleted file mode 100644 index 15022eadd..000000000 --- a/src/main/java/com/gmail/nossr50/skills/swords/CounterAttackEventHandler.java +++ /dev/null @@ -1,37 +0,0 @@ -package com.gmail.nossr50.skills.swords; - -import org.bukkit.entity.LivingEntity; -import org.bukkit.entity.Player; - -import com.gmail.nossr50.locale.LocaleLoader; -import com.gmail.nossr50.skills.utilities.CombatTools; -import com.gmail.nossr50.skills.utilities.SkillTools; - -public class CounterAttackEventHandler { - private SwordsManager manager; - private LivingEntity attacker; - private int damage; - protected int skillModifier; - - protected CounterAttackEventHandler(SwordsManager manager, LivingEntity attacker, int damage) { - this.manager = manager; - this.attacker = attacker; - this.damage = damage; - } - - protected void calculateSkillModifier() { - this.skillModifier = SkillTools.skillCheck(manager.getSkillLevel(), Swords.counterAttackMaxBonusLevel); - } - - protected void dealDamage() { - CombatTools.dealDamage(attacker, damage / Swords.counterAttackModifier); - } - - protected void sendAbilityMessages() { - manager.getMcMMOPlayer().getPlayer().sendMessage(LocaleLoader.getString("Swords.Combat.Countered")); - - if (attacker instanceof Player) { - ((Player) attacker).sendMessage(LocaleLoader.getString("Swords.Combat.Counter.Hit")); - } - } -} diff --git a/src/main/java/com/gmail/nossr50/skills/swords/SerratedStrikesEventHandler.java b/src/main/java/com/gmail/nossr50/skills/swords/SerratedStrikesEventHandler.java deleted file mode 100644 index 57e147215..000000000 --- a/src/main/java/com/gmail/nossr50/skills/swords/SerratedStrikesEventHandler.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.gmail.nossr50.skills.swords; - -import org.bukkit.entity.LivingEntity; - -import com.gmail.nossr50.skills.runnables.BleedTimer; -import com.gmail.nossr50.skills.utilities.CombatTools; -import com.gmail.nossr50.skills.utilities.SkillType; - -public class SerratedStrikesEventHandler { - private SwordsManager manager; - private LivingEntity target; - private int damage; - - protected SerratedStrikesEventHandler(SwordsManager manager, LivingEntity target, int damage) { - this.manager = manager; - this.target = target; - this.damage = damage; - } - - protected void applyAbilityEffects() { - CombatTools.applyAbilityAoE(manager.getMcMMOPlayer().getPlayer(), target, damage / Swords.serratedStrikesModifier, SkillType.SWORDS); - BleedTimer.add(target, Swords.serratedStrikesBleedTicks); - } -} diff --git a/src/main/java/com/gmail/nossr50/skills/swords/SwordsManager.java b/src/main/java/com/gmail/nossr50/skills/swords/SwordsManager.java index d00d91188..3d72dd94b 100644 --- a/src/main/java/com/gmail/nossr50/skills/swords/SwordsManager.java +++ b/src/main/java/com/gmail/nossr50/skills/swords/SwordsManager.java @@ -1,11 +1,16 @@ package com.gmail.nossr50.skills.swords; import org.bukkit.entity.LivingEntity; +import org.bukkit.entity.Player; import com.gmail.nossr50.datatypes.McMMOPlayer; +import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.skills.SkillManager; +import com.gmail.nossr50.skills.runnables.BleedTimer; +import com.gmail.nossr50.skills.utilities.CombatTools; +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.Users; public class SwordsManager extends SkillManager { public SwordsManager(McMMOPlayer mcMMOPlayer) { @@ -15,35 +20,48 @@ public class SwordsManager extends SkillManager { /** * Check for Bleed effect. * - * @param defender The defending entity + * @param target The defending entity */ - public void bleedCheck(LivingEntity defender) { - BleedEventHandler eventHandler = new BleedEventHandler(this, defender); + public void bleedCheck(LivingEntity target) { + Player player = getPlayer(); - float chance = (float) ((Swords.bleedMaxChance / Swords.bleedMaxBonusLevel) * getSkillLevel()); - if (chance > Swords.bleedMaxChance) chance = (float) Swords.bleedMaxChance; + if (SkillTools.activationSuccessful(player, skill, Swords.bleedMaxChance, Swords.bleedMaxBonusLevel)) { - if (chance > Misc.getRandom().nextInt(activationChance)) { - eventHandler.addBleedTicks(); - eventHandler.sendAbilityMessages(); + if (getSkillLevel() >= Swords.bleedMaxBonusLevel) { + BleedTimer.add(target, Swords.bleedMaxTicks); + } + else { + BleedTimer.add(target, Swords.bleedBaseTicks); + } + + if (getProfile().useChatNotifications()) { + player.sendMessage(LocaleLoader.getString("Swords.Combat.Bleeding")); + } + + if (target instanceof Player) { + Player defender = (Player) target; + + if (Users.getPlayer(defender).getProfile().useChatNotifications()) { + defender.sendMessage(LocaleLoader.getString("Swords.Combat.Bleeding.Started")); + } + } } } public void counterAttackChecks(LivingEntity attacker, int damage) { - CounterAttackEventHandler eventHandler = new CounterAttackEventHandler(this, attacker, damage); - eventHandler.calculateSkillModifier(); + if (SkillTools.activationSuccessful(getPlayer(), skill, Swords.counterAttackMaxChance, Swords.counterAttackMaxBonusLevel)) { + CombatTools.dealDamage(attacker, damage / Swords.counterAttackModifier); - float chance = (float) ((Swords.counterAttackMaxChance / Swords.counterAttackMaxBonusLevel) * getSkillLevel()); - if (chance > Swords.counterAttackMaxChance) chance = (float) Swords.counterAttackMaxChance; + getPlayer().sendMessage(LocaleLoader.getString("Swords.Combat.Countered")); - if (chance > Misc.getRandom().nextInt(activationChance)) { - eventHandler.dealDamage(); - eventHandler.sendAbilityMessages(); + if (attacker instanceof Player) { + ((Player) attacker).sendMessage(LocaleLoader.getString("Swords.Combat.Counter.Hit")); + } } } public void serratedStrikes(LivingEntity target, int damage) { - SerratedStrikesEventHandler eventHandler = new SerratedStrikesEventHandler(this, target, damage); - eventHandler.applyAbilityEffects(); + CombatTools.applyAbilityAoE(getPlayer(), target, damage / Swords.serratedStrikesModifier, skill); + BleedTimer.add(target, Swords.serratedStrikesBleedTicks); } }