package com.rs.game.player.actions;

import com.rs.game.item.Item;
import com.rs.game.player.Player;
import com.rs.net.decoders.handlers.InventoryOptionsHandler;

//@Author OnegaiSatan / Baki

public class Dyingcapes {

	public static enum Weapon {
	    	//Black Dying (CleanId, RedItem, YellowItem, BlueItem, OrangeItem, GreenItem, PurpleItem, PinkItem)
		Capes1(1019, 1007, 1023, 1021, 1031, 1027, 1029, 6959),
		//Red Dying (CleanId, RedItem, YellowItem, BlueItem, OrangeItem, GreenItem, PurpleItem, PinkItem)
		Capes2(1007, 1007, 1023, 1021, 1031, 1027, 1029, 6959),
		//Yellow Dying (CleanId, RedItem, YellowItem, BlueItem, OrangeItem, GreenItem, PurpleItem, PinkItem)
		Capes3(1023, 1007, 1023, 1021, 1031, 1027, 1029, 6959),
		//Blue Dying (CleanId, RedItem, YellowItem, BlueItem, OrangeItem, GreenItem, PurpleItem, PinkItem)
		Capes4(1021, 1007, 1023, 1021, 1031, 1027, 1029, 6959),
		//Orange Dying (CleanId, RedItem, YellowItem, BlueItem, OrangeItem, GreenItem, PurpleItem, PinkItem)
		Capes5(1031, 1007, 1023, 1021, 1031, 1027, 1029, 6959),
		//Green Dying (CleanId, RedItem, YellowItem, BlueItem, OrangeItem, GreenItem, PurpleItem, PinkItem)
		Capes6(1027, 1007, 1023, 1021, 1031, 1027, 1029, 6959),
		//Purple Dying (CleanId, RedItem, YellowItem, BlueItem, OrangeItem, GreenItem, PurpleItem, PinkItem)
		Capes7(1029, 1007, 1023, 1021, 1031, 1027, 1029, 6959),
		//Red Dying (CleanId, RedItem, YellowItem, BlueItem, OrangeItem, GreenItem, PurpleItem, PinkItem)
		Capes8(6959, 1007, 1023, 1021, 1031, 1027, 1029, 6959)
		;

		private int id;
		private int[] dyeIds;

		private Weapon(int id, int... dyeIds) {
			this.id = id;
			this.dyeIds = dyeIds;
		}
	}

	private static Weapon getWeapon(int id) {
		for (Weapon weapon : Weapon.values())
			if (weapon.id == id)
				return weapon;
		return null;
	}

	public static int[][] DYE = new int[][]
	{
	{ 1763, 1765, 1767, 1769, 1771, 1773, 6955 },
	{ -1, -1, -1, -1, -1, -1, -1 } };

	public static boolean dye(Player player, Item item1, Item item2, boolean dungeoneering) {
		for (int i = 0; i < DYE[dungeoneering ? 1 : 0].length; i++) {
			Item weapon = InventoryOptionsHandler.contains(DYE[dungeoneering ? 1 : 0][i], item1, item2);
			if (weapon == null)
				continue;
			return dying(player, weapon, i, dungeoneering);
		}
		return false;
	}

	public static boolean dying(Player player, Item item, int type, boolean dungeoneering) {
		Weapon weapon = getWeapon(item.getId());
		if (weapon == null)
			return false;
		player.getInventory().deleteItem(item.getId(), 1);
		player.getInventory().addItem(weapon.dyeIds[type], 1);
		player.getInventory().deleteItem(DYE[dungeoneering ? 1 : 0][type], 1);
		player.getPackets().sendGameMessage("You dye your " + item.getName() + " with enthusiasm.");
		return true;
	}

}
