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.PlayerReadyState;
import com.game.state.StateBase;
import com.taurus.core.plugin.redis.Redis;

/**
 * 房间初始状态
 * 
 */
public class RoomInitState extends StateBase<Room> {

	
	@Override
	public void execute(Room owner, String cmd, int gid, Object param) {
		switch (cmd) {
			case ActionEvent.EVENT_READY:
				for (Entry<Integer, Player> entry : owner.playerMapById.entrySet()) {
					if (!(entry.getValue().stateMachine.curState instanceof PlayerReadyState)) {
						return;
					}
				}
				if (owner.maxPlayers == owner.playerMapById.size()) {
					owner.redis_room_map.put("open","0");
					Redis.use().hmset(owner.room_key, owner.redis_room_map);
					owner.stateMachine.changeState(Global.getState(RoomWaitState.class));
				}
				break;

			default:
				break;
		}

	}

}
