Restructuring Blast Mining.

This commit is contained in:
gmcferrin 2013-01-09 19:45:34 -05:00
parent 39e9e426ef
commit 1839f6ce8c
8 changed files with 324 additions and 247 deletions

View File

@ -204,14 +204,14 @@ public class BlockListener implements Listener {
/* MINING */ /* MINING */
else if (BlockChecks.canBeSuperBroken(block) && Permissions.mining(player)) { else if (BlockChecks.canBeSuperBroken(block) && Permissions.mining(player)) {
MiningManager manager = new MiningManager(player); MiningManager miningManager = new MiningManager(player);
if (configInstance.getMiningRequiresTool()) { if (configInstance.getMiningRequiresTool()) {
if (ItemChecks.isPickaxe(inHand)) { if (ItemChecks.isPickaxe(inHand)) {
manager.miningBlockCheck(block); miningManager.miningBlockCheck(block);
} }
} }
else { else {
manager.miningBlockCheck(block); miningManager.miningBlockCheck(block);
} }
} }
@ -356,17 +356,17 @@ public class BlockListener implements Listener {
} }
} }
else if (profile.getAbilityMode(AbilityType.SUPER_BREAKER) && Skills.triggerCheck(player, block, AbilityType.SUPER_BREAKER)) { else if (profile.getAbilityMode(AbilityType.SUPER_BREAKER) && Skills.triggerCheck(player, block, AbilityType.SUPER_BREAKER)) {
MiningManager manager = new MiningManager(player); MiningManager miningManager = new MiningManager(player);
if (configInstance.getMiningRequiresTool()) { if (configInstance.getMiningRequiresTool()) {
if (ItemChecks.isPickaxe(inHand)) { if (ItemChecks.isPickaxe(inHand)) {
event.setInstaBreak(true); event.setInstaBreak(true);
manager.superBreakerBlockCheck(block); miningManager.superBreakerBlockCheck(block);
} }
} }
else { else {
event.setInstaBreak(true); event.setInstaBreak(true);
manager.superBreakerBlockCheck(block); miningManager.superBreakerBlockCheck(block);
} }
} }
else if (profile.getSkillLevel(SkillType.WOODCUTTING) >= LEAF_BLOWER_LEVEL && (material.equals(Material.LEAVES) || (configInstance.getBlockModsEnabled() && ModChecks.isCustomLeafBlock(block)))) { else if (profile.getSkillLevel(SkillType.WOODCUTTING) >= LEAF_BLOWER_LEVEL && (material.equals(Material.LEAVES) || (configInstance.getBlockModsEnabled() && ModChecks.isCustomLeafBlock(block)))) {

View File

@ -35,7 +35,7 @@ import com.gmail.nossr50.party.PartyManager;
import com.gmail.nossr50.runnables.BleedTimer; import com.gmail.nossr50.runnables.BleedTimer;
import com.gmail.nossr50.skills.acrobatics.AcrobaticsManager; import com.gmail.nossr50.skills.acrobatics.AcrobaticsManager;
import com.gmail.nossr50.skills.archery.Archery; import com.gmail.nossr50.skills.archery.Archery;
import com.gmail.nossr50.skills.mining.BlastMining; import com.gmail.nossr50.skills.mining.MiningManager;
import com.gmail.nossr50.skills.taming.TamingManager; import com.gmail.nossr50.skills.taming.TamingManager;
import com.gmail.nossr50.util.Combat; import com.gmail.nossr50.util.Combat;
import com.gmail.nossr50.util.Misc; import com.gmail.nossr50.util.Misc;
@ -151,7 +151,8 @@ public class EntityListener implements Listener {
acroManager.rollCheck(event); acroManager.rollCheck(event);
} }
else if (cause == DamageCause.BLOCK_EXPLOSION && Permissions.demolitionsExpertise(player)) { else if (cause == DamageCause.BLOCK_EXPLOSION && Permissions.demolitionsExpertise(player)) {
BlastMining.demolitionsExpertise(player, event); MiningManager miningManager = new MiningManager(player);
miningManager.demolitionsExpertise(event);
} }
if (event.getDamage() >= 1) { if (event.getDamage() >= 1) {
@ -219,7 +220,8 @@ public class EntityListener implements Listener {
Player player = plugin.getTNTPlayer(id); Player player = plugin.getTNTPlayer(id);
if (Permissions.biggerBombs(player)) { if (Permissions.biggerBombs(player)) {
BlastMining.biggerBombs(player, event); MiningManager miningManager = new MiningManager(player);
miningManager.biggerBombs(event);
} }
} }
} }
@ -243,7 +245,8 @@ public class EntityListener implements Listener {
if (plugin.tntIsTracked(id)) { if (plugin.tntIsTracked(id)) {
Player player = plugin.getTNTPlayer(id); Player player = plugin.getTNTPlayer(id);
BlastMining.dropProcessing(player, event); MiningManager miningManager = new MiningManager(player);
miningManager.blastMiningDropProcessing(event);
plugin.removeFromTNTTracker(id); plugin.removeFromTNTTracker(id);
} }
} }

