local ZPDef = ZPFramework.ZPImport("zp_base.luaScript.ZPDef") local ZPCmd=ZPFramework.ZPImport("zp_base.luaScript.Protocol.ZPCmd") local ZPMessage=ZPFramework.ZPImport("zp_base.luaScript.Protocol.ZPMessage") local ZPFuc = ZPFramework.ZPImport("zp_base.luaScript.ZPFunctions") local Room = class("Room" , require("luaScript.Protocol.ProtocolRoomBase")) function Room:initRoomInfo() -- 房间信息 self.roomInfo = ZPMessage.RoomInfoLocal:new() self.seatShowList = {} --记录离线uid self.offLineUid = {} --记录离线时间 self.offLineTime = {} self:resetDismissData() --手牌数据 self.cards = {} self.bGameStart = false 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)) self.roomInfo.nGameStartCount = response.nGameStartCount; self.roomInfo.nTotalGameNum = response.nTotalGameNum; self.roomInfo.nRoomOwnedUid = response.nRoomOwnedUid; self.roomInfo.nBankSeatId = response.nBankSeatId; self.roomInfo.xiaoSeatId = response.xiaoSeatId; --清空上一局胡牌信息 self.roomInfo.hupaiInfo = nil -- 清空上一局的手牌信息 self.cards = {} -- 发送广播通知,游戏开始了 self:dispatchEvent({name = "onGameStartResponse"}); 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)) self.roomInfo.nbankFirstGrabCard = response.nbankFirstGrabCard --目前server只发自己过来,后续战绩回放考虑到会发所有玩家来,故以userid为key于扩展 local cardData = self:serverCardToMyCard(response.cardList) logD("Room:onGameSendCardResponse : "..table.tostring(cardData)) self.roomInfo.memberList[response.nUserId].cardList = cardData self.roomInfo.nbankFirstGrabCard = response.nbankFirstGrabCard self.cards[response.nUserId] = cardData if self:isLittleFamily() then self.roomInfo.nBankUid = response.nUserId self.cards[app.user.loginInfo.uid] = cardData end -- 发送广播通知,发牌开始了 self:dispatchEvent({name = "onGameSendCardResponse"}); end -- 系统发牌后发来的自动提操作 function Room:onSystemOperationStart(status, response) logD("-------------------- 游戏提结果 ------------------------") if not self.roomInfo then logD("self.roomInfo no exist,容错处理!") return end logD("Room:onSystemOperationStart(), ", table.tostring(response)) -- 发送广播通知,游戏开始了 self:dispatchEvent({name = "onSystemOperationStart",response = response}); end -- 广播桌子上所有玩家庄家起手操作 --[[若庄家可以胡牌, 则客户端显示胡牌, 过两个按钮,若不能胡牌,则判断用户是否要出牌, 若能出牌,则显示出牌提示,若庄家既不能胡牌,也不能出牌,客户端无需处理, 此种情况下server会自动跳转到下家抓牌, 强制胡牌的情况下必胡 ]] function Room:onBankerOutCard(status, response) logD("-------------------- 游戏庄家起手操作------------------------") if not self.roomInfo then logD("self.roomInfo no exist,容错处理!") return end self.roomInfo.nBankUid = response.nUserId logD("Room:onBankerOutCard(), ", table.tostring(response)) -- 发送广播通知,游戏开始了 self:dispatchEvent({name = "onBankerOutCard",response = response}); end function Room:onMoPai(status,response) logD("-------------------- 摸牌 ------------------------") if not self.roomInfo then print("容错处理") return end logD("Room:onMoPai(), response = ", table.tostring(response)) self:dispatchEvent({name = "onMoPai" , response = response}); end function Room:onQiPai(status,response) logD("-------------------- 弃牌 ------------------------") if not self.roomInfo then print("容错处理") return end logD("Room:onQiPai(), response = ", table.tostring(response)) self:dispatchEvent({name = "onQiPai",response = response}); end function Room:onOutCardError(status,response) logD("-------------------- 出牌错误 ------------------------") if not self.roomInfo then print("容错处理") return end logD("Room:onOutCardError(), response = ", table.tostring(response)) --[[错误码说明: OUT_CARD_SUCCESS = 0, //正常 OUT_CARD_ON_NEED = 1, //不需要出牌 OUT_CARD_INVALID = 2, //出牌非法--]] local errorCode = response.result if errorCode == ZPDef.OutCardErrorTip.OUT_CARD_SUCCESS then showTooltip("出牌无效") elseif errorCode == ZPDef.OutCardErrorTip.OUT_CARD_SUCCESS then showTooltip("不需要出牌") else showTooltip("出牌未知") end self:dispatchEvent({name = "onOutCardError"}); 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 = "onOutCardSuccess" , response = response}); end --小局结算 function Room:onGameXiaoJuResponse(status, response) logD("--------------------小局结算 ------------------------") if not self.roomInfo then logD("self.roomInfo no exist,容错处理!") return end logD("Room:onGameXiaoJuResponse() :", table.tostring(response)) self:dispatchEvent({name = "onGameXiaoJuResponse",response = response}); end --大局结算 function Room:onGameDaJuResponse(status, response) logD("-------------------- 大局结算 ------------------------") if not self.roomInfo then logD("self.roomInfo no exist,容错处理!") return end logD("Room:onGameDaJuResponse() :", table.tostring(response)) self:dispatchEvent({name = "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 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)) -- 发送通知 self:dispatchEvent({name = "onEnterRoomSuccess", gameId = ZPDef.GameID, gameType = self.roomInfo.strGameInfo.gamerule}) end --获取手牌结果 function Room:onGetHandcardsResponese(status, response) print("Room:onGetHandcardsResponese()", table.tostring(response)) local cardData = self:serverCardToMyCard(response.handCard) self.roomInfo.memberList[response.nUserId].cardList = {} self.roomInfo.memberList[response.nUserId].cardList = cardData self.cards[response.nUserId] = cardData self:dispatchEvent({name = "onGetHandcardsResponese"}); 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 = {} local playerCount = self.bGameStart and self:getActualPlayerNum() or self.roomInfo.nMaxPlayCount or 4 for k,v in pairs(self.roomInfo.memberList) do local config=ZPDef.ZPRoomPlayerSitConfig[playerCount] local num=(v.nSeatId - mySeatId + playerCount) % playerCount local nSeatShowId = config[num+1] 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.intValue local memberInfo = self.roomInfo.memberList[nUserId] --标记准备了 if memberInfo then memberInfo.nPlayerFlag = 1 end self:dispatchEvent({name = "onUserReadyResponse"}); end -- 我发起请求解散房间 function Room:requestDismissRoom(opType) --1: 表示发起解散 2:同意解散 3:不同意解散 local request = ZPMessage.DismissRequest:new() request.operateType = opType self:sendResponse{cmd = ZPCmd.GAME_COMMAND_DISBAND_GAME , 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:dispatchEvent({name = "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 = "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] if self.roomInfo.nGameStartCount == 0 then local memberList = self.roomInfo.memberList memberList[nUserId] = nil end self:updateGpsUserInfo(nil,false) self.roomInfo.nStartGameUid = response.nStartGameUid logD("30000000--runOtherLogoutResponse") self:dispatchEvent({name = "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 = ZPMessage.RoomMemberInfo:new() other.nUserId = response.nUserId other.nSeatId = response.nSeatId other.userInfo = response.userInfo other.nTotalMoney = response.nTotalMoney other.nPlayerFlag = response.nPlayerFlag 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() --检测GPS self:updateGpsUserInfo(response.nUserId,true) local nSeatShowId = self.userList[other.nUserId] -- 发送广播通知,某个位置有人坐下了 self:dispatchEvent({name = "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 = "onUserExitResponseRoom",response = response}); end function Room:onTingCardResult(status, response) logD("Room:onTingCardResult(), ", table.tostring(response)) if not self.roomInfo then logD("self.roomInfo no exist,容错处理!") return end self:dispatchEvent({name = "onTingCardResult",response = response}); end function Room:onZhaNiaoResponese(status, response) logD("Room:onZhaNiaoResponese(), ", table.tostring(response)) if not self.roomInfo then logD("self.roomInfo no exist,容错处理!") return end self.roomInfo.leftZhaBirdTime = response.leftZhaBirdTime self:dispatchEvent({name = "onZhaNiaoResponese",response = response}); end function Room:onZhaNiaoResult(status, response) logD("Room:onZhaNiaoResult(), ", table.tostring(response)) if not self.roomInfo then logD("self.roomInfo no exist,容错处理!") return end self:dispatchEvent({name = "onZhaNiaoResult",response = response}); end function Room:onChoicePlace(status, response) logD("Room:onChoicePlace(), ", table.tostring(response)) if not self.roomInfo then logD("self.roomInfo no exist,容错处理!") return end self:dispatchEvent({name = "onChoicePlace",response = response}); end function Room:onBaoJingResponse(status, response) logD("Room:onBaoJingResponse(), ", table.tostring(response)) if not self.roomInfo then logD("self.roomInfo no exist,容错处理!") return end self:dispatchEvent({name = "onBaoJingResponse",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.nShowTableId = response.nShowTableId self.roomInfo.nMaxPlayCount = response.nMaxPlayCount self.roomInfo.nRoomOwnedUid = response.nRoomOwnedUid self.roomInfo.nTotalGameNum = response.nTotalGameNum self.roomInfo.nGameStartCount = response.nGameStartCount self.roomInfo.strGameInfo = response.strGameInfo self.roomInfo.nStatus = response.nStatus self.roomInfo.nDismissToTalTime = response.nDismissToTalTime self.roomInfo.nBankSeatId = response.nBankSeatId self.roomInfo.nZhongBankCnt = response.nZhongBankCnt self.roomInfo.bUserDisbandGame = response.bUserDisbandGame self.roomInfo.nDismissStateTime = response.nDismissStateTime self.roomInfo.arrayTableInfo = response.arrayTableInfo self.roomInfo.dipaiList = response.dipaiList self.roomInfo.showCardSeatId = response.showCardSeatId self.roomInfo.showCard = response.showCard self.roomInfo.mainOpCode = response.mainOpCode self.roomInfo.isSubmitOp = response.isSubmitOp self.roomInfo.showCardFlag = response.showCardFlag self.roomInfo.outCardSeatId = response.outCardSeatId self.roomInfo.lastOperate = response.lastOperate self.roomInfo.lastOpCard = response.lastOpCard self.roomInfo.disCardSeatId = response.disCardSeatId self.roomInfo.disCard = response.disCard self.roomInfo.leftZhaBirdTime = response.leftZhaBirdTime self.roomInfo.stopFlag = response.stopFlag self.roomInfo.winUserId = response.winUserId self.roomInfo.dianPaoUserId = response.dianPaoUserId self.roomInfo.huType = response.huType self.roomInfo.huCard = response.huCard self.roomInfo.tingCards = response.tingCards or {} self.roomInfo.hupaiInfo = response.hupaiInfo self.roomInfo.xiaoSeatId = response.xiaoSeatId; self.roomInfo.offLineInfo = response.offLineInfo self.roomInfo.tuoGuanInfo = response.tuoGuanInfo self:addReconnectionData(response) if self.roomInfo.nStatus ~= ZPDef.ReconnectState.GAME_STATUS_INIT then self.bGameStart = true end 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 for i,v in pairs(self.roomInfo.hupaiInfo or {}) do--增加容错 self.roomInfo.dianPaoUserId = v.dianPaoUid self.roomInfo.huCard = v.huCard 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 self.roomInfo.memberList[v.nUserId].userInfo = v.userInfo self.roomInfo.memberList[v.nUserId].nTotalMoney = v.nTotalMoney self.roomInfo.memberList[v.nUserId].nOnlineStatus = v.nOnlineStatus self.roomInfo.memberList[v.nUserId].nDisbandStatus = v.nDisbandStatus --这里只记录,暂时没用到。可能战绩回放的时候是需要用的 local cardData = self:serverCardToMyCard(v.handCard) self.roomInfo.memberList[v.nUserId].cardList = {} self.roomInfo.memberList[v.nUserId].cardList = cardData if v.nSeatId == self.roomInfo.nBankSeatId then self.roomInfo.nBankUid = v.nUserId end end local myUserId = self:getMyRecordUserId() for i,v in pairs(self.roomInfo.memberList) do if self:isLittleFamily() and 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])) --检测GPS self:updateGpsUserInfo(nil,false) -- 更新椅子号 self:updateUserSeateShowId(self.roomInfo.xiaoSeatId) local jsonInfo = json.decode(self.roomInfo.strGameInfo) -- 发送通知 self:dispatchEvent({name = "onEnterRoomSuccess", gameId = ZPDef.GameID or app.gameId, gameType = jsonInfo.gamerule}) 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 ~= ZPDef.SendCardType.SINGLE_CARD then if not cardData[realIndex] then cardData[realIndex] = {} end local list,mType = ZPFuc.getZPCardList(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,ZPDef.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,ZPDef.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,ZPDef.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,ZPDef.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,ZPDef.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,ZPDef.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,ZPDef.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,ZPDef.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,ZPDef.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,ZPDef.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,ZPDef.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,ZPDef.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,ZPDef.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 = "onOtherDroppedResponse", response = response}); end --如果多家可以操作,先操作的会收到通知要等待其他人 function Room:onOperationFirst(status,response) logD("-------------------- 如果多家可以操作,先操作的会收到通知要等待其他人 ------------------------") if not self.roomInfo then print("容错处理") return end self:dispatchEvent({name = "onOperationFirst",response = response}) end --操作错误 function Room:onOperationError(status) logD("-------------------- onOperationError ------------------------") if not self.roomInfo then print("容错处理") return end showTooltip("操作发生了错误...") --错误的时候如何处理 self:dispatchEvent({name = "onOperationError"}) end --操作成功 --[[ 说明:用户自己收到操作结果时, 要判断操作者他是否要出牌,若要出牌,则需提示出牌 若不用出牌,客户端无需处理, server会广播下家抓牌 ]] function Room:onOperationCodeSuccess(status,response) logD("-------------------- 操作成功 ------------------------") if not self.roomInfo then print("容错处理") return end logD("Room:onOperationCodeSuccess(), response = ", table.tostring(response)) self:dispatchEvent({name = "onOperationCodeSuccess",response = response}); end -- 服务器下发玩家的准备状态 function Room:onUserReadyResponse(status, response) print("Room:onUserReadyResponse(), ", table.tostring(response)) if not self.roomInfo then print("self.roomInfo no exist,容错处理!") return end local nUserId = response.nUserId local memberInfo = self.roomInfo.memberList[nUserId] --标记准备了 if memberInfo then memberInfo.nPlayerFlag = 1 end self:dispatchEvent({name = "onUserReadyResponse"}); end -- 通知服务器玩家GPS数据发生变化 function Room:onGpsChangeRequest() print("Room:onUserInfoChangeRequest()") local request = StringPacket:new() request.stringValue = app.user.userInfo or "" logD("Room:onGpsChangeRequest()", table.tostring(request)) self:sendResponse{cmd = ZPCmd.GAME_COMMAND_CLIENT_CHANGE_USERINFO , sender = request}; end --[[-- 服务器下发玩家GPS数据发生变化 function Room:onGpsChangeResponse(status, response) print("Room:onGpsChangeResponse()", table.tostring(response)) local nUserId = response.uid local memberInfo = self.roomInfo.memberList[nUserId] if memberInfo then memberInfo.userInfo = response.userInfo end self:dispatchEvent({name = "onGpsChangeResponse", nUserId = nUserId}); end--]] -- 服务器下发爆牌结果 function Room:onBaoPaiResponese(status, response) print("Room:onBaoPaiResponese()", table.tostring(response)) self:dispatchEvent({name = "onBaoPaiResponese",response = response}); end -- 广播最后一张牌 function Room:onLastCardResponse(status, response) print("Room:onLastCardResponse()", table.tostring(response)) self:dispatchEvent({name = "onLastCardResponse",response = response}); end function Room:ctor(net) Room.super.ctor(self , net); -- GPS信息发生变化的时候主动给服务器发消息 app:addEventListener("onUpdateLoctionSuccessed", handler(self, self.onGpsChangeRequest)) --发送 -- 请求准备 self:defMsgFunc{name = "callReadyRequest" , cmd = ZPCmd.GAME_COMMAND_USER_READY}; -- 离开房间 self:defMsgFunc{name = "callLeaveRequest" , cmd = ZPCmd.GAME_COMMAND_USER_LEAVE}; -- 玩家请求解散房间,获取其他玩家回复解散房间 self:defMsgFunc{name = "dismissRoomRequest", cmd = ZPCmd.GAME_COMMAND_DISBAND_GAME, sender = ZPMessage.DismissRequest}; -- 玩家请求立即开局 self:defMsgFunc{name = "quickStartRequest", cmd = ZPCmd.GAME_COMMAND_REQUEST_EARLY_START, sender = ZPMessage.EarlyStartRequest}; --发送爆牌选择 self:defMsgFunc{name = "BaoPai",cmd = ZPCmd.GAME_COMMAND_BAO_PAI,sender = ZPMessage.BaoPai}; --获取手牌 self:defMsgFunc{name = "callGetHandcardsRequest" , cmd = ZPCmd.GAME_COMMAND_USER_GET_HANDCARDS}; --GAME --发送操作码 self:defMsgFunc{name = "sendOperationCode" , cmd = ZPCmd.GAME_COMMAND_SEND_CODE_RESPONSE, sender = ZPMessage.GameSendOpCodeResponse}; --发送出牌 self:defMsgFunc{name = "sendOutCard",cmd = ZPCmd.GAME_COMMAND_OUT_CARD,sender = ZPMessage.OutCard}; --接收 -- 玩家进入桌子成功 self:defPushMsg{cmd = ZPCmd.GAME_COMMAND_LOGIN_GAME_SUCCESS, reader = ZPMessage.SitDownSuccessResponse, func = handler(self , self.onSitDownSuccessResponse)}; -- 玩家进入桌子失败 self:defPushMsg{cmd = ZPCmd.GAME_COMMAND_LOGIN_GAME_ERR, reader = ZPMessage.SitDownFailedResponse, func = handler(self , self.onSitDownFailedResponse)}; -- 玩家收到解散房间的请求 self:defPushMsg{cmd = ZPCmd.GAME_COMMAND_BROADCAST_DISBAND_GAME, reader = ZPMessage.DismissResponse, func = handler(self , self.onDismissResponse)}; -- 收到玩家申请解散房间 self:defPushMsg{cmd = ZPCmd.GAME_COMMAND_DISBAND_GAME, reader = ZPMessage.DismissResult, func = handler(self , self.onUserDismissResultResponse)}; -- 其他玩家退出房间 self:defPushMsg{cmd = ZPCmd.GAME_COMMAND_BROADCAST_USER_LOGOUT, reader = ZPMessage.OtherLogoutResponse, func = handler(self , self.onOtherLogoutResponse)}; -- 收到服务器下发的玩家准备状态 self:defPushMsg{cmd = ZPCmd.GAME_COMMAND_BROADCAST_USER_READY, reader = ZPMessage.IntPacket, func = handler(self , self.onUserReadyResponse)}; -- 其他玩家进入桌子 self:defPushMsg{cmd = ZPCmd.GAME_COMMAND_BROADCAST_USER_LOGIN, reader = ZPMessage.OtherSitDownResponse, func = handler(self , self.onOtherSitDownResponse)}; -- 用户退出 self:defPushMsg{cmd = ZPCmd.GAME_COMMAND_LOGOUT_GAME_SUCCESS, reader = ZPMessage.UserExitResponse, func = handler(self , self.onUserExitResponse)}; -- 游戏正式开始 self:defPushMsg{cmd = ZPCmd.GAME_COMMAND_BROADCAST_GAME_START, reader = ZPMessage.GameStartResponse, func = handler(self , self.onGameStartResponse)}; --发牌 self:defPushMsg{cmd = ZPCmd.GAME_COMMAND_SENDCARD_RESPONSE, reader = ZPMessage.GameSendCardResponse,func = handler(self , self.onGameSendCardResponse)}; --开局后系统可以提的自动消息 self:defPushMsg{cmd = ZPCmd.GAME_COMMAND_SYSTEM_RESPONSE, reader = ZPMessage.SystemOperationStart,func = handler(self , self.onSystemOperationStart)}; --广播桌子上所有玩家庄家起手操作 self:defPushMsg{cmd = ZPCmd.GAME_COMMAND_BAKER_OUTCARD_RESPONSE, reader = ZPMessage.BankerOutCard,func = handler(self , self.onBankerOutCard)}; --如果多家可以操作,先操作的会收到通知要等待其他人 self:defPushMsg{cmd = ZPCmd.GAME_COMMAND_OPERATION_FIRST,reader = ZPMessage.OperationCodeFirst,func = handler(self,self.onOperationFirst)} --若玩家操作不对,如operateCode值不对等,通过协议0x810d通知客户端操作错误,此协议暂定无参数 self:defPushMsg{cmd = ZPCmd.GAME_COMMAND_OPERATION_CODE_ERROR,func = handler(self,self.onOperationError)} --玩家操作成功, 则广播通知桌子上其他玩家操作结果,协议0x810b self:defPushMsg{cmd = ZPCmd.GAME_COMMAND_OPERATION_CODE_SUCCESS,reader = ZPMessage.OperationCodeSuccess,func = handler(self,self.onOperationCodeSuccess)} --摸牌 self:defPushMsg{cmd = ZPCmd.GAME_COMMAND_MO_PAI,reader = ZPMessage.MoPai,func = handler(self,self.onMoPai)} --弃牌 self:defPushMsg{cmd = ZPCmd.GAME_COMMAND_QI_PAI,reader = ZPMessage.QiPai,func = handler(self,self.onQiPai)} --出牌错误 self:defPushMsg{cmd = ZPCmd.GAME_COMMAND_OUT_CARD_ERROR,reader = ZPMessage.OutCardError,func = handler(self,self.onOutCardError)} --出牌成功 self:defPushMsg{cmd = ZPCmd.GAME_COMMAND_OUT_CARD_SUCCESS,reader = ZPMessage.OutCardSuccess,func = handler(self,self.onOutCardSuccess)} --单局结算 self:defPushMsg{cmd = ZPCmd.GAME_COMMAND_GAME_XIAO_JU, reader = ZPMessage.GameXiaoJuResponse, func = handler(self , self.onGameXiaoJuResponse)}; --总结算 self:defPushMsg{cmd = ZPCmd.GAME_COMMAND_GAME_DA_JU, reader = ZPMessage.GameDaJuResponse, func = handler(self , self.onGameDaJuResponse)}; --听牌结果 self:defPushMsg{cmd = ZPCmd.GAME_COMMAND_TINGCARD, reader = ZPMessage.TingCardResult, func = handler(self , self.onTingCardResult)}; --爆牌结果 self:defPushMsg{cmd = ZPCmd.GAME_COMMAND_BAO_PAI, reader = ZPMessage.BaoPaiResponse, func = handler(self , self.onBaoPaiResponese)}; self:defPushMsg{cmd = ZPCmd.GAME_COMMAND_BAO_PAI_RESPONSE, reader = ZPMessage.BaoPaiResponse, func = handler(self , self.onBaoPaiResponese)}; -- 玩家信息改变 --self:defPushMsg{cmd = ZPCmd.GAME_COMMAND_SERVER_CHANGE_USERINFO, reader = ZPMessage.ServerChangeUserInfo, func = handler(self , self.onGpsChangeResponse)}; --断线重连 self:defPushMsg{cmd = ZPCmd.GAME_COMMAND_GAME_RECONNECTION,reader = ZPMessage.GameReconnection,func = handler(self,self.onGameReconnection)} -- 其他玩家掉线 self:defPushMsg{cmd = ZPCmd.GAME_COMMAND_BROADCAST_USER_DROPPED, reader = ZPMessage.OtherDroppedResponse, func = handler(self , self.onOtherDroppedResponse)}; -- 收到玩家申请立即开局的广播 self:defPushMsg{cmd = ZPCmd.GAME_COMMAND_RESPONSE_EARLY_START, reader = ZPMessage.EarlyStartBroadcast, func = handler(self , self.onQuickStartResponse)}; --收到玩家申请立即开局的结果 self:defPushMsg{cmd = ZPCmd.GAME_COMMAND_BROAD_QUICKLY_START, reader = ZPMessage.EarlyStartResult, func = handler(self , self.onQuickStartResultResponse)}; -- 发完牌后,庄家收到最后一张牌 self:defPushMsg{cmd = ZPCmd.GAME_COMMAND_BROADCAST_LAST_CARD, reader = ZPMessage.LastCard, func = handler(self , self.onLastCardResponse)}; -- 请求获取牌结果 self:defPushMsg{cmd = ZPCmd.GAME_COMMAND_USER_GET_HANDCARDS, reader = ZPMessage.GetHandcardsResponse, func = handler(self , self.onGetHandcardsResponese)}; -- 托管广播 self:defPushMsg{cmd = ZPCmd.GAME_COMMAND_TUOGUAN_RESPONSE, reader = ZPMessage.TuoGuanResponse, func = handler(self , self.onTuoGuanResponse)}; --[[-- 客户端发起快速请求 self:defMsgFunc{name = ZPDef.ZPEvent.RequestFastsStart, cmd = ZPCmd.GAME_COMMAND_FAST_START_GAME, sender = ZPMessage.FastStartRequest} -- 快速开始请求返回 self:defPushMsg{cmd = ZPCmd.GAME_COMMAND_FAST_START_RESULT, reader = ZPMessage.FastStartRequestResult, func = handler(self, self.onUserRequestFast)} -- 快速开始广播请求 self:defPushMsg{cmd = ZPCmd.GAME_COMMAND_BROAD_FAST_START_GAME, reader = ZPMessage.FastStartStatus, func = handler(self, self.onBroadcastFastRequest)} -- 快速开始成功 self:defPushMsg{cmd = ZPCmd.GAME_COMMAND_BROAD_QUICKLY_START, reader = ZPMessage.UpdateSeatIds, func = handler(self, self.onFastStartSucc)}--]] 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) if self.userList and self.userList[nUserId] then return self.userList[nUserId]; else return nil end 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(ZPDef.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:requestQuickStart(opType) --0初始状态 1申请开始游戏 2同意开始游戏 3不同意开始游戏 local request = ZPMessage.EarlyStartRequest:new() request.optType = opType self:sendResponse{cmd = ZPCmd.GAME_COMMAND_REQUEST_EARLY_START , sender = request}; end -- 申请立即开局广播 function Room:onQuickStartResponse(status, response) if not self.roomInfo then logD("self.roomInfo no exist,容错处理!") return end logD("Room:onQuickStartResponse:",table.tostring(response)) self.nleftStartGameTimeout = response.nleftStartGameTimeout self.quickStartInfo = {} for i,v in pairs(response.earlyStartPlayerInfo) do self.quickStartInfo[v.nUserId] = v.optType end local nUserId = response.nUserId local operateType = response.operateType self:dispatchEvent({name = "onQuickStartResponse", response = response}); end -- 立即开局结果 function Room:onQuickStartResultResponse(status, response) if not self.roomInfo then logD("self.roomInfo no exist,容错处理!") return end logD("Room:onQuickStartResultResponse:",table.tostring(response)) --nSeatId for i,v in pairs(response.updateSeatId) do if self.roomInfo.memberList[v.nUserId] then self.roomInfo.memberList[v.nUserId].nSeatId = v.nSeatId end end -- 更新椅子号 self:updateTableView(true) self:dispatchEvent({name = "onQuickStartResultResponse", response = response}); end function Room:updateTableView(bGameStart) self.bGameStart = bGameStart self.seatShowList = {} self:updateUserSeateShowId() end --[[-- 游戏快速开始,更新玩家座位号 function Room:onFastStartSucc( status, response ) self.roomInfo.nMaxPlayCount = #response.pList local gameInfo = json.decode(self.roomInfo.strGameInfo) gameInfo.playnum = self.roomInfo.nMaxPlayCount self.roomInfo.strGameInfo = json.encode(gameInfo) for _,v in pairs(response.pList) do self.roomInfo.memberList[v.nUserId].nSeatId = v.nSeatId end -- 更新椅子号 self.seatShowList = {} self:updateUserSeateShowId() self:dispatchEvent({name = ZPDef.ZPEvent.FastStartSucc ,response = response}) end -- 快速开始操作广播 function Room:onBroadcastFastRequest( status, response )-- self:dispatchEvent({name = ZPDef.ZPEvent.BraodcastFastStart ,response = response}) end -- 快速开始请求返回 function Room:onUserRequestFast( status, response )--快速开始请求错误提示错误 local errTxt ={ [0] = "成功", [1] = "人数不够", [2] = "其他人已请求", [3] = "房间人数已满", [4] = "非法操作" } local txt = errTxt[response.result] if txt then showTooltip(txt) end end--]] -- 检查此桌是否有此ID玩家 function Room:checkUserIDIsInTable(nUserId) if nUserId > 99999 and self.roomInfo.memberList[nUserId] and self.roomInfo.memberList[nUserId].nSeatId then return true end return false end -- 获取桌子上实际人数 function Room:getActualPlayerNum() 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 -- 获取自己是否是小家(观看的人) 且选了小家可以看牌才返回true function Room:isLittleFamily() if not self.roomInfo.memberList[app.user.loginInfo.uid] then return false end local meSeatID = self.roomInfo.memberList[app.user.loginInfo.uid].nSeatId if self.roomInfo.xiaoSeatId and meSeatID and self.roomInfo.xiaoSeatId == meSeatID then return true end return false 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 = isOpenView or false, isGameStart = isGameStart, -- maxPlayerNum = self.roomInfo.nMaxPlayCount, }) end end -- 申请托管 function Room:requestTuoGuan(optType) local request = ZPMessage.TuoGuan:new() request.optType = optType; logD("requestTuoGuan",table.tostring(request)) self:sendResponse{cmd = ZPCmd.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;