25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.

2223 satır
73 KiB

  1. require("luaScript.Views.Room.RoomFunctions")
  2. local MJRoomToolView = MJFramework.MJImport("mj.luaScript.Views.Room.MJRoomToolView")
  3. local MJRoomPlayerView = MJFramework.MJImport("mj.luaScript.Views.Room.MJRoomPlayerView")
  4. local MJDefine = MJFramework.MJImport("mj.luaScript.MJDefine")
  5. local MJMessage = MJFramework.MJImport("mj.luaScript.Protocol.MJMessage")
  6. local MJFunction = MJFramework.MJImport("mj.luaScript.MJFunction")
  7. -- 布局相关
  8. local MJHandCardView = MJFramework.MJImport("mj.luaScript.Views.Game.MJHandCardView") -- 手牌
  9. local MJRoomXiaoJuView = MJFramework.MJImport("mj.luaScript.Views.Room.MJRoomXiaoJuView") -- 小结算
  10. local MJRoomDaJuView = MJFramework.MJImport("mj.luaScript.Views.Room.MJRoomDaJuView") -- 大结算
  11. local MJRoomDirection = MJFramework.MJImport("mj.luaScript.Views.Room.MJRoomDirection") -- 中间方位
  12. local MJAnimationCompnent = MJFramework.MJImport("mj.luaScript.Views.Compnent.MJAnimationCompnent") -- 动画?
  13. local MJBenJinView = MJFramework.MJImport("mj.luaScript.Views.Components.MJFanBenJinView") -- 本金动画
  14. local MJPiaoView = MJFramework.MJImport("mj.luaScript.Views.Components.MJPiaoView") -- 飘操作界面
  15. local MJDingQueView = MJFramework.MJImport("mj.luaScript.Views.Components.MJDingQueView") -- 定缺操作界面
  16. local MJDingQueAniView = MJFramework.MJImport("mj.luaScript.Views.Components.MJDingQueAniView") -- 定缺动画界面
  17. local MJSound = MJFramework.MJImport("mj.luaScript.MJSound")
  18. local MJRoomView = MJFramework.MJFrameworkClassImprot("mj.luaScript.Views.Room.MJRoomView")
  19. local yibinmajiangRoomView = class("yibinmajiangRoomView", MJRoomView)
  20. local zhongNiaoTime = 1.33
  21. local HU_EFFECT_TAG = 100
  22. function yibinmajiangRoomView:ctor()
  23. yibinmajiangRoomView.super.ctor(self)
  24. self.operates = {}
  25. self._isReplay = false -- 是否处于回放
  26. MJDefine.MJConfig = MJDefine.loadMJConfig(self.desktopType)
  27. end
  28. function yibinmajiangRoomView:onEnter()
  29. yibinmajiangRoomView.super.onEnter(self)
  30. self.ZOrder = {}
  31. self:setCheckDefault()
  32. self:doSound()
  33. end
  34. function yibinmajiangRoomView:onExit()
  35. yibinmajiangRoomView.super.onExit(self)
  36. self:cleanCache()
  37. end
  38. -- 加载UI
  39. function yibinmajiangRoomView:loadUi()
  40. local ui = loadUI("mj_yibinmajiang/res/ui_fangjian/mj_yibinmajiang_roomView.ui")
  41. self.ui = ui
  42. self:addChild(ui)
  43. end
  44. -- 设置默认值
  45. function yibinmajiangRoomView:setCheckDefault()
  46. MJDefine.isAutomatic = true
  47. end
  48. -- 播放声音(1 普通话 2 方言)
  49. function yibinmajiangRoomView:doSound()
  50. local bgmType = tonumber(loadUserInfo("yibinmajiang_bgm")) or 1
  51. MJSound.PlayGameBGM(bgmType)
  52. local cacheLan = "mj_language"..(MJDefine.GameID or app.gameId)
  53. local defaultValue = tonumber(loadUserInfo(cacheLan)) or 2
  54. -- saveUserInfo("mj_language", defaultValue)
  55. MJSound.setSoundType(defaultValue)
  56. end
  57. -- 添加节点至指定层
  58. -- @param layerName 指定层级的名称,background(背景层)、game(游戏层)、anim(动画特效层)、popup(弹框层)、system(系统弹框层)
  59. -- @param node 要添加的节点
  60. -- @param zorder 指定的zorder
  61. function yibinmajiangRoomView:addToLayer(layerName, node, zorder)
  62. if layerName == "background" then
  63. layerName = "Layout_Background"
  64. elseif layerName == "game" then
  65. layerName = "Layout_Game"
  66. elseif layerName == "anim" then
  67. layerName = "Layout_Anim"
  68. elseif layerName == "popup" then
  69. layerName = "Layout_PopUp"
  70. elseif layerName == "system" then
  71. layerName = "Layout_System"
  72. end
  73. local layer = self.ui.Items[layerName]
  74. if not layer then
  75. self:addChild(node)
  76. return
  77. end
  78. self.ZOrder = self.ZOrder or {}
  79. self.ZOrder[layerName] = self.ZOrder[layerName] or 0
  80. self.ZOrder[layerName] = zorder or (self.ZOrder[layerName] + 1)
  81. node:setLocalZOrder(self.ZOrder[layerName])
  82. layer:addChild(node)
  83. end
  84. -- 清除缓存
  85. function yibinmajiangRoomView:cleanCache()
  86. local preload = package.loaded
  87. for k, v in pairs(package.loaded or {}) do
  88. local res1 = string.find( k, "mj.luaScript") or 0
  89. local res2 = string.find( k, "mj_yibinmajiang.luaScript") or 0
  90. if res1 > 0 or res2 > 0 then
  91. package.loaded[k] = nil
  92. end
  93. end
  94. end
  95. -- 初始化试图
  96. function yibinmajiangRoomView:initView()
  97. --暂时隐藏牌数
  98. self.ui.Items.ImageView_CardNum:setVisible(false)
  99. -- 初始化玩家层
  100. self:initPlayerView();
  101. --加载工具层
  102. self:initToolView()
  103. -- 初始化方向
  104. self:initDirectionView()
  105. -- 初始化听牌组件
  106. self:initTingCardView()
  107. -- 初始化听牌按钮,动态创建的
  108. self:initTingBtnView()
  109. --定时器
  110. self.ui.Items.Text_Time:setText(MJFunction.getTimeString())
  111. if not self.Time then
  112. self.Time = cc.Director:getInstance():getScheduler():scheduleScriptFunc(function()
  113. self.ui.Items.Text_Time:setText(MJFunction.getTimeString())
  114. end,1.0,false)
  115. end
  116. self.ui.Items.Layout_Ting_Tip_Card_Panel:setVisible(false)
  117. end
  118. -- 初始化玩家playerView
  119. function yibinmajiangRoomView:initPlayerView()
  120. if not self.playerView then
  121. self.playerView = MJRoomPlayerView:new()
  122. self:addToLayer("game", self.playerView, 6);
  123. end
  124. end
  125. -- 初始化手牌playerhandcard
  126. function yibinmajiangRoomView:initHandCardNodes()
  127. local maxPlayCount = app.room.roomInfo:getMaxPlayerCount();
  128. if MJDefine.MJRoomPlayerSitConfig[maxPlayCount] then
  129. for k,v in pairs(MJDefine.MJRoomPlayerSitConfig[maxPlayCount]) do
  130. if self.playerHandCards[v] then
  131. self.playerHandCards[v]:removeFromParent();
  132. end
  133. self.playerHandCards[v] = MJHandCardView:new(v, self.desktopType);
  134. self:addToLayer("game", self.playerHandCards[v], v + 1);
  135. end
  136. end
  137. end
  138. -- 初始化工具栏toolview
  139. function yibinmajiangRoomView:initToolView()
  140. if not self.toolView then
  141. self.toolView = MJRoomToolView:new(self.desktopType)
  142. self:addToLayer("game", self.toolView, 7);
  143. end
  144. end
  145. -- 初始化中间方向指示器direcionView
  146. function yibinmajiangRoomView:initDirectionView()
  147. if not self.direcionView then
  148. self.direcionView = MJRoomDirection:new(self.desktopType)
  149. self:addToLayer("background", self.direcionView);
  150. self.direcionView:setVisible(false)
  151. end
  152. end
  153. -- 初始化听牌组件_tingCardView
  154. function yibinmajiangRoomView:initTingCardView()
  155. if not self._tingCardView then
  156. self._tingCardView = require("mj_yibinmajiang.luaScript.Views.Components.yibinmajiangTingCardView"):new();
  157. self:addToLayer("game", self._tingCardView, 6);
  158. self._tingCardView:setData(nil);
  159. self:setTingCardVisible(false);
  160. end
  161. end
  162. -- 初始化听牌按钮
  163. function yibinmajiangRoomView:initTingBtnView()
  164. local yibinmajiangTingBtnView = import("mj_yibinmajiang.luaScript.Views.Components.yibinmajiangTingBtnView");
  165. local btnTing = yibinmajiangTingBtnView:new();
  166. btnTing:setCallback(handler(self, self.onBtnTingInfoClicked));
  167. btnTing:setPosition(cc.p(230, 158));
  168. self.btnTing = btnTing;
  169. self:addToLayer("game", self.btnTing, 8)
  170. end
  171. -- 听按钮点击事件
  172. function yibinmajiangRoomView:onBtnTingInfoClicked( )
  173. playBtnEffect()
  174. if self._tingCardView:isVisible() then
  175. self:setTingCardVisible(false);
  176. else
  177. self:setTingCardVisible(true);
  178. end
  179. end
  180. -- 更换背景
  181. function yibinmajiangRoomView:changeGameBg()
  182. if app.systemSetting.info.viewType == MJDefine.DesktopType.TwoD then --更新2D麻将类型 金色还是绿色
  183. local value = loadUserInfo("mj_desktop_2d_mjType") --or MJDefine.DesktopType.TwoD
  184. if value=="" or not value then
  185. value = MJDefine.DesktopType.TwoD
  186. saveUserInfo("mj_desktop_2d_mjType", value)
  187. end
  188. self.desktopType = value
  189. else
  190. self.desktopType = app.systemSetting.info.viewType
  191. end
  192. self:loadTextureCache()
  193. local defaultValue = tonumber(loadUserInfo("yibinmajiang_desktop_background")) or 2
  194. local bgData = MJDefine.CHANGE_GAME_BG[defaultValue]
  195. --更换2D桌面
  196. if self.desktopType==MJDefine.DesktopType.TwoD or self.desktopType==MJDefine.DesktopType.TwoDGold then
  197. self.ui.Items.ImageView_bg:loadTexture(bgData['2d'])
  198. else
  199. self.ui.Items.ImageView_bg:loadTexture(bgData['3d'])
  200. end
  201. --记录当前的桌布类型(2d/3d)
  202. self.curDeskType = self.desktopType
  203. end
  204. -- 一键截屏
  205. function yibinmajiangRoomView:onClickButtonShot( sender )
  206. playBtnEffect()
  207. showScreenShot()
  208. end
  209. -- 隐藏俱乐部
  210. function yibinmajiangRoomView:hideClub()
  211. -- self.ui.Items.Button_Club:setVisible(false)
  212. if self.clubView and not tolua.isnull(self.clubView) then
  213. self.clubView:removeFromParent()
  214. self.clubView = nil
  215. end
  216. end
  217. -- 默认状态
  218. function yibinmajiangRoomView:defaultState()
  219. --队列初始化
  220. self.callbackQueue = {}
  221. self.callbackRunning = false
  222. self.playerView:setOffLineVisible(false)
  223. self.playerView:setPlayerVisible(false)
  224. if self.waitOperates and #self.waitOperates>0 then
  225. for k,v in pairs(self.waitOperates) do
  226. v:removeFromParent()
  227. end
  228. end
  229. self.waitOperates = {}
  230. self:resetGame()
  231. end
  232. -- 加载缓存
  233. function yibinmajiangRoomView:loadTextureCache()
  234. yibinmajiangRoomView.super.loadTextureCache(self)
  235. loadSpriteFrameFile("mj_yibinmajiang/res/zy_fangjian/anim/yibinmajiang_effect_guangxiao.plist")
  236. loadSpriteFrameFile("mj_yibinmajiang/res/zy_fangjian/anim/yibinmajiang_effect_guafeng.plist")
  237. loadSpriteFrameFile("mj_yibinmajiang/res/zy_fangjian/anim/yibinmajiang_effect_xiayu.plist")
  238. end
  239. -- 初始化游戏按钮
  240. function yibinmajiangRoomView:initGameButton()
  241. --点击空白
  242. self.ui.Items.Layout_Touch:registerClick(nil,function()
  243. -- 隐藏个人信息
  244. self.playerView:removePlayerInfoView()
  245. self.toolView:setMenuVisible(false)
  246. if self.playerHandCards[MJDefine.MyViewId] then
  247. self.playerHandCards[MJDefine.MyViewId]:hideOperateItem()
  248. end
  249. self.toolView:hideRule()
  250. self:setTingCardVisible(false)
  251. end)
  252. --隐藏听牌模板
  253. self.ui.Items.Item_Ting:setVisible(false)
  254. self:setButtonTingInfoVisible(false)
  255. end
  256. -- 中间转盘停止
  257. function yibinmajiangRoomView:stopDirection()
  258. self.direcionView:stopAllActions()
  259. if self.direcionView.ui then
  260. self.direcionView.ui.Items.ImageView_Dir_Down:setVisible(false)
  261. self.direcionView.ui.Items.ImageView_Dir_Up:setVisible(false)
  262. self.direcionView.ui.Items.ImageView_Dir_Left:setVisible(false)
  263. self.direcionView.ui.Items.ImageView_Dir_Right:setVisible(false)
  264. self.direcionView.ui.Items.Text_Time:setString(string.format("%02d",0))
  265. end
  266. end
  267. -- 获得组合牌数据
  268. function yibinmajiangRoomView:getChangeGruopDatas(g)
  269. local opType = g.opType
  270. local showType = MJDefine.MJOperateToGroupType[g.opType]
  271. local opCard = g.opCard
  272. local cardNum = g.cardNum
  273. local fromViewId = nil
  274. local targetSeatId = g.targetSeatId--操作位置座位号
  275. local fromUserId = g.opUserId or g.fromUserId --触发操作玩家
  276. local fromViewId1 = app.room:getViewIdByUserId(fromUserId)
  277. local useRedNum = g.useRedNum
  278. local lziCard = g.lziCard
  279. if fromUserId > 0 and targetSeatId then
  280. fromViewId = app.room:transPos(targetSeatId, app.room:getSeatIdByUserId(fromUserId))
  281. --判断是否是对面玩家,对面玩家的话要做一次翻转
  282. local opViewId = app.room:getViewIdBySeatId(targetSeatId)
  283. if opViewId == 2 then --对面
  284. if fromViewId == 1 then
  285. fromViewId = 3
  286. elseif fromViewId == 3 then
  287. fromViewId = 1
  288. end
  289. end
  290. --三人玩只有上下家
  291. if app.room:getMaxPlayerCount() == 3 and fromViewId == 2 then fromViewId = 3 end
  292. if app.room:getMaxPlayerCount() == 2 and fromViewId ~= 0 then
  293. fromViewId = showType == MJDefine.MJGroupType.Peng and 2 or 4;
  294. end
  295. end
  296. --组合一下牌
  297. local group={
  298. opType = opType,
  299. showType = showType,
  300. values = {},
  301. opCard = opCard,
  302. cardNum = cardNum,
  303. fromViewId = fromViewId,
  304. fromViewId1 = fromViewId1,--真正的来源viewID
  305. }
  306. if MJDefine.MJGroupType.Chi==showType then
  307. elseif MJDefine.MJGroupType.Peng==showType then
  308. group.values={opCard,opCard,opCard}
  309. elseif MJDefine.MJGroupType.Fei==showType then
  310. for i = 1, 3 do
  311. if i <= useRedNum then
  312. table.insert(group.values, lziCard)
  313. else
  314. table.insert(group.values, opCard)
  315. end
  316. end
  317. elseif MJDefine.MJGroupType.Ti==showType then
  318. group.values={opCard,opCard,opCard}
  319. else
  320. group.values={opCard,opCard,opCard,opCard}
  321. end
  322. return group
  323. end
  324. -- 设置听牌按钮状态
  325. function yibinmajiangRoomView:setButtonTingInfoVisible (isVisible)
  326. if self.btnTing then
  327. self.btnTing:setVisible(isVisible);
  328. end
  329. end
  330. -- 设置听牌界面是否可见
  331. function yibinmajiangRoomView:setTingCardVisible (isVisible)
  332. if not self._tingCardView then
  333. return
  334. end
  335. self._tingCardView:setVisible(isVisible);
  336. end
  337. -- 设置听箭头
  338. function yibinmajiangRoomView:pushTing()
  339. local function runPushTing(onEnd)
  340. local myUserId = app.room:getMyUserId();
  341. local player = app.room.roomInfo.memberList[myUserId]
  342. local huCards = player.huCards;
  343. if self.playerHandCards[MJDefine.MyViewId] then
  344. if not (table.nums(huCards) > 0) then
  345. -- 已经胡牌,不显示听牌箭头
  346. self.playerHandCards[MJDefine.MyViewId]:pushTing()
  347. end
  348. end
  349. if onEnd then
  350. onEnd()
  351. end
  352. end
  353. self:addCallBack(runPushTing);
  354. end
  355. -- 显示操作分
  356. function yibinmajiangRoomView:showOperateScore( optScore )
  357. if not optScore then
  358. return ;
  359. end
  360. for k, v in ipairs(optScore or {}) do
  361. v.viewId = app.room:getViewIdByUserId(v.uid);
  362. end
  363. self._scoreAnim = MJFramework.MJImport("mj_yibinmajiang.luaScript.Views.Animation.yibinmajiangScoreAnimation"):new();
  364. self._scoreAnim:play(optScore, function ()
  365. self.playerView:refreshPlayerScore(optScore)
  366. end);
  367. self:addToLayer("anim", self._scoreAnim);
  368. end
  369. -- 胡牌动画
  370. function yibinmajiangRoomView:playHuAni(response)
  371. -- 不需要播放胡牌顺序
  372. -- 需要可以从自贡麻将同步
  373. end
  374. -- 更新准备状态
  375. function yibinmajiangRoomView:updateReady()
  376. local roomInfo = app.room.roomInfo;
  377. local nUserId = app.room:getMyUserId()--app.user.loginInfo.uid
  378. local gameStartCount = roomInfo:getGameStartCount();
  379. if gameStartCount > 0 then
  380. self.toolView.ui.Items.Button_Leave:setEnabled(false)
  381. self:setBtnSitDownVisible(false)
  382. else
  383. self.toolView.ui.Items.Button_Leave:setEnabled(true)
  384. end
  385. if gameStartCount == 0 and roomInfo:getRoomOwnedUid() ~= nUserId then
  386. self.toolView.ui.Items.Button_Dismiss:setEnabled(false)
  387. else
  388. self.toolView.ui.Items.Button_Dismiss:setEnabled(true)
  389. end
  390. end
  391. -- 重置游戏
  392. function yibinmajiangRoomView:resetGame()
  393. yibinmajiangRoomView.super.resetGame(self)
  394. app.room.roomInfo:setLastOutViewId(nil);
  395. self.ui.Items.Layout_Effect:removeAllChildren()
  396. self.ui.Items.Layout_Effect_piao:removeAllChildren()
  397. -- self.playerView:clearBao()
  398. self.playerView:clearAllPiao()
  399. self.playerView:clearDingQue()
  400. self.playerView:clearHu()
  401. if self._benjinView then
  402. self._benjinView:removeFromParent()
  403. self._benjinView = nil
  404. end
  405. self.isTing = false;
  406. if self._tingCardView then
  407. self:setTingCardVisible(false);
  408. end
  409. end
  410. -- 显示漂
  411. function yibinmajiangRoomView:showPiao()
  412. self:stopDirection()
  413. local roomInfo = app.room.roomInfo
  414. local gameInfo = roomInfo:getGameRule()
  415. if not gameInfo.piaomode or tonumber(gameInfo.piaomode)==0 then return end
  416. if not self._piaoView then
  417. self._piaoView = MJPiaoView:new()
  418. self:addToLayer("game", self._piaoView)
  419. end
  420. self._piaoView:setVisible(true)
  421. end
  422. -- 显示定缺
  423. function yibinmajiangRoomView:showDingQue(response)
  424. local roomInfo = app.room.roomInfo
  425. local gameInfo = roomInfo:getGameRule()
  426. local isDingqueRule = (getNumBand(gameInfo.specialrule, 0x01) or 0) > 0
  427. if not isDingqueRule then
  428. return
  429. end
  430. if not self._dingqueView then
  431. self._dingqueView = MJDingQueView:new()
  432. self:addToLayer("game", self._dingqueView)
  433. end
  434. local data = response and response.response or {}
  435. local nice_choose = data.nice_choose
  436. self._dingqueView:showDingQueOpreate(nice_choose)
  437. end
  438. -- 显示定缺结果
  439. function yibinmajiangRoomView:showDingQueResult(response)
  440. if not self._dingqueAniView then
  441. self._dingqueAniView = MJDingQueAniView:new()
  442. self:addToLayer("anim", self._dingqueAniView)
  443. end
  444. -- local data = response.response
  445. local data = app.room.roomInfo:getDingQueInfo()
  446. for i, v in pairs(data) do
  447. local viewId = app.room:getViewIdByUserId(i)
  448. local result = v
  449. local posTable = {}
  450. local function endCallback()
  451. self.playerView:showDingQue(viewId, result)
  452. end
  453. posTable = self.playerView:getDingQuePos()[viewId]
  454. self.playerView:clearDingQue(viewId)
  455. self._dingqueAniView:showDingQueResultAniOneByOne(viewId, result, posTable, endCallback)
  456. if viewId == MJDefine.MyViewId then
  457. if self:checkMyCardHaveDingQue() then
  458. if self.playerHandCards and self.playerHandCards[MJDefine.MyViewId] then
  459. for i, v in pairs(self.playerHandCards[MJDefine.MyViewId]:getHandCardNodes()) do
  460. local colorType = v:getMJColorType()
  461. if colorType ~= result and not v:getIsTingYongCard() then
  462. v:setStatus(MJDefine.MJStatus.Disable)
  463. else
  464. v:setIsDingQueCard(true)
  465. end
  466. end
  467. end
  468. -- 刷新一下手牌排序
  469. self.playerHandCards[MJDefine.MyViewId]:resetHandCards()
  470. self.playerHandCards[MJDefine.MyViewId]:cleanTouchMJ()
  471. else
  472. for i, v in pairs(self.playerHandCards[MJDefine.MyViewId]:getHandCardNodes()) do
  473. if not v:getIsTingYongCard() then
  474. v:setStatus(MJDefine.MJStatus.Normal)
  475. end
  476. end
  477. end
  478. end
  479. end
  480. end
  481. -- 开始本金 isAni是否要播本金动画
  482. function yibinmajiangRoomView:showBenJin(response, isAni, endFun)
  483. logD("yibinmajiangRoomView:showBenJin")
  484. local data = response.response
  485. local isAni = (false ~= isAni) and true or false
  486. MJSound.PlayBenJinSound()
  487. local benjinCard = app.room.roomInfo:getBenJinCard()
  488. if self._benjinView then
  489. self._benjinView:removeFromParent()
  490. self._benjinView = nil
  491. end
  492. local showCards = data.benjinCard
  493. local tingCardTable = data.tingCard
  494. local endCallback = function()
  495. -- 结束回调
  496. -- 设置听用牌
  497. if self.playerHandCards and self.playerHandCards[MJDefine.MyViewId] then
  498. for _, j in ipairs(tingCardTable) do
  499. for i, v in pairs(self.playerHandCards[MJDefine.MyViewId]:getHandCardNodes()) do
  500. local value = v:getValue()
  501. if j.card == value then
  502. v:setIsTingYongCard(true)
  503. end
  504. end
  505. end
  506. -- 刷新一下手牌排序
  507. self.playerHandCards[MJDefine.MyViewId]:resetHandCards()
  508. self.playerHandCards[MJDefine.MyViewId]:cleanTouchMJ()
  509. end
  510. -- 如果是回放中,也要把其他玩家手牌给设置为听用牌
  511. if self._isReplay then
  512. for _, viewId in pairs(MJDefine.PlayerViewType) do
  513. if viewId ~= MJDefine.MyViewId then -- 如果不是自己,这里只做其他的人听用牌
  514. if self.playerHandCards and self.playerHandCards[viewId] then
  515. for _, j in ipairs(tingCardTable) do
  516. for i, v in pairs(self.playerHandCards[viewId]:getHandCardNodes()) do
  517. local value = v:getValue()
  518. if j.card == value then
  519. v:setIsTingYongCard(true)
  520. end
  521. end
  522. end
  523. -- 刷新一下手牌排序
  524. self.playerHandCards[viewId]:resetHandCards()
  525. end
  526. end
  527. end
  528. end
  529. -- 如果有另传结束,那么也使用
  530. if endFun then
  531. endFun()
  532. end
  533. end
  534. self._benjinView = MJBenJinView:new(self.desktopType)
  535. self._benjinView:setEndCallback(endCallback)
  536. self._benjinView:setIsShowAni(isAni)
  537. self._benjinView:setCards(showCards, tingCardTable)
  538. self:addToLayer("game", self._benjinView, 6) -- 由于tool在game层上,需要跟这个做zorder上区别,所以放置在了game层上
  539. end
  540. -- 显示查听的牌,弃用
  541. function yibinmajiangRoomView:setChaTingCardViewVisible(bVisible,tingCards)
  542. end
  543. -- 显示听牌框,弃用
  544. function yibinmajiangRoomView:setTingCardViewVisible(bVisible,tingCards)
  545. end
  546. -- 检查手牌中是否有定缺
  547. function yibinmajiangRoomView:checkMyCardHaveDingQue()
  548. -- 检查规则
  549. local roomInfo = app.room.roomInfo
  550. local gameInfo = roomInfo:getGameRule()
  551. local isDingqueRule = (getNumBand(gameInfo.specialrule, 0x01) or 0) > 0
  552. if not isDingqueRule then
  553. return false
  554. end
  555. -- 检查定缺信息
  556. local myUserId = app.room:getMyUserId()
  557. local que = app.room.roomInfo:getDingQueInfo(myUserId)
  558. if not que then
  559. return false
  560. end
  561. -- 如果是回放,那么也不显示定缺
  562. if self._isReplay then
  563. return false
  564. end
  565. -- 检查手牌
  566. if self.playerHandCards and self.playerHandCards[MJDefine.MyViewId] then
  567. for i, v in pairs(self.playerHandCards[MJDefine.MyViewId]:getHandCardNodes()) do
  568. local colorType = v:getMJColorType()
  569. if colorType == que and not v:getIsTingYongCard() then
  570. return true
  571. end
  572. end
  573. end
  574. return false
  575. end
  576. -- 重写倒牌,倒完牌后,如果有胡牌,则还要显示胡牌
  577. function yibinmajiangRoomView:showOpenCard()
  578. local roomInfo = app.room.roomInfo
  579. for k,v in pairs(roomInfo.memberList) do
  580. local viewId = app.room:getViewIdByUserId(v.nUserId)
  581. if viewId and self.playerHandCards[viewId] then
  582. if viewId==MJDefine.MyViewId then
  583. -- 我自己则屏蔽触摸事件
  584. self.playerHandCards[viewId]:removeTouchEvent()
  585. else
  586. --倒牌
  587. self.playerHandCards[viewId]:removeAllHandCards()
  588. self.playerHandCards[viewId]:createOpenHandCards(v.handCards)
  589. if next(v.huCards) and next(v.huCards[1]) and v.huCards[1].huCard and v.huCards[1].huCard > 0 then
  590. local huCardValue = v.huCards[1].huCard
  591. self.playerHandCards[viewId]:createHandCards(huCardValue, true)
  592. end
  593. end
  594. end
  595. end
  596. end
  597. -------------------------------------------------------------------------------------------------
  598. -- 游戏消息 --------------------------------------------------------------------------------------
  599. -------------------------------------------------------------------------------------------------
  600. -- 开始发牌
  601. function yibinmajiangRoomView:onGameSendCardResponse()
  602. logD("yibinmajiangRoomView:onGameSendCardResponse", "开始发牌")
  603. --发牌的时候清除桌面上的飘
  604. self.ui.Items.Layout_Effect_piao:removeAllChildren()
  605. local function runGameSendCardResponse(onEnd)
  606. log("2000000000-yibinmajiangRoomView - runGameSendCardResponse()" )
  607. local myUserId = app.room:getMyUserId()
  608. for k,v in pairs(app.room.roomInfo.memberList) do
  609. local viewId = app.room:getViewIdByUserId(v.nUserId)
  610. if self.playerHandCards[viewId] then
  611. self.playerHandCards[viewId]:createHandCards(v.handCards)
  612. self.playerHandCards[viewId]:resetHandCards()
  613. end
  614. end
  615. -- MJSound.PlayStartGame()
  616. MJAnimationCompnent.CreateStartSendCards(self.playerHandCards, function()
  617. if onEnd then
  618. onEnd();
  619. end
  620. end)
  621. local count = table.nums(app.room.roomInfo.memberList);
  622. local totalCards = MJDefine.totalCard
  623. self.direcionView:updateCardNums(totalCards - count * 13);
  624. end
  625. log("2000000000-yibinmajiangRoomView - addCallBack(runGameSendCardResponse)" )
  626. self:addCallBack(runGameSendCardResponse);
  627. end
  628. -- 有玩家准备
  629. function yibinmajiangRoomView:onUserReadyResponse(response)
  630. logD("yibinmajiangRoomView:onUserReadyResponse", "有玩家准备了")
  631. yibinmajiangRoomView.super.onUserReadyResponse(self,response)
  632. local roomInfo = app.room.roomInfo;
  633. local myUserId = app.room:getMyUserId()
  634. if response and response.nUserId==myUserId then
  635. self.playerView:clearAllPiao()
  636. local totalCards = MJDefine.totalCard
  637. self.direcionView:updateCardNums(totalCards);
  638. end
  639. self:setButtonTingInfoVisible(false);
  640. end
  641. -- 广播桌子上所有玩家庄家起手操作,这里其实是发牌
  642. function yibinmajiangRoomView:onBankerOutCard(data)
  643. local function runOnBankerOutCard(onEnd)
  644. logD("yibinmajiangRoomView:onBankerOutCard", "玩家抓牌", table.tostring(data.response))
  645. local nUserId = data.response.nUserId
  646. local viewId = app.room:getViewIdByUserId(nUserId)
  647. local card= data.response.card
  648. local operates=data.response.operates
  649. local nSeatId=data.response.nSeatId
  650. local roomInfo = app.room.roomInfo;
  651. -- 抓牌
  652. if self.playerHandCards[viewId] then
  653. self.playerHandCards[viewId]:onGetCard(operates,card)
  654. end
  655. if viewId == MJDefine.MyViewId then
  656. local huCards = roomInfo.memberList[nUserId].huCards or {};
  657. -- 默认抓牌隐藏听牌按钮
  658. self:setButtonTingInfoVisible(false);
  659. if table.nums(huCards) > 0 then
  660. -- 如果玩家已经胡了,则不隐藏听牌按钮
  661. self:setButtonTingInfoVisible(true);
  662. end
  663. if operates and table.nums(operates)>0 then
  664. self.operates = operates
  665. else
  666. self.operates = {}
  667. end
  668. if self.playerHandCards[MJDefine.MyViewId] then
  669. self.playerHandCards[MJDefine.MyViewId]:setTing(false)
  670. local player = roomInfo.memberList[data.response.nUserId]
  671. end
  672. app.room:dispatchEvent({name = MJDefine.MJEvent.SelectCard})
  673. app.room:dispatchEvent({name = MJDefine.MJEvent.PushTing})
  674. -- app.room:dispatchEvent({name = MJDefine.MJEvent.ShowTing})
  675. self:setTingCardVisible(false);
  676. -- 抓牌后,需要判断抓的牌是否是听用牌
  677. local lastCard = self.playerHandCards[MJDefine.MyViewId]:getLastCard()
  678. for i, v in ipairs(app.room.roomInfo:getTingYongCard()) do
  679. if v.card == lastCard:getValue() then
  680. lastCard:setIsTingYongCard(true)
  681. end
  682. end
  683. -- 抓牌后需要判断遍历手中,有缺的话,只显示缺,不然就全部显示
  684. if self:checkMyCardHaveDingQue() then
  685. local myUserId = app.room:getMyUserId()
  686. for i, v in pairs(self.playerHandCards[MJDefine.MyViewId]:getHandCardNodes()) do
  687. local colorType = v:getMJColorType()
  688. if colorType ~= app.room.roomInfo:getDingQueInfo(myUserId) and not v:getIsTingYongCard() then
  689. v:setStatus(MJDefine.MJStatus.Disable)
  690. else
  691. v:setIsDingQueCard(true)
  692. end
  693. end
  694. else
  695. for i, v in pairs(self.playerHandCards[MJDefine.MyViewId]:getHandCardNodes()) do
  696. if not v:getIsTingYongCard() then
  697. v:setStatus(MJDefine.MJStatus.Normal)
  698. end
  699. end
  700. end
  701. -- 清除所有操作按钮
  702. -- self.playerHandCards[MJDefine.MyViewId]:hideOperate()
  703. self.playerHandCards[MJDefine.MyViewId]:hideOperateItem()
  704. self.playerHandCards[MJDefine.MyViewId]:showOperate(operates,card,true)
  705. else
  706. -- 如果是回放,也需要判断其他玩家抓的牌是否是听用牌
  707. if self._isReplay then
  708. if self.playerHandCards and self.playerHandCards[viewId] then
  709. local lastCard = self.playerHandCards[viewId]:getLastCard()
  710. for i, v in ipairs(app.room.roomInfo:getTingYongCard()) do
  711. if v.card == lastCard:getValue() then
  712. lastCard:setIsTingYongCard(true)
  713. end
  714. end
  715. end
  716. end
  717. end
  718. -- local myUserId = app.room:getMyUserId()
  719. -- if data.response.nUserId == myUserId then
  720. -- if self.playerHandCards[MJDefine.MyViewId] then
  721. -- self.playerHandCards[MJDefine.MyViewId]:pushTing()
  722. -- end
  723. -- end
  724. if type(data.response.nLeaveCardNum) == "number" then
  725. roomInfo:setLeaveCardNum(data.response.nLeaveCardNum)
  726. self.direcionView:updateCardNums(data.response.nLeaveCardNum)
  727. end
  728. self:updateGameNums()
  729. self.direcionView:updateDirection(nSeatId)
  730. if onEnd then
  731. onEnd()
  732. end
  733. end
  734. log("2000000000-yibinmajiangRoomView - addCallBack(runOnBankerOutCard)")
  735. self:addCallBack(runOnBankerOutCard);
  736. end
  737. -- 庄家初始操作(由于有定缺,所以一开始时候会发送8106<获取手牌>和811a<只获取操作和听牌数据>来区别分开来,之后就全部都是8106来读手牌和操作)
  738. function yibinmajiangRoomView:onGameRoundStartOperate(data)
  739. local function runOnGameRoundStartOperate(onEnd)
  740. logD("yibinmajiangRoomView:runOnGameRoundStartOperate", "811a开始操作", table.tostring(data.response))
  741. local nUserId = data.response.nUserId
  742. local viewId = app.room:getViewIdByUserId(nUserId)
  743. local card= data.response.card
  744. local operates=data.response.operates
  745. local nSeatId=data.response.nSeatId
  746. local roomInfo = app.room.roomInfo;
  747. if viewId == MJDefine.MyViewId then
  748. local huCards = roomInfo.memberList[nUserId].huCards or {};
  749. if operates and table.nums(operates)>0 then
  750. self.operates = operates
  751. else
  752. self.operates = {}
  753. end
  754. self.playerHandCards[MJDefine.MyViewId]:setOutCardEnable(true)
  755. self.playerHandCards[MJDefine.MyViewId]:hideOperateItem()
  756. self.playerHandCards[MJDefine.MyViewId]:showOperate(operates,card,true)
  757. -- if self.playerHandCards[MJDefine.MyViewId] then
  758. -- self.playerHandCards[MJDefine.MyViewId]:pushTing()
  759. -- end
  760. app.room:dispatchEvent({name = MJDefine.MJEvent.PushTing})
  761. end
  762. if onEnd then
  763. onEnd()
  764. end
  765. end
  766. log("2000000000-yibinmajiangRoomView - addCallBack(runOnGameRoundStartOperate)")
  767. self:addCallBack(runOnGameRoundStartOperate);
  768. end
  769. function yibinmajiangRoomView:onTurnOutCard(data)
  770. local function runOnTurnOutCard(onEnd)
  771. logE("MJRoomView:runOnOutCard(), response = ", table.tostring(data.response))
  772. log("2000000000-MJRoomView - runOnOutCard")
  773. if app.room.roomInfo:getLastOutViewId() ~= MJDefine.MyViewId then
  774. self.playerHandCards[MJDefine.MyViewId]:setOutCardEnable(true)
  775. end
  776. -- local viewId = app.room:getViewIdByUserId(data.response.nUserId)
  777. -- local card= data.response.card
  778. -- if self.playerHandCards[viewId] then
  779. -- self.playerHandCards[viewId]:createOutCards(card)
  780. -- end
  781. if onEnd then
  782. onEnd()
  783. end
  784. end
  785. log("2000000000-MJRoomView - addCallBack(runOnTurnOutCard)")
  786. self:addCallBack(runOnTurnOutCard)
  787. end
  788. -- 出牌成功
  789. function yibinmajiangRoomView:onOutCardSuccess(data)
  790. logE("yibinmajiangRoomView:onOutCardSuccess(), response = ", table.tostring(data.response))
  791. local function runOnOutCardSuccess(onEnd)
  792. log("2000000000-yibinmajiangRoomView - runOnOutCardSuccess---------")
  793. -- app.room.roomInfo.outCardUserId = data.response.nUserId
  794. local roomInfo = app.room.roomInfo;
  795. local nUserId = data.response.nUserId
  796. local viewId = app.room:getViewIdByUserId(nUserId)
  797. local card= data.response.card
  798. local operates=data.response.operates
  799. local opType = operates.opType
  800. if operates and table.nums(operates)>0 then
  801. self.operates = operates
  802. self:setTingCardVisible(false);
  803. else
  804. self.operates = {}
  805. end
  806. local function callback()
  807. -- roomInfo:LastOutViewId(nil)
  808. self.playerHandCards[MJDefine.MyViewId]:showOperate(operates,card)
  809. if onEnd then
  810. onEnd()
  811. end
  812. end
  813. -- self.lastOutCard = card
  814. if self.playerHandCards[viewId] then
  815. --(viewId~=MJDefine.MyViewId) and roomInfo:getLastOutViewId()~=MJDefine.MyViewId
  816. if viewId==MJDefine.MyViewId then
  817. local gameInfo = roomInfo:getGameRule();
  818. local zidonghu = getNumBand(gameInfo.specialrule, 0x08) or 0;
  819. local player = roomInfo.memberList[nUserId]
  820. callback() -- 显示操作
  821. self.playerHandCards[viewId]:setTing(false)
  822. if gameInfo.tingpai > 0 then
  823. -- 检查是否可听
  824. self.ui:sendMsg(app.room, MJDefine.MJEvent.Ting) -- 每次出牌都请求一次是否可听
  825. end
  826. if table.nums(player.huCards) > 0 then
  827. -- 胡牌后,显示听牌按钮
  828. self:setButtonTingInfoVisible(true);
  829. end
  830. -- self.ui:sendMsg(app.room,MJDefine.MJEvent.Ting)
  831. self:setTingCardVisible(false);
  832. -- self.isTing = true;
  833. -- self:setButtonTingInfoVisible(true);
  834. -- 如果出牌后,自己还是听状态,则显示听按钮
  835. -- local nTingStatus = player.nTingStatus
  836. -- if nTingStatus == MJDefine.MJTingStatus.Ting then
  837. -- self:setButtonTingInfoVisible(true)
  838. -- end
  839. -- 自己出牌后,需要判断是否还有定缺牌,没有的话则亮起所有手牌
  840. if not self:checkMyCardHaveDingQue() then
  841. for i, v in pairs(self.playerHandCards[MJDefine.MyViewId]:getHandCardNodes()) do
  842. if not v:getIsTingYongCard() then
  843. v:setStatus(MJDefine.MJStatus.Normal)
  844. end
  845. end
  846. end
  847. else
  848. self.playerHandCards[viewId]:onOutCard(card,callback)
  849. end
  850. app.room:dispatchEvent({name = MJDefine.MJEvent.OutCardFalg, value=card ,viewId=viewId})
  851. else
  852. callback()
  853. end
  854. roomInfo:setLastOutViewId(viewId);
  855. end
  856. log("2000000000-yibinmajiangRoomView - addCallBack(runOnOutCardSuccess)")
  857. self:addCallBack(runOnOutCardSuccess, 0.5)
  858. end
  859. -- 已经发送了过操作
  860. function yibinmajiangRoomView:onSendGuo()
  861. self.operates = {}
  862. end
  863. -- 操作成功
  864. function yibinmajiangRoomView:onOperationCodeSuccess(data)
  865. local function runOnOperationSuccess(onEnd)
  866. local response = data.response
  867. local nUserId = response.nUserId
  868. local opType = response.opType
  869. local opCard = response.opCard
  870. local bIsOutCard = response.isNeedOutCard > 0
  871. local fromSeatId = response.fromSeatId
  872. local cardNum = response.cardNum or 0;
  873. local useRedNum = response.useRedNum
  874. local lziCard = response.lziCard
  875. local viewId = app.room:getViewIdByUserId(nUserId)
  876. local fromViewId = app.room:getViewIdBySeatId(fromSeatId)
  877. local opSeatId = app.room:getSeatIdByViewId(viewId)
  878. local fromUserId = app.room:getUserIdBySeatId(fromSeatId)
  879. if self.playerHandCards[viewId] then
  880. --组合一下牌
  881. local groups={
  882. self:getChangeGruopDatas({opType=opType, opCard=opCard, cardNum = cardNum, targetSeatId=opSeatId, opUserId=fromUserId, useRedNum=useRedNum, lziCard=lziCard})
  883. }
  884. --删除手中对应的牌
  885. local deleteCards
  886. for k,v in pairs(groups) do
  887. if v.showType==MJDefine.MJGroupType.Peng then
  888. self.playerHandCards[viewId]:removeHandCardByNum(opCard,2,v.cardNum)
  889. elseif v.showType==MJDefine.MJGroupType.Chi then
  890. --TODO:吃的牌删除两张
  891. elseif v.showType==MJDefine.MJGroupType.AnGang
  892. or v.showType==MJDefine.MJGroupType.MAnGang then
  893. if v.cardNum <= 4 then
  894. self.playerHandCards[viewId]:removeHandCardByNum(opCard,4,v.cardNum)
  895. else
  896. -- 多头杠移除1张手牌
  897. self.playerHandCards[viewId]:removeHandCardByNum(opCard,1,v.cardNum)
  898. end
  899. elseif v.showType==MJDefine.MJGroupType.Fei then
  900. self.playerHandCards[viewId]:removeHandCardByNum(lziCard,useRedNum,v.cardNum)
  901. self.playerHandCards[viewId]:removeHandCardByNum(opCard,2-useRedNum,v.cardNum)
  902. elseif v.showType==MJDefine.MJGroupType.Ti then
  903. -- 做互换的操作
  904. else
  905. if opType==MJDefine.MJOperateType.OPREATE_BAGANG then
  906. self.playerHandCards[viewId]:removeHandCardByNum(opCard,1,v.cardNum)
  907. else
  908. self.playerHandCards[viewId]:removeHandCardByNum(opCard,3,v.cardNum)
  909. end
  910. end
  911. end
  912. --删除出去的牌 遍历哪些操作需要删除牌
  913. for k,v in pairs(MJDefine.MJOperateNeedRemoveCard) do
  914. if v==opType then
  915. self.playerHandCards[fromViewId]:removeOutCard(opCard)
  916. break
  917. end
  918. end
  919. if opType==MJDefine.MJOperateType.OPREATE_BAGANG then
  920. self.playerHandCards[viewId]:buGang(opCard,cardNum)
  921. elseif opType==MJDefine.MJOperateType.OPREATE_TI then
  922. self.playerHandCards[viewId]:ti(opCard,lziCard)
  923. else
  924. self.playerHandCards[viewId]:createGroupCards(groups)--创建显示的牌
  925. end
  926. -- 提操作不需要刷新手牌
  927. if opType ~= MJDefine.MJOperateType.OPREATE_TI then
  928. self.playerHandCards[viewId]:resetHandCards()
  929. end
  930. self.playerHandCards[viewId]:hideOperate()
  931. self.playerHandCards[viewId]:setOutCardEnable(bIsOutCard)
  932. if self.playerHandCards[viewId]:isLock() then
  933. self.playerHandCards[viewId]:lockHandCard();
  934. end
  935. self.direcionView:updateDirection(app.room:getSeatIdByViewId(viewId))
  936. end
  937. local function guafengxiayuEffect()
  938. local effect
  939. if (opType==MJDefine.MJOperateType.OPREATE_ZHIGANG) or (opType==MJDefine.MJOperateType.OPREATE_BAGANG) or
  940. (opType==MJDefine.MJOperateType.OPREATE_MINGGANG) then
  941. effect=MJAnimationCompnent.createGuaFengEffect()
  942. MJSound.PlayWindSound()
  943. elseif (opType==MJDefine.MJOperateType.OPREATE_ANGANG) then
  944. effect=MJAnimationCompnent.createXiaYuEffect()
  945. MJSound.PlayRainSound()
  946. end
  947. if effect then
  948. self.ui.Items.Layout_Player:addChild(effect)
  949. effect:setLocalZOrder(1000)
  950. effect:setPosition(self.playerHandCards[viewId]:getAnimationPostion())
  951. end
  952. end
  953. if (opType==MJDefine.MJOperateType.OPREATE_ZHIGANG) or (opType==MJDefine.MJOperateType.OPREATE_BAGANG) or
  954. (opType==MJDefine.MJOperateType.OPREATE_MINGGANG) or (opType==MJDefine.MJOperateType.OPREATE_ANGANG) then
  955. -- 花麻将直接播放刮风下雨效果,不播放“杠”字效果
  956. guafengxiayuEffect();
  957. else
  958. local effectCallback = function ()
  959. guafengxiayuEffect();
  960. end
  961. --播放动画
  962. local effect=MJAnimationCompnent.CreateOperareEffect(opType, effectCallback)
  963. if effect then
  964. self.ui.Items.Layout_Player:addChild(effect);
  965. effect:setLocalZOrder(1000);
  966. effect:setPosition(self.playerHandCards[viewId]:getAnimationPostion());
  967. end
  968. end
  969. self:showOperateScore(response.optScore);
  970. --音效
  971. local userInfo = app.room:getUserInfo(nUserId)
  972. if userInfo then
  973. MJSound.PlayOperateSound(userInfo.sex,opType)
  974. end
  975. if viewId == MJDefine.MyViewId then
  976. self.playerHandCards[MJDefine.MyViewId]:setTing(false)
  977. self:setButtonTingInfoVisible(false)
  978. self.operates={}
  979. end
  980. --删除等待操作的显示
  981. if self.waitOperates and #self.waitOperates>0 then
  982. for k,v in pairs(self.waitOperates) do
  983. v:removeFromParent()
  984. end
  985. self.waitOperates={}
  986. end
  987. --[[if viewId == MJDefine.MyViewId and opType==MJDefine.MJOperateType.OPREATE_PENG then
  988. local cards = {opCard}
  989. self.playerHandCards[viewId]:cardEnabled(cards, true)
  990. end--]]
  991. -- 取消操作按钮
  992. self.playerHandCards[MJDefine.MyViewId]:hideOperate()
  993. if onEnd then
  994. onEnd()
  995. end
  996. end
  997. self:addCallBack(runOnOperationSuccess)
  998. end
  999. -- 重连
  1000. function yibinmajiangRoomView:onGameReconnection()
  1001. local function onGameReconnectionCallback(onEnd)
  1002. --更新房间基础数据
  1003. local roomInfo = app.room.roomInfo;
  1004. self:updateRoomBaseData()
  1005. if (not isReviewVersion()) and cc.Application:getInstance():getTargetPlatform() ~= 0 then
  1006. self:updateAllGpsInfo()
  1007. end
  1008. -- self:checkGpsDistance(nil,roomInfo:getGameStartCount() == 0)
  1009. -- self:checkMyGpsNeedUpdate();
  1010. self.toolView:updateButton()
  1011. --显示离线状态
  1012. for k,v in pairs(roomInfo.memberList) do
  1013. local viewId = app.room:getViewIdByUserId(k)
  1014. self.playerView:setPlayerOffLineVisible(v.nOnlineStatus ~= MJDefine.PlayerOnlineStatus.Online, viewId)
  1015. end
  1016. -- local gameStatus = roomInfo:getGameStatus();
  1017. -- showTooltip('当前游戏状态是'..gameStatus..' startCount是'..roomInfo:getGameStartCount())
  1018. if roomInfo:getGameStartCount() > 0 then
  1019. -- 当前局数大于0,处于重连状态
  1020. self:handleGameReconnection();
  1021. else
  1022. -- 游戏未开始,非重连
  1023. self:handleGameNormal();
  1024. end
  1025. if onEnd then
  1026. onEnd();
  1027. end
  1028. end
  1029. self:addCallBack(onGameReconnectionCallback);
  1030. end
  1031. -- 重连游戏的逻辑处理
  1032. function yibinmajiangRoomView:handleGameReconnection()
  1033. local roomInfo = app.room.roomInfo;
  1034. local myUserId = app.room:getMyUserId();
  1035. local memberStatus = {};
  1036. local dismissUserId = 0;
  1037. local gameStatus = roomInfo:getGameStatus();
  1038. local isOperated = false
  1039. local meIsHu = false
  1040. -- 当前局数大于0,子游戏重连
  1041. if self._fastRequestView then
  1042. -- 隐藏快速开局
  1043. self._fastRequestView:removeSelf()
  1044. self._fastRequestView = nil
  1045. end
  1046. --隐藏俱乐部
  1047. self:hideClub()
  1048. for k,v in pairs(roomInfo.memberList) do
  1049. -- local nOffLineState = v.nOnlineStatus
  1050. -- --显示离线
  1051. -- self.playerView:setPlayerOffLineVisible(nOffLineState ~= MJDefine.PlayerOnlineStatus.Online,viewId)
  1052. --发起解散状态的ID
  1053. dismissUserId = (v.nDisbandStatus == 1) and v.nUserId or dismissUserId;
  1054. if v.nDisbandStatus ~= 0 then
  1055. table.insert(memberStatus,{userId = v.nUserId , status = v.nDisbandStatus})
  1056. end
  1057. end
  1058. --显示解散界面
  1059. if roomInfo:getIsUserDisbandGame() == 1 and dismissUserId ~= 0 and roomInfo:getIsGameOver() ~= 1 then
  1060. local view = require("luaScript.Views.Room.RoomDismissView"):new(dismissUserId, roomInfo.memberList, roomInfo:getDismissStateTime());
  1061. -- self:addChild(view,1);
  1062. self:addToLayer("popup", view, 10);
  1063. app.room:dispatchEvent({name = GAME_EVENT.DISSMISS_UPDATE_STATUS, memberStatus = memberStatus});
  1064. end
  1065. --如果一局结束,玩家点了准备,不再显示牌信息
  1066. if MJDefine.GameStatus.GAME_STATUS_ROUND_OVER == gameStatus or MJDefine.GameStatus.GAME_STATUS_GAME_OVER == gameStatus then
  1067. if roomInfo.memberList[myUserId].nPlayerFlag == 1 then --游戏为停止或开始状态
  1068. self:onUserReadyResponse({nUserId = myUserId});
  1069. return
  1070. end
  1071. end
  1072. -- 刷新庄家显示
  1073. self:updateBanker()
  1074. -- 初始化玩家手牌节点
  1075. self:initHandCardNodes()
  1076. --初始化方位
  1077. self.direcionView:initDirection(self.desktopType)
  1078. self.direcionView:updateDirection(app.room:getSeatIdByUserId(roomInfo:getNeedOutCardId()));
  1079. self.direcionView:updateCardNums(roomInfo:getLeaveCardNum())
  1080. --显示用户的牌和信息
  1081. for userId,v in pairs(roomInfo.memberList) do
  1082. local viewId = app.room:getViewIdByUserId(userId)
  1083. if self.playerHandCards[viewId] then
  1084. --组合一下牌
  1085. local groups={}
  1086. for k, v in ipairs(v.operates) do
  1087. table.insert(groups, self:getChangeGruopDatas(v));
  1088. end
  1089. self.playerHandCards[viewId]:createGroupCards(groups);
  1090. self.playerHandCards[viewId]:createOutCards(v.outCards);
  1091. if table.nums(v.huCards) > 0 and viewId ~= MJDefine.MyViewId then
  1092. self.playerHandCards[viewId]:createOpenHandCards(v.handCards);
  1093. else
  1094. self.playerHandCards[viewId]:createHandCards(v.handCards);
  1095. -- self.playerHandCards[viewId]:moveLastCard()
  1096. end
  1097. if v.nPlayerFlag > 1 then
  1098. if viewId == MJDefine.MyViewId then
  1099. -- self.playerHandCards[viewId]:resetHandCards();
  1100. local operates = roomInfo:getOperates();
  1101. self.operates = (operates and table.nums(operates)>0) and operates or {};
  1102. -- 已经胡牌的玩家,不能操作手牌
  1103. if table.nums(v.huCards) > 0 then
  1104. self.playerHandCards[viewId]:lockHandCard(true)
  1105. end
  1106. -- 判断断线重连前,如果有操作话,是否有操作过
  1107. local operateTable = json.decode(v.isOperated)
  1108. if operateTable.subOpt and operateTable.subOpt > 0 then
  1109. isOperated = true
  1110. end
  1111. end
  1112. local isHu = table.nums(v.huCards) > 0
  1113. self.playerView:showHu(viewId, isHu)
  1114. self.playerView:showHuFlag(viewId, isHu)
  1115. -- 显示定缺
  1116. -- if v.isDingQue == 1 then
  1117. -- self.playerView:showDingQue(viewId, v.dingquetype)
  1118. -- end
  1119. end
  1120. --显示飘状态
  1121. self.playerView:showPiao(viewId,tonumber(v.piaostate) == 1)
  1122. -- 刷新胡牌
  1123. -- self.playerHandCards[viewId]:onGetHuCard(v.huCards, true);
  1124. if next(v.huCards) and next(v.huCards[1]) and v.huCards[1].huCard and v.huCards[1].huCard > 0 then
  1125. local huCardValue = v.huCards[1].huCard
  1126. self.playerHandCards[viewId]:createHandCards(huCardValue, true)
  1127. self.playerView:showHu(viewId, true)
  1128. self.playerView:showHuFlag(viewId, true)
  1129. if viewId == MJDefine.MyViewId then
  1130. meIsHu = true
  1131. end
  1132. end
  1133. end
  1134. end
  1135. --显示出牌角标
  1136. local lastOutCardViewId = app.room:getViewIdByUserId(roomInfo:getOutCardUserId());
  1137. app.room:dispatchEvent({name = MJDefine.MJEvent.OutCardFalg, value = roomInfo:getLastOpCard(), viewId = lastOutCardViewId});
  1138. -- 显示本金和听用牌
  1139. local benjinCard = app.room.roomInfo:getBenJinCard()
  1140. if benjinCard and benjinCard > 0 then
  1141. local tingCard = app.room.roomInfo:getTingYongCard()
  1142. local data = {response = {benjinCard = benjinCard, tingCard = tingCard}}
  1143. self:showBenJin(data, false)
  1144. end
  1145. -- 还没胡牌,遍历手牌,让定缺牌先出
  1146. if not meIsHu then
  1147. if self:checkMyCardHaveDingQue() then
  1148. if app.room:checkIsAllChooseDingQue() then
  1149. local result = app.room.roomInfo:getDingQueInfo(myUserId)
  1150. if self.playerHandCards and self.playerHandCards[MJDefine.MyViewId] then
  1151. for i, v in pairs(self.playerHandCards[MJDefine.MyViewId]:getHandCardNodes()) do
  1152. local colorType = v:getMJColorType()
  1153. if colorType ~= result and not v:getIsTingYongCard() then
  1154. v:setStatus(MJDefine.MJStatus.Disable)
  1155. else
  1156. v:setIsDingQueCard(true)
  1157. end
  1158. end
  1159. end
  1160. end
  1161. else
  1162. for i, v in pairs(self.playerHandCards[MJDefine.MyViewId]:getHandCardNodes()) do
  1163. if not v:getIsTingYongCard() then
  1164. v:setStatus(MJDefine.MJStatus.Normal)
  1165. end
  1166. end
  1167. end
  1168. self.playerHandCards[MJDefine.MyViewId]:resetHandCards()
  1169. end
  1170. -- 如果我胡了,锁定手牌
  1171. if meIsHu then
  1172. self.playerHandCards[MJDefine.MyViewId]:lockHandCard()
  1173. end
  1174. -- 将重连前最后操作的牌,放到最后一张
  1175. -- 这里要特殊处理,提操作后,发来的操作牌还是提牌,但是这个提牌已经被放下去了,所以要判断手牌是否包含这张牌(?)
  1176. -- 如果当前是有操作,并且是自己可以出牌的情况,那么needOutCardid会发0
  1177. if roomInfo:getNeedOutCardId() == myUserId or roomInfo:getNeedOutCardId() == 0 then
  1178. local lastOpCardValue = roomInfo:getLastOpCard();
  1179. if lastOpCardValue ~= 0 then
  1180. if self.playerHandCards[MJDefine.MyViewId]:getMjByValue(lastOpCardValue) then
  1181. self.playerHandCards[MJDefine.MyViewId]:removeHandCard(lastOpCardValue);
  1182. self.playerHandCards[MJDefine.MyViewId]:resetHandCards();
  1183. self.playerHandCards[MJDefine.MyViewId]:createHandCards(lastOpCardValue);
  1184. -- 设置最后一张是否为听用牌
  1185. local tingCardTable = app.room.roomInfo:getTingYongCard()
  1186. local lastOpCard = self.playerHandCards[MJDefine.MyViewId]:getLastCard()
  1187. for _, j in ipairs(tingCardTable) do
  1188. if j.card == lastOpCardValue then
  1189. lastOpCard:setIsTingYongCard(true)
  1190. break
  1191. end
  1192. end
  1193. end
  1194. end
  1195. self.playerHandCards[MJDefine.MyViewId]:setOutCardEnable(true);
  1196. end
  1197. -- 如果我还没胡牌,并且当前不是我出牌,请求一次听数据(不能放在上面,因为中间还有个移除最后一张牌并刷新)
  1198. if not meIsHu then
  1199. -- if not (roomInfo:getNeedOutCardId() == myUserId or roomInfo:getNeedOutCardId() then -- 这里不能用getNeedOutCard来判断,因为有时候会发userid,如果玩家有操作或者其他玩家有操作(胡之类的),那么也会发0
  1200. local isMyTurn = table.nums(self.playerHandCards[MJDefine.MyViewId]:getHandCardNodes()) % 3 == 2
  1201. if not isMyTurn then
  1202. self.ui:sendMsg(app.room, MJDefine.MJEvent.Ting)
  1203. end
  1204. end
  1205. --设置可以出牌的人
  1206. -- local outCardViewId = app.room:getViewIdBySeatId(roomInfo.outCardSeatId)
  1207. -- if outCardViewId then
  1208. -- if (outCardViewId~=MJDefine.MyViewId and roomInfo.lastOpCard==0) or (outCardViewId == MJDefine.MyViewId or roomInfo.isNeedOutCard) then
  1209. -- self.playerHandCards[outCardViewId]:setOutCardEnable(true)
  1210. -- end
  1211. -- end
  1212. --显示听标示
  1213. app.room:dispatchEvent({name = MJDefine.MJEvent.PushTing});
  1214. -- 如果有操作显示操作按钮
  1215. -- 如果断线前有操作过就不显示了
  1216. if not isOperated then
  1217. local isMyTurn = table.nums(self.playerHandCards[MJDefine.MyViewId]:getHandCardNodes()) % 3 == 2
  1218. self.playerHandCards[MJDefine.MyViewId]:showOperate(roomInfo:getOperates(), roomInfo:getLastOpCard(), isMyTurn)
  1219. end
  1220. -- 等待缺状态(8)
  1221. if gameStatus == MJDefine.GameStatus.GAME_STATUS_WAIT_SELECT_QUE then
  1222. local gameInfo = roomInfo:getGameRule();
  1223. for i, player in pairs(roomInfo.memberList) do
  1224. local viewId = app.room:getViewIdByUserId(player.nUserId)
  1225. if myUserId == player.nUserId then
  1226. if tonumber(player.dingquetype) ~= -1 then
  1227. -- self.playerView:showDingQue(viewId, player.dingquetype)
  1228. else
  1229. if getNumBand(gameInfo.specialrule, 0x01) > 0 then
  1230. local myNiceChoose = player.nice_choose
  1231. self:showDingQue({response = {nice_choose = myNiceChoose}})
  1232. end
  1233. end
  1234. else
  1235. if tonumber(player.dingquetype) ~= -1 then
  1236. -- self.playerView:showDingQue(viewId, player.dingquetype)
  1237. end
  1238. end
  1239. end
  1240. else
  1241. for i, player in pairs(roomInfo.memberList) do
  1242. local viewId = app.room:getViewIdByUserId(player.nUserId)
  1243. if tonumber(player.dingquetype) ~= -1 then
  1244. self.playerView:showDingQue(viewId, player.dingquetype)
  1245. end
  1246. end
  1247. end
  1248. -- 等待漂状态(12)
  1249. if gameStatus == MJDefine.GameStatus.GAME_STATUS_WAIT_PIAO then
  1250. local gameInfo = roomInfo:getGameRule();
  1251. for i, player in pairs(roomInfo.memberList) do
  1252. local viewId = app.room:getViewIdByUserId(player.nUserId)
  1253. if myUserId == player.nUserId then
  1254. if tonumber(player.isPiao) == 1 then -- 操作过飘了
  1255. self.playerView:showPiao(viewId,tonumber(player.piaostate) == 1)
  1256. else
  1257. if gameInfo.piaomode == 1 then--可以飘 还没有飘 显示飘按钮
  1258. self:showPiao()
  1259. end
  1260. end
  1261. else
  1262. self.playerView:showPiao(viewId,tonumber(player.piaostate) == 1)
  1263. end
  1264. if tonumber(player.piaostate) == 1 then
  1265. local effect = MJAnimationCompnent.CreatePiaoEffect()
  1266. if effect then
  1267. self.ui.Items.Layout_Effect_piao:addChild(effect)
  1268. effect:setLocalZOrder(1000)
  1269. effect:setPosition(self.playerHandCards[viewId]:getAnimationPostion())
  1270. end
  1271. end
  1272. end
  1273. end
  1274. --显示结算界面
  1275. if gameStatus == MJDefine.GameStatus.GAME_STATUS_ROUND_OVER or gameStatus == MJDefine.GameStatus.GAME_STATUS_GAME_OVER then
  1276. -- 摊开手牌
  1277. self:showOpenCard()
  1278. -- 显示小局结算
  1279. self:showXiaoJuView();
  1280. end
  1281. self:setBtnSitDownVisible(false)
  1282. end
  1283. -- 游戏未开始时重连的逻辑处理
  1284. function yibinmajiangRoomView:handleGameNormal()
  1285. local roomInfo = app.room.roomInfo;
  1286. local gameStatus = roomInfo:getGameStatus();
  1287. local gameInfo = roomInfo:getGameRule();
  1288. local myUserId = app.room:getMyUserId();
  1289. if gameStatus and gameStatus < MJDefine.GameStatus.GAME_STATUS_WAIT_BANKER_START then
  1290. --self.toolView:enableHosting(false)
  1291. local quickStartInfo = roomInfo:getQuickStartInfo();
  1292. if quickStartInfo then
  1293. if quickStartInfo.tablefaststate == 1 then
  1294. local tmpInfo = {}
  1295. for uid,status in pairs(quickStartInfo.list) do
  1296. table.insert(tmpInfo, {nUserId=tonumber(uid), nStatus = status})
  1297. end
  1298. local response = {}
  1299. response.pList = tmpInfo
  1300. response.timeOut = roomInfo:getQuickStartInfo().time
  1301. self:onBroadcastFaststart({response=response})
  1302. else
  1303. --self.toolView:showFastStart(true)
  1304. end
  1305. else
  1306. if self._fastRequestView then
  1307. self._fastRequestView:removeSelf()
  1308. self._fastRequestView = nil
  1309. end
  1310. --self.toolView:showFastStart(true)
  1311. end
  1312. elseif gameStatus == MJDefine.GameStatus.GAME_STATUS_ROUND_OVER or gameStatus == MJDefine.GameStatus.GAME_STATUS_GAME_OVER then
  1313. local mySelf = roomInfo.memberList[myUserId];
  1314. if mySelf.nPlayerFlag ~= 1 then
  1315. --显示哪些玩家胡牌
  1316. for i,player in pairs(roomInfo.memberList) do
  1317. local viewId = app.room:getViewIdByUserId(player.nUserId)
  1318. end
  1319. end
  1320. end
  1321. end
  1322. -- 小局结算消息
  1323. function yibinmajiangRoomView:onGameXiaoJuResponse(data)
  1324. local function runGameXiaoJuResponse(onEnd)
  1325. if not tolua.isnull(self.firstTingTipsView) then
  1326. self.firstTingTipsView:killSelf()
  1327. self.firstTingTipsView = nil
  1328. end
  1329. -- 取消操作按钮
  1330. if self.playerHandCards and self.playerHandCards[MJDefine.MyViewId] then
  1331. self.playerHandCards[MJDefine.MyViewId]:hideOperate()
  1332. end
  1333. local roomInfo = app.room.roomInfo
  1334. self.direcionView:stopAllActions()
  1335. self.operates = {}
  1336. self:setTingCardVisible(false);
  1337. app.room:resetTings()
  1338. app.room:cleanTingStatus()
  1339. --如果是解散直接return
  1340. --[[if roomInfo:getStopFlag() == MJDefine.StopFlag.STOP_FLAG_LONG_NOT_END or roomInfo:getStopFlag() == MJDefine.StopFlag.STOP_FLAG_DISBAND_GAME then
  1341. if onEnd then
  1342. onEnd()
  1343. end
  1344. return
  1345. end --]]
  1346. --所有胡牌的人 考虑抢杠胡的问题
  1347. --[[local viewIds={}
  1348. local failViewId=0
  1349. for k,v in pairs(roomInfo.memberList) do
  1350. local viewId = app.room:getViewIdByUserId(v.nUserId)
  1351. if v.result>0 then
  1352. table.insert(viewIds,viewId)
  1353. --处理掉huCard, 不加入手牌
  1354. --播放音效
  1355. if viewId==MJDefine.MyViewId then
  1356. --MJSound.PlayWinGame()
  1357. end
  1358. if v.result==MJDefine.MJGameHuType.HU_DIANPAO then
  1359. failViewId = app.room:getViewIdBySeatId(v.dpSeatId)
  1360. end
  1361. end
  1362. end]]
  1363. self:showOpenCard()
  1364. --被抢杠的人回退补杠
  1365. -- if resultInfo.hutype==MJDefine.MJHuType.QiangGangHu and roomInfo:getStopFlag() == MJDefine.StopFlag.STOP_FLAG_NORMAL then
  1366. -- self.playerHandCards[failViewId]:retoreBuGang(resultInfo.hucard)
  1367. -- end
  1368. local function callback()
  1369. local roomInfo = app.room.roomInfo
  1370. local memberList = roomInfo.memberList;
  1371. local hasHandcards = true;
  1372. for k, v in pairs(memberList) do
  1373. if v.handCards and #v.handCards == 0 then
  1374. hasHandcards = false;
  1375. break;
  1376. end
  1377. end
  1378. if not hasHandcards then
  1379. -- 还没发牌就结束游戏,直接返回大厅
  1380. app.room.roomInfo.needJieSuanInfo = 1;
  1381. app.room:dispatchEvent({name = GAME_EVENT.DISSMISS_CLOSE});
  1382. return ;
  1383. end
  1384. self:showXiaoJuView()
  1385. if onEnd then
  1386. onEnd()
  1387. end
  1388. self.ui.Items.Layout_Effect_piao:removeAllChildren()
  1389. end
  1390. if roomInfo:getStopFlag() == MJDefine.StopFlag.STOP_FLAG_HUANG_ZHUANG then
  1391. local effect=MJAnimationCompnent.CreateLiuJuEffect(callback)
  1392. self.ui.Items.Layout_Player:addChild(effect)
  1393. effect:setLocalZOrder(1000)
  1394. MJSound.PlayHuangZhuang()
  1395. else
  1396. local delayTime = 1.5;
  1397. if roomInfo:getStopFlag() == MJDefine.StopFlag.STOP_FLAG_LONG_NOT_END or roomInfo:getStopFlag() == MJDefine.StopFlag.STOP_FLAG_DISBAND_GAME then
  1398. delayTime = 0;
  1399. end
  1400. runDelay(delayTime, function ()
  1401. callback()
  1402. end)
  1403. end
  1404. end
  1405. self:addCallBack(runGameXiaoJuResponse);
  1406. end
  1407. -- 显示小局结算
  1408. function yibinmajiangRoomView:showXiaoJuView()
  1409. self.direcionView:stopAllActions()
  1410. self:setTingCardVisible(false);
  1411. if self.xiaojuView then
  1412. self.xiaojuView:removeFromParent()
  1413. end
  1414. local roomInfo = app.room.roomInfo
  1415. -- 打开胡牌
  1416. local memberList = roomInfo.memberList
  1417. for k, v in pairs(memberList) do
  1418. local viewId = app.room:getViewIdByUserId(v.nUserId)
  1419. local huCards = v.huCards
  1420. if self.playerHandCards[viewId] then
  1421. -- 需要判断玩家是否有胡牌并且有值
  1422. if next(huCards) and next(huCards[1]) and huCards[1].huCard and huCards[1].huCard > 0 then
  1423. local huCardValue = huCards[1].huCard
  1424. -- self.playerHandCards[viewId]:onGetHuCard(huCards, true);
  1425. -- self.playerHandCards[viewId]:createHandCards(huCardValue, true)
  1426. end
  1427. end
  1428. end
  1429. self.xiaojuView = MJRoomXiaoJuView:new(self.desktopType)
  1430. self:addToLayer("popup", self.xiaojuView,1);
  1431. app.room:dispatchEvent({name = MJDefine.MJEvent.EVENT_XIAOJU_VIEW_SHOWED});
  1432. end
  1433. -- 大局结算消息
  1434. function yibinmajiangRoomView:onGameDaJuResponse(data)
  1435. if self._gameoverview then
  1436. return
  1437. end
  1438. runDelay(0.3, function ()
  1439. if app.room.roomInfo.needJieSuanInfo == 1 then--显示总结算
  1440. self:showGameOverResult(data.response)
  1441. else
  1442. --[[local roomInfo=app.room.roomInfo
  1443. --如果是解散直接跳转总结算
  1444. if roomInfo:getStopFlag() == MJDefine.StopFlag.STOP_FLAG_LONG_NOT_END or roomInfo:getStopFlag() == MJDefine.StopFlag.STOP_FLAG_DISBAND_GAME then
  1445. self:showGameOverResult(data.response)
  1446. end --]]
  1447. app.room:dispatchEvent({name = GAME_EVENT.DISSMISS_CLOSE})
  1448. end
  1449. end)
  1450. end
  1451. -- 显示大局结算
  1452. function yibinmajiangRoomView:showGameOverResult(data)
  1453. if self._gameoverview ~= nil then
  1454. return
  1455. end
  1456. self.direcionView:stopAllActions()
  1457. self:resetGame()
  1458. local view=MJRoomDaJuView:new(data)
  1459. view:setAnchorPoint(cc.p(0.5, 0.5))
  1460. app:showWaitDialog(view)
  1461. self._gameoverview = view
  1462. app.room:dispatchEvent({name = MJDefine.MJEvent.EVENT_DAJU_VIEW_SHOWED});
  1463. end
  1464. -- 听牌状态
  1465. function yibinmajiangRoomView:onTingCardStatus()
  1466. local myUserId=app.user.loginInfo.uid
  1467. local memberList=app.room.roomInfo.memberList
  1468. local player = memberList[myUserId]
  1469. if not player then
  1470. return
  1471. end
  1472. local nTingStatus = player.nTingStatus
  1473. -- showTooltip('收到听状态'..nTingStatus)
  1474. if nTingStatus == MJDefine.MJTingStatus.Ting then
  1475. print("---------onTingCardStatus-----------1 "..myUserId)
  1476. -- if player.isBaoPai == 1 then
  1477. self.ui:sendMsg(app.room,MJDefine.MJEvent.Ting)
  1478. -- end
  1479. self.isTing = true
  1480. self:setButtonTingInfoVisible(true)
  1481. else
  1482. print("---------onTingCardStatus-----------0 "..myUserId)
  1483. self:setButtonTingInfoVisible(false)
  1484. end
  1485. end
  1486. -- 听牌结果
  1487. function yibinmajiangRoomView:onTingCardResult(data)
  1488. print("---------听牌结果-------------")
  1489. local tingCards = data.response.tingCards or {};
  1490. self.isTing = table.nums(tingCards) > 0;
  1491. self:setButtonTingInfoVisible(self.isTing);
  1492. self._tingCardView:setData(tingCards);
  1493. end
  1494. -- 显示听
  1495. function yibinmajiangRoomView:showTing(evet)
  1496. local roomInfo=app.room.roomInfo;
  1497. local selectCard = evet.card;
  1498. if not selectCard or evet.card <= 0 then
  1499. return;
  1500. end
  1501. local curTingCards = roomInfo:getTingCardsByCard(selectCard);
  1502. if not self._tingCardView then
  1503. return ;
  1504. end
  1505. self._tingCardView:setData(curTingCards);
  1506. self.isTing = table.nums(curTingCards) > 0;
  1507. if self.isTing and (not self:isMySelfHu()) then
  1508. self:setTingCardVisible(true);
  1509. else
  1510. self:setTingCardVisible(false);
  1511. end
  1512. end
  1513. -- 判断我是否胡了
  1514. function yibinmajiangRoomView:isMySelfHu()
  1515. local myUserId = app.room:getMyUserId()
  1516. local player = app.room.roomInfo.memberList[myUserId]
  1517. if not player then
  1518. return false
  1519. end
  1520. local huCards = player.huCards or {}
  1521. return table.nums(huCards) > 0
  1522. end
  1523. -- 胡牌消息
  1524. function yibinmajiangRoomView:onHuResponse(data)
  1525. local function runHuResponse(onEnd)
  1526. local response = data.response
  1527. local function callback()
  1528. self:playHuAni(response)
  1529. if onEnd then
  1530. onEnd()
  1531. end
  1532. end
  1533. --删除等待操作的显示
  1534. if self.waitOperates and #self.waitOperates>0 then
  1535. for k,v in pairs(self.waitOperates) do
  1536. v:removeFromParent()
  1537. end
  1538. self.waitOperates={}
  1539. end
  1540. local viewId = app.room:getViewIdByUserId(response.nUserId)
  1541. local userInfo=app.room:getUserInfoByViewId(viewId)
  1542. local roomInfo = app.room.roomInfo;
  1543. local isNeedRemoveCard = false
  1544. local isPlayHuEffect = false;
  1545. local huInfos = {};
  1546. -- 添加胡牌数据
  1547. if response.huType == MJDefine.MJGameHuType.HU_ZIMO then
  1548. isPlayHuEffect = true;
  1549. local huData = {};
  1550. huData.huType = response.huType
  1551. huData.viewId = viewId;
  1552. huData.userInfo = app.room:getUserInfoByViewId(viewId);
  1553. table.insert(huInfos, huData);
  1554. else
  1555. local ext = roomInfo.memberList[response.nUserId].ext or {};
  1556. local huIndex = roomInfo.memberList[response.nUserId].huIndex;
  1557. if response.isReplay then
  1558. local seat = app.room:getSeatIdByUserId(response.nUserId);
  1559. ext.seat = string.format("%s;", seat);
  1560. huIndex = 1;
  1561. end
  1562. isNeedRemoveCard = true
  1563. isPlayHuEffect = true
  1564. local huData = {};
  1565. huData.huType = response.huType
  1566. huData.viewId = viewId
  1567. huData.userInfo = app.room:getUserInfoByViewId(viewId)
  1568. table.insert(huInfos, huData)
  1569. -- local huSeats = string.split(ext.seat, ";");
  1570. -- if huSeats and huIndex then
  1571. -- if (#huSeats - 1) == huIndex then -- 因为最后一个是空格,所以要减一
  1572. -- isNeedRemoveCard = true
  1573. -- isPlayHuEffect = true;
  1574. -- for k, v in ipairs(huSeats) do
  1575. -- if string.len(v) > 0 then
  1576. -- local seat = tonumber(v);
  1577. -- local huData = {};
  1578. -- huData.huType = MJDefine.MJGameHuType.HU_DIANPAO;
  1579. -- huData.viewId = app.room:getViewIdBySeatId(seat);
  1580. -- huData.userInfo = app.room:getUserInfoByViewId(huData.viewId);
  1581. -- table.insert(huInfos, huData);
  1582. -- end
  1583. -- end
  1584. -- end
  1585. -- end
  1586. end
  1587. -- 胡牌动画
  1588. if isPlayHuEffect then
  1589. local function showHuFlag()
  1590. self.playerView:showHuFlag(viewId, true)
  1591. end
  1592. for k, v in ipairs(huInfos) do
  1593. --先播放胡牌动画和音效,再显示胡牌顺序
  1594. local effect = MJAnimationCompnent.CreateHuEffect(v.huType, showHuFlag)
  1595. if v.huType == MJDefine.MJGameHuType.HU_ZIMO then
  1596. MJSound.PlayOperateSound(v.userInfo.sex,MJDefine.MJOperateType.OPREATE_ZIMOHU)
  1597. else
  1598. MJSound.PlayOperateSound(v.userInfo.sex,MJDefine.MJOperateType.OPREATE_DIANPAOHU)
  1599. end
  1600. self.ui.Items.Layout_Effect:addChild(effect)
  1601. effect:setTag(HU_EFFECT_TAG)
  1602. effect:setLocalZOrder(1000)
  1603. effect:setPosition(self.playerHandCards[v.viewId]:getAnimationPostion())
  1604. end
  1605. self:showOperateScore(response.optScore);
  1606. --放炮动画
  1607. if response.huType ~= MJDefine.MJGameHuType.HU_ZIMO then
  1608. local failViewId = app.room:getViewIdByUserId(response.dpUserId)
  1609. local effect=MJAnimationCompnent.CreateDianPaoEffect(showHuFlag)
  1610. self.ui.Items.Layout_Effect:addChild(effect)
  1611. effect:setLocalZOrder(1000)
  1612. effect:setPosition(self.playerHandCards[failViewId]:getAnimationPostion())
  1613. end
  1614. end
  1615. -- 创建胡牌
  1616. local huCards = roomInfo.memberList[response.nUserId].huCards;
  1617. local huCard = response.huCard;
  1618. if response.huType==MJDefine.MJGameHuType.HU_DIANPAO then
  1619. local failViewId = app.room:getViewIdByUserId(response.dpUserId)
  1620. --点炮胡或抢杠胡,胡牌类型都是发 点炮胡
  1621. if response.isQiangGng > 0 then
  1622. -- logD("isQiangGng huCard:"..huCard)
  1623. --抢杠胡
  1624. -- self.playerHandCards[viewId]:onGetCard(nil,huCard)
  1625. -- self.playerHandCards[viewId]:onGetHuCard({huCard});
  1626. self.playerHandCards[viewId]:createHandCards(huCard.huCard, true)
  1627. --被抢杠的人回退补杠
  1628. self.playerHandCards[failViewId]:retoreBuGang(huCard.huCard,1)
  1629. -- self.playerHandCards[failViewId]:removeHandCardByNum(huCard, 1);
  1630. self.playerHandCards[failViewId]:resetHandCards();
  1631. -- 自动胡情况下,抢杠会自动出牌,此处需设置被抢杠玩家为上次出牌玩家
  1632. -- 否则会出现多牌情况
  1633. -- local gameInfo = roomInfo:getGameRule();
  1634. -- local zidonghu = getNumBand(gameInfo.specialrule, 0x08) or 0;
  1635. -- if zidonghu > 0 then
  1636. -- roomInfo:setLastOutViewId(failViewId);
  1637. -- end
  1638. elseif response.isGspHu and response.isGspHu > 0 then--点杠炮事手上已经有杠的牌 不需要再加一张胡的牌
  1639. --将胡的牌收走
  1640. if not self.playerHandCards[viewId]:removeLastHandCard() then
  1641. if isNeedRemoveCard then
  1642. self.playerHandCards[failViewId]:removeOutCard(huCard.huCard);
  1643. end
  1644. end
  1645. -- self.playerHandCards[viewId]:onGetHuCard({huCard});
  1646. self.playerHandCards[viewId]:createHandCards(huCard.huCard, true)
  1647. else
  1648. -- self.playerHandCards[viewId]:onGetCard(nil,response.huCard)
  1649. -- self.playerHandCards[viewId]:onGetHuCard({huCard});
  1650. self.playerHandCards[viewId]:createHandCards(huCard.huCard, true)
  1651. --将胡的牌收走
  1652. if isNeedRemoveCard then
  1653. self.playerHandCards[failViewId]:removeOutCard(huCard.huCard);
  1654. end
  1655. end
  1656. if failViewId==MJDefine.MyViewId and roomInfo:getLastOutViewId() == MJDefine.MyViewId then --修改点炮的人连续二次出牌 不删除牌
  1657. roomInfo:setLastOutViewId(nil);
  1658. end
  1659. --此处仅做保留,没有实际意义
  1660. elseif response.huType==MJDefine.MJGameHuType.HU_QIANGGANG then
  1661. local failViewId = app.room:getViewIdByUserId(response.dpUserId)
  1662. if response.redRealCard > 0 then
  1663. --抢杠胡时,胡牌的人将胡的牌加入手中
  1664. -- self.playerHandCards[viewId]:onGetCard(nil,response.redRealCard)
  1665. -- self.playerHandCards[viewId]:onGetHuCard({huCard});
  1666. self.playerHandCards[viewId]:createHandCards(huCard.huCard, true)
  1667. --被抢杠的人回退补杠
  1668. self.playerHandCards[failViewId]:retoreBuGang(response.redRealCard,1)
  1669. end
  1670. end
  1671. if response.nUserId == app.room:getMyUserId() then
  1672. if response.huType == MJDefine.MJGameHuType.HU_ZIMO then
  1673. -- 自摸时,把最后一张牌去掉,胡牌区
  1674. self.playerHandCards[viewId]:removeLastHandCard();
  1675. -- self.playerHandCards[viewId]:onGetHuCard({huCard});
  1676. self.playerHandCards[viewId]:createHandCards(huCard.huCard, true)
  1677. end
  1678. self.playerHandCards[viewId]:setOutCardEnable(false)
  1679. self:setTingCardVisible(false);
  1680. self.playerHandCards[viewId]:setTing(false)
  1681. self:setButtonTingInfoVisible(false)
  1682. self.playerHandCards[viewId]:lockHandCard();
  1683. -- local specialrule = roomInfo:getGameRuleByKey("specialrule") or 0;
  1684. -- if getNumBand(specialrule, 0x08) > 0 then
  1685. -- self.playerHandCards[viewId]:lockHandCard(true);
  1686. -- end
  1687. -- 胡牌之后,显示听牌按钮,并拉取新的数据
  1688. -- 胡牌之后,不显示听牌按钮,不拉取新的数据
  1689. -- self.ui:sendMsg(app.room,MJDefine.MJEvent.Ting)
  1690. -- self:setButtonTingInfoVisible(true);
  1691. else
  1692. if response.huType == MJDefine.MJGameHuType.HU_ZIMO then
  1693. self.playerHandCards[viewId]:removeLastHandCard();
  1694. local huCard = huCards[#huCards];
  1695. local tmpCard = {
  1696. huCard = huCard.huCard;
  1697. huType = huCard.huType;
  1698. dpSeatId = huCard.dpSeatId;
  1699. };
  1700. if not response.isReplay then
  1701. -- 其他玩家自摸也要显示牌
  1702. -- tmpCard.huCard = 0;
  1703. end
  1704. -- self.playerHandCards[viewId]:onGetHuCard({tmpCard});
  1705. self.playerHandCards[viewId]:createHandCards(huCard.huCard, true)
  1706. end
  1707. -- 其他人胡了倒牌
  1708. local handCards = {}
  1709. for k,v in pairs(self.playerHandCards[viewId]:getHandCardNodes() or {}) do
  1710. table.insert(handCards,{card = v.value or v:getValue()})
  1711. end
  1712. -- if response.huType==MJDefine.MJGameHuType.HU_ZIMO then --如果是自摸胡 把最后一张替换为胡的牌
  1713. -- handCards[#handCards] = {card = response.huCard}
  1714. -- end
  1715. self.playerHandCards[viewId]:removeAllHandCards()
  1716. self.playerHandCards[viewId]:createOpenHandCards(handCards)
  1717. -- self.playerHandCards[viewId]:removeLastHandCard();
  1718. end
  1719. self.playerHandCards[MJDefine.MyViewId]:hideOperate()
  1720. self.playerView:showHu(viewId, true);
  1721. callback();
  1722. end
  1723. self:addCallBack(runHuResponse, 0.5);
  1724. end
  1725. -- 游戏开始
  1726. function yibinmajiangRoomView:onGameStartResponse()
  1727. yibinmajiangRoomView.super.onGameStartResponse(self)
  1728. self._gameoverview = nil
  1729. self:changeGameBg()
  1730. -- self:playGameStartAnim()
  1731. end
  1732. -- 游戏开始动画
  1733. function yibinmajiangRoomView:playGameStartAnim ()
  1734. if self.gameStartAnim then
  1735. self.gameStartAnim = nil;
  1736. end
  1737. -- 整起音效
  1738. local userInfo=app.room:getUserInfoByViewId(MJDefine.MyViewId);
  1739. MJSound.PlayGameStartSound(userInfo.sex)
  1740. local visibleSize = cc.Director:getInstance():getVisibleSize();
  1741. local GameStartAnim = import("mj_yibinmajiang.luaScript.Views.Animation.yibinmajiangGameStartAnimation");
  1742. self.gameStartAnim = GameStartAnim:new();
  1743. self.gameStartAnim:play(nil);
  1744. self:addToLayer("anim", self.gameStartAnim);
  1745. end
  1746. -- 有玩家退出房间
  1747. function yibinmajiangRoomView:onOtherLogoutResponse(data)
  1748. if (not data or not data.nUserId or not data.nSeatShowId) then
  1749. return
  1750. end
  1751. local function test(onEnd)
  1752. self.playerView:updatePlayerInfo(data.nSeatShowId)
  1753. self:onUserReadyResponse()
  1754. --更新GPS
  1755. -- self:updateAllGpsInfo()
  1756. -- self:checkGpsDistance()
  1757. -- 是否显示邀请好友
  1758. self.toolView:updateButton()
  1759. logE("88888-onOtherLogoutResponse onEnd")
  1760. if onEnd then
  1761. onEnd()
  1762. end
  1763. end
  1764. self:addCallBack(test)
  1765. end
  1766. -- 显示飘操作按钮消息
  1767. function yibinmajiangRoomView:onStartPiao(response)
  1768. local function runPiao(onEnd)
  1769. logD("yibinmajiangRoomView:onStartPiao")
  1770. self:showPiao()
  1771. if onEnd then
  1772. onEnd()
  1773. end
  1774. end
  1775. logD("yibinmajiangRoomView:runPiao")
  1776. self:addCallBack(runPiao)
  1777. end
  1778. -- 飘结果消息
  1779. function yibinmajiangRoomView:onPiaoResponse(response)
  1780. local function runonPiaoResponse(onEnd)
  1781. logD("yibinmajiangRoomView:runonPiaoResponse")
  1782. local data = response.response
  1783. local userId = data.nUserId--操作的玩家
  1784. local playersPiaostate = data.playerPiaoState -- 所有玩家的飘状态
  1785. if playersPiaostate then
  1786. for i,v in pairs(playersPiaostate) do
  1787. local viewId = app.room:getViewIdByUserId(v.nUserId)
  1788. local userInfo=app.room:getUserInfoByViewId(viewId)
  1789. self.playerView:showPiao(viewId, v.piaostate == 1)
  1790. if userId == v.nUserId then
  1791. --飘音效
  1792. MJSound.PlayPiaoSound(userInfo.sex, v.piaostate)
  1793. if v.piaostate == 1 then
  1794. local effect = MJAnimationCompnent.CreatePiaoEffect()
  1795. if effect then
  1796. self.ui.Items.Layout_Effect_piao:addChild(effect)
  1797. effect:setLocalZOrder(1000)
  1798. effect:setPosition(self.playerHandCards[viewId]:getAnimationPostion())
  1799. end
  1800. end
  1801. end
  1802. end
  1803. else
  1804. local viewId = app.room:getViewIdByUserId(userId)
  1805. self.playerView:showPiao(viewId,data.piaostate==1)
  1806. if data.piaostate then
  1807. --飘音效
  1808. local userInfo=app.room:getUserInfoByViewId(viewId)
  1809. MJSound.PlayPiaoSound(userInfo.sex, data.piaostate)
  1810. if data.piaostate == 1 then
  1811. local effect = MJAnimationCompnent.CreatePiaoEffect()
  1812. if effect then
  1813. self.ui.Items.Layout_Effect_piao:addChild(effect)
  1814. effect:setLocalZOrder(1000)
  1815. effect:setPosition(self.playerHandCards[viewId]:getAnimationPostion())
  1816. end
  1817. end
  1818. end
  1819. end
  1820. if onEnd then
  1821. onEnd()
  1822. end
  1823. end
  1824. logD("yibinmajiangRoomView:runonPiaoResponse--------")
  1825. self:addCallBack(runonPiaoResponse)
  1826. end
  1827. -- 等待操作
  1828. function yibinmajiangRoomView:onWaitOperate(data)
  1829. if true then
  1830. -- 不需要显示“我要碰”、“我要杠”等操作
  1831. return
  1832. end
  1833. yibinmajiangRoomView.super.onWaitOperate(self, data);
  1834. --等待操作的UID
  1835. local nUserId = data.response.nUserId
  1836. -- 有操作,则不能操作手牌
  1837. local viewId = app.room:getViewIdByUserId(nUserId);
  1838. if viewId == MJDefine.MyViewId and data.response and data.response.opType > 0 then
  1839. self.playerHandCards[viewId]:setOutCardEnable(false);
  1840. end
  1841. end
  1842. -- 改变试图
  1843. function yibinmajiangRoomView:onEventChangeViewType(data)
  1844. MJDefine.MJConfig = MJDefine.loadMJConfig()
  1845. self:changeGameBg(true)
  1846. self.ui:sendMsg(app.room, MJDefine.MJEvent.GetTableInfo);
  1847. end
  1848. -- 开始定缺
  1849. function yibinmajiangRoomView:onDingQueStart(response)
  1850. local function runDingQue(onEnd)
  1851. logD("yibinmajiangRoomView:onDingQueStart")
  1852. self:showDingQue(response)
  1853. if onEnd then
  1854. onEnd()
  1855. end
  1856. end
  1857. logD("yibinmajiangRoomView:runDingQue")
  1858. self:addCallBack(runDingQue, 1.45) -- 因为是与本金动画同时播放的,所以要延迟本金动画的始末时间1.45s
  1859. end
  1860. -- 定缺结果
  1861. function yibinmajiangRoomView:onDingQueResponse(response)
  1862. local function runDingQueResponse(onEnd)
  1863. logD("yibinmajiangRoomView:onDingQueResponse")
  1864. self:showDingQueResult(response)
  1865. if onEnd then
  1866. onEnd()
  1867. end
  1868. end
  1869. logD("yibinmajiangRoomView:runDingQueResponse")
  1870. self:addCallBack(runDingQueResponse)
  1871. end
  1872. -- 开始播放本金动画
  1873. function yibinmajiangRoomView:onBenJinStart(response)
  1874. local function runBenJinStart(onEnd)
  1875. logD("yibinmajiangRoomView:onBenJinStart")
  1876. self:showBenJin(response, true)
  1877. if onEnd then
  1878. onEnd()
  1879. end
  1880. end
  1881. logD("yibinmajiangRoomView:runBenJinStart")
  1882. self:addCallBack(runBenJinStart)
  1883. end
  1884. -- 提操作成功后收到操作
  1885. function yibinmajiangRoomView:onNoticeTiAfterOpResponse(response)
  1886. local function runNoticeTiAfterOp(onEnd)
  1887. local data = response.response
  1888. local nUserId = data.nUserId
  1889. local viewId = app.room:getViewIdByUserId(nUserId)
  1890. local operates = data.operates
  1891. if viewId == MJDefine.MyViewId then
  1892. if operates and table.nums(operates)>0 then
  1893. self.operates = operates
  1894. else
  1895. self.operates = {}
  1896. end
  1897. self.playerHandCards[MJDefine.MyViewId]:setOutCardEnable(true)
  1898. self.playerHandCards[MJDefine.MyViewId]:hideOperateItem()
  1899. self.playerHandCards[MJDefine.MyViewId]:showOperate(operates, nil, true)
  1900. end
  1901. if onEnd then
  1902. onEnd()
  1903. end
  1904. end
  1905. logD("yibinmajiangRoomView:runNoticeTiAfterOp")
  1906. self:addCallBack(runNoticeTiAfterOp)
  1907. end
  1908. -- 游戏消息
  1909. function yibinmajiangRoomView:bindExtendMessage()
  1910. self:bindEvent(app.room, MJDefine.MJEvent.StartPiao, handler(self , self.onStartPiao)) -- 开始飘
  1911. self:bindEvent(app.room, MJDefine.MJEvent.PiaoResponse, handler(self , self.onPiaoResponse)) -- 飘结果
  1912. self:bindEvent(app.room, MJDefine.MJEvent.BenJinStart, handler(self, self.onBenJinStart)) -- 开始本金动画
  1913. self:bindEvent(app.room, MJDefine.MJEvent.DingQueStart, handler(self, self.onDingQueStart)) -- 开始定缺
  1914. self:bindEvent(app.room, MJDefine.MJEvent.DingQueResponse, handler(self, self.onDingQueResponse)) -- 定缺结果
  1915. self:bindEvent(app.room, MJDefine.MJEvent.HuResponse, handler(self , self.onHuResponse)) -- 玩家胡牌
  1916. self:bindEvent(app.room, MJDefine.MJEvent.OutCardTings, handler(self , self.pushTing)) -- 出牌/操作后听操作
  1917. self:bindEvent(app.room, MJDefine.MJEvent.GameRoundStartOperate, handler(self , self.onGameRoundStartOperate)) -- 庄家初始操作
  1918. self:bindEvent(app.room, MJDefine.MJEvent.NoticeTiAfterOp, handler(self, self.onNoticeTiAfterOpResponse))
  1919. -- 待定
  1920. self:bindEvent(app.room, MJDefine.MJEvent.SendGuo, handler(self , self.onSendGuo))
  1921. self:bindEvent(app, MJDefine.MJEvent.ChangeTableBg , handler(self , self.changeGameBg)); --更换桌布
  1922. -- 未定的一些信息,待用
  1923. self:bindEvent(app, MJDefine.MJEvent.ChangeLanguage , handler(self , self.doSound))
  1924. self:bindEvent(app, MJDefine.MJEvent.ChangeChatEnable , handler(self , self.onChangeChatEnable))
  1925. self:bindEvent(app, "applicationWillEnterForeground", handler(self, self.onApplicationWillEnterForeground ))
  1926. self:bindEvent(app, "applicationDidEnterBackground", handler(self, self.onApplicationDidEnterBackground ))
  1927. self:bindEvent(app, MJDefine.MJEvent.ChangeViewType, handler(self, self.onEventChangeViewType))
  1928. self:bindEvent(app.room , MJDefine.MJEvent.QiangDuanOperates, handler(self , self.onQiangDuanOperates))
  1929. end
  1930. function yibinmajiangRoomView:clean()
  1931. self.playerView:init()
  1932. -- --默认状态
  1933. self:defaultState()
  1934. app.room:resetRoomInfo()
  1935. self:setBtnSitDownVisible(false)
  1936. self.ui:sendMsg(app.room, MJDefine.MJEvent.CallReadyRequest)
  1937. --
  1938. self._gameoverview = nil
  1939. end
  1940. function yibinmajiangRoomView:onApplicationWillEnterForeground ()
  1941. end
  1942. function yibinmajiangRoomView:onApplicationDidEnterBackground( )
  1943. end
  1944. -- 抢断操作,因为会收到二次确认消息,所以强制发过给服务端
  1945. function yibinmajiangRoomView:onQiangDuanOperates(data)
  1946. local function runOnQiangDuanOperates(onEnd)
  1947. logD("yibinmajiangRoomView:runOnQiangDuanOperates")
  1948. local response = data.response
  1949. -- if response.operates and self.playerHandCards[MJDefine.MyViewId] then
  1950. -- self.playerHandCards[MJDefine.MyViewId]:showOperate(response.operates)
  1951. -- end
  1952. local card = 0
  1953. if response.operates then
  1954. card = response.operates[1].opCard
  1955. end
  1956. local data = {
  1957. opType = MJDefine.MJOperateType.OPREATE_CANCEL,
  1958. opCard = card,
  1959. useRedNum = 0,
  1960. }
  1961. if self.playerHandCards[MJDefine.MyViewId] then
  1962. self.playerHandCards[MJDefine.MyViewId]:sendOp(data)
  1963. end
  1964. -- 强制发过给服务端
  1965. if onEnd then
  1966. onEnd()
  1967. end
  1968. end
  1969. logD("yibinmajiangRoomView:onQiangDuanOperates")
  1970. self:addCallBack(runOnQiangDuanOperates)
  1971. end
  1972. return yibinmajiangRoomView