package extend.zp.player.rule;

import com.game.Global;
import com.game.Util;
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.PRPongState;
import extend.zp.tip.IRuleBase;
import extend.zp.tip.Tip;

/**
 * �����
 * 
 */
public class RulePong implements IRuleBase {

	@Override
	public boolean condition(EXPlayer player) {
		// �й�Ĭ�ϲ����
		if (player.isEntrust() || player.siShou) return false;
		EXRoom room = player.getRoom();
		if(player.cardInhand.size()<=2) {
			return false;
		}
		
		int card = room.showCard;
		if(player.chouList.contains(card))return false;
		
		boolean result = false;
		result = check(player,card);
		
		return result;
	}
	
	private boolean check(EXPlayer player,int card){
		if (Util.cardNum(card, player.cardInhand) >= 2) {
			ITArray opcard = TArray.newInstance();
			opcard.addInt(card);
			opcard.addInt(card);
			
			Tip tip = new Tip(card,opcard, RuleWeight.PONG,this, RuleWeight.TYPE_PONG);
			tip.group_type = RuleWeight.GROUO_PONG;
			player.tipMgr.addTip(tip);
			return true;
		}
		return false;
	}

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

}
