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.PRDrawPaoState;
import extend.zp.player.rulestate.PRWinState;
import extend.zp.tip.IRuleBase;
import extend.zp.tip.Tip;
import extend.zp.uitl.Paixing;


public class RuleWin implements IRuleBase {
	@Override
	public boolean condition(EXPlayer player) {
		////System.out.println("RuleWin");
		if (player.isLaoYe) {

			return false;
		}


		EXPlayer activePlayer = (EXPlayer) player.room.playerMapBySeat.get(player.room.activeSeat);

		if (player.getRoom().roomoutcardlist.size()==0&&player.seat!=activePlayer.seat){
			return false;
		}
		if (activePlayer == null) {
			return false;
		}


		if (Paixing.checkWin(player, activePlayer.drawCard)) {
			player.guohupao = true;
			ITArray opcard = TArray.newInstance();
			opcard.addInt(activePlayer.drawCard);
			int weight = RuleWeight.WIN3;
			if (activePlayer.seat != player.seat) {
				if (player.seat == activePlayer.nextSeat) {
					weight = RuleWeight.WIN2;
				} else {
					weight = RuleWeight.WIN1;
				}
			}
			Tip tip = new Tip(activePlayer.drawCard, opcard, weight, this, RuleWeight.TYPE_WIN);
			player.tipMgr.addTip(tip);
			player.getRoom().winSeat = activePlayer.seat;
			player.hupai_count = player.hupai_count + 1;

			player.winCard = activePlayer.drawCard;
			return true;
		}

		return false;
	}

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