package extend.mj.uitl;

import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Random;

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

import extend.mj.OpCard;
import extend.mj.WinCardType;

public class CardUtil {

	static public OpCard findOpcard(List<OpCard> opcards, int card,int type) {
		for (OpCard oc : opcards) {
			if(oc.type == type) {
				if (card == oc.card) {
					return oc;
				}
			}
		}
		return null;
	}
	

	final static Random random	= new Random();
	static {
		random.setSeed(System.currentTimeMillis());
	}
	static public int randomDiceNum() {
		int result = random.nextInt(5);
		return result + 1;
	}

	static public ITArray toMPData_WinMap(Map<Integer, WinCardType> map) {
		return toMPData_WinMap(map,false);
	}
	
	static public ITArray toMPData_WinMap(Map<Integer, WinCardType> map,boolean is_opcard) {
		if (map != null && map.size() > 0) {
			ITArray array = TArray.newInstance();
			for (Entry<Integer, WinCardType> entry : map.entrySet()) {
				WinCardType wct = entry.getValue();
				array.addTObject(wct.toTObject(is_opcard));
			}
			return array;
		}
		return null;
	}
}
