package com.rs.game.player.actions;

//import com.rs.Settings;
import com.rs.game.item.Item;
//import com.rs.game.player.Equipment;
import com.rs.game.player.Player;
import com.rs.game.player.Skills;
//import com.rs.utils.Utils;

public class DungeoneeringLeatherMaking extends Action {

	public enum SmeltingBar {
	    
	    	PROTOLEATHER_VAMBRACES(1, 13.1, new Item[] { new Item(17424), new Item(17446), new Item(17447) }, new Item(17195), Skills.CRAFTING),

	    	PROTOLEATHER_BOOTS(3, 14.8, new Item[] { new Item(17424), new Item(17446), new Item(17447) }, new Item(17297), Skills.CRAFTING),
	    	
	    	PROTOLEATHER_COIF(5, 33, new Item[] { new Item(17424), new Item(17424), new Item(17446), new Item(17447) }, new Item(17041), Skills.CRAFTING),
	    	
	    	PROTOLEATHER_SHIELD(6, 52.8, new Item[] { new Item(17424), new Item(17424), new Item(17424), new Item(17446), new Item(17447) }, new Item(27871), Skills.CRAFTING),
	    	
	    	PROTOLEATHER_CHAPS(7, 54.6, new Item[] { new Item(17424), new Item(17424), new Item(17424), new Item(17446), new Item(17447) }, new Item(17319), Skills.CRAFTING),
	    	
	    	PROTOLEATHER_BODY(9, 99.5, new Item[] { new Item(17424), new Item(17424), new Item(17424), new Item(17424), new Item(17424), new Item(17446), new Item(17447) }, new Item(17173), Skills.CRAFTING),
	    	
	    	SUBLEATHER_VAMBRACES(11, 21.6, new Item[] { new Item(17426), new Item(17446), new Item(17447) }, new Item(17197), Skills.CRAFTING),

	    	SUBLEATHER_BOOTS(13, 23.3, new Item[] { new Item(17426), new Item(17446), new Item(17447) }, new Item(17299), Skills.CRAFTING),
	    	
	    	SUBLEATHER_COIF(15, 50, new Item[] { new Item(17426), new Item(17426), new Item(17446), new Item(17447) }, new Item(17043), Skills.CRAFTING),
	    	
	    	SUBLEATHER_SHIELD(16, 78.3, new Item[] { new Item(17426), new Item(17426), new Item(17426), new Item(17446), new Item(17447) }, new Item(27873), Skills.CRAFTING),
	    	
	    	SUBLEATHER_CHAPS(17, 80.1, new Item[] { new Item(17426), new Item(17426), new Item(17426), new Item(17446), new Item(17447) }, new Item(17321), Skills.CRAFTING),
	    	
	    	SUBLEATHER_BODY(19, 142, new Item[] { new Item(17426), new Item(17426), new Item(17426), new Item(17426), new Item(17426), new Item(17446), new Item(17447) }, new Item(17175), Skills.CRAFTING),
	    	
	    	PARALEATHER_VAMBRACES(21, 30.1, new Item[] { new Item(17428), new Item(17446), new Item(17447) }, new Item(17199), Skills.CRAFTING),

	    	PARALEATHER_BOOTS(23, 31.8, new Item[] { new Item(17428), new Item(17446), new Item(17447) }, new Item(17301), Skills.CRAFTING),
	    	
	    	PARALEATHER_COIF(25, 67, new Item[] { new Item(17428), new Item(17428), new Item(17446), new Item(17447) }, new Item(17045), Skills.CRAFTING),
	    	
	    	PARALEATHER_SHIELD(26, 103.8, new Item[] { new Item(17428), new Item(17428), new Item(17428), new Item(17446), new Item(17447) }, new Item(27875), Skills.CRAFTING),
	    	
	    	PARALEATHER_CHAPS(27, 105.6, new Item[] { new Item(17428), new Item(17428), new Item(17428), new Item(17446), new Item(17447) }, new Item(17323), Skills.CRAFTING),
	    	
	    	PARALEATHER_BODY(29, 184.5, new Item[] { new Item(17428), new Item(17428), new Item(17428), new Item(17428), new Item(17428), new Item(17446), new Item(17447) }, new Item(17177), Skills.CRAFTING),
	    	
	    	ARCHLEATHER_VAMBRACES(31, 38.6, new Item[] { new Item(17430), new Item(17446), new Item(17447) }, new Item(17201), Skills.CRAFTING),

	    	ARCHLEATHER_BOOTS(33, 40.3, new Item[] { new Item(17430), new Item(17446), new Item(17447) }, new Item(17303), Skills.CRAFTING),
	    	
