2013-01-22 18:43:25 +01:00
|
|
|
package com.gmail.nossr50.skills.herbalism;
|
2012-01-09 20:00:13 +01:00
|
|
|
|
2013-01-29 17:24:41 +01:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
|
|
|
|
2013-01-08 17:31:07 +01:00
|
|
|
import org.bukkit.DyeColor;
|
2012-01-09 20:00:13 +01:00
|
|
|
import org.bukkit.Location;
|
|
|
|
import org.bukkit.Material;
|
|
|
|
import org.bukkit.block.Block;
|
2013-01-28 22:55:57 +01:00
|
|
|
import org.bukkit.block.BlockFace;
|
2012-01-09 20:00:13 +01:00
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
import org.bukkit.event.block.BlockBreakEvent;
|
2013-01-24 21:46:29 +01:00
|
|
|
import org.bukkit.event.entity.FoodLevelChangeEvent;
|
2012-01-09 20:00:13 +01:00
|
|
|
import org.bukkit.inventory.ItemStack;
|
2012-02-24 07:02:23 +01:00
|
|
|
import org.bukkit.inventory.PlayerInventory;
|
|
|
|
|
2012-06-07 00:02:22 +02:00
|
|
|
import com.gmail.nossr50.mcMMO;
|
2013-01-02 01:27:50 +01:00
|
|
|
import com.gmail.nossr50.config.AdvancedConfig;
|
2012-04-26 16:27:57 +02:00
|
|
|
import com.gmail.nossr50.config.Config;
|
2013-01-29 17:24:41 +01:00
|
|
|
import com.gmail.nossr50.config.TreasuresConfig;
|
2012-01-09 20:00:13 +01:00
|
|
|
import com.gmail.nossr50.datatypes.PlayerProfile;
|
2012-06-25 15:39:02 +02:00
|
|
|
import com.gmail.nossr50.datatypes.mods.CustomBlock;
|
2013-01-29 17:24:41 +01:00
|
|
|
import com.gmail.nossr50.datatypes.treasure.HylianTreasure;
|
2012-04-27 11:47:11 +02:00
|
|
|
import com.gmail.nossr50.locale.LocaleLoader;
|
2012-03-11 04:21:53 +01:00
|
|
|
import com.gmail.nossr50.runnables.GreenThumbTimer;
|
2013-01-22 18:43:25 +01:00
|
|
|
import com.gmail.nossr50.skills.AbilityType;
|
|
|
|
import com.gmail.nossr50.skills.SkillType;
|
2013-01-26 23:01:55 +01:00
|
|
|
import com.gmail.nossr50.skills.SkillTools;
|
2012-04-27 11:47:11 +02:00
|
|
|
import com.gmail.nossr50.util.Misc;
|
2012-05-17 06:24:33 +02:00
|
|
|
import com.gmail.nossr50.util.ModChecks;
|
2012-04-27 11:47:11 +02:00
|
|
|
import com.gmail.nossr50.util.Permissions;
|
|
|
|
import com.gmail.nossr50.util.Users;
|
2012-01-09 20:00:13 +01:00
|
|
|
|
2012-03-10 19:03:31 +01:00
|
|
|
public class Herbalism {
|
2013-01-24 21:46:29 +01:00
|
|
|
public static int farmersDietRankLevel1 = AdvancedConfig.getInstance().getFarmerDietRankChange();
|
|
|
|
public static int farmersDietRankLevel2 = farmersDietRankLevel1 * 2;
|
|
|
|
public static int farmersDietMaxLevel = farmersDietRankLevel1 * 5;
|
2013-01-22 07:52:34 +01:00
|
|
|
|
|
|
|
public static int greenThumbStageChangeLevel = AdvancedConfig.getInstance().getGreenThumbStageChange();
|
|
|
|
public static int greenThumbStageMaxLevel = greenThumbStageChangeLevel * 4;
|
|
|
|
|
|
|
|
public static double greenThumbMaxChance = AdvancedConfig.getInstance().getGreenThumbChanceMax();
|
|
|
|
public static int greenThumbMaxLevel = AdvancedConfig.getInstance().getGreenThumbMaxLevel();
|
|
|
|
|
|
|
|
public static double doubleDropsMaxChance = AdvancedConfig.getInstance().getHerbalismDoubleDropsChanceMax();
|
|
|
|
public static int doubleDropsMaxLevel = AdvancedConfig.getInstance().getHerbalismDoubleDropsMaxLevel();
|
2013-01-22 08:20:05 +01:00
|
|
|
public static boolean doubleDropsDisabled = Config.getInstance().herbalismDoubleDropsDisabled();
|
2013-01-22 07:52:34 +01:00
|
|
|
|
|
|
|
public static double hylianLuckMaxChance = AdvancedConfig.getInstance().getHylianLuckChanceMax();
|
|
|
|
public static int hylianLuckMaxLevel = AdvancedConfig.getInstance().getHylianLucksMaxLevel();
|
2012-03-26 17:04:17 +02:00
|
|
|
|
2013-01-26 01:21:33 +01:00
|
|
|
public static boolean greenTerraWalls = Config.getInstance().getHerbalismGreenThumbCobbleWallToMossyWall();
|
|
|
|
public static boolean greenTerraSmoothBrick = Config.getInstance().getHerbalismGreenThumbSmoothbrickToMossy();
|
|
|
|
public static boolean greenTerraDirt = Config.getInstance().getHerbalismGreenThumbDirtToGrass();
|
|
|
|
public static boolean greenTerraCobble = Config.getInstance().getHerbalismGreenThumbCobbleToMossy();
|
|
|
|
|
2013-01-28 22:55:57 +01:00
|
|
|
/**
|
|
|
|
* Handle the farmers diet skill.
|
|
|
|
*
|
|
|
|
* @param player The player to activate the skill for
|
|
|
|
* @param rankChange The # of levels to change rank for the food
|
|
|
|
* @param event The actual FoodLevelChange event
|
|
|
|
*/
|
2013-01-24 21:46:29 +01:00
|
|
|
public static void farmersDiet(Player player, int rankChange, FoodLevelChangeEvent event) {
|
|
|
|
if (!Permissions.farmersDiet(player)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-01-26 23:01:55 +01:00
|
|
|
SkillTools.handleFoodSkills(player, SkillType.HERBALISM, event, farmersDietRankLevel1, farmersDietMaxLevel, rankChange);
|
2013-01-24 21:46:29 +01:00
|
|
|
}
|
|
|
|
|
2012-03-10 19:03:31 +01:00
|
|
|
/**
|
|
|
|
* Activate the Green Terra ability.
|
|
|
|
*
|
|
|
|
* @param player The player activating the ability
|
|
|
|
* @param block The block to be changed by Green Terra
|
|
|
|
*/
|
|
|
|
public static void greenTerra(Player player, Block block) {
|
|
|
|
PlayerInventory inventory = player.getInventory();
|
|
|
|
boolean hasSeeds = inventory.contains(Material.SEEDS);
|
|
|
|
|
|
|
|
if (!hasSeeds) {
|
2013-01-17 17:02:55 +01:00
|
|
|
player.sendMessage(LocaleLoader.getString("Herbalism.Ability.GTe.NeedMore"));
|
2013-01-26 01:21:33 +01:00
|
|
|
return;
|
2012-03-10 19:03:31 +01:00
|
|
|
}
|
2013-01-26 01:21:33 +01:00
|
|
|
|
2013-01-29 16:07:32 +01:00
|
|
|
inventory.removeItem(new ItemStack(Material.SEEDS));
|
|
|
|
player.updateInventory(); // Needed until replacement available
|
|
|
|
greenTerraConvert(player, block);
|
2012-04-29 05:22:17 +02:00
|
|
|
}
|
2012-06-05 15:57:10 +02:00
|
|
|
|
2012-04-29 05:22:17 +02:00
|
|
|
public static void greenTerraConvert(Player player, Block block) {
|
|
|
|
if (Misc.blockBreakSimulate(block, player, false)) {
|
2013-01-26 01:21:33 +01:00
|
|
|
Material type = block.getType();
|
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
case SMOOTH_BRICK:
|
|
|
|
if (greenTerraSmoothBrick && block.getData() == 0x0) {
|
|
|
|
block.setData((byte) 0x1);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
|
|
|
|
case DIRT:
|
|
|
|
if (greenTerraDirt) {
|
|
|
|
block.setType(Material.GRASS);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
|
|
|
|
case COBBLESTONE:
|
|
|
|
if (greenTerraCobble) {
|
|
|
|
block.setType(Material.MOSSY_COBBLESTONE);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
|
|
|
|
case COBBLE_WALL:
|
|
|
|
if (greenTerraWalls && block.getData() == 0x0) {
|
|
|
|
block.setData((byte) 0x1);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return;
|
2012-11-05 01:06:33 +01:00
|
|
|
}
|
2012-03-10 19:03:31 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-28 22:55:57 +01:00
|
|
|
private static int calculateCatciAndSugarDrops(Block block) {
|
|
|
|
Material blockType = block.getType();
|
|
|
|
int dropAmount = 0;
|
|
|
|
|
|
|
|
for (int y = 0; y <= 2; y++) {
|
|
|
|
Block relativeBlock = block.getRelative(BlockFace.UP, y);
|
|
|
|
if (relativeBlock.getType().equals(blockType) && !mcMMO.placeStore.isTrue(relativeBlock)) {
|
|
|
|
dropAmount++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return dropAmount;
|
|
|
|
}
|
|
|
|
|
2012-03-10 19:03:31 +01:00
|
|
|
/**
|
|
|
|
* Check for extra Herbalism drops.
|
|
|
|
*
|
|
|
|
* @param block The block to check for extra drops
|
|
|
|
* @param player The player getting extra drops
|
|
|
|
* @param event The event to use for Green Thumb
|
|
|
|
* @param plugin mcMMO plugin instance
|
|
|
|
*/
|
2012-06-07 00:02:22 +02:00
|
|
|
public static void herbalismProcCheck(final Block block, Player player, BlockBreakEvent event, mcMMO plugin) {
|
2013-01-28 22:55:57 +01:00
|
|
|
if (Config.getInstance().getHerbalismAFKDisabled() && player.isInsideVehicle()) {
|
|
|
|
return;
|
|
|
|
}
|
2012-03-13 08:31:07 +01:00
|
|
|
|
2013-01-28 22:55:57 +01:00
|
|
|
PlayerProfile profile = Users.getProfile(player);
|
2012-07-03 16:04:04 +02:00
|
|
|
int herbLevel = profile.getSkillLevel(SkillType.HERBALISM);
|
2013-01-28 22:55:57 +01:00
|
|
|
Material blockType = block.getType();
|
2012-03-10 21:43:48 +01:00
|
|
|
|
2013-01-28 22:55:57 +01:00
|
|
|
HerbalismBlock herbalismBlock = HerbalismBlock.getHerbalismBlock(blockType);
|
|
|
|
CustomBlock customBlock = null;
|
2012-05-17 06:24:33 +02:00
|
|
|
|
2012-03-10 19:03:31 +01:00
|
|
|
int xp = 0;
|
2013-01-28 22:55:57 +01:00
|
|
|
int dropAmount = 1;
|
|
|
|
ItemStack dropItem = null;
|
2012-03-10 19:03:31 +01:00
|
|
|
|
2013-01-28 22:55:57 +01:00
|
|
|
if (herbalismBlock != null) {
|
|
|
|
if (blockType == Material.CACTUS || blockType == Material.SUGAR_CANE_BLOCK) {
|
|
|
|
dropItem = herbalismBlock.getDropItem();
|
|
|
|
dropAmount = calculateCatciAndSugarDrops(block);
|
|
|
|
xp = herbalismBlock.getXpGain() * dropAmount;
|
2012-03-10 19:03:31 +01:00
|
|
|
}
|
2013-01-28 22:55:57 +01:00
|
|
|
else if (herbalismBlock.hasGreenThumbPermission(player)){
|
|
|
|
dropItem = herbalismBlock.getDropItem();
|
|
|
|
xp = herbalismBlock.getXpGain();
|
2012-11-10 01:37:12 +01:00
|
|
|
|
2013-01-27 22:34:47 +01:00
|
|
|
greenThumbWheat(block, player, event, plugin);
|
2012-03-10 19:03:31 +01:00
|
|
|
}
|
2013-01-28 22:55:57 +01:00
|
|
|
else {
|
|
|
|
if (!mcMMO.placeStore.isTrue(block)) {
|
|
|
|
dropItem = herbalismBlock.getDropItem();
|
|
|
|
xp = herbalismBlock.getXpGain();
|
2012-03-10 19:03:31 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-01-28 22:55:57 +01:00
|
|
|
else {
|
|
|
|
customBlock = ModChecks.getCustomBlock(block);
|
|
|
|
dropItem = customBlock.getItemDrop();
|
|
|
|
xp = customBlock.getXpGain();
|
2012-05-01 07:14:32 +02:00
|
|
|
}
|
|
|
|
|
2013-01-07 02:52:31 +01:00
|
|
|
if (Permissions.herbalismDoubleDrops(player)) {
|
2013-01-28 22:55:57 +01:00
|
|
|
int activationChance = Misc.calculateActivationChance(Permissions.luckyHerbalism(player));
|
|
|
|
double chance = (doubleDropsMaxChance / doubleDropsMaxLevel) * Misc.skillCheck(herbLevel, doubleDropsMaxLevel);
|
2012-03-10 19:03:31 +01:00
|
|
|
|
2013-01-22 02:01:33 +01:00
|
|
|
if (chance > Misc.getRandom().nextInt(activationChance)) {
|
2013-01-28 22:55:57 +01:00
|
|
|
Location location = block.getLocation();
|
2012-05-01 07:14:32 +02:00
|
|
|
|
2013-01-28 22:55:57 +01:00
|
|
|
if (herbalismBlock != null && herbalismBlock.canDoubleDrop()) {
|
|
|
|
Misc.dropItems(location, dropItem, dropAmount);
|
|
|
|
}
|
|
|
|
else if (customBlock != null){
|
|
|
|
int minimumDropAmount = customBlock.getMinimumDropAmount();
|
|
|
|
int maximumDropAmount = customBlock.getMaximumDropAmount();
|
2012-05-01 07:14:32 +02:00
|
|
|
|
2013-01-28 22:55:57 +01:00
|
|
|
if (minimumDropAmount != maximumDropAmount) {
|
|
|
|
Misc.randomDropItems(location, dropItem, 50, maximumDropAmount - minimumDropAmount);
|
2012-10-29 04:56:33 +01:00
|
|
|
}
|
|
|
|
|
2013-01-28 22:55:57 +01:00
|
|
|
Misc.dropItems(location, dropItem, minimumDropAmount);
|
2012-03-10 21:43:48 +01:00
|
|
|
}
|
2012-03-10 19:03:31 +01:00
|
|
|
}
|
2012-03-10 21:43:48 +01:00
|
|
|
}
|
2012-05-01 07:14:32 +02:00
|
|
|
|
2013-01-26 23:01:55 +01:00
|
|
|
SkillTools.xpProcessing(player, profile, SkillType.HERBALISM, xp);
|
2012-01-09 20:00:13 +01:00
|
|
|
}
|
2012-03-10 19:03:31 +01:00
|
|
|
|
|
|
|
/**
|
2012-03-11 04:21:53 +01:00
|
|
|
* Apply the Green Thumb ability to crops.
|
2012-03-10 19:03:31 +01:00
|
|
|
*
|
|
|
|
* @param block The block to apply the ability to
|
|
|
|
* @param player The player using the ability
|
|
|
|
* @param event The event triggering the ability
|
|
|
|
* @param plugin mcMMO plugin instance
|
|
|
|
*/
|
2012-06-07 00:02:22 +02:00
|
|
|
private static void greenThumbWheat(Block block, Player player, BlockBreakEvent event, mcMMO plugin) {
|
2012-07-03 16:04:04 +02:00
|
|
|
PlayerProfile profile = Users.getProfile(player);
|
|
|
|
int herbLevel = profile.getSkillLevel(SkillType.HERBALISM);
|
2012-03-10 19:03:31 +01:00
|
|
|
PlayerInventory inventory = player.getInventory();
|
2012-11-10 01:37:12 +01:00
|
|
|
boolean hasSeeds = false;
|
2012-07-04 21:35:14 +02:00
|
|
|
Location location = block.getLocation();
|
2012-11-10 01:37:12 +01:00
|
|
|
Material type = block.getType();
|
|
|
|
|
|
|
|
switch(type) {
|
|
|
|
case CROPS:
|
|
|
|
hasSeeds = inventory.contains(Material.SEEDS);
|
|
|
|
break;
|
|
|
|
case COCOA:
|
2013-01-09 00:14:12 +01:00
|
|
|
try {
|
2013-01-14 03:24:43 +01:00
|
|
|
hasSeeds = inventory.containsAtLeast(new ItemStack(Material.INK_SACK, 1, DyeColor.BROWN.getDyeData()), 1);
|
2013-01-09 00:14:12 +01:00
|
|
|
}
|
|
|
|
catch(Exception e) {
|
2013-01-10 18:55:54 +01:00
|
|
|
hasSeeds = inventory.containsAtLeast(new ItemStack(Material.INK_SACK, 1, (short) 3), 1);
|
2013-01-09 00:14:12 +01:00
|
|
|
}
|
2013-01-14 02:56:05 +01:00
|
|
|
catch(NoSuchMethodError e) {
|
|
|
|
hasSeeds = inventory.containsAtLeast(new ItemStack(Material.INK_SACK, 1, (short) 3), 1);
|
|
|
|
}
|
2012-11-10 01:37:12 +01:00
|
|
|
break;
|
|
|
|
case CARROT:
|
|
|
|
hasSeeds = inventory.contains(Material.CARROT_ITEM);
|
|
|
|
break;
|
|
|
|
case POTATO:
|
|
|
|
hasSeeds = inventory.contains(Material.POTATO_ITEM);
|
|
|
|
break;
|
|
|
|
case NETHER_WARTS:
|
|
|
|
hasSeeds = inventory.contains(Material.NETHER_STALK);
|
|
|
|
break;
|
2012-12-24 18:35:17 +01:00
|
|
|
default:
|
|
|
|
break;
|
2012-11-10 01:37:12 +01:00
|
|
|
}
|
2012-03-10 19:03:31 +01:00
|
|
|
|
2013-01-22 02:01:33 +01:00
|
|
|
int activationChance = Misc.calculateActivationChance(Permissions.luckyHerbalism(player));
|
2012-07-02 17:09:55 +02:00
|
|
|
|
2013-01-22 07:52:34 +01:00
|
|
|
float chance = (float) ((greenThumbMaxChance / greenThumbMaxLevel) * herbLevel);
|
|
|
|
if (chance > greenThumbMaxChance) chance = (float) greenThumbMaxChance;
|
2013-01-02 01:27:50 +01:00
|
|
|
|
2013-01-22 02:01:33 +01:00
|
|
|
if (hasSeeds && profile.getAbilityMode(AbilityType.GREEN_TERRA) || hasSeeds && (chance > Misc.getRandom().nextInt(activationChance))) {
|
2012-03-10 19:03:31 +01:00
|
|
|
event.setCancelled(true);
|
2012-03-11 04:21:53 +01:00
|
|
|
|
2012-11-10 01:37:12 +01:00
|
|
|
switch(type) {
|
|
|
|
case CROPS:
|
|
|
|
Misc.dropItem(location, new ItemStack(Material.WHEAT));
|
|
|
|
Misc.randomDropItems(location, new ItemStack(Material.SEEDS), 50, 3);
|
|
|
|
inventory.removeItem(new ItemStack(Material.SEEDS));
|
|
|
|
break;
|
|
|
|
case COCOA:
|
2013-01-09 00:14:12 +01:00
|
|
|
try {
|
2013-01-14 03:23:11 +01:00
|
|
|
Misc.dropItems(location, new ItemStack(Material.INK_SACK, 1, DyeColor.BROWN.getDyeData()), 3);
|
|
|
|
inventory.removeItem(new ItemStack(Material.INK_SACK, 1, DyeColor.BROWN.getDyeData()));
|
2013-01-09 00:14:12 +01:00
|
|
|
}
|
|
|
|
catch(Exception e) {
|
2013-01-09 00:52:50 +01:00
|
|
|
Misc.dropItems(location, new ItemStack(Material.INK_SACK, 1, (short) 3), 3);
|
2013-01-09 00:14:12 +01:00
|
|
|
inventory.removeItem(new ItemStack(Material.INK_SACK, 1, (short) 3));
|
|
|
|
}
|
2013-01-14 02:56:05 +01:00
|
|
|
catch(NoSuchMethodError e) {
|
|
|
|
Misc.dropItems(location, new ItemStack(Material.INK_SACK, 1, (short) 3), 3);
|
|
|
|
inventory.removeItem(new ItemStack(Material.INK_SACK, 1, (short) 3));
|
|
|
|
}
|
2012-11-10 01:37:12 +01:00
|
|
|
break;
|
|
|
|
case CARROT:
|
|
|
|
Misc.dropItem(location, new ItemStack(Material.CARROT_ITEM));
|
|
|
|
Misc.randomDropItems(location, new ItemStack(Material.CARROT_ITEM), 50, 3);
|
2012-11-16 01:34:57 +01:00
|
|
|
inventory.removeItem(new ItemStack(Material.CARROT_ITEM));
|
2012-11-10 01:37:12 +01:00
|
|
|
break;
|
|
|
|
case POTATO:
|
|
|
|
Misc.dropItem(location, new ItemStack(Material.POTATO_ITEM));
|
|
|
|
Misc.randomDropItems(location, new ItemStack(Material.POTATO_ITEM), 50, 3);
|
|
|
|
Misc.randomDropItem(location, new ItemStack(Material.POISONOUS_POTATO), 2);
|
|
|
|
inventory.removeItem(new ItemStack(Material.POTATO_ITEM));
|
|
|
|
break;
|
|
|
|
case NETHER_WARTS:
|
2013-01-09 00:52:50 +01:00
|
|
|
Misc.dropItems(location, new ItemStack(Material.NETHER_STALK), 2);
|
2012-11-10 01:37:12 +01:00
|
|
|
Misc.randomDropItems(location, new ItemStack(Material.NETHER_STALK), 50, 2);
|
|
|
|
inventory.removeItem(new ItemStack(Material.NETHER_STALK));
|
|
|
|
break;
|
2012-12-24 18:35:17 +01:00
|
|
|
default:
|
|
|
|
break;
|
2012-11-10 01:37:12 +01:00
|
|
|
}
|
2012-03-10 19:03:31 +01:00
|
|
|
|
2012-11-10 01:37:12 +01:00
|
|
|
plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new GreenThumbTimer(block, profile, type), 1);
|
2012-05-15 06:49:19 +02:00
|
|
|
player.updateInventory(); // Needed until replacement available
|
2012-03-10 19:03:31 +01:00
|
|
|
}
|
2012-01-09 20:00:13 +01:00
|
|
|
}
|
2012-03-11 04:21:53 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Apply the Green Thumb ability to blocks.
|
|
|
|
*
|
|
|
|
* @param is The item in the player's hand
|
|
|
|
* @param player The player activating the ability
|
|
|
|
* @param block The block being used in the ability
|
|
|
|
*/
|
|
|
|
public static void greenThumbBlocks(ItemStack is, Player player, Block block) {
|
2012-07-03 16:04:04 +02:00
|
|
|
PlayerProfile profile = Users.getProfile(player);
|
|
|
|
int skillLevel = profile.getSkillLevel(SkillType.HERBALISM);
|
2012-03-11 04:21:53 +01:00
|
|
|
int seeds = is.getAmount();
|
|
|
|
|
|
|
|
player.setItemInHand(new ItemStack(Material.SEEDS, seeds - 1));
|
|
|
|
|
2013-01-22 02:01:33 +01:00
|
|
|
int activationChance = Misc.calculateActivationChance(Permissions.luckyHerbalism(player));
|
2012-07-02 17:09:55 +02:00
|
|
|
|
2013-01-22 07:52:34 +01:00
|
|
|
float chance = (float) ((greenThumbMaxChance / greenThumbMaxLevel) * skillLevel);
|
|
|
|
if (chance > greenThumbMaxChance) chance = (float) greenThumbMaxChance;
|
2013-01-02 01:27:50 +01:00
|
|
|
|
2013-01-22 02:01:33 +01:00
|
|
|
if (chance > Misc.getRandom().nextInt(activationChance)) {
|
2012-04-29 05:22:17 +02:00
|
|
|
greenTerraConvert(player, block);
|
2012-03-11 04:21:53 +01:00
|
|
|
}
|
|
|
|
else {
|
2012-05-06 09:55:15 +02:00
|
|
|
player.sendMessage(LocaleLoader.getString("Herbalism.Ability.GTh.Fail"));
|
2012-03-11 04:21:53 +01:00
|
|
|
}
|
|
|
|
}
|
2013-01-19 18:33:57 +01:00
|
|
|
|
|
|
|
public static void hylianLuck(Block block, Player player, BlockBreakEvent event) {
|
2013-01-22 07:52:34 +01:00
|
|
|
int skillLevel = Users.getProfile(player).getSkillLevel(SkillType.HERBALISM);
|
|
|
|
|
2013-01-29 16:07:32 +01:00
|
|
|
double chance = (hylianLuckMaxChance / hylianLuckMaxLevel) * Misc.skillCheck(skillLevel, hylianLuckMaxLevel);
|
2013-01-22 02:01:33 +01:00
|
|
|
int activationChance = Misc.calculateActivationChance(Permissions.luckyHerbalism(player));
|
2013-01-19 18:33:57 +01:00
|
|
|
|
2013-01-22 02:01:33 +01:00
|
|
|
if (chance > Misc.getRandom().nextInt(activationChance)) {
|
2013-01-29 17:24:41 +01:00
|
|
|
List<HylianTreasure> treasures = new ArrayList<HylianTreasure>();
|
2013-01-19 18:33:57 +01:00
|
|
|
|
|
|
|
switch (block.getType()) {
|
|
|
|
case DEAD_BUSH:
|
|
|
|
case LONG_GRASS:
|
|
|
|
case SAPLING:
|
2013-01-29 17:24:41 +01:00
|
|
|
treasures = TreasuresConfig.getInstance().hylianFromBushes;
|
2013-01-19 18:33:57 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case RED_ROSE:
|
|
|
|
case YELLOW_FLOWER:
|
2013-01-25 18:33:48 +01:00
|
|
|
if (mcMMO.placeStore.isTrue(block)) {
|
|
|
|
mcMMO.placeStore.setFalse(block);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-01-29 17:24:41 +01:00
|
|
|
treasures = TreasuresConfig.getInstance().hylianFromFlowers;
|
2013-01-19 18:33:57 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case FLOWER_POT:
|
2013-01-29 17:24:41 +01:00
|
|
|
treasures = TreasuresConfig.getInstance().hylianFromPots;
|
2013-01-19 18:33:57 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-01-29 17:24:41 +01:00
|
|
|
int dropNumber = Misc.getRandom().nextInt(treasures.size());
|
|
|
|
ItemStack item = treasures.get(dropNumber + 1).getDrop();
|
|
|
|
Location location = block.getLocation();
|
|
|
|
|
2013-01-19 18:33:57 +01:00
|
|
|
event.setCancelled(true);
|
|
|
|
event.getBlock().setType(Material.AIR);
|
|
|
|
Misc.dropItem(location, item);
|
|
|
|
player.sendMessage(LocaleLoader.getString("Herbalism.HylianLuck"));
|
|
|
|
}
|
|
|
|
}
|
2012-10-31 04:12:43 +01:00
|
|
|
}
|