2012-02-07 07:37:41 +01:00
|
|
|
/*
|
|
|
|
This file is part of mcMMO.
|
|
|
|
|
|
|
|
mcMMO is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
mcMMO is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with mcMMO. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
package com.gmail.nossr50.skills;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Iterator;
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
import org.bukkit.Location;
|
|
|
|
import org.bukkit.block.Block;
|
|
|
|
import org.bukkit.inventory.ItemStack;
|
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
|
|
|
|
|
|
|
import com.gmail.nossr50.Users;
|
2012-02-07 07:37:41 +01:00
|
|
|
import com.gmail.nossr50.m;
|
|
|
|
import com.gmail.nossr50.mcMMO;
|
2012-03-01 22:50:39 +01:00
|
|
|
import com.gmail.nossr50.config.LoadProperties;
|
|
|
|
import com.gmail.nossr50.datatypes.PlayerProfile;
|
|
|
|
import com.gmail.nossr50.datatypes.SkillType;
|
2012-02-07 07:37:41 +01:00
|
|
|
|
|
|
|
public class BlastMining{
|
|
|
|
|
2012-03-01 22:50:39 +01:00
|
|
|
public static Block explosionBlockDrops(Block block, Location loc)
|
2012-02-07 07:37:41 +01:00
|
|
|
{
|
|
|
|
int id = block.getTypeId();
|
2012-02-25 00:25:24 +01:00
|
|
|
ItemStack item = new ItemStack(id, 1);
|
2012-02-07 07:37:41 +01:00
|
|
|
|
2012-02-24 04:26:20 +01:00
|
|
|
switch (id){
|
2012-02-07 07:37:41 +01:00
|
|
|
//GLOWSTONE
|
|
|
|
case 89:
|
2012-02-25 00:25:24 +01:00
|
|
|
item = new ItemStack(348, 1);
|
2012-02-24 04:26:20 +01:00
|
|
|
m.mcDropItems(loc, item, 2);
|
|
|
|
m.mcRandomDropItems(loc, item, 50, 2);
|
2012-02-07 07:37:41 +01:00
|
|
|
break;
|
|
|
|
//REDSTONE
|
|
|
|
case 73:
|
2012-02-25 00:25:24 +01:00
|
|
|
item = new ItemStack(331, 1);
|
2012-02-24 04:26:20 +01:00
|
|
|
m.mcDropItems(loc, item, 4);
|
|
|
|
m.mcRandomDropItem(loc, item, 50);
|
2012-02-07 07:37:41 +01:00
|
|
|
break;
|
|
|
|
case 74:
|
2012-02-25 00:25:24 +01:00
|
|
|
item = new ItemStack(331, 1);
|
2012-02-24 04:26:20 +01:00
|
|
|
m.mcDropItems(loc, item, 4);
|
|
|
|
m.mcRandomDropItem(loc, item, 50);
|
2012-02-07 07:37:41 +01:00
|
|
|
break;
|
|
|
|
//LAPIS
|
|
|
|
case 21:
|
2012-02-25 00:25:24 +01:00
|
|
|
item = new ItemStack(351, 1, (byte)0,(byte)0x4);
|
2012-02-24 04:26:20 +01:00
|
|
|
m.mcDropItems(loc, item, 4);
|
|
|
|
m.mcRandomDropItems(loc, item, 50, 4);
|
2012-02-07 07:37:41 +01:00
|
|
|
break;
|
|
|
|
//DIAMOND
|
|
|
|
case 56:
|
2012-02-25 00:25:24 +01:00
|
|
|
item = new ItemStack(264, 1);
|
2012-02-07 07:37:41 +01:00
|
|
|
m.mcDropItem(loc, item);
|
|
|
|
break;
|
|
|
|
//STONE
|
|
|
|
case 1:
|
2012-02-25 00:25:24 +01:00
|
|
|
item = new ItemStack(4, 1);
|
2012-02-07 07:37:41 +01:00
|
|
|
m.mcDropItem(loc, item);
|
|
|
|
break;
|
|
|
|
//COAL
|
|
|
|
case 16:
|
2012-02-25 00:25:24 +01:00
|
|
|
item = new ItemStack(263, 1);
|
2012-02-07 07:37:41 +01:00
|
|
|
m.mcDropItem(loc, item);
|
|
|
|
break;
|
2012-02-25 08:49:53 +01:00
|
|
|
default:
|
|
|
|
m.mcDropItem(loc, item);
|
|
|
|
break;
|
2012-02-25 00:25:24 +01:00
|
|
|
}
|
2012-03-01 22:50:39 +01:00
|
|
|
return block;
|
2012-02-24 04:26:20 +01:00
|
|
|
}
|
2012-02-25 00:25:24 +01:00
|
|
|
|
2012-03-01 22:50:39 +01:00
|
|
|
public static List<Block> explosionYields(List<Block> ores, List<Block> debris, float yield, float oreBonus, float debrisReduction, Location location, int extraDrops)
|
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);
|
2012-02-25 00:25:24 +01:00
|
|
|
explosionBlockDrops(temp, location);
|
|
|
|
if(extraDrops == 2)
|
2012-03-01 22:50:39 +01:00
|
|
|
blocksDropped.add(temp);
|
2012-02-25 00:25:24 +01:00
|
|
|
explosionBlockDrops(temp, location);
|
|
|
|
if(extraDrops == 3)
|
2012-03-01 22:50:39 +01:00
|
|
|
blocksDropped.add(temp);
|
2012-02-25 00:25:24 +01:00
|
|
|
explosionBlockDrops(temp, location);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(yield - debrisReduction != 0)
|
|
|
|
{
|
|
|
|
Iterator<Block> iterator3 = debris.iterator();
|
|
|
|
while(iterator3.hasNext())
|
|
|
|
{
|
|
|
|
Block temp = iterator3.next();
|
|
|
|
if((float)Math.random() < (yield - debrisReduction))
|
|
|
|
explosionBlockDrops(temp, location);
|
|
|
|
}
|
|
|
|
}
|
2012-03-01 22:50:39 +01:00
|
|
|
return blocksDropped;
|
2012-02-07 07:37:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Process the drops from the explosion
|
|
|
|
*/
|
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();
|
2012-02-25 00:25:24 +01:00
|
|
|
Location location = event.getLocation();
|
2012-02-07 07:37:41 +01:00
|
|
|
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-02-25 00:25:24 +01:00
|
|
|
if(temp.getData() != 5 && !plugin.misc.blockWatchList.contains(temp))
|
2012-02-07 07:37:41 +01:00
|
|
|
{
|
2012-02-25 08:49:53 +01:00
|
|
|
if(m.isOre(temp))
|
2012-02-25 00:25:24 +01:00
|
|
|
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);
|
|
|
|
//+35% ores, -10% debris
|
2012-02-07 07:37:41 +01:00
|
|
|
if(skillLevel >= 125 && skillLevel < 250)
|
2012-03-01 22:50:39 +01:00
|
|
|
xp = explosionYields(ores, debris, yield, .35f, .10f, location, 1);
|
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)
|
2012-03-01 22:50:39 +01:00
|
|
|
xp = explosionYields(ores, debris, yield, .40f, .20f, location, 1);
|
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)
|
2012-03-01 22:50:39 +01:00
|
|
|
xp = explosionYields(ores, debris, yield, .45f, .30f, location, 1);
|
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)
|
2012-03-01 22:50:39 +01:00
|
|
|
xp = explosionYields(ores, debris, yield, .50f, .30f, location, 1);
|
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)
|
2012-03-01 22:50:39 +01:00
|
|
|
xp = explosionYields(ores, debris, yield, .55f, .30f, location, 2);
|
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)
|
2012-03-01 22:50:39 +01:00
|
|
|
xp = explosionYields(ores, debris, yield, .60f, .30f, location, 2);
|
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)
|
2012-03-01 22:50:39 +01:00
|
|
|
xp = explosionYields(ores, debris, yield, .65f, .30f, location, 3);
|
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)
|
2012-03-01 22:50:39 +01:00
|
|
|
xp = explosionYields(ores, debris, yield, .70f, .30f, location, 3);
|
|
|
|
|
2012-03-01 23:02:23 +01:00
|
|
|
Iterator<Block> xpGain = xp.iterator();
|
|
|
|
|
2012-03-01 22:50:39 +01:00
|
|
|
while(xpGain.hasNext())
|
|
|
|
{
|
|
|
|
blastMiningXP(player, xpGain.next(), plugin);
|
|
|
|
}
|
2012-02-07 07:37:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Bigger Bombs (Unlocked at Mining 250)
|
|
|
|
*
|
|
|
|
* Increases radius of explosion by 1 at 250.
|
|
|
|
* Increases radius of explosion by 2 at 500.
|
|
|
|
* Increases radius of explosion by 3 at 750.
|
|
|
|
* Increases radius of explosion by 4 at 1000.
|
|
|
|
*/
|
|
|
|
public static void biggerBombs(int skillLevel, ExplosionPrimeEvent event)
|
|
|
|
{
|
|
|
|
float radius = event.getRadius();
|
|
|
|
if(skillLevel < 250)
|
|
|
|
return;
|
|
|
|
if(skillLevel >= 250)
|
|
|
|
radius++;
|
|
|
|
if(skillLevel >= 500)
|
|
|
|
radius++;
|
|
|
|
if(skillLevel >= 750)
|
|
|
|
radius++;
|
|
|
|
if(skillLevel >= 1000)
|
|
|
|
radius++;
|
|
|
|
|
|
|
|
event.setRadius(radius);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Demolitions Expertise (Unlocked at Mining 500)
|
|
|
|
*
|
|
|
|
* Reduces explosion damage to 1/4 of normal at 500.
|
2012-02-23 19:09:23 +01:00
|
|
|
* Reduces explosion damage to 1/2 of normal at 750.
|
|
|
|
* Reduces explosion damage to 0 at 1000.
|
2012-02-07 07:37:41 +01:00
|
|
|
*/
|
2012-02-25 00:25:24 +01:00
|
|
|
public static void demolitionsExpertise(int skill, EntityDamageEvent event)
|
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
|
|
|
public static void blastMiningXP(Player player, Block block, mcMMO plugin)
|
|
|
|
{
|
|
|
|
PlayerProfile PP = Users.getProfile(player);
|
|
|
|
if(plugin.misc.blockWatchList.contains(block) || block.getData() == (byte) 5)
|
|
|
|
return;
|
|
|
|
int xp = 0;
|
|
|
|
int id = block.getTypeId();
|
|
|
|
|
|
|
|
switch (id) {
|
|
|
|
//COAL
|
|
|
|
case 16:
|
|
|
|
xp += LoadProperties.mcoal;
|
|
|
|
break;
|
|
|
|
//GOLD
|
|
|
|
case 14:
|
|
|
|
xp += LoadProperties.mgold;
|
|
|
|
break;
|
|
|
|
//DIAMOND
|
|
|
|
case 56:
|
|
|
|
xp += LoadProperties.mdiamond;
|
|
|
|
break;
|
|
|
|
//IRON
|
|
|
|
case 15:
|
|
|
|
xp += LoadProperties.miron;
|
|
|
|
break;
|
|
|
|
//REDSTONE
|
|
|
|
case 73:
|
|
|
|
xp += LoadProperties.mredstone;
|
|
|
|
break;
|
|
|
|
case 74:
|
|
|
|
xp += LoadProperties.mredstone;
|
|
|
|
break;
|
|
|
|
//LAPIS
|
|
|
|
case 21:
|
|
|
|
xp += LoadProperties.mlapis;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
PP.addXP(SkillType.MINING, xp, player);
|
|
|
|
Skills.XpCheckSkill(SkillType.MINING, player);
|
|
|
|
}
|
|
|
|
|
2012-02-07 07:37:41 +01:00
|
|
|
}
|