package extend.mj;

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.ITObject;
import extend.mj.player.state.EXPlayerDisCardTipState;
import extend.mj.tip.Action;
import extend.mj.tip.TipManager;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;

public class EXRoom extends Room {

	//
	public Map<Integer, TipManager>	tipMap;
	public List<Action>				actionList;

	public RoomCard					card;

	public int						activeCard;
	public int						currenDiscardSeat;
	public int						lastDiscardSeat;
	public int						winCount	= 0;
	public boolean					liuju		= false;
	public boolean					last_liuju	= false;

	public ArrayList<CardNiao>		niao;

	public int						piaoNiaoCount;
	public int                      adminSeat  = 0;
	public int  					lastWinPlayerId = 0;
	public boolean 					isGengZhuang = false;
	public int						first_zhuang_card = 0;
	public int						geng_zhuan_num = 0;
	public int						gent_zhuan_nextSeat = 0;
	/*
	 * 上一次庄家座位号
	 */
	public int 						lastBankerSeat = 0;
	public int 						piaoCount 	= 0;

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

		this.tipMap = new HashMap<Integer, TipManager>();
		this.actionList = new ArrayList<Action>();
		this.niao = new ArrayList<CardNiao>();

		if (!this.config.containsKey(Config.ROOM_CONFIG_DIANPAO))
		{
			this.config.putBoolean(Config.ROOM_CONFIG_DIANPAO, false);
		}
		if (!this.config.containsKey(Config.ROOM_CONFIG_HUNYISE))
		{
			this.config.putBoolean(Config.ROOM_CONFIG_HUNYISE, false);
		}

		if (!this.config.containsKey(Config.ROOM_CONFIG_QINGYISE))
		{
			this.config.putBoolean(Config.ROOM_CONFIG_QINGYISE, false);
		}
		if (!this.config.containsKey(Config.ROOM_CONFIG_PENGPENGHU))
		{
			this.config.putBoolean(Config.ROOM_CONFIG_PENGPENGHU, false);
		}
		if (!this.config.containsKey(Config.ROOM_CONFIG_QIDUI))
		{
			this.config.putBoolean(Config.ROOM_CONFIG_QIDUI, false);
		}
		if (!this.config.containsKey(Config.ROOM_CONFIG_HAOHUA_QIDUI))
		{
			this.config.putBoolean(Config.ROOM_CONFIG_HAOHUA_QIDUI, false);
		}
		if (!this.config.containsKey(Config.ROOM_CONFIG_HAOHUA2_QIDUI))
		{
			this.config.putBoolean(Config.ROOM_CONFIG_HAOHUA2_QIDUI, false);
		}
		if (!this.config.containsKey(Config.ROOM_CONFIG_HAOHUA3_QIDUI))
		{
			this.config.putBoolean(Config.ROOM_CONFIG_HAOHUA3_QIDUI, false);
		}
		if (!this.config.containsKey(Config.ROOM_CONFIG_GANGSHANGKAIHUA_2bei))
		{
			this.config.putBoolean(Config.ROOM_CONFIG_GANGSHANGKAIHUA_2bei, false);
		}
		if (!this.config.containsKey(Config.ROOM_CONFIG_SHISHANGYAO))
		{
			this.config.putBoolean(Config.ROOM_CONFIG_SHISHANGYAO, false);
		}
		if (!this.config.containsKey(Config.ROOM_CONFIG_TIANDIHU))
		{
			this.config.putBoolean(Config.ROOM_CONFIG_TIANDIHU, false);
		}
		if (!this.config.containsKey(Config.ROOM_CONFIG_SHIBALUOHAN))
		{
			this.config.putBoolean(Config.ROOM_CONFIG_SHIBALUOHAN, false);
		}
		if (!this.config.containsKey(Config.ROOM_CONFIG_XIAOSHANYUAN))
		{
			this.config.putBoolean(Config.ROOM_CONFIG_XIAOSHANYUAN, false);
		}
		if (!this.config.containsKey(Config.ROOM_CONFIG_DASHANYUAN))
		{
			this.config.putBoolean(Config.ROOM_CONFIG_DASHANYUAN, false);
		}
		if (!this.config.containsKey(Config.ROOM_CONFIG_DASIXI))
		{
			this.config.putBoolean(Config.ROOM_CONFIG_DASIXI, false);
		}
		if (!this.config.containsKey(Config.ROOM_CONFIG_XIAOSIXI))
		{
			this.config.putBoolean(Config.ROOM_CONFIG_XIAOSIXI, false);
		}
		if (!this.config.containsKey(Config.ROOM_CONFIG_LOUHU))
		{
			this.config.putBoolean(Config.ROOM_CONFIG_LOUHU, false);
		}
		if (!this.config.containsKey(Config.ROOM_CONFIG_GUO_PENG))
		{
			this.config.putBoolean(Config.ROOM_CONFIG_GUO_PENG, false);
		}
		if (!this.config.containsKey(Config.ROOM_CONFIG_GUO_GONG))
		{
			this.config.putBoolean(Config.ROOM_CONFIG_GUO_GONG, false);
		}

