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.

2539 lines
86 KiB

  1. require("luaScript.Views.Room.RoomFunctions")
  2. local MJRoomToolView=MJFramework.MJImport("mj.luaScript.Views.Room.MJRoomToolView")
  3. local MJRoomMessageView=MJFramework.MJImport("mj.luaScript.Views.Room.MJRoomMessageView")
  4. local MJRoomPlayerView=MJFramework.MJImport("mj.luaScript.Views.Room.MJRoomPlayerView")
  5. local MJDefine=MJFramework.MJImport("mj.luaScript.MJDefine")
  6. local MJHandCardView=MJFramework.MJImport("mj.luaScript.Views.Game.MJHandCardView")
  7. local MJRoomXiaoJuView=MJFramework.MJImport("mj.luaScript.Views.Room.MJRoomXiaoJuView")
  8. local MJRoomDaJuView=MJFramework.MJImport("mj.luaScript.Views.Room.MJRoomDaJuView")
  9. local MJRoomDismissView=MJFramework.MJImport("mj.luaScript.Views.Room.MJRoomDismissView")
  10. local MJRoomDirection=MJFramework.MJImport("mj.luaScript.Views.Room.MJRoomDirection")
  11. local MJMessage=MJFramework.MJImport("mj.luaScript.Protocol.MJMessage")
  12. local MJ=MJFramework.MJImport("mj.luaScript.Views.Game.MJ")
  13. local MJWanFa=MJFramework.ImportWanFa("luaScript.SubGameDefine.MaJiang.MJWanFa")
  14. local MJAnimationCompnent=MJFramework.MJImport("mj.luaScript.Views.Compnent.MJAnimationCompnent")
  15. local MJFunction=MJFramework.MJImport("mj.luaScript.MJFunction")
  16. local MJSound = MJFramework.MJImport("mj.luaScript.MJSound")
  17. local MJRoomView = MJFramework.MJFrameworkClassImprot("mj.luaScript.Views.Room.MJRoomView")
  18. local linshuiRoomView = class("linshuiRoomView", MJRoomView)
  19. local zhongNiaoTime=1.33
  20. local HU_EFFECT_TAG = 100
  21. function linshuiRoomView:ctor()
  22. linshuiRoomView.super.ctor(self)
  23. self.operates = {}
  24. if app.systemSetting.info.viewType == MJDefine.DesktopType.TwoD then -- viewType只保存2d 3d类型 mj_desktop_2d_mjType保存2d麻将类型
  25. local value = loadUserInfo("mj_linshui_desktop_2d_mjType")
  26. if value=="" or not value then
  27. value = MJDefine.DesktopType.TwoDL
  28. saveUserInfo("mj_linshui_desktop_2d_mjType", value)
  29. end
  30. self.desktopType = value
  31. else
  32. self.desktopType = app.systemSetting.info.viewType
  33. end
  34. MJDefine.MJConfig = MJDefine.loadMJConfig(self.desktopType)
  35. end
  36. function linshuiRoomView:loadUi()
  37. local ui = loadUI("mj_linshui/res/ui_fangjian/mj_linshui_roomView.ui")
  38. self.ui = ui
  39. self:addChild(ui)
  40. end
  41. function linshuiRoomView:onEnter()
  42. linshuiRoomView.super.onEnter(self)
  43. -- 初始化听牌组件
  44. self:initTingCardView();
  45. -- 初始化听牌按钮,动态创建的
  46. self:initTingBtnView();
  47. self:setButtonTingInfoVisible(false);
  48. --获取是否贴鬼杠和是否自动对齐
  49. self:setCheckDefault()
  50. self:doSound()
  51. end
  52. function linshuiRoomView:onExit()
  53. linshuiRoomView.super.onExit(self)
  54. self:cleanCache()
  55. end
  56. function linshuiRoomView:cleanCache()
  57. local preload = package.loaded
  58. for k, v in pairs(package.loaded or {}) do
  59. local res1 = string.find( k, "mj.luaScript") or 0
  60. local res2 = string.find( k, "mj_linshui.luaScript") or 0
  61. if res1 > 0 or res2 > 0 then
  62. package.loaded[k] = nil
  63. end
  64. end
  65. local temp = {
  66. "mj/res/ui/zy_fangjian/mj.plist",
  67. "mj/res/ui/zy_fangjian/mahjong/mj_2d_cards.plist",
  68. "mj/res/ui/zy_fangjian/mj_2d.plist",
  69. "mj/res/ui/zy_fangjian/mahjong/mj_3d_cards_1.plist",
  70. "mj/res/ui/zy_fangjian/mahjong/mj_3d_cards_2.plist",
  71. "mj/res/ui/zy_fangjian/mj_2d_gold.plist",
  72. "mj/res/ui/zy_fangjian/mahjong/mj_2d_cards_l.plist",
  73. "mj_linshui/res/zy_fangjian/mj_2d_cards.plist",
  74. "mj_linshui/res/zy_fangjian/mj_2d_gold.plist",
  75. "mj_linshui/res/zy_fangjian/mj_2d_lgold.plist",
  76. }
  77. -- 删除缓存,防止与其他麻将资源混淆(例如南充麻将的墨绿大麻将和邻水麻将的金黄大麻将)
  78. for i, v in ipairs(temp) do
  79. cc.SpriteFrameCache:getInstance():removeSpriteFramesFromFile(v)
  80. end
  81. end
  82. function linshuiRoomView:doSound()--1 普通话 2 方言
  83. local cacheLan = "mj_language"..(GAME_IDS.linshuiMJ or MJDefine.GameID)
  84. --saveUserInfo(cacheLan,1)--恒定为普通话
  85. local defaultValue = tonumber(loadUserInfo(cacheLan)) or 2
  86. saveUserInfo(cacheLan,defaultValue)
  87. logD("doSound:"..defaultValue.." "..cacheLan)
  88. MJSound.setSoundType(defaultValue)
  89. end
  90. function linshuiRoomView:setCheckDefault()
  91. MJDefine.isAutomatic = true
  92. end
  93. -- 一键截屏
  94. function linshuiRoomView:onClickButtonShot( sender )
  95. playBtnEffect()
  96. showScreenShot()
  97. end
  98. --隐藏俱乐部
  99. function linshuiRoomView:hideClub()
  100. -- self.ui.Items.Button_Club:setVisible(false)
  101. if self.clubView and not tolua.isnull(self.clubView) then
  102. self.clubView:removeFromParent()
  103. self.clubView=nil
  104. end
  105. end
  106. --更换桌布(同维度)
  107. function linshuiRoomView:changeGameBg(isUpdateViewType)
  108. if isUpdateViewType then
  109. if app.systemSetting.info.viewType == MJDefine.DesktopType.TwoD then --更新2D麻将类型 金色还是绿色
  110. local value = loadUserInfo("mj_linshui_desktop_2d_mjType") --or MJDefine.DesktopType.TwoD
  111. if value=="" or not value then
  112. value = MJDefine.DesktopType.TwoDL
  113. saveUserInfo("mj_linshui_desktop_2d_mjType", value)
  114. end
  115. logD("changeGameBg value:"..value)
  116. self.desktopType = value
  117. else
  118. self.desktopType = app.systemSetting.info.viewType
  119. end
  120. self:loadTextureCache()
  121. logD("changeGameBg"..self.desktopType)
  122. end
  123. local defaultValue = tonumber(loadUserInfo("linshui_mj_desktop_group")) or 3
  124. local bgData = MJDefine.CHANGE_GAME_BG[defaultValue]
  125. if self.desktopType==MJDefine.DesktopType.TwoD or self.desktopType==MJDefine.DesktopType.TwoDGold or self.desktopType==MJDefine.DesktopType.TwoDL then
  126. self.ui.Items.ImageView_bg:loadTexture(bgData['2d'])
  127. else
  128. self.ui.Items.ImageView_bg:loadTexture(bgData['3d'])
  129. end
  130. end
  131. function linshuiRoomView:defaultState()
  132. --队列初始化
  133. self.callbackQueue = {}
  134. self.callbackRunning = false
  135. self.playerView:setOffLineVisible(false)
  136. self.playerView:setPlayerVisible(false)
  137. if self.waitOperates and #self.waitOperates>0 then
  138. for k,v in pairs(self.waitOperates) do
  139. v:removeFromParent()
  140. end
  141. end
  142. self.waitOperates = {}
  143. self:resetGame()
  144. end
  145. function linshuiRoomView:loadTextureCache()
  146. linshuiRoomView.super.loadTextureCache(self)
  147. -- local defaultValue = tonumber(loadUserInfo("luzhou_mj_majhong")) or 1
  148. loadSpriteFrameFile("mj_linshui/res/zy_fangjian/mj_operateEffect.plist")
  149. loadSpriteFrameFile("mj_linshui/res/zy_fangjian/effect_guafeng.plist")
  150. loadSpriteFrameFile("mj_linshui/res/zy_fangjian/effect_xiayu.plist")
  151. end
  152. function linshuiRoomView:initGameButton()
  153. --点击空白
  154. self.ui.Items.Layout_Touch:registerClick(nil,function()
  155. -- 隐藏个人信息
  156. self.playerView:removePlayerInfoView()
  157. self.toolView:setMenuVisible(false)
  158. if self.playerHandCards[MJDefine.MyViewId] then
  159. self.playerHandCards[MJDefine.MyViewId]:hideOperateItem()
  160. end
  161. self.toolView:hideRule()
  162. self:setTingCardVisible(false);
  163. self:setTingCardViewVisible(false);
  164. end)
  165. --隐藏听牌模板
  166. self.ui.Items.Item_Ting:setVisible(false)
  167. --self.ui.Items.Button_Ting_Info:setVisible(false);
  168. --self.ui.Items.Button_Ting_Info:registerClick(handler(self, self.onBtnTingInfoClicked))
  169. self.toolView.ui.Items.Button_Face:setPosition(cc.p(1208*g_radio_x,(322+25)*g_radio_y))
  170. self.toolView.ui.Items.Button_Voice:setPosition(cc.p(1208*g_radio_x,(237+30)*g_radio_y))
  171. end
  172. --通知庄家可以爆牌
  173. function linshuiRoomView:onBankerBaoPai(data)
  174. local function runBankerBaoPai(onEnd)
  175. local myUserId = app.room:getMyUserId()
  176. local viewId = app.room:getViewIdByUserId(myUserId)
  177. if data.response.nUserId == myUserId then
  178. self:showBaoJiao()
  179. self.playerHandCards[viewId]:setOutCardEnable(false)
  180. end
  181. if onEnd then
  182. onEnd()
  183. end
  184. end
  185. self:addCallBack(runBankerBaoPai)
  186. end
  187. --广播玩家爆牌
  188. function linshuiRoomView:onBaoPai(data)
  189. local myUserId = app.room:getMyUserId()
  190. if data.response.isBaoPai == 1 then
  191. local effect=MJAnimationCompnent.CreateBaoEffect()
  192. local viewId = app.room:getViewIdByUserId(data.response.nUserId)
  193. local userInfo=app.room:getUserInfoByViewId(viewId)
  194. --爆牌音效
  195. MJSound.PlayBaoSound(userInfo.sex)
  196. if effect then
  197. self.ui.Items.Layout_Player:addChild(effect)
  198. effect:setLocalZOrder(1000)
  199. effect:setPosition(self.playerHandCards[viewId]:getAnimationPostion())
  200. end
  201. if myUserId == data.response.nUserId then
  202. --self.playerHandCards[viewId]:lockHandCard(true)
  203. self.playerHandCards[viewId]:setBaoPai(1)
  204. -- self.playerHandCards[viewId]:setOutCardEnable(false)
  205. else
  206. --self.playerHandCards[viewId]:setOutCardEnable(true)
  207. end
  208. self.playerHandCards[viewId]:setOutCardEnable(true)
  209. self.playerView:playBaoAnim(viewId)
  210. elseif data.response.isBaoPai == 2 then--博自摸
  211. local effect=MJAnimationCompnent.CreateBoZiMoEffect()
  212. local viewId = app.room:getViewIdByUserId(data.response.nUserId)
  213. local myUserId = app.room:getMyUserId()
  214. local userInfo=app.room:getUserInfoByViewId(viewId)
  215. --爆牌音效
  216. MJSound.PlayBaoSound(userInfo.sex)
  217. if effect then
  218. self.ui.Items.Layout_Player:addChild(effect)
  219. effect:setLocalZOrder(1000)
  220. effect:setPosition(self.playerHandCards[viewId]:getAnimationPostion())
  221. end
  222. if myUserId == data.response.nUserId then
  223. self.playerHandCards[viewId]:lockHandCard(true)
  224. else
  225. end
  226. self.playerView:showBoZiMo(viewId,true)
  227. elseif self.reShowBao and self.reShowBao == true then--过爆
  228. self.guobao = true--重连过爆要显示打出的第一张牌
  229. end
  230. if myUserId == data.response.nUserId then--报牌后可以躺
  231. self.playerHandCards[MJDefine.MyViewId]:showOperate(data.response.operates)
  232. self.playerHandCards[MJDefine.MyViewId]:setOutCardEnable(true)
  233. end
  234. if app.room:getMyUserId() == data.response.nUserId then
  235. self:hideBaoJiao()
  236. end
  237. --[[if app.room:getMyUserId() == data.response.nUserId and (data.response.isBaoPai == 1 or data.response.isBaoPai == 2) then
  238. local gameInfo =json.decode(app.room.roomInfo.strGameInfo);
  239. --if gameInfo.tingpai > 0 then
  240. --self.ui.Items.Button_Ting_Info:setVisible(true);
  241. self:setButtonTingInfoVisible(true)
  242. app.room.roomInfo.memberList[data.response.nUserId].nTingStatus = MJDefine.MJTingStatus.Ting;
  243. self.ui:sendMsg(app.room, MJDefine.MJEvent.Ting)
  244. self.isTing = true;
  245. --end
  246. end--]]
  247. end
  248. function linshuiRoomView:onGameSendCardResponse()
  249. --发牌的时候清除桌面上的飘
  250. self.ui.Items.Layout_Effect_luobo:removeAllChildren()
  251. local function runGameSendCardResponse(onEnd)
  252. log("2000000000-linshuiRoomView - runGameSendCardResponse()" )
  253. self:hidePiao()
  254. local myUserId = app.room:getMyUserId()
  255. for k,v in pairs(app.room.roomInfo.memberList) do
  256. local viewId = app.room:getViewIdByUserId(v.nUserId)
  257. if self.playerHandCards[viewId] then
  258. self.playerHandCards[viewId]:createHandCards(v.handCards)
  259. self.playerHandCards[viewId]:resetHandCards()
  260. end
  261. if v.isBaoPai == 1 and myUserId == v.nUserId then
  262. --self.playerHandCards[viewId]:showBaoPai()
  263. self:showBaoJiao()
  264. end
  265. end
  266. self.playerHandCards[MJDefine.MyViewId]:initSwapCardTouchEvent()
  267. MJAnimationCompnent.CreateStartSendCards(self.playerHandCards,onEnd)
  268. self.isTang = false
  269. -- if onEnd then
  270. -- onEnd()
  271. -- end
  272. self.toolView:showTuoGuan(app.room.roomInfo.hosting==1)
  273. self:doSound()
  274. --每次发牌检测一次是否牌出去了,需要重连解决一下
  275. self:checkIsNeddAdapt()
  276. end
  277. log("2000000000-linshuiRoomView - addCallBack(runGameSendCardResponse)" )
  278. self:addCallBack(runGameSendCardResponse);
  279. end
  280. function linshuiRoomView:checkIsNeddAdapt()
  281. log("linshuiRoomView:checkIsNeddAdapt" )
  282. local callFunc = function(onEnd)
  283. if self.playerHandCards[MJDefine.MyViewId].isUseNew3D then
  284. if self.playerHandCards[MJDefine.MyViewId]:isUseNew3D() then
  285. MJDefine.loadMJConfig(self.desktopType)
  286. end
  287. end
  288. self:requestReconnect()
  289. if onEnd then
  290. onEnd()
  291. end
  292. end
  293. local winSize = cc.Director:getInstance():getWinSize()
  294. for i, v in pairs(self.playerHandCards) do
  295. log("v:getHandCardPosInitY = "..v:getHandCardPosInitY().." winSize.height = "..winSize.height )
  296. if v:getHandCardPosInitY() > winSize.height then
  297. self:addCallBack(callFunc)
  298. break
  299. end
  300. end
  301. end
  302. function linshuiRoomView:onUserReadyResponse(response)
  303. linshuiRoomView.super.onUserReadyResponse(self,response)
  304. local myUserId = app.room:getMyUserId()
  305. if response and response.nUserId==myUserId then
  306. self.playerView:clearBao()
  307. self.playerView:clearAllPiao()
  308. --self.playerView:clearAllBoZiMo()
  309. self.playerView:clearAllQue()
  310. self.playerView:clearAllHuOrder()
  311. self:setTingCardVisible(false);
  312. self:setTingCardViewVisible(false);
  313. if self.playerHandCards[MJDefine.MyViewId] then
  314. self.playerHandCards[MJDefine.MyViewId]:setQueType(-1)--设置缺牌类型为空
  315. end
  316. app.room.roomInfo.luoboCards = nil
  317. -- local roomInfo = app.room.roomInfo
  318. -- for k,v in pairs(roomInfo.memberList) do
  319. -- self.ui.Items.Layout_Player:removeChildByTag(HU_EFFECT_TAG)
  320. -- end
  321. end
  322. --self.ui.Items.Button_Ting_Info:setVisible(false);
  323. self:setButtonTingInfoVisible(false)
  324. end
  325. -- 广播桌子上所有玩家庄家起手操作 这里其实是发牌
  326. function linshuiRoomView:onBankerOutCard(data)
  327. --[[ -- 庄家uid
  328. , defVar("nUserId", VT_Int, 0)
  329. -- 庄家操作类型
  330. , defVar("mainOpCode", VT_Short, 0)
  331. --庄家是否需要出牌0不需要 1:需要
  332. , defVar("IsShouldOutCard", VT_UChar, 0)--]]
  333. local function runOnBankerOutCard(onEnd)
  334. logE("linshuiRoomView onBankerOutCard :"..table.tostring(data.response))
  335. -- if not data.response.nUserId then
  336. -- showTooltip("庄家起手操作nUserId is not exist")
  337. -- end
  338. local viewId = app.room:getViewIdByUserId(data.response.nUserId)
  339. local card= data.response.card
  340. local operates=data.response.operates
  341. local nSeatId=data.response.nSeatId
  342. -- app.room.roomInfo.outCardUserId = data.response.nUserId
  343. if self.playerHandCards[viewId] then
  344. self.playerHandCards[viewId]:onGetCard(operates,card)
  345. end
  346. --检测定缺牌
  347. self.playerHandCards[MJDefine.MyViewId]:checkQueAndDisableOtherCard()
  348. --先清除所有操作按钮
  349. --self.playerHandCards[MJDefine.MyViewId]:hideOperate()
  350. self.playerHandCards[MJDefine.MyViewId]:hideOperateItem()
  351. self.playerHandCards[MJDefine.MyViewId]:showOperate(operates,card,true)
  352. if viewId == MJDefine.MyViewId then
  353. --self.ui.Items.Button_Ting_Info:setVisible(false)
  354. self:setButtonTingInfoVisible(false)
  355. if operates and table.nums(operates)>0 then
  356. self.operates = operates
  357. else
  358. self.operates = {}
  359. end
  360. if self.playerHandCards[MJDefine.MyViewId] then
  361. self.playerHandCards[MJDefine.MyViewId]:setTing(false)
  362. local player = app.room.roomInfo.memberList[data.response.nUserId]
  363. if player and player.isBaoPai==1 then
  364. --self.playerHandCards[MJDefine.MyViewId]:lockHandCard(true)
  365. end
  366. end
  367. app.room:dispatchEvent({name = MJDefine.MJEvent.SelectCard})
  368. app.room:dispatchEvent({name = MJDefine.MJEvent.PushTing})
  369. -- app.room:dispatchEvent({name = MJDefine.MJEvent.ShowTing})
  370. end
  371. -- local myUserId = app.room:getMyUserId()
  372. -- if data.response.nUserId == myUserId then
  373. -- if self.playerHandCards[MJDefine.MyViewId] then
  374. -- self.playerHandCards[MJDefine.MyViewId]:pushTing()
  375. -- end
  376. -- end
  377. self:updateGameNums()
  378. self.direcionView:updateDirection(nSeatId)
  379. if onEnd then
  380. onEnd()
  381. end
  382. end
  383. log("2000000000-linshuiRoomView - addCallBack(runOnBankerOutCard)")
  384. self:addCallBack(runOnBankerOutCard);
  385. end
  386. function linshuiRoomView:onAfterDingQue(data)
  387. local function runOnAfterDingQue(onEnd)
  388. logE("linshuiRoomView onAfterDingQue :"..table.tostring(data.response))
  389. local viewId = app.room:getViewIdByUserId(data.response.nUserId)
  390. local card= data.response.card
  391. local operates=data.response.operates
  392. local nSeatId=data.response.nSeatId
  393. self.playerHandCards[MJDefine.MyViewId]:hideOperateItem()
  394. self.playerHandCards[MJDefine.MyViewId]:showOperate(operates,card,true)
  395. if viewId == MJDefine.MyViewId then
  396. --self.ui.Items.Button_Ting_Info:setVisible(false)
  397. self:setButtonTingInfoVisible(false)
  398. if operates and table.nums(operates)>0 then
  399. self.operates = operates
  400. local isCanHu = false
  401. for k,v in pairs(operates.Datas) do
  402. if (v.opType == MJDefine.MJOperateType.OPREATE_DIANPAOHU) or (v.opType == MJDefine.MJOperateType.OPREATE_ZIMOHU) then
  403. isCanHu = true
  404. break
  405. end
  406. end
  407. if isCanHu == true then
  408. self.playerHandCards[MJDefine.MyViewId]:setOutCardEnable(false)
  409. else
  410. self.playerHandCards[MJDefine.MyViewId]:setOutCardEnable(true)
  411. end
  412. else
  413. self.playerHandCards[MJDefine.MyViewId]:setOutCardEnable(true)
  414. self.operates = {}
  415. end
  416. if self.playerHandCards[MJDefine.MyViewId] then
  417. self.playerHandCards[MJDefine.MyViewId]:setTing(false)
  418. end
  419. app.room:dispatchEvent({name = MJDefine.MJEvent.SelectCard})
  420. app.room:dispatchEvent({name = MJDefine.MJEvent.PushTing})
  421. end
  422. self:updateGameNums()
  423. self.direcionView:updateDirection(nSeatId)
  424. self.playerHandCards[MJDefine.MyViewId]:checkQueAndDisableOtherCard()
  425. self.playerHandCards[MJDefine.MyViewId]:initTouchEvent()
  426. if onEnd then
  427. onEnd()
  428. end
  429. end
  430. self:addCallBack(runOnAfterDingQue)
  431. end
  432. function linshuiRoomView:onTurnOutCard(data)
  433. local function runOnTurnOutCard(onEnd)
  434. logE("MJRoomView:runOnOutCard(), response = ", table.tostring(data.response))
  435. log("2000000000-MJRoomView - runOnOutCard")
  436. if app.room.roomInfo.lastOutViewId~=MJDefine.MyViewId then
  437. self.playerHandCards[MJDefine.MyViewId]:setOutCardEnable(true)
  438. end
  439. -- local viewId = app.room:getViewIdByUserId(data.response.nUserId)
  440. -- local card= data.response.card
  441. -- if self.playerHandCards[viewId] then
  442. -- self.playerHandCards[viewId]:createOutCards(card)
  443. -- end
  444. if onEnd then
  445. onEnd()
  446. end
  447. end
  448. log("2000000000-MJRoomView - addCallBack(runOnTurnOutCard)")
  449. self:addCallBack(runOnTurnOutCard)
  450. end
  451. --出牌成功
  452. function linshuiRoomView:onOutCardSuccess(data)
  453. logE("linshuiRoomView:onOutCardSuccess(), response = ", table.tostring(data.response))
  454. local function runOnOutCardSuccess(onEnd)
  455. log("2000000000-linshuiRoomView - runOnOutCardSuccess---------")
  456. -- app.room.roomInfo.outCardUserId = data.response.nUserId
  457. local viewId = app.room:getViewIdByUserId(data.response.nUserId)
  458. local card= data.response.card
  459. local operates=data.response.operates
  460. local typr = operates.opType
  461. if operates and table.nums(operates)>0 then
  462. self.operates = operates
  463. else
  464. self.operates = {}
  465. end
  466. local function callback()
  467. -- app.room.roomInfo.lastOutViewId = nil
  468. self.playerHandCards[MJDefine.MyViewId]:showOperate(operates,card)
  469. self.playerHandCards[MJDefine.MyViewId]:checkQueAndDisableOtherCard()
  470. --self.playerHandCards[MJDefine.MyViewId]:checkBaoAndDisableCard()
  471. self.playerHandCards[MJDefine.MyViewId]:setTing(false)
  472. if onEnd then
  473. onEnd()
  474. end
  475. end
  476. -- self.lastOutCard = card
  477. if self.playerHandCards[viewId] then
  478. --(viewId~=MJDefine.MyViewId or player.isBaoPai == 1) and app.room.roomInfo.lastOutViewId~=MJDefine.MyViewId
  479. if viewId==MJDefine.MyViewId then
  480. local player = app.room.roomInfo.memberList[data.response.nUserId]
  481. local function doOutCard(viewId, card, callback)
  482. self.playerHandCards[viewId]:onOutCard(card,callback)
  483. --音效
  484. local userInfo=app.room:getUserInfoByViewId(viewId)
  485. if userInfo then
  486. MJSound.PlayMJSound(userInfo.sex,card)
  487. end
  488. end
  489. self.playerHandCards[viewId]:setTing(false)
  490. --点击爆牌的时候 前端已经打出牌 要判断上次出牌的人是不是自己 避免重复出牌
  491. if ((player.isBaoPai==1 or player.isBaoPai==2 or (self.isTang and self.isTang == true) or (self.guobao and self.guobao == true))
  492. and app.room.roomInfo.lastOutViewId~=MJDefine.MyViewId) then
  493. self.guobao = nil
  494. doOutCard(viewId, card, callback)
  495. elseif app.room.roomInfo.hosting == 1 then
  496. -- 托管状态下
  497. doOutCard(viewId, card, callback)
  498. elseif self.needDeleteOutCard and true == self.needDeleteOutCard then
  499. self.needDeleteOutCard = nil
  500. uploadLogs("mjduopai")
  501. doOutCard(viewId, card, callback)
  502. else
  503. callback()
  504. end
  505. local gameInfo = json.decode(app.room.roomInfo.strGameInfo);
  506. --if gameInfo.tingpai > 0 then
  507. self._isOutCardTingCheck = true;
  508. self.ui:sendMsg(app.room,MJDefine.MJEvent.Ting)
  509. --end
  510. else
  511. self.playerHandCards[viewId]:onOutCard(card,callback)
  512. end
  513. app.room:dispatchEvent({name = MJDefine.MJEvent.OutCardFalg, value=card ,viewId=viewId})
  514. else
  515. callback()
  516. end
  517. app.room.roomInfo.lastOutViewId = viewId
  518. end
  519. log("2000000000-linshuiRoomView - addCallBack(runOnOutCardSuccess)")
  520. self:addCallBack(runOnOutCardSuccess)
  521. end
  522. function linshuiRoomView:onOutCard(data)
  523. local function runOnOutCard(onEnd)
  524. if app.room:getViewIdByUserId(data.response.nUserId) == MJDefine.MyViewId then
  525. --[[
  526. --隐藏听牌
  527. self:setTingCardViewVisible(false)
  528. --显示查听
  529. if app.room.roomInfo.tings then
  530. for k,v in pairs(app.room.roomInfo.tings) do
  531. if tonumber(k) == data.response.card then
  532. self:setChaTingCardViewVisible(true)
  533. break
  534. end
  535. end
  536. end
  537. ]]
  538. --如果是托管状态需要删除一次手牌
  539. if app.room.roomInfo.hosting == 1 and data.response.card and tonumber(data.response.card) ~= 0 then
  540. local viewId = app.room:getViewIdByUserId(data.response.nUserId)
  541. local card = data.response.card
  542. if viewId == MJDefine.MyViewId then
  543. self.playerHandCards[viewId]:setTing(false)
  544. self.playerHandCards[viewId]:onOutCard(data.response.card,nil,true)
  545. app.room:dispatchEvent({name = MJDefine.MJEvent.OutCardFalg, value = card ,viewId = viewId})
  546. end
  547. end
  548. end
  549. if onEnd then
  550. onEnd()
  551. end
  552. end
  553. self:addCallBack(runOnOutCard)
  554. end
  555. --已经发送了过操作,此时就算再勾选贴鬼碰,也不会显示操作
  556. function linshuiRoomView:onSendGuo()
  557. --发牌重置,主要用于贴鬼碰/杠
  558. MJDefine.isSendGuo = false
  559. self.operates = {}
  560. end
  561. -- 操作成功
  562. function linshuiRoomView:onOperationCodeSuccess(data)
  563. local function runOnOperationSuccess(onEnd)
  564. local response = data.response
  565. local nUserId = response.nUserId
  566. local opType = response.opType
  567. local opCard = response.opCard
  568. local bIsOutCard = response.isNeedOutCard > 0
  569. local fromSeatId = response.fromSeatId
  570. local isNeedTang = response.isNeedTang or 0
  571. local redNum = 0 or response.redNum
  572. local viewId = app.room:getViewIdByUserId(nUserId)
  573. local fromViewId = app.room:getViewIdBySeatId(fromSeatId)
  574. local opSeatId = app.room:getSeatIdByViewId(viewId)
  575. local fromUserId = app.room:getUserIdBySeatId(fromSeatId)
  576. -- 是否是胡牌一起的操作 1是 0不是 (1时不需要清掉出牌区域的牌)
  577. local huAndOpreate = response.huAndOpreate
  578. logD('是否是胡牌一起的操作', huAndOpreate)
  579. if self.playerHandCards[viewId] then
  580. --组合一下牌
  581. local groups={
  582. self:getChangeGruopDatas({opType=opType, opCard=opCard, redNum = redNum, targetSeatId=opSeatId, opUserId=fromUserId})
  583. }
  584. --删除手中对应的牌
  585. local deleteCards
  586. for k,v in pairs(groups) do
  587. if v.showType==MJDefine.MJGroupType.Peng then
  588. self.playerHandCards[viewId]:removeHandCardByNum(opCard,2,v.redNum)
  589. elseif v.showType==MJDefine.MJGroupType.Chi then
  590. --TODO:吃的牌删除两张
  591. elseif v.showType==MJDefine.MJGroupType.AnGang
  592. or v.showType==MJDefine.MJGroupType.MAnGang then
  593. self.playerHandCards[viewId]:removeHandCardByNum(opCard,4,v.redNum)
  594. else
  595. if opType==MJDefine.MJOperateType.OPREATE_BAGANG then
  596. self.playerHandCards[viewId]:removeHandCardByNum(opCard,1,v.redNum)
  597. else
  598. self.playerHandCards[viewId]:removeHandCardByNum(opCard,3,v.redNum)
  599. end
  600. end
  601. end
  602. --删除出去的牌 遍历哪些操作需要删除牌
  603. for k,v in pairs(MJDefine.MJOperateNeedRemoveCard) do
  604. if v==opType and huAndOpreate == 0 then
  605. self.playerHandCards[fromViewId]:removeOutCard(opCard)
  606. break
  607. end
  608. end
  609. if opType==MJDefine.MJOperateType.OPREATE_BAGANG then
  610. self.playerHandCards[viewId]:buGang(opCard,redNum)
  611. else
  612. self.playerHandCards[viewId]:createGroupCards(groups)--创建显示的牌
  613. end
  614. self.playerHandCards[viewId]:resetHandCards()
  615. self.playerHandCards[viewId]:hideOperate()
  616. self.playerHandCards[viewId]:setOutCardEnable(bIsOutCard)
  617. self.direcionView:updateDirection(app.room:getSeatIdByViewId(viewId))
  618. end
  619. local function guafengxiayuEffect()
  620. local effect
  621. if (opType==MJDefine.MJOperateType.OPREATE_ZHIGANG) or (opType==MJDefine.MJOperateType.OPREATE_BAGANG) or
  622. (opType==MJDefine.MJOperateType.OPREATE_MINGGANG) then
  623. effect=MJAnimationCompnent.createGuaFengEffect()
  624. MJSound.PlayWindSound()
  625. elseif (opType==MJDefine.MJOperateType.OPREATE_ANGANG) then
  626. effect=MJAnimationCompnent.createXiaYuEffect()
  627. MJSound.PlayRainSound()
  628. end
  629. if effect then
  630. self.ui.Items.Layout_Player:addChild(effect)
  631. effect:setLocalZOrder(1000)
  632. effect:setPosition(self.playerHandCards[viewId]:getAnimationPostion())
  633. end
  634. end
  635. --[[if (opType==MJDefine.MJOperateType.OPREATE_ZHIGANG) or (opType==MJDefine.MJOperateType.OPREATE_BAGANG) or
  636. (opType==MJDefine.MJOperateType.OPREATE_MINGGANG) or (opType==MJDefine.MJOperateType.OPREATE_ANGANG) then
  637. guafengxiayuEffect()
  638. else--]]
  639. --播放动画
  640. local effect=MJAnimationCompnent.CreateOperareEffect(opType)--,onEnd)
  641. if effect then
  642. self.ui.Items.Layout_Player:addChild(effect)
  643. effect:setLocalZOrder(1000)
  644. effect:setPosition(self.playerHandCards[viewId]:getAnimationPostion())
  645. -- else
  646. -- if onEnd then
  647. -- onEnd()
  648. -- end
  649. end
  650. --end
  651. --音效
  652. local userInfo=app.room:getUserInfo(nUserId)
  653. if userInfo then
  654. MJSound.PlayOperateSound(userInfo.sex,opType)
  655. end
  656. if viewId == MJDefine.MyViewId then
  657. self.playerHandCards[MJDefine.MyViewId]:setTing(false)
  658. self:setTingCardViewVisible(false)
  659. --self.ui.Items.Button_Ting_Info:setVisible(false)
  660. self:setButtonTingInfoVisible(false)
  661. self.operates={}
  662. --碰等操作后检查定缺牌
  663. self.playerHandCards[MJDefine.MyViewId]:checkQueAndDisableOtherCard()
  664. --self.playerHandCards[MJDefine.MyViewId]:checkBaoAndDisableCard()
  665. end
  666. --删除等待操作的显示
  667. if self.waitOperates and #self.waitOperates>0 then
  668. for k,v in pairs(self.waitOperates) do
  669. v:removeFromParent()
  670. end
  671. self.waitOperates={}
  672. end
  673. --[[if viewId == MJDefine.MyViewId and opType==MJDefine.MJOperateType.OPREATE_PENG then
  674. local cards = {opCard}
  675. self.playerHandCards[viewId]:cardEnabled(cards, true)
  676. end--]]
  677. -- 取消操作按钮
  678. self.playerHandCards[MJDefine.MyViewId]:hideOperate()
  679. if onEnd then
  680. onEnd()
  681. end
  682. end
  683. self:addCallBack(runOnOperationSuccess)
  684. end
  685. function linshuiRoomView:test()
  686. self.playerHandCards={}
  687. self.playerHandCards[MJDefine.MyViewId] = MJHandCardView:new(MJDefine.MyViewId)
  688. self:addChild(self.playerHandCards[MJDefine.MyViewId])
  689. self.playerView = MJRoomPlayerView:new()
  690. self:addChild(self.playerView)
  691. end
  692. --飘状态停止
  693. function linshuiRoomView:stopDirection()
  694. self.direcionView:stopAllActions()
  695. self.direcionView.ui.Items.ImageView_Dir_Down:setVisible(false)
  696. self.direcionView.ui.Items.ImageView_Dir_Up:setVisible(false)
  697. self.direcionView.ui.Items.ImageView_Dir_Left:setVisible(false)
  698. self.direcionView.ui.Items.ImageView_Dir_Right:setVisible(false)
  699. self.direcionView.ui.Items.Text_Time:setString(string.format("%02d",0))
  700. --self.direcionView.ui.Items.Text_Leave_Card_Num:setText("72")
  701. end
  702. function linshuiRoomView:onGameReconnection()
  703. linshuiRoomView.super.onGameReconnection(self)
  704. self:doSound()
  705. local roomInfo = app.room.roomInfo
  706. local gameInfo=json.decode(roomInfo.strGameInfo)
  707. local piaoMode = gameInfo.piaomode
  708. local isDingQue = getNumBand(gameInfo.specRule, 0x0004)>0
  709. local myUserId = app.room:getMyUserId()
  710. -- 托管状态恢复
  711. for k,v in pairs(roomInfo.hostInfos or {}) do
  712. local aiStatus = v.aiStatus;
  713. local nUserID = v.nUserID;
  714. local viewId = app.room:getViewIdByUserId(nUserID)
  715. local isTuoGuan = aiStatus == 1;
  716. self.playerView:showTuoGuanByViewId(viewId,isTuoGuan)
  717. end
  718. local isMyGetCard = false
  719. local meIsHu = false
  720. if roomInfo.nStatus and roomInfo.nStatus>=MJDefine.GameStatus.GAME_STATUS_WAIT_BANKER_START and roomInfo.nStatus<MJDefine.GameStatus.GAME_STATUS_GAME_OVER then
  721. -- 游戏开始后才显示托管状态
  722. self.toolView:showTuoGuan(app.room.roomInfo.hosting == 1)
  723. end
  724. if (roomInfo.nStatus==MJDefine.GameStatus.GAME_STATUS_ROUND_OVER or roomInfo.nStatus==MJDefine.GameStatus.GAME_STATUS_GAME_OVER) and
  725. roomInfo.memberList[myUserId].nPlayerFlag ~= 1 then
  726. local fpSeatId = -1
  727. for k,v in pairs(roomInfo.memberList) do
  728. if v.result == MJDefine.MJGameHuType.HU_DIANPAO or v.result == MJDefine.MJGameHuType.HU_QIANGGANG then
  729. fpSeatId = v.dpSeatId
  730. end
  731. end
  732. --显示哪些玩家胡牌
  733. for i,player in pairs(roomInfo.memberList) do
  734. local viewId = app.room:getViewIdByUserId(player.nUserId)
  735. local nSeatId = app.room:getSeatIdByUserId(player.nUserId)
  736. local effect
  737. if player.result>0 and self.playerHandCards[viewId] then
  738. self.playerView:showHuOrder(viewId,player.result,player.huOrder)
  739. --effect = MJAnimationCompnent.CreateHuOrderEffect(player.result,player.huOrder)
  740. if myUserId == player.nUserId then
  741. --self.playerHandCards[viewId]:removeHandCard(player.huCard)
  742. --self.playerHandCards[viewId]:resetHandCards()
  743. self.playerHandCards[viewId]:createHandCards(player.huCard)
  744. self.playerHandCards[viewId]:moveLastCard()
  745. else
  746. --self.playerHandCards[viewId]:removeHandCard(player.huCard)
  747. --self.playerHandCards[viewId]:resetHandCards()
  748. self.playerHandCards[viewId]:createOpenHandCards(player.huCard)
  749. self.playerHandCards[viewId]:moveLastOpenCard()
  750. end
  751. end
  752. --[[if nSeatId == fpSeatId then
  753. effect = MJAnimationCompnent.CreateFangPaoEffect()
  754. end--]]
  755. if effect then
  756. self.ui.Items.Layout_Effect:addChild(effect)
  757. effect:setTag(HU_EFFECT_TAG)
  758. effect:setLocalZOrder(1000)
  759. local pos = self.playerHandCards[viewId]:getAnimationPostion()
  760. if viewId==MJDefine.PlayerViewType.My then
  761. effect:setPosition(pos.x,pos.y-60)
  762. elseif viewId==MJDefine.PlayerViewType.Left then
  763. effect:setPosition(pos.x-20,pos.y)
  764. elseif viewId==MJDefine.PlayerViewType.Right then
  765. effect:setPosition(pos.x+10,pos.y)
  766. elseif viewId==MJDefine.PlayerViewType.Top then
  767. effect:setPosition(pos.x,pos.y+10)
  768. end
  769. end
  770. if gameInfo.luobonum and gameInfo.luobonum > 0 then
  771. local effect1 = MJAnimationCompnent.CreateLoBoLabel(player.luoboNum or 0)
  772. local pos = self.playerHandCards[viewId]:getAnimationPostion()
  773. if viewId==MJDefine.PlayerViewType.My then
  774. effect1:setPosition(pos.x+130,pos.y-60)
  775. elseif viewId==MJDefine.PlayerViewType.Left then
  776. effect1:setPosition(pos.x-20-30,pos.y-70)
  777. elseif viewId==MJDefine.PlayerViewType.Right then
  778. effect1:setPosition(pos.x+10-30,pos.y-70)
  779. elseif viewId==MJDefine.PlayerViewType.Top then
  780. effect1:setPosition(pos.x+130,pos.y+10-50)
  781. end
  782. self.ui.Items.Layout_Effect:addChild(effect1)
  783. end
  784. --显示飘状态
  785. self.playerView:showPiao(viewId,tonumber(player.isPiao))
  786. end
  787. elseif roomInfo.nStatus==MJDefine.GameStatus.GAME_STATUS_WAIT_SWAP_CARDS then--等待换牌
  788. self.playerHandCards[MJDefine.MyViewId]:initSwapCardTouchEvent()
  789. self:showSwapCard(true)
  790. self.swapCard.Items.Button_sure:setEnabled(false)
  791. for i,player in pairs(roomInfo.memberList) do
  792. local viewId = app.room:getViewIdByUserId(player.nUserId)
  793. if player.nUserId == myUserId then
  794. if player.isSwapCard == 1 and self.swapCard and self.swapCard.Items.ImageView_bg then--操作过换牌
  795. self.swapCard.Items.ImageView_bg:setVisible(false)
  796. end
  797. else
  798. self:setSwapCardSucc(player.isSwapCard == 1,viewId)
  799. end
  800. if player.isSwapCard == 1 then
  801. self.playerHandCards[viewId]:createSwapCards({0,0,0})
  802. end
  803. end
  804. elseif roomInfo.nStatus==MJDefine.GameStatus.GAME_STATUS_WAIT_SELECT_QUE then--等待选缺
  805. -- 服务端没有给当前最优选,所以由客户端来自行判断
  806. local t = {[0] = 'wan', [1] = 'tong', [2] = 'tiao'}
  807. local temp = {wan = 0, tiao = 0, tong = 0}
  808. for _, mj in ipairs(self.playerHandCards[MJDefine.MyViewId]:getHandCardNodes()) do
  809. local mjType = mj:getMJColorType()
  810. if mjType <= 2 and mjType >= 0 and t[mjType] then
  811. temp[t[mjType]] = temp[t[mjType]] + 1
  812. end
  813. end
  814. local min = temp.wan
  815. for i, mType in pairs(t) do
  816. if min > temp[mType] then
  817. min = temp[mType]
  818. roomInfo.memberList[myUserId].nQue = i
  819. end
  820. end
  821. self.playerHandCards[MJDefine.MyViewId]:setHandCardsDidable()
  822. self:showDingQue(roomInfo.memberList[myUserId].nQue)
  823. for i,player in pairs(roomInfo.memberList) do
  824. local viewId = app.room:getViewIdByUserId(player.nUserId)
  825. if viewId == MJDefine.MyViewId then
  826. self.playerHandCards[viewId]:moveLastCard()
  827. end
  828. if player.nUserId == myUserId then
  829. if player.isDingQue == 1 then--操作过定缺
  830. self:hideDingQueOp()
  831. self.playerView:showQue(player.nQue,viewId,true)
  832. self.playerHandCards[viewId]:setQueType(player.nQue)
  833. end
  834. else
  835. self:setDingQueSucc(player.isDingQue == 1,viewId)
  836. end
  837. end
  838. --[[elseif roomInfo.nStatus==MJDefine.GameStatus.GAME_STATUS_WAIT_PIAO then
  839. self:stopDirection()
  840. for i,player in pairs(roomInfo.memberList) do
  841. local viewId = app.room:getViewIdByUserId(player.nUserId)
  842. if myUserId == player.nUserId then
  843. if tonumber(player.canPiao) == 1 then -- 操作过飘了
  844. self.playerView:showPiao(viewId,tonumber(player.isPiao))
  845. else
  846. --随飘或者固定飘的第一局,恢复显示飘
  847. if piaoMode == 1 or (piaoMode == 2 and roomInfo.nGameStartCount == 1) then--可以飘 还没有飘 显示飘按钮
  848. self:showPiao()
  849. end
  850. end
  851. else
  852. self.playerView:showPiao(viewId,tonumber(player.isPiao))
  853. end
  854. if tonumber(player.isPiao) > 0 then
  855. local effect = MJAnimationCompnent.CreatePiaoEffect()
  856. if effect then
  857. self.ui.Items.Layout_Effect_luobo:addChild(effect)
  858. effect:setLocalZOrder(1000)
  859. effect:setPosition(self.playerHandCards[viewId]:getAnimationPostion())
  860. end
  861. end
  862. end
  863. elseif roomInfo.nStatus==MJDefine.GameStatus.GAME_STATUS_WAIT_OP_BAO then--等待爆牌
  864. for k,v in pairs(roomInfo.memberList) do
  865. local viewId = app.room:getViewIdByUserId(v.nUserId)
  866. --可以爆牌玩家显示爆牌
  867. if v.canBaoPai == 1 and v.nUserId == myUserId then
  868. --self.playerHandCards[viewId]:showBaoPai()
  869. self:showBaoJiao()
  870. end
  871. --已爆牌玩家不能出牌
  872. if v.isBaoPai ~= 0 then
  873. if v.isBaoPai == 1 then-- 报叫
  874. self.playerView:playBaoAnim(viewId)
  875. end
  876. if v.nUserId == myUserId then --自己爆牌
  877. self.playerHandCards[viewId]:lockHandCard(true)
  878. -- self.playerHandCards[viewId]:setOutCardEnable(false)
  879. end
  880. app.room:dispatchEvent({name = MJDefine.MJEvent.OutCardFalg,value = roomInfo.lastOpCard,viewId = viewId})
  881. else
  882. end
  883. --显示飘状态
  884. self.playerView:showPiao(viewId,tonumber(v.isPiao))
  885. end--]]
  886. elseif roomInfo.nGameStartCount > 0 and roomInfo.memberList[myUserId].nPlayerFlag ~= 1 then--游戏中
  887. --local outCardUserId = app.room:getUserIdBySeatId(roomInfo.needOutCardId)
  888. local bIsOutCard = roomInfo.isNeedOutCard > 0 or false
  889. if (not bIsOutCard) and roomInfo.memberList[myUserId].nTingStatus == MJDefine.MJTingStatus.Ting then
  890. local gameInfo =json.decode(app.room.roomInfo.strGameInfo);
  891. --if gameInfo.tingpai > 0 then
  892. --self.ui.Items.Button_Ting_Info:setVisible(true);
  893. self:setButtonTingInfoVisible(true)
  894. --end
  895. end
  896. for k,v in pairs(roomInfo.memberList) do
  897. local viewId = app.room:getViewIdByUserId(v.nUserId)
  898. if isDingQue then--如果选择了定缺玩法
  899. self.playerView:showQue(v.nQue,viewId,true)
  900. self.playerHandCards[viewId]:setQueType(v.nQue)
  901. end
  902. --可以爆牌玩家显示爆牌
  903. if v.canBaoPai and v.canBaoPai == 1 and v.nUserId == myUserId then
  904. self.reShowBao = true--重连显示报叫操作标志
  905. self:showBaoJiao()
  906. end
  907. --已爆牌玩家不能出牌
  908. if v.isBaoPai and v.isBaoPai ~= 0 then
  909. if v.isBaoPai == 1 then-- 报叫
  910. self.playerView:playBaoAnim(viewId)
  911. self.playerHandCards[viewId]:setBaoPai(1)
  912. end
  913. if v.nUserId == myUserId then --自己爆牌
  914. --self.playerHandCards[viewId]:lockHandCard(true)
  915. end
  916. app.room:dispatchEvent({name = MJDefine.MJEvent.OutCardFalg,value = roomInfo.lastOpCard,viewId = viewId})
  917. end
  918. local handcardNum = #v.handCards
  919. if handcardNum%3 == 2 and v.nUserId == myUserId then
  920. isMyGetCard = true
  921. end
  922. if roomInfo.outCardUserId == v.nUserId then
  923. if v.nUserId == myUserId and roomInfo.lastOpCard~=0 and isMyGetCard then
  924. self.playerHandCards[viewId]:removeHandCard(roomInfo.lastOpCard)
  925. self.playerHandCards[viewId]:resetHandCards()
  926. if v.isBaoPai == 1 then
  927. self.playerHandCards[viewId]:setNotTingCardDidable(true)
  928. end
  929. self.playerHandCards[viewId]:createHandCards(roomInfo.lastOpCard)
  930. end
  931. if roomInfo.isNeedOutCard > 0 then
  932. self.playerHandCards[viewId]:setOutCardEnable(true)
  933. end
  934. end
  935. if viewId == MJDefine.MyViewId then
  936. if roomInfo.operates and table.nums(roomInfo.operates)>0 then
  937. self.operates = roomInfo.operates
  938. else
  939. self.operates = {}
  940. end
  941. end
  942. --显示飘状态
  943. self.playerView:showPiao(viewId,tonumber(v.isPiao))
  944. if (v.nTingStatus==MJDefine.MJTingStatus.Ting or v.isBaoPai ~= 0) and (not isMyGetCard) then
  945. -- 听牌、报叫、胡牌情况下,显示听牌按钮
  946. -- 此时需重新请求一下听牌数据,否则显示为空
  947. self.ui:sendMsg(app.room, MJDefine.MJEvent.Ting)
  948. self.isTing = true;
  949. self:setButtonTingInfoVisible(true);
  950. end
  951. end
  952. --显示哪些玩家胡牌
  953. for i,player in pairs(roomInfo.memberList) do
  954. local viewId = app.room:getViewIdByUserId(player.nUserId)
  955. local effect
  956. if player.result>0 then --胡的类型大于0
  957. if player.result == MJDefine.MJGameHuType.HU_ZIMO then
  958. --effect=MJAnimationCompnent.CreateHuOrderEffect(player.result,player.huOrder)
  959. else
  960. --effect=MJAnimationCompnent.CreateHuOrderEffect(player.result,player.huOrder)
  961. end
  962. self.playerView:showHuOrder(viewId,player.result,player.huOrder)
  963. if viewId == MJDefine.MyViewId then
  964. self.playerHandCards[viewId]:createHandCards(player.huCard)
  965. self.playerHandCards[viewId]:moveLastCard()
  966. meIsHu = true
  967. else
  968. self.playerHandCards[viewId]:removeAllHandCards()
  969. self.playerHandCards[viewId]:createOpenHandCards(player.handCards)
  970. self.playerHandCards[viewId]:createOpenHandCards(player.huCard)
  971. self.playerHandCards[viewId]:moveLastOpenCard()
  972. end
  973. end
  974. if effect then
  975. self.ui.Items.Layout_Effect:addChild(effect)
  976. effect:setTag(HU_EFFECT_TAG)
  977. effect:setLocalZOrder(1000)
  978. local pos = self.playerHandCards[viewId]:getAnimationPostion()
  979. if viewId==MJDefine.PlayerViewType.My then
  980. effect:setPosition(pos.x,pos.y-60)
  981. elseif viewId==MJDefine.PlayerViewType.Left then
  982. effect:setPosition(pos.x-20,pos.y)
  983. elseif viewId==MJDefine.PlayerViewType.Right then
  984. effect:setPosition(pos.x+10,pos.y)
  985. elseif viewId==MJDefine.PlayerViewType.Top then
  986. effect:setPosition(pos.x,pos.y+10)
  987. end
  988. end
  989. end
  990. end
  991. if isMyGetCard and(not meIsHu) then
  992. self.playerHandCards[MJDefine.MyViewId]:checkQueAndDisableOtherCard()
  993. self.playerHandCards[MJDefine.MyViewId]:setOutCardEnable(true)
  994. end
  995. --显示出牌角标(需要服务器修改outCardUserId为最后一位出牌玩家的id,而不是当前需要出牌玩家的ID)
  996. local lastOutCardViewId = app.room:getViewIdByUserId(roomInfo.outCardUserId);
  997. app.room:dispatchEvent({name = MJDefine.MJEvent.OutCardFalg, value = roomInfo.lastOpCard, viewId = lastOutCardViewId});
  998. --显示听标示
  999. app.room:dispatchEvent({name = MJDefine.MJEvent.PushTing});
  1000. app.room:dispatchEvent({name = MJDefine.MJEvent.ShowTing})
  1001. --如果有操作显示操作按钮
  1002. if not (roomInfo.nStatus==MJDefine.GameStatus.GAME_STATUS_WAIT_OP_BAO) then
  1003. if self.playerHandCards[MJDefine.MyViewId] then
  1004. self.playerHandCards[MJDefine.MyViewId]:showOperate(roomInfo.operates,roomInfo.lastOpCard,isMyGetCard);
  1005. end
  1006. if table.nums(roomInfo.operates) > 0 and isMyGetCard then
  1007. --self.playerHandCards[MJDefine.MyViewId]:setOutCardEnable(false)
  1008. end
  1009. end
  1010. --如果一局结束,玩家点了准备,不再显示牌信息
  1011. if MJDefine.GameStatus.GAME_STATUS_ROUND_OVER == roomInfo.nStatus and roomInfo.memberList[myUserId].nPlayerFlag == 1
  1012. or MJDefine.GameStatus.GAME_STATUS_GAME_OVER == roomInfo.nStatus and roomInfo.memberList[myUserId].nPlayerFlag == 1
  1013. then --游戏为停止或开始状态
  1014. self:onUserReadyResponse({nUserId=myUserId})
  1015. end
  1016. if meIsHu and meIsHu == true then
  1017. self.playerHandCards[MJDefine.MyViewId]:setOutCardEnable(false)
  1018. self:setTingCardViewVisible(false)
  1019. --self.ui.Items.Button_Ting_Info:setVisible(false)
  1020. self:setButtonTingInfoVisible(false)
  1021. self.playerHandCards[MJDefine.MyViewId]:setTing(false)
  1022. self.playerHandCards[MJDefine.MyViewId]:lockHandCard(true);
  1023. self.playerHandCards[MJDefine.MyViewId]:checkQueAndDisableOtherCard()
  1024. end
  1025. --快速成局
  1026. if roomInfo.nGameStartCount == 0 then
  1027. -- 游戏未开始
  1028. if roomInfo.nStatus and roomInfo.nStatus<MJDefine.GameStatus.GAME_STATUS_WAIT_BANKER_START then
  1029. if roomInfo.bUserFastStartGame then
  1030. if roomInfo.bUserFastStartGame == 1 then
  1031. --[[local tmpInfo = {}
  1032. for uid,status in pairs(roomInfo.pList) do
  1033. table.insert(tmpInfo, {nUserId=tonumber(uid), nStatus = status})
  1034. end--]]
  1035. local response = {}
  1036. response.pList = roomInfo.pList
  1037. response.timeOut = roomInfo.leftFastStartGameTime
  1038. self:onBroadcastFaststart({response=response})
  1039. end
  1040. else
  1041. if self._fastRequestView then
  1042. self._fastRequestView:removeSelf()
  1043. self._fastRequestView = nil
  1044. end
  1045. end
  1046. end
  1047. end
  1048. end
  1049. function linshuiRoomView:getChangeGruopDatas(g)
  1050. local opType=g.opType
  1051. local showType=MJDefine.MJOperateToGroupType[g.opType]
  1052. local opCard=g.opCard
  1053. local redNum = g.redNum
  1054. local fromViewId = nil
  1055. local targetSeatId = g.targetSeatId--操作位置座位号
  1056. local fromUserId = g.opUserId or g.fromUserId or 0 --触发操作玩家
  1057. local fromViewId1 = app.room:getViewIdByUserId(fromUserId)
  1058. if fromUserId<=0 or not targetSeatId then
  1059. else
  1060. fromViewId = app.room:transPos( targetSeatId, app.room:getSeatIdByUserId(fromUserId))
  1061. --判断是否是对面玩家,对面玩家的话要做一次翻转
  1062. local opViewId = app.room:getViewIdBySeatId(targetSeatId)
  1063. if opViewId == 2 then --对面
  1064. if fromViewId==1 then fromViewId = 3
  1065. elseif fromViewId==3 then fromViewId = 1 end
  1066. end
  1067. --三人玩只有上下家
  1068. if app.room:getMaxPlayerCount()==3 and fromViewId==2 then fromViewId = 3 end
  1069. if app.room:getMaxPlayerCount()==2 and fromViewId~=0 then
  1070. if showType == MJDefine.MJGroupType.Peng then
  1071. fromViewId = 2
  1072. else
  1073. fromViewId = 4
  1074. end
  1075. end
  1076. end
  1077. --组合一下牌
  1078. local group={
  1079. opType=opType,
  1080. showType=showType,
  1081. values={},
  1082. opCard = opCard,
  1083. redNum = redNum,
  1084. fromViewId = fromViewId,
  1085. fromViewId1 = fromViewId1,--真正的来源viewID
  1086. }
  1087. if MJDefine.MJGroupType.Chi==showType then
  1088. elseif MJDefine.MJGroupType.Peng==showType then
  1089. group.values={opCard,opCard,opCard}
  1090. else
  1091. group.values={opCard,opCard,opCard,opCard}
  1092. end
  1093. return group
  1094. end
  1095. -- 小局结算
  1096. function linshuiRoomView:onGameXiaoJuResponse(data)
  1097. local function runGameXiaoJuResponse(onEnd)
  1098. if not tolua.isnull(self.firstTingTipsView) then
  1099. self.firstTingTipsView:killSelf()
  1100. self.firstTingTipsView = nil
  1101. end
  1102. -- 取消操作按钮
  1103. if self.playerHandCards and self.playerHandCards[MJDefine.MyViewId] then
  1104. self.playerHandCards[MJDefine.MyViewId]:hideOperate()
  1105. end
  1106. local roomInfo = app.room.roomInfo
  1107. self.direcionView:stopAllActions()
  1108. self.operates = {}
  1109. self:setTingCardViewVisible(false)
  1110. app.room:resetTings()
  1111. app.room:cleanTingStatus()
  1112. --如果是解散直接return
  1113. --[[if roomInfo.stopFlag==MJDefine.StopFlag.STOP_FLAG_LONG_NOT_END or roomInfo.stopFlag==MJDefine.StopFlag.STOP_FLAG_DISBAND_GAME then
  1114. if onEnd then
  1115. onEnd()
  1116. end
  1117. return
  1118. end --]]
  1119. --所有胡牌的人 考虑抢杠胡的问题
  1120. local viewIds={}
  1121. local failViewId=0
  1122. for k,v in pairs(roomInfo.memberList) do
  1123. local viewId = app.room:getViewIdByUserId(v.nUserId)
  1124. if v.result and v.result>0 then
  1125. table.insert(viewIds,viewId)
  1126. --处理掉huCard, 不加入手牌
  1127. --播放音效
  1128. if viewId==MJDefine.MyViewId then
  1129. --MJSound.PlayWinGame()
  1130. end
  1131. if v.result==MJDefine.MJGameHuType.HU_DIANPAO then
  1132. failViewId = app.room:getViewIdBySeatId(v.dpSeatId)
  1133. end
  1134. end
  1135. end
  1136. self:showOpenCard()
  1137. for k,v in pairs(roomInfo.memberList) do
  1138. local viewId = app.room:getViewIdByUserId(v.nUserId)
  1139. if viewId and self.playerHandCards[viewId] then
  1140. if viewId==MJDefine.MyViewId then
  1141. else
  1142. --倒牌
  1143. if v.result and v.result>0 or (v.huCard and v.huCard ~= 0 and (not (roomInfo.stopFlag==MJDefine.StopFlag.STOP_FLAG_HUANG_ZHUANG))) then
  1144. self.playerHandCards[viewId]:createOpenHandCards(v.huCard)
  1145. self.playerHandCards[viewId]:moveLastOpenCard()
  1146. end
  1147. end
  1148. end
  1149. end
  1150. --被抢杠的人回退补杠
  1151. -- if resultInfo.hutype==MJDefine.MJHuType.QiangGangHu and roomInfo.stopFlag==MJDefine.StopFlag.STOP_FLAG_NORMAL then
  1152. -- self.playerHandCards[failViewId]:retoreBuGang(resultInfo.hucard)
  1153. -- end
  1154. local function callback()
  1155. self:showXiaoJuView()
  1156. if onEnd then
  1157. onEnd()
  1158. end
  1159. self.ui.Items.Layout_Effect_luobo:removeAllChildren()
  1160. end
  1161. local function luoboNumCallBack()
  1162. local strGameInfo = json.decode(app.room.roomInfo.strGameInfo)
  1163. if strGameInfo.luobonum and strGameInfo.luobonum > 0 then
  1164. local index = 1
  1165. for k,v in pairs(roomInfo.memberList) do
  1166. local viewId = app.room:getViewIdByUserId(v.nUserId)
  1167. local effect
  1168. if index == app.room.roomInfo.nMaxPlayCount then
  1169. effect = MJAnimationCompnent.CreateLoBoLabel(v.luoboNum,callback)
  1170. else
  1171. effect = MJAnimationCompnent.CreateLoBoLabel(v.luoboNum)
  1172. end
  1173. local pos = self.playerHandCards[viewId]:getAnimationPostion()
  1174. if viewId==MJDefine.PlayerViewType.My then
  1175. effect:setPosition(pos.x+130,pos.y-60)
  1176. elseif viewId==MJDefine.PlayerViewType.Left then
  1177. effect:setPosition(pos.x-20-30,pos.y-70)
  1178. elseif viewId==MJDefine.PlayerViewType.Right then
  1179. effect:setPosition(pos.x+10-30,pos.y-70)
  1180. elseif viewId==MJDefine.PlayerViewType.Top then
  1181. effect:setPosition(pos.x+130,pos.y+10-50)
  1182. end
  1183. self.ui.Items.Layout_Effect_luobo_Lable:addChild(effect)
  1184. index = index + 1
  1185. end
  1186. else
  1187. callback()
  1188. end
  1189. end
  1190. local luoboCards = roomInfo.luoboCards
  1191. local function luoboCallBack()
  1192. if luoboCards and #luoboCards>0 then
  1193. local luoNum = #luoboCards
  1194. --加一个黑底
  1195. local layer = cc.LayerColor:create(cc.c4b(0,0,0,120))
  1196. layer:setAnchorPoint(cc.p(0.5,0.5))
  1197. layer:ignoreAnchorPointForPosition(false)
  1198. local tPos = self.ui.Items.ImageView_Logo:getPosition()
  1199. local tLuoBoPos = {
  1200. [1] = {[1] = cc.p(tPos.x,360-40)},
  1201. [2] = {[1] = cc.p(tPos.x-50,360),[2] = cc.p(tPos.x+50,360)},
  1202. }
  1203. layer:setPosition(cc.p(getWinSize().width/2,getWinSize().height/2))
  1204. self.ui.Items.Layout_Effect_luobo:addChild(layer)
  1205. for i,v in pairs(luoboCards) do
  1206. local effect
  1207. if i == #luoboCards then
  1208. effect = MJAnimationCompnent.CreateLoBoEffect(v,self.desktopType,luoboNumCallBack)
  1209. else
  1210. effect = MJAnimationCompnent.CreateLoBoEffect(v,self.desktopType)
  1211. end
  1212. if MJDefine.LuoBoPos[luoNum] and MJDefine.LuoBoPos[luoNum][i] then
  1213. effect:setPosition(tLuoBoPos[luoNum][i])
  1214. self.ui.Items.Layout_Effect_luobo:addChild(effect)
  1215. end
  1216. end
  1217. else
  1218. self:runDelay(1.0,function()
  1219. callback()
  1220. end)
  1221. end
  1222. end
  1223. if #viewIds>0 then
  1224. if roomInfo.stopFlag==MJDefine.StopFlag.STOP_FLAG_LONG_NOT_END or roomInfo.stopFlag==MJDefine.StopFlag.STOP_FLAG_DISBAND_GAME then
  1225. self:runDelay(1.0,function()
  1226. callback()
  1227. end)
  1228. else
  1229. luoboCallBack()
  1230. end
  1231. local userInfo=app.room:getUserInfo(app.room:getMyUserId())
  1232. if userInfo then --拔萝卜音效
  1233. end
  1234. else
  1235. if roomInfo.stopFlag==MJDefine.StopFlag.STOP_FLAG_HUANG_ZHUANG then
  1236. local effect=MJAnimationCompnent.CreateLiuJuEffect(callback)
  1237. self.ui.Items.Layout_Player:addChild(effect)
  1238. effect:setLocalZOrder(1000)
  1239. MJSound.PlayHuangZhuang()
  1240. else
  1241. callback()
  1242. end
  1243. end
  1244. end
  1245. self:addCallBack(runGameXiaoJuResponse);
  1246. end
  1247. -- 显示小局结算
  1248. function linshuiRoomView:showXiaoJuView()
  1249. self.direcionView:stopAllActions()
  1250. self:setTingCardViewVisible(false)
  1251. if self.xiaojuView then
  1252. self.xiaojuView:removeFromParent()
  1253. end
  1254. local roomInfo = app.room.roomInfo
  1255. self.xiaojuView = MJRoomXiaoJuView:new(self.desktopType)
  1256. self:addChild(self.xiaojuView)
  1257. end
  1258. function linshuiRoomView:setTingCardViewVisible(bVisible,tingCards)
  1259. self.ui.Items.Layout_Ting_Tip_Card_Panel:setVisible(false)
  1260. --[[if self._tingCardView and (not tolua.isnull(self._tingCardView)) then
  1261. self._tingCardView:setData(tingCards)
  1262. if (not tingCards) or (type(tingCards) == 'table' and #tingCards==0) then
  1263. self:setTingCardVisible(false)
  1264. return
  1265. end
  1266. self:setTingCardVisible(bVisible)
  1267. end--]]
  1268. end
  1269. --显示查听的牌
  1270. function linshuiRoomView:setChaTingCardViewVisible(bVisible,tingCards)
  1271. end
  1272. function linshuiRoomView:onTingCardStatus()
  1273. local myUserId=app.user.loginInfo.uid;
  1274. local memberList=app.room.roomInfo.memberList;
  1275. local player = memberList[myUserId];
  1276. if not player then
  1277. return ;
  1278. end
  1279. local nTingStatus = player.nTingStatus
  1280. if nTingStatus == MJDefine.MJTingStatus.Ting then
  1281. print("---------onTingCardStatus-----------1 "..myUserId)
  1282. if player.isBaoPai == 1 then
  1283. self.ui:sendMsg(app.room,MJDefine.MJEvent.Ting)
  1284. end
  1285. self.isTing = true;
  1286. self:setButtonTingInfoVisible(true);
  1287. else
  1288. print("---------onTingCardStatus-----------0 "..myUserId)
  1289. self:setButtonTingInfoVisible(false);
  1290. end
  1291. end
  1292. function linshuiRoomView:onTingCardResult(data)
  1293. print("---------听牌结果-------------")
  1294. --[[if data.response.tingType==MJDefine.MJTingType.QuanTing then
  1295. -- self:setChaTingCardViewVisible(true,{})
  1296. else
  1297. if self._isOutCardTingCheck then
  1298. self._isOutCardTingCheck = false
  1299. local count = table.nums(data.response.tingCards);
  1300. local isTing = count > 0;
  1301. --self.ui.Items.Button_Ting_Info:setVisible(isTing);
  1302. self:setButtonTingInfoVisible(isTing)
  1303. self:setTingCardViewVisible(false, data.response.tingCards)
  1304. else
  1305. self:setTingCardViewVisible(true, data.response.tingCards)
  1306. end
  1307. self._tingCardView:setData(tingCards);
  1308. end--]]
  1309. local tingCards = data.response.tingCards or {};
  1310. self.isTing = table.nums(tingCards) > 0;
  1311. self:setButtonTingInfoVisible(self.isTing);
  1312. self._tingCardView:setData(tingCards);
  1313. self:setTingCardVisible(false);
  1314. end
  1315. function linshuiRoomView:showTing(evet)
  1316. --[[local roomInfo=app.room.roomInfo
  1317. local selectCard = evet.card;
  1318. if not selectCard or evet.card <= 0 then
  1319. return;
  1320. end
  1321. if evet.card and roomInfo.tings and #roomInfo.tings>0 then
  1322. local isTing = false
  1323. for k,v in pairs(roomInfo.tings) do
  1324. if evet.card==v.outCard then
  1325. self:setTingCardViewVisible(true,v.tingCards)
  1326. isTing = true
  1327. end
  1328. end
  1329. if not isTing then
  1330. self:setTingCardViewVisible(false)
  1331. end
  1332. else
  1333. self:setTingCardViewVisible(false)
  1334. local isMyGetCard = true
  1335. if self.playerHandCards[MJDefine.MyViewId] then
  1336. local handCards = self.playerHandCards[MJDefine.MyViewId]:getHandCardNodes()
  1337. if handCards and type(handCards) == 'table' then
  1338. isMyGetCard = (#handCards%3==2)
  1339. end
  1340. end
  1341. local myUserId = app.room:getMyUserId()
  1342. if roomInfo.nGameStartCount > 0 and roomInfo.memberList[myUserId].nPlayerFlag == 2 and (not isMyGetCard) then--游戏中,不是摸牌阶段
  1343. self._isOutCardTingCheck = true;
  1344. self.ui:sendMsg(app.room,MJDefine.MJEvent.Ting)
  1345. end
  1346. end--]]
  1347. local roomInfo=app.room.roomInfo;
  1348. local selectCard = evet.card;
  1349. if not selectCard or evet.card <= 0 then
  1350. return;
  1351. end
  1352. local curTingCards = app.room:getTingCardsByCard(selectCard);
  1353. if not self._tingCardView then
  1354. return ;
  1355. end
  1356. self._tingCardView:setData(curTingCards);
  1357. self.isTing = table.nums(curTingCards) > 0;
  1358. if self.isTing and (not self:isMySelfHu()) then
  1359. self:setTingCardVisible(true);
  1360. else
  1361. self:setTingCardVisible(false);
  1362. end
  1363. end
  1364. function linshuiRoomView:isMySelfHu()
  1365. local myUserId = app.room:getMyUserId();
  1366. local player = app.room.roomInfo.memberList[myUserId];
  1367. if not player then
  1368. return false;
  1369. end
  1370. local huCards = player.huCards or {};
  1371. return table.nums(huCards) > 0;
  1372. end
  1373. function linshuiRoomView:pushTing()
  1374. local function runPushTing(onEnd)
  1375. if self.playerHandCards[MJDefine.MyViewId] then
  1376. self.playerHandCards[MJDefine.MyViewId]:pushTing()
  1377. end
  1378. if onEnd then
  1379. onEnd()
  1380. end
  1381. end
  1382. self:addCallBack(runPushTing);
  1383. end
  1384. function linshuiRoomView:onHuResponse(data)
  1385. local function runHuResponse(onEnd)
  1386. local response = data.response
  1387. local function callback()
  1388. self:playHuAni(response)
  1389. if onEnd then
  1390. onEnd()
  1391. end
  1392. end
  1393. local viewId = app.room:getViewIdByUserId(response.nUserId)
  1394. local userInfo=app.room:getUserInfoByViewId(viewId)
  1395. --先播放胡牌动画和音效,再显示胡牌顺序
  1396. local effect = MJAnimationCompnent.CreateHuEffect(response.huType,callback)
  1397. if response.huType == MJDefine.MJGameHuType.HU_ZIMO then
  1398. MJSound.PlayOperateSound(userInfo.sex,MJDefine.MJOperateType.OPREATE_ZIMOHU)
  1399. -- effect=MJAnimationCompnent.CreateHuEffect("zimo",callback)
  1400. -- elseif response.huType == MJDefine.MJGameHuType.HU_QIANGGANG then
  1401. else
  1402. MJSound.PlayOperateSound(userInfo.sex,MJDefine.MJOperateType.OPREATE_DIANPAOHU)
  1403. -- effect=MJAnimationCompnent.CreateHuEffect("hu",callback)
  1404. -- --点炮显示
  1405. end
  1406. if effect then
  1407. self.ui.Items.Layout_Effect:addChild(effect)
  1408. effect:setTag(HU_EFFECT_TAG)
  1409. effect:setLocalZOrder(1000)
  1410. effect:setPosition(self.playerHandCards[viewId]:getAnimationPostion())
  1411. end
  1412. --删除等待操作的显示
  1413. if self.waitOperates and #self.waitOperates>0 then
  1414. for k,v in pairs(self.waitOperates) do
  1415. v:removeFromParent()
  1416. end
  1417. self.waitOperates={}
  1418. end
  1419. if response.huType==MJDefine.MJGameHuType.HU_DIANPAO and response.curOpType ~= 1 then
  1420. local failViewId = app.room:getViewIdByUserId(response.dpId)
  1421. --点炮胡或抢杠胡,胡牌类型都是发 点炮胡
  1422. if response.isQiangGng > 0 then
  1423. local huCard = response.huCard == 65 and response.redRealCard or response.huCard --如果胡的牌是红中 用真实的牌 否则用胡的牌
  1424. -- logD("isQiangGng huCard:"..huCard)
  1425. --抢杠胡
  1426. self.playerHandCards[viewId]:onGetCard(nil,huCard)
  1427. --被抢杠的人回退补杠
  1428. --self.playerHandCards[failViewId]:retoreBuGang(huCard,1)
  1429. elseif response.isGspHu and response.isGspHu > 0 then
  1430. local gameInfo =json.decode(app.room.roomInfo.strGameInfo);
  1431. if gameInfo.gshmode == 1 then
  1432. dghDianPao = true
  1433. --点杠炮(选择的点杠花)时手上已经有杠的牌 不需要再加一张胡的牌
  1434. else
  1435. self.playerHandCards[viewId]:onGetCard(nil,response.huCard)
  1436. --将胡的牌收走
  1437. self.playerHandCards[failViewId]:removeOutCard(response.huCard)
  1438. end
  1439. else
  1440. self.playerHandCards[viewId]:onGetCard(nil,response.huCard)
  1441. --将胡的牌收走
  1442. self.playerHandCards[failViewId]:removeOutCard(response.huCard)
  1443. end
  1444. local function fangpaoCallback()
  1445. self:playFangPaoAni(failViewId)
  1446. end
  1447. --放炮动画
  1448. effect=MJAnimationCompnent.CreateDianPaoEffect()--fangpaoCallback
  1449. self.ui.Items.Layout_Effect:addChild(effect)
  1450. effect:setLocalZOrder(1000)
  1451. effect:setPosition(self.playerHandCards[failViewId]:getAnimationPostion())
  1452. if failViewId==MJDefine.MyViewId and app.room.roomInfo.lastOutViewId==MJDefine.MyViewId then --修改点炮的人连续二次出牌 不删除牌
  1453. app.room.roomInfo.lastOutViewId = nil
  1454. end
  1455. --此处仅做保留,没有实际意义
  1456. elseif response.huType==MJDefine.MJGameHuType.HU_QIANGGANG then
  1457. local failViewId = app.room:getViewIdByUserId(response.dpId)
  1458. if response.redRealCard > 0 then
  1459. --抢杠胡时,胡牌的人将胡的牌加入手中
  1460. self.playerHandCards[viewId]:onGetCard(nil,response.redRealCard)
  1461. --被抢杠的人回退补杠
  1462. --self.playerHandCards[failViewId]:retoreBuGang(response.redRealCard,1)
  1463. end
  1464. end
  1465. if response.nUserId == app.room:getMyUserId() then
  1466. self.playerHandCards[viewId]:setOutCardEnable(false)
  1467. self:setTingCardViewVisible(false)
  1468. --self.ui.Items.Button_Ting_Info:setVisible(false)
  1469. self:setButtonTingInfoVisible(false)
  1470. self.playerHandCards[viewId]:setTing(false)
  1471. self.playerHandCards[viewId]:lockHandCard(true);
  1472. self.playerHandCards[MJDefine.MyViewId]:hideOperate()
  1473. else
  1474. -- 其他人胡了倒牌
  1475. local handCards = {}
  1476. for k,v in pairs(self.playerHandCards[viewId]:getHandCardNodes() or {}) do
  1477. table.insert(handCards,{card = v.value or v:getValue()})
  1478. end
  1479. if response.huType==MJDefine.MJGameHuType.HU_ZIMO or response.curOpType == 1 or (response.isGspHu and response.isGspHu > 0) then --如果是自摸胡 把最后一张替换为胡的牌或点杠花点炮
  1480. handCards[#handCards] = {card = response.huCard}
  1481. end
  1482. self.playerHandCards[viewId]:removeAllHandCards()
  1483. self.playerHandCards[viewId]:createOpenHandCards(handCards)
  1484. self.playerHandCards[viewId]:moveLastOpenCard()
  1485. end
  1486. --self.playerHandCards[MJDefine.MyViewId]:hideOperate()
  1487. end
  1488. self:addCallBack(runHuResponse);
  1489. end
  1490. function linshuiRoomView:playHuAni(response)
  1491. local strGameInfo = json.decode(app.room.roomInfo.strGameInfo)
  1492. --local effect = MJAnimationCompnent.CreateHuOrderEffect(response.huType,response.huOrder)
  1493. -- if response.huType == 1 then
  1494. -- effect=MJAnimationCompnent.CreateHuOrderEffect("zimo",response.huOrder)
  1495. -- else
  1496. -- effect=MJAnimationCompnent.CreateHuOrderEffect("hu",response.huOrder)
  1497. -- end
  1498. local viewId = app.room:getViewIdByUserId(response.nUserId)
  1499. self.playerView:showHuOrder(viewId,response.huType,response.huOrder)
  1500. if effect then
  1501. self.ui.Items.Layout_Effect:addChild(effect)
  1502. effect:setTag(HU_EFFECT_TAG)
  1503. effect:setLocalZOrder(1000)
  1504. local pos = self.playerHandCards[viewId]:getAnimationPostion()
  1505. if viewId==MJDefine.PlayerViewType.My then
  1506. effect:setPosition(pos.x,pos.y-60)
  1507. elseif viewId==MJDefine.PlayerViewType.Left then
  1508. effect:setPosition(pos.x-20,pos.y)
  1509. elseif viewId==MJDefine.PlayerViewType.Right then
  1510. effect:setPosition(pos.x+10,pos.y)
  1511. elseif viewId==MJDefine.PlayerViewType.Top then
  1512. effect:setPosition(pos.x,pos.y+10)
  1513. end
  1514. end
  1515. end
  1516. function linshuiRoomView:playFangPaoAni(viewId)
  1517. local effect = MJAnimationCompnent.CreateFangPaoEffect()
  1518. --local viewId = app.room:getViewIdByUserId(response.nUserId)
  1519. if effect then
  1520. self.ui.Items.Layout_Effect:addChild(effect)
  1521. effect:setTag(HU_EFFECT_TAG)
  1522. effect:setLocalZOrder(1000)
  1523. local pos = self.playerHandCards[viewId]:getAnimationPostion()
  1524. if viewId==MJDefine.PlayerViewType.My then
  1525. effect:setPosition(pos.x,pos.y-60)
  1526. elseif viewId==MJDefine.PlayerViewType.Left then
  1527. effect:setPosition(pos.x-20,pos.y)
  1528. elseif viewId==MJDefine.PlayerViewType.Right then
  1529. effect:setPosition(pos.x+10,pos.y)
  1530. elseif viewId==MJDefine.PlayerViewType.Top then
  1531. effect:setPosition(pos.x,pos.y+10)
  1532. end
  1533. end
  1534. end
  1535. function linshuiRoomView:onQiangDuanOperates(data)
  1536. local function runOnQiangDuanOperates(onEnd)
  1537. logD("linshuiRoomView:runOnQiangDuanOperates")
  1538. local response = data.response
  1539. if response.operates and self.playerHandCards[MJDefine.MyViewId] then
  1540. self.playerHandCards[MJDefine.MyViewId]:showOperate(response.operates)
  1541. end
  1542. if onEnd then
  1543. onEnd()
  1544. end
  1545. end
  1546. logD("linshuiRoomView:onQiangDuanOperates")
  1547. self:addCallBack(runOnQiangDuanOperates)
  1548. end
  1549. --游戏消息
  1550. function linshuiRoomView:bindExtendMessage()
  1551. self:bindEvent(app.room , MJDefine.MJEvent.OutCardTings, handler(self , self.pushTing));
  1552. self:bindEvent(app.room , MJDefine.MJEvent.HuResponse, handler(self , self.onHuResponse))
  1553. self:bindEvent(app.room , MJDefine.MJEvent.BaoPaiResponse, handler(self , self.onBaoPai))
  1554. self:bindEvent(app.room , MJDefine.MJEvent.BankerBaoPai, handler(self , self.onBankerBaoPai))
  1555. self:bindEvent(app.room , MJDefine.MJEvent.SendGuo, handler(self , self.onSendGuo))
  1556. self:bindEvent(app.room , MJDefine.MJEvent.QiangDuanOperates, handler(self , self.onQiangDuanOperates))
  1557. self:bindEvent(app , MJDefine.MJEvent.ChangeLanguage , handler(self , self.doSound))
  1558. self:bindEvent(app.room , MJDefine.MJEvent.StartPiao, handler(self , self.onStartPiao))
  1559. self:bindEvent(app.room , MJDefine.MJEvent.PiaoResponse, handler(self , self.onPiaoResponse))
  1560. self:bindEvent(app, MJDefine.MJEvent.ChangeViewType, handler(self, self.onEventChangeViewType ))
  1561. --换三张,服务器会通过0x8122通知换牌
  1562. self:bindEvent(app.room , MJDefine.MJEvent.NoticeSwapCard,handler(self,self.onNoticeSwapCardResponse))
  1563. --换三张失败
  1564. self:bindEvent(app.room , MJDefine.MJEvent.SwapCardErr,handler(self,self.onChangeCardFail))
  1565. --换三张成功
  1566. self:bindEvent(app.room , MJDefine.MJEvent.SwapCardSucc,handler(self,self.onChangeCardSucc))
  1567. --换三张成功后的信息
  1568. self:bindEvent(app.room , MJDefine.MJEvent.SwapCardSuccInfo,handler(self,self.onChangeCardInfo))
  1569. --服务器通知定缺
  1570. self:bindEvent(app.room , MJDefine.MJEvent.NoticeDingQue,handler(self,self.onNoticeDingQueResponse))
  1571. --当玩家操作成功后,通过0x8131广播定缺成功
  1572. self:bindEvent(app.room , MJDefine.MJEvent.DingQueSucc,handler(self,self.onDingQueSuccResponse))
  1573. --当所有玩家定缺成功后,服务器会通过广播告诉玩家定缺类型
  1574. self:bindEvent(app.room , MJDefine.MJEvent.DingQueSuccInfo,handler(self,self.onDingQueSuccInfoResponse))
  1575. --内容和0x8106保持统一 广播桌子上所有玩家庄家起手操作
  1576. self:bindEvent(app.room , MJDefine.MJEvent.AfterDingQue,handler(self , self.onAfterDingQue))
  1577. --检测是否符合换三张规则
  1578. self:bindEvent(app.room , MJDefine.MJEvent.CheckIsInSwapRule,handler(self , self.onCheckIsInSwapRule))
  1579. --躺牌
  1580. self:bindEvent(app.room , MJDefine.MJEvent.TangPaiResponse,handler(self,self.onTangPaiResponse))
  1581. -- 托管
  1582. self:bindEvent(app.room , MJDefine.MJEvent.HostingRequest, handler(self, self.onHostingRequest))
  1583. end
  1584. function linshuiRoomView:clean()
  1585. self.playerView:init()
  1586. -- --默认状态
  1587. self:defaultState()
  1588. app.room:resetRoomInfo()
  1589. self:setBtnSitDownVisible(false)
  1590. self.ui:sendMsg(app.room, MJDefine.MJEvent.CallReadyRequest)
  1591. --
  1592. self._gameoverview = nil
  1593. end
  1594. function linshuiRoomView:updateReady()
  1595. local nUserId = app.room:getMyUserId()--app.user.loginInfo.uid
  1596. if app.room.roomInfo.nGameStartCount > 0 then
  1597. self.toolView.ui.Items.Button_Leave:setEnabled(false)
  1598. self:setBtnSitDownVisible(false)
  1599. else
  1600. self.toolView.ui.Items.Button_Leave:setEnabled(true)
  1601. end
  1602. if app.room.roomInfo.nGameStartCount == 0 and app.room.roomInfo.nRoomOwnedUid ~= nUserId then
  1603. self.toolView.ui.Items.Button_Dismiss:setEnabled(false)
  1604. else
  1605. self.toolView.ui.Items.Button_Dismiss:setEnabled(true)
  1606. end
  1607. self:checkCanDismiss()
  1608. end
  1609. -- 游戏开始
  1610. function linshuiRoomView:onGameStartResponse()
  1611. linshuiRoomView.super.onGameStartResponse(self)
  1612. self._gameoverview = nil
  1613. end
  1614. -- 大局结算
  1615. function linshuiRoomView:onGameDaJuResponse(data)
  1616. app.club_php:dispatchEvent({name = GAME_EVENT.CLUB_BACK_ROOM})
  1617. if self._gameoverview then
  1618. return
  1619. end
  1620. if app.room.roomInfo.needJieSuanInfo == 1 then--显示总结算
  1621. self:showGameOverResult(data.response)
  1622. else
  1623. --[[local roomInfo=app.room.roomInfo
  1624. --如果是解散直接跳转总结算
  1625. if roomInfo.stopFlag==MJDefine.StopFlag.STOP_FLAG_LONG_NOT_END or roomInfo.stopFlag==MJDefine.StopFlag.STOP_FLAG_DISBAND_GAME then
  1626. self:showGameOverResult(data.response)
  1627. end --]]
  1628. local roomInfo=app.room.roomInfo
  1629. local isNoCard = false--没有手牌
  1630. for i,player in pairs(roomInfo.memberList) do
  1631. if type(player.handCards) == 'table' and #player.handCards <= 0 then
  1632. local a = #player.handCards
  1633. isNoCard = true
  1634. break
  1635. end
  1636. end
  1637. if isNoCard then
  1638. self:showGameOverResult(data.response)
  1639. end
  1640. app.room:dispatchEvent({name = GAME_EVENT.DISSMISS_CLOSE})
  1641. end
  1642. end
  1643. -- 大局结算
  1644. function linshuiRoomView:showGameOverResult(data)
  1645. if self._gameoverview ~= nil then
  1646. return
  1647. end
  1648. self.direcionView:stopAllActions()
  1649. self:resetGame()
  1650. local view=MJRoomDaJuView:new(data)
  1651. view:setAnchorPoint(cc.p(0.5, 0.5))
  1652. app:showWaitDialog(view)
  1653. self._gameoverview = view
  1654. end
  1655. function linshuiRoomView:onOtherLogoutResponse(data)
  1656. -- local jushu = app.room.roomInfo.nGameStartCount or 0
  1657. if (not data or not data.nUserId or not data.nSeatShowId) then
  1658. return
  1659. end
  1660. local function test(onEnd)
  1661. self.playerView:updatePlayerInfo(data.nSeatShowId)
  1662. self:onUserReadyResponse()
  1663. --更新GPS
  1664. --self:updateAllGpsInfo()
  1665. --self:checkGpsDistance()
  1666. -- 是否显示邀请好友
  1667. self.toolView:updateButton()
  1668. logE("88888-onOtherLogoutResponse onEnd")
  1669. if onEnd then
  1670. onEnd()
  1671. end
  1672. end
  1673. self:addCallBack(test)
  1674. end
  1675. function linshuiRoomView:resetGame()
  1676. linshuiRoomView.super.resetGame(self)
  1677. self.ui.Items.Layout_Effect:removeAllChildren()
  1678. self.ui.Items.Layout_Effect_luobo_Lable:removeAllChildren()
  1679. self.ui.Items.Layout_Effect_luobo:removeAllChildren()
  1680. self.playerView:clearBao()
  1681. self.playerView:clearAllPiao()
  1682. --self.playerView:clearAllBoZiMo()
  1683. self.playerView:clearAllQue()
  1684. self.playerView:clearAllHuOrder()
  1685. if self.playerHandCards[MJDefine.MyViewId] then
  1686. self.playerHandCards[MJDefine.MyViewId]:setQueType(-1)--设置缺牌类型为空
  1687. self.playerHandCards[MJDefine.MyViewId]:setBaoPai(0)--重置报状态
  1688. end
  1689. self:setTingCardVisible(false);
  1690. self:setTingCardViewVisible(false);
  1691. self.isTang = false
  1692. app.room.roomInfo.lastOutViewId = 0
  1693. self.reShowBao = nil --重连显示报操作标志
  1694. self.guobao = nil--重连过报标志
  1695. end
  1696. --显示换三张
  1697. function linshuiRoomView:showSwapCard(isOpered)--是否已经操作过
  1698. self:stopDirection()
  1699. local roomInfo=app.room.roomInfo
  1700. local gameInfo=json.decode(roomInfo.strGameInfo)
  1701. if not gameInfo.specRule or (not (getNumBand(gameInfo.specRule, 0x0002)>0)) then return end
  1702. isOpered = isOpered or false
  1703. self:hideSwapCard()
  1704. local ui=loadUI("mj_linshui/res/ui_fangjian/mj_linshui_swap_card.ui")
  1705. self.ui.Items.Layout_Player:addChild(ui)
  1706. self.swapCard=ui
  1707. self.swapCard.Items.ImageView_bg:setVisible(isOpered)
  1708. for i=1,4 do--先隐藏全部
  1709. if self.swapCard.Items["Layout_swapCard_"..i] then
  1710. self.swapCard.Items["Layout_swapCard_"..i]:setVisible(false)
  1711. end
  1712. self:setSwapCardSucc(false,i)
  1713. end
  1714. for k,v in pairs(app.room.roomInfo.memberList) do--根据人数显示
  1715. local viewId = app.room:getViewIdByUserId(v.nUserId)
  1716. if self.playerHandCards[viewId] then
  1717. if self.swapCard.Items["Layout_swapCard_"..viewId] then
  1718. self.swapCard.Items["Layout_swapCard_"..viewId]:setVisible(true)
  1719. end
  1720. else
  1721. if self.swapCard.Items["Layout_swapCard_"..viewId] then
  1722. self.swapCard.Items["Layout_swapCard_"..viewId]:setVisible(false)
  1723. end
  1724. end
  1725. end
  1726. --确定换牌按钮
  1727. ui.Items.Button_sure:registerClick(function()
  1728. playBtnEffect()
  1729. self.swapCard.Items.ImageView_bg:setVisible(false)
  1730. --请求换牌
  1731. local cards = self.playerHandCards[MJDefine.MyViewId]:getSelectedCards()
  1732. app.room:requestSwapCards(cards)
  1733. --[[local request = MJMessage.PiaoRequest:new()
  1734. request.isPiao = 0
  1735. self.ui:sendMsg(app.room,MJDefine.MJEvent.PiaoRequest,request)--]]
  1736. end)
  1737. end
  1738. --隐藏换三张
  1739. function linshuiRoomView:hideSwapCard()
  1740. if self.swapCard then
  1741. self.swapCard:removeFromParent()
  1742. self.swapCard=nil
  1743. end
  1744. end
  1745. --换三张,服务器会通过0x8122通知换牌
  1746. function linshuiRoomView:onNoticeSwapCardResponse(response)
  1747. local function runNoticeSwapCard(onEnd)
  1748. logD("linshuiRoomView:onNoticeSwapCardResponse")
  1749. local data = response.response
  1750. self:showSwapCard(true)
  1751. self.playerHandCards[MJDefine.MyViewId]:initSwapCardTouchEvent()
  1752. --弹出推荐牌
  1753. self.playerHandCards[MJDefine.MyViewId]:resetHandCards()
  1754. self.playerHandCards[MJDefine.MyViewId]:selectCardsByCards(data.swapCards)
  1755. self.swapCard.Items.Button_sure:setEnabled(true)
  1756. if onEnd then
  1757. onEnd()
  1758. end
  1759. end
  1760. logD("linshuiRoomView:runNoticeSwapCard")
  1761. self:addCallBack(runNoticeSwapCard)
  1762. end
  1763. --换三张失败
  1764. function linshuiRoomView:onChangeCardFail(response)
  1765. local function runChangeCardFail(onEnd)
  1766. logD("linshuiRoomView:onChangeCardFail")
  1767. self:showSwapCard(true)
  1768. self.playerHandCards[MJDefine.MyViewId]:resetHandCards()
  1769. self.swapCard.Items.Button_sure:setEnabled(false)
  1770. if onEnd then
  1771. onEnd()
  1772. end
  1773. end
  1774. logD("linshuiRoomView:runChangeCardFail")
  1775. self:addCallBack(runChangeCardFail)
  1776. end
  1777. --换三张成功
  1778. function linshuiRoomView:onChangeCardSucc(response)
  1779. local function runChangeCardSucc(onEnd)
  1780. logD("linshuiRoomView:onChangeCardSucc")
  1781. local data = response.response
  1782. local userId = data.nUserId--操作的玩家
  1783. local viewId = app.room:getViewIdByUserId(userId)
  1784. if viewId == MJDefine.MyViewId then
  1785. if self.swapCard and self.swapCard.Items.ImageView_bg then
  1786. self.swapCard.Items.ImageView_bg:setVisible(false)
  1787. end
  1788. self.playerHandCards[MJDefine.MyViewId]:deleteSelectedCards()
  1789. else
  1790. self:setSwapCardSucc(true,viewId)
  1791. local tmpCards = {}
  1792. for i=1,3 do
  1793. table.insert(tmpCards,{card = 0})
  1794. end
  1795. self.playerHandCards[viewId]:removeHandCard(tmpCards)
  1796. self.playerHandCards[viewId]:resetHandCards()
  1797. end
  1798. self.playerHandCards[viewId]:createSwapCards({0,0,0})
  1799. if onEnd then
  1800. onEnd()
  1801. end
  1802. end
  1803. logD("linshuiRoomView:runChangeCardSucc--------")
  1804. self:addCallBack(runChangeCardSucc)
  1805. end
  1806. --换三张成功后的信息
  1807. function linshuiRoomView:onChangeCardInfo(response)
  1808. local function runChangeCardInfo(onEnd)
  1809. logD("linshuiRoomView:onChangeCardInfo")
  1810. self:hideSwapCard()
  1811. local data = response.response
  1812. self:showSwapDirection(data.swapType)
  1813. for i,v in pairs(data.swapCards) do
  1814. for i=1,4 do
  1815. if i == MJDefine.MyViewId and self.playerHandCards[MJDefine.MyViewId] then
  1816. self.playerHandCards[MJDefine.MyViewId]:onGetCard(nil,tonumber(v.card),true)
  1817. elseif self.playerHandCards[i] then
  1818. self.playerHandCards[i]:onGetCard(nil,0,true)
  1819. end
  1820. end
  1821. end
  1822. --self.playerHandCards[MJDefine.MyViewId]:resetHandCards()
  1823. for i=1,4 do
  1824. if self.playerHandCards[i] then
  1825. self.playerHandCards[i]:deleteSwapCards()
  1826. end
  1827. end
  1828. self.playerHandCards[MJDefine.MyViewId]:removeTouchEventOnly()
  1829. for i,v in pairs(data.swapCards) do
  1830. local handCards = self.playerHandCards[MJDefine.MyViewId]:getHandCardNodes() or {}
  1831. for j,mjCard in pairs(handCards) do
  1832. if mjCard:getValue() == tonumber(v.card) and mjCard:getSelected() ~= MJDefine.MJStatus.Select then
  1833. --local mjCard = self.playerHandCards[MJDefine.MyViewId]:getMjByValue(tonumber(v.card))
  1834. --if mjCard and mjCard:getSelected() ~= MJDefine.MJStatus.Select then
  1835. mjCard:setSelected(MJDefine.MJStatus.Select)
  1836. mjCard:recordPostion()
  1837. local initPos = mjCard:getPosition()
  1838. local toPos = cc.p(initPos.x, initPos.y + 25)
  1839. mjCard:setPosition(toPos)
  1840. mjCard:runDeSelectAnimationWithTime(1.0)
  1841. mjCard:runAction(cc.Sequence:create(cc.DelayTime:create(1.0),cc.CallFunc:create(function()
  1842. mjCard:setSelected(MJDefine.MJStatus.Normal)
  1843. end)))
  1844. break
  1845. end
  1846. --end
  1847. end
  1848. end
  1849. --[[self:runAction(cc.Sequence:create(cc.DelayTime:create(1.0),cc.CallFunc:create(function()
  1850. self.playerHandCards[MJDefine.MyViewId]:initTouchEvent()
  1851. end)))--]]
  1852. if onEnd then
  1853. onEnd()
  1854. end
  1855. end
  1856. logD("linshuiRoomView:runChangeCardInfo--------")
  1857. self:addCallBack(runChangeCardInfo)
  1858. end
  1859. --设置换牌成功 isSwaped:true显示有勾的,false显示换牌中
  1860. function linshuiRoomView:setSwapCardSucc(isSwaped,viewId)
  1861. isSwaped = isSwaped or false
  1862. if not self.swapCard or tolua.isnull(self.swapCard) then
  1863. return
  1864. end
  1865. if self.swapCard.Items["ImageView_swaping_"..viewId] then
  1866. self.swapCard.Items["ImageView_swaping_"..viewId]:setVisible(not isSwaped)
  1867. end
  1868. if self.swapCard.Items["ImageView_swaped_"..viewId] then
  1869. self.swapCard.Items["ImageView_swaped_"..viewId]:setVisible(false)--isSwaped 不显示选牌中了
  1870. end
  1871. end
  1872. --换牌方式 1顺时针 2对家换牌 3逆时针
  1873. function linshuiRoomView:showSwapDirection(dir)
  1874. if not dir then return end
  1875. self:hideSwapDirection()
  1876. local ui=loadUI("mj_linshui/res/ui_fangjian/mj_linshui_swap_direction.ui")
  1877. self.ui.Items.Layout_Player:addChild(ui)
  1878. self.swapDirection=ui
  1879. self.swapDirection.Items.Layout_ShunShiZhen:setVisible(dir == 1)
  1880. self.swapDirection.Items.Layout_NiShiZhen:setVisible(dir == 3)
  1881. self.swapDirection.Items.Layout_DuiJia:setVisible(dir == 2)
  1882. self.swapDirection.Items.ImageView_s:playClip("shunshizhen")
  1883. self.swapDirection.Items.ImageView_n:playClip("nishizhen")
  1884. self.swapDirection.Items.Layout_DuiJia:playClip("duijia")
  1885. self.swapDirection:runAction(cc.Sequence:create(cc.DelayTime:create(1.0),cc.CallFunc:create(function()
  1886. self:hideSwapDirection()
  1887. end)))
  1888. end
  1889. function linshuiRoomView:hideSwapDirection()
  1890. if self.swapDirection then
  1891. self.swapDirection:removeFromParent()
  1892. self.swapDirection = nil
  1893. end
  1894. end
  1895. --显示定缺界面
  1896. function linshuiRoomView:showDingQue(tp)
  1897. self:hideDingQue()
  1898. local ui=loadUI("mj_linshui/res/ui_fangjian/mj_linshui_dingque.ui")
  1899. self:addChild(ui)
  1900. self.dingque=ui
  1901. self:showDingQueOpEffect(tp)
  1902. for i=1,4 do--先隐藏全部
  1903. if self.dingque.Items["Layout_DingQue_"..i] then
  1904. self.dingque.Items["Layout_DingQue_"..i]:setVisible(false)
  1905. end
  1906. end
  1907. for k,v in pairs(app.room.roomInfo.memberList) do--根据人数显示
  1908. local viewId = app.room:getViewIdByUserId(v.nUserId)
  1909. if self.playerHandCards[viewId] then
  1910. if self.dingque.Items["Layout_DingQue_"..viewId] then
  1911. self.dingque.Items["Layout_DingQue_"..viewId]:setVisible(true)
  1912. end
  1913. else
  1914. if self.dingque.Items["Layout_DingQue_"..viewId] then
  1915. self.dingque.Items["Layout_DingQue_"..viewId]:setVisible(false)
  1916. end
  1917. end
  1918. end
  1919. ui.Items.Button_Wan:registerClick(function()
  1920. playBtnEffect()
  1921. self:hideDingQueOp()
  1922. local request = MJMessage.QueCard:new()
  1923. request.queCard = 0
  1924. logD(request.isDingQue,"发送定缺:0")
  1925. self.ui:sendMsg(app.room, MJDefine.MJEvent.RequestDingQue, request)
  1926. end)
  1927. ui.Items.Button_Tong:registerClick(function()
  1928. playBtnEffect()
  1929. self:hideDingQueOp()
  1930. local request = MJMessage.QueCard:new()
  1931. request.queCard = 1
  1932. logD(request.isDingQue,"发送定缺:1")
  1933. self.ui:sendMsg(app.room, MJDefine.MJEvent.RequestDingQue, request)
  1934. end)
  1935. ui.Items.Button_Tiao:registerClick(function()
  1936. playBtnEffect()
  1937. self:hideDingQueOp()
  1938. local request = MJMessage.QueCard:new()
  1939. request.queCard = 2
  1940. logD(request.isDingQue,"发送定缺:2")
  1941. self.ui:sendMsg(app.room, MJDefine.MJEvent.RequestDingQue, request)
  1942. end)
  1943. end
  1944. --隐藏定缺界面
  1945. function linshuiRoomView:hideDingQue()
  1946. if self.dingque then
  1947. self.dingque:removeFromParent()
  1948. self.dingque=nil
  1949. end
  1950. end
  1951. --显示定缺界面操作按钮特效
  1952. function linshuiRoomView:showDingQueOpEffect(tp)
  1953. if not self.dingque or tolua.isnull(self.dingque) then
  1954. return
  1955. end
  1956. self.dingque.Items.Layout_Wan_Effect:setVisible(tp==0)
  1957. self.dingque.Items.Layout_Tong_Effect:setVisible(tp==1)
  1958. self.dingque.Items.Layout_Tiao_Effect:setVisible(tp==2)
  1959. self.dingque.Items.ImageView_Wan_Effect1:playClip("neiquan")
  1960. self.dingque.Items.ImageView_Wan_Effect2:playClip("waiquan")
  1961. self.dingque.Items.ImageView_Tong_Effect1:playClip("neiquan")
  1962. self.dingque.Items.ImageView_Tong_Effect2:playClip("waiquan")
  1963. self.dingque.Items.ImageView_Tiao_Effect1:playClip("neiquan")
  1964. self.dingque.Items.ImageView_Tiao_Effect2:playClip("waiquan")
  1965. end
  1966. --隐藏定缺界面操作按钮
  1967. function linshuiRoomView:hideDingQueOp()
  1968. if not self.dingque or tolua.isnull(self.dingque) then
  1969. return
  1970. end
  1971. self.dingque.Items.Button_Wan:setVisible(false)
  1972. self.dingque.Items.Button_Tong:setVisible(false)
  1973. self.dingque.Items.Button_Tiao:setVisible(false)
  1974. self.dingque.Items.Layout_Wan_Effect:setVisible(false)
  1975. self.dingque.Items.Layout_Tong_Effect:setVisible(false)
  1976. self.dingque.Items.Layout_Tiao_Effect:setVisible(false)
  1977. end
  1978. --设置定缺成功 isDingque:true显示有勾的,false显示定缺中
  1979. function linshuiRoomView:setDingQueSucc(isDingque,viewId)
  1980. isDingque = isDingque or false
  1981. if not self.dingque or tolua.isnull(self.dingque) then
  1982. return
  1983. end
  1984. if self.dingque.Items["ImageView_dingquez_"..viewId] then
  1985. self.dingque.Items["ImageView_dingquez_"..viewId]:setVisible(not isDingque)
  1986. end
  1987. if self.dingque.Items["ImageView_dingquew_"..viewId] then
  1988. self.dingque.Items["ImageView_dingquew_"..viewId]:setVisible(isDingque)
  1989. end
  1990. end
  1991. function linshuiRoomView:onBtnTingInfoClicked( )
  1992. --[[playBtnEffect()
  1993. if self.ui.Items.Layout_Ting_Tip_Card_Panel:isVisible() then
  1994. self.ui.Items.Layout_Ting_Tip_Card_Panel:setVisible(false)
  1995. else
  1996. self.ui:sendMsg(app.room,MJDefine.MJEvent.Ting)
  1997. end--]]
  1998. playBtnEffect()
  1999. if self._tingCardView:isVisible() then
  2000. self:setTingCardVisible(false);
  2001. else
  2002. self:setTingCardVisible(true);
  2003. end
  2004. end
  2005. function linshuiRoomView:onChangeChatEnable()
  2006. if not self.messageView or tolua.isnull(self.messageView) then
  2007. return
  2008. end
  2009. local voiceEnable = tonumber(loadUserInfo("linshuiPingBiYuYinKG")) or 1
  2010. local propEnable = tonumber(loadUserInfo("linshuiHuDongBiaoQingKG")) or 1
  2011. self.messageView:setVoiceEnabled(voiceEnable==1)
  2012. self.messageView:setPropEnabled(propEnable==1)
  2013. end
  2014. function linshuiRoomView:onEventChangeViewType(data)
  2015. self:changeGameBg(true)
  2016. logD("linshuiRoomView:onEventChangeViewType "..self.desktopType)
  2017. MJDefine.MJConfig = MJDefine.loadMJConfig(self.desktopType)
  2018. logD("linshuiRoomView:onEventChangeViewType "..MJDefine.MJConfig_2d.MAHJONG_CARD)
  2019. self.ui:sendMsg(app.room, MJDefine.MJEvent.GetTableInfo);
  2020. end
  2021. --服务器通知定缺
  2022. function linshuiRoomView:onNoticeDingQueResponse(response)
  2023. local function runNoticeDingQue(onEnd)
  2024. logD("linshuiRoomView:onNoticeDingQueResponse")
  2025. local data = response.response
  2026. self:showDingQue(data.queCard)
  2027. for i=1,4 do--置为定缺中
  2028. self:setDingQueSucc(false,i)
  2029. end
  2030. self.playerHandCards[MJDefine.MyViewId]:setHandCardsDidable()
  2031. if onEnd then
  2032. onEnd()
  2033. end
  2034. end
  2035. logD("linshuiRoomView:runNoticeDingQue")
  2036. self:addCallBack(runNoticeDingQue)
  2037. end
  2038. --当玩家操作成功后,通过0x8131广播定缺成功
  2039. function linshuiRoomView:onDingQueSuccResponse(response)
  2040. local function runDingQueSucc(onEnd)
  2041. logD("linshuiRoomView:onDingQueSuccResponse")
  2042. local data = response.response
  2043. local userId = data.nUserId--操作的玩家
  2044. local viewId = app.room:getViewIdByUserId(userId)
  2045. if viewId == MJDefine.MyViewId then
  2046. self:hideDingQueOp()
  2047. self.playerView:showQue(data.queCard,viewId,true)
  2048. self.playerHandCards[viewId]:setQueType(data.queCard)
  2049. else
  2050. self:setDingQueSucc(true,viewId)
  2051. end
  2052. if onEnd then
  2053. onEnd()
  2054. end
  2055. end
  2056. logD("linshuiRoomView:runDingQueSucc")
  2057. self:addCallBack(runDingQueSucc)
  2058. end
  2059. --当所有玩家定缺成功后,服务器会通过广播告诉玩家定缺类型
  2060. function linshuiRoomView:onDingQueSuccInfoResponse(response)
  2061. local function runDingQueSuccInfo(onEnd)
  2062. logD("linshuiRoomView:onDingQueSuccInfoResponse")
  2063. self:hideDingQue()
  2064. local data = response.response
  2065. for i,v in pairs(data.dingQueInfo) do
  2066. local userId = v.nUserId--操作的玩家
  2067. local viewId = app.room:getViewIdByUserId(userId)
  2068. self.playerView:showQue(v.queCard,viewId,true)
  2069. self.playerHandCards[viewId]:setQueType(v.queCard)
  2070. if viewId == MJDefine.MyViewId then
  2071. self.playerHandCards[viewId]:initTouchEvent()
  2072. end
  2073. self.playerHandCards[viewId]:resetHandCards()
  2074. end
  2075. self.playerHandCards[MJDefine.MyViewId]:checkQueAndDisableOtherCard()
  2076. if onEnd then
  2077. onEnd()
  2078. end
  2079. end
  2080. logD("linshuiRoomView:runDingQueSuccInfo")
  2081. self:addCallBack(runDingQueSuccInfo)
  2082. end
  2083. function linshuiRoomView:onCheckIsInSwapRule(data)
  2084. if not data then return end
  2085. if not self.swapCard then return end
  2086. self.swapCard.Items.Button_sure:setEnabled(data.canCommit)
  2087. end
  2088. --躺牌结果
  2089. function linshuiRoomView:onTangPaiResponse(response)
  2090. if not response then return end
  2091. local data = response.response
  2092. if not data then return end
  2093. local opUserId = data.nUserId
  2094. local viewId = app.room:getViewIdByUserId(opUserId)
  2095. local isTang = data.isTang
  2096. local tangCards = data.tangCards
  2097. local paoCards = data.paoCards
  2098. --躺的人手牌躺牌变色 其他人看到躺牌倒下
  2099. local myUserId = app.room:getMyUserId()
  2100. self.playerHandCards[MJDefine.MyViewId]:setPaoCard(true,paoCards)
  2101. if opUserId == myUserId then
  2102. self.isTang = true
  2103. self.playerHandCards[viewId]:setTangSuccess(true)
  2104. self.playerHandCards[viewId]:setTangCard(true,tangCards)
  2105. else
  2106. self.playerHandCards[viewId]:showTangCard(true,tangCards)
  2107. end
  2108. local effect=MJAnimationCompnent.CreateTangEffect()
  2109. if effect then
  2110. self.ui.Items.Layout_Player:addChild(effect)
  2111. effect:setLocalZOrder(1000)
  2112. effect:setPosition(self.playerHandCards[viewId]:getAnimationPostion())
  2113. end
  2114. --躺音效
  2115. local userInfo=app.room:getUserInfoByViewId(viewId)
  2116. MJSound.PlayTangSound(userInfo.sex)
  2117. end
  2118. -- 初始化听牌组件
  2119. function linshuiRoomView:initTingCardView ()
  2120. if not self._tingCardView then
  2121. self._tingCardView = require("mj_linshui.luaScript.Views.Compnent.linshuiTingCardView"):new();
  2122. self:addChild(self._tingCardView)
  2123. self._tingCardView:setData(nil);
  2124. self:setTingCardVisible(false);
  2125. end
  2126. end
  2127. -- 初始化听牌按钮
  2128. function linshuiRoomView:initTingBtnView ()
  2129. local linshuiTingBtnView = import("mj_linshui.luaScript.Views.Compnent.linshuiTingBtnView");
  2130. local btnTing = linshuiTingBtnView:new();
  2131. btnTing:setCallback(handler(self, self.onBtnTingInfoClicked));
  2132. btnTing:setPosition(cc.p(230, 158));
  2133. self.btnTing = btnTing;
  2134. self.ui.Items.Layout_record:addChild(self.btnTing)
  2135. end
  2136. function linshuiRoomView:setButtonTingInfoVisible(isVisible)
  2137. if self.btnTing then
  2138. self.btnTing:setVisible(isVisible);
  2139. end
  2140. end
  2141. function linshuiRoomView:setTingCardVisible (isVisible)
  2142. if not self._tingCardView then
  2143. return ;
  2144. end
  2145. self._tingCardView:setVisible(isVisible);
  2146. end
  2147. -- 飘操作---------------------------------------------------------------
  2148. function linshuiRoomView:showPiao()
  2149. self:stopDirection()
  2150. local roomInfo=app.room.roomInfo
  2151. local gameInfo=json.decode(roomInfo.strGameInfo)
  2152. if not gameInfo.piaomode or tonumber(gameInfo.piaomode)==0 then return end
  2153. self:hidePiao()
  2154. local ui=loadUI("mj_linshui/res/ui_fangjian/mj_linshui_piao.ui")
  2155. self.ui.Items.Layout_Player:addChild(ui)
  2156. self.piao=ui
  2157. ui.Items.Button_BuPiao:registerClick(function()
  2158. playBtnEffect()
  2159. self:hidePiao()
  2160. local request = MJMessage.PiaoRequest:new()
  2161. request.isPiao = 0
  2162. self.ui:sendMsg(app.room,MJDefine.MJEvent.PiaoRequest,request)
  2163. end)
  2164. for i=1,5 do
  2165. local uiButton = string.format("Button_Piao_%d",i)
  2166. ui.Items[uiButton]:registerClick(function()
  2167. playBtnEffect()
  2168. self:hidePiao()
  2169. local request = MJMessage.PiaoRequest:new()
  2170. request.isPiao = i
  2171. self.ui:sendMsg(app.room,MJDefine.MJEvent.PiaoRequest,request)
  2172. end)
  2173. end
  2174. end
  2175. function linshuiRoomView:hidePiao()
  2176. if self.piao then
  2177. self.piao:removeFromParent()
  2178. self.piao=nil
  2179. end
  2180. end
  2181. --显示飘操作按钮
  2182. function linshuiRoomView:onStartPiao(response)
  2183. local function runPiao(onEnd)
  2184. logD("linshuiRoomView:onStartPiao")
  2185. self:showPiao()
  2186. if onEnd then
  2187. onEnd()
  2188. end
  2189. end
  2190. logD("linshuiRoomView:runPiao")
  2191. self:addCallBack(runPiao)
  2192. end
  2193. --飘结果
  2194. function linshuiRoomView:onPiaoResponse(response)
  2195. local function runonPiaoResponse(onEnd)
  2196. logD("linshuiRoomView:runonPiaoResponse")
  2197. local data = response.response
  2198. local userId = data.nUserId--操作的玩家
  2199. local playersPiaostate = data.playerPiaoState--所有玩家的飘状态
  2200. if playersPiaostate then
  2201. for i,v in pairs(playersPiaostate) do
  2202. local viewId = app.room:getViewIdByUserId(v.nUserId)
  2203. local myUserId = app.room:getMyUserId()
  2204. local userInfo=app.room:getUserInfoByViewId(viewId)
  2205. if myUserId == data.nUserId then
  2206. else
  2207. end
  2208. self.playerView:showPiao(viewId,v.piaostate)
  2209. app.room.roomInfo.memberList[v.nUserId].isPiao = v.piaostate
  2210. if v.piaostate>0 and userId == v.nUserId then
  2211. --飘音效
  2212. MJSound.PlayPiaoSound(userInfo.sex)
  2213. local effect = MJAnimationCompnent.CreatePiaoEffect()
  2214. if effect then
  2215. self.ui.Items.Layout_Effect_luobo:addChild(effect)
  2216. effect:setLocalZOrder(1000)
  2217. effect:setPosition(self.playerHandCards[viewId]:getAnimationPostion())
  2218. end
  2219. end
  2220. end
  2221. else
  2222. local viewId = app.room:getViewIdByUserId(userId)
  2223. self.playerView:showPiao(viewId,data.piaostate)
  2224. app.room.roomInfo.memberList[userId].isPiao = data.piaostate
  2225. if data.piaostate and data.piaostate > 0 then
  2226. --飘音效
  2227. local userInfo=app.room:getUserInfoByViewId(viewId)
  2228. MJSound.PlayPiaoSound(userInfo.sex)
  2229. local effect = MJAnimationCompnent.CreatePiaoEffect()
  2230. if effect then
  2231. self.ui.Items.Layout_Effect_luobo:addChild(effect)
  2232. effect:setLocalZOrder(1000)
  2233. effect:setPosition(self.playerHandCards[viewId]:getAnimationPostion())
  2234. end
  2235. end
  2236. end
  2237. if onEnd then
  2238. onEnd()
  2239. end
  2240. end
  2241. logD("linshuiRoomView:runonPiaoResponse--------")
  2242. self:addCallBack(runonPiaoResponse)
  2243. end
  2244. function linshuiRoomView:showBaoJiao()
  2245. self:hideBaoJiao()
  2246. local ui=loadUI("mj_linshui/res/ui_fangjian/mj_linshui_baojiao.ui")
  2247. self:addChild(ui)
  2248. self.baojiao=ui
  2249. ui.Items.Button_Bao:registerClick(function()
  2250. playBtnEffect()
  2251. self:hideBaoJiao()
  2252. local request = MJMessage.BaoPaiRequest:new()
  2253. request.isBaoPai = 1
  2254. logD(request.isBaoPai,"发送爆:1")
  2255. self.ui:sendMsg(app.room, MJDefine.MJEvent.BaoPaiRequest, request)
  2256. end)
  2257. ui.Items.Button_guo:registerClick(function()
  2258. playBtnEffect()
  2259. self:hideBaoJiao()
  2260. local request = MJMessage.BaoPaiRequest:new()
  2261. request.isBaoPai = 0
  2262. logD(request.isBaoPai,"发送爆:0")
  2263. self.ui:sendMsg(app.room, MJDefine.MJEvent.BaoPaiRequest, request)
  2264. end)
  2265. --[[local gameInfo =json.decode(app.room.roomInfo.strGameInfo);
  2266. if gameInfo.baojiao then
  2267. ui.Items.Button_Bao:setVisible(gameInfo.baojiao == 1);
  2268. end--]]
  2269. ui.Items.Layout_baojiao:requestDoLayout()
  2270. ui.Items.Layout_baojiao:doLayout();
  2271. end
  2272. function linshuiRoomView:hideBaoJiao()
  2273. if self.baojiao then
  2274. self.baojiao:removeFromParent()
  2275. self.baojiao=nil
  2276. end
  2277. end
  2278. ---
  2279. -- 托管通知
  2280. -- @param data
  2281. -- @return
  2282. --
  2283. function linshuiRoomView:onHostingRequest( data )
  2284. local response = data.response
  2285. if response.nUserId == app.user.loginInfo.uid then
  2286. if response.status == 1 then --托管状态
  2287. self.toolView:showTuoGuan(true)
  2288. self:hidePiao()
  2289. elseif response.status == 0 then--取消托管状态
  2290. self.toolView:showTuoGuan(false)
  2291. end
  2292. end
  2293. local isTuoGuan = response.status == 1;
  2294. local viewId = app.room:getViewIdByUserId(response.nUserId)
  2295. self.playerView:showTuoGuanByViewId(viewId,isTuoGuan)
  2296. end
  2297. function linshuiRoomView:onWaitOperate(data)
  2298. --什么都不做
  2299. end
  2300. return linshuiRoomView