Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

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