Cleanup on FishingCommand, split Farmer's Diet & Fisherman's Diet into

distinct config values. Fixes #556
This commit is contained in:
GJ 2013-01-22 00:47:56 -05:00
parent 91b318e8f7
commit 176ffcc3d1
7 changed files with 118 additions and 78 deletions

View File

@ -81,9 +81,22 @@ public abstract class SkillCommand implements CommandExecutor {
return true; return true;
} }
protected String[] calculateAbilityDisplayValues(double chance) {
if (isLucky) {
double luckyChance = chance * 1.3333D;
if (luckyChance >= 100D) {
return new String[] { percent.format(chance / 100.0D), percent.format(1.0D) };
}
return new String[] { percent.format(chance / 100.0D), percent.format(luckyChance / 100.0D) };
}
return new String[] { percent.format(chance / 100.0D), null };
}
protected String[] calculateAbilityDisplayValues(int maxBonusLevel, double maxChance) { protected String[] calculateAbilityDisplayValues(int maxBonusLevel, double maxChance) {
double abilityChance; double abilityChance;
double luckyChance;
if (skillValue >= maxBonusLevel) { if (skillValue >= maxBonusLevel) {
abilityChance = maxChance; abilityChance = maxChance;
@ -93,7 +106,7 @@ public abstract class SkillCommand implements CommandExecutor {
} }
if (isLucky) { if (isLucky) {
luckyChance = abilityChance * 1.3333D; double luckyChance = abilityChance * 1.3333D;
if (luckyChance >= 100D) { if (luckyChance >= 100D) {
return new String[] { percent.format(abilityChance / 100.0D), percent.format(1.0D) }; return new String[] { percent.format(abilityChance / 100.0D), percent.format(1.0D) };

View File

@ -6,7 +6,6 @@ import com.gmail.nossr50.datatypes.SkillType;
import com.gmail.nossr50.locale.LocaleLoader; import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.skills.gathering.Fishing; import com.gmail.nossr50.skills.gathering.Fishing;
import com.gmail.nossr50.util.Permissions; import com.gmail.nossr50.util.Permissions;
import com.gmail.nossr50.util.Skills;
public class FishingCommand extends SkillCommand { public class FishingCommand extends SkillCommand {
@ -15,22 +14,18 @@ public class FishingCommand extends SkillCommand {
private int lootTier; private int lootTier;
private String magicChance; private String magicChance;
private String magicChanceLucky; private String magicChanceLucky;
private String chanceRaining; private String chanceRaining = "";
private int shakeUnlockLevel;
private String shakeChance; private String shakeChance;
private String shakeChanceLucky; private String shakeChanceLucky;
private String fishermansDietRank; private String fishermansDietRank;
private int magicHunterMultiplier = advancedConfig.getFishingMagicMultiplier(); private int fishermansDietRankChange = AdvancedConfig.getInstance().getFarmerDietRankChange();
private int fishermansDietRankChange = advancedConfig.getFarmerDietRankChange();
private int fishermansDietRankMaxLevel = fishermansDietRankChange * 5; private int fishermansDietRankMaxLevel = fishermansDietRankChange * 5;
private boolean canTreasureHunt; private boolean canTreasureHunt;
private boolean canMagicHunt; private boolean canMagicHunt;
private boolean canShake; private boolean canShake;
private boolean canFishermansDiet; private boolean canFishermansDiet;
private boolean lucky;
private boolean raining;
public FishingCommand() { public FishingCommand() {
super(SkillType.FISHING); super(SkillType.FISHING);
@ -38,30 +33,32 @@ public class FishingCommand extends SkillCommand {
@Override @Override
protected void dataCalculations() { protected void dataCalculations() {
//TREASURE HUNTER
raining = player.getWorld().hasStorm();
chanceRaining = "";
lootTier = Fishing.getFishingLootTier(profile); lootTier = Fishing.getFishingLootTier(profile);
double magicChanceD = lootTier * magicHunterMultiplier;
if (raining) { //TREASURE HUNTER
double enchantChance = lootTier * Fishing.magicHunterMultiplier;
if (player.getWorld().hasStorm()) {
chanceRaining = LocaleLoader.getString("Fishing.Chance.Raining"); chanceRaining = LocaleLoader.getString("Fishing.Chance.Raining");
magicChanceD = magicChanceD * 1.1D; enchantChance = enchantChance * 1.1D;
} }
magicChance = percent.format(magicChanceD / 100D);
if (magicChanceD * 1.3333D >= 100D) magicChanceLucky = percent.format(1D);
else magicChanceLucky = percent.format(magicChanceD * 1.3333D / 100D);
//Shake String[] treasureHunterStrings = calculateAbilityDisplayValues(enchantChance);
int dropChance = Fishing.getShakeChance(lootTier); magicChance = treasureHunterStrings[0];
shakeChance = percent.format(dropChance / 100D); magicChanceLucky = treasureHunterStrings[1];
if (dropChance * 1.3333D >= 100D) shakeChanceLucky = percent.format(1D);
else shakeChanceLucky = percent.format(dropChance * 1.3333D / 100D);
shakeUnlockLevel = advancedConfig.getShakeUnlockLevel();
//Fishermans Diet //SHAKE
if (skillValue >= fishermansDietRankMaxLevel) fishermansDietRank = "5"; String[] shakeStrings = calculateAbilityDisplayValues(Fishing.getShakeChance(lootTier));
else fishermansDietRank = String.valueOf((int) ((double) skillValue / (double) fishermansDietRankChange)); shakeChance = shakeStrings[0];
shakeChanceLucky = shakeStrings[1];
//FISHERMAN'S DIET
if (skillValue >= fishermansDietRankMaxLevel) {
fishermansDietRank = "5";
}
else {
fishermansDietRank = String.valueOf((int) (skillValue / fishermansDietRankChange));
}
} }
@Override @Override
@ -70,7 +67,6 @@ public class FishingCommand extends SkillCommand {
canMagicHunt = Permissions.fishingMagic(player); canMagicHunt = Permissions.fishingMagic(player);
canShake = Permissions.shakeMob(player); canShake = Permissions.shakeMob(player);
canFishermansDiet = Permissions.fishermansDiet(player); canFishermansDiet = Permissions.fishermansDiet(player);
lucky = Permissions.luckyFishing(player);
} }
@Override @Override
@ -80,10 +76,7 @@ public class FishingCommand extends SkillCommand {
@Override @Override
protected void effectsDisplay() { protected void effectsDisplay() {
if (lucky) { luckyEffectsDisplay();
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.FISHING) }) }));
}
if (canTreasureHunt) { if (canTreasureHunt) {
player.sendMessage(LocaleLoader.getString("Effects.Template", new Object[] { LocaleLoader.getString("Fishing.Effect.0"), LocaleLoader.getString("Fishing.Effect.1") })); player.sendMessage(LocaleLoader.getString("Effects.Template", new Object[] { LocaleLoader.getString("Fishing.Effect.0"), LocaleLoader.getString("Fishing.Effect.1") }));
@ -114,21 +107,25 @@ public class FishingCommand extends SkillCommand {
} }
if (canMagicHunt) { if (canMagicHunt) {
if (lucky) if (isLucky) {
player.sendMessage(LocaleLoader.getString("Fishing.Enchant.Chance", new Object[] { magicChance}) + chanceRaining + LocaleLoader.getString("Perks.lucky.bonus", new Object[] { magicChanceLucky })); player.sendMessage(LocaleLoader.getString("Fishing.Enchant.Chance", new Object[] { magicChance}) + chanceRaining + LocaleLoader.getString("Perks.lucky.bonus", new Object[] { magicChanceLucky }));
else }
else {
player.sendMessage(LocaleLoader.getString("Fishing.Enchant.Chance", new Object[] { magicChance}) + chanceRaining); player.sendMessage(LocaleLoader.getString("Fishing.Enchant.Chance", new Object[] { magicChance}) + chanceRaining);
}
} }
if (canShake) { if (canShake) {
if (skillValue < advancedConfig.getShakeUnlockLevel()) { if (skillValue < Fishing.shakeUnlockLevel) {
player.sendMessage(LocaleLoader.getString("Ability.Generic.Template.Lock", new Object[] { LocaleLoader.getString("Fishing.Ability.Locked.0", new Object[] { shakeUnlockLevel }) })); player.sendMessage(LocaleLoader.getString("Ability.Generic.Template.Lock", new Object[] { LocaleLoader.getString("Fishing.Ability.Locked.0", new Object[] { Fishing.shakeUnlockLevel }) }));
} }
else { else {
if (lucky) if (isLucky) {
player.sendMessage(LocaleLoader.getString("Fishing.Ability.Shake", new Object[] { shakeChance }) + LocaleLoader.getString("Perks.lucky.bonus", new Object[] { shakeChanceLucky })); player.sendMessage(LocaleLoader.getString("Fishing.Ability.Shake", new Object[] { shakeChance }) + LocaleLoader.getString("Perks.lucky.bonus", new Object[] { shakeChanceLucky }));
else }
else {
player.sendMessage(LocaleLoader.getString("Fishing.Ability.Shake", new Object[] { shakeChance })); player.sendMessage(LocaleLoader.getString("Fishing.Ability.Shake", new Object[] { shakeChance }));
}
} }
} }

View File

@ -77,6 +77,8 @@ public class AdvancedConfig extends ConfigLoader {
public int getFishingMagicMultiplier() { return config.getInt("Skills.Fishing.MagicHunter_Multiplier", 5); } public int getFishingMagicMultiplier() { return config.getInt("Skills.Fishing.MagicHunter_Multiplier", 5); }
public int getFishermanDietRankChange() { return config.getInt("Skills.Fishing.Fisherman_Diet_RankChange", 200); }
/* Shake */ /* Shake */
public int getShakeUnlockLevel() { return config.getInt("Skills.Fishing.Shake_UnlockLevel", 150); } public int getShakeUnlockLevel() { return config.getInt("Skills.Fishing.Shake_UnlockLevel", 150); }
public int getShakeChanceRank1() { return config.getInt("Skills.Fishing.Shake_Chance.Rank_1", 25); } public int getShakeChanceRank1() { return config.getInt("Skills.Fishing.Shake_Chance.Rank_1", 25); }
@ -86,7 +88,7 @@ public class AdvancedConfig extends ConfigLoader {
public int getShakeChanceRank5() { return config.getInt("Skills.Fishing.Shake_Chance.Rank_5", 75); } public int getShakeChanceRank5() { return config.getInt("Skills.Fishing.Shake_Chance.Rank_5", 75); }
/* HERBALISM */ /* HERBALISM */
public int getFarmerDietRankChange() { return config.getInt("Skills.Herbalism.Food_RankChange", 200); } 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 getGreenThumbStageChange() { return config.getInt("Skills.Herbalism.GreenThumb_StageChange", 200); }
public int getGreenThumbChanceMax() { return config.getInt("Skills.Herbalism.GreenThumb_ChanceMax", 100); } public int getGreenThumbChanceMax() { return config.getInt("Skills.Herbalism.GreenThumb_ChanceMax", 100); }

View File

@ -305,97 +305,110 @@ public class EntityListener implements Listener {
int rankChange = 0; int rankChange = 0;
boolean fish = false; boolean fish = false;
boolean herb = false; boolean herb = false;
int FoodRank1 = advancedConfig.getFarmerDietRankChange(); int herbFoodRank1 = advancedConfig.getFarmerDietRankChange();
int FoodRank2 = advancedConfig.getFarmerDietRankChange() * 2; int herbFoodRank2 = advancedConfig.getFarmerDietRankChange() * 2;
int FoodRankMax = advancedConfig.getFarmerDietRankChange() * 5; int herbFoodRankMax = advancedConfig.getFarmerDietRankChange() * 5;
int fishFoodRank1 = advancedConfig.getFishermanDietRankChange();
int fishFoodRank2 = advancedConfig.getFishermanDietRankChange() * 2;
int fishFoodRankMax = advancedConfig.getFishermanDietRankChange() * 5;
switch (food) { switch (food) {
case BREAD: case BREAD:
/* BREAD RESTORES 2 1/2 HUNGER - RESTORES 5 HUNGER @ 1000 */ /* BREAD RESTORES 2 1/2 HUNGER - RESTORES 5 HUNGER @ 1000 */
herb = true; herb = true;
rankChange = FoodRank1; rankChange = herbFoodRank1;
break; break;
case COOKIE: case COOKIE:
/* COOKIE RESTORES 1/2 HUNGER - RESTORES 2 HUNGER @ 1000 */ /* COOKIE RESTORES 1/2 HUNGER - RESTORES 2 HUNGER @ 1000 */
herb = true; herb = true;
rankChange = FoodRank2; rankChange = herbFoodRank2;
break; break;
case MELON: case MELON:
/* MELON RESTORES 1 HUNGER - RESTORES 2 1/2 HUNGER @ 1000 */ /* MELON RESTORES 1 HUNGER - RESTORES 2 1/2 HUNGER @ 1000 */
herb = true; herb = true;
rankChange = FoodRank2; rankChange = herbFoodRank2;
break; break;
case MUSHROOM_SOUP: case MUSHROOM_SOUP:
/* MUSHROOM SOUP RESTORES 4 HUNGER - RESTORES 6 1/2 HUNGER @ 1000 */ /* MUSHROOM SOUP RESTORES 4 HUNGER - RESTORES 6 1/2 HUNGER @ 1000 */
herb = true; herb = true;
rankChange = FoodRank1; rankChange = herbFoodRank1;
break; break;
case CARROT_ITEM: case CARROT_ITEM:
/* CARROT RESTORES 2 HUNGER - RESTORES 4 1/2 HUNGER @ 1000 */ /* CARROT RESTORES 2 HUNGER - RESTORES 4 1/2 HUNGER @ 1000 */
herb = true; herb = true;
rankChange = FoodRank1; rankChange = herbFoodRank1;
break; break;
case POTATO_ITEM: case POTATO_ITEM:
/* POTATO RESTORES 1/2 HUNGER - RESTORES 2 HUNGER @ 1000 */ /* POTATO RESTORES 1/2 HUNGER - RESTORES 2 HUNGER @ 1000 */
herb = true; herb = true;
rankChange = FoodRank2; rankChange = herbFoodRank2;
break; break;
case BAKED_POTATO: case BAKED_POTATO:
/* BAKED POTATO RESTORES 3 HUNGER - RESTORES 5 1/2 HUNGER @ 1000 */ /* BAKED POTATO RESTORES 3 HUNGER - RESTORES 5 1/2 HUNGER @ 1000 */
herb = true; herb = true;
rankChange = FoodRank1; rankChange = herbFoodRank1;
break; break;
case POISONOUS_POTATO: case POISONOUS_POTATO:
/* POISONOUS POTATO RESTORES 1 HUNGER - RESTORES 2 1/2 HUNGER @ 1000 */ /* POISONOUS POTATO RESTORES 1 HUNGER - RESTORES 2 1/2 HUNGER @ 1000 */
herb = true; herb = true;
rankChange = FoodRank2; rankChange = herbFoodRank2;
break; break;
case GOLDEN_CARROT: case GOLDEN_CARROT:
/* GOLDEN CARROT RESTORES 3 HUNGER - RESTORES 5 1/2 HUNGER @ 1000 */ /* GOLDEN CARROT RESTORES 3 HUNGER - RESTORES 5 1/2 HUNGER @ 1000 */
herb = true; herb = true;
rankChange = FoodRank1; rankChange = herbFoodRank1;
break; break;
case PUMPKIN_PIE: case PUMPKIN_PIE:
/* PUMPKIN PIE RESTORES 4 HUNGER - RESTORES 6 1/2 HUNGER @ 1000 */ /* PUMPKIN PIE RESTORES 4 HUNGER - RESTORES 6 1/2 HUNGER @ 1000 */
herb = true; herb = true;
rankChange = FoodRank1; rankChange = herbFoodRank1;
break; break;
case RAW_FISH: case RAW_FISH:
/* RAW FISH RESTORES 1 HUNGER - RESTORES 2 1/2 HUNGER @ 1000 */ /* RAW FISH RESTORES 1 HUNGER - RESTORES 2 1/2 HUNGER @ 1000 */
rankChange = FoodRank2; rankChange = fishFoodRank2;
fish = true; fish = true;
break; break;
case COOKED_FISH: case COOKED_FISH:
/* COOKED FISH RESTORES 2 1/2 HUNGER - RESTORES 5 HUNGER @ 1000 */ /* COOKED FISH RESTORES 2 1/2 HUNGER - RESTORES 5 HUNGER @ 1000 */
rankChange = FoodRank1; rankChange = fishFoodRank1;
fish = true; fish = true;
break; break;
default: default:
return; return;
} }
if (herb && !Permissions.farmersDiet(player)) { if (herb) {
return; if (!Permissions.farmersDiet(player)) {
} return;
else if (fish && !Permissions.fishermansDiet(player)) { }
return;
}
for (int i = FoodRank1; i <= FoodRankMax; i += rankChange) { for (int i = herbFoodRank1; i <= herbFoodRankMax; i += rankChange) {
if ((herb && herbLevel >= i) || (fish && fishLevel >= i)) { if (herbLevel >= i) {
foodChange++; foodChange++;
}
}
}
else if (fish) {
if (!Permissions.fishermansDiet(player)) {
return;
}
for (int i = fishFoodRank1; i <= fishFoodRankMax; i += rankChange) {
if (fish && fishLevel >= i) {
foodChange++;
}
} }
} }

View File

@ -36,7 +36,20 @@ import com.gmail.nossr50.util.Skills;
import com.gmail.nossr50.util.Users; import com.gmail.nossr50.util.Users;
public class Fishing { public class Fishing {
static AdvancedConfig advancedConfig = AdvancedConfig.getInstance(); public static int fishingTierLevel1 = AdvancedConfig.getInstance().getFishingTierLevelsTier1();
public static int fishingTierLevel2 = AdvancedConfig.getInstance().getFishingTierLevelsTier2();
public static int fishingTierLevel3 = AdvancedConfig.getInstance().getFishingTierLevelsTier3();
public static int fishingTierLevel4 = AdvancedConfig.getInstance().getFishingTierLevelsTier4();
public static int fishingTierLevel5 = AdvancedConfig.getInstance().getFishingTierLevelsTier5();
public static int shakeChanceLevel1 = AdvancedConfig.getInstance().getShakeChanceRank1();
public static int shakeChanceLevel2 = AdvancedConfig.getInstance().getShakeChanceRank2();
public static int shakeChanceLevel3 = AdvancedConfig.getInstance().getShakeChanceRank3();
public static int shakeChanceLevel4 = AdvancedConfig.getInstance().getShakeChanceRank4();
public static int shakeChanceLevel5 = AdvancedConfig.getInstance().getShakeChanceRank5();
public static int shakeUnlockLevel = AdvancedConfig.getInstance().getShakeUnlockLevel();
public static int magicHunterMultiplier = AdvancedConfig.getInstance().getFishingMagicMultiplier();
/** /**
* Get the player's current fishing loot tier. * Get the player's current fishing loot tier.
@ -49,13 +62,13 @@ public class Fishing {
int level = profile.getSkillLevel(SkillType.FISHING); int level = profile.getSkillLevel(SkillType.FISHING);
int fishingTier; int fishingTier;
if (level >= advancedConfig.getFishingTierLevelsTier5()) { if (level >= fishingTierLevel5) {
fishingTier = 5; fishingTier = 5;
} else if (level >= advancedConfig.getFishingTierLevelsTier4()) { } else if (level >= fishingTierLevel4) {
fishingTier = 4; fishingTier = 4;
} else if (level >= advancedConfig.getFishingTierLevelsTier3()) { } else if (level >= fishingTierLevel3) {
fishingTier = 3; fishingTier = 3;
} else if (level >= advancedConfig.getFishingTierLevelsTier2()) { } else if (level >= fishingTierLevel2) {
fishingTier = 2; fishingTier = 2;
} else { } else {
fishingTier = 1; fishingTier = 1;
@ -133,7 +146,6 @@ public class Fishing {
if (theCatch.getItemStack().getType() != Material.RAW_FISH) { if (theCatch.getItemStack().getType() != Material.RAW_FISH) {
int lootTier = Fishing.getFishingLootTier(profile); int lootTier = Fishing.getFishingLootTier(profile);
int magicHunterMultiplier = advancedConfig.getFishingMagicMultiplier();
int specificChance = 1; int specificChance = 1;
boolean enchanted = false; boolean enchanted = false;
ItemStack fishingResults = theCatch.getItemStack(); ItemStack fishingResults = theCatch.getItemStack();
@ -460,19 +472,19 @@ public class Fishing {
public static int getShakeChance(int lootTier) { public static int getShakeChance(int lootTier) {
switch (lootTier) { switch (lootTier) {
case 1: case 1:
return advancedConfig.getShakeChanceRank1(); return shakeChanceLevel1;
case 2: case 2:
return advancedConfig.getShakeChanceRank2(); return shakeChanceLevel2;
case 3: case 3:
return advancedConfig.getShakeChanceRank3(); return shakeChanceLevel3;
case 4: case 4:
return advancedConfig.getShakeChanceRank4(); return shakeChanceLevel4;
case 5: case 5:
return advancedConfig.getShakeChanceRank5(); return shakeChanceLevel5;
default: default:
return 10; return 10;

View File

@ -116,12 +116,15 @@ Skills:
# MagicHunter_Multiplier: Determines the chance of fishing enchanted items. The chance is calculated by getting the fishing TreasureHunt tier and multiplying it with MagicHunter_Multiplier # MagicHunter_Multiplier: Determines the chance of fishing enchanted items. The chance is calculated by getting the fishing TreasureHunt tier and multiplying it with MagicHunter_Multiplier
MagicHunter_Multiplier: 5 MagicHunter_Multiplier: 5
# This determines when Fisherman's Diet adds extra hunger recovery to food
Fisherman_Diet_RankChange: 200
# #
# Settings for Herbalism # Settings for Herbalism
### ###
Herbalism: Herbalism:
# This determines when Farmersdiet and Fishermans diet add extra hunger recovery to food # This determines when Farmersdiet and Fishermans diet add extra hunger recovery to food
Food_RankChange: 200 Farmer_Diet_RankChange: 200
# GreenThumb_StageChange: Level value when the GreenThumb stage level goes up # GreenThumb_StageChange: Level value when the GreenThumb stage level goes up
# GreenThumb_ChanceMax: Maximum chance of GreenThumb # GreenThumb_ChanceMax: Maximum chance of GreenThumb

View File

@ -122,7 +122,7 @@ Fishing.Skillup=[[YELLOW]]Fishing skill increased by {0}. Total ({1})
#HERBALISM #HERBALISM
Herbalism.Ability.DoubleDropChance=[[RED]]Double Drop Chance: [[YELLOW]]{0} Herbalism.Ability.DoubleDropChance=[[RED]]Double Drop Chance: [[YELLOW]]{0}
Herbalism.Ability.FD=[[RED]]Farmers Diet: [[YELLOW]]Rank {0} Herbalism.Ability.FD=[[RED]]Farmer''s Diet: [[YELLOW]]Rank {0}
Herbalism.Ability.GTe.Length=[[RED]]Green Terra Length: [[YELLOW]]{0}s Herbalism.Ability.GTe.Length=[[RED]]Green Terra Length: [[YELLOW]]{0}s
Herbalism.Ability.GTe.NeedMore=[[RED]]You need more seeds to spread Green Terra. Herbalism.Ability.GTe.NeedMore=[[RED]]You need more seeds to spread Green Terra.
Herbalism.Ability.GTh.Chance=[[RED]]Green Thumb Chance: [[YELLOW]]{0} Herbalism.Ability.GTh.Chance=[[RED]]Green Thumb Chance: [[YELLOW]]{0}