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

222 рядки
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("xuyongRoom" , 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:addReconnectionData(response)
  30. self.roomInfo.nQuanCard = response.nQuanCard
  31. end
  32. function Room:onGameReconnection(status,response)
  33. Room.super.onGameReconnection(self,status,response)
  34. self:resetRound()
  35. local extInfo = json.decode(response.extJson or "")
  36. if extInfo and type(extInfo)=='table' and extInfo[tostring(self:getMyUserId())] then
  37. local myinfo = extInfo[tostring(self:getMyUserId())]
  38. self.roomInfo.hosting = myinfo.hosted or 0--托管状态
  39. self.roomInfo.quickStartInfo = extInfo.faststart--提前开局
  40. else
  41. self.roomInfo.hosting = 0
  42. end
  43. end
  44. function Room:isMyself(uid)
  45. return uid==self:getMyUserId()
  46. end
  47. -- 更新玩家的相对椅子号
  48. function Room:updateUserSeateShowId(xiaoSeatId)
  49. local myUserId = self:getMyRecordUserId()
  50. local mySeatId = self.roomInfo.memberList[myUserId].nSeatId
  51. self.roomInfo.nUserId = self:getMyRecordUserId()
  52. self.roomInfo.nSeatId = mySeatId
  53. --除了自己的第一次seatid辅助
  54. local anotherSeatID = -1
  55. --[视图椅子号] = userID
  56. --[座位号] = userID
  57. --[userID] = 视图椅子号
  58. self.seatShowList = {}
  59. self.userList = {}
  60. self.seatList = {}
  61. for k,v in pairs(self.roomInfo.memberList) do
  62. if v.nUserId and v.nSeatId then
  63. local maxNum = 3--ZPFuc.getCreateRoomPlayerNum()
  64. local isChange = false
  65. if app.room:getActualPlayerNum() >= 3 then
  66. maxNum = 4
  67. end
  68. local nSeatShowId --= (v.nSeatId - mySeatId + 4) % 4
  69. if mySeatId <= v.nSeatId then
  70. nSeatShowId = v.nSeatId - mySeatId
  71. elseif mySeatId > v.nSeatId then
  72. nSeatShowId = maxNum - mySeatId + v.nSeatId
  73. end
  74. if app.room:getActualPlayerNum() == 2 then--self.roomInfo.playerNum == 2 then
  75. if (v.nSeatId == mySeatId) then
  76. nSeatShowId = 4
  77. else
  78. nSeatShowId = 1--两人玩时,对家坐哪里
  79. end
  80. elseif app.room:getActualPlayerNum() == 3 and v.nUserId ~= 0 then
  81. if (v.nSeatId == mySeatId) then
  82. nSeatShowId = 4
  83. else
  84. --local nSeatShowId = (v.nSeatId - mySeatId + 4) % 4
  85. if nSeatShowId == 2 then
  86. if mySeatId > v.nSeatId then
  87. nSeatShowId = nSeatShowId + 1
  88. isChange = true
  89. else
  90. isChange = true
  91. nSeatShowId = nSeatShowId - 1
  92. end
  93. end
  94. if nSeatShowId == 0 then
  95. if mySeatId > v.nSeatId then
  96. nSeatShowId = nSeatShowId + 1
  97. else
  98. nSeatShowId = 3
  99. end
  100. elseif (nSeatShowId == 1 or nSeatShowId == 3) and anotherSeatID >= 0 then
  101. isChange = true
  102. end
  103. if anotherSeatID < 0 and not isChange then
  104. anotherSeatID = v.nSeatId
  105. end
  106. end
  107. elseif app.room:getActualPlayerNum() == 4 and v.nUserId ~= 0 then
  108. if (v.nSeatId == mySeatId) and (v.nSeatId ~= self.roomInfo.xiaoSeatId) then
  109. nSeatShowId = 4
  110. else
  111. if xiaoSeatId and xiaoSeatId >=0 and nSeatShowId == 2 then
  112. if mySeatId == xiaoSeatId then
  113. if math.abs(mySeatId - v.nSeatId) == 2 then
  114. nSeatShowId = 4
  115. end
  116. elseif mySeatId > v.nSeatId then
  117. isChange = true
  118. nSeatShowId = nSeatShowId + 1
  119. else
  120. isChange = true
  121. nSeatShowId = nSeatShowId - 1
  122. end
  123. else
  124. end
  125. if xiaoSeatId and v.nSeatId == self.roomInfo.xiaoSeatId then
  126. nSeatShowId = 2
  127. end
  128. end
  129. --强制转换小家视角与庄家一致
  130. if mySeatId == xiaoSeatId then
  131. if nSeatShowId == 1 then
  132. nSeatShowId = 3
  133. elseif nSeatShowId == 3 then
  134. nSeatShowId = 1
  135. end
  136. end
  137. end
  138. if nSeatShowId == 0 then
  139. nSeatShowId = 4
  140. end
  141. if v.nUserId == 0 then
  142. nSeatShowId = 2
  143. else
  144. if self.seatShowList[nSeatShowId] and isChange == true then
  145. if nSeatShowId == 1 then
  146. nSeatShowId = 3
  147. elseif nSeatShowId == 3 then
  148. nSeatShowId = 1
  149. end
  150. elseif self.seatShowList[nSeatShowId] and isChange == false then
  151. local olduid = self.seatShowList[nSeatShowId]
  152. local oldshowid = self.userList[olduid]
  153. local newshowid = 0
  154. if nSeatShowId == 1 then
  155. newshowid = 3
  156. elseif nSeatShowId == 3 then
  157. newshowid = 1
  158. end
  159. self.seatShowList[newshowid] = olduid
  160. self.userList[olduid] = newshowid
  161. end
  162. end
  163. self.seatShowList[nSeatShowId] = v.nUserId
  164. self.seatList[v.nSeatId] = v.nUserId
  165. self.userList[v.nUserId] = nSeatShowId
  166. end
  167. end
  168. logD("User:updateUserSeateShowId(), seatShowList", table.tostring(self.seatShowList))
  169. logD("User:updateUserSeateShowId(),seatList ", table.tostring(self.seatList))
  170. logD("User:updateUserSeateShowId(),userList ", table.tostring(self.userList))
  171. end
  172. -- 游戏发牌结果
  173. function Room:onGameSendCardResponse(status, response)
  174. logD("-------------------- 游戏发牌 ------------------------")
  175. if not self.roomInfo then
  176. logD("self.roomInfo no exist,容错处理!")
  177. return
  178. end
  179. logD("Room:onGameSendCardResponse(), ", table.tostring(response))
  180. self.roomInfo.nbankFirstGrabCard = response.nbankFirstGrabCard
  181. --目前server只发自己过来,后续战绩回放考虑到会发所有玩家来,故以userid为key于扩展
  182. local cardData = self:serverCardToMyCard(response.cardList)
  183. logD("Room:onGameSendCardResponse : "..table.tostring(cardData))
  184. self.roomInfo.memberList[response.nUserId].cardList = cardData
  185. self.cards[response.nUserId] = cardData
  186. if self:isLittleFamily() then
  187. self.roomInfo.nBankUid = response.nUserId
  188. self.cards[app.user.loginInfo.uid] = cardData
  189. end
  190. self.roomInfo.nQuanCard = response.nQuanCard
  191. -- 发送广播通知,发牌开始了
  192. self:dispatchEvent({name = "onGameSendCardResponse"});
  193. end
  194. return Room;