Archery.java 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. package com.gmail.nossr50.skills;
  2. import java.util.Random;
  3. import org.bukkit.Location;
  4. import org.bukkit.Material;
  5. import org.bukkit.entity.Entity;
  6. import org.bukkit.entity.Player;
  7. import org.bukkit.inventory.ItemStack;
  8. import com.gmail.nossr50.Users;
  9. import com.gmail.nossr50.m;
  10. import com.gmail.nossr50.mcMMO;
  11. import com.gmail.nossr50.mcPermissions;
  12. import com.gmail.nossr50.datatypes.PlayerProfile;
  13. import com.gmail.nossr50.datatypes.SkillType;
  14. import com.gmail.nossr50.locale.mcLocale;
  15. import com.gmail.nossr50.party.Party;
  16. public class Archery {
  17. private static Random random = new Random();
  18. /**
  19. * Track arrows fired for later retrieval.
  20. *
  21. * @param plugin mcMMO plugin instance
  22. * @param entity Entity damaged by the arrow
  23. * @param PPa PlayerProfile of the player firing the arrow
  24. */
  25. public static void trackArrows(mcMMO plugin, Entity entity, PlayerProfile PPa) {
  26. final int MAX_BONUS_LEVEL = 1000;
  27. int skillLevel = PPa.getSkillLevel(SkillType.ARCHERY);
  28. if (!plugin.arrowTracker.containsKey(entity)) {
  29. plugin.arrowTracker.put(entity, 0);
  30. }
  31. if (skillLevel > MAX_BONUS_LEVEL || (random.nextInt(1000) <= skillLevel)) {
  32. plugin.arrowTracker.put(entity, 1);
  33. }
  34. }
  35. /**
  36. * Check for ignition on arrow hit.
  37. *
  38. * @param entity Entity damaged by the arrow
  39. * @param attacker Player who fired the arrow
  40. */
  41. public static void ignitionCheck(Entity entity, Player attacker) {
  42. //Check to see if PVP for this world is disabled before executing
  43. if (!entity.getWorld().getPVP()) {
  44. return;
  45. }
  46. final int IGNITION_CHANCE = 25;
  47. final int MAX_IGNITION_TICKS = 120;
  48. PlayerProfile PPa = Users.getProfile(attacker);
  49. if (random.nextInt(100) <= IGNITION_CHANCE) {
  50. int ignition = 20;
  51. /* Add 20 ticks for every 200 skill levels */
  52. ignition += (PPa.getSkillLevel(SkillType.ARCHERY) / 200) * 20;
  53. if (ignition > MAX_IGNITION_TICKS) {
  54. ignition = MAX_IGNITION_TICKS;
  55. }
  56. if (entity instanceof Player) {
  57. Player defender = (Player) entity;
  58. if (!Party.getInstance().inSameParty(attacker, defender)) {
  59. defender.setFireTicks(defender.getFireTicks() + ignition);
  60. attacker.sendMessage(mcLocale.getString("Combat.Ignition"));
  61. defender.sendMessage(mcLocale.getString("Combat.BurningArrowHit"));
  62. }
  63. }
  64. else {
  65. entity.setFireTicks(entity.getFireTicks() + ignition);
  66. attacker.sendMessage(mcLocale.getString("Combat.Ignition"));
  67. }
  68. }
  69. }
  70. /**
  71. * Check for Daze.
  72. *
  73. * @param defender Defending player
  74. * @param attacker Attacking player
  75. */
  76. public static void dazeCheck(Player defender, Player attacker) {
  77. final int MAX_BONUS_LEVEL = 1000;
  78. int skillLevel = Users.getProfile(attacker).getSkillLevel(SkillType.ARCHERY);
  79. Location loc = defender.getLocation();
  80. int skillCheck = m.skillCheck(skillLevel, MAX_BONUS_LEVEL);
  81. if (random.nextInt(10) > 5) {
  82. loc.setPitch(90);
  83. }
  84. else {
  85. loc.setPitch(-90);
  86. }
  87. if (random.nextInt(2000) <= skillCheck && mcPermissions.getInstance().daze(attacker)) {
  88. defender.teleport(loc);
  89. defender.sendMessage(mcLocale.getString("Combat.TouchedFuzzy"));
  90. attacker.sendMessage(mcLocale.getString("Combat.TargetDazed"));
  91. }
  92. }
  93. /**
  94. * Check for arrow retrieval.
  95. *
  96. * @param entity The entity hit by the arrows
  97. * @param plugin mcMMO plugin instance
  98. */
  99. public static void arrowRetrievalCheck(Entity entity, mcMMO plugin) {
  100. if (plugin.arrowTracker.containsKey(entity)) {
  101. m.mcDropItems(entity.getLocation(), new ItemStack(Material.ARROW), plugin.arrowTracker.get(entity));
  102. }
  103. plugin.arrowTracker.remove(entity);
  104. }
  105. }