Added "Shroom Thumb" ability to Herbalism. Closes #724

This commit is contained in:
GJ
2013-02-25 09:58:25 -05:00
parent 3bd9a30055
commit 2373ca82ba
10 changed files with 124 additions and 2 deletions

View File

@ -111,6 +111,9 @@ public class AdvancedConfig extends AutoUpdateConfigLoader {
public double getHylianLuckChanceMax() { return config.getDouble("Skills.Herbalism.HylianLuck_ChanceMax", 10.0D); }
public int getHylianLuckMaxLevel() { return config.getInt("Skills.Herbalism.HylianLuck_MaxBonusLevel", 1000); }
public double getShroomThumbChanceMax() { return config.getDouble("Skills.Herbalism.ShroomThumb_ChanceMax", 50.0D); }
public int getShroomThumbMaxLevel() { return config.getInt("Skills.Herbalism.ShroomThumb_MaxBonusLevel", 1500); }
/* MINING */
public double getMiningDoubleDropChance() { return config.getDouble("Skills.Mining.DoubleDrops_ChanceMax", 100.0D); }
public int getMiningDoubleDropMaxLevel() { return config.getInt("Skills.Mining.DoubleDrops_MaxBonusLevel", 1000); }

View File

@ -363,6 +363,12 @@ public class PlayerListener implements Listener {
}
}
/* SHROOM THUMB CHECK */
else if (BlockChecks.canMakeShroomy(blockState)) {
if (Herbalism.processGreenThumbBlocks(blockState, player) && SkillTools.blockBreakSimulate(block, player, false)) {
blockState.update(true);
}
}
break;
case RIGHT_CLICK_AIR:

View File

