Axes.java 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. package com.gmail.nossr50.skills.combat;
  2. import java.util.Random;
  3. import org.bukkit.enchantments.Enchantment;
  4. import org.bukkit.entity.AnimalTamer;
  5. import org.bukkit.entity.Entity;
  6. import org.bukkit.entity.LivingEntity;
  7. import org.bukkit.entity.Player;
  8. import org.bukkit.entity.Tameable;
  9. import org.bukkit.event.entity.EntityDamageByEntityEvent;
  10. import org.bukkit.inventory.ItemStack;
  11. import org.bukkit.inventory.PlayerInventory;
  12. import com.gmail.nossr50.config.AdvancedConfig;
  13. import com.gmail.nossr50.datatypes.PlayerProfile;
  14. import com.gmail.nossr50.datatypes.SkillType;
  15. import com.gmail.nossr50.locale.LocaleLoader;
  16. import com.gmail.nossr50.party.PartyManager;
  17. import com.gmail.nossr50.util.Misc;
  18. import com.gmail.nossr50.util.Permissions;
  19. import com.gmail.nossr50.util.Users;
  20. public class Axes {
  21. static AdvancedConfig advancedConfig = AdvancedConfig.getInstance();
  22. private static Random random = new Random();
  23. /**
  24. * Apply bonus to damage done by axes.
  25. *
  26. * @param attacker The attacking player
  27. * @param event The event to modify
  28. */
  29. public static void axesBonus(Player attacker, EntityDamageByEntityEvent event) {
  30. if(attacker == null)
  31. return;
  32. final int MAX_BONUS = advancedConfig.getBonusDamageAxesBonusMax();
  33. final int MAX_LEVEL = advancedConfig.getBonusDamageAxesMaxBonusLevel();
  34. final int INCREASE_LEVEL = MAX_LEVEL / MAX_BONUS;
  35. /* Add 1 DMG for every 50 skill levels (default value) */
  36. int bonus = (int) ((double) Users.getProfile(attacker).getSkillLevel(SkillType.AXES) / (double) INCREASE_LEVEL);
  37. if (bonus > MAX_BONUS) {
  38. bonus = MAX_BONUS;
  39. }
  40. event.setDamage(event.getDamage() + bonus);
  41. }
  42. /**
  43. * Check for critical chances on axe damage.
  44. *
  45. * @param attacker The attacking player
  46. * @param event The event to modify
  47. */
  48. public static void axeCriticalCheck(Player attacker, EntityDamageByEntityEvent event) {
  49. if(attacker == null)
  50. return;
  51. Entity entity = event.getEntity();
  52. if (entity instanceof Tameable) {
  53. Tameable pet = (Tameable) entity;
  54. if (pet.isTamed()) {
  55. AnimalTamer tamer = pet.getOwner();
  56. if (tamer instanceof Player) {
  57. Player owner = (Player) tamer;
  58. if (owner == attacker || PartyManager.getInstance().inSameParty(attacker, owner)) {
  59. return;
  60. }
  61. }
  62. }
  63. }
  64. final int MAX_BONUS_LEVEL = advancedConfig.getAxesCriticalMaxBonusLevel();
  65. final double MAX_CHANCE = advancedConfig.getAxesCriticalChance();
  66. final double PVP_MODIFIER = advancedConfig.getAxesCriticalPVPModifier();
  67. final int PVE_MODIFIER = advancedConfig.getAxesCriticalPVEModifier();
  68. PlayerProfile attackerProfile = Users.getProfile(attacker);
  69. int skillLevel = attackerProfile.getSkillLevel(SkillType.AXES);
  70. int skillCheck = Misc.skillCheck(skillLevel, MAX_BONUS_LEVEL);
  71. int randomChance = 100;
  72. double chance = (MAX_CHANCE / MAX_BONUS_LEVEL) * skillCheck;
  73. if (chance > MAX_CHANCE) chance = MAX_CHANCE;
  74. if (Permissions.luckyAxes(attacker)) {
  75. randomChance = (int) (randomChance * 0.75);
  76. }
  77. if (chance > random.nextInt(randomChance) && !entity.isDead()){
  78. // if (random.nextInt(randomChance) <= skillCheck && !entity.isDead()){
  79. int damage = event.getDamage();
  80. if (entity instanceof Player){
  81. event.setDamage((int) (damage * PVP_MODIFIER));
  82. ((Player) entity).sendMessage(LocaleLoader.getString("Axes.Combat.CritStruck"));
  83. }
  84. else {
  85. event.setDamage(damage * PVE_MODIFIER);
  86. }
  87. attacker.sendMessage(LocaleLoader.getString("Axes.Combat.CriticalHit"));
  88. }
  89. }
  90. /**
  91. * Check for Impact ability.
  92. *
  93. * @param attacker The attacking player
  94. * @param target The defending entity
  95. * @param event The event to modify
  96. */
  97. @SuppressWarnings("deprecation")
  98. public static void impact(Player attacker, LivingEntity target, EntityDamageByEntityEvent event) {
  99. if(attacker == null)
  100. return;
  101. /*
  102. * TODO: Finish this skill. The idea is you will greatly damage an opponents armor.
  103. * When they are unarmored, you have a proc that will stun them and deal additional damage.
  104. */
  105. if (target instanceof Player) {
  106. Player targetPlayer = (Player) target;
  107. short durabilityDamage = 1; //Start with 1 durability damage
  108. /* Every 50 Skill Levels you gain 1 durability damage (default values) */
  109. int impactIncreaseLevel = advancedConfig.getArmorImpactIncreaseLevel();
  110. float impactMaxDamage = advancedConfig.getArmorImpactMaxDurabilityDamage() / 100F;
  111. short maxDurability;
  112. durabilityDamage += (int) ((double) Users.getProfile(attacker).getSkillLevel(SkillType.AXES) / (double) impactIncreaseLevel);
  113. if (!hasArmor(targetPlayer)) {
  114. applyGreaterImpact(attacker, target, event);
  115. }
  116. else {
  117. for (ItemStack armor : targetPlayer.getInventory().getArmorContents()) {
  118. if(Math.random() * 100 > 75) {
  119. int lowerdamage = 0;
  120. for (int i = 0; i <= durabilityDamage; i ++) {
  121. if (armor.containsEnchantment(Enchantment.DURABILITY)) {
  122. int level = armor.getEnchantmentLevel(Enchantment.DURABILITY);
  123. if (random.nextInt(level + 1) > 0) {
  124. lowerdamage++;
  125. }
  126. }
  127. }
  128. int newDurabilityDamage = durabilityDamage - lowerdamage;
  129. maxDurability = (short) (armor.getType().getMaxDurability() * impactMaxDamage);
  130. if (newDurabilityDamage > maxDurability) newDurabilityDamage = maxDurability;
  131. armor.setDurability((short) (armor.getDurability() + newDurabilityDamage)); //Damage armor piece
  132. }
  133. }
  134. targetPlayer.updateInventory();
  135. }
  136. }
  137. else {
  138. applyGreaterImpact(attacker, target, event); //Since mobs are technically unarmored, this will always trigger
  139. }
  140. }
  141. /**
  142. * Apply Greater Impact ability.
  143. *
  144. * @param attacker The attacking player
  145. * @param target The defending entity
  146. * @param event The event to modify
  147. */
  148. private static void applyGreaterImpact(Player attacker, LivingEntity target, EntityDamageByEntityEvent event) {
  149. if(attacker == null)
  150. return;
  151. final int GREATER_IMPACT_CHANCE = advancedConfig.getGreaterImpactChance();
  152. final double GREATER_IMPACT_MULTIPLIER = advancedConfig.getGreaterImpactModifier();
  153. final int GREATER_IMPACT_DAMAGE = advancedConfig.getGreaterImpactBonusDamage();
  154. if (!Permissions.greaterImpact(attacker)) {
  155. return;
  156. }
  157. int randomChance = 100;
  158. if (Permissions.luckyAxes(attacker)) {
  159. randomChance = (int) (randomChance * 0.75);
  160. }
  161. if (random.nextInt(randomChance) <= GREATER_IMPACT_CHANCE) {
  162. event.setDamage(event.getDamage() + GREATER_IMPACT_DAMAGE);
  163. target.setVelocity(attacker.getLocation().getDirection().normalize().multiply(GREATER_IMPACT_MULTIPLIER));
  164. attacker.sendMessage(LocaleLoader.getString("Axes.Combat.GI.Proc"));
  165. }
  166. }
  167. /**
  168. * Check if a player has armor.
  169. *
  170. * @param player Player whose armor to check
  171. * @return true if the player has armor, false otherwise
  172. */
  173. private static boolean hasArmor(Player player) {
  174. if(player == null)
  175. return false;
  176. PlayerInventory inventory = player.getInventory();
  177. if (inventory.getBoots() != null || inventory.getChestplate() != null || inventory.getHelmet() != null || inventory.getLeggings() != null) {
  178. return true;
  179. }
  180. else {
  181. return false;
  182. }
  183. }
  184. }