2013-01-22 18:43:25 +01:00
|
|
|
package com.gmail.nossr50.skills.fishing;
|
2011-11-28 14:17:01 +01:00
|
|
|
|
2012-03-13 08:00:49 +01:00
|
|
|
import java.util.ArrayList;
|
2013-01-30 00:12:55 +01:00
|
|
|
import java.util.Collections;
|
2012-02-21 19:10:51 +01:00
|
|
|
import java.util.List;
|
|
|
|
|
2011-12-01 18:46:46 +01:00
|
|
|
import org.bukkit.enchantments.Enchantment;
|
2012-03-13 08:00:49 +01:00
|
|
|
import org.bukkit.entity.Item;
|
|
|
|
import org.bukkit.entity.LivingEntity;
|
|
|
|
import org.bukkit.entity.Player;
|
2013-01-25 02:10:50 +01:00
|
|
|
import org.bukkit.event.entity.FoodLevelChangeEvent;
|
2013-01-30 23:29:36 +01:00
|
|
|
import org.bukkit.event.player.PlayerFishEvent;
|
2011-11-28 14:17:01 +01:00
|
|
|
import org.bukkit.inventory.ItemStack;
|
|
|
|
|
2012-11-21 21:49:54 +01:00
|
|
|
import com.gmail.nossr50.config.AdvancedConfig;
|
2012-04-26 16:27:57 +02:00
|
|
|
import com.gmail.nossr50.config.Config;
|
2012-05-17 16:26:21 +02:00
|
|
|
import com.gmail.nossr50.config.TreasuresConfig;
|
2013-02-01 06:38:25 +01:00
|
|
|
import com.gmail.nossr50.datatypes.McMMOPlayer;
|
2012-02-21 08:53:34 +01:00
|
|
|
import com.gmail.nossr50.datatypes.treasure.FishingTreasure;
|
2012-04-27 11:47:11 +02:00
|
|
|
import com.gmail.nossr50.locale.LocaleLoader;
|
2013-01-30 17:53:51 +01:00
|
|
|
import com.gmail.nossr50.skills.utilities.SkillTools;
|
|
|
|
import com.gmail.nossr50.skills.utilities.SkillType;
|
2012-04-27 11:47:11 +02:00
|
|
|
import com.gmail.nossr50.util.ItemChecks;
|
|
|
|
import com.gmail.nossr50.util.Misc;
|
2012-04-30 14:26:37 +02:00
|
|
|
import com.gmail.nossr50.util.Permissions;
|
2011-11-28 14:17:01 +01:00
|
|
|
|
2013-01-30 00:12:55 +01:00
|
|
|
public final class Fishing {
|
|
|
|
static final AdvancedConfig ADVANCED_CONFIG = AdvancedConfig.getInstance();
|
|
|
|
|
2013-01-30 22:51:11 +01:00
|
|
|
// The order of the values is extremely important, a few methods depend on it to work properly
|
2013-01-30 00:12:55 +01:00
|
|
|
protected enum Tier {
|
2013-01-30 19:24:56 +01:00
|
|
|
FIVE(5) {
|
|
|
|
@Override public int getLevel() {return ADVANCED_CONFIG.getFishingTierLevelsTier5();}
|
|
|
|
@Override public int getShakeChance() {return ADVANCED_CONFIG.getShakeChanceRank5();}
|
|
|
|
@Override public int getVanillaXPBoostModifier() {return ADVANCED_CONFIG.getFishingVanillaXPModifierRank5();}},
|
|
|
|
FOUR(4) {
|
|
|
|
@Override public int getLevel() {return ADVANCED_CONFIG.getFishingTierLevelsTier4();}
|
|
|
|
@Override public int getShakeChance() {return ADVANCED_CONFIG.getShakeChanceRank4();}
|
|
|
|
@Override public int getVanillaXPBoostModifier() {return ADVANCED_CONFIG.getFishingVanillaXPModifierRank4();}},
|
|
|
|
THREE(3) {
|
|
|
|
@Override public int getLevel() {return ADVANCED_CONFIG.getFishingTierLevelsTier3();}
|
|
|
|
@Override public int getShakeChance() {return ADVANCED_CONFIG.getShakeChanceRank3();}
|
|
|
|
@Override public int getVanillaXPBoostModifier() {return ADVANCED_CONFIG.getFishingVanillaXPModifierRank3();}},
|
|
|
|
TWO(2) {
|
|
|
|
@Override public int getLevel() {return ADVANCED_CONFIG.getFishingTierLevelsTier2();}
|
|
|
|
@Override public int getShakeChance() {return ADVANCED_CONFIG.getShakeChanceRank2();}
|
|
|
|
@Override public int getVanillaXPBoostModifier() {return ADVANCED_CONFIG.getFishingVanillaXPModifierRank2();}},
|
|
|
|
ONE(1) {
|
|
|
|
@Override public int getLevel() {return ADVANCED_CONFIG.getFishingTierLevelsTier1();}
|
|
|
|
@Override public int getShakeChance() {return ADVANCED_CONFIG.getShakeChanceRank1();}
|
|
|
|
@Override public int getVanillaXPBoostModifier() {return ADVANCED_CONFIG.getFishingVanillaXPModifierRank1();}};
|
2013-01-30 00:12:55 +01:00
|
|
|
|
|
|
|
int numerical;
|
|
|
|
|
|
|
|
private Tier(int numerical) {
|
|
|
|
this.numerical = numerical;
|
|
|
|
}
|
|
|
|
|
|
|
|
public int toNumerical() {
|
|
|
|
return numerical;
|
|
|
|
}
|
|
|
|
|
|
|
|
abstract protected int getLevel();
|
|
|
|
abstract protected int getShakeChance();
|
2013-01-30 19:24:56 +01:00
|
|
|
abstract protected int getVanillaXPBoostModifier();
|
2013-01-30 00:12:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: Get rid of that
|
|
|
|
public static int fishermansDietRankLevel1 = ADVANCED_CONFIG.getFishermanDietRankChange();
|
2013-01-25 02:10:50 +01:00
|
|
|
public static int fishermansDietRankLevel2 = fishermansDietRankLevel1 * 2;
|
|
|
|
public static int fishermansDietMaxLevel = fishermansDietRankLevel1 * 5;
|
2013-01-22 07:52:34 +01:00
|
|
|
|
2013-01-30 00:12:55 +01:00
|
|
|
private Fishing() {}
|
2012-03-26 17:04:17 +02:00
|
|
|
|
2013-01-30 00:12:55 +01:00
|
|
|
/**
|
|
|
|
* 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
|
2013-01-25 02:10:50 +01:00
|
|
|
if (!Permissions.fishermansDiet(player)) {
|
|
|
|
return;
|
|
|
|
}
|
2013-01-30 00:12:55 +01:00
|
|
|
|
2013-01-26 23:01:55 +01:00
|
|
|
SkillTools.handleFoodSkills(player, SkillType.FISHING, event, fishermansDietRankLevel1, fishermansDietMaxLevel, rankChange);
|
2013-01-25 02:10:50 +01:00
|
|
|
}
|
|
|
|
|
2012-03-13 08:00:49 +01:00
|
|
|
/**
|
2013-01-30 00:12:55 +01:00
|
|
|
* Begins Shake Mob ability
|
|
|
|
*
|
|
|
|
* @param player Player using the ability
|
|
|
|
* @param mob Targeted mob
|
|
|
|
* @param skillLevel Fishing level of the player
|
2012-03-13 08:00:49 +01:00
|
|
|
*/
|
2013-01-30 00:12:55 +01:00
|
|
|
public static void beginShakeMob(Player player, LivingEntity mob, int skillLevel) {
|
|
|
|
ShakeMob.process(player, mob, skillLevel);
|
2012-03-13 08:00:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-01-30 00:12:55 +01:00
|
|
|
* Begins Fishing
|
|
|
|
*
|
2013-02-01 06:38:25 +01:00
|
|
|
* @param mcMMOPlayer Player fishing
|
2013-01-30 00:12:55 +01:00
|
|
|
* @param skillLevel Fishing level of the player
|
2013-01-30 23:29:36 +01:00
|
|
|
* @param event Event to process
|
2012-03-13 08:00:49 +01:00
|
|
|
*/
|
2013-02-01 06:38:25 +01:00
|
|
|
public static void beginFishing(McMMOPlayer mcMMOPlayer, int skillLevel, PlayerFishEvent event) {
|
2013-01-30 22:51:11 +01:00
|
|
|
int treasureXp = 0;
|
2013-02-01 06:38:25 +01:00
|
|
|
Player player = mcMMOPlayer.getPlayer();
|
2013-01-30 00:12:55 +01:00
|
|
|
FishingTreasure treasure = checkForTreasure(player, skillLevel);
|
2013-01-11 23:55:54 +01:00
|
|
|
|
2013-01-30 00:12:55 +01:00
|
|
|
if (treasure != null) {
|
|
|
|
player.sendMessage(LocaleLoader.getString("Fishing.ItemFound"));
|
2012-03-13 08:00:49 +01:00
|
|
|
|
2013-01-30 22:51:11 +01:00
|
|
|
treasureXp = treasure.getXp();
|
2013-01-26 00:37:43 +01:00
|
|
|
ItemStack treasureDrop = treasure.getDrop();
|
2012-04-24 15:21:21 +02:00
|
|
|
|
2013-01-30 00:12:55 +01:00
|
|
|
if (Permissions.fishingMagic(player) && beginMagicHunter(player, skillLevel, treasureDrop, player.getWorld().hasStorm())) {
|
|
|
|
player.sendMessage(LocaleLoader.getString("Fishing.MagicFound"));
|
2013-01-26 00:37:43 +01:00
|
|
|
}
|
2013-01-30 00:12:55 +01:00
|
|
|
|
|
|
|
// Drop the original catch at the feet of the player and set the treasure as the real catch
|
2013-01-30 23:29:36 +01:00
|
|
|
Item caught = (Item) event.getCaught();
|
2013-01-30 00:12:55 +01:00
|
|
|
Misc.dropItem(player.getEyeLocation(), caught.getItemStack());
|
|
|
|
caught.setItemStack(treasureDrop);
|
2012-03-27 13:51:30 +02:00
|
|
|
}
|
2012-03-13 08:00:49 +01:00
|
|
|
|
2013-02-03 12:45:19 +01:00
|
|
|
mcMMOPlayer.beginXpGain(SkillType.FISHING, Config.getInstance().getFishingBaseXP() + treasureXp);
|
2013-01-30 23:36:33 +01:00
|
|
|
event.setExpToDrop(event.getExpToDrop() * getVanillaXpMultiplier(skillLevel));
|
2013-01-30 22:51:11 +01:00
|
|
|
}
|
2013-01-30 19:24:56 +01:00
|
|
|
|
2012-03-13 08:00:49 +01:00
|
|
|
/**
|
2013-01-30 00:12:55 +01:00
|
|
|
* Checks for treasure
|
|
|
|
*
|
|
|
|
* @param player Player fishing
|
|
|
|
* @param skillLevel Fishing level of the player
|
|
|
|
* @return Chosen treasure
|
2012-03-13 08:00:49 +01:00
|
|
|
*/
|
2013-01-30 00:12:55 +01:00
|
|
|
private static FishingTreasure checkForTreasure(Player player, int skillLevel) {
|
|
|
|
if (!Config.getInstance().getFishingDropsEnabled() || !Permissions.fishingTreasures(player)) {
|
|
|
|
return null;
|
|
|
|
}
|
2013-01-10 21:22:47 +01:00
|
|
|
|
2013-01-30 00:12:55 +01:00
|
|
|
List<FishingTreasure> rewards = new ArrayList<FishingTreasure>();
|
2013-01-12 23:09:42 +01:00
|
|
|
|
2013-01-30 00:12:55 +01:00
|
|
|
for (FishingTreasure treasure : TreasuresConfig.getInstance().fishingRewards) {
|
|
|
|
int maxLevel = treasure.getMaxLevel();
|
2012-03-13 08:00:49 +01:00
|
|
|
|
2013-01-30 00:12:55 +01:00
|
|
|
if (treasure.getDropLevel() <= skillLevel && (maxLevel >= skillLevel || maxLevel <= 0)) {
|
|
|
|
rewards.add(treasure);
|
2012-03-13 08:00:49 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-30 00:12:55 +01:00
|
|
|
if (rewards.isEmpty()) {
|
|
|
|
return null;
|
2013-01-24 17:45:40 +01:00
|
|
|
}
|
|
|
|
|
2013-01-30 00:12:55 +01:00
|
|
|
FishingTreasure treasure = rewards.get(Misc.getRandom().nextInt(rewards.size()));
|
|
|
|
ItemStack treasureDrop = treasure.getDrop();
|
2013-02-13 22:45:49 +01:00
|
|
|
int activationChance = SkillTools.calculateActivationChance(Permissions.luckyFishing(player));
|
2013-01-24 17:45:40 +01:00
|
|
|
|
2013-01-30 00:12:55 +01:00
|
|
|
if (Misc.getRandom().nextDouble() * activationChance > treasure.getDropChance()) {
|
|
|
|
return null;
|
2013-01-24 17:45:40 +01:00
|
|
|
}
|
|
|
|
|
2013-01-30 00:12:55 +01:00
|
|
|
short maxDurability = treasureDrop.getType().getMaxDurability();
|
2012-07-02 17:09:55 +02:00
|
|
|
|
2013-01-30 00:12:55 +01:00
|
|
|
if (maxDurability > 0) {
|
|
|
|
treasureDrop.setDurability((short) (Misc.getRandom().nextInt(maxDurability)));
|
2012-07-02 17:09:55 +02:00
|
|
|
}
|
|
|
|
|
2013-01-30 00:12:55 +01:00
|
|
|
return treasure;
|
|
|
|
}
|
2012-06-05 15:57:10 +02:00
|
|
|
|
2013-01-30 00:12:55 +01:00
|
|
|
/**
|
|
|
|
* 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;
|
2012-11-07 13:30:20 +01:00
|
|
|
}
|
2012-03-13 08:00:49 +01:00
|
|
|
|
2013-02-13 22:45:49 +01:00
|
|
|
int activationChance = SkillTools.calculateActivationChance(Permissions.luckyFishing(player));
|
2012-11-13 01:33:37 +01:00
|
|
|
|
2013-01-30 00:12:55 +01:00
|
|
|
if (storm) {
|
|
|
|
activationChance = (int) (activationChance * 0.909);
|
|
|
|
}
|
2012-11-13 01:33:37 +01:00
|
|
|
|
2013-01-30 00:12:55 +01:00
|
|
|
if (Misc.getRandom().nextInt(activationChance) > getLootTier(skillLevel) * ADVANCED_CONFIG.getFishingMagicMultiplier()) {
|
|
|
|
return false;
|
|
|
|
}
|
2012-11-13 01:33:37 +01:00
|
|
|
|
2013-01-30 00:12:55 +01:00
|
|
|
List<Enchantment> possibleEnchantments = new ArrayList<Enchantment>();
|
2012-11-13 01:33:37 +01:00
|
|
|
|
2013-01-30 00:12:55 +01:00
|
|
|
for (Enchantment enchantment : Enchantment.values()) {
|
|
|
|
if (enchantment.canEnchantItem(itemStack)) {
|
|
|
|
possibleEnchantments.add(enchantment);
|
|
|
|
}
|
|
|
|
}
|
2012-11-13 01:33:37 +01:00
|
|
|
|
2013-01-30 00:12:55 +01:00
|
|
|
// 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());
|
2012-11-13 01:33:37 +01:00
|
|
|
|
2013-01-30 00:12:55 +01:00
|
|
|
boolean enchanted = false;
|
|
|
|
int specificChance = 1;
|
2012-11-13 01:33:37 +01:00
|
|
|
|
2013-01-30 00:12:55 +01:00
|
|
|
for (Enchantment possibleEnchantment : possibleEnchantments) {
|
|
|
|
boolean conflicts = false;
|
2012-11-13 01:33:37 +01:00
|
|
|
|
2013-01-30 00:12:55 +01:00
|
|
|
for (Enchantment currentEnchantment : itemStack.getEnchantments().keySet()) {
|
|
|
|
conflicts = currentEnchantment.conflictsWith(possibleEnchantment);
|
2012-11-13 01:33:37 +01:00
|
|
|
|
2013-01-30 00:12:55 +01:00
|
|
|
if (conflicts) {
|
|
|
|
break;
|
2013-01-14 02:56:05 +01:00
|
|
|
}
|
2013-01-30 00:12:55 +01:00
|
|
|
}
|
2012-11-13 01:33:37 +01:00
|
|
|
|
2013-01-30 00:12:55 +01:00
|
|
|
if (!conflicts && Misc.getRandom().nextInt(specificChance) == 0) {
|
|
|
|
itemStack.addEnchantment(possibleEnchantment, Misc.getRandom().nextInt(possibleEnchantment.getMaxLevel()) + 1);
|
2012-11-13 01:33:37 +01:00
|
|
|
|
2013-01-30 00:12:55 +01:00
|
|
|
specificChance++;
|
|
|
|
enchanted = true;
|
2012-11-13 01:33:37 +01:00
|
|
|
}
|
2012-03-13 08:00:49 +01:00
|
|
|
}
|
|
|
|
|
2013-01-30 00:12:55 +01:00
|
|
|
return enchanted;
|
2012-03-13 08:00:49 +01:00
|
|
|
}
|
2012-12-24 22:56:25 +01:00
|
|
|
|
2012-11-08 20:15:40 +01:00
|
|
|
/**
|
2013-01-30 00:12:55 +01:00
|
|
|
* Gets the loot tier for a given skill level
|
|
|
|
*
|
|
|
|
* @param skillLevel Fishing skill level
|
|
|
|
* @return Loot tier
|
2012-11-08 20:15:40 +01:00
|
|
|
*/
|
2013-01-30 00:12:55 +01:00
|
|
|
public static int getLootTier(int skillLevel) {
|
|
|
|
for (Tier tier : Tier.values()) {
|
|
|
|
if (skillLevel >= tier.getLevel()) {
|
|
|
|
return tier.toNumerical();
|
|
|
|
}
|
2012-11-08 20:15:40 +01:00
|
|
|
}
|
2013-01-30 00:12:55 +01:00
|
|
|
|
|
|
|
return 0;
|
2012-12-24 22:56:25 +01:00
|
|
|
}
|
2013-01-30 19:24:56 +01:00
|
|
|
|
|
|
|
/**
|
2013-01-30 22:51:11 +01:00
|
|
|
* Gets the vanilla xp multiplier for a given skill level
|
2013-01-30 19:24:56 +01:00
|
|
|
*
|
|
|
|
* @param skillLevel Fishing skill level
|
|
|
|
* @return Shake Mob probability
|
|
|
|
*/
|
2013-01-30 22:51:11 +01:00
|
|
|
public static int getVanillaXpMultiplier(int skillLevel) {
|
2013-01-30 19:24:56 +01:00
|
|
|
for (Tier tier : Tier.values()) {
|
|
|
|
if (skillLevel >= tier.getLevel()) {
|
|
|
|
return tier.getVanillaXPBoostModifier();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2011-11-28 14:17:01 +01:00
|
|
|
}
|