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 DungeoneeringClothMaking extends Action {

	public enum SmeltingBar {
	    
	    	SALVE_GLOVES(1, 12.5, new Item[] { new Item(17468), new Item(17446), new Item(17447) }, new Item(17151), Skills.CRAFTING),

		SALVE_SHOES(2, 14.2, new Item[] { new Item(17468), new Item(17446), new Item(17447) }, new Item(16911), Skills.CRAFTING),
		
		SALVE_HOOD(3, 31.8, new Item[] { new Item(17468), new Item(17468), new Item(17446), new Item(17447) }, new Item(16735), Skills.CRAFTING),
		
		SALVE_SHIELD(6, 52.8, new Item[] { new Item(17468), new Item(17468), new Item(17468), new Item(17446), new Item(17447) }, new Item(27724), Skills.CRAFTING),
		
		SALVE_ROBE_BOTTOM(6, 52.8, new Item[] { new Item(17468), new Item(17468), new Item(17468), new Item(17446), new Item(17447) }, new Item(16845), Skills.CRAFTING),
		
		SALVE_ROBE_TOP(8, 96.5, new Item[] { new Item(17468), new Item(17468), new Item(17468), new Item(17468), new Item(17468), new Item(17446), new Item(17447) }, new Item(17217), Skills.CRAFTING),
		
		SALVE_ORB(8, 19.3, new Item[] { new Item(17468), new Item(17446), new Item(17447) }, new Item(27937), Skills.CRAFTING),
		
		WILDERCRESS_GLOVES(10, 21, new Item[] { new Item(17470), new Item(17446), new Item(17447) }, new Item(17153), Skills.CRAFTING),
		
		WILDERCRESS_SHOES(12, 22.7, new Item[] { new Item(17470), new Item(17446), new Item(17447) }, new Item(16913), Skills.CRAFTING),
		
		WILDERCRESS_HOOD(14, 48.8, new Item[] { new Item(17470), new Item(17470), new Item(17446), new Item(17447) }, new Item(16737), Skills.CRAFTING),
		
		WILDERCRESS_SHIELD(16, 78.3, new Item[] { new Item(17470), new Item(17470), new Item(17470), new Item(17446), new Item(17447) }, new Item(27726), Skills.CRAFTING),
		
		WILDERCRESS_ROBE_BOTTOM(16, 78.3, new Item[] { new Item(17470), new Item(17470), new Item(17470), new Item(17446), new Item(17447) }, new Item(16847), Skills.CRAFTING),
		
		WILDERCRESS_ROBE_TOP(18, 139, new Item[] { new Item(17470), new Item(17470), new Item(17470), new Item(17470), new Item(17470), new Item(17446), new Item(17447) }, new Item(17219), Skills.CRAFTING),
		
		WILDERCRESS_ORB(18, 27.8, new Item[] { new Item(17470), new Item(17446), new Item(17447) }, new Item(27939), Skills.CRAFTING),
		
		BLIGHTLEAF_GLOVES(20, 29.5, new Item[] { new Item(17472), new Item(17446), new Item(17447) }, new Item(17155), Skills.CRAFTING),
		
		BLIGHTLEAF_SHOES(22, 31.2, new Item[] { new Item(17472), new Item(17446), new Item(17447) }, new Item(16915), Skills.CRAFTING),
		
		BLIGHTLEAF_HOOD(24, 65.8, new Item[] { new Item(17472), new Item(17472), new Item(17446), new Item(17447) }, new Item(16739), Skills.CRAFTING),
		
		BLIGHTLEAF_SHIELD(26, 103.8, new Item[] { new Item(17472), new Item(17472), new Item(17472), new Item(17446), new Item(17447) }, new Item(27728), Skills.CRAFTING),
		
		BLIGHTLEAF_ROBE_BOTTOM(26, 103.8, new Item[] { new Item(17472), new Item(17472), new Item(17472), new Item(17446), new Item(17447) }, new Item(16849), Skills.CRAFTING),
		
		BLIGHTLEAF_ROBE_TOP(28, 181.5, new Item[] { new Item(17472), new Item(17472), new Item(17472), new Item(17472), new Item(17472), new Item(17446), new Item(17447) }, new Item(17221), Skills.CRAFTING),
		
		BLIGHTLEAF_ORB(28, 36.3, new Item[] { new Item(17472), new Item(17446), new Item(17447) }, new Item(27941), Skills.CRAFTING),
		
		ROSEBLOOD_GLOVES(30, 38, new Item[] { new Item(17474), new Item(17446), new Item(17447) }, new Item(17157), Skills.CRAFTING),
		
		ROSEBLOOD_SHOES(32, 39.7, new Item[] { new Item(17474), new Item(17446), new Item(17447) }, new Item(16917), Skills.CRAFTING),
		
		ROSEBLOOD_HOOD(34, 82.8, new Item[] { new Item(17474), new Item(17474), new Item(17446), new Item(17447) }, new Item(16741), Skills.CRAFTING),
		
		ROSEBLOOD_SHIELD(36, 129.3, new Item[] { new Item(17474), new Item(17474), new Item(17474), new Item(17446), new Item(17447) }, new Item(27730), Skills.CRAFTING),
		
		ROSEBLOOD_ROBE_BOTTOM(36, 129.3, new Item[] { new Item(17474), new Item(17474), new Item(17474), new Item(17446), new Item(17447) }, new Item(16851), Skills.CRAFTING),
		
		ROSEBLOOD_ROBE_TOP(38, 224, new Item[] { new Item(17474), new Item(17474), new Item(17474), new Item(17474), new Item(17474), new Item(17446), new Item(17447) }, new Item(17223), Skills.CRAFTING),
		
		ROSEBLOOD_ORB(38, 44.8, new Item[] { new Item(17474), new Item(17446), new Item(17447) }, new Item(27943), Skills.CRAFTING),
		
		BRYLL_GLOVES(40, 46.5, new Item[] { new Item(17476), new Item(17446), new Item(17447) }, new Item(17159), Skills.CRAFTING),
		
		BRYLL_SHOES(42, 48.2, new Item[] { new Item(17476), new Item(17446), new Item(17447) }, new Item(16919), Skills.CRAFTING),
		
		BRYLL_HOOD(44, 99.8, new Item[] { new Item(17476), new Item(17476), new Item(17446), new Item(17447) }, new Item(16743), Skills.CRAFTING),
		
		BRYLL_SHIELD(46, 154.8, new Item[] { new Item(17476), new Item(17476), new Item(17476), new Item(17446), new Item(17447) }, new Item(27732), Skills.CRAFTING),
		
		BRYLL_ROBE_BOTTOM(46, 154.8, new Item[] { new Item(17476), new Item(17476), new Item(17476), new Item(17446), new Item(17447) }, new Item(16853), Skills.CRAFTING),
		
		BRYLL_ROBE_TOP(48, 266.5, new Item[] { new Item(17476), new Item(17476), new Item(17476), new Item(17476), new Item(17476), new Item(17446), new Item(17447) }, new Item(17225), Skills.CRAFTING),
		
		BRYLL_ORB(48, 53.3, new Item[] { new Item(17476), new Item(17446), new Item(17447) }, new Item(27945), Skills.CRAFTING),
		
		DUSKWEED_GLOVES(50, 55, new Item[] { new Item(17478), new Item(17446), new Item(17447) }, new Item(17161), Skills.CRAFTING),
		
		DUSKWEED_SHOES(52, 56.7, new Item[] { new Item(17478), new Item(17446), new Item(17447) }, new Item(16921), Skills.CRAFTING),
		
		DUSKWEED_HOOD(54, 116.8, new Item[] { new Item(17478), new Item(17478), new Item(17446), new Item(17447) }, new Item(16745), Skills.CRAFTING),
		
		DUSKWEED_SHIELD(56, 180.3, new Item[] { new Item(17478), new Item(17478), new Item(17478), new Item(17446), new Item(17449) }, new Item(27732), Skills.CRAFTING),
		
		DUSKWEED_ROBE_BOTTOM(56, 180.3, new Item[] { new Item(17478), new Item(17478), new Item(17478), new Item(17446), new Item(17449) }, new Item(16853), Skills.CRAFTING),
		
		DUSKWEED_ROBE_TOP(58, 309, new Item[] { new Item(17478), new Item(17478), new Item(17478), new Item(17478), new Item(17478), new Item(17446), new Item(17447) }, new Item(17227), Skills.CRAFTING),
		
		DUSKWEED_ORB(58, 61.8, new Item[] { new Item(17478), new Item(17446), new Item(17447) }, new Item(27947), Skills.CRAFTING),
		
		SOULBELL_GLOVES(60, 63.5, new Item[] { new Item(17480), new Item(17446), new Item(17447) }, new Item(17163), Skills.CRAFTING),
		
		SOULBELL_SHOES(62, 65.2, new Item[] { new Item(17480), new Item(17446), new Item(17447) }, new Item(16923), Skills.CRAFTING),
		
		SOULBELL_HOOD(64, 133.8, new Item[] { new Item(17480), new Item(17480), new Item(17446), new Item(17447) }, new Item(16747), Skills.CRAFTING),
		
		SOULBELL_SHIELD(66, 205.8, new Item[] { new Item(17480), new Item(17480), new Item(17480), new Item(17446), new Item(17449) }, new Item(27734), Skills.CRAFTING),
		
		SOULBELL_ROBE_BOTTOM(66, 205.8, new Item[] { new Item(17480), new Item(17480), new Item(17480), new Item(17446), new Item(17449) }, new Item(16855), Skills.CRAFTING),
		
		SOULBELL_ROBE_TOP(68, 351.5, new Item[] { new Item(17480), new Item(17480), new Item(17480), new Item(17480), new Item(17480), new Item(17446), new Item(17447) }, new Item(17229), Skills.CRAFTING),
		
		SOULBELL_ORB(68, 70.3, new Item[] { new Item(17480), new Item(17446), new Item(17447) }, new Item(27949), Skills.CRAFTING),
		
		ECTOCLOTH_GLOVES(70, 72, new Item[] { new Item(17482), new Item(17446), new Item(17447) }, new Item(17165), Skills.CRAFTING),
		
		ECTOCLOTH_SHOES(72, 73.7, new Item[] { new Item(17482), new Item(17446), new Item(17447) }, new Item(16925), Skills.CRAFTING),
		
		ECTOCLOTH_HOOD(74, 150.8, new Item[] { new Item(17482), new Item(17482), new Item(17446), new Item(17447) }, new Item(16749), Skills.CRAFTING),
		
		ECTOCLOTH_SHIELD(76, 231.3, new Item[] { new Item(17482), new Item(17482), new Item(17482), new Item(17446), new Item(17449) }, new Item(27736), Skills.CRAFTING),
		
		ECTOCLOTH_ROBE_BOTTOM(76, 231.3, new Item[] { new Item(17482), new Item(17482), new Item(17482), new Item(17446), new Item(17449) }, new Item(16857), Skills.CRAFTING),
		
		ECTOCLOTH_ROBE_TOP(78, 394, new Item[] { new Item(17482), new Item(17482), new Item(17482), new Item(17482), new Item(17482), new Item(17446), new Item(17447) }, new Item(17231), Skills.CRAFTING),
		
		ECTOSPHERE(78, 78.8, new Item[] { new Item(17482), new Item(17446), new Item(17447) }, new Item(27951), Skills.CRAFTING),
		
		RUNIC_GLOVES(80, 80.5, new Item[] { new Item(17484), new Item(17446), new Item(17447) }, new Item(17167), Skills.CRAFTING),
		
		RUNIC_SHOES(82, 82.2, new Item[] { new Item(17484), new Item(17446), new Item(17447) }, new Item(16927), Skills.CRAFTING),
		
		RUNIC_HOOD(84, 167.8, new Item[] { new Item(17484), new Item(17484), new Item(17446), new Item(17447) }, new Item(16751), Skills.CRAFTING),
		
		RUNIC_SHIELD(86, 256.8, new Item[] { new Item(17484), new Item(17484), new Item(17484), new Item(17446), new Item(17449) }, new Item(27738), Skills.CRAFTING),
		
		RUNIC_ROBE_BOTTOM(86, 256.8, new Item[] { new Item(17484), new Item(17484), new Item(17484), new Item(17446), new Item(17449) }, new Item(16859), Skills.CRAFTING),
		
		RUNIC_ROBE_TOP(88, 436.5, new Item[] { new Item(17484), new Item(17484), new Item(17484), new Item(17484), new Item(17484), new Item(17446), new Item(17447) }, new Item(17233), Skills.CRAFTING),
		
		RUNIC_ORB(88, 87.3, new Item[] { new Item(17484), new Item(17446), new Item(17447) }, new Item(27953), Skills.CRAFTING),
		
		SPIRITBLOOM_GLOVES(90, 89, new Item[] { new Item(17486), new Item(17446), new Item(17447) }, new Item(17169), Skills.CRAFTING),
		
		SPIRITBLOOM_SHOES(92, 90.7, new Item[] { new Item(17486), new Item(17446), new Item(17447) }, new Item(16929), Skills.CRAFTING),
		
		SPIRITBLOOM_HOOD(94, 184.8, new Item[] { new Item(17486), new Item(17486), new Item(17446), new Item(17447) }, new Item(16753), Skills.CRAFTING),
		
		SPIRITBLOOM_SHIELD(96, 282.3, new Item[] { new Item(17486), new Item(17486), new Item(17486), new Item(17446), new Item(17449) }, new Item(27740), Skills.CRAFTING),
		
		SPIRITBLOOM_ROBE_BOTTOM(96, 282.3, new Item[] { new Item(17486), new Item(17486), new Item(17486), new Item(17446), new Item(17449) }, new Item(16861), Skills.CRAFTING),
		
		SPIRITBLOOM_ROBE_TOP(98, 479, new Item[] { new Item(17486), new Item(17486), new Item(17486), new Item(17486), new Item(17486), new Item(17446), new Item(17447) }, new Item(17235), Skills.CRAFTING),
		
		SPIRITBLOOM_ORB(98, 95.8, new Item[] { new Item(17486), new Item(17446), new Item(17447) }, new Item(27955), 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 DungeoneeringClothMaking(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);
	}
}