package extend.mj.room.state;

import com.game.Global;
import com.game.data.Player;
import com.game.state.StateBase;

import extend.mj.Config;
import extend.mj.EXMainServer;
import extend.mj.EXPlayer;
import extend.mj.EXRoom;

import java.util.Map;

/**
 * ���俪ʼ״̬
 * 
 */
public class EXRoomStartGameState extends StateBase<EXRoom> {

	@Override
	public void enter(EXRoom owner) {
//		owner.readyCount = 0;
//		for (Entry<Integer, Player> entry : owner.playerMapById.entrySet()) {
//			Player player = entry.getValue();
//			player.ready = false;
//			player.clear();
//			player.initSeat();
//		}
		owner.startGame();
		
		this.toNextState(owner);
	}

	@Override
	public void toNextState(EXRoom owner) {
		if(owner.config.containsKey(Config.ROOM_CONFIG_PIAO) && owner.config.getInt(Config.ROOM_CONFIG_PIAO) != 0) {
			if (owner.config.getInt(Config.ROOM_CONFIG_PIAO) == 3)
			{
				int piaofen = owner.config.getInt(Config.ROOM_CONFIG_PIAO_FEN);

				for (Map.Entry<Integer, Player> entry : owner.playerMapById.entrySet()) {
					EXPlayer player = (EXPlayer) entry.getValue();
					player.piao = piaofen;
					player.last_piao = piaofen;
					EXMainServer.gameCtr.piaoEvent(player);
				}
				owner.stateMachine.changeState(Global.getState(EXRoomDealState.class));
			}
			else {
				owner.stateMachine.changeState(Global.getState(EXRoomPiaoState.class));
			}
		}
		else{
			owner.stateMachine.changeState(Global.getState(EXRoomDealState.class));
		}
	}

}
