package extend.mj.player.state;

import com.game.ActionEvent;
import com.game.Global;
import com.game.player.state.PlayerPauseState;
import com.game.player.state.PlayerWaitState;
import com.taurus.core.entity.ITObject;

import extend.mj.EXActionEvent;
import extend.mj.EXMainServer;
import extend.mj.EXPlayer;
import extend.mj.EXRoom;
import extend.mj.room.state.EXRoomSetpState;

/**
 * 
 */
public class EXPlayerTianTingTipState extends EXPlayerTipState {

	@Override
	protected void _tipEvent(EXPlayer owner) {
		EXMainServer.gameCtr.tingTipEvent(owner);
	}
	@Override
	protected void _action(EXPlayer owner,int id,int gid) {
		owner.tipMgr.clean();
		if(id!=0) {
			owner.tianting = true;
			owner.autoOutCard = true;
			EXMainServer.gameCtr.tingEvent(owner);
		}
		if(owner.seat == owner.room.bankerSeat) {
			EXRoom room = owner.getRoom();
			owner.room.broadCastToServer(owner.playerid, EXActionEvent.EVENT_OTHER_DISCARD, room.activeCard);
			if (room.tipMap.size() != 0) {
				owner.stateMachine.changeState(Global.getState(PlayerPauseState.class));
			} else {
				this.toNextState(owner);
			}
		}else {
			owner.stateMachine.changeState(Global.getState(PlayerWaitState.class));
			owner.getRoom().tianTingCount --;
			owner.getRoom().stateMachine.execute(EXActionEvent.EVENT_TIANTING, gid, null);
		}
	}
	
	@Override
	public void execute(EXPlayer owner, String cmd, int gid, Object param) {
		super.execute(owner, cmd, gid, param);
		if (cmd.equals(EXActionEvent.EVENT_ACTION)) {
			ITObject netParam = (ITObject) param;
			int id = netParam.getInt("id");
			_action(owner,id,gid);
		}else if(cmd.equals(ActionEvent.EVENT_TIMER_AUTO)) {
			_action(owner,0,gid);
		}
	}

	@Override
	public void toNextState(EXPlayer owner) {
		if(owner.seat == owner.room.bankerSeat) {
			owner.stateMachine.changeState(Global.getState(PlayerWaitState.class));
			owner.room.stateMachine.changeState(Global.getState(EXRoomSetpState.class));
		}else {
			super.toNextState(owner);
		}
	}
}
