Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

1760 строки
58 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 zigongRoomView = class("zigongRoomView", MJRoomView)
  19. local zhongNiaoTime=1.33
  20. local HU_EFFECT_TAG = 100
  21. function zigongRoomView:ctor()
  22. zigongRoomView.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_zg_desktop_2d_mjType")
  26. if value=="" or not value then
  27. value = MJDefine.DesktopType.TwoD
  28. saveUserInfo("mj_zg_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 zigongRoomView:loadUi()
  37. local ui = loadUI("mj_zigong/res/ui_fangjian/mj_zigong_roomView.ui")
  38. self.ui = ui
  39. self:addChild(ui)
  40. end
  41. function zigongRoomView:onEnter()
  42. zigongRoomView.super.onEnter(self)
  43. --获取是否贴鬼杠和是否自动对齐
  44. self:setCheckDefault()
  45. self:doSound()
  46. end
  47. function zigongRoomView:initView ()
  48. zigongRoomView.super.initView(self);
  49. self:initRuleView();
  50. end
  51. ---
  52. -- 初始化规则弹框
  53. -- @return
  54. --
  55. function zigongRoomView:initRuleView ()
  56. if self._ruleView then
  57. -- 已经创建过了
  58. return ;
  59. end
  60. local RuleViewClass = require("mj.luaScript.Views.Room.MJRuleViewVertical");
  61. local ruleView = RuleViewClass:new();
  62. self:addChild(ruleView);
  63. local roomInfo = app.room.roomInfo or {};
  64. local ruleList = MJWanFa.getWanFaInfoTab(roomInfo.strGameInfo, roomInfo.nTotalGameNum)
  65. ruleView:setRuleList(ruleList or {});
  66. ruleView:setBtnRuleOffset(60, nil);
  67. self._ruleView = ruleView;
  68. end
  69. function zigongRoomView:onExit()
  70. zigongRoomView.super.onExit(self)
  71. self:cleanCache()
  72. end
  73. function zigongRoomView:cleanCache()
  74. local preload = package.loaded
  75. for k, v in pairs(package.loaded or {}) do
  76. local res1 = string.find( k, "mj.luaScript") or 0
  77. local res2 = string.find( k, "mj_zigong.luaScript") or 0
  78. if res1 > 0 or res2 > 0 then
  79. package.loaded[k] = nil
  80. end
  81. end
  82. end
  83. function zigongRoomView:doSound()--1 普通话 2 方言
  84. local cacheLan = "mj_language"..(MJDefine.GameID or app.gameId)
  85. local defaultValue = tonumber(loadUserInfo(cacheLan)) or 2
  86. saveUserInfo(cacheLan,defaultValue)
  87. MJSound.setSoundType(defaultValue)
  88. end
  89. function zigongRoomView:setCheckDefault()
  90. MJDefine.isAutomatic = true
  91. end
  92. -- 一键截屏
  93. function zigongRoomView:onClickButtonShot( sender )
  94. playBtnEffect()
  95. showScreenShot()
  96. end
  97. --隐藏俱乐部
  98. function zigongRoomView:hideClub()
  99. -- self.ui.Items.Button_Club:setVisible(false)
  100. if self.clubView and not tolua.isnull(self.clubView) then
  101. self.clubView:removeFromParent()
  102. self.clubView=nil
  103. end
  104. end
  105. --更换桌布(同维度)
  106. function zigongRoomView:changeGameBg(isUpdateViewType)
  107. if isUpdateViewType then
  108. if app.systemSetting.info.viewType == MJDefine.DesktopType.TwoD then --更新2D麻将类型 金色还是绿色
  109. local value = loadUserInfo("mj_zg_desktop_2d_mjType") --or MJDefine.DesktopType.TwoD
  110. if value=="" or not value then
  111. value = MJDefine.DesktopType.TwoD
  112. saveUserInfo("mj_zg_desktop_2d_mjType", value)
  113. end
  114. logD("changeGameBg value:"..value)
  115. self.desktopType = value
  116. else
  117. self.desktopType = app.systemSetting.info.viewType
  118. end
  119. self:loadTextureCache()
  120. logD("changeGameBg"..self.desktopType)
  121. end
  122. local defaultValue = tonumber(loadUserInfo("zigong_mj_desktop_group")) or 2
  123. local bgData = MJDefine.CHANGE_GAME_BG[defaultValue]
  124. if self.desktopType==MJDefine.DesktopType.TwoD or self.desktopType==MJDefine.DesktopType.TwoDGold then
  125. self.ui.Items.ImageView_bg:loadTexture(bgData['2d'])
  126. else
  127. self.ui.Items.ImageView_bg:loadTexture(bgData['3d'])
  128. end
  129. end
  130. function zigongRoomView:defaultState()
  131. --队列初始化
  132. self.callbackQueue = {}
  133. self.callbackRunning = false
  134. self.playerView:setOffLineVisible(false)
  135. self.playerView:setPlayerVisible(false)
  136. if self.waitOperates and #self.waitOperates>0 then
  137. for k,v in pairs(self.waitOperates) do
  138. v:removeFromParent()
  139. end
  140. end
  141. self.waitOperates = {}
  142. self:resetGame()
  143. end
  144. function zigongRoomView:loadTextureCache()
  145. zigongRoomView.super.loadTextureCache(self)
  146. -- local defaultValue = tonumber(loadUserInfo("luzhou_mj_majhong")) or 1
  147. loadSpriteFrameFile("mj_zigong/res/zy_fangjian/zigong_operateEffect.plist")
  148. loadSpriteFrameFile("mj_zigong/res/zy_fangjian/effect_guangxiao.plist")
  149. loadSpriteFrameFile("mj_zigong/res/zy_fangjian/effect_guafeng.plist")
  150. loadSpriteFrameFile("mj_zigong/res/zy_fangjian/effect_xiayu.plist")
  151. end
  152. function zigongRoomView:initGameButton()
  153. --点击空白
  154. self.ui.Items.Layout_Touch:registerClick(nil,function()
  155. -- 隐藏个人信息
  156. self.playerView:removePlayerInfoView()
  157. self.toolView:setMenuVisible(false)
  158. if self.playerHandCards[MJDefine.MyViewId] then
  159. self.playerHandCards[MJDefine.MyViewId]:hideOperateItem()
  160. end
  161. self.toolView:hideRule()
  162. self:setTingCardViewVisible(false);
  163. end)
  164. --隐藏听牌模板
  165. self.ui.Items.Item_Ting:setVisible(false)
  166. self.ui.Items.Button_Ting_Info:setVisible(false);
  167. self.ui.Items.Button_Ting_Info:registerClick(handler(self, self.onBtnTingInfoClicked))
  168. self.toolView.ui.Items.Button_Face:setPosition(cc.p(1208*g_radio_x,(322+25)*g_radio_y))
  169. self.toolView.ui.Items.Button_Voice:setPosition(cc.p(1208*g_radio_x,(237+30)*g_radio_y))
  170. end
  171. --通知庄家可以爆牌
  172. function zigongRoomView:onBankerBaoPai(data)
  173. local function runBankerBaoPai(onEnd)
  174. local myUserId = app.room:getMyUserId()
  175. local viewId = app.room:getViewIdByUserId(myUserId)
  176. if data.response.nUserId == myUserId then
  177. self:showBaoJiao()
  178. self.playerHandCards[viewId]:setOutCardEnable(false)
  179. end
  180. if onEnd then
  181. onEnd()
  182. end
  183. end
  184. self:addCallBack(runBankerBaoPai)
  185. end
  186. --广播玩家爆牌
  187. function zigongRoomView:onBaoPai(data)
  188. if data.response.isBaoPai == 1 then
  189. local effect=MJAnimationCompnent.CreateBaoEffect()
  190. local viewId = app.room:getViewIdByUserId(data.response.nUserId)
  191. local myUserId = app.room:getMyUserId()
  192. local userInfo=app.room:getUserInfoByViewId(viewId)
  193. --爆牌音效
  194. MJSound.PlayBaoSound(userInfo.sex)
  195. if effect then
  196. self.ui.Items.Layout_Player:addChild(effect)
  197. effect:setLocalZOrder(1000)
  198. effect:setPosition(self.playerHandCards[viewId]:getAnimationPostion())
  199. end
  200. if myUserId == data.response.nUserId then
  201. self.playerHandCards[viewId]:lockHandCard(true)
  202. -- self.playerHandCards[viewId]:setOutCardEnable(false)
  203. else
  204. --self.playerHandCards[viewId]:setOutCardEnable(true)
  205. end
  206. self.playerView:playBaoAnim(viewId)
  207. elseif data.response.isBaoPai == 2 then--博自摸
  208. local effect=MJAnimationCompnent.CreateBoZiMoEffect()
  209. local viewId = app.room:getViewIdByUserId(data.response.nUserId)
  210. local myUserId = app.room:getMyUserId()
  211. local userInfo=app.room:getUserInfoByViewId(viewId)
  212. --爆牌音效
  213. MJSound.PlayBaoSound(userInfo.sex)
  214. if effect then
  215. self.ui.Items.Layout_Player:addChild(effect)
  216. effect:setLocalZOrder(1000)
  217. effect:setPosition(self.playerHandCards[viewId]:getAnimationPostion())
  218. end
  219. if myUserId == data.response.nUserId then
  220. self.playerHandCards[viewId]:lockHandCard(true)
  221. else
  222. end
  223. self.playerView:showBoZiMo(viewId,true)
  224. end
  225. if app.room:getMyUserId() == data.response.nUserId then
  226. self:hideBaoJiao()
  227. if (data.response.isBaoPai == 1 or data.response.isBaoPai == 2) then
  228. local gameInfo =json.decode(app.room.roomInfo.strGameInfo);
  229. if gameInfo.tingpai > 0 then
  230. self.ui.Items.Button_Ting_Info:setVisible(true);
  231. app.room.roomInfo.memberList[data.response.nUserId].nTingStatus = MJDefine.MJTingStatus.Ting;
  232. end
  233. end
  234. end
  235. end
  236. function zigongRoomView:onGameSendCardResponse()
  237. --发牌的时候清除桌面上的飘
  238. self.ui.Items.Layout_Effect_luobo:removeAllChildren()
  239. local function runGameSendCardResponse(onEnd)
  240. log("2000000000-zigongRoomView - runGameSendCardResponse()" )
  241. --走过重连标志值为false
  242. self.isRunGameReconnection = false
  243. self:hidePiao()
  244. local myUserId = app.room:getMyUserId()
  245. for k,v in pairs(app.room.roomInfo.memberList) do
  246. local viewId = app.room:getViewIdByUserId(v.nUserId)
  247. if self.playerHandCards[viewId] then
  248. self.playerHandCards[viewId]:createHandCards(v.handCards)
  249. self.playerHandCards[viewId]:resetHandCards()
  250. end
  251. if v.isBaoPai == 1 and myUserId == v.nUserId then
  252. --self.playerHandCards[viewId]:showBaoPai()
  253. self:showBaoJiao()
  254. end
  255. end
  256. -- local effect=MJAnimationCompnent.CreateGameStart()
  257. -- self.ui.Items.Layout_Player:addChild(effect,5)
  258. -- MJSound.PlayStartGame()
  259. MJAnimationCompnent.CreateStartSendCards(self.playerHandCards,onEnd)
  260. -- if onEnd then
  261. -- onEnd()
  262. -- end
  263. self.toolView:showTuoGuan(app.room.roomInfo.hosting==1)
  264. end
  265. log("2000000000-zigongRoomView - addCallBack(runGameSendCardResponse)" )
  266. self:addCallBack(runGameSendCardResponse);
  267. end
  268. function zigongRoomView:onUserReadyResponse(response)
  269. zigongRoomView.super.onUserReadyResponse(self,response)
  270. local myUserId = app.room:getMyUserId()
  271. if response and response.nUserId==myUserId then
  272. self.playerView:clearBao()
  273. self.playerView:clearAllPiao()
  274. self.playerView:clearAllBoZiMo()
  275. app.room.roomInfo.luoboCards = nil
  276. -- local roomInfo = app.room.roomInfo
  277. -- for k,v in pairs(roomInfo.memberList) do
  278. -- self.ui.Items.Layout_Player:removeChildByTag(HU_EFFECT_TAG)
  279. -- end
  280. end
  281. self.ui.Items.Button_Ting_Info:setVisible(false);
  282. end
  283. -- 广播桌子上所有玩家庄家起手操作 这里其实是发牌
  284. function zigongRoomView:onBankerOutCard(data)
  285. --[[ -- 庄家uid
  286. , defVar("nUserId", VT_Int, 0)
  287. -- 庄家操作类型
  288. , defVar("mainOpCode", VT_Short, 0)
  289. --庄家是否需要出牌0不需要 1:需要
  290. , defVar("IsShouldOutCard", VT_UChar, 0)--]]
  291. local function runOnBankerOutCard(onEnd)
  292. logE("zigongRoomView onBankerOutCard :"..table.tostring(data.response))
  293. -- if not data.response.nUserId then
  294. -- showTooltip("庄家起手操作nUserId is not exist")
  295. -- end
  296. local viewId = app.room:getViewIdByUserId(data.response.nUserId)
  297. local card= data.response.card
  298. local operates=data.response.operates
  299. local nSeatId=data.response.nSeatId
  300. -- app.room.roomInfo.outCardUserId = data.response.nUserId
  301. if self.playerHandCards[viewId] then
  302. self.playerHandCards[viewId]:onGetCard(operates,card)
  303. end
  304. --先清除所有操作按钮
  305. --self.playerHandCards[MJDefine.MyViewId]:hideOperate()
  306. self.playerHandCards[MJDefine.MyViewId]:hideOperateItem()
  307. self.playerHandCards[MJDefine.MyViewId]:showOperate(operates,card,true)
  308. if viewId == MJDefine.MyViewId then
  309. self.ui.Items.Button_Ting_Info:setVisible(false)
  310. if operates and table.nums(operates)>0 then
  311. self.operates = operates
  312. else
  313. self.operates = {}
  314. end
  315. if self.playerHandCards[MJDefine.MyViewId] then
  316. self.playerHandCards[MJDefine.MyViewId]:setTing(false)
  317. local player = app.room.roomInfo.memberList[data.response.nUserId]
  318. if player and player.isBaoPai==1 then
  319. self.playerHandCards[MJDefine.MyViewId]:lockHandCard(true)
  320. end
  321. end
  322. app.room:dispatchEvent({name = MJDefine.MJEvent.SelectCard})
  323. app.room:dispatchEvent({name = MJDefine.MJEvent.PushTing})
  324. -- app.room:dispatchEvent({name = MJDefine.MJEvent.ShowTing})
  325. local curHandCards = self.playerHandCards[viewId]:getHandCardsNum()
  326. if curHandCards%3 ~= 2 then--抓了牌之后,手牌不正确,主动重连一下
  327. app.room.roomInfo.requestGetTableInfo = true
  328. self.ui:sendMsg(app.room, MJDefine.MJEvent.GetTableInfo);
  329. end
  330. end
  331. -- local myUserId = app.room:getMyUserId()
  332. -- if data.response.nUserId == myUserId then
  333. -- if self.playerHandCards[MJDefine.MyViewId] then
  334. -- self.playerHandCards[MJDefine.MyViewId]:pushTing()
  335. -- end
  336. -- end
  337. self:updateGameNums()
  338. self.direcionView:updateDirection(nSeatId)
  339. if onEnd then
  340. onEnd()
  341. end
  342. end
  343. log("2000000000-zigongRoomView - addCallBack(runOnBankerOutCard)")
  344. self:addCallBack(runOnBankerOutCard);
  345. end
  346. function zigongRoomView:onTurnOutCard(data)
  347. local function runOnTurnOutCard(onEnd)
  348. logE("MJRoomView:runOnOutCard(), response = ", table.tostring(data.response))
  349. log("2000000000-MJRoomView - runOnOutCard")
  350. if app.room.roomInfo.lastOutViewId~=MJDefine.MyViewId then
  351. self.playerHandCards[MJDefine.MyViewId]:setOutCardEnable(true)
  352. end
  353. -- local viewId = app.room:getViewIdByUserId(data.response.nUserId)
  354. -- local card= data.response.card
  355. -- if self.playerHandCards[viewId] then
  356. -- self.playerHandCards[viewId]:createOutCards(card)
  357. -- end
  358. if onEnd then
  359. onEnd()
  360. end
  361. end
  362. log("2000000000-MJRoomView - addCallBack(runOnTurnOutCard)")
  363. self:addCallBack(runOnTurnOutCard)
  364. end
  365. --出牌成功
  366. function zigongRoomView:onOutCardSuccess(data)
  367. logE("zigongRoomView:onOutCardSuccess(), response = ", table.tostring(data.response))
  368. local function runOnOutCardSuccess(onEnd)
  369. log("2000000000-zigongRoomView - runOnOutCardSuccess---------")
  370. -- app.room.roomInfo.outCardUserId = data.response.nUserId
  371. local viewId = app.room:getViewIdByUserId(data.response.nUserId)
  372. local card= data.response.card
  373. local operates=data.response.operates
  374. local typr = operates.opType
  375. if operates and table.nums(operates)>0 then
  376. self.operates = operates
  377. else
  378. self.operates = {}
  379. end
  380. local function callback()
  381. -- app.room.roomInfo.lastOutViewId = nil
  382. self.playerHandCards[MJDefine.MyViewId]:showOperate(operates,card)
  383. if onEnd then
  384. onEnd()
  385. end
  386. end
  387. -- self.lastOutCard = card
  388. if self.playerHandCards[viewId] then
  389. --(viewId~=MJDefine.MyViewId or player.isBaoPai == 1) and app.room.roomInfo.lastOutViewId~=MJDefine.MyViewId
  390. if viewId==MJDefine.MyViewId then
  391. local player = app.room.roomInfo.memberList[data.response.nUserId]
  392. self.playerHandCards[viewId]:setTing(false)
  393. local curHandCards = self.playerHandCards[viewId]:getHandCardsNum() or 0
  394. if ((player.isBaoPai==1 or player.isBaoPai==2) and app.room.roomInfo.lastOutViewId~=MJDefine.MyViewId) or app.room.roomInfo.hosting == 1 then --点击爆牌的时候 前端已经打出牌 要判断上次出牌的人是不是自己 避免重复出牌
  395. self.playerHandCards[viewId]:onOutCard(card,callback)
  396. --音效
  397. local userInfo=app.room:getUserInfoByViewId(viewId)
  398. if userInfo then
  399. MJSound.PlayMJSound(userInfo.sex,card)
  400. end
  401. elseif self.needDeleteOutCard and true == self.needDeleteOutCard then
  402. self.needDeleteOutCard = nil
  403. uploadLogs("mjduopai")
  404. self.playerHandCards[viewId]:onOutCard(card,callback)
  405. elseif self.isRunGameReconnection and true ==self.isRunGameReconnection and curHandCards%3 == 2 then--重连后,手牌是可以出牌的,则删除一张牌
  406. self.playerHandCards[viewId]:onOutCard(card,callback)
  407. else
  408. callback()
  409. end
  410. self.isRunGameReconnection = false
  411. local gameInfo = json.decode(app.room.roomInfo.strGameInfo);
  412. if gameInfo.tingpai > 0 then
  413. self._isOutCardTingCheck = true;
  414. self.ui:sendMsg(app.room,MJDefine.MJEvent.Ting)
  415. end
  416. else
  417. self.playerHandCards[viewId]:onOutCard(card,callback)
  418. end
  419. app.room:dispatchEvent({name = MJDefine.MJEvent.OutCardFalg, value=card ,viewId=viewId})
  420. else
  421. callback()
  422. end
  423. app.room.roomInfo.lastOutViewId = viewId
  424. end
  425. log("2000000000-zigongRoomView - addCallBack(runOnOutCardSuccess)")
  426. self:addCallBack(runOnOutCardSuccess)
  427. end
  428. --已经发送了过操作,此时就算再勾选贴鬼碰,也不会显示操作
  429. function zigongRoomView:onSendGuo()
  430. --发牌重置,主要用于贴鬼碰/杠
  431. MJDefine.isSendGuo = false
  432. self.operates = {}
  433. end
  434. -- 操作成功
  435. function zigongRoomView:onOperationCodeSuccess(data)
  436. local function runOnOperationSuccess(onEnd)
  437. local response = data.response
  438. local nUserId = response.nUserId
  439. local opType = response.opType
  440. local opCard = response.opCard
  441. local bIsOutCard = response.isNeedOutCard > 0
  442. local fromSeatId = response.fromSeatId
  443. local redNum = response.redNum
  444. local viewId = app.room:getViewIdByUserId(nUserId)
  445. local fromViewId = app.room:getViewIdBySeatId(fromSeatId)
  446. local opSeatId = app.room:getSeatIdByViewId(viewId)
  447. local fromUserId = app.room:getUserIdBySeatId(fromSeatId)
  448. if self.playerHandCards[viewId] then
  449. --组合一下牌
  450. local groups={
  451. self:getChangeGruopDatas({opType=opType, opCard=opCard, redNum = redNum, targetSeatId=opSeatId, opUserId=fromUserId})
  452. }
  453. --删除手中对应的牌
  454. local deleteCards
  455. for k,v in pairs(groups) do
  456. if v.showType==MJDefine.MJGroupType.Peng then
  457. self.playerHandCards[viewId]:removeHandCardByNum(opCard,2,v.redNum)
  458. elseif v.showType==MJDefine.MJGroupType.Chi then
  459. --TODO:吃的牌删除两张
  460. elseif v.showType==MJDefine.MJGroupType.AnGang
  461. or v.showType==MJDefine.MJGroupType.MAnGang then
  462. self.playerHandCards[viewId]:removeHandCardByNum(opCard,4,v.redNum)
  463. else
  464. if opType==MJDefine.MJOperateType.OPREATE_BAGANG then
  465. self.playerHandCards[viewId]:removeHandCardByNum(opCard,1,v.redNum)
  466. else
  467. self.playerHandCards[viewId]:removeHandCardByNum(opCard,3,v.redNum)
  468. end
  469. end
  470. end
  471. --删除出去的牌 遍历哪些操作需要删除牌
  472. for k,v in pairs(MJDefine.MJOperateNeedRemoveCard) do
  473. if v==opType then
  474. self.playerHandCards[fromViewId]:removeOutCard(opCard)
  475. break
  476. end
  477. end
  478. if opType==MJDefine.MJOperateType.OPREATE_BAGANG then
  479. self.playerHandCards[viewId]:buGang(opCard,redNum)
  480. else
  481. self.playerHandCards[viewId]:createGroupCards(groups)--创建显示的牌
  482. end
  483. self.playerHandCards[viewId]:resetHandCards()
  484. self.playerHandCards[viewId]:hideOperate()
  485. self.playerHandCards[viewId]:setOutCardEnable(bIsOutCard)
  486. self.direcionView:updateDirection(app.room:getSeatIdByViewId(viewId))
  487. end
  488. local function guafengxiayuEffect()
  489. local effect
  490. if (opType==MJDefine.MJOperateType.OPREATE_ZHIGANG) or (opType==MJDefine.MJOperateType.OPREATE_BAGANG) or
  491. (opType==MJDefine.MJOperateType.OPREATE_MINGGANG) then
  492. effect=MJAnimationCompnent.createGuaFengEffect()
  493. MJSound.PlayWindSound()
  494. elseif (opType==MJDefine.MJOperateType.OPREATE_ANGANG) then
  495. effect=MJAnimationCompnent.createXiaYuEffect()
  496. MJSound.PlayRainSound()
  497. end
  498. if effect then
  499. self.ui.Items.Layout_Player:addChild(effect)
  500. effect:setLocalZOrder(1000)
  501. effect:setPosition(self.playerHandCards[viewId]:getAnimationPostion())
  502. end
  503. end
  504. if (opType==MJDefine.MJOperateType.OPREATE_ZHIGANG) or (opType==MJDefine.MJOperateType.OPREATE_BAGANG) or
  505. (opType==MJDefine.MJOperateType.OPREATE_MINGGANG) or (opType==MJDefine.MJOperateType.OPREATE_ANGANG) then
  506. guafengxiayuEffect()
  507. else
  508. --播放动画
  509. local effect=MJAnimationCompnent.CreateOperareEffect(opType)--,onEnd)
  510. if effect then
  511. self.ui.Items.Layout_Player:addChild(effect)
  512. effect:setLocalZOrder(1000)
  513. effect:setPosition(self.playerHandCards[viewId]:getAnimationPostion())
  514. -- else
  515. -- if onEnd then
  516. -- onEnd()
  517. -- end
  518. end
  519. end
  520. --音效
  521. local userInfo=app.room:getUserInfo(nUserId)
  522. if userInfo then
  523. MJSound.PlayOperateSound(userInfo.sex,opType)
  524. end
  525. if viewId == MJDefine.MyViewId then
  526. self.playerHandCards[MJDefine.MyViewId]:setTing(false)
  527. self:setTingCardViewVisible(false)
  528. self.ui.Items.Button_Ting_Info:setVisible(false)
  529. self.operates={}
  530. end
  531. --删除等待操作的显示
  532. if self.waitOperates and #self.waitOperates>0 then
  533. for k,v in pairs(self.waitOperates) do
  534. v:removeFromParent()
  535. end
  536. self.waitOperates={}
  537. end
  538. --[[if viewId == MJDefine.MyViewId and opType==MJDefine.MJOperateType.OPREATE_PENG then
  539. local cards = {opCard}
  540. self.playerHandCards[viewId]:cardEnabled(cards, true)
  541. end--]]
  542. -- 取消操作按钮
  543. self.playerHandCards[MJDefine.MyViewId]:hideOperate()
  544. if onEnd then
  545. onEnd()
  546. end
  547. end
  548. self:addCallBack(runOnOperationSuccess)
  549. end
  550. function zigongRoomView:test()
  551. self.playerHandCards={}
  552. self.playerHandCards[MJDefine.MyViewId] = MJHandCardView:new(MJDefine.MyViewId)
  553. self:addChild(self.playerHandCards[MJDefine.MyViewId])
  554. self.playerView = MJRoomPlayerView:new()
  555. self:addChild(self.playerView)
  556. end
  557. --飘状态停止
  558. function zigongRoomView:stopDirection()
  559. self.direcionView:stopAllActions()
  560. self.direcionView.ui.Items.ImageView_Dir_Down:setVisible(false)
  561. self.direcionView.ui.Items.ImageView_Dir_Up:setVisible(false)
  562. self.direcionView.ui.Items.ImageView_Dir_Left:setVisible(false)
  563. self.direcionView.ui.Items.ImageView_Dir_Right:setVisible(false)
  564. self.direcionView.ui.Items.Text_Time:setString(string.format("%02d",0))
  565. self.direcionView.ui.Items.Text_Leave_Card_Num:setText("72")
  566. end
  567. function zigongRoomView:onGameReconnection()
  568. zigongRoomView.super.onGameReconnection(self)
  569. self.isRunGameReconnection = true
  570. local roomInfo = app.room.roomInfo
  571. local gameInfo=json.decode(roomInfo.strGameInfo)
  572. local piaoMode = gameInfo.piaomode
  573. -- 显示玩家头像上的托管标识
  574. for k,v in pairs(roomInfo.memberList) do
  575. local viewId = app.room:getViewIdByUserId(v.nUserId)
  576. local extInfo = roomInfo.extJson or ""
  577. if extInfo and type(extInfo)=='table' and extInfo[tostring(v.nUserId)] then
  578. local info = extInfo[tostring(v.nUserId)]
  579. local host = info.hosted or 0--托管状态
  580. local isTuoGuan = host == 1;
  581. self.playerView:showTuoGuanByViewId(viewId,isTuoGuan)
  582. end
  583. end
  584. local myUserId = app.room:getMyUserId()
  585. local isMyGetCard = false
  586. if roomInfo.nStatus and roomInfo.nStatus>=MJDefine.GameStatus.GAME_STATUS_WAIT_BANKER_START and roomInfo.nStatus<MJDefine.GameStatus.GAME_STATUS_GAME_OVER then
  587. -- 游戏开始后才显示托管状态
  588. self.toolView:showTuoGuan(app.room.roomInfo.hosting == 1)
  589. end
  590. if (roomInfo.nStatus==MJDefine.GameStatus.GAME_STATUS_ROUND_OVER or roomInfo.nStatus==MJDefine.GameStatus.GAME_STATUS_GAME_OVER) and
  591. roomInfo.memberList[myUserId].nPlayerFlag ~= 1 then
  592. --显示哪些玩家胡牌
  593. for i,player in pairs(roomInfo.memberList) do
  594. local viewId = app.room:getViewIdByUserId(player.nUserId)
  595. --已爆牌玩家
  596. if player.isBaoPai ~= 0 then
  597. --self.playerView:playBaoAnim(viewId)
  598. end
  599. local effect
  600. if player.result>0 and self.playerHandCards[viewId] then
  601. effect = MJAnimationCompnent.CreateHuOrderEffect(player.result,player.huOrder)
  602. if myUserId == player.nUserId then
  603. self.playerHandCards[viewId]:createHandCards(player.huCard)
  604. self.playerHandCards[viewId]:moveLastCard()
  605. else
  606. self.playerHandCards[viewId]:createOpenHandCards(player.huCard)
  607. self.playerHandCards[viewId]:moveLastOpenCard()
  608. end
  609. end
  610. if effect then
  611. self.ui.Items.Layout_Effect:addChild(effect)
  612. effect:setTag(HU_EFFECT_TAG)
  613. effect:setLocalZOrder(1000)
  614. local pos = self.playerHandCards[viewId]:getAnimationPostion()
  615. if viewId==MJDefine.PlayerViewType.My then
  616. effect:setPosition(pos.x,pos.y-60)
  617. elseif viewId==MJDefine.PlayerViewType.Left then
  618. effect:setPosition(pos.x-20,pos.y)
  619. elseif viewId==MJDefine.PlayerViewType.Right then
  620. effect:setPosition(pos.x+10,pos.y)
  621. elseif viewId==MJDefine.PlayerViewType.Top then
  622. effect:setPosition(pos.x,pos.y+10)
  623. end
  624. end
  625. if gameInfo.luobonum and gameInfo.luobonum > 0 then
  626. local effect1 = MJAnimationCompnent.CreateLoBoLabel(player.luoboNum or 0)
  627. local pos = self.playerHandCards[viewId]:getAnimationPostion()
  628. if viewId==MJDefine.PlayerViewType.My then
  629. effect1:setPosition(pos.x+130,pos.y-60)
  630. elseif viewId==MJDefine.PlayerViewType.Left then
  631. effect1:setPosition(pos.x-20-30,pos.y-70)
  632. elseif viewId==MJDefine.PlayerViewType.Right then
  633. effect1:setPosition(pos.x+10-30,pos.y-70)
  634. elseif viewId==MJDefine.PlayerViewType.Top then
  635. effect1:setPosition(pos.x+130,pos.y+10-50)
  636. end
  637. self.ui.Items.Layout_Effect:addChild(effect1)
  638. end
  639. end
  640. --[[local luoboCards = roomInfo.luoboCards
  641. if luoboCards and #luoboCards>0 then
  642. local luoNum = #luoboCards
  643. for i,v in pairs(luoboCards) do
  644. local mj=MJ:new(v,MJDefine.MJType.Out,MJDefine.MyViewId,self.desktopType)
  645. if MJDefine.LuoBoPos[luoNum] and MJDefine.LuoBoPos[luoNum][i] then
  646. mj:setPosition(MJDefine.LuoBoPos[luoNum][i])
  647. mj:setPositionY(mj:getPositionY()+25)
  648. self.ui.Items.Layout_Effect:addChild(mj)
  649. local mjSize = mj:getContentSize()
  650. local sprite = cc.Sprite:createWithSpriteFrameName("zg_room_luoboyezi.png")
  651. sprite:setScale(0.6)
  652. sprite:setPosition(cc.p(mjSize.width/2,mjSize.height+14))
  653. mj:addChild(sprite,-1)
  654. mj:setScale(1.5)
  655. end
  656. end
  657. end--]]
  658. elseif roomInfo.nStatus==MJDefine.GameStatus.GAME_STATUS_WAIT_PIAO then
  659. self:stopDirection()
  660. for i,player in pairs(roomInfo.memberList) do
  661. local viewId = app.room:getViewIdByUserId(player.nUserId)
  662. if myUserId == player.nUserId then
  663. if tonumber(player.canPiao) == 1 then -- 操作过飘了
  664. self.playerView:showPiao(viewId,tonumber(player.isPiao) == 1)
  665. else
  666. if piaoMode == 1 then--可以飘 还没有飘 显示飘按钮
  667. self:showPiao()
  668. end
  669. end
  670. else
  671. self.playerView:showPiao(viewId,tonumber(player.isPiao) == 1)
  672. end
  673. if tonumber(player.isPiao) == 1 then
  674. local effect = MJAnimationCompnent.CreatePiaoEffect()
  675. if effect then
  676. self.ui.Items.Layout_Effect_luobo:addChild(effect)
  677. effect:setLocalZOrder(1000)
  678. effect:setPosition(self.playerHandCards[viewId]:getAnimationPostion())
  679. end
  680. end
  681. end
  682. elseif roomInfo.nGameStartCount > 0 and roomInfo.memberList[myUserId].nPlayerFlag ~= 1 then--游戏中
  683. --local outCardUserId = app.room:getUserIdBySeatId(roomInfo.needOutCardId)
  684. local bIsOutCard = roomInfo.isNeedOutCard > 0 or false
  685. if (not bIsOutCard) and roomInfo.memberList[myUserId].nTingStatus == MJDefine.MJTingStatus.Ting then
  686. local gameInfo =json.decode(app.room.roomInfo.strGameInfo);
  687. if gameInfo.tingpai > 0 then
  688. self.ui.Items.Button_Ting_Info:setVisible(true);
  689. end
  690. end
  691. for k,v in pairs(roomInfo.memberList) do
  692. local viewId = app.room:getViewIdByUserId(v.nUserId)
  693. --可以爆牌玩家显示爆牌
  694. if v.canBaoPai == 1 and v.nUserId == myUserId then
  695. --self.playerHandCards[viewId]:showBaoPai()
  696. self:showBaoJiao()
  697. end
  698. --已爆牌玩家不能出牌
  699. if v.isBaoPai ~= 0 then
  700. if v.isBaoPai == 1 then-- 报叫
  701. self.playerView:playBaoAnim(viewId)
  702. elseif v.isBaoPai == 2 then-- 博自摸
  703. self.playerView:showBoZiMo(viewId,true)
  704. end
  705. if v.nUserId == myUserId then --自己爆牌
  706. self.playerHandCards[viewId]:lockHandCard(true)
  707. -- self.playerHandCards[viewId]:setOutCardEnable(false)
  708. end
  709. app.room:dispatchEvent({name = MJDefine.MJEvent.OutCardFalg,value = roomInfo.lastOpCard,viewId = viewId})
  710. else
  711. --if roomInfo.outCardUserId == myUserId and table.nums(roomInfo.operates)>0 then
  712. -- self.playerHandCards[viewId]:onGetCard(roomInfo.operates)
  713. --end
  714. end
  715. if viewId == MJDefine.MyViewId then
  716. if roomInfo.operates and table.nums(roomInfo.operates)>0 then
  717. self.operates = roomInfo.operates
  718. else
  719. self.operates = {}
  720. end
  721. local handcardNum = #v.handCards
  722. if handcardNum%3 == 2 then
  723. isMyGetCard = true
  724. end
  725. if app.room.roomInfo.requestGetTableInfo and app.room.roomInfo.requestGetTableInfo == true then
  726. --如果是主动请求的重连,什么都不干
  727. app.room.roomInfo.requestGetTableInfo = nil
  728. else
  729. if isMyGetCard and isMyGetCard == true then
  730. showTooltip("重连成功,现在轮到您出牌了,注意看牌哦!!!")
  731. end
  732. end
  733. end
  734. if roomInfo.outCardUserId == v.nUserId then
  735. if v.nUserId == myUserId and roomInfo.lastOpCard~=0 and roomInfo.isNeedOutCard > 0 then
  736. self.playerHandCards[viewId]:removeHandCard(roomInfo.lastOpCard)
  737. self.playerHandCards[viewId]:resetHandCards()
  738. self.playerHandCards[viewId]:createHandCards(roomInfo.lastOpCard)
  739. end
  740. if roomInfo.isNeedOutCard > 0 then
  741. self.playerHandCards[viewId]:setOutCardEnable(true)
  742. end
  743. end
  744. --需要出牌且听牌状态为1时,需要请求服务器推送听牌数据
  745. --[[if roomInfo.isNeedOutCard==MJDefine.NeedOutCard.Need and v.nUserId == myUserId then
  746. if roomInfo.tingStatus == MJDefine.MJTingStatus.Ting then
  747. self.ui:sendMsg(app.room,MJDefine.MJEvent.Ting)
  748. end
  749. end--]]
  750. --显示飘状态
  751. self.playerView:showPiao(viewId,tonumber(v.isPiao) == 1)
  752. end
  753. --显示哪些玩家胡牌
  754. for i,player in pairs(roomInfo.memberList) do
  755. local viewId = app.room:getViewIdByUserId(player.nUserId)
  756. local effect
  757. if player.result>0 then --胡的类型大于0
  758. if player.result == MJDefine.MJGameHuType.HU_ZIMO then
  759. effect=MJAnimationCompnent.CreateHuOrderEffect(player.result,player.huOrder)
  760. else
  761. effect=MJAnimationCompnent.CreateHuOrderEffect(player.result,player.huOrder)
  762. end
  763. if viewId == MJDefine.MyViewId then
  764. self.playerHandCards[viewId]:createHandCards(player.huCard)
  765. self.playerHandCards[viewId]:moveLastCard()
  766. else
  767. self.playerHandCards[viewId]:removeAllHandCards()
  768. self.playerHandCards[viewId]:createOpenHandCards(player.handCards)
  769. self.playerHandCards[viewId]:createOpenHandCards(player.huCard)
  770. self.playerHandCards[viewId]:moveLastOpenCard()
  771. end
  772. end
  773. if effect then
  774. self.ui.Items.Layout_Effect:addChild(effect)
  775. effect:setTag(HU_EFFECT_TAG)
  776. effect:setLocalZOrder(1000)
  777. local pos = self.playerHandCards[viewId]:getAnimationPostion()
  778. if viewId==MJDefine.PlayerViewType.My then
  779. effect:setPosition(pos.x,pos.y-60)
  780. elseif viewId==MJDefine.PlayerViewType.Left then
  781. effect:setPosition(pos.x-20,pos.y)
  782. elseif viewId==MJDefine.PlayerViewType.Right then
  783. effect:setPosition(pos.x+10,pos.y)
  784. elseif viewId==MJDefine.PlayerViewType.Top then
  785. effect:setPosition(pos.x,pos.y+10)
  786. end
  787. end
  788. end
  789. end
  790. --显示出牌角标(需要服务器修改outCardUserId为最后一位出牌玩家的id,而不是当前需要出牌玩家的ID)
  791. local lastOutCardViewId = app.room:getViewIdByUserId(roomInfo.outCardUserId);
  792. app.room:dispatchEvent({name = MJDefine.MJEvent.OutCardFalg, value = roomInfo.lastOpCard, viewId = lastOutCardViewId});
  793. --显示听标示
  794. app.room:dispatchEvent({name = MJDefine.MJEvent.PushTing});
  795. --如果有操作显示操作按钮
  796. if self.playerHandCards[MJDefine.MyViewId] then
  797. self.playerHandCards[MJDefine.MyViewId]:showOperate(roomInfo.operates,roomInfo.lastOpCard,isMyGetCard);
  798. end
  799. --如果一局结束,玩家点了准备,不再显示牌信息
  800. if MJDefine.GameStatus.GAME_STATUS_ROUND_OVER == roomInfo.nStatus and roomInfo.memberList[myUserId].nPlayerFlag == 1
  801. or MJDefine.GameStatus.GAME_STATUS_GAME_OVER == roomInfo.nStatus and roomInfo.memberList[myUserId].nPlayerFlag == 1
  802. then --游戏为停止或开始状态
  803. self:onUserReadyResponse({nUserId=myUserId})
  804. end
  805. end
  806. function zigongRoomView:getChangeGruopDatas(g)
  807. local opType=g.opType
  808. local showType=MJDefine.MJOperateToGroupType[g.opType]
  809. local opCard=g.opCard
  810. local redNum = g.redNum
  811. local fromViewId = nil
  812. local targetSeatId = g.targetSeatId--操作位置座位号
  813. local fromUserId = g.opUserId or g.fromUserId --触发操作玩家
  814. local fromViewId1 = app.room:getViewIdByUserId(fromUserId)
  815. if fromUserId<=0 or not targetSeatId then
  816. else
  817. fromViewId = app.room:transPos( targetSeatId, app.room:getSeatIdByUserId(fromUserId))
  818. --判断是否是对面玩家,对面玩家的话要做一次翻转
  819. local opViewId = app.room:getViewIdBySeatId(targetSeatId)
  820. if opViewId == 2 then --对面
  821. if fromViewId==1 then fromViewId = 3
  822. elseif fromViewId==3 then fromViewId = 1 end
  823. end
  824. --三人玩只有上下家
  825. if app.room:getMaxPlayerCount()==3 and fromViewId==2 then fromViewId = 3 end
  826. if app.room:getMaxPlayerCount()==2 and fromViewId~=0 then
  827. if showType == MJDefine.MJGroupType.Peng then
  828. fromViewId = 2
  829. else
  830. fromViewId = 4
  831. end
  832. end
  833. end
  834. --组合一下牌
  835. local group={
  836. opType=opType,
  837. showType=showType,
  838. values={},
  839. opCard = opCard,
  840. redNum = redNum,
  841. fromViewId = fromViewId,
  842. fromViewId1 = fromViewId1,--真正的来源viewID
  843. }
  844. if MJDefine.MJGroupType.Chi==showType then
  845. elseif MJDefine.MJGroupType.Peng==showType then
  846. group.values={opCard,opCard,opCard}
  847. else
  848. group.values={opCard,opCard,opCard,opCard}
  849. end
  850. return group
  851. end
  852. -- 小局结算
  853. function zigongRoomView:onGameXiaoJuResponse(data)
  854. local function runGameXiaoJuResponse(onEnd)
  855. if not tolua.isnull(self.firstTingTipsView) then
  856. self.firstTingTipsView:killSelf()
  857. self.firstTingTipsView = nil
  858. end
  859. -- 取消操作按钮
  860. if self.playerHandCards and self.playerHandCards[MJDefine.MyViewId] then
  861. self.playerHandCards[MJDefine.MyViewId]:hideOperate()
  862. end
  863. local roomInfo = app.room.roomInfo
  864. self.direcionView:stopAllActions()
  865. self.operates = {}
  866. self:setTingCardViewVisible(false)
  867. app.room:resetTings()
  868. app.room:cleanTingStatus()
  869. --如果是解散直接return
  870. --[[if roomInfo.stopFlag==MJDefine.StopFlag.STOP_FLAG_LONG_NOT_END or roomInfo.stopFlag==MJDefine.StopFlag.STOP_FLAG_DISBAND_GAME then
  871. if onEnd then
  872. onEnd()
  873. end
  874. return
  875. end --]]
  876. --所有胡牌的人 考虑抢杠胡的问题
  877. local viewIds={}
  878. local failViewId=0
  879. for k,v in pairs(roomInfo.memberList) do
  880. local viewId = app.room:getViewIdByUserId(v.nUserId)
  881. if v.result>0 then
  882. table.insert(viewIds,viewId)
  883. --处理掉huCard, 不加入手牌
  884. --播放音效
  885. if viewId==MJDefine.MyViewId then
  886. --MJSound.PlayWinGame()
  887. end
  888. if v.result==MJDefine.MJGameHuType.HU_DIANPAO then
  889. failViewId = app.room:getViewIdBySeatId(v.dpSeatId)
  890. end
  891. end
  892. end
  893. self:showOpenCard()
  894. for k,v in pairs(roomInfo.memberList) do
  895. local viewId = app.room:getViewIdByUserId(v.nUserId)
  896. if viewId and self.playerHandCards[viewId] then
  897. if viewId==MJDefine.MyViewId then
  898. else
  899. --倒牌
  900. if v.huCard and v.huCard ~= 0 then
  901. self.playerHandCards[viewId]:createOpenHandCards(v.huCard)
  902. self.playerHandCards[viewId]:moveLastOpenCard()
  903. end
  904. end
  905. end
  906. end
  907. --被抢杠的人回退补杠
  908. -- if resultInfo.hutype==MJDefine.MJHuType.QiangGangHu and roomInfo.stopFlag==MJDefine.StopFlag.STOP_FLAG_NORMAL then
  909. -- self.playerHandCards[failViewId]:retoreBuGang(resultInfo.hucard)
  910. -- end
  911. local function callback()
  912. self:showXiaoJuView()
  913. if onEnd then
  914. onEnd()
  915. end
  916. self.ui.Items.Layout_Effect_luobo:removeAllChildren()
  917. end
  918. local function luoboNumCallBack()
  919. local strGameInfo = json.decode(app.room.roomInfo.strGameInfo)
  920. if strGameInfo.luobonum and strGameInfo.luobonum > 0 then
  921. local index = 1
  922. for k,v in pairs(roomInfo.memberList) do
  923. local viewId = app.room:getViewIdByUserId(v.nUserId)
  924. local effect
  925. if index == app.room.roomInfo.nMaxPlayCount then
  926. effect = MJAnimationCompnent.CreateLoBoLabel(v.luoboNum,callback)
  927. else
  928. effect = MJAnimationCompnent.CreateLoBoLabel(v.luoboNum)
  929. end
  930. local pos = self.playerHandCards[viewId]:getAnimationPostion()
  931. if viewId==MJDefine.PlayerViewType.My then
  932. effect:setPosition(pos.x+130,pos.y-60)
  933. elseif viewId==MJDefine.PlayerViewType.Left then
  934. effect:setPosition(pos.x-20-30,pos.y-70)
  935. elseif viewId==MJDefine.PlayerViewType.Right then
  936. effect:setPosition(pos.x+10-30,pos.y-70)
  937. elseif viewId==MJDefine.PlayerViewType.Top then
  938. effect:setPosition(pos.x+130,pos.y+10-50)
  939. end
  940. self.ui.Items.Layout_Effect_luobo_Lable:addChild(effect)
  941. index = index + 1
  942. end
  943. else
  944. callback()
  945. end
  946. end
  947. local luoboCards = roomInfo.luoboCards
  948. local function luoboCallBack()
  949. if luoboCards and #luoboCards>0 then
  950. local luoNum = #luoboCards
  951. --加一个黑底
  952. local layer = cc.LayerColor:create(cc.c4b(0,0,0,120))
  953. layer:setAnchorPoint(cc.p(0.5,0.5))
  954. layer:ignoreAnchorPointForPosition(false)
  955. local tPos = self.ui.Items.ImageView_Logo:getPosition()
  956. local tLuoBoPos = {
  957. [1] = {[1] = cc.p(tPos.x,360-40)},
  958. [2] = {[1] = cc.p(tPos.x-50,360),[2] = cc.p(tPos.x+50,360)},
  959. }
  960. layer:setPosition(cc.p(getWinSize().width/2,getWinSize().height/2))
  961. self.ui.Items.Layout_Effect_luobo:addChild(layer)
  962. for i,v in pairs(luoboCards) do
  963. local effect
  964. if i == #luoboCards then
  965. effect = MJAnimationCompnent.CreateLoBoEffect(v,self.desktopType,luoboNumCallBack)
  966. else
  967. effect = MJAnimationCompnent.CreateLoBoEffect(v,self.desktopType)
  968. end
  969. if MJDefine.LuoBoPos[luoNum] and MJDefine.LuoBoPos[luoNum][i] then
  970. effect:setPosition(tLuoBoPos[luoNum][i])
  971. self.ui.Items.Layout_Effect_luobo:addChild(effect)
  972. end
  973. end
  974. else
  975. self:runDelay(1.0,function()
  976. callback()
  977. end)
  978. end
  979. end
  980. if #viewIds>0 then
  981. if roomInfo.stopFlag==MJDefine.StopFlag.STOP_FLAG_LONG_NOT_END or roomInfo.stopFlag==MJDefine.StopFlag.STOP_FLAG_DISBAND_GAME then
  982. self:runDelay(1.0,function()
  983. callback()
  984. end)
  985. else
  986. luoboCallBack()
  987. end
  988. local userInfo=app.room:getUserInfo(app.room:getMyUserId())
  989. if userInfo then --拔萝卜音效
  990. end
  991. else
  992. if roomInfo.stopFlag==MJDefine.StopFlag.STOP_FLAG_HUANG_ZHUANG then
  993. local effect=MJAnimationCompnent.CreateLiuJuEffect(callback)
  994. self.ui.Items.Layout_Player:addChild(effect)
  995. effect:setLocalZOrder(1000)
  996. MJSound.PlayHuangZhuang()
  997. else
  998. callback()
  999. end
  1000. end
  1001. end
  1002. self:addCallBack(runGameXiaoJuResponse);
  1003. end
  1004. -- 显示小局结算
  1005. function zigongRoomView:showXiaoJuView()
  1006. self.direcionView:stopAllActions()
  1007. self:setTingCardViewVisible(false)
  1008. if self.xiaojuView then
  1009. self.xiaojuView:removeFromParent()
  1010. end
  1011. local roomInfo = app.room.roomInfo
  1012. self.xiaojuView = MJRoomXiaoJuView:new(self.desktopType)
  1013. self:addChild(self.xiaojuView)
  1014. end
  1015. function zigongRoomView:setTingCardViewVisible(bVisible,tingCards)
  1016. log("setTingCardViewVisible :"..table.tostring(tingCards))
  1017. self.ui.Items.Layout_Ting_Tip_Card_Panel:setVisible(bVisible)
  1018. -- self.ui.Items.ListView_Ting:removeAllItems()
  1019. -- self.ui.Items.ListView_Ting:getHBar():setVisible(false)
  1020. self.ui.Items.ListView_Ting:removeAllChildren()
  1021. -- self.ui.Items.Item_Ting:setVisible(false)
  1022. -- self.toolView:setVisible(false)
  1023. if not tingCards then return end
  1024. local count = #tingCards
  1025. local row = math.ceil(count/5) --几行
  1026. self.ui.Items.ListView_Ting:setSize(cc.size(670,80*row))
  1027. self.ui.Items.Layout_Ting_Tip_Card_Panel:setSize(cc.size(row>1 and 786 or count*134+116,80*row+40))
  1028. self.ui.Items.ImageView_Ting:setPositionY(self.ui.Items.Layout_Ting_Tip_Card_Panel:getContentSize().height-60)
  1029. for k,v in pairs(tingCards) do
  1030. local item = self.ui.Items.Item_Ting:getCopied()
  1031. item:setVisible(true)
  1032. local items = getUIItems(item)
  1033. items.Text_Num:setString(v.count.."张")
  1034. items.Text_Fan:setString(v.fanshu.."番")
  1035. local mj=MJ:new(v.card,MJDefine.MJType.Stand,MJDefine.MyViewId,self.desktopType)
  1036. mj:setPosition(cc.p(20,30))
  1037. mj:setScale(0.5)
  1038. items.Node:addChild(mj)
  1039. self.ui.Items.ListView_Ting:addChild(item)
  1040. end
  1041. self.ui.Items.ListView_Ting:requestDoLayout()
  1042. self.ui.Items.ListView_Ting:doLayout()
  1043. end
  1044. --显示查听的牌
  1045. function zigongRoomView:setChaTingCardViewVisible(bVisible,tingCards)
  1046. end
  1047. function zigongRoomView:onTingCardStatus()
  1048. local myUserId=app.user.loginInfo.uid
  1049. local memberList=app.room.roomInfo.memberList
  1050. if memberList[myUserId] then
  1051. local nTingStatus=memberList[myUserId].nTingStatus
  1052. if nTingStatus == MJDefine.MJTingStatus.Ting then
  1053. print("---------onTingCardStatus-----------1 "..myUserId)
  1054. -- self:setChaTingCardViewVisible(true)
  1055. -- self:setTingCardViewVisible(true, )
  1056. --self._isTingStateChanged = true--防止出现听牌提示闪一下的bug
  1057. --self.ui:sendMsg(app.room,MJDefine.MJEvent.Ting)
  1058. self.ui.Items.Button_Ting_Info:setVisible(true);
  1059. else
  1060. print("---------onTingCardStatus-----------0 "..myUserId)
  1061. -- self:setChaTingCardViewVisible(false)
  1062. self:setTingCardViewVisible(false)
  1063. self.ui.Items.Button_Ting_Info:setVisible(false);
  1064. end
  1065. end
  1066. end
  1067. function zigongRoomView:onTingCardResult(data)
  1068. print("---------听牌结果-------------")
  1069. if data.response.tingType==MJDefine.MJTingType.QuanTing then
  1070. -- self:setChaTingCardViewVisible(true,{})
  1071. else
  1072. if self._isOutCardTingCheck then
  1073. self._isOutCardTingCheck = false
  1074. local count = table.nums(data.response.tingCards);
  1075. local isTing = count > 0;
  1076. self.ui.Items.Button_Ting_Info:setVisible(isTing);
  1077. self:setTingCardViewVisible(false, data.response.tingCards)
  1078. else
  1079. self:setTingCardViewVisible(true, data.response.tingCards)
  1080. end
  1081. end
  1082. end
  1083. function zigongRoomView:showTing(evet)
  1084. local roomInfo=app.room.roomInfo
  1085. -- if evet.card and roomInfo.tings and roomInfo.tings[evet.card] then
  1086. -- self:setTingCardViewVisible(true,roomInfo.tings[evet.card])
  1087. -- else
  1088. -- self:setTingCardViewVisible(false)
  1089. -- end
  1090. if evet.card and roomInfo.tings and #roomInfo.tings>0 then
  1091. local isTing = false
  1092. for k,v in pairs(roomInfo.tings) do
  1093. if evet.card==v.outCard then
  1094. self:setTingCardViewVisible(true,v.tingCards)
  1095. isTing = true
  1096. end
  1097. end
  1098. if not isTing then
  1099. self:setTingCardViewVisible(false)
  1100. end
  1101. else
  1102. self:setTingCardViewVisible(false)
  1103. end
  1104. end
  1105. function zigongRoomView:pushTing()
  1106. local function runPushTing(onEnd)
  1107. if self.playerHandCards[MJDefine.MyViewId] then
  1108. self.playerHandCards[MJDefine.MyViewId]:pushTing()
  1109. end
  1110. if onEnd then
  1111. onEnd()
  1112. end
  1113. end
  1114. self:addCallBack(runPushTing);
  1115. end
  1116. function zigongRoomView:onHuResponse(data)
  1117. local function runHuResponse(onEnd)
  1118. local response = data.response
  1119. local function callback()
  1120. self:playHuAni(response)
  1121. if onEnd then
  1122. onEnd()
  1123. end
  1124. end
  1125. local viewId = app.room:getViewIdByUserId(response.nUserId)
  1126. local userInfo=app.room:getUserInfoByViewId(viewId)
  1127. --先播放胡牌动画和音效,再显示胡牌顺序
  1128. local effect = MJAnimationCompnent.CreateHuEffect(response.huType,callback)
  1129. if response.huType == MJDefine.MJGameHuType.HU_ZIMO then
  1130. MJSound.PlayOperateSound(userInfo.sex,MJDefine.MJOperateType.OPREATE_ZIMOHU)
  1131. -- effect=MJAnimationCompnent.CreateHuEffect("zimo",callback)
  1132. -- elseif response.huType == MJDefine.MJGameHuType.HU_QIANGGANG then
  1133. else
  1134. MJSound.PlayOperateSound(userInfo.sex,MJDefine.MJOperateType.OPREATE_DIANPAOHU)
  1135. -- effect=MJAnimationCompnent.CreateHuEffect("hu",callback)
  1136. -- --点炮显示
  1137. end
  1138. if effect then
  1139. self.ui.Items.Layout_Effect:addChild(effect)
  1140. effect:setTag(HU_EFFECT_TAG)
  1141. effect:setLocalZOrder(1000)
  1142. effect:setPosition(self.playerHandCards[viewId]:getAnimationPostion())
  1143. end
  1144. --删除等待操作的显示
  1145. if self.waitOperates and #self.waitOperates>0 then
  1146. for k,v in pairs(self.waitOperates) do
  1147. v:removeFromParent()
  1148. end
  1149. self.waitOperates={}
  1150. end
  1151. if response.huType==MJDefine.MJGameHuType.HU_DIANPAO and response.curOpType ~= 1 then
  1152. local failViewId = app.room:getViewIdByUserId(response.dpId)
  1153. --点炮胡或抢杠胡,胡牌类型都是发 点炮胡
  1154. if response.isQiangGng > 0 then
  1155. local huCard = response.huCard == 65 and response.redRealCard or response.huCard --如果胡的牌是红中 用真实的牌 否则用胡的牌
  1156. -- logD("isQiangGng huCard:"..huCard)
  1157. --抢杠胡
  1158. self.playerHandCards[viewId]:onGetCard(nil,huCard)
  1159. --被抢杠的人回退补杠
  1160. self.playerHandCards[failViewId]:retoreBuGang(huCard,1)
  1161. --[[elseif response.isGspHu and response.isGspHu > 0 then
  1162. local gameInfo =json.decode(app.room.roomInfo.strGameInfo);
  1163. if gameInfo.dianganghua == 1 then
  1164. dghDianPao = true
  1165. --点杠炮(选择的点杠花)时手上已经有杠的牌 不需要再加一张胡的牌
  1166. else
  1167. self.playerHandCards[viewId]:onGetCard(nil,response.huCard)
  1168. --将胡的牌收走
  1169. self.playerHandCards[failViewId]:removeOutCard(response.huCard)
  1170. end--]]
  1171. else
  1172. self.playerHandCards[viewId]:onGetCard(nil,response.huCard)
  1173. --将胡的牌收走
  1174. self.playerHandCards[failViewId]:removeOutCard(response.huCard)
  1175. end
  1176. --放炮动画
  1177. effect=MJAnimationCompnent.CreateDianPaoEffect()
  1178. self.ui.Items.Layout_Effect:addChild(effect)
  1179. effect:setLocalZOrder(1000)
  1180. effect:setPosition(self.playerHandCards[failViewId]:getAnimationPostion())
  1181. if failViewId==MJDefine.MyViewId and app.room.roomInfo.lastOutViewId==MJDefine.MyViewId then --修改点炮的人连续二次出牌 不删除牌
  1182. app.room.roomInfo.lastOutViewId = nil
  1183. end
  1184. --此处仅做保留,没有实际意义
  1185. elseif response.huType==MJDefine.MJGameHuType.HU_QIANGGANG then
  1186. local failViewId = app.room:getViewIdByUserId(response.dpId)
  1187. if response.redRealCard > 0 then
  1188. --抢杠胡时,胡牌的人将胡的牌加入手中
  1189. self.playerHandCards[viewId]:onGetCard(nil,response.redRealCard)
  1190. --被抢杠的人回退补杠
  1191. self.playerHandCards[failViewId]:retoreBuGang(response.redRealCard,1)
  1192. end
  1193. end
  1194. if response.nUserId == app.room:getMyUserId() then
  1195. self.playerHandCards[viewId]:setOutCardEnable(false)
  1196. self:setTingCardViewVisible(false)
  1197. self.playerHandCards[viewId]:setTing(false)
  1198. else
  1199. -- 其他人胡了倒牌
  1200. local handCards = {}
  1201. for k,v in pairs(self.playerHandCards[viewId]:getHandCardNodes() or {}) do
  1202. table.insert(handCards,{card = v.value or v:getValue()})
  1203. end
  1204. if response.huType==MJDefine.MJGameHuType.HU_ZIMO or response.curOpType == 1 then --如果是自摸胡 把最后一张替换为胡的牌或点杠花点炮
  1205. handCards[#handCards] = {card = response.huCard}
  1206. end
  1207. self.playerHandCards[viewId]:removeAllHandCards()
  1208. self.playerHandCards[viewId]:createOpenHandCards(handCards)
  1209. self.playerHandCards[viewId]:moveLastOpenCard()
  1210. end
  1211. self.playerHandCards[MJDefine.MyViewId]:hideOperate()
  1212. end
  1213. self:addCallBack(runHuResponse);
  1214. end
  1215. function zigongRoomView:playHuAni(response)
  1216. local strGameInfo = json.decode(app.room.roomInfo.strGameInfo)
  1217. local effect = MJAnimationCompnent.CreateHuOrderEffect(response.huType,response.huOrder)
  1218. -- if response.huType == 1 then
  1219. -- effect=MJAnimationCompnent.CreateHuOrderEffect("zimo",response.huOrder)
  1220. -- else
  1221. -- effect=MJAnimationCompnent.CreateHuOrderEffect("hu",response.huOrder)
  1222. -- end
  1223. local viewId = app.room:getViewIdByUserId(response.nUserId)
  1224. if effect then
  1225. self.ui.Items.Layout_Effect:addChild(effect)
  1226. effect:setTag(HU_EFFECT_TAG)
  1227. effect:setLocalZOrder(1000)
  1228. local pos = self.playerHandCards[viewId]:getAnimationPostion()
  1229. if viewId==MJDefine.PlayerViewType.My then
  1230. effect:setPosition(pos.x,pos.y-60)
  1231. elseif viewId==MJDefine.PlayerViewType.Left then
  1232. effect:setPosition(pos.x-20,pos.y)
  1233. elseif viewId==MJDefine.PlayerViewType.Right then
  1234. effect:setPosition(pos.x+10,pos.y)
  1235. elseif viewId==MJDefine.PlayerViewType.Top then
  1236. effect:setPosition(pos.x,pos.y+10)
  1237. end
  1238. end
  1239. end
  1240. function zigongRoomView:onQiangDuanOperates(data)
  1241. local function runOnQiangDuanOperates(onEnd)
  1242. logD("zigongRoomView:runOnQiangDuanOperates")
  1243. local response = data.response
  1244. if response.operates and self.playerHandCards[MJDefine.MyViewId] then
  1245. self.playerHandCards[MJDefine.MyViewId]:showOperate(response.operates)
  1246. end
  1247. if onEnd then
  1248. onEnd()
  1249. end
  1250. end
  1251. logD("zigongRoomView:onQiangDuanOperates")
  1252. self:addCallBack(runOnQiangDuanOperates)
  1253. end
  1254. --游戏消息
  1255. function zigongRoomView:bindExtendMessage()
  1256. self:bindEvent(app.room , MJDefine.MJEvent.OutCardTings, handler(self , self.pushTing));
  1257. self:bindEvent(app.room , MJDefine.MJEvent.HuResponse, handler(self , self.onHuResponse))
  1258. self:bindEvent(app.room , MJDefine.MJEvent.BaoPaiResponse, handler(self , self.onBaoPai))
  1259. self:bindEvent(app.room , MJDefine.MJEvent.BankerBaoPai, handler(self , self.onBankerBaoPai))
  1260. self:bindEvent(app.room , MJDefine.MJEvent.SendGuo, handler(self , self.onSendGuo))
  1261. self:bindEvent(app.room , MJDefine.MJEvent.QiangDuanOperates, handler(self , self.onQiangDuanOperates))
  1262. self:bindEvent(app , MJDefine.MJEvent.ChangeLanguage , handler(self , self.doSound))
  1263. self:bindEvent(app.room , MJDefine.MJEvent.StartPiao, handler(self , self.onStartPiao))
  1264. self:bindEvent(app.room , MJDefine.MJEvent.PiaoResponse, handler(self , self.onPiaoResponse))
  1265. self:bindEvent(app, MJDefine.MJEvent.ChangeViewType, handler(self, self.onEventChangeViewType ))
  1266. -- 托管
  1267. self:bindEvent(app.room , MJDefine.MJEvent.HostingRequest, handler(self, self.onHostingRequest))
  1268. end
  1269. function zigongRoomView:clean()
  1270. self.playerView:init()
  1271. -- --默认状态
  1272. self:defaultState()
  1273. app.room:resetRoomInfo()
  1274. self:setBtnSitDownVisible(false)
  1275. self.ui:sendMsg(app.room, MJDefine.MJEvent.CallReadyRequest)
  1276. --
  1277. self._gameoverview = nil
  1278. end
  1279. function zigongRoomView:updateReady()
  1280. local nUserId = app.room:getMyUserId()--app.user.loginInfo.uid
  1281. if app.room.roomInfo.nGameStartCount > 0 then
  1282. self.toolView.ui.Items.Button_Leave:setEnabled(false)
  1283. self:setBtnSitDownVisible(false)
  1284. else
  1285. self.toolView.ui.Items.Button_Leave:setEnabled(true)
  1286. end
  1287. if app.room.roomInfo.nGameStartCount == 0 and app.room.roomInfo.nRoomOwnedUid ~= nUserId then
  1288. self.toolView.ui.Items.Button_Dismiss:setEnabled(false)
  1289. else
  1290. self.toolView.ui.Items.Button_Dismiss:setEnabled(true)
  1291. end
  1292. self:checkCanDismiss()
  1293. end
  1294. -- 游戏开始
  1295. function zigongRoomView:onGameStartResponse()
  1296. zigongRoomView.super.onGameStartResponse(self)
  1297. self._gameoverview = nil
  1298. end
  1299. -- 大局结算
  1300. function zigongRoomView:onGameDaJuResponse(data)
  1301. app.club_php:dispatchEvent({name = GAME_EVENT.CLUB_BACK_ROOM})
  1302. if self._gameoverview then
  1303. return
  1304. end
  1305. if app.room.roomInfo.needJieSuanInfo == 1 then--显示总结算
  1306. self:showGameOverResult(data.response)
  1307. else
  1308. --[[local roomInfo=app.room.roomInfo
  1309. --如果是解散直接跳转总结算
  1310. if roomInfo.stopFlag==MJDefine.StopFlag.STOP_FLAG_LONG_NOT_END or roomInfo.stopFlag==MJDefine.StopFlag.STOP_FLAG_DISBAND_GAME then
  1311. self:showGameOverResult(data.response)
  1312. end --]]
  1313. local roomInfo=app.room.roomInfo
  1314. local isNoCard = false--没有手牌
  1315. for i,player in pairs(roomInfo.memberList) do
  1316. if type(player.handCards) == 'table' and #player.handCards <= 0 then
  1317. local a = #player.handCards
  1318. isNoCard = true
  1319. break
  1320. end
  1321. end
  1322. if isNoCard then
  1323. self:showGameOverResult(data.response)
  1324. end
  1325. app.room:dispatchEvent({name = GAME_EVENT.DISSMISS_CLOSE})
  1326. end
  1327. end
  1328. -- 大局结算
  1329. function zigongRoomView:showGameOverResult(data)
  1330. if self._gameoverview ~= nil then
  1331. return
  1332. end
  1333. self.direcionView:stopAllActions()
  1334. self:resetGame()
  1335. local view=MJRoomDaJuView:new(data)
  1336. view:setAnchorPoint(cc.p(0.5, 0.5))
  1337. app:showWaitDialog(view)
  1338. self._gameoverview = view
  1339. self:showGameOverAward()
  1340. end
  1341. function zigongRoomView:onOtherLogoutResponse(data)
  1342. -- local jushu = app.room.roomInfo.nGameStartCount or 0
  1343. if (not data or not data.nUserId or not data.nSeatShowId) then
  1344. return
  1345. end
  1346. local function test(onEnd)
  1347. self.playerView:updatePlayerInfo(data.nSeatShowId)
  1348. self:onUserReadyResponse()
  1349. --更新GPS
  1350. --self:updateAllGpsInfo()
  1351. --self:checkGpsDistance()
  1352. -- 是否显示邀请好友
  1353. self.toolView:updateButton()
  1354. if self._fastRequestView then
  1355. self._fastRequestView:removeSelf()
  1356. self._fastRequestView = nil
  1357. end
  1358. logE("88888-onOtherLogoutResponse onEnd")
  1359. if onEnd then
  1360. onEnd()
  1361. end
  1362. end
  1363. self:addCallBack(test)
  1364. end
  1365. function zigongRoomView:resetGame()
  1366. zigongRoomView.super.resetGame(self)
  1367. self.ui.Items.Layout_Effect:removeAllChildren()
  1368. self.ui.Items.Layout_Effect_luobo_Lable:removeAllChildren()
  1369. self.ui.Items.Layout_Effect_luobo:removeAllChildren()
  1370. self.playerView:clearBao()
  1371. self.playerView:clearAllPiao()
  1372. self.playerView:clearAllBoZiMo()
  1373. end
  1374. function zigongRoomView:showPiao()
  1375. self:stopDirection()
  1376. local roomInfo=app.room.roomInfo
  1377. local gameInfo=json.decode(roomInfo.strGameInfo)
  1378. if not gameInfo.piaomode or tonumber(gameInfo.piaomode)==0 then return end
  1379. self:hidePiao()
  1380. local ui=loadUI("mj_zigong/res/ui_fangjian/mj_zigong_piao.ui")
  1381. self.ui.Items.Layout_Player:addChild(ui)
  1382. self.piao=ui
  1383. ui.Items.Button_BuPiao:registerClick(function()
  1384. playBtnEffect()
  1385. self:hidePiao()
  1386. local request = MJMessage.PiaoRequest:new()
  1387. request.isPiao = 0
  1388. self.ui:sendMsg(app.room,MJDefine.MJEvent.PiaoRequest,request)
  1389. end)
  1390. ui.Items.Button_Piao:registerClick(function()
  1391. playBtnEffect()
  1392. self:hidePiao()
  1393. local request = MJMessage.PiaoRequest:new()
  1394. request.isPiao = 1
  1395. self.ui:sendMsg(app.room,MJDefine.MJEvent.PiaoRequest,request)
  1396. end)
  1397. end
  1398. function zigongRoomView:hidePiao()
  1399. if self.piao then
  1400. self.piao:removeFromParent()
  1401. self.piao=nil
  1402. end
  1403. end
  1404. --显示飘操作按钮
  1405. function zigongRoomView:onStartPiao(response)
  1406. local function runPiao(onEnd)
  1407. logD("zigongRoomView:onStartPiao")
  1408. self:showPiao()
  1409. if onEnd then
  1410. onEnd()
  1411. end
  1412. end
  1413. logD("zigongRoomView:runPiao")
  1414. self:addCallBack(runPiao)
  1415. end
  1416. --飘结果
  1417. function zigongRoomView:onPiaoResponse(response)
  1418. local function runonPiaoResponse(onEnd)
  1419. logD("zigongRoomView:runonPiaoResponse")
  1420. local data = response.response
  1421. local userId = data.nUserId--操作的玩家
  1422. local playersPiaostate = data.playerPiaoState--所有玩家的飘状态
  1423. if playersPiaostate then
  1424. for i,v in pairs(playersPiaostate) do
  1425. local viewId = app.room:getViewIdByUserId(v.nUserId)
  1426. local myUserId = app.room:getMyUserId()
  1427. local userInfo=app.room:getUserInfoByViewId(viewId)
  1428. if myUserId == data.nUserId then
  1429. else
  1430. end
  1431. self.playerView:showPiao(viewId,v.piaostate==1)
  1432. if v.piaostate==1 and userId == v.nUserId then
  1433. --飘音效
  1434. MJSound.PlayPiaoSound(userInfo.sex)
  1435. local effect = MJAnimationCompnent.CreatePiaoEffect()
  1436. if effect then
  1437. self.ui.Items.Layout_Effect_luobo:addChild(effect)
  1438. effect:setLocalZOrder(1000)
  1439. effect:setPosition(self.playerHandCards[viewId]:getAnimationPostion())
  1440. end
  1441. end
  1442. end
  1443. else
  1444. local viewId = app.room:getViewIdByUserId(userId)
  1445. self.playerView:showPiao(viewId,data.piaostate==1)
  1446. if data.piaostate and data.piaostate == 1 then
  1447. --飘音效
  1448. local userInfo=app.room:getUserInfoByViewId(viewId)
  1449. MJSound.PlayPiaoSound(userInfo.sex)
  1450. local effect = MJAnimationCompnent.CreatePiaoEffect()
  1451. if effect then
  1452. self.ui.Items.Layout_Effect_luobo:addChild(effect)
  1453. effect:setLocalZOrder(1000)
  1454. effect:setPosition(self.playerHandCards[viewId]:getAnimationPostion())
  1455. end
  1456. end
  1457. end
  1458. if onEnd then
  1459. onEnd()
  1460. end
  1461. end
  1462. logD("zigongRoomView:runonPiaoResponse--------")
  1463. self:addCallBack(runonPiaoResponse)
  1464. end
  1465. function zigongRoomView:showBaoJiao()
  1466. self:hideBaoJiao()
  1467. local ui=loadUI("mj_zigong/res/ui_fangjian/mj_zigong_baojiao.ui")
  1468. self:addChild(ui)
  1469. self.baojiao=ui
  1470. ui.Items.Button_bozimo:registerClick(function()
  1471. playBtnEffect()
  1472. self:hideBaoJiao()
  1473. local request = MJMessage.BaoPaiRequest:new()
  1474. request.isBaoPai = 2
  1475. logD(request.isBaoPai,"发送爆:2")
  1476. self.ui:sendMsg(app.room, MJDefine.MJEvent.BaoPaiRequest, request)
  1477. end)
  1478. ui.Items.Button_Bao:registerClick(function()
  1479. playBtnEffect()
  1480. self:hideBaoJiao()
  1481. local request = MJMessage.BaoPaiRequest:new()
  1482. request.isBaoPai = 1
  1483. logD(request.isBaoPai,"发送爆:1")
  1484. self.ui:sendMsg(app.room, MJDefine.MJEvent.BaoPaiRequest, request)
  1485. end)
  1486. ui.Items.Button_guo:registerClick(function()
  1487. playBtnEffect()
  1488. self:hideBaoJiao()
  1489. local request = MJMessage.BaoPaiRequest:new()
  1490. request.isBaoPai = 0
  1491. logD(request.isBaoPai,"发送爆:0")
  1492. self.ui:sendMsg(app.room, MJDefine.MJEvent.BaoPaiRequest, request)
  1493. end)
  1494. local gameInfo =json.decode(app.room.roomInfo.strGameInfo);
  1495. if gameInfo.baojiao then
  1496. ui.Items.Button_Bao:setVisible(gameInfo.baojiao == 1);
  1497. end
  1498. if gameInfo.specrule then
  1499. local bozimo = getNumBand(gameInfo.specrule, 0x0002) > 0
  1500. ui.Items.Button_bozimo:setVisible(bozimo);
  1501. end
  1502. ui.Items.Layout_baojiao:requestDoLayout()
  1503. ui.Items.Layout_baojiao:doLayout();
  1504. end
  1505. function zigongRoomView:hideBaoJiao()
  1506. if self.baojiao then
  1507. self.baojiao:removeFromParent()
  1508. self.baojiao=nil
  1509. end
  1510. end
  1511. function zigongRoomView:onBtnTingInfoClicked( )
  1512. playBtnEffect()
  1513. if self.ui.Items.Layout_Ting_Tip_Card_Panel:isVisible() then
  1514. self.ui.Items.Layout_Ting_Tip_Card_Panel:setVisible(false)
  1515. else
  1516. self.ui:sendMsg(app.room,MJDefine.MJEvent.Ting)
  1517. end
  1518. end
  1519. function zigongRoomView:onChangeChatEnable()
  1520. if not self.messageView or tolua.isnull(self.messageView) then
  1521. return
  1522. end
  1523. local voiceEnable = tonumber(loadUserInfo("zigongPingBiYuYinKG")) or 1
  1524. local propEnable = tonumber(loadUserInfo("zigongHuDongBiaoQingKG")) or 1
  1525. self.messageView:setVoiceEnabled(voiceEnable==1)
  1526. self.messageView:setPropEnabled(propEnable==1)
  1527. end
  1528. function zigongRoomView:onEventChangeViewType(data)
  1529. MJDefine.MJConfig = MJDefine.loadMJConfig()
  1530. self:changeGameBg(true)
  1531. app.room.roomInfo.requestGetTableInfo = true
  1532. self.ui:sendMsg(app.room, MJDefine.MJEvent.GetTableInfo);
  1533. end
  1534. function zigongRoomView:onHostingRequest( data )
  1535. local response = data.response
  1536. if response.nUserId == app.user.loginInfo.uid then
  1537. if response.status == 1 then --托管状态
  1538. self.toolView:showTuoGuan(true)
  1539. elseif response.status == 0 then--取消托管状态
  1540. self.toolView:showTuoGuan(false)
  1541. end
  1542. end
  1543. local isTuoGuan = response.status == 1;
  1544. local viewId = app.room:getViewIdByUserId(response.nUserId)
  1545. self.playerView:showTuoGuanByViewId(viewId,isTuoGuan)
  1546. if isTuoGuan then
  1547. self:hidePiao()
  1548. self:hideBaoJiao()
  1549. end
  1550. end
  1551. return zigongRoomView