package com.rs.game.player.actions;

import com.rs.game.Animation;
import com.rs.game.Graphics;
import com.rs.game.EffectsManager.EffectType;
import com.rs.game.player.Player;
import com.rs.utils.Utils;

public class Rest extends Action {

	private static int[][] REST_DEFS =
	{
	{ 5713, 1549, 5748, -1, -1 },
	{ 11786, 1550, 11788, -1, -1 },
	{ 5713, 1551, 2921, -1, -1 },
	{ 20304, 2869, 20306, -1, -1 },//Strongarm Rest
	{ 17301, 2591, 17303, -1, -1 },//Zen Resting
	{ 20287, 2870, 20288, 4003, 4005 },//Arcane Rest
	{ 24647, 3277, 24651, 5164, 5165 },//Crystal Impling Rest
	{ 23654, 3166, 23656, 4838, 4840 },//Sinister Slumber
	{ 23660, 3167, 23662, 4841, 4843 },//Crowd Surf
	{ 23669, 3168, 23671, 4844, 4846 },//Armchair Warrior
	{ 24684, 3275, 24685, 5173, 5175 },//Energy Drain
	{ 24682, 3276, -1, -1, -1 }//Wushanko Resting
	};

	private int index;
	private boolean musician;

	public Rest(boolean musician) {
		this.musician = musician;
	}

	@Override
	public boolean start(Player player) {
		if (!process(player))
			return false;
		index = Utils.random(REST_DEFS.length);
		player.setResting(musician ? 2 : 1);
		player.setNextAnimation(new Animation(REST_DEFS[index][0]));
		player.getAppearence().setRenderEmote(REST_DEFS[index][1]);
		player.setNextGraphics(new Graphics(REST_DEFS[index][3]));
		setActionDelay(player, 1);
		return true;
	}

	@Override
	public boolean process(Player player) {
		if (player.getEffectsManager().hasActiveEffect(EffectType.POISON)) {
			player.getPackets().sendGameMessage("You can't rest while you're poisoned.");
			return false;
		}
		if (player.isUnderCombat()) {
			player.getPackets().sendGameMessage("You can't rest until 10 seconds after the end of combat.");
			return false;
		}
		return true;
	}

	@Override
	public int processWithDelay(Player player) {
		return 0;
	}

	@Override
	public void stop(Player player) {
		player.setResting(0);
		player.setNextAnimation(new Animation(REST_DEFS[index][2]));
		player.setNextGraphics(new Graphics(REST_DEFS[index][4]));
		player.getEmotesManager().setNextEmoteEnd();
		player.getAppearence().setRenderEmote(-1);
	}

}
