package extend.mj.player.rulestate;

import com.game.Global;
import com.game.Util;
import com.game.state.StateBase;
import com.taurus.core.entity.ITArray;
import com.taurus.core.entity.TArray;
import extend.mj.*;
import extend.mj.player.state.EXPlayerKongDrawState;
import extend.mj.player.state.EXPlayerWaitKongWinState;
import extend.mj.uitl.CardUtil;

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

	@Override
	public void enter(EXPlayer owner) {
		
		EXRoom room = owner.getRoom();
		ITArray opCard = owner.opCard;
		int card = opCard.getInt(0);

		Util.removeCard(owner.cardInhand, card, 1);
		CardUtil.removeGroup(owner.pongGroup, card);
		CardUtil.removeOpcard(owner.opCardList, new OpCard(RuleWeight.TYPE_PONG, card));

		int[] kong = new int[4];
		kong[0] = card;
		kong[1] = card;
		kong[2] = card;
		kong[3] = card;
		owner.kongGroup.add(kong);
		owner.opCardList.add(new OpCard(RuleWeight.TYPE_KONG, card));
		owner.gangshangpao = true;
		
		ITArray opcard = TArray.newInstance();
		opcard.addInt(card);
		
		EXMainServer.gameCtr.actionCard(owner, card, RuleWeight.TYPE_PONG_KONG, owner.seat,opcard);

		room.activeCard = card;
		boolean qiangkong = room.config.getBoolean(Config.ROOM_CONFIG_QIANGKONG);
		if(qiangkong) {
			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));
			}
		}else {
			toNextState(owner);
		}
		
	}

	@Override
	public void toNextState(EXPlayer owner) {
		owner.settleLog.add(Config.SETTLE_MING_KONG);
		owner.getRoom().addAllScore(owner, Config.BU_GANG_SCORE, EXScore.KONG);
		owner.getRoom().activeCard = 0;
		owner.ming_gang_num++;
		owner.stateMachine.changeState(Global.getState(EXPlayerKongDrawState.class));
	}

}
