diff --git a/src/main/java/com/gmail/nossr50/config/AdvancedConfig.java b/src/main/java/com/gmail/nossr50/config/AdvancedConfig.java index 9c2750fc4..c5e3b3b95 100644 --- a/src/main/java/com/gmail/nossr50/config/AdvancedConfig.java +++ b/src/main/java/com/gmail/nossr50/config/AdvancedConfig.java @@ -25,6 +25,7 @@ public class AdvancedConfig extends AutoUpdateConfigLoader { /* ACROBATICS */ public double getDodgeChanceMax() { return config.getDouble("Skills.Acrobatics.Dodge_ChanceMax", 20.0D); } public int getDodgeMaxBonusLevel() { return config.getInt("Skills.Acrobatics.Dodge_MaxBonusLevel", 800); } + public int getDodgeDamageModifier() { return config.getInt("Skills.Acrobatics.Dodge_DamageModifer", 2); } public double getRollChanceMax() { return config.getDouble("Skills.Acrobatics.Roll_ChanceMax", 100.0D); } public int getRollMaxBonusLevel() { return config.getInt("Skills.Acrobatics.Roll_MaxBonusLevel", 1000); } diff --git a/src/main/java/com/gmail/nossr50/skills/SkillManager.java b/src/main/java/com/gmail/nossr50/skills/SkillManager.java index 71a2cdbb3..84ddc8c09 100644 --- a/src/main/java/com/gmail/nossr50/skills/SkillManager.java +++ b/src/main/java/com/gmail/nossr50/skills/SkillManager.java @@ -41,4 +41,8 @@ public abstract class SkillManager { public SkillType getSkill() { return skill; } + + public void applyXpGain(int xp) { + mcMMOPlayer.beginXpGain(skill, xp); + } } 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 618c8269e..97c6059eb 100644 --- a/src/main/java/com/gmail/nossr50/skills/acrobatics/Acrobatics.java +++ b/src/main/java/com/gmail/nossr50/skills/acrobatics/Acrobatics.java @@ -1,6 +1,8 @@ package com.gmail.nossr50.skills.acrobatics; import org.bukkit.Material; +import org.bukkit.entity.Entity; +import org.bukkit.entity.LightningStrike; import org.bukkit.entity.Player; import com.gmail.nossr50.config.AdvancedConfig; @@ -16,6 +18,7 @@ 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 int dodgeDamageModifier = AdvancedConfig.getInstance().getDodgeDamageModifier(); public static double rollMaxChance = AdvancedConfig.getInstance().getRollChanceMax(); public static int rollMaxBonusLevel = AdvancedConfig.getInstance().getRollMaxBonusLevel(); @@ -38,12 +41,25 @@ public final class Acrobatics { return (player.getItemInHand().getType() != Material.ENDER_PEARL) && !(afkLevelingDisabled && player.isInsideVehicle()) && Permissions.roll(player); } + public static boolean canDodge(Player player, Entity damager) { + if (Permissions.dodge(player)) { + if (damager instanceof Player && SkillType.ACROBATICS.getPVPEnabled()) { + return true; + } + else if (!(damager instanceof Player) && SkillType.ACROBATICS.getPVEEnabled() && !(damager instanceof LightningStrike && Acrobatics.dodgeLightningDisabled)) { + return true; + } + } + + return false; + } + public static int processRoll(Player player, int damage) { if (player.isSneaking() && Permissions.gracefulRoll(player)) { return processGracefulRoll(player, damage); } - int modifiedDamage = calculateModifiedDamage(damage, rollThreshold); + int modifiedDamage = calculateModifiedRollDamage(damage, rollThreshold); if (!isFatal(player, modifiedDamage) && isSuccessfulRoll(player, rollMaxChance, rollMaxBonusLevel, 1)) { player.sendMessage(LocaleLoader.getString("Acrobatics.Roll.Text")); @@ -59,7 +75,7 @@ public final class Acrobatics { } private static int processGracefulRoll(Player player, int damage) { - int modifiedDamage = calculateModifiedDamage(damage, gracefulRollThreshold); + int modifiedDamage = calculateModifiedRollDamage(damage, gracefulRollThreshold); if (!isFatal(player, modifiedDamage) && isSuccessfulRoll(player, gracefulRollMaxChance, gracefulRollMaxBonusLevel, gracefulRollSuccessModifier)) { player.sendMessage(LocaleLoader.getString("Acrobatics.Ability.Proc")); @@ -74,15 +90,19 @@ public final class Acrobatics { return damage; } - private static boolean isFatal(Player player, int damage) { + protected static boolean isFatal(Player player, int damage) { return player.getHealth() - damage < 1; } - private static int calculateModifiedDamage(int damage, int damageThreshold) { + protected static int calculateModifiedDodgeDamage(int damage, int damageModifier) { + return Math.max(damage / damageModifier, 1); + } + + protected static int calculateModifiedRollDamage(int damage, int damageThreshold) { return Math.max(damage - damageThreshold, 0); } - private static boolean isSuccessfulRoll(Player player, double maxChance, int maxLevel, int successModifier) { + protected 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)); 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 f1c3f364d..396d9ceb0 100644 --- a/src/main/java/com/gmail/nossr50/skills/acrobatics/AcrobaticsManager.java +++ b/src/main/java/com/gmail/nossr50/skills/acrobatics/AcrobaticsManager.java @@ -1,11 +1,15 @@ package com.gmail.nossr50.skills.acrobatics; -import org.bukkit.event.entity.EntityDamageEvent; +import org.bukkit.entity.Player; import com.gmail.nossr50.datatypes.McMMOPlayer; +import com.gmail.nossr50.datatypes.PlayerProfile; +import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.skills.SkillManager; +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.ParticleEffectUtils; public class AcrobaticsManager extends SkillManager { public AcrobaticsManager (McMMOPlayer mcMMOPlayer) { @@ -17,15 +21,27 @@ public class AcrobaticsManager extends SkillManager { * * @param event The event to check */ - public void dodgeCheck(EntityDamageEvent event) { - DodgeEventHandler eventHandler = new DodgeEventHandler(this, event); + public int dodgeCheck(int damage) { + int modifiedDamage = Acrobatics.calculateModifiedDodgeDamage(damage, Acrobatics.dodgeDamageModifier); + Player player = getPlayer(); - double chance = (Acrobatics.dodgeMaxChance / Acrobatics.dodgeMaxBonusLevel) * eventHandler.skillModifier; + if (!Acrobatics.isFatal(player, modifiedDamage) && SkillTools.activationSuccessful(player, skill, Acrobatics.dodgeMaxChance, Acrobatics.dodgeMaxBonusLevel)) { + ParticleEffectUtils.playDodgeEffect(player); - if (chance > Misc.getRandom().nextInt(activationChance) && !eventHandler.isFatal(eventHandler.modifiedDamage)) { - eventHandler.modifyEventDamage(); - eventHandler.sendAbilityMessage(); - eventHandler.processXpGain(eventHandler.damage * Acrobatics.dodgeXpModifier); + PlayerProfile playerProfile = getProfile(); + + if (playerProfile.useChatNotifications()) { + player.sendMessage(LocaleLoader.getString("Acrobatics.Combat.Proc")); + } + + // Why do we check respawn cooldown here? + if (System.currentTimeMillis() >= playerProfile.getRespawnATS() + Misc.PLAYER_RESPAWN_COOLDOWN_SECONDS) { + applyXpGain(damage * Acrobatics.dodgeXpModifier); + } + + return modifiedDamage; } + + return damage; } } diff --git a/src/main/java/com/gmail/nossr50/skills/utilities/CombatTools.java b/src/main/java/com/gmail/nossr50/skills/utilities/CombatTools.java index 6bd831951..d7566b853 100644 --- a/src/main/java/com/gmail/nossr50/skills/utilities/CombatTools.java +++ b/src/main/java/com/gmail/nossr50/skills/utilities/CombatTools.java @@ -8,7 +8,6 @@ import org.bukkit.entity.Arrow; import org.bukkit.entity.Entity; import org.bukkit.entity.EntityType; import org.bukkit.entity.IronGolem; -import org.bukkit.entity.LightningStrike; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Player; import org.bukkit.entity.Skeleton; @@ -253,23 +252,19 @@ public final class CombatTools { ItemStack heldItem = player.getItemInHand(); + if (Acrobatics.canDodge(player, damager)) { + event.setDamage(SkillManagerStore.getInstance().getAcrobaticsManager(player.getName()).dodgeCheck(event.getDamage())); + } + if (damager instanceof Player) { if (SkillType.SWORDS.getPVPEnabled() && ItemChecks.isSword(heldItem) && Permissions.counterAttack(player)) { SkillManagerStore.getInstance().getSwordsManager(player.getName()).counterAttackChecks((LivingEntity) damager, event.getDamage()); } - - if (SkillType.ACROBATICS.getPVPEnabled() && Permissions.dodge(player)) { - SkillManagerStore.getInstance().getAcrobaticsManager(player.getName()).dodgeCheck(event); - } } else { if (SkillType.SWORDS.getPVEEnabled() && damager instanceof LivingEntity && ItemChecks.isSword(heldItem) && Permissions.counterAttack(player)) { SkillManagerStore.getInstance().getSwordsManager(player.getName()).counterAttackChecks((LivingEntity) damager, event.getDamage()); } - - if (SkillType.ACROBATICS.getPVEEnabled() && !(damager instanceof LightningStrike && Acrobatics.dodgeLightningDisabled) && Permissions.dodge(player)) { - SkillManagerStore.getInstance().getAcrobaticsManager(player.getName()).dodgeCheck(event); - } } } } diff --git a/src/main/resources/advanced.yml b/src/main/resources/advanced.yml index 39baed646..0d60c90b6 100644 --- a/src/main/resources/advanced.yml +++ b/src/main/resources/advanced.yml @@ -22,8 +22,10 @@ Skills: Acrobatics: # Dodge_ChanceMax: Maximum chance of dodging when on Dodge_MaxBonusLevel or higher # Dodge_MaxBonusLevel: On this level or higher, the dodge chance will not go higher than Dodge_ChanceMax + # Dodge_DamageModifer: Dodge damage will be divided by this multiplier Dodge_ChanceMax: 20.0 Dodge_MaxBonusLevel: 800 + Dodge_DamageModifier: 2 # 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