2012-02-07 07:37:41 +01:00
|
|
|
package com.gmail.nossr50.skills;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
2012-03-11 04:21:53 +01:00
|
|
|
import java.util.HashSet;
|
2012-02-07 07:37:41 +01:00
|
|
|
import java.util.Iterator;
|
|
|
|
import java.util.List;
|
2012-03-26 17:04:17 +02:00
|
|
|
import java.util.Random;
|
2012-02-07 07:37:41 +01:00
|
|
|
|
2012-03-11 04:21:53 +01:00
|
|
|
import org.bukkit.ChatColor;
|
|
|
|
import org.bukkit.Material;
|
2012-02-07 07:37:41 +01:00
|
|
|
import org.bukkit.block.Block;
|
2012-03-01 22:50:39 +01:00
|
|
|
import org.bukkit.entity.Player;
|
2012-03-11 04:21:53 +01:00
|
|
|
import org.bukkit.entity.TNTPrimed;
|
2012-02-07 07:37:41 +01:00
|
|
|
import org.bukkit.event.entity.EntityDamageEvent;
|
|
|
|
import org.bukkit.event.entity.EntityExplodeEvent;
|
|
|
|
import org.bukkit.event.entity.ExplosionPrimeEvent;
|
2012-03-01 22:50:39 +01:00
|
|
|
|
2012-02-07 07:37:41 +01:00
|
|
|
import com.gmail.nossr50.mcMMO;
|
2012-03-11 04:21:53 +01:00
|
|
|
import com.gmail.nossr50.datatypes.AbilityType;
|
|
|
|
import com.gmail.nossr50.datatypes.PlayerProfile;
|
2012-03-01 22:50:39 +01:00
|
|
|
import com.gmail.nossr50.datatypes.SkillType;
|
2012-04-27 11:47:11 +02:00
|
|
|
import com.gmail.nossr50.locale.LocaleLoader;
|
|
|
|
import com.gmail.nossr50.util.BlockChecks;
|
|
|
|
import com.gmail.nossr50.util.Misc;
|
|
|
|
import com.gmail.nossr50.util.Users;
|
2012-02-07 07:37:41 +01:00
|
|
|
|
2012-03-12 22:28:13 +01:00
|
|
|
public class BlastMining {
|
|
|
|
|
2012-03-26 17:04:17 +02:00
|
|
|
private static Random random = new Random();
|
|
|
|
|
2012-03-12 22:28:13 +01:00
|
|
|
/**
|
|
|
|
* Handler for what blocks drop from the explosion.
|
|
|
|
*
|
|
|
|
* @param ores List of ore blocks destroyed by the explosion
|
|
|
|
* @param debris List of non-ore blocks destroyed by the explosion
|
|
|
|
* @param yield Percentage of blocks to drop
|
|
|
|
* @param oreBonus Percentage bonus for ore drops
|
|
|
|
* @param debrisReduction Percentage reduction for non-ore drops
|
|
|
|
* @param extraDrops Number of times to drop each block
|
|
|
|
* @return A list of blocks dropped from the explosion
|
|
|
|
*/
|
2012-03-15 22:29:27 +01:00
|
|
|
private static List<Block> explosionYields(List<Block> ores, List<Block> debris, float yield, float oreBonus, float debrisReduction, int extraDrops) {
|
2012-03-12 22:28:13 +01:00
|
|
|
Iterator<Block> iterator2 = ores.iterator();
|
|
|
|
List<Block> blocksDropped = new ArrayList<Block>();
|
|
|
|
|
|
|
|
while (iterator2.hasNext()) {
|
|
|
|
Block temp = iterator2.next();
|
|
|
|
|
2012-03-26 17:04:17 +02:00
|
|
|
if (random.nextFloat() < (yield + oreBonus)) {
|
2012-03-12 22:28:13 +01:00
|
|
|
blocksDropped.add(temp);
|
|
|
|
Mining.miningDrops(temp);
|
|
|
|
|
2012-03-15 05:52:37 +01:00
|
|
|
if (!temp.hasMetadata("mcmmoPlacedBlock")) {
|
2012-03-12 22:28:13 +01:00
|
|
|
if (extraDrops == 2) {
|
|
|
|
blocksDropped.add(temp);
|
|
|
|
Mining.miningDrops(temp);
|
|
|
|
}
|
|
|
|
if (extraDrops == 3) {
|
|
|
|
blocksDropped.add(temp);
|
|
|
|
Mining.miningDrops(temp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (yield - debrisReduction != 0) {
|
|
|
|
Iterator<Block> iterator3 = debris.iterator();
|
|
|
|
|
|
|
|
while (iterator3.hasNext()) {
|
|
|
|
Block temp = iterator3.next();
|
|
|
|
|
2012-03-26 17:04:17 +02:00
|
|
|
if (random.nextFloat() < (yield - debrisReduction))
|
2012-03-12 22:28:13 +01:00
|
|
|
Mining.miningDrops(temp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return blocksDropped;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handler for explosion drops and XP gain.
|
|
|
|
*
|
|
|
|
* @param player Player triggering the explosion
|
|
|
|
* @param event Event whose explosion is being processed
|
|
|
|
*/
|
2012-03-15 22:29:27 +01:00
|
|
|
public static void dropProcessing(Player player, EntityExplodeEvent event) {
|
2012-03-12 22:28:13 +01:00
|
|
|
final int RANK_1_LEVEL = 125;
|
|
|
|
final int RANK_2_LEVEL = 250;
|
|
|
|
final int RANK_3_LEVEL = 375;
|
|
|
|
final int RANK_4_LEVEL = 500;
|
|
|
|
final int RANK_5_LEVEL = 625;
|
|
|
|
final int RANK_6_LEVEL = 750;
|
|
|
|
final int RANK_7_LEVEL = 875;
|
|
|
|
final int RANK_8_LEVEL = 1000;
|
|
|
|
|
|
|
|
int skillLevel = Users.getProfile(player).getSkillLevel(SkillType.MINING);
|
|
|
|
float yield = event.getYield();
|
|
|
|
List<Block> blocks = event.blockList();
|
|
|
|
Iterator<Block> iterator = blocks.iterator();
|
|
|
|
|
|
|
|
List<Block> ores = new ArrayList<Block>();
|
|
|
|
List<Block> debris = new ArrayList<Block>();
|
|
|
|
List<Block> xp = new ArrayList<Block>();
|
|
|
|
|
|
|
|
while (iterator.hasNext()) {
|
|
|
|
Block temp = iterator.next();
|
|
|
|
|
|
|
|
if (BlockChecks.isOre(temp.getType())) {
|
|
|
|
ores.add(temp);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
debris.add(temp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//Normal explosion
|
|
|
|
if (skillLevel < RANK_1_LEVEL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
event.setYield(0);
|
|
|
|
|
|
|
|
//Triple Drops, No debris, +70% ores
|
|
|
|
if (skillLevel >= RANK_8_LEVEL) {
|
2012-03-15 22:29:27 +01:00
|
|
|
xp = explosionYields(ores, debris, yield, .70f, .30f, 3);
|
2012-03-12 22:28:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//Triple Drops, No debris, +65% ores
|
|
|
|
else if (skillLevel >= RANK_7_LEVEL) {
|
2012-03-15 22:29:27 +01:00
|
|
|
xp = explosionYields(ores, debris, yield, .65f, .30f, 3);
|
2012-03-12 22:28:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//Double Drops, No Debris, +60% ores
|
|
|
|
else if (skillLevel >= RANK_6_LEVEL) {
|
2012-03-15 22:29:27 +01:00
|
|
|
xp = explosionYields(ores, debris, yield, .60f, .30f, 2);
|
2012-03-12 22:28:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//Double Drops, No Debris, +55% ores
|
|
|
|
else if (skillLevel >= RANK_5_LEVEL) {
|
2012-03-15 22:29:27 +01:00
|
|
|
xp = explosionYields(ores, debris, yield, .55f, .30f, 2);
|
2012-03-12 22:28:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//No debris, +50% ores
|
|
|
|
else if (skillLevel >= RANK_4_LEVEL) {
|
2012-03-15 22:29:27 +01:00
|
|
|
xp = explosionYields(ores, debris, yield, .50f, .30f, 1);
|
2012-03-12 22:28:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//No debris, +45% ores
|
|
|
|
else if (skillLevel >= RANK_3_LEVEL) {
|
2012-03-15 22:29:27 +01:00
|
|
|
xp = explosionYields(ores, debris, yield, .45f, .30f, 1);
|
2012-03-12 22:28:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//+40% ores, -20% debris
|
|
|
|
else if (skillLevel >= RANK_2_LEVEL) {
|
2012-03-15 22:29:27 +01:00
|
|
|
xp = explosionYields(ores, debris, yield, .40f, .20f, 1);
|
2012-03-12 22:28:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
//+35% ores, -10% debris
|
|
|
|
else if (skillLevel >= RANK_1_LEVEL) {
|
2012-03-15 22:29:27 +01:00
|
|
|
xp = explosionYields(ores, debris, yield, .35f, .10f, 1);
|
2012-03-12 22:28:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
for (Block block : xp) {
|
2012-03-15 05:52:37 +01:00
|
|
|
if (!block.hasMetadata("mcmmoPlacedBlock")) {
|
2012-03-12 22:28:13 +01:00
|
|
|
Mining.miningXP(player, block);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Increases the blast radius of the explosion.
|
|
|
|
*
|
|
|
|
* @param player Player triggering the explosion
|
|
|
|
* @param event Event whose explosion radius is being changed
|
|
|
|
*/
|
|
|
|
public static void biggerBombs(Player player, ExplosionPrimeEvent event) {
|
|
|
|
final int RANK_1_LEVEL = 250;
|
|
|
|
final int RANK_2_LEVEL = 500;
|
|
|
|
final int RANK_3_LEVEL = 750;
|
|
|
|
final int RANK_4_LEVEL = 1000;
|
|
|
|
|
|
|
|
int skillLevel = Users.getProfile(player).getSkillLevel(SkillType.MINING);
|
|
|
|
float radius = event.getRadius();
|
|
|
|
|
|
|
|
if (skillLevel < RANK_1_LEVEL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (skillLevel >= RANK_1_LEVEL) {
|
|
|
|
radius++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (skillLevel >= RANK_2_LEVEL) {
|
|
|
|
radius++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (skillLevel >= RANK_3_LEVEL) {
|
|
|
|
radius++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (skillLevel >= RANK_4_LEVEL) {
|
|
|
|
radius++;
|
|
|
|
}
|
|
|
|
|
|
|
|
event.setRadius(radius);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Decreases damage dealt by the explosion.
|
|
|
|
*
|
|
|
|
* @param player Player triggering the explosion
|
|
|
|
* @param event Event whose explosion damage is being reduced
|
|
|
|
*/
|
|
|
|
public static void demolitionsExpertise(Player player, EntityDamageEvent event) {
|
|
|
|
final int RANK_1_LEVEL = 500;
|
|
|
|
final int RANK_2_LEVEL = 750;
|
|
|
|
final int RANK_3_LEVEL = 1000;
|
|
|
|
|
|
|
|
int skill = Users.getProfile(player).getSkillLevel(SkillType.MINING);
|
|
|
|
int damage = event.getDamage();
|
|
|
|
|
|
|
|
if (skill < RANK_1_LEVEL) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (skill >= RANK_3_LEVEL) {
|
|
|
|
damage = 0;
|
|
|
|
}
|
|
|
|
else if (skill >= RANK_2_LEVEL) {
|
|
|
|
damage = damage / 2;
|
|
|
|
}
|
|
|
|
else if (skill >= RANK_1_LEVEL) {
|
|
|
|
damage = damage/4;
|
|
|
|
}
|
|
|
|
|
|
|
|
event.setDamage(damage);
|
|
|
|
}
|
2012-02-07 07:37:41 +01:00
|
|
|
|
2012-03-20 03:05:17 +01:00
|
|
|
/**
|
|
|
|
* Remotely detonate TNT for Blast Mining.
|
|
|
|
*
|
|
|
|
* @param player Player detonating the TNT
|
|
|
|
* @param plugin mcMMO plugin instance
|
|
|
|
*/
|
2012-03-11 04:21:53 +01:00
|
|
|
public static void remoteDetonation(Player player, mcMMO plugin) {
|
2012-03-12 22:28:13 +01:00
|
|
|
final byte SNOW = 78;
|
|
|
|
final byte AIR = 0;
|
|
|
|
final int BLOCKS_AWAY = 100;
|
2012-03-13 19:09:32 +01:00
|
|
|
final int TIME_CONVERSION_FACTOR = 1000;
|
2012-03-12 22:28:13 +01:00
|
|
|
|
2012-03-11 04:21:53 +01:00
|
|
|
PlayerProfile PP = Users.getProfile(player);
|
|
|
|
HashSet<Byte> transparent = new HashSet<Byte>();
|
|
|
|
|
2012-03-12 22:28:13 +01:00
|
|
|
transparent.add(SNOW);
|
|
|
|
transparent.add(AIR);
|
2012-03-11 04:21:53 +01:00
|
|
|
|
2012-03-12 22:28:13 +01:00
|
|
|
Block block = player.getTargetBlock(transparent, BLOCKS_AWAY);
|
2012-03-11 04:21:53 +01:00
|
|
|
|
2012-04-27 11:47:11 +02:00
|
|
|
if (block.getType().equals(Material.TNT) && Misc.blockBreakSimulate(block, player, true) && PP.getSkillLevel(SkillType.MINING) >= 125) {
|
2012-03-29 20:24:41 +02:00
|
|
|
final double MAX_DISTANCE_AWAY = 10.0;
|
2012-03-11 04:21:53 +01:00
|
|
|
AbilityType ability = AbilityType.BLAST_MINING;
|
|
|
|
|
|
|
|
/* Check Cooldown */
|
2012-03-13 19:09:32 +01:00
|
|
|
if(!Skills.cooldownOver(PP.getSkillDATS(ability) * TIME_CONVERSION_FACTOR, ability.getCooldown())) {
|
2012-04-27 11:47:11 +02:00
|
|
|
player.sendMessage(LocaleLoader.getString("Skills.TooTired") + ChatColor.YELLOW + " (" + Skills.calculateTimeLeft(PP.getSkillDATS(ability) * TIME_CONVERSION_FACTOR, ability.getCooldown()) + "s)");
|
2012-03-11 04:21:53 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Send message to nearby players */
|
|
|
|
for(Player y : player.getWorld().getPlayers()) {
|
2012-04-27 11:47:11 +02:00
|
|
|
if(y != player && Misc.isNear(player.getLocation(), y.getLocation(), MAX_DISTANCE_AWAY)) {
|
2012-03-11 04:21:53 +01:00
|
|
|
y.sendMessage(ability.getAbilityPlayer(player));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-04-27 11:47:11 +02:00
|
|
|
player.sendMessage(LocaleLoader.getString("Mining.Blast.Boom"));
|
2012-03-11 04:21:53 +01:00
|
|
|
|
|
|
|
/* Create the TNT entity */
|
2012-03-12 22:28:13 +01:00
|
|
|
TNTPrimed tnt = player.getWorld().spawn(block.getLocation(), TNTPrimed.class);
|
2012-03-20 23:36:47 +01:00
|
|
|
plugin.tntTracker.put(tnt.getEntityId(), player);
|
2012-03-12 22:28:13 +01:00
|
|
|
block.setType(Material.AIR);
|
2012-03-11 04:21:53 +01:00
|
|
|
tnt.setFuseTicks(0);
|
|
|
|
|
|
|
|
PP.setSkillDATS(ability, System.currentTimeMillis()); //Save DATS for Blast Mining
|
2012-03-27 08:33:35 +02:00
|
|
|
PP.setAbilityInformed(ability, false);
|
2012-03-11 04:21:53 +01:00
|
|
|
}
|
|
|
|
}
|
2012-03-06 07:48:45 +01:00
|
|
|
}
|