package extend.zp;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;

import com.game.Global;
import com.game.Util;
import com.game.data.Player;
import com.game.data.Room;
import com.game.player.state.PlayerWaitState;
import com.taurus.core.entity.ITArray;
import com.taurus.core.entity.ITObject;
import com.taurus.core.entity.TArray;
import com.taurus.core.entity.TObject;

import extend.zp.player.state.EXPlayerDisCardTipState;
import extend.zp.tip.Action;
import extend.zp.tip.TipManager;
import extend.zp.uitl.CardUtil;

public class EXRoom extends Room {

	//
	public Map<Integer, TipManager>	tipMap;
	public Action				curAction;

	public List<Action>				actionList;
	public RoomCard					card;

	public int						showCard;
	public int						currenDiscardSeat;
	public boolean					liuju		= false;
	

	public boolean					tianHu     = true;
	public ITArray					throwList;
	public int lastPaoSeat;
	public int draw = -1;
	public boolean isAllPass = false;
	public int douLiuZi = 0;


	public EXRoom(String roomid, Map<String, String> redis_room_map) {
		super(roomid, redis_room_map);
		card = new RoomCard(this);

		this.actionList = new ArrayList<Action>();
		this.tipMap = new HashMap<Integer, TipManager>();
		this.throwList = TArray.newInstance();
		this.isEntrust=true;
	}


	/*public void addAction(Action action) {
		if (this.curAction ==null) {
			this.curAction = action;
		} else if (action.tip.weight > this.curAction.tip.weight) {
			this.curAction = action;
		} else if (action.tip.weight == this.curAction.tip.weight) {
			int pos = Util.getPos(this.activeSeat, action.player.seat,this.maxPlayers);
			int pos1 = Util.getPos(this.activeSeat, this.curAction.player.seat, this.maxPlayers);
			if (pos < pos1) {
				this.curAction = action;
			}
		}

		checkAction();
	}*/

	public void addAction(Action action) {
		if (this.actionList.size() == 0) {
			this.actionList.add(action);
		} else if (action.tip.weight > this.actionList.get(0).tip.weight) {
			this.actionList.clear();
			this.actionList.add(action);
		} else if (action.tip.weight == this.actionList.get(0).tip.weight) {
			this.actionList.add(action);
		}
		checkAction();
	}
	
	public void changePaiXing(int seat, ITObject params) {
		ITArray paixing = params.getTArray("card_list");
		if (paixing == null) {
			paixing = TArray.newInstance();
		}

		ITObject cmdData = TObject.newInstance();
		cmdData.putTArray("card_list", paixing);
		this.getPlayBack().addCommand("ChangePaiXing", seat, cmdData);
	}
	
	public void checkAction() {
		boolean isWeightest = this.isWeightestAction();
		if (!isWeightest) {
			return;
		}
		if (this.isAllPass()) {
			this.isAllPass = true;
			EXPlayer activePlayer = (EXPlayer)this.playerMapBySeat.get(this.activeSeat);
			activePlayer.stateMachine.toNextState();
		} else {
			for (Action action : this.actionList) {
				action.run();
			}
			this.actionList.clear();
		}
	}

	public boolean isAllPass() {
		return this.actionList.size() == 0 && this.tipMap.size() == 0;
	}

	public boolean isWeightestAction() {
		if (this.isAllPass()) {
			return true;
		}
		if (this.actionList.size() == 0) {
			return false;
		}
		Action curaction = this.actionList.get(0);
		for (Entry<Integer, TipManager> entry : this.tipMap.entrySet()) {
			TipManager tip = entry.getValue();
			if (curaction.player.seat == tip.owner.seat) {
				continue;
			}
			if (curaction.tip.weight <= tip.getWeightest()) {
				return false;
			}
		}
		for (Entry<Integer, Player> entry : this.playerMapById.entrySet()) {
			Player player = entry.getValue();
			if (curaction.player.seat == player.seat) {
				continue;
			}
			if (player.stateMachine.curState instanceof EXPlayerDisCardTipState) {
				player.stateMachine.changeState(Global.getState(PlayerWaitState.class));
			}
		}
		return true;
	}

	public ITObject getReloadInfo(Player player) {
		ITObject data = this.getReloadInfoEx(player);
		EXPlayer p = (EXPlayer) player;
		
		if(p.pxData !=null) {
			data.putTArray("hand_px_data", p.pxData);
		}
		data.putInt("show_card", this.showCard);
		data.putTArray("hand_card", Util.toTArray(p.cardInhand));
		data.putInt("left_card", card.getCount());
		data.putInt("score_pool", this.douLiuZi);
		
		ITArray paramArray = TArray.newInstance();
		for (int chiCard : p.suoCardList) {
			paramArray.addInt(chiCard);
		}
		data.putTArray("suoCard", paramArray);
		data.putTArray("tinglist", Util.toTArray(p.tingList));
		if (p.tingMap.size() > 0) {
			ITArray infoList = new TArray();
			for (Entry<Integer, List<Integer>> entry : p.tingMap.entrySet()) {
				ITObject obj = TObject.newInstance();
				obj.putInt("card", entry.getKey());
				obj.putTArray("ting_list", Util.toTArray(entry.getValue()));;
				infoList.addTObject(obj);
			}
			data.putTArray("ting", infoList);
		}
		data.putInt("curren_outcard_seat", currenDiscardSeat);
		
		return data;
	}

	public ITObject getReloadInfoEx(Player player) {
		ITObject data = new TObject();
		data.putInt("active_seat", this.activeSeat);
		data.putInt("banker_seat", this.bankerSeat);
		data.putBoolean("playing", this.isplaying);
		ITArray info_list = TArray.newInstance();
		for (Entry<Integer, Player> entry : this.playerMapBySeat.entrySet()) {
			info_list.addTObject(((EXPlayer)entry.getValue()).getReloadInfo(entry.getValue().seat == player.seat ? true : false));
		}
		data.putTArray("info_list", info_list);
		return data;
	}
	
	public void addScore(EXPlayer destPlayer, EXPlayer fromPlayer, int score, int type) {
		destPlayer.score.round_log.put(type, destPlayer.score.round_log.get(type) + score);
		fromPlayer.score.round_log.put(type, fromPlayer.score.round_log.get(type) - score);

		destPlayer.score.round_score += score;
		destPlayer.score.total_score += score;

		fromPlayer.score.round_score -= score;
		fromPlayer.score.total_score -= score;
	}
	
	public void addDouLiuZiScore(EXPlayer destPlayer, int score, int type) {
		destPlayer.score.round_log.put(type, (destPlayer.score.round_log.get(type) == null 
				? 0 : destPlayer.score.round_log.get(type)) - score);
		
		destPlayer.score.round_score -= score;
		destPlayer.score.total_score -= score;
		this.douLiuZi += score;
	}

	public void addAllScore(EXPlayer destPlayer, int socre, int type) {
		for (Entry<Integer, Player> entry : this.playerMapById.entrySet()) {
			if (entry.getKey().equals(destPlayer.playerid)) {
				continue;
			}
			EXPlayer fromPlayer = (EXPlayer) entry.getValue();
			this.addScore(destPlayer, fromPlayer, socre, type);
		}
	}
	
	private boolean checkBian3(List<OpCard> opCardList, int winCard) {
		for (OpCard opCard : opCardList) {
			if (opCard.type != RuleWeight.TYPE_CHOW) continue;
			List<Integer> list = new ArrayList<Integer>();
			list.add(opCard.card1);
			list.add(opCard.card2);
			list.add(opCard.card3);
			if ((winCard % 100 == 3 && Collections.max(list) == winCard) 
					|| (winCard % 100 == 8 && Collections.min(list) == winCard)) {
				return true;
			}else {
				if (Collections.min(list) + 1  == winCard) return true;
			}
		}
		return false;
	}
	
