package com.rs.game.player.actions;

import com.rs.game.item.Item;
import com.rs.game.player.Player;
import com.rs.game.player.Skills;

public class PotionMaking extends Action {

	public enum SmeltingBar {//SewingLeather
	    
	    	COCONUT_MILK(1, 13.8, new Item[] { new Item(5976), new Item(229) }, new Item(5935), Skills.HERBLORE),

	    	//Unfinished Potions
	    	GUAM_POTION_UNF(1, 1, new Item[] { new Item(249), new Item(227) }, new Item(91), Skills.HERBLORE),
	    	
	    	SNAKEWEED_MIXTURE(3, 1, new Item[] { new Item(1526), new Item(227) }, new Item(737), Skills.HERBLORE),
	    	
	    	ARDRIGAL_MIXTURE(3, 1, new Item[] { new Item(1528), new Item(227) }, new Item(738), Skills.HERBLORE),
	    	
	    	ROGUES_PURSE_POTION_UNF(5, 1, new Item[] { new Item(1534), new Item(227) }, new Item(4840), Skills.HERBLORE),
	    	
	    	TARROMIN_POTION_UNF(5, 1, new Item[] { new Item(253), new Item(227) }, new Item(95), Skills.HERBLORE),
	    	
	    	MARRENTIL_POTION_UNF(9, 1, new Item[] { new Item(251), new Item(227) }, new Item(93), Skills.HERBLORE),
	    	
	    	HARRALANDER_POTION_UNF(18, 1, new Item[] { new Item(255), new Item(227) }, new Item(97), Skills.HERBLORE),
	    	
	    	RANARR_POTION_UNF(25, 1, new Item[] { new Item(257), new Item(227) }, new Item(99), Skills.HERBLORE),
	    	
	    	TOADFLAX_POTION_UNF(30, 1, new Item[] { new Item(2998), new Item(227) }, new Item(3002), Skills.HERBLORE),
	    	
	    	SPIRITWEED_POTION_UNF(35, 1, new Item[] { new Item(12172), new Item(227) }, new Item(12181), Skills.HERBLORE),
	    	
	    	IRIT_POTION_UNF(40, 1, new Item[] { new Item(259), new Item(227) }, new Item(101), Skills.HERBLORE),
	    	
	    	WERGALI_POTION_UNF(41, 1, new Item[] { new Item(14854), new Item(227) }, new Item(14856), Skills.HERBLORE),
	    	
	    	AVANTOE_POTION_UNF(48, 1, new Item[] { new Item(261), new Item(227) }, new Item(103), Skills.HERBLORE),
	    	
	    	KWUARM_POTION_UNF(54, 1, new Item[] { new Item(263), new Item(227) }, new Item(105), Skills.HERBLORE),
	    	
	    	MAGIC_ESSENCE_UNF(57, 1, new Item[] { new Item(9017), new Item(227) }, new Item(9019), Skills.HERBLORE),
	    	
	    	SNAPDRAGON_POTION_UNF(59, 1, new Item[] { new Item(3000), new Item(227) }, new Item(3004), Skills.HERBLORE),
	    	
	    	CADANTINE_POTION_UNF(65, 1, new Item[] { new Item(265), new Item(227) }, new Item(107), Skills.HERBLORE),
	    	
	    	LANTADYME_POTION_UNF(67, 1, new Item[] { new Item(2481), new Item(227) }, new Item(2483), Skills.HERBLORE),
	    	
	    	ANTIPOISON1(68, 1, new Item[] { new Item(2998), new Item(5935) }, new Item(5942), Skills.HERBLORE),
	    	
	    	DWARF_WEED_POTION_UNF(70, 1, new Item[] { new Item(267), new Item(227) }, new Item(109), Skills.HERBLORE),
	    	
	    	WEAPON_POISON1(73, 1, new Item[] { new Item(6016), new Item(5935) }, new Item(5936), Skills.HERBLORE),
	    	
	    	TORSTOL_POTION_UNF(75, 1, new Item[] { new Item(269), new Item(227) }, new Item(111), Skills.HERBLORE),
	    	
	    	ANTIPOISON2(79, 1, new Item[] { new Item(259), new Item(5935) }, new Item(5951), Skills.HERBLORE),
	    	
	    	WEAPON_POISON2(82, 1, new Item[] { new Item(2398), new Item(5935) }, new Item(5939), Skills.HERBLORE),
	    	
	    	FELLSTALK_POTION_UNF(91, 1, new Item[] { new Item(21624), new Item(227) }, new Item(21628), Skills.HERBLORE),
	    	
	    	//Potions
	    	ATTACK_POTION(1, 25, new Item[] { new Item(221), new Item(91) }, new Item(121), Skills.HERBLORE),
	    	
	    	RANGING_POTION(3, 30, new Item[] { new Item(1951), new Item(91) }, new Item(27506), Skills.HERBLORE),
	    	
