ArcheryManager.java 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. package com.gmail.nossr50.skills.archery;
  2. import org.bukkit.entity.LivingEntity;
  3. import org.bukkit.entity.Player;
  4. import org.bukkit.event.entity.EntityDamageEvent;
  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 ArcheryManager {
  10. private Player player;
  11. private PlayerProfile profile;
  12. private int skillLevel;
  13. private Permissions permissionsInstance;
  14. public ArcheryManager (Player player) {
  15. this.player = player;
  16. this.profile = Users.getProfile(player);
  17. //Compatibility with Citizens, Citizens NPCs won't create a profile so we'll check for it here
  18. if(this.profile == null)
  19. return;
  20. this.skillLevel = profile.getSkillLevel(SkillType.ARCHERY);
  21. this.permissionsInstance = Permissions.getInstance();
  22. }
  23. /**
  24. * Track arrows fired for later retrieval.
  25. *
  26. * @param livingEntity Entity damaged by the arrow
  27. */
  28. public void trackArrows(LivingEntity livingEntity) {
  29. if(player == null)
  30. return;
  31. if(permissionsInstance == null)
  32. return;
  33. if (!permissionsInstance.trackArrows(player)) {
  34. return;
  35. }
  36. ArrowTrackingEventHandler eventHandler = new ArrowTrackingEventHandler(this, livingEntity);
  37. int randomChance = 100;
  38. if (player.hasPermission("mcmmo.perks.lucky.archery")) {
  39. randomChance = (int) (randomChance * 0.75);
  40. }
  41. final float chance = (float) (((double) Archery.ARROW_TRACKING_MAX_BONUS / (double) Archery.ARROW_TRACKING_MAX_BONUS_LEVEL) * skillLevel);
  42. if (chance > Archery.getRandom().nextInt(randomChance)) {
  43. eventHandler.addToTracker();
  44. }
  45. }
  46. /**
  47. * Check for Daze.
  48. *
  49. * @param defender Defending player
  50. * @param event The event to modify
  51. */
  52. public void dazeCheck(Player defender, EntityDamageEvent event) {
  53. if(player == null)
  54. return;
  55. if(permissionsInstance == null)
  56. return;
  57. if (!permissionsInstance.daze(player)) {
  58. return;
  59. }
  60. DazeEventHandler eventHandler = new DazeEventHandler(this, event, defender);
  61. int randomChance = 100;
  62. if (player.hasPermission("mcmmo.perks.lucky.archery")) {
  63. randomChance = (int) (randomChance * 0.75);
  64. }
  65. final float chance = (float) (((double) Archery.DAZE_MAX_BONUS / (double) Archery.DAZE_MAX_BONUS_LEVEL) * skillLevel);
  66. if (chance > Archery.getRandom().nextInt(randomChance)) {
  67. eventHandler.handleDazeEffect();
  68. eventHandler.sendAbilityMessages();
  69. }
  70. }
  71. /**
  72. * Handle archery bonus damage.
  73. *
  74. * @param event The event to modify.
  75. */
  76. public void bonusDamage(EntityDamageEvent event) {
  77. if(player == null)
  78. return;
  79. if(permissionsInstance == null)
  80. return;
  81. if (!permissionsInstance.archeryBonus(player)) {
  82. return;
  83. }
  84. if (skillLevel >= Archery.BONUS_DAMAGE_INCREASE_LEVEL) {
  85. ArcheryBonusDamageEventHandler eventHandler = new ArcheryBonusDamageEventHandler(this, event);
  86. eventHandler.calculateDamageBonus();
  87. eventHandler.modifyEventDamage();
  88. }
  89. }
  90. protected int getSkillLevel() {
  91. return skillLevel;
  92. }
  93. protected Player getPlayer() {
  94. return player;
  95. }
  96. }