From e85a0f6cfcecf642dd1c5a259277a21a5bce70e2 Mon Sep 17 00:00:00 2001 From: GJ Date: Fri, 22 Feb 2013 13:39:47 -0500 Subject: [PATCH] Change Acrobatics roll handling to take event.getDamage() instead of the event. Also adds a few new config options in advanced.yml for further customizing roll behavior. --- .../gmail/nossr50/config/AdvancedConfig.java | 4 + .../nossr50/listeners/EntityListener.java | 8 +- .../nossr50/skills/acrobatics/Acrobatics.java | 69 +++++++++++- .../skills/acrobatics/AcrobaticsManager.java | 27 ----- .../skills/acrobatics/RollEventHandler.java | 101 ------------------ src/main/resources/advanced.yml | 6 ++ 6 files changed, 83 insertions(+), 132 deletions(-) delete mode 100644 src/main/java/com/gmail/nossr50/skills/acrobatics/RollEventHandler.java diff --git a/src/main/java/com/gmail/nossr50/config/AdvancedConfig.java b/src/main/java/com/gmail/nossr50/config/AdvancedConfig.java index 494af7b28..f9e200f9c 100644 --- a/src/main/java/com/gmail/nossr50/config/AdvancedConfig.java +++ b/src/main/java/com/gmail/nossr50/config/AdvancedConfig.java @@ -20,6 +20,7 @@ public class AdvancedConfig extends ConfigLoader { protected void loadKeys() { // TODO Do we need to use this? } + /* GENERAL */ public int getAbilityLength() { return config.getInt("Skills.General.Ability_IncreaseLevel", 50); } @@ -29,9 +30,12 @@ public class AdvancedConfig extends ConfigLoader { public double getRollChanceMax() { return config.getDouble("Skills.Acrobatics.Roll_ChanceMax", 100.0D); } public int getRollMaxBonusLevel() { return config.getInt("Skills.Acrobatics.Roll_MaxBonusLevel", 1000); } + public int getRollDamageThreshold() { return config.getInt("Skills.Acrobatics.Roll_DamageThreshold", 7); } public double getGracefulRollChanceMax() { return config.getDouble("Skills.Acrobatics.GracefulRoll_ChanceMax", 100.0D); } public int getGracefulRollMaxBonusLevel() { return config.getInt("Skills.Acrobatics.GracefulRoll_MaxBonusLevel", 500); } + public int getGracefulRollDamageThreshold() { return config.getInt("Skills.Acrobatics.GracefulRoll_DamageThreshold", 14); } + public int getGracefulRollSuccessModifer() { return config.getInt("Skills.Acrobatics.GracefulRoll_SuccessModifier", 2); } public int getDodgeXPModifier() { return config.getInt("Skills.Acrobatics.Dodge_XP_Modifier", 120); } public int getRollXPModifier() { return config.getInt("Skills.Acrobatics.Roll_XP_Modifier", 80); } diff --git a/src/main/java/com/gmail/nossr50/listeners/EntityListener.java b/src/main/java/com/gmail/nossr50/listeners/EntityListener.java index e31351960..d78f5dced 100644 --- a/src/main/java/com/gmail/nossr50/listeners/EntityListener.java +++ b/src/main/java/com/gmail/nossr50/listeners/EntityListener.java @@ -34,7 +34,6 @@ import com.gmail.nossr50.events.fake.FakeEntityDamageByEntityEvent; import com.gmail.nossr50.events.fake.FakeEntityDamageEvent; import com.gmail.nossr50.party.PartyManager; import com.gmail.nossr50.skills.acrobatics.Acrobatics; -import com.gmail.nossr50.skills.acrobatics.AcrobaticsManager; import com.gmail.nossr50.skills.archery.Archery; import com.gmail.nossr50.skills.fishing.Fishing; import com.gmail.nossr50.skills.herbalism.Herbalism; @@ -176,8 +175,11 @@ public class EntityListener implements Listener { if (!CombatTools.isInvincible(player, event.getDamage())) { if (cause == DamageCause.FALL && player.getItemInHand().getType() != Material.ENDER_PEARL && !(Acrobatics.afkLevelingDisabled && player.isInsideVehicle()) && Permissions.roll(player)) { - AcrobaticsManager acrobaticsManager = new AcrobaticsManager(mcMMOPlayer); - acrobaticsManager.rollCheck(event); + event.setDamage(Acrobatics.processRoll(player, event.getDamage())); + + if (event.getDamage() == 0) { + event.setCancelled(true); + } } else if (cause == DamageCause.BLOCK_EXPLOSION && Permissions.demolitionsExpertise(player)) { MiningManager miningManager = new MiningManager(mcMMOPlayer); diff --git a/src/main/java/com/gmail/nossr50/skills/acrobatics/Acrobatics.java b/src/main/java/com/gmail/nossr50/skills/acrobatics/Acrobatics.java index a085632f7..11d332359 100644 --- a/src/main/java/com/gmail/nossr50/skills/acrobatics/Acrobatics.java +++ b/src/main/java/com/gmail/nossr50/skills/acrobatics/Acrobatics.java @@ -1,22 +1,89 @@ package com.gmail.nossr50.skills.acrobatics; +import org.bukkit.entity.Player; + import com.gmail.nossr50.config.AdvancedConfig; import com.gmail.nossr50.config.Config; +import com.gmail.nossr50.locale.LocaleLoader; +import com.gmail.nossr50.skills.utilities.PerksUtils; +import com.gmail.nossr50.skills.utilities.SkillType; +import com.gmail.nossr50.util.Misc; +import com.gmail.nossr50.util.Permissions; +import com.gmail.nossr50.util.Users; -public class Acrobatics { +public final class Acrobatics { public static double dodgeMaxChance = AdvancedConfig.getInstance().getDodgeChanceMax(); public static int dodgeMaxBonusLevel = AdvancedConfig.getInstance().getDodgeMaxBonusLevel(); public static int dodgeXpModifier = AdvancedConfig.getInstance().getDodgeXPModifier(); public static double rollMaxChance = AdvancedConfig.getInstance().getRollChanceMax(); public static int rollMaxBonusLevel = AdvancedConfig.getInstance().getRollMaxBonusLevel(); + public static int rollThreshold = AdvancedConfig.getInstance().getRollDamageThreshold(); public static double gracefulRollMaxChance = AdvancedConfig.getInstance().getGracefulRollChanceMax(); public static int gracefulRollMaxBonusLevel = AdvancedConfig.getInstance().getGracefulRollMaxBonusLevel(); + public static int gracefulRollThreshold = AdvancedConfig.getInstance().getGracefulRollDamageThreshold(); + public static int gracefulRollSuccessModifier = AdvancedConfig.getInstance().getGracefulRollSuccessModifer(); public static int rollXpModifier = AdvancedConfig.getInstance().getRollXPModifier(); public static int fallXpModifier = AdvancedConfig.getInstance().getFallXPModifier(); public static boolean afkLevelingDisabled = Config.getInstance().getAcrobaticsAFKDisabled(); public static boolean dodgeLightningDisabled = Config.getInstance().getDodgeLightningDisabled(); + + private Acrobatics() {}; + + public static int processRoll(Player player, int damage) { + if (player.isSneaking() && Permissions.gracefulRoll(player)) { + return processGracefulRoll(player, damage); + } + + int modifiedDamage = calculateModifiedDamage(damage, rollThreshold); + + if (!isFatal(player, modifiedDamage) && isSuccessfulRoll(player, rollMaxChance, rollMaxBonusLevel, 1)) { + player.sendMessage(LocaleLoader.getString("Acrobatics.Roll.Text")); + applyXpGain(player, damage, rollXpModifier); + + return modifiedDamage; + } + else if (!isFatal(player, damage)) { + applyXpGain(player, damage, fallXpModifier); + } + + return damage; + } + + private static int processGracefulRoll(Player player, int damage) { + int modifiedDamage = calculateModifiedDamage(damage, gracefulRollThreshold); + + if (!isFatal(player, modifiedDamage) && isSuccessfulRoll(player, gracefulRollMaxChance, gracefulRollMaxBonusLevel, gracefulRollSuccessModifier)) { + player.sendMessage(LocaleLoader.getString("Acrobatics.Ability.Proc")); + applyXpGain(player, damage, rollXpModifier); + + return modifiedDamage; + } + else if (!isFatal(player, damage)) { + applyXpGain(player, damage, fallXpModifier); + } + + return damage; + } + + private static boolean isFatal(Player player, int damage) { + return player.getHealth() - damage < 1; + } + + private static int calculateModifiedDamage(int damage, int damageThreshold) { + return Math.max(damage - damageThreshold, 0); + } + + private static boolean isSuccessfulRoll(Player player, double maxChance, int maxLevel, int successModifier) { + double successChance = (maxChance / maxLevel) * Math.min(Users.getPlayer(player).getProfile().getSkillLevel(SkillType.ACROBATICS), maxLevel) * successModifier; + + return successChance > Misc.getRandom().nextInt(PerksUtils.handleLuckyPerks(player, SkillType.ACROBATICS)); + } + + private static void applyXpGain(Player player, int baseXp, int multiplier) { + Users.getPlayer(player).beginXpGain(SkillType.ACROBATICS, baseXp * multiplier); + } } \ No newline at end of file diff --git a/src/main/java/com/gmail/nossr50/skills/acrobatics/AcrobaticsManager.java b/src/main/java/com/gmail/nossr50/skills/acrobatics/AcrobaticsManager.java index 293844abf..f1c3f364d 100644 --- a/src/main/java/com/gmail/nossr50/skills/acrobatics/AcrobaticsManager.java +++ b/src/main/java/com/gmail/nossr50/skills/acrobatics/AcrobaticsManager.java @@ -12,33 +12,6 @@ public class AcrobaticsManager extends SkillManager { super(mcMMOPlayer, SkillType.ACROBATICS); } - /** - * Check for fall damage reduction. - * - * @param event The event to check - */ - public void rollCheck(EntityDamageEvent event) { - RollEventHandler eventHandler = new RollEventHandler(this, event); - - double chance; - - if (eventHandler.isGraceful) { - chance = (Acrobatics.gracefulRollMaxChance / Acrobatics.gracefulRollMaxBonusLevel) * eventHandler.skillModifier; - } - else { - chance = (Acrobatics.rollMaxChance / Acrobatics.rollMaxBonusLevel) * eventHandler.skillModifier; - } - - if (chance > Misc.getRandom().nextInt(activationChance) && !eventHandler.isFatal(eventHandler.modifiedDamage)) { - eventHandler.modifyEventDamage(); - eventHandler.sendAbilityMessage(); - eventHandler.processXpGain(eventHandler.damage * Acrobatics.rollXpModifier); - } - else if (!eventHandler.isFatal(event.getDamage())) { - eventHandler.processXpGain(eventHandler.damage * Acrobatics.fallXpModifier); - } - } - /** * Check for dodge damage reduction. * diff --git a/src/main/java/com/gmail/nossr50/skills/acrobatics/RollEventHandler.java b/src/main/java/com/gmail/nossr50/skills/acrobatics/RollEventHandler.java deleted file mode 100644 index 81fb9367d..000000000 --- a/src/main/java/com/gmail/nossr50/skills/acrobatics/RollEventHandler.java +++ /dev/null @@ -1,101 +0,0 @@ -package com.gmail.nossr50.skills.acrobatics; - -import org.bukkit.entity.Player; -import org.bukkit.event.entity.EntityDamageEvent; - -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.Permissions; - -public class RollEventHandler extends AcrobaticsEventHandler { - protected boolean isGraceful; - private int damageThreshold; - - protected RollEventHandler(AcrobaticsManager manager, EntityDamageEvent event) { - super(manager, event); - - isGracefulRoll(); - calculateSkillModifier(); - calculateDamageThreshold(); - calculateModifiedDamage(); - } - - @Override - protected void calculateSkillModifier() { - int skillModifer = manager.getSkillLevel(); - - if (isGraceful) { - skillModifer = skillModifer * 2; - } - - skillModifer = SkillTools.skillCheck(skillModifer, Acrobatics.rollMaxBonusLevel); - this.skillModifier = skillModifer; - } - - @Override - protected void calculateModifiedDamage() { - int modifiedDamage = damage - damageThreshold; - - if (modifiedDamage < 0) { - modifiedDamage = 0; - } - - this.modifiedDamage = modifiedDamage; - } - - @Override - protected void modifyEventDamage() { - event.setDamage(modifiedDamage); - - if (event.getDamage() == 0) { - event.setCancelled(true); - } - } - - - @Override - protected void sendAbilityMessage() { - Player player = manager.getMcMMOPlayer().getPlayer(); - - if (isGraceful) { - player.sendMessage(LocaleLoader.getString("Acrobatics.Ability.Proc")); - } - else { - player.sendMessage(LocaleLoader.getString("Acrobatics.Roll.Text")); - } - } - - - @Override - protected void processXpGain(int xp) { - manager.getMcMMOPlayer().beginXpGain(SkillType.ACROBATICS, xp); - } - - /** - * Check if this is a graceful roll. - */ - private void isGracefulRoll() { - Player player = manager.getMcMMOPlayer().getPlayer(); - - if (Permissions.gracefulRoll(player)) { - this.isGraceful = player.isSneaking(); - } - else { - this.isGraceful = false; - } - } - - /** - * Calculate the damage threshold for this event. - */ - private void calculateDamageThreshold() { - int damageThreshold = 7; - - if (isGraceful) { - damageThreshold = damageThreshold * 2; - } - - this.damageThreshold = damageThreshold; - } -} diff --git a/src/main/resources/advanced.yml b/src/main/resources/advanced.yml index 276622d1f..1e953ef16 100644 --- a/src/main/resources/advanced.yml +++ b/src/main/resources/advanced.yml @@ -27,13 +27,19 @@ Skills: # Roll_ChanceMax: Maximum chance of rolling when on Roll_MaxBonusLevel or higher # Roll_MaxBonusLevel: On this level or higher, the roll chance will not go higher than Roll_ChanceMax + # Roll_DamageThreshold: The max damage a player can negate with a roll Roll_ChanceMax: 100.0 Roll_MaxBonusLevel: 1000 + Roll_DamageThreshold: 7 # GracefulRoll_ChanceMax: Maximum chance of graceful rolling when on GracefulRoll_MaxBonusLevel or higher # GracefulRoll_MaxBonusLevel: On this level or higher, the graceful roll chance will not go higher than GracefulRoll_ChanceMax + # GracefulRoll_DamageThreshold: The max damage a player can negate with a graceful roll + # GracefulRoll_SuccessModifier: Graceful rolls will be this many times more likely to succeed than regular rolls GracefulRoll_ChanceMax: 100.0 GracefulRoll_MaxBonusLevel: 500 + GracefulRoll_DamageThreshold: 14 + GracefulRoll_SuccessModifier: 2 # Amount of experience for performing a dodge, roll or fall Dodge_XP_Modifier: 120