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 PokerUtil = require("zp_doushisi.luaScript.Views.Room.doushisiPokerUtil") local ZPProtocol=ZPFramework.ZPFrameworkClassImprot("zp_base.luaScript.Protocol.ZPProtocol") local Room = class("doushisiRoom" , ZPProtocol) function Room:ctor(net) Room.super.ctor(self , net); --请求重连消息 --self:defMsgFunc{name = ZPDef.ZPEvent.GetTableInfo ,cmd = RoomCmd.GAME_COMMAND_GET_TABLE_INFO}; --发送刷新手牌请求 self:defMsgFunc{name = "reflashHandCard",cmd = RoomCmd.GAME_COMMAND_REFLASH_HANDCARDS,sender = ZPMessage.ReflashHandCard}; --发送起手操作码 self:defMsgFunc{name = "sendQiShouOperate" , cmd = RoomCmd.GAME_COMMAND_QI_SHOU_SEND_OPCODE, sender = ZPMessage.GameQiShouSendOperateCodeResponse}; --接收起手操作提示 self:defPushMsg{cmd = RoomCmd.GAME_COMMAND_OPERATE_TISHI, reader = ZPMessage.UserOperateNotify, func = handler(self, self.onUserOperateResponse)}; --广播起手操作 self:defPushMsg{cmd = RoomCmd.GAME_COMMAND_QI_SHOU_BROADCARST, reader = ZPMessage.GameQiShouBroadCastOperate, func = handler(self, self.onBroadCastQiShouOperate)}; --广播玩家进牌 self:defPushMsg{cmd = RoomCmd.GAME_COMMAND_USER_GETCARD, reader = ZPMessage.GameUserGetCard, func = handler(self, self.onBroadCastUserGetCard)}; --广播头家出牌 self:defPushMsg{cmd = RoomCmd.GAME_COMMAND_BANKER_OUT_CARD, reader = ZPMessage.GameBankerOutCard, func = handler(self, self.onBroadCastBankerOutCard)}; --通知玩家包赔 self:defPushMsg{cmd = RoomCmd.GAME_COMMAND_CHECK_USER_BAOPEI, reader = ZPMessage.BaoPei, func = handler(self, self.onOutCardIsBaoPeiResponse)}; --玩家进牌后显示的操作 self:defPushMsg{cmd = RoomCmd.GAME_COMMAND_TINGCARD_RESPONSE, reader = ZPMessage.GameUserGetCardOperateNotify, func = handler(self, self.onUserGetCardOperteResponse)}; --刷新手牌 self:defPushMsg{cmd = RoomCmd.GAME_COMMAND_REFLASH_HANDCARDS_RESPONSE, reader = ZPMessage.ReflashHandcardsResponse, func = handler(self , self.onReflashHandcardsResponese)}; --抢巴胡 self:defPushMsg{cmd = RoomCmd.GAME_COMMAND_QIANG_BA_HU, reader = ZPMessage.QiangBaResponse, func = handler(self , self.onQiangBaResponese)}; --过巴变灰 self:defPushMsg{cmd = RoomCmd.GAME_COMMAND_GUOBA_LOAK_CARD, reader = ZPMessage.GuoBaResponse, func = handler(self, self.onGuoBaResponse)}; -- 请求托管 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: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: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 -- 更新椅子号 self:updateUserSeateShowId() logD("Room:onSitDownSuccessResponse() roomInfo = ", table.tostring(self.roomInfo)) -- 发送通知 self:dispatchEvent({name = "onEnterRoomSuccess", gameId = GAME_IDS.luzhouDaEr, gameType = self.roomInfo.strGameInfo.gamerule}) 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.leftCardNum = response.leftCardNum --清空上一局胡牌信息 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.cards[response.nUserId] = cardData if self:isLittleFamily() then self.roomInfo.nBankUid = response.nUserId self.cards[app.user.loginInfo.uid] = cardData end self.roomInfo.leftCardNum = response.leftCardNum local cardlist = self.roomInfo.memberList[response.nUserId].cardList local fapaiList = {} local toujiaViewId = self:getViewIdBySeatId(app.room.roomInfo.nBankSeatId) local xiaojiaViewId = self:getViewIdBySeatId(app.room.roomInfo.xiaoSeatId) for i = 1,ZPDef.GameMaxPlayer do local cardData = {} if self:getActualPlayerNum() == 4 then if i == 4 then cardData.list = cardlist cardData.num = #cardlist cardData.viewId = i table.insert(fapaiList,cardData) else if i == xiaojiaViewId then cardData.num = 5 cardData.list = {} for i = 1,cardData.num do table.insert(cardData.list, 0) end elseif i == toujiaViewId then cardData.num = 8 cardData.list = {} for i = 1,cardData.num do table.insert(cardData.list, 0) end else cardData.num = 7 cardData.list = {} for i = 1,cardData.num do table.insert(cardData.list, 0) end end cardData.viewId = i table.insert(fapaiList,cardData) end elseif app.room:getActualPlayerNum() == 3 then if i ~= 2 then if i == 4 then cardData.list = cardlist cardData.num = #cardlist cardData.viewId = i table.insert(fapaiList,cardData) else if i == toujiaViewId then cardData.num = 8 cardData.list = {} for i = 1,cardData.num do table.insert(cardData.list, 0) end else cardData.num = 7 cardData.list = {} for i = 1,cardData.num do table.insert(cardData.list, 0) end end cardData.viewId = i table.insert(fapaiList,cardData) end end end end app.room.roomInfo.fapaiList = fapaiList -- 发送广播通知,发牌开始了 self:dispatchEvent({name = "onGameSendCardResponse"}); 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.roomInfo.TouoperateCard = response.ToucardList --self.roomInfo.BaoperateCard = response.BacardList if self:isMyself(response.nUserId) then self.roomInfo.totoalTuoNum = response.totalTuoNum end 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)) if self:isMyself(response.nUserId) then self.roomInfo.totoalTuoNum = response.totalTuoNum end self:dispatchEvent({name = "onBroadCastQiShouOperate",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:onGuoBaResponse(status, response) logD("------------广播用户过巴操作---------------") if not self.roomInfo then logD("self.roomInfo no exist,容错处理!") return end logD("Room:onGuoBaResponse(), ", table.tostring(response)) self:dispatchEvent({name = "onGuoBaResponse",response = response}) end function Room:onBroadCastBankerOutCard(status, response) logD("------------通知头家出牌--------------") if not self.roomInfo then logD("self.roomInfo no exist,容错处理!") return end logD("Room:onBroadCastBankerOutCard(), ", table.tostring(response)) self:dispatchEvent({name = "onBroadCastBankerOutCard",response = response}) end function Room:onOutCardIsBaoPeiResponse(status, response) logD("------------通知打出的牌可能包赔--------------") if not self.roomInfo then logD("self.roomInfo no exist,容错处理!") return end logD("Room:onOutCardIsBaoPeiResponse(), ", table.tostring(response)) self:dispatchEvent({name = "onOutCardIsBaoPeiResponse",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:onQiangBaResponese(status, response) logD("------------通知玩家抢巴操作--------------") if not self.roomInfo then logD("self.roomInfo no exist,容错处理!") return end logD("Room:onQiangBaResponese(), ", table.tostring(response)) self:dispatchEvent({name = "onQiangBaResponese",response = response}) end -- 获取自己是否是小家(观看的人) 且选了小家可以看牌才返回true 长牌用不到 function Room:isLittleFamily() return false 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 or {} 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 or {} self.roomInfo.xiaoSeatId = response.xiaoSeatId; self.roomInfo.offLineInfo = response.offLineInfo self.roomInfo.fanpaiSeatId = response.fanpaiSeatId self.roomInfo.chiPaiList = response.chiCardList or {} self.roomInfo.isBaopeiCard = response.isBaopeiCard self.roomInfo.totalTuoNum = response.totalTuoNum self.roomInfo.curOpreateID = response.curOpreateID self.roomInfo.isBaopeiGuo = response.isBaopeiGuo self.roomInfo.houzhuaCard = response.houzhuaCard or {} self.roomInfo.curEnterCard = response.curEnterCard self.roomInfo.isZiMoHu = response.isZiMoHu self.roomInfo.pengCardlist = response.canPengOpCard self.roomInfo.isQiangBaHu = response.isQiangBaHu for k,v in ipairs(response.disCard or {}) do table.insert(self.roomInfo.disCard,v) end --起手操作 self.roomInfo.startOpList = {} self.roomInfo.startOpList["ishu"] = response.ishu self.roomInfo.startOpList["ToucardList"] = response.ToucardList or {} self.roomInfo.startOpList["BacardList"] = response.BacardList or {} self:addReconnectionData(response) local leftCardList = {} 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 leftCardList[v.nUserId] = extIf.LeftCard 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 local fapaiList = {} local cardlist = self.cards[myUserId] local toujiaViewId = self:getViewIdBySeatId(app.room.roomInfo.nBankSeatId) local xiaojiaViewId = self:getViewIdBySeatId(app.room.roomInfo.xiaoSeatId) for i = 1,ZPDef.GameMaxPlayer do local cardData = {} if self:getActualPlayerNum() == 4 then if i == 4 then cardData.list = cardlist cardData.num = #cardlist cardData.viewId = i table.insert(fapaiList,cardData) else if i == xiaojiaViewId then local userId = self:getUserIdByViewId(i) cardData.num = leftCardList[userId] cardData.list = {} for i = 1,cardData.num do table.insert(cardData.list, 0) end elseif i == toujiaViewId then local userId = self:getUserIdByViewId(i) cardData.num = leftCardList[userId] cardData.list = {} for i = 1,cardData.num do table.insert(cardData.list, 0) end else local userId = self:getUserIdByViewId(i) cardData.num = leftCardList[userId] cardData.list = {} for i = 1,cardData.num do table.insert(cardData.list, 0) end end cardData.viewId = i table.insert(fapaiList,cardData) end elseif self:getActualPlayerNum() == 3 then if i ~= 2 then if i == 4 then cardData.list = cardlist cardData.num = #cardlist cardData.viewId = i table.insert(fapaiList,cardData) else if i == toujiaViewId then local userId = self:getUserIdByViewId(i) cardData.num = leftCardList[userId] cardData.list = {} for i = 1,cardData.num do table.insert(cardData.list, 0) end else local userId = self:getUserIdByViewId(i) cardData.num = leftCardList[userId] cardData.list = {} for i = 1,cardData.num do table.insert(cardData.list, 0) end end cardData.viewId = i table.insert(fapaiList,cardData) end end end end app.room.roomInfo.fapaiList = fapaiList -- 发送通知 self:dispatchEvent({name = "onEnterRoomSuccess", gameId = ZPDef.GameID or app.gameId, gameType = jsonInfo.gamerule}) end --获取手牌结果 function Room:onGetHandcardsResponese(status, response) 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:onSystemOperationStart(status, response) logD("-------------------- 等待玩家报叫------------------------") if not self.roomInfo then logD("self.roomInfo no exist,容错处理!") return end logD("Room:onSystemOperationStart(), ", table.tostring(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, //出牌非法 OUT_CARD_BAOPEI = 3, //不出包赔牌--]] local errorCode = response.result if errorCode == ZPDef.OutCardErrorTip.OUT_CARD_SUCCESS then showTooltip("出牌无效") elseif errorCode == ZPDef.OutCardErrorTip.OUT_CARD_SUCCESS then showTooltip("不需要出牌") elseif errorCode == ZPDef.OutCardErrorTip.OUT_CARD_BAOPEI then showTooltip("请重新选择!") else showTooltip("出牌未知") end self:dispatchEvent({name = "onOutCardError"}); end --[[ 思维: 服务器把牌都排序好了,客户端只要拿到数据负责显示 ]] function Room:serverCardToMyCard(serverCardList) -- --根据定义组合牌 local cardData = {} --加起来为14的一组 local groupCardlist = {} --单张一组 local singleCardList = {} for k,v in ipairs(serverCardList) do if v.type == ZPDef.SendCardType.TWO_SUM_CHI then table.insert(groupCardlist,v.card) else for _,value in pairs(v.card or {}) do table.insert(singleCardList, value) end end end local resultGroupList = {} local resultsingleCardList = {} --先给加起来为14的排序 for k,cards in pairs(groupCardlist) do local cardlist = PokerUtil.pokerSortDssCards(cards) table.insert(resultGroupList,cardlist) end resultsingleCardList = PokerUtil.pokerSortDssCards(singleCardList) table.sort(resultGroupList, function (a, b) return a[1].val < b[1].val end) for i = 1,#resultGroupList do local cardlist = resultGroupList[i] for i = 1, #cardlist do local card = cardlist[i].cid table.insert(cardData,card) end end for i = 1, #resultsingleCardList do local card = resultsingleCardList[i].cid table.insert(cardData,card) end logD("Room:resultCardData : "..table.tostring(cardData)) return cardData 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: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:getSameVlaueList(list) local tt = {} for i = 1,#list do local value = list[i]%16 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:rankHandCard(tPureHandCards) --发牌 local index = 1 local cardData = {} local list = {} local cardList = {} --把手分成点数相同列数 local tempHandCardList = self:getSameVlaueList(tPureHandCards) logD("Room:rankHandCard : "..table.tostring(tempHandCardList)) local singleCardList = {} local groupCardlist = {} local tempgroupCardlist = {} --按照点数去寻找牌组 点数有1 - 14 for i = 1,14 do list = {} tempgroupCardlist = {} local hCardList = tempHandCardList[i] if hCardList and table.nums(hCardList) > 0 then --先把找到的列数放入数组中 --再找点数加起来为14的列数 local secondDian = 14 - i local secondList = tempHandCardList[secondDian] local isgroup = false if secondDian ~= 7 then if secondList and table.nums(secondList) > 0 then --再把找到的加起来为14的列数放入数组中 isgroup = true for m = 1,#hCardList do table.insert(tempgroupCardlist, hCardList[m]) end tempHandCardList[i] = {} for j = 1,#secondList do table.insert(tempgroupCardlist, secondList[j]) end tempHandCardList[secondDian] = {} table.insert(groupCardlist,tempgroupCardlist) end if not isgroup then for j = 1,#hCardList do table.insert(singleCardList,hCardList[j]) end tempHandCardList[i] = {} end else local lens = table.nums(hCardList) if lens > 1 then for m = 1,#hCardList do table.insert(tempgroupCardlist, hCardList[m]) end table.insert(groupCardlist,tempgroupCardlist) else for j = 1,#hCardList do table.insert(singleCardList,hCardList[j]) end end tempHandCardList[i] = {} end end end local resultGroupList = {} local resultsingleCardList = {} --先给加起来为14的排序 for k,cards in pairs(groupCardlist) do local cardlist = PokerUtil.pokerSortDssCards(cards) table.insert(resultGroupList,cardlist) end resultsingleCardList = PokerUtil.pokerSortDssCards(singleCardList) table.sort(resultGroupList, function (a, b) return a[1].val < b[1].val end) for i = 1,#resultGroupList do local cardlist = resultGroupList[i] for i = 1, #cardlist do local card = cardlist[i].cid table.insert(cardData,card) end end for i = 1, #resultsingleCardList do local card = resultsingleCardList[i].cid table.insert(cardData,card) end logD("Room:resultCardData : "..table.tostring(cardData)) 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 return Room;