package com.game.room.state;

import java.util.Map.Entry;

import com.game.ActionEvent;
import com.game.Global;
import com.game.data.Player;
import com.game.data.Room;
import com.game.player.state.PlayerPopupState;
import com.game.player.state.PlayerReadyState;
import com.game.state.StateBase;

/**
 * 房间重连状态
 * 
 */
public class RoomReloadState extends  StateBase<Room>{
	
	public void execute(Room owner, String cmd, int gid, Object param) {
		switch (cmd) {
			case ActionEvent.EVENT_READY:
				for (Entry<Integer, Player> entry : owner.playerMapBySeat.entrySet()) {
					Player p = entry.getValue();
					if (!(p.stateMachine.curState instanceof PlayerReadyState || p.stateMachine.curState instanceof PlayerPopupState)) {
						return;
					}
				}
				if(owner.round == 0 &&owner.startGameNum == 0 && owner.playerMapBySeat.size()>1) {

					owner.stateMachine.changeState(Global.getState(RoomWaitState.class));

				}else {
					int num = owner.startGameNum ==0 ? 2 :owner.startGameNum;
					if(owner.playerMapBySeat.size() >= num) {
						owner.stateMachine.changeState(Global.getState(RoomStartGameState.class));
						//owner.stateMachine.changeState(Global.getState(RoomWaitState.class));
					}
				}
				break;
		}
	}
}
