Change how we do custom drops

Beginnings of fishing drops
This commit is contained in:
NuclearW
2012-02-20 17:10:37 -05:00
parent 1943ce884a
commit ad2ed37d0a
6 changed files with 323 additions and 227 deletions

View File

@ -20,28 +20,33 @@ import com.gmail.nossr50.mcMMO;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.inventory.ItemStack;
import com.gmail.nossr50.datatypes.HUDType;
import com.gmail.nossr50.datatypes.treasure.ExcavationTreasure;
import com.gmail.nossr50.datatypes.treasure.FishingTreasure;
import com.gmail.nossr50.datatypes.treasure.Treasure;
public class LoadProperties {
public static Boolean enableOnlyActivateWhenSneaking,
enableAbilityMessages, enableAbilities, showDisplayName, showFaces,
watch, xplockEnable, xpbar, xpicon, partybar, string, bucket, web,
xprateEnable, slimeballs, spoutEnabled, donateMessage,
chimaeraWingEnable, xpGainsMobSpawners, myspawnEnable, mccEnable,
mcmmoEnable, partyEnable, inviteEnable, acceptEnable, whoisEnable,
statsEnable, addxpEnable, ptpEnable, mmoeditEnable,
xplockEnable, xpbar, xpicon, partybar, xprateEnable, spoutEnabled,
donateMessage, chimaeraWingEnable, xpGainsMobSpawners, myspawnEnable,
mccEnable, mcmmoEnable, partyEnable, inviteEnable, acceptEnable,
whoisEnable, statsEnable, addxpEnable, ptpEnable, mmoeditEnable,
clearmyspawnEnable, mcgodEnable, mcabilityEnable, mctopEnable,
mcrefreshEnable, aEnable, pEnable, enableMotd, enableMySpawn,
enableCobbleToMossy, useMySQL, cocoabeans, mushrooms,
toolsLoseDurabilityFromAbilities, pvpxp, miningrequirespickaxe,
excavationRequiresShovel, woodcuttingrequiresaxe, eggs, apples,
cake, music, diamond, glowstone, slowsand, sulphur, netherrack,
bones, coal, clay, anvilmessages, mayDowngradeEnchants,
enableCobbleToMossy, useMySQL, toolsLoseDurabilityFromAbilities,
pvpxp, miningrequirespickaxe, excavationRequiresShovel,
woodcuttingrequiresaxe, anvilmessages, mayDowngradeEnchants,
mayLoseEnchants, fishingDrops, leatherArmor, ironArmor, goldArmor,
diamondArmor, woodenTools, stoneTools, ironTools, goldTools,
diamondTools, enderPearl, blazeRod, records, glowstoneDust,
@ -89,21 +94,14 @@ public class LoadProperties {
sorceryxpmodifier, unarmedxpmodifier, herbalismxpmodifier,
excavationxpmodifier, archeryxpmodifier, swordsxpmodifier,
axesxpmodifier, acrobaticsxpmodifier;
public static List<String> excavationTreasures = new ArrayList<String>();
public static List<Integer> excavationIDs = new ArrayList<Integer>();
public static List<Integer> excavationDatas = new ArrayList<Integer>();
public static List<Integer> excavationAmounts = new ArrayList<Integer>();
public static List<Integer> excavationXPs = new ArrayList<Integer>();
public static List<Double> excavationDropChances = new ArrayList<Double>();
public static List<Integer> excavationDropLevels = new ArrayList<Integer>();
public static List<Boolean> excavationFromDirt = new ArrayList<Boolean>();
public static List<Boolean> excavationFromGrass = new ArrayList<Boolean>();
public static List<Boolean> excavationFromSand = new ArrayList<Boolean>();
public static List<Boolean> excavationFromGravel = new ArrayList<Boolean>();
public static List<Boolean> excavationFromClay = new ArrayList<Boolean>();
public static List<Boolean> excavationFromMycel = new ArrayList<Boolean>();
public static List<Boolean> excavationFromSoulSand = new ArrayList<Boolean>();
public static List<ExcavationTreasure> excavationFromDirt = new ArrayList<ExcavationTreasure>();
public static List<ExcavationTreasure> excavationFromGrass = new ArrayList<ExcavationTreasure>();
public static List<ExcavationTreasure> excavationFromSand = new ArrayList<ExcavationTreasure>();
public static List<ExcavationTreasure> excavationFromGravel = new ArrayList<ExcavationTreasure>();
public static List<ExcavationTreasure> excavationFromClay = new ArrayList<ExcavationTreasure>();
public static List<ExcavationTreasure> excavationFromMycel = new ArrayList<ExcavationTreasure>();
public static List<ExcavationTreasure> excavationFromSoulSand = new ArrayList<ExcavationTreasure>();
public static HUDType defaulthud;
protected static File configFile;
@ -394,24 +392,6 @@ public class LoadProperties {
keepEnchantsRank3 = readInteger("Arcane_Forging.Keep_Enchants.Chance.Rank_3", 30);
keepEnchantsRank4 = readInteger("Arcane_Forging.Keep_Enchants.Chance.Rank_4", 40);
cocoabeans = readBoolean("Excavation.Drops.Cocoa_Beans", true);
mushrooms = readBoolean("Excavation.Drops.Mushrooms", true);
glowstone = readBoolean("Excavation.Drops.Glowstone", true);
eggs = readBoolean("Excavation.Drops.Eggs", true);
apples = readBoolean("Excavation.Drops.Apples", true);
cake = readBoolean("Excavation.Drops.Cake", true);
music = readBoolean("Excavation.Drops.Music", true);
diamond = readBoolean("Excavation.Drops.Diamond", true);
slowsand = readBoolean("Excavation.Drops.Slowsand", true);
sulphur = readBoolean("Excavation.Drops.Sulphur", true);
netherrack = readBoolean("Excavation.Drops.Netherrack", true);
bones = readBoolean("Excavation.Drops.Bones", true);
slimeballs = readBoolean("Excavation.Drops.Slimeballs", true);
watch = readBoolean("Excavation.Drops.Watch", true);
string = readBoolean("Excavation.Drops.String", true);
bucket = readBoolean("Excavation.Drops.Bucket", true);
web = readBoolean("Excavation.Drops.Web", true);
fishingDrops = readBoolean("Fishing.Drops.Item_Drops_Enabled", true);
fishingDropChanceTier1 = readInteger("Fishing.Drops.Drop_Chance.Tier_1", 20);
fishingDropChanceTier2 = readInteger("Fishing.Drops.Drop_Chance.Tier_2", 25);
@ -457,25 +437,77 @@ public class LoadProperties {
aDisplayNames = readBoolean("Commands.a.Display_Names", true);
pDisplayNames = readBoolean("Commands.p.Display_Names", true);
//Custom Excavation Drops
excavationTreasures = config.getStringList("Excavation.Treasure");
Iterator<String> iterator = excavationTreasures.iterator();
// Load treasures
Map<String, Treasure> treasures = new HashMap<String, Treasure>();
ConfigurationSection treasureSection = config.getConfigurationSection("Treasures");
Set<String> treasureConfigSet = treasureSection.getKeys(false);
Iterator<String> iterator = treasureConfigSet.iterator();
while(iterator.hasNext())
{
String temp2 = iterator.next();
excavationIDs.add(config.getInt("Treasures." + temp2 + ".ID"));
excavationDatas.add(config.getInt("Treasures." + temp2 + ".Data"));
excavationXPs.add(config.getInt("Treasures." + temp2 + ".XP"));
excavationAmounts.add(config.getInt("Treasures." + temp2 + ".Amount"));
excavationDropChances.add(config.getDouble("Treasures." + temp2 + ".Drop_Chance"));
excavationDropLevels.add(config.getInt("Treasures." + temp2 + ".Drop_Level"));
excavationFromDirt.add(config.getBoolean("Treasures." + temp2 + ".Drops_From.Dirt"));
excavationFromGrass.add(config.getBoolean("Treasures." + temp2 + ".Drops_From.Grass"));
excavationFromSand.add(config.getBoolean("Treasures." + temp2 + ".Drops_From.Sand"));
excavationFromGravel.add(config.getBoolean("Treasures." + temp2 + ".Drops_From.Gravel"));
excavationFromClay.add(config.getBoolean("Treasures." + temp2 + ".Drops_From.Clay"));
excavationFromMycel.add(config.getBoolean("Treasures." + temp2 + ".Drops_From.Mycelium"));
excavationFromSoulSand.add(config.getBoolean("Treasures." + temp2 + ".Drops_From.Soul_Sand"));
String treasureName = iterator.next();
int id = config.getInt("Treasures." + treasureName + ".ID");
int amount = config.getInt("Treasures." + treasureName + ".Amount");
int data = config.getInt("Treasures." + treasureName + ".Data");
int xp = config.getInt("Treasures." + treasureName + ".XP");
Double dropChance = config.getDouble("Treasures." + treasureName + ".Drop_Chance");
int dropLevel = config.getInt("Treasures." + treasureName + ".Drop_Level");
ItemStack item = new ItemStack(id, amount, (byte) 0, (byte) data);
if(readBoolean("Treasures." + treasureName + ".Drops_From.Fishing", false)) {
// TODO: Fishing
} else {
ExcavationTreasure eTreasure = new ExcavationTreasure(item, xp, dropChance, dropLevel);
if(readBoolean("Treasures." + treasureName + ".Drops_From.Dirt", false))
eTreasure.setDropsFromDirt();
if(readBoolean("Treasures." + treasureName + ".Drops_From.Grass", false))
eTreasure.setDropsFromGrass();
if(readBoolean("Treasures." + treasureName + ".Drops_From.Sand", false))
eTreasure.setDropsFromSand();
if(readBoolean("Treasures." + treasureName + ".Drops_From.Gravel", false))
eTreasure.setDropsFromGravel();
if(readBoolean("Treasures." + treasureName + ".Drops_From.Clay", false))
eTreasure.setDropsFromClay();
if(readBoolean("Treasures." + treasureName + ".Drops_From.Mycelium", false))
eTreasure.setDropsFromMycel();
if(readBoolean("Treasures." + treasureName + ".Drops_From.Soul_Sand", false))
eTreasure.setDropsFromSoulSand();
treasures.put(treasureName, eTreasure);
}
}
List<String> excavationTreasures = config.getStringList("Excavation.Treasure");
Iterator<String> treasureIterator = treasures.keySet().iterator();
while(treasureIterator.hasNext()) {
String treasureKey = treasureIterator.next();
Treasure treasure = treasures.get(treasureKey);
if(treasure instanceof FishingTreasure) {
// TODO: Fishing
} else if(treasure instanceof ExcavationTreasure) {
if(!excavationTreasures.contains(treasureKey)) continue;
ExcavationTreasure eTreasure = (ExcavationTreasure) treasure;
if(eTreasure.getDropsFromDirt())
excavationFromDirt.add(eTreasure);
if(eTreasure.getDropsFromGrass())
excavationFromGrass.add(eTreasure);
if(eTreasure.getDropsFromSand())
excavationFromSand.add(eTreasure);
if(eTreasure.getDropsFromGravel())
excavationFromGravel.add(eTreasure);
if(eTreasure.getDropsFromClay())
excavationFromClay.add(eTreasure);
if(eTreasure.getDropsFromMycel())
excavationFromMycel.add(eTreasure);
if(eTreasure.getDropsFromSoulSand())
excavationFromSoulSand.add(eTreasure);
}
}
}
}

View File

@ -0,0 +1,127 @@
package com.gmail.nossr50.datatypes.treasure;
import org.bukkit.inventory.ItemStack;
public class ExcavationTreasure extends Treasure {
// dirt grass sand gravel clay mycel soulsand
// 00000001 - dirt 1
// 00000010 - grass 2
// 00000100 - sand 4
// 00001000 - gravel 8
// 00010000 - clay 16
// 00100000 - mycel 32
// 01000000 - soulsand 64
private byte dropsFrom = 0x0;
public ExcavationTreasure(ItemStack drop, int xp, Double dropChance, int dropLevel) {
super(drop, xp, dropChance, dropLevel);
}
// Raw getters and setters
public byte getDropsFrom() {
return dropsFrom;
}
public void setDropsFrom(byte dropsFrom) {
this.dropsFrom = dropsFrom;
}
// Getters
public boolean getDropsFromDirt() {
return getDropFromMask(1);
}
public boolean getDropsFromGrass() {
return getDropFromMask(2);
}
public boolean getDropsFromSand() {
return getDropFromMask(4);
}
public boolean getDropsFromGravel() {
return getDropFromMask(8);
}
public boolean getDropsFromClay() {
return getDropFromMask(16);
}
public boolean getDropsFromMycel() {
return getDropFromMask(32);
}
public boolean getDropsFromSoulSand() {
return getDropFromMask(64);
}
private boolean getDropFromMask(int mask) {
return ((dropsFrom & mask) > 0) ? true : false;
}
// Setters
public void setDropsFromDirt() {
setDropFromMask(1);
}
public void setDropsFromGrass() {
setDropFromMask(2);
}
public void setDropsFromSand() {
setDropFromMask(4);
}
public void setDropsFromGravel() {
setDropFromMask(8);
}
public void setDropsFromClay() {
setDropFromMask(16);
}
public void setDropsFromMycel() {
setDropFromMask(32);
}
public void setDropsFromSoulSand() {
setDropFromMask(64);
}
private void setDropFromMask(int mask) {
dropsFrom |= mask;
}
// Un-setters
public void unsetDropsFromDirt() {
unsetDropFromMask(1);
}
public void unsetDropsFromGrass() {
unsetDropFromMask(2);
}
public void unsetDropsFromSand() {
unsetDropFromMask(4);
}
public void unsetDropsFromGravel() {
unsetDropFromMask(8);
}
public void unsetDropsFromClay() {
unsetDropFromMask(16);
}
public void unsetDropsFromMycel() {
unsetDropFromMask(32);
}
public void unsetDropsFromSoulSand() {
unsetDropFromMask(64);
}
private void unsetDropFromMask(int mask) {
dropsFrom &= ~mask;
}
}

View File

@ -0,0 +1,12 @@
package com.gmail.nossr50.datatypes.treasure;
import org.bukkit.inventory.ItemStack;
public class FishingTreasure extends Treasure {
public FishingTreasure(ItemStack drop, int xp, Double dropChance, int dropLevel) {
super(drop, xp, dropChance, dropLevel);
// TODO Auto-generated constructor stub
}
}

View File

@ -0,0 +1,50 @@
package com.gmail.nossr50.datatypes.treasure;
import org.bukkit.inventory.ItemStack;
public abstract class Treasure {
private int xp;
private Double dropChance;
private int dropLevel;
private ItemStack drop;
public Treasure(ItemStack drop, int xp, Double dropChance, int dropLevel) {
this.drop = drop;
this.xp = xp;
this.dropChance = dropChance;
this.dropLevel = dropLevel;
}
public ItemStack getDrop() {
return drop;
}
public void setDrop(ItemStack drop) {
this.drop = drop;
}
public int getXp() {
return xp;
}
public void setXp(int xp) {
this.xp = xp;
}
public Double getDropChance() {
return dropChance;
}
public void setDropChance(Double dropChance) {
this.dropChance = dropChance;
}
public int getDropLevel() {
return dropLevel;
}
public void setDropLevel(int dropLevel) {
this.dropLevel = dropLevel;
}
}

View File

@ -17,7 +17,6 @@
package com.gmail.nossr50.skills;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.Bukkit;
import org.bukkit.Location;
@ -36,6 +35,8 @@ import com.gmail.nossr50.config.LoadProperties;
import com.gmail.nossr50.datatypes.AbilityType;
import com.gmail.nossr50.datatypes.PlayerProfile;
import com.gmail.nossr50.datatypes.SkillType;
import com.gmail.nossr50.datatypes.treasure.ExcavationTreasure;
import org.getspout.spoutapi.sound.SoundEffect;
public class Excavation
@ -90,132 +91,96 @@ public class Excavation
int skillLevel = PP.getSkillLevel(SkillType.EXCAVATION);
ArrayList<ItemStack> is = new ArrayList<ItemStack>();
int xp = 0;
//Custom Excavation Drops
List<Integer> idValues = LoadProperties.excavationIDs;
List<Integer> dataValues = LoadProperties.excavationDatas;
List<Integer> xpValues = LoadProperties.excavationXPs;
List<Integer> amounts = LoadProperties.excavationAmounts;
List<Double> dropChances = LoadProperties.excavationDropChances;
List<Integer> dropLevels = LoadProperties.excavationDropLevels;
List<Boolean> dirt = LoadProperties.excavationFromDirt;
List<Boolean> grass = LoadProperties.excavationFromGrass;
List<Boolean> sand = LoadProperties.excavationFromSand;
List<Boolean> gravel = LoadProperties.excavationFromGravel;
List<Boolean> clay = LoadProperties.excavationFromClay;
List<Boolean> mycel = LoadProperties.excavationFromMycel;
List<Boolean> soulSand = LoadProperties.excavationFromSoulSand;
switch(type)
{
case DIRT:
for(int i = 0; i < dirt.size(); i++)
for(ExcavationTreasure treasure : LoadProperties.excavationFromDirt)
{
if(dirt.get(i))
if(skillLevel >= treasure.getDropLevel())
{
if(skillLevel >= dropLevels.get(i))
if(Math.random() * 100 > (100.00 - treasure.getDropChance()))
{
if(Math.random() * 100 > (100.00 - dropChances.get(i)))
{
xp += xpValues.get(i);
is.add(new ItemStack(idValues.get(i), amounts.get(i), (byte)0, dataValues.get(i).byteValue()));
}
xp += treasure.getXp();
is.add(treasure.getDrop());
}
}
}
break;
case GRASS:
for(int i = 0; i < grass.size(); i++)
for(ExcavationTreasure treasure : LoadProperties.excavationFromGrass)
{
if(grass.get(i))
if(skillLevel >= treasure.getDropLevel())
{
if(skillLevel >= dropLevels.get(i))
if(Math.random() * 100 > (100.00 - treasure.getDropChance()))
{
if(Math.random() * 100 > (100.00 - dropChances.get(i)))
{
xp += xpValues.get(i);
is.add(new ItemStack(idValues.get(i), amounts.get(i), (byte)0, dataValues.get(i).byteValue()));
}
xp += treasure.getXp();
is.add(treasure.getDrop());
}
}
}
break;
case SAND:
for(int i = 0; i < sand.size(); i++)
for(ExcavationTreasure treasure : LoadProperties.excavationFromSand)
{
if(sand.get(i))
if(skillLevel >= treasure.getDropLevel())
{
if(skillLevel >= dropLevels.get(i))
if(Math.random() * 100 > (100.00 - treasure.getDropChance()))
{
if(Math.random() * 100 > (100.00 - dropChances.get(i)))
{
xp += xpValues.get(i);
is.add(new ItemStack(idValues.get(i), amounts.get(i), (byte)0, dataValues.get(i).byteValue()));
}
xp += treasure.getXp();
is.add(treasure.getDrop());
}
}
}
break;
case GRAVEL:
for(int i = 0; i < gravel.size(); i++)
for(ExcavationTreasure treasure : LoadProperties.excavationFromGravel)
{
if(gravel.get(i))
if(skillLevel >= treasure.getDropLevel())
{
if(skillLevel >= dropLevels.get(i))
if(Math.random() * 100 > (100.00 - treasure.getDropChance()))
{
if(Math.random() * 100 > (100.00 - dropChances.get(i)))
{
xp += xpValues.get(i);
is.add(new ItemStack(idValues.get(i), amounts.get(i), (byte)0, dataValues.get(i).byteValue()));
}
xp += treasure.getXp();
is.add(treasure.getDrop());
}
}
}
break;
case CLAY:
for(int i = 0; i < clay.size(); i++)
for(ExcavationTreasure treasure : LoadProperties.excavationFromClay)
{
if(clay.get(i))
if(skillLevel >= treasure.getDropLevel())
{
if(skillLevel >= dropLevels.get(i))
if(Math.random() * 100 > (100.00 - treasure.getDropChance()))
{
if(Math.random() * 100 > (100.00 - dropChances.get(i)))
{
xp += xpValues.get(i);
is.add(new ItemStack(idValues.get(i), amounts.get(i), (byte)0, dataValues.get(i).byteValue()));
}
xp += treasure.getXp();
is.add(treasure.getDrop());
}
}
}
break;
case MYCEL:
for(int i = 0; i < mycel.size(); i++)
for(ExcavationTreasure treasure : LoadProperties.excavationFromMycel)
{
if(mycel.get(i))
if(skillLevel >= treasure.getDropLevel())
{
if(skillLevel >= dropLevels.get(i))
if(Math.random() * 100 > (100.00 - treasure.getDropChance()))
{
if(Math.random() * 100 > (100.00 - dropChances.get(i)))
{
xp += xpValues.get(i);
is.add(new ItemStack(idValues.get(i), amounts.get(i), (byte)0, dataValues.get(i).byteValue()));
}
xp += treasure.getXp();
is.add(treasure.getDrop());
}
}
}
break;
case SOUL_SAND:
for(int i = 0; i < soulSand.size(); i++)
for(ExcavationTreasure treasure : LoadProperties.excavationFromSoulSand)
{
if(soulSand.get(i))
if(skillLevel >= treasure.getDropLevel())
{
if(skillLevel >= dropLevels.get(i))
if(Math.random() * 100 > (100.00 - treasure.getDropChance()))
{
if(Math.random() * 100 > (100.00 - dropChances.get(i)))
{
xp += xpValues.get(i);
is.add(new ItemStack(idValues.get(i), amounts.get(i), (byte)0, dataValues.get(i).byteValue()));
}
xp += treasure.getXp();
is.add(treasure.getDrop());
}
}
}