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.EXPlayer;
import extend.mj.RuleWeight;
import extend.mj.player.rulestate.PRSelfKongState;
import extend.mj.tip.IRuleBase;
import extend.mj.tip.Tip;

import java.util.Map;
import java.util.Map.Entry;

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

	@Override
	public boolean condition(EXPlayer player) {

		Global.logger.info("RuleSelfKong");
		if (player.isEntrust()) {
			return  false;
		}
		Map<Integer, Integer> cardMap = Util.getCardNumMap(player.cardInhand);
		boolean result = false;

		for (Entry<Integer, Integer> entry : cardMap.entrySet()) {

			int card = entry.getKey();

			int num = entry.getValue();
			if (player.getRoom().isLaizi(card))
			{
				continue;
			}
			if (player.getRoom().isFanPai(card))
			{
				if (num >= 3)
				{
					ITArray opcard = TArray.newInstance();
					opcard.addInt(card);
					Tip tip = new Tip(card,opcard, RuleWeight.SELFKONG,this, RuleWeight.TYPE_SELF_KONG);
					player.tipMgr.addTip(tip);
					result = true;

				}
			}
			else {
				if (num >= 4) {
					ITArray opcard = TArray.newInstance();
					opcard.addInt(card);
					Tip tip = new Tip(card,opcard, RuleWeight.SELFKONG,this, RuleWeight.TYPE_SELF_KONG);
					player.tipMgr.addTip(tip);
					result = true;

				}
			}
		}
		return result;
	}

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

	}
}
