2013-03-01 06:52:01 +01:00
|
|
|
package com.gmail.nossr50.skills.herbalism;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
|
|
|
|
2013-03-08 10:11:33 +01:00
|
|
|
import org.bukkit.CropState;
|
2013-03-01 06:52:01 +01:00
|
|
|
import org.bukkit.Material;
|
|
|
|
import org.bukkit.block.BlockState;
|
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
import org.bukkit.inventory.ItemStack;
|
|
|
|
import org.bukkit.inventory.PlayerInventory;
|
2013-03-08 10:11:33 +01:00
|
|
|
import org.bukkit.material.CocoaPlant;
|
|
|
|
import org.bukkit.material.CocoaPlant.CocoaPlantSize;
|
2013-03-01 06:52:01 +01:00
|
|
|
|
|
|
|
import com.gmail.nossr50.mcMMO;
|
|
|
|
import com.gmail.nossr50.config.Config;
|
|
|
|
import com.gmail.nossr50.config.treasure.TreasureConfig;
|
|
|
|
import com.gmail.nossr50.datatypes.mods.CustomBlock;
|
|
|
|
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
|
|
|
|
import com.gmail.nossr50.datatypes.skills.AbilityType;
|
|
|
|
import com.gmail.nossr50.datatypes.skills.SkillType;
|
|
|
|
import com.gmail.nossr50.datatypes.skills.ToolType;
|
|
|
|
import com.gmail.nossr50.datatypes.treasure.HylianTreasure;
|
|
|
|
import com.gmail.nossr50.locale.LocaleLoader;
|
2013-03-08 10:11:33 +01:00
|
|
|
import com.gmail.nossr50.runnables.skills.HerbalismBlockUpdaterTask;
|
2013-03-01 06:52:01 +01:00
|
|
|
import com.gmail.nossr50.skills.SkillManager;
|
|
|
|
import com.gmail.nossr50.util.BlockUtils;
|
|
|
|
import com.gmail.nossr50.util.Misc;
|
|
|
|
import com.gmail.nossr50.util.ModUtils;
|
|
|
|
import com.gmail.nossr50.util.Permissions;
|
|
|
|
import com.gmail.nossr50.util.StringUtils;
|
|
|
|
import com.gmail.nossr50.util.skills.SkillUtils;
|
|
|
|
|
|
|
|
public class HerbalismManager extends SkillManager {
|
|
|
|
public HerbalismManager(McMMOPlayer mcMMOPlayer) {
|
|
|
|
super(mcMMOPlayer, SkillType.HERBALISM);
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean canBlockCheck() {
|
|
|
|
return !(Config.getInstance().getHerbalismAFKDisabled() && getPlayer().isInsideVehicle());
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean canGreenThumbBlock(BlockState blockState) {
|
|
|
|
Player player = getPlayer();
|
|
|
|
|
|
|
|
return player.getItemInHand().getType() == Material.SEEDS && BlockUtils.canMakeMossy(blockState) && Permissions.greenThumbBlock(player, blockState.getType());
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean canUseShroomThumb(BlockState blockState) {
|
|
|
|
Player player = getPlayer();
|
|
|
|
Material itemType = player.getItemInHand().getType();
|
|
|
|
|
|
|
|
return (itemType == Material.RED_MUSHROOM || itemType == Material.BROWN_MUSHROOM) && BlockUtils.canMakeShroomy(blockState) && Permissions.shroomThumb(player);
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean canUseHylianLuck() {
|
2013-03-04 15:40:03 +01:00
|
|
|
return Permissions.hylianLuck(getPlayer());
|
2013-03-01 06:52:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public boolean canGreenTerraBlock(BlockState blockState) {
|
2013-03-03 17:06:05 +01:00
|
|
|
return mcMMOPlayer.getAbilityMode(AbilityType.GREEN_TERRA) && BlockUtils.canMakeMossy(blockState);
|
2013-03-01 06:52:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public boolean canActivateAbility() {
|
2013-03-03 17:06:05 +01:00
|
|
|
return mcMMOPlayer.getToolPreparationMode(ToolType.HOE) && Permissions.greenTerra(getPlayer());
|
2013-03-01 06:52:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public boolean canGreenTerraPlant() {
|
2013-03-03 17:06:05 +01:00
|
|
|
return mcMMOPlayer.getAbilityMode(AbilityType.GREEN_TERRA);
|
2013-03-01 06:52:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle the Farmer's Diet ability
|
|
|
|
*
|
|
|
|
* @param rankChange The # of levels to change rank for the food
|
|
|
|
* @param eventFoodLevel The initial change in hunger from the event
|
|
|
|
* @return the modified change in hunger for the event
|
|
|
|
*/
|
|
|
|
public int farmersDiet(int rankChange, int eventFoodLevel) {
|
2013-03-08 10:33:20 +01:00
|
|
|
return SkillUtils.handleFoodSkills(getPlayer(), skill, eventFoodLevel, Herbalism.farmersDietRankLevel1, Herbalism.farmersDietMaxLevel, rankChange);
|
2013-03-01 06:52:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Process the Green Terra ability.
|
|
|
|
*
|
|
|
|
* @param blockState The {@link BlockState} to check ability activation for
|
|
|
|
* @return true if the ability was successful, false otherwise
|
|
|
|
*/
|
|
|
|
public boolean processGreenTerra(BlockState blockState) {
|
|
|
|
Player player = getPlayer();
|
|
|
|
|
|
|
|
if (!Permissions.greenThumbBlock(player, blockState.getType())) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
PlayerInventory playerInventory = player.getInventory();
|
|
|
|
ItemStack seed = new ItemStack(Material.SEEDS);
|
|
|
|
|
|
|
|
if (!playerInventory.containsAtLeast(seed, 1)) {
|
|
|
|
player.sendMessage(LocaleLoader.getString("Herbalism.Ability.GTe.NeedMore"));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
playerInventory.removeItem(seed);
|
|
|
|
player.updateInventory(); // Needed until replacement available
|
|
|
|
|
|
|
|
return Herbalism.convertGreenTerraBlocks(blockState);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-03-08 10:11:33 +01:00
|
|
|
*
|
2013-03-01 06:52:01 +01:00
|
|
|
*
|
|
|
|
* @param blockState The {@link BlockState} to check ability activation for
|
|
|
|
*/
|
|
|
|
public void herbalismBlockCheck(BlockState blockState) {
|
2013-03-08 14:53:54 +01:00
|
|
|
Material material = blockState.getType();
|
2013-03-08 19:33:03 +01:00
|
|
|
boolean oneBlockPlant = (material == Material.CACTUS || material == Material.SUGAR_CANE_BLOCK) ? false : true;
|
2013-03-08 14:53:54 +01:00
|
|
|
|
2013-03-08 19:33:03 +01:00
|
|
|
if (oneBlockPlant && mcMMO.placeStore.isTrue(blockState)) {
|
2013-03-08 10:11:33 +01:00
|
|
|
return;
|
|
|
|
}
|
2013-03-01 06:52:01 +01:00
|
|
|
|
2013-03-08 10:11:33 +01:00
|
|
|
HerbalismBlock herbalismBlock = HerbalismBlock.getHerbalismBlock(material);
|
|
|
|
ItemStack drop = null;
|
|
|
|
int amount = 1;
|
2013-03-01 06:52:01 +01:00
|
|
|
int xp = 0;
|
2013-03-08 10:35:52 +01:00
|
|
|
boolean greenTerra = mcMMOPlayer.getAbilityMode(skill.getAbility());
|
2013-03-01 06:52:01 +01:00
|
|
|
|
|
|
|
if (herbalismBlock != null) {
|
2013-03-08 10:11:33 +01:00
|
|
|
if (herbalismBlock.hasGreenThumbPermission(getPlayer())) {
|
|
|
|
processGreenThumbPlants(blockState, greenTerra);
|
2013-03-01 06:52:01 +01:00
|
|
|
}
|
2013-03-08 10:11:33 +01:00
|
|
|
|
|
|
|
xp = herbalismBlock.getXpGain();
|
|
|
|
|
|
|
|
if (herbalismBlock.canDoubleDrop() && Permissions.doubleDrops(getPlayer(), skill)) {
|
|
|
|
drop = herbalismBlock.getDropItem();
|
2013-03-01 06:52:01 +01:00
|
|
|
}
|
2013-03-08 10:11:33 +01:00
|
|
|
|
2013-03-08 19:33:03 +01:00
|
|
|
if (!oneBlockPlant) {
|
2013-03-08 10:11:33 +01:00
|
|
|
amount = Herbalism.calculateCatciAndSugarDrops(blockState);
|
|
|
|
xp *= amount;
|
2013-03-01 06:52:01 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2013-03-08 10:11:33 +01:00
|
|
|
CustomBlock customBlock = ModUtils.getCustomBlock(blockState);
|
2013-03-01 06:52:01 +01:00
|
|
|
xp = customBlock.getXpGain();
|
|
|
|
|
2013-03-08 10:11:33 +01:00
|
|
|
if (Permissions.doubleDrops(getPlayer(), skill)) {
|
2013-03-01 06:52:01 +01:00
|
|
|
int minimumDropAmount = customBlock.getMinimumDropAmount();
|
|
|
|
int maximumDropAmount = customBlock.getMaximumDropAmount();
|
2013-03-08 10:11:33 +01:00
|
|
|
drop = customBlock.getItemDrop();
|
|
|
|
amount = Misc.getRandom().nextInt(maximumDropAmount - minimumDropAmount + 1) + minimumDropAmount;
|
2013-03-01 06:52:01 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
applyXpGain(xp);
|
2013-03-08 10:11:33 +01:00
|
|
|
|
|
|
|
if (drop == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = greenTerra ? 2 : 1; i != 0; i--) {
|
|
|
|
if (SkillUtils.activationSuccessful(getSkillLevel(), getActivationChance(), Herbalism.doubleDropsMaxChance, Herbalism.doubleDropsMaxLevel)) {
|
|
|
|
Misc.dropItems(blockState.getLocation(), drop, amount);
|
|
|
|
}
|
|
|
|
}
|
2013-03-01 06:52:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Process the Green Thumb ability for blocks.
|
|
|
|
*
|
|
|
|
* @param blockState The {@link BlockState} to check ability activation for
|
|
|
|
* @return true if the ability was successful, false otherwise
|
|
|
|
*/
|
|
|
|
public boolean processGreenThumbBlocks(BlockState blockState) {
|
2013-03-04 15:40:03 +01:00
|
|
|
if (!SkillUtils.activationSuccessful(getSkillLevel(), getActivationChance(), Herbalism.greenThumbMaxChance, Herbalism.greenThumbMaxLevel)) {
|
|
|
|
getPlayer().sendMessage(LocaleLoader.getString("Herbalism.Ability.GTh.Fail"));
|
2013-03-01 06:52:01 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return Herbalism.convertGreenTerraBlocks(blockState);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Process the Hylian Luck ability.
|
|
|
|
*
|
|
|
|
* @param blockState The {@link BlockState} to check ability activation for
|
|
|
|
* @return true if the ability was successful, false otherwise
|
|
|
|
*/
|
|
|
|
public boolean processHylianLuck(BlockState blockState) {
|
2013-03-04 15:40:03 +01:00
|
|
|
if (!SkillUtils.activationSuccessful(getSkillLevel(), getActivationChance(), Herbalism.hylianLuckMaxChance, Herbalism.hylianLuckMaxLevel)) {
|
2013-03-01 06:52:01 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
List<HylianTreasure> treasures = new ArrayList<HylianTreasure>();
|
|
|
|
|
|
|
|
switch (blockState.getType()) {
|
|
|
|
case DEAD_BUSH:
|
|
|
|
case LONG_GRASS:
|
|
|
|
case SAPLING:
|
|
|
|
treasures = TreasureConfig.getInstance().hylianFromBushes;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case RED_ROSE:
|
|
|
|
case YELLOW_FLOWER:
|
|
|
|
if (mcMMO.placeStore.isTrue(blockState)) {
|
|
|
|
mcMMO.placeStore.setFalse(blockState);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
treasures = TreasureConfig.getInstance().hylianFromFlowers;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case FLOWER_POT:
|
|
|
|
treasures = TreasureConfig.getInstance().hylianFromPots;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (treasures.isEmpty()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
blockState.setRawData((byte) 0x0);
|
|
|
|
blockState.setType(Material.AIR);
|
|
|
|
|
|
|
|
Misc.dropItem(blockState.getLocation(), treasures.get(Misc.getRandom().nextInt(treasures.size())).getDrop());
|
2013-03-04 15:40:03 +01:00
|
|
|
getPlayer().sendMessage(LocaleLoader.getString("Herbalism.HylianLuck"));
|
2013-03-01 06:52:01 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Process the Shroom Thumb ability.
|
|
|
|
*
|
|
|
|
* @param blockState The {@link BlockState} to check ability activation for
|
|
|
|
* @return true if the ability was successful, false otherwise
|
|
|
|
*/
|
|
|
|
public boolean processShroomThumb(BlockState blockState) {
|
|
|
|
Player player = getPlayer();
|
|
|
|
PlayerInventory playerInventory = player.getInventory();
|
|
|
|
|
|
|
|
if (!playerInventory.contains(Material.BROWN_MUSHROOM)) {
|
|
|
|
player.sendMessage(LocaleLoader.getString("Skills.NeedMore", StringUtils.getPrettyItemString(Material.BROWN_MUSHROOM)));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!playerInventory.contains(Material.RED_MUSHROOM)) {
|
|
|
|
player.sendMessage(LocaleLoader.getString("Skills.NeedMore", StringUtils.getPrettyItemString(Material.RED_MUSHROOM)));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
playerInventory.removeItem(new ItemStack(Material.BROWN_MUSHROOM));
|
|
|
|
playerInventory.removeItem(new ItemStack(Material.RED_MUSHROOM));
|
|
|
|
player.updateInventory();
|
|
|
|
|
2013-03-04 15:40:03 +01:00
|
|
|
if (!SkillUtils.activationSuccessful(getSkillLevel(), getActivationChance(), Herbalism.shroomThumbMaxChance, Herbalism.shroomThumbMaxLevel)) {
|
2013-03-01 06:52:01 +01:00
|
|
|
player.sendMessage(LocaleLoader.getString("Herbalism.Ability.ShroomThumb.Fail"));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return Herbalism.convertShroomThumb(blockState);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Process the Green Thumb ability for plants.
|
|
|
|
*
|
|
|
|
* @param blockState The {@link BlockState} to check ability activation for
|
2013-03-08 10:11:33 +01:00
|
|
|
* @param greenTerra
|
2013-03-01 06:52:01 +01:00
|
|
|
*/
|
2013-03-08 10:11:33 +01:00
|
|
|
private void processGreenThumbPlants(BlockState blockState, boolean greenTerra) {
|
2013-03-01 06:52:01 +01:00
|
|
|
Player player = getPlayer();
|
|
|
|
PlayerInventory playerInventory = player.getInventory();
|
2013-03-08 10:11:33 +01:00
|
|
|
ItemStack seed = (blockState.getType() == Material.CROPS) ? new ItemStack(Material.SEEDS) : HerbalismBlock.getHerbalismBlock(blockState.getType()).getDropItem();
|
2013-03-01 06:52:01 +01:00
|
|
|
|
|
|
|
if (!playerInventory.containsAtLeast(seed, 1)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-03-08 10:11:33 +01:00
|
|
|
if (!greenTerra && !SkillUtils.activationSuccessful(getSkillLevel(), getActivationChance(), Herbalism.greenThumbMaxChance, Herbalism.greenThumbMaxLevel)) {
|
2013-03-01 06:52:01 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-03-08 10:11:33 +01:00
|
|
|
if (!handleBlockState(blockState, greenTerra)) {
|
2013-03-01 06:52:01 +01:00
|
|
|
return;
|
|
|
|
}
|
2013-03-08 10:11:33 +01:00
|
|
|
|
|
|
|
playerInventory.removeItem(seed);
|
|
|
|
player.updateInventory(); // Needed until replacement available
|
2013-03-20 08:11:16 +01:00
|
|
|
new HerbalismBlockUpdaterTask(blockState).runTaskLater(mcMMO.p, 0);
|
2013-03-08 10:11:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private boolean handleBlockState(BlockState blockState, boolean greenTerra) {
|
|
|
|
switch (blockState.getType()) {
|
|
|
|
case CROPS:
|
|
|
|
case CARROT:
|
|
|
|
case POTATO:
|
|
|
|
if (greenTerra) {
|
|
|
|
blockState.setRawData(CropState.MEDIUM.getData()); // 2
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
blockState.setRawData(getGreenThumbStage());
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
case NETHER_WARTS:
|
|
|
|
if (greenTerra) {
|
|
|
|
blockState.setRawData((byte) 2);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
int greenThumbStage = getGreenThumbStage();
|
|
|
|
|
|
|
|
if (greenThumbStage > 2) {
|
|
|
|
blockState.setRawData((byte) 2);
|
|
|
|
}
|
|
|
|
else if (greenThumbStage == 2) {
|
|
|
|
blockState.setRawData((byte) 1);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
blockState.setRawData((byte) 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
case COCOA:
|
|
|
|
CocoaPlant plant = (CocoaPlant) blockState.getData();
|
|
|
|
|
|
|
|
if (greenTerra || getGreenThumbStage() > 1) {
|
|
|
|
plant.setSize(CocoaPlantSize.MEDIUM);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
plant.setSize(CocoaPlantSize.SMALL);
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private byte getGreenThumbStage() {
|
2013-03-08 10:33:20 +01:00
|
|
|
return (byte) Math.min(Math.min(getProfile().getSkillLevel(skill), Herbalism.greenThumbStageMaxLevel) / Herbalism.greenThumbStageChangeLevel, 4);
|
2013-03-01 06:52:01 +01:00
|
|
|
}
|
|
|
|
}
|