ArcheryManager.java 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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.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 ArcheryManager extends SkillManager {
  10. public ArcheryManager (Player player) {
  11. super(player, SkillType.ARCHERY);
  12. }
  13. /**
  14. * Track arrows fired for later retrieval.
  15. *
  16. * @param livingEntity Entity damaged by the arrow
  17. */
  18. public void trackArrows(LivingEntity livingEntity) {
  19. if (Misc.isNPC(player) || !Permissions.trackArrows(player)) {
  20. return;
  21. }
  22. ArrowTrackingEventHandler eventHandler = new ArrowTrackingEventHandler(this, livingEntity);
  23. int randomChance = 100;
  24. if (Permissions.luckyArchery(player)) {
  25. randomChance = (int) (randomChance * 0.75);
  26. }
  27. float chance = ((float) Archery.ARROW_TRACKING_MAX_BONUS / Archery.ARROW_TRACKING_MAX_BONUS_LEVEL) * eventHandler.skillModifier;
  28. if (chance > Misc.getRandom().nextInt(randomChance)) {
  29. eventHandler.addToTracker();
  30. }
  31. }
  32. /**
  33. * Check for Daze.
  34. *
  35. * @param defender Defending player
  36. * @param event The event to modify
  37. */
  38. public void dazeCheck(Player defender, EntityDamageEvent event) {
  39. if (Misc.isNPC(player) || !Permissions.daze(player)) {
  40. return;
  41. }
  42. DazeEventHandler eventHandler = new DazeEventHandler(this, event, defender);
  43. int randomChance = 100;
  44. if (Permissions.luckyArchery(player)) {
  45. randomChance = (int) (randomChance * 0.75);
  46. }
  47. float chance = ((float) Archery.DAZE_MAX_BONUS / Archery.DAZE_MAX_BONUS_LEVEL) * eventHandler.skillModifier;
  48. if (chance > Misc.getRandom().nextInt(randomChance)) {
  49. eventHandler.handleDazeEffect();
  50. eventHandler.sendAbilityMessages();
  51. }
  52. }
  53. /**
  54. * Handle archery bonus damage.
  55. *
  56. * @param event The event to modify.
  57. */
  58. public void bonusDamage(EntityDamageEvent event) {
  59. if (Misc.isNPC(player) || !Permissions.archeryBonus(player)) {
  60. return;
  61. }
  62. if (skillLevel >= Archery.BONUS_DAMAGE_INCREASE_LEVEL) {
  63. ArcheryBonusDamageEventHandler eventHandler = new ArcheryBonusDamageEventHandler(this, event);
  64. eventHandler.calculateDamageBonus();
  65. eventHandler.modifyEventDamage();
  66. }
  67. }
  68. }