AxesManager.java 7.3 KB

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