package extend.mj.player.rule;

import com.game.Global;
import com.taurus.core.entity.ITArray;
import com.taurus.core.entity.TArray;

import extend.mj.EXPlayer;
import extend.mj.RuleWeight;
import extend.mj.player.rulestate.PRPongKongState;
import extend.mj.tip.IRuleBase;
import extend.mj.tip.Tip;

/**
 * ���ܼ��
 * 
 *
 * 2017��8��30��
 * RulePongKong.java
 */
public class RulePongKong implements IRuleBase {

	@Override
	public boolean condition(EXPlayer player) {
		boolean result = false;
		if (player.isEntrust()) {
			return  false;
		}
		for (int card : player.cardInhand) {
			if(!player.notPongKongList.contains(card)) {
				result = conditionCard(player, card) || result;
			}
		}
		return result;

	}

	public boolean conditionCard(EXPlayer player, int card) {

		for (int[] cardGroup : player.pongGroup) {
			if (card == cardGroup[0]) {
				ITArray opcard = TArray.newInstance();
				opcard.addInt(card);
				Tip tip = new Tip(card,opcard, RuleWeight.KONG,this, RuleWeight.TYPE_PONG_KONG);
				player.tipMgr.addTip(tip);
				return true;
			}
		}
		return false;

	}

	@Override
	public void action(EXPlayer player,Tip tip) {
		// TODO Auto-generated method stub
		player.stateMachine.changeState(Global.getState(PRPongKongState.class));

	}

}
