Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

1198 строки
41 KiB

  1. local RoomCmd=MJFramework.MJImport("mj.luaScript.Protocol.MJCmd")
  2. local MJMessage=MJFramework.MJImport("mj.luaScript.Protocol.MJMessage")
  3. local MJDefine=MJFramework.MJImport("mj.luaScript.MJDefine")
  4. local Room = class("Room" , require("luaScript.Protocol.ProtocolRoomBase"))
  5. function Room:initRoomInfo()
  6. -- 房间信息
  7. self.roomInfo ={
  8. memberList={},
  9. }-- MJMessage.RoomInfoLocal:new()
  10. self.seatShowList = {} -- [seatShowId] = nUserId
  11. self:resetDismissData()
  12. --手牌数据
  13. self.cards = {}
  14. end
  15. function Room:resetDismissData()
  16. --玩家解散数据(userId 为Key,解散类型为value)
  17. self.dismissInfo = {}
  18. --解散总时间
  19. self.roomInfo.nDismissToTalTime = nil
  20. -- 解散倒计时
  21. self.roomInfo.nDismissStateTime = nil
  22. -- 解散显示
  23. self.roomInfo.nShowDismiss = false
  24. end
  25. -- 游戏正式开始
  26. function Room:onGameStartResponse(status, response)
  27. logD("-------------------- 新的一局开始了 ------------------------")
  28. if not self.roomInfo then
  29. logD("self.roomInfo no exist,容错处理!")
  30. return
  31. end
  32. logD("Room:onGameStartResponse(), ", table.tostring(response))
  33. self.roomInfo.nGameStartCount = response.nGameStartCount;
  34. self.roomInfo.nTotalGameNum = response.nTotalGameNum;
  35. self.roomInfo.nRoomOwnedUid = response.nRoomOwnedUid;
  36. self.roomInfo.nBankSeatId = response.nBankSeatId;
  37. self.roomInfo.shuffleList = response.shuffleList;
  38. self.roomInfo.shuffleNum = response.shuffleNum;
  39. self.roomInfo.nLeaveCardNum = 0
  40. -- 清空上一局的手牌信息
  41. self.cards = {}
  42. -- 发送广播通知,游戏开始了
  43. self:dispatchEvent({name = MJDefine.MJEvent.GameStartResponse});
  44. end
  45. -- 游戏发牌结果
  46. function Room:onGameSendCardResponse(status, response)
  47. logD("-------------------- 游戏发牌 ------------------------")
  48. if not self.roomInfo then
  49. logD("self.roomInfo no exist,容错处理!")
  50. return
  51. end
  52. --[[ -- 用户uid
  53. , defVar("nUserId", VT_Int, 0)
  54. -- 庄家第一张摸的牌
  55. , defVar("nbankFirstGrabCard", VT_UChar, 0)
  56. -- 牌值类型列表
  57. , defVar("cardList", VT_Vector(CardSendListData), {})--]]
  58. logD("Room:onGameSendCardResponse(), ", table.tostring(response))
  59. -- self.roomInfo.nbankFirstGrabCard = response.nbankFirstGrabCard
  60. --目前server只发自己过来,后续战绩回放考虑到会发所有玩家来,故以userid为key于扩展
  61. -- local cardData = self:serverCardToMyCard(response.cardList)
  62. -- logD("Room:onGameSendCardResponse : "..table.tostring(cardData))
  63. for k,v in pairs(response.playerCards) do
  64. self.roomInfo.memberList[v.nUserId].handCards = v.handCards
  65. end
  66. -- self.cards[response.nUserId] = cardData
  67. -- 发送广播通知,发牌开始了
  68. self:dispatchEvent({name = MJDefine.MJEvent.GameSendCardResponse});
  69. end
  70. -- 系统发牌后发来的自动提操作
  71. function Room:onSystemOperationStart(status, response)
  72. logD("-------------------- 游戏提结果 ------------------------")
  73. if not self.roomInfo then
  74. logD("self.roomInfo no exist,容错处理!")
  75. return
  76. end
  77. logD("Room:onSystemOperationStart(), ", table.tostring(response))
  78. -- 发送广播通知,游戏开始了
  79. self:dispatchEvent({name = "onSystemOperationStart",response = response});
  80. end
  81. -- 广播桌子上所有玩家庄家起手操作
  82. --[[若庄家可以胡牌, 则客户端显示胡牌, 过两个按钮,若不能胡牌,则判断用户是否要出牌,
  83. 若能出牌,则显示出牌提示,若庄家既不能胡牌,也不能出牌,客户端无需处理,
  84. 此种情况下server会自动跳转到下家抓牌, 强制胡牌的情况下必胡
  85. ]]
  86. function Room:onBankerOutCard(status, response)
  87. logD("-------------------- 游戏庄家起手操作------------------------")
  88. if not self.roomInfo then
  89. logD("self.roomInfo no exist,容错处理!")
  90. return
  91. end
  92. self.roomInfo.nLeaveCardNum = response.nLeaveCardNum
  93. self.roomInfo.needOutCardId = response.nUserId
  94. --logD("Room:onBankerOutCard(), ", table.tostring(response))
  95. local myUserId = self:getMyUserId()
  96. if response.nUserId==myUserId then
  97. --这里自己摸牌后,不隐藏听牌提示
  98. --self.roomInfo.memberList[myUserId].nTingStatus=MJDefine.MJTingStatus.NoTing
  99. -- dump(self.roomInfo.memberList[myUserId])
  100. --self:dispatchEvent({name = MJDefine.MJEvent.TingSatus})
  101. end
  102. -- 发送广播通知,游戏开始了
  103. self:dispatchEvent({name = MJDefine.MJEvent.BankerOutCard ,response = response});
  104. end
  105. function Room:onQiangGangHu(status,response)
  106. logD("-------------------- 抢杠胡 ------------------------")
  107. if not self.roomInfo then
  108. print("容错处理")
  109. return
  110. end
  111. logD("Room:onQiangGangHu(), response = ", table.tostring(response))
  112. self:dispatchEvent({name = MJDefine.MJEvent.QiangGangHu , response = response});
  113. end
  114. function Room:onQiPai(status,response)
  115. logD("-------------------- 弃牌 ------------------------")
  116. if not self.roomInfo then
  117. print("容错处理")
  118. return
  119. end
  120. logD("Room:onQiPai(), response = ", table.tostring(response))
  121. self:dispatchEvent({name = MJDefine.MJEvent.OutCardResponse ,response = response});
  122. end
  123. function Room:onOutCardError(status,response)
  124. logD("-------------------- 出牌错误 ------------------------")
  125. if not self.roomInfo then
  126. print("容错处理")
  127. return
  128. end
  129. logD("Room:onOutCardError(), response = ", table.tostring(response))
  130. --[[错误码说明:
  131. OUT_CARD_SUCCESS = 0, //正常
  132. OUT_CARD_ON_NEED = 1, //不需要出牌
  133. OUT_CARD_INVALID = 2, //出牌非法--]]
  134. local errorCode = response.result
  135. -- if errorCode == LHQ_OUT_CARD_ERROR_TIP.OUT_CARD_SUCCESS then
  136. showTooltip("出牌无效")
  137. -- elseif errorCode == LHQ_OUT_CARD_ERROR_TIP.OUT_CARD_SUCCESS then
  138. -- showTooltip("不需要出牌")
  139. -- else
  140. -- showTooltip("出牌未知")
  141. -- end
  142. self:dispatchEvent({name = MJDefine.MJEvent.OutCardError });
  143. end
  144. function Room:onOutCardSuccess(status,response)
  145. logD("-------------------- 出牌成功 ------------------------")
  146. if not self.roomInfo then
  147. print("容错处理")
  148. return
  149. end
  150. logD("Room:onOutCardSuccess(), response = ", table.tostring(response))
  151. self:dispatchEvent({name = MJDefine.MJEvent.OutCardSuccess , response = response});
  152. end
  153. function Room:onTurnOutCard(status,response)
  154. logD("-------------------- 指示出牌 ------------------------")
  155. if not self.roomInfo then
  156. print("容错处理")
  157. return
  158. end
  159. logD("Room:onTurnOutCard(), response = ", table.tostring(response))
  160. self:dispatchEvent({name = MJDefine.MJEvent.TurnOutCard});
  161. end
  162. --小局结算
  163. function Room:onGameXiaoJuResponse(status, response)
  164. logD("--------------------小局结算 ------------------------")
  165. if not self.roomInfo then
  166. logD("self.roomInfo no exist,容错处理!")
  167. return
  168. end
  169. -- 一局结束的原因
  170. self.roomInfo.stopFlag=response.stopFlag
  171. -- 房间信息
  172. self.roomInfo.strGameInfo=response.strGameInfo
  173. --结算信息
  174. self.roomInfo.strResultInfo=response.strResultInfo
  175. --玩家信息
  176. for k,v in pairs(response.playerInfos) do
  177. if self.roomInfo.memberList[v.nUserId] then
  178. --当前局分数
  179. self.roomInfo.memberList[v.nUserId].nTurnScore=v.nTurnScore
  180. --总分
  181. self.roomInfo.memberList[v.nUserId].nTotalMoney=v.nTotalMoney
  182. --玩家本局输赢情况 0不胡不输 1胡,2点炮或者输
  183. self.roomInfo.memberList[v.nUserId].result=v.result
  184. -- 胡牌牌类型-7对胡、平胡,0为输或者不胡不输
  185. self.roomInfo.memberList[v.nUserId].huType=v.huType
  186. self.roomInfo.memberList[v.nUserId].gruoupCards = v.gruoupCards
  187. self.roomInfo.memberList[v.nUserId].outCards = v.outCards
  188. self.roomInfo.memberList[v.nUserId].handCards = v.handCards
  189. end
  190. -- self.roomInfo.memberList[v.nUserId].nTotalMoney=v.nTotalMoney
  191. -- self.roomInfo.memberList[v.nUserId].
  192. -- local viewId = app.room:getViewIdByUserId(k)
  193. -- local nScore = v.nTotalMoney
  194. -- local memberInfo = app.room.roomInfo.memberList[k]
  195. -- memberInfo.nTotalMoney = nScore
  196. -- self.allNodes[viewId].score:setText(tostring(nScore))
  197. end
  198. -- self.roomInfo.playerInfos",VT_Vector(message.XiaojuPlayerInfo),{})
  199. --是否大局结束,结束是1
  200. self.roomInfo.isGameOver=response.isGameOver
  201. --操作统计
  202. self.roomInfo.opsCntMapString=response.opsCntMapString
  203. self.roomInfo.scoreCntMap=json.decode(response.soreCntMapString)
  204. logD("Room:onGameXiaoJuResponse() :", table.tostring(response))
  205. self:dispatchEvent({name = MJDefine.MJEvent.GameXiaoJuResponse,response = response});
  206. end
  207. --大局结算
  208. function Room:onGameDaJuResponse(status, response)
  209. logD("-------------------- 大局结算 ------------------------")
  210. if not self.roomInfo then
  211. logD("self.roomInfo no exist,容错处理!")
  212. return
  213. end
  214. for k,v in pairs(response.nTotalPlayerInfos) do
  215. if self.roomInfo.memberList[v.nUserId] then
  216. self.roomInfo.memberList[v.nUserId].nTotalInfo=json.decode(v.nTotalInfo)
  217. end
  218. end
  219. logD("Room:onGameDaJuResponse() :", table.tostring(response))
  220. self:dispatchEvent({name = MJDefine.MJEvent.GameDaJuResponse ,response = response});
  221. end
  222. -- 玩家进入桌子成功
  223. function Room:onSitDownSuccessResponse(status, response)
  224. logD("--------------------玩家进入桌子成功--------------------")
  225. logD("Room:onSitDownSuccessResponse(), ", table.tostring(response))
  226. app.net:onMsgClear()
  227. app.net:onMsgPause()
  228. -- 记录当前桌子号
  229. self:initRoomInfo()
  230. -- 获取到的房间信息
  231. -- self.gameId = response.gameId
  232. self.roomInfo.gameId = response.gameId
  233. self.roomInfo.nShowTableId = response.nShowTableId
  234. self.roomInfo.nMaxPlayCount = response.nMaxPlayCount
  235. self.roomInfo.nRoomOwnedUid = response.nRoomOwnedUid
  236. self.roomInfo.nTotalGameNum = response.nTotalGameNum
  237. self.roomInfo.strGameInfo = response.strGameInfo
  238. self.roomInfo.nGameStartCount = response.nGameStartCount or 0
  239. self.roomInfo.nLeaveCardNum = response.nLeaveCardNum or 0
  240. -- 桌子上其他玩家的信息
  241. for k,v in pairs(response.memberList) do
  242. self.roomInfo.memberList[v.nUserId] = v
  243. -- self.roomInfo.memberList[v.nUserId].nTingStatus=MJDefine.MJTingStatus.NoTing
  244. end
  245. -- 更新椅子号
  246. self:updateUserSeateShowId()
  247. logD("Room:onSitDownSuccessResponse() roomInfo = ", table.tostring(self.roomInfo))
  248. -- 发送通知
  249. self:dispatchEvent({name = MJDefine.MJEvent.EnterRoomSuccess, gameId = self.roomInfo.gameId, gameType = self.roomInfo.strGameInfo.gamerule})
  250. end
  251. -- 玩家进入桌子失败
  252. function Room:onSitDownFailedResponse(status, response)
  253. logD("--------------------玩家进入桌子失败--------------------")
  254. local errorCode = response.nErrorCode
  255. local errorString = ENTER_ROOM_RET_STR[errorCode] or string.format("坐下失败 errorCode = %s", errorCode);
  256. showTooltip(errorString);
  257. end
  258. -- 更新玩家的相对椅子号
  259. function Room:updateUserSeateShowId()
  260. local myUserId = self:getMyUserId()
  261. local mySeatId
  262. self.isOnLooker = false
  263. if self.isOnLooker then
  264. mySeatId = 3
  265. else
  266. mySeatId = self.roomInfo.memberList[myUserId].nSeatId
  267. end
  268. self.roomInfo.nUserId = myUserId
  269. self.roomInfo.nSeatId = mySeatId
  270. --[视图椅子号] = userID
  271. --[座位号] = userID
  272. --[userID] = 视图椅子号
  273. self.seatList = {}
  274. self.userList = {}
  275. local playerCount=self.roomInfo.nMaxPlayCount or 4
  276. --[[local gameInfo = json.decode(self.roomInfo.strGameInfo)
  277. if gameInfo.isfaststart ~= 1 then
  278. playerCount = gameInfo.playnum
  279. end--]]
  280. for k,v in pairs(self.roomInfo.memberList) do
  281. local config=MJDefine.MJRoomPlayerSitConfig[playerCount]
  282. local num=(v.nSeatId - mySeatId + playerCount) % playerCount
  283. local nSeatShowId = config[num+1]
  284. -- if nSeatShowId == 0 then
  285. -- nSeatShowId = 4
  286. -- end
  287. self.seatShowList[nSeatShowId] = v.nUserId
  288. self.seatList[v.nSeatId] = v.nUserId
  289. self.userList[v.nUserId] = nSeatShowId
  290. end
  291. logD("User:updateUserSeateShowId(), playerCount", playerCount)
  292. logD("User:updateUserSeateShowId(), seatShowList", table.tostring(self.seatShowList))
  293. logD("User:updateUserSeateShowId(),seatList ", table.tostring(self.seatList))
  294. logD("User:updateUserSeateShowId(),userList ", table.tostring(self.userList))
  295. --logD("User:updateUserSeateShowId(), ")
  296. end
  297. -- 服务器下发玩家的准备状态
  298. function Room:onUserReadyResponse(status, response)
  299. logD("Room:onUserReadyResponse(), ", table.tostring(response))
  300. if not self.roomInfo then
  301. logD("self.roomInfo no exist,容错处理!")
  302. return
  303. end
  304. local nUserId = response.nUserId
  305. local memberInfo = self.roomInfo.memberList[nUserId]
  306. --准备的时候设置听
  307. memberInfo.nTingStatus=MJDefine.MJTingStatus.NoTing
  308. --标记准备了
  309. if memberInfo then
  310. memberInfo.nPlayerFlag = 1
  311. end
  312. self:dispatchEvent({name = MJDefine.MJEvent.UserReadyResponse ,nUserId=nUserId});
  313. end
  314. -- 我发起请求解散房间
  315. function Room:requestDismissRoom(opType)
  316. --1: 表示发起解散 2:同意解散 3:不同意解散
  317. local request = MJMessage.DismissRequest:new()
  318. request.operateType = opType
  319. self:sendResponse{cmd = RoomCmd.GAME_COMMAND_DISBAND_GAME , sender = request};
  320. end
  321. --8012
  322. function Room:onDismissResponse(status, response)
  323. --[[-- nUserId
  324. , defVar("nUserId", VT_Int, 0)
  325. -- 1: 表示发起解散 2:同意解散 3:不同意解散
  326. , defVar("operateType", VT_UChar, 0)
  327. -- 剩余解散超时时间
  328. , defVar("timeLeft", VT_Short, 0) --]]
  329. if not self.roomInfo then
  330. logD("self.roomInfo no exist,容错处理!")
  331. return
  332. end
  333. local nUserId = response.nUserId
  334. local operateType = response.operateType
  335. -- 收到玩家发起请求时,数据重置
  336. if response.operateType == 1 then
  337. self:resetDismissData()
  338. end
  339. --数据记录
  340. self.dismissInfo[nUserId] = operateType;
  341. self:dispatchEvent({name = MJDefine.MJEvent.DismissResponse , response = response});
  342. end
  343. -- 发起请求回复 8011
  344. function Room:onUserDismissResultResponse(status, response)
  345. logD("User:onUserDismissResultResponse, ", table.tostring(response))
  346. if not self.roomInfo then
  347. logD("self.roomInfo no exist,容错处理!")
  348. return
  349. end
  350. --[[
  351. -- 0:成功
  352. -- 1:operateType取值范围不对
  353. -- 2:当前没人发起解散
  354. -- 3:已经有人申请解散
  355. , defVar("errorCode", VT_Short, 0)
  356. -- 玩家操作
  357. , defVar("operateType", VT_Int, 0)
  358. -- 桌子上其他用户数量
  359. , defVar("memberList", VT_VectorToMap(UserDismissResult, "nUserId"))
  360. -- 剩余解散超时时间
  361. , defVar("timeLeft", VT_Short, 0) --]]
  362. logD("30000000--runUserDismissResultResponse")
  363. if response.errorCode == 1 then
  364. showTooltip("operateType取值范围不对")
  365. elseif response.errorCode == 2 then
  366. showTooltip("当前没人发起解散")
  367. elseif response.errorCode == 3 then
  368. showTooltip("已经有人申请解散")
  369. elseif response.errorCode == 4 then
  370. showTooltip("用户已经操作过")
  371. else
  372. -- 其他玩家的解散状态
  373. for uid, value in pairs(response.memberList) do
  374. self.dismissInfo[uid] = value.dismissState
  375. end
  376. self:dispatchEvent({name = MJDefine.MJEvent.DismissResponse, response = response});
  377. end
  378. end
  379. -- 其他玩家退出房间
  380. function Room:onOtherLogoutResponse(status, response)
  381. logD("Room:onOtherLogoutResponse(), response = ", table.tostring(response))
  382. if not self.roomInfo then
  383. logD("self.roomInfo no exist,容错处理!")
  384. return
  385. end
  386. local nUserId = response.nUserId
  387. local nSeatShowId = self.userList[nUserId]
  388. if not self.roomInfo.isGameOver then
  389. local memberList = self.roomInfo.memberList
  390. memberList[nUserId]=nil
  391. end
  392. self:updateGpsUserInfo(nil,false)
  393. self.roomInfo.nStartGameUid = response.nStartGameUid
  394. logD("30000000--runOtherLogoutResponse")
  395. self:dispatchEvent({name = MJDefine.MJEvent.OtherLogoutResponse , nUserId = nUserId, nSeatShowId = nSeatShowId});
  396. end
  397. -- 其他玩家进入桌子
  398. function Room:onOtherSitDownResponse(status, response)
  399. logD("Room:onOtherSitDownResponse(), response = ", table.tostring(response))
  400. if not self.roomInfo then
  401. logD("self.roomInfo no exist,容错处理!")
  402. return
  403. end
  404. local other = MJMessage.RoomMemberInfo:new()
  405. other.nUserId = response.nUserId
  406. other.nSeatId = response.nSeatId
  407. other.userInfo = response.userInfo
  408. other.nTotalMoney = response.nTotalMoney
  409. other.nPlayerFlag = response.nPlayerFlag
  410. local memberList = self.roomInfo.memberList
  411. -- 添加其他玩家的用户ID
  412. if memberList[other.nUserId] then
  413. memberList[other.nUserId] = other:updateTo(memberList[other.nUserId])
  414. else
  415. memberList[other.nUserId] = other
  416. end
  417. -- 更新椅子号
  418. self:updateUserSeateShowId()
  419. local nSeatShowId = self.userList[other.nUserId]
  420. --检测GPS
  421. self:updateGpsUserInfo(response.nUserId,true)
  422. -- 发送广播通知,某个位置有人坐下了
  423. self:dispatchEvent({name = MJDefine.MJEvent.OtherSitDownResponse , nSeatShowId = nSeatShowId});
  424. end
  425. function Room:onUserExitResponse(status, response)
  426. logD("Room:onUserExitResponse(), ", table.tostring(response))
  427. if not self.roomInfo then
  428. logD("self.roomInfo no exist,容错处理!")
  429. return
  430. end
  431. local ttExtInfo = string.split(response.userInfo, ",")
  432. app.user.loginInfo.historyCardNum = ttExtInfo[1];
  433. app.user.loginInfo.curCardNum = ttExtInfo[2];
  434. self:dispatchEvent({name = MJDefine.MJEvent.UserExitResponseRoom ,response = response});
  435. end
  436. function Room:onTingCardStatus(status, response)
  437. logD("Room:onTingCardStatus(), ", table.tostring(response))
  438. print("--------onTingCardStatus--------")
  439. if not self.roomInfo then
  440. logD("self.roomInfo no exist,容错处理!")
  441. return
  442. end
  443. local myUserId = app.user.loginInfo.uid
  444. self.roomInfo.memberList[myUserId].nTingStatus=response.nTingStatus
  445. self:dispatchEvent({name = MJDefine.MJEvent.TingSatus})
  446. end
  447. function Room:onTingCardResult( status, response )
  448. logD("Room:onTingCardResult(), ", table.tostring(response))
  449. print("--------onTingCardResult--------")
  450. if not self.roomInfo then
  451. logD("self.roomInfo no exist,容错处理!")
  452. return
  453. end
  454. self:dispatchEvent({name = MJDefine.MJEvent.TingResult,response = response})
  455. end
  456. function Room:pushTing( status, response )
  457. print("--------pushTing--------")
  458. logD("Room:pushTing, ", table.tostring(response))
  459. if not self.roomInfo then
  460. logD("self.roomInfo no exist,容错处理!")
  461. return
  462. end
  463. self.roomInfo.tings={}
  464. for k,v in pairs(response.tings) do
  465. -- print(v)
  466. self.roomInfo.tings[v.card]=v.tingCards
  467. -- if v.card~=0 then
  468. -- print(v.card)
  469. -- end
  470. end
  471. --摸到牌不隐藏听牌提示
  472. --[[if table.nums(self.roomInfo.tings)>0 then
  473. local myUserId = self:getMyUserId()--app.user.loginInfo.uid
  474. self.roomInfo.memberList[myUserId].nTingStatus=MJDefine.MJTingStatus.NoTing--response.nTingStatus
  475. self:dispatchEvent({name = MJDefine.MJEvent.TingSatus})
  476. end--]]
  477. self:dispatchEvent({name = MJDefine.MJEvent.PushTing})
  478. end
  479. -- function Room:onDaiXing(status, response)
  480. -- logD("Room:onTingCardResult(), ", table.tostring(response))
  481. -- if not self.roomInfo then
  482. -- logD("self.roomInfo no exist,容错处理!")
  483. -- return
  484. -- end
  485. -- self:dispatchEvent({name = "onDaiXing",response = response});
  486. -- end
  487. -- function Room:onQiHuSelfResponese(status, response)
  488. -- logD("Room:onQiHuSelfResponese(), ", table.tostring(response))
  489. -- if not self.roomInfo then
  490. -- logD("self.roomInfo no exist,容错处理!")
  491. -- return
  492. -- end
  493. -- self:dispatchEvent({name = "onQiHuSelfResponese",response = response});
  494. -- end
  495. -- function Room:onOtherQiHuTongZhi(status, response)
  496. -- logD("Room:onOtherQiHuTongZhi(), ", table.tostring(response))
  497. -- if not self.roomInfo then
  498. -- logD("self.roomInfo no exist,容错处理!")
  499. -- return
  500. -- end
  501. -- self:dispatchEvent({name = "onOtherQiHuTongZhi",response = response});
  502. -- end
  503. function Room:resetRound()
  504. self.roomInfo.quickStartInfo = nil
  505. --self.roomInfo.hosting = 0--重置托管
  506. end
  507. function Room:resetFastInfo()
  508. self.roomInfo.quickStartInfo = nil
  509. end
  510. --断线重连
  511. function Room:onGameReconnection(status,response)
  512. logD("===============重连成功,清空之前所有存在的队列==================")
  513. app.net:onMsgClear()
  514. app.net:onMsgPause()
  515. logD("Room:onGameReconnection(), response = ", table.tostring(response))
  516. self:initRoomInfo();
  517. -- 获取到的房间信息
  518. self.roomInfo.gameId = response.gameId
  519. self.roomInfo.nShowTableId = response.nShowTableId
  520. self.roomInfo.nMaxPlayCount = response.nMaxPlayCount
  521. self.roomInfo.nRoomOwnedUid = response.nRoomOwnedUid
  522. self.roomInfo.nTotalGameNum = response.nTotalGameNum
  523. self.roomInfo.nBaseChips = response.nBaseChips
  524. self.roomInfo.strGameInfo = response.strGameInfo
  525. self.roomInfo.nGameStartCount = response.nGameStartCount
  526. self.roomInfo.nStatus = response.nStatus
  527. self.roomInfo.nBankSeatId = response.nBankSeatId
  528. self.roomInfo.nMySeatId = response.nMySeatId
  529. self.roomInfo.bUserDisbandGame = response.bUserDisbandGame
  530. self.roomInfo.nDismissStateTime = response.nDismissStateTime
  531. self.roomInfo.leaveCards = response.leaveCards
  532. self.roomInfo.nLeaveCardNum = #self.roomInfo.leaveCards
  533. self.roomInfo.outCardUserId = response.outCardUserId
  534. self.roomInfo.outCardSeatId = response.outCardSeatId
  535. self.roomInfo.lastOpCard = response.lastOpCard
  536. self.roomInfo.operates = response.operates
  537. self.roomInfo.needOutCardId = response.needOutCardId
  538. self.roomInfo.lastOutCardId = response.lastOutCardId
  539. self.roomInfo.lastOutCard = response.lastOutCard
  540. self.roomInfo.stopFlag = response.stopFlag
  541. self.roomInfo.strResultInfo = response.strResultInfo
  542. self.roomInfo.resultInfos = response.resultInfos
  543. self.roomInfo.opsCntMapString = response.opsCntMapString
  544. self.roomInfo.scoreCntMap = json.decode(response.soreCntMapString)
  545. self.roomInfo.tableGroupCards = response.tableGroupCards
  546. -- 桌子上其他玩家的信息
  547. for k,v in pairs(response.playerInfos) do
  548. self:setMemberInfo(v)
  549. -- if not self.roomInfo.memberList[v.nUserId] then
  550. -- self.roomInfo.memberList[v.nUserId] = {}
  551. -- end
  552. -- self.roomInfo.memberList[v.nUserId].nUserId = v.nUserId
  553. -- self.roomInfo.memberList[v.nUserId].nSeatId = v.nSeatId
  554. -- self.roomInfo.memberList[v.nUserId].nPlayerFlag = v.nPlayerFlag
  555. -- self.roomInfo.memberList[v.nUserId].userInfo = v.userInfo
  556. -- self.roomInfo.memberList[v.nUserId].nTurnScore = v.nTurnScore
  557. -- self.roomInfo.memberList[v.nUserId].nTotalMoney = v.nTotalMoney
  558. -- self.roomInfo.memberList[v.nUserId].nTingStatus = v.nTingStatus
  559. -- self.roomInfo.memberList[v.nUserId].gruoupCards = v.gruoupCards
  560. -- self.roomInfo.memberList[v.nUserId].outCards = v.outCards
  561. -- self.roomInfo.memberList[v.nUserId].handCards = v.handCards
  562. -- self.roomInfo.memberList[v.nUserId].nOnlineStatus = v.nOnlineStatus
  563. -- self.roomInfo.memberList[v.nUserId].nDisbandStatus = v.nDisbandStatus
  564. self.dismissInfo[v.nUserId] = v.nDisbandStatus
  565. --这里只记录,暂时没用到。可能战绩回放的时候是需要用的
  566. -- local cardData = self:serverCardToMyCard(v.handCard)
  567. -- self.roomInfo.memberList[v.nUserId].cardList = {}
  568. -- self.roomInfo.memberList[v.nUserId].cardList = cardData
  569. end
  570. --结算信息
  571. for k,v in pairs(response.resultInfos) do
  572. --番数
  573. self.roomInfo.memberList[v.nUserId].fanshu=v.fanshu
  574. --玩家本局输赢情况 0不胡不输 1胡,2点炮或者输
  575. self.roomInfo.memberList[v.nUserId].result=v.result
  576. -- 胡牌牌类型-7对胡、平胡,0为输或者不胡不输
  577. self.roomInfo.memberList[v.nUserId].huType=v.huType
  578. end
  579. self:addExtendData(response)
  580. --[[local extInfo = json.decode(response.extJson or "")
  581. local uid = self:getMyUserId()
  582. if extInfo and type(extInfo) == 'table' and extInfo[tostring(uid)] then
  583. local myInfo = extInfo[tostring(uid)]
  584. --self.roomInfo.hosting = myInfo.hosted or 0--托管状态
  585. self.roomInfo.quickStartInfo = extInfo.faststart
  586. end--]]
  587. --更新自己的数据
  588. -- local myUserId = app.user.loginInfo.uid
  589. -- self.cards[myUserId] = self.roomInfo.memberList[myUserId].handCards
  590. print("self.cards[myUserId]:"..table.tostring(self.cards[myUserId]))
  591. self:updateGpsUserInfo(nil,false)
  592. -- 更新椅子号
  593. self:updateUserSeateShowId()
  594. local jsonInfo = json.decode(self.roomInfo.strGameInfo)
  595. -- 发送通知
  596. self:dispatchEvent({name = MJDefine.MJEvent.EnterRoomSuccess, gameId = app.gameId, gameType = jsonInfo.gamerule})
  597. end
  598. --更新额外数据 便于子游戏改写数据
  599. function Room:addExtendData()
  600. end
  601. function Room:setMemberInfo(v)
  602. if not self.roomInfo.memberList[v.nUserId] then
  603. self.roomInfo.memberList[v.nUserId] = {}
  604. end
  605. self.roomInfo.memberList[v.nUserId].nUserId = v.nUserId
  606. self.roomInfo.memberList[v.nUserId].nSeatId = v.nSeatId
  607. self.roomInfo.memberList[v.nUserId].nPlayerFlag = v.nPlayerFlag
  608. self.roomInfo.memberList[v.nUserId].nDisbandStatus = v.nDisbandStatus
  609. self.roomInfo.memberList[v.nUserId].nOnlineStatus = v.nOnlineStatus
  610. self.roomInfo.memberList[v.nUserId].userInfo = v.userInfo
  611. self.roomInfo.memberList[v.nUserId].nTurnScore = v.nTurnScore
  612. self.roomInfo.memberList[v.nUserId].nTotalMoney = v.nTotalMoney
  613. self.roomInfo.memberList[v.nUserId].nTingStatus = v.nTingStatus
  614. self.roomInfo.memberList[v.nUserId].gruoupCards = v.gruoupCards
  615. self.roomInfo.memberList[v.nUserId].handCards = v.handCards
  616. self.roomInfo.memberList[v.nUserId].outCards = v.outCards
  617. if self.roomInfo.tableGroupCards then
  618. for i,k in pairs(self.roomInfo.tableGroupCards) do
  619. if v.nUserId == k.nUserId then
  620. self.roomInfo.memberList[v.nUserId].gruoupCards = k.operates
  621. end
  622. end
  623. else
  624. self.roomInfo.memberList[v.nUserId].gruoupCards = v.gruoupCards
  625. end
  626. end
  627. -- 其他玩家是否掉线
  628. function Room:onOtherDroppedResponse(status, response)
  629. if not self.roomInfo then return end
  630. logD("User:onOtherDroppedResponse(), response = ", table.tostring(response))
  631. logD("30000000--runOtherDroppedResponse")
  632. local nUserId = response.nUserId
  633. local nOnlineStatus = response.nOnlineStatus
  634. if nOnlineStatus== MJDefine.PlayOnlineStatus.offline and self.roomInfo.memberList[nUserId] then
  635. self.roomInfo.memberList[nUserId].offlinetime = 0
  636. end
  637. self:dispatchEvent({name = MJDefine.MJEvent.OtherDroppedResponse , response = response});
  638. end
  639. --如果多家可以操作,先操作的会收到通知要等待其他人
  640. -- function Room:onOperationFirst(status,response)
  641. -- logD("-------------------- 如果多家可以操作,先操作的会收到通知要等待其他人 ------------------------")
  642. -- if not self.roomInfo then
  643. -- print("容错处理")
  644. -- return
  645. -- end
  646. -- self:dispatchEvent({name = "onOperationFirst",response = response})
  647. -- end
  648. --操作错误
  649. function Room:onOperationError(status)
  650. logD("-------------------- onOperationError ------------------------")
  651. if not self.roomInfo then
  652. print("容错处理")
  653. return
  654. end
  655. showTooltip("操作发生了错误...")
  656. --错误的时候如何处理
  657. self:dispatchEvent({name = "onOperationError"})
  658. end
  659. --操作成功
  660. --[[
  661. 说明:用户自己收到操作结果时, 要判断操作者他是否要出牌,若要出牌,则需提示出牌
  662. 若不用出牌,客户端无需处理, server会广播下家抓牌
  663. ]]
  664. function Room:onOperationCodeSuccess(status,response)
  665. logD("-------------------- 操作成功 ------------------------")
  666. if not self.roomInfo then
  667. print("容错处理")
  668. return
  669. end
  670. logD("Room:onOperationCodeSuccess(), response = ", table.tostring(response))
  671. self:dispatchEvent({name = MJDefine.MJEvent.OperationCodeSuccess ,response = response});
  672. end
  673. -- 服务器下发玩家的准备状态
  674. -- function Room:onUserReadyResponse(status, response)
  675. -- print("Room:onUserReadyResponse(), ", table.tostring(response))
  676. -- if not self.roomInfo then
  677. -- print("self.roomInfo no exist,容错处理!")
  678. -- return
  679. -- end
  680. -- local nUserId = response.nUserId
  681. -- local memberInfo = self.roomInfo.memberList[nUserId]
  682. -- --标记准备了
  683. -- if memberInfo then
  684. -- memberInfo.nPlayerFlag = 1
  685. -- end
  686. -- self:dispatchEvent({name = "onUserReadyResponse"});
  687. -- end
  688. -- 通知服务器玩家GPS数据发生变化
  689. -- function Room:onGpsChangeRequest()
  690. -- print("Room:onUserInfoChangeRequest()")
  691. -- local request = StringPacket:new()
  692. -- request.stringValue = app.user.userInfo or ""
  693. -- logD("Room:onGpsChangeRequest()", table.tostring(request))
  694. -- self:sendResponse{cmd = RoomCmd.GAME_COMMAND_CLIENT_CHANGE_USERINFO , sender = request};
  695. -- end
  696. -- -- 服务器下发玩家GPS数据发生变化
  697. -- function Room:onGpsChangeResponse(status, response)
  698. -- print("Room:onGpsChangeResponse()", table.tostring(response))
  699. -- --server收到0x8060协议后,广播当前桌子上所有用户
  700. -- ServerChangeUserInfo = defClass("ServerChangeUserInfo"
  701. -- --更新信息的用户uid
  702. -- , defVar("uid", VT_Int, -1)
  703. -- --用户信息
  704. -- , defVar("userInfo", VT_String, "")
  705. -- --保留字段,暂不使用
  706. -- , defVar("reserved", VT_String, "")
  707. -- )
  708. -- print("Room:onGpsChangeResponse()", table.tostring(response))
  709. -- local nUserId = response.uid
  710. -- local memberInfo = self.roomInfo.memberList[nUserId]
  711. -- if memberInfo then
  712. -- memberInfo.userInfo = response.userInfo
  713. -- end
  714. -- self:dispatchEvent({name = MJDefine.MJEvent.GpsChangeResponse , nUserId = nUserId});
  715. -- end
  716. -- 更新托管倒计时
  717. function Room:onUpdateDirectionTime( status, response )
  718. self:dispatchEvent({name = MJDefine.MJEvent.UpdateDirectionTime ,response = response})
  719. end
  720. -- 游戏快速开始,更新玩家座位号
  721. function Room:onFastStartSucc( status, response )
  722. self.roomInfo.nMaxPlayCount = #response.pList
  723. local gameInfo = json.decode(self.roomInfo.strGameInfo)
  724. gameInfo.playnum = self.roomInfo.nMaxPlayCount
  725. self.roomInfo.strGameInfo = json.encode(gameInfo)
  726. for _,v in pairs(response.pList) do
  727. self.roomInfo.memberList[v.nUserId].nSeatId = v.nSeatId
  728. end
  729. -- 更新椅子号
  730. self.seatShowList = {}
  731. self:updateUserSeateShowId()
  732. self:dispatchEvent({name = MJDefine.MJEvent.FastStartSucc ,response = response})
  733. end
  734. -- 快速开始操作广播 0x8201
  735. function Room:onBroadcastFastRequest( status, response )
  736. if not self.roomInfo then return end
  737. for _,v in pairs(response.pList) do
  738. self.roomInfo.memberList[v.nUserId].nStatus = v.nStatus
  739. end
  740. self.roomInfo.timeOut = response.timeOut
  741. self:dispatchEvent({name = MJDefine.MJEvent.BraodcastFastStart ,response = response})
  742. end
  743. -- 快速开始请求失败
  744. function Room:onUserRequestFastError( status, response )--快速开始请求错误提示错误
  745. local errTxt ={
  746. [1] = "人数不够",
  747. [2] = "其他人已请求",
  748. [3] = "房间人数已满",
  749. [4] = "非法操作"
  750. }
  751. local txt = errTxt[response.result]
  752. if txt then
  753. showTooltip(txt)
  754. end
  755. end
  756. -- 托管
  757. function Room:onHostingRequest( status, response )
  758. -- 是否托管
  759. if response.nUserId == self:getMyUserId() then
  760. self.roomInfo.hosting = response.status
  761. end
  762. self:dispatchEvent({name = MJDefine.MJEvent.HostingRequest, response = response});
  763. end
  764. -- 收到服务器下发PASS操作
  765. function Room:onUserPassRequest( status, response )
  766. self:dispatchEvent({name = MJDefine.MJEvent.USER_PASS ,response = response});
  767. end
  768. function Room:ctor(net)
  769. Room.super.ctor(self , net);
  770. -- GPS信息发生变化的时候主动给服务器发消息
  771. -- app:addEventListener( MJDefine.MJEvent.UpdateLoctionSuccessed , handler(self, self.onGpsChangeRequest))
  772. --发送
  773. -- 请求准备
  774. self:defMsgFunc{name = MJDefine.MJEvent.CallReadyRequest , cmd = RoomCmd.GAME_COMMAND_USER_READY};
  775. -- 离开房间
  776. self:defMsgFunc{name = MJDefine.MJEvent.CallLeaveRequest , cmd = RoomCmd.GAME_COMMAND_USER_LEAVE};
  777. -- 玩家请求解散房间,获取其他玩家回复解散房间
  778. self:defMsgFunc{name = MJDefine.MJEvent.DismissRoomRequest, cmd = RoomCmd.GAME_COMMAND_DISBAND_GAME, sender = MJMessage.DismissRequest};
  779. --GAME
  780. -- --发送操作码
  781. self:defMsgFunc{name = MJDefine.MJEvent.Operate , cmd = RoomCmd.GAME_COMMAND_SEND_CODE_RESPONSE, sender = MJMessage.OperateCard};
  782. -- --发送出牌
  783. self:defMsgFunc{name = MJDefine.MJEvent.OutCard,cmd = RoomCmd.GAME_COMMAND_OUT_CARD,sender = MJMessage.Card};
  784. -- --发送听牌
  785. self:defMsgFunc{name = MJDefine.MJEvent.Ting ,cmd = RoomCmd.GAME_COMMAND_TINGCARD} --,sender = MJMessage.RequestTingCard
  786. -- --发送弃胡
  787. -- self:defMsgFunc{name = "RequestQiHu",cmd = RoomCmd.GAME_COMMAND_QiHu,sender = SendQiHu};
  788. -- --接收
  789. -- -- 玩家进入桌子成功
  790. self:defPushMsg{cmd = RoomCmd.GAME_COMMAND_LOGIN_GAME_SUCCESS, reader = MJMessage.SitDownSuccessResponse, func = handler(self , self.onSitDownSuccessResponse)};
  791. -- -- 玩家进入桌子失败
  792. self:defPushMsg{cmd = RoomCmd.GAME_COMMAND_LOGIN_GAME_ERR, reader = MJMessage.SitDownFailedResponse, func = handler(self , self.onSitDownFailedResponse)};
  793. -- -- 玩家收到解散房间的请求
  794. self:defPushMsg{cmd = RoomCmd.GAME_COMMAND_BROADCAST_DISBAND_GAME, reader = MJMessage.DismissResponse, func = handler(self , self.onDismissResponse)};
  795. -- -- 收到玩家申请解散房间
  796. self:defPushMsg{cmd = RoomCmd.GAME_COMMAND_DISBAND_GAME, reader = MJMessage.DismissResult, func = handler(self , self.onUserDismissResultResponse)};
  797. -- -- 其他玩家退出房间
  798. self:defPushMsg{cmd = RoomCmd.GAME_COMMAND_BROADCAST_USER_LOGOUT, reader = MJMessage.OtherLogoutResponse, func = handler(self , self.onOtherLogoutResponse)};
  799. -- -- 收到服务器下发的玩家准备状态
  800. self:defPushMsg{cmd = RoomCmd.GAME_COMMAND_BROADCAST_USER_READY, reader = MJMessage.UserId, func = handler(self , self.onUserReadyResponse)};
  801. -- -- 其他玩家进入桌子
  802. self:defPushMsg{cmd = RoomCmd.GAME_COMMAND_BROADCAST_USER_LOGIN, reader = MJMessage.OtherSitDownResponse, func = handler(self , self.onOtherSitDownResponse)};
  803. -- -- 用户退出
  804. self:defPushMsg{cmd = RoomCmd.GAME_COMMAND_LOGOUT_GAME_SUCCESS, reader = MJMessage.UserExitResponse, func = handler(self , self.onUserExitResponse)};
  805. -- -- 游戏正式开始
  806. self:defPushMsg{cmd = RoomCmd.GAME_COMMAND_BROADCAST_GAME_START, reader = MJMessage.GameStartResponse, func = handler(self , self.onGameStartResponse)};
  807. -- --发牌
  808. self:defPushMsg{cmd = RoomCmd.GAME_COMMAND_SENDCARD_RESPONSE, reader = MJMessage.GameSendCardResponse,func = handler(self , self.onGameSendCardResponse)};
  809. -- --广播桌子上所有玩家庄家起手操作
  810. self:defPushMsg{cmd = RoomCmd.GAME_COMMAND_BAKER_OUTCARD_RESPONSE, reader = MJMessage.BankerOutCard,func = handler(self , self.onBankerOutCard)};
  811. -- --若玩家操作不对,如operateCode值不对等,通过协议0x810d通知客户端操作错误,此协议暂定无参数
  812. self:defPushMsg{cmd = RoomCmd.GAME_COMMAND_OPERATION_CODE_ERROR,func = handler(self,self.onOperationError)}
  813. -- --玩家操作成功, 则广播通知桌子上其他玩家操作结果,协议0x810b
  814. self:defPushMsg{cmd = RoomCmd.GAME_COMMAND_OPERATION_CODE_SUCCESS,reader = MJMessage.OperationCodeSuccess,func = handler(self,self.onOperationCodeSuccess)}
  815. -- --抢杠胡
  816. self:defPushMsg{cmd = RoomCmd.GAME_COMMAND_QIANG_GANG_HU,reader = MJMessage.QiangGangHu,func = handler(self,self.onQiangGangHu)}
  817. -- 弃牌
  818. self:defPushMsg{cmd = RoomCmd.GAME_COMMAND_QI_PAI,reader = MJMessage.QiPai,func = handler(self,self.onQiPai)}
  819. --出牌错误
  820. self:defPushMsg{cmd = RoomCmd.GAME_COMMAND_OUT_CARD_ERROR,reader = MJMessage.OutCardError,func = handler(self,self.onOutCardError)}
  821. --指示出牌
  822. self:defPushMsg{cmd = RoomCmd.GAME_COMMAND_TURN_OUT_CARD,func = handler(self,self.onTurnOutCard)} --reader = MJMessage.OutCardError,
  823. --出牌成功
  824. self:defPushMsg{cmd = RoomCmd.GAME_COMMAND_OUT_CARD_SUCCESS,reader = MJMessage.OutCardSuccess,func = handler(self,self.onOutCardSuccess)}
  825. --单局结算
  826. self:defPushMsg{cmd = RoomCmd.GAME_COMMAND_GAME_XIAO_JU, reader = MJMessage.GameXiaoJuResponse, func = handler(self , self.onGameXiaoJuResponse)};
  827. -- --总结算
  828. self:defPushMsg{cmd = RoomCmd.GAME_COMMAND_GAME_DA_JU, reader = MJMessage.GameDaJuResponse, func = handler(self , self.onGameDaJuResponse)};
  829. -- --听牌状态
  830. self:defPushMsg{cmd = RoomCmd.GAME_COMMAND_BROADCAST_TING, reader = MJMessage.TingCardStatus, func = handler(self , self.onTingCardStatus)};
  831. -- --听牌结果
  832. self:defPushMsg{cmd = RoomCmd.GAME_COMMAND_RESPONSE_TINGCARD, reader = MJMessage.TingCardResult, func = handler(self , self.onTingCardResult)};
  833. --推送听
  834. --self:defPushMsg{cmd = RoomCmd.GAME_PUSH_TING, reader = MJMessage.Tings, func = handler(self , self.pushTing)};
  835. --断线重连
  836. self:defPushMsg{cmd = RoomCmd.GAME_COMMAND_GAME_RECONNECTION,reader = MJMessage.GameReconnection,func = handler(self,self.onGameReconnection)}
  837. -- 其他玩家掉线
  838. self:defPushMsg{cmd = RoomCmd.GAME_COMMAND_BROADCAST_USER_DROPPED, reader = MJMessage.OtherDroppedResponse, func = handler(self , self.onOtherDroppedResponse)};
  839. --gps消息
  840. -- self:defPushMsg{cmd = RoomCmd.GAME_COMMAND_SERVER_CHANGE_USERINFO, reader = MJMessage.ServerChangeUserInfo, func = handler(self , self.onGpsChangeResponse)}
  841. -- 客户端发起快速请求
  842. self:defMsgFunc{name = MJDefine.MJEvent.RequestFastsStart, cmd = RoomCmd.GAME_COMMAND_FAST_START_GAME, sender = MJMessage.FastStartRequest}
  843. -- 快速开始请求返回(失败)
  844. self:defPushMsg{cmd = RoomCmd.GAME_COMMAND_FAST_START_ERROR, reader = MJMessage.FastStartRequestError, func = handler(self, self.onUserRequestFastError)}
  845. -- 快速开始广播请求 0x8201
  846. self:defPushMsg{cmd = RoomCmd.GAME_COMMAND_BROAD_FAST_START_GAME, reader = MJMessage.FastStartStatus, func = handler(self, self.onBroadcastFastRequest)}
  847. -- 快速开始成功 0x8203
  848. self:defPushMsg{cmd = RoomCmd.GAME_COMMAND_BROAD_QUICKLY_START, reader = MJMessage.UpdateSeatIds, func = handler(self, self.onFastStartSucc)}
  849. -- -- 首次听牌,提示托管
  850. -- self:defPushMsg{cmd = RoomCmd.GAME_COMMAND_TING_HOSTED, reader = MJMessage.FirstTingTips, func = handler(self, self.onFirstTingTips)}
  851. -- user pass
  852. self:defPushMsg{cmd = RoomCmd.GAME_COMMAND_USER_PASS, reader = MJMessage.UserPass, func = handler(self,self.onUserPassRequest)}
  853. end
  854. --辅助查找
  855. -- 通过玩家逻辑椅子号找到玩家ID
  856. function Room:getUserIdBySeatId(seatId)
  857. return self.seatList[seatId]
  858. end
  859. -- 通过玩家视图椅子号找到玩家ID
  860. function Room:getUserIdByViewId(seatShowId)
  861. return self.seatShowList[seatShowId]
  862. end
  863. -- 通过玩家ID获取玩家展示的座位号
  864. function Room:getViewIdByUserId(nUserId)
  865. return self.userList[nUserId];
  866. end
  867. -- 通过玩家逻辑椅子号找到视图椅子号
  868. function Room:getViewIdBySeatId(nSeatId)
  869. local userid = self:getUserIdBySeatId(nSeatId)
  870. return self:getViewIdByUserId(userid)
  871. end
  872. -- 通过玩家视图椅子号找到逻辑椅子号
  873. function Room:getSeatIdByViewId(nViewId)
  874. local userid = self:getUserIdByViewId(nViewId)
  875. for seatId,nUserId in pairs(self.seatList) do
  876. if userid == nUserId then
  877. return seatId
  878. end
  879. end
  880. end
  881. -- return table of userInfo, not string
  882. function Room:getUserInfo(nUserId)
  883. if self.roomInfo.memberList[nUserId] then
  884. return json.decode(self.roomInfo.memberList[nUserId].userInfo)
  885. else
  886. return nil
  887. end
  888. end
  889. function Room:getUserInfoByViewId(nViewId)
  890. local userid = self:getUserIdByViewId(nViewId)
  891. return self:getUserInfo(userid)
  892. end
  893. function Room:getMyUserId()
  894. if self:isInMemberList() then
  895. return app.user.loginInfo.uid--self:getUserIdByViewId(MJDefine.MyViewId)
  896. else
  897. for nUserId,v in pairs(self.roomInfo.memberList) do
  898. return nUserId
  899. end
  900. -- return self:getUserIdBySeatId(0)
  901. end
  902. end
  903. function Room:isInMemberList()
  904. if self.roomInfo then
  905. for nUserId,v in pairs (self.roomInfo.memberList) do
  906. if app.user.loginInfo.uid==nUserId then
  907. return true
  908. end
  909. end
  910. end
  911. return false
  912. end
  913. function Room:resetTings()
  914. self.roomInfo.tings={}
  915. end
  916. function Room:isTingStatus()
  917. local myUserId=app.user.loginInfo.uid
  918. local memberList=self.roomInfo.memberList
  919. if memberList[myUserId] then
  920. local nTingStatus=memberList[myUserId].nTingStatus
  921. if nTingStatus == MJDefine.MJTingStatus.Ting then
  922. return true
  923. -- self:setChaTingCardViewVisible(true)
  924. -- else
  925. -- self:setChaTingCardViewVisible(false)
  926. end
  927. end
  928. return false
  929. end
  930. function Room:getWinViewIds()
  931. local viewIds={}
  932. for k,v in pairs(self.roomInfo.memberList) do
  933. local viewId = self:getViewIdByUserId(v.nUserId)
  934. if v.result==MJDefine.MJGameResultType.Win then
  935. table.insert(viewIds,viewId)
  936. end
  937. end
  938. return viewIds
  939. end
  940. function Room:requestQuickStart(opType)
  941. --1: 表示发起解散 2:同意解散 3:不同意解散
  942. local request = MJMessage.FastStartRequest:new()
  943. request.operateType = opType
  944. self:sendResponse{cmd = RoomCmd.GAME_COMMAND_FAST_START_GAME , sender = request};
  945. end
  946. --更新gps用户数据
  947. --需要检测的ID 没有则检测所有人的距离
  948. --isOpenView 危险距离是否主动弹出提示
  949. function Room:updateGpsUserInfo(userId,isOpenView)
  950. if self.roomInfo and self.roomInfo.memberList then
  951. local gameStartCount = self.roomInfo.nGameStartCount or 0
  952. local isGameStart = gameStartCount>0
  953. --如果是游戏开始后收到消息则不处理
  954. local userInfoList = {}
  955. for nUserId, memberInfo in pairs(self.roomInfo.memberList) do
  956. local nSeatId = memberInfo.nSeatId
  957. local userInfo = memberInfo.userInfo
  958. if userInfo then
  959. local userInfo2 = json.decode(userInfo)
  960. if userInfo2 then
  961. userInfoList[nUserId] = {nSeatId = nSeatId, userInfo = userInfo}
  962. end
  963. end
  964. end
  965. if isGameStart or (not self:isAutoPopupGPS()) then
  966. isOpenView = false
  967. end
  968. self:dispatchEvent({
  969. name = GAME_EVENT.GPS_UPDATE_USER_INFO,
  970. userId=userId,
  971. userInfoList = userInfoList,
  972. isOpenView = isOpenView or false,
  973. isGameStart = isGameStart,
  974. -- maxPlayerNum = self.roomInfo.nMaxPlayCount,
  975. })
  976. end
  977. end
  978. function Room:isAutoPopupGPS()
  979. return true
  980. end
  981. function Room:checkGpsIsNew()
  982. if self:isAutoPopupGPS() then
  983. return Room.super.checkGpsIsNew(self)
  984. else
  985. app.room:requestGpsChange()
  986. return false
  987. end
  988. end
  989. return Room;