@ -27,6 +27,7 @@ import com.gmail.nossr50.skills.utilities.SkillTools;
import com.gmail.nossr50.skills.utilities.SkillType;
import com.gmail.nossr50.util.Misc;
import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.StringUtils;
import com.gmail.nossr50.util.Users;
public class Herbalism {
@ -46,6 +47,9 @@ public class Herbalism {
public static double hylianLuckMaxChance = AdvancedConfig.getInstance().getHylianLuckChanceMax();
public static int hylianLuckMaxLevel = AdvancedConfig.getInstance().getHylianLuckMaxLevel();
public static double shroomThumbMaxChance = AdvancedConfig.getInstance().getShroomThumbChanceMax();
public static int shroomThumbMaxLevel = AdvancedConfig.getInstance().getShroomThumbMaxLevel();
/**
* Handle the farmers diet skill.
*
@ -314,4 +318,59 @@ public class Herbalism {
player.sendMessage(LocaleLoader.getString("Herbalism.HylianLuck"));
return true;
}
/**
* Process the Shroom Thumb 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 processShroomThumb(BlockState blockState, Player player) {
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();
if (!SkillTools.activationSuccessful(player, SkillType.HERBALISM, shroomThumbMaxChance, shroomThumbMaxLevel)) {
player.sendMessage(LocaleLoader.getString("Herbalism.Ability.ShroomThumb.Fail"));
return false;
}
return convertShroomThumb(blockState, player);
}
/**
* 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 convertShroomThumb(BlockState blockState, Player player) {
if (!Permissions.shroomThumb(player)) {
return false;
}
switch (blockState.getType()){
case DIRT:
case GRASS:
blockState.setType(Material.MYCEL);
return true;
default:
return false;
}
}
}

View File

@ -18,6 +18,8 @@ public class HerbalismCommand extends SkillCommand {
private String doubleDropChanceLucky;
private String hylianLuckChance;
private String hylianLuckChanceLucky;
private String shroomThumbChance;
private String shroomThumbChanceLucky;
private boolean hasHylianLuck;
private boolean canGreenTerra;
@ -25,6 +27,7 @@ public class HerbalismCommand extends SkillCommand {
private boolean canGreenThumbBlocks;
private boolean canFarmersDiet;
private boolean canDoubleDrop;
private boolean canShroomThumb;
private boolean doubleDropsDisabled;
public HerbalismCommand() {
@ -57,6 +60,11 @@ public class HerbalismCommand extends SkillCommand {
String[] hylianLuckStrings = calculateAbilityDisplayValues(Herbalism.hylianLuckMaxLevel, Herbalism.hylianLuckMaxChance);
hylianLuckChance = hylianLuckStrings[0];
hylianLuckChanceLucky = hylianLuckStrings[1];
//SHROOM THUMB
String[] shroomThumbStrings = calculateAbilityDisplayValues(Herbalism.shroomThumbMaxLevel, Herbalism.shroomThumbMaxChance);
shroomThumbChance = shroomThumbStrings[0];
shroomThumbChanceLucky = shroomThumbStrings[1];
}
@Override
@ -68,11 +76,12 @@ public class HerbalismCommand extends SkillCommand {
canFarmersDiet = Permissions.farmersDiet(player);
canDoubleDrop = Permissions.doubleDrops(player, skill);
doubleDropsDisabled = skill.getDoubleDropsDisabled();
canShroomThumb = Permissions.shroomThumb(player);
}
@Override
protected boolean effectsHeaderPermissions() {
return canGreenTerra || (canDoubleDrop && !doubleDropsDisabled) || canFarmersDiet || canGreenThumbBlocks || canGreenThumbWheat;
return canGreenTerra || (canDoubleDrop && !doubleDropsDisabled) || canFarmersDiet || canGreenThumbBlocks || canGreenThumbWheat || canShroomThumb;
}
@Override
@ -99,6 +108,10 @@ public class HerbalismCommand extends SkillCommand {
player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Herbalism.Effect.10"), LocaleLoader.getString("Herbalism.Effect.11")));
}
if (canShroomThumb) {
player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Herbalism.Effect.12"), LocaleLoader.getString("Herbalism.Effect.13")));
}
if (canDoubleDrop && !doubleDropsDisabled) {
player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Herbalism.Effect.8"), LocaleLoader.getString("Herbalism.Effect.9")));
}
@ -106,7 +119,7 @@ public class HerbalismCommand extends SkillCommand {
@Override
protected boolean statsHeaderPermissions() {
return canGreenTerra || (canDoubleDrop && !doubleDropsDisabled) || canFarmersDiet || canGreenThumbBlocks || canGreenThumbWheat;
return canGreenTerra || (canDoubleDrop && !doubleDropsDisabled) || canFarmersDiet || canGreenThumbBlocks || canGreenThumbWheat || canShroomThumb;
}
@Override
@ -145,6 +158,16 @@ public class HerbalismCommand extends SkillCommand {
player.sendMessage(LocaleLoader.getString("Herbalism.Ability.HylianLuck", hylianLuckChance));
}
}
if (canShroomThumb) {
if (isLucky) {
player.sendMessage(LocaleLoader.getString("Herbalism.Ability.ShroomThumb.Chance", shroomThumbChance) + LocaleLoader.getString("Perks.lucky.bonus", shroomThumbChanceLucky));
}
else {
player.sendMessage(LocaleLoader.getString("Herbalism.Ability.ShroomThumb.Chance", shroomThumbChance));
}
}
if (canDoubleDrop && !doubleDropsDisabled) {
if (isLucky) {
player.sendMessage(LocaleLoader.getString("Herbalism.Ability.DoubleDropChance", doubleDropChance) + LocaleLoader.getString("Perks.lucky.bonus", doubleDropChanceLucky));

View File

@ -345,4 +345,21 @@ public final class BlockChecks {
return false;
}
}
/**
* Determine if a given block can be made into Mycelium
*
* @param blockState The {@link BlockState} of the block to check
* @return true if the block can be made in Mycelium, false otherwise
*/
public static boolean canMakeShroomy(BlockState blockState) {
switch (blockState.getType()) {
case DIRT:
case GRASS:
return true;
default:
return false;
}
}
}

View File

@ -146,6 +146,7 @@ public final class Permissions {
public static boolean greenThumbBlock(Permissible permissible, Material material) { return permissible.hasPermission("mcmmo.ability.herbalism.greenthumb.blocks." + material.toString().replace("_", "").toLowerCase()); }
public static boolean greenThumbPlant(Permissible permissible, Material material) { return permissible.hasPermission("mcmmo.ability.herbalism.greenthumb.plants." + material.toString().replace("_", "").toLowerCase()); }
public static boolean hylianLuck(Permissible permissible) { return permissible.hasPermission("mcmmo.ability.herbalism.hylianluck"); }
public static boolean shroomThumb(Permissible permissible) { return permissible.hasPermission("mcmmo.ability.herbalism.shroomthumb"); }
/* MINING */
public static boolean biggerBombs(Permissible permissible) { return permissible.hasPermission("mcmmo.ability.mining.blastmining.biggerbombs"); }