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.EXRoom;
import extend.mj.OpCard;
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) {

		if(player.autoOutCard)return false;
		EXRoom room = player.getRoom();
		if (room.activeHaidi) {
			return false;
		}
		
		boolean result = false;
		for (int card : player.cardInhand) {
			result = check(player, card) || result;
		}
		
		return result;
	}

	private boolean check(EXPlayer player, int card) {
		for (OpCard opc : player.opCardList) {
			if (opc.type == RuleWeight.TYPE_PONG && card == opc.card) {
				ITArray opcard = TArray.newInstance();
				opcard.addInt(card);
				Tip tip = new Tip(card,opcard, RuleWeight.SELF_KONG,this, RuleWeight.TYPE_PONG_KONG);
				tip.group_type = RuleWeight.GROUO_KONG;
				player.tipMgr.addTip(tip);
				return true;
			}
		}
		return false;
	}

	@Override
	public void action(EXPlayer player,Tip tip) {
		player.stateMachine.changeState(Global.getState(PRPongKongState.class));

	}

}
