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.EXRoom;
import extend.mj.RuleWeight;
import extend.mj.player.rulestate.PROtherWinState;
import extend.mj.tip.IRuleBase;
import extend.mj.tip.Tip;
import extend.mj.uitl.WinCard;

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

	@Override
	public boolean condition(EXPlayer player) {
		if(!player.forceCheckWin&&player.louhu)return false;
		EXRoom room = player.getRoom();
		ITObject config = room.config;
		boolean hz_hu = config.getBoolean(Config.ROOM_CONFIG_HZ_HU);
		/*if (!player.forceCheckWin&&!config.getBoolean(Config.ROOM_CONFIG_DIANPAO)&&!hz_hu) {
			return false;
		}*/
		if (!player.forceCheckWin&&!config.getBoolean(Config.ROOM_CONFIG_DIANPAOHU)){
			return false;
		}
		boolean qidui = config.getBoolean(Config.ROOM_CONFIG_QIDUI);

		int activieCard = room.activeCard;
		boolean laizi = room.config.getBoolean(Config.ROOM_CONFIG_HONGZHONG);
		WinCard win = new WinCard(player.cardInhand, room.activeCard, Config.HONGZHONG, laizi,qidui);
		if(hz_hu&&win.zhong_count >0) {
			return false;
		}
		if (win.checkQidui() || win.tryWin(room)) {
			ITArray opcard = TArray.newInstance();
			opcard.addInt(activieCard);
			Tip tip = new Tip(room.activeCard,opcard, RuleWeight.WIN,this, RuleWeight.TYPE_WIN);
			tip.winType = player.forceCheckWin? 1 :0;
			player.tipMgr.addTip(tip);
			return true;
		}
		
		return false;
	}

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

}
