package extend.zp.player.rulestate;

import com.game.Global;
import com.game.data.Player;
import com.game.player.state.PlayerWaitState;
import com.game.state.StateBase;
import com.taurus.core.entity.ITArray;
import com.taurus.core.entity.TArray;

import com.taurus.core.util.Logger;
import com.taurus.permanent.TPServer;
import extend.zp.EXMainServer;
import extend.zp.EXPlayer;
import extend.zp.OpCard;
import extend.zp.PlayerRuleManager;
import extend.zp.RuleWeight;
import extend.zp.player.state.EXPlayerDiscardState;
import extend.zp.room.state.EXRoomSetpState;
import extend.zp.uitl.Paixing;

import java.util.Map;
import java.util.concurrent.TimeUnit;

/**
 * ��Ӧ���ƴ���״̬
 * 
 * 
 *
 *         2017��8��30�� PRPongState.java
 */
public class PRWeiState extends StateBase<EXPlayer> {
	Logger logger = Logger.getLogger(getClass());

	@Override
	public void enter(EXPlayer owner) {
		// TODO Auto-generated method stub
		int card = owner.opCard.getInt(0);
		int[] weiGroup = new int[3];
		weiGroup[0] = card;
		weiGroup[1] = card;
		weiGroup[2] = card;


		owner.weiGroup.add(weiGroup);
		int type = owner.chouPongSet.contains(card) ? RuleWeight.TYPE_CHOUWEI : RuleWeight.TYPE_WEI;
		if (type==RuleWeight.TYPE_WEI){
			owner.getRoom().weiRoomGroup.add(weiGroup);
		}

		owner.opCardList.add(new OpCard(type, card, card, card, Paixing.caclHuxi(type, card)));

		ITArray opcard = TArray.newInstance();
		opcard.addInt(card);
		opcard.addInt(card);

		EXMainServer.gameCtr.actionCard(owner, card, card, type, owner.seat, opcard);
		EXMainServer.playerRuleMgr.condition(PlayerRuleManager.HU_RULE, owner);
	}

	@Override
	public void toNextState(EXPlayer owner) {
		owner.isTingHu = false;
		////System.out.println("ok1");
		if (owner.getRoom().card.getCount() == 0) {
			owner.getRoom().liuju = true;
			owner.getRoom().liujuNum++;
			owner.getRoom().endGame();
			return;
		}
		////System.out.println("ok2");
		//if (owner.tiCount > 1) {
		//	owner.tiCount--;
		//	owner.stateMachine.changeState(Global.getState(PlayerWaitState.class));
		//	owner.room.stateMachine.changeState(Global.getState(EXRoomSetpState.class));
		owner.stateMachine.changeState(Global.getState(EXPlayerDiscardState.class));
		//} else {
			//timer(owner);
		//}
	}

	@Override
	public void exit(EXPlayer owner) {
		// TODO Auto-generated method stub

	}

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

	}
}
