From 5a9ca96a0fc844bbb0aa0e7dcca44cc3bbe20e48 Mon Sep 17 00:00:00 2001 From: GJ Date: Tue, 22 Jan 2013 01:52:34 -0500 Subject: [PATCH] Cleanup of HerbalismCommand, added config options for Hylian Luck --- Changelog.txt | 4 +- .../gmail/nossr50/commands/SkillCommand.java | 8 ++ .../commands/skills/FishingCommand.java | 10 +- .../commands/skills/HerbalismCommand.java | 103 +++++++----------- .../gmail/nossr50/config/AdvancedConfig.java | 7 +- .../nossr50/skills/gathering/Fishing.java | 3 + .../nossr50/skills/gathering/Herbalism.java | 40 ++++--- src/main/resources/advanced.yml | 11 +- 8 files changed, 89 insertions(+), 97 deletions(-) diff --git a/Changelog.txt b/Changelog.txt index 0f831a841..e88a4838c 100644 --- a/Changelog.txt +++ b/Changelog.txt @@ -9,10 +9,12 @@ Key: Version 1.4.00-dev + Added new cancellable McMMOPlayerDisarmEvent for Citizens compatibility - fires whenever a player is disarmed. + + Added config options for Hylian Luck skill = Fixed bug where Impact was applied incorrectly due to an inverted method call = Fixed bug where Impact improperly determined the defender's armor = Fixed ArrayIndexOutOfBoundsException resulting from being unranked in a skill when using FlatFile -! Changed how Tree Feller is handled, it should now put less stress on the CPU + ! Changed how Tree Feller is handled, it should now put less stress on the CPU + ! Changed Fisherman's Diet and Farmer's Diet to use two seperate config values Version 1.3.14 + Added new Hylian Luck skill to Herbalism. diff --git a/src/main/java/com/gmail/nossr50/commands/SkillCommand.java b/src/main/java/com/gmail/nossr50/commands/SkillCommand.java index 04efea1cd..a37efd593 100644 --- a/src/main/java/com/gmail/nossr50/commands/SkillCommand.java +++ b/src/main/java/com/gmail/nossr50/commands/SkillCommand.java @@ -81,6 +81,14 @@ public abstract class SkillCommand implements CommandExecutor { return true; } + protected String calculateRank(int maxLevel, int rankChangeLevel) { + if (skillValue >= maxLevel) { + return String.valueOf(maxLevel / rankChangeLevel); + } + + return String.valueOf((int) (skillValue / rankChangeLevel)); + } + protected String[] calculateAbilityDisplayValues(double chance) { if (isLucky) { double luckyChance = chance * 1.3333D; diff --git a/src/main/java/com/gmail/nossr50/commands/skills/FishingCommand.java b/src/main/java/com/gmail/nossr50/commands/skills/FishingCommand.java index 0759ca257..461175c68 100644 --- a/src/main/java/com/gmail/nossr50/commands/skills/FishingCommand.java +++ b/src/main/java/com/gmail/nossr50/commands/skills/FishingCommand.java @@ -19,9 +19,6 @@ public class FishingCommand extends SkillCommand { private String shakeChanceLucky; private String fishermansDietRank; - private int fishermansDietRankChange = AdvancedConfig.getInstance().getFarmerDietRankChange(); - private int fishermansDietRankMaxLevel = fishermansDietRankChange * 5; - private boolean canTreasureHunt; private boolean canMagicHunt; private boolean canShake; @@ -53,12 +50,7 @@ public class FishingCommand extends SkillCommand { shakeChanceLucky = shakeStrings[1]; //FISHERMAN'S DIET - if (skillValue >= fishermansDietRankMaxLevel) { - fishermansDietRank = "5"; - } - else { - fishermansDietRank = String.valueOf((int) (skillValue / fishermansDietRankChange)); - } + fishermansDietRank = calculateRank(Fishing.fishermanDietMaxLevel, Fishing.fishermanDietRankChangeLevel); } @Override diff --git a/src/main/java/com/gmail/nossr50/commands/skills/HerbalismCommand.java b/src/main/java/com/gmail/nossr50/commands/skills/HerbalismCommand.java index 2753f80cb..5df8a78f8 100644 --- a/src/main/java/com/gmail/nossr50/commands/skills/HerbalismCommand.java +++ b/src/main/java/com/gmail/nossr50/commands/skills/HerbalismCommand.java @@ -5,8 +5,8 @@ import com.gmail.nossr50.config.AdvancedConfig; import com.gmail.nossr50.config.Config; import com.gmail.nossr50.datatypes.SkillType; import com.gmail.nossr50.locale.LocaleLoader; +import com.gmail.nossr50.skills.gathering.Herbalism; import com.gmail.nossr50.util.Permissions; -import com.gmail.nossr50.util.Skills; public class HerbalismCommand extends SkillCommand { AdvancedConfig advancedConfig = AdvancedConfig.getInstance(); @@ -22,16 +22,6 @@ public class HerbalismCommand extends SkillCommand { private String hylianLuckChance; private String hylianLuckChanceLucky; - private int abilityLengthIncreaseLevel = advancedConfig.getAbilityLength(); - private int farmersDietRankChange = advancedConfig.getFarmerDietRankChange(); - private int farmersDietMaxLevel = farmersDietRankChange * 5; - private int greenThumbStageChange = advancedConfig.getGreenThumbStageChange(); - private int greenThumbStageMaxLevel = greenThumbStageChange * 4; - private double greenThumbMaxBonus = advancedConfig.getGreenThumbChanceMax(); - private int greenThumbMaxLevel = advancedConfig.getGreenThumbMaxLevel(); - private double doubleDropsMaxBonus = advancedConfig.getHerbalismDoubleDropsChanceMax(); - private int doubleDropsMaxLevel = advancedConfig.getHerbalismDoubleDropsMaxLevel(); - private boolean hasHylianLuck; private boolean canGreenTerra; private boolean canGreenThumbWheat; @@ -39,8 +29,6 @@ public class HerbalismCommand extends SkillCommand { private boolean canFarmersDiet; private boolean canDoubleDrop; private boolean doubleDropsDisabled; - private boolean lucky; - private boolean endurance; public HerbalismCommand() { super(SkillType.HERBALISM); @@ -48,50 +36,30 @@ public class HerbalismCommand extends SkillCommand { @Override protected void dataCalculations() { - float greenThumbChanceF; - float doubleDropChanceF; - float hylianLuckChanceF; + //GREEN TERRA + String[] greenTerraStrings = calculateLengthDisplayValues(); + greenTerraLength = greenTerraStrings[0]; + greenTerraLengthEndurance = greenTerraStrings[1]; - int length = 2 + (int) ((double) skillValue / (double) abilityLengthIncreaseLevel); - greenTerraLength = String.valueOf(length); - - if (Permissions.activationTwelve(player)) { - length = length + 12; - } - else if (Permissions.activationEight(player)) { - length = length + 8; - } - else if (Permissions.activationFour(player)) { - length = length + 4; - } - int maxLength = SkillType.HERBALISM.getAbility().getMaxTicks(); - if (maxLength != 0 && length > maxLength) { - length = maxLength; - } - greenTerraLengthEndurance = String.valueOf(length); //FARMERS DIET - if (skillValue >= farmersDietMaxLevel) farmersDietRank = "5"; - else farmersDietRank = String.valueOf((int) ((double) skillValue / (double) farmersDietRankChange)); - //GREEN THUMB - if (skillValue >= greenThumbStageMaxLevel) greenThumbStage = "4"; - else greenThumbStage = String.valueOf((int) ((double) skillValue / (double) greenThumbStageChange)); + farmersDietRank = calculateRank(Herbalism.farmersDietMaxLevel, Herbalism.farmersDietRankChangeLevel); + + //GREEN THUMB + greenThumbStage = calculateRank(Herbalism.greenThumbStageMaxLevel, Herbalism.greenThumbStageMaxLevel); + + String[] greenThumbStrings = calculateAbilityDisplayValues(Herbalism.greenThumbMaxLevel, Herbalism.greenThumbMaxChance); + greenThumbChance = greenThumbStrings[0]; + greenThumbChanceLucky = greenThumbStrings[1]; - if (skillValue >= greenThumbMaxLevel) greenThumbChanceF = (float) (greenThumbMaxBonus); - else greenThumbChanceF = (float) ((greenThumbMaxBonus / greenThumbMaxLevel) * skillValue); - greenThumbChance = percent.format(greenThumbChanceF / 100D); - if (greenThumbChanceF * 1.3333D >= 100D) greenThumbChanceLucky = percent.format(1D); - else greenThumbChanceLucky = percent.format(greenThumbChanceF * 1.3333D / 100D); //DOUBLE DROPS - if (skillValue >= doubleDropsMaxLevel) doubleDropChanceF = (float) (doubleDropsMaxBonus); - else doubleDropChanceF = (float) ((doubleDropsMaxBonus / doubleDropsMaxLevel) * skillValue); - doubleDropChance = percent.format(doubleDropChanceF / 100D); - if (doubleDropChanceF * 1.3333D >= 100D) doubleDropChanceLucky = percent.format(1D); - else doubleDropChanceLucky = percent.format(doubleDropChanceF * 1.3333D / 100D); + String[] doubleDropStrings = calculateAbilityDisplayValues(Herbalism.doubleDropsMaxLevel, Herbalism.doubleDropsMaxChance); + doubleDropChance = doubleDropStrings[0]; + doubleDropChanceLucky = doubleDropStrings[1]; + //HYLIAN LUCK - hylianLuckChanceF = (skillValue / 100); - hylianLuckChance = percent.format(hylianLuckChanceF / 100D); - if (hylianLuckChanceF * 1.3333D >= 100D) hylianLuckChanceLucky = percent.format(1D); - else hylianLuckChanceLucky = percent.format(hylianLuckChanceF * 1.3333D / 100D); + String[] hylianLuckStrings = calculateAbilityDisplayValues(Herbalism.hylianLuckMaxLevel, Herbalism.hylianLuckMaxChance); + hylianLuckChance = hylianLuckStrings[0]; + hylianLuckChanceLucky = hylianLuckStrings[1]; } @Override @@ -105,8 +73,6 @@ public class HerbalismCommand extends SkillCommand { canFarmersDiet = Permissions.farmersDiet(player); canDoubleDrop = Permissions.herbalismDoubleDrops(player); doubleDropsDisabled = configInstance.herbalismDoubleDropsDisabled(); - lucky = Permissions.luckyHerbalism(player); - endurance = Permissions.activationTwelve(player) || Permissions.activationEight(player) || Permissions.activationFour(player); } @Override @@ -116,10 +82,7 @@ public class HerbalismCommand extends SkillCommand { @Override protected void effectsDisplay() { - if (lucky) { - String perkPrefix = LocaleLoader.getString("MOTD.PerksPrefix"); - player.sendMessage(perkPrefix + LocaleLoader.getString("Effects.Template", new Object[] { LocaleLoader.getString("Perks.lucky.name"), LocaleLoader.getString("Perks.lucky.desc", new Object[] { Skills.localizeSkillName(SkillType.HERBALISM) }) })); - } + luckyEffectsDisplay(); if (canGreenTerra) { player.sendMessage(LocaleLoader.getString("Effects.Template", new Object[] { LocaleLoader.getString("Herbalism.Effect.0"), LocaleLoader.getString("Herbalism.Effect.1") })); @@ -154,17 +117,21 @@ public class HerbalismCommand extends SkillCommand { @Override protected void statsDisplay() { if (canGreenTerra) { - if (endurance) + if (hasEndurance) { player.sendMessage(LocaleLoader.getString("Herbalism.Ability.GTe.Length", new Object[] { greenTerraLength }) + LocaleLoader.getString("Perks.activationtime.bonus", new Object[] { greenTerraLengthEndurance })); - else + } + else { player.sendMessage(LocaleLoader.getString("Herbalism.Ability.GTe.Length", new Object[] { greenTerraLength })); + } } if (canGreenThumbBlocks || canGreenThumbWheat) { - if (lucky) + if (isLucky) { player.sendMessage(LocaleLoader.getString("Herbalism.Ability.GTh.Chance", new Object[] { greenThumbChance }) + LocaleLoader.getString("Perks.lucky.bonus", new Object[] { greenThumbChanceLucky })); - else + } + else { player.sendMessage(LocaleLoader.getString("Herbalism.Ability.GTh.Chance", new Object[] { greenThumbChance })); + } } if (canGreenThumbWheat) { @@ -176,16 +143,20 @@ public class HerbalismCommand extends SkillCommand { } if (hasHylianLuck) { - if (lucky) + if (isLucky) { player.sendMessage(LocaleLoader.getString("Herbalism.Ability.HylianLuck", new Object[] { hylianLuckChance }) + LocaleLoader.getString("Perks.lucky.bonus", new Object[] { hylianLuckChanceLucky })); - else + } + else { player.sendMessage(LocaleLoader.getString("Herbalism.Ability.HylianLuck", new Object[] { hylianLuckChance })); + } } if (canDoubleDrop && !doubleDropsDisabled) { - if (lucky) + if (isLucky) { player.sendMessage(LocaleLoader.getString("Herbalism.Ability.DoubleDropChance", new Object[] { doubleDropChance }) + LocaleLoader.getString("Perks.lucky.bonus", new Object[] { doubleDropChanceLucky })); - else + } + else { player.sendMessage(LocaleLoader.getString("Herbalism.Ability.DoubleDropChance", new Object[] { doubleDropChance })); + } } } } diff --git a/src/main/java/com/gmail/nossr50/config/AdvancedConfig.java b/src/main/java/com/gmail/nossr50/config/AdvancedConfig.java index 45989fe7c..c554713a9 100644 --- a/src/main/java/com/gmail/nossr50/config/AdvancedConfig.java +++ b/src/main/java/com/gmail/nossr50/config/AdvancedConfig.java @@ -91,12 +91,15 @@ public class AdvancedConfig extends ConfigLoader { public int getFarmerDietRankChange() { return config.getInt("Skills.Herbalism.Farmer_Diet_RankChange", 200); } public int getGreenThumbStageChange() { return config.getInt("Skills.Herbalism.GreenThumb_StageChange", 200); } - public int getGreenThumbChanceMax() { return config.getInt("Skills.Herbalism.GreenThumb_ChanceMax", 100); } + public double getGreenThumbChanceMax() { return config.getDouble("Skills.Herbalism.GreenThumb_ChanceMax", 100.0D); } public int getGreenThumbMaxLevel() { return config.getInt("Skills.Herbalism.GreenThumb_MaxBonusLevel", 1500); } - public int getHerbalismDoubleDropsChanceMax() { return config.getInt("Skills.Herbalism.DoubleDrops_ChanceMax", 100); } + public double getHerbalismDoubleDropsChanceMax() { return config.getDouble("Skills.Herbalism.DoubleDrops_ChanceMax", 100.0D); } public int getHerbalismDoubleDropsMaxLevel() { return config.getInt("Skills.Herbalism.DoubleDrops_MaxBonusLevel", 1000); } + public double getHylianLuckChanceMax() { return config.getDouble("Skills.Herbalism.HylianLuck_ChanceMax", 10.0D); } + public int getHylianLucksMaxLevel() { return config.getInt("Skills.Herbalism.HylianLuck_MaxBonusLevel", 1000); } + /* MINING */ public int getMiningDoubleDropChance() { return config.getInt("Skills.Mining.DoubleDrops_ChanceMax", 100); } public int getMiningDoubleDropMaxLevel() { return config.getInt("Skills.Mining.DoubleDrops_MaxBonusLevel", 1000); } diff --git a/src/main/java/com/gmail/nossr50/skills/gathering/Fishing.java b/src/main/java/com/gmail/nossr50/skills/gathering/Fishing.java index 7a7e9d911..01979f30a 100755 --- a/src/main/java/com/gmail/nossr50/skills/gathering/Fishing.java +++ b/src/main/java/com/gmail/nossr50/skills/gathering/Fishing.java @@ -49,6 +49,9 @@ public class Fishing { public static int shakeChanceLevel5 = AdvancedConfig.getInstance().getShakeChanceRank5(); public static int shakeUnlockLevel = AdvancedConfig.getInstance().getShakeUnlockLevel(); + public static int fishermanDietRankChangeLevel = AdvancedConfig.getInstance().getFishermanDietRankChange(); + public static int fishermanDietMaxLevel = fishermanDietRankChangeLevel * 5; + public static int magicHunterMultiplier = AdvancedConfig.getInstance().getFishingMagicMultiplier(); /** diff --git a/src/main/java/com/gmail/nossr50/skills/gathering/Herbalism.java b/src/main/java/com/gmail/nossr50/skills/gathering/Herbalism.java index 8b944c14a..6a2595156 100644 --- a/src/main/java/com/gmail/nossr50/skills/gathering/Herbalism.java +++ b/src/main/java/com/gmail/nossr50/skills/gathering/Herbalism.java @@ -28,7 +28,20 @@ import com.gmail.nossr50.util.Skills; import com.gmail.nossr50.util.Users; public class Herbalism { - static AdvancedConfig advancedConfig = AdvancedConfig.getInstance(); + public static int farmersDietRankChangeLevel = AdvancedConfig.getInstance().getFarmerDietRankChange(); + public static int farmersDietMaxLevel = farmersDietRankChangeLevel * 5; + + 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(); + public static int hylianLuckMaxLevel = AdvancedConfig.getInstance().getHylianLucksMaxLevel(); /** * Activate the Green Terra ability. @@ -84,8 +97,6 @@ public class Herbalism { return; final PlayerProfile profile = Users.getProfile(player); - final double MAX_CHANCE = advancedConfig.getHerbalismDoubleDropsChanceMax(); - final int MAX_BONUS_LEVEL = advancedConfig.getHerbalismDoubleDropsMaxLevel(); int herbLevel = profile.getSkillLevel(SkillType.HERBALISM); int id = block.getTypeId(); @@ -103,8 +114,8 @@ public class Herbalism { int activationChance = Misc.calculateActivationChance(Permissions.luckyHerbalism(player)); - float chance = (float) ((MAX_CHANCE / MAX_BONUS_LEVEL) * herbLevel); - if (chance > MAX_CHANCE) chance = (float) MAX_CHANCE; + float chance = (float) ((doubleDropsMaxChance / doubleDropsMaxLevel) * herbLevel); + if (chance > doubleDropsMaxChance) chance = (float) doubleDropsMaxChance; switch (type) { case BROWN_MUSHROOM: @@ -406,9 +417,6 @@ public class Herbalism { * @param plugin mcMMO plugin instance */ private static void greenThumbWheat(Block block, Player player, BlockBreakEvent event, mcMMO plugin) { - final int MAX_CHANCE = advancedConfig.getGreenThumbChanceMax(); - final int MAX_BONUS_LEVEL = advancedConfig.getGreenThumbMaxLevel(); - PlayerProfile profile = Users.getProfile(player); int herbLevel = profile.getSkillLevel(SkillType.HERBALISM); PlayerInventory inventory = player.getInventory(); @@ -446,8 +454,8 @@ public class Herbalism { int activationChance = Misc.calculateActivationChance(Permissions.luckyHerbalism(player)); - float chance = (float) (((double) MAX_CHANCE / (double) MAX_BONUS_LEVEL) * herbLevel); - if (chance > MAX_CHANCE) chance = MAX_CHANCE; + float chance = (float) ((greenThumbMaxChance / greenThumbMaxLevel) * herbLevel); + if (chance > greenThumbMaxChance) chance = (float) greenThumbMaxChance; if (hasSeeds && profile.getAbilityMode(AbilityType.GREEN_TERRA) || hasSeeds && (chance > Misc.getRandom().nextInt(activationChance))) { event.setCancelled(true); @@ -505,9 +513,6 @@ public class Herbalism { * @param block The block being used in the ability */ public static void greenThumbBlocks(ItemStack is, Player player, Block block) { - final int MAX_CHANCE = advancedConfig.getGreenThumbChanceMax(); - final int MAX_BONUS_LEVEL = advancedConfig.getGreenThumbMaxLevel(); - PlayerProfile profile = Users.getProfile(player); int skillLevel = profile.getSkillLevel(SkillType.HERBALISM); int seeds = is.getAmount(); @@ -516,8 +521,8 @@ public class Herbalism { int activationChance = Misc.calculateActivationChance(Permissions.luckyHerbalism(player)); - float chance = (float) (((double) MAX_CHANCE / (double) MAX_BONUS_LEVEL) * skillLevel); - if (chance > MAX_CHANCE) chance = MAX_CHANCE; + float chance = (float) ((greenThumbMaxChance / greenThumbMaxLevel) * skillLevel); + if (chance > greenThumbMaxChance) chance = (float) greenThumbMaxChance; if (chance > Misc.getRandom().nextInt(activationChance)) { greenTerraConvert(player, block); @@ -528,7 +533,10 @@ public class Herbalism { } public static void hylianLuck(Block block, Player player, BlockBreakEvent event) { - int chance = Users.getProfile(player).getSkillLevel(SkillType.HERBALISM) / 100; + int skillLevel = Users.getProfile(player).getSkillLevel(SkillType.HERBALISM); + + float chance = (float) ((hylianLuckMaxChance / hylianLuckMaxLevel) * skillLevel); + if (chance > hylianLuckMaxChance) chance = (float) hylianLuckMaxChance; int activationChance = Misc.calculateActivationChance(Permissions.luckyHerbalism(player)); diff --git a/src/main/resources/advanced.yml b/src/main/resources/advanced.yml index 0a38520c8..6674fdc25 100644 --- a/src/main/resources/advanced.yml +++ b/src/main/resources/advanced.yml @@ -128,15 +128,20 @@ Skills: # GreenThumb_StageChange: Level value when the GreenThumb stage level goes up # GreenThumb_ChanceMax: Maximum chance of GreenThumb - # GreenThumb_MaxBonusLevel: On this level, greenthumb chance will be GreenThumb_ChanceMax + # GreenThumb_MaxBonusLevel: On this level, GreenThumb chance will be GreenThumb_ChanceMax GreenThumb_StageChange: 200 - GreenThumb_ChanceMax: 100 + GreenThumb_ChanceMax: 100.0 GreenThumb_MaxBonusLevel: 1500 # DoubleDrops_ChanceMax: Maximum chance of receiving double drops # DoubleDrops_MaxBonusLevel: Level when the maximum chance of receiving double drops is reached - DoubleDrops_ChanceMax: 100 + DoubleDrops_ChanceMax: 100.0 DoubleDrops_MaxBonusLevel: 1000 + + # HylianLuck_ChanceMax: Maximum chance of Hylian Luck + # HylianLuck_MaxBonusLevel: On this level, Hylian Luck chance will be HylianLuck_ChanceMax + HylianLuck_ChanceMax: 10.0 + HylianLuck_MaxBonusLevel: 1000 # # Settings for Mining ###