|
- local PKDef = PKFramework.PKImport("pk_base.luaScript.PKDef")
- local PKCmd = PKFramework.PKImport("pk_base.luaScript.Protocol.PKCmd")
- local PKMessage=PKFramework.PKImport("pk_base.luaScript.Protocol.PKMessage")
- local PKFuc = PKFramework.PKImport("pk_base.luaScript.PKFunctions")
-
- local Room = class("Room" , require("luaScript.Protocol.ProtocolRoomBase"))
-
- function Room:initRoomInfo()
- -- 房间信息
- self.roomInfo = PKMessage.RoomInfoLocal:new()
-
-
- self.seatShowList = {}
- --记录离线uid
- self.offLineUid = {}
- --记录离线时间
- self.offLineTime = {}
-
- self:resetDismissData()
- --手牌数据
- self.cards = {}
- end
-
- function Room:resetDismissData()
- --玩家解散数据(userId 为Key,解散类型为value)
- self.dismissInfo = {}
- --解散总时间
- self.roomInfo.nDismissToTalTime = nil
- -- 解散倒计时
- self.roomInfo.nDismissStateTime = nil
- -- 解散显示
- self.roomInfo.nShowDismiss = false
- end
-
- -- 游戏正式开始
- function Room:onGameStartResponse(status, response)
- logD("-------------------- 新的一局开始了 ------------------------")
- if not self.roomInfo then
- logD("self.roomInfo no exist,容错处理!")
- return
- end
-
- logD("Room:onGameStartResponse(), ", table.tostring(response))
- for k,v in pairs(response) do
- self.roomInfo[k] = v;
- end
-
- -- 清空上一局的手牌信息
- self.cards = {}
-
- -- 发送广播通知,游戏开始了
- self:dispatchEvent({name = PKDef.PKEvent.OnGameStartResponse});
- end
-
- -- 游戏状态更新
- function Room:onGameUpdateStatus(status, response)
- logD("--------------------游戏状态更新------------------------")
- if not self.roomInfo then
- logD("self.roomInfo no exist,容错处理!")
- return
- end
-
- logD("Room:onGameUpdateStatus(), ", table.tostring(response))
-
- for k,v in pairs(response) do
- self.roomInfo[k] = v;
- end
-
- -- 发送广播通知,游戏开始了
- self:dispatchEvent({name = PKDef.PKEvent.OnGameUpdateStatus});
- end
-
- function Room:onBaoPaiStartBroad(status, response)
- logD("--------------------服务器依次广播通知玩家爆牌操作------------------------")
- if not self.roomInfo then
- logD("self.roomInfo no exist,容错处理!")
- return
- end
-
- logD("Room:onBaoPaiStartBroad(), ", table.tostring(response))
-
- -- 发送广播通知,游戏开始了
- self:dispatchEvent({name = PKDef.PKEvent.OnBaoPaiStartBroad,response = response});
- end
-
- --只有错误的时候才返回
- function Room:onBaoPaiResponse(status, response)
- logD("--------------------服务器依次广播通知玩家包牌操作------------------------")
- if not self.roomInfo then
- logD("self.roomInfo no exist,容错处理!")
- return
- end
-
- logD("Room:onBaoPaiResponse(), ", table.tostring(response))
-
- -- 发送广播通知,游戏开始了
- self:dispatchEvent({name = PKDef.PKEvent.OnBaoPaiResponse,response = response});
- end
-
- -- 游戏发牌结果
- function Room:onGameSendCardResponse(status, response)
- logD("-------------------- 游戏发牌 ------------------------")
- if not self.roomInfo then
- logD("self.roomInfo no exist,容错处理!")
- return
- end
-
- logD("Room:onGameSendCardResponse(), ", table.tostring(response))
-
- --目前server只发自己过来,后续战绩回放考虑到会发所有玩家来,故以userid为key于扩展
- local cardData = self:getCardList(response.cardList)
- self.roomInfo.memberList[response.nUserId].cardList = cardData
- self.cards[response.nUserId] = cardData
-
- -- 发送广播通知,发牌开始了
- self:dispatchEvent({name = PKDef.PKEvent.OnGameSendCardResponse});
- end
-
- function Room:onGameBankerChange(status, response)
- logD("-------------------- 爆牌庄家变更 ------------------------")
- if not self.roomInfo then
- logD("self.roomInfo no exist,容错处理!")
- return
- end
-
- logD("Room:onGameBankerChange(), ", table.tostring(response))
-
- for k,v in pairs(response) do
- self.roomInfo[k] = v;
- end
-
- self:dispatchEvent({name = PKDef.PKEvent.OnGameBankerChange});
- end
-
- function Room:onPlayerBaoPaiResult(status, response)
- logD("-------------------- 玩家爆牌广播 ------------------------")
- if not self.roomInfo then
- logD("self.roomInfo no exist,容错处理!")
- return
- end
-
- logD("Room:onPlayerBaoPaiResult(), ", table.tostring(response))
-
- self:dispatchEvent({name = PKDef.PKEvent.OnPlayerBaoPaiResult,response = response});
- end
-
- function Room:onBroadCastNoPlayPlayer(status, response)
- logD("-------------------- 玩家爆牌广播 ------------------------")
- if not self.roomInfo then
- logD("self.roomInfo no exist,容错处理!")
- return
- end
-
- logD("Room:onBroadCastNoPlayPlayer(), ", table.tostring(response))
-
- self:dispatchEvent({name = PKDef.PKEvent.OnBroadCastNoPlayPlayer,response = response});
- end
-
- function Room:onBroadCastBankerCallCard(status, response)
- logD("-------------------- 通知庄叫牌 ------------------------")
- if not self.roomInfo then
- logD("self.roomInfo no exist,容错处理!")
- return
- end
-
- logD("Room:onBroadCastBankerCallCard(), ", table.tostring(response))
-
- self:dispatchEvent({name = PKDef.PKEvent.OnBroadCastBankerCallCard,response = response});
- end
-
- function Room:onGameBankerSendCallCardResponse(status, response)
- logD("-------------------- 庄家叫牌结果 ------------------------")
- if not self.roomInfo then
- logD("self.roomInfo no exist,容错处理!")
- return
- end
-
- logD("Room:onGameBankerSendCallCardResponse(), ", table.tostring(response))
-
- self:dispatchEvent({name = PKDef.PKEvent.OnGameBankerSendCallCardResponse,response = response});
- end
-
- function Room:onBroadPlayerOutCard(status,response)
- logD("-------------------- 出牌通知 ------------------------")
- if not self.roomInfo then
- print("容错处理")
- return
- end
- logD("Room:onBroadPlayerOutCard(), response = ", table.tostring(response))
-
- self:dispatchEvent({name = PKDef.PKEvent.OnBroadPlayerOutCard , response = response});
- end
-
- function Room:onOutCardError(status,response)
- logD("-------------------- 出牌错误 ------------------------")
- if not self.roomInfo then
- print("容错处理")
- return
- end
- logD("Room:onOutCardError(), response = ", table.tostring(response))
-
- self:dispatchEvent({name = PKDef.PKEvent.OnOutCardError , response = response});
- end
-
- function Room:onOutCardSuccess(status,response)
- logD("-------------------- 出牌成功 ------------------------")
- if not self.roomInfo then
- print("容错处理")
- return
- end
- logD("Room:onOutCardSuccess(), response = ", table.tostring(response))
-
- self:dispatchEvent({name = PKDef.PKEvent.OnOutCardSuccess , response = response});
- end
-
-
- function Room:onFriendAppear(status,response)
- logD("-------------------- 盟友出现 ------------------------")
- if not self.roomInfo then
- print("容错处理")
- return
- end
- logD("Room:onFriendAppear(), response = ", table.tostring(response))
-
- self.roomInfo.nBankerHelper = response.nBankerHelper;
-
- self:dispatchEvent({name = PKDef.PKEvent.OnFriendAppear});
- end
-
- function Room:onOutCardRanking(status,response)
- logD("-------------------- 出牌成功 ------------------------")
- if not self.roomInfo then
- print("容错处理")
- return
- end
- logD("Room:onOutCardRanking(), response = ", table.tostring(response))
-
-
- self:dispatchEvent({name = PKDef.PKEvent.OnOutCardRanking , response = response});
- end
-
-
- --小局结算
- function Room:onGameXiaoJuResponse(status, response)
- logD("--------------------小局结算 ------------------------")
- if not self.roomInfo then
- logD("self.roomInfo no exist,容错处理!")
- return
- end
-
- for k,v in pairs(response) do
- self.roomInfo[k] = v;
- end
-
- for k,v in pairs(self.roomInfo.playerList) do
- if v.userInfo ~= "" then
- v.userInfo = string.subStringReverse(v.userInfo,"}")
- end
- end
-
- logD("Room:onGameXiaoJuResponse() :", table.tostring(response))
- self:dispatchEvent({name = PKDef.PKEvent.OnGameXiaoJuResponse,response = response});
- end
-
- --大局结算
- function Room:onGameDaJuResponse(status, response)
- logD("-------------------- 大局结算 ------------------------")
- if not self.roomInfo then
- logD("self.roomInfo no exist,容错处理!")
- return
- end
-
- for k,v in pairs(response) do
- self.roomInfo[k] = v;
- end
-
- for k,v in pairs(self.roomInfo.allData) do
- if v.userInfo ~= "" then
- v.userInfo = string.subStringReverse(v.userInfo,"}")
- end
- end
-
- logD("Room:onGameDaJuResponse() :", table.tostring(response))
- self:dispatchEvent({name = PKDef.PKEvent.OnGameDaJuResponse,response = response});
- end
-
- -- 玩家进入桌子成功
- function Room:onSitDownSuccessResponse(status, response)
- logD("--------------------玩家进入桌子成功--------------------")
- logD("Room:onSitDownSuccessResponse(), ", table.tostring(response))
-
- app.net:onMsgClear()
- app.net:onMsgPause()
-
- -- 记录当前桌子号
- self:initRoomInfo()
-
- -- 获取到的房间信息
- self.roomInfo.nShowTableId = response.nShowTableId
- self.roomInfo.nMaxPlayCount = response.nMaxPlayCount
- self.roomInfo.nRoomOwnedUid = response.nRoomOwnedUid
- self.roomInfo.nTotalGameNum = response.nTotalGameNum
- self.roomInfo.strGameInfo = response.strGameInfo
-
- -- 桌子上其他玩家的信息
- for k,v in pairs(response.memberList) do
- self.roomInfo.memberList[v.nUserId] = v
- self.roomInfo.memberList[v.nUserId].userInfo = string.subStringReverse(v.userInfo,"}")
- end
-
- -- 桌子上其他玩家的信息Ex
- if response.memberListEx then
- for k,v in pairs(response.memberListEx) do
- self.roomInfo.memberList[v.nUserId].nOnlineStatus = v.nOnlineStatus
- end
- end
-
- -- 更新椅子号
- self:updateUserSeateShowId()
-
- logD("Room:onSitDownSuccessResponse() roomInfo = ", table.tostring(self.roomInfo))
-
- if PKDef.GameID == 0 then
- showTooltip("您的游戏还未设置gameid")
- end
- -- 发送通知
- self:dispatchEvent({name = PKDef.PKEvent.OnEnterRoomSuccess, gameId = PKDef.GameID, gameType = self.roomInfo.strGameInfo.gamerule})
- end
-
- -- 玩家进入桌子失败
- function Room:onSitDownFailedResponse(status, response)
- logD("--------------------玩家进入桌子失败--------------------")
- app.waitDialogManager:closeWaitNetworkDialog();
- local errorCode = response.nErrorCode
- local errorString = ENTER_ROOM_RET_STR[errorCode] or string.format("坐下失败 errorCode = %s", errorCode);
- showTooltip(errorString);
- end
-
- -- 更新玩家的相对椅子号
- function Room:updateUserSeateShowId()
- local myUserId = self:getMyRecordUserId()
-
- local mySeatId
- self.isOnLooker = false
- if self.isOnLooker then
- mySeatId = 3
- else
- mySeatId = self.roomInfo.memberList[myUserId].nSeatId
- end
-
- self.roomInfo.nUserId = self:getMyRecordUserId()
- self.roomInfo.nSeatId = mySeatId
-
- --[视图椅子号] = userID
- --[座位号] = userID
- --[userID] = 视图椅子号
- self.seatList = {}
- self.userList = {}
- self.seatList = {}
-
- local userCount=self.roomInfo.nMaxPlayCount or 4
- for k,v in pairs(self.roomInfo.memberList) do
- local currentSeatID = v.nSeatId
- local num = (v.nSeatId - mySeatId + userCount) % userCount
- num = num + 1
- local nSeatShowId = PKDef.VIEW_CONFIG[userCount][num]
- self.seatShowList[nSeatShowId] = v.nUserId
- self.seatList[v.nSeatId] = v.nUserId
- self.userList[v.nUserId] = nSeatShowId
- end
-
- logD("User:updateUserSeateShowId(), seatShowList", table.tostring(self.seatShowList))
- logD("User:updateUserSeateShowId(),seatList ", table.tostring(self.seatList))
- logD("User:updateUserSeateShowId(),userList ", table.tostring(self.userList))
- end
-
- -- 服务器下发玩家的准备状态
- function Room:onUserReadyResponse(status, response)
- logD("Room:onUserReadyResponse(), ", table.tostring(response))
- if not self.roomInfo then
- logD("self.roomInfo no exist,容错处理!")
- return
- end
- local nUserId = response.nUserId
-
- local memberInfo = self.roomInfo.memberList[nUserId]
-
- --标记准备了
- if memberInfo then
- memberInfo.nPlayerFlag = PKDef.USER_STATE.READY
- end
-
- self:dispatchEvent({name = PKDef.PKEvent.OnUserReadyResponse});
- end
-
- -- 我发起请求解散房间
- function Room:requestDismissRoom(opType)
- --1: 表示发起解散 2:同意解散 3:不同意解散
- local request = PKMessage.DismissRequest:new()
- request.operateType = opType
- self:sendResponse{cmd = PKCmd.GAME_COMMAND_DISBAND_GAME , sender = request};
- end
-
- function Room:requestBaoPai(opType)
- local request = PKMessage.BaoPai:new()
- request.opType = opType
- self:sendResponse{cmd = PKCmd.GAME_COMMAND_BAO_PAI , sender = request};
- end
-
- function Room:requestCallCard(card)
- local request = PKMessage.GameBankerSendCallCard:new()
- request.card = card
- self:sendResponse{cmd = PKCmd.GAME_COMMAND_SEND_CODE_RESPONSE , sender = request};
- end
-
- function Room:requestSendOutCard(opType,cards,cardsEx)
- local request = PKMessage.OutCard:new()
- request.opType = opType
- for _,v in ipairs(cards) do
- table.insert(request.cards.Datas, v)
- end
- for _,v in ipairs(cardsEx) do
- table.insert(request.cardsEx.Datas, v)
- end
- logD("requestSendOutCard :",table.tostring(request))
- self:sendResponse{cmd = PKCmd.GAME_COMMAND_OUT_CARD , sender = request};
- end
-
- --8012
- function Room:onDismissResponse(status, response)
- if not self.roomInfo then
- logD("self.roomInfo no exist,容错处理!")
- return
- end
-
- local nUserId = response.nUserId
- local operateType = response.operateType
-
- -- 收到玩家发起请求时,数据重置
- if response.operateType == 1 then
- self:resetDismissData()
- end
-
- --数据记录
- self.dismissInfo[nUserId] = operateType;
- self.roomInfo.nDismissStateTime = response.timeLeft
-
- self:dispatchEvent({name = PKDef.PKEvent.OnDismissResponse, response = response});
- end
-
- -- 发起请求回复 8011
- function Room:onUserDismissResultResponse(status, response)
- logD("User:onUserDismissResultResponse, ", table.tostring(response))
- if not self.roomInfo then
- logD("self.roomInfo no exist,容错处理!")
- return
- end
- logD("30000000--runUserDismissResultResponse")
- if response.errorCode == 1 then
- showTooltip("operateType取值范围不对")
- elseif response.errorCode == 2 then
- showTooltip("当前没人发起解散")
- elseif response.errorCode == 3 then
- showTooltip("已经有人申请解散")
- elseif response.errorCode == 4 then
- showTooltip("用户已经操作过")
- else
- -- 其他玩家的解散状态
- for uid, value in pairs(response.memberList) do
- self.dismissInfo[uid] = value.dismissState
- end
- self:dispatchEvent({name = PKDef.PKEvent.OnDismissResponse, response = response});
- end
- end
-
- -- 其他玩家退出房间
- function Room:onOtherLogoutResponse(status, response)
- logD("Room:onOtherLogoutResponse(), response = ", table.tostring(response))
- if not self.roomInfo then
- logD("self.roomInfo no exist,容错处理!")
- return
- end
- local nUserId = response.nUserId
- local nSeatShowId = self.userList[nUserId]
-
- self.roomInfo.nStartGameUid = response.nStartGameUid
-
- logD("30000000--runOtherLogoutResponse")
- self:dispatchEvent({name = PKDef.PKEvent.OnOtherLogoutResponse, nUserId = nUserId, nSeatShowId = nSeatShowId});
- end
-
- -- 其他玩家进入桌子
- function Room:onOtherSitDownResponse(status, response)
- logD("Room:onOtherSitDownResponse(), response = ", table.tostring(response))
- if not self.roomInfo then
- logD("self.roomInfo no exist,容错处理!")
- return
- end
-
- local other = PKMessage.RoomMemberInfo:new()
- other.nUserId = response.nUserId
- other.nSeatId = response.nSeatId
- other.userInfo = response.userInfo
- other.nTotalScore = response.nTotalScore
- other.nPlayerFlag = response.nPlayerFlag
- other.nOnlineStatus = 1
-
- local memberList = self.roomInfo.memberList
-
- -- 添加其他玩家的用户ID
- if memberList[other.nUserId] then
- memberList[other.nUserId] = other:updateTo(memberList[other.nUserId])
- else
- memberList[other.nUserId] = other
- end
-
- -- 更新椅子号
- self:updateUserSeateShowId()
-
- local nSeatShowId = self.userList[other.nUserId]
-
- --检测GPS
- self:updateGpsUserInfo(response.nUserId,true)
-
- -- 发送广播通知,某个位置有人坐下了
- self:dispatchEvent({name = PKDef.PKEvent.OnOtherSitDownResponse, nSeatShowId = nSeatShowId});
- end
-
- function Room:onUserExitResponse(status, response)
- logD("Room:onUserExitResponse(), ", table.tostring(response))
- if not self.roomInfo then
- logD("self.roomInfo no exist,容错处理!")
- return
- end
-
- local ttExtInfo = string.split(response.userInfo, ",")
- app.user.loginInfo.historyCardNum = ttExtInfo[1];
- app.user.loginInfo.curCardNum = ttExtInfo[2];
-
- self:dispatchEvent({name = PKDef.PKEvent.OnUserExitResponseRoom,response = response});
- end
-
- --断线重连
- function Room:onGameReconnection(status,response)
- logD("===============重连成功,清空之前所有存在的队列==================")
-
- app.net:onMsgClear()
- app.net:onMsgPause()
- logD("Room:onGameReconnection(), response = ", table.tostring(response))
- self:initRoomInfo();
-
- -- 获取到的房间信息
- self.roomInfo.nMaxPlayCount = response.nMaxPlayCount
- self.roomInfo.nRoomOwnedUid = response.nRoomOwnedUid
- self.roomInfo.nStartGameUid = response.nStartGameUid
- self.roomInfo.nGameStartCount = response.nGameStartCount
- self.roomInfo.nTotalGameNum = response.nTotalGameNum
- self.roomInfo.strGameInfo = response.strGameInfo
- self.roomInfo.bUserDisbandGame = response.bUserDisbandGame
- self.roomInfo.nStatus = response.nStatus
- self.roomInfo.disBandTimeOut = response.disBandTimeOut
- self.roomInfo.nShowTableId = response.nShowTableId
- self.roomInfo.cAskCard = response.cAskCard
- self.roomInfo.nBankerUserId = response.nBankerUserId
- self.roomInfo.bFriendAppear = response.bFriendAppear
- self.roomInfo.nBankerHelper = response.nBankerHelper
- self.roomInfo.GetOpUid = response.GetOpUid
- self.roomInfo.cardType = response.cardType
- self.roomInfo.cardList = response.cardList
- self.roomInfo.arrayTableInfo = response.arrayTableInfo
- self.roomInfo.currentUserId = response.currentUserId
- self.roomInfo.opType = response.opType
- self.roomInfo.noCards = response.noCards
- self.roomInfo.curOpType = response.curOpType
- self.roomInfo.opTypeTime = response.opTypeTime
- self.roomInfo.bUserFastStartGame = response.bUserFastStartGame
- self.roomInfo.nFastStartTimeOut = response.nFastStartTimeOut
- self.roomInfo.fastStartPlayerInfos = response.fastStartPlayerInfos
- self.roomInfo.playerTuoGuanState = response.playerTuoGuanState
- self:addReconnectionData(response)
-
-
- --[[ if self.roomInfo.offLineInfo and next(self.roomInfo.offLineInfo) ~= nil then
- for i,v in pairs(self.roomInfo.offLineInfo) do
- if v.extInfo then
- local extIf = json.decode(v.extInfo)
- if extIf.OffTime and v.nUserId then
- self.offLineTime[v.nUserId] = extIf.OffTime
- end
- end
- end
- end--]]
-
- --[[if app.club_php.clubID and app.club_php.clubID ~= 0 and self.roomInfo.nGameStartCount > 0 then
- app.club_php:getClubList();
- end--]]
-
- -- 桌子上其他玩家的信息
- for k,v in pairs(response.arrayTableInfo) do
- if not self.roomInfo.memberList[v.nUserId] then
- self.roomInfo.memberList[v.nUserId] = {}
- end
- self.roomInfo.memberList[v.nUserId].nUserId = v.nUserId
- self.roomInfo.memberList[v.nUserId].nSeatId = v.nSeatId
- self.roomInfo.memberList[v.nUserId].nPlayerFlag = v.nPlayerFlag
- if v.userInfo ~= "" then
- self.roomInfo.memberList[v.nUserId].userInfo = string.subStringReverse(v.userInfo,"}")
- end
- self.roomInfo.memberList[v.nUserId].nTotalScore = v.nTotalScore
- self.roomInfo.memberList[v.nUserId].nOnlineStatus = v.nOnlineStatus
- --这里只记录,暂时没用到。可能战绩回放的时候是需要用的
- logD(table.tostring(v.handCardList))
- self.roomInfo.memberList[v.nUserId].cardList = {}
- self.roomInfo.memberList[v.nUserId].cardList = self:getCardList(v.handCardList)
-
- end
-
- local myUserId = self:getMyRecordUserId()
- for i,v in pairs(self.roomInfo.memberList) do
- if self.roomInfo.nBankSeatId == v.nSeatId then
- self.roomInfo.memberList[myUserId].cardList = v.cardList
- end
- end
-
- --更新自己的数据
- self.cards[myUserId] = self.roomInfo.memberList[myUserId].cardList
-
- print("self.cards[myUserId]:"..table.tostring(self.cards[myUserId]))
-
- -- 更新椅子号
- self:updateUserSeateShowId()
-
- self:updateGpsUserInfo(nil,false)
-
- local jsonInfo = json.decode(self.roomInfo.strGameInfo)
- -- 发送通知
- self:dispatchEvent({name = PKDef.PKEvent.OnEnterRoomSuccess, gameId = app.gameId, gameType = jsonInfo.gamerule})
- end
-
- function Room:getCardList(serverCardList)
- local tt = {}
- if serverCardList then
- for k,v in ipairs(serverCardList) do
- table.insert(tt,v.card)
- end
- end
- return tt;
- end
-
- function Room:getTableList(serverCardList)
- local tt = {}
- if serverCardList then
- for k,v in ipairs(serverCardList) do
- table.insert(tt,v)
- end
- end
- return tt;
- end
-
-
- --扩展给子类用
- function Room:addReconnectionData(response)
-
- end
-
- --约定俗成解析牌
- --[[
- 思维:
- 服务器排好序后发牌过来,最多有10列,每一列最多有3行;
- 排序按一列算,普通2-3个,串特殊4个。
- 默认3个满一列,串的时候不做任何处理,开局的时候自动串起,之后不会出现4个的情况
- 单张的重建一列,并要求单张列数到达3叠满后才会开启新的一列。
-
- 使用:
- 传入服务器的牌,返回解析后的数组保存到self.cards[用户ID]去,正常发牌,只有自己的牌,断线重连也只有自己的牌,
- 战绩回放的时候,server会返回所有玩家的牌
- ]]
- function Room:serverCardToMyCard(serverCardList)
- --
- --根据定义组合牌
- local cardData = {}
- --每一个组合数据
- local singleList = {}
- --单个组合索引
- local index = 1
- --真实索引
- local realIndex = 1
-
- local tt = {}
- for i = 1,10 do
- for k,v in ipairs(serverCardList) do
- local idx = 0
- local tCard = nil
- if not v.opcard then
- tCard = v.card
- else
- tCard = v.opcard
- end
- if tCard > 16 then
- idx = tCard - 16
- else
- idx = tCard
- end
- if i == idx then
- table.insert(tt,v)
- end
- end
- end
- --1 2 da2 4 5 6 7 8 9 10 3
- for k,v in ipairs(tt) do
- --不是单张牌,直接给一列
- if v.type ~= PKDef.SendCardType.SINGLE_CARD then
- if not cardData[realIndex] then
- cardData[realIndex] = {}
- end
- local list,mType = PKFuc.getPKCardList(v.card,v.type)
- cardData[realIndex] = list
- realIndex = realIndex + 1
- else
- if table.nums(singleList) > 0 then
- local isFind = false
- for kSin,kCard in pairsByKeys(singleList) do
- if math.abs(v.card - kCard) <= 1 then
- table.insert(cardData[kSin],v.card)
- isFind = true
- end
- end
- if not isFind then
- singleList[realIndex] = v.card
- cardData[realIndex] = {v.card}
- realIndex = realIndex + 1
- end
- else
- singleList[realIndex] = v.card
- cardData[realIndex] = {v.card}
- realIndex = realIndex + 1
- end
- end
- end
-
- return cardData
- end
-
- --牌排序算法:
- --[[
- @parm:color 1表示小写,2为大写
- @parm:digit 1-10,表示值
- ]]
- function Room:getSendCardLogic(color,digit,mType)
- local list = {}
- if color == 1 then
- list.card = digit
- else
- list.card = digit + 16
- end
-
- list.type = mType
- return list
- end
-
- --服务器排序逻辑,拿来自己写回放排序
- function Room:rankHandCard(tPureHandCards)
- --发牌
- local cardList = {}
- local index = 1
- --大小写1-10,11为总张数
- for digit = 1,10 do
- for color = 1,2 do --纯手牌 color == 1表示小写,2为大写
- if tPureHandCards[color][digit] ~= 0 then
- local otherColor
- if color == 1 then
- otherColor = 2
- else
- otherColor = 1
- end
-
- --串小写
- if (tPureHandCards[color][digit] == 4) then
- tPureHandCards[color][digit] = tPureHandCards[color][digit] - 4
- tPureHandCards[color][11] = tPureHandCards[color][11] - 4
-
- cardList[index] = self:getSendCardLogic(color,digit,PKDef.SendCardType.GUN_ZI_FOUR_SAME)
- index = index + 1
- end
-
- --串大写
- if (tPureHandCards[otherColor][digit] == 4) then
- tPureHandCards[otherColor][digit] = tPureHandCards[otherColor][digit] - 4
- tPureHandCards[otherColor][11] = tPureHandCards[otherColor][11] - 4
-
- cardList[index] = self:getSendCardLogic(otherColor,digit,PKDef.SendCardType.GUN_ZI_FOUR_SAME)
- index = index + 1
- end
-
- --哨小写
- if (tPureHandCards[color][digit] == 3) then
- tPureHandCards[color][digit] = tPureHandCards[color][digit] - 3
- tPureHandCards[color][11] = tPureHandCards[color][11] - 3
-
- cardList[index] = self:getSendCardLogic(color,digit,PKDef.SendCardType.KAN_THREE_SAME)
- index = index + 1
- end
-
- --哨大写
- if (tPureHandCards[otherColor][digit] == 3) then
- tPureHandCards[otherColor][digit] = tPureHandCards[otherColor][digit] - 3
- tPureHandCards[otherColor][11] = tPureHandCards[otherColor][11] - 3
-
- cardList[index] = self:getSendCardLogic(otherColor,digit,PKDef.SendCardType.KAN_THREE_SAME)
- index = index + 1
- end
-
- --二七十
- if(digit == 2) then
- if(tPureHandCards[color][7] <= 1 and tPureHandCards[color][10] <= 1) then
- if(tPureHandCards[color][2] == 1 and tPureHandCards[color][7] == 1 and tPureHandCards[color][10] == 1 )then
- --cardModel.push_back(GetModelTwoSevenTen(make_card(color,digit)))
- tPureHandCards[color][2] = tPureHandCards[color][2] - 1
- tPureHandCards[color][7] = tPureHandCards[color][7] - 1
- tPureHandCards[color][10] = tPureHandCards[color][10] - 1
- tPureHandCards[color][11] = tPureHandCards[color][11] - 3
-
- cardList[index] = self:getSendCardLogic(color,digit,PKDef.SendCardType.TWO_SEVEN_TEN)
- index = index + 1
- end
- end
- if(tPureHandCards[otherColor][7] <= 1 and tPureHandCards[otherColor][10] <= 1) then
- if(tPureHandCards[otherColor][2] == 1 and tPureHandCards[otherColor][7] == 1
- and tPureHandCards[otherColor][10] == 1 ) then
- --cardModel.push_back(GetModelTwoSevenTen(make_card(otherColor,digit)))
- tPureHandCards[otherColor][2] = tPureHandCards[otherColor][2] - 1
- tPureHandCards[otherColor][7] = tPureHandCards[otherColor][7] - 1
- tPureHandCards[otherColor][10] = tPureHandCards[otherColor][10] - 1
- tPureHandCards[otherColor][11] = tPureHandCards[otherColor][11] - 3
- cardList[index] = self:getSendCardLogic(otherColor,digit,PKDef.SendCardType.TWO_SEVEN_TEN)
- index = index + 1
- end
- end
-
- end
-
- --一句话
- if(digit+2 <= 10 and tPureHandCards[color][digit] == 1 and tPureHandCards[color][digit+1] == 1
- and tPureHandCards[color][digit+2] == 1) then
- tPureHandCards[color][digit] = tPureHandCards[color][digit] - 1
- tPureHandCards[color][digit+1] = tPureHandCards[color][digit+1] - 1
- tPureHandCards[color][digit+2] = tPureHandCards[color][digit+2] - 1
- tPureHandCards[color][11] = tPureHandCards[color][11] - 3
-
- cardList[index] = self:getSendCardLogic(color,digit,PKDef.SendCardType.SHUN_ZI)
- index = index + 1
- end
- --一句话
- if(digit+2 <= 10 and tPureHandCards[otherColor][digit] == 1 and tPureHandCards[otherColor][digit+1] == 1
- and tPureHandCards[otherColor][digit+2] == 1) then
- tPureHandCards[otherColor][digit] = tPureHandCards[otherColor][digit] - 1
- tPureHandCards[otherColor][digit+1] = tPureHandCards[otherColor][digit+1] - 1
- tPureHandCards[otherColor][digit+2] = tPureHandCards[otherColor][digit+2] - 1
- tPureHandCards[otherColor][11] = tPureHandCards[otherColor][11] - 3
-
- cardList[index] = self:getSendCardLogic(otherColor,digit,PKDef.SendCardType.SHUN_ZI)
- index = index + 1
- end
-
-
- if(tPureHandCards[color][digit] >= 2 and tPureHandCards[otherColor][digit] == 1) then --大大小搭子
- --cardModel.push_back(GetModelDaZiByMix(make_card(color,digit)))
- tPureHandCards[color][digit] = tPureHandCards[color][digit] - 2
- tPureHandCards[otherColor][digit] = tPureHandCards[otherColor][digit] - 1
- tPureHandCards[color][11] = tPureHandCards[color][11] - 2
- tPureHandCards[otherColor][11] = tPureHandCards[otherColor][11] -1
-
- cardList[index] = self:getSendCardLogic(otherColor,digit,PKDef.SendCardType.DA_ZI_TWO_AND_ONE)
- index = index + 1
-
- elseif(tPureHandCards[color][digit] == 1 and tPureHandCards[otherColor][digit] >= 2) then --小小大搭子
- --cardModel.push_back(GetModelDaZiBySame(make_card(color,digit)))
- tPureHandCards[color][digit] = tPureHandCards[color][digit] - 1
- tPureHandCards[otherColor][digit] = tPureHandCards[otherColor][digit] - 2
- tPureHandCards[color][11] = tPureHandCards[color][11] - 1
- tPureHandCards[otherColor][11] = tPureHandCards[otherColor][11] - 2
-
- cardList[index] = self:getSendCardLogic(color,digit,PKDef.SendCardType.DA_ZI_TWO_AND_ONE)
- index = index + 1
-
- elseif(tPureHandCards[color][digit] >= 2)then
- --cardModel.push_back(GetModelZhuangZi(make_card(color,digit))) --对子
- tPureHandCards[color][digit] = tPureHandCards[color][digit] - 2
- tPureHandCards[color][11] = tPureHandCards[color][11] - 2
-
- cardList[index] = self:getSendCardLogic(color,digit,PKDef.SendCardType.ZHUANG_ZI)
- index = index + 1
- end
-
-
- --混对(一张大一张小)
- if(tPureHandCards[color][digit] == 1 and tPureHandCards[otherColor][digit] == 1) then
- --cardModel.push_back(GetModelMixZhuangZi(make_card(color,digit)))
- tPureHandCards[color][digit] = tPureHandCards[color][digit] - 1
- tPureHandCards[otherColor][digit] = tPureHandCards[otherColor][digit] - 1
- tPureHandCards[color][11] = tPureHandCards[color][11] - 1
- tPureHandCards[otherColor][11] = tPureHandCards[otherColor][11] - 1
-
- cardList[index] = self:getSendCardLogic(otherColor,digit,PKDef.SendCardType.MIX_ZHUANG_ZI)
- index = index + 1
-
- elseif(tPureHandCards[color][digit] == 1) then --单张
- --IChessModel model
- --model.ichess_type = SINGLE_CARD
- --model.ichess_opCard = make_card(color,digit)
- --model.ichess_cards.push_back(model.ichess_opCard)
-
- --cardModel.push_back(model)
-
- tPureHandCards[color][digit] = tPureHandCards[color][digit] - 1
- tPureHandCards[color][11] = tPureHandCards[color][11] - 1
-
- cardList[index] = self:getSendCardLogic(color,digit,PKDef.SendCardType.SINGLE_CARD)
- index = index + 1
- end
- end
- end
- end
- return cardList
- end
-
- -- 其他玩家是否掉线
- function Room:onOtherDroppedResponse(status, response)
- logD("User:onOtherDroppedResponse(), response = ", table.tostring(response))
- logD("30000000--runOtherDroppedResponse")
- self:dispatchEvent({name = PKDef.PKEvent.OnOtherDroppedResponse, response = response});
- end
-
- -- 通知服务器玩家GPS数据发生变化
- function Room:onGpsChangeRequest()
- print("Room:onGpsChangeRequest()")
-
- local request = StringPacket:new()
- request.stringValue = app.user.userInfo or ""
-
- logD("Room:onGpsChangeRequest()", table.tostring(request))
- self:sendResponse{cmd = PKCmd.GAME_COMMAND_CLIENT_CHANGE_USERINFO , sender = request};
-
- end
-
- -- 服务器下发玩家GPS数据发生变化
- function Room:onServerChangeUserInfo(status, response)
- print("Room:onServerChangeUserInfo()", table.tostring(response))
-
- local nUserId = response.uid
- local memberInfo = self.roomInfo.memberList[nUserId]
- if memberInfo then
- memberInfo.userInfo = response.userInfo
- end
-
- self:dispatchEvent({name = PKDef.PKEvent.OnServerChangeUserInfo, nUserId = nUserId});
- end
-
- function Room:ctor(net)
- Room.super.ctor(self , net);
-
- -------------------------------------------------------------------------常用发送模块-----------------------------------------------------------------------------
- -- 请求准备
- self:defMsgFunc{name = PKDef.PKEvent.CallReadyRequest , cmd = PKCmd.GAME_COMMAND_USER_READY};
- -- 离开房间
- self:defMsgFunc{name = PKDef.PKEvent.CallLeaveRequest , cmd = PKCmd.GAME_COMMAND_USER_LEAVE};
- -- 玩家请求解散房间,获取其他玩家回复解散房间
- self:defMsgFunc{name = PKDef.PKEvent.DismissRoomRequest, cmd = PKCmd.GAME_COMMAND_DISBAND_GAME, sender = PKMessage.DismissRequest};
- -- 客户端发起快速请求
- self:defMsgFunc{name = PKDef.PKEvent.RequestFastsStart, cmd = PKCmd.GAME_COMMAND_REQUEST_GAME_START, sender = PKMessage.GameStartRequest}
-
- -------------------------------------------------------------------------扑克发送模块-----------------------------------------------------------------------------
- --发送包牌
- self:defMsgFunc{name = PKDef.PKEvent.BaoPai,cmd = PKCmd.GAME_COMMAND_BAO_PAI,sender = PKMessage.BaoPai};
- --发送出牌
- self:defMsgFunc{name = PKDef.PKEvent.SendOutCard,cmd = PKCmd.GAME_COMMAND_OUT_CARD,sender = PKMessage.OutCard};
- -- 庄家请求叫牌
- self:defMsgFunc{name = PKDef.PKEvent.SendCallCard,cmd = PKCmd.GAME_COMMAND_SEND_CODE_RESPONSE,sender = PKMessage.GameBankerSendCallCard};
-
- -------------------------------------------------------------------------常用接收模块-----------------------------------------------------------------------------
- -- 玩家进入桌子成功
- self:defPushMsg{cmd = PKCmd.GAME_COMMAND_LOGIN_GAME_SUCCESS, reader = PKMessage.SitDownSuccessResponse, func = handler(self , self.onSitDownSuccessResponse)};
- -- 玩家进入桌子失败
- self:defPushMsg{cmd = PKCmd.GAME_COMMAND_LOGIN_GAME_ERR, reader = PKMessage.SitDownFailedResponse, func = handler(self , self.onSitDownFailedResponse)};
- -- 玩家收到解散房间的请求
- self:defPushMsg{cmd = PKCmd.GAME_COMMAND_BROADCAST_DISBAND_GAME, reader = PKMessage.DismissResponse, func = handler(self , self.onDismissResponse)};
- -- 收到玩家申请解散房间
- self:defPushMsg{cmd = PKCmd.GAME_COMMAND_DISBAND_GAME, reader = PKMessage.DismissResult, func = handler(self , self.onUserDismissResultResponse)};
- -- 其他玩家退出房间
- self:defPushMsg{cmd = PKCmd.GAME_COMMAND_BROADCAST_USER_LOGOUT, reader = PKMessage.OtherLogoutResponse, func = handler(self , self.onOtherLogoutResponse)};
- -- 收到服务器下发的玩家准备状态
- self:defPushMsg{cmd = PKCmd.GAME_COMMAND_BROADCAST_USER_READY, reader = PKMessage.IntPacket, func = handler(self , self.onUserReadyResponse)};
- -- 其他玩家进入桌子
- self:defPushMsg{cmd = PKCmd.GAME_COMMAND_BROADCAST_USER_LOGIN, reader = PKMessage.OtherSitDownResponse, func = handler(self , self.onOtherSitDownResponse)};
- -- 用户退出
- self:defPushMsg{cmd = PKCmd.GAME_COMMAND_LOGOUT_GAME_SUCCESS, reader = PKMessage.UserExitResponse, func = handler(self , self.onUserExitResponse)};
- -- 其他玩家掉线
- self:defPushMsg{cmd = PKCmd.GAME_COMMAND_BROADCAST_USER_DROPPED, reader = PKMessage.OtherDroppedResponse, func = handler(self , self.onOtherDroppedResponse)};
-
- -- 快速开始请求返回
- self:defPushMsg{cmd = PKCmd.GAME_COMMAND_FAST_START_ERROR, reader = PKMessage.FastStartRequestError, func = handler(self, self.onUserRequestFastError)}
- -- 快速开始广播请求
- self:defPushMsg{cmd = PKCmd.GAME_COMMAND_BROAD_FAST_START_GAME, reader = PKMessage.FastStartStatus, func = handler(self, self.onBroadcastFastRequest)}
- -- 快速开始成功
- self:defPushMsg{cmd = PKCmd.GAME_COMMAND_BROAD_QUICKLY_START, reader = PKMessage.UpdateSeatIds, func = handler(self, self.onFastStartSucc)}
- -- 玩家信息改变
- self:defPushMsg{cmd = PKCmd.GAME_COMMAND_SERVER_CHANGE_USERINFO, reader = PKMessage.ServerChangeUserInfo, func = handler(self , self.onServerChangeUserInfo)};
-
- -------------------------------------------------------------------------游戏内接收模块-----------------------------------------------------------------------------
-
- --扑克游戏接受消息:
- --游戏正式开始
- self:defPushMsg{cmd = PKCmd.GAME_COMMAND_BROADCAST_GAME_START, reader = PKMessage.GameStartResponse, func = handler(self , self.onGameStartResponse)};
- --服务器广播游戏状态更新
- self:defPushMsg{cmd = PKCmd.GAME_COMMAND_GAME_UPDATE_STATUS, reader = PKMessage.GameUpdateStatus, func = handler(self , self.onGameUpdateStatus)};
- --服务器依次广播通知玩家爆牌操作
- self:defPushMsg{cmd = PKCmd.GAME_COMMAND_BAO_PAI_RESPONSE_BROAD, reader = PKMessage.BaoPaiStartBroad, func = handler(self , self.onBaoPaiStartBroad)};
- --服务器依次广播通知玩家爆牌操作
- self:defPushMsg{cmd = PKCmd.GAME_COMMAND_BAO_PAI, reader = PKMessage.BaoPaiResponse, func = handler(self , self.onBaoPaiResponse)};
- --发牌
- self:defPushMsg{cmd = PKCmd.GAME_COMMAND_SENDCARD_RESPONSE, reader = PKMessage.GameSendCardResponse,func = handler(self , self.onGameSendCardResponse)};
- --玩家爆牌,庄家变更
- self:defPushMsg{cmd = PKCmd.GAME_COMMAND_ON_BANKER_CHANGE, reader = PKMessage.GameBankerChange,func = handler(self , self.onGameBankerChange)};
- --玩家爆牌选择后广播给其他玩家
- self:defPushMsg{cmd = PKCmd.GAME_COMMAND_BAOPAI_BROAD, reader = PKMessage.PlayerBaoPaiResult,func = handler(self , self.onPlayerBaoPaiResult)};
- --广播不参与游戏玩家id本局游戏有玩家反爆,形成1v1局面,另外两位玩家不参与游戏,协议号:0x8112
- self:defPushMsg{cmd = PKCmd.GAME_COMMAND_BROADCAST_NO_PLAY_PLAYER, reader = PKMessage.BroadCastNoPlayPlayer,func = handler(self,self.onBroadCastNoPlayPlayer)};
- --通知庄家叫牌
- self:defPushMsg{cmd = PKCmd.GAME_COMMAND_BROADCAST_BANKER_CALL_CARD, reader = PKMessage.BroadCastBankerCallCard,func = handler(self,self.onBroadCastBankerCallCard)};
- --庄家叫牌结果
- self:defPushMsg{cmd = PKCmd.GAME_COMMAND_SEND_CODE_RESPONSE, reader = PKMessage.GameBankerSendCallCardResponse,func = handler(self,self.onGameBankerSendCallCardResponse)};
- --通知出牌
- self:defPushMsg{cmd = PKCmd.GAME_COMMAND_BROADCAST_OUT_CARD, reader = PKMessage.BroadPlayerOutCard,func = handler(self,self.onBroadPlayerOutCard)};
- --出牌错误
- self:defPushMsg{cmd = PKCmd.GAME_COMMAND_OUT_CARD, reader = PKMessage.OutCardError,func = handler(self,self.onOutCardError)};
- --出牌success
- self:defPushMsg{cmd = PKCmd.GAME_COMMAND_OUT_CARD_SUCCESS, reader = PKMessage.OutCardSuccess,func = handler(self,self.onOutCardSuccess)};
- --广播盟友现身
- self:defPushMsg{cmd = PKCmd.GAME_COMMAND_FRIEND_APPEAR, reader = PKMessage.FriendAppear,func = handler(self,self.onFriendAppear)};
- --玩家出完牌广播名次
- self:defPushMsg{cmd = PKCmd.GAME_COMMAND_ON_OUTCARD_RANKING, reader = PKMessage.OutCardRanking,func = handler(self,self.onOutCardRanking)};
- --单局结算
- self:defPushMsg{cmd = PKCmd.GAME_COMMAND_GAME_XIAO_JU, reader = PKMessage.GameXiaoJuResponse, func = handler(self , self.onGameXiaoJuResponse)};
- --总结算
- self:defPushMsg{cmd = PKCmd.GAME_COMMAND_GAME_DA_JU, reader = PKMessage.GameDaJuResponse, func = handler(self , self.onGameDaJuResponse)};
- --断线重连
- self:defPushMsg{cmd = PKCmd.GAME_COMMAND_GAME_RECONNECTION,reader = PKMessage.GameReconnection,func = handler(self,self.onGameReconnection)}
- --托管广播
- self:defPushMsg{cmd = PKCmd.GAME_COMMAND_TUOGUAN_RESPONSE, reader = PKMessage.TuoGuanResponse, func = handler(self , self.onTuoGuanResponse)};
- end
-
- --辅助查找
- -- 通过玩家逻辑椅子号找到玩家ID
- function Room:getUserIdBySeatId(seatId)
- return self.seatList[seatId]
- end
-
- -- 通过玩家视图椅子号找到玩家ID
- function Room:getUserIdByViewId(seatShowId)
- return self.seatShowList[seatShowId]
- end
-
- -- 通过玩家ID获取玩家展示的座位号
- function Room:getViewIdByUserId(nUserId)
- return self.userList[nUserId];
- end
-
- -- 通过玩家逻辑椅子号找到视图椅子号
- function Room:getViewIdBySeatId(nSeatId)
- local userid = self:getUserIdBySeatId(nSeatId)
- return self:getViewIdByUserId(userid)
- end
-
- -- 通过玩家视图椅子号找到逻辑椅子号
- function Room:getSeatIdByViewId(nViewId)
- local userid = self:getUserIdByViewId(nViewId)
- for seatId,nUserId in pairs(self.seatList) do
- if userid == nUserId then
- return seatId
- end
- end
- end
-
- -- return table of userInfo, not string
- function Room:getUserInfo(nUserId)
- if self.roomInfo.memberList[nUserId] and self.roomInfo.memberList[nUserId].userInfo then
- return json.decode(self.roomInfo.memberList[nUserId].userInfo)
- else
- return nil
- end
- end
-
- function Room:getMyUserId()
- return self:getUserIdByViewId(PKDef.MyViewID)
- end
-
- --获取自己的ID,API仅限回放使用
- --[[
- 如果自己在里面玩,那么就返回我自己的ID,为第一视角
- 如果是管理员或者其他目的进来查看回放,则以这局玩家最小的ID为第一视角
- ]]
- function Room:getMyRecordUserId()
- local myUserId = app.user.loginInfo.uid
- local minID = 0
- local isFind = false
- for k,v in pairsByKeys(self.roomInfo.memberList) do
- if myUserId == v.nUserId then
- return myUserId
- end
- if not isFind then
- minID = v.nUserId
- isFind = true
- end
- end
- return minID
- end
-
-
- --游戏快速开始,更新玩家座位号
- function Room:onFastStartSucc(status, response)
- self.roomInfo.nMaxPlayCount = #response.playerList
-
- local gameInfo = json.decode(self.roomInfo.strGameInfo)
- gameInfo.playnum = self.roomInfo.nMaxPlayCount
- self.roomInfo.strGameInfo = json.encode(gameInfo)
-
- for _,v in pairs(response.playerList) do
- self.roomInfo.memberList[v.uid].nSeatId = v.nSeatId
- end
-
- --更新椅子号
- self.seatShowList = {}
- self:updateUserSeateShowId()
- self:dispatchEvent({name = PKDef.PKEvent.FastStartSucc, response = response})
- end
-
- --快速开始操作广播 0x8201
- function Room:onBroadcastFastRequest(status, response)
- for _,v in pairs(response.playerList) do
- if response.uid == v.uid then
- v.optType = response.optType
- end
- self.roomInfo.memberList[v.uid].optType = v.optType
- end
-
- self.roomInfo.nleftStartGameTimeout = response.nleftStartGameTimeout
- self:dispatchEvent({name = PKDef.PKEvent.BraodcastFastStart, response = response})
- end
-
- --快速开始请求失败
- function Room:onUserRequestFastError(status, response)--快速开始请求错误提示错误
- local errTxt ={
- [1] = "人数不够",
- [2] = "其他人已请求",
- [3] = "房间人数已满",
- [4] = "非法操作"
- }
- local txt = errTxt[response.result]
- if txt then
- showTooltip(txt)
- end
- end
-
- -- 检查此桌是否有此ID玩家
- function Room:checkUserIDIsInTable(nUserId)
- if nUserId > 0 and self.roomInfo.memberList[nUserId] and self.roomInfo.memberList[nUserId].nSeatId then
- return true
- end
- return false
- end
-
- -- 获取桌子上实际人数
- function Room:getCurMaxPlayer()
- local playernum = 0
- for i,v in pairs(self.roomInfo.memberList) do
- if self:checkUserIDIsInTable(i) then
- playernum = playernum + 1
- end
- end
- return playernum
- end
-
- function Room:sendSpeedStartCmd(opType)
- local request = PKMessage.GameStartRequest:new()
- request.optType = opType
- logD("Room sendSpeedStartCmd" .. table.tostring(request))
- self:sendResponse({cmd = PKCmd.GAME_COMMAND_REQUEST_GAME_START, sender = request})
- end
-
- --更新gps用户数据
- --需要检测的ID 没有则检测所有人的距离
- --isOpenView 危险距离是否主动弹出提示
- function Room:updateGpsUserInfo(userId,isOpenView)
- if self.roomInfo and self.roomInfo.memberList then
- local isGameStart = self.roomInfo.nGameStartCount>0
- --如果是游戏开始后收到消息则不处理
- local userInfoList = {}
- for nUserId, memberInfo in pairs(self.roomInfo.memberList) do
- local nSeatId = memberInfo.nSeatId
- local userInfo = memberInfo.userInfo
- if userInfo then
- local userInfo2 = json.decode(userInfo)
- if userInfo2 then
- userInfoList[nUserId] = {nSeatId = nSeatId, userInfo = userInfo}
- end
- end
- end
-
- if isGameStart then
- isOpenView = false
- end
-
- self:dispatchEvent({
- name = GAME_EVENT.GPS_UPDATE_USER_INFO,
- userId=userId,
- userInfoList = userInfoList,
- isOpenView = false,--isOpenView or false,
- isGameStart = isGameStart,
- -- maxPlayerNum = self.roomInfo.nMaxPlayCount,
- })
- end
- end
-
- -- 申请托管
- function Room:requestTuoGuan(optType)
- local request = PKMessage.sendTuoGuan:new()
- request.entrustType = optType;
- logD("requestTuoGuan",table.tostring(request))
- self:sendResponse{cmd = PKCmd.GAME_COMMAND_REQUEST_TUOGUAN , sender = request};
- end
-
- function Room:onTuoGuanResponse(status, response)
- logD("Room:onTuoGuanResponse(), ", table.tostring(response))
- if not self.roomInfo then
- logD("self.roomInfo no exist,容错处理!")
- return
- end
-
- self:dispatchEvent({name = "onTuoGuanResponse",response = response});
- end
-
- return Room;
|