|
@@ -1,35 +1,22 @@
|
|
|
package com.gmail.nossr50.skills.fishing;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
+import java.util.Collections;
|
|
|
import java.util.List;
|
|
|
|
|
|
-import org.bukkit.DyeColor;
|
|
|
-import org.bukkit.Location;
|
|
|
-import org.bukkit.Material;
|
|
|
import org.bukkit.enchantments.Enchantment;
|
|
|
-import org.bukkit.entity.Entity;
|
|
|
-import org.bukkit.entity.EntityType;
|
|
|
import org.bukkit.entity.Item;
|
|
|
import org.bukkit.entity.LivingEntity;
|
|
|
import org.bukkit.entity.Player;
|
|
|
-import org.bukkit.entity.Sheep;
|
|
|
-import org.bukkit.entity.Skeleton;
|
|
|
-import org.bukkit.entity.Skeleton.SkeletonType;
|
|
|
import org.bukkit.event.entity.FoodLevelChangeEvent;
|
|
|
import org.bukkit.event.player.PlayerFishEvent;
|
|
|
import org.bukkit.inventory.ItemStack;
|
|
|
-import org.bukkit.material.MaterialData;
|
|
|
-import org.bukkit.material.Wool;
|
|
|
-import org.bukkit.potion.Potion;
|
|
|
-import org.bukkit.potion.PotionType;
|
|
|
|
|
|
import com.gmail.nossr50.config.AdvancedConfig;
|
|
|
import com.gmail.nossr50.config.Config;
|
|
|
import com.gmail.nossr50.config.TreasuresConfig;
|
|
|
-import com.gmail.nossr50.datatypes.PlayerProfile;
|
|
|
import com.gmail.nossr50.datatypes.treasure.FishingTreasure;
|
|
|
import com.gmail.nossr50.locale.LocaleLoader;
|
|
|
-import com.gmail.nossr50.skills.Combat;
|
|
|
import com.gmail.nossr50.skills.SkillType;
|
|
|
import com.gmail.nossr50.skills.SkillTools;
|
|
|
import com.gmail.nossr50.util.ItemChecks;
|
|
@@ -37,481 +24,213 @@ import com.gmail.nossr50.util.Misc;
|
|
|
import com.gmail.nossr50.util.Permissions;
|
|
|
import com.gmail.nossr50.util.Users;
|
|
|
|
|
|
-public class Fishing {
|
|
|
- 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 fishermansDietRankLevel1 = AdvancedConfig.getInstance().getFishermanDietRankChange();
|
|
|
+public final class Fishing {
|
|
|
+ static final AdvancedConfig ADVANCED_CONFIG = AdvancedConfig.getInstance();
|
|
|
+
|
|
|
+ // The order of the values is extremely important, Fishing.getLootTier() and ShakeMob.getShakeChance() depend on it to work properly
|
|
|
+ protected enum Tier {
|
|
|
+ FIVE(5) {@Override public int getLevel() {return ADVANCED_CONFIG.getFishingTierLevelsTier5();} @Override public int getShakeChance() {return ADVANCED_CONFIG.getShakeChanceRank5();}},
|
|
|
+ FOUR(4) {@Override public int getLevel() {return ADVANCED_CONFIG.getFishingTierLevelsTier4();} @Override public int getShakeChance() {return ADVANCED_CONFIG.getShakeChanceRank4();}},
|
|
|
+ THREE(3) {@Override public int getLevel() {return ADVANCED_CONFIG.getFishingTierLevelsTier3();} @Override public int getShakeChance() {return ADVANCED_CONFIG.getShakeChanceRank3();}},
|
|
|
+ TWO(2) {@Override public int getLevel() {return ADVANCED_CONFIG.getFishingTierLevelsTier2();} @Override public int getShakeChance() {return ADVANCED_CONFIG.getShakeChanceRank2();}},
|
|
|
+ ONE(1) {@Override public int getLevel() {return ADVANCED_CONFIG.getFishingTierLevelsTier1();} @Override public int getShakeChance() {return ADVANCED_CONFIG.getShakeChanceRank1();}};
|
|
|
+
|
|
|
+ int numerical;
|
|
|
+
|
|
|
+ private Tier(int numerical) {
|
|
|
+ this.numerical = numerical;
|
|
|
+ }
|
|
|
+
|
|
|
+ public int toNumerical() {
|
|
|
+ return numerical;
|
|
|
+ }
|
|
|
+
|
|
|
+ abstract protected int getLevel();
|
|
|
+ abstract protected int getShakeChance();
|
|
|
+ }
|
|
|
+
|
|
|
+ // TODO: Get rid of that
|
|
|
+ public static int fishermansDietRankLevel1 = ADVANCED_CONFIG.getFishermanDietRankChange();
|
|
|
public static int fishermansDietRankLevel2 = fishermansDietRankLevel1 * 2;
|
|
|
public static int fishermansDietMaxLevel = fishermansDietRankLevel1 * 5;
|
|
|
|
|
|
- public static int magicHunterMultiplier = AdvancedConfig.getInstance().getFishingMagicMultiplier();
|
|
|
+ private Fishing() {}
|
|
|
|
|
|
- public static void fishermansDiet(Player player, int rankChange, FoodLevelChangeEvent event) {
|
|
|
+ /**
|
|
|
+ * Begins Fisherman's Diet ability
|
|
|
+ *
|
|
|
+ * @param player Player using the ability
|
|
|
+ * @param rankChange ???
|
|
|
+ * @param event Event to process
|
|
|
+ */
|
|
|
+ public static void beginFishermansDiet(Player player, int rankChange, FoodLevelChangeEvent event) {
|
|
|
+ // TODO: The permission should probably not be checked here
|
|
|
+ // TODO: Also I don't like the idea of moving event around
|
|
|
if (!Permissions.fishermansDiet(player)) {
|
|
|
return;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
SkillTools.handleFoodSkills(player, SkillType.FISHING, event, fishermansDietRankLevel1, fishermansDietMaxLevel, rankChange);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Get the player's current fishing loot tier.
|
|
|
- *
|
|
|
- * @param profile
|
|
|
- * The profile of the player
|
|
|
- * @return the player's current fishing rank
|
|
|
+ * Begins Shake Mob ability
|
|
|
+ *
|
|
|
+ * @param player Player using the ability
|
|
|
+ * @param mob Targeted mob
|
|
|
+ * @param skillLevel Fishing level of the player
|
|
|
*/
|
|
|
- public static int getFishingLootTier(PlayerProfile profile) {
|
|
|
- int level = profile.getSkillLevel(SkillType.FISHING);
|
|
|
- int fishingTier;
|
|
|
-
|
|
|
- if (level >= fishingTierLevel5) {
|
|
|
- fishingTier = 5;
|
|
|
- } else if (level >= fishingTierLevel4) {
|
|
|
- fishingTier = 4;
|
|
|
- } else if (level >= fishingTierLevel3) {
|
|
|
- fishingTier = 3;
|
|
|
- } else if (level >= fishingTierLevel2) {
|
|
|
- fishingTier = 2;
|
|
|
- } else {
|
|
|
- fishingTier = 1;
|
|
|
- }
|
|
|
-
|
|
|
- return fishingTier;
|
|
|
+ public static void beginShakeMob(Player player, LivingEntity mob, int skillLevel) {
|
|
|
+ ShakeMob.process(player, mob, skillLevel);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Get item results from Fishing.
|
|
|
- *
|
|
|
- * @param player
|
|
|
- * The player that was fishing
|
|
|
- * @param event
|
|
|
- * The event to modify
|
|
|
+ * Begins Fishing
|
|
|
+ *
|
|
|
+ * @param player Player fishing
|
|
|
+ * @param skillLevel Fishing level of the player
|
|
|
+ * @param event Event to process
|
|
|
*/
|
|
|
- private static void getFishingResults(Player player, PlayerFishEvent event) {
|
|
|
- if (player == null)
|
|
|
- return;
|
|
|
-
|
|
|
- PlayerProfile profile = Users.getProfile(player);
|
|
|
- Item theCatch = (Item) event.getCaught();
|
|
|
-
|
|
|
- if (Config.getInstance().getFishingDropsEnabled() && Permissions.fishingTreasures(player)) {
|
|
|
- int skillLevel = profile.getSkillLevel(SkillType.FISHING);
|
|
|
- List<FishingTreasure> rewards = new ArrayList<FishingTreasure>();
|
|
|
+ public static void beginFishing(Player player, int skillLevel, PlayerFishEvent event) {
|
|
|
+ // TODO: Find a way to not pass the event directly
|
|
|
+ int xp = 0;
|
|
|
+ FishingTreasure treasure = checkForTreasure(player, skillLevel);
|
|
|
|
|
|
- for (FishingTreasure treasure : TreasuresConfig.getInstance().fishingRewards) {
|
|
|
- int maxLevel = treasure.getMaxLevel();
|
|
|
-
|
|
|
- if (treasure.getDropLevel() <= skillLevel && (maxLevel >= skillLevel || maxLevel <= 0)) {
|
|
|
- rewards.add(treasure);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- if (rewards.isEmpty()) {
|
|
|
- return;
|
|
|
- }
|
|
|
+ if (treasure != null) {
|
|
|
+ player.sendMessage(LocaleLoader.getString("Fishing.ItemFound"));
|
|
|
|
|
|
- FishingTreasure treasure = rewards.get(Misc.getRandom().nextInt(rewards.size()));
|
|
|
+ xp += treasure.getXp();
|
|
|
ItemStack treasureDrop = treasure.getDrop();
|
|
|
|
|
|
- int activationChance = Misc.calculateActivationChance(Permissions.luckyFishing(player));
|
|
|
-
|
|
|
- if (Misc.getRandom().nextDouble() * activationChance <= treasure.getDropChance()) {
|
|
|
- player.getWorld().dropItem(player.getEyeLocation(), theCatch.getItemStack()); // Drop the original item
|
|
|
-
|
|
|
- short maxDurability = treasureDrop.getType().getMaxDurability();
|
|
|
-
|
|
|
- if (maxDurability > 0) {
|
|
|
- treasureDrop.setDurability((short) (Misc.getRandom().nextInt(maxDurability))); // Change durability to random value
|
|
|
- }
|
|
|
-
|
|
|
- theCatch.setItemStack(treasureDrop);
|
|
|
- Users.getPlayer(player).addXP(SkillType.FISHING, treasure.getXp());
|
|
|
+ if (Permissions.fishingMagic(player) && beginMagicHunter(player, skillLevel, treasureDrop, player.getWorld().hasStorm())) {
|
|
|
+ player.sendMessage(LocaleLoader.getString("Fishing.MagicFound"));
|
|
|
}
|
|
|
+
|
|
|
+ // Drop the original catch at the feet of the player and set the treasure as the real catch
|
|
|
+ Item caught = (Item) event.getCaught();
|
|
|
+ Misc.dropItem(player.getEyeLocation(), caught.getItemStack());
|
|
|
+ caught.setItemStack(treasureDrop);
|
|
|
}
|
|
|
|
|
|
- SkillTools.xpProcessing(player, profile, SkillType.FISHING, Config.getInstance().getFishingBaseXP());
|
|
|
+ SkillTools.xpProcessing(player, Users.getProfile(player), SkillType.FISHING, Config.getInstance().getFishingBaseXP() + xp);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Process results from Fishing.
|
|
|
- *
|
|
|
- * @param event
|
|
|
- * The event to modify
|
|
|
+ * Checks for treasure
|
|
|
+ *
|
|
|
+ * @param player Player fishing
|
|
|
+ * @param skillLevel Fishing level of the player
|
|
|
+ * @return Chosen treasure
|
|
|
*/
|
|
|
- public static void processResults(PlayerFishEvent event) {
|
|
|
- Player player = event.getPlayer();
|
|
|
-
|
|
|
- getFishingResults(player, event);
|
|
|
- Item theCatch = (Item) event.getCaught();
|
|
|
-
|
|
|
- if (theCatch.getItemStack().getType() != Material.RAW_FISH) {
|
|
|
- int lootTier = Fishing.getFishingLootTier(Users.getProfile(player));
|
|
|
- int specificChance = 1;
|
|
|
- boolean enchanted = false;
|
|
|
- ItemStack fishingResults = theCatch.getItemStack();
|
|
|
-
|
|
|
- player.sendMessage(LocaleLoader.getString("Fishing.ItemFound"));
|
|
|
-
|
|
|
- if (ItemChecks.isEnchantable(fishingResults)) {
|
|
|
- int activationChance = Misc.calculateActivationChance(Permissions.luckyFishing(player));
|
|
|
+ private static FishingTreasure checkForTreasure(Player player, int skillLevel) {
|
|
|
+ if (!Config.getInstance().getFishingDropsEnabled() || !Permissions.fishingTreasures(player)) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
|
|
|
- if (player.getWorld().hasStorm()) {
|
|
|
- activationChance = (int) (activationChance * 0.909);
|
|
|
- }
|
|
|
+ List<FishingTreasure> rewards = new ArrayList<FishingTreasure>();
|
|
|
|
|
|
- /* CHANCE OF ITEM BEING ENCHANTED
|
|
|
- * 5% - Tier 1
|
|
|
- * 10% - Tier 2
|
|
|
- * 15% - Tier 3
|
|
|
- * 20% - Tier 4
|
|
|
- * 25% - Tier 5
|
|
|
- */
|
|
|
- if (Misc.getRandom().nextInt(activationChance) <= (lootTier * magicHunterMultiplier) && Permissions.fishingMagic(player)) {
|
|
|
- for (Enchantment newEnchant : Enchantment.values()) {
|
|
|
- boolean conflicts = false;
|
|
|
-
|
|
|
- if (newEnchant.canEnchantItem(fishingResults)) {
|
|
|
- specificChance++;
|
|
|
-
|
|
|
- for (Enchantment oldEnchant : fishingResults.getEnchantments().keySet()) {
|
|
|
- conflicts = oldEnchant.conflictsWith(newEnchant);
|
|
|
-
|
|
|
- if (conflicts) {
|
|
|
- specificChance--;
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /* CHANCE OF GETTING EACH ENCHANTMENT
|
|
|
- * 50% - 1st Enchantment
|
|
|
- * 33% - 2nd Enchantment
|
|
|
- * 25% - 3rd Enchantment
|
|
|
- * 20% - 4th Enchantment
|
|
|
- * 16.66% - 5th Enchantment
|
|
|
- * 14.29% - 6th Enchantment
|
|
|
- * 12.5% - 7th Enchantment
|
|
|
- * 11.11% - 8th Enchantment
|
|
|
- */
|
|
|
- if (!conflicts && Misc.getRandom().nextInt(specificChance) < 1) {
|
|
|
- enchanted = true;
|
|
|
- int randomEnchantLevel = Misc.getRandom().nextInt(newEnchant.getMaxLevel()) + 1;
|
|
|
-
|
|
|
- if (randomEnchantLevel < newEnchant.getStartLevel()) {
|
|
|
- randomEnchantLevel = newEnchant.getStartLevel();
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- fishingResults.addEnchantment(newEnchant, randomEnchantLevel);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
+ for (FishingTreasure treasure : TreasuresConfig.getInstance().fishingRewards) {
|
|
|
+ int maxLevel = treasure.getMaxLevel();
|
|
|
|
|
|
- if (enchanted) {
|
|
|
- player.sendMessage(LocaleLoader.getString("Fishing.MagicFound"));
|
|
|
+ if (treasure.getDropLevel() <= skillLevel && (maxLevel >= skillLevel || maxLevel <= 0)) {
|
|
|
+ rewards.add(treasure);
|
|
|
}
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
- /**
|
|
|
- * Shake a mob, have them drop an item.
|
|
|
- *
|
|
|
- * @param event
|
|
|
- * The event to modify
|
|
|
- */
|
|
|
- public static void shakeMob(PlayerFishEvent event) {
|
|
|
- Entity caughtEntity = event.getCaught();
|
|
|
-
|
|
|
- if (!(caughtEntity instanceof LivingEntity)) {
|
|
|
- return;
|
|
|
+ if (rewards.isEmpty()) {
|
|
|
+ return null;
|
|
|
}
|
|
|
|
|
|
- Player player = event.getPlayer();
|
|
|
+ FishingTreasure treasure = rewards.get(Misc.getRandom().nextInt(rewards.size()));
|
|
|
+ ItemStack treasureDrop = treasure.getDrop();
|
|
|
+ int activationChance = Misc.calculateActivationChance(Permissions.luckyFishing(player));
|
|
|
|
|
|
- if (Users.getProfile(player).getSkillLevel(SkillType.FISHING) < Fishing.shakeUnlockLevel || !Permissions.shakeMob(player)) {
|
|
|
- return;
|
|
|
+ if (Misc.getRandom().nextDouble() * activationChance > treasure.getDropChance()) {
|
|
|
+ return null;
|
|
|
}
|
|
|
|
|
|
- int randomChance = 100;
|
|
|
+ short maxDurability = treasureDrop.getType().getMaxDurability();
|
|
|
|
|
|
- //TODO: Invert this so it matches the rest of our lucky checks...
|
|
|
- if (Permissions.luckyFishing(event.getPlayer())) {
|
|
|
- randomChance = 125;
|
|
|
+ if (maxDurability > 0) {
|
|
|
+ treasureDrop.setDurability((short) (Misc.getRandom().nextInt(maxDurability)));
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- final PlayerProfile profile = Users.getProfile(player);
|
|
|
- int lootTier = getFishingLootTier(profile);
|
|
|
+ return treasure;
|
|
|
+ }
|
|
|
|
|
|
- int dropChance = getShakeChance(lootTier);
|
|
|
-
|
|
|
- if (Permissions.luckyFishing(player)) {
|
|
|
- // With lucky perk on max level tier, its 100%
|
|
|
- dropChance = (int) (dropChance * 1.25);
|
|
|
+ /**
|
|
|
+ * Processes for treasure
|
|
|
+ *
|
|
|
+ * @param player Player fishing
|
|
|
+ * @param skillLevel Fishing level of the player
|
|
|
+ * @param itemStack ItemStack to enchant
|
|
|
+ * @param storm World's weather
|
|
|
+ * @return True if the ItemStack has been enchanted
|
|
|
+ */
|
|
|
+ private static boolean beginMagicHunter(Player player, int skillLevel, ItemStack itemStack, boolean storm) {
|
|
|
+ if (!ItemChecks.isEnchantable(itemStack)) {
|
|
|
+ return false;
|
|
|
}
|
|
|
|
|
|
- final int DROP_CHANCE = Misc.getRandom().nextInt(100);
|
|
|
- final int DROP_NUMBER = Misc.getRandom().nextInt(randomChance) + 1;
|
|
|
-
|
|
|
- LivingEntity le = (LivingEntity) event.getCaught();
|
|
|
- EntityType type = le.getType();
|
|
|
- Location location = le.getLocation();
|
|
|
-
|
|
|
- if (DROP_CHANCE < dropChance) {
|
|
|
-
|
|
|
- switch (type) {
|
|
|
- case BLAZE:
|
|
|
- Misc.dropItem(location, new ItemStack(Material.BLAZE_ROD));
|
|
|
- break;
|
|
|
+ int activationChance = Misc.calculateActivationChance(Permissions.luckyFishing(player));
|
|
|
|
|
|
- case CAVE_SPIDER:
|
|
|
- if (DROP_NUMBER > 50) {
|
|
|
- Misc.dropItem(location, new ItemStack(Material.SPIDER_EYE));
|
|
|
- } else {
|
|
|
- Misc.dropItem(location, new ItemStack(Material.STRING));
|
|
|
- }
|
|
|
- break;
|
|
|
-
|
|
|
- case CHICKEN:
|
|
|
- if (DROP_NUMBER > 66) {
|
|
|
- Misc.dropItem(location, new ItemStack(Material.FEATHER));
|
|
|
- } else if (DROP_NUMBER > 33) {
|
|
|
- Misc.dropItem(location, new ItemStack(Material.RAW_CHICKEN));
|
|
|
- } else {
|
|
|
- Misc.dropItem(location, new ItemStack(Material.EGG));
|
|
|
- }
|
|
|
- break;
|
|
|
-
|
|
|
- case COW:
|
|
|
- if (DROP_NUMBER > 95) {
|
|
|
- Misc.dropItem(location, new ItemStack(Material.MILK_BUCKET));
|
|
|
- } else if (DROP_NUMBER > 50) {
|
|
|
- Misc.dropItem(location, new ItemStack(Material.LEATHER));
|
|
|
- } else {
|
|
|
- Misc.dropItem(location, new ItemStack(Material.RAW_BEEF));
|
|
|
- }
|
|
|
- break;
|
|
|
-
|
|
|
- case CREEPER:
|
|
|
- if (DROP_NUMBER > 97) {
|
|
|
- Misc.dropItem(location, new ItemStack(Material.SKULL_ITEM, 1, (short) 4));
|
|
|
- } else {
|
|
|
- Misc.dropItem(location, new ItemStack(Material.SULPHUR));
|
|
|
- }
|
|
|
- break;
|
|
|
-
|
|
|
- case ENDERMAN:
|
|
|
- Misc.dropItem(location, new ItemStack(Material.ENDER_PEARL));
|
|
|
- break;
|
|
|
-
|
|
|
- case GHAST:
|
|
|
- if (DROP_NUMBER > 50) {
|
|
|
- Misc.dropItem(location, new ItemStack(Material.SULPHUR));
|
|
|
- } else {
|
|
|
- Misc.dropItem(location, new ItemStack(Material.GHAST_TEAR));
|
|
|
- }
|
|
|
- break;
|
|
|
-
|
|
|
- case IRON_GOLEM:
|
|
|
- if (DROP_NUMBER > 97) {
|
|
|
- Misc.dropItem(location, new ItemStack(Material.PUMPKIN));
|
|
|
- } else if (DROP_NUMBER > 85) {
|
|
|
- Misc.dropItem(location, new ItemStack(Material.IRON_INGOT));
|
|
|
- } else {
|
|
|
- Misc.dropItem(location, new ItemStack(Material.RED_ROSE));
|
|
|
- }
|
|
|
- break;
|
|
|
-
|
|
|
- case MAGMA_CUBE:
|
|
|
- Misc.dropItem(location, new ItemStack(Material.MAGMA_CREAM));
|
|
|
- break;
|
|
|
-
|
|
|
- case MUSHROOM_COW:
|
|
|
- if (DROP_NUMBER > 95) {
|
|
|
- Misc.dropItem(location, new ItemStack(Material.MILK_BUCKET));
|
|
|
- } else if (DROP_NUMBER > 90) {
|
|
|
- Misc.dropItem(location, new ItemStack(Material.MUSHROOM_SOUP));
|
|
|
- } else if (DROP_NUMBER > 60) {
|
|
|
- Misc.dropItem(location, new ItemStack(Material.LEATHER));
|
|
|
- } else if (DROP_NUMBER > 30) {
|
|
|
- Misc.dropItem(location, new ItemStack(Material.RAW_BEEF));
|
|
|
- } else {
|
|
|
- Misc.dropItem(location, new ItemStack(Material.RED_MUSHROOM));
|
|
|
- Misc.randomDropItems(location, new ItemStack(Material.RED_MUSHROOM), 50, 2);
|
|
|
- }
|
|
|
- break;
|
|
|
+ if (storm) {
|
|
|
+ activationChance = (int) (activationChance * 0.909);
|
|
|
+ }
|
|
|
|
|
|
- case PIG:
|
|
|
- Misc.dropItem(location, new ItemStack(Material.PORK));
|
|
|
- break;
|
|
|
+ if (Misc.getRandom().nextInt(activationChance) > getLootTier(skillLevel) * ADVANCED_CONFIG.getFishingMagicMultiplier()) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
|
|
|
- case PIG_ZOMBIE:
|
|
|
- if (DROP_NUMBER > 50) {
|
|
|
- Misc.dropItem(location, new ItemStack(Material.ROTTEN_FLESH));
|
|
|
- } else {
|
|
|
- Misc.dropItem(location, new ItemStack(Material.GOLD_NUGGET));
|
|
|
- }
|
|
|
- break;
|
|
|
+ List<Enchantment> possibleEnchantments = new ArrayList<Enchantment>();
|
|
|
|
|
|
- case SHEEP:
|
|
|
- final Sheep sheep = (Sheep) le;
|
|
|
+ for (Enchantment enchantment : Enchantment.values()) {
|
|
|
+ if (enchantment.canEnchantItem(itemStack)) {
|
|
|
+ possibleEnchantments.add(enchantment);
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- if (!sheep.isSheared()) {
|
|
|
- final Wool wool = new Wool();
|
|
|
- wool.setColor(sheep.getColor());
|
|
|
+ // This make sure that the order isn't always the same, for example previously Unbreaking had a lot more chance to be used than any other enchant
|
|
|
+ Collections.shuffle(possibleEnchantments, Misc.getRandom());
|
|
|
|
|
|
- final ItemStack theWool = wool.toItemStack();
|
|
|
- theWool.setAmount(1 + Misc.getRandom().nextInt(6));
|
|
|
+ boolean enchanted = false;
|
|
|
+ int specificChance = 1;
|
|
|
|
|
|
- Misc.dropItem(location, theWool);
|
|
|
- sheep.setSheared(true);
|
|
|
- }
|
|
|
- break;
|
|
|
-
|
|
|
- case SKELETON:
|
|
|
- if (((Skeleton) le).getSkeletonType() == SkeletonType.WITHER) {
|
|
|
- if (DROP_NUMBER > 97) {
|
|
|
- Misc.dropItem(location, new ItemStack(Material.SKULL_ITEM, 1, (short) 1));
|
|
|
- } else if (DROP_NUMBER > 50) {
|
|
|
- Misc.dropItem(location, new ItemStack(Material.BONE));
|
|
|
- } else {
|
|
|
- Misc.dropItem(location, new ItemStack(Material.COAL));
|
|
|
- Misc.randomDropItems(location, new ItemStack(Material.COAL), 50, 2);
|
|
|
- }
|
|
|
- } else {
|
|
|
- if (DROP_NUMBER > 97) {
|
|
|
- Misc.dropItem(location, new ItemStack(Material.SKULL_ITEM));
|
|
|
- } else if (DROP_NUMBER > 50) {
|
|
|
- Misc.dropItem(location, new ItemStack(Material.BONE));
|
|
|
- } else {
|
|
|
- Misc.dropItem(location, new ItemStack(Material.ARROW));
|
|
|
- Misc.randomDropItems(location, new ItemStack(Material.ARROW), 50, 2);
|
|
|
- }
|
|
|
- }
|
|
|
- break;
|
|
|
-
|
|
|
- case SLIME:
|
|
|
- Misc.dropItem(location, new ItemStack(Material.SLIME_BALL));
|
|
|
- break;
|
|
|
-
|
|
|
- case SNOWMAN:
|
|
|
- if (DROP_NUMBER > 97) {
|
|
|
- Misc.dropItem(location, new ItemStack(Material.PUMPKIN));
|
|
|
- } else {
|
|
|
- Misc.dropItem(location, new ItemStack(Material.SNOW_BALL));
|
|
|
- Misc.randomDropItems(location, new ItemStack(Material.SNOW_BALL), 50, 4);
|
|
|
- }
|
|
|
- break;
|
|
|
+ for (Enchantment possibleEnchantment : possibleEnchantments) {
|
|
|
+ boolean conflicts = false;
|
|
|
|
|
|
- case SPIDER:
|
|
|
- if (DROP_NUMBER > 50) {
|
|
|
- Misc.dropItem(location, new ItemStack(Material.SPIDER_EYE));
|
|
|
- } else {
|
|
|
- Misc.dropItem(location, new ItemStack(Material.STRING));
|
|
|
- }
|
|
|
- break;
|
|
|
+ for (Enchantment currentEnchantment : itemStack.getEnchantments().keySet()) {
|
|
|
+ conflicts = currentEnchantment.conflictsWith(possibleEnchantment);
|
|
|
|
|
|
- case SQUID:
|
|
|
- ItemStack item;
|
|
|
- try {
|
|
|
- item = (new MaterialData(Material.INK_SACK, DyeColor.BLACK.getDyeData())).toItemStack(1);
|
|
|
- }
|
|
|
- catch(Exception e) {
|
|
|
- item = (new MaterialData(Material.INK_SACK, (byte) 0)).toItemStack(1);
|
|
|
+ if (conflicts) {
|
|
|
+ break;
|
|
|
}
|
|
|
- catch(NoSuchMethodError e) {
|
|
|
- item = (new MaterialData(Material.INK_SACK, (byte) 0)).toItemStack(1);
|
|
|
- }
|
|
|
-
|
|
|
- Misc.dropItem(location, item);
|
|
|
- break;
|
|
|
-
|
|
|
- case WITCH:
|
|
|
- final int DROP_NUMBER_2 = Misc.getRandom().nextInt(randomChance) + 1;
|
|
|
- if (DROP_NUMBER > 95) {
|
|
|
- if (DROP_NUMBER_2 > 66) {
|
|
|
- Misc.dropItem(location, new Potion(PotionType.INSTANT_HEAL).toItemStack(1));
|
|
|
- } else if (DROP_NUMBER_2 > 33) {
|
|
|
- Misc.dropItem(location, new Potion(PotionType.FIRE_RESISTANCE).toItemStack(1));
|
|
|
- } else {
|
|
|
- Misc.dropItem(location, new Potion(PotionType.SPEED).toItemStack(1));
|
|
|
- }
|
|
|
- } else {
|
|
|
- if (DROP_NUMBER_2 > 88) {
|
|
|
- Misc.dropItem(location, new ItemStack(Material.GLASS_BOTTLE));
|
|
|
- } else if (DROP_NUMBER_2 > 75) {
|
|
|
- Misc.dropItem(location, new ItemStack(Material.GLOWSTONE_DUST));
|
|
|
- } else if (DROP_NUMBER_2 > 63) {
|
|
|
- Misc.dropItem(location, new ItemStack(Material.SULPHUR));
|
|
|
- } else if (DROP_NUMBER_2 > 50) {
|
|
|
- Misc.dropItem(location, new ItemStack(Material.REDSTONE));
|
|
|
- } else if (DROP_NUMBER_2 > 38) {
|
|
|
- Misc.dropItem(location, new ItemStack(Material.SPIDER_EYE));
|
|
|
- } else if (DROP_NUMBER_2 > 25) {
|
|
|
- Misc.dropItem(location, new ItemStack(Material.STICK));
|
|
|
- } else if (DROP_NUMBER_2 > 13) {
|
|
|
- Misc.dropItem(location, new ItemStack(Material.SUGAR));
|
|
|
- } else {
|
|
|
- Misc.dropItem(location, new ItemStack(Material.POTION));
|
|
|
- }
|
|
|
- }
|
|
|
- break;
|
|
|
+ }
|
|
|
|
|
|
- case ZOMBIE:
|
|
|
- if (DROP_NUMBER > 97) {
|
|
|
- Misc.dropItem(location, new ItemStack(Material.SKULL_ITEM, 1, (short) 2));
|
|
|
- } else {
|
|
|
- Misc.dropItem(location, new ItemStack(Material.ROTTEN_FLESH));
|
|
|
- }
|
|
|
- break;
|
|
|
+ if (!conflicts && Misc.getRandom().nextInt(specificChance) == 0) {
|
|
|
+ itemStack.addEnchantment(possibleEnchantment, Misc.getRandom().nextInt(possibleEnchantment.getMaxLevel()) + 1);
|
|
|
|
|
|
- default:
|
|
|
- break;
|
|
|
+ specificChance++;
|
|
|
+ enchanted = true;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- Combat.dealDamage(le, 1);
|
|
|
+ return enchanted;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Gets chance of shake success.
|
|
|
- *
|
|
|
- * @param rank
|
|
|
- * Treasure hunter rank
|
|
|
- * @return The chance of a successful shake
|
|
|
+ * Gets the loot tier for a given skill level
|
|
|
+ *
|
|
|
+ * @param skillLevel Fishing skill level
|
|
|
+ * @return Loot tier
|
|
|
*/
|
|
|
- public static int getShakeChance(int lootTier) {
|
|
|
- switch (lootTier) {
|
|
|
- case 1:
|
|
|
- return shakeChanceLevel1;
|
|
|
-
|
|
|
- case 2:
|
|
|
- return shakeChanceLevel2;
|
|
|
-
|
|
|
- case 3:
|
|
|
- return shakeChanceLevel3;
|
|
|
-
|
|
|
- case 4:
|
|
|
- return shakeChanceLevel4;
|
|
|
-
|
|
|
- case 5:
|
|
|
- return shakeChanceLevel5;
|
|
|
-
|
|
|
- default:
|
|
|
- return 10;
|
|
|
+ public static int getLootTier(int skillLevel) {
|
|
|
+ for (Tier tier : Tier.values()) {
|
|
|
+ if (skillLevel >= tier.getLevel()) {
|
|
|
+ return tier.toNumerical();
|
|
|
+ }
|
|
|
}
|
|
|
+
|
|
|
+ return 0;
|
|
|
}
|
|
|
}
|