BlastMining.java 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  1. package com.gmail.nossr50.skills;
  2. import java.util.ArrayList;
  3. import java.util.HashSet;
  4. import java.util.Iterator;
  5. import java.util.List;
  6. import org.bukkit.ChatColor;
  7. import org.bukkit.Material;
  8. import org.bukkit.block.Block;
  9. import org.bukkit.entity.Player;
  10. import org.bukkit.entity.TNTPrimed;
  11. import org.bukkit.event.entity.EntityDamageEvent;
  12. import org.bukkit.event.entity.EntityExplodeEvent;
  13. import org.bukkit.event.entity.ExplosionPrimeEvent;
  14. import com.gmail.nossr50.BlockChecks;
  15. import com.gmail.nossr50.Users;
  16. import com.gmail.nossr50.m;
  17. import com.gmail.nossr50.mcMMO;
  18. import com.gmail.nossr50.datatypes.AbilityType;
  19. import com.gmail.nossr50.datatypes.PlayerProfile;
  20. import com.gmail.nossr50.datatypes.SkillType;
  21. import com.gmail.nossr50.locale.mcLocale;
  22. public class BlastMining {
  23. /**
  24. * Handler for what blocks drop from the explosion.
  25. *
  26. * @param ores List of ore blocks destroyed by the explosion
  27. * @param debris List of non-ore blocks destroyed by the explosion
  28. * @param yield Percentage of blocks to drop
  29. * @param oreBonus Percentage bonus for ore drops
  30. * @param debrisReduction Percentage reduction for non-ore drops
  31. * @param extraDrops Number of times to drop each block
  32. * @return A list of blocks dropped from the explosion
  33. */
  34. private static List<Block> explosionYields(List<Block> ores, List<Block> debris, float yield, float oreBonus, float debrisReduction, int extraDrops) {
  35. Iterator<Block> iterator2 = ores.iterator();
  36. List<Block> blocksDropped = new ArrayList<Block>();
  37. while (iterator2.hasNext()) {
  38. Block temp = iterator2.next();
  39. if ((float) Math.random() < (yield + oreBonus)) {
  40. blocksDropped.add(temp);
  41. Mining.miningDrops(temp);
  42. if (!temp.hasMetadata("mcmmoPlacedBlock")) {
  43. if (extraDrops == 2) {
  44. blocksDropped.add(temp);
  45. Mining.miningDrops(temp);
  46. }
  47. if (extraDrops == 3) {
  48. blocksDropped.add(temp);
  49. Mining.miningDrops(temp);
  50. }
  51. }
  52. }
  53. }
  54. if (yield - debrisReduction != 0) {
  55. Iterator<Block> iterator3 = debris.iterator();
  56. while (iterator3.hasNext()) {
  57. Block temp = iterator3.next();
  58. if ((float) Math.random() < (yield - debrisReduction))
  59. Mining.miningDrops(temp);
  60. }
  61. }
  62. return blocksDropped;
  63. }
  64. /**
  65. * Handler for explosion drops and XP gain.
  66. *
  67. * @param player Player triggering the explosion
  68. * @param event Event whose explosion is being processed
  69. */
  70. public static void dropProcessing(Player player, EntityExplodeEvent event) {
  71. final int RANK_1_LEVEL = 125;
  72. final int RANK_2_LEVEL = 250;
  73. final int RANK_3_LEVEL = 375;
  74. final int RANK_4_LEVEL = 500;
  75. final int RANK_5_LEVEL = 625;
  76. final int RANK_6_LEVEL = 750;
  77. final int RANK_7_LEVEL = 875;
  78. final int RANK_8_LEVEL = 1000;
  79. int skillLevel = Users.getProfile(player).getSkillLevel(SkillType.MINING);
  80. float yield = event.getYield();
  81. List<Block> blocks = event.blockList();
  82. Iterator<Block> iterator = blocks.iterator();
  83. List<Block> ores = new ArrayList<Block>();
  84. List<Block> debris = new ArrayList<Block>();
  85. List<Block> xp = new ArrayList<Block>();
  86. while (iterator.hasNext()) {
  87. Block temp = iterator.next();
  88. if (BlockChecks.isOre(temp.getType())) {
  89. ores.add(temp);
  90. }
  91. else {
  92. debris.add(temp);
  93. }
  94. }
  95. //Normal explosion
  96. if (skillLevel < RANK_1_LEVEL) {
  97. return;
  98. }
  99. event.setYield(0);
  100. //Triple Drops, No debris, +70% ores
  101. if (skillLevel >= RANK_8_LEVEL) {
  102. xp = explosionYields(ores, debris, yield, .70f, .30f, 3);
  103. }
  104. //Triple Drops, No debris, +65% ores
  105. else if (skillLevel >= RANK_7_LEVEL) {
  106. xp = explosionYields(ores, debris, yield, .65f, .30f, 3);
  107. }
  108. //Double Drops, No Debris, +60% ores
  109. else if (skillLevel >= RANK_6_LEVEL) {
  110. xp = explosionYields(ores, debris, yield, .60f, .30f, 2);
  111. }
  112. //Double Drops, No Debris, +55% ores
  113. else if (skillLevel >= RANK_5_LEVEL) {
  114. xp = explosionYields(ores, debris, yield, .55f, .30f, 2);
  115. }
  116. //No debris, +50% ores
  117. else if (skillLevel >= RANK_4_LEVEL) {
  118. xp = explosionYields(ores, debris, yield, .50f, .30f, 1);
  119. }
  120. //No debris, +45% ores
  121. else if (skillLevel >= RANK_3_LEVEL) {
  122. xp = explosionYields(ores, debris, yield, .45f, .30f, 1);
  123. }
  124. //+40% ores, -20% debris
  125. else if (skillLevel >= RANK_2_LEVEL) {
  126. xp = explosionYields(ores, debris, yield, .40f, .20f, 1);
  127. }
  128. //+35% ores, -10% debris
  129. else if (skillLevel >= RANK_1_LEVEL) {
  130. xp = explosionYields(ores, debris, yield, .35f, .10f, 1);
  131. }
  132. for (Block block : xp) {
  133. if (!block.hasMetadata("mcmmoPlacedBlock")) {
  134. Mining.miningXP(player, block);
  135. }
  136. }
  137. }
  138. /**
  139. * Increases the blast radius of the explosion.
  140. *
  141. * @param player Player triggering the explosion
  142. * @param event Event whose explosion radius is being changed
  143. */
  144. public static void biggerBombs(Player player, ExplosionPrimeEvent event) {
  145. final int RANK_1_LEVEL = 250;
  146. final int RANK_2_LEVEL = 500;
  147. final int RANK_3_LEVEL = 750;
  148. final int RANK_4_LEVEL = 1000;
  149. int skillLevel = Users.getProfile(player).getSkillLevel(SkillType.MINING);
  150. float radius = event.getRadius();
  151. if (skillLevel < RANK_1_LEVEL) {
  152. return;
  153. }
  154. if (skillLevel >= RANK_1_LEVEL) {
  155. radius++;
  156. }
  157. if (skillLevel >= RANK_2_LEVEL) {
  158. radius++;
  159. }
  160. if (skillLevel >= RANK_3_LEVEL) {
  161. radius++;
  162. }
  163. if (skillLevel >= RANK_4_LEVEL) {
  164. radius++;
  165. }
  166. event.setRadius(radius);
  167. }
  168. /**
  169. * Decreases damage dealt by the explosion.
  170. *
  171. * @param player Player triggering the explosion
  172. * @param event Event whose explosion damage is being reduced
  173. */
  174. public static void demolitionsExpertise(Player player, EntityDamageEvent event) {
  175. final int RANK_1_LEVEL = 500;
  176. final int RANK_2_LEVEL = 750;
  177. final int RANK_3_LEVEL = 1000;
  178. int skill = Users.getProfile(player).getSkillLevel(SkillType.MINING);
  179. int damage = event.getDamage();
  180. if (skill < RANK_1_LEVEL) {
  181. return;
  182. }
  183. if (skill >= RANK_3_LEVEL) {
  184. damage = 0;
  185. }
  186. else if (skill >= RANK_2_LEVEL) {
  187. damage = damage / 2;
  188. }
  189. else if (skill >= RANK_1_LEVEL) {
  190. damage = damage/4;
  191. }
  192. event.setDamage(damage);
  193. }
  194. /**
  195. * Remotely detonate TNT for Blast Mining.
  196. *
  197. * @param player Player detonating the TNT
  198. * @param plugin mcMMO plugin instance
  199. */
  200. public static void remoteDetonation(Player player, mcMMO plugin) {
  201. final byte SNOW = 78;
  202. final byte AIR = 0;
  203. final int BLOCKS_AWAY = 100;
  204. final int TIME_CONVERSION_FACTOR = 1000;
  205. PlayerProfile PP = Users.getProfile(player);
  206. HashSet<Byte> transparent = new HashSet<Byte>();
  207. transparent.add(SNOW);
  208. transparent.add(AIR);
  209. Block block = player.getTargetBlock(transparent, BLOCKS_AWAY);
  210. if (block.getType().equals(Material.TNT) && m.blockBreakSimulate(block, player, true) && PP.getSkillLevel(SkillType.MINING) >= 125) {
  211. final int MAX_DISTANCE_AWAY = 10;
  212. AbilityType ability = AbilityType.BLAST_MINING;
  213. /* Check Cooldown */
  214. if(!Skills.cooldownOver(PP.getSkillDATS(ability) * TIME_CONVERSION_FACTOR, ability.getCooldown())) {
  215. player.sendMessage(mcLocale.getString("Skills.TooTired") + ChatColor.YELLOW + " (" + Skills.calculateTimeLeft(PP.getSkillDATS(ability) * TIME_CONVERSION_FACTOR, ability.getCooldown()) + "s)");
  216. return;
  217. }
  218. /* Send message to nearby players */
  219. for(Player y : player.getWorld().getPlayers()) {
  220. if(y != player && m.isNear(player.getLocation(), y.getLocation(), MAX_DISTANCE_AWAY)) {
  221. y.sendMessage(ability.getAbilityPlayer(player));
  222. }
  223. }
  224. player.sendMessage(mcLocale.getString("BlastMining.Boom"));
  225. /* Create the TNT entity */
  226. TNTPrimed tnt = player.getWorld().spawn(block.getLocation(), TNTPrimed.class);
  227. plugin.misc.tntTracker.put(tnt.getEntityId(), player);
  228. block.setType(Material.AIR);
  229. tnt.setFuseTicks(0);
  230. PP.setSkillDATS(ability, System.currentTimeMillis()); //Save DATS for Blast Mining
  231. PP.setBlastMiningInformed(false);
  232. }
  233. }
  234. }