Axes.java 5.5 KB

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