Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

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