package extend.zp.player.rule;

import com.game.Global;
import com.taurus.core.entity.ITArray;
import com.taurus.core.entity.TArray;

import com.taurus.core.util.Logger;
import extend.zp.EXPlayer;
import extend.zp.RuleWeight;
import extend.zp.player.rulestate.PRLiuState;
import extend.zp.tip.IRuleBase;
import extend.zp.tip.Tip;
import extend.zp.uitl.CardUtil;

import java.util.Map;


public class RuleLiu implements IRuleBase {
	Logger logger = Logger.getLogger(getClass());

	@Override
	public boolean condition(EXPlayer player) {
		if (player.isDeadPut)
		{
			return false;
		}
		int eventCard = player.drawCard;
		logger.info("jefe RuleLiu " +eventCard);
		Map<Integer, Integer> cardMap = CardUtil.getCardNumMap(player.cardInhand);
		for (Map.Entry<Integer, Integer> entry : cardMap.entrySet()) {
			// 如果抓的牌  手中刚好有三张
			int card = entry.getKey();
			int num = entry.getValue();
			if (card == player.drawCard && num == 3) {
				ITArray opcard = TArray.newInstance();
				opcard.addInt(eventCard);
				opcard.addInt(eventCard);
				opcard.addInt(eventCard);
				Tip tip = new Tip(eventCard, opcard, RuleWeight.TI, this, RuleWeight.TYPE_TI);
				player.tipMgr.addTip(tip);
				return true;
			}
		}
		for (int i = 0; i < player.weiGroup.size(); i++) {
			if (eventCard == player.weiGroup.get(i)[0]) {
				ITArray opcard = TArray.newInstance();
				opcard.addInt(eventCard);
				opcard.addInt(eventCard);
				opcard.addInt(eventCard);
				Tip tip = new Tip(eventCard, opcard, RuleWeight.TI, this, RuleWeight.TYPE_TI);
				player.tipMgr.addTip(tip);
				return true;
			}
		}

		logger.info("jefe RuleLiu end" );
		return false;
	}

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