package extend.mj.player.rule;

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

import extend.mj.Config;
import extend.mj.EXPlayer;
import extend.mj.RuleWeight;
import extend.mj.player.rulestate.PRSelfWinState;
import extend.mj.tip.IRuleBase;
import extend.mj.tip.Tip;
import extend.mj.uitl.WinCard;

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

	@Override
	public boolean condition(EXPlayer player) {
		// TODO Auto-generated method stub
		ITObject config = player.room.config;
		boolean qidui = config.getBoolean(Config.ROOM_CONFIG_QIDUI);
		boolean laizi = config.getBoolean(Config.ROOM_CONFIG_HONGZHONG);
		WinCard win = new WinCard(player.cardInhand, Config.HONGZHONG, laizi,qidui);
		if (win.checkQidui() || win.tryWin(player.getRoom())) {
			ITArray opcard = TArray.newInstance();
			opcard.addInt(player.drawCard);
			Tip tip = new Tip(player.drawCard,opcard, RuleWeight.SELF_WIN,this, RuleWeight.TYPE_WIN);
			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(PRSelfWinState.class));

	}

}
