Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

204 рядки
6.7 KiB

  1. local RoomCmd=MJFramework.MJImport("mj.luaScript.Protocol.MJCmd")
  2. local MJMessage=MJFramework.MJImport("mj.luaScript.Protocol.MJMessage")
  3. local MJDefine=MJFramework.MJImport("mj.luaScript.MJDefine")
  4. local MJProtocol=MJFramework.MJFrameworkClassImprot("mj.luaScript.Protocol.MJProtocol")
  5. local Room = class("hongzhongRoom" , MJProtocol)
  6. function Room:addExtendData(response)
  7. for k, v in pairs(response.playerPiaoInfos) do
  8. if not self.roomInfo.memberList[v.nUserId] then
  9. self.roomInfo.memberList[v.nUserId] = {}
  10. end
  11. self.roomInfo.memberList[v.nUserId].nPiaoNum = v.nPiaoNum
  12. end
  13. end
  14. -- function Room:setMemberInfo(v)
  15. -- Room.super.setMemberInfo(self,v)
  16. -- self.roomInfo.memberList[v.nUserId].nPiaoNum = v.nPiaoNum
  17. -- end
  18. function Room:onXiaPiaoResponse(status,response)
  19. logD("-------------------- hongzhongRoom:onXiaPiaoResponse ------------------------")
  20. if not self.roomInfo then
  21. print("容错处理")
  22. return
  23. end
  24. local nUserId=response.nUserId
  25. local nPiaoNum=response.nPiaoNum
  26. if self.roomInfo.memberList[nUserId] then
  27. self.roomInfo.memberList[nUserId].nPiaoNum=nPiaoNum
  28. end
  29. self:dispatchEvent({name = MJDefine.MJEvent.XiaPiaoResponse, nUserId=nUserId})
  30. end
  31. function Room:onXiaPiaoTime(status,response)
  32. logD("-------------------- hongzhongRoom:onXiaPiaoTime ------------------------")
  33. if not self.roomInfo then
  34. print("容错处理")
  35. return
  36. end
  37. self.roomInfo.nPiaoLeftTime=response.nPiaoLeftTime
  38. self:dispatchEvent({name = MJDefine.MJEvent.XiaPiaoTime})
  39. end
  40. function Room:ctor(net)
  41. Room.super.ctor(self , net);
  42. --请求重连消息
  43. self:defMsgFunc{name = MJDefine.MJEvent.GetTableInfo,cmd = RoomCmd.GAME_COMMAND_GET_TABLE_INFO};
  44. --选择飘
  45. self:defMsgFunc{name = MJDefine.MJEvent.XiaPiao,cmd = RoomCmd.GAME_COMMAND_XIA_PIAO ,sender = MJMessage.XiaPiao}
  46. --回应
  47. self:defPushMsg{cmd = RoomCmd.GAME_COMMAND_XIA_PIAO,reader = MJMessage.XiaPiaoResponse,func = handler(self,self.onXiaPiaoResponse)}
  48. self:defPushMsg{cmd = RoomCmd.GAME_COMMAND_XIA_PIAO_TIME,reader = MJMessage.XiaPiaoTime,func = handler(self,self.onXiaPiaoTime)}
  49. -- 客户端发起快速请求
  50. self:defMsgFunc{name = MJDefine.MJEvent.RequestFastsStart, cmd = RoomCmd.GAME_COMMAND_FAST_START_GAME, sender = MJMessage.FastStartRequest}
  51. -- 快速开始请求返回
  52. if not self.PushMsgList[RoomCmd.GAME_COMMAND_FAST_START_RESULT] then
  53. self:defPushMsg{cmd = RoomCmd.GAME_COMMAND_FAST_START_RESULT, reader = MJMessage.FastStartRequestResult, func = handler(self, self.onUserRequestFastError)}
  54. end
  55. -- 快速开始广播请求
  56. if not self.PushMsgList[RoomCmd.GAME_COMMAND_BROAD_FAST_START_GAME] then
  57. self:defPushMsg{cmd = RoomCmd.GAME_COMMAND_BROAD_FAST_START_GAME, reader = MJMessage.FastStartStatus, func = handler(self, self.onBroadcastFastRequest)}
  58. end
  59. -- 快速开始成功
  60. if not self.PushMsgList[RoomCmd.GAME_COMMAND_BROAD_QUICKLY_START] then
  61. self:defPushMsg{cmd = RoomCmd.GAME_COMMAND_BROAD_QUICKLY_START, reader = MJMessage.UpdateSeatIds, func = handler(self, self.onFastStartSucc)}
  62. end
  63. -- 收到托管回调
  64. self:defPushMsg{cmd = RoomCmd.GAME_COMMAND_USER_HOSTING_REQUEST, reader = MJMessage.HostingRequest, func = handler(self,self.onHostingRequest)}
  65. -- user pass
  66. self:defPushMsg{cmd = RoomCmd.GAME_COMMAND_USER_PASS, reader = MJMessage.UserPass, func = handler(self,self.onUserPassRequest)}
  67. -- 请求托管
  68. self:defMsgFunc{name = MJDefine.MJEvent.HostingRequest, cmd = RoomCmd.GAME_COMMAND_USER_HOSTING_REQUEST, sender = MJMessage.HostingRequest}
  69. --推送听
  70. self:defPushMsg{cmd = RoomCmd.GAME_PUSH_TING, reader = MJMessage.Tings, func = handler(self , self.pushTing)};
  71. end
  72. -- 游戏快速开始,更新玩家座位号
  73. function Room:onFastStartSucc( status, response )
  74. self.roomInfo.nMaxPlayCount = #response.pList
  75. local gameInfo = json.decode(self.roomInfo.strGameInfo)
  76. gameInfo.playnum = self.roomInfo.nMaxPlayCount
  77. self.roomInfo.strGameInfo = json.encode(gameInfo)
  78. for _,v in pairs(response.pList) do
  79. self.roomInfo.memberList[v.nUserId].nSeatId = v.nSeatId
  80. end
  81. -- 更新椅子号
  82. self.seatShowList = {}
  83. self:updateUserSeateShowId()
  84. self:dispatchEvent({name = MJDefine.MJEvent.FastStartSucc ,response = response})
  85. end
  86. -- 快速开始操作广播
  87. function Room:onBroadcastFastRequest( status, response )--
  88. self:dispatchEvent({name = MJDefine.MJEvent.BraodcastFastStart ,response = response})
  89. end
  90. -- 款速开始请求返回
  91. function Room:onUserRequestFastError( status, response )--快速开始请求错误提示错误
  92. local errTxt ={
  93. [0] = "成功",
  94. [1] = "人数不够",
  95. [2] = "其他人已请求",
  96. [3] = "房间人数已满",
  97. [4] = "非法操作"
  98. }
  99. local txt = errTxt[response.result]
  100. if txt then
  101. showTooltip(txt)
  102. end
  103. end
  104. -- 获取房间最大玩家人数
  105. function Room:getMaxPlayerCount()
  106. return self.roomInfo.nMaxPlayCount
  107. end
  108. -- 获取房间人数
  109. function Room:getPlayerCount()
  110. local count = 0
  111. for k,v in pairs(self.roomInfo.memberList) do
  112. count = count + 1
  113. end
  114. return count
  115. end
  116. -- 重置上局信息
  117. function Room:resetRound()
  118. self.roomInfo.quickStartInfo = nil
  119. self.roomInfo.hosting = 0--重置托管
  120. end
  121. function Room:resetFastInfo()
  122. self.roomInfo.quickStartInfo = nil
  123. end
  124. function Room:onGameReconnection(status,response)
  125. -- 获取到的房间信息
  126. Room.super.onGameReconnection(self,status,response)
  127. self.roomInfo.shuffleNum = response.shuffleNum
  128. self:resetRound()
  129. local extInfo = json.decode(response.extJson or "")
  130. self.roomInfo.extJson = extInfo
  131. if extInfo and type(extInfo)=='table' and extInfo[tostring(self:getMyUserId())] then
  132. local myinfo = extInfo[tostring(self:getMyUserId())]
  133. self.roomInfo.hosting = myinfo.hosted or 0--托管状态
  134. self.roomInfo.quickStartInfo = extInfo.faststart--提前开局
  135. else
  136. self.roomInfo.hosting = 0
  137. end
  138. end
  139. function Room:isMyself(uid)
  140. return uid==self:getMyUserId()
  141. end
  142. -- 托管
  143. function Room:onHostingRequest( status, response )
  144. -- 是否托管
  145. if response.nUserId == self:getMyUserId() then
  146. self.roomInfo.hosting = response.status
  147. end
  148. self:dispatchEvent({name = MJDefine.MJEvent.HostingRequest, response = response});
  149. end
  150. -- 收到服务器下发PASS操作
  151. function Room:onUserPassRequest( status, response )
  152. self:dispatchEvent({name = MJDefine.MJEvent.USER_PASS ,response = response});
  153. end
  154. -- 根据uid获取座位号
  155. function Room:getSeatIdByUserId( nUserId )
  156. return self:getSeatIdByViewId(self:getViewIdByUserId(nUserId))
  157. end
  158. -- 视角转换
  159. function Room:transPos(targetSeatId, seatId )
  160. local MaxCount = self.roomInfo.nMaxPlayCount
  161. local showPos = 4
  162. local target = targetSeatId
  163. if target <= seatId then
  164. showPos = seatId - target
  165. elseif target > seatId then
  166. showPos = MaxCount - target + seatId
  167. end
  168. return showPos
  169. end
  170. function Room:isAutoPopupGPS()
  171. return false
  172. end
  173. return Room;