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.EXPlayerDiscardState;
import extend.mj.player.state.EXPlayerDrawState;
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();
		owner.is_fang_jian_gang = false;
		ITArray opCard = owner.opCard;
		int card = opCard.getInt(0);
		if (owner.getRoom().isFanPai(card))
		{
			Util.removeCard(owner.cardInhand, card, 3);
			int [] kongGroup = new int [4];
			kongGroup[0] = card;
			kongGroup[1] = card;
			kongGroup[2] = card;
			owner.selfKongGroup.add(kongGroup);
			owner.opCardList.add(new OpCard(RuleWeight.TYPE_SELF_KONG, card, owner.seat, kongGroup));
			owner.gangshangpao = false;

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

			room.addAllScore(owner, Config.AN_GANG_SCORE, EXScore.KONG);
			owner.an_gang_num++;
			owner.settleLog.add(Config.SETTLE_AN_KONG);

			if(!EXMainServer.playerRuleMgr.condition(PlayerRuleManager.CHOW_PONG_DISCARD_RULE, owner,false)){
				toNextState(owner);
			}
		}
		else {
			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);

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

	@Override
	public void toNextState(EXPlayer owner) {
		owner.drawCard = 0;
		owner.stateMachine.changeState(Global.getState(EXPlayerDiscardState.class));
	}
}
