local RoomCmd = { --[[/** * 客户端通过协议0x8060通知server, 用户信息改变 *
 * 推送: {@code ClientChangeUserInfo}
 * 
*/--]] GAME_COMMAND_CLIENT_CHANGE_USERINFO = 0x8060, --[[/** * server收到0x8060协议后,广播当前桌子上所有用户 *
 * 推送: {@code ServerChangeUserInfo}
 * 
*/--]] GAME_COMMAND_SERVER_CHANGE_USERINFO = 0x8061, --[[/** * server收到0x8018协议后,广播当前桌子上所有用户 若小局结束后发现玩家红花数不足,系统则会自动解散此牌局,解散前服务器广播每个玩家 解散的具体的原因 *
 * 推送: {@code RedFlowerDismiss}
 * 
*/--]] GAME_COMMAND_RED_FLOWER_DISMISS = 0x8018, --[[/** * 洗牌协议 *
 * 推送: {@code }
 * 
*/--]] GAME_COMMAND_XIPAI = 0x8062, --[[/** * 游戏结束后,服务器判断大赢家是否满足赠送条件,满足赠送条件的用户将会收到协议 *
 * 推送: {@code ChouJiangBroad}
 * 
*/--]] GAME_COMMAND_CHOUJIANG = 0x800a, } --* server收到0x8018协议后,广播当前桌子上所有用户 local ChouJiangBroad = defClass("ChouJiangBroad" --赠送产生的唯一标识,客户端拿到传给php领奖 , defVar("rewardToken", VT_String, "") --玩家剩余的积分 , defVar("leftMatchScore", VT_Int, 0) --需要支付的积分 , defVar("useScore", VT_Int, 0) --[[奖励格式json串,内容: {"prize":[" {\"idx\":4,\"type\":13,\"val\":0}", "{\"idx\":5,\"type\":13,\"val\":0}", "{\"idx\":1,\"type\":13,\"val\":0}", "{\"idx\":2,\"type\":13,\"val\":0}", "{\"idx\":3,\"type\":13,\"val\":0}" ]} idx表示序号,type表示奖励类型,13表示房卡,1表示金币 val对应奖励的数值 ]] , defVar("rewardInfo", VT_String, "") ) --* server收到0x8018协议后,广播当前桌子上所有用户 local RedFlowerDismiss = defClass("RedFlowerDismiss" --更新信息的用户uid , defVar("retCode", VT_Short, 0) ) --server收到0x8060协议后,广播当前桌子上所有用户 local ServerChangeUserInfo = defClass("ServerChangeUserInfo" --更新信息的用户uid , defVar("uid", VT_Int, -1) --用户信息 , defVar("userInfo", VT_String, "") --保留字段,暂不使用 , defVar("reserved", VT_String, "") ) local RoomBase = class("RoomBase" , require("luaScript.Protocol.Protocol")) local matchErrorTip = { [1] = "超时停止游戏", [2] = "群主解散", [3] = "房卡不足", [4] = "系统解散", [5] = "桌子上有玩家红花数不足,房间自动解散!", } function RoomBase:ctor(net) RoomBase.super.ctor(self , net); -- 清空大结算抽奖数据,可能由于某些原因, -- 导致大结算没弹框或者消息延迟收到有数据缓存 dd.IGameOverAward.setAwardData(nil) self:initBindEvent() end function RoomBase:initBindEvent() self:defPushMsg{cmd = RoomCmd.GAME_COMMAND_SERVER_CHANGE_USERINFO, reader = ServerChangeUserInfo, func = handler(self , self.onGpsChangeResponse)} self:defPushMsg{cmd = RoomCmd.GAME_COMMAND_RED_FLOWER_DISMISS, reader = RedFlowerDismiss, func = handler(self , self.onRedFlowerDismiss)} self:defPushMsg{cmd = RoomCmd.GAME_COMMAND_XIPAI, reader = BytePacket, func = handler(self , self.onGameXiPai)} self:defPushMsg{cmd = RoomCmd.GAME_COMMAND_CHOUJIANG, reader = ChouJiangBroad, func = handler(self , self.onChouJiangBroad)} end -- 通知服务器玩家GPS数据发生变化 function RoomBase:requestGpsChange() local request = StringPacket:new() request.stringValue = app.user.userInfo or "" logD("RoomBase:requestGpsChange()", table.tostring(request)) self:sendResponse{cmd = RoomCmd.GAME_COMMAND_CLIENT_CHANGE_USERINFO , sender = request}; end -- 服务器下发玩家GPS数据发生变化 function RoomBase:onGpsChangeResponse(status, response) print("RoomBase:onGpsChangeResponse()", table.tostring(response)) --[[ --server收到0x8060协议后,广播当前桌子上所有用户 ServerChangeUserInfo = defClass("ServerChangeUserInfo" --更新信息的用户uid , defVar("uid", VT_Int, -1) --用户信息 , defVar("userInfo", VT_String, "") --保留字段,暂不使用 , defVar("reserved", VT_String, "") ) --]] -- print("RoomBase:onGpsChangeResponse()", table.tostring(response)) local nUserId = response.uid local memberInfo = self.roomInfo and self.roomInfo.memberList and self.roomInfo.memberList[nUserId] if memberInfo then memberInfo.userInfo = response.userInfo end self:updateGpsUserInfo(nUserId) end function RoomBase:onRedFlowerDismiss(status, response) print("RoomBase:onRedFlowerDismiss()", table.tostring(response)) local code = response.retCode if code then self.roomInfo.isRedFlowerDismiss = true local retCode = matchErrorTip[code] or "errcode【"..code.."】不存在!" if code == 5 then retCode = "桌子上有玩家排名分不足,房间自动解散!" if app.club_php.clubID and app.club_php.clubID ~= 0 then if app.club_php:getCestIsOpen(app.club_php.clubID) then retCode = "桌上有选手比赛积分不足被淘汰,房间自动解散。" end end end showConfirmDialog(retCode) end end --更新gps用户数据 --需要检测的ID 没有则检测所有人的距离 --isOpenView 危险距离是否主动弹出提示 function RoomBase:updateGpsUserInfo(userId,isOpenView) if self.roomInfo and self.roomInfo.memberList then local isGameStart = self.roomInfo.nGameStartCount>0 local userInfoList = {} for nUserId, memberInfo in pairs(self.roomInfo.memberList) do local nSeatId = memberInfo.nSeatId local userInfo = memberInfo.userInfo userInfoList[nUserId] = {nSeatId = nSeatId, userInfo = userInfo} end if isGameStart then isOpenView = false end self:dispatchEvent({ name = GAME_EVENT.GPS_UPDATE_USER_INFO, userId=userId, userInfoList = userInfoList, isOpenView = isOpenView or false, isGameStart = isGameStart, -- maxPlayerNum = self.roomInfo.nMaxPlayCount, }) end end --检测本地gps信息跟服务器数据是否一致,不一致则发送更新 function RoomBase:checkGpsIsNew() if self.roomInfo and self.roomInfo.memberList then local myUserId = app.room:getMyUserId() or app.user.loginInfo.uid local user = self.roomInfo.memberList[myUserId] if user then local userInfo = json.decode(user.userInfo or "") if userInfo then local isNewest = app.user:isGpsInfoNewest(userInfo.gpsInfo) --不是最新的数据则发送给服务器同步 if not isNewest then app.room:requestGpsChange() return false end end end end return true end -- 通过玩家逻辑椅子号找到玩家ID function RoomBase:getUserIdBySeatId(nSeatId) return 0 end -- 通过玩家视图椅子号找到玩家ID function RoomBase:getUserIdByViewId(nViewId) return nil end -- 通过玩家ID获取玩家展示的座位号 function RoomBase:getViewIdByUserId(nUserId) return 1 end -- 通过玩家逻辑椅子号找到视图椅子号 function RoomBase:getViewIdBySeatId(nSeatId) return 1 end -- 通过玩家ID找到逻辑椅子号 function RoomBase:getSeatIdByUserId(nViewId) return 1 end -- 通过玩家视图椅子号找到逻辑椅子号 function RoomBase:getSeatIdByViewId(nUserId) return 1 end -- 获取房间内的用户信息 function RoomBase:getUserInfo(uid) return "" end function RoomBase:getMyUserId() if self:isInMemberList() then return app.user.loginInfo.uid else if self.roomInfo and self.roomInfo.memberList then for nUserId,v in pairs(self.roomInfo.memberList) do return nUserId end else return app.user.loginInfo.uid end end end function RoomBase:isInMemberList() if self.roomInfo and self.roomInfo.memberList then for nUserId,v in pairs (self.roomInfo.memberList) do if app.user.loginInfo.uid==nUserId then return true end end end return false end function RoomBase:sendGameXiPai() self:sendResponse{cmd = RoomCmd.GAME_COMMAND_XIPAI}; end -- 洗牌结果 function RoomBase:onGameXiPai(status, response) print("RoomBase:onGameXiPai()", table.tostring(response)) local result = response.byteValue if result == 3 then showTooltip("房卡不足") elseif result == 2 then showTooltip("已设置洗牌") elseif result == 1 then showTooltip("桌子状态未在小局结束") elseif result == 0 then app.user.loginInfo.curCardNum = app.user.loginInfo.curCardNum - 2 end end -- 抽奖结果 function RoomBase:onChouJiangBroad(status, response) logD("RoomBase:onChouJiangBroad()", table.tostring(response)) dd.IGameOverAward.setAwardData(response) end return RoomBase;