package extend.mj.player.rule;

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

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;

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

	@Override
	public boolean condition(EXPlayer player) {
		if(player.autoOutCard)return false;
		
		if (player.getRoom().activeHaidi) {
			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 (num >= 4) {
				ITArray opcard = TArray.newInstance();
				opcard.addInt(card);
				Tip tip = new Tip(card,opcard, RuleWeight.SELF_KONG,this, RuleWeight.TYPE_SELF_KONG);
				tip.group_type = RuleWeight.GROUO_KONG;
				player.tipMgr.addTip(tip);
				result = true;
			}
		}
		return result;
	}

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

	}
}
