package extend.mj.room.state;

import java.util.Map.Entry;

import com.game.Global;
import com.game.data.Player;
import com.game.state.StateBase;
import com.taurus.core.entity.ITObject;
import com.taurus.core.entity.TObject;

import extend.mj.Config;
import extend.mj.EXActionEvent;
import extend.mj.EXMainServer;
import extend.mj.EXPlayBack;
import extend.mj.EXRoom;
import extend.mj.player.state.EXPlayerPiaoNiaoTipState;

/**
 * ���䷢��״̬
 * 
 *
 * 2017��8��30��
 * EXRoomDealState.java
 */
public class EXRoomDealState extends StateBase<EXRoom> {

	@Override
	public void enter(EXRoom owner) {
		owner.card.init();
		if (owner.bankerSeat == 0) {
			owner.bankerSeat = 1;
		}
//		owner.isplaying = true;
//		owner.round += 1;
		
		boolean piao_niao = owner.config.getBoolean(Config.ROOM_CONFIG_PIAO_NIAO);
		if(piao_niao) {
			owner.piaoNiaoCount = owner.maxPlayers;
			for (Entry<Integer, Player> entry : owner.playerMapById.entrySet()) {
				Player player = entry.getValue();
				player.stateMachine.changeState(Global.getState(EXPlayerPiaoNiaoTipState.class));
			}
		}else{
			this.toNextState(owner);
		}
		
	}

	@Override
	public void toNextState(EXRoom owner) {
		ITObject param = new TObject();
		param.putInt("bank_seat", owner.bankerSeat);
		EXMainServer.gameCtr.dealCard(owner);
		owner.playBackData = new EXPlayBack(owner);
		owner.stateMachine.changeState(Global.getState(EXRoomSetpState.class));
	}
	
	public void execute(EXRoom owner, String cmd, int gid, Object param) {
		if(cmd.equals(EXActionEvent.EVENT_PIAO_NIAO)) {
			if(owner.piaoNiaoCount==0) {
				this.toNextState(owner);
			}
		}
		
	}
}
