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-02-22 17:23:46 +01:00
|
|
|
import org.bukkit.CropState;
|
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;
|
2013-02-22 17:23:46 +01:00
|
|
|
import org.bukkit.block.BlockState;
|
2012-01-09 20:00:13 +01:00
|
|
|
import org.bukkit.entity.Player;
|
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;
|
2013-02-22 17:23:46 +01:00
|
|
|
import org.bukkit.material.CocoaPlant;
|
|
|
|
import org.bukkit.material.CocoaPlant.CocoaPlantSize;
|
2012-02-24 07:02:23 +01:00
|
|
|
|
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;
|
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;
|
2013-01-30 17:35:33 +01:00
|
|
|
import com.gmail.nossr50.mods.ModChecks;
|
|
|
|
import com.gmail.nossr50.mods.datatypes.CustomBlock;
|
2013-01-30 17:53:51 +01:00
|
|
|
import com.gmail.nossr50.skills.utilities.AbilityType;
|
|
|
|
import com.gmail.nossr50.skills.utilities.SkillTools;
|
|
|
|
import com.gmail.nossr50.skills.utilities.SkillType;
|
2012-04-27 11:47:11 +02:00
|
|
|
import com.gmail.nossr50.util.Misc;
|
|
|
|
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();
|
|
|
|
|
|
|
|
public static double hylianLuckMaxChance = AdvancedConfig.getInstance().getHylianLuckChanceMax();
|
2013-02-21 00:20:34 +01:00
|
|
|
public static int hylianLuckMaxLevel = AdvancedConfig.getInstance().getHylianLuckMaxLevel();
|
2012-03-26 17:04:17 +02:00
|
|
|
|
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
|
|
|
/**
|
2013-02-22 17:23:46 +01:00
|
|
|
* Process the Green Terra ability.
|
2012-03-10 19:03:31 +01:00
|
|
|
*
|
2013-02-22 17:23:46 +01:00
|
|
|
* @param blockState The {@link BlockState} to check ability activation for
|
|
|
|
* @param player The {@link Player} using this ability
|
|
|
|
* @return true if the ability was successful, false otherwise
|
2012-03-10 19:03:31 +01:00
|
|
|
*/
|
2013-02-22 17:23:46 +01:00
|
|
|
public static boolean processGreenTerra(BlockState blockState, Player player) {
|
|
|
|
PlayerInventory playerInventory = player.getInventory();
|
|
|
|
ItemStack seed = new ItemStack(Material.SEEDS);
|
2012-03-10 19:03:31 +01:00
|
|
|
|
2013-02-22 17:23:46 +01:00
|
|
|
if (!playerInventory.containsAtLeast(seed, 1)) {
|
2013-01-17 17:02:55 +01:00
|
|
|
player.sendMessage(LocaleLoader.getString("Herbalism.Ability.GTe.NeedMore"));
|
2013-02-22 17:23:46 +01:00
|
|
|
return false;
|
2012-03-10 19:03:31 +01:00
|
|
|
}
|
2013-01-26 01:21:33 +01:00
|
|
|
|
2013-02-22 17:23:46 +01:00
|
|
|
playerInventory.removeItem(seed);
|
|
|
|
player.updateInventory(); // Needed until replacement available
|
2012-06-05 15:57:10 +02:00
|
|
|
|
2013-02-22 17:23:46 +01:00
|
|
|
return convertGreenTerraBlocks(blockState, player);
|
|
|
|
}
|
2013-01-26 01:21:33 +01:00
|
|
|
|
2013-02-22 17:23:46 +01:00
|
|
|
/**
|
|
|
|
* Convert blocks affected by the Green Thumb & Green Terra abilities.
|
|
|
|
*
|
|
|
|
* @param blockState The {@link BlockState} to check ability activation for
|
|
|
|
* @param player The {@link Player} using this ability
|
|
|
|
* @return true if the ability was successful, false otherwise
|
|
|
|
*/
|
|
|
|
private static boolean convertGreenTerraBlocks(BlockState blockState, Player player) {
|
|
|
|
Material blockType = blockState.getType();
|
2013-02-19 06:56:25 +01:00
|
|
|
|
2013-02-22 17:23:46 +01:00
|
|
|
if (!Permissions.greenThumbBlock(player, blockType)) {
|
|
|
|
return false;
|
|
|
|
}
|
2013-01-26 01:21:33 +01:00
|
|
|
|
2013-02-22 17:23:46 +01:00
|
|
|
switch (blockType) {
|
|
|
|
case COBBLE_WALL:
|
|
|
|
case SMOOTH_BRICK:
|
|
|
|
blockState.setRawData((byte) 0x1);
|
|
|
|
return true;
|
2013-01-26 01:21:33 +01:00
|
|
|
|
2013-02-22 17:23:46 +01:00
|
|
|
case DIRT:
|
|
|
|
blockState.setType(Material.GRASS);
|
|
|
|
return true;
|
2013-01-26 01:21:33 +01:00
|
|
|
|
2013-02-22 17:23:46 +01:00
|
|
|
case COBBLESTONE:
|
|
|
|
blockState.setType(Material.MOSSY_COBBLESTONE);
|
|
|
|
return true;
|
2013-01-26 01:21:33 +01:00
|
|
|
|
2013-02-22 17:23:46 +01:00
|
|
|
default:
|
|
|
|
return false;
|
2012-03-10 19:03:31 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-22 17:23:46 +01:00
|
|
|
/**
|
|
|
|
* Calculate the drop amounts for cacti & sugar cane based on the blocks above them.
|
|
|
|
*
|
|
|
|
* @param blockState The {@link BlockState} of the bottom block of the plant
|
|
|
|
* @return the number of bonus drops to award from the blocks in this plant
|
|
|
|
*/
|
|
|
|
private static int calculateCatciAndSugarDrops(BlockState blockState) {
|
|
|
|
Block block = blockState.getBlock();
|
|
|
|
Material blockType = blockState.getType();
|
2013-01-28 22:55:57 +01:00
|
|
|
int dropAmount = 0;
|
|
|
|
|
2013-02-22 17:23:46 +01:00
|
|
|
// Handle the original block
|
|
|
|
if (!mcMMO.placeStore.isTrue(blockState)) {
|
|
|
|
dropAmount++;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Handle the two blocks above it - cacti & sugar cane can only grow 3 high naturally
|
|
|
|
for (int y = 1; y < 3; y++) {
|
2013-01-28 22:55:57 +01:00
|
|
|
Block relativeBlock = block.getRelative(BlockFace.UP, y);
|
2013-02-22 17:23:46 +01:00
|
|
|
Material relativeBlockType = relativeBlock.getType();
|
|
|
|
|
|
|
|
// If the first one is air, so is the next one
|
|
|
|
if (relativeBlockType == Material.AIR) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (relativeBlockType == blockType && !mcMMO.placeStore.isTrue(relativeBlock)) {
|
2013-01-28 22:55:57 +01:00
|
|
|
dropAmount++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return dropAmount;
|
|
|
|
}
|
|
|
|
|
2012-03-10 19:03:31 +01:00
|
|
|
/**
|
2013-02-22 17:23:46 +01:00
|
|
|
* Process double drops & XP gain for Herbalism.
|
2012-03-10 19:03:31 +01:00
|
|
|
*
|
2013-02-22 17:23:46 +01:00
|
|
|
* @param blockState The {@link BlockState} to check ability activation for
|
|
|
|
* @param player The {@link Player} using this ability
|
|
|
|
* @return true if the ability was successful, false otherwise
|
2012-03-10 19:03:31 +01:00
|
|
|
*/
|
2013-02-22 17:23:46 +01:00
|
|
|
public static boolean herbalismBlockCheck(BlockState blockState, Player player) {
|
2013-01-28 22:55:57 +01:00
|
|
|
if (Config.getInstance().getHerbalismAFKDisabled() && player.isInsideVehicle()) {
|
2013-02-22 17:23:46 +01:00
|
|
|
return false;
|
2013-01-28 22:55:57 +01:00
|
|
|
}
|
2012-03-13 08:31:07 +01:00
|
|
|
|
2013-02-22 17:23:46 +01:00
|
|
|
Material blockType = blockState.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;
|
2013-02-22 17:23:46 +01:00
|
|
|
boolean update = false;
|
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();
|
2013-02-22 17:23:46 +01:00
|
|
|
dropAmount = calculateCatciAndSugarDrops(blockState);
|
2013-01-28 22:55:57 +01:00
|
|
|
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();
|
2013-02-22 17:23:46 +01:00
|
|
|
update = processGreenThumbPlants(blockState, player);
|
2012-03-10 19:03:31 +01:00
|
|
|
}
|
2013-01-28 22:55:57 +01:00
|
|
|
else {
|
2013-02-22 17:23:46 +01:00
|
|
|
if (!mcMMO.placeStore.isTrue(blockState)) {
|
2013-01-28 22:55:57 +01:00
|
|
|
dropItem = herbalismBlock.getDropItem();
|
|
|
|
xp = herbalismBlock.getXpGain();
|
2012-03-10 19:03:31 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-01-28 22:55:57 +01:00
|
|
|
else {
|
2013-02-22 17:23:46 +01:00
|
|
|
customBlock = ModChecks.getCustomBlock(blockState);
|
2013-01-28 22:55:57 +01:00
|
|
|
dropItem = customBlock.getItemDrop();
|
|
|
|
xp = customBlock.getXpGain();
|
2012-05-01 07:14:32 +02:00
|
|
|
}
|
|
|
|
|
2013-02-22 17:23:46 +01:00
|
|
|
if (Permissions.doubleDrops(player, SkillType.HERBALISM) && SkillTools.activationSuccessful(player, SkillType.HERBALISM, doubleDropsMaxChance, doubleDropsMaxLevel)) {
|
|
|
|
Location location = blockState.getLocation();
|
2012-03-10 19:03:31 +01:00
|
|
|
|
2013-02-22 17:23:46 +01:00
|
|
|
if (dropItem != null && 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-02-22 17:23:46 +01:00
|
|
|
if (minimumDropAmount != maximumDropAmount) {
|
|
|
|
Misc.randomDropItems(location, dropItem, maximumDropAmount - minimumDropAmount);
|
2013-01-28 22:55:57 +01:00
|
|
|
}
|
2012-05-01 07:14:32 +02:00
|
|
|
|
2013-02-22 17:23:46 +01:00
|
|
|
Misc.dropItems(location, dropItem, minimumDropAmount);
|
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-02-22 17:23:46 +01:00
|
|
|
Users.getPlayer(player).beginXpGain(SkillType.HERBALISM, xp);
|
|
|
|
return update;
|
2012-01-09 20:00:13 +01:00
|
|
|
}
|
2012-03-10 19:03:31 +01:00
|
|
|
|
|
|
|
/**
|
2013-02-22 17:23:46 +01:00
|
|
|
* Convert plants affected by the Green Terra ability.
|
2012-03-10 19:03:31 +01:00
|
|
|
*
|
2013-02-22 17:23:46 +01:00
|
|
|
* @param blockState The {@link BlockState} to check ability activation for
|
|
|
|
* @return true if the ability was successful, false otherwise
|
2012-03-10 19:03:31 +01:00
|
|
|
*/
|
2013-02-22 17:23:46 +01:00
|
|
|
private static boolean convertGreenTerraPlants(BlockState blockState) {
|
|
|
|
switch (blockState.getType()) {
|
2012-11-10 01:37:12 +01:00
|
|
|
case CROPS:
|
|
|
|
case CARROT:
|
|
|
|
case POTATO:
|
2013-02-22 17:23:46 +01:00
|
|
|
blockState.setRawData(CropState.MEDIUM.getData());
|
|
|
|
return true;
|
|
|
|
|
2012-11-10 01:37:12 +01:00
|
|
|
case NETHER_WARTS:
|
2013-02-22 17:23:46 +01:00
|
|
|
blockState.setRawData((byte) 0x2);
|
|
|
|
return true;
|
|
|
|
|
|
|
|
case COCOA:
|
|
|
|
CocoaPlant plant = (CocoaPlant) blockState.getData();
|
|
|
|
plant.setSize(CocoaPlantSize.MEDIUM);
|
|
|
|
blockState.setData(plant);
|
|
|
|
return true;
|
|
|
|
|
2012-12-24 18:35:17 +01:00
|
|
|
default:
|
2013-02-22 17:23:46 +01:00
|
|
|
return false;
|
2012-11-10 01:37:12 +01:00
|
|
|
}
|
2013-02-22 17:23:46 +01:00
|
|
|
}
|
2012-03-10 19:03:31 +01:00
|
|
|
|
2013-02-22 17:23:46 +01:00
|
|
|
/**
|
|
|
|
* Process the Green Thumb ability for blocks.
|
|
|
|
*
|
|
|
|
* @param blockState The {@link BlockState} to check ability activation for
|
|
|
|
* @param player The {@link Player} using this ability
|
|
|
|
* @return true if the ability was successful, false otherwise
|
|
|
|
*/
|
|
|
|
public static boolean processGreenThumbBlocks(BlockState blockState, Player player) {
|
|
|
|
if (!SkillTools.activationSuccessful(player, SkillType.HERBALISM, greenThumbMaxChance, greenThumbMaxLevel)) {
|
|
|
|
player.sendMessage(LocaleLoader.getString("Herbalism.Ability.GTh.Fail"));
|
|
|
|
return false;
|
2013-02-16 03:42:56 +01:00
|
|
|
}
|
|
|
|
|
2013-02-22 17:23:46 +01:00
|
|
|
return convertGreenTerraBlocks(blockState, player);
|
|
|
|
}
|
2012-07-02 17:09:55 +02:00
|
|
|
|
2013-02-22 17:23:46 +01:00
|
|
|
/**
|
|
|
|
* Convert plants affected by the Green Thumb ability.
|
|
|
|
*
|
|
|
|
* @param blockState The {@link BlockState} to check ability activation for
|
|
|
|
* @param skillLevel The player's Herbalism skill level
|
|
|
|
* @return true if the ability was successful, false otherwise
|
|
|
|
*/
|
|
|
|
private static boolean convertGreenThumbPlants(BlockState blockState, int skillLevel) {
|
|
|
|
int greenThumbStage = Math.min(skillLevel, greenThumbStageMaxLevel) / 4;
|
2013-01-02 01:27:50 +01:00
|
|
|
|
2013-02-22 17:23:46 +01:00
|
|
|
switch(blockState.getType()) {
|
|
|
|
case CROPS:
|
|
|
|
case CARROT:
|
|
|
|
case POTATO:
|
|
|
|
blockState.setRawData((byte) greenThumbStage);
|
|
|
|
return true;
|
|
|
|
|
|
|
|
case NETHER_WARTS:
|
|
|
|
if (greenThumbStage > 2) {
|
|
|
|
blockState.setRawData((byte) 0x2);
|
2012-11-10 01:37:12 +01:00
|
|
|
}
|
2013-02-22 17:23:46 +01:00
|
|
|
else if (greenThumbStage == 2) {
|
|
|
|
blockState.setRawData((byte) 0x1);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
blockState.setRawData((byte) 0x0);
|
|
|
|
}
|
|
|
|
return true;
|
2012-03-10 19:03:31 +01:00
|
|
|
|
2013-02-22 17:23:46 +01:00
|
|
|
case COCOA:
|
|
|
|
CocoaPlant plant = (CocoaPlant) blockState.getData();
|
|
|
|
|
|
|
|
if (greenThumbStage > 1) {
|
|
|
|
plant.setSize(CocoaPlantSize.MEDIUM);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
plant.setSize(CocoaPlantSize.SMALL);
|
|
|
|
}
|
|
|
|
blockState.setData(plant);
|
|
|
|
return true;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return false;
|
2012-03-10 19:03:31 +01:00
|
|
|
}
|
2012-01-09 20:00:13 +01:00
|
|
|
}
|
2012-03-11 04:21:53 +01:00
|
|
|
|
|
|
|
/**
|
2013-02-22 17:23:46 +01:00
|
|
|
* Process the Green Thumb ability for plants.
|
2012-03-11 04:21:53 +01:00
|
|
|
*
|
2013-02-22 17:23:46 +01:00
|
|
|
* @param blockState The {@link BlockState} to check ability activation for
|
|
|
|
* @param player The {@link Player} using this ability
|
|
|
|
* @return true if the ability was successful, false otherwise
|
2012-03-11 04:21:53 +01:00
|
|
|
*/
|
2013-02-22 17:23:46 +01:00
|
|
|
private static boolean processGreenThumbPlants(BlockState blockState, Player player) {
|
|
|
|
PlayerProfile playerProfile = Users.getPlayer(player).getProfile();
|
2012-07-02 17:09:55 +02:00
|
|
|
|
2013-02-22 17:23:46 +01:00
|
|
|
if (playerProfile.getAbilityMode(AbilityType.GREEN_TERRA)) {
|
|
|
|
return convertGreenTerraPlants(blockState);
|
2012-03-11 04:21:53 +01:00
|
|
|
}
|
2013-02-22 17:23:46 +01:00
|
|
|
else if (SkillTools.activationSuccessful(player, SkillType.HERBALISM, greenThumbMaxChance, greenThumbMaxLevel)) {
|
2013-02-24 20:04:54 +01:00
|
|
|
PlayerInventory playerInventory = player.getInventory();
|
|
|
|
ItemStack seed = HerbalismBlock.getHerbalismBlock(blockState.getType()).getDropItem();
|
|
|
|
|
|
|
|
if (!playerInventory.containsAtLeast(seed, 1)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-02-22 17:23:46 +01:00
|
|
|
playerInventory.removeItem(seed);
|
|
|
|
player.updateInventory(); // Needed until replacement available
|
|
|
|
|
|
|
|
return convertGreenThumbPlants(blockState, playerProfile.getSkillLevel(SkillType.HERBALISM));
|
2012-03-11 04:21:53 +01:00
|
|
|
}
|
2013-02-22 17:23:46 +01:00
|
|
|
|
|
|
|
return false;
|
2012-03-11 04:21:53 +01:00
|
|
|
}
|
2013-01-19 18:33:57 +01:00
|
|
|
|
2013-02-22 17:23:46 +01:00
|
|
|
/**
|
|
|
|
* Process the Hylian Luck ability.
|
|
|
|
*
|
|
|
|
* @param blockState The {@link BlockState} to check ability activation for
|
|
|
|
* @param player The {@link Player} using this ability
|
|
|
|
* @return true if the ability was successful, false otherwise
|
|
|
|
*/
|
|
|
|
public static boolean processHylianLuck(BlockState blockState, Player player) {
|
|
|
|
if (!SkillTools.activationSuccessful(player, SkillType.HERBALISM, hylianLuckMaxChance, hylianLuckMaxLevel)) {
|
|
|
|
return false;
|
|
|
|
}
|
2013-01-22 07:52:34 +01:00
|
|
|
|
2013-02-22 17:23:46 +01:00
|
|
|
List<HylianTreasure> treasures = new ArrayList<HylianTreasure>();
|
2013-01-19 18:33:57 +01:00
|
|
|
|
2013-02-22 17:23:46 +01:00
|
|
|
switch (blockState.getType()) {
|
|
|
|
case DEAD_BUSH:
|
|
|
|
case LONG_GRASS:
|
|
|
|
case SAPLING:
|
|
|
|
treasures = TreasuresConfig.getInstance().hylianFromBushes;
|
|
|
|
break;
|
2013-01-19 18:33:57 +01:00
|
|
|
|
2013-02-22 17:23:46 +01:00
|
|
|
case RED_ROSE:
|
|
|
|
case YELLOW_FLOWER:
|
|
|
|
if (mcMMO.placeStore.isTrue(blockState)) {
|
|
|
|
mcMMO.placeStore.setFalse(blockState);
|
|
|
|
return false;
|
|
|
|
}
|
2013-01-19 18:33:57 +01:00
|
|
|
|
2013-02-22 17:23:46 +01:00
|
|
|
treasures = TreasuresConfig.getInstance().hylianFromFlowers;
|
|
|
|
break;
|
2013-01-25 18:33:48 +01:00
|
|
|
|
2013-02-22 17:23:46 +01:00
|
|
|
case FLOWER_POT:
|
|
|
|
treasures = TreasuresConfig.getInstance().hylianFromPots;
|
|
|
|
break;
|
2013-01-19 18:33:57 +01:00
|
|
|
|
2013-02-22 17:23:46 +01:00
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
2013-01-19 18:33:57 +01:00
|
|
|
|
2013-02-22 17:23:46 +01:00
|
|
|
if (treasures.isEmpty()) {
|
|
|
|
return false;
|
|
|
|
}
|
2013-01-19 18:33:57 +01:00
|
|
|
|
2013-02-22 17:23:46 +01:00
|
|
|
blockState.setRawData((byte) 0x0);
|
|
|
|
blockState.setType(Material.AIR);
|
2013-01-29 17:24:41 +01:00
|
|
|
|
2013-02-22 17:23:46 +01:00
|
|
|
Misc.dropItem(blockState.getLocation(), treasures.get(Misc.getRandom().nextInt(treasures.size())).getDrop());
|
|
|
|
player.sendMessage(LocaleLoader.getString("Herbalism.HylianLuck"));
|
|
|
|
return true;
|
2013-01-19 18:33:57 +01:00
|
|
|
}
|
2012-10-31 04:12:43 +01:00
|
|
|
}
|