25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

110 lines
2.9 KiB

  1. local MJDefine = MJFramework.MJImport("mj.luaScript.MJDefine")
  2. local RoomCmd = MJFramework.MJImport("mj.luaScript.Protocol.MJCmd")
  3. local MJMessage = MJFramework.MJImport("mj.luaScript.Protocol.MJMessage")
  4. local Room = class("luzhouguiRoom_Coin" , require("mj_luzhougui.luaScript.Protocol.luzhouguiProtocol"))
  5. function Room:ctor(net)
  6. Room.super.ctor(self, net)
  7. -- 开局后后台推送的信息
  8. self:defPushMsg{cmd = 0x8301, reader = MJMessage.GameInfoChange, func = handler(self , self.onGameInfoChange)};
  9. end
  10. function Room:initRoomInfo()
  11. Room.super.initRoomInfo(self)
  12. --记录当前游戏serverLevel
  13. self.roomInfo.serverLevel = tonumber(app.user.serverLevel)
  14. end
  15. -- 开局后后台推送的信息
  16. function Room:onGameInfoChange(status, response)
  17. logD("Room:onGameInfoChange(), ", table.tostring(response))
  18. self:dispatchEvent({name = "onGameInfoChange", response = response});
  19. end
  20. -- 服务器下发玩家的准备状态
  21. function Room:onUserReadyResponse(status, response)
  22. Room.super.onUserReadyResponse(self, status, response)
  23. --游戏结束置为假
  24. if response.nUserId == self:getMyUserId() then
  25. self.roomInfo.isGameOver = false
  26. end
  27. end
  28. -- 自己退出房间
  29. function Room:onUserExitResponse(status, response)
  30. if self.roomInfo and self.roomInfo.isGameOver == true then
  31. return
  32. end
  33. if self.roomInfo and self.roomInfo.changeTable == true then
  34. self.roomInfo.changeTable = nil
  35. return
  36. end
  37. Room.super.onUserExitResponse(self, status, response)
  38. end
  39. -- 其他玩家退出房间
  40. function Room:onOtherLogoutResponse(status, response)
  41. if self.roomInfo and self.roomInfo.isGameOver == true then
  42. return
  43. end
  44. Room.super.onOtherLogoutResponse(self, status, response)
  45. end
  46. function Room:addExtendData(response)
  47. Room.super.addExtendData(self, response)
  48. self.roomInfo.extJson = response.extJson
  49. self.roomInfo.extJsonData = json.decode(response.extJson)
  50. for k,v in pairs(app.room.roomInfo.memberList) do
  51. local extJsonData = app.room.roomInfo.extJsonData["" .. k]
  52. if extJsonData then
  53. if tonumber(k) == self:getMyUserId() then
  54. self.roomInfo.hosting = extJsonData.hosted
  55. end
  56. v.hosted = extJsonData.hosted
  57. end
  58. end
  59. end
  60. function Room:onGameXiaoJuResponse(status, response)
  61. --刷新金币
  62. for k,v in pairs(response.allPlayerInfo) do --response.allPlayerInfo.Datas
  63. if v.nUserId == self:getMyUserId() then
  64. app.user.loginInfo.curJingbiNum = tonumber(v.nTotalMoney)
  65. break
  66. end
  67. end
  68. Room.super.onGameXiaoJuResponse(self, status, response)
  69. --局数置为0
  70. self.roomInfo.nGameStartCount = 0
  71. --游戏结束置为真
  72. self.roomInfo.isGameOver = true
  73. end
  74. function Room:getCoinByUserId(nUserId)
  75. --金币
  76. if self.roomInfo then
  77. local memberInfo = self.roomInfo.memberList[tonumber(nUserId)]
  78. if memberInfo then
  79. return memberInfo.nTotalMoney
  80. end
  81. end
  82. return 0
  83. end
  84. --更新gps用户数据
  85. function Room:updateGpsUserInfo(userId,isOpenView)
  86. --金币场不显示gps
  87. end
  88. return Room