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.

300 lines
8.4 KiB

  1. local RoomCmd = {
  2. --[[/**
  3. * 客户端通过协议0x8060通知server, 用户信息改变
  4. * <pre>
  5. * 推送: {@code ClientChangeUserInfo}
  6. * </pre>
  7. */--]]
  8. GAME_COMMAND_CLIENT_CHANGE_USERINFO = 0x8060,
  9. --[[/**
  10. * server收到0x8060协议后,广播当前桌子上所有用户
  11. * <pre>
  12. * 推送: {@code ServerChangeUserInfo}
  13. * </pre>
  14. */--]]
  15. GAME_COMMAND_SERVER_CHANGE_USERINFO = 0x8061,
  16. --[[/**
  17. * server收到0x8018协议后,广播当前桌子上所有用户
  18. 若小局结束后发现玩家红花数不足,系统则会自动解散此牌局,解散前服务器广播每个玩家 解散的具体的原因
  19. * <pre>
  20. * 推送: {@code RedFlowerDismiss}
  21. * </pre>
  22. */--]]
  23. GAME_COMMAND_RED_FLOWER_DISMISS = 0x8018,
  24. --[[/**
  25. * 洗牌协议
  26. * <pre>
  27. * 推送: {@code }
  28. * </pre>
  29. */--]]
  30. GAME_COMMAND_XIPAI = 0x8062,
  31. --[[/**
  32. * 游戏结束后,服务器判断大赢家是否满足赠送条件,满足赠送条件的用户将会收到协议
  33. * <pre>
  34. * 推送: {@code ChouJiangBroad}
  35. * </pre>
  36. */--]]
  37. GAME_COMMAND_CHOUJIANG = 0x800a,
  38. }
  39. --* server收到0x8018协议后,广播当前桌子上所有用户
  40. local ChouJiangBroad = defClass("ChouJiangBroad"
  41. --赠送产生的唯一标识,客户端拿到传给php领奖
  42. , defVar("rewardToken", VT_String, "")
  43. --玩家剩余的积分
  44. , defVar("leftMatchScore", VT_Int, 0)
  45. --需要支付的积分
  46. , defVar("useScore", VT_Int, 0)
  47. --[[奖励格式json串,内容:
  48. {"prize":["
  49. {\"idx\":4,\"type\":13,\"val\":0}",
  50. "{\"idx\":5,\"type\":13,\"val\":0}",
  51. "{\"idx\":1,\"type\":13,\"val\":0}",
  52. "{\"idx\":2,\"type\":13,\"val\":0}",
  53. "{\"idx\":3,\"type\":13,\"val\":0}"
  54. ]}
  55. idx表示序号,type表示奖励类型,13表示房卡,1表示金币 val对应奖励的数值
  56. ]]
  57. , defVar("rewardInfo", VT_String, "")
  58. )
  59. --* server收到0x8018协议后,广播当前桌子上所有用户
  60. local RedFlowerDismiss = defClass("RedFlowerDismiss"
  61. --更新信息的用户uid
  62. , defVar("retCode", VT_Short, 0)
  63. )
  64. --server收到0x8060协议后,广播当前桌子上所有用户
  65. local ServerChangeUserInfo = defClass("ServerChangeUserInfo"
  66. --更新信息的用户uid
  67. , defVar("uid", VT_Int, -1)
  68. --用户信息
  69. , defVar("userInfo", VT_String, "")
  70. --保留字段,暂不使用
  71. , defVar("reserved", VT_String, "")
  72. )
  73. local RoomBase = class("RoomBase" , require("luaScript.Protocol.Protocol"))
  74. local matchErrorTip = {
  75. [1] = "超时停止游戏",
  76. [2] = "群主解散",
  77. [3] = "房卡不足",
  78. [4] = "系统解散",
  79. [5] = "桌子上有玩家红花数不足,房间自动解散!",
  80. }
  81. function RoomBase:ctor(net)
  82. RoomBase.super.ctor(self , net);
  83. -- 清空大结算抽奖数据,可能由于某些原因,
  84. -- 导致大结算没弹框或者消息延迟收到有数据缓存
  85. dd.IGameOverAward.setAwardData(nil)
  86. self:initBindEvent()
  87. end
  88. function RoomBase:initBindEvent()
  89. self:defPushMsg{cmd = RoomCmd.GAME_COMMAND_SERVER_CHANGE_USERINFO, reader = ServerChangeUserInfo, func = handler(self , self.onGpsChangeResponse)}
  90. self:defPushMsg{cmd = RoomCmd.GAME_COMMAND_RED_FLOWER_DISMISS, reader = RedFlowerDismiss, func = handler(self , self.onRedFlowerDismiss)}
  91. self:defPushMsg{cmd = RoomCmd.GAME_COMMAND_XIPAI, reader = BytePacket, func = handler(self , self.onGameXiPai)}
  92. self:defPushMsg{cmd = RoomCmd.GAME_COMMAND_CHOUJIANG, reader = ChouJiangBroad, func = handler(self , self.onChouJiangBroad)}
  93. end
  94. -- 通知服务器玩家GPS数据发生变化
  95. function RoomBase:requestGpsChange()
  96. local request = StringPacket:new()
  97. request.stringValue = app.user.userInfo or ""
  98. logD("RoomBase:requestGpsChange()", table.tostring(request))
  99. self:sendResponse{cmd = RoomCmd.GAME_COMMAND_CLIENT_CHANGE_USERINFO , sender = request};
  100. end
  101. -- 服务器下发玩家GPS数据发生变化
  102. function RoomBase:onGpsChangeResponse(status, response)
  103. print("RoomBase:onGpsChangeResponse()", table.tostring(response))
  104. --[[
  105. --server收到0x8060协议后,广播当前桌子上所有用户
  106. ServerChangeUserInfo = defClass("ServerChangeUserInfo"
  107. --更新信息的用户uid
  108. , defVar("uid", VT_Int, -1)
  109. --用户信息
  110. , defVar("userInfo", VT_String, "")
  111. --保留字段,暂不使用
  112. , defVar("reserved", VT_String, "")
  113. )
  114. --]]
  115. -- print("RoomBase:onGpsChangeResponse()", table.tostring(response))
  116. local nUserId = response.uid
  117. local memberInfo = self.roomInfo and self.roomInfo.memberList and self.roomInfo.memberList[nUserId]
  118. if memberInfo then
  119. memberInfo.userInfo = response.userInfo
  120. end
  121. self:updateGpsUserInfo(nUserId)
  122. end
  123. function RoomBase:onRedFlowerDismiss(status, response)
  124. print("RoomBase:onRedFlowerDismiss()", table.tostring(response))
  125. local code = response.retCode
  126. if code then
  127. self.roomInfo.isRedFlowerDismiss = true
  128. local retCode = matchErrorTip[code] or "errcode【"..code.."】不存在!"
  129. if code == 5 then
  130. retCode = "桌子上有玩家排名分不足,房间自动解散!"
  131. if app.club_php.clubID and app.club_php.clubID ~= 0 then
  132. if app.club_php:getCestIsOpen(app.club_php.clubID) then
  133. retCode = "桌上有选手比赛积分不足被淘汰,房间自动解散。"
  134. end
  135. end
  136. end
  137. showConfirmDialog(retCode)
  138. end
  139. end
  140. --更新gps用户数据
  141. --需要检测的ID 没有则检测所有人的距离
  142. --isOpenView 危险距离是否主动弹出提示
  143. function RoomBase:updateGpsUserInfo(userId,isOpenView)
  144. if self.roomInfo and self.roomInfo.memberList then
  145. local isGameStart = self.roomInfo.nGameStartCount>0
  146. local userInfoList = {}
  147. for nUserId, memberInfo in pairs(self.roomInfo.memberList) do
  148. local nSeatId = memberInfo.nSeatId
  149. local userInfo = memberInfo.userInfo
  150. userInfoList[nUserId] = {nSeatId = nSeatId, userInfo = userInfo}
  151. end
  152. if isGameStart then
  153. isOpenView = false
  154. end
  155. self:dispatchEvent({
  156. name = GAME_EVENT.GPS_UPDATE_USER_INFO,
  157. userId=userId,
  158. userInfoList = userInfoList,
  159. isOpenView = isOpenView or false,
  160. isGameStart = isGameStart,
  161. -- maxPlayerNum = self.roomInfo.nMaxPlayCount,
  162. })
  163. end
  164. end
  165. --检测本地gps信息跟服务器数据是否一致,不一致则发送更新
  166. function RoomBase:checkGpsIsNew()
  167. if self.roomInfo and self.roomInfo.memberList then
  168. local myUserId = app.room:getMyUserId() or app.user.loginInfo.uid
  169. local user = self.roomInfo.memberList[myUserId]
  170. if user then
  171. local userInfo = json.decode(user.userInfo or "")
  172. if userInfo then
  173. local isNewest = app.user:isGpsInfoNewest(userInfo.gpsInfo)
  174. --不是最新的数据则发送给服务器同步
  175. if not isNewest then
  176. app.room:requestGpsChange()
  177. return false
  178. end
  179. end
  180. end
  181. end
  182. return true
  183. end
  184. -- 通过玩家逻辑椅子号找到玩家ID
  185. function RoomBase:getUserIdBySeatId(nSeatId)
  186. return 0
  187. end
  188. -- 通过玩家视图椅子号找到玩家ID
  189. function RoomBase:getUserIdByViewId(nViewId)
  190. return nil
  191. end
  192. -- 通过玩家ID获取玩家展示的座位号
  193. function RoomBase:getViewIdByUserId(nUserId)
  194. return 1
  195. end
  196. -- 通过玩家逻辑椅子号找到视图椅子号
  197. function RoomBase:getViewIdBySeatId(nSeatId)
  198. return 1
  199. end
  200. -- 通过玩家ID找到逻辑椅子号
  201. function RoomBase:getSeatIdByUserId(nViewId)
  202. return 1
  203. end
  204. -- 通过玩家视图椅子号找到逻辑椅子号
  205. function RoomBase:getSeatIdByViewId(nUserId)
  206. return 1
  207. end
  208. -- 获取房间内的用户信息
  209. function RoomBase:getUserInfo(uid)
  210. return ""
  211. end
  212. function RoomBase:getMyUserId()
  213. if self:isInMemberList() then
  214. return app.user.loginInfo.uid
  215. else
  216. if self.roomInfo and self.roomInfo.memberList then
  217. for nUserId,v in pairs(self.roomInfo.memberList) do
  218. return nUserId
  219. end
  220. else
  221. return app.user.loginInfo.uid
  222. end
  223. end
  224. end
  225. function RoomBase:isInMemberList()
  226. if self.roomInfo and self.roomInfo.memberList then
  227. for nUserId,v in pairs (self.roomInfo.memberList) do
  228. if app.user.loginInfo.uid==nUserId then
  229. return true
  230. end
  231. end
  232. end
  233. return false
  234. end
  235. function RoomBase:sendGameXiPai()
  236. self:sendResponse{cmd = RoomCmd.GAME_COMMAND_XIPAI};
  237. end
  238. -- 洗牌结果
  239. function RoomBase:onGameXiPai(status, response)
  240. print("RoomBase:onGameXiPai()", table.tostring(response))
  241. local result = response.byteValue
  242. if result == 3 then
  243. showTooltip("房卡不足")
  244. elseif result == 2 then
  245. showTooltip("已设置洗牌")
  246. elseif result == 1 then
  247. showTooltip("桌子状态未在小局结束")
  248. elseif result == 0 then
  249. app.user.loginInfo.curCardNum = app.user.loginInfo.curCardNum - 2
  250. end
  251. end
  252. -- 抽奖结果
  253. function RoomBase:onChouJiangBroad(status, response)
  254. logD("RoomBase:onChouJiangBroad()", table.tostring(response))
  255. dd.IGameOverAward.setAwardData(response)
  256. end
  257. return RoomBase;