Added ability to configure drops from Shake in treasures.yml

This commit is contained in:
GJ
2013-04-11 21:40:09 -04:00
parent 5ad7716137
commit 875091a1ce
6 changed files with 794 additions and 91 deletions

View File

@ -1,16 +1,13 @@
package com.gmail.nossr50.skills.fishing;
import java.util.Map;
import java.util.Map.Entry;
import java.util.List;
import org.bukkit.DyeColor;
import org.bukkit.Material;
import org.bukkit.entity.LivingEntity;
import org.bukkit.inventory.ItemStack;
import org.bukkit.potion.Potion;
import org.bukkit.potion.PotionType;
import com.gmail.nossr50.config.AdvancedConfig;
import com.gmail.nossr50.config.treasure.TreasureConfig;
import com.gmail.nossr50.datatypes.treasure.ShakeTreasure;
import com.gmail.nossr50.util.Misc;
public final class Fishing {
@ -66,115 +63,70 @@ public final class Fishing {
* @param target Targeted entity
* @param possibleDrops List of ItemStack that can be dropped
*/
protected static void findPossibleDrops(LivingEntity target, Map<ItemStack, Integer> possibleDrops) {
protected static List<ShakeTreasure> findPossibleDrops(LivingEntity target) {
switch (target.getType()) {
case BLAZE:
possibleDrops.put(new ItemStack(Material.BLAZE_ROD), 100);
break;
return TreasureConfig.getInstance().shakeFromBlaze;
case CAVE_SPIDER:
case SPIDER:
possibleDrops.put(new ItemStack(Material.SPIDER_EYE), 50);
possibleDrops.put(new ItemStack(Material.STRING), 50);
break;
return TreasureConfig.getInstance().shakeFromCaveSpider;
case CHICKEN:
possibleDrops.put(new ItemStack(Material.FEATHER), 34);
possibleDrops.put(new ItemStack(Material.RAW_CHICKEN), 33);
possibleDrops.put(new ItemStack(Material.EGG), 33);
break;
return TreasureConfig.getInstance().shakeFromChicken;
case COW:
possibleDrops.put(new ItemStack(Material.MILK_BUCKET), 2);
possibleDrops.put(new ItemStack(Material.LEATHER), 49);
possibleDrops.put(new ItemStack(Material.RAW_BEEF), 49);
break;
return TreasureConfig.getInstance().shakeFromCow;
case CREEPER:
possibleDrops.put(new ItemStack(Material.SKULL_ITEM, 1, (short) 4), 1);
possibleDrops.put(new ItemStack(Material.SULPHUR), 99);
break;
return TreasureConfig.getInstance().shakeFromCreeper;
case ENDERMAN:
possibleDrops.put(new ItemStack(Material.ENDER_PEARL), 100);
break;
return TreasureConfig.getInstance().shakeFromEnderman;
case GHAST:
possibleDrops.put(new ItemStack(Material.SULPHUR), 50);
possibleDrops.put(new ItemStack(Material.GHAST_TEAR), 50);
break;
return TreasureConfig.getInstance().shakeFromGhast;
case IRON_GOLEM:
possibleDrops.put(new ItemStack(Material.PUMPKIN), 3);
possibleDrops.put(new ItemStack(Material.IRON_INGOT), 12);
possibleDrops.put(new ItemStack(Material.RED_ROSE), 85);
break;
return TreasureConfig.getInstance().shakeFromIronGolem;
case MAGMA_CUBE:
possibleDrops.put(new ItemStack(Material.MAGMA_CREAM), 100);
break;
return TreasureConfig.getInstance().shakeFromMagmaCube;
case MUSHROOM_COW:
possibleDrops.put(new ItemStack(Material.MILK_BUCKET), 5);
possibleDrops.put(new ItemStack(Material.MUSHROOM_SOUP), 5);
possibleDrops.put(new ItemStack(Material.LEATHER), 30);
possibleDrops.put(new ItemStack(Material.RAW_BEEF), 30);
possibleDrops.put(new ItemStack(Material.RED_MUSHROOM, Misc.getRandom().nextInt(3) + 1), 30);
break;
return TreasureConfig.getInstance().shakeFromMushroomCow;
case PIG:
possibleDrops.put(new ItemStack(Material.PORK), 100);
break;
return TreasureConfig.getInstance().shakeFromPig;
case PIG_ZOMBIE:
possibleDrops.put(new ItemStack(Material.ROTTEN_FLESH), 50);
possibleDrops.put(new ItemStack(Material.GOLD_NUGGET), 50);
break;
return TreasureConfig.getInstance().shakeFromPigZombie;
case SHEEP:
possibleDrops.put(new ItemStack(Material.WOOL, Misc.getRandom().nextInt(6) + 1), 100);
break;
return TreasureConfig.getInstance().shakeFromSheep;
case SKELETON:
possibleDrops.put(new ItemStack(Material.SKULL_ITEM, 1, (short) 0), 2);
possibleDrops.put(new ItemStack(Material.BONE), 49);
possibleDrops.put(new ItemStack(Material.ARROW, Misc.getRandom().nextInt(3) + 1), 49);
break;
return TreasureConfig.getInstance().shakeFromSkeleton;
case SLIME:
possibleDrops.put(new ItemStack(Material.SLIME_BALL), 100);
break;
return TreasureConfig.getInstance().shakeFromSlime;
case SNOWMAN:
possibleDrops.put(new ItemStack(Material.PUMPKIN), 3);
possibleDrops.put(new ItemStack(Material.SNOW_BALL, Misc.getRandom().nextInt(4) + 1), 97);
break;
return TreasureConfig.getInstance().shakeFromSnowman;
case SPIDER:
return TreasureConfig.getInstance().shakeFromSpider;
case SQUID:
possibleDrops.put(new ItemStack(Material.INK_SACK, 1, DyeColor.BLACK.getDyeData()), 100);
break;
return TreasureConfig.getInstance().shakeFromSquid;
case WITCH:
possibleDrops.put(new Potion(PotionType.INSTANT_HEAL).toItemStack(1), 1);
possibleDrops.put(new Potion(PotionType.FIRE_RESISTANCE).toItemStack(1), 1);
possibleDrops.put(new Potion(PotionType.SPEED).toItemStack(1), 1);
possibleDrops.put(new ItemStack(Material.GLASS_BOTTLE), 9);
possibleDrops.put(new ItemStack(Material.GLOWSTONE_DUST), 13);
possibleDrops.put(new ItemStack(Material.SULPHUR), 12);
possibleDrops.put(new ItemStack(Material.REDSTONE), 13);
possibleDrops.put(new ItemStack(Material.SPIDER_EYE), 12);
possibleDrops.put(new ItemStack(Material.STICK), 13);
possibleDrops.put(new ItemStack(Material.SUGAR), 12);
possibleDrops.put(new ItemStack(Material.POTION), 13);
break;
return TreasureConfig.getInstance().shakeFromWitch;
case ZOMBIE:
possibleDrops.put(new ItemStack(Material.SKULL_ITEM, 1, (short) 2), 2);
possibleDrops.put(new ItemStack(Material.ROTTEN_FLESH), 98);
break;
return TreasureConfig.getInstance().shakeFromZombie;
default:
return;
return null;
}
}
@ -184,15 +136,15 @@ public final class Fishing {
* @param possibleDrops List of ItemStack that can be dropped
* @return Chosen ItemStack
*/
protected static ItemStack chooseDrop(Map<ItemStack, Integer> possibleDrops) {
protected static ItemStack chooseDrop(List<ShakeTreasure> possibleDrops) {
int dropProbability = Misc.getRandom().nextInt(100);
int cumulatedProbability = 0;
double cumulatedProbability = 0;
for (Entry<ItemStack, Integer> entry : possibleDrops.entrySet()) {
cumulatedProbability += entry.getValue();
for (ShakeTreasure treasure : possibleDrops) {
cumulatedProbability += treasure.getDropChance();
if (dropProbability < cumulatedProbability) {
return entry.getKey();
return treasure.getDrop();
}
}

View File

@ -2,9 +2,7 @@ package com.gmail.nossr50.skills.fishing;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.bukkit.Material;
import org.bukkit.enchantments.Enchantment;
@ -24,6 +22,7 @@ import com.gmail.nossr50.config.treasure.TreasureConfig;
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import com.gmail.nossr50.datatypes.skills.SkillType;
import com.gmail.nossr50.datatypes.treasure.FishingTreasure;
import com.gmail.nossr50.datatypes.treasure.ShakeTreasure;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.skills.SkillManager;
import com.gmail.nossr50.skills.fishing.Fishing.Tier;
@ -144,11 +143,9 @@ public class FishingManager extends SkillManager {
*/
public void shakeCheck(LivingEntity target) {
if (getShakeProbability() > Misc.getRandom().nextInt(getActivationChance())) {
Map<ItemStack, Integer> possibleDrops = new HashMap<ItemStack, Integer>();
List<ShakeTreasure> possibleDrops = Fishing.findPossibleDrops(target);
Fishing.findPossibleDrops(target, possibleDrops);
if (possibleDrops.isEmpty()) {
if (possibleDrops == null || possibleDrops.isEmpty()) {
return;
}