From 6bfc1b84de6610018a1520ade113fdbaccd25918 Mon Sep 17 00:00:00 2001 From: GJ Date: Fri, 23 Aug 2013 10:58:50 -0400 Subject: [PATCH] Let's do this the right way. --- .../skills/archery/ArcheryManager.java | 43 ++++++----- .../nossr50/skills/axes/AxesManager.java | 75 ++++++++++--------- .../nossr50/skills/taming/TamingManager.java | 29 ++++--- .../skills/unarmed/UnarmedManager.java | 11 ++- .../nossr50/util/skills/CombatUtils.java | 74 +++++++++--------- 5 files changed, 124 insertions(+), 108 deletions(-) diff --git a/src/main/java/com/gmail/nossr50/skills/archery/ArcheryManager.java b/src/main/java/com/gmail/nossr50/skills/archery/ArcheryManager.java index 96ad08026..17a5b8e0b 100644 --- a/src/main/java/com/gmail/nossr50/skills/archery/ArcheryManager.java +++ b/src/main/java/com/gmail/nossr50/skills/archery/ArcheryManager.java @@ -1,9 +1,11 @@ package com.gmail.nossr50.skills.archery; import org.bukkit.Location; +import org.bukkit.entity.Arrow; import org.bukkit.entity.Entity; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; +import org.bukkit.event.entity.EntityDamageEvent.DamageCause; import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffectType; @@ -15,6 +17,7 @@ import com.gmail.nossr50.skills.SkillManager; import com.gmail.nossr50.util.Misc; import com.gmail.nossr50.util.Permissions; import com.gmail.nossr50.util.player.UserManager; +import com.gmail.nossr50.util.skills.CombatUtils; import com.gmail.nossr50.util.skills.SkillUtils; public class ArcheryManager extends SkillManager { @@ -68,26 +71,26 @@ public class ArcheryManager extends SkillManager { * @param damage The amount of damage initially dealt by the event * @return the modified event damage if the ability was successful, the original event damage otherwise */ - public double dazeCheck(Player defender, double damage) { - if (SkillUtils.activationSuccessful(getSkillLevel(), getActivationChance(), Archery.dazeMaxBonus, Archery.dazeMaxBonusLevel)) { - Location dazedLocation = defender.getLocation(); - dazedLocation.setPitch(90 - Misc.getRandom().nextInt(181)); - - defender.teleport(dazedLocation); - defender.addPotionEffect(new PotionEffect(PotionEffectType.CONFUSION, 20 * 10, 10)); - - if (UserManager.getPlayer(defender).useChatNotifications()) { - defender.sendMessage(LocaleLoader.getString("Combat.TouchedFuzzy")); - } - - if (mcMMOPlayer.useChatNotifications()) { - getPlayer().sendMessage(LocaleLoader.getString("Combat.TargetDazed")); - } - - return damage + Archery.dazeModifier; + public void daze(Player defender, Arrow arrow) { + if (!SkillUtils.activationSuccessful(getSkillLevel(), getActivationChance(), Archery.dazeMaxBonus, Archery.dazeMaxBonusLevel)) { + return; } - return damage; + Location dazedLocation = defender.getLocation(); + dazedLocation.setPitch(90 - Misc.getRandom().nextInt(181)); + + defender.teleport(dazedLocation); + defender.addPotionEffect(new PotionEffect(PotionEffectType.CONFUSION, 20 * 10, 10)); + + if (UserManager.getPlayer(defender).useChatNotifications()) { + defender.sendMessage(LocaleLoader.getString("Combat.TouchedFuzzy")); + } + + if (mcMMOPlayer.useChatNotifications()) { + getPlayer().sendMessage(LocaleLoader.getString("Combat.TargetDazed")); + } + + CombatUtils.dealDamage(defender, Archery.dazeModifier, DamageCause.PROJECTILE, arrow); } /** @@ -96,10 +99,10 @@ public class ArcheryManager extends SkillManager { * @param damage The amount of damage initially dealt by the event * @return the modified event damage */ - public double skillShotCheck(double damage) { + public void skillShot(LivingEntity target, double damage, Arrow arrow) { double damageBonusPercent = Math.min(((getSkillLevel() / Archery.skillShotIncreaseLevel) * Archery.skillShotIncreasePercentage), Archery.skillShotMaxBonusPercentage); double archeryBonus = damage * damageBonusPercent; - return damage + archeryBonus; + CombatUtils.dealDamage(target, archeryBonus, DamageCause.PROJECTILE, arrow); } } diff --git a/src/main/java/com/gmail/nossr50/skills/axes/AxesManager.java b/src/main/java/com/gmail/nossr50/skills/axes/AxesManager.java index 77de304b5..21f573afa 100644 --- a/src/main/java/com/gmail/nossr50/skills/axes/AxesManager.java +++ b/src/main/java/com/gmail/nossr50/skills/axes/AxesManager.java @@ -55,10 +55,10 @@ public class AxesManager extends SkillManager { * @param damage The amount of damage initially dealt by the event * @return the modified event damage */ - public double axeMasteryCheck(double damage) { + public void axeMastery(LivingEntity target) { double axeBonus = Math.min(getSkillLevel() / (Axes.bonusDamageMaxBonusLevel / Axes.bonusDamageMaxBonus), Axes.bonusDamageMaxBonus); - return damage + axeBonus; + CombatUtils.dealDamage(target, axeBonus, getPlayer()); } /** @@ -68,20 +68,25 @@ public class AxesManager extends SkillManager { * @param damage The amount of damage initially dealt by the event * @return the modified event damage if the ability was successful, the original event damage otherwise */ - public double criticalHitCheck(LivingEntity target, double damage) { - if (SkillUtils.activationSuccessful(getSkillLevel(), getActivationChance(), Axes.criticalHitMaxChance, Axes.criticalHitMaxBonusLevel)) { - getPlayer().sendMessage(LocaleLoader.getString("Axes.Combat.CriticalHit")); - - if (target instanceof Player) { - ((Player) target).sendMessage(LocaleLoader.getString("Axes.Combat.CritStruck")); - - return damage * Axes.criticalHitPVPModifier; - } - - return damage * Axes.criticalHitPVEModifier; + public void criticalHit(LivingEntity target, double damage) { + if (!SkillUtils.activationSuccessful(getSkillLevel(), getActivationChance(), Axes.criticalHitMaxChance, Axes.criticalHitMaxBonusLevel)) { + return; } - return damage; + Player player = getPlayer(); + + player.sendMessage(LocaleLoader.getString("Axes.Combat.CriticalHit")); + + if (target instanceof Player) { + ((Player) target).sendMessage(LocaleLoader.getString("Axes.Combat.CritStruck")); + + damage = (damage * Axes.criticalHitPVPModifier) - damage; + } + else { + damage = (damage * Axes.criticalHitPVEModifier) - damage; + } + + CombatUtils.dealDamage(target, damage, player); } /** @@ -111,29 +116,29 @@ public class AxesManager extends SkillManager { * @param damage The amount of damage initially dealt by the event * @return the modified event damage if the ability was successful, the original event damage otherwise */ - public double greaterImpactCheck(LivingEntity target, double damage) { - if (Axes.greaterImpactChance > Misc.getRandom().nextInt(getActivationChance())) { - Player player = getPlayer(); - - ParticleEffectUtils.playGreaterImpactEffect(target); - target.setVelocity(player.getLocation().getDirection().normalize().multiply(Axes.greaterImpactKnockbackMultiplier)); - - if (mcMMOPlayer.useChatNotifications()) { - player.sendMessage(LocaleLoader.getString("Axes.Combat.GI.Proc")); - } - - if (target instanceof Player) { - Player defender = (Player) target; - - if (UserManager.getPlayer(defender).useChatNotifications()) { - defender.sendMessage(LocaleLoader.getString("Axes.Combat.GI.Struck")); - } - } - - return damage + Axes.greaterImpactBonusDamage; + public void greaterImpact(LivingEntity target) { + if (!(Axes.greaterImpactChance > Misc.getRandom().nextInt(getActivationChance()))) { + return; } - return damage; + Player player = getPlayer(); + + ParticleEffectUtils.playGreaterImpactEffect(target); + target.setVelocity(player.getLocation().getDirection().normalize().multiply(Axes.greaterImpactKnockbackMultiplier)); + + if (mcMMOPlayer.useChatNotifications()) { + player.sendMessage(LocaleLoader.getString("Axes.Combat.GI.Proc")); + } + + if (target instanceof Player) { + Player defender = (Player) target; + + if (UserManager.getPlayer(defender).useChatNotifications()) { + defender.sendMessage(LocaleLoader.getString("Axes.Combat.GI.Struck")); + } + } + + CombatUtils.dealDamage(target, Axes.greaterImpactBonusDamage, player); } /** diff --git a/src/main/java/com/gmail/nossr50/skills/taming/TamingManager.java b/src/main/java/com/gmail/nossr50/skills/taming/TamingManager.java index f87ab707d..224526723 100644 --- a/src/main/java/com/gmail/nossr50/skills/taming/TamingManager.java +++ b/src/main/java/com/gmail/nossr50/skills/taming/TamingManager.java @@ -19,6 +19,7 @@ import com.gmail.nossr50.skills.SkillManager; import com.gmail.nossr50.util.Misc; import com.gmail.nossr50.util.Permissions; import com.gmail.nossr50.util.StringUtils; +import com.gmail.nossr50.util.skills.CombatUtils; import com.gmail.nossr50.util.skills.SkillUtils; public class TamingManager extends SkillManager { @@ -103,19 +104,25 @@ public class TamingManager extends SkillManager { * @param target The LivingEntity to apply Gore on * @param damage The initial damage */ - public double gore(LivingEntity target, double damage) { - if (SkillUtils.activationSuccessful(getSkillLevel(), getActivationChance(), Taming.goreMaxChance, Taming.goreMaxBonusLevel)) { - BleedTimerTask.add(target, Taming.goreBleedTicks); - - if (target instanceof Player) { - ((Player) target).sendMessage(LocaleLoader.getString("Combat.StruckByGore")); - } - - getPlayer().sendMessage(LocaleLoader.getString("Combat.Gore")); - return damage * Taming.goreModifier; + public void gore(LivingEntity target, double damage, Wolf wolf) { + if (!SkillUtils.activationSuccessful(getSkillLevel(), getActivationChance(), Taming.goreMaxChance, Taming.goreMaxBonusLevel)) { + return; } - return damage; + BleedTimerTask.add(target, Taming.goreBleedTicks); + + if (target instanceof Player) { + ((Player) target).sendMessage(LocaleLoader.getString("Combat.StruckByGore")); + } + + getPlayer().sendMessage(LocaleLoader.getString("Combat.Gore")); + + damage = (damage * Taming.goreModifier) - damage; + CombatUtils.dealDamage(target, damage, wolf); + } + + public void sharpenedClaws(LivingEntity target, Wolf wolf) { + CombatUtils.dealDamage(target, Taming.sharpenedClawsBonusDamage, wolf); } /** diff --git a/src/main/java/com/gmail/nossr50/skills/unarmed/UnarmedManager.java b/src/main/java/com/gmail/nossr50/skills/unarmed/UnarmedManager.java index 103d3fe5f..78d6a5ae6 100644 --- a/src/main/java/com/gmail/nossr50/skills/unarmed/UnarmedManager.java +++ b/src/main/java/com/gmail/nossr50/skills/unarmed/UnarmedManager.java @@ -16,6 +16,7 @@ import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.skills.SkillManager; import com.gmail.nossr50.util.Misc; import com.gmail.nossr50.util.Permissions; +import com.gmail.nossr50.util.skills.CombatUtils; import com.gmail.nossr50.util.skills.SkillUtils; public class UnarmedManager extends SkillManager { @@ -95,8 +96,10 @@ public class UnarmedManager extends SkillManager { return false; } - public double berserkDamage(double damage) { - return damage * Unarmed.berserkDamageModifier; + public void berserkDamage(LivingEntity target, double damage) { + damage = (damage * Unarmed.berserkDamageModifier) - damage; + + CombatUtils.dealDamage(target, damage, getPlayer()); } /** @@ -105,10 +108,10 @@ public class UnarmedManager extends SkillManager { * @param damage The amount of damage initially dealt by the event * @return the modified event damage */ - public double ironArmCheck(double damage) { + public void ironArm(LivingEntity target) { int unarmedBonus = Math.min(Unarmed.ironArmMinBonusDamage + (getSkillLevel() / Unarmed.ironArmIncreaseLevel), Unarmed.ironArmMaxBonusDamage); - return damage + unarmedBonus; + CombatUtils.dealDamage(target, unarmedBonus, getPlayer()); } /** diff --git a/src/main/java/com/gmail/nossr50/util/skills/CombatUtils.java b/src/main/java/com/gmail/nossr50/util/skills/CombatUtils.java index 35e90b65c..538d8fa92 100644 --- a/src/main/java/com/gmail/nossr50/util/skills/CombatUtils.java +++ b/src/main/java/com/gmail/nossr50/util/skills/CombatUtils.java @@ -34,7 +34,6 @@ import com.gmail.nossr50.skills.archery.ArcheryManager; import com.gmail.nossr50.skills.axes.AxesManager; import com.gmail.nossr50.skills.swords.Swords; import com.gmail.nossr50.skills.swords.SwordsManager; -import com.gmail.nossr50.skills.taming.Taming; import com.gmail.nossr50.skills.taming.TamingManager; import com.gmail.nossr50.skills.unarmed.UnarmedManager; import com.gmail.nossr50.util.ItemUtils; @@ -75,18 +74,18 @@ public final class CombatUtils { } if (axesManager.canUseAxeMastery()) { - dealDamage(target, axesManager.axeMasteryCheck(event.getDamage()), player); + axesManager.axeMastery(target); } if (axesManager.canCriticalHit(target)) { - dealDamage(target, axesManager.criticalHitCheck(target, event.getDamage()), player); + axesManager.criticalHit(target, event.getDamage()); } if (axesManager.canImpact(target)) { axesManager.impactCheck(target); } else if (axesManager.canGreaterImpact(target)) { - dealDamage(target, axesManager.greaterImpactCheck(target, event.getDamage()), player); + axesManager.greaterImpact(target); } if (axesManager.canUseSkullSplitter(target)) { @@ -105,11 +104,11 @@ public final class CombatUtils { } if (unarmedManager.canUseIronArm()) { - dealDamage(target, unarmedManager.ironArmCheck(event.getDamage()), player); + unarmedManager.ironArm(target); } if (unarmedManager.canUseBerserk()) { - dealDamage(target, unarmedManager.berserkDamage(event.getDamage()), player); + unarmedManager.berserkDamage(target, event.getDamage()); } if (unarmedManager.canDisarm(target)) { @@ -128,22 +127,22 @@ public final class CombatUtils { } if (tamingManager.canUseSharpenedClaws()) { - dealDamage(target, Taming.sharpenedClawsBonusDamage, master); + tamingManager.sharpenedClaws(target, wolf); } if (tamingManager.canUseGore()) { - dealDamage(target, tamingManager.gore(target, event.getDamage()), master); + tamingManager.gore(target, event.getDamage(), wolf); } startGainXp(mcMMOPlayer, target, SkillType.TAMING); } - private static void processArcheryCombat(LivingEntity target, Player player, EntityDamageByEntityEvent event, Entity arrow) { + private static void processArcheryCombat(LivingEntity target, Player player, EntityDamageByEntityEvent event, Arrow arrow) { McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player); ArcheryManager archeryManager = mcMMOPlayer.getArcheryManager(); if (archeryManager.canSkillShot()) { - dealDamage(target, archeryManager.skillShotCheck(event.getDamage()), player); + archeryManager.skillShot(target, event.getDamage(), arrow); } if (target instanceof Player && SkillType.UNARMED.getPVPEnabled()) { @@ -159,7 +158,7 @@ public final class CombatUtils { } if (archeryManager.canDaze(target)) { - dealDamage(target, archeryManager.dazeCheck((Player) target, event.getDamage()), player); + archeryManager.daze((Player) target, arrow); } if (!arrow.hasMetadata(mcMMO.infiniteArrowKey) && archeryManager.canTrackArrows()) { @@ -251,13 +250,14 @@ public final class CombatUtils { } } else if (damager.getType() == EntityType.ARROW) { - LivingEntity shooter = ((Arrow) damager).getShooter(); + Arrow arrow = (Arrow) damager; + LivingEntity shooter = arrow.getShooter(); if (shooter != null && shooter instanceof Player && shouldProcessSkill(target, SkillType.ARCHERY)) { Player player = (Player) shooter; if (!Misc.isNPCEntity(player) && Permissions.skillEnabled(player, SkillType.ARCHERY)) { - processArcheryCombat(target, player, event, damager); + processArcheryCombat(target, player, event, arrow); } } } @@ -345,56 +345,54 @@ public final class CombatUtils { * Attempt to damage target for value dmg with reason CUSTOM * * @param target LivingEntity which to attempt to damage - * @param dmg Amount of damage to attempt to do + * @param damage Amount of damage to attempt to do */ - public static void dealDamage(LivingEntity target, double dmg) { - dealDamage(target, dmg, EntityDamageEvent.DamageCause.CUSTOM); - } - - /** - * Attempt to damage target for value dmg with reason cause - * - * @param target LivingEntity which to attempt to damage - * @param dmg Amount of damage to attempt to do - * @param cause DamageCause to pass to damage event - */ - private static void dealDamage(LivingEntity target, double dmg, DamageCause cause) { + public static void dealDamage(LivingEntity target, double damage) { if (Config.getInstance().getEventCallbackEnabled()) { - EntityDamageEvent ede = new FakeEntityDamageEvent(target, cause, dmg); + EntityDamageEvent ede = new FakeEntityDamageEvent(target, DamageCause.CUSTOM, damage); mcMMO.p.getServer().getPluginManager().callEvent(ede); if (ede.isCancelled()) { return; } - target.damage(ede.getDamage()); - } - else { - target.damage(dmg); + damage = ede.getDamage(); } + + target.damage(damage); } /** * Attempt to damage target for value dmg with reason ENTITY_ATTACK with damager attacker * * @param target LivingEntity which to attempt to damage - * @param dmg Amount of damage to attempt to do + * @param damage Amount of damage to attempt to do * @param attacker Player to pass to event as damager */ - private static void dealDamage(LivingEntity target, double dmg, Player attacker) { + public static void dealDamage(LivingEntity target, double damage, LivingEntity attacker) { + dealDamage(target, damage, DamageCause.ENTITY_ATTACK, attacker); + } + + /** + * Attempt to damage target for value dmg with reason ENTITY_ATTACK with damager attacker + * + * @param target LivingEntity which to attempt to damage + * @param damage Amount of damage to attempt to do + * @param attacker Player to pass to event as damager + */ + public static void dealDamage(LivingEntity target, double damage, DamageCause cause, Entity attacker) { if (Config.getInstance().getEventCallbackEnabled()) { - EntityDamageEvent ede = new FakeEntityDamageByEntityEvent(attacker, target, EntityDamageEvent.DamageCause.ENTITY_ATTACK, dmg); + EntityDamageEvent ede = new FakeEntityDamageByEntityEvent(attacker, target, cause, damage); mcMMO.p.getServer().getPluginManager().callEvent(ede); if (ede.isCancelled()) { return; } - target.damage(ede.getDamage()); - } - else { - target.damage(dmg); + damage = ede.getDamage(); } + + target.damage(damage); } /**