	public int caclSpecialScore(EXPlayer owner) {
		int huXi = 0;
		int wanFa = owner.getRoom().config.getInt(Config.ROOM_CONFIG_WANFA);
		for(int i = 0; i < owner.specialList.size(); i++) {
			if (owner.specialList.get(i) == 1) {
				int xi = wanFa == 3 ? (i == 6 ? 150 : 100) : (i == 6 ? 200 : 150); 
				huXi += xi;
				owner.winMtList.add(new MingTang(50+(i > 5 ? i + 1 : i), MingTang.ST_HUXI, xi));
			}
		}
		owner.winHuxi += huXi;
		if (owner.winType == 1) owner.paiZu();
		return huXi;
	}
	
	
	public int caclWin(EXPlayer owner,boolean zimo) {
		owner.winMtList.clear();
		int wanfa = owner.room.config.getInt(Config.ROOM_CONFIG_WANFA);
		int huxi = 0;
		boolean duizi = true, duiDaoHu = false, dandiao = false, haveXi = true, bianKan = false
				, geShanDaNiu = false;
		int shouXi = 0, zhuoXi = 0, hong_num = 0;
		for(OpCard opc : owner.opCardList) {
			zhuoXi += opc.huXi;
			switch(opc.type) {
				/*case RuleWeight.TYPE_PONG:
				case RuleWeight.TYPE_WEI:
					break;*/
				case RuleWeight.TYPE_CHOW:
					duizi = false;
					break;
			}
			if(opc.huXi <= 0) haveXi = false;
			if(CardUtil.checkHongCard(opc.card1))hong_num++;
			if(CardUtil.checkHongCard(opc.card2))hong_num++;
			if(CardUtil.checkHongCard(opc.card3))hong_num++;
		}
		int jiangCard = 0;
		for(OpCard cg : owner.handCard) {
			Set<Integer> set = new HashSet<Integer>();
			set.add(cg.card1);
			set.add(cg.card2);
			if (cg.card3 > 0) set.add(cg.card3);
			if (RuleWeight.TYPE_JIANG == cg.type) jiangCard = cg.card1;
			if(set.size() > 1)
				duizi = false;
			if(RuleWeight.TYPE_JIANG == cg.type && cg.card1 == owner.winCard)
				dandiao = true;
			if(cg.huXi <= 0) haveXi = false;
			shouXi += cg.huXi;
			if (RuleWeight.TYPE_CHOW == cg.type) duizi = false; 
			if (RuleWeight.TYPE_PONG == cg.type && set.contains(owner.winCard) || owner.kaWei) duiDaoHu = true;// ���ȵ����ͶԶԵ������ڱ߿���
			if(CardUtil.checkHongCard(cg.card1))hong_num++;
			if(CardUtil.checkHongCard(cg.card2))hong_num++;
			if(cg.card3 > 0 && CardUtil.checkHongCard(cg.card3))hong_num++;
		}
		boolean piaodui = false;
		if (duizi && hong_num == 3 && CardUtil.checkPiaoDui(owner.opCardList, owner.handCard))
			piaodui = true;
		if (duiDaoHu && Math.abs(jiangCard - owner.winCard) == 2) geShanDaNiu = true;
		int contains123 = 0;
		if (!duizi && !duiDaoHu && !dandiao) {
			bianKan = checkBian3(owner.handCard, owner.winCard);
		}
		int beishu = 0, jiaxi = 0;
		Global.logger.info("list card");
		Global.logger.info(owner.opCardList);
		Global.logger.info(owner.handCard);
		Set<Integer> tuanYuanSet = CardUtil.checkTuanYuan(owner.opCardList, owner.handCard);
		Global.logger.info(tuanYuanSet);
		List<Integer> yinList = new ArrayList<Integer>();
		for(int ty : tuanYuanSet) {
			if(CardUtil.checkHongCard(ty))
				yinList.add(ty);
		}
		if (owner.huXi == 2) {
			int hxi = wanfa == 3 ? 150 : 200;
			owner.winMtList.add(new MingTang(MingTang.TYPE_ERXIMANHUAYUAN, MingTang.ST_HUXI, wanfa == 3 ? 150 : 200));// ��Ϣ��԰��
			if (wanfa == 3) {
				if(zimo) {
					hxi += 20;
					owner.winMtList.add(new MingTang(MingTang.TYPE_ZIMO, MingTang.ST_HUXI, 20));
				}
				if(bianKan) {
					hxi += 20;
					owner.winMtList.add(new MingTang(MingTang.TYPE_LINGBIANKAN, MingTang.ST_HUXI, 20));
				}
				if(dandiao) {
					if(duizi) {
						hxi += 50;
						owner.winMtList.add(new MingTang(MingTang.TYPE_DANDIAO,MingTang.ST_HUXI,50));
					} else {
						hxi += 20;
						owner.winMtList.add(new MingTang(MingTang.TYPE_DANDIAO,MingTang.ST_HUXI,20));
					}
				}
				if(this.config.getBoolean(Config.ROOM_CONFIG_ZXS) && zimo && owner.winCard == 103) { // ׽С��
					hxi += 30;
					owner.winMtList.add(new MingTang(MingTang.TYPE_ZHUOXIAOSAN, MingTang.ST_HUXI, 30));
				}
			
				if (this.config.getBoolean(Config.ROOM_CONFIG_XLX) && CardUtil.checkXinLianXin(owner.opCardList, owner.handCard)) {
					hxi += 20;
					owner.winMtList.add(new MingTang(MingTang.TYPE_XINLIANXIN, MingTang.ST_HUXI, 20));
				}
			}else if (wanfa == 2) {
				if(zimo) { 
					hxi += 40;
					owner.winMtList.add(new MingTang(MingTang.TYPE_ZIMO, MingTang.ST_HUXI, 40));
				}
				if(bianKan) { 
					hxi += 30;
					owner.winMtList.add(new MingTang(MingTang.TYPE_LINGBIANKAN, MingTang.ST_HUXI, 30));
				}
				if(dandiao) {
					if(duizi) {
						hxi += 50;
						owner.winMtList.add(new MingTang(MingTang.TYPE_DANDIAO,MingTang.ST_HUXI,50));
					} else {
						hxi += 30;
						owner.winMtList.add(new MingTang(MingTang.TYPE_DANDIAO,MingTang.ST_HUXI,30));
					}
				}
				if(this.config.getBoolean(Config.ROOM_CONFIG_QQR) && owner.cardInhand.size() == 1) {// ȫ����
					hxi += 150;
					owner.winMtList.add(new MingTang(MingTang.TYPE_QUANQIUREN,MingTang.ST_HUXI,150));
				}
				if(this.config.getBoolean(Config.ROOM_CONFIG_ZXS) && zimo && owner.winCard == 103) { // ׽С��
					hxi += 100;
					owner.winMtList.add(new MingTang(MingTang.TYPE_ZHUOXIAOSAN, MingTang.ST_HUXI, 100));
				}
				if(this.card.getCount() == 0) { 
					hxi += 30;
					owner.winMtList.add(new MingTang(MingTang.TYPE_HAIDIHU,MingTang.ST_HUXI,30));
				}
			
				if (CardUtil.checkXinLianXin(owner.opCardList, owner.handCard)) {
					hxi += 30;
					owner.winMtList.add(new MingTang(MingTang.TYPE_XINLIANXIN, MingTang.ST_HUXI, 30));
				}
			}else if (wanfa == 1) {
				if(zimo) { 
					hxi += 40;
					owner.winMtList.add(new MingTang(MingTang.TYPE_ZIMO, MingTang.ST_HUXI, 40));
				}
				if(bianKan) {
					hxi += 40;
					owner.winMtList.add(new MingTang(MingTang.TYPE_LINGBIANKAN, MingTang.ST_HUXI, 40));
				}
				if(dandiao) {
					if(duizi) {
						hxi += 50;
						owner.winMtList.add(new MingTang(MingTang.TYPE_DANDIAO,MingTang.ST_HUXI,50));
					} else {
						hxi += 30;
						owner.winMtList.add(new MingTang(MingTang.TYPE_DANDIAO,MingTang.ST_HUXI,30));
					}
				}
				if(zimo && owner.winCard == 103) { 
					hxi += 100;
					owner.winMtList.add(new MingTang(MingTang.TYPE_ZHUOXIAOSAN, MingTang.ST_HUXI, 100));
				}
	
				if (CardUtil.checkXinLianXin(owner.opCardList, owner.handCard)) {
					hxi += 30;
					owner.winMtList.add(new MingTang(MingTang.TYPE_XINLIANXIN, MingTang.ST_HUXI, 30));
				}
				if(this.card.getCount() == 0) { 
					hxi += 50;
					owner.winMtList.add(new MingTang(MingTang.TYPE_HAIDIHU,MingTang.ST_HUXI,50));
				}
				if(owner.cardInhand.size() == 1) {
					hxi += 150;
					owner.winMtList.add(new MingTang(MingTang.TYPE_QUANQIUREN,MingTang.ST_HUXI,150));
				}
			}else if (wanfa == 4) { 
				if(zimo) { 
					hxi += 40;
					owner.winMtList.add(new MingTang(MingTang.TYPE_ZIMO, MingTang.ST_HUXI, 40));
				}
				if(bianKan) {
					hxi += 40;
					owner.winMtList.add(new MingTang(MingTang.TYPE_LINGBIANKAN, MingTang.ST_HUXI, 40));
				}
				if(dandiao) {
					if(duizi) {
						hxi += 50;
						owner.winMtList.add(new MingTang(MingTang.TYPE_DANDIAO,MingTang.ST_HUXI,50));
					} else {
						hxi += 30;
						owner.winMtList.add(new MingTang(MingTang.TYPE_DANDIAO,MingTang.ST_HUXI,30));
					}
				}
				if(this.card.getCount() == 0) {
					hxi += 50;
					owner.winMtList.add(new MingTang(MingTang.TYPE_HAIDIHU,MingTang.ST_HUXI,50));
				}
		
				if (CardUtil.checkXinLianXin(owner.opCardList, owner.handCard)) {
					hxi += 30;
					owner.winMtList.add(new MingTang(MingTang.TYPE_XINLIANXIN, MingTang.ST_HUXI, 30));
				}
				if(owner.cardInhand.size() == 1) {
					hxi += 150;
					owner.winMtList.add(new MingTang(MingTang.TYPE_QUANQIUREN,MingTang.ST_HUXI,150));
				}
				if(zimo && owner.winCard == 103) { 
					hxi += 100;
					owner.winMtList.add(new MingTang(MingTang.TYPE_ZHUOXIAOSAN, MingTang.ST_HUXI, 100));
				}
			}
			owner.winHuxi = hxi;
			return hxi;
		}
		if(wanfa == 0) {
			if(yinList.size() >= 1) {
				int xi = (yinList.size() * 10);
				owner.winMtList.add(new MingTang(MingTang.TYPE_YINHU, MingTang.ST_HUXI, xi));
				jiaxi += xi;	
			}
			if(hong_num >= 10) { 
				int xi = (hong_num - 9) * 10;
				if(xi > 10) {
					owner.winMtList.add(new MingTang(MingTang.TYPE_DUOHONGHU, MingTang.ST_HUXI, xi));
				} else { 
					owner.winMtList.add(new MingTang(MingTang.TYPE_HONGHU, MingTang.ST_HUXI, xi));
				}
				jiaxi += xi;
			}
			if(hong_num <= 0) {
				if(duizi) {
					beishu += 6;
					owner.winMtList.add(new MingTang(MingTang.TYPE_WUDUI, MingTang.ST_HUXI_TIMES, 6));
				}else {
					
					beishu += 4;
					owner.winMtList.add(new MingTang(MingTang.TYPE_WUHU, MingTang.ST_HUXI_TIMES, 4));
				}
			}
			if(hong_num > 0 && duizi) { 
				beishu += 4;
				owner.winMtList.add(new MingTang(MingTang.TYPE_DUIZIHU, MingTang.ST_HUXI_TIMES, 4));
			}
			if(hong_num == 1) {
				beishu += 3;
				owner.winMtList.add(new MingTang(MingTang.TYPE_YIDIANHONG, MingTang.ST_HUXI_TIMES, 3));
			}
			boolean huayuan = CardUtil.checkContainHong(owner.opCardList, owner.handCard);
			if(huayuan) { 
				jiaxi += 50;
				owner.winMtList.add(new MingTang(MingTang.TYPE_MANHUAYUAN,MingTang.ST_HUXI,50));
			}
			int se = CardUtil.checkQingyise(owner.opCardList, owner.handCard);
			if(se > 0) {
				jiaxi += 50;
				owner.winMtList.add(new MingTang(se==1?MingTang.TYPE_XIAOYISE:MingTang.TYPE_DAYISE,MingTang.ST_HUXI,50));
			}
			huxi = owner.huXi * (beishu > 0 ? beishu : 1) + jiaxi;
		/*===========================================================================================================*/
		} else if(wanfa == 1) {
			if(hong_num > 0 && duizi) {
				beishu += 10;
				owner.winMtList.add(new MingTang(MingTang.TYPE_DUIZIHU, MingTang.ST_HUXI_TIMES, 10));
			}
			if(hong_num <= 0) {
				if(duizi) {
					beishu += 15;
					owner.winMtList.add(new MingTang(MingTang.TYPE_WUDUI, MingTang.ST_HUXI_TIMES, 15));
				}else {
					
					beishu += 6;
					owner.winMtList.add(new MingTang(MingTang.TYPE_WUHU, MingTang.ST_HUXI_TIMES, 6));
				}
			}
		
			if (CardUtil.checkXinLianXin(owner.opCardList, owner.handCard)) {
				jiaxi += 30;
				owner.winMtList.add(new MingTang(MingTang.TYPE_XINLIANXIN, MingTang.ST_HUXI, 30));
			}
			if(hong_num == 1) {
				beishu += 4;
				owner.winMtList.add(new MingTang(MingTang.TYPE_YIDIANHONG, MingTang.ST_HUXI_TIMES, 4));
			}
			if(yinList.size() >= 1) {
				if(hong_num == yinList.size() * 4) {
					int xi = (yinList.size() * 150);
					owner.winMtList.add(new MingTang(MingTang.TYPE_CHUNYINHU, MingTang.ST_HUXI, xi));
					jiaxi += xi;
				}// else {
					int xi = (yinList.size() * 30);
					owner.winMtList.add(new MingTang(MingTang.TYPE_YINHU, MingTang.ST_HUXI, xi));
					jiaxi += xi;
				//}
			}
			if(hong_num >= 10) {
				int xi = (hong_num - 9) * 30;
				if(xi > 30) {
					owner.winMtList.add(new MingTang(MingTang.TYPE_DUOHONGHU, MingTang.ST_HUXI, xi));
				} else {
					owner.winMtList.add(new MingTang(MingTang.TYPE_HONGHU, MingTang.ST_HUXI, xi));
				}
				jiaxi += xi;
			}
			boolean huayuan = CardUtil.checkContainHong(owner.opCardList, owner.handCard);
			if(huayuan) {
				//按需求150改成120 05-20 mt
				jiaxi += 120;
				owner.winMtList.add(new MingTang(MingTang.TYPE_MANHUAYUAN,MingTang.ST_HUXI,120));
			}
			int se = CardUtil.checkQingyise(owner.opCardList, owner.handCard);
			if(se > 0) {
				//按需求200改成150 05-20 mt
				jiaxi += 150;
				owner.winMtList.add(new MingTang(se==1?MingTang.TYPE_XIAOYISE:MingTang.TYPE_DAYISE,MingTang.ST_HUXI,150));
			}
			if(zimo) {
				jiaxi += 40;
				owner.winMtList.add(new MingTang(MingTang.TYPE_ZIMO, MingTang.ST_HUXI, 40));
			}
			if (duiDaoHu) {
				jiaxi += 20;
				owner.winMtList.add(new MingTang(MingTang.TYPE_DUIDAOHU, MingTang.ST_HUXI, 20));
			}
			if (geShanDaNiu) { 
				jiaxi += 20;
				owner.winMtList.add(new MingTang(MingTang.TYPE_GSDN, MingTang.ST_HUXI, 20));
			}
			if(zimo && owner.winCard == 103) { 
				jiaxi += 100;
				owner.winMtList.add(new MingTang(MingTang.TYPE_ZHUOXIAOSAN, MingTang.ST_HUXI, 100));
			}
		
			if(tuanYuanSet.size() >= 2) {
				boolean result1 = false;
				boolean result2 = false;
				boolean result3 = false;
				boolean result4 = false;
				for(int ty : tuanYuanSet) {
					if(ty % 100 == 10) {
						if(tuanYuanSet.contains(ty - 9))
							result1 = true;
					} else {
						if(tuanYuanSet.contains(ty +1))
							result2 = true;
					}
					if(ty % 100 <= 8) {
						if(tuanYuanSet.contains(ty +1) && tuanYuanSet.contains(ty +2))
							result3 = true;
					}
					int type = ty / 100;
					if(type == 1 && tuanYuanSet.contains(ty + 100)) {
						result4 = true;
					}
					if(type == 2 && tuanYuanSet.contains(ty - 100)) {
						result4 = true;
					}
				}
				if(tuanYuanSet.size() == 2) {
					if(tuanYuanSet.contains(108) && tuanYuanSet.contains(208)) { // �����ͷ
						jiaxi += 300;
						owner.winMtList.add(new MingTang(MingTang.TYPE_ZHENBAPENGTOU,MingTang.ST_HUXI,300));
					}else if (result4) {
						jiaxi += 150;
						owner.winMtList.add(new MingTang(MingTang.TYPE_JIABAPENGTOU,MingTang.ST_HUXI,150));
					}else if (result1) {
						jiaxi += 150;
						owner.winMtList.add(new MingTang(MingTang.TYPE_LONGBAIWEI,MingTang.ST_HUXI,150));
					}else if (result2) {
						jiaxi += 80;
						owner.winMtList.add(new MingTang(MingTang.TYPE_JIEMEIZHUO,MingTang.ST_HUXI,80));
					}//else {
						jiaxi += 40;
						owner.winMtList.add(new MingTang(MingTang.TYPE_ZHUOHU,MingTang.ST_HUXI,40));
					//}
				} else if(tuanYuanSet.size() > 2) {
					if (tuanYuanSet.contains(108) && tuanYuanSet.contains(208)) { // �����ͷ
						jiaxi += 300;
						owner.winMtList.add(new MingTang(MingTang.TYPE_ZHENBAPENGTOU,MingTang.ST_HUXI,300));
					}
					if (result4) { 
						jiaxi += 150;
						owner.winMtList.add(new MingTang(MingTang.TYPE_JIABAPENGTOU,MingTang.ST_HUXI,150));
					}
					if (result1) { 
						jiaxi += 150;
						owner.winMtList.add(new MingTang(MingTang.TYPE_LONGBAIWEI,MingTang.ST_HUXI,150));
					}
					if (result3) { 
						if(tuanYuanSet.size() == 4) { 
							jiaxi += 400;
							owner.winMtList.add(new MingTang(MingTang.TYPE_DIASUNZHUODAITUO,MingTang.ST_HUXI,400));
						}else {
							jiaxi += 300;
							owner.winMtList.add(new MingTang(MingTang.TYPE_DIASUNZHUO,MingTang.ST_HUXI,300));
						}
					}
					if (result2 &&!result3) {
						jiaxi += 150;
						owner.winMtList.add(new MingTang(MingTang.TYPE_JIEMEIZHUODAITUO,MingTang.ST_HUXI,150));
					}
					if (tuanYuanSet.size() == 3 && !result3 && !result2) {
						jiaxi += 100;
						owner.winMtList.add(new MingTang(MingTang.TYPE_SANLUANZHUO,MingTang.ST_HUXI,100));
					}else if (tuanYuanSet.size() == 4) {
						jiaxi += 300;
						owner.winMtList.add(new MingTang(MingTang.TYPE_SILUANZHUO,MingTang.ST_HUXI,300));
					}
				} 
			}
			if(this.card.getCount() == 0) { 
				jiaxi += 50;
				owner.winMtList.add(new MingTang(MingTang.TYPE_HAIDIHU,MingTang.ST_HUXI,50));
			}
			if(dandiao) { 
				if(duizi) {
					jiaxi += 50;
					owner.winMtList.add(new MingTang(MingTang.TYPE_DANDIAO,MingTang.ST_HUXI,50));
				} else {
					jiaxi += 30;
					owner.winMtList.add(new MingTang(MingTang.TYPE_DANDIAO,MingTang.ST_HUXI,30));
				}
			}
			int specialDuiDaoHu = 0 ;
			if(duiDaoHu) {
				specialDuiDaoHu = CardUtil.checkSpecialDuiDaoHu(owner.opCardList, owner.handCard, owner.winCard);
				if(specialDuiDaoHu == 1) {
					jiaxi += 50;
					owner.winMtList.add(new MingTang(MingTang.TYPE_BEIKAOBEI,MingTang.ST_HUXI,50));
				}else if (specialDuiDaoHu == 2) { 
					jiaxi += 50;
					owner.winMtList.add(new MingTang(MingTang.TYPE_SHOUQIANSHOU,MingTang.ST_HUXI,50));
				}
			}
			if(haveXi) { 
				jiaxi += 50;
				owner.winMtList.add(new MingTang(MingTang.TYPE_DINGDUI,MingTang.ST_HUXI,50));
			}
			if(owner.cardInhand.size() == 1) { 
				jiaxi += 150;
				owner.winMtList.add(new MingTang(MingTang.TYPE_QUANQIUREN,MingTang.ST_HUXI,150));
			}
			if(owner.huXi == 10 && owner.kaWei) { 
				jiaxi += 50;
				owner.winMtList.add(new MingTang(MingTang.TYPE_KAWEI,MingTang.ST_HUXI,50));
			}
			if(this.tianHu &&owner.seat == this.bankerSeat) {
				//按需求150改100 05-20 mt
				jiaxi += 100;
				owner.winMtList.add(new MingTang(MingTang.TYPE_TIANHU, MingTang.ST_HUXI, 100));
			}
			if(piaodui) {
				jiaxi += 50;
				owner.winMtList.add(new MingTang(MingTang.TYPE_PIAODUI, MingTang.ST_HUXI, 50));
			}
		
			if (dandiao && CardUtil.checkJiDing(owner.handCard, owner.winCard)) {
				jiaxi += 100;
				owner.winMtList.add(new MingTang(MingTang.TYPE_JIDING, MingTang.ST_HUXI, 100));
			}
			if(shouXi == zhuoXi && zhuoXi ==5) { 
				jiaxi += 50;
				owner.winMtList.add(new MingTang(MingTang.TYPE_SXWUQIANNIAN, MingTang.ST_HUXI, 50));
			}
			if(bianKan) { 
				jiaxi += 40;
				owner.winMtList.add(new MingTang(MingTang.TYPE_LINGBIANKAN, MingTang.ST_HUXI, 40));
			}
			if(specialDuiDaoHu == 3) {
				jiaxi += 100;
				owner.winMtList.add(new MingTang(MingTang.TYPE_ZHENBEIKAOBEI, MingTang.ST_HUXI, 100));
			}
			if(specialDuiDaoHu == 4) {
				jiaxi += 50;
				owner.winMtList.add(new MingTang(MingTang.TYPE_FENGPAIWEI, MingTang.ST_HUXI, 50));
			}
			if(owner.huXi == 10) { 
				//按需求50改30 05-20 mt
				jiaxi += 30;
				owner.winMtList.add(new MingTang(MingTang.TYPE_KAHU, MingTang.ST_HUXI, 30));
			}
			huxi = owner.huXi * (beishu > 0 ? beishu : 1) + jiaxi;
		/*===========================================================================================================*/
		} else if(wanfa == 2) {
			Global.logger.info("yinhu :"+yinList.size());
			if(yinList.size() >= 1) {
				if(hong_num == yinList.size() * 4) {
					int xi = (yinList.size() * 150);
					owner.winMtList.add(new MingTang(MingTang.TYPE_CHUNYINHU, MingTang.ST_HUXI, xi));
					jiaxi += xi;
				} //else {
					int xi = (yinList.size() * 30);
					owner.winMtList.add(new MingTang(MingTang.TYPE_YINHU, MingTang.ST_HUXI, xi));
					jiaxi += xi;
				//}
			}
			if (CardUtil.checkXinLianXin(owner.opCardList, owner.handCard)) {
				jiaxi += 30;
				owner.winMtList.add(new MingTang(MingTang.TYPE_XINLIANXIN, MingTang.ST_HUXI, 30));
			}
			if(bianKan) { 
				jiaxi += 30;
				owner.winMtList.add(new MingTang(MingTang.TYPE_LINGBIANKAN, MingTang.ST_HUXI, 30));
			}
			if (geShanDaNiu) {
				jiaxi += 20;
				owner.winMtList.add(new MingTang(MingTang.TYPE_GSDN, MingTang.ST_HUXI, 20));
			}
			if (duiDaoHu) {
				jiaxi += 20;
				owner.winMtList.add(new MingTang(MingTang.TYPE_DUIDAOHU, MingTang.ST_HUXI, 20));
			}
			if(owner.huXi == 10) { 
				jiaxi += 30;
				owner.winMtList.add(new MingTang(MingTang.TYPE_KAHU, MingTang.ST_HUXI, 30));
			}
			if(zimo) {
				jiaxi += 40;
				owner.winMtList.add(new MingTang(MingTang.TYPE_ZIMO, MingTang.ST_HUXI, 40));
			}
			if(hong_num >= 10) {
				//按需求20改30，05-20 mt
				int xi = (hong_num - 9) * 30;
				if(xi > 30) {
					owner.winMtList.add(new MingTang(MingTang.TYPE_DUOHONGHU, MingTang.ST_HUXI, xi));
				} else { 
					owner.winMtList.add(new MingTang(MingTang.TYPE_HONGHU, MingTang.ST_HUXI, xi));
				}
				jiaxi += xi;
			}
			if(hong_num > 0 && duizi) {
				//按需求8改10，05-20 mt
				beishu += 10;
				owner.winMtList.add(new MingTang(MingTang.TYPE_DUIZIHU, MingTang.ST_HUXI_TIMES, 10));
			}
			if(hong_num <= 0) {
				if(duizi) { 
					//按需求10改15，05-20 mt
					beishu += 15;
					owner.winMtList.add(new MingTang(MingTang.TYPE_WUDUI, MingTang.ST_HUXI_TIMES, 15));
				} else { 
					beishu += 6;
					owner.winMtList.add(new MingTang(MingTang.TYPE_WUHU, MingTang.ST_HUXI_TIMES, 6));
				}
			}
			if(hong_num == 1) {
				beishu += 4;
				owner.winMtList.add(new MingTang(MingTang.TYPE_YIDIANHONG, MingTang.ST_HUXI_TIMES, 4));
			}
			boolean huayuan = CardUtil.checkContainHong(owner.opCardList, owner.handCard);
			if(huayuan) { 
				//按需求200改120，05-20 mt 此处本来是150
				jiaxi += 120;
				owner.winMtList.add(new MingTang(MingTang.TYPE_MANHUAYUAN,MingTang.ST_HUXI,120));
			}
			int se = CardUtil.checkQingyise(owner.opCardList, owner.handCard);
			if(se > 0) { 
				//按需求200改150，05-20 mt
				jiaxi += 150;
				owner.winMtList.add(new MingTang(se==1?MingTang.TYPE_XIAOYISE:MingTang.TYPE_DAYISE,MingTang.ST_HUXI,150));
			}
			if(tuanYuanSet.size() >= 2) {
				boolean result1 = false;
				boolean result2 = false;
				boolean result3 = false;
				boolean result4 = false;
				for(int ty : tuanYuanSet) {
					if(ty % 100 == 10) {
						if(tuanYuanSet.contains(ty - 9))
							result1 = true;
					} else {
						if(tuanYuanSet.contains(ty +1))
							result2 = true;
					}
					if(ty % 100 <= 8) {
						if(tuanYuanSet.contains(ty +1) && tuanYuanSet.contains(ty +2))
							result3 = true;
					}
					int type = ty / 100;
					if(type == 1 && tuanYuanSet.contains(ty + 100)) {
						result4 = true;
					}
					if(type == 2 && tuanYuanSet.contains(ty - 100)) {
						result4 = true;
					}
				}
				if(tuanYuanSet.size() == 2) {
					if(tuanYuanSet.contains(108) && tuanYuanSet.contains(208)) { 
						jiaxi += 300;
						owner.winMtList.add(new MingTang(MingTang.TYPE_ZHENBAPENGTOU,MingTang.ST_HUXI,300));
					}else if (result4) {
						jiaxi += 150;
						owner.winMtList.add(new MingTang(MingTang.TYPE_JIABAPENGTOU,MingTang.ST_HUXI,150));
					}else if (this.config.getBoolean(Config.ROOM_CONFIG_LBW) &&  result1) {// ����β
						jiaxi += 150;
						owner.winMtList.add(new MingTang(MingTang.TYPE_LONGBAIWEI,MingTang.ST_HUXI,150));
					}else if (result2) {
						jiaxi += 80;
						owner.winMtList.add(new MingTang(MingTang.TYPE_JIEMEIZHUO,MingTang.ST_HUXI,80));
					}//else {
						jiaxi += 40;
						owner.winMtList.add(new MingTang(MingTang.TYPE_ZHUOHU,MingTang.ST_HUXI,40));
					//}
				} else if(tuanYuanSet.size() > 2) {
					if (tuanYuanSet.contains(108) && tuanYuanSet.contains(208)) {
						jiaxi += 300;
						owner.winMtList.add(new MingTang(MingTang.TYPE_ZHENBAPENGTOU,MingTang.ST_HUXI,300));
					}
					if (result4) {
						jiaxi += 150;
						owner.winMtList.add(new MingTang(MingTang.TYPE_JIABAPENGTOU,MingTang.ST_HUXI,150));
					}
					if (result1) { 
						jiaxi += 150;
						owner.winMtList.add(new MingTang(MingTang.TYPE_LONGBAIWEI,MingTang.ST_HUXI,150));
					}
					if (result3) { 
						if(tuanYuanSet.size() == 4) {
							jiaxi += 400;
							owner.winMtList.add(new MingTang(MingTang.TYPE_DIASUNZHUODAITUO,MingTang.ST_HUXI,400));
						}else {
							jiaxi += 300;
							owner.winMtList.add(new MingTang(MingTang.TYPE_DIASUNZHUO,MingTang.ST_HUXI,300));
						}
					}
					if (result2 && !result3) {
						//按需求120改成150 05-20 mt
						jiaxi += 150;
						owner.winMtList.add(new MingTang(MingTang.TYPE_JIEMEIZHUODAITUO,MingTang.ST_HUXI,150));
					}
					if (tuanYuanSet.size() == 3 && !result3 && !result2) {
						jiaxi += 100;
						owner.winMtList.add(new MingTang(MingTang.TYPE_SANLUANZHUO,MingTang.ST_HUXI,100));
					}else if (tuanYuanSet.size() == 4) {
						jiaxi += 300;
						owner.winMtList.add(new MingTang(MingTang.TYPE_SILUANZHUO,MingTang.ST_HUXI,300));
					}
				} 
			}
			if(this.card.getCount() == 0) { 
				//按需求30改成50 05-20 mt
				jiaxi += 50;
				owner.winMtList.add(new MingTang(MingTang.TYPE_HAIDIHU,MingTang.ST_HUXI,50));
			}
			if(dandiao) {
				if(duizi) {
					jiaxi += 50;
					owner.winMtList.add(new MingTang(MingTang.TYPE_DANDIAO,MingTang.ST_HUXI,50));
				} else {
					jiaxi += 30;
					owner.winMtList.add(new MingTang(MingTang.TYPE_DANDIAO,MingTang.ST_HUXI,30));
				}
			}
			if(duiDaoHu) {
				int specialDuiDaoHu = CardUtil.checkSpecialDuiDaoHu(owner.opCardList, owner.handCard, owner.winCard);
				if(specialDuiDaoHu == 1 || specialDuiDaoHu == 3) { 
					jiaxi += 50;
					owner.winMtList.add(new MingTang(MingTang.TYPE_BEIKAOBEI,MingTang.ST_HUXI,50));
				}else if (specialDuiDaoHu == 2) {
					jiaxi += 50;
					owner.winMtList.add(new MingTang(MingTang.TYPE_SHOUQIANSHOU,MingTang.ST_HUXI,50));
				}
			}
			if(this.config.getBoolean(Config.ROOM_CONFIG_DD) && haveXi) {
				jiaxi += 50;
				owner.winMtList.add(new MingTang(MingTang.TYPE_DINGDUI,MingTang.ST_HUXI,50));
			}
			if(this.config.getBoolean(Config.ROOM_CONFIG_QQR) && owner.cardInhand.size() == 1) {
				jiaxi += 150;
				owner.winMtList.add(new MingTang(MingTang.TYPE_QUANQIUREN,MingTang.ST_HUXI,150));
			}
			if(owner.huXi == 10 && owner.kaWei) {
				jiaxi += 50;
				owner.winMtList.add(new MingTang(MingTang.TYPE_KAWEI,MingTang.ST_HUXI,50));
			}
			if(this.config.getBoolean(Config.ROOM_CONFIG_TH) && this.tianHu && owner.seat == this.bankerSeat) {
				jiaxi += 100;
				owner.winMtList.add(new MingTang(MingTang.TYPE_TIANHU, MingTang.ST_HUXI, 100));
			}
			if(this.config.getBoolean(Config.ROOM_CONFIG_PD) && piaodui) {
				jiaxi += 50;
				owner.winMtList.add(new MingTang(MingTang.TYPE_PIAODUI, MingTang.ST_HUXI, 50));
			}
		
			if (dandiao && CardUtil.checkJiDing(owner.handCard, owner.winCard)) {
				jiaxi += 100;
				owner.winMtList.add(new MingTang(MingTang.TYPE_JIDING, MingTang.ST_HUXI, 100));
			}
			if(this.config.getBoolean(Config.ROOM_CONFIG_ZXS) && zimo && owner.winCard == 103) { 
				jiaxi += 100;
				owner.winMtList.add(new MingTang(MingTang.TYPE_ZHUOXIAOSAN, MingTang.ST_HUXI, 100));
			}
			if(this.config.getBoolean(Config.ROOM_CONFIG_SXWQN) && shouXi == zhuoXi && zhuoXi ==5) {
				jiaxi += 50;
				owner.winMtList.add(new MingTang(MingTang.TYPE_SXWUQIANNIAN, MingTang.ST_HUXI, 50));
			}
			huxi = owner.huXi * (beishu > 0 ? beishu : 1) + jiaxi;
	/*===========================================================================================================*/
		} else if(wanfa == 3) { 
			if(yinList.size() >= 1) { 
				if(hong_num == yinList.size() * 4) {
					int xi = (yinList.size() * 100);
					owner.winMtList.add(new MingTang(MingTang.TYPE_CHUNYINHU, MingTang.ST_HUXI, xi));
					jiaxi += xi;
				}// else {
					int xi = (yinList.size() * 20);
					owner.winMtList.add(new MingTang(MingTang.TYPE_YINHU, MingTang.ST_HUXI, xi));
					jiaxi += xi;
				//}
			}
			if(bianKan) {
				jiaxi += 20;
				owner.winMtList.add(new MingTang(MingTang.TYPE_LINGBIANKAN, MingTang.ST_HUXI, 20));
			}
			if (geShanDaNiu) { 
				jiaxi += 20;
				owner.winMtList.add(new MingTang(MingTang.TYPE_GSDN, MingTang.ST_HUXI, 20));
			}
			if (duiDaoHu) {
				jiaxi += 20;
				owner.winMtList.add(new MingTang(MingTang.TYPE_DUIDAOHU, MingTang.ST_HUXI, 20));
			}
			if(owner.huXi == 10) { 
				jiaxi += 20;
				owner.winMtList.add(new MingTang(MingTang.TYPE_KAHU, MingTang.ST_HUXI, 20));
			}
			if(zimo) { 
				jiaxi += 20;
				owner.winMtList.add(new MingTang(MingTang.TYPE_ZIMO, MingTang.ST_HUXI, 20));
			}
		
			if (this.config.getBoolean(Config.ROOM_CONFIG_XLX) && CardUtil.checkXinLianXin(owner.opCardList, owner.handCard)) {
				jiaxi += 20;
				owner.winMtList.add(new MingTang(MingTang.TYPE_XINLIANXIN, MingTang.ST_HUXI, 20));
			}
			if(hong_num >= 10) {
				int xi = (hong_num - 9) * 20;
				if(xi > 10) {
					owner.winMtList.add(new MingTang(MingTang.TYPE_DUOHONGHU, MingTang.ST_HUXI, xi));
				} else { 
					owner.winMtList.add(new MingTang(MingTang.TYPE_HONGHU, MingTang.ST_HUXI, xi));
				}
				jiaxi += xi;
			}
			if(hong_num > 0 && duizi) {
				beishu += 6;
				owner.winMtList.add(new MingTang(MingTang.TYPE_DUIZIHU, MingTang.ST_HUXI_TIMES, 6));
			}
			if(hong_num <= 0) {
				if(duizi) {
					beishu += 8;
					owner.winMtList.add(new MingTang(MingTang.TYPE_WUDUI, MingTang.ST_HUXI_TIMES, 8));
				} else {
					beishu += 4;
					owner.winMtList.add(new MingTang(MingTang.TYPE_WUHU, MingTang.ST_HUXI_TIMES, 4));
				}
			}
			if(hong_num == 1) {
				beishu += 3;
				owner.winMtList.add(new MingTang(MingTang.TYPE_YIDIANHONG, MingTang.ST_HUXI_TIMES, 3));
			}
			boolean huayuan = CardUtil.checkContainHong(owner.opCardList, owner.handCard);
			if(huayuan) {
				jiaxi += 100;
				owner.winMtList.add(new MingTang(MingTang.TYPE_MANHUAYUAN,MingTang.ST_HUXI,100));
			}
			int se = CardUtil.checkQingyise(owner.opCardList, owner.handCard);
			if(se > 0) { 
				jiaxi += 100;
				owner.winMtList.add(new MingTang(se==1?MingTang.TYPE_XIAOYISE:MingTang.TYPE_DAYISE,MingTang.ST_HUXI,100));
			}
			if(tuanYuanSet.size() >= 2) {
				boolean result1 = false;
				boolean result2 = false;
				boolean result3 = false;
				boolean result4 = false;
				for(int ty : tuanYuanSet) {
					if(ty % 100 == 10) {
						if(tuanYuanSet.contains(ty - 9))
							result1 = true;
					} else {
						if(tuanYuanSet.contains(ty +1))
							result2 = true;
					}
					if(ty % 100 <= 8) {
						if(tuanYuanSet.contains(ty +1) && tuanYuanSet.contains(ty +2))
							result3 = true;
					}
					int type = ty / 100;
					if(type == 1 && tuanYuanSet.contains(ty + 100)) {
						result4 = true;
					}
					if(type == 2 && tuanYuanSet.contains(ty - 100)) {
						result4 = true;
					}
				}
				if(tuanYuanSet.size() == 2) {
					if(tuanYuanSet.contains(108) && tuanYuanSet.contains(208)) { 
						jiaxi += 200;
						owner.winMtList.add(new MingTang(MingTang.TYPE_ZHENBAPENGTOU,MingTang.ST_HUXI,200));
					}else if (result4) {
						jiaxi += 100;
						owner.winMtList.add(new MingTang(MingTang.TYPE_JIABAPENGTOU,MingTang.ST_HUXI,100));
					}else if (this.config.getBoolean(Config.ROOM_CONFIG_LBW) && result1) {
						jiaxi += 100;
						owner.winMtList.add(new MingTang(MingTang.TYPE_LONGBAIWEI,MingTang.ST_HUXI,100));
					}else if (result2) {
						jiaxi += 40;
						owner.winMtList.add(new MingTang(MingTang.TYPE_JIEMEIZHUO,MingTang.ST_HUXI,40));
					}//else {
						jiaxi += 20;
						owner.winMtList.add(new MingTang(MingTang.TYPE_ZHUOHU,MingTang.ST_HUXI,20));
					//}
				} else if(tuanYuanSet.size() > 2) {
					if (tuanYuanSet.contains(108) && tuanYuanSet.contains(208)) { 
						jiaxi += 200;
						owner.winMtList.add(new MingTang(MingTang.TYPE_ZHENBAPENGTOU,MingTang.ST_HUXI,200));
					}
					if (result4) {
						jiaxi += 100;
						owner.winMtList.add(new MingTang(MingTang.TYPE_JIABAPENGTOU,MingTang.ST_HUXI,100));
					}
					if (result1) {
						jiaxi += 100;
						owner.winMtList.add(new MingTang(MingTang.TYPE_LONGBAIWEI,MingTang.ST_HUXI,100));
					}
					if (result3) { 
						if(tuanYuanSet.size() == 4) { 
							//按需求，200改成300 05-20 mt
							jiaxi += 300;
							owner.winMtList.add(new MingTang(MingTang.TYPE_DIASUNZHUODAITUO,MingTang.ST_HUXI,300));
						}else {
							jiaxi += 150;
							owner.winMtList.add(new MingTang(MingTang.TYPE_DIASUNZHUO,MingTang.ST_HUXI,150));
						}
					}
					if (result2 && !result3) {
						jiaxi += 80;
						owner.winMtList.add(new MingTang(MingTang.TYPE_JIEMEIZHUODAITUO,MingTang.ST_HUXI,80));
					}
					if (tuanYuanSet.size() == 3 && !result3 && !result2) {
						jiaxi += 60;
						owner.winMtList.add(new MingTang(MingTang.TYPE_SANLUANZHUO,MingTang.ST_HUXI,60));
					}else if (tuanYuanSet.size() == 4 && !result3) {
						//按需求，100改成200 05-20 mt
						jiaxi += 200;
						owner.winMtList.add(new MingTang(MingTang.TYPE_SILUANZHUO,MingTang.ST_HUXI,200));
					}
				} 
			}
			if(this.card.getCount() == 0) {
				jiaxi += 20;
				owner.winMtList.add(new MingTang(MingTang.TYPE_HAIDIHU,MingTang.ST_HUXI,20));
			}
			if(dandiao) {
				if(duizi) {
					jiaxi += 50;
					owner.winMtList.add(new MingTang(MingTang.TYPE_DANDIAO,MingTang.ST_HUXI,50));
				} else {
					jiaxi += 20;
					owner.winMtList.add(new MingTang(MingTang.TYPE_DANDIAO,MingTang.ST_HUXI,20));
				}
			}
			if(duiDaoHu) {
				int specialDuiDaoHu = CardUtil.checkSpecialDuiDaoHu(owner.opCardList, owner.handCard, owner.winCard);
				if(specialDuiDaoHu == 1 || specialDuiDaoHu == 3) { 
					jiaxi += 20;
					owner.winMtList.add(new MingTang(MingTang.TYPE_BEIKAOBEI,MingTang.ST_HUXI,20));
				}else if (specialDuiDaoHu == 2) {
					jiaxi += 20;
					owner.winMtList.add(new MingTang(MingTang.TYPE_SHOUQIANSHOU,MingTang.ST_HUXI,20));
				}
			}
			if(this.config.getBoolean(Config.ROOM_CONFIG_DD) && haveXi) {
				jiaxi += 20;
				owner.winMtList.add(new MingTang(MingTang.TYPE_DINGDUI,MingTang.ST_HUXI,20));
			}
			if(this.config.getBoolean(Config.ROOM_CONFIG_QQR) && owner.cardInhand.size() == 1) {
				jiaxi += 100;
				owner.winMtList.add(new MingTang(MingTang.TYPE_QUANQIUREN,MingTang.ST_HUXI,100));
			}
			if(owner.huXi == 10 && owner.kaWei) {
				jiaxi += 50;
				owner.winMtList.add(new MingTang(MingTang.TYPE_KAWEI,MingTang.ST_HUXI,50));
			}
			if(this.config.getBoolean(Config.ROOM_CONFIG_TH) && this.tianHu && owner.seat == this.bankerSeat) {
				jiaxi += 50;
				owner.winMtList.add(new MingTang(MingTang.TYPE_TIANHU, MingTang.ST_HUXI, 50));
			}
			if(this.config.getBoolean(Config.ROOM_CONFIG_PD) && piaodui) {
				jiaxi += 20;
				owner.winMtList.add(new MingTang(MingTang.TYPE_PIAODUI, MingTang.ST_HUXI, 20));
			}
		
			if (dandiao && CardUtil.checkJiDing(owner.handCard, owner.winCard)) {
				jiaxi += 50;
				owner.winMtList.add(new MingTang(MingTang.TYPE_JIDING, MingTang.ST_HUXI, 50));
			}
			if(this.config.getBoolean(Config.ROOM_CONFIG_SXWQN) && shouXi == zhuoXi && zhuoXi ==5) {
				jiaxi += 20;
				owner.winMtList.add(new MingTang(MingTang.TYPE_SXWUQIANNIAN, MingTang.ST_HUXI, 20));
			}
			if(this.config.getBoolean(Config.ROOM_CONFIG_ZXS) && zimo && owner.winCard == 103) { 
				jiaxi += 30;
				owner.winMtList.add(new MingTang(MingTang.TYPE_ZHUOXIAOSAN, MingTang.ST_HUXI, 30));
			}
			huxi = owner.huXi * (beishu > 0 ? beishu : 1) + jiaxi;
		/*===========================================================================================================*/
		} else if(wanfa == 4) {
			if(hong_num > 0 && duizi) { 
				beishu += 10;
				owner.winMtList.add(new MingTang(MingTang.TYPE_DUIZIHU, MingTang.ST_HUXI_TIMES, 10));
			}
			if(hong_num <= 0) {
				if(duizi) {
					beishu += 15;
					owner.winMtList.add(new MingTang(MingTang.TYPE_WUDUI, MingTang.ST_HUXI_TIMES, 15));
				} else { 
					//按需求6改8 05-20 mt
					beishu += 8;
					owner.winMtList.add(new MingTang(MingTang.TYPE_WUHU, MingTang.ST_HUXI_TIMES, 8));
				}
			}
			if(hong_num == 1) { 
				//按需求4改6 05-20 mt
				beishu += 6;
				owner.winMtList.add(new MingTang(MingTang.TYPE_YIDIANHONG, MingTang.ST_HUXI_TIMES, 6));
			}
			if(yinList.size() >= 1) {
				if(hong_num == yinList.size() * 4) {
					int xi = (yinList.size() * 150);
					owner.winMtList.add(new MingTang(MingTang.TYPE_CHUNYINHU, MingTang.ST_HUXI, xi));
					jiaxi += xi;
				}// else {
					int xi = (yinList.size() * 30);
					owner.winMtList.add(new MingTang(MingTang.TYPE_YINHU, MingTang.ST_HUXI, xi));
					jiaxi += xi;
				//}
			}
			if(hong_num >= 10) {
				int xi = (hong_num - 9) * 30;
				if(xi > 30) {
					owner.winMtList.add(new MingTang(MingTang.TYPE_DUOHONGHU, MingTang.ST_HUXI, xi));
				} else { 
					owner.winMtList.add(new MingTang(MingTang.TYPE_HONGHU, MingTang.ST_HUXI, xi));
				}
				jiaxi += xi;
			}
			boolean huayuan = CardUtil.checkContainHong(owner.opCardList, owner.handCard);
			if(huayuan) {
				jiaxi += 150;
				owner.winMtList.add(new MingTang(MingTang.TYPE_MANHUAYUAN,MingTang.ST_HUXI,150));
			}
			int se = CardUtil.checkQingyise(owner.opCardList, owner.handCard);
			if(se > 0) {
				//按需求200改150 05-20 mt
				jiaxi += 150;
				owner.winMtList.add(new MingTang(se==1?MingTang.TYPE_XIAOYISE:MingTang.TYPE_DAYISE,MingTang.ST_HUXI,150));
			}
			if(tuanYuanSet.size() >= 2) {
				boolean result1 = false;
				boolean result2 = false;
				boolean result3 = false;
				boolean result4 = false;
				for(int ty : tuanYuanSet) {
					if(ty % 100 == 10) {
						if(tuanYuanSet.contains(ty - 9))
							result1 = true;
					} else {
						if(tuanYuanSet.contains(ty +1))
							result2 = true;
					}
					if(ty % 100 <= 8) {
						if(tuanYuanSet.contains(ty +1) && tuanYuanSet.contains(ty +2))
							result3 = true;
					}
					int type = ty / 100;
					if(type == 1 && tuanYuanSet.contains(ty + 100)) {
						result4 = true;
					}
					if(type == 2 && tuanYuanSet.contains(ty - 100)) {
						result4 = true;
					}
				}
				if(tuanYuanSet.size() == 2) {
					if(tuanYuanSet.contains(108) && tuanYuanSet.contains(208)) { 
						jiaxi += 300;
						owner.winMtList.add(new MingTang(MingTang.TYPE_ZHENBAPENGTOU,MingTang.ST_HUXI,300));
					}else if (result4) {
						jiaxi += 150;
						owner.winMtList.add(new MingTang(MingTang.TYPE_JIABAPENGTOU,MingTang.ST_HUXI,150));
					}else if (result1) {
						jiaxi += 150;
						owner.winMtList.add(new MingTang(MingTang.TYPE_LONGBAIWEI,MingTang.ST_HUXI,150));
					}else if (result2) {
						jiaxi += 80;
						owner.winMtList.add(new MingTang(MingTang.TYPE_JIEMEIZHUO,MingTang.ST_HUXI,80));
					}//else {
						//按需求40改50 05-20 mt
						jiaxi += 50;
						owner.winMtList.add(new MingTang(MingTang.TYPE_ZHUOHU,MingTang.ST_HUXI,50));
					//}
				} else if(tuanYuanSet.size() > 2) {
					if (tuanYuanSet.contains(108) && tuanYuanSet.contains(208)) { 
						//按需求300改400 05-20 mt
						jiaxi += 400;
						owner.winMtList.add(new MingTang(MingTang.TYPE_ZHENBAPENGTOU,MingTang.ST_HUXI,400));
					}
					if (result4) { 
						//按需求150改200 05-20 mt
						jiaxi += 200;
						owner.winMtList.add(new MingTang(MingTang.TYPE_JIABAPENGTOU,MingTang.ST_HUXI,200));
					}
					if (result1) { 
						jiaxi += 150;
						owner.winMtList.add(new MingTang(MingTang.TYPE_LONGBAIWEI,MingTang.ST_HUXI,150));
					}
					if (result3) { 
						if(tuanYuanSet.size() == 4) {
							jiaxi += 400;
							owner.winMtList.add(new MingTang(MingTang.TYPE_DIASUNZHUODAITUO,MingTang.ST_HUXI,400));
						}else {
							jiaxi += 300;
							owner.winMtList.add(new MingTang(MingTang.TYPE_DIASUNZHUO,MingTang.ST_HUXI,300));
						}
					}
					if (result2 &&!result3) {
						//按需求150改200 05-20 mt
						jiaxi += 200;
						owner.winMtList.add(new MingTang(MingTang.TYPE_JIEMEIZHUODAITUO,MingTang.ST_HUXI,200));
					}
					if (tuanYuanSet.size() == 3 && !result3 && !result2) {
						//按需求100改150 05-20 mt jefe
						jiaxi += 150;
						owner.winMtList.add(new MingTang(MingTang.TYPE_SANLUANZHUO,MingTang.ST_HUXI,150));
					}else if (tuanYuanSet.size() == 4) {
						jiaxi += 300;
						owner.winMtList.add(new MingTang(MingTang.TYPE_SILUANZHUO,MingTang.ST_HUXI,300));
					}
				} 
			}
			if(this.card.getCount() == 0) { 
				jiaxi += 50;
				owner.winMtList.add(new MingTang(MingTang.TYPE_HAIDIHU,MingTang.ST_HUXI,50));
			}
			if(dandiao) {
				if(duizi) {
					jiaxi += 50;
					owner.winMtList.add(new MingTang(MingTang.TYPE_DANDIAO,MingTang.ST_HUXI,50));
				} else {
					jiaxi += 30;
					owner.winMtList.add(new MingTang(MingTang.TYPE_DANDIAO,MingTang.ST_HUXI,30));
				}
			}
			int specialDuiDaoHu = 0;
			if(duiDaoHu) {
				specialDuiDaoHu = CardUtil.checkSpecialDuiDaoHu(owner.opCardList, owner.handCard, owner.winCard);
				if(specialDuiDaoHu == 1) { 
					jiaxi += 50;
					owner.winMtList.add(new MingTang(MingTang.TYPE_BEIKAOBEI,MingTang.ST_HUXI,50));
				}else if (specialDuiDaoHu == 2) { 
					jiaxi += 50;
					owner.winMtList.add(new MingTang(MingTang.TYPE_SHOUQIANSHOU,MingTang.ST_HUXI,50));
				}
			}
			if(haveXi) {
				jiaxi += 50;
				owner.winMtList.add(new MingTang(MingTang.TYPE_DINGDUI,MingTang.ST_HUXI,50));
			}
			if(owner.cardInhand.size() == 1) {
				jiaxi += 150;
				owner.winMtList.add(new MingTang(MingTang.TYPE_QUANQIUREN,MingTang.ST_HUXI,150));
			}
			if(owner.huXi == 10 && owner.kaWei) {
				//按需求50改100 05-20 mt
				jiaxi += 100;
				owner.winMtList.add(new MingTang(MingTang.TYPE_KAWEI,MingTang.ST_HUXI,100));
			}
			if(this.tianHu && owner.seat == this.bankerSeat) {
				jiaxi += 150;
				owner.winMtList.add(new MingTang(MingTang.TYPE_TIANHU, MingTang.ST_HUXI, 150));
			}
			if(piaodui) {
				jiaxi += 50;
				owner.winMtList.add(new MingTang(MingTang.TYPE_PIAODUI, MingTang.ST_HUXI, 50));
			}
			if (dandiao && CardUtil.checkJiDing(owner.handCard, owner.winCard)) {
				jiaxi += 100;
				owner.winMtList.add(new MingTang(MingTang.TYPE_JIDING, MingTang.ST_HUXI, 100));
			}
			if(shouXi == zhuoXi && zhuoXi ==5) {
				jiaxi += 50;
				owner.winMtList.add(new MingTang(MingTang.TYPE_SXWUQIANNIAN, MingTang.ST_HUXI, 50));
			}
			/**=========================================================================================*/
			if(bianKan) {
				jiaxi += 40;
				owner.winMtList.add(new MingTang(MingTang.TYPE_LINGBIANKAN, MingTang.ST_HUXI, 40));
			}
			if(specialDuiDaoHu == 3 ) {
				jiaxi += 100;
				owner.winMtList.add(new MingTang(MingTang.TYPE_ZHENBEIKAOBEI, MingTang.ST_HUXI, 100));
			}
			if(specialDuiDaoHu == 4) { 
				int xiao = owner.winCard % 100;
				if(xiao == 1 || xiao == 10) {
					jiaxi += 50;
					owner.winMtList.add(new MingTang(MingTang.TYPE_FENGPAIWEI, MingTang.ST_HUXI, 50));
				}
			}
			if(owner.huXi == 10) {
				jiaxi += 50;
				owner.winMtList.add(new MingTang(MingTang.TYPE_KAHU, MingTang.ST_HUXI, 50));
			}
			if(zimo) { 
				//按需求40改30 05-20 mt
				jiaxi += 30;
				owner.winMtList.add(new MingTang(MingTang.TYPE_ZIMO, MingTang.ST_HUXI, 30));
			}
			if(haveXi) { 
				jiaxi += 50;
				owner.winMtList.add(new MingTang(MingTang.TYPE_DINGDINGXI, MingTang.ST_HUXI, 50));
			}
			if (duiDaoHu) { 
				jiaxi += 30;
				owner.winMtList.add(new MingTang(MingTang.TYPE_DUIDAOHU, MingTang.ST_HUXI, 30));
			}
			if (geShanDaNiu) {
				jiaxi += 30;
				owner.winMtList.add(new MingTang(MingTang.TYPE_GSDN, MingTang.ST_HUXI, 30));
			}
			if (specialDuiDaoHu == 5) { 
				jiaxi += 30;
				owner.winMtList.add(new MingTang(MingTang.TYPE_JIAFENGBAIWEI, MingTang.ST_HUXI, 30));
			}
			if(zimo && owner.winCard == 103) { 
				jiaxi += 100;
				owner.winMtList.add(new MingTang(MingTang.TYPE_ZHUOXIAOSAN, MingTang.ST_HUXI, 100));
			}
			/*if(CardUtil.checkErXiManHuaYuan(owner.opCardList, owner.handCard)) { 
				jiaxi += 150;
				owner.winMtList.add(new MingTang(MingTang.TYPE_ERXIMANHUAYUAN, MingTang.ST_HUXI, 150));
			}*/
			if((tuanYuanSet.contains(101) && tuanYuanSet.contains(210)) || (tuanYuanSet.contains(110) && tuanYuanSet.contains(201))) {
				jiaxi += 100;
				owner.winMtList.add(new MingTang(MingTang.TYPE_JIALONGBAIWU, MingTang.ST_HUXI, 100));
			}
			if (dandiao && CardUtil.checkYuanYuanDing(owner.opCardList, owner.handCard, owner.winCard)) {
				//按需求50改100 05-20 mt
				jiaxi += 100;
				owner.winMtList.add(new MingTang(MingTang.TYPE_YUANYUANDING, MingTang.ST_HUXI, 100));
			}
		
			if (CardUtil.checkXinLianXin(owner.opCardList, owner.handCard)) {
				jiaxi += 30;
				owner.winMtList.add(new MingTang(MingTang.TYPE_XINLIANXIN, MingTang.ST_HUXI, 30));
			}
			
			if(hong_num == 2 && contains123 == 2) {
				jiaxi += 50;
				owner.winMtList.add(new MingTang(MingTang.TYPE_ERLONGXIZHU, MingTang.ST_HUXI, 50));
			}
			if(owner.cardInhand.size() == 1 && CardUtil.checkHongCard(owner.cardInhand.get(0))) {
				jiaxi += 50;
				owner.winMtList.add(new MingTang(MingTang.TYPE_MEINVCAIDANCHE,MingTang.ST_HUXI,50));
			}
			huxi = owner.huXi * (beishu > 0 ? beishu : 1) + jiaxi;
		}
		owner.winHuxi = huxi;
		return huxi;
	}
	