		this.config.putBoolean(Config.ROOM_CONFIG_NONEALL, false);
		this.config.putBoolean(Config.ROOM_CONFIG_ZHUANGXIAN, false);
		this.config.putBoolean(Config.ROOM_CONFIG_QIANGKONG_NIAO, true);

		//可抢杠胡
		if (!this.config.containsKey(Config.ROOM_CONFIG_QIANGKONG))
		{
			this.config.putBoolean(Config.ROOM_CONFIG_QIANGKONG, false);
		}

		//可抢杠胡2倍
		if (!this.config.containsKey(Config.ROOM_CONFIG_QIANGKONG_2BEI))
		{
			this.config.putBoolean(Config.ROOM_CONFIG_QIANGKONG_2BEI, false);
		}

		//明杠可抢
		if (!this.config.containsKey(Config.ROOM_CONFIG_QIANGKONG_MING))
		{
			this.config.putBoolean(Config.ROOM_CONFIG_QIANGKONG_MING, false);
		}

		//抢杠全包
		if (!this.config.containsKey(Config.ROOM_CONFIG_QG_TYPE))
		{
			this.config.putBoolean(Config.ROOM_CONFIG_QG_TYPE, false);
		}
		
		//杠爆全包
		if (!this.config.containsKey(Config.ROOM_CONFIG_GANGBAO_TYPE))
		{
			this.config.putBoolean(Config.ROOM_CONFIG_GANGBAO_TYPE, false);
		}

		this.config.putBoolean(Config.ROOM_CONFIG_HZ_HU, false);

		if (!this.config.containsKey(Config.ROOM_CONFIG_GENGZHUAN))
		{
			this.config.putBoolean(Config.ROOM_CONFIG_GENGZHUAN, false);
		}

		if (!this.config.containsKey(Config.ROOM_CONFIG_JIEJIEGAO))
		{
			this.config.putBoolean(Config.ROOM_CONFIG_JIEJIEGAO, false);
		}

		if (!this.config.containsKey(Config.ROOM_CONFIG_JIEJIEGAO_FIRST_NO))
		{
			this.config.putBoolean(Config.ROOM_CONFIG_JIEJIEGAO_FIRST_NO, false);
		}

		if (!this.config.containsKey(Config.ROOM_CONFIG_LIAN_ZHUANG)) {
			this.config.putBoolean(Config.ROOM_CONFIG_LIAN_ZHUANG, false);
		}

		if (!this.config.containsKey(Config.ROOM_CONFIG_WUGUI_JIABEI))
		{
			this.config.putBoolean(Config.ROOM_CONFIG_WUGUI_JIABEI, false);
		}

		if (!this.config.containsKey(Config.ROOM_CONFIG_NO_WAN))
		{
			this.config.putBoolean(Config.ROOM_CONFIG_NO_WAN, false);
		}

		if (!this.config.containsKey(Config.ROOM_CONFIG_QIDUI_JIA_FAN))
		{
			this.config.putBoolean(Config.ROOM_CONFIG_QIDUI_JIA_FAN, false);
		}

		if (!this.config.containsKey(Config.ROOM_CONFIG_QIDUI_4BEI))
		{
			this.config.putBoolean(Config.ROOM_CONFIG_QIDUI_4BEI, false);
		}

		if (!this.config.containsKey(Config.ROOM_CONFIG_MA_GEN_GONG))
		{
			this.config.putBoolean(Config.ROOM_CONFIG_MA_GEN_GONG, false);
		}

		if (!this.config.containsKey(Config.ROOM_CONFIG_WU_FENG))
		{
			this.config.putBoolean(Config.ROOM_CONFIG_WU_FENG, false);
		}

		////幺九
		if (!this.config.containsKey(Config.ROOM_CONFIG_YAO_JIU))
		{
			this.config.putBoolean(Config.ROOM_CONFIG_YAO_JIU, false);
		}

