package com.rs.game.player.actions;

import com.rs.cache.loaders.ItemDefinitions;
import com.rs.game.Animation;
import com.rs.game.item.Item;
import com.rs.game.player.Player;
import com.rs.game.player.Skills;

public class BoltCutting extends Action {

	/**
	 * Enum for Bolt Tips
	 * 
	 * @author Baki/OnegaiSatan
	 * 
	 */
	public enum Bolt {
		OPALBOLTTIPS(1609, 45, 15, 1, 886), 
		PEARLBOLTTIPS(411, 46, 15, 1, 886), 
		JADEBOLTS(1611, 9187, 20, 13, 886),
		RED_TOPAZBOLTS(1613, 9188, 25, 16, 892), 
		SAPPHIREBOLTS(1607, 9189, 50, 20, 888), 
		EMERALDBOLTS(1605, 9190, 67, 27, 889), 
		RUBYBOLTS(1603, 9191, 85, 34, 887), 
		DIAMONDBOLTS(1601, 9192, 107.5, 43, 891), 
		DRAGONSTONEBOLTS(1615, 9193, 137.5, 55,885), 
		ONYXBOLTS(6573, 9194, 168, 67, 2717),
		HYDRIXBOLTS(31855, 31867, 168, 67, 2717);

		private double experience;
		private int levelRequired;
		private int uncut, cut;
		private int emote;

		private Bolt(int uncut, int cut, double experience, int levelRequired, int emote) {
			this.uncut = uncut;
			this.cut = cut;
			this.experience = experience;
			this.levelRequired = levelRequired;
			this.emote = emote;
		}

		public int getLevelRequired() {
			return levelRequired;
		}

		public double getExperience() {
			return experience;
		}

		public int getUncut() {
			return uncut;
		}

		public int getCut() {
			return cut;
		}

		public int getEmote() {
			return emote;
		}

	}

	public static void cut(Player player, Bolt bolt) {
		if (player.getInventory().getItems().getNumberOf(new Item(bolt.getUncut(), 1)) <= 1) // contains just
			player.getActionManager().setAction(new BoltCutting(bolt, 1));
		else
			player.getDialogueManager().startDialogue("BoltCuttingD", bolt);
	}

	private Bolt bolt;
	private int quantity;

	public BoltCutting(Bolt bolt, int quantity) {
		this.bolt = bolt;
		this.quantity = quantity;
	}

	public boolean checkAll(Player player) {
		if (player.getSkills().getLevel(Skills.FLETCHING) < bolt.getLevelRequired()) {
			player.getDialogueManager().startDialogue("SimpleMessage", "You need a Fletching level of " + bolt.getLevelRequired() + " to cut that gem.");
			return false;
		}
		if (!player.getInventory().containsOneItem(bolt.getUncut())) {
			player.getDialogueManager().startDialogue("SimpleMessage", "You don't have any " + ItemDefinitions.getItemDefinitions(bolt.getUncut()).getName().toLowerCase() + " to cut.");
			return false;
		}
		return true;
	}

	@Override
	public boolean start(Player player) {
		if (checkAll(player)) {
			setActionDelay(player, 1);
			player.setNextAnimation(new Animation(bolt.getEmote()));
			return true;
		}
		return false;
	}

	@Override
	public boolean process(Player player) {
		return checkAll(player);
	}

	@Override
	public int processWithDelay(Player player) {
		player.getInventory().deleteItem(bolt.getUncut(), 1);
		player.getInventory().addItem(bolt.getCut(), 12);
		player.getSkills().addXp(Skills.FLETCHING, bolt.getExperience());
		player.getPackets().sendGameMessage("You cut the " + ItemDefinitions.getItemDefinitions(bolt.getUncut()).getName().toLowerCase() + ".", true);
		quantity--;
		if (quantity <= 0)
			return -1;
		player.setNextAnimation(new Animation(bolt.getEmote()));
		return 0;
	}

	@Override
	public void stop(final Player player) {
		setActionDelay(player, 3);
	}

	public static boolean cut(Player player, Item itemUsed, Item usedWith) {
	    // TODO Auto-generated method stub
	    return false;
	}
}
