local RoomCmd=ZPFramework.ZPImport("zp_base.luaScript.Protocol.ZPCmd") local ZPMessage=ZPFramework.ZPImport("zp_base.luaScript.Protocol.ZPMessage") local ZPDef=ZPFramework.ZPImport("zp_base.luaScript.ZPDef") local ZPFuc=ZPFramework.ZPImport("zp_base.luaScript.ZPFunctions") local ZPProtocol=ZPFramework.ZPFrameworkClassImprot("zp_base.luaScript.Protocol.ZPProtocol") local Room = class("xichongRoom" , ZPProtocol) local tempCardVlue ={ [17] = 20, --11 [18] = 30, --12 [49] = 40, --31 [34] = 41, --22 [20] = 50, --14 [50] = 51, --32 [21] = 60, --15 [36] = 61, --24 [51] = 62, --33 [22] = 70, --16 [82] = 71, --52 [52] = 72, --34 [38] = 80, --26 [53] = 81, --35 [68] = 82, --44 [54] = 90, --36 [84] = 91, --54 [70] = 100, --46 [85] = 101, --55 [86] = 110, --56 [102] = 120, --66 } function Room:ctor(net) Room.super.ctor(self , net); --请求重连消息 self:defMsgFunc{name = ZPDef.ZPEvent.GetTableInfo ,cmd = RoomCmd.GAME_COMMAND_GET_TABLE_INFO}; --广播起手操作 self:defPushMsg{cmd = RoomCmd.GAME_SERVER_BROAD_PIAO, reader = ZPMessage.GamePiao, func = handler(self, self.onBroadCastUserPiao)}; --接收暗操作提示 self:defPushMsg{cmd = RoomCmd.GAME_COMMAND_OPERATE_TISHI, reader = ZPMessage.UserOperateNotify, func = handler(self, self.onUserOperateResponse)}; --发送报操作 self:defMsgFunc{name = "sendBaoOperate" , cmd = RoomCmd.GAME_CLIENT_SEND_BAO, sender = ZPMessage.GameBaoSendOperateCode}; --服务器广播报操作 self:defPushMsg{cmd = RoomCmd.GAME_COMMAND_BROADCAST_BAO_JIAO, reader = ZPMessage.UserBaoResulst, func = handler(self, self.onBroadUserBaoResponse)}; --接收报操作提示 self:defPushMsg{cmd = RoomCmd.GAME_COMMAND_USER_BAO_ACTION, reader = ZPMessage.UserCanBaoNotify, func = handler(self, self.onUserCanBaoResponse)}; --广播起手操作 self:defPushMsg{cmd = RoomCmd.GAME_COMMAND_BROADCAST_TOU_OPERATION, reader = ZPMessage.GameQiShouBroadCastOperate, func = handler(self, self.onBroadCastQiShouOperate)}; --广播通知玩家出牌 self:defPushMsg{cmd = RoomCmd.GAME_COMMAND_BROADCAST_OUT_PROMPT, reader = ZPMessage.GameUserOutCard, func = handler(self, self.onBroadCastUserOutCard)}; --广播玩家进牌 self:defPushMsg{cmd = RoomCmd.GAME_COMMAND_BROADCAST_ENTER_CARD, reader = ZPMessage.GameUserGetCard, func = handler(self, self.onBroadCastUserGetCard)}; --玩家进牌后显示的操作 self:defPushMsg{cmd = RoomCmd.GAME_COMMAND_TINGCARD_RESPONSE, reader = ZPMessage.GameUserGetCardOperateNotify, func = handler(self, self.onUserGetCardOperteResponse)}; --发送刷新手牌请求 self:defMsgFunc{name = "reflashHandCard",cmd = RoomCmd.GAME_COMMAND_REFLASH_HANDCARDS,sender = ZPMessage.ReflashHandCard}; --刷新手牌 self:defPushMsg{cmd = RoomCmd.GAME_COMMAND_REFLASH_HANDCARDS_RESPONSE, reader = ZPMessage.ReflashHandcardsResponse, func = handler(self , self.onReflashHandcardsResponese)}; -- 请求托管 self:defMsgFunc{name = ZPDef.ZPEvent.HostingRequest, cmd = RoomCmd.GAME_COMMAND_USER_HOSTING_REQUEST, sender = ZPMessage.HostingRequest} -- 收到托管回调 self:defPushMsg{cmd = RoomCmd.GAME_COMMAND_USER_HOSTING_RESPONSE, reader = ZPMessage.HostingResponse, func = handler(self,self.onHostingResponse)} 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 = {} 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 self.roomInfo.hupaiInfo = response.hupaiInfo self.roomInfo.xiaoSeatId = response.xiaoSeatId; self.roomInfo.offLineInfo = response.offLineInfo self.roomInfo.fanpaiSeatId = response.fanpaiSeatId self.roomInfo.chiPaiList = response.chiCardList or {} self.roomInfo.totalTuoNum = response.totalTuoNum self.roomInfo.curOpreateID = response.curOpreateID self.roomInfo.firstOutCard = {} self.roomInfo.baoType = response.baoType self.roomInfo.isSanSiGen = response.isSanSiGen self.roomInfo.isZiMoHu = response.isZiMoHu self.roomInfo.isBiHu = response.isBiHu for k,v in ipairs(response.disCard or {}) do table.insert(self.roomInfo.disCard,v) end for k,v in ipairs(response.nomorlDisCard or {}) do table.insert(self.roomInfo.disCard,v) end for k,v in ipairs(response.firstOutCard or {}) do table.insert(self.roomInfo.firstOutCard,v) end --起手操作 self.roomInfo.startOpList = {} self.roomInfo.startOpList["ishu"] = response.ishu self.roomInfo.startOpList["TouoperateCode"] = response.TouoperateCode self.roomInfo.startOpList["ToucardList"] = response.ToucardList or {} self.roomInfo.startOpList["BaoperateCode"] = response.BaoperateCode self.roomInfo.startOpList["BacardList"] = response.BacardList or {} self.roomInfo.startOpList["totalTuoNum"] = response.totalTuoNum 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 for i,v in pairs(self.roomInfo.hupaiInfo) 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 --这里只记录,暂时没用到。可能战绩回放的时候是需要用的 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 --头家UID 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() local jsonInfo = json.decode(self.roomInfo.strGameInfo) self:resetRound() --没用到 local extInfo = json.decode(response.extJson or "") if extInfo and type(extInfo)=='table' and extInfo[tostring(self:getMyUserId())] then local myinfo = extInfo[tostring(self:getMyUserId())] self.roomInfo.hosting = myinfo.hosted or 0--托管状态 self.roomInfo.quickStartInfo = extInfo.faststart--提前开局 else self.roomInfo.hosting = 0 end -- 发送通知 self:dispatchEvent({name = "onEnterRoomSuccess", gameId = ZPDef.GameID or app.gameId, gameType = jsonInfo.gamerule}) end --获取手牌结果 function Room:onReflashHandcardsResponese(status, response) print("Room:onReflashHandcardsResponese()", 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 = "onReflashHandcardsResponese"}); end -- 广播桌子上所有玩家庄家起手操作 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:onUserGetCardOperteResponse(status, response) logD("------------进牌后通知玩家显示操作--------------") if not self.roomInfo then logD("self.roomInfo no exist,容错处理!") return end logD("Room:onUserGetCardOperteResponse(), ", table.tostring(response)) self:dispatchEvent({name = "onUserGetCardOperteResponse",response = response}) end function Room:onBroadCastUserGetCard(status, response) logD("------------广播用户进牌操作---------------") if not self.roomInfo then logD("self.roomInfo no exist,容错处理!") return end logD("Room:onBroadCastUserGetCard(), ", table.tostring(response)) self:dispatchEvent({name = "onBroadCastUserGetCard",response = response}) end function Room:onBroadCastUserOutCard(status, response) logD("------------通知玩家出牌--------------") if not self.roomInfo then logD("self.roomInfo no exist,容错处理!") return end logD("Room:onBroadCastUserOutCard(), ", table.tostring(response)) self:dispatchEvent({name = "onBroadCastUserOutCard",response = response}) end function Room:onBroadUserBaoResponse(status, response) logD("------------广播用户报操作---------------") if not self.roomInfo then logD("self.roomInfo no exist,容错处理!") return end logD("Room:onBroadUserBaoResponse(), ", table.tostring(response)) self:dispatchEvent({name = "onBroadUserBaoResponse",response = response}) end function Room:onUserCanBaoResponse(status, response) logD("------------提示用户报操作---------------") if not self.roomInfo then logD("self.roomInfo no exist,容错处理!") return end logD("Room:onUserCanBaoResponse(), ", table.tostring(response)) self:dispatchEvent({name = "onUserCanBaoResponse",response = response}) end function Room:onUserOperateResponse(status, response) logD("------------提示用户暗操作---------------") if not self.roomInfo then logD("self.roomInfo no exist,容错处理!") return end logD("Room:onUserOperateResponse(), ", table.tostring(response)) self:dispatchEvent({name = "onUserOperateResponse",response = response}) end function Room:onBroadCastQiShouOperate(status, response) logD("------------广播用户暗操作---------------") if not self.roomInfo then logD("self.roomInfo no exist,容错处理!") return end logD("Room:onBroadCastQiShouOperate(), ", table.tostring(response)) self:dispatchEvent({name = "onBroadCastQiShouOperate",response = response}) end function Room:onBroadCastUserPiao(status, response) logD("------------广播用户选飘---------------") if not self.roomInfo then logD("self.roomInfo no exist,容错处理!") return end logD("Room:onBroadCastUserPiao(), ", table.tostring(response)) self:dispatchEvent({name = "onBroadCastUserPiao",response = response}) 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.fanpaiSeatId = response.turnSeatId; self.roomInfo.fanpaiValue = response.turnCard; --清空上一局胡牌信息 self.roomInfo.hupaiInfo = nil -- 清空上一局的手牌信息 self.cards = {} -- 发送广播通知,游戏开始了 self:dispatchEvent({name = "onGameStartResponse"}); end -- 获取自己是否是小家(观看的人) 且选了小家可以看牌才返回true 长牌用不到 function Room:isLittleFamily() return false 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.cards[response.nUserId] = cardData if self:isLittleFamily() then self.roomInfo.nBankUid = response.nUserId self.cards[app.user.loginInfo.uid] = cardData end self.roomInfo.totalTuoNum = response.totalTuoNum -- 发送广播通知,发牌开始了 self:dispatchEvent({name = "onGameSendCardResponse"}); end -- 获取房间最大玩家人数 function Room:getMaxPlayerCount() return self.roomInfo.nMaxPlayCount end -- 获取房间人数 function Room:getPlayerCount() local count = 0 for k,v in pairs(self.roomInfo.memberList) do count = count + 1 end return count end -- 重置上局信息 function Room:resetRound() self.roomInfo.quickStartInfo = nil end function Room:resetFastInfo() self.roomInfo.quickStartInfo = nil end function Room:isMyself(uid) return uid==self:getMyUserId() end -- 更新玩家的相对椅子号 function Room:updateUserSeateShowId(xiaoSeatId) local myUserId = self:getMyRecordUserId() local mySeatId = self.roomInfo.memberList[myUserId].nSeatId self.roomInfo.nUserId = self:getMyRecordUserId() self.roomInfo.nSeatId = mySeatId --除了自己的第一次seatid辅助 local anotherSeatID = -1 --[视图椅子号] = userID --[座位号] = userID --[userID] = 视图椅子号 self.seatShowList = {} self.userList = {} self.seatList = {} for k,v in pairs(self.roomInfo.memberList) do if v.nUserId and v.nSeatId then local maxNum = 3--ZPFuc.getCreateRoomPlayerNum() local isChange = false if app.room:getActualPlayerNum() >= 3 then maxNum = 4 end local nSeatShowId --= (v.nSeatId - mySeatId + 4) % 4 if mySeatId <= v.nSeatId then nSeatShowId = v.nSeatId - mySeatId elseif mySeatId > v.nSeatId then nSeatShowId = maxNum - mySeatId + v.nSeatId end if app.room:getActualPlayerNum() == 2 then--self.roomInfo.playerNum == 2 then if (v.nSeatId == mySeatId) then nSeatShowId = 4 else nSeatShowId = 1--两人玩时,对家坐哪里 end elseif app.room:getActualPlayerNum() == 3 and v.nUserId ~= 0 then if (v.nSeatId == mySeatId) then nSeatShowId = 4 else --local nSeatShowId = (v.nSeatId - mySeatId + 4) % 4 if nSeatShowId == 2 then if mySeatId > v.nSeatId then nSeatShowId = nSeatShowId + 1 isChange = true else isChange = true nSeatShowId = nSeatShowId - 1 end end if nSeatShowId == 0 then if mySeatId > v.nSeatId then nSeatShowId = nSeatShowId + 1 else nSeatShowId = 3 end elseif (nSeatShowId == 1 or nSeatShowId == 3) and anotherSeatID >= 0 then isChange = true end if anotherSeatID < 0 and not isChange then anotherSeatID = v.nSeatId end end elseif app.room:getActualPlayerNum() == 4 and v.nUserId ~= 0 then if (v.nSeatId == mySeatId) and (v.nSeatId ~= self.roomInfo.xiaoSeatId) then nSeatShowId = 4 else if xiaoSeatId and xiaoSeatId >=0 and nSeatShowId == 2 then if mySeatId == xiaoSeatId then if math.abs(mySeatId - v.nSeatId) == 2 then nSeatShowId = 4 end elseif mySeatId > v.nSeatId then isChange = true nSeatShowId = nSeatShowId + 1 else isChange = true nSeatShowId = nSeatShowId - 1 end else end if xiaoSeatId and v.nSeatId == self.roomInfo.xiaoSeatId then nSeatShowId = 2 end end --强制转换小家视角与庄家一致 if mySeatId == xiaoSeatId then if nSeatShowId == 1 then nSeatShowId = 3 elseif nSeatShowId == 3 then nSeatShowId = 1 end end end if nSeatShowId == 0 then nSeatShowId = 4 end if v.nUserId == 0 then nSeatShowId = 2 else if self.seatShowList[nSeatShowId] and isChange == true then if nSeatShowId == 1 then nSeatShowId = 3 elseif nSeatShowId == 3 then nSeatShowId = 1 end elseif self.seatShowList[nSeatShowId] and isChange == false then local olduid = self.seatShowList[nSeatShowId] local oldshowid = self.userList[olduid] local newshowid = 0 if nSeatShowId == 1 then newshowid = 3 elseif nSeatShowId == 3 then newshowid = 1 end self.seatShowList[newshowid] = olduid self.userList[olduid] = newshowid end end self.seatShowList[nSeatShowId] = v.nUserId self.seatList[v.nSeatId] = v.nUserId self.userList[v.nUserId] = nSeatShowId end 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:serverCardToMyCard(serverCardList) -- --根据定义组合牌 local cardData = {} --单个组合索引 local index = 1 --真实索引 local realIndex = 1 local tempserverCardlist = {} local singleCardList = {} for k,v in ipairs(serverCardList) do local cardlist = {} for _,val in pairs(v.card or {}) do table.insert(cardlist,val) end table.insert(tempserverCardlist,cardlist) end --先对二维数组排序 for k,v in ipairs(tempserverCardlist or {}) do local cardlist = v table.sort(cardlist,function(a,b) local numA = tempCardVlue[a] local numB = tempCardVlue[b] if numA ~= nil and numB ~= nil then return numA < numB end end) end table.sort(tempserverCardlist,function(a,b) local index = a[1] local numA = tempCardVlue[index] local index1 = b[1] local numB = tempCardVlue[index1] if numA ~= nil and numB ~= nil then return numA < numB end end) logD("Room:sortMycard : "..table.tostring(tempserverCardlist)) for k,v in ipairs(tempserverCardlist) do local list = v if #list <= 4 then --如果是四张以下直接放一列 local cardlist = {} for k,v in ipairs(list) do table.insert(cardlist,v) end --先按值牌序 table.sort(cardlist,function(a,b) local numA = tonumber(a) local numB = tonumber(b) if numA ~= nil and numB ~= nil then return numA < numB end end) --按点数排序 table.sort(cardlist,function(a,b) local numA = tempCardVlue[a] local numB = tempCardVlue[b] if (numA ~= nil) and (numB ~= nil) then return numA > numB end return false end) cardData[realIndex] = cardlist realIndex = realIndex + 1 else --大于五张要分开 --首先考虑三张一样的 local cardlist = {} for k,v in ipairs(list) do table.insert(cardlist,v) end --local tempCardList = self:getSameVlaueList(cardlist) local tempCardList = self:spiltSameList(cardlist) local tempResultCardList = {} for k,v in pairs(tempCardList) do table.insert(tempResultCardList,v) end --按点数排序 table.sort(tempResultCardList,function(a,b) local index = a[1] local numA = tempCardVlue[index] local index1 = b[1] local numB = tempCardVlue[index1] if (numA ~= nil) and (numB ~= nil) then return numA < numB end return false end) for k,templist in pairs (tempResultCardList) do table.sort(templist,function(a,b) local numA = tempCardVlue[tonumber(a)] local numB = tempCardVlue[tonumber(b)] if numA ~= nil and numB ~= nil then return numA > numB end return false end) local cardlist = templist cardData[realIndex] = cardlist realIndex = realIndex + 1 end --[[ for k,templist in pairs(tempResultCardList) do if #templist > 4 then local same,sameValue = self:checkListHaveSame(templist) local indexValue = {} if same then for k,v in ipairs(sameValue) do local cardlist = {} for i = 1,#templist do if templist[i] == tonumber(v) then table.insert(cardlist,templist[i]) table.insert(indexValue,i) --保存重复的索引值 end end cardData[realIndex] = cardlist realIndex = realIndex + 1 end local ttlist = {} for i = 1,#templist do if not self:isHasInCardlist(i,indexValue) then table.insert(ttlist,templist[i]) end end if #ttlist >= 1 then local cardlist = {} for k,v in ipairs(ttlist) do table.insert(cardlist,v) end cardData[realIndex] = cardlist realIndex = realIndex + 1 end else local cardlist = {} for i = 1,#templist do table.insert(cardlist,templist[i]) if #cardlist == 4 then cardData[realIndex] = cardlist realIndex = realIndex + 1 cardlist = {} end end if #cardlist >= 1 then cardData[realIndex] = cardlist realIndex = realIndex + 1 end end else local cardlist = templist cardData[realIndex] = cardlist realIndex = realIndex + 1 end end--]] end end --最后判断单张列表是否还有值 if #singleCardList > 0 then cardData[realIndex] = singleCardList realIndex = realIndex + 1 end logD("Room:resultCardData : "..table.tostring(cardData)) return cardData end function Room:getMostBigValue(list) local smallValue = list[1] for i = 1,#list do if list[i] > smallValue then smallValue = list[i] end end return smallValue end --拆分数组中对子和三个以上的值 function Room:spiltSameList(list) local tt = {} local templist = list --按点数从小到大排序 table.sort(templist,function(a,b) local numA = tempCardVlue[tonumber(a)] local numB = tempCardVlue[tonumber(b)] if (numA ~= nil) and (numB ~= nil) then return numA < numB end return false end) local ttValue = {} for i = 1,#list do local value = list[i] if ttValue[value] then ttValue[value] = ttValue[value] + 1 else ttValue[value] = 1 end end local ttResult = {} for k,v in pairs(ttValue) do local cardlist = {} local card = tonumber(k) cardlist.card = {} cardlist.value = math.modf(tempCardVlue[tonumber(k)]/10) cardlist.num = v for i = 1,v do table.insert(cardlist.card,tonumber(k)) end table.insert(ttResult,cardlist) end local index = 1 for i = 1, #ttResult do local resultData = ttResult[i] if resultData.num then for j = i+1,#ttResult do local resultData1 = ttResult[j] if resultData1.num then --把加起来为4的列数都先放好 if ((resultData1.num + resultData.num == 4) and (resultData.num == 1 or resultData.num == 3) and resultData.value == resultData1.value) or ((resultData1.num + resultData.num == 4) and (resultData.num == resultData.num) and resultData.value == resultData1.value) then local cardlist = {} for k,v in pairs(resultData1.card) do table.insert(cardlist,v) end for k,v in pairs(resultData.card) do table.insert(cardlist,v) end tt[index] = cardlist index = index + 1 ttResult[i] = {} ttResult[j] = {} break end end end end end local leftNum = 0 for i = 1,#ttResult do local resultData = ttResult[i] if resultData.num and resultData.num <= 2 then leftNum = leftNum + resultData.num elseif resultData.num and resultData.num >= 3 then --大于三张的要单独放一列 local cardlist = {} if resultData.num then for k,v in pairs(resultData.card) do table.insert(cardlist,v) end end tt[index] = cardlist index = index + 1 ttResult[i] = {} end end if leftNum > 0 then local mValue = {} for i = 1,#ttResult do local resultData = ttResult[i] if resultData.num then if not mValue[resultData.value] then mValue[resultData.value] = {} end for k,v in pairs(resultData.card) do table.insert(mValue[resultData.value],v) end end end for k,v in pairs(mValue) do tt[index] = v index = index + 1 end --[[else--]] --[[ local cardlist = {} for i = 1,#ttResult do local resultData = ttResult[i] if resultData.num then for k,v in pairs(resultData.card) do table.insert(cardlist,v) end end end tt[index] = cardlist index = index + 1--]] end for i = 1,#tt do local tempResultCardList = tt[i] table.sort(tempResultCardList,function(a,b) local numA = tempCardVlue[tonumber(a)] local numB = tempCardVlue[tonumber(b)] if numA ~= nil and numB ~= nil then return numA < numB end return false end) end return tt end function Room:checkListHaveSame(list) local tt = {} local same = false local sameValue = {} for i = 1,#list do local value = list[i] if tt[value] then tt[value] = tt[value] + 1 else tt[value] = 1 end end for k,v in pairs(tt) do if v >= 3 then same = true table.insert(sameValue,k) end end return same,sameValue end --获取点数相同的列数 function Room:getSameVlaueList(list) local tt = {} table.sort(list,function(a,b) local numA = tempCardVlue[tonumber(a)] local numB = tempCardVlue[tonumber(b)] if numA ~= nil and numB ~= nil then return numA > numB end end) for i = 1,#list do local value = math.modf(tempCardVlue[tonumber(list[i])]/10) if tt[value] then table.insert(tt[value],list[i]) else tt[value] = {} table.insert(tt[value],list[i]) end end return tt end function Room:isHasInCardlist(value,list) local isHas = false for k,v in pairs(list) do if value == v then isHas = true end end return isHas end --回放排序 --根据服务器逻辑进行排序 function Room:rankHandCard(tPureHandCards) --发牌 local index = 1 local cardData = {} local list = {} local cardList = {} --把手分成点数相同列数 local tempHandCardList = self:getSameVlaueList(tPureHandCards) logD("Room:rankHandCard : "..table.tostring(tempHandCardList)) --按照点数去寻找牌组 点数只有2-12 for i = 2,12 do list = {} cardList = {} local hCardList = tempHandCardList[i] if hCardList and table.nums(hCardList) > 0 then --先把找到的列数放入数组中 for i = 1,#hCardList do table.insert(cardList, hCardList[i]) end tempHandCardList[i] = {} --再找点数加起来为14的列数 local secondDian = 14 - i local secondList = tempHandCardList[secondDian] if secondList and table.nums(secondList) > 0 then --再把找到的加起来为14的列数放入数组中 for i = 1,#secondList do table.insert(cardList, secondList[i]) end tempHandCardList[secondDian] = {} end end if table.nums(cardList) > 0 then table.sort(cardList,function(a,b) local numA = tempCardVlue[tonumber(a)] local numB = tempCardVlue[tonumber(b)] if numA ~= nil and numB ~= nil then return numA < numB end end) list.card = cardList cardData[index] = list index = index + 1 end end return cardData end --- -- 托管通知 -- @return -- function Room:onHostingResponse (status, response) local userList = response.userList for k, v in ipairs(userList) do -- 是否托管 if v.nUserId == self:getMyUserId() then self.roomInfo.hosting = v.status end self:dispatchEvent({name = ZPDef.ZPEvent.HostingRequest, response = {nUserId = v.nUserId, status = v.status}}); end end -- 获取我当前是否处于托管状态 function Room:getMeIsInAIStatus() return self.roomInfo.hosting == 1 end return Room;