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 java.util.Collections;

/**
 * ��Ӧ���ܴ���״̬
 * 
 *
 * 2017��8��30��
 * PRSelfKongState.java
 */
public class PRSelfKongState 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, 4);
		int [] kongGroup = new int [4];
		kongGroup[0] = card;
		kongGroup[1] = card;
		kongGroup[2] = card;
		kongGroup[3] = card;
		owner.selfKongGroup.add(kongGroup);
		owner.opCardList.add(new OpCard(RuleWeight.TYPE_SELF_KONG, card, owner.seat, kongGroup));
		owner.gangshangpao = true;

		ITArray opcard = TArray.newInstance();
		opcard.addInt(card);
		opcard.addInt(card);
		opcard.addInt(card);
		opcard.addInt(card);
		EXMainServer.gameCtr.actionCard(owner, card, RuleWeight.TYPE_SELF_KONG, owner.seat,opcard);



		EXMainServer.gameCtr.kaiGangEvent(owner);

		Global.logger.info("angang:"+Config.AN_GANG_SCORE);
		Global.logger.info("angang:"+EXScore.AN_KONG);
		room.addAllScore(owner, Config.AN_GANG_SCORE, EXScore.AN_KONG);

		room.gangnum = room.gangnum+1;
		owner.liangang++;
		owner.an_gang_num++;

		owner.settleLog.add(Config.SETTLE_AN_KONG);




	}

	@Override
	public void toNextState(EXPlayer owner) {
		owner.drawCard = 0;
	//	owner.stateMachine.changeState(Global.getState(EXPlayerDiscardState.class));
		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("PRSelfKongState:"+discard2);


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