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.ITObject;
import com.taurus.core.entity.TArray;
import extend.mj.*;
import extend.mj.player.state.EXPlayerKongDrawState;
import extend.mj.uitl.CardUtil;

import java.util.Collections;

/**
 * ��Ӧ���ܴ���״̬
 * 
 *
 * 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;
		Global.logger.info("PRPongKongState opcard:");
		Global.logger.info(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;
		


		room.activeCard = card;

		room.gangnum = room.gangnum+1;
		EXMainServer.gameCtr.kaiGangEvent(owner);
		EXMainServer.gameCtr.actionCard(owner, card, RuleWeight.TYPE_PONG_KONG, owner.seat,opCard);


	}

	@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));
	}

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

			case EXActionEvent.EVENT_DOGANG:
				ITObject netParam2 = (ITObject) param;
				int discard2 = netParam2.getInt("card");
				EXRoom room = owner.getRoom();
				RoomCard cards = room.card;
				Global.logger.info("cards list1:"+cards.cardList);
				Collections.reverse(cards.cardList);
				Util.removeCard(cards.cardList, discard2, 1);
				Global.logger.info("cards list2:"+cards.cardList);
				cards.cardList.add(discard2);
				Collections.reverse(cards.cardList);

				room.gangzi1 = cards.cardList.get(cards.cardList.size()-1);
				room.gangzi2 = cards.cardList.get(cards.cardList.size()-2);

				EXMainServer.gameCtr.sendGangZiEvent(room);
				//}
				Global.logger.info("cards list3:"+cards.cardList);
				Global.logger.info("PROtherKongState:"+discard2);
				ITArray opcard = TArray.newInstance();
				opcard.addInt(discard2);

				toNextState(owner);
				break;
			default:
				break;
		}
	}

}
