package extend.mj.player.rulestate;

import com.game.Global;
import com.game.Util;
import com.game.player.state.PlayerWaitState;
import com.game.state.StateBase;
import com.taurus.core.entity.ITArray;
import com.taurus.core.entity.TArray;

import extend.mj.Config;
import extend.mj.EXMainServer;
import extend.mj.EXPlayer;
import extend.mj.EXRoom;
import extend.mj.EXScore;
import extend.mj.OpCard;
import extend.mj.RuleWeight;
import extend.mj.player.state.EXPlayerDrawState;

/**
 * ��Ӧ���ܴ���״̬
 * 
 *
 * 2017��8��30��
 * PROtherKongState.java
 */
public class PROtherKongState extends StateBase<EXPlayer> {

	@Override
	public void enter(EXPlayer owner) {
		// TODO Auto-generated method stub
		
		EXRoom room = owner.getRoom();
		EXPlayer activePlayer =  (EXPlayer)room.playerMapBySeat.get(owner.room.activeSeat);
		activePlayer.outcardList.remove(activePlayer.outcardList.size()-1);
		activePlayer.stateMachine.changeState(Global.getState(PlayerWaitState.class));
		int fromseat  = activePlayer.seat;
		room.addScore(owner,activePlayer, 3,EXScore.KONG);
		
		EXMainServer.gameCtr.changeActiveSeat(room,owner.seat);
		owner.cardInhand.add(owner.getRoom().activeCard);
		
		
		int [] kongGroup = new int [4];
		int card = room.activeCard;
		kongGroup[0] = card;
		kongGroup[1] = card;
		kongGroup[2] = card;
		kongGroup[3] = card;
		
		owner.kongGroup.add(kongGroup);
		owner.opCardList.add( new OpCard(RuleWeight.TYPE_KONG, card, fromseat) );
		Util.removeCard(owner.cardInhand, card, 4);
		room.activeCard = 0;
		room.lastDiscardSeat = 0;
		ITArray opcard = TArray.newInstance();
		opcard.addInt(card);
		opcard.addInt(card);
		opcard.addInt(card);
		EXMainServer.gameCtr.actionCard(owner, card, RuleWeight.TYPE_KONG, fromseat,opcard);
		owner.settleLog.add(Config.SETTLE_MING_KONG);
//		owner.stateMachine.changeState( Global.getState(EXPlayerDrawState.class) );
		
//		owner.room.broadCastToServer(owner.playerid, EXActionEvent.EVENT_KONG_WIN, null);
//		if(room.tipMap.size() == 0){
			toNextState(owner);
//		}else{
//			owner.stateMachine.changeState(Global.getState(EXPlayerWaitKongWinState.class));
//		}
	}

	@Override
	public void toNextState(EXPlayer owner) {
		owner.stateMachine.changeState(Global.getState(EXPlayerDrawState.class));
		
	}

	@Override
	public void exit(EXPlayer owner) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void execute(EXPlayer owner, String cmd, int gid, Object param) {
		// TODO Auto-generated method stub
		
	}

}