	    	MAGIC_POTION(5, 35, new Item[] { new Item(1474), new Item(95) }, new Item(27514), Skills.HERBLORE),
	    	
	    	STRENGTH_POTION(7, 40, new Item[] { new Item(225), new Item(95) }, new Item(115), Skills.HERBLORE),
	    	
	    	RELICYMS_BALM(8, 40, new Item[] { new Item(1526), new Item(4840) }, new Item(4844), Skills.HERBLORE),
	    	
	    	DEFENCE_POTION(9, 45, new Item[] { new Item(948), new Item(93) }, new Item(133), Skills.HERBLORE),
	    	
	    	ANTIPOISON1_POTION(13, 50, new Item[] { new Item(235), new Item(93) }, new Item(175), Skills.HERBLORE),
	    	
	    	SERUM_207(15, 50, new Item[] { new Item(592), new Item(95) }, new Item(3410), Skills.HERBLORE),
	    	
	    	GUTHIX_REST(18, 59.5, new Item[] { new Item(251), new Item(91) }, new Item(4419), Skills.HERBLORE),
	    	
	    	RESTORE_POTION(22, 62.5, new Item[] { new Item(223), new Item(97) }, new Item(127), Skills.HERBLORE),
	    	
	    	GUTHIX_BALANCE_UNF(22, 25, new Item[] { new Item(1550), new Item(127) }, new Item(7652), Skills.HERBLORE),
	    	
	    	GUTHIX_BALANCE(22, 25, new Item[] { new Item(7650), new Item(7652) }, new Item(7662), Skills.HERBLORE),
	    	
	    	BLAMISH_OIL(25, 80, new Item[] { new Item(1581), new Item(97) }, new Item(1582), Skills.HERBLORE),
	    	
	    	ENERGY_POTION(26, 67.5, new Item[] { new Item(1975), new Item(97) }, new Item(3010), Skills.HERBLORE),
	    	
	    	SUPER_FISHING_EXPLOSIVE(31, 55, new Item[] { new Item(12630), new Item(91) }, new Item(12633), Skills.HERBLORE),
	    	
	    	AGILITY_POTION(34, 80, new Item[] { new Item(2152), new Item(3002) }, new Item(3034), Skills.HERBLORE),
	    	
	    	COMBAT_POTION(36, 84, new Item[] { new Item(9736), new Item(97) }, new Item(9741), Skills.HERBLORE),
	    	
	    	GOBLIN_POTION(37, 85, new Item[] { new Item(11807), new Item(3002) }, new Item(11810), Skills.HERBLORE),
	    	
	    	PRAYER_POTION(38, 87.5, new Item[] { new Item(231), new Item(99) }, new Item(139), Skills.HERBLORE),
	    	
	    	SUMMONING_POTION(40, 92, new Item[] { new Item(12109), new Item(12181) }, new Item(12142), Skills.HERBLORE),
	    	
	    	CRAFTING_POTION(42, 95, new Item[] { new Item(5004), new Item(14856) }, new Item(14840), Skills.HERBLORE),
	    	
	    	SUPER_ATTACK_POTION(45, 100, new Item[] { new Item(221), new Item(101) }, new Item(145), Skills.HERBLORE),
	    	
	    	SUPER_ANTIPOISON1(48, 106.3, new Item[] { new Item(235), new Item(101) }, new Item(181), Skills.HERBLORE),
	    	
	    	FISHING_POTION(50, 112.5, new Item[] { new Item(231), new Item(103) }, new Item(151), Skills.HERBLORE),
	    	
	    	SUPER_ENERGY(52, 117.5, new Item[] { new Item(2970), new Item(103) }, new Item(3018), Skills.HERBLORE),
	    	
	    	HUNTER_POTION(53, 120, new Item[] { new Item(10111), new Item(103) }, new Item(10000), Skills.HERBLORE),
	    	
	    	SUPER_STRENGTH_POTION(55, 125, new Item[] { new Item(225), new Item(105) }, new Item(157), Skills.HERBLORE),
	    	
	    	MAGIC_ESSENCE(57, 130, new Item[] { new Item(9018), new Item(9019) }, new Item(9022), Skills.HERBLORE),
	    	
	    	FLETCHING_POTION(58, 132, new Item[] { new Item(11525), new Item(14856) }, new Item(14848), Skills.HERBLORE),
	    	
	    	WEAPON_POISON_3(60, 137.5, new Item[] { new Item(241), new Item(105) }, new Item(187), Skills.HERBLORE),
	    	
	    	SUPER_RESTORE(63, 142.5, new Item[] { new Item(223), new Item(3004) }, new Item(3026), Skills.HERBLORE),
	    	
	    	MUXTURE1(65, 47.5, new Item[] { new Item(235), new Item(3026) }, new Item(10911), Skills.HERBLORE),
	    	
