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.RuleWeight;
import extend.zp.player.rulestate.PRDrawPongState;
import extend.zp.tip.IRuleBase;
import extend.zp.tip.Tip;
import extend.zp.uitl.CardUtil;


public class RuleDrawPong implements IRuleBase {
	@Override
	public boolean condition(EXPlayer player) {
		if (player.cardInhand.size() <= 2) {
			return false;
		}
		EXPlayer activePlayer = (EXPlayer) player.room.playerMapBySeat.get(player.room.activeSeat);
		if (player.seat == activePlayer.seat) {
			return false;
		}
		int eventCard = activePlayer.drawCard;
		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(PRDrawPongState.class));
	}
}
