您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

2422 行
72 KiB

  1. local PKDef = PKFramework.PKImport("pk_base.luaScript.PKDef")
  2. local PKFuc = PKFramework.PKImport("pk_base.luaScript.PKFunctions")
  3. local PKSound = PKFramework.PKImport("pk_base.luaScript.PKSound")
  4. local PKMessage = PKFramework.PKImport("pk_base.luaScript.Protocol.PKMessage")
  5. local PKRoomPlayerView=PKFramework.PKImport("pk_base.luaScript.Views.Room.PKRoomPlayerView")
  6. local PKRoomToolView = PKFramework.PKImport("pk_base.luaScript.Views.Room.PKRoomToolView")
  7. local PKRoomXiaoJuChaPaiView=PKFramework.PKImport("pk_base.luaScript.Views.Room.PKRoomXiaoJuChaPaiView")
  8. local PKRoomXiaoJuView=PKFramework.PKImport("pk_base.luaScript.Views.Room.PKRoomXiaoJuView")
  9. local PKRoomOperationView=PKFramework.PKImport("pk_base.luaScript.Views.Room.PKRoomOperationView")
  10. local PKRoomCard=PKFramework.PKImport("pk_base.luaScript.Views.Room.PKRoomCard")
  11. local PKRoomCountAllView=PKFramework.PKImport("pk_base.luaScript.Views.Room.PKRoomDaJuView")
  12. local PKRoomSettingView = PKFramework.PKImport("pk_base.luaScript.Views.Room.PKRoomSettingView")
  13. local PKAnimationCompnent=PKFramework.PKImport("pk_base.luaScript.Views.Component.PKAnimationCompnent")
  14. local PKWanFa = PKFramework.ImportWanFa("luaScript.SubGameDefine.PuKe.PKWanFa")
  15. --local RoomDefined = require("Views.Room.RoomDefined")
  16. local PKRoomView = class("PKRoomView", cc.UIView)
  17. function PKRoomView:ctor()
  18. PKRoomView.super.ctor(self);
  19. self.Time = nil
  20. --牌Layout UI
  21. self.handCardRoot = {}
  22. --手牌数组UI
  23. self.handCardItem = {}
  24. --牌数据UI
  25. self.handCardValueLocal = {}
  26. --扇形最大列数
  27. self.lieShuMax = 20
  28. --扇形最大行数
  29. self.hangShuMax = 1
  30. --是否出牌
  31. self.bOutCard = false
  32. --组合牌之间的间隔
  33. self.cardInterval = 80
  34. --牌上升高度
  35. self.cardOffY = 30;
  36. self:resetShangJiaData();
  37. --正在执行删除牌操作的时候,保护删除是正常,避免少牌可能性出现
  38. self.isGodHand = false
  39. --提示
  40. self.tipList = {}
  41. --最后一手牌
  42. self.lastHandTemp = {};
  43. --shegn
  44. self.leftCardNum = {};
  45. --isReconet
  46. self.isReconet = false
  47. self.isRecord = false
  48. for i = 1,4 do
  49. self.leftCardNum[i] = 0;
  50. end
  51. end
  52. function PKRoomView:loadRoomUI()
  53. local ui = loadUI("pk_base/res/ui/ui_fangjian/pk_ui_fangjian.ui");
  54. self.ui = ui;
  55. self:addChild(ui);
  56. end
  57. function PKRoomView:onEnter()
  58. PKRoomView.super.onEnter(self)
  59. self:loadRoomUI();
  60. --加载纹理缓存
  61. self:loadTextureCache()
  62. --初始化游戏事件按钮
  63. self:initGameButton()
  64. --初始化基础节点
  65. self:initBaseNode()
  66. -- 初始化GPS组件
  67. self:initGpsComponent();
  68. --默认状态
  69. self:defaultState()
  70. --监听事件
  71. self:bindAllEvent()
  72. self:onGameReconnection()
  73. --起飞
  74. self:startGame()
  75. -- 背景音乐
  76. self:playBGM()
  77. end
  78. -- 播放背景音乐
  79. function PKRoomView:playBGM()
  80. local cacheMusic = "gameBgMusic"..(PKDef.GameID or app.gameId)
  81. local defaultValue = tonumber(loadUserInfo(cacheMusic)) or 1
  82. PKSound.PlayGameBGM(defaultValue)
  83. end
  84. function PKRoomView:doSound()--1 普通话 2 方言
  85. local PKLanguageType = "PKLanguageType"..app.gameId
  86. local languageType = tonumber(loadUserInfo(PKLanguageType)) or PKDef.GameLanguageType.PU_TONG_HUA
  87. PKSound.setCurLanguage(idx)
  88. end
  89. function PKRoomView:startGame()
  90. --起飞
  91. app.net:onMsgResume()
  92. end
  93. function PKRoomView:loadTextureCache()
  94. PKFuc.loadSpriteFromFile("pk_base/res/ui/zy_fangjian/card/pk_card_1.plist")
  95. end
  96. function PKRoomView:initBaseNode()
  97. --玩家界面
  98. self.PlayerView = PKRoomPlayerView:new()
  99. self.ui.Items.Layout_Player:addChild(self.PlayerView)
  100. --工具界面
  101. self.toolView = PKRoomToolView:new(self)
  102. self.ui.Items.Layout_Tool:addChild(self.toolView)
  103. --操作界面
  104. self.operationView = PKRoomOperationView:new(self)
  105. self.ui.Items.Layout_OperationView:addChild(self.operationView)
  106. self.operationView:setPlayerView(self.PlayerView)
  107. local timestr = os.date("%y-%m-%d %H:%M:%S")
  108. self.ui.Items.Text_systemTime:setText(timestr)
  109. --定时器
  110. if not self.Time then
  111. self.Time = cc.Director:getInstance():getScheduler():scheduleScriptFunc(function()
  112. local timestr = os.date("%y-%m-%d %H:%M:%S")
  113. self.ui.Items.Text_systemTime:setText(timestr)
  114. end,1.0,false)
  115. end
  116. self.outCardList = {}
  117. for i = 1, PKDef.GameMaxPlayer do
  118. local weaveCardName = string.format("Layout_outCard_%d",i)
  119. self.outCardList[i] = self.ui.Items[weaveCardName]
  120. end
  121. --隐藏出牌复制节点
  122. self.ui.Items.Layout_CardItem:setVisible(false)
  123. end
  124. function PKRoomView:onExit()
  125. PKRoomView.super.onExit(self)
  126. --关闭定时器
  127. if self.Time then
  128. cc.Director:getInstance():getScheduler():unscheduleScriptEntry(self.Time)
  129. end
  130. app.room:dispatchEvent({name = "onGameOverResponse"});
  131. stopBGMusic()
  132. end
  133. function PKRoomView:initGameButton()
  134. self.ui.Items.Layout_Touch:registerClick(function ()
  135. if not self.toolView.ui.Items.Button_Menu:isBright() then
  136. self.toolView:onClickMenu()
  137. end
  138. self:BanlanceAllCard()
  139. end)
  140. end
  141. function PKRoomView:defaultState()
  142. --队列初始化
  143. self.callbackQueue = {}
  144. self.callbackRunning = false
  145. if self.PlayerView then
  146. self.PlayerView:setOffLine(false)
  147. self.PlayerView:setPlayerVisible(false)
  148. end
  149. self:resetGameData()
  150. --第一局清理托管标志,后面每局开始不清理(不然会出现没有取消托管,托管标志不显示bug)
  151. self.PlayerView:setTuoGuanFlagVisible(false)
  152. end
  153. function PKRoomView:resetGameData()
  154. logD("===========重置游戏数据===============")
  155. self.handCardRoot = {}
  156. self.handCardItem = {}
  157. self.handCardValueLocal = {}
  158. app.room.roomInfo.isShowDismiss = false
  159. self.isFristOutCard = true
  160. self.isReconet = false
  161. self:setWaitBgVisible(false)
  162. self:setWetChatVisible(false)
  163. self:setBtnSitDownVisible(false)
  164. self:setBtnClubInviteVisible(false)
  165. self:setLiangPaiVisible(false)
  166. if self.PlayerView then
  167. self.PlayerView:setReadyStateVisible()
  168. self.PlayerView:setBankerVisible()
  169. self.PlayerView:setOperatorTipVisible()
  170. self.PlayerView:setAllClockVisible()
  171. self.PlayerView:hideLeftCard()
  172. self.PlayerView:hideAllPopText()
  173. self.PlayerView:setOffLine()
  174. self.PlayerView:setOwnerVisible()
  175. self.PlayerView:setOffLineBg()
  176. self.PlayerView:setFriendFlagVisible()
  177. self.PlayerView:setBaoPaiFlagVisible()
  178. self.PlayerView:setRankingFlagVisible()
  179. for i = 1, PKDef.GameMaxPlayer do
  180. self.PlayerView:showBaoJingAni(i,true)
  181. end
  182. end
  183. self.operationView:hideSelf(true)
  184. --操作码
  185. self.isGameOver = false
  186. self.isGodHand = false
  187. --发牌器
  188. self.fapaiqiLeftCard = nil
  189. --移除所有的牌局
  190. self.ui.Items.LayoutMain_4:removeAllChildren()
  191. for i = 1, PKDef.GameMaxPlayer do
  192. local weaveCardName = string.format("Layout_outCard_%d",i)
  193. self.ui.Items[weaveCardName]:removeAllChildren()
  194. end
  195. if self.xiaojuView then
  196. self.xiaojuView:removeFromParent()
  197. self.xiaojuView = nil
  198. end
  199. if self.chaPaiView and (not tolua.isnull(self.chaPaiView)) then
  200. self.chaPaiView:removeFromParent()
  201. self.chaPaiView = nil
  202. end
  203. self.weaveCardList = {}
  204. self.tiShiCount = 1;
  205. --停止一些动画
  206. self.ui:stopAllActions()
  207. --重置包牌数据
  208. for k,v in pairs(app.room.roomInfo.memberList) do
  209. local memberInfo = app.room.roomInfo.memberList[v.nUserId]
  210. if memberInfo then
  211. memberInfo.baoPai = nil
  212. end
  213. end
  214. end
  215. --更新房间基础数据
  216. function PKRoomView:updateRoomBaseData()
  217. --初始化背景
  218. local PKgameBgPicture = "gameBgPicture"..(PKDef.GameID or app.gameId)
  219. local idx2 = tonumber(loadUserInfo(PKgameBgPicture)) or 4
  220. self:setTableImg(idx2)
  221. local roomInfo = app.room.roomInfo;
  222. -- 房间号
  223. self.ui.Items.Text_roomNum:setText(tostring(roomInfo.nShowTableId));
  224. --局数
  225. self:updateGameNums()
  226. self:showOwner()
  227. self:onUserReadyResponse()
  228. for i = 1,PKDef.GameMaxPlayer do
  229. self.PlayerView:updatePlayerInfo(i)
  230. end
  231. self.toolView:showFastStart(true)
  232. -- 是否显示邀请好友
  233. if app.room.roomInfo.nGameStartCount > 0 then
  234. self:setWetChatVisible(false)
  235. self:setBtnClubInviteVisible(false)
  236. else
  237. self:setBtnClubInviteVisible(app.room:getCurMaxPlayer() < PKFuc.getCreateRoomPlayerNum())
  238. self:setWetChatVisible(app.room:getCurMaxPlayer() < PKFuc.getCreateRoomPlayerNum())
  239. end
  240. end
  241. function PKRoomView:onGameReconnection()
  242. --logE("PK当前版本号:"..PKFuc.getPKCurVersion())
  243. --更新房间基础数据
  244. self:updateRoomBaseData()
  245. local roomInfo = app.room.roomInfo;
  246. --断线重连
  247. if roomInfo.nGameStartCount > 0 then
  248. local function runOnGameReconnection(onEnd)
  249. local roomInfo = app.room.roomInfo;
  250. --显示庄家
  251. self:updateBanker()
  252. local myUserID = app.room:getMyRecordUserId()
  253. --解散状态
  254. local isDismiss = false
  255. local uid = 0
  256. for k,v in pairs(roomInfo.arrayTableInfo) do
  257. local viewId = app.room:getViewIdByUserId(k)
  258. local nOffLineState = v.nOnlineStatus
  259. --显示离线
  260. self.PlayerView:setPlayerOffLine(nOffLineState ~= 1,viewId)
  261. local viewId = app.room:getViewIdByUserId(k)
  262. --记录玩家解散状态 0:初始状态, 1:发起解散 2: 同意解散 3:不同意解散
  263. app.room.dismissInfo[k] = v.disbandStatus;
  264. --有人发起解散时才显示解散界面
  265. if v.disbandStatus == 1 then
  266. isDismiss = true
  267. uid = k
  268. end
  269. if self.toolView.chatView then
  270. self.toolView.chatView:addPlayer(k)
  271. end
  272. end
  273. --有人发起解散时才显示解散界面
  274. if isDismiss then
  275. app.room.roomInfo.nDismissStateTime = roomInfo.nDismissStateTime or roomInfo.disBandTimeOut;
  276. app.room.roomInfo.nDismissToTalTime = roomInfo.nDismissToTalTime;
  277. local view = require("luaScript.Views.Room.RoomDismissView"):new(uid,app.room.roomInfo.memberList,roomInfo.nDismissStateTime)
  278. view:setAnchorPoint(cc.p(0.5, 0.5));
  279. app:showWaitDialog(view);
  280. end
  281. --托管状态恢复
  282. for k,v in pairs(roomInfo.playerTuoGuanState or {}) do
  283. local entrustType = v.state;--托管状态 1-托管中 0-未托管
  284. local nUserID = v.nUserId;
  285. local viewId = app.room:getViewIdByUserId(nUserID)
  286. local isTuoGuan = entrustType == 1;
  287. if viewId == self:getMeViewId() then
  288. if isTuoGuan then
  289. self:showTuoGuan(true)
  290. self.isTuoGuan = true
  291. else
  292. self:showTuoGuan(false)
  293. self.isTuoGuan = false
  294. end
  295. end
  296. self.PlayerView:showTuoGuanByViewId(viewId,isTuoGuan)
  297. end
  298. --如果一局结束,玩家点了准备,不再显示牌信息
  299. if PKDef.ReconnectState.GAME_STATUS_ROUND_OVER == roomInfo.nStatus and roomInfo.memberList[myUserID].nPlayerFlag == PKDef.USER_STATE.READY
  300. or PKDef.ReconnectState.GAME_STATUS_GAME_OVER == roomInfo.nStatus and roomInfo.memberList[myUserID].nPlayerFlag == PKDef.USER_STATE.READY
  301. then --游戏为停止或开始状态
  302. self:onUserReadyResponse()
  303. if onEnd then
  304. onEnd()
  305. end
  306. return
  307. end
  308. for k,v in pairs(roomInfo.arrayTableInfo or {}) do
  309. local viewId = app.room:getViewIdByUserId(v.nUserId)
  310. local nScore = v.nTotalScore or 0
  311. --玩家分数
  312. self.PlayerView:setPlayerScore(viewId,nScore)
  313. --恢复手牌
  314. if v.nUserId == myUserID then
  315. self:createCard(false,myUserID,nil)
  316. end
  317. local viewId = app.room:getViewIdByUserId(v.nUserId)
  318. self.leftCardNum[viewId] = table.nums(v.handCardList)
  319. --显示剩余牌
  320. self.PlayerView:setLeftCardNum(viewId,true,self.leftCardNum[viewId])
  321. if self.leftCardNum[viewId] < 3 then
  322. self:playBaoJingAni(viewId)
  323. end
  324. end
  325. if PKDef.ReconnectState.GAME_STATUS_INIT == roomInfo.nStatus then
  326. elseif PKDef.ReconnectState.GAME_STATUS_WAIT_BANKER_START == roomInfo.nStatus then
  327. elseif PKDef.ReconnectState.GAME_STATUS_WAITTING == roomInfo.nStatus then
  328. elseif PKDef.ReconnectState.GAME_STATUS_READALL == roomInfo.nStatus then
  329. elseif PKDef.ReconnectState.GAME_STATUS_CHOOSE_PIAO == roomInfo.nStatus then
  330. elseif PKDef.ReconnectState.GAME_STATUS_SHUFFLE == roomInfo.nStatus then
  331. elseif PKDef.ReconnectState.GAME_STATUS_SENDCARDS == roomInfo.nStatus then
  332. elseif PKDef.ReconnectState.GAME_STATUS_ASK_BAO == roomInfo.nStatus then
  333. local viewId = app.room:getViewIdByUserId(app.room.roomInfo.currentUserId)
  334. self.PlayerView:showClockVisible(viewId,true,app.room.roomInfo.opTypeTime)
  335. if viewId == self:getMeViewId() then
  336. if app.room.roomInfo.opType == 3 then
  337. self.operationView:setLayoutBaoPaiView(true)
  338. elseif app.room.roomInfo.opType == 4 then
  339. self.operationView:setLayoutFanPaoView(true)
  340. end
  341. end
  342. for k,v in pairs(roomInfo.arrayTableInfo) do
  343. local viewId = app.room:getViewIdByUserId(v.nUserId)
  344. local state = v.baoPaiType
  345. if state > 1 then
  346. self.PlayerView:showOperatorTip(viewId,state,false)
  347. self.PlayerView:showBaoPaiFlag(viewId,state)
  348. end
  349. end
  350. elseif PKDef.ReconnectState.GAME_STATUS_ASK_CARD == roomInfo.nStatus then
  351. local viewId = app.room:getViewIdByUserId(app.room.roomInfo.currentUserId)
  352. self.PlayerView:showClockVisible(viewId,true,app.room.roomInfo.opTypeTime)
  353. self.operationView:setCallCardView(true,app.room.roomInfo.noCards)
  354. elseif PKDef.ReconnectState.GAME_STATUS_PLAYING == roomInfo.nStatus then
  355. self.isFristOutCard = false
  356. local lastUserId = roomInfo.GetOpUid;
  357. local cardType = roomInfo.cardType;
  358. local cardList = app.room:getCardList(roomInfo.cardList);
  359. self:resetShangJiaData()
  360. self.shangJiaData.cardList = cardList
  361. self.shangJiaData.cardType = cardType;
  362. self.shangJiaData.nUserId = lastUserId;
  363. --恢复上家手牌
  364. if self.shangJiaData.nUserId > 0 then
  365. local shangjiaViewId = app.room:getViewIdByUserId(self.shangJiaData.nUserId);
  366. self:createOutCard(shangjiaViewId, cardList, roomInfo.cardType, true,cardList,nil);
  367. end
  368. local viewId = app.room:getViewIdByUserId(app.room.roomInfo.currentUserId)
  369. self.PlayerView:showClockVisible(viewId,true,app.room.roomInfo.opTypeTime)
  370. if viewId == self:getMeViewId() then
  371. self.operationView:setOperatorPanelView(true,app.room.roomInfo.curOpType)
  372. self:initTipData()
  373. end
  374. if app.room.roomInfo.cAskCard > 0 then
  375. self.operationView:setCallCardView(true,app.room.roomInfo.noCards,app.room.roomInfo.cAskCard,true)
  376. if app.room.roomInfo.bFriendAppear == 0 then
  377. self:showFriendFlag()
  378. else
  379. self:showMengYouFlag(false)
  380. end
  381. end
  382. for k,v in pairs(roomInfo.arrayTableInfo) do
  383. local viewId = app.room:getViewIdByUserId(v.nUserId)
  384. local IsPlaying = v.IsPlaying
  385. local baoPaiType = v.baoPaiType
  386. if IsPlaying == 0 then
  387. if viewId == self:getMeViewId() then
  388. self.ui.Items.Layout_Wait:setVisible(true)
  389. end
  390. elseif baoPaiType == 1 then
  391. self.PlayerView:showBaoPaiFlag(viewId,baoPaiType)
  392. end
  393. if v.ranking > 0 then
  394. self.PlayerView:showRanking(viewId,v.ranking)
  395. self.PlayerView:showBaoJingAni(viewId,true)
  396. end
  397. end
  398. elseif PKDef.ReconnectState.GAME_STATUS_ROUND_OVER == roomInfo.nStatus then
  399. self.isReconet = true
  400. for k,v in pairs(roomInfo.arrayTableInfo) do
  401. local memberInfo = app.room.roomInfo.memberList[v.nUserId]
  402. if memberInfo then
  403. memberInfo.baoPai = v.baoPaiType
  404. end
  405. end
  406. self:setBtnSitDownVisible(false)
  407. elseif PKDef.ReconnectState.GAME_STATUS_GAME_OVER == roomInfo.nStatus then
  408. self.isReconet = true
  409. self:setBtnSitDownVisible(false)
  410. end
  411. if onEnd then
  412. onEnd()
  413. end
  414. end
  415. log("2000000000-PKRoomView - self:addCallBack(runOnGameReconnection)" )
  416. self:addCallBack(runOnGameReconnection)
  417. else
  418. --未开局正常坐下这里会进来
  419. for k,v in pairs(roomInfo.memberList) do
  420. local viewId = app.room:getViewIdByUserId(k)
  421. local nOffLineState = v.nOnlineStatus or 1
  422. --显示离线
  423. self.PlayerView:setPlayerOffLine(nOffLineState ~= 1,viewId)
  424. if self.toolView.chatView then
  425. self.toolView.chatView:addPlayer(k)
  426. end
  427. end
  428. --未开局重连坐下
  429. for k,v in pairs(roomInfo.arrayTableInfo) do
  430. local viewId = app.room:getViewIdByUserId(k)
  431. local nOffLineState = v.nOnlineStatus
  432. --显示离线
  433. self.PlayerView:setPlayerOffLine(nOffLineState ~= 1,viewId)
  434. end
  435. if table.nums(roomInfo.arrayTableInfo) <=0 then
  436. if self.toolView.chatView then
  437. self.toolView.chatView:addPlayer(app.room:getUserIdByViewId(self:getMeViewId()))
  438. end
  439. end
  440. --游戏未开始
  441. local fastStartUserId = 0
  442. --显示离线状态
  443. if roomInfo.fastStartPlayerInfos then
  444. for k,v in pairs(roomInfo.fastStartPlayerInfos) do
  445. --发起快速开始ID
  446. if v.optType == PKDef.SPEED_START_GAME.START_OPT_TYPE_REQ then
  447. fastStartUserId = v.uid
  448. end
  449. end
  450. --显示快速开始界面
  451. if roomInfo.bUserFastStartGame == 1 and fastStartUserId ~= 0 then
  452. if self.startView then
  453. self.startView:removeFromParent()
  454. end
  455. local function callback()
  456. self.startView = nil
  457. end
  458. local responseEx = {}
  459. responseEx.nleftStartGameTimeout = roomInfo.nFastStartTimeOut
  460. responseEx.playerList = roomInfo.fastStartPlayerInfos
  461. self.startView = import("pk_base.luaScript.Views.Room.PKRoomStartWaitView"):new(responseEx, callback);
  462. self.startView:setAnchorPoint(cc.p(0.5, 0.5));
  463. app:showWaitDialog(self.startView);
  464. end
  465. end
  466. end
  467. end
  468. --隐藏微信按钮
  469. function PKRoomView:setWetChatVisible(bVisible)
  470. self.toolView.ui.Items.Layout_Invite:setVisible(bVisible)
  471. if isReviewVersion() then
  472. self.toolView.ui.Items.Layout_Invite:setVisible(false)
  473. end
  474. self.toolView.ui.Items.Layout_Btn:requestDoLayout()
  475. self.toolView.ui.Items.Layout_Btn:doLayout()
  476. end
  477. --隐藏准备按钮
  478. function PKRoomView:setBtnSitDownVisible(bVisible)
  479. self.toolView.ui.Items.Layout_Ready:setVisible(bVisible)
  480. self.toolView.ui.Items.Layout_Btn:requestDoLayout()
  481. self.toolView.ui.Items.Layout_Btn:doLayout()
  482. end
  483. function PKRoomView:setBtnClubInviteVisible(bVisible)
  484. self.toolView.ui.Items.Layout_ClubInvite:setVisible(false);
  485. if app.club_php.clubID and app.club_php.clubID ~= 0 then
  486. self.toolView.ui.Items.Layout_ClubInvite:setVisible(bVisible);
  487. end
  488. --[[if app.club_php.isArena and app.club_php.isArena == 2 then
  489. self.toolView.ui.Items.Layout_ClubInvite:setVisible(false);
  490. end--]]
  491. self.toolView.ui.Items.Layout_Btn:requestDoLayout()
  492. self.toolView.ui.Items.Layout_Btn:doLayout()
  493. end
  494. function PKRoomView:bindAllEvent()
  495. --[[
  496. 消息分类管理
  497. ]]
  498. --用户状态(包括准备,其他玩家进入或者离开通知,离线等)
  499. self:bindUserStatedMessage()
  500. --私人场消息(包括解散等)
  501. self:bindPrivateMessage()
  502. --游戏消息
  503. self:bindGameMessage()
  504. --游戏场景消息
  505. self:bindGameSceneMessage()
  506. --绑定更换桌布事件
  507. self:bindEvent(app , PKDef.PKEvent.OnChangeTable , handler(self , self.onChangeTable));
  508. end
  509. function PKRoomView:onChangeTable(data)
  510. local idx = data.idx
  511. self:setTableImg(idx)
  512. end
  513. function PKRoomView:setTableImg(idx)
  514. local name = string.format("pk_base/res/ui/zy_fangjian/bg/pk_common_bg_%d.jpg",idx)
  515. --桌布
  516. self.ui.Items.ImageView_bg:loadTexture(name)
  517. local cacheGameBgPic = "gameBgPicture"..(PKDef.GameID or app.gameId)
  518. saveUserInfo(cacheGameBgPic,idx)
  519. --改变水印
  520. self:changeLogo(idx)
  521. end
  522. function PKRoomView:changeLogo(idx)
  523. --[[ local name = nil
  524. local config = getSubGameConfig(29)
  525. -- if idx == 6 then
  526. -- name = "pk_base/res/ui/zy_fangjian/pk_roomtitle_2.png"
  527. -- if config.gameDataConfig and config.gameDataConfig.logo2 then
  528. -- name = config.gameDataConfig.logo2
  529. -- end
  530. -- else
  531. name = "pk_base/res/ui/zy_fangjian/pk_roomtitle_1.png"
  532. if config.gameDataConfig and config.gameDataConfig.logo1 then
  533. name = config.gameDataConfig.logo1
  534. end
  535. -- end
  536. --桌布
  537. self.ui.Items.ImageView_Logo:loadTexture(name)--]]
  538. self:initLogo()
  539. end
  540. function PKRoomView:initLogo()
  541. if tolua.isnull(self.ui.Items.ImageView_Logo) then
  542. return
  543. end
  544. if not (type(getSubGameRoomLogo) == 'function') then
  545. self.ui.Items.ImageView_Logo:setVisible(false)
  546. return
  547. end
  548. local roomInfo = app.room.roomInfo
  549. local gameInfo = json.decode(roomInfo.strGameInfo or "")
  550. local gamerule = tonumber(gameInfo.gamerule or 0)
  551. roomInfo.gameId = roomInfo.gameId or app.gameId or 0
  552. local logofile = getSubGameRoomLogo(roomInfo.gameId, gamerule)
  553. if logofile then
  554. self.ui.Items.ImageView_Logo:loadTexture(logofile)
  555. self.ui.Items.ImageView_Logo:setVisible(true);
  556. else
  557. self.ui.Items.ImageView_Logo:setVisible(false);
  558. end
  559. end
  560. --用户状态消息
  561. function PKRoomView:bindUserStatedMessage()
  562. --默认状态
  563. self:bindEvent(app.room , PKDef.PKEvent.DefaultState , handler(self , self.defaultState));
  564. -- 玩家准备
  565. self:bindEvent(app.room , PKDef.PKEvent.OnUserReadyResponse , handler(self , self.onUserReadyResponse));
  566. -- 其他玩家进入房间
  567. self:bindEvent(app.room , PKDef.PKEvent.OnOtherSitDownResponse , handler(self , self.onOtherSitDownResponse));
  568. -- 其他玩家退出房間
  569. self:bindEvent(app.room , PKDef.PKEvent.OnOtherLogoutResponse , handler(self , self.onOtherLogoutResponse));
  570. -- 其他玩家掉线
  571. self:bindEvent(app.room , PKDef.PKEvent.OnOtherDroppedResponse , handler(self , self.onOtherDroppedResponse));
  572. -- 用户T出
  573. self:bindEvent(app.room , PKDef.PKEvent.OnUserExitResponseRoom , handler(self , self.onUserExitResponseRoom));
  574. -- 玩家的GPS信息发生变化
  575. --self:bindEvent(app.room , PKDef.PKEvent.OnServerChangeUserInfo , handler(self , self.onServerChangeUserInfo));
  576. self:bindEvent(app.room, PKDef.PKEvent.BraodcastFastStart , handler(self, self.onBroadcastFaststart));
  577. self:bindEvent(app.room, PKDef.PKEvent.FastStartSucc , handler(self, self.onFastStartSucc));
  578. end
  579. --私人场消息
  580. function PKRoomView:bindPrivateMessage()
  581. -- 玩家收到解散房间的请求
  582. self:bindEvent(app.room , PKDef.PKEvent.OnDismissResponse , handler(self , self.onDismissResponse));
  583. end
  584. --游戏消息
  585. function PKRoomView:bindGameMessage()
  586. -- 游戏开始
  587. self:bindEvent(app.room , PKDef.PKEvent.OnGameStartResponse , handler(self , self.onGameStartResponse));
  588. --游戏状态更新
  589. self:bindEvent(app.room , PKDef.PKEvent.OnGameUpdateStatus , handler(self , self.onGameUpdateStatus));
  590. --包牌
  591. self:bindEvent(app.room , PKDef.PKEvent.OnBaoPaiStartBroad , handler(self , self.onBaoPaiStartBroad));
  592. self:bindEvent(app.room , PKDef.PKEvent.OnBaoPaiResponse , handler(self , self.onBaoPaiResponse));
  593. self:bindEvent(app.room , PKDef.PKEvent.OnGameBankerChange , handler(self , self.onGameBankerChange));
  594. self:bindEvent(app.room , PKDef.PKEvent.OnPlayerBaoPaiResult , handler(self , self.onPlayerBaoPaiResult));
  595. self:bindEvent(app.room , PKDef.PKEvent.OnBroadCastNoPlayPlayer , handler(self , self.onBroadCastNoPlayPlayer));
  596. self:bindEvent(app.room , PKDef.PKEvent.OnBroadCastBankerCallCard , handler(self , self.onBroadCastBankerCallCard));
  597. self:bindEvent(app.room , PKDef.PKEvent.OnGameBankerSendCallCardResponse , handler(self , self.onGameBankerSendCallCardResponse));
  598. self:bindEvent(app.room , PKDef.PKEvent.OnFriendAppear , handler(self , self.onFriendAppear));
  599. self:bindEvent(app.room , PKDef.PKEvent.OnOutCardRanking , handler(self , self.onOutCardRanking));
  600. -- 开始给桌子上用户发牌
  601. self:bindEvent(app.room , PKDef.PKEvent.OnGameSendCardResponse , handler(self , self.onGameSendCardResponse));
  602. -- 出牌通知
  603. self:bindEvent(app.room , PKDef.PKEvent.OnBroadPlayerOutCard, handler(self , self.onBroadPlayerOutCard));
  604. -- 出牌错误
  605. self:bindEvent(app.room , PKDef.PKEvent.OnOutCardError, handler(self , self.onOutCardError));
  606. -- 出牌成功
  607. self:bindEvent(app.room , PKDef.PKEvent.OnOutCardSuccess, handler(self , self.onOutCardSuccess));
  608. self:bindEvent(app.room , PKDef.PKEvent.OnGameXiaoJuResponse , handler(self , self.onGameXiaoJuResponse));
  609. self:bindEvent(app.room , PKDef.PKEvent.OnGameDaJuResponse , handler(self , self.onGameDaJuResponse));
  610. --托管结果
  611. self:bindEvent(app.room , "onTuoGuanResponse",handler(self , self.onTuoGuanResponse));
  612. end
  613. --场景恢复
  614. function PKRoomView:bindGameSceneMessage()
  615. local function onEnterRoomSuccess(event)
  616. if tolua.isnull(self.ui) then
  617. logE("self.is null")
  618. return
  619. end
  620. self:stopAllActions()
  621. self:defaultState()
  622. self:onGameReconnection()
  623. self:startGame()
  624. end
  625. app.hall:addEventListener(PKDef.PKEvent.OnEnterRoomSuccess, onEnterRoomSuccess)
  626. end
  627. function PKRoomView:onBroadcastFaststart(data)
  628. local response = data.response
  629. if self.startView then
  630. local function callTip(txt)
  631. showTooltip(txt)
  632. end
  633. self.startView:updateState(response, callTip)
  634. else
  635. --“有玩家进入房间” 和 “超时未作出选择”,快速开始中断
  636. if data.response.optType == 5 or data.response.optType == 6 then
  637. return
  638. end
  639. local function callback()
  640. self.startView = nil
  641. end
  642. self.startView = import("pk_base.luaScript.Views.Room.PKRoomStartWaitView"):new(response,callback);
  643. self.startView:setAnchorPoint(cc.p(0.5, 0.5));
  644. app:showWaitDialog(self.startView);
  645. end
  646. end
  647. function PKRoomView:onFastStartSucc(data)
  648. if self._fastRequestView then
  649. self._fastRequestView:removeSelf()
  650. end
  651. self.PlayerView:setPlayerVisible(false)
  652. self:updateRoomBaseData()
  653. end
  654. --自己的视图ID
  655. function PKRoomView:getMeViewId()
  656. return PKDef.MyViewID
  657. end
  658. function PKRoomView:onGameSendCardResponse()
  659. local function runGameSendCardResponse(onEnd)
  660. log("2000000000-PKRoomView - runGameSendCardResponse()")
  661. --发牌
  662. self:createCard(true,app.user.loginInfo.uid,onEnd)
  663. end
  664. log("2000000000-PKRoomView - addCallBack(runGameSendCardResponse)" )
  665. self:addCallBack(runGameSendCardResponse);
  666. end
  667. function PKRoomView:createCard(bShowAnimation,nUserID,onEnd)
  668. logD("====================RoomView:createCard()===================");
  669. local cardList = app.room.cards[nUserID]
  670. if not cardList or table.nums(cardList) <= 0 then
  671. --重连当自己没有手牌
  672. return
  673. end
  674. local function sortFunc(a,b)
  675. return tonumber(PKFuc.getCardValue(a)) < tonumber(PKFuc.getCardValue(b))
  676. end
  677. logD("cardList:",table.tostring(cardList))
  678. table.sort(cardList,sortFunc)
  679. --重新调整
  680. local tt = {};
  681. for i = table.nums(cardList),1,-1 do
  682. table.insert(tt,cardList[i])
  683. end
  684. logE("createCard Rank ok :"..table.tostring(tt))
  685. local index = 1
  686. self.ui.Items.LayoutMain_4:removeAllChildren();
  687. local max = table.nums(tt)
  688. local mSprite = cc.ImageView:createNode();
  689. mSprite:loadTextureFromPlist("pk_cards_0_1.png")
  690. self.cardWidth = mSprite:getContentSize().width
  691. --不管有无数据,默认创建10列数据
  692. for i = 1,4 do
  693. self.leftCardNum[i] = max
  694. end
  695. for i = 1,max do
  696. local value = tt[i] or 0
  697. local isShowFlag = nUserID == app.room.roomInfo.nBankerUserId and i == max
  698. local card = PKRoomCard:new(value,i,isShowFlag)
  699. local pos = cc.p(self.ui.Items.Layout_StartPos:getPositionX() + (i - max / 2) * (self.cardWidth - self.cardInterval), self.ui.Items.Layout_StartPos:getPositionY());
  700. card.ui:setPosition(pos)
  701. self.ui.Items.LayoutMain_4:addChild(card.ui,1)
  702. --数据记录
  703. self.handCardRoot[i] = card
  704. self.handCardValueLocal[i] = value
  705. --存储所有的单牌节点Image
  706. self.handCardItem[index] = card.imgList
  707. index = index + 1
  708. end
  709. logD("create card finish self.handCardValueLocal : "..table.tostring(self.handCardValueLocal))
  710. if bShowAnimation then
  711. self:showGetCardAni(onEnd)
  712. else
  713. --注册点击
  714. self:registerCardTouch()
  715. --排序
  716. self:RankCard(true)
  717. if onEnd then
  718. onEnd()
  719. end
  720. end
  721. end
  722. -- 发牌动画
  723. function PKRoomView:showGetCardAni(onEnd)
  724. local screenWidth = getWinSize().width;
  725. local max = table.nums(self.handCardItem)
  726. local function secondAction()
  727. local index2 = 0;
  728. for j = max,1,-1 do
  729. local card = self.handCardItem[j];
  730. local seq2 = cc.Sequence:create(cc.DelayTime:create(0.03 * (max - j)),
  731. cc.CallFunc:create(function ()
  732. PKFuc.logCard(card.value);
  733. local fileName = PKFuc.getPKCardImgByValue(card.value);
  734. card:loadTextureFromPlist(fileName);
  735. end), cc.CallFunc:create(function ()
  736. index2 = index2 + 1;
  737. if index2 == max then
  738. logD("only do once!")
  739. --注册点击
  740. self:registerCardTouch();
  741. --排序
  742. self:RankCard();
  743. if app.room.roomInfo.playerList then
  744. for k,v in pairs(app.room.roomInfo.playerList) do
  745. local nUserID = v.nUserId
  746. local viewId = app.room:getViewIdByUserId(nUserID)
  747. --显示剩余牌
  748. self.PlayerView:setLeftCardNum(viewId,true,self.leftCardNum[viewId])
  749. end
  750. end
  751. if onEnd then
  752. onEnd();
  753. end
  754. end
  755. end))
  756. card:getParent():runAction(seq2);
  757. end
  758. end
  759. local index = 0;
  760. for i = 1, max do
  761. local card = self.handCardItem[i];
  762. card:getParent():setOpacity(0);
  763. local srcPos = card:getParent():getPosition();
  764. local fileName = PKFuc.getPKCardImgByValue(0xff);
  765. card:loadTextureFromPlist(fileName);
  766. card:getParent():setPositionX(screenWidth + 800);
  767. local time = 0.1;
  768. local spawn = cc.Spawn:create(cc.FadeIn:create(time), cc.MoveTo:create(time, srcPos));
  769. local seq = cc.Sequence:create(cc.DelayTime:create(0.1 * i), cc.CallFunc:create(function ()
  770. PKSound.PlayGetCard()
  771. end),spawn,cc.CallFunc:create(function ()
  772. index = index + 1
  773. if index == max then
  774. logD("first action only do once!")
  775. secondAction();
  776. end
  777. end));
  778. card:getParent():runAction(seq);
  779. end
  780. end
  781. --牌UI调整
  782. function PKRoomView:RankCard(isNotShowAni)
  783. --如果列小于最大列数则需要调整UI
  784. local showColNum = self:getVisibleCardLayoutNum()
  785. if showColNum == 0 then
  786. return
  787. end
  788. local tpYouCount = 1
  789. local handCardRootTemp = {}
  790. local handCardValueLocalTemp = {}
  791. for k = 1,table.nums(self.handCardValueLocal) do
  792. if self.handCardValueLocal[k] > 0 then
  793. local tarPos = cc.p(self.ui.Items.Layout_StartPos:getPositionX() + (tpYouCount - showColNum / 2) * (self.cardWidth - self.cardInterval),
  794. self.ui.Items.Layout_StartPos:getPositionY());
  795. if true then
  796. self.handCardRoot[k].ui:setPosition(tarPos)
  797. else
  798. self.handCardRoot[k].ui:runAction(cc.MoveTo:create(0.17, tarPos));
  799. end
  800. self.handCardRoot[k].imgList.lieshu = tpYouCount
  801. handCardValueLocalTemp[tpYouCount] = self.handCardValueLocal[k]
  802. handCardRootTemp[tpYouCount] = self.handCardRoot[k]
  803. self.handCardRoot[k].flag:setVisible(false)
  804. tpYouCount = tpYouCount + 1;
  805. end
  806. end
  807. self.handCardValueLocal = handCardValueLocalTemp;
  808. self.handCardRoot = handCardRootTemp;
  809. local idx = table.nums(self.handCardRoot)
  810. self.handCardRoot[idx].flag:setVisible(app.room.roomInfo.nBankerUserId == app.room:getMyRecordUserId())
  811. end
  812. --整理牌
  813. function PKRoomView:neatenCard(isNotShowAni)
  814. self:RankCard(isNotShowAni)
  815. end
  816. function PKRoomView:getVisibleCardLayoutNum()
  817. local index = 0
  818. for i,v in ipairs(self.handCardValueLocal) do
  819. if v > 0 then
  820. index = index + 1
  821. end
  822. end
  823. return index
  824. end
  825. --获取该列显示了几个
  826. function PKRoomView:getRowVisibleCount(lieshu)
  827. local count = 0
  828. for k = 1, 4 do
  829. if self.handCardRoot[lieshu].imgList[k] and self.handCardRoot[lieshu].imgList[k]:isVisible() then
  830. count = count + 1
  831. end
  832. end
  833. return count
  834. end
  835. function PKRoomView:resetCardState()
  836. for i = table.nums(self.handCardItem), 1 do
  837. local mSprite = self.handCardItem[i];
  838. mSprite.hit = false;
  839. mSprite:setColor(PKDef.nomalColor);
  840. end
  841. end
  842. --注册点击事件
  843. function PKRoomView:registerCardTouch()
  844. local function getPosOO()
  845. local nodeTouch = self.ui.Items.Layout_Touch;
  846. local posTouch = nodeTouch:getWorldPosition()
  847. local poaAnchor = nodeTouch:getAnchorPoint()
  848. local sizeTouch = nodeTouch:getContentSize();
  849. local posOO = { x = posTouch.x - sizeTouch.width * poaAnchor.x , y = posTouch.y - sizeTouch.height * poaAnchor.y}
  850. return posOO;
  851. end
  852. --触摸
  853. local max = table.nums(self.handCardItem)
  854. for itemK,itemV in ipairs(self.handCardItem) do
  855. function onTouchBegan(touch)
  856. self.beginPos = touch:getLocation();
  857. PKFuc.logCard(itemV.value);
  858. --当前滑动选中的牌
  859. self.hitItem = {};
  860. table.insert(self.hitItem,itemV)
  861. self:resetCardState()
  862. itemV:setColor(PKDef.selectColor)
  863. itemV.hit = true;
  864. logD("88888888-=============onTouchBegan================")
  865. end
  866. function onTouchMove(touch)
  867. local touchPos = touch:getLocation();
  868. local dis = touchPos.x - self.beginPos.x;
  869. local towardRight
  870. if dis > 0 then
  871. towardRight = true
  872. else
  873. towardRight = false
  874. end
  875. if math.abs(touchPos.x - self.beginPos.x) < 5 then
  876. logD("小于5过滤");
  877. return
  878. end
  879. local touchPos = touch:getLocation()
  880. for i = max, 1, -1 do
  881. local mSprite = self.handCardItem[i]
  882. local posNode = mSprite:getParent():convertToNodeSpace(touchPos)
  883. local width = self.cardInterval
  884. local height = mSprite:getContentSize().height
  885. local x = mSprite:getPositionX()
  886. local y = mSprite:getPositionY()
  887. local mRect = cc.Rectangle:new(x,y,width,height)
  888. local cardWorldPos = mSprite:getParent():convertToWorldSpace(mSprite:getPosition())
  889. --是否朝右
  890. local isRight = cardWorldPos.x < touchPos.x
  891. ---如果是朝左,去掉间隔再比较
  892. if not towardRight then
  893. isRight = cardWorldPos.x < touchPos.x - width
  894. end
  895. if mSprite.value == 0 or (mSprite.hit and (isRight == towardRight)) then
  896. --牌是选中&&滑动的朝向和touchpos.x在牌的左右方向一样,则不计算,也就说,这个牌一直在选中范围里面的,过滤!
  897. else
  898. if mRect:contains(posNode.x,posNode.y) and not mSprite.hit then
  899. if mSprite.value == 0 then
  900. showTooltip("move 不合法")
  901. end
  902. mSprite.hit = true;
  903. mSprite:setColor(PKDef.selectColor)
  904. table.insert(self.hitItem,mSprite)
  905. PKFuc.logCard(mSprite.value)
  906. break;
  907. else
  908. mSprite.hit = false;
  909. mSprite:setColor(PKDef.nomalColor)
  910. for idx = 1,table.nums(self.hitItem) do
  911. if self.hitItem[idx].value == mSprite.value then
  912. table.remove(self.hitItem,idx)
  913. break;
  914. end
  915. end
  916. end
  917. end
  918. end
  919. end
  920. function onTouchEnd(touch)
  921. if not itemV.value then
  922. return;
  923. end
  924. logD("88888888-=============onTouchEnd================")
  925. logD("self.hitItem.length :", table.nums(self.hitItem));
  926. self:BanlanceCard();
  927. end
  928. function onTouchCancel(touch)
  929. if not itemV.value then
  930. return
  931. end
  932. logD("88888888-=============onTouchCancel================")
  933. logD("self.hitItem.length :", table.nums(self.hitItem));
  934. self:BanlanceCard();
  935. end
  936. itemV:setTouchEnabled(true)
  937. itemV:registerTouchEvent(onTouchBegan, onTouchMove, onTouchEnd, onTouchCancel)
  938. end
  939. end
  940. function PKRoomView:BanlanceCard()
  941. local tt = {};
  942. local max = table.nums(self.hitItem)
  943. for i = 1,max do
  944. local card = self.hitItem[i];
  945. local cardValue = card.value;
  946. table.insert(tt,cardValue)
  947. PKFuc.logCard(cardValue);
  948. if card:getPositionY() == self.cardOffY then
  949. card:setPositionY(0);
  950. else
  951. card:setPositionY(self.cardOffY);
  952. end
  953. card:setColor(PKDef.nomalColor)
  954. card.hit = false;
  955. end
  956. end
  957. function PKRoomView:sendOutCard()
  958. local srcList = self:getOutCardList();
  959. if table.nums(srcList) > 0 then
  960. local tpLeftIsLai = self:getLeftIsLai(srcList)
  961. local tpCardInfo = PKFuc.getCardType(srcList)
  962. --outCardList是多个出牌组合
  963. local outCardList = PKFuc.getIsCanOutCard(srcList, tpCardInfo, self.shangJiaData)
  964. if not tpLeftIsLai and outCardList and table.nums(outCardList) > 0 then
  965. if table.nums(outCardList) > 1 then
  966. self.operationView:setOperatorPanelView(false)
  967. self.operationView:setChoiceCardView(true,srcList,outCardList)
  968. else
  969. --srcList原始的癞子数据
  970. --outCardList是癞子转换为具体某个牌的数据
  971. app.room:requestSendOutCard(1,srcList,outCardList[1])
  972. local list = {}
  973. for k,card in ipairs(outCardList[1]) do
  974. table.insert(list,card)
  975. end
  976. --加个排序
  977. local function sortFunc(a,b)
  978. return tonumber(PKFuc.getCardValue(a)) < tonumber(PKFuc.getCardValue(b))
  979. end
  980. table.sort(list,sortFunc)
  981. self:createOutCard(self:getMeViewId(), list, tpCardInfo[1].cardType, false, srcList);
  982. self.PlayerView:showClockVisible(self:getMeViewId(), false)
  983. self.operationView:setOperatorPanelView(false)
  984. end
  985. else
  986. showTooltip("你选择的牌不满足规则!请重新选择!");
  987. end
  988. else
  989. showTooltip("请选择牌");
  990. end
  991. end
  992. function PKRoomView:sendNoOutCard()
  993. app.room:requestSendOutCard(0, {},{})
  994. self.operationView:setOperatorPanelView(false)
  995. self.PlayerView:showClockVisible(self:getMeViewId(), false)
  996. self:BanlanceAllCard();
  997. end
  998. function PKRoomView:onTiShiClick()
  999. if self.weaveCardList and table.nums(self.weaveCardList) > 0 then
  1000. local function tiShi()
  1001. local weaveList = self.weaveCardList[self.tiShiCount]
  1002. if weaveList then
  1003. self:BanlanceAllCard()
  1004. for j = 1,table.nums(weaveList) do
  1005. local weaveValue = weaveList[j]
  1006. for i = 1, table.nums(self.handCardItem) do
  1007. local sprite = self.handCardItem[i]
  1008. local value = sprite.value;
  1009. if value == weaveValue then
  1010. sprite:setPositionY(self.cardOffY);
  1011. end
  1012. end
  1013. end
  1014. self.tiShiCount = self.tiShiCount + 1;
  1015. else
  1016. self.tiShiCount = 1;
  1017. tiShi();
  1018. end
  1019. end
  1020. tiShi();
  1021. else
  1022. self:sendNoOutCard()
  1023. end
  1024. end
  1025. function PKRoomView:createOutCard(viewId, outCardList, cardType, isReconet, srcList, onEnd)
  1026. if viewId == self:getMeViewId() and not isReconet then
  1027. --删除原有的数据
  1028. for j = 1, table.nums(srcList) do
  1029. local card = srcList[j]
  1030. for i = 1, table.nums(self.handCardValueLocal) do
  1031. local value = self.handCardValueLocal[i];
  1032. if value == card then
  1033. self.handCardValueLocal[i] = 0;
  1034. break;
  1035. end
  1036. end
  1037. end
  1038. --UI隐藏
  1039. for j = 1, table.nums(srcList) do
  1040. local card = srcList[j]
  1041. for i = 1, table.nums(self.handCardItem) do
  1042. local cardLocal = self.handCardItem[i]
  1043. if card == cardLocal.value then
  1044. cardLocal:setVisible(false)
  1045. cardLocal:setOpacity(255)
  1046. cardLocal:setPositionY(0);
  1047. cardLocal.value = 0;
  1048. cardLocal.lieshu = nil;
  1049. cardLocal.hit = false;
  1050. break;
  1051. end
  1052. end
  1053. end
  1054. --重新排序
  1055. self:RankCard();
  1056. end
  1057. -- 清理所有玩家的牌
  1058. for i = 1, PKDef.GameMaxPlayer do
  1059. self:cleanOutCardByViewId(i)
  1060. end
  1061. --清理当前玩家的桌面牌
  1062. local layout = self.outCardList[viewId]
  1063. layout:removeAllChildren()
  1064. local nUserId = app.room:getUserIdByViewId(viewId)
  1065. local value;
  1066. --创建牌到屏幕
  1067. if outCardList and table.nums(outCardList) > 0 then
  1068. for i = 1, table.nums(outCardList) do
  1069. local mSprite = self.ui.Items.Layout_CardItem:getCopied()
  1070. mSprite.Items = getUIItems(mSprite)
  1071. local finalFileName = PKFuc.getPKCardImgByValue(outCardList[i])
  1072. mSprite.Items.ImageView_CardItem:loadTextureFromPlist(finalFileName)
  1073. local size = mSprite:getContentSize()
  1074. if app.room.roomInfo.nBankerUserId ~= nUserId then
  1075. mSprite.Items.ImageView_BankerFlag:setVisible(false)
  1076. end
  1077. layout:addChild(mSprite)
  1078. end
  1079. layout:requestDoLayout()
  1080. layout:doLayout()
  1081. local first = outCardList[1]
  1082. value = PKFuc.getCardValue(first)
  1083. end
  1084. local userInfo = app.room:getUserInfo(nUserId)
  1085. --播放动画
  1086. if cardType and not isReconet then
  1087. if cardType == PKDef.CARD_TYPE.BANZIPAO_TYPE_SINGLE or cardType == PKDef.CARD_TYPE.BANZIPAO_TYPE_DUIZI then
  1088. PKSound.playVoiceCardValue(userInfo.sex,PKFuc.getCardValue(srcList[1]),cardType)
  1089. self.ui:runAction(
  1090. cc.Sequence:create(
  1091. cc.DelayTime:create(0.2),
  1092. cc.CallFunc:create(function ()
  1093. if onEnd then
  1094. onEnd()
  1095. end
  1096. end)
  1097. )
  1098. )
  1099. elseif cardType == PKDef.CARD_TYPE.BANZIPAO_TYPE_SANZHANG then
  1100. PKAnimationCompnent.playBoomAnimation(self.ui.Items.Layout_Touch,self.outCardList[viewId]:getPosition(),viewId,onEnd)
  1101. PKSound.playVoiceCardValue(userInfo.sex,0,cardType)
  1102. elseif cardType == PKDef.CARD_TYPE.BANZIPAO_TYPE_SHUNZI then
  1103. PKAnimationCompnent.playShunZiAnimation(self.ui.Items.Layout_Touch,self.outCardList[viewId]:getPosition(),viewId,onEnd)
  1104. PKSound.playVoiceCardValue(userInfo.sex,0,cardType)
  1105. elseif cardType == PKDef.CARD_TYPE.BANZIPAO_TYPE_SHUANGSHUN then
  1106. PKAnimationCompnent.playBanZiPaoAnimation(self.ui.Items.Layout_Touch,self.outCardList[viewId]:getPosition(),viewId,onEnd)
  1107. PKSound.playVoiceCardValue(userInfo.sex,0,cardType)
  1108. elseif cardType == PKDef.CARD_TYPE.BANZIPAO_TYPE_SANSHUN then
  1109. PKAnimationCompnent.playGunTongAnimation(self.ui.Items.Layout_Touch,self.outCardList[viewId]:getPosition(),viewId,onEnd)
  1110. PKSound.playVoiceCardValue(userInfo.sex,0,cardType)
  1111. elseif cardType == PKDef.CARD_TYPE.BANZIPAO_TYPE_SISHUN then
  1112. PKAnimationCompnent.playGunLongAnimation(self.ui.Items.Layout_Touch,self.outCardList[viewId]:getPosition(),viewId,onEnd)
  1113. PKSound.playVoiceCardValue(userInfo.sex,0,cardType)
  1114. elseif cardType == PKDef.CARD_TYPE.BANZIPAO_TYPE_BOMB then
  1115. PKAnimationCompnent.playQingDanAnimation(self.ui.Items.Layout_Touch,self.outCardList[viewId]:getPosition(),viewId,onEnd)
  1116. PKSound.playVoiceCardValue(userInfo.sex,PKFuc.getCardValue(srcList[1]),cardType)
  1117. elseif cardType == PKDef.CARD_TYPE.BANZIPAO_TYPE_TIANPAI then
  1118. PKAnimationCompnent.playTianPaiAnimation(self.ui.Items.Layout_Touch,self.outCardList[viewId]:getPosition(),viewId,onEnd)
  1119. PKSound.playVoiceCardValue(userInfo.sex,0,cardType)
  1120. else
  1121. if onEnd then
  1122. onEnd()
  1123. end
  1124. end
  1125. else
  1126. if onEnd then
  1127. onEnd()
  1128. end
  1129. end
  1130. end
  1131. function PKRoomView:playTianPaiAnimation(nUserId, callback)
  1132. local viewId = app.room:getViewIdByUserId(nUserId)
  1133. local userInfo = app.room:getUserInfo(nUserId)
  1134. PKAnimationCompnent.playTianPaiAnimation(
  1135. self.ui.Items.Layout_Touch,
  1136. self.outCardList[viewId]:getPosition(),
  1137. viewId,
  1138. function ()
  1139. if callback then
  1140. callback()
  1141. end
  1142. end
  1143. )
  1144. PKSound.playVoiceCardValue(userInfo.sex, 0, PKDef.CARD_TYPE.BANZIPAO_TYPE_TIANPAI)
  1145. end
  1146. --播放报警动画
  1147. function PKRoomView:playBaoJingAni(viewId)
  1148. if viewId ~= PKDef.MyViewID then
  1149. self.PlayerView:showBaoJingAni(viewId)
  1150. end
  1151. end
  1152. --通知出牌
  1153. function PKRoomView:onBroadPlayerOutCard(data)
  1154. local function runonBroadPlayerOutCard(onEnd)
  1155. local response = data.response
  1156. logD("PKRoomView:runonBroadPlayerOutCard(), response = ", table.tostring(response))
  1157. local nUserId = response.nUserId;
  1158. local opType = response.opType;
  1159. self.PlayerView:hideAllPopText()
  1160. if self.isFristOutCard then
  1161. self.isFristOutCard = false
  1162. self.PlayerView:setOperatorTipVisible()
  1163. end
  1164. local viewId = app.room:getViewIdByUserId(nUserId)
  1165. self.outCardOpType = opType;
  1166. self.weaveCardList = {};
  1167. self.tiShiCount = 1;
  1168. self.PlayerView:showClockVisible(viewId,true,PKDef.OpTime.OUTCARD)
  1169. --清理桌面牌
  1170. self:cleanOutCardByViewId(viewId);
  1171. if viewId == self:getMeViewId() then
  1172. self.operationView:setOperatorPanelView(true,opType)
  1173. -- self:BanlanceAllCard();
  1174. if opType == 2 then
  1175. self:resetShangJiaData()
  1176. --清理桌面牌
  1177. for i = 1, PKDef.GameMaxPlayer do
  1178. self:cleanOutCardByViewId(i);
  1179. end
  1180. end
  1181. self:initTipData()
  1182. --判断是不是最后一手牌
  1183. --local handList = self:getMyHandCardList();
  1184. --[[local cardType = PKFuc.getCardType(handList);
  1185. local bLast = PKFuc.getIsCanOutCard(handList, cardType, self.shangJiaData);
  1186. local isHaveBoom = PKFuc.getIsHaveBoom(handList);
  1187. if bLast and cardType ~= PKDef.CARD_TYPE.LANDLORD_TYPE_NULL and not isHaveBoom then
  1188. logD("-------------------是最后一手牌-----------------------")
  1189. self.ui:runAction(cc.Sequence:create(
  1190. cc.DelayTime:create(0.5),
  1191. cc.CallFunc:create(function ()
  1192. self:letMyHandCardUp()
  1193. self:sendOutCard()
  1194. end)))
  1195. end--]]
  1196. else--如果不是自己出牌,隐藏出牌按钮
  1197. self.operationView:setOperatorPanelView(false)
  1198. end
  1199. if onEnd then
  1200. onEnd()
  1201. end
  1202. end
  1203. log("2000000000-PKRoomView - addCallBack(runonBroadPlayerOutCard)")
  1204. self:addCallBack(runonBroadPlayerOutCard)
  1205. end
  1206. function PKRoomView:initTipData()
  1207. if self.operationView.ui.Items.Button_Tip:isVisible() and 0 == table.nums(self.weaveCardList) then
  1208. logD("self.shangJiaData:",table.tostring(self.shangJiaData))
  1209. logD("self.handCardValueLocal:",table.tostring(self.handCardValueLocal))
  1210. self.weaveCardList = PKFuc.getTip(self.handCardValueLocal, self.shangJiaData)
  1211. end
  1212. end
  1213. function PKRoomView:letMyHandCardUp()
  1214. local tt = {};
  1215. for i = table.nums(self.handCardItem),1,-1 do
  1216. local mSprite = self.handCardItem[i];
  1217. if mSprite.value then
  1218. mSprite:setPositionY(self.cardOffY);
  1219. mSprite:setOpacity(0);
  1220. end
  1221. end
  1222. return tt;
  1223. end
  1224. function PKRoomView:getMyHandCardList()
  1225. local tt = {};
  1226. for i = table.nums(self.handCardItem),1,-1 do
  1227. local mSprite = self.handCardItem[i];
  1228. if mSprite.value then
  1229. table.insert(tt,mSprite.value)
  1230. end
  1231. end
  1232. return tt;
  1233. end
  1234. function PKRoomView:cleanOutCardByViewId(viewId)
  1235. local layout = self.ui.Items["Layout_outCard_"..viewId];
  1236. if layout then
  1237. layout:removeAllChildren();
  1238. end
  1239. end
  1240. function PKRoomView:BanlanceAllCard()
  1241. for i = 1,table.nums(self.handCardItem) do
  1242. local card = self.handCardItem[i];
  1243. if card:getPositionY() == self.cardOffY then
  1244. card:setPositionY(0);
  1245. end
  1246. card:setColor(PKDef.nomalColor)
  1247. card.hit = false;
  1248. end
  1249. end
  1250. function PKRoomView:getOutCardList()
  1251. local tt = {};
  1252. for i = table.nums(self.handCardItem),1,-1 do
  1253. local mSprite = self.handCardItem[i]
  1254. if mSprite.value and mSprite:getPositionY() == self.cardOffY then
  1255. table.insert(tt,mSprite.value)
  1256. PKFuc.logCard(mSprite.value)
  1257. end
  1258. end
  1259. return tt;
  1260. end
  1261. function PKRoomView:getLeftIsLai(outCardList)
  1262. local tt = {};
  1263. tt[14] = 0; --14(0xe花牌)
  1264. tt[0] = 0; --计数
  1265. --手上的牌
  1266. for i = 1, table.nums(self.handCardRoot) do
  1267. local tpValue = PKFuc.getCardValue(self.handCardRoot[i].imgList.value)
  1268. tt[tpValue] = tt[tpValue] or 0
  1269. tt[tpValue] = tt[tpValue] + 1
  1270. tt[0] = tt[0] + 1
  1271. end
  1272. --手上的牌 - 翘起来的牌
  1273. for _i = 1,table.nums(outCardList) do
  1274. local _tpValue = PKFuc.getCardValue(outCardList[_i])
  1275. if 0 ~= tt[_tpValue] then
  1276. tt[_tpValue] = tt[_tpValue] - 1
  1277. tt[0] = tt[0] - 1
  1278. else
  1279. logD("getLeftIsLai error not find handCard : "..tostring(outCardList[_i]))
  1280. end
  1281. end
  1282. --tt为得到为翘起来的牌,14为癞子,如果癞子的数量等于总的数量,证明剩下的全是癞子
  1283. return tt[14] > 0 and tt[14] == tt[0]
  1284. end
  1285. --出牌错误
  1286. function PKRoomView:onOutCardError(data)
  1287. local function runOnOutCardError(onEnd)
  1288. logE("PKRoomView:onOutCardError(), response = ", table.tostring(data.response))
  1289. log("2000000000-PKRoomView - runOnOutCardError")
  1290. local errorType = data.response.errorType
  1291. local cards = data.response.cards
  1292. local nUserId = data.response.nUserId
  1293. local viewId = app.room:getViewIdByUserId(nUserId)
  1294. if viewId == self:getMeViewId() then
  1295. showTooltip("你选择的牌不满足规则!请重新选择哦!!!")
  1296. --清楚桌面的牌
  1297. self:cleanOutCardByViewId(viewId);
  1298. self.operationView:setOperatorPanelView(true,self.outCardOpType);
  1299. --视为超时了
  1300. self.PlayerView:showClockVisible(viewId, true, PKDef.OpTime.OUTCARD);
  1301. --
  1302. for k,v in pairs(cards) do
  1303. table.insert(self.handCardValueLocal,v.card)
  1304. end
  1305. local card = DeepCopy(self.handCardValueLocal)
  1306. self.ui.Items.LayoutMain_4:removeAllChildren();
  1307. self.handCardItem = {}
  1308. self.handCardValueLocal = {}
  1309. self.handCardRoot = {}
  1310. app.room.cards[nUserId] = {}
  1311. app.room.cards[nUserId] = card
  1312. self:createCard(false, nUserId, null);
  1313. end
  1314. if onEnd then
  1315. onEnd()
  1316. end
  1317. end
  1318. log("2000000000-PKRoomView - addCallBack(runOnOutCardError)")
  1319. self:addCallBack(runOnOutCardError)
  1320. end
  1321. --出牌成功
  1322. function PKRoomView:onOutCardSuccess(data)
  1323. logD("PKRoomView:onOutCardSuccess(), response = ", table.tostring(data.response))
  1324. local function runOnOutCardSuccess(onEnd)
  1325. log("2000000000-PKRoomView - runOnOutCardSuccess")
  1326. local response = data.response
  1327. --出牌者ID
  1328. local nUserId = response.nUserId
  1329. --操作类型 0 pass 1 出牌
  1330. local opType = response.opType
  1331. --牌型
  1332. local cardsType = response.cardsType
  1333. --剩余手牌数
  1334. local leftNum = response.leftNum
  1335. --原始数据
  1336. local cardList = app.room:getCardList(response.cardList)
  1337. --解析了癞子后的数据
  1338. local cardList2 = app.room:getCardList(response.cardList2)
  1339. local viewId = app.room:getViewIdByUserId(nUserId)
  1340. if opType == 0 then
  1341. self.PlayerView:showOperatorTip(viewId,opType,true)
  1342. if onEnd then
  1343. onEnd()
  1344. end
  1345. return
  1346. end
  1347. self:resetShangJiaData()
  1348. self.shangJiaData.cardList = cardList2;
  1349. self.shangJiaData.cardType = cardsType;
  1350. self.shangJiaData.nUserId = nUserId;
  1351. --显示剩余手牌数
  1352. self.leftCardNum[viewId] = leftNum
  1353. self.PlayerView:setLeftCardNum(viewId,true,self.leftCardNum[viewId])
  1354. local userInfo = app.room:getUserInfo(nUserId)
  1355. if leftNum > 0 and leftNum <= 3 then
  1356. PKSound.PlayLeftNumSound(userInfo.sex,leftNum)
  1357. end
  1358. if leftNum <= 3 then
  1359. self:playBaoJingAni(viewId)
  1360. end
  1361. if viewId ~= self:getMeViewId() or self.isRecord then
  1362. local tpCardInfo = PKFuc.getCardType(cardList)
  1363. if tpCardInfo[1] and tpCardInfo[1].cardType and tpCardInfo[1].cardType == 0 then
  1364. cardsType = tpCardInfo[1].cardType
  1365. end
  1366. --判断是不是天牌
  1367. self:createOutCard(viewId,cardList2,cardsType,false,cardList,onEnd)
  1368. else
  1369. if self.isTuoGuan then--如果是托管状态需要删除一次手牌
  1370. self:createOutCard(viewId,cardList2,cardsType,false,cardList,nil)
  1371. end
  1372. self.operationView:setOperatorPanelView(false)
  1373. if onEnd then
  1374. onEnd()
  1375. end
  1376. end
  1377. end
  1378. log("2000000000-PKRoomView - addCallBack(runOnOutCardSuccess)")
  1379. self:addCallBack(runOnOutCardSuccess)
  1380. end
  1381. --[[
  1382. outCard:出的牌
  1383. ]]
  1384. function PKRoomView:IsTingPaiCard(outCard)
  1385. if outCard then
  1386. local data = self.tingCardLocal[outCard]
  1387. if data then
  1388. --标记只听模式
  1389. self.isNoCardTingPai = true
  1390. else
  1391. self.isNoCardTingPai = false
  1392. end
  1393. self.tingCardLocal = {}
  1394. --倒叙遍历1-10列
  1395. for col = self.lieShuMax,1,-1 do --列数
  1396. for row = self.hangShuMax,1,-1 do --行数
  1397. local card = self.handCardRoot[col].imgList[row]:getChildren()[1]
  1398. if card then
  1399. self.handCardRoot[col].imgList[row]:getChildren()[1]:setVisible(false)
  1400. end
  1401. end
  1402. end
  1403. end
  1404. end
  1405. function PKRoomView:addCallBack(callback)
  1406. table.insert(self.callbackQueue, callback)
  1407. logE(" #self.callbackQueue:".. #self.callbackQueue)
  1408. --高延迟情况下,执行快速播放,15条是没有标准,根据实际调整的
  1409. --if #self.callbackQueue >= 15 then
  1410. --cc.Director:getInstance():getScheduler():setTimeScale(5.0)
  1411. --else
  1412. cc.Director:getInstance():getScheduler():setTimeScale(1.0)
  1413. --end
  1414. local function runFunc()
  1415. log("2000000000 - runNextFunc() size = ", #self.callbackQueue )
  1416. if #self.callbackQueue <= 0 then
  1417. self.callbackRunning = false
  1418. return
  1419. end
  1420. --logE("2000000001 - ", debug.traceback())
  1421. local func = self.callbackQueue[1]
  1422. table.remove(self.callbackQueue,1)
  1423. self.callbackRunning = true
  1424. func(function()
  1425. self.callbackRunning = false;
  1426. runFunc();
  1427. end)
  1428. end
  1429. log("self.callbackRunning:",self.callbackRunning)
  1430. if not self.callbackRunning then
  1431. runFunc();
  1432. end
  1433. end
  1434. -- 其他玩家坐下成功
  1435. function PKRoomView:onOtherSitDownResponse(data)
  1436. if not data or not data.nSeatShowId then
  1437. return
  1438. end
  1439. local nSeatShowId = data.nSeatShowId;
  1440. local nUserId = app.room:getUserIdByViewId(nSeatShowId)
  1441. if self.toolView.chatView then
  1442. self.toolView.chatView:addPlayer(nUserId)
  1443. end
  1444. self:onUserReadyResponse()
  1445. -- 是否显示邀请好友
  1446. self:setWetChatVisible(table.nums(app.room.roomInfo.memberList) < PKFuc.getCreateRoomPlayerNum())
  1447. self:setBtnClubInviteVisible(table.nums(app.room.roomInfo.memberList) < PKFuc.getCreateRoomPlayerNum())
  1448. if app.room.roomInfo.nGameStartCount > 0 then
  1449. self:setWetChatVisible(false)
  1450. self:setBtnClubInviteVisible(false)
  1451. end
  1452. self.toolView:showFastStart(true)
  1453. if self.startView then
  1454. local userInfo = app.room:getUserInfo(nUserId);
  1455. userInfo = type(userInfo) == "string" and json.decode(userInfo) or userInfo
  1456. showTooltip("中途有【" .. getSubStringNickname(userInfo.nickname) .. "】玩家加入,申请开始系统自动关闭!")
  1457. self.startView:cleanup()
  1458. end
  1459. end
  1460. function PKRoomView:onOtherLogoutResponse(data)
  1461. local jushu = app.room.roomInfo.nGameStartCount or 0
  1462. if (not data or not data.nUserId or not data.nSeatShowId) or jushu > 0 then
  1463. logD("88888-return onOtherLogoutResponse")
  1464. return
  1465. end
  1466. if self.toolView.chatView then
  1467. self.toolView.chatView:delPlayer(data.nUserId)
  1468. end
  1469. local function test(onEnd)
  1470. app.room:updateUserSeateShowId()
  1471. -- 是否显示邀请好友
  1472. self:setWetChatVisible(app.room:getCurMaxPlayer() < PKFuc.getCreateRoomPlayerNum())
  1473. self:setBtnClubInviteVisible(app.room:getCurMaxPlayer() < PKFuc.getCreateRoomPlayerNum())
  1474. if app.room.roomInfo.nGameStartCount > 0 then
  1475. self:setWetChatVisible(false)
  1476. self:setBtnClubInviteVisible(false)
  1477. end
  1478. local memberList = app.room.roomInfo.memberList
  1479. memberList[data.nUserId] = nil
  1480. app.room:updateGpsUserInfo(nil,false)
  1481. self:onUserReadyResponse()
  1482. self.toolView:showFastStart(true)
  1483. if self.startView then
  1484. self.startView:removeFromParent()
  1485. self.startView = nil
  1486. end
  1487. logD("88888-onOtherLogoutResponse onEnd")
  1488. if onEnd then
  1489. onEnd()
  1490. end
  1491. end
  1492. logD("88888-addCallBack onOtherLogoutResponse")
  1493. self:addCallBack(test)
  1494. end
  1495. function PKRoomView:updateGameNums()
  1496. -- 更新当前局数
  1497. local roomInfo = app.room.roomInfo
  1498. local curCount = roomInfo.nGameStartCount or 0
  1499. local str = string.format("局数:%d/%d", curCount, roomInfo.nTotalGameNum)
  1500. self.ui.Items.Text_JuShu:setText(str);
  1501. end
  1502. -- 游戏开始
  1503. function PKRoomView:onGameStartResponse()
  1504. local function runGameStartResponse(onEnd)
  1505. log("2000000000-PKRoomView - runGameStartResponse()" )
  1506. --重置玩家数据
  1507. self:resetGameData()
  1508. --写入数据
  1509. for k,v in pairs(app.room.roomInfo.memberList) do
  1510. v.nPlayerFlag = PKDef.USER_STATE.PLAYING
  1511. end
  1512. --更新玩家状态状态
  1513. self:onUserReadyResponse()
  1514. -- 隐藏邀请好友
  1515. self:setWetChatVisible(false)
  1516. self:setBtnClubInviteVisible(false)
  1517. self.toolView:showFastStart(false)
  1518. -- 更新局数
  1519. self:updateGameNums()
  1520. --更新分数
  1521. for k,v in pairs(app.room.roomInfo.memberList) do
  1522. local nSeatShowId = app.room:getViewIdByUserId(v.nUserId)
  1523. self.PlayerView:updatePlayerInfo(nSeatShowId)
  1524. end
  1525. app.room.roomInfo.nBankerUserId = app.room:getViewIdBySeatId(app.room.roomInfo.nBankerSeatId)
  1526. --更新庄家
  1527. self:updateBanker()
  1528. self:showOwner();
  1529. if onEnd then
  1530. onEnd()
  1531. end
  1532. end
  1533. log("2000000000-PKRoomView - addCallBack(runGameStartResponse)")
  1534. self:addCallBack(runGameStartResponse);
  1535. end
  1536. function PKRoomView:onBaoPaiResponse(data)
  1537. local function runOnBaoPaiResponese(onEnd)
  1538. log("2000000000-PKRoomView - runOnBaoPaiResponese()")
  1539. local response = data.response
  1540. local errType = response.errType
  1541. --1-轮次错误 2-该玩家已经操作过了
  1542. if errType == 1 then
  1543. showTooltip("轮次错误")
  1544. elseif errType == 2 then
  1545. showTooltip("该玩家已经操作过了")
  1546. end
  1547. if onEnd then
  1548. onEnd()
  1549. end
  1550. end
  1551. log("2000000000-PKRoomView - addCallBack(runOnBaoPaiResponese)" )
  1552. self:addCallBack(runOnBaoPaiResponese);
  1553. end
  1554. function PKRoomView:onGameUpdateStatus()
  1555. local function runonGameUpdateStatus(onEnd)
  1556. log("2000000000-PKRoomView - runonGameUpdateStatus()" )
  1557. if onEnd then
  1558. onEnd()
  1559. end
  1560. end
  1561. log("2000000000-PKRoomView - addCallBack(runonGameUpdateStatus)" )
  1562. self:addCallBack(runonGameUpdateStatus);
  1563. end
  1564. function PKRoomView:onBaoPaiStartBroad(data)
  1565. local function runonBaoPaiStartBroad(onEnd)
  1566. log("2000000000-PKRoomView - runonBaoPaiStartBroad()" )
  1567. local response = data.response;
  1568. local askUid = response.askUid
  1569. local opType = response.opType
  1570. local viewId = app.room:getViewIdByUserId(askUid)
  1571. --显示闹钟
  1572. self.PlayerView:showClockVisible(viewId,true,PKDef.OpTime.BAOPAI)
  1573. if opType == 3 then
  1574. if viewId == self:getMeViewId() then
  1575. self.operationView:setLayoutBaoPaiView(true)
  1576. end
  1577. elseif opType == 4 then
  1578. if viewId == self:getMeViewId() then
  1579. self.operationView:setLayoutFanPaoView(true)
  1580. end
  1581. end
  1582. if onEnd then
  1583. onEnd()
  1584. end
  1585. end
  1586. log("2000000000-PKRoomView - addCallBack(runonBaoPaiStartBroad)" )
  1587. self:addCallBack(runonBaoPaiStartBroad);
  1588. end
  1589. function PKRoomView:onGameBankerChange()
  1590. local function runonGameBankerChange(onEnd)
  1591. log("2000000000-PKRoomView - runonGameBankerChange()" )
  1592. self:updateBanker()
  1593. if onEnd then
  1594. onEnd()
  1595. end
  1596. end
  1597. log("2000000000-PKRoomView - addCallBack(runonGameBankerChange)" )
  1598. self:addCallBack(runonGameBankerChange);
  1599. end
  1600. function PKRoomView:onPlayerBaoPaiResult(data)
  1601. local function runonPlayerBaoPaiResult(onEnd)
  1602. log("2000000000-PKRoomView - runonPlayerBaoPaiResult()" )
  1603. local response = data.response;
  1604. local askUid = response.askUid
  1605. local opType = response.opType
  1606. local viewId = app.room:getViewIdByUserId(askUid)
  1607. self.PlayerView:showOperatorTip(viewId,opType,true)
  1608. self.PlayerView:showBaoPaiFlag(viewId,opType)
  1609. --记录,查牌用
  1610. local memberInfo = app.room.roomInfo.memberList[askUid]
  1611. if memberInfo then
  1612. memberInfo.baoPai = opType
  1613. end
  1614. if app.room:getMyRecordUserId() == askUid then
  1615. self.operationView:setLayoutBaoPaiView(false)
  1616. self.operationView:setLayoutFanPaoView(false)
  1617. end
  1618. if onEnd then
  1619. onEnd()
  1620. end
  1621. end
  1622. log("2000000000-PKRoomView - addCallBack(runonPlayerBaoPaiResult)" )
  1623. self:addCallBack(runonPlayerBaoPaiResult);
  1624. end
  1625. function PKRoomView:onBroadCastNoPlayPlayer(data)
  1626. local function runonBroadCastNoPlayPlayer(onEnd)
  1627. log("2000000000-PKRoomView - runonBroadCastNoPlayPlayer()" )
  1628. local response = data.response
  1629. local uid = response.uid
  1630. local viewId = app.room:getViewIdByUserId(uid)
  1631. if viewId == self:getMeViewId() then
  1632. self.ui.Items.Layout_Wait:setVisible(true)
  1633. end
  1634. if onEnd then
  1635. onEnd()
  1636. end
  1637. end
  1638. log("2000000000-PKRoomView - addCallBack(runonBroadCastNoPlayPlayer)" )
  1639. self:addCallBack(runonBroadCastNoPlayPlayer);
  1640. end
  1641. function PKRoomView:onBroadCastBankerCallCard(data)
  1642. local function runonBroadCastBankerCallCard(onEnd)
  1643. log("2000000000-PKRoomView - runonBroadCastBankerCallCard()")
  1644. local response = data.response;
  1645. local nBankerUserId = response.nBankerUserId;
  1646. local noCards = response.noCards;
  1647. local viewId = app.room:getViewIdByUserId(nBankerUserId)
  1648. self.PlayerView:setOperatorTipVisible()
  1649. self.PlayerView:showClockVisible(viewId,true,PKDef.OpTime.CALLCARD)
  1650. self.operationView:setCallCardView(true,noCards)
  1651. if onEnd then
  1652. onEnd()
  1653. end
  1654. end
  1655. log("2000000000-PKRoomView - addCallBack(runonBroadCastBankerCallCard)" )
  1656. self:addCallBack(runonBroadCastBankerCallCard);
  1657. end
  1658. function PKRoomView:onGameBankerSendCallCardResponse(data)
  1659. local function runonGameBankerSendCallCardResponse(onEnd)
  1660. log("2000000000-PKRoomView - runonGameBankerSendCallCardResponse()" )
  1661. local response = data.response;
  1662. local nBankerUserId = response.nBankerUserId;
  1663. local callCard = response.card;
  1664. app.room.roomInfo.cAskCard = callCard
  1665. local viewId = app.room:getViewIdByUserId(nBankerUserId)
  1666. self.PlayerView:setAllClockVisible()
  1667. self.operationView:setCallCardView(true,nil,callCard)
  1668. self:showFriendFlag()
  1669. --音效
  1670. local userInfo = app.room:getUserInfo(nBankerUserId)
  1671. PKSound.PlayJiaoPaiSound(userInfo.sex)
  1672. if onEnd then
  1673. onEnd()
  1674. end
  1675. end
  1676. log("2000000000-PKRoomView - addCallBack(runonGameBankerSendCallCardResponse)" )
  1677. self:addCallBack(runonGameBankerSendCallCardResponse);
  1678. end
  1679. function PKRoomView:showFriendFlag()
  1680. local list = self:getMyHandCardList()
  1681. local firendList = {}
  1682. local enemyList = {}
  1683. for k,v in ipairs(list) do
  1684. if v == app.room.roomInfo.cAskCard then
  1685. local nbankerViewId = app.room:getViewIdByUserId(app.room.roomInfo.nBankerUserId)
  1686. for k,v in pairs(app.room.roomInfo.memberList) do
  1687. local viewId = app.room:getViewIdByUserId(v.nUserId)
  1688. if viewId == self:getMeViewId() or viewId == nbankerViewId then
  1689. table.insert(firendList,viewId)
  1690. else
  1691. table.insert(enemyList,viewId)
  1692. end
  1693. end
  1694. self.PlayerView:showFriendFlag(firendList,enemyList)
  1695. break
  1696. end
  1697. end
  1698. end
  1699. function PKRoomView:showMengYouFlag(bAni)
  1700. local firendList = {}
  1701. local enemyList = {}
  1702. local nFriendViewId = app.room:getViewIdByUserId(app.room.roomInfo.nBankerHelper)
  1703. local nBankerViewId = app.room:getViewIdByUserId(app.room.roomInfo.nBankerUserId)
  1704. for k,v in pairs(app.room.roomInfo.memberList) do
  1705. local viewId = app.room:getViewIdByUserId(v.nUserId)
  1706. if viewId == nBankerViewId or viewId == nFriendViewId then
  1707. table.insert(firendList,viewId)
  1708. else
  1709. table.insert(enemyList,viewId)
  1710. end
  1711. end
  1712. self.PlayerView:showFriendFlag(firendList,enemyList,bAni)
  1713. end
  1714. function PKRoomView:onFriendAppear()
  1715. local function runonFriendAppear(onEnd)
  1716. log("2000000000-PKRoomView - runonFriendAppear()" )
  1717. self:showMengYouFlag(true)
  1718. if onEnd then
  1719. onEnd()
  1720. end
  1721. end
  1722. log("2000000000-PKRoomView - addCallBack(runonFriendAppear)" )
  1723. self:addCallBack(runonFriendAppear);
  1724. end
  1725. function PKRoomView:onOutCardRanking(data)
  1726. local function runonOutCardRanking(onEnd)
  1727. log("2000000000-PKRoomView - runonOutCardRanking()" )
  1728. local response = data.response
  1729. local nUserId = response.uid
  1730. local ranking = response.ranking
  1731. local viewId = app.room:getViewIdByUserId(nUserId)
  1732. if viewId then
  1733. self.PlayerView:showRanking(viewId,tonumber(ranking))
  1734. self.PlayerView:showBaoJingAni(viewId,true)
  1735. end
  1736. if onEnd then
  1737. onEnd()
  1738. end
  1739. end
  1740. log("2000000000-PKRoomView - addCallBack(runonOutCardRanking)" )
  1741. self:addCallBack(runonOutCardRanking);
  1742. end
  1743. function PKRoomView:setLiangPaiVisible(bVisible)
  1744. --self.xiaojuChaPaiView:setVisible(bVisible)
  1745. end
  1746. -- 小局结算
  1747. function PKRoomView:onGameXiaoJuResponse(data)
  1748. self.PlayerView:setAllClockVisible()
  1749. self.PlayerView:setAllBaoJingVisible()
  1750. local function runGameXiaoJuResponse(onEnd)
  1751. local response = data.response
  1752. --标记单局结束
  1753. self.isGameOver = true
  1754. local roomInfo = app.room.roomInfo
  1755. local myScore = 0
  1756. --玩家分数
  1757. for k,v in pairs(roomInfo.playerList) do
  1758. local viewId = app.room:getViewIdByUserId(k)
  1759. local nScore = tonumber(v.nTotalScore)
  1760. local memberInfo = app.room.roomInfo.memberList[k]
  1761. memberInfo.nTotalScore = nScore
  1762. self.PlayerView:setPlayerScore(viewId,nScore)
  1763. if viewId == PKDef.MyViewID then
  1764. myScore = nScore
  1765. end
  1766. end
  1767. local function showXiaoJu(noShowSound)
  1768. if self.xiaojuView then
  1769. -- 停止背景音乐
  1770. stopBGMusic()
  1771. self.xiaojuView:setVisible(true)
  1772. if not noShowSound then
  1773. if myScore >= 0 then
  1774. PKSound.PlayWinSound()
  1775. else
  1776. PKSound.PlayLoseSound()
  1777. end
  1778. end
  1779. end
  1780. end
  1781. local function showChaPai()
  1782. self.chaPaiView = PKRoomXiaoJuChaPaiView:new(showXiaoJu)
  1783. self:addChild(self.chaPaiView)
  1784. end
  1785. local function nextCallBackFun()
  1786. self:resetGameData()
  1787. self:playBGM()
  1788. self.ui:sendMsg(app.room, PKDef.PKEvent.CallReadyRequest);
  1789. end
  1790. local function showAllJieSuan()
  1791. if self.RoomCountAllViewUI then
  1792. -- 停止背景音乐
  1793. stopBGMusic()
  1794. self.RoomCountAllViewUI:setVisible(true)
  1795. self:showGameOverAward()
  1796. end
  1797. end
  1798. self.xiaojuView = PKRoomXiaoJuView:new(nextCallBackFun,showChaPai,showAllJieSuan)
  1799. self:addChild(self.xiaojuView)
  1800. self.xiaojuView:setVisible(false)
  1801. --天牌
  1802. if app.room.roomInfo.mSpecialType == 1 then
  1803. local winerInfo = nil
  1804. for k,v in pairs(app.room.roomInfo.playerList) do
  1805. if v.mWinLose == 1 then
  1806. winerInfo = v
  1807. break
  1808. end
  1809. end
  1810. local viewId = app.room:getViewIdByUserId(winerInfo.nUserId)
  1811. self:playTianPaiAnimation(winerInfo.nUserId,function ()
  1812. showXiaoJu()
  1813. end)
  1814. else
  1815. local time = 2
  1816. if self.isReconet then
  1817. time = 0.001
  1818. end
  1819. self.ui:runAction(cc.Sequence:create(cc.DelayTime:create(time),cc.CallFunc:create(function ()
  1820. showXiaoJu()
  1821. end)))
  1822. end
  1823. --结束
  1824. if onEnd then
  1825. onEnd()
  1826. end
  1827. end
  1828. log("2000000000-PKRoomView - addCallBack(runGameXiaoJuResponse)" )
  1829. self:addCallBack(runGameXiaoJuResponse);
  1830. end
  1831. -- 大局结算
  1832. function PKRoomView:onGameDaJuResponse(data)
  1833. local function runGameDaJuResponse(onEnd)
  1834. app.room:dispatchEvent({name = GAME_EVENT.DISSMISS_CLOSE});
  1835. if data.response.stopFlag == 9 then
  1836. app.room.roomInfo.isShowDismiss = true
  1837. end
  1838. if app.room.roomInfo.nGameStartCount == app.room.roomInfo.nTotalGameNum and not app.room.roomInfo.isShowDismiss then
  1839. -- 打开结算
  1840. local view = PKRoomCountAllView:new(data.response);
  1841. view:setAnchorPoint(cc.p(0.5, 0.5));
  1842. local visibleSize = getWinSize()
  1843. view:setPosition(cc.p(visibleSize.width/2,visibleSize.height/2))
  1844. self:addChild(view);
  1845. self.RoomCountAllViewUI = view;
  1846. view:setVisible(false);
  1847. else
  1848. -- 打开结算
  1849. local view = PKRoomCountAllView:new(data.response);
  1850. view:setAnchorPoint(cc.p(0.5, 0.5));
  1851. app:showWaitDialog(view)
  1852. stopBGMusic()
  1853. self:showGameOverAward()
  1854. end
  1855. if onEnd then
  1856. onEnd()
  1857. end
  1858. end
  1859. log("2000000000-PKRoomView - addCallBack(runGameDaJuResponse)")
  1860. self:addCallBack(runGameDaJuResponse);
  1861. end
  1862. function PKRoomView:onUserReadyResponse()
  1863. self.PlayerView:setPlayerVisible(false)
  1864. for k,v in pairs(app.room.roomInfo.memberList) do
  1865. local nSeatShowId = app.room:getViewIdByUserId(v.nUserId)
  1866. self.PlayerView:setPlayerReadyState(nSeatShowId,(v.nPlayerFlag == PKDef.USER_STATE.READY))
  1867. self.PlayerView:updatePlayerInfo(nSeatShowId)
  1868. end
  1869. local nUserId = app.room:getMyRecordUserId()
  1870. local memberInfo = app.room.roomInfo.memberList[nUserId]
  1871. self:setBtnSitDownVisible(memberInfo.nPlayerFlag == PKDef.USER_STATE.SIT_DOWN)
  1872. if app.room.roomInfo.nGameStartCount > 0 then
  1873. self.toolView.ui.Items.Button_Leave:setEnabled(false)
  1874. end
  1875. if app.room.roomInfo.nGameStartCount == 0 and app.room.roomInfo.nRoomOwnedUid ~= app.user.loginInfo.uid then
  1876. self.toolView.ui.Items.Button_Dismiss:setEnabled(false)
  1877. else
  1878. self.toolView.ui.Items.Button_Dismiss:setEnabled(true)
  1879. end
  1880. if app.club_php.clubID and app.club_php.clubID ~= 0 then
  1881. if app.room.roomInfo.nGameStartCount <= 0 then
  1882. self.toolView.ui.Items.Button_Dismiss:setEnabled(false)
  1883. else
  1884. self.toolView.ui.Items.Button_Dismiss:setEnabled(true)
  1885. end
  1886. end
  1887. -- 显示是否可以解散
  1888. self.toolView:checkCanDismiss()
  1889. end
  1890. function PKRoomView:onDismissResponse(event)
  1891. if not event or not event.response then
  1892. return
  1893. end
  1894. print("onDismissResponse() response = ", event.response)
  1895. local response = event.response
  1896. --当前时间
  1897. app.room.roomInfo.nDismissStateTime = response.timeLeft
  1898. --总的时间
  1899. app.room.roomInfo.nDismissToTalTime = response.timeLeft --服务器没发解散总时间来。那么就和一开始收到的解散剩余时间一致
  1900. --显示解散(此标志会影响闹钟时间会冻住)
  1901. app.room.roomInfo.nShowDismiss = true
  1902. if response.operateType == 1 then
  1903. if response.memberList ~= nil then
  1904. for k,v in pairs(response.memberList) do
  1905. if v.dismissState == 1 then
  1906. local view = require("luaScript.Views.Room.RoomDismissView"):new(v.nUserId,app.room.roomInfo.memberList,response.timeLeft)
  1907. view:setAnchorPoint(cc.p(0.5, 0.5));
  1908. app:showWaitDialog(view);
  1909. return
  1910. end
  1911. end
  1912. else
  1913. local view = require("luaScript.Views.Room.RoomDismissView"):new(response.nUserId,app.room.roomInfo.memberList,response.timeLeft)
  1914. view:setAnchorPoint(cc.p(0.5, 0.5));
  1915. app:showWaitDialog(view);
  1916. end
  1917. else
  1918. local memberStatus={}
  1919. if response.memberList ~= nil then
  1920. for k,v in pairs(response.memberList) do
  1921. table.insert(memberStatus,{userId = v.nUserId, status = v.dismissState})
  1922. end
  1923. else
  1924. table.insert(memberStatus,{userId = response.nUserId, status = response.operateType})
  1925. end
  1926. app.room:dispatchEvent({name = GAME_EVENT.DISSMISS_UPDATE_STATUS , memberStatus = memberStatus});
  1927. end
  1928. end
  1929. --更新庄家
  1930. function PKRoomView:updateBanker()
  1931. --只显示当前的庄家座位号
  1932. if app.room.roomInfo.nBankerUserId then
  1933. local viewId = app.room:getViewIdByUserId(app.room.roomInfo.nBankerUserId)
  1934. if self.PlayerView:setPlayerBankerVisible(viewId,true) then
  1935. else
  1936. showTooltip("庄家椅子号"..tostring(viewId).."不匹配")
  1937. end
  1938. end
  1939. end
  1940. --显示房主
  1941. function PKRoomView:showOwner()
  1942. --只显示当前的庄家座位号
  1943. local nBankerSeatId = app.room.roomInfo.nRoomOwnedUid
  1944. local viewId = app.room:getViewIdByUserId(nBankerSeatId)
  1945. self.PlayerView:setPlayerOwnerVisible(viewId,true)
  1946. end
  1947. function PKRoomView:onOtherDroppedResponse(data)
  1948. if not data.response.nUserId then
  1949. return
  1950. end
  1951. local nUserId = data.response.nUserId
  1952. local nDroppedStatus = data.response.nDroppedStatus
  1953. local memberInfo = app.room.roomInfo.memberList[nUserId]
  1954. if memberInfo then
  1955. memberInfo.nOnlineStatus = nDroppedStatus == 1 and 0 or 1
  1956. end
  1957. local viewId = app.room:getViewIdByUserId(nUserId)
  1958. --[[app.room.offLineUid[tonumber(nUserId)] = (nDroppedStatus == 1)
  1959. if nDroppedStatus == 0 then--如果上线了 离线时间置0
  1960. app.room.offLineTime[tonumber(nUserId)] = 0
  1961. self.PlayerView:reSetClockTime(viewId)
  1962. end--]]
  1963. self.PlayerView:setPlayerOffLine(memberInfo.nOnlineStatus == 1,viewId)
  1964. end
  1965. function PKRoomView:goToHall()
  1966. gotoMainView()
  1967. end
  1968. function PKRoomView:onUserExitResponseRoom(data)
  1969. local function runUserExitResponseRoom(onEnd)
  1970. log("2000000000-PKRoomView - runUserExitResponseRoom()" )
  1971. local response = data.response
  1972. --房间号
  1973. local roomid = app.room.roomInfo.nShowTableId
  1974. -- 0: 不退出, 1: 退出
  1975. if response.logoutFlag == 1 then
  1976. self:goToHall()
  1977. end
  1978. --app.room:dispatchEvent({name = "onUserExitResponseHall"});
  1979. logE("88888-onUserExitResponseRoom onEnd")
  1980. if onEnd then
  1981. onEnd()
  1982. end
  1983. end
  1984. log("2000000000-PKRoomView - addCallBack(runUserExitResponseRoom)" )
  1985. self:addCallBack(runUserExitResponseRoom);
  1986. end
  1987. function PKRoomView:initGpsComponent()
  1988. local versionCode = getAppVersionCode()
  1989. versionCode = tonumber(versionCode) or 0
  1990. logD("RoomView:initGpsComponent() versionCode = ", versionCode)
  1991. if isReviewVersion() then
  1992. self.toolView.ui.Items.Button_dingwei:setVisible(false)
  1993. return
  1994. end
  1995. -- 创建 gps 组件
  1996. --self.gpsComponent = import("luaScript.Views.Room.RoomGpsComponent"):new(self.ui.Items.Button_GPS)
  1997. local function exitRoomCallback()
  1998. local isGameStart = app.room.roomInfo.nGameStartCount > 0
  1999. if isGameStart then
  2000. app.room:requestDismissRoom(1)
  2001. else
  2002. self.ui:sendMsg(app.room, "callLeaveRequest");
  2003. end
  2004. end
  2005. local function dismissCallback()
  2006. app.room:requestDismissRoom(1)
  2007. end
  2008. self.gpsComponent = import("luaScript.Views.Room.RoomGpsComponentView"):new(4,self.toolView.ui.Items.Button_dingwei,exitRoomCallback,exitRoomCallback)
  2009. self:addChild(self.gpsComponent)
  2010. -- GPS 按钮
  2011. self.toolView.ui.Items.Button_dingwei:registerClick(handler(self, self.showGpsView))
  2012. end
  2013. -- 更新所有玩家的信息到GPS组件
  2014. function PKRoomView:updateAllGpsInfo()
  2015. local userInfoList = {}
  2016. log("updateAllGpsInfo memberList:"..table.tostring(app.room.roomInfo.memberList))
  2017. for nUserId, memberInfo in pairs(app.room.roomInfo.memberList) do
  2018. local nSeatId = memberInfo.nSeatId
  2019. local userInfo = memberInfo.userInfo
  2020. userInfoList[nUserId] = {nSeatId = nSeatId, userInfo = userInfo}
  2021. end
  2022. if self.gpsComponent then
  2023. self.gpsComponent:updateUserInfos(userInfoList)
  2024. end
  2025. end
  2026. -- 显示GPS界面
  2027. function PKRoomView:showGpsView()
  2028. print("RoomView:showGpsView()")
  2029. local isGameStart = app.room.roomInfo.nGameStartCount > 0
  2030. if self.gpsComponent then
  2031. self.gpsComponent:showGpsView(isGameStart)
  2032. end
  2033. end
  2034. --多维数组转 一维数组
  2035. function PKRoomView:ChangeDataToVector(data)
  2036. local tt = {}
  2037. for i = 1, self.lieShuMax do
  2038. for j = 1, self.hangShuMax do
  2039. if data[i][j] then
  2040. table.insert(tt,data[i][j])
  2041. end
  2042. end
  2043. end
  2044. return tt
  2045. end
  2046. function PKRoomView:resetShangJiaData()
  2047. self.shangJiaData = {};
  2048. self.shangJiaData.cardList = {};
  2049. self.shangJiaData.cardType = 0;
  2050. self.shangJiaData.nUserId = 0;
  2051. end
  2052. function PKRoomView:setWaitBgVisible(bVisible)
  2053. self.ui.Items.Layout_Wait:setVisible(bVisible)
  2054. end
  2055. --显示隐藏托管
  2056. function PKRoomView:showTuoGuan(isShow)
  2057. if isShow then
  2058. if not self.tuoguanView then
  2059. self.tuoguanView = import("pk_base.luaScript.Views.Room.PKRoomTuoGuanView"):new()
  2060. self:addChild(self.tuoguanView)
  2061. end
  2062. else
  2063. if self.tuoguanView and not tolua.isnull(self.tuoguanView) then
  2064. self.tuoguanView:removeFromParent()
  2065. self.tuoguanView = nil
  2066. end
  2067. end
  2068. end
  2069. --托管结果协议
  2070. function PKRoomView:onTuoGuanResponse(data)
  2071. local function runTuoGuanResponse(onEnd)
  2072. log("2000000000-PKRoomView - (runTuoGuanResponse)")
  2073. local response = data.response
  2074. local entrustType = response.entrustType;--托管状态 1-托管中 0-未托管
  2075. local nUserID = response.nUserId;
  2076. local viewId = app.room:getViewIdByUserId(nUserID)
  2077. local isTuoGuan = entrustType == 1;
  2078. if viewId == self:getMeViewId() then
  2079. if isTuoGuan then
  2080. self:showTuoGuan(true)
  2081. self.isTuoGuan = true
  2082. else
  2083. self:showTuoGuan(false)
  2084. self.isTuoGuan = false
  2085. end
  2086. end
  2087. self.PlayerView:showTuoGuanByViewId(viewId,isTuoGuan)
  2088. if onEnd then
  2089. onEnd()
  2090. end
  2091. end
  2092. log("2000000000-PKRoomView - addCallBack(runTuoGuanResponse)")
  2093. self:addCallBack(runTuoGuanResponse)
  2094. end
  2095. --获取托管状态
  2096. function PKRoomView:getTuoGuanState()
  2097. return self.isTuoGuan or false
  2098. end
  2099. ---
  2100. -- 显示抽奖界面
  2101. --
  2102. function PKRoomView:showGameOverAward()
  2103. if not (dd and dd.IGameOverAward) then
  2104. return
  2105. end
  2106. self:runDelay(0.1, function ( )
  2107. -- 延迟0.1秒执行,可能有些游戏弹大结算的时候还未收到抽奖消息
  2108. dd.IGameOverAward.showAwardView();
  2109. end)
  2110. end
  2111. return PKRoomView;