package extend.zp.player.rule;

import com.game.Global;
import com.game.Util;
import com.game.data.Player;
import com.taurus.core.entity.ITArray;
import com.taurus.core.entity.TArray;
import extend.zp.*;
import extend.zp.player.rulestate.PRWinState;
import extend.zp.tip.IRuleBase;
import extend.zp.tip.Tip;
import extend.zp.uitl.CardUtil;
import extend.zp.uitl.Paixing;
import extend.zp.uitl.WinCardNew;

import java.util.Map;


public class RuleDrawWin implements IRuleBase {
	@Override
	public boolean condition(EXPlayer player) {
		if (player.isLaoYe) {
			return false;
		}
		EXRoom room = player.getRoom();
		////System.out.println("RuleDrawWin:");
		EXPlayer activePlayer = (EXPlayer) player.room.playerMapBySeat.get(player.room.activeSeat);
		if (activePlayer == null) {
			return false;
		}
		int	eventCard = room.activeCard;
		activePlayer.drawCard = eventCard;

		if (Paixing.checkWin(player, eventCard)) {


			ITArray opcard = TArray.newInstance();
			opcard.addInt(eventCard);
			int weight = RuleWeight.WINPAO;
			player.winCard = eventCard;


			Tip tip = new Tip(room.drawCard, opcard, weight, this, RuleWeight.TYPE_WIN);
			player.tipMgr.addTip(tip);
			player.getRoom().winSeat = activePlayer.seat;
			player.getRoom().isFanPao = true;
			for (Map.Entry<Integer, Player> entry : player.getRoom().playerMapById.entrySet()) {
				EXPlayer rplayer = (EXPlayer) entry.getValue();
				if (rplayer.playerid!=player.playerid){
					rplayer.dianpao_count = rplayer.dianpao_count +1;
				}
			}
			return true;
		}

		return false;
	}

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