package com.rs.game.player.content;

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

public class WeaponFire {

    public static final int DAMP_CLOTH = 1485;
    
	public static enum Weapon {
	    
		BRONZE_FIRE_ARROWS(882, 598),
		
		IRON_FIRE_ARROWS(884, 2532),
		
		STEEL_FIRE_ARROWS(886, 2534),
		
		MITHRIL_FIRE_ARROWS(888, 2536),
		
		ADAMANT_FIRE_ARROWS(890, 2538),
		
		RUNE_FIRE_ARROWS(892, 2540),
		
		DRAGON_FIRE_ARROWS(11212, 11217),
		
		DARK_FIRE_ARROWS(29617, 29627),
		
		;

		private int id;
		private int[] poisonIds;

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

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

	public static int[][] POISON = new int[][]
	{
	{ 1485, 1485 },
	{ 17572, 17596 } };

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

	public static boolean poison(Player player, Item item, int type, boolean dungeoneering) {
		Weapon weapon = getWeapon(item.getId());
		if (weapon == null)
			return false;
		int amt = item.getAmount() > Settings.getCraftRate() * 15 ? Settings.getCraftRate() * 15 : item.getAmount();
		if (amt > 1 && !player.getInventory().hasFreeSlots()) {
			player.getPackets().sendGameMessage("Not enough space in your inventory.");
			return false;
		}
		player.getInventory().deleteItem(item.getId(), amt);
		player.getInventory().deleteItem(DAMP_CLOTH, 1);
		player.getInventory().addItem(weapon.poisonIds[type], amt);
		player.getPackets().sendGameMessage("You wrap a damp cloth around some " + item.getName() + "s.");
		return true;
	}

}
