Cleaned up the fishing enchantment checks.

This commit is contained in:
GJ 2012-03-14 11:43:18 -04:00
parent ea2615aeae
commit 9ef1c3b5bf

View File

@ -2,6 +2,7 @@ package com.gmail.nossr50.skills;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map;
import org.bukkit.DyeColor; import org.bukkit.DyeColor;
import org.bukkit.Location; import org.bukkit.Location;
@ -131,44 +132,28 @@ public class Fishing {
player.sendMessage(mcLocale.getString("Fishing.ItemFound")); player.sendMessage(mcLocale.getString("Fishing.ItemFound"));
if (Repair.isArmor(fishingResults) || Repair.isTools(fishingResults)) { if (Repair.isArmor(fishingResults) || Repair.isTools(fishingResults)) {
if (Math.random() * 100 <= ENCHANTMENT_CHANCE) { if (Math.random() * 100 <= ENCHANTMENT_CHANCE) {
for (Enchantment enchantment : Enchantment.values()) { for (Enchantment newEnchant : Enchantment.values()) {
if (enchantment.canEnchantItem(fishingResults)) { if (newEnchant.canEnchantItem(fishingResults)) {
Map<Enchantment, Integer> resultEnchantments = fishingResults.getEnchantments();
//TODO: Clean this up. It's ugly & unreadable. for (Enchantment oldEnchant : resultEnchantments.keySet()) {
//Prevent impossible enchantment combinations if (oldEnchant.conflictsWith(newEnchant)) {
if ((fishingResults.containsEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL) || fishingResults.containsEnchantment(Enchantment.PROTECTION_EXPLOSIONS) || return;
fishingResults.containsEnchantment(Enchantment.PROTECTION_FIRE) || fishingResults.containsEnchantment(Enchantment.PROTECTION_PROJECTILE)) &&
(enchantment.equals(Enchantment.PROTECTION_EXPLOSIONS) || enchantment.equals(Enchantment.PROTECTION_PROJECTILE) || enchantment.equals(Enchantment.PROTECTION_FIRE) || enchantment.equals(Enchantment.PROTECTION_ENVIRONMENTAL))){
return;
}
//More impossible enchantment combinations
else if ((fishingResults.containsEnchantment(Enchantment.DAMAGE_ALL) || fishingResults.containsEnchantment(Enchantment.DAMAGE_ARTHROPODS) || fishingResults.containsEnchantment(Enchantment.DAMAGE_UNDEAD)) &&
(enchantment.equals(Enchantment.DAMAGE_ALL) || enchantment.equals(Enchantment.DAMAGE_ARTHROPODS) || enchantment.equals(Enchantment.DAMAGE_UNDEAD))){
return;
}
//Even more impossible enchantment combinations
else if ((fishingResults.containsEnchantment(Enchantment.SILK_TOUCH) || fishingResults.containsEnchantment(Enchantment.LOOT_BONUS_BLOCKS)) &&
(enchantment.equals(Enchantment.SILK_TOUCH) || enchantment.equals(Enchantment.LOOT_BONUS_BLOCKS))){
return;
}
else {
//Actual chance to have an enchantment is related to your fishing skill
if (Math.random() * 15 < Fishing.getFishingLootTier(PP)) {
enchanted = true;
int randomEnchantLevel = (int)(Math.random() * enchantment.getMaxLevel()) + 1;
if (randomEnchantLevel == 0) {
randomEnchantLevel = 1;
}
fishingResults.addEnchantment(enchantment, randomEnchantLevel);
} }
} }
/* Actual chance to have an enchantment is related to your fishing skill */
if (Math.random() * 15 < Fishing.getFishingLootTier(PP)) {
enchanted = true;
int randomEnchantLevel = (int) (Math.random() * newEnchant.getMaxLevel()) + 1;
if (randomEnchantLevel == 0) {
randomEnchantLevel = 1;
}
fishingResults.addEnchantment(newEnchant, randomEnchantLevel);
}
} }
} }
} }