mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2025-06-25 18:24:43 +02:00
Fishing Treasure Hunter overhaul
This commit is contained in:
@ -4,7 +4,9 @@ import org.bukkit.block.Biome;
|
||||
import org.bukkit.entity.EntityType;
|
||||
|
||||
import com.gmail.nossr50.config.AdvancedConfig;
|
||||
import com.gmail.nossr50.config.treasure.TreasureConfig;
|
||||
import com.gmail.nossr50.datatypes.skills.SkillType;
|
||||
import com.gmail.nossr50.datatypes.treasure.Rarity;
|
||||
import com.gmail.nossr50.locale.LocaleLoader;
|
||||
import com.gmail.nossr50.skills.fishing.Fishing;
|
||||
import com.gmail.nossr50.skills.fishing.Fishing.Tier;
|
||||
@ -13,14 +15,21 @@ import com.gmail.nossr50.util.player.UserManager;
|
||||
|
||||
public class FishingCommand extends SkillCommand {
|
||||
private int lootTier;
|
||||
private String magicChance;
|
||||
private String magicChanceLucky;
|
||||
private String chanceRaining = "";
|
||||
private String shakeChance;
|
||||
private String shakeChanceLucky;
|
||||
private int fishermansDietRank;
|
||||
private String biteChance;
|
||||
|
||||
private String trapTreasure;
|
||||
private String commonTreasure;
|
||||
private String uncommonTreasure;
|
||||
private String rareTreasure;
|
||||
private String epicTreasure;
|
||||
private String legendaryTreasure;
|
||||
private String recordTreasure;
|
||||
|
||||
private String magicChance;
|
||||
|
||||
private boolean canTreasureHunt;
|
||||
private boolean canMagicHunt;
|
||||
private boolean canShake;
|
||||
@ -39,16 +48,24 @@ public class FishingCommand extends SkillCommand {
|
||||
// TREASURE HUNTER
|
||||
if (canTreasureHunt) {
|
||||
lootTier = mcMMOPlayer.getFishingManager().getLootTier();
|
||||
double enchantChance = lootTier * AdvancedConfig.getInstance().getFishingMagicMultiplier();
|
||||
|
||||
if (isStorming) {
|
||||
chanceRaining = LocaleLoader.getString("Fishing.Chance.Raining");
|
||||
enchantChance *= 1.1D;
|
||||
}
|
||||
// Item drop rates
|
||||
trapTreasure = calculateAbilityDisplayValues(TreasureConfig.getInstance().getItemDropRate(lootTier, Rarity.TRAP))[0];
|
||||
commonTreasure = calculateAbilityDisplayValues(TreasureConfig.getInstance().getItemDropRate(lootTier, Rarity.COMMON))[0];
|
||||
uncommonTreasure = calculateAbilityDisplayValues(TreasureConfig.getInstance().getItemDropRate(lootTier, Rarity.UNCOMMON))[0];
|
||||
rareTreasure = calculateAbilityDisplayValues(TreasureConfig.getInstance().getItemDropRate(lootTier, Rarity.RARE))[0];
|
||||
epicTreasure = calculateAbilityDisplayValues(TreasureConfig.getInstance().getItemDropRate(lootTier, Rarity.EPIC))[0];
|
||||
legendaryTreasure = calculateAbilityDisplayValues(TreasureConfig.getInstance().getItemDropRate(lootTier, Rarity.LEGENDARY))[0];
|
||||
recordTreasure = calculateAbilityDisplayValues(TreasureConfig.getInstance().getItemDropRate(lootTier, Rarity.RECORD))[0];
|
||||
|
||||
String[] treasureHunterStrings = calculateAbilityDisplayValues(enchantChance);
|
||||
magicChance = treasureHunterStrings[0];
|
||||
magicChanceLucky = treasureHunterStrings[1];
|
||||
// Magic hunter drop rates
|
||||
double commonEnchantment = TreasureConfig.getInstance().getEnchantmentDropRate(lootTier, Rarity.COMMON);
|
||||
double uncommonEnchantment = TreasureConfig.getInstance().getEnchantmentDropRate(lootTier, Rarity.UNCOMMON);
|
||||
double rareEnchantment = TreasureConfig.getInstance().getEnchantmentDropRate(lootTier, Rarity.RARE);
|
||||
double epicEnchantment = TreasureConfig.getInstance().getEnchantmentDropRate(lootTier, Rarity.EPIC);
|
||||
double legendaryEnchantment = TreasureConfig.getInstance().getEnchantmentDropRate(lootTier, Rarity.LEGENDARY);
|
||||
|
||||
magicChance = calculateAbilityDisplayValues(commonEnchantment + uncommonEnchantment + rareEnchantment + epicEnchantment + legendaryEnchantment)[0];
|
||||
}
|
||||
|
||||
// SHAKE
|
||||
@ -107,20 +124,20 @@ public class FishingCommand extends SkillCommand {
|
||||
player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Fishing.Effect.2"), LocaleLoader.getString("Fishing.Effect.3")));
|
||||
}
|
||||
|
||||
if (canShake) {
|
||||
player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Fishing.Effect.4"), LocaleLoader.getString("Fishing.Effect.5")));
|
||||
}
|
||||
|
||||
if (canFishermansDiet) {
|
||||
player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Fishing.Effect.6"), LocaleLoader.getString("Fishing.Effect.7")));
|
||||
if (canIceFish) {
|
||||
player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Fishing.Effect.10"), LocaleLoader.getString("Fishing.Effect.11")));
|
||||
}
|
||||
|
||||
if (canMasterAngler) {
|
||||
player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Fishing.Effect.8"), LocaleLoader.getString("Fishing.Effect.9")));
|
||||
}
|
||||
|
||||
if (canIceFish) {
|
||||
player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Fishing.Effect.10"), LocaleLoader.getString("Fishing.Effect.11")));
|
||||
if (canShake) {
|
||||
player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Fishing.Effect.4"), LocaleLoader.getString("Fishing.Effect.5")));
|
||||
}
|
||||
|
||||
if (canFishermansDiet) {
|
||||
player.sendMessage(LocaleLoader.getString("Effects.Template", LocaleLoader.getString("Fishing.Effect.6"), LocaleLoader.getString("Fishing.Effect.7")));
|
||||
}
|
||||
}
|
||||
|
||||
@ -131,16 +148,28 @@ public class FishingCommand extends SkillCommand {
|
||||
|
||||
@Override
|
||||
protected void statsDisplay() {
|
||||
if (canMasterAngler) {
|
||||
player.sendMessage(LocaleLoader.getString("Fishing.Ability.Chance", biteChance));
|
||||
}
|
||||
|
||||
if (canTreasureHunt) {
|
||||
player.sendMessage(LocaleLoader.getString("Fishing.Ability.Rank", lootTier, Tier.EIGHT.toNumerical()));
|
||||
player.sendMessage(LocaleLoader.getString("Fishing.Ability.TH.DropRate", trapTreasure, commonTreasure, uncommonTreasure, rareTreasure, epicTreasure, legendaryTreasure, recordTreasure));
|
||||
}
|
||||
|
||||
if (canMagicHunt) {
|
||||
player.sendMessage(LocaleLoader.getString("Fishing.Enchant.Chance", magicChance) + chanceRaining + (isLucky ? LocaleLoader.getString("Perks.Lucky.Bonus", magicChanceLucky) : ""));
|
||||
player.sendMessage(LocaleLoader.getString("Fishing.Ability.TH.MagicRate", magicChance));
|
||||
}
|
||||
|
||||
if (canIceFish) {
|
||||
int unlockLevel = AdvancedConfig.getInstance().getIceFishingUnlockLevel();
|
||||
|
||||
if (skillValue < unlockLevel) {
|
||||
player.sendMessage(LocaleLoader.getString("Ability.Generic.Template.Lock", LocaleLoader.getString("Fishing.Ability.Locked.1", unlockLevel)));
|
||||
}
|
||||
else {
|
||||
player.sendMessage(LocaleLoader.getString("Fishing.Ability.IceFishing"));
|
||||
}
|
||||
}
|
||||
|
||||
if (canMasterAngler) {
|
||||
player.sendMessage(LocaleLoader.getString("Fishing.Ability.Chance", biteChance));
|
||||
}
|
||||
|
||||
if (canShake) {
|
||||
@ -157,16 +186,5 @@ public class FishingCommand extends SkillCommand {
|
||||
if (canFishermansDiet) {
|
||||
player.sendMessage(LocaleLoader.getString("Fishing.Ability.FD", fishermansDietRank));
|
||||
}
|
||||
|
||||
if (canIceFish) {
|
||||
int unlockLevel = AdvancedConfig.getInstance().getIceFishingUnlockLevel();
|
||||
|
||||
if (skillValue < unlockLevel) {
|
||||
player.sendMessage(LocaleLoader.getString("Ability.Generic.Template.Lock", LocaleLoader.getString("Fishing.Ability.Locked.1", unlockLevel)));
|
||||
}
|
||||
else {
|
||||
player.sendMessage(LocaleLoader.getString("Fishing.Ability.IceFishing"));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -199,10 +199,6 @@ public class AdvancedConfig extends AutoUpdateConfigLoader {
|
||||
}
|
||||
}
|
||||
|
||||
if (getFishingMagicMultiplier() <= 0) {
|
||||
reason.add("Skills.Fishing.MagicHunter.Multiplier should be greater than 0!");
|
||||
}
|
||||
|
||||
if (getFishermanDietRankChange() < 1) {
|
||||
reason.add("Skills.Fishing.FishermansDiet.RankChange should be at least 1!");
|
||||
}
|
||||
@ -655,8 +651,6 @@ public class AdvancedConfig extends AutoUpdateConfigLoader {
|
||||
public double getShakeChance(Fishing.Tier tier) { return config.getDouble("Skills.Fishing.Shake_Chance.Rank_" + tier.toNumerical()); }
|
||||
public int getFishingVanillaXPModifier(Fishing.Tier tier) { return config.getInt("Skills.Fishing.VanillaXPMultiplier.Rank_" + tier.toNumerical()); }
|
||||
|
||||
public double getFishingMagicMultiplier() { return config.getDouble("Skills.Fishing.MagicHunter.Multiplier", 2.5D); }
|
||||
|
||||
public int getFishermanDietRankChange() { return config.getInt("Skills.Fishing.FishermansDiet.RankChange", 200); }
|
||||
|
||||
public int getIceFishingUnlockLevel() { return config.getInt("Skills.Fishing.IceFishing.UnlockLevel", 50); }
|
||||
|
@ -1,11 +1,13 @@
|
||||
package com.gmail.nossr50.config.treasure;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.DyeColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
@ -14,10 +16,13 @@ import org.bukkit.potion.Potion;
|
||||
import org.bukkit.potion.PotionType;
|
||||
|
||||
import com.gmail.nossr50.config.ConfigLoader;
|
||||
import com.gmail.nossr50.datatypes.treasure.EnchantmentTreasure;
|
||||
import com.gmail.nossr50.datatypes.treasure.ExcavationTreasure;
|
||||
import com.gmail.nossr50.datatypes.treasure.FishingTreasure;
|
||||
import com.gmail.nossr50.datatypes.treasure.HylianTreasure;
|
||||
import com.gmail.nossr50.datatypes.treasure.Rarity;
|
||||
import com.gmail.nossr50.datatypes.treasure.ShakeTreasure;
|
||||
import com.gmail.nossr50.util.EnchantmentUtils;
|
||||
|
||||
public class TreasureConfig extends ConfigLoader {
|
||||
private static TreasureConfig instance;
|
||||
@ -57,7 +62,8 @@ public class TreasureConfig extends ConfigLoader {
|
||||
public List<ShakeTreasure> shakeFromWitch = new ArrayList<ShakeTreasure>();
|
||||
public List<ShakeTreasure> shakeFromZombie = new ArrayList<ShakeTreasure>();
|
||||
|
||||
public List<FishingTreasure> fishingRewards = new ArrayList<FishingTreasure>();
|
||||
public HashMap<Rarity, List<FishingTreasure>> fishingRewards = new HashMap<Rarity, List<FishingTreasure>>();
|
||||
public HashMap<Rarity, List<EnchantmentTreasure>> fishingEnchantments = new HashMap<Rarity, List<EnchantmentTreasure>>();
|
||||
|
||||
private TreasureConfig() {
|
||||
super("treasures.yml");
|
||||
@ -82,6 +88,7 @@ public class TreasureConfig extends ConfigLoader {
|
||||
loadTreaures("Fishing");
|
||||
loadTreaures("Excavation");
|
||||
loadTreaures("Hylian_Luck");
|
||||
loadEnchantments();
|
||||
|
||||
for (EntityType entity : EntityType.values()) {
|
||||
if (entity.isAlive()) {
|
||||
@ -102,6 +109,13 @@ public class TreasureConfig extends ConfigLoader {
|
||||
return;
|
||||
}
|
||||
|
||||
// Initialize fishing HashMap
|
||||
for (Rarity rarity : Rarity.values()) {
|
||||
if (!fishingRewards.containsKey(rarity)) {
|
||||
fishingRewards.put(rarity, (new ArrayList<FishingTreasure>()));
|
||||
}
|
||||
}
|
||||
|
||||
for (String treasureName : treasureSection.getKeys(false)) {
|
||||
// Validate all the things!
|
||||
List<String> reason = new ArrayList<String>();
|
||||
@ -159,17 +173,13 @@ public class TreasureConfig extends ConfigLoader {
|
||||
/*
|
||||
* Specific Types
|
||||
*/
|
||||
int maxLevel = 0;
|
||||
Rarity rarity = null;
|
||||
|
||||
if (isFishing) {
|
||||
maxLevel = config.getInt(type + "." + treasureName + ".Max_Level");
|
||||
rarity = Rarity.getRarity(config.getString(type + "." + treasureName + ".Rarity"));
|
||||
|
||||
if (maxLevel < -1) {
|
||||
reason.add(treasureName + " has an invalid Max_Level: " + maxLevel);
|
||||
}
|
||||
|
||||
if (maxLevel != -1 && maxLevel < dropLevel) {
|
||||
reason.add(treasureName + " Max_Level must be -1 or greater than Drop_Level!");
|
||||
if (rarity == null) {
|
||||
reason.add("Invalid Rarity for item: " + treasureName);
|
||||
}
|
||||
}
|
||||
|
||||
@ -219,7 +229,7 @@ public class TreasureConfig extends ConfigLoader {
|
||||
|
||||
if (noErrorsInConfig(reason)) {
|
||||
if (isFishing) {
|
||||
fishingRewards.add(new FishingTreasure(item, xp, dropChance, dropLevel, maxLevel));
|
||||
fishingRewards.get(rarity).add(new FishingTreasure(item, xp));
|
||||
}
|
||||
else if (isShake) {
|
||||
ShakeTreasure shakeTreasure = new ShakeTreasure(item, xp, dropChance, dropLevel);
|
||||
@ -343,4 +353,37 @@ public class TreasureConfig extends ConfigLoader {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void loadEnchantments() {
|
||||
for (Rarity rarity : Rarity.values()) {
|
||||
if (rarity == Rarity.TRAP || rarity == Rarity.RECORD) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!fishingEnchantments.containsKey(rarity)) {
|
||||
fishingEnchantments.put(rarity, (new ArrayList<EnchantmentTreasure>()));
|
||||
}
|
||||
|
||||
ConfigurationSection enchantmentSection = config.getConfigurationSection("Enchantments_Rarity." + rarity.toString());
|
||||
|
||||
if (enchantmentSection == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (String enchantmentName : enchantmentSection.getKeys(false)) {
|
||||
int level = config.getInt("Enchantments_Rarity." + rarity.toString() + "." + enchantmentName);
|
||||
Enchantment enchantment = EnchantmentUtils.getByName(enchantmentName);
|
||||
|
||||
if (enchantment == null) {
|
||||
plugin.getLogger().warning("Skipping invalid enchantment in treasures.yml: " + enchantmentName);
|
||||
continue;
|
||||
}
|
||||
|
||||
fishingEnchantments.get(rarity).add(new EnchantmentTreasure(enchantment, level));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public double getItemDropRate(int tier, Rarity rarity) { return config.getDouble("Item_Drop_Rates.Tier_" + tier + "." + rarity.toString()); }
|
||||
public double getEnchantmentDropRate(int tier, Rarity rarity) { return config.getDouble("Enchantment_Drop_Rates.Tier_" + tier + "." + rarity.toString()); }
|
||||
}
|
||||
|
@ -0,0 +1,29 @@
|
||||
package com.gmail.nossr50.datatypes.treasure;
|
||||
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
|
||||
public class EnchantmentTreasure {
|
||||
private Enchantment enchantment;
|
||||
private int level;
|
||||
|
||||
public EnchantmentTreasure(Enchantment enchantment, int level) {
|
||||
this.setEnchantment(enchantment);
|
||||
this.setLevel(level);
|
||||
}
|
||||
|
||||
public Enchantment getEnchantment() {
|
||||
return enchantment;
|
||||
}
|
||||
|
||||
public void setEnchantment(Enchantment enchantment) {
|
||||
this.enchantment = enchantment;
|
||||
}
|
||||
|
||||
public int getLevel() {
|
||||
return level;
|
||||
}
|
||||
|
||||
public void setLevel(int level) {
|
||||
this.level = level;
|
||||
}
|
||||
}
|
@ -3,18 +3,8 @@ package com.gmail.nossr50.datatypes.treasure;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class FishingTreasure extends Treasure {
|
||||
private int maxLevel;
|
||||
|
||||
public FishingTreasure(ItemStack drop, int xp, Double dropChance, int dropLevel, int maxLevel) {
|
||||
super(drop, xp, dropChance, dropLevel);
|
||||
this.setMaxLevel(maxLevel);
|
||||
}
|
||||
|
||||
public int getMaxLevel() {
|
||||
return maxLevel;
|
||||
}
|
||||
|
||||
public void setMaxLevel(int maxLevel) {
|
||||
this.maxLevel = maxLevel;
|
||||
public FishingTreasure(ItemStack drop, int xp) {
|
||||
super(drop, xp, 0, 0);
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,20 @@
|
||||
package com.gmail.nossr50.datatypes.treasure;
|
||||
|
||||
public enum Rarity {
|
||||
RECORD,
|
||||
LEGENDARY,
|
||||
EPIC,
|
||||
RARE,
|
||||
UNCOMMON,
|
||||
COMMON,
|
||||
TRAP;
|
||||
|
||||
public static Rarity getRarity(String string) {
|
||||
try {
|
||||
return valueOf(string);
|
||||
}
|
||||
catch (IllegalArgumentException ex) {
|
||||
return COMMON;
|
||||
}
|
||||
}
|
||||
};
|
@ -26,10 +26,15 @@ import org.bukkit.entity.Player;
|
||||
import org.bukkit.entity.Sheep;
|
||||
import org.bukkit.entity.Skeleton;
|
||||
import org.bukkit.entity.Skeleton.SkeletonType;
|
||||
import org.bukkit.entity.TNTPrimed;
|
||||
import org.bukkit.entity.ThrownPotion;
|
||||
import org.bukkit.event.player.PlayerFishEvent;
|
||||
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.material.Wool;
|
||||
import org.bukkit.potion.Potion;
|
||||
import org.bukkit.potion.PotionType;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import com.gmail.nossr50.mcMMO;
|
||||
import com.gmail.nossr50.config.AdvancedConfig;
|
||||
@ -38,7 +43,9 @@ import com.gmail.nossr50.config.experience.ExperienceConfig;
|
||||
import com.gmail.nossr50.config.treasure.TreasureConfig;
|
||||
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
|
||||
import com.gmail.nossr50.datatypes.skills.SkillType;
|
||||
import com.gmail.nossr50.datatypes.treasure.EnchantmentTreasure;
|
||||
import com.gmail.nossr50.datatypes.treasure.FishingTreasure;
|
||||
import com.gmail.nossr50.datatypes.treasure.Rarity;
|
||||
import com.gmail.nossr50.datatypes.treasure.ShakeTreasure;
|
||||
import com.gmail.nossr50.events.fake.FakeBlockBreakEvent;
|
||||
import com.gmail.nossr50.events.fake.FakePlayerFishEvent;
|
||||
@ -62,6 +69,7 @@ public class FishingManager extends SkillManager {
|
||||
private int fishingTries = 0;
|
||||
private long fishingTimestamp = 0L;
|
||||
private Location fishingTarget;
|
||||
private Item fishingCatch;
|
||||
|
||||
public FishingManager(McMMOPlayer mcMMOPlayer) {
|
||||
super(mcMMOPlayer, SkillType.FISHING);
|
||||
@ -246,8 +254,9 @@ public class FishingManager extends SkillManager {
|
||||
/**
|
||||
* Handle the Fisherman's Diet ability
|
||||
*
|
||||
* @param rankChange The # of levels to change rank for the food
|
||||
* @param rankChange The # of levels to change rank for the food
|
||||
* @param eventFoodLevel The initial change in hunger from the event
|
||||
*
|
||||
* @return the modified change in hunger for the event
|
||||
*/
|
||||
public int handleFishermanDiet(int rankChange, int eventFoodLevel) {
|
||||
@ -294,16 +303,18 @@ public class FishingManager extends SkillManager {
|
||||
* @param fishingCatch The {@link Item} initially caught
|
||||
*/
|
||||
public void handleFishing(Item fishingCatch) {
|
||||
this.fishingCatch = fishingCatch;
|
||||
int treasureXp = 0;
|
||||
Player player = getPlayer();
|
||||
FishingTreasure treasure = null;
|
||||
|
||||
if (Config.getInstance().getFishingDropsEnabled() && Permissions.fishingTreasureHunter(player)) {
|
||||
treasure = getFishingTreasure();
|
||||
this.fishingCatch = null;
|
||||
}
|
||||
|
||||
if (treasure != null) {
|
||||
player.sendMessage(LocaleLoader.getString("Fishing.ItemFound"));
|
||||
player.sendMessage(LocaleLoader.getString("Fishing.Ability.TH.ItemFound"));
|
||||
|
||||
treasureXp = treasure.getXp();
|
||||
ItemStack treasureDrop = treasure.getDrop().clone(); // Not cloning is bad, m'kay?
|
||||
@ -339,10 +350,10 @@ public class FishingManager extends SkillManager {
|
||||
}
|
||||
|
||||
if (enchanted) {
|
||||
player.sendMessage(LocaleLoader.getString("Fishing.MagicFound"));
|
||||
player.sendMessage(LocaleLoader.getString("Fishing.Ability.TH.MagicFound"));
|
||||
}
|
||||
|
||||
Misc.dropItem(player.getEyeLocation(), fishingCatch.getItemStack());
|
||||
// Misc.dropItem(player.getEyeLocation(), fishingCatch.getItemStack());
|
||||
fishingCatch.setItemStack(treasureDrop);
|
||||
}
|
||||
}
|
||||
@ -354,6 +365,7 @@ public class FishingManager extends SkillManager {
|
||||
* Handle the vanilla XP boost for Fishing
|
||||
*
|
||||
* @param experience The amount of experience initially awarded by the event
|
||||
*
|
||||
* @return the modified event damage
|
||||
*/
|
||||
public int handleVanillaXpBoost(int experience) {
|
||||
@ -439,28 +451,32 @@ public class FishingManager extends SkillManager {
|
||||
* @return The {@link FishingTreasure} found, or null if no treasure was found.
|
||||
*/
|
||||
private FishingTreasure getFishingTreasure() {
|
||||
List<FishingTreasure> rewards = new ArrayList<FishingTreasure>();
|
||||
int skillLevel = getSkillLevel();
|
||||
double diceRoll = Misc.getRandom().nextDouble() * 100;
|
||||
FishingTreasure treasure = null;
|
||||
|
||||
for (FishingTreasure treasure : TreasureConfig.getInstance().fishingRewards) {
|
||||
int maxLevel = treasure.getMaxLevel();
|
||||
for (Rarity rarity : Rarity.values()) {
|
||||
double dropRate = TreasureConfig.getInstance().getItemDropRate(getLootTier(), rarity);
|
||||
|
||||
if (treasure.getDropLevel() <= skillLevel && (maxLevel >= skillLevel || maxLevel <= 0)) {
|
||||
rewards.add(treasure);
|
||||
if (diceRoll <= dropRate) {
|
||||
if (rarity == Rarity.TRAP) {
|
||||
handleTraps();
|
||||
break;
|
||||
}
|
||||
|
||||
List<FishingTreasure> fishingTreasures = TreasureConfig.getInstance().fishingRewards.get(rarity);
|
||||
treasure = fishingTreasures.get(Misc.getRandom().nextInt(fishingTreasures.size()));
|
||||
break;
|
||||
}
|
||||
|
||||
diceRoll -= dropRate;
|
||||
}
|
||||
|
||||
if (rewards.isEmpty()) {
|
||||
if (treasure == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
FishingTreasure treasure = rewards.get(Misc.getRandom().nextInt(rewards.size()));
|
||||
ItemStack treasureDrop = treasure.getDrop();
|
||||
|
||||
if (!SkillUtils.treasureDropSuccessful(treasure.getDropChance(), activationChance)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
short maxDurability = treasureDrop.getType().getMaxDurability();
|
||||
|
||||
if (maxDurability > 0) {
|
||||
@ -470,41 +486,91 @@ public class FishingManager extends SkillManager {
|
||||
return treasure;
|
||||
}
|
||||
|
||||
private void handleTraps() {
|
||||
Player player = getPlayer();
|
||||
|
||||
if (Misc.getRandom().nextBoolean()) {
|
||||
player.sendMessage(LocaleLoader.getString("Fishing.Ability.TH.Boom"));
|
||||
|
||||
TNTPrimed tnt = (TNTPrimed) player.getWorld().spawnEntity(fishingCatch.getLocation(), EntityType.PRIMED_TNT);
|
||||
fishingCatch.setPassenger(tnt);
|
||||
|
||||
Vector velocity = fishingCatch.getVelocity();
|
||||
double magnitude = velocity.length();
|
||||
fishingCatch.setVelocity(velocity.multiply((magnitude + 1) / magnitude));
|
||||
|
||||
tnt.setFuseTicks(3 * Misc.TICK_CONVERSION_FACTOR);
|
||||
}
|
||||
else {
|
||||
player.sendMessage(LocaleLoader.getString("Fishing.Ability.TH.Poison"));
|
||||
|
||||
ThrownPotion thrownPotion = player.getWorld().spawn(fishingCatch.getLocation(), ThrownPotion.class);
|
||||
thrownPotion.setItem(new Potion(PotionType.POISON).splash().toItemStack(1));
|
||||
|
||||
fishingCatch.setPassenger(thrownPotion);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Process the Magic Hunter ability
|
||||
*
|
||||
* @param treasureDrop The {@link ItemStack} to enchant
|
||||
*
|
||||
* @return true if the item has been enchanted
|
||||
*/
|
||||
private Map<Enchantment, Integer> handleMagicHunter(ItemStack treasureDrop) {
|
||||
Player player = getPlayer();
|
||||
int activationChance = this.activationChance;
|
||||
Map<Enchantment, Integer> enchants = new HashMap<Enchantment, Integer>();
|
||||
List<EnchantmentTreasure> fishingEnchantments = null;
|
||||
|
||||
if (player.getWorld().hasStorm()) {
|
||||
activationChance *= Fishing.STORM_MODIFIER;
|
||||
double diceRoll = Misc.getRandom().nextDouble() * 100;
|
||||
|
||||
for (Rarity rarity : Rarity.values()) {
|
||||
if (rarity == Rarity.TRAP || rarity == Rarity.RECORD) {
|
||||
continue;
|
||||
}
|
||||
|
||||
double dropRate = TreasureConfig.getInstance().getEnchantmentDropRate(getLootTier(), rarity);
|
||||
|
||||
if (diceRoll <= dropRate) {
|
||||
fishingEnchantments = TreasureConfig.getInstance().fishingEnchantments.get(rarity);
|
||||
break;
|
||||
}
|
||||
|
||||
diceRoll -= dropRate;
|
||||
}
|
||||
|
||||
Map<Enchantment, Integer> enchants = new HashMap<Enchantment, Integer>();
|
||||
|
||||
if (Misc.getRandom().nextInt(activationChance) > getLootTier() * AdvancedConfig.getInstance().getFishingMagicMultiplier()) {
|
||||
if (fishingEnchantments == null) {
|
||||
return enchants;
|
||||
}
|
||||
|
||||
List<Enchantment> possibleEnchantments = getPossibleEnchantments(treasureDrop);
|
||||
List<Enchantment> validEnchantments = getPossibleEnchantments(treasureDrop);
|
||||
List<EnchantmentTreasure> possibleEnchants = new ArrayList<EnchantmentTreasure>();
|
||||
|
||||
for (EnchantmentTreasure enchantmentTreasure : fishingEnchantments) {
|
||||
if (validEnchantments.contains(enchantmentTreasure.getEnchantment())) {
|
||||
possibleEnchants.add(enchantmentTreasure);
|
||||
}
|
||||
}
|
||||
|
||||
if (possibleEnchants.isEmpty()) {
|
||||
return enchants;
|
||||
}
|
||||
|
||||
// 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());
|
||||
Collections.shuffle(possibleEnchants, Misc.getRandom());
|
||||
|
||||
int specificChance = 1;
|
||||
|
||||
for (Enchantment possibleEnchantment : possibleEnchantments) {
|
||||
for (EnchantmentTreasure enchantmentTreasure : possibleEnchants) {
|
||||
Enchantment possibleEnchantment = enchantmentTreasure.getEnchantment();
|
||||
|
||||
if (treasureDrop.getItemMeta().hasConflictingEnchant(possibleEnchantment) || Misc.getRandom().nextInt(specificChance) != 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
enchants.put(possibleEnchantment, Math.max(Misc.getRandom().nextInt(possibleEnchantment.getMaxLevel()) + 1, possibleEnchantment.getStartLevel()));
|
||||
enchants.put(possibleEnchantment, enchantmentTreasure.getLevel());
|
||||
|
||||
specificChance++;
|
||||
specificChance *= 2;
|
||||
}
|
||||
|
||||
return enchants;
|
||||
|
50
src/main/java/com/gmail/nossr50/util/EnchantmentUtils.java
Normal file
50
src/main/java/com/gmail/nossr50/util/EnchantmentUtils.java
Normal file
@ -0,0 +1,50 @@
|
||||
package com.gmail.nossr50.util;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
|
||||
public class EnchantmentUtils {
|
||||
|
||||
private static final HashMap<String, Enchantment> enchants = new HashMap<String, Enchantment>();
|
||||
|
||||
static {
|
||||
enchants.put("SHARPNESS", Enchantment.DAMAGE_ALL);
|
||||
enchants.put("POWER", Enchantment.ARROW_DAMAGE);
|
||||
enchants.put("FIRE_PROTECTION", Enchantment.PROTECTION_FIRE);
|
||||
enchants.put("FEATHER_FALLING", Enchantment.PROTECTION_FALL);
|
||||
enchants.put("PROTECTION", Enchantment.PROTECTION_ENVIRONMENTAL);
|
||||
enchants.put("BLAST_PROTECTION", Enchantment.PROTECTION_EXPLOSIONS);
|
||||
enchants.put("PROJECTILE_PROTECTION", Enchantment.PROTECTION_PROJECTILE);
|
||||
enchants.put("RESPIRATION", Enchantment.OXYGEN);
|
||||
enchants.put("INFINITY", Enchantment.ARROW_INFINITE);
|
||||
enchants.put("AQUA_AFFINITY", Enchantment.WATER_WORKER);
|
||||
enchants.put("UNBREAKING", Enchantment.DURABILITY);
|
||||
enchants.put("SMITE", Enchantment.DAMAGE_UNDEAD);
|
||||
enchants.put("BANE_OF_ARTHROPODS", Enchantment.DAMAGE_ARTHROPODS);
|
||||
enchants.put("EFFICIENCY", Enchantment.DIG_SPEED);
|
||||
enchants.put("FIRE_ASPECT", Enchantment.FIRE_ASPECT);
|
||||
enchants.put("SILK_TOUCH", Enchantment.SILK_TOUCH);
|
||||
enchants.put("FORTUNE", Enchantment.LOOT_BONUS_BLOCKS);
|
||||
enchants.put("LOOTING", Enchantment.LOOT_BONUS_MOBS);
|
||||
enchants.put("PUNCH", Enchantment.ARROW_KNOCKBACK);
|
||||
enchants.put("FLAME", Enchantment.ARROW_FIRE);
|
||||
enchants.put("KNOCKBACK", Enchantment.KNOCKBACK);
|
||||
enchants.put("THORNS", Enchantment.THORNS);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to get an {@link Enchantment} using it's Vanilla Minecraft name or Bukkit enum name
|
||||
*
|
||||
* @param enchantmentName Vanilla or Bukkit name of enchantment
|
||||
*
|
||||
* @return Enchantment or null if no enchantment was found
|
||||
*/
|
||||
public static Enchantment getByName(String enchantmentName) {
|
||||
if (enchants.containsKey(enchantmentName)) {
|
||||
return enchants.get(enchantmentName);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user