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

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