您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

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