package extend.zp.player.rule;

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

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

import extend.zp.EXMainServer;
import extend.zp.EXPlayer;
import extend.zp.OpCard;
import extend.zp.RuleWeight;
import extend.zp.tip.IRuleBase;
import extend.zp.uitl.CardUtil;
import extend.zp.uitl.Paixing;


public class RuleDealTi implements IRuleBase {
	@Override
	public boolean condition(EXPlayer player) {
		
		Map<Integer, Integer> cardMap = CardUtil.getCardNumMap(player.cardInhand);
		for (Entry<Integer, Integer> entry : cardMap.entrySet()) {
			
			int card = entry.getKey();
			int num = entry.getValue();
			
			// 如果抓的牌  手中刚好有三张
			if (card == player.drawCard && num == 3) {
				
				player.winCard = player.drawCard;
				player.drawCard = 0;
				player.tiCount++;

				ITArray opcard = TArray.newInstance();
				opcard.addInt(card);
				opcard.addInt(card);
				opcard.addInt(card);
				CardUtil.removeCard(player.cardInhand, card, num);

				int[] tiGroup = new int[4];
				tiGroup[0] = card;
				tiGroup[1] = card;
				tiGroup[2] = card;
				tiGroup[3] = card;

				player.tiGroup.add(tiGroup);
				player.opCardList.add(new OpCard(RuleWeight.TYPE_TI, card, card, card, Paixing.caclHuxi(RuleWeight.TYPE_TI, card)));

				EXMainServer.gameCtr.actionCard(player, card, card, RuleWeight.TYPE_TI, player.seat, opcard);
			}
			
			
			if (num == 4) {
				player.tiCount++;

				ITArray opcard = TArray.newInstance();
				opcard.addInt(card);
				opcard.addInt(card);
				opcard.addInt(card);
				opcard.addInt(card);
				CardUtil.removeCard(player.cardInhand, card, num);

				int[] tiGroup = new int[4];
				tiGroup[0] = card;
				tiGroup[1] = card;
				tiGroup[2] = card;
				tiGroup[3] = card;

				player.tiGroup.add(tiGroup);
				player.opCardList.add(new OpCard(RuleWeight.TYPE_TI, card, card, card, Paixing.caclHuxi(RuleWeight.TYPE_TI, card)));
				EXMainServer.gameCtr.actionCard(player, card, card, RuleWeight.TYPE_TI, player.seat, opcard);
			}
		}
		return false;
	}

	@Override
	public void action(EXPlayer player) {
		
	}
}
