You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

222 rivejä
6.3 KiB

  1. local RoomCmd=ZPFramework.ZPImport("zp_base.luaScript.Protocol.ZPCmd")
  2. local ZPMessage=ZPFramework.ZPImport("zp_base.luaScript.Protocol.ZPMessage")
  3. local ZPDef=ZPFramework.ZPImport("zp_base.luaScript.ZPDef")
  4. local ZPFuc=ZPFramework.ZPImport("zp_base.luaScript.ZPFunctions")
  5. local ZPProtocol=ZPFramework.ZPFrameworkClassImprot("zp_base.luaScript.Protocol.ZPProtocol")
  6. local Room = class("luzhouRoom" , ZPProtocol)
  7. function Room:ctor(net)
  8. Room.super.ctor(self , net);
  9. end
  10. -- 获取房间最大玩家人数
  11. function Room:getMaxPlayerCount()
  12. return self.roomInfo.nMaxPlayCount
  13. end
  14. -- 获取房间人数
  15. function Room:getPlayerCount()
  16. local count = 0
  17. for k,v in pairs(self.roomInfo.memberList) do
  18. count = count + 1
  19. end
  20. return count
  21. end
  22. -- 重置上局信息
  23. function Room:resetRound()
  24. self.roomInfo.quickStartInfo = nil
  25. end
  26. function Room:resetFastInfo()
  27. self.roomInfo.quickStartInfo = nil
  28. end
  29. function Room:onGameReconnection(status,response)
  30. Room.super.onGameReconnection(self,status,response)
  31. self:resetRound()
  32. local extInfo = json.decode(response.extJson or "")
  33. if extInfo and type(extInfo)=='table' and extInfo[tostring(self:getMyUserId())] then
  34. local myinfo = extInfo[tostring(self:getMyUserId())]
  35. self.roomInfo.hosting = myinfo.hosted or 0--托管状态
  36. self.roomInfo.quickStartInfo = extInfo.faststart--提前开局
  37. else
  38. self.roomInfo.hosting = 0
  39. end
  40. end
  41. function Room:isMyself(uid)
  42. return uid==self:getMyUserId()
  43. end
  44. -- 更新玩家的相对椅子号
  45. function Room:updateUserSeateShowId(xiaoSeatId)
  46. local myUserId = self:getMyRecordUserId()
  47. local mySeatId = self.roomInfo.memberList[myUserId].nSeatId
  48. self.roomInfo.nUserId = self:getMyRecordUserId()
  49. self.roomInfo.nSeatId = mySeatId
  50. --除了自己的第一次seatid辅助
  51. local anotherSeatID = -1
  52. --[视图椅子号] = userID
  53. --[座位号] = userID
  54. --[userID] = 视图椅子号
  55. self.seatShowList = {}
  56. self.userList = {}
  57. self.seatList = {}
  58. for k,v in pairs(self.roomInfo.memberList) do
  59. if v.nUserId and v.nSeatId then
  60. local maxNum = 3--ZPFuc.getCreateRoomPlayerNum()
  61. local isChange = false
  62. if app.room:getActualPlayerNum() >= 3 then
  63. maxNum = 4
  64. end
  65. local nSeatShowId --= (v.nSeatId - mySeatId + 4) % 4
  66. if mySeatId <= v.nSeatId then
  67. nSeatShowId = v.nSeatId - mySeatId
  68. elseif mySeatId > v.nSeatId then
  69. nSeatShowId = maxNum - mySeatId + v.nSeatId
  70. end
  71. if app.room:getActualPlayerNum() == 2 then--self.roomInfo.playerNum == 2 then
  72. if (v.nSeatId == mySeatId) then
  73. nSeatShowId = 4
  74. else
  75. nSeatShowId = 1--两人玩时,对家坐哪里
  76. end
  77. elseif app.room:getActualPlayerNum() == 3 and v.nUserId ~= 0 then
  78. if (v.nSeatId == mySeatId) then
  79. nSeatShowId = 4
  80. else
  81. --local nSeatShowId = (v.nSeatId - mySeatId + 4) % 4
  82. if nSeatShowId == 2 then
  83. if mySeatId > v.nSeatId then
  84. nSeatShowId = nSeatShowId + 1
  85. isChange = true
  86. else
  87. isChange = true
  88. nSeatShowId = nSeatShowId - 1
  89. end
  90. end
  91. if nSeatShowId == 0 then
  92. if mySeatId > v.nSeatId then
  93. nSeatShowId = nSeatShowId + 1
  94. else
  95. nSeatShowId = 3
  96. end
  97. elseif (nSeatShowId == 1 or nSeatShowId == 3) and anotherSeatID >= 0 then
  98. isChange = true
  99. end
  100. if anotherSeatID < 0 and not isChange then
  101. anotherSeatID = v.nSeatId
  102. end
  103. end
  104. elseif app.room:getActualPlayerNum() == 4 and v.nUserId ~= 0 then
  105. if (v.nSeatId == mySeatId) and (v.nSeatId ~= self.roomInfo.xiaoSeatId) then
  106. nSeatShowId = 4
  107. else
  108. if xiaoSeatId and xiaoSeatId >=0 and nSeatShowId == 2 then
  109. if mySeatId == xiaoSeatId then
  110. if math.abs(mySeatId - v.nSeatId) == 2 then
  111. nSeatShowId = 4
  112. end
  113. elseif mySeatId > v.nSeatId then
  114. isChange = true
  115. nSeatShowId = nSeatShowId + 1
  116. else
  117. isChange = true
  118. nSeatShowId = nSeatShowId - 1
  119. end
  120. else
  121. end
  122. if xiaoSeatId and v.nSeatId == self.roomInfo.xiaoSeatId then
  123. nSeatShowId = 2
  124. end
  125. end
  126. --强制转换小家视角与庄家一致
  127. if mySeatId == xiaoSeatId then
  128. if nSeatShowId == 1 then
  129. nSeatShowId = 3
  130. elseif nSeatShowId == 3 then
  131. nSeatShowId = 1
  132. end
  133. end
  134. end
  135. if nSeatShowId == 0 then
  136. nSeatShowId = 4
  137. end
  138. if v.nUserId == 0 then
  139. nSeatShowId = 2
  140. else
  141. if self.seatShowList[nSeatShowId] and isChange == true then
  142. if nSeatShowId == 1 then
  143. nSeatShowId = 3
  144. elseif nSeatShowId == 3 then
  145. nSeatShowId = 1
  146. end
  147. elseif self.seatShowList[nSeatShowId] and isChange == false then
  148. local olduid = self.seatShowList[nSeatShowId]
  149. local oldshowid = self.userList[olduid]
  150. local newshowid = 0
  151. if nSeatShowId == 1 then
  152. newshowid = 3
  153. elseif nSeatShowId == 3 then
  154. newshowid = 1
  155. end
  156. self.seatShowList[newshowid] = olduid
  157. self.userList[olduid] = newshowid
  158. end
  159. end
  160. self.seatShowList[nSeatShowId] = v.nUserId
  161. self.seatList[v.nSeatId] = v.nUserId
  162. self.userList[v.nUserId] = nSeatShowId
  163. end
  164. end
  165. logD("User:updateUserSeateShowId(), seatShowList", table.tostring(self.seatShowList))
  166. logD("User:updateUserSeateShowId(),seatList ", table.tostring(self.seatList))
  167. logD("User:updateUserSeateShowId(),userList ", table.tostring(self.userList))
  168. end
  169. --[[-- 玩家进入桌子成功
  170. function Room:onSitDownSuccessResponse(status, response)
  171. logD("--------------------玩家进入桌子成功--------------------")
  172. logD("Room:onSitDownSuccessResponse(), ", table.tostring(response))
  173. app.net:onMsgClear()
  174. app.net:onMsgPause()
  175. -- 记录当前桌子号
  176. self:initRoomInfo()
  177. -- 获取到的房间信息
  178. self.roomInfo.nShowTableId = response.nShowTableId
  179. self.roomInfo.nMaxPlayCount = response.nMaxPlayCount
  180. self.roomInfo.nRoomOwnedUid = response.nRoomOwnedUid
  181. self.roomInfo.nTotalGameNum = response.nTotalGameNum
  182. self.roomInfo.strGameInfo = response.strGameInfo
  183. -- 桌子上其他玩家的信息
  184. for k,v in pairs(response.memberList) do
  185. self.roomInfo.memberList[v.nUserId] = v
  186. end
  187. -- 更新椅子号
  188. self:updateUserSeateShowId()
  189. logD("Room:onSitDownSuccessResponse() roomInfo = ", table.tostring(self.roomInfo))
  190. -- 发送通知
  191. self:dispatchEvent({name = "onEnterRoomSuccess", gameId = GAME_IDS.luzhouDaEr, gameType = self.roomInfo.strGameInfo.gamerule})
  192. end--]]
  193. return Room;