|
- require("luaScript.Protocol.ProtocolCommon")
-
- local MatchCmd = require("luaScript.Protocol.Match.ProtocolMatchCmd")
- local MatchMessage = require("luaScript.Protocol.Match.ProtocolMatchMessage")
-
- local MatchDefined = require("luaScript.Views.Match.Constant.MatchDefined")
- local MatchEvents = require("luaScript.Views.Match.Constant.MatchEvents")
- local Match = class("Match" , require("luaScript.Protocol.Protocol"))
-
-
- function Match:ctor(net)
- Match.super.ctor(self , net);
-
- self.matchInfo={}
- self.matchInfo.matchList={}
- self.matchInfo.status=MatchDefined.MATCH_STATUS.DEFAULT
- self:initView()
-
- --发送
- -- 进入比赛
- self:defMsgFunc{name = MatchEvents.ENTER_MATCH , cmd = MatchCmd.CMD_MATCH_ENTER, sender = MatchMessage.MatchEnter};
- -- 加入房间
- -- self:defMsgFunc{name = "clubJoinRoomRequest" , cmd = MatchCmd.GAME_COMMAND_CLUB_JOINROOM_REQUEST, sender = ClubJoinRoomRequest};
-
- --接收
- -- 返回比赛列表信息
- self:defPushMsg{cmd = MatchCmd.CMD_GET_LIST_RESPONSE , reader = MatchMessage.MatchGetListResponse, func = handler(self , self.getListResponse)}
- -- 报名成功 0x5007
- self:defPushMsg{cmd = MatchCmd.CMD_SIGN_UP_ERROR_RESPONSE , reader = MatchMessage.MatchSignUpError, func = handler(self , self.signUpErrorResponse)}
- -- 报名失败 0x5006
- self:defPushMsg{cmd = MatchCmd.CMD_SIGN_UP_SUCCESS_RESPONSE, reader = MatchMessage.MatchSignUpSuccess, func = handler(self, self.signUpSuccessResponse)}
- -- 报名信息更新 0x5018
- self:defPushMsg{cmd = MatchCmd.CMD_SIGN_UP_INFO_RESPONSE, reader = MatchMessage.MatchSignUpInfo, func = handler(self, self.signUpInfoResponse)}
- -- 比赛开始
- self:defPushMsg{cmd = MatchCmd.CMD_MATCH_START_RESPONSE, reader = MatchMessage.MatchStart, func = handler(self, self.matchStartResponse)}
- -- 比赛结束
- self:defPushMsg{cmd = MatchCmd.CMD_MATCH_OVER_RESPONSE, func = handler(self, self.matchOverResponse)}
- -- 比赛异常结束
- self:defPushMsg{cmd = MatchCmd.CMD_MATCH_EXCEPTION_RESPONSE, reader = MatchMessage.MatchException, func = handler(self, self.matchExceptionResponse)}
- -- 一轮结束 0x500e
- self:defPushMsg{cmd = MatchCmd.CMD_ROUND_OVER_RESPONSE, reader = MatchMessage.MacthRoundOver, func = handler(self, self.roundOverResponse)}
- -- 下一轮开始 0x5100
- self:defPushMsg{cmd = MatchCmd.CMD_ROUND_START_RESPONSE, reader = MatchMessage.MatchRoundStart, func = handler(self, self.roundStartResponse)}
- -- 奖励信息
- self:defPushMsg{cmd = MatchCmd.CMD_AWARD_INFO_RESPONSE, reader = MatchMessage.MatchAwardInfo, func = handler(self, self.awardInfoResponse)}
- -- 进入比赛失败 0x501a
- self:defPushMsg{cmd = MatchCmd.CMD_MATCH_ENTER_ERROR, reader = MatchMessage.MatchEnterError, func = handler(self, self.enterMatchError)}
- -- 进入比赛信息 0x501b
- self:defPushMsg{cmd = MatchCmd.CMD_MATCH_ENTER_INFO, reader = MatchMessage.MatchInfo, func = handler(self, self.enterMatchInfo)}
- -- 比赛已经开始 0x5015
- self:defPushMsg{cmd = MatchCmd.CMD_MATCH_ALREADY_START, reader = MatchMessage.MatchAlreadyStart, func = handler(self, self.matchAlreadyStart)}
- -- 等待比赛开始 0x5017
- self:defPushMsg{cmd = MatchCmd.CMD_MATCH_WAIT, reader = MatchMessage.MatchWait, func = handler(self, self.matchWait)}
- -- 排行榜 0x500f
- self:defPushMsg{cmd = MatchCmd.CMD_MATCH_RANK_RESPONSE, reader = MatchMessage.MatchRank, func = handler(self, self.matchRankResponse)}
- -- 排行推送 0x501c
- self:defPushMsg{cmd = MatchCmd.CMD_MATCH_PUSH_RANK, reader = MatchMessage.MatchPushRank, func = handler(self, self.matchPushRank)}
- end
-
- function Match:initView()
- self.MatchRoomWaitView = "zp_hsb.luaScript.Views.Match.yxhsbMatchRoomWaitView"
- end
-
- -- 获取比赛场列表
- function Match:getListRequest(index)
- local request = MatchMessage.MatchGetList:new()
- request.uid = tonumber(app.user.loginInfo.uid)
-
- local appVersion = getAppVersionNum()
- local resVersion = loadVersion()
- request.version = appVersion.."."..resVersion
- request.areano = app.user.areano
- request.index = index or 0
- dump(request)
- self:sendResponse({cmd = MatchCmd.CMD_GET_LIST , sender = request})
- end
-
- -- 获取比赛场列表回调
- function Match:getListResponse(status,response)
- logD("Match:getListResponse(), ", table.tostring(response))
- self.matchInfo.isMatchListOver = response.isMatchListOver
- self.matchInfo.matchList = response.matchList
- self:dispatchEvent({name=MatchEvents.GET_LIST})
- end
-
- --报名
- function Match:signUp(data)
- local request = MatchMessage.MatchSignUp:new()
- request.gameId = data.gameId
- request.matchIndex = data.matchIndex
- request.matchType = data.matchType
- request.userInfo = app.user.userInfo
- dump(request)
-
- local matchInfo = self.matchInfo.matchList[data.matchIndex]
- local rewardInfo = json.decode(matchInfo.rewardInfo)
- self.matchInfo.rewards = rewardInfo.rewards
- self.matchInfo.matchName = matchInfo.matchName
- self.matchInfo.matchIndex = data.matchIndex
-
- self:sendResponse({cmd = MatchCmd.CMD_SIGN_UP , sender = request})
- end
-
- --取消报名
- function Match:signUpCancel()
- local request = MatchMessage.MatchSignUpCancel:new()
- request.uid = tonumber(app.user.loginInfo.uid)
- dump(request)
- self:sendResponse({cmd = MatchCmd.CMD_SIGN_UP_CANCEL , sender = request})
-
- self:dispatchEvent({name = MatchEvents.SIGN_UP_CANCEL})
- end
-
- --报名失败回调
- function Match:signUpErrorResponse(status,response)
- logD("Match:signUpErrorResponse(), ", table.tostring(response))
- -- 0, //服务器系统错误 1, //比赛信息错误
- -- 2, //报名费不足 3, //比赛已经开始且不属于重连
- -- 4, //玩家已經報名
- if response.result==4 then
- self:dispatchEvent({name = MatchEvents.SIGN_UP_SUCCESS})
- elseif response.result==2 then
- showTooltip("报名费不足!")
- end
- end
-
- --报名成功回调
- function Match:signUpSuccessResponse(status,response)
- logD("Match:signUpSuccessResponse(), ", table.tostring(response))
- self.matchInfo.curSignUpCnt=response.curSignUpCnt
- self.matchInfo.maxMatchCnt=response.maxMatchCnt
- self.matchInfo.status=MatchDefined.MATCH_STATUS.WAIT_START
- self.matchInfo.userScore=0
- self.matchInfo.promotionInfo=response.promotionInfo
- self:dispatchEvent({name = MatchEvents.SIGN_UP_SUCCESS})
- end
-
- --报名信息更新回调
- function Match:signUpInfoResponse(status,response)
- logD("Match:signUpInfoResponse(), ", table.tostring(response))
- self.matchInfo.curSignUpCnt=response.curSignUpCnt
- self.matchInfo.maxMatchCnt=response.maxMatchCnt
- self:dispatchEvent({name = MatchEvents.SIGN_UP_UPDATE})
- end
-
- --比赛开始
- function Match:matchStartResponse(status,response)
- logD("Match:matchStartResponse(), ", table.tostring(response))
- self.matchInfo.rank=response.rank
- self.matchInfo.curRound=1
- self.matchInfo.maxRound=response.maxRound
- self.matchInfo.promotionInfo=response.promotionInfo
- self.matchInfo.status=MatchDefined.MATCH_STATUS.GOING
- self:dispatchEvent({name = MatchEvents.MATCH_START})
- end
-
- --比赛结束
- function Match:matchOverResponse(status,response)
- logD("Match:matchOverResponse(), ", table.tostring(response))
- setShowCountAll(false)
- app.net:runNextMsg()
- end
-
- --比赛异常结束
- function Match:matchExceptionResponse(status,response)
- logD("Match:matchExceptionResponse(), ", table.tostring(response))
-
- end
-
- --下一轮开始
- function Match:roundStartResponse(status,response)
- logD("Match:roundStartResponse(), ", table.tostring(response))
- self.matchInfo.rank=response.rank
- self.matchInfo.nextRound=response.nextRound
- self.matchInfo.curRound=response.nextRound
- self.matchInfo.maxRound=response.maxRound
-
- app.net:onMsgPause()
- self:dispatchEvent({name = MatchEvents.ROUND_NEXT,response=response})
- end
-
- --一轮结束
- function Match:roundOverResponse(status,response)
- logD("Match:roundOverResponse(), ", table.tostring(response))
-
- self.matchInfo.rank=response.rank
- self.matchInfo.result=response.result
- -- Short notEndTableCnt; // 未结束的桌子数量
- self.matchInfo.notEndTableCnt=response.notEndTableCnt
- -- Short curRound; //当前轮数
- self.matchInfo.curRound=response.curRound
- -- Short maxRound; //总轮数
- self.matchInfo.maxRound=response.maxRound
- -- Short maxMatchCnt; //总开赛人数
- self.matchInfo.maxMatchCnt=response.maxMatchCnt
-
- self.matchInfo.promotionInfo=response.promotionInfo
-
- local rewardInfo = json.decode(response.rewardInfo)
- self.matchInfo.rewards = rewardInfo.rewards
-
- -- //1. 淘汰 2.晋级 3. 等待
- if response.result==1 then
- self.matchInfo.status=MatchDefined.MATCH_STATUS.OUT
- else
- self.matchInfo.status=MatchDefined.MATCH_STATUS.WAIT_UP
- end
-
- app.net:onMsgPause()
- if app:getCurrentView().__cname=="MatchRoomWaitView" then
- self:dispatchEvent({name = MatchEvents.ROUND_OVER})
- else
- local view = import(self.MatchRoomWaitView):new()
- app:gotoView(view)
- end
- end
-
- --奖励信息
- function Match:awardInfoResponse(status,response)
- logD("Match:awardInfoResponse(), ", table.tostring(response))
- self.matchInfo.rank=response.rank
- self.matchInfo.awardList=response.awardList
- self.matchInfo.status=MatchDefined.MATCH_STATUS.OVER
- self.matchInfo.userScore=response.userScore
-
- --没有奖励视为淘汰
- if response.hasReward==0 then
- self.matchInfo.status=MatchDefined.MATCH_STATUS.OUT
- end
-
- local ttExtInfo = string.split(response.userExtInfo, ",")
- app.user.loginInfo.historyCardNum = ttExtInfo[1];
- app.user.loginInfo.curCardNum = ttExtInfo[2];
-
- local view = import(self.MatchRoomWaitView):new()
- app:gotoView(view)
-
- app.net:onMsgResume()
- -- self:dispatchEvent({name = MatchEvents.MATCH_OVER,response=response})
- end
-
- function Match:enterMatchError(status,response)
- logD("Match:enterMatchError(), ", table.tostring(response))
- app.waitDialogManager:closeWaitNetworkDialog();
- gotoMainView();
- end
-
- function Match:enterMatchInfo(status,response)
- logD("Match:enterMatchInfo(), ", table.tostring(response))
- app.waitDialogManager:closeWaitNetworkDialog();
-
- self.matchInfo.gameId=response.gameId
- self.matchInfo.tableId=response.tableId
- self.matchInfo.gameInfo=response.gameInfo
- self.matchInfo.matchStatus=response.matchStatus
- self.matchInfo.matchIndex = response.matchIndex
- -- self.matchInfo.rank=response.rank
- -- self.matchInfo.tableList=response.tableList
-
- --1比赛开始
- if response.matchStatus==1 then
- app:changeGameProtocol(2,0,PROTOCOL_TYPE.MATCH)
- else
- -- local view = import("Views.Match.MatchRoomWaitView"):new()
- -- app:gotoView(view)
- end
- end
-
- function Match:matchAlreadyStart(status,response)
- logD("Match:matchAlreadyStart(), ", table.tostring(response))
- self.matchInfo.curRound=response.curRound
- self.matchInfo.curRoundJuShu=response.curRoundJuShu
- self.matchInfo.maxMatchCnt=response.maxMatchCnt
- self.matchInfo.maxRound=response.maxRound
- self.matchInfo.rank=response.rank
- self.matchInfo.tableList=response.tableList
- self.matchInfo.promotionInfo=response.promotionInfo
- self.matchInfo.matchName=response.matchName
-
- local rewardInfo = json.decode(response.rewardInfo)
- self.matchInfo.rewards = rewardInfo.rewards
-
- self.matchInfo.status=MatchDefined.MATCH_STATUS.GOING
- end
-
- function Match:matchWait(status,response)
- logD("Match:matchWait(), ", table.tostring(response))
- self.matchInfo.curSignUpCnt=response.curSignUpCnt
- self.matchInfo.maxMatchCnt=response.maxMatchCnt
- self.matchInfo.matchType=response.matchType
- self.matchInfo.matchName=response.matchName
- self.matchInfo.promotionInfo=response.promotionInfo
- local rewardInfo = json.decode(response.rewardInfo)
- self.matchInfo.rewards = rewardInfo.rewards
- self.matchInfo.status=MatchDefined.MATCH_STATUS.WAIT_START
-
- local view = import(self.MatchRoomWaitView):new()
- app:gotoView(view)
- end
-
- --请求排行榜
- function Match:matchRank()
- local request = MatchMessage.MatchSignUpCancel:new()
- request.uid = tonumber(app.user.loginInfo.uid)
- dump(request)
- self:sendResponse({cmd = MatchCmd.CMD_MATCH_RANK , sender = request})
- end
-
- --请求排行榜 回调
- function Match:matchRankResponse(status,response)
- logD("Match:matchRankResponse(), ", table.tostring(response))
- self.matchInfo.rank=response.rank
- self.matchInfo.rankList=response.rankList
- self:dispatchEvent({name = MatchEvents.MATCH_RANK})
- end
-
- function Match:matchPushRank(status,response)
- logD("Match:matchPushRank(), ", table.tostring(response))
- if app.user.loginInfo.uid==response.uid then
- self.matchInfo.rank=response.rank
- self.matchInfo.maxMatchCnt=response.maxMatchCnt
- end
- self:dispatchEvent({name = MatchEvents.MATCH_PUSH_RANK})
- end
-
- return Match;
|