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.PlayerEndState;
import com.game.player.state.PlayerPopupState;
import com.game.player.state.PlayerReadyState;
import com.game.state.StateBase;


public class RoomEndState extends StateBase<Room>{
	@Override
	public void enter(Room owner) {
		owner.saveSocre();
		
		for (Entry<Integer, Player> entry : owner.playerMapBySeat.entrySet()) { 
			Player player = entry.getValue();
			player.stateMachine.changeState( Global.getState(PlayerEndState.class));
		}
	}
	
	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 player = entry.getValue();
					if(player.stateMachine.curState instanceof PlayerPopupState) {
						continue;
					}
					if (!(player.stateMachine.curState instanceof PlayerReadyState)) {
						return;
					}
				}
				owner.stateMachine.changeState(Global.getState(RoomStartGameState.class));
				break;
		}
	}
}
