|
- require("luaScript.Protocol.ProtocolCommon")
-
- local defs = require("pk_erdoudizhu.luaScript.Def_ERDouDiZhu")
- local Functions = require("pk_erdoudizhu.luaScript.Functions_ERDouDiZhu")
- local Cmds = require("pk_erdoudizhu.luaScript.Protocol.ProtocolCmd_ERDouDiZhu")
- local Messages = require("pk_erdoudizhu.luaScript.Protocol.ProtocolMessage_ERDouDiZhu")
-
-
- local Room = class("Room" , require("luaScript.Protocol.ProtocolRoomBase"))
-
- --队列初始化
- local callbackQueue = {}
- local callbackRunning = true
-
- function Room:ctor(net)
- Room.super.ctor(self , net)
-
- -- GPS信息发生变化的时候主动给服务器发消息
- app:addEventListener("onUpdateLoctionSuccessed", handler(self, self.onGpsChangeRequest))
-
- --发送
- -- 请求准备
- self:defMsgFunc{name = "callReadyRequest" , cmd = Cmds.GAME_COMMAND_USER_READY}
- -- 玩家请求解散房间,获取其他玩家回复解散房间
- self:defMsgFunc{name = "dismissRoomRequest", cmd = Cmds.GAME_COMMAND_DISBAND_GAME, sender = Messages.DismissRequest}
- -- 离开房间
- self:defMsgFunc{name = "callLeaveRequest" , cmd = Cmds.GAME_COMMAND_USER_LEAVE}
- -- 请求托管(取消or发送)
- self:defMsgFunc{name = 'HostingRequest', cmd = Cmds.GAME_COMMAND_USER_HOSTING_REQUEST_0x8134, sender = Messages.HostingRequest}
-
-
- --接收
- -- 玩家进入桌子成功
- self:defPushMsg{cmd = Cmds.GAME_COMMAND_LOGIN_GAME_SUCCESS, reader = Messages.SitDownSuccessResponse, func = handler(self , self.onSitDownSuccessResponse)}
- -- 玩家进入桌子失败
- self:defPushMsg{cmd = Cmds.GAME_COMMAND_LOGIN_GAME_ERR, reader = Messages.SitDownFailedResponse, func = handler(self , self.onSitDownFailedResponse)}
- -- 断线重连
- self:defPushMsg{cmd = Cmds.GAME_COMMAND_GAME_RECONNECTION, reader = Messages.GameReconnection, func = handler(self, self.onGameReconnection)}
- -- 用户退出
- self:defPushMsg{cmd = Cmds.GAME_COMMAND_LOGOUT_GAME_SUCCESS, reader = Messages.UserExitResponse, func = handler(self , self.onUserExitResponse)}
- -- 其他玩家进入桌子
- self:defPushMsg{cmd = Cmds.GAME_COMMAND_BROADCAST_USER_LOGIN, reader = Messages.OtherSitDownResponse, func = handler(self , self.onOtherSitDownResponse)}
- -- 其他玩家掉线
- self:defPushMsg{cmd = Cmds.GAME_COMMAND_BROADCAST_USER_DROPPED, reader = Messages.OtherDroppedResponse, func = handler(self , self.onOtherDroppedResponse)}
- -- 其他玩家退出房间
- self:defPushMsg{cmd = Cmds.GAME_COMMAND_BROADCAST_USER_LOGOUT, reader = Messages.OtherLogoutResponse, func = handler(self , self.onOtherLogoutResponse)}
- -- 收到服务器下发的玩家准备状态
- self:defPushMsg{cmd = Cmds.GAME_COMMAND_BROADCAST_USER_READY, reader = Messages.IntPacket, func = handler(self , self.onUserReadyResponse)}
-
-
-
- -- 游戏开始
- self:defPushMsg{cmd = Cmds.cmd_0x8104, reader = Messages.cmd_0x8104_RespStructure, func = handler(self , self.cmd_0x8104_Resp)}
- -- 更新游戏状态
- self:defPushMsg{cmd = Cmds.cmd_0x8105, reader = Messages.cmd_0x8105_RespStructure, func = handler(self , self.cmd_0x8105_Resp)}
- -- 发牌
- self:defPushMsg{cmd = Cmds.cmd_0x8106, reader = Messages.cmd_0x8106_RespStructure, func = handler(self , self.cmd_0x8106_Resp)}
- -- 通知玩家叫分
- self:defPushMsg{cmd = Cmds.cmd_0x8108, reader = Messages.cmd_0x8108_RespStructure, func = handler(self , self.cmd_0x8108_Resp)}
- -- 广播叫分结果
- self:defPushMsg{cmd = Cmds.cmd_0x8109, reader = Messages.cmd_0x8109_RespStructure, func = handler(self , self.cmd_0x8109_Resp)}
- -- 叫分结果,将底牌发给地主
- self:defPushMsg{cmd = Cmds.cmd_0x810a, reader = Messages.cmd_0x810a_RespStructure, func = handler(self , self.cmd_0x810a_Resp)}
- -- 通知加倍
- self:defPushMsg{cmd = Cmds.cmd_0x810c, reader = Messages.cmd_0x810c_RespStructure, func = handler(self , self.cmd_0x810c_Resp)}
- -- 广播玩家加倍结果
- self:defPushMsg{cmd = Cmds.cmd_0x810d, reader = Messages.cmd_0x810d_RespStructure, func = handler(self , self.cmd_0x810d_Resp)}
- -- 玩家出牌轮次广播
- self:defPushMsg{cmd = Cmds.cmd_0x810e, reader = Messages.cmd_0x810e_RespStructure, func = handler(self , self.cmd_0x810e_Resp)}
- -- 玩家出牌错误
- self:defPushMsg{cmd = Cmds.cmd_0x810f, reader = Messages.cmd_0x810f_RespStructure, func = handler(self , self.cmd_0x810f_Resp)}
- -- 玩家出牌成功
- self:defPushMsg{cmd = Cmds.cmd_0x8110, reader = Messages.cmd_0x8110_RespStructure, func = handler(self , self.cmd_0x8110_Resp)}
- -- 倍率发生变化
- self:defPushMsg{cmd = Cmds.cmd_0x8111, reader = Messages.cmd_0x8111_RespStructure, func = handler(self , self.cmd_0x8111_Resp)}
- -- 小局结算
- self:defPushMsg{cmd = Cmds.cmd_0x8112, reader = Messages.cmd_0x8112_RespStructure, func = handler(self , self.cmd_0x8112_Resp)}
- -- 总结算
- self:defPushMsg{cmd = Cmds.cmd_0x8113, reader = Messages.cmd_0x8113_RespStructure, func = handler(self , self.cmd_0x8113_Resp)}
- -- 无人叫分重新洗牌
- self:defPushMsg{cmd = Cmds.cmd_0x8114, reader = Messages.cmd_0x8114_RespStructure, func = handler(self , self.cmd_0x8114_Resp)}
-
- -- 玩家收到解散房间的请求
- self:defPushMsg{cmd = Cmds.GAME_COMMAND_BROADCAST_DISBAND_GAME, reader = Messages.DismissResponse, func = handler(self , self.onDismissResponse)}
- -- 收到玩家申请解散房间
- self:defPushMsg{cmd = Cmds.GAME_COMMAND_DISBAND_GAME, reader = Messages.DismissResult, func = handler(self , self.onUserDismissResultResponse)}
- -- 收到玩家申请立即开局
- self:defPushMsg{cmd = Cmds.GAME_COMMAND_RESPONSE_EARLY_START, reader = Messages.EarlyStartResult, func = handler(self , self.onQuickStartResponse)}
- -- 收到托管回调
- self:defPushMsg{cmd = Cmds.GAME_COMMAND_USER_HOSTING_RESPONSE_0x8133, reader = Messages.HostingResponse, func = handler(self,self.onHostingResponse)}
-
- -- 通知抢地主
- self:defPushMsg{cmd = Cmds.cmd_0x8123, reader = Messages.cmd_0x8123_RespStructure, func = handler(self , self.cmd_0x8123_Resp)}
- -- 抢地主结果
- self:defPushMsg{cmd = Cmds.cmd_0x8124, reader = Messages.cmd_0x8124_RespStructure, func = handler(self , self.cmd_0x8124_Resp)}
- -- 通知让牌
- self:defPushMsg{cmd = Cmds.cmd_0x8121, reader = Messages.cmd_0x8121_RespStructure, func = handler(self , self.cmd_0x8121_Resp)}
- -- 让牌结果
- self:defPushMsg{cmd = Cmds.cmd_0x8122, reader = Messages.cmd_0x8122_RespStructure, func = handler(self , self.cmd_0x8122_Resp)}
- end
-
- -- 无人叫分重新洗牌
- function Room:cmd_0x8114_Resp(status, response)
- if not self.roomInfo then
- logD("self.roomInfo no exist,容错处理!")
- return
- end
-
- logD("Room:cmd_0x8114_Resp(), ", table.tostring(response))
-
- -- 发送广播通知
- self:dispatchEvent({name = "cmd_0x8114_Resp", response = response})
- end
-
- -- 总结算
- function Room:cmd_0x8113_Resp(status, response)
- if not self.roomInfo then
- logD("self.roomInfo no exist,容错处理!")
- return
- end
-
- logD("Room:cmd_0x8113_Resp(), ", table.tostring(response))
-
- self.roomInfo.isGameOver = 1
- self.roomInfo._GameOverInfo = response
- self.roomInfo._stopFlag = response.stopFlag
-
- -- 发送广播通知
- self:dispatchEvent({name = "cmd_0x8113_Resp", response = response})
- end
-
- -- 小局结算
- function Room:cmd_0x8112_Resp(status, response)
- if not self.roomInfo then
- logD("self.roomInfo no exist,容错处理!")
- return
- end
-
- logD("Room:cmd_0x8112_Resp(), ", table.tostring(response))
-
- self.roomInfo.isGameOver = response.isGameOver
-
- for _,v in pairs(response.memberList) do
- self.roomInfo.memberList[v.nUserId].nTotalScore = v.nTotalScore
- end
-
- for _, v in pairs(response.memberOperateData or {}) do
- response.memberList[v.nUserId].ext = v.ext -- 强制把操作数据添加到memeberlist里面,因为小结算直接用的发来的repsonse数据而不是self.roomInfo.memberList
- end
-
- -- 发送广播通知
- self:dispatchEvent({name = "cmd_0x8112_Resp", response = response})
- end
-
- -- 倍率发生变化
- function Room:cmd_0x8111_Resp(status, response)
- if not self.roomInfo then
- logD("self.roomInfo no exist,容错处理!")
- return
- end
-
- logD("Room:cmd_0x8111_Resp(), ", table.tostring(response))
-
- self.roomInfo.nBombs = response.nBombs
- self.roomInfo.curAskLoard = response.baseScore
- self.roomInfo.nMult = response.nMult
- self.roomInfo.nRang = response.nRang
- self.roomInfo.diType = response.diType
-
- -- 发送广播通知
- self:dispatchEvent({name = "cmd_0x8111_Resp", response = response})
- end
-
- -- 玩家出牌成功
- function Room:cmd_0x8110_Resp(status, response)
- if not self.roomInfo then
- logD("self.roomInfo no exist,容错处理!")
- return
- end
-
- logD("Room:cmd_0x8110_Resp(), ", table.tostring(response))
-
- -- 发送广播通知
- self:dispatchEvent({name = "cmd_0x8110_Resp", response = response})
- end
-
- -- 玩家出牌错误
- function Room:cmd_0x810f_Resp(status, response)
- if not self.roomInfo then
- logD("self.roomInfo no exist,容错处理!")
- return
- end
-
- logD("Room:cmd_0x810f_Resp(), ", table.tostring(response))
-
- -- 发送广播通知
- self:dispatchEvent({name = "cmd_0x810f_Resp", response = response})
- end
-
- -- 玩家出牌轮次广播
- function Room:cmd_0x810e_Resp(status, response)
- if not self.roomInfo then
- logD("self.roomInfo no exist,容错处理!")
- return
- end
-
- logD("Room:cmd_0x810e_Resp(), ", table.tostring(response))
-
- -- 发送广播通知
- self:dispatchEvent({name = "cmd_0x810e_Resp", response = response})
- end
-
- -- 广播玩家加倍结果
- function Room:cmd_0x810d_Resp(status, response)
- if not self.roomInfo then
- logD("self.roomInfo no exist,容错处理!")
- return
- end
-
- logD("Room:cmd_0x810d_Resp(), ", table.tostring(response))
-
- self.roomInfo.memberList[response.nUserId].askBei = response.askBei
-
- -- 发送广播通知
- self:dispatchEvent({name = "cmd_0x810d_Resp", response = response})
- end
-
- -- 通知加倍
- function Room:cmd_0x810c_Resp(status, response)
- if not self.roomInfo then
- logD("self.roomInfo no exist,容错处理!")
- return
- end
-
- logD("Room:cmd_0x810c_Resp(), ", table.tostring(response))
-
- -- 发送广播通知
- self:dispatchEvent({name = "cmd_0x810c_Resp", response = response})
- end
-
- -- 叫分结果,将底牌发给地主
- function Room:cmd_0x810a_Resp(status, response)
- if not self.roomInfo then
- logD("self.roomInfo no exist,容错处理!")
- return
- end
-
- logD("Room:cmd_0x810a_Resp(), ", table.tostring(response))
-
- -- 这里有设置了庄家id
- for k,v in pairs(response.Datas) do
- self.roomInfo[k] = v
- end
-
- -- 发送广播通知
- self:dispatchEvent({name = "cmd_0x810a_Resp", response = response})
- end
-
- -- 通知玩家叫分
- function Room:cmd_0x8108_Resp(status, response)
- if not self.roomInfo then
- logD("self.roomInfo no exist,容错处理!")
- return
- end
-
- logD("Room:cmd_0x8108_Resp(), ", table.tostring(response))
-
- self.roomInfo.memberList[response.nUserId].askLoard = response.askLoard
-
- -- 发送广播通知
- self:dispatchEvent({name = "cmd_0x8108_Resp", response = response})
- end
-
- -- 发牌
- function Room:cmd_0x8106_Resp(status, response)
- if not self.roomInfo then
- logD("self.roomInfo no exist,容错处理!")
- return
- end
-
- logD("Room:cmd_0x8106_Resp(), ", table.tostring(response))
-
- self.roomInfo.memberList[response.nUserId].handCards = response.handCards
-
- -- 发送广播通知
- self:dispatchEvent({name = "cmd_0x8106_Resp", response = response})
- end
-
- -- 更新游戏状态
- function Room:cmd_0x8105_Resp(status, response)
- if not self.roomInfo then
- logD("self.roomInfo no exist,容错处理!")
- return
- end
-
- logD("Room:cmd_0x8105_Resp(), ", table.tostring(response))
-
- self.roomInfo.nStatus = response.nStatus
-
- -- 发送广播通知
- self:dispatchEvent({name = "cmd_0x8105_Resp", response = response})
- end
-
- -- 游戏开始
- function Room:cmd_0x8104_Resp(status, response)
- if not self.roomInfo then
- logD("self.roomInfo no exist,容错处理!")
- return
- end
-
- logD("Room:cmd_0x8104_Resp(), ", table.tostring(response))
-
- for k,v in pairs(response.Datas) do
- self.roomInfo[k] = v
- end
-
- --重置准备状态
- for _,v in pairs(self.roomInfo.memberList) do
- v.nPlayerFlag = 0
- end
- --重置叫分
- self.roomInfo.curAskLoard = 0
- -- 重置倍数
- self.roomInfo.nMult = 1
- -- 重置让牌
- self.roomInfo.nRang = 0
- -- 重置底牌类型
- self.roomInfo.diType = 0
-
- -- 发送广播通知
- self:dispatchEvent({name = "cmd_0x8104_Resp", response = response})
- end
-
- -- 广播叫分结果
- function Room:cmd_0x8109_Resp(status, response)
- if not self.roomInfo then
- logD("self.roomInfo no exist,容错处理!")
- return
- end
-
- logD("Room:cmd_0x8109_Resp(), ", table.tostring(response))
-
- if response.askLoard ~= 0 then
- self.roomInfo.curAskLoard = response.askLoard
- end
-
- -- 发送广播通知
- self:dispatchEvent({name = "cmd_0x8109_Resp", response = response})
- end
-
- -- 通知抢地主
- function Room:cmd_0x8123_Resp(status, response)
- if not self.roomInfo then
- logD("self.roomInfo no exist,容错处理!")
- return
- end
-
- logD("Room:cmd_0x8123_Resp(), ", table.tostring(response))
-
- -- 发送广播通知
- self:dispatchEvent({name = "cmd_0x8123_Resp", response = response})
- end
-
- -- 抢地主结果
- function Room:cmd_0x8124_Resp(status, response)
- if not self.roomInfo then
- logD("self.roomInfo no exist,容错处理!")
- return
- end
-
- logD("Room:cmd_0x8124_Resp(), ", table.tostring(response))
-
- self.roomInfo.memberList[response.nUserId].qiang = response.opType
-
- -- 发送广播通知
- self:dispatchEvent({name = "cmd_0x8124_Resp", response = response})
- end
-
- -- 通知让牌
- function Room:cmd_0x8121_Resp(status, response)
- if not self.roomInfo then
- logD("self.roomInfo no exist,容错处理!")
- return
- end
-
- logD("Room:cmd_0x8121_Resp(), ", table.tostring(response))
-
- -- 发送广播通知
- self:dispatchEvent({name = "cmd_0x8121_Resp", response = response})
- end
-
- -- 让牌结果
- function Room:cmd_0x8122_Resp(status, response)
- if not self.roomInfo then
- logD("self.roomInfo no exist,容错处理!")
- return
- end
-
- logD("Room:cmd_0x8122_Resp(), ", table.tostring(response))
-
- self.roomInfo.memberList[response.nUserId].askRangNum = tonumber(response.opType) -- 选择的让牌数
- self.roomInfo.nRangTotalNums = tonumber(response.nRangNums) -- 总让牌数
-
- -- 发送广播通知
- self:dispatchEvent({name = "cmd_0x8122_Resp", response = response})
- end
-
- --8012
- function Room:onDismissResponse(status, response)
- --[[-- nUserId
- , defVar("nUserId", VT_Int, 0)
- -- 1: 表示发起解散 2:同意解散 3:不同意解散
- , defVar("operateType", VT_UChar, 0)
- -- 剩余解散超时时间
- , defVar("timeLeft", VT_Short, 0) --]]
- if not self.roomInfo then
- logD("self.roomInfo no exist,容错处理!")
- return
- end
-
- local nUserId = response.nUserId
- local operateType = response.operateType
-
- -- 收到玩家发起请求时,数据重置
- if response.operateType == 1 then
- self:resetDismissData()
- end
-
- --数据记录
- self.dismissInfo[nUserId] = operateType
- self:dispatchEvent({name = "onDismissResponse", response = response})
- end
-
- -- 发起请求回复 8011
- function Room:onUserDismissResultResponse(status, response)
- logD("User:onUserDismissResultResponse, ", table.tostring(response))
- if not self.roomInfo then
- logD("self.roomInfo no exist,容错处理!")
- return
- end
- --[[
- -- 0:成功
- -- 1:operateType取值范围不对
- -- 2:当前没人发起解散
- -- 3:已经有人申请解散
- , defVar("errorCode", VT_Short, 0)
- -- 玩家操作
- , defVar("operateType", VT_Int, 0)
-
- -- 桌子上其他用户数量
- , defVar("memberList", VT_VectorToMap(UserDismissResult, "nUserId"))
- -- 剩余解散超时时间
- , defVar("timeLeft", VT_Short, 0) --]]
-
- logD("30000000--runUserDismissResultResponse")
- if response.errorCode == 1 then
- showTooltip("operateType取值范围不对")
- elseif response.errorCode == 2 then
- showTooltip("当前没人发起解散")
- elseif response.errorCode == 3 then
- showTooltip("已经有人申请解散")
- elseif response.errorCode == 4 then
- showTooltip("用户已经操作过")
- else
- -- 其他玩家的解散状态
- for uid, value in pairs(response.memberList) do
- self.dismissInfo[uid] = value.dismissState
- end
- self:dispatchEvent({name = "onDismissResponse", response = response})
- end
- end
-
- -- 服务器下发玩家GPS数据发生变化
- function Room:onGpsChangeResponse(status, response)
- print("Room:onGpsChangeResponse()", table.tostring(response))
-
- --[[
- --server收到0x8060协议后,广播当前桌子上所有用户
- ServerChangeUserInfo = defClass("ServerChangeUserInfo"
- --更新信息的用户uid
- , defVar("uid", VT_Int, -1)
- --用户信息
- , defVar("userInfo", VT_String, "")
- --保留字段,暂不使用
- , defVar("reserved", VT_String, "")
- )
- --]]
-
- print("Room:onGpsChangeResponse()", table.tostring(response))
-
- local nUserId = response.uid
- local memberInfo = self.roomInfo.memberList[nUserId]
- if memberInfo then
- memberInfo.userInfo = response.userInfo
- end
-
- self:dispatchEvent({name = "onGpsChangeResponse", nUserId = nUserId})
- end
-
- --辅助查找
- -- 通过玩家逻辑椅子号找到玩家ID
- function Room:getUserIdBySeatId(seatId)
- return self.seatList[seatId]
- end
-
- -- 通过玩家视图椅子号找到玩家ID
- function Room:getUserIdByViewId(seatShowId)
- return self.seatShowList[seatShowId]
- end
-
- -- 通过玩家逻辑椅子号找到视图椅子号
- function Room:getViewIdBySeatId(nSeatId)
- local userid = self:getUserIdBySeatId(nSeatId)
- return self:getViewIdByUserId(userid)
- end
-
- -- 通过玩家视图椅子号找到逻辑椅子号
- function Room:getSeatIdByViewId(nViewId)
- local userid = self:getUserIdByViewId(nViewId)
- for seatId,nUserId in pairs(self.seatList) do
- if userid == nUserId then
- return seatId
- end
- end
- end
-
- -- return table of userInfo, not string
- function Room:getUserInfo(nUserId)
- if self.roomInfo.memberList[nUserId] then
- return json.decode(self.roomInfo.memberList[nUserId].userInfo)
- else
- return nil
- end
- end
-
- -- 发起请求立即开局
- function Room:requestQuickStart(opType)
- --0初始状态 1申请开始游戏 2同意开始游戏 3不同意开始游戏
- local request = Messages.EarlyStartRequest:new()
- request.optType = opType
- self:sendResponse{cmd = Cmds.GAME_COMMAND_REQUEST_EARLY_START , sender = request}
- end
-
- -- 立即开局结果
- function Room:onQuickStartResponse(status, response)
- if not self.roomInfo then
- logD("self.roomInfo no exist,容错处理!")
- return
- end
-
- self.nleftStartGameTimeout = response.nleftStartGameTimeout
- self.quickStartInfo = {}
- for i,v in pairs(response.earlyStartPlayerInfo) do
- self.quickStartInfo[v.nUserId] = v.optType
- end
-
- self:dispatchEvent({name = "onQuickStartResponse", response = response})
- end
-
- -- 托管通知(回复)
- function Room:onHostingResponse(status, response)
- logD("Room:onHostingResponse 0x8133()", table.tostring(response))
-
- local userList = response.userList
- for k, v in ipairs(userList) do
- -- 保留状态,为了下一局
- self.roomInfo.memberList[v.nUserId].AIStatus = v.status or 0
-
- -- 是否托管
- -- if v.nUserId == self:getMyUserId() then
- -- self.roomInfo.hosting = v.status
- -- end
- self:dispatchEvent({name = 'onHostingResponse', response = {nUserId = v.nUserId, status = v.status}})
- end
- end
-
- function Room:resetDismissData()
- --玩家解散数据(userId 为Key,解散类型为value)
- self.dismissInfo = {}
-
- --解散总时间
- self.roomInfo.nDismissToTalTime = nil
-
- -- 解散倒计时
- self.roomInfo.nDismissStateTime = nil
-
- -- 解散显示
- self.roomInfo.nShowDismiss = false
- end
-
- function Room:initRoomInfo()
- self.roomInfo = {}
-
- self.seatShowList = {}
-
- self:resetDismissData()
-
- --手牌数据
- self.cards = {}
- end
-
- -- 通知服务器玩家GPS数据发生变化
- function Room:onGpsChangeRequest()
- print("Room:onUserInfoChangeRequest()")
-
- local request = StringPacket:new()
- request.stringValue = app.user.userInfo or ""
-
- logD("Room:onGpsChangeRequest()", table.tostring(request))
- self:sendResponse{cmd = Cmds.GAME_COMMAND_CLIENT_CHANGE_USERINFO , sender = request}
- end
-
-
- -- 玩家进入桌子成功
- function Room:onSitDownSuccessResponse(status, response)
- logD("--------------------玩家进入桌子成功--------------------")
- logD("Room:onSitDownSuccessResponse(), ", table.tostring(response))
-
- app.net:onMsgClear()
- app.net:onMsgPause()
-
- -- 记录当前桌子号
- self:initRoomInfo()
-
- -- 获取到的房间信息
- for k,v in pairs(response.Datas) do
- self.roomInfo[k] = v
- end
-
- --设置默认数据
- self.roomInfo.nGameStartCount = self.roomInfo.nGameStartCount or 0
-
- local gameinfo = json.decode(self.roomInfo.strGameInfo)
-
- self.roomInfo.gameinfo = gameinfo
-
- --俱乐部标志
- self.roomInfo.clubId = gameinfo.clubId
-
- -- 更新椅子号
- self:updateUserSeateShowId()
-
- logD("Room:onSitDownSuccessResponse() roomInfo = ", table.tostring(self.roomInfo))
-
- -- 发送通知
- self:dispatchEvent({name = "onEnterRoomSuccess", gameId = GAME_IDS.ERDouDiZhu, gameType = gameinfo.gamerule})
- end
-
- -- 玩家进入桌子失败
- function Room:onSitDownFailedResponse(status, response)
- logD("--------------------玩家进入桌子失败--------------------")
- app.waitDialogManager:closeWaitNetworkDialog()
- local errorCode = response.nErrorCode
- local errorString = ENTER_ROOM_RET_STR[errorCode] or string.format("坐下失败 errorCode = %s", errorCode)
- showTooltip(errorString)
- end
-
- function Room:getMyRecordUserId()
- local myUserId = app.user.loginInfo.uid
- local minID = 0
- local isFind = false
- for k,v in pairsByKeys(self.roomInfo.memberList) do
- if myUserId == v.nUserId then
- return myUserId
- end
- if not isFind then
- minID = v.nUserId
- isFind = true
- end
- end
- return minID
- end
-
-
- -- 检查此桌是否有此ID玩家
- function Room:checkUserIDIsInTable(nUserId)
- if self.roomInfo.memberList then
- local memberInfo = self.roomInfo.memberList[nUserId]
- if memberInfo then
- return true
- else
- return false
- end
- else
- return false
- end
- end
-
- -- 获取桌子上实际人数
- function Room:getActualPlayerNum()
- local playernum = 0
- for i,v in pairs(self.roomInfo.memberList) do
- if self:checkUserIDIsInTable(i) then
- playernum = playernum + 1
- end
- end
- return playernum
- end
-
- -- 更新玩家的相对椅子号
- function Room:updateUserSeateShowId()
- local myUserId = self:getMyRecordUserId()
- local mySeatId = self.roomInfo.memberList[myUserId].nSeatId
-
- self.roomInfo.nUserId = myUserId
- self.roomInfo.nSeatId = mySeatId
-
- local serverSeatToViewSeat = {
- [4] = {
- [0] = 4,
- [1] = 1,
- [2] = 2,
- [3] = 3,
- },
- [3] = {
- [0] = 4,
- [1] = 1,
- [2] = 3,
- },
- [2] = {
- [0] = 4,
- [1] = 2,
- }
- }
- self.seatList = {}
- self.userList = {}
- self.seatShowList = {}
- for k,v in pairs(self.roomInfo.memberList) do
- local relativeSeat = (v.nSeatId - mySeatId + self.roomInfo.nMaxPlayCount) % self.roomInfo.nMaxPlayCount
- local nSeatShowId = serverSeatToViewSeat[self.roomInfo.nMaxPlayCount][relativeSeat]
- self.seatShowList[nSeatShowId] = v.nUserId
- self.userList[v.nUserId] = nSeatShowId
- self.seatList[v.nSeatId] = v.nUserId
- end
-
- logD("User:updateUserSeateShowId(),seatShowList", table.tostring(self.seatShowList))
- logD("User:updateUserSeateShowId(),seatList ", table.tostring(self.seatList))
- logD("User:updateUserSeateShowId(),userList ", table.tostring(self.userList))
- end
-
- --断线重连
- function Room:onGameReconnection(status,response)
- logD("===============重连成功,清空之前所有存在的队列==================")
-
- app.net:onMsgClear()
- app.net:onMsgPause()
- logD(" = ", table.tostring(response))
- self:initRoomInfo()
-
- -- 获取到的房间信息
- for k,v in pairs(response.Datas) do
- self.roomInfo[k] = v
- end
-
- local gameinfo = json.decode(self.roomInfo.strGameInfo)
-
- self.roomInfo.gameinfo = gameinfo
-
- --俱乐部标志
- self.roomInfo.clubId = gameinfo.clubId
-
- --当前叫分
- self.roomInfo.curAskLoard = 0
- for k,v in pairs(self.roomInfo.memberList) do
- --最大叫分
- if v.askLoard > self.roomInfo.curAskLoard then
- self.roomInfo.curAskLoard = v.askLoard
- end
- --加倍状态
- v.askBei = v.bAskBei == 1 and v.askBei == 2 and 1 or 0
- end
-
- -- 将过数据插入到member数据内
- for i, v in pairs(response.Datas.guoInfo) do
- if self.roomInfo.memberList[i] then
- self.roomInfo.memberList[i].nGuo = v.nGuo
- end
- end
-
- -- 更新椅子号
- self:updateUserSeateShowId()
-
- -- 如果处于叫分阶段,移除地主ID
- if self.roomInfo.nStatus == defs.GAME_STATUS.ASK_LOARD then
- self.roomInfo.nBankerId = 0
- end
-
- --小局结算
- if self.roomInfo.nStatus == defs.GAME_STATUS.ROUND_OVER then
- local myMemberInfo = self.roomInfo.memberList[self:getMyUserId()]
- --已经准备,则重置一些状态
- if myMemberInfo.nPlayerFlag == 1 then
- --庄家
- self.roomInfo.nBankerId = 0
- --玩家数据
- for k,v in pairs(self.roomInfo.memberList) do
- --加倍状态
- v.askBei = 0
- --手牌
- v.handCards.Datas = {}
- end
- end
- end
-
- -- 发送通知
- self:dispatchEvent({name = "onEnterRoomSuccess", gameId = GAME_IDS.ERDouDiZhu, gameType = gameinfo.gamerule})
- end
-
- -- 通过玩家ID获取玩家展示的座位号
- function Room:getViewIdByUserId(nUserId)
- return self.userList[nUserId]
- end
-
- -- 我发起请求解散房间
- function Room:requestDismissRoom(opType)
- --1: 表示发起解散 2:同意解散 3:不同意解散
- local request = Messages.DismissRequest:new()
- request.operateType = opType
- self:sendResponse{cmd = Cmds.GAME_COMMAND_DISBAND_GAME , sender = request}
- end
-
- function Room:onUserExitResponse(status, response)
- logD("Room:onUserExitResponse(), ", table.tostring(response))
- if not self.roomInfo then
- logD("self.roomInfo no exist, 容错处理!")
- return
- end
-
- local ttExtInfo = string.split(response.userInfo, ",")
- app.user.loginInfo.historyCardNum = ttExtInfo[1]
- app.user.loginInfo.curCardNum = ttExtInfo[2]
-
- self:dispatchEvent({name = "onUserExitResponseRoom",response = response})
- end
-
- -- 其他玩家进入桌子
- function Room:onOtherSitDownResponse(status, response)
- logD("Room:onOtherSitDownResponse(), response = ", table.tostring(response))
- if not self.roomInfo then
- logD("self.roomInfo no exist,容错处理!")
- return
- end
-
- self.roomInfo.memberList[response.nUserId] = response
-
- -- 更新椅子号
- self:updateUserSeateShowId()
-
- -- 发送广播通知,某个位置有人坐下了
- self:dispatchEvent({name = "onOtherSitDownResponse", response = response})
- end
-
- -- 其他玩家是否掉线
- function Room:onOtherDroppedResponse(status, response)
- logD("User:onOtherDroppedResponse(), response = ", table.tostring(response))
-
- local memberInfo = self.roomInfo.memberList[response.nUserId]
- if memberInfo then
- memberInfo.nOnlineStatus = response.nOnlineStatus
- end
-
- self:dispatchEvent({name = "onOtherDroppedResponse", response = response})
- end
-
- -- 其他玩家退出房间
- function Room:onOtherLogoutResponse(status, response)
- logD("Room:onOtherLogoutResponse(), response = ", table.tostring(response))
-
- if not self.roomInfo then
- logD("self.roomInfo no exist,容错处理!")
- return
- end
-
- --已开局玩家不可退出(不做处理)
- if (self.roomInfo.nGameStartCount or 0) > 0 then
- logD("onOtherLogoutResponse 已开局玩家不可退出")
- return
- end
-
- response.viewId = self:getViewIdByUserId(response.nUserId)
-
- self.roomInfo.memberList[response.nUserId] = nil
-
- self:dispatchEvent({name = "onOtherLogoutResponse", response = response})
- end
-
- -- 服务器下发玩家的准备状态
- function Room:onUserReadyResponse(status, response)
- logD("Room:onUserReadyResponse(), ", table.tostring(response))
-
- if not self.roomInfo then
- logD("self.roomInfo no exist,容错处理!")
- return
- end
-
- if response.nUserId == self:getMyUserId() then
- --重置庄家
- self.roomInfo.nBankerId = 0
-
- --重置炸弹数量
- self.roomInfo.nBombs = 0
-
- --重置加倍
- for k,v in pairs(self.roomInfo.memberList) do
- v.askBei = 0
- end
- end
-
- --标记准备了
- self.roomInfo.memberList[response.nUserId].nPlayerFlag = 1
-
- self:dispatchEvent({name = "onUserReadyResponse", response = response})
- end
-
- function Room:getMyUserId()
- return self:getUserIdByViewId(defs.VIEW_ID.MY_VIEW_ID)
- end
-
- function Room:sendAskLoard(askLoard)
- local request = Messages.AskLoard:new()
- request.askLoard = askLoard
- self:sendResponse{cmd = Cmds.cmd_0x8109 , sender = request}
- end
-
- function Room:sendAskBei(askBei)
- local request = Messages.AskBei:new()
- request.askBei = askBei
- self:sendResponse{cmd = Cmds.cmd_0x810d , sender = request}
- end
-
- function Room:sendOperation(data)
- local request = Messages.Operation:new()
- request.opType = data.opType
- for _,v in ipairs(data.cards) do
- table.insert(request.cards.Datas, v)
- end
- self:sendResponse{cmd = Cmds.cmd_0x810f , sender = request}
- end
-
- function Room:sendQiang(qiang)
- local request = Messages.Qiang:new()
- request.qiang = qiang
- self:sendResponse{cmd = Cmds.cmd_0x8124 , sender = request}
- end
-
- function Room:sendRang(rang)
- local request = Messages.Rang:new()
- request.rang = rang
- self:sendResponse{cmd = Cmds.cmd_0x8122 , sender = request}
- end
-
- return Room
|