2012-01-09 20:00:13 +01:00
|
|
|
package com.gmail.nossr50.skills;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
2012-03-12 22:57:44 +01:00
|
|
|
import java.util.List;
|
2012-02-05 21:24:44 +01:00
|
|
|
|
|
|
|
import org.bukkit.Bukkit;
|
2012-01-09 20:00:13 +01:00
|
|
|
import org.bukkit.Location;
|
|
|
|
import org.bukkit.Material;
|
|
|
|
import org.bukkit.block.Block;
|
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
import org.bukkit.inventory.ItemStack;
|
2012-02-05 21:24:44 +01:00
|
|
|
import org.bukkit.event.player.PlayerAnimationEvent;
|
|
|
|
|
2012-02-04 15:35:07 +01:00
|
|
|
import com.gmail.nossr50.spout.SpoutStuff;
|
2012-01-09 20:00:13 +01:00
|
|
|
import com.gmail.nossr50.Users;
|
|
|
|
import com.gmail.nossr50.m;
|
|
|
|
import com.gmail.nossr50.config.LoadProperties;
|
2012-02-29 05:28:14 +01:00
|
|
|
import com.gmail.nossr50.config.LoadTreasures;
|
2012-01-09 20:00:13 +01:00
|
|
|
import com.gmail.nossr50.datatypes.PlayerProfile;
|
|
|
|
import com.gmail.nossr50.datatypes.SkillType;
|
2012-02-20 23:10:37 +01:00
|
|
|
import com.gmail.nossr50.datatypes.treasure.ExcavationTreasure;
|
|
|
|
|
2012-02-04 16:45:37 +01:00
|
|
|
import org.getspout.spoutapi.sound.SoundEffect;
|
2012-01-09 20:00:13 +01:00
|
|
|
|
2012-03-12 22:57:44 +01:00
|
|
|
public class Excavation {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check to see if a block can be broken by Giga Drill Breaker.
|
|
|
|
*
|
|
|
|
* @param material The type of block to check
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
public static boolean canBeGigaDrillBroken(Material type) {
|
|
|
|
switch (type) {
|
|
|
|
case CLAY:
|
|
|
|
case DIRT:
|
|
|
|
case GRASS:
|
|
|
|
case GRAVEL:
|
|
|
|
case MYCEL:
|
|
|
|
case SAND:
|
|
|
|
case SOUL_SAND:
|
|
|
|
return true;
|
2012-03-19 02:12:29 +01:00
|
|
|
|
2012-03-12 22:57:44 +01:00
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check to see if treasures were found.
|
|
|
|
*
|
|
|
|
* @param block The block to check
|
|
|
|
* @param player The player who broke the block
|
|
|
|
*/
|
|
|
|
public static void excavationProcCheck(Block block, Player player) {
|
|
|
|
Material type = block.getType();
|
|
|
|
Location loc = block.getLocation();
|
|
|
|
|
|
|
|
PlayerProfile PP = Users.getProfile(player);
|
|
|
|
int skillLevel = PP.getSkillLevel(SkillType.EXCAVATION);
|
|
|
|
ArrayList<ItemStack> is = new ArrayList<ItemStack>();
|
|
|
|
|
|
|
|
List<ExcavationTreasure> treasures = new ArrayList<ExcavationTreasure>();
|
|
|
|
|
|
|
|
int xp = LoadProperties.mbase;
|
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
case DIRT:
|
|
|
|
treasures = LoadTreasures.excavationFromDirt;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GRASS:
|
|
|
|
treasures = LoadTreasures.excavationFromGrass;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SAND:
|
|
|
|
treasures = LoadTreasures.excavationFromSand;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GRAVEL:
|
|
|
|
treasures = LoadTreasures.excavationFromGravel;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CLAY:
|
|
|
|
treasures = LoadTreasures.excavationFromClay;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MYCEL:
|
|
|
|
treasures = LoadTreasures.excavationFromMycel;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SOUL_SAND:
|
|
|
|
treasures = LoadTreasures.excavationFromSoulSand;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (ExcavationTreasure treasure : treasures) {
|
|
|
|
if (skillLevel >= treasure.getDropLevel()) {
|
|
|
|
if (Math.random() * 100 <= treasure.getDropChance()) {
|
|
|
|
xp += treasure.getXp();
|
|
|
|
is.add(treasure.getDrop());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//Drop items
|
|
|
|
for (ItemStack x : is) {
|
|
|
|
if (x != null) {
|
|
|
|
m.mcDropItem(loc, x);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//Handle XP related tasks
|
|
|
|
PP.addXP(SkillType.EXCAVATION, xp, player);
|
|
|
|
Skills.XpCheckSkill(SkillType.EXCAVATION, player);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle triple drops from Giga Drill Breaker.
|
|
|
|
*
|
|
|
|
* @param player The player using the ability
|
|
|
|
* @param block The block to check
|
|
|
|
*/
|
|
|
|
public static void gigaDrillBreaker(Player player, Block block) {
|
|
|
|
Skills.abilityDurabilityLoss(player.getItemInHand(), LoadProperties.abilityDurabilityLoss);
|
|
|
|
|
2012-03-15 05:52:37 +01:00
|
|
|
if (!block.hasMetadata("mcmmoPlacedBlock")) {
|
2012-03-12 22:57:44 +01:00
|
|
|
PlayerAnimationEvent armswing = new PlayerAnimationEvent(player);
|
|
|
|
Bukkit.getPluginManager().callEvent(armswing);
|
|
|
|
|
|
|
|
Excavation.excavationProcCheck(block, player);
|
|
|
|
Excavation.excavationProcCheck(block, player);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (LoadProperties.spoutEnabled) {
|
|
|
|
SpoutStuff.playSoundForPlayer(SoundEffect.POP, player, block.getLocation());
|
|
|
|
}
|
2012-01-09 20:00:13 +01:00
|
|
|
}
|
2012-02-01 21:57:47 +01:00
|
|
|
}
|