|
- 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("ErWuRoom" , 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: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.GameSendOpCodeResponse};
- --接收起手操作提示
- 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 = 2--两人玩时,对家坐哪里
- 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
- if app.room:getActualPlayerNum() == 2 then
- nSeatShowId = 1
- end
- 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.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
-
-
- --[[
- --test
- response.cardList = {}
- response.cardList = {
- {
- type = 1,
- card = {0x11,0x22,0x14,0x15}
- },
- {
- type = 2,
- card = {0x11,0x22,0x14,0x15}
- },
- {
- type = 3,
- card = {0x11,0x22,0x14,0x15}
- },
- {
- type = 4,
- card = {0x11,0x22,0x14,0x15}
- }
- }
- ]]
-
- --目前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: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:onGameXiaoJuResponse(status, response)
- logD("--------------------小局结算 ------------------------")
- if not self.roomInfo then
- logD("self.roomInfo no exist,容错处理!")
- return
- end
-
- if self:getActualPlayerNum() == 2 then
- local handcards = self:rankHandCard(response.thirdHandcards);
- -- handcards = self:serverCardToMyCard(handcards);
-
- local userId = 0;
- local player = {
- nUserId = userId,
- nTurnScore = 0,
- nTotalMoney = 0,
- nBaoPaiStatus = 0,
- totalTuoNum = 0,
- tableWeaveCard = {},
- handCard = handcards,
- desertedArea = 0,
- };
-
- response.playList.Datas[userId] = player;
- end
-
- logD("Room:onGameXiaoJuResponse() :", table.tostring(response))
- self:dispatchEvent({name = "onGameXiaoJuResponse",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 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.isQiangBaHu = response.isQiangBaHu
-
- for k,v in ipairs(response.disCard or {}) do
- table.insert(self.roomInfo.disCard,v)
- end
-
- for k,v in ipairs(response.afterbadisCard or {}) do
- table.insert(self.roomInfo.disCard,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.roomInfo.startOpList["PengList"] = response.pengList
-
- 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
-
- if self:getActualPlayerNum() == 2 and table.nums(response.thirdHandcards) > 0 then
- local userId = 0
- local thirdHandcards = self:rankHandCard(response.thirdHandcards)
- thirdHandcards = self:serverCardToMyCard(thirdHandcards)
- if not self.roomInfo.memberList[userId] then
- self.roomInfo.memberList[userId] = {}
- end
- self.roomInfo.memberList[userId].cardList = thirdHandcards
-
- if self.roomInfo.arrayTableInfo[userId] then
- self.roomInfo.arrayTableInfo[userId].Datas.handCard.Datas = self:rankHandCard(response.thirdHandcards)
- 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: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 = {}
- --单个组合索引
- local index = 1
- --真实索引
- local realIndex = 1
-
- local tempserverCardlist = {}
-
- local singleCardList = {}
-
- for k,v in ipairs(serverCardList) do
- table.insert(tempserverCardlist,v.card)
- 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 <= 5 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
- local cardlist = templist
- cardData[realIndex] = cardlist
- realIndex = realIndex + 1
- end
-
- --[[ for k,templist in pairs(tempResultCardList) do
-
- if #templist > 5 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 == 5 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: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: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
-
- --先把加起来等于5的分开出来
- 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 == 5) and (resultData.num == 1 or resultData.num == 4) and resultData.value == resultData1.value)
- or ((resultData1.num + resultData.num == 5) and (resultData.num == 3 or resultData.num == 2) 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
-
- --再把对子放一起去 最多放两对
- 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 == 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
-
-
- for i = 1,#tt do
- table.sort(tt,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)
- end
-
- if leftNum <= 2 then
- local hasFind = false
- local lens = table.nums(tt)
- if lens > 0 then
- --优先去找对子
- for i=lens,1,-1 do
- local cardlist = tt[i]
- if table.nums(cardlist) == 4 and leftNum == 1 then
- 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
- hasFind = true
- end
- if hasFind then
- break
- end
- end
-
- --如果没有对子则找三个的
- if not hasFind then
- for i=lens,1,-1 do
- local cardlist = tt[i]
- if table.nums(cardlist) == 3 then
- 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
- hasFind = true
- end
- if hasFind then
- break
- end
- end
- end
- end
-
- --如果三个的都没有则单独放一列
- if not hasFind then
- 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
- elseif leftNum > 2 and leftNum <= 5 then
- 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
- else
- 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
- 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: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
-
- --获取自己的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 and v.nUserId ~= 0 then
- minID = v.nUserId
- isFind = true
- end
- end
- return minID
- end
-
- return Room;
|