package com.rs.game.player.content;

import com.rs.cache.loaders.ItemDefinitions;
import com.rs.game.Animation;
import com.rs.game.player.Player;
import com.rs.game.player.Skills;
import com.rs.game.player.actions.Action;

/**
 * 
 * @author OnegaiSatan
 */

public class SpinningAction extends Action {

	private Animation SPINNING = new Animation(883);
	private int itemUsed;

	public static int getSpunId(int itemUsed) {
		switch(itemUsed) {
		case 1737:
			return 1759;
		case 15415:
			return 15416;
		case 1779:
			return 1777;
		case 9436:
			return 9438;
		case 6051:
			return 6038;
		case 10814:
			return 954;
		case 3693:
			return 3694;
		//Dungeoneering
		case 17448://Salve
			return 17468;
		case 17450://Wildercress
			return 17470;
		case 17452://Brightleaf
			return 17472;
		case 17454://Roseblood
			return 17474;
		case 17456://Bryll
			return 17476;
		case 17458://Duskweed
			return 17478;
		case 17460://Soulbell
			return 17480;
		case 17462://Ectograss
			return 17482;
		case 17464://Runeleaf
			return 17484;
		case 17466://Spiritbloom
			return 17486;
		default:
			return -1;
		}
	}

	public SpinningAction(int itemUsed) {
		this.itemUsed = itemUsed;
	}
	
	public boolean checkAll(Player player) {
		if (getSpunId(itemUsed) == -1) {
			player.getPackets().sendGameMessage("You can't spin that on a spinning wheel.");
			return false;
		}
		if (!player.getInventory().containsItem(itemUsed, 1)) {
			player.getPackets().sendGameMessage("You have run out of "+ItemDefinitions.getItemDefinitions(itemUsed).getName().toLowerCase()+" to spin!");
			return false;
		}
		return true;
	}

	@Override
	public boolean start(Player player) {
		if (!checkAll(player))
			return false;
		player.getPackets().sendGameMessage("You start spinning the "+ItemDefinitions.getItemDefinitions(itemUsed).getName().toLowerCase()+" into "+ItemDefinitions.getItemDefinitions(getSpunId(itemUsed)).getName().toLowerCase()+".", true);
		return true;
	}

	@Override
	public boolean process(Player player) {
		if (!checkAll(player))
			return false;
		return true;
	}

	@Override
	public int processWithDelay(Player player) {
		if (!checkAll(player))
			return -1;
		player.setNextAnimation(SPINNING);
		player.getInventory().deleteItem(itemUsed, 1);
		player.getInventory().addItem(getSpunId(itemUsed), 1);
		player.getSkills().addXp(Skills.CRAFTING, 15);
		return 1;
	}

	@Override
	public void stop(Player player) {

	}
}
