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.

327 lines
12 KiB

  1. require("luaScript.Protocol.ProtocolCommon")
  2. local MatchCmd = require("luaScript.Protocol.Match.ProtocolMatchCmd")
  3. local MatchMessage = require("luaScript.Protocol.Match.ProtocolMatchMessage")
  4. local MatchDefined = require("luaScript.Views.Match.Constant.MatchDefined")
  5. local MatchEvents = require("luaScript.Views.Match.Constant.MatchEvents")
  6. local Match = class("Match" , require("luaScript.Protocol.Protocol"))
  7. function Match:ctor(net)
  8. Match.super.ctor(self , net);
  9. self.matchInfo={}
  10. self.matchInfo.matchList={}
  11. self.matchInfo.status=MatchDefined.MATCH_STATUS.DEFAULT
  12. self:initView()
  13. --发送
  14. -- 进入比赛
  15. self:defMsgFunc{name = MatchEvents.ENTER_MATCH , cmd = MatchCmd.CMD_MATCH_ENTER, sender = MatchMessage.MatchEnter};
  16. -- 加入房间
  17. -- self:defMsgFunc{name = "clubJoinRoomRequest" , cmd = MatchCmd.GAME_COMMAND_CLUB_JOINROOM_REQUEST, sender = ClubJoinRoomRequest};
  18. --接收
  19. -- 返回比赛列表信息
  20. self:defPushMsg{cmd = MatchCmd.CMD_GET_LIST_RESPONSE , reader = MatchMessage.MatchGetListResponse, func = handler(self , self.getListResponse)}
  21. -- 报名成功 0x5007
  22. self:defPushMsg{cmd = MatchCmd.CMD_SIGN_UP_ERROR_RESPONSE , reader = MatchMessage.MatchSignUpError, func = handler(self , self.signUpErrorResponse)}
  23. -- 报名失败 0x5006
  24. self:defPushMsg{cmd = MatchCmd.CMD_SIGN_UP_SUCCESS_RESPONSE, reader = MatchMessage.MatchSignUpSuccess, func = handler(self, self.signUpSuccessResponse)}
  25. -- 报名信息更新 0x5018
  26. self:defPushMsg{cmd = MatchCmd.CMD_SIGN_UP_INFO_RESPONSE, reader = MatchMessage.MatchSignUpInfo, func = handler(self, self.signUpInfoResponse)}
  27. -- 比赛开始
  28. self:defPushMsg{cmd = MatchCmd.CMD_MATCH_START_RESPONSE, reader = MatchMessage.MatchStart, func = handler(self, self.matchStartResponse)}
  29. -- 比赛结束
  30. self:defPushMsg{cmd = MatchCmd.CMD_MATCH_OVER_RESPONSE, func = handler(self, self.matchOverResponse)}
  31. -- 比赛异常结束
  32. self:defPushMsg{cmd = MatchCmd.CMD_MATCH_EXCEPTION_RESPONSE, reader = MatchMessage.MatchException, func = handler(self, self.matchExceptionResponse)}
  33. -- 一轮结束 0x500e
  34. self:defPushMsg{cmd = MatchCmd.CMD_ROUND_OVER_RESPONSE, reader = MatchMessage.MacthRoundOver, func = handler(self, self.roundOverResponse)}
  35. -- 下一轮开始 0x5100
  36. self:defPushMsg{cmd = MatchCmd.CMD_ROUND_START_RESPONSE, reader = MatchMessage.MatchRoundStart, func = handler(self, self.roundStartResponse)}
  37. -- 奖励信息
  38. self:defPushMsg{cmd = MatchCmd.CMD_AWARD_INFO_RESPONSE, reader = MatchMessage.MatchAwardInfo, func = handler(self, self.awardInfoResponse)}
  39. -- 进入比赛失败 0x501a
  40. self:defPushMsg{cmd = MatchCmd.CMD_MATCH_ENTER_ERROR, reader = MatchMessage.MatchEnterError, func = handler(self, self.enterMatchError)}
  41. -- 进入比赛信息 0x501b
  42. self:defPushMsg{cmd = MatchCmd.CMD_MATCH_ENTER_INFO, reader = MatchMessage.MatchInfo, func = handler(self, self.enterMatchInfo)}
  43. -- 比赛已经开始 0x5015
  44. self:defPushMsg{cmd = MatchCmd.CMD_MATCH_ALREADY_START, reader = MatchMessage.MatchAlreadyStart, func = handler(self, self.matchAlreadyStart)}
  45. -- 等待比赛开始 0x5017
  46. self:defPushMsg{cmd = MatchCmd.CMD_MATCH_WAIT, reader = MatchMessage.MatchWait, func = handler(self, self.matchWait)}
  47. -- 排行榜 0x500f
  48. self:defPushMsg{cmd = MatchCmd.CMD_MATCH_RANK_RESPONSE, reader = MatchMessage.MatchRank, func = handler(self, self.matchRankResponse)}
  49. -- 排行推送 0x501c
  50. self:defPushMsg{cmd = MatchCmd.CMD_MATCH_PUSH_RANK, reader = MatchMessage.MatchPushRank, func = handler(self, self.matchPushRank)}
  51. end
  52. function Match:initView()
  53. self.MatchRoomWaitView = "zp_hsb.luaScript.Views.Match.yxhsbMatchRoomWaitView"
  54. end
  55. -- 获取比赛场列表
  56. function Match:getListRequest(index)
  57. local request = MatchMessage.MatchGetList:new()
  58. request.uid = tonumber(app.user.loginInfo.uid)
  59. local appVersion = getAppVersionNum()
  60. local resVersion = loadVersion()
  61. request.version = appVersion.."."..resVersion
  62. request.areano = app.user.areano
  63. request.index = index or 0
  64. dump(request)
  65. self:sendResponse({cmd = MatchCmd.CMD_GET_LIST , sender = request})
  66. end
  67. -- 获取比赛场列表回调
  68. function Match:getListResponse(status,response)
  69. logD("Match:getListResponse(), ", table.tostring(response))
  70. self.matchInfo.isMatchListOver = response.isMatchListOver
  71. self.matchInfo.matchList = response.matchList
  72. self:dispatchEvent({name=MatchEvents.GET_LIST})
  73. end
  74. --报名
  75. function Match:signUp(data)
  76. local request = MatchMessage.MatchSignUp:new()
  77. request.gameId = data.gameId
  78. request.matchIndex = data.matchIndex
  79. request.matchType = data.matchType
  80. request.userInfo = app.user.userInfo
  81. dump(request)
  82. local matchInfo = self.matchInfo.matchList[data.matchIndex]
  83. local rewardInfo = json.decode(matchInfo.rewardInfo)
  84. self.matchInfo.rewards = rewardInfo.rewards
  85. self.matchInfo.matchName = matchInfo.matchName
  86. self.matchInfo.matchIndex = data.matchIndex
  87. self:sendResponse({cmd = MatchCmd.CMD_SIGN_UP , sender = request})
  88. end
  89. --取消报名
  90. function Match:signUpCancel()
  91. local request = MatchMessage.MatchSignUpCancel:new()
  92. request.uid = tonumber(app.user.loginInfo.uid)
  93. dump(request)
  94. self:sendResponse({cmd = MatchCmd.CMD_SIGN_UP_CANCEL , sender = request})
  95. self:dispatchEvent({name = MatchEvents.SIGN_UP_CANCEL})
  96. end
  97. --报名失败回调
  98. function Match:signUpErrorResponse(status,response)
  99. logD("Match:signUpErrorResponse(), ", table.tostring(response))
  100. -- 0, //服务器系统错误 1, //比赛信息错误
  101. -- 2, //报名费不足 3, //比赛已经开始且不属于重连
  102. -- 4, //玩家已經報名
  103. if response.result==4 then
  104. self:dispatchEvent({name = MatchEvents.SIGN_UP_SUCCESS})
  105. elseif response.result==2 then
  106. showTooltip("报名费不足!")
  107. end
  108. end
  109. --报名成功回调
  110. function Match:signUpSuccessResponse(status,response)
  111. logD("Match:signUpSuccessResponse(), ", table.tostring(response))
  112. self.matchInfo.curSignUpCnt=response.curSignUpCnt
  113. self.matchInfo.maxMatchCnt=response.maxMatchCnt
  114. self.matchInfo.status=MatchDefined.MATCH_STATUS.WAIT_START
  115. self.matchInfo.userScore=0
  116. self.matchInfo.promotionInfo=response.promotionInfo
  117. self:dispatchEvent({name = MatchEvents.SIGN_UP_SUCCESS})
  118. end
  119. --报名信息更新回调
  120. function Match:signUpInfoResponse(status,response)
  121. logD("Match:signUpInfoResponse(), ", table.tostring(response))
  122. self.matchInfo.curSignUpCnt=response.curSignUpCnt
  123. self.matchInfo.maxMatchCnt=response.maxMatchCnt
  124. self:dispatchEvent({name = MatchEvents.SIGN_UP_UPDATE})
  125. end
  126. --比赛开始
  127. function Match:matchStartResponse(status,response)
  128. logD("Match:matchStartResponse(), ", table.tostring(response))
  129. self.matchInfo.rank=response.rank
  130. self.matchInfo.curRound=1
  131. self.matchInfo.maxRound=response.maxRound
  132. self.matchInfo.promotionInfo=response.promotionInfo
  133. self.matchInfo.status=MatchDefined.MATCH_STATUS.GOING
  134. self:dispatchEvent({name = MatchEvents.MATCH_START})
  135. end
  136. --比赛结束
  137. function Match:matchOverResponse(status,response)
  138. logD("Match:matchOverResponse(), ", table.tostring(response))
  139. setShowCountAll(false)
  140. app.net:runNextMsg()
  141. end
  142. --比赛异常结束
  143. function Match:matchExceptionResponse(status,response)
  144. logD("Match:matchExceptionResponse(), ", table.tostring(response))
  145. end
  146. --下一轮开始
  147. function Match:roundStartResponse(status,response)
  148. logD("Match:roundStartResponse(), ", table.tostring(response))
  149. self.matchInfo.rank=response.rank
  150. self.matchInfo.nextRound=response.nextRound
  151. self.matchInfo.curRound=response.nextRound
  152. self.matchInfo.maxRound=response.maxRound
  153. app.net:onMsgPause()
  154. self:dispatchEvent({name = MatchEvents.ROUND_NEXT,response=response})
  155. end
  156. --一轮结束
  157. function Match:roundOverResponse(status,response)
  158. logD("Match:roundOverResponse(), ", table.tostring(response))
  159. self.matchInfo.rank=response.rank
  160. self.matchInfo.result=response.result
  161. -- Short notEndTableCnt; // 未结束的桌子数量
  162. self.matchInfo.notEndTableCnt=response.notEndTableCnt
  163. -- Short curRound; //当前轮数
  164. self.matchInfo.curRound=response.curRound
  165. -- Short maxRound; //总轮数
  166. self.matchInfo.maxRound=response.maxRound
  167. -- Short maxMatchCnt; //总开赛人数
  168. self.matchInfo.maxMatchCnt=response.maxMatchCnt
  169. self.matchInfo.promotionInfo=response.promotionInfo
  170. local rewardInfo = json.decode(response.rewardInfo)
  171. self.matchInfo.rewards = rewardInfo.rewards
  172. -- //1. 淘汰 2.晋级 3. 等待
  173. if response.result==1 then
  174. self.matchInfo.status=MatchDefined.MATCH_STATUS.OUT
  175. else
  176. self.matchInfo.status=MatchDefined.MATCH_STATUS.WAIT_UP
  177. end
  178. app.net:onMsgPause()
  179. if app:getCurrentView().__cname=="MatchRoomWaitView" then
  180. self:dispatchEvent({name = MatchEvents.ROUND_OVER})
  181. else
  182. local view = import(self.MatchRoomWaitView):new()
  183. app:gotoView(view)
  184. end
  185. end
  186. --奖励信息
  187. function Match:awardInfoResponse(status,response)
  188. logD("Match:awardInfoResponse(), ", table.tostring(response))
  189. self.matchInfo.rank=response.rank
  190. self.matchInfo.awardList=response.awardList
  191. self.matchInfo.status=MatchDefined.MATCH_STATUS.OVER
  192. self.matchInfo.userScore=response.userScore
  193. --没有奖励视为淘汰
  194. if response.hasReward==0 then
  195. self.matchInfo.status=MatchDefined.MATCH_STATUS.OUT
  196. end
  197. local ttExtInfo = string.split(response.userExtInfo, ",")
  198. app.user.loginInfo.historyCardNum = ttExtInfo[1];
  199. app.user.loginInfo.curCardNum = ttExtInfo[2];
  200. local view = import(self.MatchRoomWaitView):new()
  201. app:gotoView(view)
  202. app.net:onMsgResume()
  203. -- self:dispatchEvent({name = MatchEvents.MATCH_OVER,response=response})
  204. end
  205. function Match:enterMatchError(status,response)
  206. logD("Match:enterMatchError(), ", table.tostring(response))
  207. app.waitDialogManager:closeWaitNetworkDialog();
  208. gotoMainView();
  209. end
  210. function Match:enterMatchInfo(status,response)
  211. logD("Match:enterMatchInfo(), ", table.tostring(response))
  212. app.waitDialogManager:closeWaitNetworkDialog();
  213. self.matchInfo.gameId=response.gameId
  214. self.matchInfo.tableId=response.tableId
  215. self.matchInfo.gameInfo=response.gameInfo
  216. self.matchInfo.matchStatus=response.matchStatus
  217. self.matchInfo.matchIndex = response.matchIndex
  218. -- self.matchInfo.rank=response.rank
  219. -- self.matchInfo.tableList=response.tableList
  220. --1比赛开始
  221. if response.matchStatus==1 then
  222. app:changeGameProtocol(2,0,PROTOCOL_TYPE.MATCH)
  223. else
  224. -- local view = import("Views.Match.MatchRoomWaitView"):new()
  225. -- app:gotoView(view)
  226. end
  227. end
  228. function Match:matchAlreadyStart(status,response)
  229. logD("Match:matchAlreadyStart(), ", table.tostring(response))
  230. self.matchInfo.curRound=response.curRound
  231. self.matchInfo.curRoundJuShu=response.curRoundJuShu
  232. self.matchInfo.maxMatchCnt=response.maxMatchCnt
  233. self.matchInfo.maxRound=response.maxRound
  234. self.matchInfo.rank=response.rank
  235. self.matchInfo.tableList=response.tableList
  236. self.matchInfo.promotionInfo=response.promotionInfo
  237. self.matchInfo.matchName=response.matchName
  238. local rewardInfo = json.decode(response.rewardInfo)
  239. self.matchInfo.rewards = rewardInfo.rewards
  240. self.matchInfo.status=MatchDefined.MATCH_STATUS.GOING
  241. end
  242. function Match:matchWait(status,response)
  243. logD("Match:matchWait(), ", table.tostring(response))
  244. self.matchInfo.curSignUpCnt=response.curSignUpCnt
  245. self.matchInfo.maxMatchCnt=response.maxMatchCnt
  246. self.matchInfo.matchType=response.matchType
  247. self.matchInfo.matchName=response.matchName
  248. self.matchInfo.promotionInfo=response.promotionInfo
  249. local rewardInfo = json.decode(response.rewardInfo)
  250. self.matchInfo.rewards = rewardInfo.rewards
  251. self.matchInfo.status=MatchDefined.MATCH_STATUS.WAIT_START
  252. local view = import(self.MatchRoomWaitView):new()
  253. app:gotoView(view)
  254. end
  255. --请求排行榜
  256. function Match:matchRank()
  257. local request = MatchMessage.MatchSignUpCancel:new()
  258. request.uid = tonumber(app.user.loginInfo.uid)
  259. dump(request)
  260. self:sendResponse({cmd = MatchCmd.CMD_MATCH_RANK , sender = request})
  261. end
  262. --请求排行榜 回调
  263. function Match:matchRankResponse(status,response)
  264. logD("Match:matchRankResponse(), ", table.tostring(response))
  265. self.matchInfo.rank=response.rank
  266. self.matchInfo.rankList=response.rankList
  267. self:dispatchEvent({name = MatchEvents.MATCH_RANK})
  268. end
  269. function Match:matchPushRank(status,response)
  270. logD("Match:matchPushRank(), ", table.tostring(response))
  271. if app.user.loginInfo.uid==response.uid then
  272. self.matchInfo.rank=response.rank
  273. self.matchInfo.maxMatchCnt=response.maxMatchCnt
  274. end
  275. self:dispatchEvent({name = MatchEvents.MATCH_PUSH_RANK})
  276. end
  277. return Match;