您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

195 行
5.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("hejiangRoom" , 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. --扩展给子类用
  42. function Room:addReconnectionData(response)
  43. self.roomInfo.delayPlayer = response.delayPlayer
  44. end
  45. function Room:isMyself(uid)
  46. return uid==self:getMyUserId()
  47. end
  48. -- 更新玩家的相对椅子号
  49. function Room:updateUserSeateShowId(xiaoSeatId)
  50. local myUserId = self:getMyRecordUserId()
  51. local mySeatId = self.roomInfo.memberList[myUserId].nSeatId
  52. self.roomInfo.nUserId = self:getMyRecordUserId()
  53. self.roomInfo.nSeatId = mySeatId
  54. --除了自己的第一次seatid辅助
  55. local anotherSeatID = -1
  56. --[视图椅子号] = userID
  57. --[座位号] = userID
  58. --[userID] = 视图椅子号
  59. self.seatShowList = {}
  60. self.userList = {}
  61. self.seatList = {}
  62. for k,v in pairs(self.roomInfo.memberList) do
  63. if v.nUserId and v.nSeatId then
  64. local maxNum = 3--ZPFuc.getCreateRoomPlayerNum()
  65. local isChange = false
  66. if app.room:getActualPlayerNum() >= 3 then
  67. maxNum = 4
  68. end
  69. local nSeatShowId --= (v.nSeatId - mySeatId + 4) % 4
  70. if mySeatId <= v.nSeatId then
  71. nSeatShowId = v.nSeatId - mySeatId
  72. elseif mySeatId > v.nSeatId then
  73. nSeatShowId = maxNum - mySeatId + v.nSeatId
  74. end
  75. if app.room:getActualPlayerNum() == 2 then--self.roomInfo.playerNum == 2 then
  76. if (v.nSeatId == mySeatId) then
  77. nSeatShowId = 4
  78. else
  79. nSeatShowId = 1--两人玩时,对家坐哪里
  80. end
  81. elseif app.room:getActualPlayerNum() == 3 then
  82. if (v.nSeatId == mySeatId) then
  83. nSeatShowId = 4
  84. else
  85. --local nSeatShowId = (v.nSeatId - mySeatId + 4) % 4
  86. if nSeatShowId == 2 then
  87. if mySeatId > v.nSeatId then
  88. nSeatShowId = nSeatShowId + 1
  89. isChange = true
  90. else
  91. isChange = true
  92. nSeatShowId = nSeatShowId - 1
  93. end
  94. end
  95. if nSeatShowId == 0 then
  96. if mySeatId > v.nSeatId then
  97. nSeatShowId = nSeatShowId + 1
  98. else
  99. nSeatShowId = 3
  100. end
  101. --[[elseif (nSeatShowId == 1 or nSeatShowId == 3) and anotherSeatID >= 0 then
  102. isChange = true--]]
  103. end
  104. if anotherSeatID < 0 and not isChange then
  105. anotherSeatID = v.nSeatId
  106. end
  107. end
  108. elseif app.room:getActualPlayerNum() == 4 then
  109. if (v.nSeatId == mySeatId) and (v.nSeatId ~= self.roomInfo.xiaoSeatId) then
  110. nSeatShowId = 4
  111. else
  112. if xiaoSeatId and xiaoSeatId >=0 and nSeatShowId == 2 then
  113. if mySeatId == xiaoSeatId then
  114. if math.abs(mySeatId - v.nSeatId) == 2 then
  115. nSeatShowId = 4
  116. end
  117. elseif mySeatId > v.nSeatId then
  118. isChange = true
  119. nSeatShowId = nSeatShowId + 1
  120. else
  121. isChange = true
  122. nSeatShowId = nSeatShowId - 1
  123. end
  124. else
  125. end
  126. if xiaoSeatId and v.nSeatId == self.roomInfo.xiaoSeatId then
  127. nSeatShowId = 2
  128. end
  129. end
  130. --强制转换小家视角与庄家一致
  131. if mySeatId == xiaoSeatId then
  132. if nSeatShowId == 1 then
  133. nSeatShowId = 3
  134. elseif nSeatShowId == 3 then
  135. nSeatShowId = 1
  136. end
  137. end
  138. end
  139. if nSeatShowId == 0 then
  140. nSeatShowId = 4
  141. end
  142. if v.nUserId == 0 then
  143. nSeatShowId = 2
  144. else
  145. if self.seatShowList[nSeatShowId] and isChange == true then
  146. if nSeatShowId == 1 then
  147. nSeatShowId = 3
  148. elseif nSeatShowId == 3 then
  149. nSeatShowId = 1
  150. end
  151. elseif self.seatShowList[nSeatShowId] and isChange == false then
  152. local olduid = self.seatShowList[nSeatShowId]
  153. local oldshowid = self.userList[olduid]
  154. local newshowid = 0
  155. if nSeatShowId == 1 then
  156. newshowid = 3
  157. elseif nSeatShowId == 3 then
  158. newshowid = 1
  159. end
  160. self.seatShowList[newshowid] = olduid
  161. self.userList[olduid] = newshowid
  162. end
  163. end
  164. self.seatShowList[nSeatShowId] = v.nUserId
  165. self.seatList[v.nSeatId] = v.nUserId
  166. self.userList[v.nUserId] = nSeatShowId
  167. end
  168. end
  169. logD("User:updateUserSeateShowId(), seatShowList", table.tostring(self.seatShowList))
  170. logD("User:updateUserSeateShowId(),seatList ", table.tostring(self.seatList))
  171. logD("User:updateUserSeateShowId(),userList ", table.tostring(self.userList))
  172. end
  173. return Room;