diff --git a/src/main/java/com/gmail/nossr50/listeners/EntityListener.java b/src/main/java/com/gmail/nossr50/listeners/EntityListener.java index 0991ed44c..2beddd118 100644 --- a/src/main/java/com/gmail/nossr50/listeners/EntityListener.java +++ b/src/main/java/com/gmail/nossr50/listeners/EntityListener.java @@ -34,8 +34,8 @@ import com.gmail.nossr50.party.PartyManager; import com.gmail.nossr50.runnables.BleedTimer; import com.gmail.nossr50.skills.acrobatics.AcrobaticsManager; import com.gmail.nossr50.skills.combat.Archery; -import com.gmail.nossr50.skills.combat.Taming; import com.gmail.nossr50.skills.gathering.BlastMining; +import com.gmail.nossr50.skills.taming.Taming; import com.gmail.nossr50.util.Combat; import com.gmail.nossr50.util.Misc; import com.gmail.nossr50.util.Permissions; diff --git a/src/main/java/com/gmail/nossr50/listeners/PlayerListener.java b/src/main/java/com/gmail/nossr50/listeners/PlayerListener.java index 869d02616..e81059e72 100644 --- a/src/main/java/com/gmail/nossr50/listeners/PlayerListener.java +++ b/src/main/java/com/gmail/nossr50/listeners/PlayerListener.java @@ -33,10 +33,10 @@ import com.gmail.nossr50.events.chat.McMMOPartyChatEvent; import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.party.Party; import com.gmail.nossr50.runnables.BleedTimer; -import com.gmail.nossr50.skills.combat.Taming; import com.gmail.nossr50.skills.gathering.BlastMining; import com.gmail.nossr50.skills.gathering.Fishing; import com.gmail.nossr50.skills.gathering.Herbalism; +import com.gmail.nossr50.skills.taming.Taming; import com.gmail.nossr50.spout.SpoutStuff; import com.gmail.nossr50.util.BlockChecks; import com.gmail.nossr50.util.Item; diff --git a/src/main/java/com/gmail/nossr50/skills/taming/FastFoodServiceEventHandler.java b/src/main/java/com/gmail/nossr50/skills/taming/FastFoodServiceEventHandler.java new file mode 100644 index 000000000..ccac0bef8 --- /dev/null +++ b/src/main/java/com/gmail/nossr50/skills/taming/FastFoodServiceEventHandler.java @@ -0,0 +1,27 @@ +package com.gmail.nossr50.skills.taming; + +import org.bukkit.entity.Wolf; + +public class FastFoodServiceEventHandler { + private Wolf wolf; + + public FastFoodServiceEventHandler (Wolf wolf) { + this.wolf = wolf; + } + + protected void modifyHealth(int damage) { + int health = wolf.getHealth(); + int maxHealth = wolf.getMaxHealth(); + + if (health < maxHealth) { + int newHealth = health + damage; + + if (newHealth <= maxHealth) { + wolf.setHealth(newHealth); + } + else { + wolf.setHealth(maxHealth); + } + } + } +} diff --git a/src/main/java/com/gmail/nossr50/skills/taming/GoreEventHandler.java b/src/main/java/com/gmail/nossr50/skills/taming/GoreEventHandler.java new file mode 100644 index 000000000..5ba37a063 --- /dev/null +++ b/src/main/java/com/gmail/nossr50/skills/taming/GoreEventHandler.java @@ -0,0 +1,44 @@ +package com.gmail.nossr50.skills.taming; + +import org.bukkit.entity.Entity; +import org.bukkit.entity.LivingEntity; +import org.bukkit.entity.Player; +import org.bukkit.event.entity.EntityDamageEvent; + +import com.gmail.nossr50.locale.LocaleLoader; +import com.gmail.nossr50.runnables.BleedTimer; +import com.gmail.nossr50.util.Misc; + +public class GoreEventHandler { + private TamingManager manager; + private EntityDamageEvent event; + private Entity entity; + protected int skillModifier; + + protected GoreEventHandler(TamingManager manager, EntityDamageEvent event) { + this.manager = manager; + this.event = event; + this.entity = event.getEntity(); + calculateSkillModifier(); + } + + protected void calculateSkillModifier() { + this.skillModifier = Misc.skillCheck(manager.getSkillLevel(), Taming.GORE_MAX_BONUS_LEVEL); + } + + protected void modifyEventDamage() { + event.setDamage(event.getDamage() * Taming.GORE_MULTIPLIER); + } + + protected void sendAbilityMessage() { + if (entity instanceof Player) { + ((Player) entity).sendMessage(LocaleLoader.getString("Combat.StruckByGore")); + } + + manager.getPlayer().sendMessage(LocaleLoader.getString("Combat.Gore")); + } + + protected void applyBleed() { + BleedTimer.add((LivingEntity) entity, Taming.GORE_BLEED_TICKS); + } +} diff --git a/src/main/java/com/gmail/nossr50/skills/taming/SharpenedClawsEventHandler.java b/src/main/java/com/gmail/nossr50/skills/taming/SharpenedClawsEventHandler.java new file mode 100644 index 000000000..0fc157077 --- /dev/null +++ b/src/main/java/com/gmail/nossr50/skills/taming/SharpenedClawsEventHandler.java @@ -0,0 +1,15 @@ +package com.gmail.nossr50.skills.taming; + +import org.bukkit.event.entity.EntityDamageEvent; + +public class SharpenedClawsEventHandler { + private EntityDamageEvent event; + + public SharpenedClawsEventHandler (EntityDamageEvent event) { + this.event = event; + } + + protected void modifyEventDamage() { + event.setDamage(event.getDamage() + Taming.SHARPENED_CLAWS_BONUS); + } +} diff --git a/src/main/java/com/gmail/nossr50/skills/combat/Taming.java b/src/main/java/com/gmail/nossr50/skills/taming/Taming.java similarity index 75% rename from src/main/java/com/gmail/nossr50/skills/combat/Taming.java rename to src/main/java/com/gmail/nossr50/skills/taming/Taming.java index 507fd5ff5..50d73b723 100644 --- a/src/main/java/com/gmail/nossr50/skills/combat/Taming.java +++ b/src/main/java/com/gmail/nossr50/skills/taming/Taming.java @@ -1,4 +1,4 @@ -package com.gmail.nossr50.skills.combat; +package com.gmail.nossr50.skills.taming; import java.util.Random; @@ -20,84 +20,25 @@ import org.bukkit.metadata.FixedMetadataValue; import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.config.Config; -import com.gmail.nossr50.datatypes.PlayerProfile; import com.gmail.nossr50.datatypes.SkillType; import com.gmail.nossr50.locale.LocaleLoader; -import com.gmail.nossr50.runnables.BleedTimer; import com.gmail.nossr50.util.Misc; import com.gmail.nossr50.util.Permissions; import com.gmail.nossr50.util.Users; public class Taming { + public static final int FAST_FOOD_SERVICE_ACTIVATION_CHANCE = 50; + public static final int FAST_FOOD_SERVICE_ACTIVATION_LEVEL = 50; + + public static final int GORE_BLEED_TICKS = 2; + public static final int GORE_MAX_BONUS_LEVEL = 1000; + public static final int GORE_MULTIPLIER = 2; + + public static final int SHARPENED_CLAWS_ACTIVATION_LEVEL = 750; + public static final int SHARPENED_CLAWS_BONUS = 2; + private static Random random = new Random(); - /** - * Apply the Fast Food Service ability. - * - * @param PPo The PlayerProfile of the wolf's owner - * @param theWolf The wolf using the ability - * @param damage The damage being absorbed by the wolf - */ - public static void fastFoodService (PlayerProfile PPo, Wolf theWolf, int damage) { - final int SKILL_ACTIVATION_LEVEL = 50; - final int ACTIVATION_CHANCE = 50; - - int health = theWolf.getHealth(); - int maxHealth = theWolf.getMaxHealth(); - - if (PPo.getSkillLevel(SkillType.TAMING) >= SKILL_ACTIVATION_LEVEL) { - if (health < maxHealth) { - if (random.nextInt(100) < ACTIVATION_CHANCE) { - if (health + damage <= maxHealth) { - theWolf.setHealth(health + damage); - } - else { - theWolf.setHealth(maxHealth); - } - } - } - } - } - - /** - * Apply the Sharpened Claws ability. - * - * @param PPo The PlayerProfile of the wolf's owner - * @param event The event to modify - */ - public static void sharpenedClaws(PlayerProfile PPo, EntityDamageEvent event) { - final int SKILL_ACTIVATION_LEVEL = 750; - final int SHARPENED_CLAWS_BONUS = 2; - - if (PPo.getSkillLevel(SkillType.TAMING) >= SKILL_ACTIVATION_LEVEL) { - event.setDamage(event.getDamage() + SHARPENED_CLAWS_BONUS); - } - } - - /** - * Apply the Gore ability. - * - * @param PPo The PlayerProfile of the wolf's owner - * @param event The event to modify - * @param master The wolf's master - */ - public static void gore(PlayerProfile PPo, EntityDamageEvent event, Player master) { - final int GORE_MULTIPLIER = 2; - - if (random.nextInt(1000) <= PPo.getSkillLevel(SkillType.TAMING)) { - Entity entity = event.getEntity(); - event.setDamage(event.getDamage() * GORE_MULTIPLIER); - - if (entity instanceof Player) { - ((Player) entity).sendMessage(LocaleLoader.getString("Combat.StruckByGore")); - } - - BleedTimer.add((LivingEntity) entity, 2); - - master.sendMessage(LocaleLoader.getString("Combat.Gore")); - } - } - /** * Get the name of a tameable animal's owner. * @@ -284,4 +225,8 @@ public class Taming { inspector.sendMessage(message); } } + + public static Random getRandom() { + return random; + } } diff --git a/src/main/java/com/gmail/nossr50/skills/taming/TamingManager.java b/src/main/java/com/gmail/nossr50/skills/taming/TamingManager.java new file mode 100644 index 000000000..8bc6762e0 --- /dev/null +++ b/src/main/java/com/gmail/nossr50/skills/taming/TamingManager.java @@ -0,0 +1,88 @@ +package com.gmail.nossr50.skills.taming; + +import org.bukkit.entity.Player; +import org.bukkit.entity.Wolf; +import org.bukkit.event.entity.EntityDamageEvent; + +import com.gmail.nossr50.datatypes.PlayerProfile; +import com.gmail.nossr50.datatypes.SkillType; +import com.gmail.nossr50.util.Permissions; +import com.gmail.nossr50.util.Users; + +public class TamingManager { + private Player player; + private PlayerProfile profile; + private int skillLevel; + private Permissions permissionsInstance; + + public TamingManager (Player player) { + this.player = player; + this.profile = Users.getProfile(player); + this.skillLevel = profile.getSkillLevel(SkillType.TAMING); + this.permissionsInstance = Permissions.getInstance(); + } + + /** + * Apply the Fast Food Service ability. + * + * @param wolf The wolf using the ability + * @param damage The damage being absorbed by the wolf + */ + public void fastFoodService(Wolf wolf, int damage) { + if (!permissionsInstance.fastFoodService(player)) { + return; + } + + if (skillLevel >= Taming.FAST_FOOD_SERVICE_ACTIVATION_LEVEL) { + if (Taming.getRandom().nextInt(100) < Taming.FAST_FOOD_SERVICE_ACTIVATION_CHANCE) { + FastFoodServiceEventHandler eventHandler = new FastFoodServiceEventHandler(wolf); + + eventHandler.modifyHealth(damage); + } + } + } + + /** + * Apply the Sharpened Claws ability. + * + * @param event The event to modify + */ + public void sharpenedClaws(EntityDamageEvent event) { + if (!permissionsInstance.sharpenedClaws(player)) { + return; + } + + if (skillLevel >= Taming.SHARPENED_CLAWS_ACTIVATION_LEVEL) { + SharpenedClawsEventHandler eventHandler = new SharpenedClawsEventHandler(event); + + eventHandler.modifyEventDamage(); + } + } + + /** + * Apply the Gore ability. + * + * @param event The event to modify + */ + public void gore(EntityDamageEvent event) { + if (!permissionsInstance.gore(player)) { + return; + } + + GoreEventHandler eventHandler = new GoreEventHandler(this, event); + + if (Taming.getRandom().nextInt(1000) <= eventHandler.skillModifier) { + eventHandler.modifyEventDamage(); + eventHandler.applyBleed(); + eventHandler.sendAbilityMessage(); + } + } + + protected int getSkillLevel() { + return skillLevel; + } + + protected Player getPlayer() { + return player; + } +} diff --git a/src/main/java/com/gmail/nossr50/util/Combat.java b/src/main/java/com/gmail/nossr50/util/Combat.java index d580151a5..5a4571846 100644 --- a/src/main/java/com/gmail/nossr50/util/Combat.java +++ b/src/main/java/com/gmail/nossr50/util/Combat.java @@ -33,8 +33,9 @@ import com.gmail.nossr50.skills.acrobatics.AcrobaticsManager; import com.gmail.nossr50.skills.combat.Archery; import com.gmail.nossr50.skills.combat.Axes; import com.gmail.nossr50.skills.combat.Swords; -import com.gmail.nossr50.skills.combat.Taming; import com.gmail.nossr50.skills.combat.Unarmed; +import com.gmail.nossr50.skills.taming.Taming; +import com.gmail.nossr50.skills.taming.TamingManager; public class Combat { private static Config configInstance = Config.getInstance(); @@ -154,7 +155,6 @@ public class Combat { if (wolf.isTamed() && wolf.getOwner() instanceof Player) { Player master = (Player) wolf.getOwner(); - PlayerProfile PPo = Users.getProfile(master); if (!configInstance.getTamingPVP()) { if (targetIsPlayer || targetIsTamedPet) { @@ -168,21 +168,13 @@ public class Combat { } } - if (permInstance.fastFoodService(master)) { - Taming.fastFoodService(PPo, wolf, event.getDamage()); - } + TamingManager tamingManager = new TamingManager(master); - if (permInstance.sharpenedClaws(master)) { - Taming.sharpenedClaws(PPo, event); - } + tamingManager.fastFoodService(wolf, event.getDamage()); + tamingManager.sharpenedClaws(event); + tamingManager.gore(event); - if (permInstance.gore(master)) { - Taming.gore(PPo, event, master); - } - - if (permInstance.taming(master)) { - startGainXp(master, PPo, target, SkillType.TAMING); - } + startGainXp(master, Users.getProfile(master), target, SkillType.TAMING); } } else if (damager instanceof Arrow) {