2
0

ArcheryManager.java 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. package com.gmail.nossr50.skills.archery;
  2. import com.gmail.nossr50.core.MetadataConstants;
  3. import com.gmail.nossr50.datatypes.interactions.NotificationType;
  4. import com.gmail.nossr50.datatypes.player.McMMOPlayer;
  5. import com.gmail.nossr50.datatypes.skills.PrimarySkillType;
  6. import com.gmail.nossr50.datatypes.skills.SubSkillType;
  7. import com.gmail.nossr50.datatypes.skills.behaviours.ArcheryBehaviour;
  8. import com.gmail.nossr50.mcMMO;
  9. import com.gmail.nossr50.skills.SkillManager;
  10. import com.gmail.nossr50.util.Misc;
  11. import com.gmail.nossr50.util.Permissions;
  12. import com.gmail.nossr50.util.skills.RankUtils;
  13. import com.gmail.nossr50.util.skills.SkillActivationType;
  14. import org.bukkit.Location;
  15. import org.bukkit.entity.Entity;
  16. import org.bukkit.entity.LivingEntity;
  17. import org.bukkit.entity.Player;
  18. import org.bukkit.entity.Projectile;
  19. import org.bukkit.potion.PotionEffect;
  20. import org.bukkit.potion.PotionEffectType;
  21. public class ArcheryManager extends SkillManager {
  22. private final ArcheryBehaviour archeryBehaviour;
  23. public ArcheryManager(mcMMO pluginRef, McMMOPlayer mcMMOPlayer) {
  24. super(pluginRef, mcMMOPlayer, PrimarySkillType.ARCHERY);
  25. //Init Behaviour
  26. this.archeryBehaviour = pluginRef.getDynamicSettingsManager().getSkillBehaviourManager().getArcheryBehaviour();
  27. }
  28. public boolean canDaze(LivingEntity target) {
  29. if (!RankUtils.hasUnlockedSubskill(getPlayer(), SubSkillType.ARCHERY_DAZE))
  30. return false;
  31. return target instanceof Player && Permissions.isSubSkillEnabled(getPlayer(), SubSkillType.ARCHERY_DAZE);
  32. }
  33. public boolean canSkillShot() {
  34. if (!RankUtils.hasUnlockedSubskill(getPlayer(), SubSkillType.ARCHERY_SKILL_SHOT))
  35. return false;
  36. return Permissions.isSubSkillEnabled(getPlayer(), SubSkillType.ARCHERY_SKILL_SHOT);
  37. }
  38. public boolean canRetrieveArrows() {
  39. if (!RankUtils.hasUnlockedSubskill(getPlayer(), SubSkillType.ARCHERY_ARROW_RETRIEVAL))
  40. return false;
  41. return Permissions.isSubSkillEnabled(getPlayer(), SubSkillType.ARCHERY_ARROW_RETRIEVAL);
  42. }
  43. /**
  44. * Calculate bonus XP awarded for Archery when hitting a far-away target.
  45. *
  46. * @param target The {@link LivingEntity} damaged by the arrow
  47. * @param damager The {@link Entity} who shot the arrow
  48. */
  49. public double distanceXpBonusMultiplier(LivingEntity target, Entity damager) {
  50. //Hacky Fix - some plugins spawn arrows and assign them to players after the ProjectileLaunchEvent fires
  51. if(!damager.hasMetadata(MetadataConstants.ARROW_DISTANCE_METAKEY))
  52. return damager.getLocation().distance(target.getLocation());
  53. Location firedLocation = (Location) damager.getMetadata(MetadataConstants.ARROW_DISTANCE_METAKEY).get(0).value();
  54. Location targetLocation = target.getLocation();
  55. if (firedLocation.getWorld() != targetLocation.getWorld()) {
  56. return 1;
  57. }
  58. return 1 + Math.min(firedLocation.distance(targetLocation), 50) * archeryBehaviour.getDistanceXpMultiplier();
  59. }
  60. /**
  61. * Track arrows fired for later retrieval.
  62. *
  63. * @param target The {@link LivingEntity} damaged by the arrow
  64. */
  65. public void processArrowRetrievalActivation(LivingEntity target, Projectile projectile) {
  66. if(projectile.hasMetadata(MetadataConstants.ARROW_TRACKER_METAKEY)) {
  67. archeryBehaviour.incrementArrowCount(target);
  68. projectile.removeMetadata(MetadataConstants.ARROW_TRACKER_METAKEY, pluginRef); //Only 1 entity per projectile
  69. }
  70. }
  71. /**
  72. * Handle the effects of the Daze ability
  73. *
  74. * @param defender The {@link Player} being affected by the ability
  75. */
  76. public double daze(Player defender) {
  77. if (!pluginRef.getRandomChanceTools().isActivationSuccessful(SkillActivationType.RANDOM_LINEAR_100_SCALE_WITH_CAP, SubSkillType.ARCHERY_DAZE, getPlayer())) {
  78. return 0;
  79. }
  80. Location dazedLocation = defender.getLocation();
  81. dazedLocation.setPitch(90 - Misc.getRandom().nextInt(181));
  82. defender.teleport(dazedLocation);
  83. defender.addPotionEffect(new PotionEffect(PotionEffectType.CONFUSION, 20 * 10, 10));
  84. if (pluginRef.getNotificationManager().doesPlayerUseNotifications(defender)) {
  85. pluginRef.getNotificationManager().sendPlayerInformation(defender, NotificationType.SUBSKILL_MESSAGE, "Combat.TouchedFuzzy");
  86. }
  87. if (mcMMOPlayer.useChatNotifications()) {
  88. pluginRef.getNotificationManager().sendPlayerInformation(getPlayer(), NotificationType.SUBSKILL_MESSAGE, "Combat.TargetDazed");
  89. }
  90. return archeryBehaviour.getDazeBonusDamage();
  91. }
  92. /**
  93. * Calculates the damage to deal after Skill Shot has been applied
  94. *
  95. * @param oldDamage The raw damage value of this arrow before we modify it
  96. */
  97. public double skillShot(double oldDamage) {
  98. if (!pluginRef.getRandomChanceTools().isActivationSuccessful(SkillActivationType.ALWAYS_FIRES, SubSkillType.ARCHERY_SKILL_SHOT, getPlayer())) {
  99. return oldDamage;
  100. }
  101. return archeryBehaviour.getSkillShotBonusDamage(getPlayer(), oldDamage);
  102. }
  103. }