2013-03-01 06:52:01 +01:00
|
|
|
package com.gmail.nossr50.skills.smelting;
|
|
|
|
|
2014-12-22 16:58:22 +01:00
|
|
|
import com.gmail.nossr50.config.Config;
|
2013-03-01 06:52:01 +01:00
|
|
|
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
|
2019-01-13 08:54:53 +01:00
|
|
|
import com.gmail.nossr50.datatypes.skills.PrimarySkillType;
|
2019-01-15 07:11:58 +01:00
|
|
|
import com.gmail.nossr50.datatypes.skills.SubSkillType;
|
2014-05-11 15:14:46 +02:00
|
|
|
import com.gmail.nossr50.datatypes.skills.XPGainReason;
|
2019-01-25 05:45:26 +01:00
|
|
|
import com.gmail.nossr50.events.skills.secondaryabilities.SubSkillRandomCheckEvent;
|
2013-03-01 06:52:01 +01:00
|
|
|
import com.gmail.nossr50.locale.LocaleLoader;
|
2018-07-26 02:29:40 +02:00
|
|
|
import com.gmail.nossr50.mcMMO;
|
2013-03-01 06:52:01 +01:00
|
|
|
import com.gmail.nossr50.skills.SkillManager;
|
2014-12-22 17:25:55 +01:00
|
|
|
import com.gmail.nossr50.skills.mining.Mining;
|
2013-03-01 06:52:01 +01:00
|
|
|
import com.gmail.nossr50.util.BlockUtils;
|
2015-11-04 21:27:03 +01:00
|
|
|
import com.gmail.nossr50.util.EventUtils;
|
2013-03-01 06:52:01 +01:00
|
|
|
import com.gmail.nossr50.util.Misc;
|
|
|
|
import com.gmail.nossr50.util.Permissions;
|
2019-01-25 05:45:26 +01:00
|
|
|
import com.gmail.nossr50.util.random.RandomChanceUtil;
|
2014-12-22 16:58:22 +01:00
|
|
|
import com.gmail.nossr50.util.skills.ParticleEffectUtils;
|
2019-01-17 17:46:10 +01:00
|
|
|
import com.gmail.nossr50.util.skills.RankUtils;
|
2019-01-09 04:52:52 +01:00
|
|
|
import com.gmail.nossr50.util.skills.SkillActivationType;
|
2013-03-01 06:52:01 +01:00
|
|
|
import com.gmail.nossr50.util.skills.SkillUtils;
|
2019-01-13 04:08:54 +01:00
|
|
|
import com.gmail.nossr50.util.sounds.SoundManager;
|
|
|
|
import com.gmail.nossr50.util.sounds.SoundType;
|
2018-07-26 02:29:40 +02:00
|
|
|
import org.bukkit.ChatColor;
|
|
|
|
import org.bukkit.Material;
|
|
|
|
import org.bukkit.block.BlockState;
|
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
import org.bukkit.event.inventory.FurnaceBurnEvent;
|
|
|
|
import org.bukkit.inventory.FurnaceRecipe;
|
|
|
|
import org.bukkit.inventory.ItemStack;
|
|
|
|
import org.bukkit.inventory.meta.ItemMeta;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
2013-03-01 06:52:01 +01:00
|
|
|
|
|
|
|
public class SmeltingManager extends SkillManager {
|
|
|
|
public SmeltingManager(McMMOPlayer mcMMOPlayer) {
|
2019-01-13 08:54:53 +01:00
|
|
|
super(mcMMOPlayer, PrimarySkillType.SMELTING);
|
2013-03-01 06:52:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public boolean canUseFluxMining(BlockState blockState) {
|
2019-01-09 04:52:52 +01:00
|
|
|
return getSkillLevel() >= Smelting.fluxMiningUnlockLevel && BlockUtils.affectedByFluxMining(blockState) && Permissions.isSubSkillEnabled(getPlayer(), SubSkillType.SMELTING_FLUX_MINING) && !mcMMO.getPlaceStore().isTrue(blockState);
|
2013-03-01 06:52:01 +01:00
|
|
|
}
|
|
|
|
|
2013-11-22 18:32:23 +01:00
|
|
|
public boolean isSecondSmeltSuccessful() {
|
2019-01-25 05:45:26 +01:00
|
|
|
return Permissions.isSubSkillEnabled(getPlayer(), SubSkillType.SMELTING_SECOND_SMELT) && RandomChanceUtil.isActivationSuccessful(SkillActivationType.RANDOM_LINEAR_100_SCALE_WITH_CAP, SubSkillType.SMELTING_SECOND_SMELT, getPlayer());
|
2013-10-09 17:44:45 +02:00
|
|
|
}
|
|
|
|
|
2013-03-01 06:52:01 +01:00
|
|
|
/**
|
|
|
|
* Process the Flux Mining ability.
|
|
|
|
*
|
|
|
|
* @param blockState The {@link BlockState} to check ability activation for
|
|
|
|
* @return true if the ability was successful, false otherwise
|
|
|
|
*/
|
|
|
|
public boolean processFluxMining(BlockState blockState) {
|
|
|
|
Player player = getPlayer();
|
|
|
|
|
2019-01-25 05:45:26 +01:00
|
|
|
SubSkillRandomCheckEvent event = new SubSkillRandomCheckEvent(getPlayer(), SubSkillType.SMELTING_FLUX_MINING, Smelting.fluxMiningChance / activationChance);
|
2013-11-22 18:32:23 +01:00
|
|
|
mcMMO.p.getServer().getPluginManager().callEvent(event);
|
|
|
|
if ((event.getChance() * activationChance) > Misc.getRandom().nextInt(activationChance)) {
|
2013-03-01 06:52:01 +01:00
|
|
|
ItemStack item = null;
|
|
|
|
|
|
|
|
switch (blockState.getType()) {
|
|
|
|
case IRON_ORE:
|
|
|
|
item = new ItemStack(Material.IRON_INGOT);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GOLD_ORE:
|
|
|
|
item = new ItemStack(Material.GOLD_INGOT);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (item == null) {
|
|
|
|
return false;
|
|
|
|
}
|
2019-01-17 17:46:10 +01:00
|
|
|
|
2015-11-04 21:27:03 +01:00
|
|
|
if (!EventUtils.simulateBlockBreak(blockState.getBlock(), player, true)) {
|
|
|
|
return false;
|
|
|
|
}
|
2013-03-01 06:52:01 +01:00
|
|
|
|
2014-12-22 17:25:55 +01:00
|
|
|
// We need to distribute Mining XP here, because the block break event gets cancelled
|
|
|
|
applyXpGain(Mining.getBlockXp(blockState), XPGainReason.PVE);
|
|
|
|
|
2016-03-11 15:20:23 +01:00
|
|
|
SkillUtils.handleDurabilityChange(getPlayer().getInventory().getItemInMainHand(), Config.getInstance().getAbilityToolDamage());
|
2014-12-22 16:58:22 +01:00
|
|
|
|
2016-03-16 17:47:40 +01:00
|
|
|
Misc.dropItems(Misc.getBlockCenter(blockState), item, isSecondSmeltSuccessful() ? 2 : 1);
|
2013-03-01 06:52:01 +01:00
|
|
|
|
|
|
|
blockState.setType(Material.AIR);
|
2014-12-22 16:58:22 +01:00
|
|
|
|
|
|
|
if (Config.getInstance().getFluxPickaxeSoundEnabled()) {
|
2019-01-13 04:08:54 +01:00
|
|
|
SoundManager.sendSound(player, blockState.getLocation(), SoundType.FIZZ);
|
2014-12-22 16:58:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
ParticleEffectUtils.playFluxEffect(blockState.getLocation());
|
2013-03-01 06:52:01 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-12-22 16:58:22 +01:00
|
|
|
public static ItemStack getFluxPickaxe(Material material, int amount) {
|
|
|
|
ItemStack itemStack = new ItemStack(material, amount);
|
|
|
|
|
|
|
|
ItemMeta itemMeta = itemStack.getItemMeta();
|
|
|
|
itemMeta.setDisplayName(ChatColor.GOLD + LocaleLoader.getString("Item.FluxPickaxe.Name"));
|
|
|
|
|
2015-11-13 01:13:27 +01:00
|
|
|
List<String> itemLore = itemMeta.hasLore() ? itemMeta.getLore() : new ArrayList<String>();
|
2014-12-22 16:58:22 +01:00
|
|
|
itemLore.add("mcMMO Item");
|
|
|
|
itemLore.add(LocaleLoader.getString("Item.FluxPickaxe.Lore.1"));
|
|
|
|
itemLore.add(LocaleLoader.getString("Item.FluxPickaxe.Lore.2", Smelting.fluxMiningUnlockLevel));
|
|
|
|
itemMeta.setLore(itemLore);
|
|
|
|
|
|
|
|
itemStack.setItemMeta(itemMeta);
|
|
|
|
return itemStack;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static FurnaceRecipe getFluxPickaxeRecipe(Material material) {
|
|
|
|
return new FurnaceRecipe(getFluxPickaxe(material, 1), material);
|
|
|
|
}
|
|
|
|
|
2013-03-01 06:52:01 +01:00
|
|
|
/**
|
|
|
|
* Increases burn time for furnace fuel.
|
|
|
|
*
|
|
|
|
* @param burnTime The initial burn time from the {@link FurnaceBurnEvent}
|
|
|
|
*/
|
|
|
|
public int fuelEfficiency(int burnTime) {
|
|
|
|
double burnModifier = 1 + (((double) getSkillLevel() / Smelting.burnModifierMaxLevel) * Smelting.burnTimeMultiplier);
|
|
|
|
|
|
|
|
return (int) (burnTime * burnModifier);
|
|
|
|
}
|
|
|
|
|
2013-10-31 18:25:06 +01:00
|
|
|
public ItemStack smeltProcessing(ItemStack smelting, ItemStack result) {
|
2014-04-18 21:56:03 +02:00
|
|
|
applyXpGain(Smelting.getResourceXp(smelting), XPGainReason.PVE);
|
2013-03-01 06:52:01 +01:00
|
|
|
|
2013-11-22 18:32:23 +01:00
|
|
|
if (isSecondSmeltSuccessful()) {
|
2013-04-24 13:08:24 +02:00
|
|
|
ItemStack newResult = result.clone();
|
|
|
|
|
|
|
|
newResult.setAmount(result.getAmount() + 1);
|
2013-03-01 06:52:01 +01:00
|
|
|
return newResult;
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
public int vanillaXPBoost(int experience) {
|
|
|
|
return experience * getVanillaXpMultiplier();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the vanilla XP multiplier
|
|
|
|
*
|
|
|
|
* @return the vanilla XP multiplier
|
|
|
|
*/
|
|
|
|
public int getVanillaXpMultiplier() {
|
2019-01-17 17:46:10 +01:00
|
|
|
return RankUtils.getRank(getPlayer(), SubSkillType.SMELTING_UNDERSTANDING_THE_ART);
|
2013-03-01 06:52:01 +01:00
|
|
|
}
|
2019-01-17 17:46:10 +01:00
|
|
|
}
|