AxesManager.java 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. package com.gmail.nossr50.skills.axes;
  2. import com.gmail.nossr50.datatypes.interactions.NotificationType;
  3. import com.gmail.nossr50.datatypes.player.McMMOPlayer;
  4. import com.gmail.nossr50.datatypes.skills.PrimarySkillType;
  5. import com.gmail.nossr50.datatypes.skills.SubSkillType;
  6. import com.gmail.nossr50.datatypes.skills.SuperAbilityType;
  7. import com.gmail.nossr50.datatypes.skills.ToolType;
  8. import com.gmail.nossr50.datatypes.skills.behaviours.AxesBehaviour;
  9. import com.gmail.nossr50.mcMMO;
  10. import com.gmail.nossr50.skills.SkillManager;
  11. import com.gmail.nossr50.util.ItemUtils;
  12. import com.gmail.nossr50.util.Permissions;
  13. import com.gmail.nossr50.util.random.RandomChanceUtil;
  14. import com.gmail.nossr50.util.skills.ParticleEffectUtils;
  15. import com.gmail.nossr50.util.skills.RankUtils;
  16. import com.gmail.nossr50.util.skills.SkillActivationType;
  17. import org.bukkit.entity.LivingEntity;
  18. import org.bukkit.entity.Player;
  19. import org.bukkit.event.entity.EntityDamageEvent.DamageModifier;
  20. import org.bukkit.inventory.ItemStack;
  21. import java.util.Map;
  22. public class AxesManager extends SkillManager {
  23. private final AxesBehaviour axesBehaviour;
  24. public AxesManager(mcMMO pluginRef, McMMOPlayer mcMMOPlayer) {
  25. super(pluginRef, mcMMOPlayer, PrimarySkillType.AXES);
  26. this.axesBehaviour = pluginRef.getDynamicSettingsManager().getSkillBehaviourManager().getAxesBehaviour();
  27. }
  28. public boolean canUseAxeMastery() {
  29. if (!RankUtils.hasUnlockedSubskill(getPlayer(), SubSkillType.AXES_AXE_MASTERY))
  30. return false;
  31. return Permissions.isSubSkillEnabled(getPlayer(), SubSkillType.AXES_AXE_MASTERY);
  32. }
  33. public boolean canCriticalHit(LivingEntity target) {
  34. if (!RankUtils.hasUnlockedSubskill(getPlayer(), SubSkillType.AXES_CRITICAL_STRIKES))
  35. return false;
  36. return target.isValid() && Permissions.isSubSkillEnabled(getPlayer(), SubSkillType.AXES_CRITICAL_STRIKES);
  37. }
  38. public boolean canImpact(LivingEntity target) {
  39. if (!RankUtils.hasUnlockedSubskill(getPlayer(), SubSkillType.AXES_ARMOR_IMPACT))
  40. return false;
  41. return target.isValid() && Permissions.isSubSkillEnabled(getPlayer(), SubSkillType.AXES_ARMOR_IMPACT) && axesBehaviour.hasArmor(target);
  42. }
  43. public boolean canGreaterImpact(LivingEntity target) {
  44. if (!RankUtils.hasUnlockedSubskill(getPlayer(), SubSkillType.AXES_GREATER_IMPACT))
  45. return false;
  46. return target.isValid() && Permissions.isSubSkillEnabled(getPlayer(), SubSkillType.AXES_GREATER_IMPACT) && !axesBehaviour.hasArmor(target);
  47. }
  48. public boolean canUseSkullSplitter(LivingEntity target) {
  49. if (!RankUtils.hasUnlockedSubskill(getPlayer(), SubSkillType.AXES_SKULL_SPLITTER))
  50. return false;
  51. return target.isValid() && mcMMOPlayer.getAbilityMode(SuperAbilityType.SKULL_SPLITTER) && Permissions.skullSplitter(getPlayer());
  52. }
  53. public boolean canActivateAbility() {
  54. return mcMMOPlayer.getToolPreparationMode(ToolType.AXE) && Permissions.skullSplitter(getPlayer());
  55. }
  56. /**
  57. * Handle the effects of the Axe Mastery ability
  58. */
  59. public double axeMastery() {
  60. if (!RandomChanceUtil.isActivationSuccessful(SkillActivationType.ALWAYS_FIRES, SubSkillType.AXES_AXE_MASTERY, getPlayer())) {
  61. return 0;
  62. }
  63. return axesBehaviour.getAxeMasteryBonusDamage(getPlayer());
  64. }
  65. /**
  66. * Handle the effects of the Critical Hit ability
  67. *
  68. * @param target The {@link LivingEntity} being affected by the ability
  69. * @param damage The amount of damage initially dealt by the event
  70. */
  71. public double criticalHit(LivingEntity target, double damage) {
  72. if (!RandomChanceUtil.isActivationSuccessful(SkillActivationType.RANDOM_LINEAR_100_SCALE_WITH_CAP, SubSkillType.AXES_CRITICAL_STRIKES, getPlayer())) {
  73. return 0;
  74. }
  75. Player player = getPlayer();
  76. if (mcMMOPlayer.useChatNotifications()) {
  77. pluginRef.getNotificationManager().sendPlayerInformation(player, NotificationType.SUBSKILL_MESSAGE, "Axes.Combat.CriticalHit");
  78. }
  79. if (target instanceof Player) {
  80. Player defender = (Player) target;
  81. if (pluginRef.getNotificationManager().doesPlayerUseNotifications(defender)) {
  82. pluginRef.getNotificationManager().sendPlayerInformation(defender, NotificationType.SUBSKILL_MESSAGE, "Axes.Combat.CritStruck");
  83. }
  84. damage = (damage * pluginRef.getConfigManager().getConfigAxes().getConfigAxesCriticalStrikes().getDamageProperty().getPVPModifier()) - damage;
  85. } else {
  86. damage = (damage * pluginRef.getConfigManager().getConfigAxes().getConfigAxesCriticalStrikes().getDamageProperty().getPVEModifier()) - damage;
  87. }
  88. return damage;
  89. }
  90. /**
  91. * Handle the effects of the Impact ability
  92. *
  93. * @param target The {@link LivingEntity} being affected by Impact
  94. */
  95. public void impactCheck(LivingEntity target) {
  96. double durabilityDamage = getImpactDurabilityDamage();
  97. for (ItemStack armor : target.getEquipment().getArmorContents()) {
  98. if (armor != null && ItemUtils.isArmor(armor)) {
  99. if (RandomChanceUtil.isActivationSuccessful(SkillActivationType.RANDOM_STATIC_CHANCE, SubSkillType.AXES_ARMOR_IMPACT, getPlayer())) {
  100. pluginRef.getSkillTools().handleDurabilityChange(armor, durabilityDamage, 1);
  101. }
  102. }
  103. }
  104. }
  105. public double getImpactDurabilityDamage() {
  106. return pluginRef.getConfigManager().getConfigAxes().getConfigAxesImpact().getImpactDurabilityDamageModifier() * RankUtils.getRank(getPlayer(), SubSkillType.AXES_ARMOR_IMPACT);
  107. }
  108. /**
  109. * Handle the effects of the Greater Impact ability
  110. *
  111. * @param target The {@link LivingEntity} being affected by the ability
  112. */
  113. public double greaterImpact(LivingEntity target) {
  114. //chance (3rd param)
  115. if (!RandomChanceUtil.isActivationSuccessful(SkillActivationType.RANDOM_STATIC_CHANCE, SubSkillType.AXES_GREATER_IMPACT, getPlayer())) {
  116. return 0;
  117. }
  118. Player player = getPlayer();
  119. ParticleEffectUtils.playGreaterImpactEffect(target);
  120. target.setVelocity(player.getLocation().getDirection().normalize().multiply(pluginRef.getConfigManager().getConfigAxes().getGreaterImpactKnockBackModifier()));
  121. if (mcMMOPlayer.useChatNotifications()) {
  122. pluginRef.getNotificationManager().sendPlayerInformation(player, NotificationType.SUBSKILL_MESSAGE, "Axes.Combat.GI.Proc");
  123. }
  124. if (target instanceof Player) {
  125. Player defender = (Player) target;
  126. if (pluginRef.getNotificationManager().doesPlayerUseNotifications(defender)) {
  127. pluginRef.getNotificationManager().sendPlayerInformation(defender, NotificationType.SUBSKILL_MESSAGE, "Axes.Combat.GI.Struck");
  128. }
  129. }
  130. return pluginRef.getConfigManager().getConfigAxes().getConfigAxesGreaterImpact().getBonusDamage();
  131. }
  132. /**
  133. * Handle the effects of the Skull Splitter ability
  134. *
  135. * @param target The {@link LivingEntity} being affected by the ability
  136. * @param damage The amount of damage initially dealt by the event
  137. */
  138. public void skullSplitterCheck(LivingEntity target, double damage, Map<DamageModifier, Double> modifiers) {
  139. pluginRef.getCombatTools().applyAbilityAoE(getPlayer(), target, damage / pluginRef.getConfigManager().getConfigAxes().getConfigAxesSkullSplitter().getSkullSplitterDamageDivisor(), modifiers, skill);
  140. }
  141. }