Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.

95 righe
2.9 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 MJProtocol = MJFramework.MJFrameworkClassImprot("mj_xzdd.luaScript.Protocol.xzddProtocol")
  5. local Room = class("xzdd2rRoom", MJProtocol)
  6. function Room:ctor(net)
  7. Room.super.ctor(self, net);
  8. end
  9. -- 游戏正式开始
  10. function Room:onGameStartResponse(status, response)
  11. logD("-------------------- 新的一局开始了 ------------------------")
  12. if not self.roomInfo then
  13. logD("self.roomInfo no exist,容错处理!")
  14. return
  15. end
  16. logD("Room:onGameStartResponse(), ", table.tostring(response))
  17. self.roomInfo.nGameStartCount = response.nGameStartCount;
  18. self.roomInfo.nTotalGameNum = response.nTotalGameNum;
  19. self.roomInfo.nRoomOwnedUid = response.nRoomOwnedUid;
  20. self.roomInfo.nBankSeatId = response.nBankSeatId;
  21. self.roomInfo.shuffleList = response.shuffleList;
  22. self.roomInfo.shuffleNum = response.shuffleNum;
  23. local gameInfo = json.decode(self.roomInfo.strGameInfo)
  24. local cardtype = tonumber(gameInfo.cardtype) or 3
  25. local totalCardNum = (cardtype == 2) and 72 or 108
  26. self.roomInfo.nLeaveCardNum = totalCardNum - self:getPlayerCount() * 13 - 1
  27. -- 清空上一局的手牌信息
  28. self.cards = {}
  29. -- 清空上一局的换牌数据
  30. for i, v in pairs(self.roomInfo.memberList) do
  31. v.isSwapCard = 0
  32. end
  33. -- 发送广播通知,游戏开始了
  34. self:dispatchEvent({name = MJDefine.MJEvent.GameStartResponse});
  35. end
  36. --换三张错误
  37. function Room:onChangeCardError(status,response)
  38. logD("-------------------- 换三张/四张错误 ------------------------")
  39. if not self.roomInfo then
  40. print("容错处理")
  41. return
  42. end
  43. local gameInfo = json.decode(self.roomInfo.strGameInfo)
  44. local swapcard = tonumber(gameInfo.swapcard) or 4
  45. logD("Room:onChangeCardError(), ", table.tostring(response))
  46. local msg = {
  47. [1] = string.format("换牌数量小于%s", swapcard),
  48. [2] = "牌面值错误",
  49. }
  50. local defaultStr = string.format("换%s张未知错误", (swapcard == 4) and '四' or '三')
  51. local m = msg[response.errFlag] or defaultStr
  52. showTooltip(""..m)
  53. self:dispatchEvent({name = MJDefine.MJEvent.SwapCardErr ,response = response});
  54. end
  55. --请求换三张
  56. function Room:requestSwapCards( cards )
  57. local request = MJMessage.GetSwapCards:new()
  58. for _,v in ipairs(cards) do
  59. table.insert(request.bySwapCard.Datas, v)
  60. --table.insert(request.byOutCard.Datas, v)
  61. end
  62. -- 如果是3张,则强制加个0(保持4张值)
  63. if #cards == 3 then
  64. table.insert(request.bySwapCard.Datas, 0)
  65. end
  66. logD('Room:requestSwapCards,请求换牌 ', table.tostring(cards))
  67. self:sendResponse{cmd = RoomCmd.GAME_COMMAND_REQUEST_CHANGE_CARD , sender = request}
  68. end
  69. function Room:isCanTing()
  70. local gameInfo = json.decode(self.roomInfo.strGameInfo)
  71. local isCanTing = (tonumber(gameInfo.ting) or 0) > 0
  72. return isCanTing
  73. end
  74. return Room;