package extend.mj.player.rule;

import com.game.Global;
import com.game.Util;
import com.taurus.core.entity.ITArray;
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.PRPongState;
import extend.mj.tip.IRuleBase;
import extend.mj.tip.Tip;

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

	@Override
	public boolean condition(EXPlayer player) {
		EXRoom room = player.getRoom();
		int eventCard = room.activeCard;
		if (player.isEntrust()) {
			return false;
		}

		if (player.getRoom().config.getBoolean(Config.ROOM_CONFIG_GUO_PENG))
		{
			if (player.notPongList.contains(eventCard))
			{
				return false;
			}
		}

		if (eventCard % 100 == 4)
		{
			return false;
		}

		if (player.is_gang)
		{
			return false;
		}

		EXPlayer activePlayer = (EXPlayer)room.playerMapBySeat.get(room.activeSeat);
		if (activePlayer.gangshangpao)
		{
			return false;
		}

		if (Util.checkCard(eventCard, player.cardInhand, 2)) {

			ITArray opcard = TArray.newInstance();
			opcard.addInt(eventCard);
			Tip tip = new Tip(eventCard, opcard, RuleWeight.PONG, this, RuleWeight.TYPE_PONG);
			player.tipMgr.addTip(tip);

			if (player.getRoom().config.getBoolean(Config.ROOM_CONFIG_GUO_PENG))
			{
				player.notPongList.add(eventCard);
			}
			return true;
		}
		else if (Util.checkCard(eventCard, player.cardInhand, 1) && Util.checkCard(eventCard /100 * 100 + 4, player.cardInhand, 1))
		{
			ITArray opcard = TArray.newInstance();
			opcard.addInt(eventCard);
			opcard.addInt(eventCard /100 * 100 + 4);
			Tip tip = new Tip(eventCard, opcard, RuleWeight.PONG, this, RuleWeight.TYPE_PONG);
			player.tipMgr.addTip(tip);

			if (player.getRoom().config.getBoolean(Config.ROOM_CONFIG_GUO_PENG))
			{
				player.notPongList.add(eventCard);
			}
			return true;
		}
		return false;
	}

	@Override
	public void action(EXPlayer player, Tip tip) {
		if (player.getRoom().config.getBoolean(Config.ROOM_CONFIG_GUO_PENG))
		{
			Util.removeCard(player.notPongList, tip.card, 4);
		}

		player.stateMachine.changeState(Global.getState(PRPongState.class));

	}

}
