Axes.java 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. package com.gmail.nossr50.skills.combat;
  2. import java.util.Random;
  3. import org.bukkit.entity.AnimalTamer;
  4. import org.bukkit.entity.Entity;
  5. import org.bukkit.entity.LivingEntity;
  6. import org.bukkit.entity.Player;
  7. import org.bukkit.entity.Tameable;
  8. import org.bukkit.event.entity.EntityDamageByEntityEvent;
  9. import org.bukkit.inventory.ItemStack;
  10. import org.bukkit.inventory.PlayerInventory;
  11. import com.gmail.nossr50.datatypes.PlayerProfile;
  12. import com.gmail.nossr50.datatypes.SkillType;
  13. import com.gmail.nossr50.locale.LocaleLoader;
  14. import com.gmail.nossr50.party.PartyManager;
  15. import com.gmail.nossr50.util.Misc;
  16. import com.gmail.nossr50.util.Permissions;
  17. import com.gmail.nossr50.util.Users;
  18. public class Axes {
  19. private static Random random = new Random();
  20. /**
  21. * Apply bonus to damage done by axes.
  22. *
  23. * @param attacker The attacking player
  24. * @param event The event to modify
  25. */
  26. public static void axesBonus(Player attacker, EntityDamageByEntityEvent event) {
  27. final int MAX_BONUS = 4;
  28. /* Add 1 DMG for every 50 skill levels */
  29. int bonus = Users.getProfile(attacker).getSkillLevel(SkillType.AXES) / 50;
  30. if (bonus > MAX_BONUS) {
  31. bonus = MAX_BONUS;
  32. }
  33. event.setDamage(event.getDamage() + bonus);
  34. }
  35. /**
  36. * Check for critical chances on axe damage.
  37. *
  38. * @param attacker The attacking player
  39. * @param event The event to modify
  40. */
  41. public static void axeCriticalCheck(Player attacker, EntityDamageByEntityEvent event) {
  42. Entity entity = event.getEntity();
  43. if (entity instanceof Tameable) {
  44. Tameable pet = (Tameable) entity;
  45. if (pet.isTamed()) {
  46. AnimalTamer tamer = pet.getOwner();
  47. if (tamer instanceof Player) {
  48. Player owner = (Player) tamer;
  49. if (owner == attacker || PartyManager.getInstance().inSameParty(attacker, owner)) {
  50. return;
  51. }
  52. }
  53. }
  54. }
  55. final int MAX_BONUS_LEVEL = 750;
  56. final double PVP_MODIFIER = 1.5;
  57. final int PVE_MODIFIER = 2;
  58. PlayerProfile attackerProfile = Users.getProfile(attacker);
  59. int skillLevel = attackerProfile.getSkillLevel(SkillType.AXES);
  60. int skillCheck = Misc.skillCheck(skillLevel, MAX_BONUS_LEVEL);
  61. int randomChance = 2000;
  62. if (attacker.hasPermission("mcmmo.perks.lucky.axes")) {
  63. randomChance = (int) (randomChance * 0.75);
  64. }
  65. if (random.nextInt(randomChance) <= skillCheck && !entity.isDead()){
  66. int damage = event.getDamage();
  67. if (entity instanceof Player){
  68. event.setDamage((int) (damage * PVP_MODIFIER));
  69. ((Player) entity).sendMessage(LocaleLoader.getString("Axes.Combat.CritStruck"));
  70. }
  71. else {
  72. event.setDamage(damage * PVE_MODIFIER);
  73. }
  74. attacker.sendMessage(LocaleLoader.getString("Axes.Combat.CriticalHit"));
  75. }
  76. }
  77. /**
  78. * Check for Impact ability.
  79. *
  80. * @param attacker The attacking player
  81. * @param target The defending entity
  82. * @param event The event to modify
  83. */
  84. public static void impact(Player attacker, LivingEntity target, EntityDamageByEntityEvent event) {
  85. /*
  86. * TODO: Finish this skill. The idea is you will greatly damage an opponents armor.
  87. * When they are unarmored, you have a proc that will stun them and deal additional damage.
  88. */
  89. if (target instanceof Player) {
  90. Player targetPlayer = (Player) target;
  91. short durabilityDamage = 5; //Start with 5 durability damage
  92. /* Every 30 Skill Levels you gain 1 durability damage */
  93. durabilityDamage += Users.getProfile(attacker).getSkillLevel(SkillType.AXES)/30;
  94. if (!hasArmor(targetPlayer)) {
  95. applyGreaterImpact(attacker, target, event);
  96. }
  97. else {
  98. for (ItemStack armor : targetPlayer.getInventory().getArmorContents()) {
  99. armor.setDurability((short) (armor.getDurability() + durabilityDamage)); //Damage armor piece
  100. }
  101. targetPlayer.updateInventory();
  102. }
  103. }
  104. else {
  105. applyGreaterImpact(attacker, target, event); //Since mobs are technically unarmored, this will always trigger
  106. }
  107. }
  108. /**
  109. * Apply Greater Impact ability.
  110. *
  111. * @param attacker The attacking player
  112. * @param target The defending entity
  113. * @param event The event to modify
  114. */
  115. private static void applyGreaterImpact(Player attacker, LivingEntity target, EntityDamageByEntityEvent event) {
  116. final int GREATER_IMPACT_CHANCE = 25;
  117. final double GREATER_IMPACT_MULTIPLIER = 1.5;
  118. if (!Permissions.getInstance().greaterImpact(attacker)) {
  119. return;
  120. }
  121. int randomChance = 100;
  122. if (attacker.hasPermission("mcmmo.perks.lucky.axes")) {
  123. randomChance = (int) (randomChance * 0.75);
  124. }
  125. if (random.nextInt(randomChance) <= GREATER_IMPACT_CHANCE) {
  126. event.setDamage(event.getDamage() + 2);
  127. target.setVelocity(attacker.getLocation().getDirection().normalize().multiply(GREATER_IMPACT_MULTIPLIER));
  128. attacker.sendMessage(LocaleLoader.getString("Axes.Combat.GI.Proc"));
  129. }
  130. }
  131. /**
  132. * Check if a player has armor.
  133. *
  134. * @param player Player whose armor to check
  135. * @return true if the player has armor, false otherwise
  136. */
  137. private static boolean hasArmor(Player player) {
  138. PlayerInventory inventory = player.getInventory();
  139. if (inventory.getBoots() != null || inventory.getChestplate() != null || inventory.getHelmet() != null || inventory.getLeggings() != null) {
  140. return true;
  141. }
  142. else {
  143. return false;
  144. }
  145. }
  146. }