View File

@ -0,0 +1,42 @@
package com.gmail.nossr50.skills.mining;
import org.bukkit.event.entity.ExplosionPrimeEvent;
public class BiggerBombsEventHandler {
private int skillLevel;
private ExplosionPrimeEvent event;
private float radius;
private float radiusModifier;
protected BiggerBombsEventHandler(MiningManager manager, ExplosionPrimeEvent event) {
this.skillLevel = manager.getSkillLevel();
this.event = event;
this.radius = event.getRadius();
}
protected void calculateRadiusIncrease() {
if (skillLevel < BlastMining.BLAST_MINING_RANK_2) {
return;
}
if (skillLevel >= BlastMining.BLAST_MINING_RANK_8) {
radiusModifier = 4.0f;
}
else if (skillLevel >= BlastMining.BLAST_MINING_RANK_6) {
radiusModifier = 3.0f;
}
else if (skillLevel >= BlastMining.BLAST_MINING_RANK_4) {
radiusModifier = 2.0f;
}
else if (skillLevel >= BlastMining.BLAST_MINING_RANK_2) {
radiusModifier = 1.0f;
}
}
protected void modifyBlastRadius() {
radius = radius + radiusModifier;
event.setRadius(radius);
}
}

View File

@ -1,20 +1,13 @@
package com.gmail.nossr50.skills.mining; package com.gmail.nossr50.skills.mining;
import java.util.ArrayList;
import java.util.HashSet; import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Random; import java.util.Random;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.entity.TNTPrimed; import org.bukkit.entity.TNTPrimed;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityExplodeEvent;
import org.bukkit.event.entity.ExplosionPrimeEvent;
import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.event.player.PlayerInteractEvent;
import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.mcMMO;
@ -23,240 +16,22 @@ import com.gmail.nossr50.datatypes.AbilityType;
import com.gmail.nossr50.datatypes.PlayerProfile; import com.gmail.nossr50.datatypes.PlayerProfile;
import com.gmail.nossr50.datatypes.SkillType; import com.gmail.nossr50.datatypes.SkillType;
import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.util.BlockChecks;
import com.gmail.nossr50.util.Misc; import com.gmail.nossr50.util.Misc;
import com.gmail.nossr50.util.Skills; import com.gmail.nossr50.util.Skills;
import com.gmail.nossr50.util.Users; import com.gmail.nossr50.util.Users;
public class BlastMining { public class BlastMining {
static AdvancedConfig advancedConfig = AdvancedConfig.getInstance(); private static AdvancedConfig advancedConfig = AdvancedConfig.getInstance();
private static Random random = new Random(); private static Random random = new Random();
private static int blastMiningRank1 = advancedConfig.getBlastMiningRank1(); public final static int BLAST_MINING_RANK_1 = advancedConfig.getBlastMiningRank1();
private static int blastMiningRank2 = advancedConfig.getBlastMiningRank2(); public final static int BLAST_MINING_RANK_2 = advancedConfig.getBlastMiningRank2();
private static int blastMiningRank3 = advancedConfig.getBlastMiningRank3(); public final static int BLAST_MINING_RANK_3 = advancedConfig.getBlastMiningRank3();
private static int blastMiningRank4 = advancedConfig.getBlastMiningRank4(); public final static int BLAST_MINING_RANK_4 = advancedConfig.getBlastMiningRank4();
private static int blastMiningRank5 = advancedConfig.getBlastMiningRank5(); public final static int BLAST_MINING_RANK_5 = advancedConfig.getBlastMiningRank5();
private static int blastMiningRank6 = advancedConfig.getBlastMiningRank6(); public final static int BLAST_MINING_RANK_6 = advancedConfig.getBlastMiningRank6();
private static int blastMiningRank7 = advancedConfig.getBlastMiningRank7(); public final static int BLAST_MINING_RANK_7 = advancedConfig.getBlastMiningRank7();
private static int blastMiningRank8 = advancedConfig.getBlastMiningRank8(); public final static int BLAST_MINING_RANK_8 = advancedConfig.getBlastMiningRank8();
/**
* 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
*/
private static List<Block> explosionYields(List<Block> ores, List<Block> debris, float yield, float oreBonus, float debrisReduction, int extraDrops) {
Iterator<Block> oresIterator = ores.iterator();
List<Block> blocksDropped = new ArrayList<Block>();
while (oresIterator.hasNext()) {
Block temp = oresIterator.next();
Location tempLocation = temp.getLocation();
Material tempType = temp.getType();
if (random.nextFloat() < (yield + oreBonus)) {
blocksDropped.add(temp);
Mining.miningDrops(temp, tempLocation, tempType);
if (!mcMMO.placeStore.isTrue(temp)) {
for (int i = 1 ; i < extraDrops ; i++) {
blocksDropped.add(temp);
Mining.miningDrops(temp, tempLocation, tempType);
}
}
}
}
if (yield - debrisReduction > 0) {
Iterator<Block> debrisIterator = debris.iterator();
while (debrisIterator.hasNext()) {
Block temp = debrisIterator.next();
Location tempLocation = temp.getLocation();
Material tempType = temp.getType();
if (random.nextFloat() < (yield - debrisReduction))
Mining.miningDrops(temp, tempLocation, tempType);
}
}
return blocksDropped;
}
/**
* Handler for explosion drops and XP gain.
*
* @param player Player triggering the explosion
* @param event Event whose explosion is being processed
*/
public static void dropProcessing(Player player, EntityExplodeEvent event) {
if(player == null)
return;
final int RANK_1_LEVEL = blastMiningRank1;
final int RANK_2_LEVEL = blastMiningRank2;
final int RANK_3_LEVEL = blastMiningRank3;
final int RANK_4_LEVEL = blastMiningRank4;
final int RANK_5_LEVEL = blastMiningRank5;
final int RANK_6_LEVEL = blastMiningRank6;
final int RANK_7_LEVEL = blastMiningRank7;
final int RANK_8_LEVEL = blastMiningRank8;
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)) {
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) {
xp = explosionYields(ores, debris, yield, .70f, .30f, 3);
}
//Triple Drops, No debris, +65% ores
else if (skillLevel >= RANK_7_LEVEL) {
xp = explosionYields(ores, debris, yield, .65f, .30f, 3);
}
//Double Drops, No Debris, +60% ores
else if (skillLevel >= RANK_6_LEVEL) {
xp = explosionYields(ores, debris, yield, .60f, .30f, 2);
}
//Double Drops, No Debris, +55% ores
else if (skillLevel >= RANK_5_LEVEL) {
xp = explosionYields(ores, debris, yield, .55f, .30f, 2);
}
//No debris, +50% ores
else if (skillLevel >= RANK_4_LEVEL) {
xp = explosionYields(ores, debris, yield, .50f, .30f, 1);
}
//No debris, +45% ores
else if (skillLevel >= RANK_3_LEVEL) {
xp = explosionYields(ores, debris, yield, .45f, .30f, 1);
}
//+40% ores, -20% debris
else if (skillLevel >= RANK_2_LEVEL) {
xp = explosionYields(ores, debris, yield, .40f, .20f, 1);
}
//+35% ores, -10% debris
else if (skillLevel >= RANK_1_LEVEL) {
xp = explosionYields(ores, debris, yield, .35f, .10f, 1);
}
for (Block block : xp) {
if (!mcMMO.placeStore.isTrue(block)) {
Mining.miningXP(player, Users.getProfile(player), block, block.getType());
}
}
}
/**
* 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) {
if(player == null)
return;
final int RANK_1_LEVEL = blastMiningRank2;
final int RANK_2_LEVEL = blastMiningRank4;
final int RANK_3_LEVEL = blastMiningRank6;
final int RANK_4_LEVEL = blastMiningRank8;
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) {
if(player == null)
return;
final int RANK_1_LEVEL = blastMiningRank4;
final int RANK_2_LEVEL = blastMiningRank6;
final int RANK_3_LEVEL = blastMiningRank8;
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);
}
/** /**
* Detonate TNT for Blast Mining * Detonate TNT for Blast Mining
@ -333,4 +108,8 @@ public class BlastMining {
profile.setSkillDATS(ability, System.currentTimeMillis()); //Save DATS for Blast Mining profile.setSkillDATS(ability, System.currentTimeMillis()); //Save DATS for Blast Mining
profile.setAbilityInformed(ability, false); profile.setAbilityInformed(ability, false);
} }
protected static Random getRandom() {
return random;
}
} }

View File

@ -0,0 +1,152 @@
package com.gmail.nossr50.skills.mining;
import java.util.List;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.event.entity.EntityExplodeEvent;
import org.bukkit.inventory.ItemStack;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.util.BlockChecks;
import com.gmail.nossr50.util.Misc;
public class BlastMiningDropEventHandler {
private MiningManager manager;
private int skillLevel;
private EntityExplodeEvent event;
private float yield;
private List<Block> blocks;
private List<Block> ores;
private List<Block> debris;
private List<Block> droppedOres;
private float oreBonus;
private float debrisReduction;
private int dropMultiplier;
public BlastMiningDropEventHandler(MiningManager manager, EntityExplodeEvent event) {
this.manager = manager;
this.skillLevel = manager.getSkillLevel();
this.event = event;
this.yield = event.getYield();
this.blocks = event.blockList();
}
protected void sortExplosionBlocks() {
for (Block block : blocks) {
if (BlockChecks.isOre(block)) {
ores.add(block);
}
else {
debris.add(block);
}
}
}
protected void processXPGain() {
for (Block block : droppedOres) {
if (!mcMMO.placeStore.isTrue(block)) {
Mining.miningXP(manager.getPlayer(), manager.getProfile(), block, block.getType());
}
}
}
protected void processDroppedBlocks() {
for (Block block : ores) {
Location location = block.getLocation();
Material type = block.getType();
if (BlastMining.getRandom().nextFloat() < (yield + oreBonus)) {
droppedOres.add(block);
Mining.miningDrops(block, location, type);
if (!mcMMO.placeStore.isTrue(block)) {
for (int i = 1 ; i < dropMultiplier ; i++) {
droppedOres.add(block);
Mining.miningDrops(block, location, type);
}
}
}
}
float debrisYield = yield - debrisReduction;
if (debrisYield > 0) {
for (Block block : debris) {
Location location = block.getLocation();
Material type = block.getType();
if (BlastMining.getRandom().nextFloat() < debrisYield) {
Misc.dropItem(location, new ItemStack(type));
}
}
}
}
protected void modifyEventYield() {
event.setYield(0);
}
protected void calcuateDropModifiers() {
calculateOreBonus();
calculateDebrisReduction();
calculateDropMultiplier();
}
private void calculateOreBonus() {
if (skillLevel >= BlastMining.BLAST_MINING_RANK_8) {
oreBonus = .70f;
}
else if (skillLevel >= BlastMining.BLAST_MINING_RANK_7) {
oreBonus = .65f;
}
else if (skillLevel >= BlastMining.BLAST_MINING_RANK_6) {
oreBonus = .60f;
}
else if (skillLevel >= BlastMining.BLAST_MINING_RANK_5) {
oreBonus = .55f;
}
else if (skillLevel >= BlastMining.BLAST_MINING_RANK_4) {
oreBonus = .50f;
}
else if (skillLevel >= BlastMining.BLAST_MINING_RANK_3) {
oreBonus = .45f;
}
else if (skillLevel >= BlastMining.BLAST_MINING_RANK_2) {
oreBonus = .40f;
}
else {
debrisReduction = .35f;
}
}
private void calculateDebrisReduction() {
if (skillLevel >= BlastMining.BLAST_MINING_RANK_3) {
debrisReduction = .30f;
}
else if (skillLevel >= BlastMining.BLAST_MINING_RANK_2) {
debrisReduction = .20f;
}
else {
debrisReduction = .10f;
}
}
private void calculateDropMultiplier() {
if (skillLevel >= BlastMining.BLAST_MINING_RANK_7) {
dropMultiplier = 3;
}
else if (skillLevel >= BlastMining.BLAST_MINING_RANK_5) {
dropMultiplier = 2;
}
else {
dropMultiplier = 1;
}
}
}

View File

@ -0,0 +1,39 @@
package com.gmail.nossr50.skills.mining;
import org.bukkit.event.entity.EntityDamageEvent;
public class DemoltionsExpertiseEventHandler {
private int skillLevel;
private EntityDamageEvent event;
private int damage;
private double damageModifier;
public DemoltionsExpertiseEventHandler(MiningManager manager, EntityDamageEvent event) {
this.skillLevel = manager.getSkillLevel();
this.event = event;
this.damage = event.getDamage();
}
protected void calculateDamageModifier() {
if (skillLevel < BlastMining.BLAST_MINING_RANK_4) {
return;
}
if (skillLevel >= BlastMining.BLAST_MINING_RANK_8) {
damageModifier = 0;
}
else if (skillLevel >= BlastMining.BLAST_MINING_RANK_6) {
damageModifier = 0.5;
}
else if (skillLevel >= BlastMining.BLAST_MINING_RANK_4) {
damageModifier = 0.25;
}
}
protected void modifyEventDamage() {
damage = (int) (damage * damageModifier);
event.setDamage(damage);
}
}

View File

@ -29,7 +29,7 @@ public class MiningBlockEventHandler {
calculateSkillModifier(); calculateSkillModifier();
} }
protected void calculateSkillModifier() { private void calculateSkillModifier() {
this.skillModifier = Misc.skillCheck(manager.getSkillLevel(), Mining.DOUBLE_DROPS_MAX_BONUS_LEVEL); this.skillModifier = Misc.skillCheck(manager.getSkillLevel(), Mining.DOUBLE_DROPS_MAX_BONUS_LEVEL);
} }
@ -48,7 +48,7 @@ public class MiningBlockEventHandler {
} }
} }
protected void processXP() { protected void processXPGain() {
Mining.miningXP(player, manager.getProfile(), block, blockType); Mining.miningXP(player, manager.getProfile(), block, blockType);
} }
} }

View File

@ -2,6 +2,9 @@ package com.gmail.nossr50.skills.mining;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.entity.EntityDamageEvent;
import org.bukkit.event.entity.EntityExplodeEvent;
import org.bukkit.event.entity.ExplosionPrimeEvent;
import com.gmail.nossr50.mcMMO; import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.datatypes.PlayerProfile; import com.gmail.nossr50.datatypes.PlayerProfile;
@ -22,6 +25,65 @@ public class MiningManager {
this.skillLevel = profile.getSkillLevel(SkillType.MINING); this.skillLevel = profile.getSkillLevel(SkillType.MINING);
} }
/**
* Handler for explosion drops and XP gain.
*
* @param event Event whose explosion is being processed
*/
public void blastMiningDropProcessing(EntityExplodeEvent event) {
if (Misc.isCitizensNPC(player)) {
return;
}
if (skillLevel < BlastMining.BLAST_MINING_RANK_1) {
return;
}
BlastMiningDropEventHandler eventHandler = new BlastMiningDropEventHandler(this, event);
eventHandler.sortExplosionBlocks();
eventHandler.modifyEventYield();
eventHandler.calcuateDropModifiers();
eventHandler.processDroppedBlocks();
eventHandler.processXPGain();
}
/**
* Decreases damage dealt by the explosion from TNT activated by Blast Mining.
*
* @param event Event whose explosion damage is being reduced
*/
public void demolitionsExpertise(EntityDamageEvent event) {
if (Misc.isCitizensNPC(player)) {
return;
}
DemoltionsExpertiseEventHandler eventHandler = new DemoltionsExpertiseEventHandler(this, event);
eventHandler.calculateDamageModifier();
eventHandler.modifyEventDamage();
}
/**
* Increases the blast radius of the explosion.
*
* @param player Player triggering the explosion
* @param event Event whose explosion radius is being changed
*/
public void biggerBombs(ExplosionPrimeEvent event) {
if (Misc.isCitizensNPC(player)) {
return;
}
BiggerBombsEventHandler eventHandler = new BiggerBombsEventHandler(this, event);
eventHandler.calculateRadiusIncrease();
eventHandler.modifyBlastRadius();
}
/** /**
* Process Mining block drops. * Process Mining block drops.
* *
@ -34,7 +96,7 @@ public class MiningManager {
MiningBlockEventHandler eventHandler = new MiningBlockEventHandler(this, block); MiningBlockEventHandler eventHandler = new MiningBlockEventHandler(this, block);
eventHandler.processXP(); eventHandler.processXPGain();
if (!Permissions.miningDoubleDrops(player)) { if (!Permissions.miningDoubleDrops(player)) {
return; return;