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

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