		//清幺九
		if (!this.config.containsKey(Config.ROOM_CONFIG_QING_YAO_JIU))
		{
			this.config.putBoolean(Config.ROOM_CONFIG_QING_YAO_JIU, false);
		}

		//有没有癞子
		if (!this.config.containsKey(Config.ROOM_CONFIG_LAIZI))
		{
			this.config.putInt(Config.ROOM_CONFIG_LAIZI, 0);
		}

		//四鬼胡牌
		if (!this.config.containsKey(Config.ROOM_CONFIG_LAIZI4_HU))
		{
			this.config.putBoolean(Config.ROOM_CONFIG_LAIZI4_HU, false);
		}

		//四鬼胡牌两倍
		if (!this.config.containsKey(Config.ROOM_CONFIG_LAIZI4_HU_2BEI))
		{
			this.config.putBoolean(Config.ROOM_CONFIG_LAIZI4_HU_2BEI, false);
		}

		//全风
		if (!this.config.containsKey(Config.ROOM_CONFIG_QUAN_FENG))
		{
			this.config.putBoolean(Config.ROOM_CONFIG_QUAN_FENG, false);
		}

		////12张落地全包
		if (!this.config.containsKey(Config.ROOM_CONFIG_12ZHANG_LUODI_QUANBAO))
		{
			this.config.putBoolean(Config.ROOM_CONFIG_12ZHANG_LUODI_QUANBAO, false);
		}

		////留够马牌
		if (!this.config.containsKey(Config.ROOM_CONFIG_LIU_GOU_MA))
		{
			this.config.putBoolean(Config.ROOM_CONFIG_LIU_GOU_MA, false);
		}

		//全求人
		if (!this.config.containsKey(Config.ROOM_CONFIG_QUAN_FENG_SCORE))
		{
			this.config.putBoolean(Config.ROOM_CONFIG_QUAN_FENG_SCORE, false);
		}

		// ROOM_CONFIG_han19 = "han19"; //含19即可
		if (!this.config.containsKey(Config.ROOM_CONFIG_han19))
		{
			this.config.putBoolean(Config.ROOM_CONFIG_han19, false);
		}

		if (!this.config.containsKey(Config.ROOM_CONFIG_ZIYISE))
		{
			this.config.putBoolean(Config.ROOM_CONFIG_ZIYISE, false);
		}


		//大胡相乘
		if (!this.config.containsKey(Config.ROOM_CONFIG_DAHU_CHENG))
		{
			this.config.putBoolean(Config.ROOM_CONFIG_DAHU_CHENG, false);
		}

		//鸡胡不能吃胡
		if (!this.config.containsKey(Config.ROOM_CONFIG_JIHU_NOTCHIHU))
		{
			this.config.putBoolean(Config.ROOM_CONFIG_JIHU_NOTCHIHU, false);
		}

		//小胡的倍数另算
		if (!this.config.containsKey(Config.ROOM_CONFIG_XIAOHU_BEI))
		{
			this.config.putBoolean(Config.ROOM_CONFIG_XIAOHU_BEI, false);
		}

		//流局两倍
		if (!this.config.containsKey(Config.ROOM_CONFIG_LIUJU_2BEI))
		{
			this.config.putBoolean(Config.ROOM_CONFIG_LIUJU_2BEI, false);
		}

		//荒庄荒杠
		if (!this.config.containsKey(Config.ROOM_CONFIG_HUANGZHUANGHUANGGANG))
		{
			this.config.putBoolean(Config.ROOM_CONFIG_HUANGZHUANGHUANGGANG, false);
		}

		//潮州特殊自摸
		if (!this.config.containsKey(Config.ROOM_CONFIG_SPECAIL_ZIMO))
		{
			this.config.putBoolean(Config.ROOM_CONFIG_SPECAIL_ZIMO, false);
		}

		//必胡，必须胡牌，不能过
		if (!this.config.containsKey(Config.ROOM_CONFIG_MUST_HU))
		{
			this.config.putBoolean(Config.ROOM_CONFIG_MUST_HU, false);
		}

		if (!this.config.containsKey(Config.ROOM_CONFIG_LIU_GOU_MA))
		{
			this.config.putBoolean(Config.ROOM_CONFIG_LIU_GOU_MA, false);
		}

		//买马,提前预定马，猜谁胡
		if (!this.config.containsKey(Config.ROOM_CONFIG_MAI_NIAO))
		{
			this.config.putInt(Config.ROOM_CONFIG_MAI_NIAO, 0);
		}

