2013-03-01 06:52:01 +01:00
|
|
|
package com.gmail.nossr50.skills.smelting;
|
|
|
|
|
|
|
|
import org.bukkit.Material;
|
|
|
|
import org.bukkit.block.BlockState;
|
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
import org.bukkit.event.inventory.FurnaceBurnEvent;
|
|
|
|
import org.bukkit.inventory.ItemStack;
|
|
|
|
|
|
|
|
import com.gmail.nossr50.mcMMO;
|
|
|
|
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
|
|
|
|
import com.gmail.nossr50.datatypes.skills.SkillType;
|
|
|
|
import com.gmail.nossr50.locale.LocaleLoader;
|
|
|
|
import com.gmail.nossr50.skills.SkillManager;
|
|
|
|
import com.gmail.nossr50.skills.mining.Mining;
|
|
|
|
import com.gmail.nossr50.skills.smelting.Smelting.Tier;
|
|
|
|
import com.gmail.nossr50.util.BlockUtils;
|
|
|
|
import com.gmail.nossr50.util.Misc;
|
|
|
|
import com.gmail.nossr50.util.Permissions;
|
|
|
|
import com.gmail.nossr50.util.skills.SkillUtils;
|
|
|
|
|
|
|
|
public class SmeltingManager extends SkillManager {
|
|
|
|
public SmeltingManager(McMMOPlayer mcMMOPlayer) {
|
|
|
|
super(mcMMOPlayer, SkillType.SMELTING);
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean canUseFluxMining(BlockState blockState) {
|
2013-04-25 15:16:42 +02:00
|
|
|
return getSkillLevel() >= Smelting.fluxMiningUnlockLevel && BlockUtils.affectedByFluxMining(blockState) && Permissions.fluxMining(getPlayer()) && !mcMMO.getPlaceStore().isTrue(blockState);
|
2013-03-01 06:52:01 +01:00
|
|
|
}
|
|
|
|
|
2013-10-09 17:44:45 +02:00
|
|
|
public boolean isDoubleDropSuccessful() {
|
|
|
|
return Permissions.doubleDrops(getPlayer(), skill) && SkillUtils.activationSuccessful(getSkillLevel(), getActivationChance(), Mining.doubleDropsMaxChance, Mining.doubleDropsMaxLevel);
|
|
|
|
}
|
|
|
|
|
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();
|
|
|
|
|
2013-03-05 04:45:37 +01:00
|
|
|
if (Smelting.fluxMiningChance > Misc.getRandom().nextInt(getActivationChance())) {
|
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;
|
|
|
|
}
|
|
|
|
|
2013-10-09 17:44:45 +02:00
|
|
|
Misc.dropItems(blockState.getLocation(), item, isDoubleDropSuccessful() ? 2 : 1);
|
2013-03-01 06:52:01 +01:00
|
|
|
|
|
|
|
blockState.setType(Material.AIR);
|
|
|
|
player.sendMessage(LocaleLoader.getString("Smelting.FluxMining.Success"));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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) {
|
2013-03-01 06:52:01 +01:00
|
|
|
Player player = getPlayer();
|
|
|
|
|
2013-10-31 18:25:06 +01:00
|
|
|
applyXpGain(Smelting.getResourceXp(smelting));
|
2013-03-01 06:52:01 +01:00
|
|
|
|
2013-03-04 15:40:03 +01:00
|
|
|
if (Permissions.doubleDrops(player, skill) && SkillUtils.activationSuccessful(getSkillLevel(), getActivationChance(), Smelting.secondSmeltMaxChance, Smelting.secondSmeltMaxLevel)) {
|
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() {
|
|
|
|
int skillLevel = getSkillLevel();
|
|
|
|
|
|
|
|
for (Tier tier : Tier.values()) {
|
|
|
|
if (skillLevel >= tier.getLevel()) {
|
|
|
|
return tier.getVanillaXPBoostModifier();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-12 21:56:42 +02:00
|
|
|
return 1;
|
2013-03-01 06:52:01 +01:00
|
|
|
}
|
|
|
|
}
|