local RoomCmd=MJFramework.MJImport("mj.luaScript.Protocol.MJCmd") local MJMessage=MJFramework.MJImport("mj.luaScript.Protocol.MJMessage") local MJDefine=MJFramework.MJImport("mj.luaScript.MJDefine") local MJProtocol=MJFramework.MJFrameworkClassImprot("mj.luaScript.Protocol.MJProtocol") local Room = class("hongzhongRoom" , MJProtocol) function Room:addExtendData(response) for k, v in pairs(response.playerPiaoInfos) do if not self.roomInfo.memberList[v.nUserId] then self.roomInfo.memberList[v.nUserId] = {} end self.roomInfo.memberList[v.nUserId].nPiaoNum = v.nPiaoNum end end -- function Room:setMemberInfo(v) -- Room.super.setMemberInfo(self,v) -- self.roomInfo.memberList[v.nUserId].nPiaoNum = v.nPiaoNum -- end function Room:onXiaPiaoResponse(status,response) logD("-------------------- hongzhongRoom:onXiaPiaoResponse ------------------------") if not self.roomInfo then print("容错处理") return end local nUserId=response.nUserId local nPiaoNum=response.nPiaoNum if self.roomInfo.memberList[nUserId] then self.roomInfo.memberList[nUserId].nPiaoNum=nPiaoNum end self:dispatchEvent({name = MJDefine.MJEvent.XiaPiaoResponse, nUserId=nUserId}) end function Room:onXiaPiaoTime(status,response) logD("-------------------- hongzhongRoom:onXiaPiaoTime ------------------------") if not self.roomInfo then print("容错处理") return end self.roomInfo.nPiaoLeftTime=response.nPiaoLeftTime self:dispatchEvent({name = MJDefine.MJEvent.XiaPiaoTime}) end function Room:ctor(net) Room.super.ctor(self , net); --请求重连消息 self:defMsgFunc{name = MJDefine.MJEvent.GetTableInfo,cmd = RoomCmd.GAME_COMMAND_GET_TABLE_INFO}; --选择飘 self:defMsgFunc{name = MJDefine.MJEvent.XiaPiao,cmd = RoomCmd.GAME_COMMAND_XIA_PIAO ,sender = MJMessage.XiaPiao} --回应 self:defPushMsg{cmd = RoomCmd.GAME_COMMAND_XIA_PIAO,reader = MJMessage.XiaPiaoResponse,func = handler(self,self.onXiaPiaoResponse)} self:defPushMsg{cmd = RoomCmd.GAME_COMMAND_XIA_PIAO_TIME,reader = MJMessage.XiaPiaoTime,func = handler(self,self.onXiaPiaoTime)} -- 客户端发起快速请求 self:defMsgFunc{name = MJDefine.MJEvent.RequestFastsStart, cmd = RoomCmd.GAME_COMMAND_FAST_START_GAME, sender = MJMessage.FastStartRequest} -- 快速开始请求返回 if not self.PushMsgList[RoomCmd.GAME_COMMAND_FAST_START_RESULT] then self:defPushMsg{cmd = RoomCmd.GAME_COMMAND_FAST_START_RESULT, reader = MJMessage.FastStartRequestResult, func = handler(self, self.onUserRequestFastError)} end -- 快速开始广播请求 if not self.PushMsgList[RoomCmd.GAME_COMMAND_BROAD_FAST_START_GAME] then self:defPushMsg{cmd = RoomCmd.GAME_COMMAND_BROAD_FAST_START_GAME, reader = MJMessage.FastStartStatus, func = handler(self, self.onBroadcastFastRequest)} end -- 快速开始成功 if not self.PushMsgList[RoomCmd.GAME_COMMAND_BROAD_QUICKLY_START] then self:defPushMsg{cmd = RoomCmd.GAME_COMMAND_BROAD_QUICKLY_START, reader = MJMessage.UpdateSeatIds, func = handler(self, self.onFastStartSucc)} end -- 收到托管回调 self:defPushMsg{cmd = RoomCmd.GAME_COMMAND_USER_HOSTING_REQUEST, reader = MJMessage.HostingRequest, func = handler(self,self.onHostingRequest)} -- user pass self:defPushMsg{cmd = RoomCmd.GAME_COMMAND_USER_PASS, reader = MJMessage.UserPass, func = handler(self,self.onUserPassRequest)} -- 请求托管 self:defMsgFunc{name = MJDefine.MJEvent.HostingRequest, cmd = RoomCmd.GAME_COMMAND_USER_HOSTING_REQUEST, sender = MJMessage.HostingRequest} --推送听 self:defPushMsg{cmd = RoomCmd.GAME_PUSH_TING, reader = MJMessage.Tings, func = handler(self , self.pushTing)}; 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 = MJDefine.MJEvent.FastStartSucc ,response = response}) end -- 快速开始操作广播 function Room:onBroadcastFastRequest( status, response )-- self:dispatchEvent({name = MJDefine.MJEvent.BraodcastFastStart ,response = response}) end -- 款速开始请求返回 function Room:onUserRequestFastError( status, response )--快速开始请求错误提示错误 local errTxt ={ [0] = "成功", [1] = "人数不够", [2] = "其他人已请求", [3] = "房间人数已满", [4] = "非法操作" } local txt = errTxt[response.result] if txt then showTooltip(txt) end 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 self.roomInfo.hosting = 0--重置托管 end function Room:resetFastInfo() self.roomInfo.quickStartInfo = nil end function Room:onGameReconnection(status,response) -- 获取到的房间信息 Room.super.onGameReconnection(self,status,response) self.roomInfo.shuffleNum = response.shuffleNum self:resetRound() local extInfo = json.decode(response.extJson or "") self.roomInfo.extJson = extInfo 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 end function Room:isMyself(uid) return uid==self:getMyUserId() end -- 托管 function Room:onHostingRequest( status, response ) -- 是否托管 if response.nUserId == self:getMyUserId() then self.roomInfo.hosting = response.status end self:dispatchEvent({name = MJDefine.MJEvent.HostingRequest, response = response}); end -- 收到服务器下发PASS操作 function Room:onUserPassRequest( status, response ) self:dispatchEvent({name = MJDefine.MJEvent.USER_PASS ,response = response}); end -- 根据uid获取座位号 function Room:getSeatIdByUserId( nUserId ) return self:getSeatIdByViewId(self:getViewIdByUserId(nUserId)) end -- 视角转换 function Room:transPos(targetSeatId, seatId ) local MaxCount = self.roomInfo.nMaxPlayCount local showPos = 4 local target = targetSeatId if target <= seatId then showPos = seatId - target elseif target > seatId then showPos = MaxCount - target + seatId end return showPos end function Room:isAutoPopupGPS() return false end return Room;