		//买马值
		if (!this.config.containsKey(Config.ROOM_CONFIG_MAI_NIAO_OPT))
		{
			this.config.putInt(Config.ROOM_CONFIG_MAI_NIAO_OPT, 0);
		}

		if (!this.config.containsKey(Config.ROOM_CONFIG_MA_GEN_DI_FEN))
		{
			this.config.putBoolean(Config.ROOM_CONFIG_MA_GEN_DI_FEN, false);
		}

		if (!this.config.containsKey(Config.ROOM_CONFIG_NIAO))
		{
			this.config.putInt(Config.ROOM_CONFIG_NIAO, 0);
		}

		if (!this.config.containsKey(Config.ROOM_CONFIG_NIAO_OPT))
		{
			this.config.putInt(Config.ROOM_CONFIG_NIAO_OPT, 0);
		}

		//10倍不计分
		if (!this.config.containsKey(Config.ROOM_CONFIG_10_BEI_BUJIFEN))
		{
			this.config.putBoolean(Config.ROOM_CONFIG_10_BEI_BUJIFEN, false);
		}

		//封顶十倍
		if (!this.config.containsKey(Config.ROOM_CONFIG_10_BEI_FENGDING))
		{
			this.config.putBoolean(Config.ROOM_CONFIG_10_BEI_FENGDING, false);
		}

		//自动胡
		if (!this.config.containsKey(Config.ROOM_CONFIG_ZI_DONG_HU))
		{
			this.config.putBoolean(Config.ROOM_CONFIG_ZI_DONG_HU, false);
		}

		//海底捞月
		//自动胡
		if (!this.config.containsKey(Config.ROOM_CONFIG_HAI_DI_NAO_YUE))
		{
			this.config.putBoolean(Config.ROOM_CONFIG_HAI_DI_NAO_YUE, false);
		}

		////使用默认基础胡分
		if (!this.config.containsKey(Config.ROOM_CONFIG_USE_BASE_HU_SCORE))
		{
			this.config.putBoolean(Config.ROOM_CONFIG_USE_BASE_HU_SCORE, false);
		}

		//门清
		if (!this.config.containsKey(Config.ROOM_CONFIG_MENG_QING))
		{
			this.config.putBoolean(Config.ROOM_CONFIG_MENG_QING, false);
		}

		//没有鸡胡，统一叫平胡
		if (!this.config.containsKey(Config.ROOM_CONFIG_JIHU_SHI_PINGHU))
		{
			this.config.putBoolean(Config.ROOM_CONFIG_JIHU_SHI_PINGHU, false);
		}

		//杠上炮2倍
		if (!this.config.containsKey(Config.ROOM_CONFIG_GANGSHANGPAO_2bei))
		{
			this.config.putBoolean(Config.ROOM_CONFIG_GANGSHANGPAO_2bei, false);
		}

		if (!this.config.containsKey(Config.ROOM_CONFIG_CHUIPAI))
		{
			this.config.putBoolean(Config.ROOM_CONFIG_CHUIPAI, false);
		}

		if (!this.config.containsKey(Config.ROOM_CONFIG_PIAO))
		{
			this.config.putInt(Config.ROOM_CONFIG_PIAO, 0);
		}

		if (!this.config.containsKey(Config.ROOM_CONFIG_PIAO_FEN))
		{
			this.config.putInt(Config.ROOM_CONFIG_PIAO_FEN, 0);
		}

		if (!this.config.containsKey(Config.ROOM_CONFIG_XUAN_ZHUANG))
		{
			this.config.putInt(Config.ROOM_CONFIG_XUAN_ZHUANG, 0);
		}

		if (!this.config.containsKey(Config.ROOM_CONFIG_QING_ZUI_HU))
		{
			this.config.putInt(Config.ROOM_CONFIG_QING_ZUI_HU, 0);
		}

		if (!this.config.containsKey(Config.ROOM_CONFIG_GANG_ZHAO_LIU_XI))
		{
			this.config.putBoolean(Config.ROOM_CONFIG_QING_ZUI_HU, false);
		}

		if (!this.config.containsKey(Config.ROOM_CONFIG_SPECIAL_PENG_PENG_HU))
		{
			this.config.putBoolean(Config.ROOM_CONFIG_SPECIAL_PENG_PENG_HU, false);
		}

		if (!this.config.containsKey(Config.ROOM_CONFIG_FEN_DIEJIA))
		{
			this.config.putInt(Config.ROOM_CONFIG_FEN_DIEJIA, 0);
		}

