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;

/**
 * ��Ӧ���ܴ���״̬
 * 
 *
 * 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);
		int [] kongGroup = new int [4];
		if (opCard.size() >= 2)
		{
			Util.removeCard(owner.cardInhand, card, 3);
			Util.removeCard(owner.cardInhand, card/100*100+4, 1);
			kongGroup[0] = card;
			kongGroup[1] = card;
			kongGroup[2] = card;
			kongGroup[3] = card/100*100+4;
			owner.selfKongGroup.add(kongGroup);
			if (owner.is_gang)
			{
				OpCard pongCard = new OpCard(RuleWeight.TYPE_SELF_KONG, card);
				pongCard.opCard = new TArray();
				pongCard.opCard.addInt(card);
				pongCard.opCard.addInt(card);
				pongCard.opCard.addInt(card);
				pongCard.opCard.addInt(card/100*100+4);
				owner.opCardList.add(pongCard);
				owner.gangshangpao = true;
			}
			else {
				OpCard pongCard = new OpCard(RuleWeight.TYPE_SELF_ZHAO, card);
				pongCard.opCard = new TArray();
				pongCard.opCard.addInt(card);
				pongCard.opCard.addInt(card);
				pongCard.opCard.addInt(card);
				pongCard.opCard.addInt(card/100*100+4);
				owner.opCardList.add(pongCard);
			}


			ITArray opcard = TArray.newInstance();
			opcard.addInt(card);
			opcard.addInt(card);
			opcard.addInt(card);
			opcard.addInt(card/100*100+4);
			if (owner.is_gang)
			{
				EXMainServer.gameCtr.actionCard(owner, card, RuleWeight.TYPE_SELF_KONG, owner.seat,opcard);
			}
			else {
				EXMainServer.gameCtr.actionCard(owner, card, RuleWeight.TYPE_SELF_ZHAO, owner.seat,opcard);
			}
		}
		else {
			Util.removeCard(owner.cardInhand, card, 4);
			kongGroup[0] = card;
			kongGroup[1] = card;
			kongGroup[2] = card;
			kongGroup[3] = card;
			owner.selfKongGroup.add(kongGroup);
			if (owner.is_gang)
			{
				OpCard pongCard = new OpCard(RuleWeight.TYPE_SELF_KONG, card);
				pongCard.opCard = new TArray();
				pongCard.opCard.addInt(card);
				pongCard.opCard.addInt(card);
				pongCard.opCard.addInt(card);
				pongCard.opCard.addInt(card);
				owner.opCardList.add(pongCard);
				owner.gangshangpao = true;
			}
			else {
				OpCard pongCard = new OpCard(RuleWeight.TYPE_SELF_ZHAO, card);
				pongCard.opCard = new TArray();
				pongCard.opCard.addInt(card);
				pongCard.opCard.addInt(card);
				pongCard.opCard.addInt(card);
				pongCard.opCard.addInt(card);
				owner.opCardList.add(pongCard);
			}

			ITArray opcard = TArray.newInstance();
			opcard.addInt(card);
			opcard.addInt(card);
			opcard.addInt(card);
			opcard.addInt(card);
			if (owner.is_gang)
			{
				EXMainServer.gameCtr.actionCard(owner, card, RuleWeight.TYPE_SELF_KONG, owner.seat,opcard);
			}
			else {
				EXMainServer.gameCtr.actionCard(owner, card, RuleWeight.TYPE_SELF_ZHAO, owner.seat,opcard);
			}
		}


		//room.addAllScore(owner, Config.AN_GANG_SCORE, EXScore.KONG);
		owner.an_gang_num++;
		owner.stateMachine.changeState(Global.getState(EXPlayerKongDrawState.class));
		owner.settleLog.add(Config.SETTLE_AN_KONG);
	}
}
