package com.robot;

import java.util.HashMap;
import java.util.Map;

import com.robot.manager.RoomManager;
import com.robot.manager.SessionManager;
import com.robot.player.state.PlayerEndState;
import com.robot.player.state.PlayerInitState;
import com.robot.player.state.PlayerPauseState;
import com.robot.player.state.PlayerPopupState;
import com.robot.player.state.PlayerReadyState;
import com.robot.player.state.PlayerReloadState;
import com.robot.player.state.PlayerSpectatorState;
import com.robot.player.state.PlayerWaitState;
import com.robot.room.state.RoomDestoryGameState;
import com.robot.room.state.RoomEndState;
import com.robot.room.state.RoomInitState;
import com.robot.room.state.RoomReloadState;
import com.robot.room.state.RoomStartGameState;
import com.robot.room.state.RoomWaitState;
import com.robot.state.StateBase;
import com.taurus.core.util.Logger;

public class Global {
	/**
	 * debug模式
	 */
	public static boolean			loggerDebug	= false;
	// 日志
	public static Logger			logger;
	// session管理器
	public static SessionManager sessionMgr;
	// 桌子管理器
	public static RoomManager roomMgr;

	public static GameController	gameCtr;
	
	public static EventController eventCtr;
	/**
	 * 游戏ID
	 */
	public static int				gameId		= 1;
	/**
	 * 游戏名字
	 */
	public static String			gameName	= "";
	
	
	
	public static void init() {

		Global.sessionMgr = new SessionManager();
		Global.roomMgr = new RoomManager();
		Global.eventCtr = new EventController();
		
		registerState(RoomInitState.class, new RoomInitState());
		registerState(RoomEndState.class, new RoomEndState());
		registerState(RoomDestoryGameState.class, new RoomDestoryGameState());
		registerState(RoomWaitState.class, new RoomWaitState());
		registerState(RoomReloadState.class, new RoomReloadState());
		registerState(RoomStartGameState.class, new RoomStartGameState());

		registerState(PlayerInitState.class, new PlayerInitState());
		registerState(PlayerPauseState.class, new PlayerPauseState());
		registerState(PlayerReadyState.class, new PlayerReadyState());
		registerState(PlayerReloadState.class, new PlayerReloadState());
		registerState(PlayerWaitState.class, new PlayerWaitState());
		registerState(PlayerSpectatorState.class, new PlayerSpectatorState());
		registerState(PlayerPopupState.class, new PlayerPopupState());
		registerState(PlayerEndState.class, new PlayerEndState());
	}

	private static Map<Class<?>, StateBase<?>> state_map = new HashMap<>();

	public static void registerState(Class<?> cls, StateBase<?> state) {
		state_map.put(cls, state);
	}

	public static StateBase<?> getState(Class<?> cls) {
		StateBase<?> state = state_map.get(cls);
		return state;
	}
	
	

	public static void info(String msg, Object... params) {
		if (loggerDebug) {
			logger.info(Util.stringFormat(msg, params));
		}
	}

	public static void warn(String msg, Object... params) {
		if (loggerDebug) {
			logger.warn(Util.stringFormat(msg, params));
		}
	}

	public static void error(String msg, Object... params) {
		if (loggerDebug) {
			logger.error(Util.stringFormat(msg, params));
		}
	}
}