	    	ARCHLEATHER_COIF(35, 84, new Item[] { new Item(17430), new Item(17430), new Item(17446), new Item(17447) }, new Item(17047), Skills.CRAFTING),
	    	
	    	ARCHLEATHER_SHIELD(36, 129.3, new Item[] { new Item(17430), new Item(17430), new Item(17430), new Item(17446), new Item(17447) }, new Item(27877), Skills.CRAFTING),
	    	
	    	ARCHLEATHER_CHAPS(37, 131.1, new Item[] { new Item(17430), new Item(17430), new Item(17430), new Item(17446), new Item(17447) }, new Item(17325), Skills.CRAFTING),
	    	
	    	ARCHLEATHER_BODY(39, 269.5, new Item[] { new Item(17430), new Item(17430), new Item(17430), new Item(17430), new Item(17430), new Item(17446), new Item(17447) }, new Item(17179), Skills.CRAFTING),
	    	
	    	DROMOLEATHER_VAMBRACES(41, 47.1, new Item[] { new Item(17432), new Item(17446), new Item(17447) }, new Item(17203), Skills.CRAFTING),

	    	DROMOLEATHER_BOOTS(43, 48.8, new Item[] { new Item(17432), new Item(17446), new Item(17447) }, new Item(17305), Skills.CRAFTING),
	    	
	    	DROMOLEATHER_COIF(45, 101, new Item[] { new Item(17432), new Item(17432), new Item(17446), new Item(17447) }, new Item(17049), Skills.CRAFTING),
	    	
	    	DROMOLEATHER_SHIELD(46, 154.8, new Item[] { new Item(17432), new Item(17432), new Item(17432), new Item(17446), new Item(17447) }, new Item(27879), Skills.CRAFTING),
	    	
	    	DROMOLEATHER_CHAPS(47, 156.6, new Item[] { new Item(17432), new Item(17432), new Item(17432), new Item(17446), new Item(17447) }, new Item(17327), Skills.CRAFTING),
	    	
	    	DROMOLEATHER_BODY(49, 269.5, new Item[] { new Item(17432), new Item(17432), new Item(17432), new Item(17432), new Item(17432), new Item(17446), new Item(17447) }, new Item(17181), Skills.CRAFTING),
	    	
	    	SPINOLEATHER_VAMBRACES(51, 55.6, new Item[] { new Item(17434), new Item(17446), new Item(17447) }, new Item(17205), Skills.CRAFTING),

	    	SPINOLEATHER_BOOTS(53, 57.3, new Item[] { new Item(17434), new Item(17446), new Item(17447) }, new Item(17307), Skills.CRAFTING),
	    	
	    	SPINOLEATHER_COIF(55, 118, new Item[] { new Item(17434), new Item(17434), new Item(17446), new Item(17447) }, new Item(17051), Skills.CRAFTING),
	    	
	    	SPINOLEATHER_SHIELD(56, 180.3, new Item[] { new Item(17434), new Item(17434), new Item(17434), new Item(17446), new Item(17447) }, new Item(27881), Skills.CRAFTING),
	    	
	    	SPINOLEATHER_CHAPS(57, 182.1, new Item[] { new Item(17434), new Item(17434), new Item(17434), new Item(17446), new Item(17447) }, new Item(17329), Skills.CRAFTING),
	    	
	    	SPINOLEATHER_BODY(59, 312, new Item[] { new Item(17434), new Item(17434), new Item(17434), new Item(17434), new Item(17434), new Item(17446), new Item(17447) }, new Item(17183), Skills.CRAFTING),
	    	
	    	GALLILEATHER_VAMBRACES(61, 64.1, new Item[] { new Item(17436), new Item(17446), new Item(17447) }, new Item(17207), Skills.CRAFTING),

	    	GALLILEATHER_BOOTS(63, 65.8, new Item[] { new Item(17436), new Item(17446), new Item(17447) }, new Item(17309), Skills.CRAFTING),
	    	
	    	GALLILEATHER_COIF(65, 135, new Item[] { new Item(17436), new Item(17436), new Item(17446), new Item(17447) }, new Item(17053), Skills.CRAFTING),
	    	
	    	GALLILEATHER_SHIELD(66, 205.8, new Item[] { new Item(17436), new Item(17436), new Item(17436), new Item(17446), new Item(17447) }, new Item(27883), Skills.CRAFTING),
	    	
	    	GALLILEATHER_CHAPS(67, 207.6, new Item[] { new Item(17436), new Item(17436), new Item(17436), new Item(17446), new Item(17447) }, new Item(17331), Skills.CRAFTING),
	    	
