AcrobaticsManager.java 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. package com.gmail.nossr50.skills.acrobatics;
  2. import org.bukkit.entity.Player;
  3. import org.bukkit.event.entity.EntityDamageEvent;
  4. import com.gmail.nossr50.config.Config;
  5. import com.gmail.nossr50.datatypes.SkillType;
  6. import com.gmail.nossr50.skills.SkillManager;
  7. import com.gmail.nossr50.util.Misc;
  8. import com.gmail.nossr50.util.Permissions;
  9. public class AcrobaticsManager extends SkillManager {
  10. private static Config config = Config.getInstance();
  11. public AcrobaticsManager (Player player) {
  12. super(player, SkillType.ACROBATICS);
  13. }
  14. /**
  15. * Check for fall damage reduction.
  16. *
  17. * @param event The event to check
  18. */
  19. public void rollCheck(EntityDamageEvent event) {
  20. if (Misc.isCitizensNPC(player) || !Permissions.roll(player)) {
  21. return;
  22. }
  23. if (config.getAcrobaticsAFKDisabled() && player.isInsideVehicle()) {
  24. return;
  25. }
  26. RollEventHandler eventHandler = new RollEventHandler(this, event);
  27. int randomChance = 100;
  28. if (Permissions.luckyAcrobatics(player)) {
  29. randomChance = (int) (randomChance * 0.75);
  30. }
  31. float chance;
  32. if (eventHandler.isGraceful) {
  33. chance = ((float) Acrobatics.GRACEFUL_MAX_CHANCE / Acrobatics.GRACEFUL_MAX_BONUS_LEVEL) * eventHandler.skillModifier;
  34. }
  35. else {
  36. chance = ((float) Acrobatics.ROLL_MAX_CHANCE / Acrobatics.ROLL_MAX_BONUS_LEVEL) * eventHandler.skillModifier;
  37. }
  38. if (chance > Misc.getRandom().nextInt(randomChance) && !eventHandler.isFatal(eventHandler.modifiedDamage)) {
  39. eventHandler.modifyEventDamage();
  40. eventHandler.sendAbilityMessage();
  41. eventHandler.processXPGain(eventHandler.damage * Acrobatics.ROLL_XP_MODIFIER);
  42. }
  43. else if (!eventHandler.isFatal(event.getDamage())) {
  44. eventHandler.processXPGain(eventHandler.damage * Acrobatics.FALL_XP_MODIFIER);
  45. }
  46. }
  47. /**
  48. * Check for dodge damage reduction.
  49. *
  50. * @param event The event to check
  51. */
  52. public void dodgeCheck(EntityDamageEvent event) {
  53. if (Misc.isCitizensNPC(player) || !Permissions.dodge(player)) {
  54. return;
  55. }
  56. DodgeEventHandler eventHandler = new DodgeEventHandler(this, event);
  57. int randomChance = 100;
  58. if (Permissions.luckyAcrobatics(player)) {
  59. randomChance = (int) (randomChance * 0.75);
  60. }
  61. float chance = ((float) Acrobatics.DODGE_MAX_CHANCE / Acrobatics.DODGE_MAX_BONUS_LEVEL) * eventHandler.skillModifier;
  62. if (chance > Misc.getRandom().nextInt(randomChance) && !eventHandler.isFatal(eventHandler.modifiedDamage)) {
  63. eventHandler.modifyEventDamage();
  64. eventHandler.sendAbilityMessage();
  65. eventHandler.processXPGain(eventHandler.damage * Acrobatics.DODGE_XP_MODIFIER);
  66. }
  67. }
  68. }