mcMMO/src/main/java/com/gmail/nossr50/skills/BlastMining.java

190 lines
5.5 KiB
Java
Raw Normal View History

2012-02-07 07:37:41 +01:00
package com.gmail.nossr50.skills;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.bukkit.block.Block;
2012-03-01 22:50:39 +01:00
import org.bukkit.entity.Player;
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-03-08 22:17:57 +01:00
import com.gmail.nossr50.BlockChecks;
2012-03-01 22:50:39 +01:00
import com.gmail.nossr50.Users;
2012-02-07 07:37:41 +01:00
import com.gmail.nossr50.mcMMO;
2012-03-01 22:50:39 +01:00
import com.gmail.nossr50.datatypes.SkillType;
2012-02-07 07:37:41 +01:00
public class BlastMining{
/**
* 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
* @param plugin mcMMO plugin instance
* @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, mcMMO plugin)
2012-02-25 00:25:24 +01:00
{
Iterator<Block> iterator2 = ores.iterator();
2012-03-01 22:50:39 +01:00
List<Block> blocksDropped = new ArrayList<Block>();
2012-02-25 00:25:24 +01:00
while(iterator2.hasNext())
{
Block temp = iterator2.next();
if((float)Math.random() < (yield + oreBonus))
{
2012-03-01 22:50:39 +01:00
blocksDropped.add(temp);
Mining.miningDrops(temp);
if(temp.getData() != (byte)5 && !plugin.misc.blockWatchList.contains(temp))
{
if(extraDrops == 2)
{
blocksDropped.add(temp);
Mining.miningDrops(temp);
}
if(extraDrops == 3)
{
blocksDropped.add(temp);
Mining.miningDrops(temp);
}
}
2012-02-25 00:25:24 +01:00
}
}
if(yield - debrisReduction != 0)
{
Iterator<Block> iterator3 = debris.iterator();
while(iterator3.hasNext())
{
Block temp = iterator3.next();
if((float)Math.random() < (yield - debrisReduction))
Mining.miningDrops(temp);
2012-02-25 00:25:24 +01:00
}
}
2012-03-01 22:50:39 +01:00
return blocksDropped;
2012-02-07 07:37:41 +01:00
}
/**
* Handler for explosion drops and XP gain.
* @param player Player triggering the explosion
* @param event Event whose explosion is being processed
* @param plugin mcMMO plugin instance
2012-02-07 07:37:41 +01:00
*/
2012-03-01 22:50:39 +01:00
public static void dropProcessing(Player player, EntityExplodeEvent event, mcMMO plugin)
2012-02-07 07:37:41 +01:00
{
2012-03-01 22:50:39 +01:00
int skillLevel = Users.getProfile(player).getSkillLevel(SkillType.MINING);
2012-02-07 07:37:41 +01:00
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>();
2012-03-01 22:50:39 +01:00
List<Block> xp = new ArrayList<Block>();
2012-02-07 07:37:41 +01:00
while(iterator.hasNext())
{
Block temp = iterator.next();
2012-03-08 22:17:57 +01:00
if(BlockChecks.isOre(temp.getType()))
ores.add(temp);
else
debris.add(temp);
2012-02-07 07:37:41 +01:00
}
//Normal explosion
if(skillLevel < 125)
return;
2012-02-25 00:25:24 +01:00
event.setYield(0);
2012-02-25 00:25:24 +01:00
//+35% ores, -10% debris
2012-02-07 07:37:41 +01:00
if(skillLevel >= 125 && skillLevel < 250)
xp = explosionYields(ores, debris, yield, .35f, .10f, 1, plugin);
2012-02-07 07:37:41 +01:00
2012-02-25 00:25:24 +01:00
//+40% ores, -20% debris
2012-02-07 07:37:41 +01:00
if(skillLevel >= 250 && skillLevel < 375)
xp = explosionYields(ores, debris, yield, .40f, .20f, 1, plugin);
2012-02-07 07:37:41 +01:00
2012-02-25 00:25:24 +01:00
//No debris, +45% ores
2012-02-07 21:28:41 +01:00
if(skillLevel >= 375 && skillLevel < 500)
xp = explosionYields(ores, debris, yield, .45f, .30f, 1, plugin);
2012-02-07 07:37:41 +01:00
2012-02-25 00:25:24 +01:00
//No debris, +50% ores
2012-02-07 21:28:41 +01:00
if(skillLevel >= 500 && skillLevel < 625)
xp = explosionYields(ores, debris, yield, .50f, .30f, 1, plugin);
2012-02-07 21:28:41 +01:00
2012-02-25 00:25:24 +01:00
//Double Drops, No Debris, +55% ores
2012-02-07 21:28:41 +01:00
if(skillLevel >= 625 && skillLevel < 750)
xp = explosionYields(ores, debris, yield, .55f, .30f, 2, plugin);
2012-02-07 07:37:41 +01:00
2012-02-25 00:25:24 +01:00
//Double Drops, No Debris, +60% ores
2012-02-07 21:28:41 +01:00
if(skillLevel >= 750 && skillLevel < 875)
xp = explosionYields(ores, debris, yield, .60f, .30f, 2, plugin);
2012-02-07 21:28:41 +01:00
2012-02-25 00:25:24 +01:00
//Triple Drops, No debris, +65% ores
if(skillLevel >= 875 && skillLevel < 1000)
xp = explosionYields(ores, debris, yield, .65f, .30f, 3, plugin);
2012-02-07 21:28:41 +01:00
2012-02-25 00:25:24 +01:00
//Triple Drops, No debris, +70% ores
2012-02-07 21:28:41 +01:00
if(skillLevel >= 1000)
xp = explosionYields(ores, debris, yield, .70f, .30f, 3, plugin);
2012-03-01 22:50:39 +01:00
2012-03-01 23:09:06 +01:00
for(Block block : xp)
2012-03-01 22:50:39 +01:00
{
if(block.getData() != (byte)5 && !plugin.misc.blockWatchList.contains(block))
Mining.miningXP(player, block);
2012-03-01 22:50:39 +01:00
}
2012-02-07 07:37:41 +01:00
}
/**
* Increases the blast radius of the explosion.
2012-02-07 07:37:41 +01:00
*
* @param player Player triggering the explosion
* @param event Event whose explosion radius is being changed
2012-02-07 07:37:41 +01:00
*/
2012-03-02 18:37:39 +01:00
public static void biggerBombs(Player player, ExplosionPrimeEvent event)
2012-02-07 07:37:41 +01:00
{
2012-03-02 18:37:39 +01:00
int skillLevel = Users.getProfile(player).getSkillLevel(SkillType.MINING);
2012-02-07 07:37:41 +01:00
float radius = event.getRadius();
if(skillLevel < 250)
return;
if(skillLevel >= 250)
radius++;
if(skillLevel >= 500)
radius++;
if(skillLevel >= 750)
radius++;
if(skillLevel >= 1000)
radius++;
2012-02-07 07:37:41 +01:00
event.setRadius(radius);
}
/**
* Decreases damage dealt by the explosion.
2012-02-07 07:37:41 +01:00
*
* @param player Player triggering the explosion
* @param event Event whose explosion damage is being reduced
2012-02-07 07:37:41 +01:00
*/
2012-03-02 18:13:35 +01:00
public static void demolitionsExpertise(Player player, EntityDamageEvent event)
2012-02-07 07:37:41 +01:00
{
2012-03-02 18:13:35 +01:00
int skill = Users.getProfile(player).getSkillLevel(SkillType.MINING);
2012-02-07 07:37:41 +01:00
int damage = event.getDamage();
if(skill < 500)
return;
2012-02-23 19:09:23 +01:00
if(skill >= 500 && skill < 750)
2012-02-07 07:37:41 +01:00
damage = damage/4;
2012-02-23 19:09:23 +01:00
if(skill >= 750 && skill < 1000)
2012-02-07 07:37:41 +01:00
damage = damage/2;
2012-02-23 19:09:23 +01:00
if(skill >= 1000)
damage = 0;
2012-02-07 07:37:41 +01:00
event.setDamage(damage);
}
2012-03-01 22:50:39 +01:00
}