	    	GALLILEATHER_BODY(69, 354.5, new Item[] { new Item(17436), new Item(17436), new Item(17436), new Item(17436), new Item(17436), new Item(17446), new Item(17447) }, new Item(17185), Skills.CRAFTING),
	    	
	    	STEGOLEATHER_VAMBRACES(71, 72.6, new Item[] { new Item(17438), new Item(17446), new Item(17447) }, new Item(17209), Skills.CRAFTING),

	    	STEGOLEATHER_BOOTS(73, 74.3, new Item[] { new Item(17438), new Item(17446), new Item(17447) }, new Item(17311), Skills.CRAFTING),
	    	
	    	STEGOLEATHER_COIF(75, 152, new Item[] { new Item(17438), new Item(17438), new Item(17446), new Item(17447) }, new Item(17055), Skills.CRAFTING),
	    	
	    	STEGOLEATHER_SHIELD(76, 231.3, new Item[] { new Item(17438), new Item(17438), new Item(17438), new Item(17446), new Item(17447) }, new Item(27885), Skills.CRAFTING),
	    	
	    	STEGOLEATHER_CHAPS(77, 233.1, new Item[] { new Item(17438), new Item(17438), new Item(17438), new Item(17446), new Item(17447) }, new Item(17333), Skills.CRAFTING),
	    	
	    	STEGOLEATHER_BODY(79, 397, new Item[] { new Item(17438), new Item(17438), new Item(17438), new Item(17438), new Item(17438), new Item(17446), new Item(17447) }, new Item(17187), Skills.CRAFTING),
	    	
	    	MEGALEATHER_VAMBRACES(81, 81.1, new Item[] { new Item(17440), new Item(17446), new Item(17447) }, new Item(17211), Skills.CRAFTING),

	    	MEGALEATHER_BOOTS(83, 82.8, new Item[] { new Item(17440), new Item(17446), new Item(17447) }, new Item(17313), Skills.CRAFTING),
	    	
	    	MEGALEATHER_COIF(85, 169, new Item[] { new Item(17440), new Item(17440), new Item(17446), new Item(17447) }, new Item(17057), Skills.CRAFTING),
	    	
	    	MEGALEATHER_SHIELD(86, 256.8, new Item[] { new Item(17440), new Item(17440), new Item(17440), new Item(17446), new Item(17447) }, new Item(27887), Skills.CRAFTING),
	    	
	    	MEGALEATHER_CHAPS(87, 258.6, new Item[] { new Item(17440), new Item(17440), new Item(17440), new Item(17446), new Item(17447) }, new Item(17335), Skills.CRAFTING),
	    	
	    	MEGALEATHER_BODY(89, 439.5, new Item[] { new Item(17440), new Item(17440), new Item(17440), new Item(17440), new Item(17440), new Item(17446), new Item(17447) }, new Item(17189), Skills.CRAFTING),
	    	
	    	TYRANNOLEATHER_VAMBRACES(91, 89.6, new Item[] { new Item(17442), new Item(17446), new Item(17447) }, new Item(17213), Skills.CRAFTING),

	    	TYRANNOLEATHER_BOOTS(93, 91.3, new Item[] { new Item(17442), new Item(17446), new Item(17447) }, new Item(17315), Skills.CRAFTING),
	    	
	    	TYRANNOLEATHER_COIF(95, 186, new Item[] { new Item(17442), new Item(17442), new Item(17446), new Item(17447) }, new Item(17059), Skills.CRAFTING),
	    	
	    	TYRANNOLEATHER_SHIELD(96, 282.3, new Item[] { new Item(17442), new Item(17442), new Item(17442), new Item(17446), new Item(17447) }, new Item(27889), Skills.CRAFTING),
	    	
	    	TYRANNOLEATHER_CHAPS(97, 284.1, new Item[] { new Item(17442), new Item(17442), new Item(17442), new Item(17446), new Item(17447) }, new Item(17337), Skills.CRAFTING),
	    	
	    	TYRANNOLEATHER_BODY(99, 482, new Item[] { new Item(17442), new Item(17442), new Item(17442), new Item(17442), new Item(17442), new Item(17446), new Item(17447) }, new Item(17191), Skills.CRAFTING),

		;  

		public static SmeltingBar getBarByProduce(int id) {
			for(SmeltingBar bar : SmeltingBar.values()) {
				if(bar.getProducedBar().getId() == id)
					return bar;
			}
			return null;
		}
		
