You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

141 lines
4.1 KiB

  1. local MJDefine = MJFramework.MJImport("mj.luaScript.MJDefine")
  2. local MJMessage = MJFramework.MJImport("mj.luaScript.Protocol.MJMessage")
  3. local MJSound = MJFramework.MJImport("mj.luaScript.MJSound")
  4. local Mahjong3DHandCard = MJFramework.MJFrameworkClassImprot("mj.luaScript.Common.3d.Mahjong3DHandCard")
  5. local HandCard3D = class("HandCard3D", Mahjong3DHandCard)
  6. function HandCard3D:ctor(...)
  7. HandCard3D.super.ctor(self, ...)
  8. end
  9. --- HandCard3D:onAfterCreateHandcards 创建手牌之后的处理
  10. function HandCard3D:onAfterCreateHandcards()
  11. HandCard3D.super.onAfterCreateHandcards(self)
  12. end
  13. function HandCard3D:onAfterCreateOpenHandcards()
  14. HandCard3D.super.onAfterCreateOpenHandcards(self)
  15. end
  16. -- 重写排序,让听用牌放在最左边
  17. function HandCard3D:sortHandCards()
  18. if self._viewId ~= MJDefine.MyViewId and (not self._isReplay) then--如果不是主视角且不是回放,不需要排序
  19. return
  20. end
  21. --[[table.sort(
  22. self._handCardNodes,
  23. function(c1, c2)
  24. if c1:getValue() == c2:getValue() and c1.tang and (not c2.tang) then
  25. return true
  26. else
  27. return c1:getValue() < c2:getValue()
  28. end
  29. end
  30. )--]]
  31. -- 拆分
  32. local temp = {}
  33. local tCard = {}
  34. local nCard = {}
  35. local qCard = {}
  36. for i, v in ipairs(self._handCardNodes) do
  37. if v:getIsTingYongCard() then
  38. table.insert(tCard, v)
  39. elseif v:getIsDingQueCard() or (v:getMJColorType() == self.queType) then
  40. table.insert(qCard, v)
  41. else
  42. table.insert(nCard, v)
  43. end
  44. end
  45. -- 按牌值顺序排序
  46. local function sortFun(c1, c2)
  47. return c1:getValue() < c2:getValue()
  48. end
  49. table.sort(tCard, sortFun)
  50. table.sort(nCard, sortFun)
  51. table.sort(qCard, sortFun)
  52. -- 添加到大表temp里面
  53. for i, v in ipairs(tCard) do
  54. table.insert(temp, v)
  55. end
  56. for i, v in ipairs(nCard) do
  57. table.insert(temp, v)
  58. end
  59. for i, v in ipairs(qCard) do
  60. table.insert(temp, v)
  61. end
  62. self._handCardNodes = temp
  63. end
  64. --发送出牌消息
  65. function HandCard3D:sendOutCard()
  66. logD("HandCard3D:sendOutCard")
  67. if not (self.isOutCard and self.touchMJ) then
  68. logD("HandCard3D:sendOutCard", "不是本家出牌")
  69. return
  70. end
  71. if self.touchMJ:getIsPaoPai() and (not self:getHandCardsIsAllPaoCard()) then
  72. self.touchMJ:restorePostion()
  73. self.touchMJ:setStatus(MJDefine.MJStatus.Normal)
  74. showTooltip("不能打出别人要胡的牌!");
  75. return
  76. end
  77. logD("HandCard3D:sendOutCard", "touchMJ", self.touchMJ:getValue())
  78. local request = MJMessage.Card:new()
  79. request.card = self.touchMJ:getValue()
  80. -- logE("LHQRecordView:setOutCardVisible"..table.tostring(request))
  81. self:sendMsg(
  82. app.room,
  83. MJDefine.MJEvent.OutCard,
  84. request,
  85. function(status, response)
  86. logE("HandCard3D:sendOutCard", "response = ", table.tostring(response))
  87. end
  88. )
  89. --音效
  90. local userInfo = app.room:getUserInfoByViewId(self._viewId)
  91. local sex = 1
  92. if userInfo then
  93. sex = userInfo.sex
  94. else
  95. logD("HandCard3D:sendOutCard", "userInfo为空,使用默认性别")
  96. end
  97. MJSound.PlayMJSound(sex, request.card)
  98. self:runOutCardAction(self.touchMJ:getValue())
  99. app.room:dispatchEvent({name = MJDefine.MJEvent.LOCAL_OUT_CARD, card = self.touchMJ:getValue()})
  100. app.room:dispatchEvent({name = MJDefine.MJEvent.OutCardFalg, value = self.touchMJ:getValue(), viewId = self._viewId})
  101. self:setOutCardEnable(false)
  102. --插牌
  103. if self.touchMJ == self._handCardNodes[#self._handCardNodes] then
  104. table.removeItem(self._handCardNodes, self.touchMJ)
  105. else
  106. table.removeItem(self._handCardNodes, self.touchMJ)
  107. self:resetHandCards()
  108. end
  109. self.touchMJ:removeFromParent()
  110. self.touchMJ = nil
  111. app.room:dispatchEvent({name = MJDefine.MJEvent.SelectCard})
  112. app.room:dispatchEvent({name = MJDefine.MJEvent.ShowTing})
  113. self:setTing(false)
  114. app.room:resetTings()
  115. app.room.roomInfo.lastOutViewId = MJDefine.MyViewId
  116. self:checkQueAndDisableOtherCard()
  117. self:checkBaoAndDisableCard()
  118. end
  119. return HandCard3D