From 2ed5e8e7174593601fcf7fdaae5afb0d97456c6f Mon Sep 17 00:00:00 2001 From: gmcferrin Date: Fri, 11 Jan 2013 17:55:54 -0500 Subject: [PATCH] Fixes issue #315 - Fishing will now properly respect min/max levels in treasures.yml --- .../gmail/nossr50/config/TreasuresConfig.java | 31 +---------- .../nossr50/skills/gathering/Fishing.java | 55 +++++++------------ 2 files changed, 22 insertions(+), 64 deletions(-) diff --git a/src/main/java/com/gmail/nossr50/config/TreasuresConfig.java b/src/main/java/com/gmail/nossr50/config/TreasuresConfig.java index 19b38b55c..a507c6299 100644 --- a/src/main/java/com/gmail/nossr50/config/TreasuresConfig.java +++ b/src/main/java/com/gmail/nossr50/config/TreasuresConfig.java @@ -25,11 +25,7 @@ public class TreasuresConfig extends ConfigLoader{ public List excavationFromClay = new ArrayList(); public List excavationFromMycel = new ArrayList(); public List excavationFromSoulSand = new ArrayList(); - public List fishingRewardsTier1 = new ArrayList(); - public List fishingRewardsTier2 = new ArrayList(); - public List fishingRewardsTier3 = new ArrayList(); - public List fishingRewardsTier4 = new ArrayList(); - public List fishingRewardsTier5 = new ArrayList(); + public List fishingRewards = new ArrayList(); private TreasuresConfig() { super("treasures.yml"); @@ -198,30 +194,7 @@ public class TreasuresConfig extends ConfigLoader{ continue; } - FishingTreasure fTreasure = (FishingTreasure) treasure; - int dropLevel = fTreasure.getDropLevel(); - int maxLevel = fTreasure.getMaxLevel(); - - if (dropLevel <= AdvancedConfig.getInstance().getFishingTierLevelsTier1() && maxLevel >= AdvancedConfig.getInstance().getFishingTierLevelsTier1()) { - fishingRewardsTier1.add(fTreasure); - } - - if (dropLevel <= AdvancedConfig.getInstance().getFishingTierLevelsTier2() && maxLevel >= AdvancedConfig.getInstance().getFishingTierLevelsTier2()) { - fishingRewardsTier2.add(fTreasure); - } - - if (dropLevel <= AdvancedConfig.getInstance().getFishingTierLevelsTier3() && maxLevel >= AdvancedConfig.getInstance().getFishingTierLevelsTier3()) { - fishingRewardsTier3.add(fTreasure); - } - - if (dropLevel <= AdvancedConfig.getInstance().getFishingTierLevelsTier4() && maxLevel >= AdvancedConfig.getInstance().getFishingTierLevelsTier4()) { - fishingRewardsTier4.add(fTreasure); - } - - if (dropLevel <= AdvancedConfig.getInstance().getFishingTierLevelsTier5() && maxLevel >= AdvancedConfig.getInstance().getFishingTierLevelsTier5()) { - fishingRewardsTier5.add(fTreasure); - } - + fishingRewards.add((FishingTreasure) treasure); } else if (treasure instanceof ExcavationTreasure) { if (!excavationTreasures.contains(treasureKey)) { 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 ac797e012..1a1469beb 100755 --- a/src/main/java/com/gmail/nossr50/skills/gathering/Fishing.java +++ b/src/main/java/com/gmail/nossr50/skills/gathering/Fishing.java @@ -77,50 +77,35 @@ public class Fishing { return; PlayerProfile profile = Users.getProfile(player); - List rewards = new ArrayList(); Item theCatch = (Item) event.getCaught(); - - switch (getFishingLootTier(profile)) { - case 1: - rewards = TreasuresConfig.getInstance().fishingRewardsTier1; - break; - - case 2: - rewards = TreasuresConfig.getInstance().fishingRewardsTier2; - break; - - case 3: - rewards = TreasuresConfig.getInstance().fishingRewardsTier3; - break; - - case 4: - rewards = TreasuresConfig.getInstance().fishingRewardsTier4; - break; - - case 5: - rewards = TreasuresConfig.getInstance().fishingRewardsTier5; - break; - - default: - break; - } - if (Config.getInstance().getFishingDropsEnabled() && rewards.size() > 0 - && Permissions.fishingTreasures(player)) { - FishingTreasure treasure; - treasure = rewards.get(Misc.getRandom().nextInt(rewards.size())); + if (Config.getInstance().getFishingDropsEnabled() && Permissions.fishingTreasures(player)) { + int skillLevel = profile.getSkillLevel(SkillType.FISHING); + List rewards = new ArrayList(); + + for (FishingTreasure treasure : TreasuresConfig.getInstance().fishingRewards) { + if (treasure.getDropLevel() <= skillLevel && treasure.getMaxLevel() >= skillLevel) { + rewards.add(treasure); + } + } + + if (rewards.size() <= 0) { + return; + } + + FishingTreasure foundTreasure = rewards.get(Misc.getRandom().nextInt(rewards.size())); int randomChance = 100; - if (Permissions.luckyFishing(player)) { randomChance = (int) (randomChance * 0.75); } - if (Misc.getRandom().nextDouble() * randomChance <= treasure.getDropChance()) { - Users.getPlayer(player).addXP(SkillType.FISHING,treasure.getXp()); - theCatch.setItemStack(treasure.getDrop()); + if (Misc.getRandom().nextDouble() * randomChance <= foundTreasure.getDropChance()) { + Users.getPlayer(player).addXP(SkillType.FISHING, foundTreasure.getXp()); + theCatch.setItemStack(foundTreasure.getDrop()); } - } else { + } + else { theCatch.setItemStack(new ItemStack(Material.RAW_FISH)); }