AcrobaticsManager.java 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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.PlayerProfile;
  6. import com.gmail.nossr50.datatypes.SkillType;
  7. import com.gmail.nossr50.util.Permissions;
  8. import com.gmail.nossr50.util.Users;
  9. public class AcrobaticsManager {
  10. private Player player;
  11. private PlayerProfile profile;
  12. private int skillLevel;
  13. public AcrobaticsManager (Player player) {
  14. this.player = player;
  15. this.profile = Users.getProfile(player);
  16. this.skillLevel = profile.getSkillLevel(SkillType.ACROBATICS);
  17. this.permissionInstance = Permissions.getInstance();
  18. }
  19. /**
  20. * Check for fall damage reduction.
  21. *
  22. * @param event The event to check
  23. */
  24. public void rollCheck(EntityDamageEvent event) {
  25. if(player == null)
  26. return;
  27. if (!Permissions.roll(player)) {
  28. return;
  29. }
  30. if(Config.getInstance().getAcrobaticsAFKDisabled() && player.isInsideVehicle())
  31. return;
  32. RollEventHandler eventHandler = new RollEventHandler(this, event);
  33. int randomChance = 100;
  34. if (Permissions.luckyAcrobatics(player)) {
  35. randomChance = (int) (randomChance * 0.75);
  36. }
  37. float chance = (float) (((double) Acrobatics.ROLL_MAX_CHANCE / (double) Acrobatics.ROLL_MAX_BONUS_LEVEL) * skillLevel);
  38. if (chance > Acrobatics.ROLL_MAX_CHANCE) chance = Acrobatics.ROLL_MAX_CHANCE;
  39. if (eventHandler.isGraceful) {
  40. chance = (float) (((double) Acrobatics.GRACEFUL_MAX_CHANCE / (double) Acrobatics.GRACEFUL_MAX_BONUS_LEVEL) * skillLevel);
  41. if (chance > Acrobatics.GRACEFUL_MAX_CHANCE) chance = Acrobatics.GRACEFUL_MAX_CHANCE;
  42. }
  43. if (chance > Acrobatics.getRandom().nextInt(randomChance) && !eventHandler.isFatal(eventHandler.modifiedDamage)) {
  44. eventHandler.modifyEventDamage();
  45. eventHandler.sendAbilityMessage();
  46. eventHandler.processXPGain(eventHandler.damage * Acrobatics.ROLL_XP_MODIFIER);
  47. }
  48. else if (!eventHandler.isFatal(event.getDamage())) {
  49. eventHandler.processXPGain(eventHandler.damage * Acrobatics.FALL_XP_MODIFIER);
  50. }
  51. }
  52. /**
  53. * Check for dodge damage reduction.
  54. *
  55. * @param event The event to check
  56. */
  57. public void dodgeCheck(EntityDamageEvent event) {
  58. if(player == null)
  59. return;
  60. if (!Permissions.dodge(player)) {
  61. return;
  62. }
  63. DodgeEventHandler eventHandler = new DodgeEventHandler(this, event);
  64. int randomChance = 100;
  65. if (Permissions.luckyAcrobatics(player)) {
  66. randomChance = (int) (randomChance * 0.75);
  67. }
  68. float chance = (float) (((double) Acrobatics.DODGE_MAX_CHANCE / (double) Acrobatics.DODGE_MAX_BONUS_LEVEL) * skillLevel);
  69. if (chance > Acrobatics.DODGE_MAX_CHANCE) chance = Acrobatics.DODGE_MAX_CHANCE;
  70. if (chance > Acrobatics.getRandom().nextInt(randomChance) && !eventHandler.isFatal(eventHandler.modifiedDamage)) {
  71. eventHandler.modifyEventDamage();
  72. eventHandler.sendAbilityMessage();
  73. eventHandler.processXPGain(eventHandler.damage * Acrobatics.DODGE_XP_MODIFIER);
  74. }
  75. }
  76. protected Player getPlayer() {
  77. return player;
  78. }
  79. protected PlayerProfile getProfile() {
  80. return profile;
  81. }
  82. protected int getSkillLevel() {
  83. return skillLevel;
  84. }
  85. }