	@Override
	protected void roomResult() {
		EXMainServer.gameCtr.roomResult(this);
	}
	
	@Override
	public void endGame() {
		super.endGame();
	}
	
	/*public void settleRound() {
		boolean total = this.round >= this.maxRound;
		if (!total)
			EXMainServer.gameCtr.roomResult(this);
		else {
			this.saveMilitaryTotal(false);
		}
		saveMilitaryRound(playBackData.getData());
		this.stateMachine.changeState(Global.getState(EXRoomRoundSettleState.class));
		
		if (total) {
			if (this.maxRound == 8) {
				for (Entry<Integer, Player> entry : this.playerMapById.entrySet()) {
					EXPlayer player = (EXPlayer) entry.getValue();
					if (player.winCount == 8) {
						player.redisTask(3, 8);
					}
				}
			}
			this.stateMachine.changeState(Global.getState(RoomEndGameState.class));
			return;
		}
	}*/

	public PlayBack getPlayBack() {
		return (PlayBack) playBackData;
	}
	
	@Override
	public void saveMilitaryTotal(boolean dissmiss) {
		super.saveMilitaryTotal(dissmiss);
		EXMainServer.gameCtr.roomTotalResult(this, dissmiss);
	}
	
	@Override
	public void clear() {
		super.clear();
		this.tianHu = true;
		this.throwList.clear();
		this.liuju = false;
		this.activeSeat = this.currenDiscardSeat = 0;
		this.lastPaoSeat = 0;
		this.draw = -1;
		this.isAllPass = false;
	}

}