		if (!this.config.containsKey(Config.ROOM_CONFIG_XIPAI_SCORE))
		{
			this.config.putInt(Config.ROOM_CONFIG_XIPAI_SCORE, 0);
			this.xi_pai_score = 1;
		}
		else {
			this.xi_pai_score = this.config.getInt(Config.ROOM_CONFIG_XIPAI_SCORE);
		}

		if (!this.config.containsKey(Config.ROOM_CONFIG_XIPAI))
		{
			this.config.putBoolean(Config.ROOM_CONFIG_XIPAI, false);
		}

		this.isEntrust=true;
		this.adminSeat = 0;
		this.lastWinPlayerId =0;

		this.first_zhuang_card = 0;
		this.geng_zhuan_num = 0;
		this.gent_zhuan_nextSeat = 0;

		if (this.config.getBoolean(Config.ROOM_CONFIG_GENGZHUAN))
		{
			this.isGengZhuang = true;
		}

		this.lastBankerSeat = 0;
		this.last_liuju = false;

		//初始化房间的特殊参数
		WinCardType.InitRoomSpecialConfig(this);
	}

	public boolean isLiuJu()
	{
		if (card.cardList.size() == 0)
		{
			return true;
		}

	    return false;
	}

	public void endGameByLiuJu()
	{
		if (config.getBoolean(Config.ROOM_CONFIG_HUANGZHUANGHUANGGANG))
		{
			for (Entry<Integer, Player> entry : this.playerMapById.entrySet()) {
				EXPlayer player = (EXPlayer) entry.getValue();
				int score = player.score.round_log.get(EXScore.KONG);
				player.score.round_score -= score;
				player.score.total_score -= score;
				player.score.round_log.put(EXScore.KONG, 0);
			}
		}
		liuju = true;
		clear_repeatwin();

		endGame();
	}

	public void endGame()
	{
		last_liuju = liuju;
		for (Entry<Integer, Player> entry : this.playerMapById.entrySet()) {
			EXPlayer player = (EXPlayer) entry.getValue();
			if (player.winer != 1)
			{
				player.last_winer = 0;
				player.repeat_win = -1;
			}
			else
			{
				player.last_winer = 1;
			}
		}
		super.endGame();
	}

	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 boolean isLaizi(int card) {
		return this.card.isLaizi(card);
	}

	public void checkAction() {
		boolean isWeightest = this.isWeightestAction();
		if (!isWeightest) {
			return;
		}
		if (this.isAllPass()) {
			Player activePlayer = 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.tip.weight <= tip.getWeightest()) {
				return false;
			}
		}

		for (Entry<Integer, Player> entry : this.playerMapById.entrySet()) {
			EXPlayer player = (EXPlayer) entry.getValue();
			if (player.stateMachine.curState instanceof EXPlayerDisCardTipState) {
				player.stateMachine.changeState(Global.getState(PlayerWaitState.class));
			}
		}
		return true;

	}

	/**
	 * 获取房间信息
	 *
	 * @return
	 */
	public ITObject getRoomInfo() {
		ITObject data = super.getRoomInfo();
		if (data != null)
		{
			data.putInt("laiziCard", this.card.laiziCard);
			data.putInt("laiziCard2", this.card.laiziCard2);
			data.putInt("laiziCardBefore", this.card.laiziCardBefore);
			data.putInt("laiziCard2Before", this.card.laiziCard2Before);
		}

		return data;
	}

	public ITObject getReloadInfo(Player player) {
		ITObject data = super.getReloadInfo(player);
		EXPlayer p = (EXPlayer) player;
		data.putTArray("hand_card", Util.toTArray(p.cardInhand));
		data.putInt("left_card", card.getCount());
		data.putInt("curren_outcard_seat", currenDiscardSeat);
		data.putInt("last_outcard_seat", lastDiscardSeat);
		return data;
	}

	public void addScore(EXPlayer destPlayer, EXPlayer fromPlayer, int score, int type) {
		boolean zhuangxian = this.config.getBoolean(Config.ROOM_CONFIG_ZHUANGXIAN);
		if(type == EXScore.WIN) {
			if (zhuangxian) {
				if (destPlayer.seat == this.bankerSeat || fromPlayer.seat == this.bankerSeat) {
					score += 1;
				}
			}
		}

		if (type == EXScore.WIN || type == EXScore.NIAO)
		{
			if (fromPlayer.tinghu10bei)
			{
				return;
			}
		}

		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 addMaGengGongScore(EXPlayer destPlayer, EXPlayer fromPlayer, int score) {
		this.addScore(destPlayer, fromPlayer, score, EXScore.MA_GENG_GONG);
	}

	public void addAllMaGengGongScore(EXPlayer destPlayer, int score) {
		for (Entry<Integer, Player> entry : this.playerMapById.entrySet()) {
			if (entry.getKey().equals(destPlayer.playerid)) {
				continue;
			}
			EXPlayer fromPlayer = (EXPlayer) entry.getValue();
			addMaGengGongScore(destPlayer, fromPlayer, score);
		}
	}

	public int GetGongScore(EXPlayer destPlayer)
	{
		return destPlayer.score.round_log.get(EXScore.KONG);
	}

	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);
		}
	}

	public void addMaiNiaoScore(EXPlayer destPlayer, EXPlayer fromPlayer, int score) {
		this.addScore(destPlayer, fromPlayer, score, EXScore.MAI_NIAO);
	}

	public void addAllMaiNiaoScore(EXPlayer destPlayer, int score) {
		for (Entry<Integer, Player> entry : this.playerMapById.entrySet()) {
			if (entry.getKey().equals(destPlayer.playerid)) {
				continue;
			}
			EXPlayer fromPlayer = (EXPlayer) entry.getValue();
			addMaiNiaoScore(destPlayer, fromPlayer, score);
		}
	}

	public void addNiaoScore(EXPlayer destPlayer, EXPlayer fromPlayer, int score) {
		this.addScore(destPlayer, fromPlayer, score, EXScore.NIAO);
	}

	public void addAllNiaoScore(EXPlayer destPlayer, int score) {
		for (Entry<Integer, Player> entry : this.playerMapById.entrySet()) {
			if (entry.getKey().equals(destPlayer.playerid)) {
				continue;
			}
			EXPlayer fromPlayer = (EXPlayer) entry.getValue();
			addNiaoScore(destPlayer, fromPlayer, score);
		}
	}

	public void addPiaoNiaoScore(EXPlayer destPlayer, EXPlayer fromPlayer) {
		int piao_niao = this.config.getInt(Config.ROOM_CONFIG_PIAO); //0:热票 1:冷票 2:不嫖 3：固定票分
		if(piao_niao == 0)return;
		this.addScore(destPlayer, fromPlayer,destPlayer.piao + fromPlayer.piao, EXScore.PIAO_NIAO);
	}

	public void addAllPiaoNiaoScore(EXPlayer destPlayer) {
		int piao_niao = this.config.getInt(Config.ROOM_CONFIG_PIAO); //0:不嫖  1:冷票 2: 3：固定票分
		if(piao_niao == 0)return;
		for (Entry<Integer, Player> entry : this.playerMapById.entrySet()) {
			if (entry.getKey().equals(destPlayer.playerid)) {
				continue;
			}
			EXPlayer fromPlayer = (EXPlayer) entry.getValue();
			addPiaoNiaoScore(destPlayer,fromPlayer);
		}
	}

	public void handle_repeatwin(EXPlayer owner)
	{
		if (owner.last_winer == 1)
		{
			owner.repeat_win += 1;
		}
		else
		{
			owner.repeat_win += 1;
		}
	}

	public void clear_repeatwin()
	{
		for (Entry<Integer, Player> entry : this.playerMapById.entrySet()) {
			EXPlayer player = (EXPlayer) entry.getValue();
			player.repeat_win = -1;
			player.last_winer = 0;
		}
	}

	@Override
	public void saveMilitaryTotal(boolean dissmiss) {
		super.saveMilitaryTotal(dissmiss);
		EXMainServer.gameCtr.roomTotalResult(this, dissmiss);
	}
	@Override
	protected void roomResult() {
		EXMainServer.gameCtr.roomResult(this);
	}

	@Override
	public void clear() {
		super.clear();

		this.liuju = false;
		this.activeSeat = this.lastDiscardSeat = this.currenDiscardSeat = 0;
		this.winCount = this.piaoNiaoCount = 0;
		this.niao.clear();

		this.isGengZhuang = false;
		this.first_zhuang_card = 0;
		this.geng_zhuan_num = 0;
		this.gent_zhuan_nextSeat = 0;
		if (this.config.getBoolean(Config.ROOM_CONFIG_GENGZHUAN))
		{
			this.isGengZhuang = true;
		}
		this.lastBankerSeat = 0;
	}

	public void winCallback(EXPlayer owner, int card) {
		this.endGame();
	}
}
