您不能選擇超過 %s 個話題 話題必須以字母或數字為開頭,可包含連接號 ('-') 且最長為 35 個字

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