package extend.pk.room.state;

import java.util.Map.Entry;

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

import extend.pk.EXActionEvent;
import extend.pk.EXMainServer;
import extend.pk.EXPlayer;
import extend.pk.EXRoom;
import extend.pk.player.state.EXPlayerDaNiaoTipState;

public class EXRoomDaNiaoState extends StateBase<EXRoom> {

	@Override
	public void enter(EXRoom owner) {
		owner.daNiaoCount = owner.maxPlayers;
		Global.logger.info("owner.daNiaoCount:" + owner.daNiaoCount);
		Global.logger.info("owner.isDaniao:" + owner.isDaniao);

		if (!owner.isDaniao) {
			owner.stateMachine.changeState(Global.getState(EXRoomDealState.class));
			return;
		}

		for (Entry<Integer, Player> entry : owner.playerMapById.entrySet()) {
			Player player = entry.getValue();
			player.stateMachine.changeState(Global.getState(EXPlayerDaNiaoTipState.class));
		}
		owner.isDaniao = false;
	}

	public void execute(EXRoom owner, String cmd, int gid, Object param) {
		if (cmd.equals(EXActionEvent.EVENT_DA_NIAO)) {
			Global.logger.info("owner.daNiaoCount:" + owner.daNiaoCount);
			if (owner.daNiaoCount <= 0) {
				owner.stateMachine.changeState(Global.getState(EXRoomDealState.class));
			}
			
		}
	}
	
}