		public static SmeltingBar getBar(int id) {
			for(SmeltingBar bar : SmeltingBar.values()) {
				for(Item item : bar.getItemsRequired())
				if(item.getId() == id)
					return bar;
			}
			return null;
		}

		private int levelRequired;
		private double experience;
		private Item[] itemsRequired;
		private Item producedBar;
		private int skillType;

		private SmeltingBar(int levelRequired, double experience, Item[] itemsRequired, Item producedBar, int skillType) {
			this.levelRequired = levelRequired;
			this.experience = experience;
			this.itemsRequired = itemsRequired;
			this.producedBar = producedBar;
			this.skillType = skillType;
		}

		public Item[] getItemsRequired() {
			return itemsRequired;
		}

		public int getLevelRequired() {
			return levelRequired;
		}

		public Item getProducedBar() {
			return producedBar;
		}

		public double getExperience() {
			return experience;
		}

		public int getSkillType() {
			return skillType;
		}
	}

	public SmeltingBar bar;
	public Player player;
	public int ticks;

	public DungeoneeringLeatherMaking(SmeltingBar bar, Player player, int ticks) {
		this.player = player;
		this.bar = bar;
		this.ticks = ticks;
	}

	@Override
	public boolean start(Player player) {
		if (bar == null || player == null) {
			return false;
		}
		if (!player.getInventory().containsItemToolBelt(bar.getItemsRequired()[0].getId(), bar.getItemsRequired()[0].getAmount())) {
			player.getPackets().sendGameMessage("You need " + bar.getItemsRequired()[0].getDefinitions().getName() + " to sow some " + bar.getProducedBar().getDefinitions().getName() + ".");
			return false;
		}
		if (bar.getItemsRequired().length > 1) {
			if (!player.getInventory().containsItemToolBelt(bar.getItemsRequired()[1].getId(), bar.getItemsRequired()[1].getAmount())) {
				player.getPackets().sendGameMessage("You need " + bar.getItemsRequired()[1].getDefinitions().getName() + " to sow some " + bar.getProducedBar().getDefinitions().getName() + ".");
				return false;
			}
		}
		if (player.getSkills().getLevel(bar.getSkillType()) < bar.getLevelRequired()) {
			player.getPackets().sendGameMessage("You need a Crafting level of at least " + bar.getLevelRequired() + " to sow some " + bar.getProducedBar().getDefinitions().getName());
			return false;
		}
		player.getPackets().sendGameMessage("You give the tanner some hides " + bar.getProducedBar().getDefinitions().getName().toLowerCase().replace("", "") + ".", true);
		return true;
	}

	@Override
	public boolean process(Player player) {
		if (bar == null || player == null) {
			return false;
		}
		if (!player.getInventory().containsItemToolBelt(bar.getItemsRequired()[0].getId(), bar.getItemsRequired()[0].getAmount())) {
			player.getPackets().sendGameMessage("You need " + bar.getItemsRequired()[0].getDefinitions().getName() + " to sow some " + bar.getProducedBar().getDefinitions().getName() + ".");
			return false;
		}
		if (bar.getItemsRequired().length > 1) {
			if (!player.getInventory().containsItemToolBelt(bar.getItemsRequired()[1].getId(), bar.getItemsRequired()[1].getAmount())) {
				player.getPackets().sendGameMessage("You need " + bar.getItemsRequired()[1].getDefinitions().getName() + " to sow some " + bar.getProducedBar().getDefinitions().getName() + ".");
				return false;
			}
		}
		if (player.getSkills().getLevel(bar.getSkillType()) < bar.getLevelRequired()) {
			player.getPackets().sendGameMessage("You need a Crafting level of at least " + bar.getLevelRequired() + " to sow some " + bar.getProducedBar().getDefinitions().getName());
			return false;
		}
		return true;
	}

	@Override
	public int processWithDelay(Player player) {
		ticks--;
		double xp = bar.getExperience();
		player.getSkills().addXp(bar.getSkillType(), xp);
		for (Item required : bar.getItemsRequired()) {
			player.getInventory().deleteItem(required.getId(), required.getAmount());
			player.getPackets().sendGameMessage("You retrieve some tanned " + bar.getProducedBar().getDefinitions().getName());
		}
			int amount = bar.getProducedBar().getAmount();
			player.getInventory().addItem(bar.getProducedBar().getId(), amount);
			player.getPackets().sendGameMessage("You retrieve some tanned " + bar.getProducedBar().getDefinitions().getName());
			player.getPackets().sendGameMessage("The leather is too impure and you fail to refine it.", true);
		if (ticks > 0) {
			return 1;
		}
		return -1;
	}

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