package extend.zp.player.rule;

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

import extend.zp.EXPlayer;
import extend.zp.EXRoom;
import extend.zp.RuleWeight;
import extend.zp.player.rulestate.PRCheck;
import extend.zp.player.rulestate.PRPongState;
import extend.zp.tip.IRuleBase;
import extend.zp.tip.Tip;
import extend.zp.uitl.CardUtil;


public class RulePong implements IRuleBase {
	@Override
	public boolean condition(EXPlayer player) {
		//System.outln("碰");
		//判断是否可以偎
		////System.out.println("RulePong");
		boolean c =  PRCheck.check(player);
		if (!c){
			return false;
		}

		if (player.cardInhand.size() <= 2) {
			return false;
		}
		EXRoom room = player.getRoom();
		int eventCard = room.activeCard;
		if (eventCard == 0) {
			return false;
		}
		if (player.isEntrust()) {
			player.chouPongSet.add(eventCard);
			return false;
		}
		// ����
		if (player.chouPongSet.contains(eventCard)) {
			return false;
		}
		if (CardUtil.cardNum(eventCard, player.outcardExList) != 0) {
			return false;
		}
		if (CardUtil.cardNum(eventCard, player.cardInhand) >= 2) {
			ITArray opcard = TArray.newInstance();
			opcard.addInt(eventCard);
			opcard.addInt(eventCard);
			Tip tip = new Tip(eventCard, opcard, RuleWeight.PONG, this, RuleWeight.TYPE_PONG);
			player.tipMgr.addTip(tip);
			return true;
		}
		return false;
	}

	@Override
	public void action(EXPlayer player) {
		player.stateMachine.changeState(Global.getState(PRPongState.class));
	}
}
