package com.l2jfrozen.gameserver.handler.voicedcommandhandlers;

import com.l2jfrozen.Config;
import com.l2jfrozen.gameserver.handler.IVoicedCommandHandler;
import com.l2jfrozen.gameserver.model.actor.instance.L2PcInstance;
import com.l2jfrozen.gameserver.model.entity.event.TvTEvent;

public class TvTCmd implements IVoicedCommandHandler
{
	private static final String[] VOICED_COMMANDS = { "tvtjoin", "tvtleave", "tvtinfo" };

	@Override
	public boolean useVoicedCommand(String s, L2PcInstance activeChar, String target)
	{
		if (s.startsWith("tvtjoin"))
		{
			if (TvTEvent.isPlayerParticipant(activeChar.getObjectId()))
			{
				activeChar.sendMessage("Вы уже зарегистрированы на участие в ТвТ");
				return false;
			}
			if (TvTEvent.isParticipating())
			{
				TvTEvent.addParticipant(activeChar);
				activeChar.sendMessage("Вы зарегистрированы на участие в ТвТ");
			}
			else 
			{
				activeChar.sendMessage("ТвТ не активен или уже идет турнир");
    		}
		}

		if(s.startsWith("tvtleave"))
		{
			if (!TvTEvent.isPlayerParticipant(activeChar.getObjectId()))
			{
				activeChar.sendMessage("Вы не были зарегистрированы на участие в ТвТ");
				return false;
			}
			if (TvTEvent.isParticipating())
			{
				TvTEvent.removeParticipant(activeChar.getObjectId());
				activeChar.sendMessage("Вы больше не зарегистрированы на участие в ТвТ");
    		}
			else
			{
				activeChar.sendMessage("ТвТ не активен или уже идет турнир");
    		}
		}
		if(s.startsWith("tvtinfo"))
		{
			int[] teamsPlayerCounts = TvTEvent.getTeamsPlayerCounts();
			int comand1 = teamsPlayerCounts[0];
			int comand2 = teamsPlayerCounts[1];
			int allplayer = comand1+comand2;
			activeChar.sendMessage("There is " + allplayer + " player participating in this event.");
			activeChar.sendMessage("In a team called " + Config.TVT_EVENT_TEAM_1_NAME + " " + comand1 + " players");
			activeChar.sendMessage("In a team called " + Config.TVT_EVENT_TEAM_2_NAME + " " + comand2 + " players");
			activeChar.sendMessage("Player Min " + Config.TVT_EVENT_MIN_LVL + ", Max " + Config.TVT_EVENT_MAX_LVL + " lvl.");
		}
		return true;
	}
	
	@Override
	public String[] getVoicedCommandList()
	{
		return VOICED_COMMANDS;
	}
}