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.

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