	    	MIXTURE2(65, 52.5, new Item[] { new Item(1526), new Item(10911) }, new Item(10919), Skills.HERBLORE),
	    	
	    	SANFEW_SERUM(65, 60, new Item[] { new Item(10937), new Item(10919) }, new Item(10927), Skills.HERBLORE),
	    	
	    	SUPER_DEFENCE_POTION(66, 150, new Item[] { new Item(239), new Item(107) }, new Item(163), Skills.HERBLORE),
	    	
	    	ANTIPOISON2_POTION(68, 155, new Item[] { new Item(6049), new Item(5942) }, new Item(5945), Skills.HERBLORE),
	    	
	    	ANTIFIRE(69, 157.5, new Item[] { new Item(241), new Item(2483) }, new Item(2454), Skills.HERBLORE),
	    	
	    	SUPER_RANGING_POTION(72, 162.5, new Item[] { new Item(245), new Item(109) }, new Item(169), Skills.HERBLORE),
	    	
	    	WEAPON_POISON_PLUS(73, 165, new Item[] { new Item(223), new Item(5936) }, new Item(5937), Skills.HERBLORE),
	    	
	    	SUPER_MAGIC_POTION(76, 172.5, new Item[] { new Item(3138), new Item(2483) }, new Item(3042), Skills.HERBLORE),
	    	
	    	ZAMORAK_BREW(78, 175, new Item[] { new Item(247), new Item(111) }, new Item(189), Skills.HERBLORE),
	    	
	    	ANTIOISON_PLUSPLUS(79, 177.5, new Item[] { new Item(6051), new Item(5951) }, new Item(5954), Skills.HERBLORE),
	    	
	    	SARADOMIN_BREW(81, 180, new Item[] { new Item(6693), new Item(3002) }, new Item(6687), Skills.HERBLORE),
	    	
	    	WEAPON_POISON_PLUS_PLUS(82, 190, new Item[] { new Item(6018), new Item(5939) }, new Item(5940), Skills.HERBLORE),
	    	
	    	ADRENALINE_POTION(84, 200, new Item[] { new Item(5972), new Item(3018) }, new Item(15301), Skills.HERBLORE),
	    	
	    	SUPER_ANTIFIRE(85, 210, new Item[] { new Item(4621), new Item(2454) }, new Item(15305), Skills.HERBLORE),
	    	
	    	EXTREME_ATTACK_POTION(88, 220, new Item[] { new Item(261), new Item(145) }, new Item(15309), Skills.HERBLORE),
	    	
	    	EXTREME_STRENGTH_POTION(89, 230, new Item[] { new Item(267), new Item(157) }, new Item(15313), Skills.HERBLORE),
	    	
	    	EXTREME_DEFENCE_POTION(90, 240, new Item[] { new Item(2481), new Item(163) }, new Item(15317), Skills.HERBLORE),
	    	
	    	EXTREME_MAGIC_POTION(91, 250, new Item[] { new Item(9594), new Item(3042) }, new Item(15321), Skills.HERBLORE),
	    	
	    	EXTREME_RANGING_POTION(92, 260, new Item[] { new Item(12539), new Item(12539), new Item(12539), new Item(12539), new Item(12539), new Item(169) }, new Item(15325), Skills.HERBLORE),
	    	
	    	SUPER_ZAMORAK_BREW(93, 180, new Item[] { new Item(245), new Item(189) }, new Item(28201), Skills.HERBLORE),
	    	
	    	SUPER_SARADOMIN_BREW(93, 180, new Item[] { new Item(28256), new Item(6687) }, new Item(28193), Skills.HERBLORE),
	    	
	    	SUPER_GUTHIX_REST(93, 59.5, new Item[] { new Item(28253), new Item(4419) }, new Item(28209), Skills.HERBLORE),
	    	
	    	SUPER_PRAYER(94, 270, new Item[] { new Item(6810), new Item(139) }, new Item(15329), Skills.HERBLORE),
	    	
	    	PRAYER_RENEWAL(94, 190, new Item[] { new Item(21622), new Item(21628) }, new Item(21632), Skills.HERBLORE),
	    	
	    	OVERLOAD(96, 1000, new Item[] { new Item(269), new Item(15309), new Item(15313), new Item(15317), new Item(15321), new Item(15325) }, new Item(15333), Skills.HERBLORE),
		
		;

		public static SmeltingBar getBarByProduce(int id) {//SewingLeather
			for(SmeltingBar bar : SmeltingBar.values()) {//SeweingLeather
				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 PotionMaking(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 brew 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 brew 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 brew 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 brew 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 brew 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 brew 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());
		}
			int amount = bar.getProducedBar().getAmount();
			player.getInventory().addItem(bar.getProducedBar().getId(), amount);
			player.getPackets().sendGameMessage("You brew together a " + bar.getProducedBar().getDefinitions().getName());
		if (ticks > 0) {
			return 1;
		}
		return -1;
	}

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