package extend.mj;

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

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;

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 ArrayList<CardNiao>		niao;

	public int						niao_score;
	public int						piaoNiaoCount;
	public int                       adminSeat  = 0;

	public int						di_fen = 2;
	public int						niao_fen = 2;

	public int						fengdingScore = 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>();
		this.fengdingScore = 0;

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

		if (!this.config.containsKey(Config.ROOM_CONFIG_FENGDING_SCORE))
		{
			this.config.putInt(Config.ROOM_CONFIG_FENGDING_SCORE, 0);
		}
		else {
			int fengding_score = this.config.getInt(Config.ROOM_CONFIG_FENGDING_SCORE);
			if (fengding_score == 0)
			{
				this.fengdingScore = 0;
			}
			else if (fengding_score == 1)
			{
				this.fengdingScore = 35;
			}
			else if (fengding_score == 2)
			{
				this.fengdingScore = 40;
			}
			else if (fengding_score == 3)
			{
				this.fengdingScore = 45;
			}
		}

		if (!this.config.containsKey(Config.ROOM_CONFIG_PIAO_NIAO))
		{
			this.config.putBoolean(Config.ROOM_CONFIG_PIAO_NIAO, 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_LAIZI4_HU))
		{
			this.config.putBoolean(Config.ROOM_CONFIG_LAIZI4_HU, false);
		}

		if (!this.config.containsKey(Config.ROOM_CONFIG_NIAO_OPT_SCORE))
		{
			this.config.putInt(Config.ROOM_CONFIG_NIAO_OPT_SCORE, 1);
		}

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

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

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

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

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

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

		//this.config.putBoolean(Config.ROOM_CONFIG_DIANPAO, true);
		//this.config.putBoolean(Config.ROOM_CONFIG_HONGZHONG, false);
		this.config.putBoolean(Config.ROOM_CONFIG_NONEALL, false);
		//this.config.putBoolean(Config.ROOM_CONFIG_ZHUANGXIAN, false);
		this.config.putInt(Config.ROOM_CONFIG_QG_TYPE, 0); //no use
		this.config.putInt(Config.ROOM_CONFIG_NIAO_SCORE, 0); //no use
		if(!this.config.containsKey(Config.ROOM_CONFIG_HZ_HU)) {
			this.config.putBoolean(Config.ROOM_CONFIG_HZ_HU,false);
		}
		this.niao_score = 2;
		if(this.config.getInt(Config.ROOM_CONFIG_NIAO) > 0) {
			int opt = this.config.getInt(Config.ROOM_CONFIG_NIAO_OPT_SCORE);
			if(opt==2)this.niao_score = 1;
		}

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

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

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

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

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

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

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

		if (!this.config.containsKey(Config.ROOM_CONFIG_DI_FEN))
		{
			this.config.putInt(Config.ROOM_CONFIG_DI_FEN, 0);
			this.di_fen = 2;
		}
		else {
			int di_index = this.config.getInt(Config.ROOM_CONFIG_DI_FEN);
			if (di_index == 0)
			{
				this.di_fen = 2;
			}
			else if (di_index == 1)
			{
				this.di_fen = 4;
			}
			else if (di_index == 2)
			{
				this.di_fen = 6;
			}
			else if (di_index == 3)
			{
				this.di_fen = 8;
			}
		}

	//	this.entrustTime = this.config.getInt("tuoguan_active_time") * 60000;
	//	this.openEntrust = this.entrustTime >  0;
	//	this.entrusResultType = this.config.getInt("tuoguan_result_type");
		this.isEntrust=true;
		this.adminSeat = 0;
	}

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

	}

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

			EXScore exscore = (EXScore) destPlayer.score;
			EXScore.HUScore hu_score = exscore.getHuScore(fromPlayer);
			if (hu_score == null) {
				hu_score = new EXScore.HUScore();
				hu_score.player = fromPlayer;
				exscore.hu_score.add(hu_score);
			}

			hu_score.score += score;
		}
		else if (type == EXScore.NIAO)
		{
			EXScore exscore = (EXScore) destPlayer.score;
			EXScore.HUScore hu_score = exscore.getHuScore(fromPlayer);
			if (hu_score == null) {
				hu_score = new EXScore.HUScore();
				hu_score.player = fromPlayer;
				exscore.hu_score.add(hu_score);
			}

			hu_score.niao_score += score;
		}

		if (type == EXScore.WIN || type == EXScore.NIAO) {
			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 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 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();
			fromPlayer.niaoCount ++;
			addNiaoScore(destPlayer, fromPlayer, score);
		}
	}
	
	public void addPiaoNiaoScore(EXPlayer destPlayer, EXPlayer fromPlayer) {
		boolean piao_niao = this.config.getBoolean(Config.ROOM_CONFIG_PIAO_NIAO);
		if (piao_niao == false) return;

		this.addScore(destPlayer, fromPlayer,destPlayer.piaoNiao + fromPlayer.piaoNiao , EXScore.PIAO_NIAO);
	}
	
	public void addAllPiaoNiaoScore(EXPlayer destPlayer) {
		boolean piao_niao = this.config.getBoolean(Config.ROOM_CONFIG_PIAO_NIAO);
		if (piao_niao == false) return;

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

	private int getNiaoNum(int card, boolean isDianPao) {
		int niao_num = 0;
		int niao = this.config.getInt(Config.ROOM_CONFIG_NIAO);
		switch (niao) {
		case Config.NIAO_TYPE_159:

			int opt = this.config.getInt(Config.ROOM_CONFIG_NIAO_OPT);
			niao_num = opt * 2;

			break;
		case Config.NIAO_TYPE_ALL:
			niao_num = 1;
			break;
		case Config.NIAO_TYPE_WOWO:
			int tem = card % 100;
			niao_num = (card == Config.HONGZHONG) ? 10 : tem;
			break;
		}
		return niao_num;
	}

	public void niao_tongPao(int card) {
		EXPlayer dianPaoPlayer = (EXPlayer) this.playerMapBySeat.get(this.activeSeat);
		__zhuaNiao(dianPaoPlayer, getNiaoNum(card, false));
		List<EXPlayer> winPlayerList = new ArrayList<EXPlayer>();
		for (Entry<Integer, Player> entry : this.playerMapById.entrySet()) {
			Player player = entry.getValue();
			if (player.winer == 1) {
				((EXPlayer)player).niaoCount = 0;
				winPlayerList.add((EXPlayer) player);
			}
		}
		for (CardNiao cn : niao) {
			boolean not_niao = true;
			if (dianPaoPlayer.playerid == cn.playerId) {
				for (EXPlayer winer : winPlayerList) {
					int score = cn.score;
					if(Global.gameId != 1&&winer.winType == 1)
						score = score * (maxPlayers - 1);
					winer.niaoCount ++;
					this.addNiaoScore(winer, dianPaoPlayer, score);
				}
				not_niao = false;
			} else {
				for (EXPlayer winer : winPlayerList) {
					if (winer.playerid == cn.playerId) {
						int score = cn.score;
						if (Global.gameId != 1&&winer.winType == 1)
							score = score * (maxPlayers - 1);
						this.addNiaoScore(winer, dianPaoPlayer, score);
						not_niao = false;
						winer.niaoCount ++;
						break;
					}
				}
			}
			if (not_niao)
				cn.score = 0;
		}
		boolean none_all = this.config.getBoolean(Config.ROOM_CONFIG_NONEALL);
		if(none_all) {
			for (EXPlayer winer : winPlayerList) {
				if(winer.niaoCount == 6 ||winer.niaoCount == 0) {
					this.addNiaoScore(winer, dianPaoPlayer, niao_score*6);
				}
			}
		}
		
		EXMainServer.gameCtr.sendNiaoEvt(dianPaoPlayer, dianPaoPlayer.seat);
	}

	public void niao_dianPao(EXPlayer owner, int card) {
//		boolean wuguijiabei = this.config.getBoolean(Config.ROOM_CONFIG_WUGUI_JIABEI);
//		if (wuguijiabei && this.config.getBoolean(Config.ROOM_CONFIG_HONGZHONG)) {
//			if (owner.winType != 1 && Util.cardNum(Config.HONGZHONG, owner.cardInhand) <= 0) {
//			    return;
//			}
//		}
		EXPlayer dianPaoPlayer = (EXPlayer) this.playerMapBySeat.get(this.activeSeat);
		EXPlayer winer = owner;
		int num = getNiaoNum(card, true);
		boolean hongzhong = Util.checkCard(Config.HONGZHONG, owner.cardInhand);
		int jm_num = config.getInt(Config.ROOM_CONFIG_JIANGMA);
		if(card!=Config.HONGZHONG&&!hongzhong&&jm_num>0) {
			num +=jm_num;
		}
		__zhuaNiao(winer, num);
		winer.niaoCount = 0;
		for (CardNiao cn : niao) {
			if (cn.playerId == winer.playerid || dianPaoPlayer.playerid == cn.playerId) {
				int score = cn.score;
				if(Global.gameId != 1&&owner.winType == 1)
					score = score * (maxPlayers - 1);
				winer.niaoCount ++;
				this.addNiaoScore(winer, dianPaoPlayer, score);
			} else {
				cn.score = 0;
			}
		}
		boolean none_all = this.config.getBoolean(Config.ROOM_CONFIG_NONEALL);
		if(none_all) {
			if(winer.niaoCount == 6 ||winer.niaoCount == 0) {
				this.addNiaoScore(winer, dianPaoPlayer, niao_score*6);
			}
		}
		EXMainServer.gameCtr.sendNiaoEvt(winer, winer.seat);
	}

	public void niao_selfWin(EXPlayer owner, int card) {
		if (this.config.getInt(Config.ROOM_CONFIG_NIAO) == 0) {
			return;
		}
		int num = getNiaoNum(card, false);
		boolean hongzhong = Util.checkCard(Config.HONGZHONG, owner.cardInhand);
		int jm_num = config.getInt(Config.ROOM_CONFIG_JIANGMA);
		if(card!=Config.HONGZHONG&&!hongzhong&&jm_num>0) {
			num +=jm_num;
		}
		__zhuaNiao(owner, num);
		for (Entry<Integer, Player> entry : owner.room.playerMapById.entrySet()) {
			((EXPlayer)entry.getValue()).niaoCount = 0;
		}
		boolean jiabei = false;
//		boolean wuguijiabei = this.config.getBoolean(Config.ROOM_CONFIG_WUGUI_JIABEI);
//		if (wuguijiabei && this.config.getBoolean(Config.ROOM_CONFIG_HONGZHONG)) {
//			if (Util.cardNum(Config.HONGZHONG, owner.cardInhand) <= 0) {
//				jiabei = true;
//			}
//		}
		for (CardNiao cn : niao) {
			boolean not_niao = true;
			if (cn.playerId == owner.playerid) {
				if (jiabei)
				{
					this.addAllNiaoScore(owner, cn.score * 2);
				}
				else {
					this.addAllNiaoScore(owner, cn.score);
				}
				not_niao = false;
			} else {
				for (Entry<Integer, Player> entry : owner.room.playerMapById.entrySet()) {
					EXPlayer player = (EXPlayer) entry.getValue();
					if (player.playerid == cn.playerId) {
						player.niaoCount ++;
						if (jiabei)
						{
							this.addNiaoScore(owner, player, cn.score * 2);
						}
						else {
							this.addNiaoScore(owner, player, cn.score);
						}
						not_niao = false;
						break;
					}
				}
			}
			if (not_niao)
				cn.score = 0;
		}
		boolean none_all = this.config.getBoolean(Config.ROOM_CONFIG_NONEALL);
		if(none_all) {
			for (Entry<Integer, Player> entry : owner.room.playerMapById.entrySet()) {
				EXPlayer player = (EXPlayer) entry.getValue();
				if(player.niaoCount == 6 ||player.niaoCount == 0) {
					if (jiabei)
					{
						this.addNiaoScore(owner, player, niao_score*6*2);
					}
					else {
						this.addNiaoScore(owner, player, niao_score*6);
					}
				}
			}
		}
//		for (OpCard opcard : owner.opCardList) {
//		    if (opcard.type == RuleWeight.TYPE_SELF_KONG)
//			{
//				this.addAllScore(owner, 3, EXScore.KONG);
//			}
//		    else if (opcard.type == RuleWeight.TYPE_KONG && opcard.seat == 0)
//			{
//				this.addAllScore(owner, 3, EXScore.KONG);
//			}
//		    else if (opcard.type == RuleWeight.TYPE_KONG && opcard.seat > 0)
//			{
//				EXPlayer activePlayer =  (EXPlayer)this.playerMapBySeat.get(opcard.seat);
//				if (activePlayer != null)
//				{
//					this.addScore(owner,activePlayer, 3,EXScore.KONG);
//				}
//			}
//		}
		EXMainServer.gameCtr.sendNiaoEvt(owner, owner.seat);
	}

	private final void __zhuaNiao(EXPlayer owner, int niao_num) {
		this.niao.clear();

		boolean niao_all = config.getInt(Config.ROOM_CONFIG_NIAO) == Config.NIAO_TYPE_ALL;
		for (int index = 0; index < niao_num; index++) {
			if (card.cardList.size() == 0) {
				break;
			}

			int card = this.card.pop();
			CardNiao cn = new CardNiao();
			cn.card = card;
			this.niao.add(cn);
			int tem = card % 100;
			if (niao_all) {
				cn.playerId = owner.playerid;
				if (card == Config.HONGZHONG || (Global.gameId == 1 &&tem == 1)) {
					cn.score = 10;
				} else {
					cn.score = tem;
				}
			} else {
				if (card == Config.HONGZHONG || tem == 1 || tem == 5 || tem == 9) {
					cn.playerId = owner.playerid;
					cn.score = niao_score;
				}
			}
		}

	}

	public void winCallback(EXPlayer owner, int card) {
		if (this.winCount >= this.actionList.size()) {
			if (actionList.size() > 1) {
				this.bankerSeat = this.activeSeat;
				niao_tongPao(card);
			} else {
				niao_dianPao(owner, card);
			}

			this.endGame();
		}
	}

	@Override
	public void endGame() {
		boolean fengding = this.config.getBoolean(Config.ROOM_CONFIG_FENGDING);
		for (Entry<Integer, Player> entry : this.playerMapById.entrySet()) {
			EXPlayer player = (EXPlayer) entry.getValue();
			if (player.winer == 1) {
				List<EXScore.HUScore> list = ((EXScore) player.score).hu_score;
				for (EXScore.HUScore hu_score : list) {
					int hu_num = hu_score.score;
					int niao_num = hu_score.niao_score;
					int sum_score = hu_num + niao_num;
					EXPlayer destPlayer = player;
					EXPlayer fromPlayer = hu_score.player;

					destPlayer.score.round_log.put(EXScore.WIN, destPlayer.score.round_log.get(EXScore.WIN) + hu_num);
					fromPlayer.score.round_log.put(EXScore.WIN, fromPlayer.score.round_log.get(EXScore.WIN) - hu_num);
					destPlayer.score.round_log.put(EXScore.NIAO, destPlayer.score.round_log.get(EXScore.NIAO) + niao_num);
					fromPlayer.score.round_log.put(EXScore.NIAO, fromPlayer.score.round_log.get(EXScore.NIAO) - niao_num);
					//if (fengding) {
					//	if (sum_score > Config.FENGDING_SCORE) {
					//		sum_score = Config.FENGDING_SCORE;
					//		player.fengding = true;
					//	}
					//}
					if (fengding && this.fengdingScore > 0)
					{
						if (sum_score > this.fengdingScore) {
							sum_score = this.fengdingScore;
							player.fengding = true;
						}
					}
					destPlayer.score.round_score += sum_score;
					destPlayer.score.total_score += sum_score;
					fromPlayer.score.round_score -= sum_score;
					fromPlayer.score.total_score -= sum_score;
				}
			}
		}
		((EXPlayBack)this.playBackData).addResultData(EXMainServer.gameCtr.getRoomResultData(this));
		super.endGame();
	}

//	public void settleRound() {
//		saveMilitaryRound(playBackData.getData());
//		boolean total = this.round >= this.maxRound;
//		if(this.entrusResultType ==EXRoom.ENTRUST_CURREN_RESULT) {
//			for (Entry<Integer, Player> entry : this.playerMapById.entrySet()) { 
//				if(entry.getValue().isEntrust()) {
//					total = true;
//					break;
//				}
//			}
//		}
//		if (!total)
//			EXMainServer.gameCtr.roomResult(this);
//		else {
//			this.saveMilitaryTotal(false);
//		}
//		this.stateMachine.changeState(Global.getState(EXRoomRoundSettleState.class));
//		this.winCount = 0;
//		
//		
//		if (total) {
//			this.stateMachine.changeState(Global.getState(RoomDestoryGameState.class));
//			return;
//		}
//	}

	@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.niao_fen = 2;
		this.di_fen = 2;
		this.fengdingScore = 0;
	}

}
