Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

3057 lignes
97 KiB

  1. -- xx : 2018 3 27
  2. -- 跑得快主界面
  3. local PdkDef = require("luaScript.SubGameDefine.PDKDefine")
  4. local PdkPlayerNode = require("pk_paodekuai.luaScript.Views.Room.Node.PdkPlayerNode")
  5. local PdkCardNode = require("pk_paodekuai.luaScript.Views.Room.Node.PdkCardNode")
  6. local PdkRoomViewConfig = require("pk_paodekuai.luaScript.Views.Room.PdkRoomViewConfig")
  7. local PdkEffectHelper = require("pk_paodekuai.luaScript.Views.Room.PdkEffectHelper"):new()
  8. local ETS = PdkRoomViewConfig.EffectType
  9. local PdkSoundHelper = require("pk_paodekuai.luaScript.Views.Room.PdkSoundHelper"):new()
  10. local RoomGpsComponent = require("luaScript.Views.Room.RoomGpsComponent")
  11. require("luaScript.Views.Room.RoomFunctions")
  12. local PdkMessage = require("pk_paodekuai.luaScript.Protocol.PdkMessage")
  13. local PdkFunctions = require("pk_paodekuai.luaScript.PdkFunctions")
  14. -- 默认选择值
  15. local CENTER_X=640*g_radio_x
  16. local CENTER_Y=360*g_radio_y
  17. local PdkRoomView = class("PdkRoomView", cc.UIView)
  18. function PdkRoomView:ctor(params)
  19. PdkRoomView.super.ctor(self)
  20. -- 玩家节点
  21. self._playerNodes = {}
  22. -- 自己手牌集合
  23. self._selfCards = {}
  24. -- 玩家出牌集合
  25. self._showCards = {{},{},{}}
  26. -- 点击选择的牌
  27. self._selectCards = {}
  28. -- 上一次出牌viewPos
  29. self._lastOutPos = 0
  30. -- 上一次出牌类型
  31. self._lastOutType = 0
  32. -- 上一次出牌,用于提示
  33. self._lastCards = {}
  34. -- 排序轮次用
  35. self._turnsQueue = {}
  36. -- 快速开始界面
  37. self.fastStartRequestView = nil
  38. self.ui = loadUI("pk_paodekuai/res/ui/ui_room/ui_pdk_gameview.ui")
  39. self:addChild(self.ui)
  40. self.panelMenu = self.ui.Items.Layout_Menu
  41. self.cardRoot = self.ui.Items.cardRoot
  42. self.imgOtherCards = self.ui.Items.ImageView_other
  43. self.txtOtherCards = self.ui.Items.Text_otherNum
  44. self:showOtherCards(false)
  45. loadSpriteFrameFile("pk_paodekuai/res/ui/zy_game/zy_room_add.plist")
  46. self:initChatView()
  47. self:initUi()
  48. self:showMenu(false)
  49. self:showTurnBtn(false)
  50. self:setRoomInfo(app.room:getRoomInfo())
  51. loadSpriteFrameFile("pk_paodekuai/res/ui/zy_game/zy_pdk_cards.plist")
  52. loadSpriteFrameFile("pk_paodekuai/res/ui/zy_effect/zy_pdk_effect.plist")
  53. loadSpriteFrameFile("pk_paodekuai/res/ui/zy_effect/zy_pdk_effect_bomb.plist")
  54. loadSpriteFrameFile("pk_paodekuai/res/ui/zy_effect/zy_pdk_effect_shunziliandui.plist")
  55. loadSpriteFrameFile("pk_paodekuai/res/ui/zy_effect/zy_pdk_effect_plan.plist")
  56. loadSpriteFrameFile("pk_paodekuai/res/ui/zy_effect/pdk_effect_spring2.plist")
  57. loadSpriteFrameFile("pk_paodekuai/res/ui/zy_effect/pdk_effect_fspring.plist")
  58. --
  59. local gameInfo = app.room:getRoomInfo().nGameInfo
  60. local data = json.decode(gameInfo)
  61. local rule = tonumber(data.specialRule)
  62. -- 是否选择三不带全
  63. self.ruleIsNotEnough = true--getNumBand(rule, 0x0008)>0
  64. -- 炸弹可拆
  65. self.ruleIsChaiBomb = getNumBand(rule, 0x0004)>0
  66. -- 是否选择4带3
  67. self.ruleIsFAT = getNumBand(rule, 0x0002)>0
  68. -- 玩法模式 经典 15张
  69. self.ruleType = tonumber(data.gamerule)
  70. -- 是否选择扎鸟
  71. self.ruleZhaniao = getNumBand(rule, 0x0001)>0
  72. --
  73. self.functionQueue = require("luaScript.Tools.FunctionQueue"):new()
  74. end
  75. --[[
  76. GAME_STATE_INIT =0, --//游戏准备状态
  77. GAME_STATE_SEND_HAND_CARD =1, --//发牌
  78. GAME_STATE_OUT_CARD =2, --//打牌
  79. GAME_STATE_ROUND_OVER =3, --//游戏一局结束
  80. GAME_STATE_GAME_OVER =4, --//游戏结束
  81. ]]
  82. function PdkRoomView:onEnter()
  83. PdkRoomView.super.onEnter()
  84. local roomInfo = app.room:getRoomInfo()
  85. if roomInfo.nGameStartCount > 0 then
  86. setShowCountAll(true)
  87. end
  88. PokerUtil = require("pk_paodekuai.luaScript.Views.Room.PokerUtil"):new({isChai=self.ruleIsChaiBomb, isFAT=self.ruleIsFAT})
  89. self:bindEvents()
  90. self:addTouchesListener()
  91. local roomInfo = app.room:getRoomInfo()
  92. if roomInfo.recoverItem then
  93. local recoverData = roomInfo.recoverItem
  94. self:recover(recoverData)
  95. else
  96. --self:checkGpsDistance(nil,roomInfo.nGameStartCount==0)
  97. end
  98. -- GPS组件
  99. self:initGpsComponent()
  100. local changeDesk = tonumber(loadUserInfo("pdk_setting_bg_idx")) or 3
  101. self:onNormalChangeDesktop({idx=changeDesk})
  102. PdkSoundHelper:playBgMusic()
  103. --定时器
  104. local roomInfo = app.room:getRoomInfo()
  105. self.ui.Items.systemTime:setText(string.format("%s", os.date("%y-%m-%d %H:%M:%S", os.time()) ) )
  106. if not self.Time then
  107. self.Time = cc.Director:getInstance():getScheduler():scheduleScriptFunc(function()
  108. local roomInfo = app.room:getRoomInfo()
  109. self.ui.Items.systemTime:setText(string.format("%s", os.date("%y-%m-%d %H:%M:%S", os.time()) ) )
  110. end,1.0,false)
  111. end
  112. if app.room.isReconnection == true then
  113. --断线重连
  114. self:isShowFastStartView()
  115. end
  116. self:checkCanDismiss()
  117. -- if self.chatView and PdkFunctions.isForbidProp() then
  118. -- self.chatView:hideBtns()
  119. -- end
  120. -- todo
  121. if self.chatView and PdkFunctions.isForbidProp() then
  122. self.chatView:hideFace()
  123. end
  124. if self.chatView and PdkFunctions.isForbidVoice() then
  125. self.chatView:hideVoice()
  126. end
  127. end
  128. function PdkRoomView:onExit()
  129. self.fastStartRequestView = nil
  130. setShowCountAll(false)
  131. if self.Time then
  132. cc.Director:getInstance():getScheduler():unscheduleScriptEntry(self.Time)
  133. self.Time = nil
  134. end
  135. for _,node in pairs(self._playerNodes) do
  136. if node then node:setTurn(false) end
  137. end
  138. PokerUtil = nil
  139. app.room:cleanCache()
  140. stopBGMusic()
  141. self:cleanCache()
  142. end
  143. function PdkRoomView:cleanCache()
  144. local preload = package.loaded
  145. for k, v in pairs(package.loaded or {}) do
  146. local res1 = string.find( k, "pk.luaScript") or 0
  147. local res2 = string.find( k, "pk_paodekuai.luaScript") or 0
  148. if res1 > 0 or res2 > 0 then
  149. package.loaded[k] = nil
  150. end
  151. end
  152. end
  153. function PdkRoomView:addFunction( func )
  154. if self.functionQueue then
  155. self.functionQueue:addFunction(func)
  156. else
  157. func()
  158. end
  159. end
  160. function PdkRoomView:initChatView()
  161. local children = self.panelMenu:getParent():getChildByTag(99)
  162. if children then
  163. children:removeFromParent()
  164. end
  165. local winSize = cc.Director:getInstance():getWinSize()
  166. local designSize = cc.p(1280,720)
  167. local radis_x = winSize.width / designSize.x
  168. local radis_y = winSize.height / designSize.y
  169. local messageList = PdkDef.ChatMessages
  170. local headInfos = {}
  171. if app.room:getRoomInfo().nMaxPlayCount == 2 then
  172. headInfos[1] = {headPos = cc.p((62)/designSize.x * winSize.width, 111/designSize.y * winSize.height), voiceDir = 2}
  173. headInfos[2] = {headPos = cc.p((1224-25)/designSize.x * winSize.width, 500/designSize.y * winSize.height), voiceDir = 1}
  174. elseif app.room:getRoomInfo().nMaxPlayCount == 3 then
  175. headInfos[1] = {headPos = cc.p((62)/designSize.x * winSize.width, 111/designSize.y * winSize.height), voiceDir = 2}
  176. headInfos[2] = {headPos = cc.p((1224-25)/designSize.x * winSize.width, 500/designSize.y * winSize.height), voiceDir = 1}
  177. headInfos[3] = {headPos = cc.p((62+25)/designSize.x * winSize.width, 500/designSize.y * winSize.height), voiceDir = 2}
  178. end
  179. local showBtn = true;
  180. self.chatView = import("luaScript.Views.Room.ChatView"):new(messageList, headInfos, showBtn)
  181. --self.chatView:setLanguage(false)
  182. self.chatView:setLocalZOrder(99)
  183. self.chatView:setTag(99)
  184. self.chatView:setBtnFace(cc.p(0.9411563, 0.3730273),"room_menu3_room_btn_kjy.png")
  185. self.chatView:setBtnVoice(cc.p(0.9411563, 0.2163281),"room_menu3_room_btn_yuyin.png")
  186. self.panelMenu:getParent():addChild(self.chatView)
  187. local pdkHuDongBiaoQingKG = tonumber(loadUserInfo("pdkHuDongBiaoQingKG")) or 1
  188. local pdkPingBiYuYinKG = tonumber(loadUserInfo("pdkPingBiYuYinKG")) or 1
  189. self.chatView:setPropEnabled(pdkHuDongBiaoQingKG == 1)
  190. self.chatView:setVoiceEnabled(pdkPingBiYuYinKG == 1)
  191. -- if PdkFunctions.isForbidProp() and self.chatView then
  192. -- self.chatView:hideBtns()
  193. -- self.chatView:setPropEnabled(false)
  194. -- self.chatView:setVoiceEnabled(false)
  195. -- end
  196. -- todo
  197. if self.chatView and PdkFunctions.isForbidProp() then
  198. self.chatView:hideFace()
  199. end
  200. if self.chatView and PdkFunctions.isForbidVoice() then
  201. self.chatView:hideVoice()
  202. end
  203. end
  204. function PdkRoomView:resetRoundData( )
  205. -- 上一次出牌viewPos
  206. self._lastOutPos = 0
  207. -- 上一次出牌类型
  208. self._lastOutType = 0
  209. self._lastCards = {}
  210. self.lastOutFlag = -1
  211. --
  212. self:showTurnBtn(false)
  213. self:cleanSelfCards()
  214. self:cleanShowCards()
  215. self:showOtherCards(false)
  216. -- 清空玩家时钟
  217. for _,v in pairs(self._playerNodes) do
  218. v:setTurn(false)
  219. end
  220. self._resultMsg = nil
  221. self:showRstComfirm(false)
  222. end
  223. function PdkRoomView:getMode()
  224. if app.room:getRoomInfo().nMaxPlayCount == 2 then
  225. return 0
  226. elseif app.room:getRoomInfo().nMaxPlayCount == 3 then
  227. return 1
  228. end
  229. return 1
  230. end
  231. function PdkRoomView:initUi()
  232. self.ui.Items.btnMenu:registerClick(handler(self , self.onClickButtonMenu))
  233. self.ui.Items.Button_Leave:registerClick(handler(self , self.onClickButtonLeave))
  234. self.ui.Items.Button_Dismiss:registerClick(handler(self , self.onClickButtonDismiss))
  235. self.ui.Items.Button_Set:registerClick(handler(self , self.onClickButtonSetting))
  236. -- self.ui.Items.Button_updateLog:registerClick(handler(self , self.onClickButtonUlog))
  237. self.ui.Items.Button_Ready:registerClick(handler(self , self.onClickButtonReady))
  238. self.ui.Items.Button_Ready.oPos = self.ui.Items.Button_Ready:getPosition()
  239. self.ui.Items.Button_invite:registerClick(handler(self , self.onClickButtonInvite))
  240. self.ui.Items.Button_invite.oPos = self.ui.Items.Button_invite:getPosition()
  241. self.ui.Items.Layout_7:registerClick(handler(self , self.onClickMenuOut))
  242. self.ui.Items.Button_rule:registerClick(handler(self, self.onClickButtonDetails))
  243. self.ui.Items.Button_Copy:registerClick(handler(self, self.onClickCopy))
  244. -- self.ui.Items.btnDetail:registerClick(handler(self , self.onClickButtonDetails))
  245. self.ui.Items.Button_tip:registerClick(handler(self , self.onClickButtonTip))
  246. self.ui.Items.Button_out:registerClick(handler(self , self.onClickButtonOut))
  247. self.ui.Items.Button_not_out:registerClick(handler(self , self.onClickButtonNotOut))
  248. --邀请俱乐部成员
  249. self.ui.Items.Button_Invite_Club:registerClick(handler(self , self.onClickInviteClub))
  250. -- self.ui.Items.btnShot:registerClick(handler(self , self.onClickButtonShot))
  251. -- 小局结算展示按钮
  252. self._btnComfirm = self.ui.Items.Button_RstComfirm
  253. self._btnComfirm:registerClick(handler(self , self.onClickButtonRstComfirm))
  254. self:showRstComfirm(false)
  255. self.ui.Items.imgTip:setVisible(false)
  256. self.ui.Items.imgTip:setOpacity(0)
  257. self.ui.Items.imgTip:setLocalZOrder(200)
  258. self.ui.Items.btnShowClub:registerClick(handler(self , self.onClickButtonShowClub))
  259. if app.club_php.clubID and app.club_php.clubID~=0 then
  260. self.ui.Items.btnShowClub:setVisible(true)
  261. self.ui.Items.Button_Invite_Club:setVisible(true)
  262. else
  263. self.ui.Items.btnShowClub:setVisible(false)
  264. self.ui.Items.Button_Invite_Club:setVisible(false)
  265. end
  266. local roomInfo = app.room:getRoomInfo()
  267. --快速开始按钮
  268. self.ui.Items.Button_fastStart:registerClick(handler(self, self.onClickFastStart))
  269. if roomInfo.nGameStartCount and roomInfo.nGameStartCount <= 0 then
  270. --游戏未开始
  271. self:showFastStart(true)
  272. else
  273. self:showFastStart(false)
  274. end
  275. --添加玩家节点
  276. local players = app.room:getPlayers()
  277. for _, info in pairs(players) do
  278. self:addPlayerNode( info )
  279. end
  280. --
  281. local myself = app.room:getMyself()
  282. if myself.playFlag>=1 then
  283. self:showSitdownBtn(false)
  284. else
  285. self:showSitdownBtn(true)
  286. end
  287. -- 水印
  288. --[[local gameInfo = roomInfo.nGameInfo
  289. local data = json.decode(gameInfo)
  290. local logostr = ""
  291. if tonumber(data.gamerule) == PdkDef.GameTypes.Normal then
  292. logostr = "pdk_img_logo_jingdian.png"
  293. else
  294. logostr = "pdk_img_logo_swz.png"
  295. end
  296. self.ui.Items.ImageView_logo:loadTexture(logostr, 1)--]]
  297. self:initLogo(1)
  298. if not isReviewVersion() and self.gpsComponent then
  299. --self.gpsComponent:updateUserInfos(app.room:getUserInfoList())
  300. end
  301. self.ui.Items.Button_invite:setVisible(app.room:getPlayerNum() ~= roomInfo.nMaxPlayCount)
  302. self:updateButtonPosition()
  303. --
  304. if not self.LeavePos then
  305. self.LeavePos = self.ui.Items.Button_Leave:getPosition()
  306. self.DisbandPos = self.ui.Items.Button_Dismiss:getPosition()
  307. self.SettingPos = self.ui.Items.Button_Set:getPosition()
  308. self.RulePos = self.ui.Items.Button_rule:getPosition()
  309. end
  310. -- self:showMenu(false, true)
  311. self.ui.Items.Layout_Rule:setVisible(false)
  312. self.ui.Items.Layout_7:setVisible(false)
  313. self.ui.Items.Text_Rule:setVisible(false)
  314. --self.ui.Items.btnMenu:setVisible(false)
  315. self.ui.Items.Layout_Menu_1:setVisible(false)
  316. self.ui.Items.Layout_Menu_1:setLocalZOrder(199)
  317. if roomInfo.nGameStartCount and roomInfo.nGameStartCount > 0 then
  318. self.ui.Items.Layout_Rule:setVisible(false)
  319. else
  320. self.ui.Items.Layout_Rule:setVisible(true)
  321. self.ui.Items.Button_rule:setVisible(false)
  322. self.ui.Items.Layout_7:setVisible(true)
  323. self.ui.Items.Layout_Rule:runAction(cc.Sequence:create(
  324. cc.DelayTime:create(2),
  325. cc.CallFunc:create(function()
  326. self.ui.Items.Layout_Rule:setVisible(false)
  327. self.ui.Items.Button_rule:setVisible(true)
  328. end)))
  329. end
  330. local bar = self.ui.Items.ListView:getVBar()
  331. -- bar:setPositionX(220)
  332. bar:setVisible(false)
  333. end
  334. function PdkRoomView:onClickInviteClub()
  335. playBtnEffect()
  336. if app.club_php.clubID and app.club_php.clubID ~= 0 then
  337. local roomInfo = app.room:getRoomInfo()
  338. local strInvite = PdkRoomViewConfig.getSimpleInviteStr(app.gameId, roomInfo)
  339. local view = import("luaScript.Views.Club.ClubInvite"):new(roomInfo.nTableId, strInvite)
  340. view:setAnchorPoint(cc.p(0.5, 0.5))
  341. app:showWaitDialog(view)
  342. end
  343. end
  344. -- 弹出小结算展示按钮
  345. function PdkRoomView:showRstComfirm( is )
  346. self._btnComfirm:setVisible(is==true)
  347. end
  348. -- 设置房间信息
  349. function PdkRoomView:setRoomInfo( info )
  350. self.ui.Items.roomNum:setString(string.format("房号: %06d", info.nTableId))
  351. self.ui.Items.Label_JuShu:setString(string.format("%02d/%02d局", info.nGameStartCount or 0, info.nTotalGameNum or 0))
  352. --设置规则信息
  353. -- local ruleInfo = json.decode(info.nGameInfo)
  354. --房间规则不会中途变化,不用多次更新
  355. if not self.isHadupdateRule then
  356. self.isHadupdateRule = true
  357. else
  358. return
  359. end
  360. self.ui.Items.ListView:removeAllChildren()
  361. self.ui.Items.ListView:setAutoSize(true)
  362. local rules = PdkRoomViewConfig.getWanfaTab(info.nGameInfo)
  363. for k,v in pairs(rules) do
  364. local text = self.ui.Items.Text_Rule:getCopied()
  365. text:setVisible(true)
  366. text:setString(v)
  367. self.ui.Items.ListView:addChild(text)
  368. end
  369. end
  370. --[[更新房间局数信息--]]
  371. function PdkRoomView:updateRoomInfo(startCount, totalCount)
  372. local roomInfo = app.room:getRoomInfo()
  373. roomInfo.nGameStartCount = startCount
  374. roomInfo.nTotalGameNum = totalCount
  375. end
  376. -- 显示操作按钮
  377. function PdkRoomView:showTurnBtn( is, isShowPass )
  378. --获取开房参数
  379. local roomInfo = app.room:getRoomInfo()
  380. local gameInfo = roomInfo.nGameInfo or ""
  381. local ruleInfo = json.decode(gameInfo)
  382. --是否选择了AAA可为炸弹
  383. local isChoiceAAA = false
  384. --是否选择了3必带2
  385. local isChoice3dai2 = false
  386. if ruleInfo and ruleInfo.specialRule and getNumBand(ruleInfo.specialRule, 0x0080)>0 then
  387. isChoiceAAA = true
  388. end
  389. if ruleInfo and ruleInfo.specialRule and getNumBand(ruleInfo.specialRule, 0x0200)>0 then
  390. isChoice3dai2 = true
  391. end
  392. if is then--倒计时 --最后一手牌
  393. local cards = self:getHandCards()
  394. local ttp = PokerUtil:checkType(cards)
  395. if (ttp==ETS.THREE_AND_ONE or ttp==ETS.THREE) and (not isChoice3dai2) then--归并3带2
  396. ttp = ETS.THREE_AND_TWO
  397. end
  398. local function __delay( onEnd )
  399. self.ui:runDelay(1, function() if onEnd and type(onEnd)=='function' then onEnd() end end)
  400. end
  401. local function __lastOut(onEnd)
  402. self:resetSelect()
  403. app.room:requestOutCards(cards)
  404. if onEnd and type(onEnd)=='function' then onEnd() end
  405. end
  406. local bombs = PokerUtil:getAllBomb(cards, isChoiceAAA)--有炸弹就不自动打出去
  407. if self._lastOutType==ttp then
  408. if ttp==ETS.LIAN_DUI or ttp==ETS.SHUN_ZI then--最后一手牌顺子连对保证牌数相等
  409. if #self._lastCards==#cards then
  410. self:addFunction(__lastOut)
  411. return
  412. end
  413. elseif ttp==ETS.AIRPLANE and #bombs <= 0 then--最后一手飞机校验
  414. if #self._lastCards>=#cards then
  415. self:addFunction(__lastOut)
  416. return
  417. end
  418. else--防止炸弹拆开成3带2打出去
  419. if self._lastCards~=ETS.BOMB then
  420. local bombs = PokerUtil:getAllBomb(cards, isChoiceAAA)--有炸弹就不自动打出去
  421. if #self._lastCards>=#cards and #bombs<=0 then
  422. self:addFunction(__lastOut)
  423. return
  424. end
  425. else
  426. if #self._lastCards>=#cards then
  427. self:addFunction(__lastOut)
  428. return
  429. end
  430. end
  431. end
  432. elseif self._lastOutType==0 then
  433. local can, handCards = self:checkOnceOut()
  434. if can then
  435. self:addFunction(__delay)
  436. self:addFunction(__lastOut)
  437. return
  438. end
  439. end
  440. else
  441. -- showTooltip("---------------------------------showBtn false")
  442. end
  443. --是否选择了可不要
  444. if ruleInfo and ruleInfo.allowPass and ruleInfo.allowPass == 1 then
  445. --开房参数设置为可不要时,才显示不要按钮
  446. self.ui.Items.Layout_not_out:setVisible(true)
  447. self.ui.Items.Button_not_out:setVisible(is==true)
  448. if not self.errorOut then--出牌错误的情况下,不改变不出按钮的状态
  449. if isShowPass ~= nil and isShowPass == false then
  450. --针对每一局开始发完牌后,庄家不能操作不要按钮
  451. self.ui.Items.Button_not_out:setBright(false)
  452. else
  453. self.ui.Items.Button_not_out:setBright(true)
  454. end
  455. else
  456. self.errorOut = nil
  457. end
  458. else
  459. self.ui.Items.Layout_not_out:setVisible(false)
  460. end
  461. --解散按钮状态
  462. if roomInfo.nGameStartCount == 0 and not app.room:isMyself(roomInfo.nRoomOwnedUid) then
  463. --未开始,且自己不是房主,则解散按钮不可点击
  464. self.ui.Items.Button_Dismiss:setEnabled(false)
  465. else
  466. self.ui.Items.Button_Dismiss:setEnabled(true)
  467. end
  468. self:checkCanDismiss()
  469. self.ui.Items.Layout_operating_menus:requestDoLayout()
  470. self.ui.Items.Layout_operating_menus:doLayout()
  471. self.ui.Items.Button_tip:setVisible(is==true)
  472. self.ui.Items.Button_out:setVisible(is==true)
  473. -- 自动提示
  474. if self._lastOutType>0 and is then
  475. local cards = self._lastCards
  476. if cards and #cards>0 then
  477. local handCards = self:getHandCards()
  478. local result = PokerUtil:getTip(handCards, cards)
  479. if result and #result > 0 then
  480. --local result2 = PokerUtil:getOnlyTip(handCards, cards)
  481. --if result2 then --有且只有一种提示 自动弹出牌
  482. -- self:tipCards(clone(result2))
  483. --end
  484. else
  485. result = {}
  486. end
  487. -- 计算不能出的牌
  488. local canotOuts = {}
  489. local tp = self._lastOutType
  490. if tp == ETS.SINGLE_CARD then
  491. local bombs = PokerUtil:getAllBomb(handCards, isChoiceAAA)
  492. for _,v in pairs(bombs) do table.insert(result, 1, v) end
  493. canotOuts = PokerUtil:leftSingleCards(handCards, result)
  494. elseif tp == ETS.DUI_ZI or tp == ETS.SHUN_ZI or tp == ETS.LIAN_DUI or tp == ETS.THREE_AND_TWO
  495. or tp == ETS.FOUR_AND_THREE or tp == ETS.AIRPLANE then
  496. local bombs = PokerUtil:getAllBomb(handCards, isChoiceAAA)
  497. for _,v in pairs(bombs) do table.insert(result, 1, v) end
  498. if tp == ETS.DUI_ZI or tp == ETS.SHUN_ZI or tp == ETS.LIAN_DUI then --飞机带的牌可以随意
  499. canotOuts = PokerUtil:leftCardsEx(handCards, result)
  500. end
  501. elseif tp == ETS.BOMB then
  502. end
  503. if #canotOuts>0 then
  504. self:downCanotOuts(canotOuts, true)
  505. end
  506. if result and #result > 0 then
  507. local result2 = PokerUtil:getOnlyTip(handCards, cards)
  508. if result2 then --有且只有一种提示 自动弹出牌
  509. self:tipCards(clone(result2[1].cid and result2 or result2[1]))
  510. end
  511. end
  512. end
  513. end
  514. end
  515. function PdkRoomView:showMenu( is, flag )
  516. -- self.ui.Items.btnMenu.show = is==true
  517. -- if flag then
  518. -- self.panelMenu:setVisible(is==true)
  519. -- return
  520. -- end
  521. -- if is==true then
  522. -- self.panelMenu:setVisible(is==true)
  523. -- local actime = 0.08
  524. -- local leavAc = { cc.Spawn:create(cc.MoveTo:create(actime, self.LeavePos), cc.FadeIn:create(actime)) }
  525. -- local disbandAc = { cc.Spawn:create(cc.MoveTo:create(actime, self.DisbandPos), cc.FadeIn:create(actime)) }
  526. -- local settingAc = { cc.Spawn:create(cc.MoveTo:create(actime, self.SettingPos), cc.FadeIn:create(actime)) }
  527. -- local uplogAc = {cc.Spawn:create(cc.MoveTo:create(actime, self.RulePos), cc.FadeIn:create(actime)) }
  528. -- self.ui.Items.Button_Leave:runAction(cc.Sequence:create(leavAc))
  529. -- self.ui.Items.Button_Dismiss:runAction(cc.Sequence:create(disbandAc))
  530. -- self.ui.Items.Button_Set:runAction(cc.Sequence:create(settingAc))
  531. -- self.ui.Items.Button_rule:runAction(cc.Sequence:create(uplogAc))
  532. -- else
  533. -- local oPos = self.ui.Items.btnMenu:getPosition()
  534. -- local actime = 0.08
  535. -- local leavAc = cc.MoveTo:create(actime, oPos)
  536. -- self.ui.Items.Button_Leave:runAction(cc.Spawn:create(leavAc:clone(), cc.FadeOut:create(actime)))
  537. -- self.ui.Items.Button_Dismiss:runAction(cc.Spawn:create(leavAc:clone(), cc.FadeOut:create(actime)))
  538. -- self.ui.Items.Button_Set:runAction(cc.Spawn:create(leavAc:clone(), cc.FadeOut:create(actime)))
  539. -- self.ui.Items.Button_rule:runAction(cc.Sequence:create(cc.Spawn:create(leavAc:clone(), cc.FadeOut:create(actime)), cc.CallFunc:create(function() self.panelMenu:setVisible(is==true) end)))
  540. -- end
  541. end
  542. -- 是否显示准备按钮
  543. function PdkRoomView:showSitdownBtn( is )
  544. if self._isGameOver and true == self._isGameOver then return end
  545. self.ui.Items.Button_Ready:setVisible(is == true)
  546. local playerNum = app.room:getPlayerNum()
  547. if playerNum ~= app.room:getRoomInfo().nMaxPlayCount then--房间人数未满
  548. self.ui.Items.Button_invite:setVisible(true)
  549. -- local invitePos = self.ui.Items.Button_invite:getPosition()
  550. -- if is then
  551. -- self.ui.Items.Button_invite:runAction(cc.MoveTo:create(0.2, self.ui.Items.Button_invite.oPos))
  552. -- self.ui.Items.Button_Ready:runAction(cc.MoveTo:create(0.2, self.ui.Items.Button_Ready.oPos))
  553. -- else
  554. -- if invitePos.x < 10 then
  555. -- self.ui.Items.Button_invite:stopAllActions()
  556. -- self.ui.Items.Button_invite:setPosition(self.ui.Items.Button_invite.oPos)
  557. -- self.ui.Items.Button_invite:runAction(cc.MoveTo:create(0.2, cc.p(10, invitePos.y)))
  558. -- end
  559. -- end
  560. else
  561. -- local readyPos = self.ui.Items.Button_Ready:getPosition()
  562. -- self.ui.Items.Button_Ready:stopAllActions()
  563. -- self.ui.Items.Button_Ready:runAction(cc.MoveTo:create(0.2, cc.p(10, readyPos.y)))
  564. end
  565. self:updateInviteClubButton()
  566. self:updateButtonPosition()
  567. end
  568. function PdkRoomView:updateButtonPosition()
  569. self.ui.Items.Button_Ready:getParent():setVisible(self.ui.Items.Button_Ready:isVisible())
  570. self.ui.Items.Button_invite:getParent():setVisible(self.ui.Items.Button_invite:isVisible())
  571. self.ui.Items.Button_Invite_Club:getParent():setVisible(self.ui.Items.Button_Invite_Club:isVisible())
  572. local roomInfo = app.room.roomInfo or {}
  573. local gameId = roomInfo.gameId or app.gameId
  574. local gameConfig = getSubGameConfig(gameId)
  575. if gameConfig.isOpenClubInvite == false then
  576. self.ui.Items.Button_Invite_Club:getParent():setVisible(false)
  577. end
  578. if isReviewVersion() then
  579. self.ui.Items.Button_invite:getParent():setVisible(false)
  580. self.ui.Items.Button_Invite_Club:getParent():setVisible(false)
  581. end
  582. self.ui.Items.Layout_Button:requestDoLayout()
  583. self.ui.Items.Layout_Button:doLayout()
  584. end
  585. function PdkRoomView:onClickButtonShowClub( sender )
  586. playBtnEffect()
  587. if IS_USER_NEW_CLUB then
  588. openClub()
  589. else
  590. local clubList = app.club_php.clubList
  591. if clubList and table.nums(clubList) > 0 then
  592. --房间号
  593. local roomInfo = app.room:getRoomInfo()
  594. if roomInfo then
  595. --创建房间时传入的桌子下标
  596. local infoT = json.decode(roomInfo.nGameInfo)
  597. self.clubView = import("luaScript.Views.Club.ClubTable"):new(clubList[app.club_php.clubID], infoT.tableIdx)
  598. self.clubView:setAnchorPoint(cc.p(0.5, 0.5))
  599. app:showWaitDialog(self.clubView)
  600. end
  601. else
  602. --未找到茶馆列表数据时,请求茶馆列表(可能是断线重连)
  603. app.club_php:getClubList();
  604. end
  605. end
  606. end
  607. function PdkRoomView:onClickButtonRstComfirm( sender )
  608. playBtnEffect()
  609. -- 小结算
  610. local showFunc = function (msg)
  611. for _,node in pairs(self._playerNodes) do
  612. node:cleanScore()
  613. end
  614. if msg then
  615. local view = import("pk_paodekuai.luaScript.Views.Room.Sub.PdkGameResultView"):new(msg)
  616. view:setAnchorPoint(cc.p(0.5, 0.5))
  617. app:showWaitDialog(view)
  618. end
  619. end
  620. showFunc(self._resultMsg)
  621. end
  622. -- 三人玩打开GPS
  623. --[[function PdkRoomView:onClickButtonGps( sender )
  624. playBtnEffect()
  625. local isStart = app.room:getRoomInfo().nGameStartCount>0
  626. local exitFunc = function ()
  627. local isStart = app.room:getRoomInfo().nGameStartCount>0
  628. if isStart then
  629. app.room:requestDismissRoom(1)--发起解散
  630. else
  631. self.ui:sendMsg(app.room, "callLeaveRequest")--离开房间
  632. end
  633. end
  634. local dismissFunc = function ()
  635. app.room:requestDismissRoom(1)--发起解散
  636. end
  637. -- self.gpsComponent:showGpsView(app.room:getRoomInfo().nMaxPlayCount, isStart, exitFunc, dismissFunc)
  638. local playerlist = app.room:getUserInfoList()
  639. if not isReviewVersion() and self.gpsComponent then
  640. self.gpsComponent:updateUserInfos(playerlist)
  641. self.gpsComponent:showGpsView(3, isStart, exitFunc, exitFunc)
  642. end
  643. end--]]
  644. -- 显示GPS界面
  645. function PdkRoomView:showGpsView()
  646. if self.isRecordScene then return end--回放场景直接return
  647. logD("PdkRoomView:showGpsView()")
  648. playBtnEffect()
  649. local isGameStart = app.room:getRoomInfo().nGameStartCount > 0
  650. if self.gpsComponent then
  651. self.gpsComponent:showGpsView(isGameStart)
  652. end
  653. end
  654. -- 玩家点击房间详情
  655. function PdkRoomView:onClickButtonDetails( sender )
  656. playBtnEffect()
  657. self.ui.Items.Layout_Rule:setVisible(not self.ui.Items.Layout_Rule:isVisible())
  658. self.ui.Items.Layout_7:setVisible(self.ui.Items.Layout_Rule:isVisible())
  659. self.ui.Items.Button_rule:setVisible(not self.ui.Items.Layout_Rule:isVisible())
  660. -- self:showMenu(false, true)
  661. -- local view = import("pk_paodekuai.luaScript.Views.Room.Sub.PdkGameDetailView"):new(app.room:getRoomInfo().nGameInfo)
  662. -- view:setAnchorPoint(cc.p(0.5, 0.5))
  663. -- app:showWaitDialog(view)
  664. end
  665. -- 一键截屏
  666. function PdkRoomView:onClickButtonShot( sender )
  667. playBtnEffect()
  668. showScreenShot()
  669. end
  670. function PdkRoomView:onClickButtonMenu( sender )
  671. playBtnEffect()
  672. --self:showMenu(not sender.show)
  673. self.ui.Items.Layout_Menu_1:setVisible(not self.ui.Items.Layout_Menu_1:isVisible())
  674. self.ui.Items.Layout_7:setVisible(self.ui.Items.Layout_Menu_1:isVisible())
  675. end
  676. function PdkRoomView:onClickMenuOut( sender )
  677. -- self:showMenu(false)
  678. self.ui.Items.Layout_Rule:setVisible(false)
  679. self.ui.Items.Layout_7:setVisible(false)
  680. self.ui.Items.Layout_Menu_1:setVisible(false)
  681. self.ui.Items.Button_rule:setVisible(true)
  682. end
  683. function PdkRoomView:onClickButtonLeave( sender )
  684. playBtnEffect()
  685. self:showMenu(false, true)
  686. self.ui:sendMsg(app.room, "callLeaveRequest")
  687. end
  688. function PdkRoomView:onClickButtonDismiss( sender )
  689. playBtnEffect()
  690. local function onClickOk()
  691. self:showMenu(false, true)
  692. app.room:requestDismissRoom(1)--发起解散
  693. end
  694. local function onClickCancel()
  695. end
  696. showConfirmDialog("确定要申请解散房间吗?", onClickOk, onClickCancel)
  697. end
  698. function PdkRoomView:onClickButtonSetting( sender )
  699. playBtnEffect()
  700. self:showMenu(false, true)
  701. local view = import("pk_paodekuai.luaScript.Views.Room.Sub.PdkSettingView"):new()
  702. view:setAnchorPoint(cc.p(0.5, 0.5))
  703. app:showWaitDialog(view)
  704. end
  705. function PdkRoomView:onClickButtonUlog( sender )
  706. playBtnEffect()
  707. self:showMenu(false, true)
  708. local view = import("luaScript.Views.Room.UplogView"):new()
  709. view:setAnchorPoint(cc.p(0.5, 0.5))
  710. app:showWaitDialog(view)
  711. end
  712. function PdkRoomView:onClickButtonTip( sender, tag, tipShow )
  713. playBtnEffect()
  714. --获取开房参数
  715. local roomInfo = app.room:getRoomInfo()
  716. local gameInfo = roomInfo.nGameInfo or ""
  717. local ruleInfo = json.decode(gameInfo)
  718. --是否选择了AAA可为炸弹
  719. local isChoiceAAA = false
  720. if ruleInfo and ruleInfo.specialRule and getNumBand(ruleInfo.specialRule, 0x0080)>0 then
  721. isChoiceAAA = true
  722. end
  723. --出牌提示
  724. local cards = self._lastCards
  725. if cards and #cards>0 then
  726. local tp = PokerUtil:checkType(cards)
  727. if tp >= ETS.NONE then
  728. return nil
  729. end
  730. -- showTooltip("提示牌型: " .. PokerUtil:getTypeString(tp))
  731. local handCards = self:getHandCards()
  732. if #handCards<=0 then return false end
  733. if tp == ETS.SINGLE_CARD then
  734. if sender._tipCards and #sender._tipCards>0 then
  735. local tmp = sender._tipCards[#sender._tipCards]
  736. if tmp[1] and type(tmp[1])=='table' then
  737. self:tipCards(clone(tmp))
  738. else
  739. self:tipCards({clone(tmp)})
  740. end
  741. table.remove(sender._tipCards, #sender._tipCards)
  742. if #sender._tipCards <= 0 then
  743. sender._tipCards = nil
  744. end
  745. else
  746. local result = PokerUtil:getTip(handCards, cards)
  747. if result and #result > 0 then else result = {} end
  748. -- 判断下家是否报单
  749. local node = self:getPlayerNodeVpos(2)
  750. if node then
  751. if node:isAlarm() then
  752. local max = result[1]
  753. for _,v in ipairs(result) do
  754. if v.val > max.val then
  755. max = v
  756. end
  757. end
  758. result = {max}
  759. end
  760. end
  761. local bombs = PokerUtil:getAllBomb(handCards, isChoiceAAA)
  762. local cds = {}
  763. for _,v in pairs(bombs) do
  764. table.insert(result, 1, v)
  765. end
  766. if #result <= 0 then return end
  767. sender._tipCards = clone(result)
  768. local tmp = sender._tipCards[#sender._tipCards]
  769. if tag then
  770. if #result>=1 then
  771. if tmp[1] and type(tmp[1])=='table' then
  772. self:tipCards(clone(tmp))
  773. else
  774. self:tipCards({clone(tmp)})
  775. end
  776. table.remove(sender._tipCards, #sender._tipCards)
  777. end
  778. else
  779. if tmp[1] and type(tmp[1])=='table' then
  780. self:tipCards(clone(tmp))
  781. else
  782. self:tipCards({clone(tmp)})
  783. end
  784. table.remove(sender._tipCards, #sender._tipCards)
  785. end
  786. end
  787. elseif tp == ETS.DUI_ZI or tp == ETS.SHUN_ZI or tp == ETS.LIAN_DUI or tp == ETS.THREE_AND_TWO
  788. or tp == ETS.FOUR_AND_THREE or tp == ETS.AIRPLANE then
  789. if sender._tipCards and #sender._tipCards>0 then
  790. self:tipCards(clone(sender._tipCards[#sender._tipCards]))
  791. table.remove(sender._tipCards, #sender._tipCards)
  792. if #sender._tipCards <= 0 then sender._tipCards = nil end
  793. else
  794. local result = PokerUtil:getTip(handCards, cards)
  795. if result and #result > 0 then else result = {} end
  796. local bombs = PokerUtil:getAllBomb(handCards, isChoiceAAA)
  797. for _,v in pairs(bombs) do table.insert(result, 1, v) end
  798. if #result <= 0 then return end
  799. sender._tipCards = clone(result)
  800. if tag then
  801. if #result >= 1 then
  802. self:tipCards(clone(sender._tipCards[#sender._tipCards]))
  803. table.remove(sender._tipCards, #sender._tipCards)
  804. end
  805. else
  806. self:tipCards(clone(sender._tipCards[#sender._tipCards]))
  807. table.remove(sender._tipCards, #sender._tipCards)
  808. end
  809. end
  810. elseif tp == ETS.BOMB then
  811. if sender._tipCards and #sender._tipCards>0 then
  812. self:tipCards(clone(sender._tipCards[#sender._tipCards]))
  813. table.remove(sender._tipCards, #sender._tipCards)
  814. if #sender._tipCards <= 0 then sender._tipCards = nil end
  815. else
  816. local result = PokerUtil:getTip(handCards, cards)
  817. if result and #result > 0 then else return end
  818. sender._tipCards = clone(result)
  819. if tag then
  820. if #result >= 1 then
  821. self:tipCards(clone(sender._tipCards[#sender._tipCards]))
  822. table.remove(sender._tipCards, #sender._tipCards)
  823. end
  824. else
  825. self:tipCards(clone(sender._tipCards[#sender._tipCards]))
  826. table.remove(sender._tipCards, #sender._tipCards)
  827. end
  828. end
  829. else
  830. return nil
  831. end
  832. else--没有牌,第一手提示
  833. local handCards = self:getHandCards()
  834. if sender._tipCards and #sender._tipCards>0 then
  835. self:tipCards(clone(sender._tipCards[#sender._tipCards]))
  836. table.remove(sender._tipCards, #sender._tipCards)
  837. if #sender._tipCards <= 0 then sender._tipCards = nil end
  838. else
  839. local result = PokerUtil:getFirstTip(handCards)
  840. if result and #result > 0 then else return end
  841. sender._tipCards = clone(result)
  842. self:tipCards(clone(sender._tipCards[#sender._tipCards]))
  843. table.remove(sender._tipCards, #sender._tipCards)
  844. end
  845. end
  846. end
  847. -- 变暗不能出的牌
  848. function PdkRoomView:downCanotOuts(canotOuts, isTouch)
  849. for _,v in pairs(canotOuts) do
  850. local node = self:getCardNode(v)
  851. if node then
  852. node:setNormal()
  853. node:setNormalColor()
  854. node:setNoTouch(isTouch)
  855. end
  856. end
  857. local tmp = {}
  858. for _,v in pairs(self._selectCards) do
  859. if v:isDown() then
  860. table.insert(tmp, v)
  861. end
  862. end
  863. self._selectCards = tmp
  864. end
  865. --出牌
  866. function PdkRoomView:onClickButtonOut( sender )
  867. playBtnEffect()
  868. local cards = self:getSelected()
  869. if #cards <= 0 then
  870. return showTooltip("请选择要出的牌")
  871. else
  872. local isThreeA = false
  873. local tp = PokerUtil:checkType(cards)
  874. local gameInfo = app.room:getRoomInfo().nGameInfo or ""
  875. local ruleInfo = json.decode(gameInfo)
  876. --是否选择了AAA为炸弹
  877. if ruleInfo.specialRule and getNumBand(ruleInfo.specialRule, 0x0080) > 0 then
  878. if PokerUtil:isAAA(cards) then
  879. tp = ETS.BOMB
  880. isThreeA = true
  881. end
  882. end
  883. if tp >=100 then
  884. return showTooltip("选择的牌型错误")
  885. end
  886. if self._lastCards and #self._lastCards>0 then
  887. self._lastOutType = PokerUtil:checkType(self._lastCards)
  888. end
  889. --检测炸弹是否可拆(不可拆要做检测)
  890. if not self.ruleIsChaiBomb then
  891. if PokerUtil:isChaiBombs(self:getHandCards(), cards) then
  892. return showTooltip("炸弹不可拆开")
  893. end
  894. end
  895. if not isThreeA and (tp == ETS.THREE_AND_ONE or tp == ETS.THREE) then--归并三带二
  896. tp = ETS.THREE_AND_TWO
  897. end
  898. if self._lastOutType==tp or self._lastOutType==0 or tp==ETS.BOMB then
  899. -- 检测下家是否报单
  900. --获取自己的座位数据
  901. local myself = app.room:getMyself()
  902. local pdata = app.room:getPlayerVpos(myself.viewPos)
  903. logD("PdkRoomView:onClickButtonOut pdata = "..table.tostring(pdata))
  904. local node = self:getPlayerNode(pdata.userId)
  905. local isAlarm = node:isAlarm()
  906. if isAlarm and #cards==1 and tp==ETS.SINGLE_CARD then
  907. -- 判断是否是最大单张
  908. if PokerUtil:isMaxCard(self:getHandCards(), cards[1]) then
  909. app.room:requestOutCards(cards)
  910. else
  911. return showTooltip("报单必须出最大牌")
  912. end
  913. else
  914. if self._lastOutType==ETS.SHUN_ZI and tp==ETS.SHUN_ZI and #self._lastCards~=#cards then--限制顺子牌张数
  915. return showTooltip("顺子牌张数错误")
  916. end
  917. -- 判断顺子的大小
  918. if self._lastCards==ETS.SHUN_ZI then
  919. pokerSortPdkCards(cards)
  920. local _, minVal = pokerParse(self._lastCards[1])
  921. if cards[1].val <= minVal then
  922. return showTooltip("出牌选择错误")
  923. end
  924. end
  925. app.room:requestOutCards(cards)
  926. end
  927. else
  928. return showTooltip("选择的牌型错误")
  929. end
  930. end
  931. end
  932. function PdkRoomView:onClickButtonNotOut( sender )
  933. local cards = {}
  934. app.room:requestOutCards(cards)
  935. end
  936. function PdkRoomView:onClickButtonReady( sender )
  937. playBtnEffect()
  938. self.ui:sendMsg(app.room, "callReadyRequestPdk")
  939. end
  940. function PdkRoomView:getInviteData()
  941. local strNames = ""
  942. local index = 0
  943. local num = app.room:getPlayerNum()
  944. for k,v in pairs(app.room:getPlayers()) do
  945. index = index + 1
  946. local name = getSubStringNickname(v.nickname)
  947. strNames = strNames..name
  948. if index < num then strNames = strNames.."," end
  949. end
  950. local roomInfo = app.room:getRoomInfo()
  951. local invitePtr = PdkRoomViewConfig.InviteConfig[roomInfo.nMaxPlayCount][num]--几缺几
  952. local strGameMode = PdkRoomViewConfig.getRuleString(roomInfo.nGameInfo)
  953. local strGameNum = string.format("%s局", roomInfo.nTotalGameNum)
  954. local desc = string.format("%s,%s 玩家:%s", strGameNum, strGameMode, strNames)
  955. print("pdk_invite : ",desc)
  956. local title = string.format("经典跑得快 房号[%s] %s", roomInfo.nTableId, invitePtr )
  957. if app.club_php.clubID and app.club_php.clubID~=0 then
  958. title = string.format("%s %sID[%d]", title,(app.club_php:getCestIsOpen(app.club_php.clubID) and PLN.CLUB_CEST_NAME or PLN.CLUB_NAME), tonumber(app.club_php.clubID))
  959. end
  960. print("pdk_invite : ", title)
  961. return title,desc
  962. end
  963. --邀请好友
  964. function PdkRoomView:onClickButtonInvite( sender )
  965. playBtnEffect()
  966. --[[local strNames = ""
  967. local index = 0
  968. local num = app.room:getPlayerNum()
  969. for k,v in pairs(app.room:getPlayers()) do
  970. index = index + 1
  971. local name = getSubStringNickname(v.nickname)
  972. strNames = strNames..name
  973. if index < num then strNames = strNames.."," end
  974. end
  975. local roomInfo = app.room:getRoomInfo()
  976. local invitePtr = PdkRoomViewConfig.InviteConfig[roomInfo.nMaxPlayCount][num]--几缺几
  977. local strGameMode = PdkRoomViewConfig.getRuleString(roomInfo.nGameInfo)
  978. local strGameNum = string.format("%s局", roomInfo.nTotalGameNum)
  979. local desc = string.format("%s,%s 玩家:%s", strGameNum, strGameMode, strNames)
  980. print("pdk_invite : ",desc)
  981. local title = string.format("欢乐跑得快 房号[%s] %s", roomInfo.nTableId, invitePtr )
  982. if app.club_php.clubID and app.club_php.clubID~=0 then
  983. title = string.format("%s 茶馆ID[%d]", title, tonumber(app.club_php.clubID))
  984. end
  985. print("pdk_invite : ", title)--]]
  986. local title,desc = self:getInviteData()
  987. local imagePath = cc.FileUtils:getInstance():getWritablePath().."icon.png"
  988. --[[ local info = {}
  989. info.scene = "talk"
  990. info.contentType = "url"
  991. info.url = app.config.Setting.appDownloadUrl
  992. info.title = title
  993. info.description = desc
  994. info.image = imagePath
  995. info.imageWidth = 100
  996. app.plugin:shareGame(info)--]]
  997. local info = {}
  998. info.title = title
  999. info.description = desc
  1000. info.copyData={type=2}
  1001. local view = import("luaScript.Views.Main.ShareView"):new(info)
  1002. view:setAnchorPoint(cc.p(0.5, 0.5))
  1003. app:showWaitDialog(view)
  1004. end
  1005. function PdkRoomView:onClickCopy()
  1006. playBtnEffect()
  1007. local title,desc = self:getInviteData()
  1008. local clubData = ""
  1009. if app.club_php.clubID and app.club_php.clubID ~= 0 then
  1010. local clubName = ""
  1011. local clubList = app.club_php.clubList
  1012. if clubList and table.nums(clubList) > 0 then
  1013. clubName = clubList[tonumber(app.club_php.clubID)].clubName;
  1014. end
  1015. clubData = string.format((app.club_php:getCestIsOpen(app.club_php.clubID) and PLN.CLUB_CEST_NAME or PLN.CLUB_NAME).."名:%s \n", clubName)
  1016. end
  1017. local tishi = "复制信息打开游戏将自动入座\n<仅供娱乐,严禁赌博>"
  1018. copyData = string.format("%s%s\n%s\n%s",clubData,title,desc,tishi)
  1019. logD(copyData)
  1020. copyStringToClipboard(copyData)
  1021. app.plugin:gotoWeiXin()
  1022. end
  1023. -- 恢复自己手牌
  1024. function PdkRoomView:recoverHandcards(_cards)
  1025. self:cleanSelfCards()
  1026. local cards = pokerSortPdkCards(_cards)
  1027. local pos = 1
  1028. local allCount = #cards
  1029. for i,card in ipairs(cards) do
  1030. self:sendOneCardNoAct(card.cid, i, pos, i==allCount, allCount)
  1031. end
  1032. self:resetCardsPos()
  1033. end
  1034. function PdkRoomView:onPdkResponseGameRecover( data )
  1035. local roomInfo = app.room:getRoomInfo()
  1036. if roomInfo.recoverItem then
  1037. local recoverData = roomInfo.recoverItem
  1038. self:recover(recoverData)
  1039. self._passGameResult = nil
  1040. end
  1041. end
  1042. function PdkRoomView:updateInviteClubButton()
  1043. if app.club_php.clubID and app.club_php.clubID~=0 then
  1044. local roomInfo = app.room:getRoomInfo()
  1045. if roomInfo.nGameStartCount==0 and table.nums(roomInfo.memberList)<roomInfo.nMaxPlayCount then
  1046. self.ui.Items.Button_Invite_Club:setVisible(true)
  1047. else
  1048. self.ui.Items.Button_Invite_Club:setVisible(false)
  1049. end
  1050. local roomInfo = app.room.roomInfo or {}
  1051. local gameId = roomInfo.gameId or app.gameId
  1052. local gameConfig = getSubGameConfig(gameId)
  1053. if gameConfig.isOpenClubInvite == false then
  1054. self.ui.Items.Button_Invite_Club:getParent():setVisible(false)
  1055. end
  1056. if isReviewVersion() then
  1057. self.ui.Items.Button_invite:getParent():setVisible(false)
  1058. self.ui.Items.Button_Invite_Club:getParent():setVisible(false)
  1059. end
  1060. end
  1061. end
  1062. --断线恢复
  1063. function PdkRoomView:recover( data , connect)
  1064. connect = connect or false
  1065. local roomInfo = app.room:getRoomInfo()
  1066. --self:checkGpsDistance(nil,roomInfo.nGameStartCount==0)
  1067. --self:checkMyGpsNeedUpdate();
  1068. -- 当前操作玩家
  1069. local curOpUserId = -1
  1070. local tmpData = {}
  1071. local outCount = 0--一手牌都没打的玩家数
  1072. local cardNum = 0--桌面上牌组数量
  1073. for _,pdata in ipairs(data) do
  1074. tmpData[pdata.userId] = pdata
  1075. local player = app.room:getPlayer(pdata.userId)
  1076. local node = self:getPlayerNode(pdata.userId)
  1077. if not node then
  1078. self:addPlayerNode(player)
  1079. else
  1080. pdata.totalScore = tonumber(pdata.totalScore)
  1081. node:setScoreNoAnim(pdata.totalScore)
  1082. node:setBanker(pdata.seatId==roomInfo.reBankerId)
  1083. node:setOffline(pdata.onlineStatus==0)
  1084. node:setOfflineTime(pdata.onlineStatus==0,pdata.offtime or 0)
  1085. node:setReady(pdata.playFlag==1)
  1086. end
  1087. if pdata.isCanOp==1 then
  1088. curOpUserId = pdata.userId
  1089. end
  1090. if app.room:getRuleCardsNum()==#pdata.handCards then outCount = outCount + 1 end
  1091. if #pdata.outCards>0 then cardNum = cardNum + 1 end
  1092. end
  1093. self:resetRoundData()
  1094. self:updateInviteClubButton()
  1095. -- 托管状态
  1096. for k,v in pairs(data or {}) do
  1097. local entrustType = v.isAi;--托管状态 1-托管中 0-未托管
  1098. local nUserID = v.userId;
  1099. local viewId = app.room:getViewIdByUserId(nUserID)
  1100. local isTuoGuan = entrustType == 1;
  1101. if app.room:isMyself(nUserID) then
  1102. if isTuoGuan then
  1103. self:showTuoGuan(true)
  1104. self.isTuoGuan = true
  1105. else
  1106. self:showTuoGuan(false)
  1107. self.isTuoGuan = false
  1108. end
  1109. end
  1110. local node = self:getPlayerNodeVpos(viewId)
  1111. if node then
  1112. node:setTuoGuan(isTuoGuan)
  1113. end
  1114. end
  1115. if roomInfo.gameStatus == PdkRoomViewConfig.GameStatus.GAME_STATE_INIT then
  1116. for _,pdata in ipairs(data) do
  1117. local player = app.room:getPlayer(pdata.userId)
  1118. local node = self:getPlayerNode(pdata.userId)
  1119. if app.room:isMyself(pdata.userId) then
  1120. self:showTurnBtn(false)--能否出牌
  1121. self:showSitdownBtn(pdata.playFlag~=1 and pdata.playFlag~=2)
  1122. end
  1123. end
  1124. --清理离线后的玩家
  1125. local players = app.room:getPlayers()
  1126. for k,v in pairs(self._playerNodes) do
  1127. local is = false
  1128. for _,pd in pairs(players) do
  1129. if pd.userId == tonumber(k) then
  1130. is = true
  1131. break
  1132. end
  1133. end
  1134. if not is then self:delPlayerNode(tonumber(k)) end
  1135. end
  1136. if app.room.isReconnection == true then
  1137. self:isShowFastStartView()
  1138. end
  1139. self:showFastStart(true)
  1140. elseif roomInfo.gameStatus == PdkRoomViewConfig.GameStatus.GAME_STATE_SEND_HAND_CARD
  1141. or roomInfo.gameStatus == PdkRoomViewConfig.GameStatus.GAME_STATE_OUT_CARD then
  1142. -- 清除上一次的提示牌
  1143. self.ui.Items.Button_tip._tipCards = nil
  1144. -- 离开房间不可点击
  1145. self.ui.Items.Button_Leave:setEnabled(false)
  1146. local cp = app.room:getPlayer(curOpUserId)
  1147. local preCid = app.room:getPreSeatId(cp.seatId)
  1148. self._lastCards = {}
  1149. self._lastOutPos = 0
  1150. self._lastOutType = 0
  1151. local lastOutPlayer = nil
  1152. while cp.seatId ~= preCid do
  1153. local d = app.room:getPlayerCid(preCid)
  1154. if d then
  1155. local tmp = tmpData[d.userId]
  1156. if tmp and #tmp.outCards>0 then
  1157. self._lastCards = tmp.outCards
  1158. self._lastOutType = PokerUtil:checkType(tmp.outCards)
  1159. self._lastOutPos = d.viewPos
  1160. lastOutPlayer = d
  1161. break
  1162. end
  1163. end
  1164. preCid = app.room:getPreSeatId(preCid)
  1165. end
  1166. for _,pdata in ipairs(data) do
  1167. local player = app.room:getPlayer(pdata.userId)
  1168. self:clearPosShow(player.viewPos)
  1169. local node = self:getPlayerNode(pdata.userId)
  1170. if app.room:isMyself(pdata.userId) then
  1171. if not connect then self:recoverHandcards(pdata.handCards) end
  1172. if node then node:showLeft(#pdata.handCards) end
  1173. else
  1174. if node then
  1175. node:showLeft(#pdata.handCards)
  1176. node:setOffline(pdata.onlineStatus==0)
  1177. node:setOfflineTime(pdata.onlineStatus==0,pdata.offtime or 0)
  1178. end
  1179. end
  1180. if node then
  1181. node:setTurn(pdata.isCanOp==1, 0)
  1182. node:setScore(pdata.totalScore)
  1183. node:setBanker(pdata.seatId==roomInfo.reBankerId)
  1184. end
  1185. local player = app.room:getPlayer(pdata.userId)
  1186. if #pdata.outCards > 0 then--显示最后一手牌
  1187. if app.room:isMyself(pdata.userId) and pdata.isCanOp==1 then
  1188. else
  1189. node:setLastOp(PokerUtil:checkType(pdata.outCards), pdata.outCards)
  1190. end
  1191. else
  1192. -- 判断是否一次牌都没出过
  1193. if app.room.roomInfo.nMaxPlayCount == outCount or (app.room:isMyself(pdata.userId) and pdata.isCanOp==1) or (pdata.isCanOp==1) then
  1194. else
  1195. if pdata.passShow then
  1196. node:setLastOp(ETS.PASS, {})
  1197. end
  1198. end
  1199. end
  1200. if pdata.isCanOp == 1 and cardNum==app.room.roomInfo.nMaxPlayCount then
  1201. node:cleanLastCards()
  1202. end
  1203. end
  1204. local isShowPass = false
  1205. --发牌后,还未出牌,判断当前可操作玩家id是否为自己
  1206. if app.room:isMyself(roomInfo.curOpUid) then
  1207. --当前操作玩家操作类型 0-pass 1-可以出牌也可以pass 2-只能出牌
  1208. if roomInfo.curOpType == 1 then
  1209. isShowPass = true
  1210. end
  1211. end
  1212. for _,pdata in ipairs(data) do
  1213. if roomInfo.gameStatus == PdkRoomViewConfig.GameStatus.GAME_STATE_SEND_HAND_CARD then--发牌庄家出牌
  1214. if app.room:isMyself(pdata.userId) then
  1215. self:showTurnBtn(pdata.seatId==roomInfo.reBankerId, isShowPass)
  1216. end
  1217. local node = self:getPlayerNode(pdata.userId)
  1218. if node and pdata.seatId==roomInfo.reBankerId then
  1219. node:setTurn(true, 0)
  1220. else
  1221. node:setTurn(false)
  1222. end
  1223. else--游戏中途
  1224. if app.room:isMyself(pdata.userId) then
  1225. self:showTurnBtn(pdata.isCanOp==1, isShowPass)--能否出牌
  1226. end
  1227. end
  1228. end
  1229. self:showSitdownBtn(false)
  1230. if self:getMode()==0 then
  1231. self:showOtherCards(true)
  1232. end
  1233. --游戏中不显示2/3人快速开始按钮
  1234. self:showFastStart(false)
  1235. elseif roomInfo.gameStatus == PdkRoomViewConfig.GameStatus.GAME_STATE_ROUND_OVER then--需要判断是否已经有单局结算页面
  1236. self.ui.Items.Button_Leave:setEnabled(false)
  1237. local response = {}
  1238. response.gameStartCount = roomInfo.nGameStartCount
  1239. response.totalGamenum = roomInfo.nTotalGameNum
  1240. response.bankSeatId = roomInfo.reBankerId
  1241. local players = {}
  1242. for i,v in ipairs(data) do
  1243. local p = {}
  1244. p.userId = v.userId
  1245. p.turnScore = v.turnScore
  1246. p.totalScore = v.totalScore
  1247. p.bombTimes = v.turnBombTimes--单局炸弹数
  1248. p.haveRedTen = v.haveRedTen
  1249. p.bSpring = v.bSpring
  1250. p.leftNum = #v.handCards
  1251. table.insert(players, p)
  1252. local player = app.room:getPlayer(p.userId)
  1253. local playerNode = self:getPlayerNode(player.userId)
  1254. if #v.outCards > 0 and player and playerNode then
  1255. playerNode:showLastCards(v.outCards, PokerUtil:checkType(v.outCards))
  1256. end
  1257. if #v.handCards>0 and player then
  1258. self:showLeftCards(player.viewPos, v.handCards or {})
  1259. end
  1260. end
  1261. response.players = players
  1262. response.leftCards = {}
  1263. self:showGameResultRecover({response=response})
  1264. --游戏中不显示2/3人快速开始按钮
  1265. self:showFastStart(false)
  1266. if self:getMode()==0 then
  1267. self:showOtherCards(true)
  1268. end
  1269. elseif roomInfo.gameStatus == PdkRoomViewConfig.GameStatus.GAME_STATE_GAME_OVER then
  1270. local response = {}
  1271. local players = {}
  1272. for i,v in ipairs(data) do
  1273. local p = {}
  1274. p.userId = v.userId
  1275. p.totalScore = v.totalScore
  1276. --"extString" = "{"bombTimes":0,"loseTimes":0,"maxScore":3,"winTimes":2}"
  1277. local extString = ""
  1278. local d = {}
  1279. d.bombTimes = v.totalBombTimes--总炸弹数
  1280. d.loseTimes = v.loseTimes
  1281. d.maxScore = v.maxScore
  1282. d.winTimes = v.winTimes
  1283. p.extString = json.encode(d)
  1284. table.insert(players, p)
  1285. end
  1286. response.players = players
  1287. self:onResponseGameOver({response=response})
  1288. local quickStartInfo = app.room.roomInfo.quickStartInfo
  1289. if quickStartInfo then
  1290. if quickStartInfo.tablefaststate == true then
  1291. local tmpInfo = {}
  1292. for uid,status in pairs(quickStartInfo.list) do
  1293. table.insert(tmpInfo, {nUserId=tonumber(uid), nStatus = status})
  1294. end
  1295. local response = {}
  1296. response.pList = tmpInfo
  1297. response.timeOut = app.room.roomInfo.quickStartInfo.time
  1298. self:onBroadcastFaststart({response=response})
  1299. else
  1300. self:showFastStart(true)
  1301. end
  1302. else
  1303. self:showFastStart(true)
  1304. end
  1305. end
  1306. if roomInfo.bUserDisbandGame == 1 then --房间是否是解散状态
  1307. app.room:dispatchEvent({name = "pdkNormalEvent_show_dissmiss_over"})
  1308. -- 其他玩家的解散状态
  1309. local dismissInfo = {}
  1310. local list = {}
  1311. for i,v in ipairs(data) do
  1312. dismissInfo[v.userId] = v.disbandStatus
  1313. local l = {}
  1314. l.nUserId = v.userId
  1315. l.dismissState = v.disbandStatus
  1316. table.insert(list, l)
  1317. end
  1318. app.room.dismissInfo = dismissInfo
  1319. local response = {}
  1320. response.memberList = list
  1321. response.timeLeft = roomInfo.leftTimeOut
  1322. response.operateType = 1
  1323. self:onDismissResponse({response=response})
  1324. end
  1325. if roomInfo.gameStatus > PdkRoomViewConfig.GameStatus.GAME_STATE_INIT and roomInfo.gameStatus <= PdkRoomViewConfig.GameStatus.GAME_STATE_GAME_OVER then
  1326. self.ui.Items.Button_invite:setVisible(false)
  1327. else
  1328. self.ui.Items.Button_invite:setVisible(app.room:getPlayerNum()~=app.room:getRoomInfo().nMaxPlayCount)
  1329. end
  1330. self:updateButtonPosition()
  1331. ----------------------------------------------------------------------------------------
  1332. roomInfo.recoverItem = nil
  1333. roomInfo.reBankerId = nil
  1334. end
  1335. -- 小局结算
  1336. function PdkRoomView:showGameResultRecover( data )
  1337. -- if self._gameResult then return false end--避免断线重连弹出多个小结算
  1338. local msg = data.response
  1339. local maxCards = 0
  1340. for _,v in pairs(msg.players) do
  1341. local node = self:getPlayerNode(v.userId)
  1342. v.totalScore = tonumber(v.totalScore)
  1343. if node then node:setScore(v.totalScore,false) end
  1344. node:hideLeft()
  1345. v.leftCards = v.leftCards or {}
  1346. if #v.leftCards > maxCards then maxCards = #v.leftCards end
  1347. local pdata = app.room:getPlayer(v.userId)
  1348. v.unionid = pdata.unionid
  1349. v.headimgurl = pdata.headimgurl
  1350. v.gpsInfo = pdata.gpsInfo
  1351. v.sex = pdata.sex
  1352. v.openid = pdata.openid
  1353. v.nickname = pdata.nickname
  1354. v.areano = pdata.areano
  1355. end
  1356. --是不是最后一局
  1357. local roomInfo = app.room:getRoomInfo()
  1358. msg.isLast = roomInfo.nGameStartCount==roomInfo.nTotalGameNum
  1359. msg.isZhaniao = self.ruleZhaniao
  1360. msg.ruleString = PdkRoomViewConfig.getRuleString(roomInfo.nGameInfo)
  1361. self._resultMsg = {}
  1362. self._resultMsg.players = msg.players
  1363. self._resultMsg.isLast = msg.isLast
  1364. self._resultMsg.isZhaniao = msg.isZhaniao
  1365. self._resultMsg.ruleString = msg.ruleString
  1366. self._resultMsg.gameStartCount = msg.gameStartCount
  1367. self._resultMsg.totalGamenum = msg.totalGamenum
  1368. -- -- 小结算
  1369. local showFunc = function ()
  1370. for _,v in pairs(self._playerNodes) do
  1371. v:hideLeft()
  1372. end
  1373. self:showRstComfirm(true)
  1374. end
  1375. self._gameResult = true
  1376. --中途恢复直接展示
  1377. -- showLeftFunc()
  1378. showFunc()
  1379. end
  1380. function PdkRoomView:bindEvents()
  1381. self:bindEvent(app.room , "onUserExitResponseRoom" , handler(self , self.onUserExitResponseRoom))
  1382. --onDismissResponse
  1383. self:bindEvent(app.room , "onDismissResponse" , handler(self , self.onDismissResponse))
  1384. -- 其他玩家进入房间
  1385. self:bindEvent(app.room , "onResponseBroadcastLogin" , handler(self , self.onResponseBroadcastLogin))
  1386. -- 玩家离开房间
  1387. self:bindEvent(app.room , "onResponseBroadcastLogout" , handler(self , self.onResponseBroadcastLogout))
  1388. -- 玩家准备
  1389. self:bindEvent(app.room , "onResponseUserReady" , handler(self , self.onResponseUserReady))
  1390. -- 游戏开始
  1391. self:bindEvent(app.room , "onResponseGameStart" , handler(self , self.onResponseGameStart))
  1392. -- 给玩家发牌
  1393. self:bindEvent(app.room , "onResponseSendCards" , handler(self , self.onResponseSendCards))
  1394. -- 玩家出牌成功
  1395. self:bindEvent(app.room , "onResponseOutCards" , handler(self , self.onResponseOutCards))
  1396. -- 玩家出牌错误
  1397. self:bindEvent(app.room , "onResponseOutCardsErr" , handler(self , self.onResponseOutCardsErr))
  1398. -- 单局结算
  1399. self:bindEvent(app.room , "onResponseGameResult" , handler(self , self.onResponseGameResult))
  1400. -- 总结算
  1401. self:bindEvent(app.room , "onResponseGameOver" , handler(self , self.onResponseGameOver))
  1402. -- 玩家离线
  1403. self:bindEvent(app.room , "onOtherDroppedResponse" , handler(self , self.onOtherDroppedResponse))
  1404. -- 游戏设置里更换桌面
  1405. self:bindEvent(app.room , "pdkNormalEvent_changeDesktop" , handler(self , self.onNormalChangeDesktop))
  1406. -- 服务器通知更新当前玩家分数
  1407. self:bindEvent(app.room , "onResponseUpdateScore" , handler(self , self.onResponseUpdateScore))
  1408. -- 服务器通知当前玩家轮次
  1409. self:bindEvent(app.room , "onResponseUpdateTurns" , handler(self , self.onResponseUpdateTurns))
  1410. -- 显示大结算
  1411. self:bindEvent(app.room , "pdkNormalEvent_show_game_over" , handler(self , self.onNormalShowGameOver))
  1412. -- 断线重连
  1413. self:bindEvent(app.room , "onResponseGameRecover" , handler(self , self.onPdkResponseGameRecover))
  1414. -- 玩家请求快速开始广播
  1415. self:bindEvent(app.room , "onBroadcastFastRequest", handler(self, self.onBroadcastFaststart))
  1416. -- 快速开始成功
  1417. self:bindEvent(app.room , "onFastStartSucc", handler(self, self.onFastStartSucc))
  1418. --监听从后台进入游戏事件
  1419. self:bindEvent(app, "applicationWillEnterForeground", handler(self, self.onApplicationWillEnterForeground))
  1420. -- 玩家的GPS信息发生变化
  1421. self:bindEvent(app.room , "onGpsChangeResponse" , handler(self , self.onGpsChangeResponse));
  1422. --托管结果
  1423. self:bindEvent(app.room , "onTuoGuanResponse",handler(self , self.onTuoGuanResponse));
  1424. end
  1425. function PdkRoomView:onNormalChangeDesktop( data )
  1426. if data.idx >5 and data.idx<1 then return end
  1427. self.ui.Items.ImageView_bg:loadTexture(string.format("pk_paodekuai/res/ui/zy_game/zy_pdk_gamebg_%d.jpg", data.idx), 0)
  1428. -- self.ui.Items.ImageView_2:setVisible(data.idx~=3)
  1429. -- self.ui.Items.ImageView_3:setVisible(data.idx~=3)
  1430. -- 水印
  1431. --[[local gameInfo = app.room:getRoomInfo().nGameInfo
  1432. local rdata = json.decode(gameInfo)
  1433. local logostr = ""
  1434. local logoJingDian = {
  1435. [1] = "pdk_img_logo_jdhuang.png",
  1436. [2] = "pdk_img_logo_jdlv.png",
  1437. [3] = "pdk_img_logo_jdlan.png",
  1438. [4] = "pdk_img_logo_jdhong.png",
  1439. }
  1440. local logoShiWu = {
  1441. [1] = "pdk_img_logo_15huang.png",
  1442. [2] = "pdk_img_logo_15lv.png",
  1443. [3] = "pdk_img_logo_15lan.png",
  1444. [4] = "pdk_img_logo_15hong.png",
  1445. }
  1446. if tonumber(rdata.gamerule) == PdkDef.GameTypes.Normal then
  1447. logostr = logoJingDian[data.idx]--(data.idx==1 or data.idx==2 ) and "pdk_img_logo_jingdian_3d.png" or "pdk_img_logo_jingdian.png"
  1448. else
  1449. logostr = logoShiWu[data.idx]--(data.idx==1 or data.idx==2 ) and "pdk_img_logo_swz_3d.png" or "pdk_img_logo_swz.png"
  1450. end
  1451. self.ui.Items.ImageView_logo:loadTexture(logostr, 1)--]]
  1452. self:initLogo(data.idx)
  1453. end
  1454. -- 水印
  1455. function PdkRoomView:initLogo(idx)
  1456. if not (type(getSubGameRoomLogo) == 'function') then--大厅不支持此方法,则隐藏logo
  1457. self.ui.Items.ImageView_logo:setVisible(false);
  1458. return
  1459. end
  1460. local gameInfo = app.room:getRoomInfo().nGameInfo
  1461. local rdata = json.decode(gameInfo)
  1462. local logofile = getSubGameRoomLogo(GAME_IDS.PaoDeKuai,tonumber(rdata.gamerule))
  1463. if logofile then
  1464. self.ui.Items.ImageView_logo:loadTexture(logofile)
  1465. self.ui.Items.ImageView_logo:setVisible(true);
  1466. else
  1467. self.ui.Items.ImageView_logo:setVisible(false);
  1468. end
  1469. end
  1470. -- 服务器通知玩家分数
  1471. function PdkRoomView:onResponseUpdateScore( data )
  1472. local msg = data.response
  1473. for _,pdata in ipairs(msg.players) do
  1474. local node = self:getPlayerNode(pdata.userId)
  1475. if node then node:setScore(pdata.totalScore) end
  1476. end
  1477. end
  1478. -- 玩家掉线
  1479. function PdkRoomView:onOtherDroppedResponse( data )
  1480. local msg = data.response
  1481. local node = self:getPlayerNode(msg.nUserId)
  1482. local pdata = app.room:getPlayer(msg.nUserId)
  1483. if node then
  1484. if msg.nDroppedStatus == 1 then
  1485. node:setOffline(true)
  1486. node:setOfflineTime(true,0)
  1487. pdata.onlineStatus = 0
  1488. elseif msg.nDroppedStatus == 0 then
  1489. node:setOfflineTime(false)
  1490. node:setOffline(false)
  1491. pdata.onlineStatus = 1
  1492. end
  1493. end
  1494. end
  1495. function PdkRoomView:onUserExitResponseRoom( data )
  1496. local function _exit( onEnd )
  1497. local response = data.response -- 0: 不退出(回到子游戏), 1: 退出(回到大厅)
  1498. if not self._isGameOver then
  1499. if response.logoutFlag == 1 then
  1500. --app:gotoView(import("luaScript.Views.Main.MainView"):new(GAME_IDS.PaoDeKuai))
  1501. gotoMainView(GAME_IDS.PaoDeKuai)
  1502. else
  1503. --app:gotoView(import("luaScript.Views.Main.MainView"):new(GAME_IDS.PaoDeKuai))
  1504. gotoMainView(GAME_IDS.PaoDeKuai)
  1505. end
  1506. end
  1507. if onEnd and type(onEnd)=='function' then onEnd() end
  1508. end
  1509. self:addFunction(_exit)
  1510. end
  1511. function PdkRoomView:onDismissResponse( data )
  1512. local __dis = function (onEnd)
  1513. local response = data.response
  1514. app.room:getRoomInfo().nDismissStateTime = response.timeLeft --剩余时间
  1515. app.room:getRoomInfo().nDismissToTalTime = app.room:getRoomInfo().nDisbandTimeout or 60 --总的时间
  1516. --显示解散(此标志会影响闹钟时间会冻住)
  1517. app.room:getRoomInfo().nShowDismiss = true
  1518. if response.operateType == 1 then
  1519. if response.memberList ~= nil then
  1520. for k,v in pairs(response.memberList) do
  1521. if v.dismissState == 1 then
  1522. --local view = import("pk_paodekuai.luaScript.Views.Room.Sub.PdkDismissView"):new(v.nUserId)
  1523. local view = require("luaScript.Views.Room.RoomDismissView"):new(v.nUserId,app.room.roomInfo.memberList,response.timeLeft)
  1524. view:setAnchorPoint(cc.p(0.5, 0.5))
  1525. app:showWaitDialog(view)
  1526. return
  1527. end
  1528. end
  1529. else
  1530. --local view = import("pk_paodekuai.luaScript.Views.Room.Sub.PdkDismissView"):new(response.nUserId)
  1531. local view = require("luaScript.Views.Room.RoomDismissView"):new(response.nUserId,app.room.roomInfo.memberList,response.timeLeft)
  1532. view:setAnchorPoint(cc.p(0.5, 0.5))
  1533. app:showWaitDialog(view)
  1534. end
  1535. else
  1536. local memberStatus={}
  1537. if response.memberList ~= nil then
  1538. for k,v in pairs(response.memberList) do
  1539. table.insert(memberStatus,{userId = v.nUserId, status = v.dismissState})
  1540. end
  1541. else
  1542. table.insert(memberStatus,{userId = response.nUserId, status = response.operateType})
  1543. end
  1544. app.room:dispatchEvent({name = GAME_EVENT.DISSMISS_UPDATE_STATUS , memberStatus = memberStatus});
  1545. end
  1546. end
  1547. __dis()
  1548. end
  1549. -- 其他玩家进入
  1550. function PdkRoomView:onResponseBroadcastLogin( data )
  1551. self:addPlayerNode(data.pInfo)
  1552. self.ui.Items.Button_invite:setVisible(app.room:getPlayerNum()~=app.room:getRoomInfo().nMaxPlayCount)
  1553. self:updateButtonPosition()
  1554. if not isReviewVersion() and self.gpsComponent then
  1555. --self.gpsComponent:updateUserInfos(app.room:getUserInfoList())
  1556. --self:checkGpsDistance(data.pInfo.userId,true)
  1557. end
  1558. local myself = app.room:getMyself()
  1559. if myself.playFlag>=1 then
  1560. self:showSitdownBtn(false)
  1561. else
  1562. self:showSitdownBtn(true)
  1563. end
  1564. self:showFastStart(true)
  1565. end
  1566. -- 玩家离开房间
  1567. function PdkRoomView:onResponseBroadcastLogout( data )
  1568. local function __logout( onEnd )
  1569. self:showFastStart(true)
  1570. self:delPlayerNode(data.userId)
  1571. local myself = app.room:getMyself()
  1572. if myself.playFlag>=1 then
  1573. self:showSitdownBtn(false)
  1574. else
  1575. self:showSitdownBtn(true)
  1576. end
  1577. --[[local roomInfo = app.room:getRoomInfo()
  1578. if roomInfo and roomInfo.nGameStartCount == 0 then
  1579. if not isReviewVersion() and self.gpsComponent then
  1580. self.gpsComponent:updateUserInfos(app.room:getUserInfoList())
  1581. self:checkGpsDistance()
  1582. end
  1583. end--]]
  1584. if onEnd and type(onEnd)=='function' then onEnd() end
  1585. end
  1586. self:addFunction(__logout)
  1587. end
  1588. -- 玩家准备
  1589. function PdkRoomView:onResponseUserReady( data )
  1590. local userId = data.userId
  1591. local node = self:getPlayerNode(userId)
  1592. if node then node:setReady(true) end
  1593. if app.room:isMyself(userId) then
  1594. self:resetRoundData()
  1595. app.room:addPlayer({playFlag=1, userId=userId})
  1596. self:showSitdownBtn(false)
  1597. end
  1598. end
  1599. -- 游戏开始
  1600. function PdkRoomView:onResponseGameStart( data )
  1601. local function __start( onEnd )
  1602. local roomInfo = app.room:getRoomInfo()
  1603. if roomInfo.nGameStartCount and roomInfo.nGameStartCount == 0 then
  1604. self:onUpdatePlayerPos(data)
  1605. end
  1606. self._gameResult = false
  1607. self._passGameResult = nil
  1608. -- 离开房间不可点击
  1609. self.ui.Items.Button_Leave:setEnabled(false)
  1610. -- 取消玩家的准备标志
  1611. for _,node in pairs(self._playerNodes) do
  1612. node:setReady(false)
  1613. node:cleanScore()
  1614. app.room:updateFlag( node:getInfo().userId, 2 )
  1615. end
  1616. self:cleanSelfCards()
  1617. self:cleanShowCards()
  1618. self.ui.Items.Button_Ready:setVisible(false)
  1619. self.ui.Items.Button_invite:setVisible(false)
  1620. self:updateButtonPosition()
  1621. self:updateInviteClubButton()
  1622. --
  1623. self:showTurnBtn(false)
  1624. self:updateRoomInfo(roomInfo.nGameStartCount, roomInfo.nTotalGameNum)
  1625. if onEnd and type(onEnd)=='function' then onEnd() end
  1626. end
  1627. self:addFunction(__start)
  1628. end
  1629. --更新玩家位置
  1630. function PdkRoomView:onUpdatePlayerPos( data )
  1631. if not data then return end
  1632. local response = data.response
  1633. if not response then return end
  1634. -- 更新椅子号
  1635. for _,v in pairs(response.players) do
  1636. app.room:addPlayer({userId = v.nUserId, seatId = v.nSeatId})
  1637. end
  1638. -- 更新视图ID
  1639. for _,v in pairs(response.players) do
  1640. app.room:addPlayer({userId = v.nUserId, viewPos = app.room:transPos(v.nSeatId)})
  1641. end
  1642. --刷新房间玩家位置
  1643. if response then
  1644. --删除所有玩家节点
  1645. for k,v in pairs(response.players) do
  1646. self:delPlayerNode(v.nUserId)
  1647. end
  1648. self:initChatView()
  1649. --重新添加玩家节点
  1650. local players = app.room:getPlayers()
  1651. for _, info in pairs(players) do
  1652. self:addPlayerNode( info )
  1653. end
  1654. end
  1655. end
  1656. -- 给玩家发牌
  1657. function PdkRoomView:onResponseSendCards( data )
  1658. self:setRoomInfo(app.room:getRoomInfo())
  1659. local function __sendCards( onEnd )
  1660. self:resetRoundData()
  1661. self._gameResult = false
  1662. self._passGameResult = nil
  1663. self:sendCards(data.response.cards)
  1664. if onEnd and type(onEnd) == 'function' then onEnd() end
  1665. end
  1666. self:addFunction(__sendCards)
  1667. local function __delay( onEnd )
  1668. self.ui:runDelay(1, function() if onEnd and type(onEnd)=='function' then onEnd() end end)
  1669. end
  1670. self:addFunction(__delay)
  1671. local function __setBanker( onEnd )
  1672. local bankerData = app.room:getPlayerCid(data.response.bankerSeat)
  1673. if bankerData then
  1674. for _,v in pairs( self._playerNodes ) do
  1675. v:setBanker(v:getInfo().userId==bankerData.userId)
  1676. v:setTurn(false)
  1677. end
  1678. end
  1679. if onEnd and type(onEnd) == 'function' then onEnd() end
  1680. end
  1681. self:addFunction(__setBanker)
  1682. local function __showTurn( onEnd )
  1683. local bankerData = app.room:getPlayerCid(data.response.bankerSeat)
  1684. if app.room:isMyself(bankerData.userId) then
  1685. --发完牌后庄家为自己,则不能操作不要按钮
  1686. local isShowPass = false
  1687. self:showTurnBtn(true,isShowPass)
  1688. local node = self:getPlayerNodeVpos(1)
  1689. if node then node:setTurn(true) end
  1690. else
  1691. self:showTurnBtn(false)
  1692. local node = self:getPlayerNode(bankerData.userId)
  1693. if node then node:setTurn(true) end
  1694. end
  1695. if onEnd and type(onEnd) == 'function' then onEnd() end
  1696. end
  1697. self:addFunction(__showTurn)
  1698. local function __showLeft( onEnd )
  1699. local left = 16
  1700. if self.ruleType==2 then left = 15 end
  1701. for uid,v in pairs(self._playerNodes) do
  1702. v:showLeft(left)
  1703. end
  1704. if onEnd and type(onEnd) == 'function' then onEnd() end
  1705. end
  1706. self:addFunction(__showLeft)
  1707. end
  1708. -- 显示轮次时钟
  1709. function PdkRoomView:showTurns( viewPos, cleanCards )
  1710. for _,node in pairs(self._playerNodes) do
  1711. local is = node:getInfo().viewPos==viewPos
  1712. node:setTurn(is)
  1713. -- if cleanCards==nil then cleanCards = true end
  1714. if cleanCards then self:clearPosShow(viewPos) end
  1715. if is then node:cleanPass() end
  1716. end
  1717. end
  1718. -- 广播当前桌子轮次@userId@seatId@outFlag
  1719. function PdkRoomView:onResponseUpdateTurns( data )
  1720. local function __updateTurns( onEnd )
  1721. local msg = data.response
  1722. self.lastOutFlag = msg.outFlag
  1723. local viewPos = app.room:transPos(msg.seatId)
  1724. if viewPos == 1 then
  1725. self:showTurns(viewPos, viewPos==1)
  1726. else--这个逻辑过了1天god知道是干什么的
  1727. local node = self:getPlayerNodeVpos(1)
  1728. self:showTurns(viewPos, node:isShowPass()==false ) --如果要得起显示对方出的牌
  1729. -- if self._lastOutPos == viewPos then --新起一轮
  1730. -- self:showTurns(viewPos, false)
  1731. -- else
  1732. -- self:showTurns(viewPos, self._lastOutPos ~= viewPos)
  1733. -- end
  1734. end
  1735. if onEnd and type(onEnd)=='function' then onEnd() end
  1736. end
  1737. self:addFunction(__updateTurns)
  1738. local function __showOp( onEnd )
  1739. local msg = data.response
  1740. local viewPos = app.room:transPos(msg.seatId)
  1741. local node = self:getPlayerNode(msg.userId)
  1742. local delay = 0
  1743. if msg.outFlag == 0 then--pass
  1744. delay = 0.5
  1745. local function _op()
  1746. if viewPos == 1 then
  1747. self:showPass()
  1748. self:cleanLastCards(false)
  1749. else
  1750. end
  1751. node:setLastOp(ETS.PASS, {})
  1752. self:showTurnBtn(false)
  1753. end
  1754. -- self.ui:runDelay(0, _op)--不需要延时,同时显示出来?
  1755. _op()
  1756. else--show op
  1757. local isShowPass = false
  1758. if viewPos == 1 then--自己能出牌
  1759. if msg.opType == 2 then--开启新的一轮
  1760. self:cleanLastCards()
  1761. self.lastOutFlag = -1
  1762. end
  1763. self:clearPosShow(1)
  1764. --操作类型 0-只能pass 1-可以出牌也可以pass 2-必须出牌
  1765. if msg.opType == 1 then
  1766. isShowPass = true
  1767. end
  1768. end
  1769. self:showTurnBtn( viewPos == 1 , isShowPass)
  1770. end
  1771. self.ui:runDelay(delay, function() if onEnd and type(onEnd)=='function' then onEnd() end end)
  1772. end
  1773. self:addFunction(__showOp)
  1774. end
  1775. -- 清理上一次的出牌
  1776. function PdkRoomView:cleanLastCards(isClean)
  1777. if isClean==nil then isClean = true end
  1778. -- if self._lastOutPos > 0 then
  1779. if isClean == true then
  1780. -- self:clearPosShow(self._lastOutPos)
  1781. end
  1782. self._lastCards = {}
  1783. self._lastOutType = 0
  1784. self._lastOutPos = 0
  1785. -- end
  1786. end
  1787. -- 玩家出牌成功
  1788. function PdkRoomView:onResponseOutCards( data )
  1789. local function __outCards( onEnd )
  1790. local msg = data.response
  1791. -- 清除上一次的提示牌
  1792. self.ui.Items.Button_tip._tipCards = nil
  1793. local isContinue = #self._lastCards>0 and self._lastOutType>0
  1794. local viewPos = app.room:getPlayer(msg.userId).viewPos
  1795. if self._lastOutPos == viewPos or self._lastOutPos == 0 then --连出两轮
  1796. for _,v in pairs(self._playerNodes) do
  1797. v:cleanPass()
  1798. end
  1799. -- 清理上一次的出牌
  1800. self:cleanLastCards()
  1801. isContinue = false
  1802. end
  1803. --操作类型,0:pass 1:接牌
  1804. if msg.opType == 1 then
  1805. -- 缓存上次出的牌
  1806. self._lastOutPos = viewPos
  1807. self._lastOutType = msg.cardType
  1808. self._lastCards = msg.cards
  1809. self._opType = msg.opType
  1810. end
  1811. self:showTurns(0)
  1812. local playerNode = self:getPlayerNode(msg.userId)
  1813. playerNode:setLastOp(msg.cardType, msg.cards, isContinue)
  1814. -- playerNode:showLastCards(msg.cards, msg.cardType, isContinue)
  1815. PdkSoundHelper:playOut()
  1816. --玩家剩余牌
  1817. local node = self:getPlayerNode(msg.userId)
  1818. if node then
  1819. if not node:isAlarm() and msg.leftNum==1 then
  1820. if self:getMode()==0 then
  1821. if node:getInfo().viewPos==2 then PdkSoundHelper:single( node:getInfo().sex ) end
  1822. elseif self:getMode()==1 then
  1823. if node:getInfo().viewPos==3 then PdkSoundHelper:single( node:getInfo().sex ) end
  1824. end
  1825. end
  1826. node:showLeft(msg.leftNum)
  1827. end
  1828. if viewPos == 1 then--判断是否自己出牌
  1829. self:showTurnBtn(false)
  1830. for _,v in pairs(msg.cards) do
  1831. self:removeCardNode(v)
  1832. end
  1833. if msg.leftNum==1 then
  1834. PdkSoundHelper:single( node:getInfo().sex )
  1835. end
  1836. --还原不可点
  1837. self:downCanotOuts(self:getHandCards(), false)
  1838. self:resetCardsPos()
  1839. end
  1840. if onEnd and type(onEnd)=='function' then onEnd() end
  1841. end
  1842. self:addFunction(__outCards)
  1843. --
  1844. local function __delay( onEnd )
  1845. self.ui:runDelay(0.5, function() if onEnd and type(onEnd)=='function' then onEnd() end end)
  1846. end
  1847. self:addFunction(__delay)
  1848. end
  1849. -- 检测手上牌能否一次打出
  1850. function PdkRoomView:checkOnceOut()
  1851. --获取开房参数
  1852. local roomInfo = app.room:getRoomInfo()
  1853. local gameInfo = roomInfo.nGameInfo
  1854. local ruleInfo = json.decode(gameInfo)
  1855. --是否选择了AAA可为炸弹
  1856. local isChoiceAAA = false
  1857. --是否选择了3必带2
  1858. local isChoice3dai2 = false
  1859. if ruleInfo and ruleInfo.specialRule and getNumBand(ruleInfo.specialRule, 0x0080)>0 then
  1860. isChoiceAAA = true
  1861. end
  1862. if ruleInfo and ruleInfo.specialRule and getNumBand(ruleInfo.specialRule, 0x0200)>0 then
  1863. isChoice3dai2 = true
  1864. end
  1865. local handCards = self:getHandCards()
  1866. local bCan, tp = PokerUtil:checkOnceOut(handCards)
  1867. if bCan then--检测是否少带接完
  1868. if tp==ETS.THREE_AND_ONE or tp==ETS.THREE then
  1869. --if not self.ruleIsNotEnough then
  1870. if isChoice3dai2 then
  1871. return false, {}
  1872. end
  1873. elseif tp==ETS.AIRPLANE then
  1874. local handCardCount = #handCards
  1875. if isChoice3dai2 and handCardCount%5 ~= 0 then
  1876. return false, {}
  1877. end
  1878. end
  1879. -- 是否拥有炸弹
  1880. local allBombs = PokerUtil:getAllBomb(handCards, isChoiceAAA)
  1881. bCan = #allBombs<=0
  1882. end
  1883. return bCan, handCards
  1884. end
  1885. -- 玩家自己显示要不起
  1886. function PdkRoomView:showPass()
  1887. self.ui.Items.imgTip:setOpacity(0)
  1888. self.ui.Items.imgTip:setVisible(true)
  1889. local ac = cc.Sequence:create(cc.FadeIn:create(0.2), cc.DelayTime:create(1), cc.FadeOut:create(0.2))
  1890. self.ui.Items.imgTip:runAction(ac)
  1891. --手牌变暗
  1892. local anFunc = function ()
  1893. self:resetSelect()
  1894. for k,v in pairs(self._selfCards) do
  1895. v:setNoTouch(true)
  1896. end
  1897. end
  1898. local mingFunc = function ()
  1899. for k,v in pairs(self._selfCards) do
  1900. v:setNoTouch(false)
  1901. end
  1902. end
  1903. local ac = cc.Sequence:create(cc.CallFunc:create(anFunc), cc.DelayTime:create(0.5), cc.CallFunc:create(mingFunc))
  1904. self.cardRoot:runAction(ac)
  1905. end
  1906. -- 春天动画
  1907. function PdkRoomView:showSpring()
  1908. local node = PdkEffectHelper:getSpring()
  1909. local winSize = cc.Director:getInstance():getWinSize()
  1910. node:setPosition(cc.p(winSize.width / 2, winSize.height / 2))
  1911. self:addChild(node)
  1912. if node.onEnter and type(node.onEnter)=='function' then
  1913. node:onEnter()
  1914. PdkSoundHelper:spring()
  1915. end
  1916. end
  1917. -- 反春天动画
  1918. function PdkRoomView:showFanSpring()
  1919. local node = PdkEffectHelper:getFanSpring()
  1920. if node then
  1921. node:setPosition(cc.p(640, 360))
  1922. self:addChild(node)
  1923. if node.onEnter and type(node.onEnter)=='function' then
  1924. node:onEnter()
  1925. PdkSoundHelper:spring()
  1926. end
  1927. end
  1928. end
  1929. -- 玩家出牌错误
  1930. function PdkRoomView:onResponseOutCardsErr( data )
  1931. local msg = data.response
  1932. if msg.errFlag == 1 and app.room:isMyself(msg.userId) then
  1933. self.errorOut = true
  1934. self:showTurnBtn(true)
  1935. end
  1936. end
  1937. -- 游戏单局结算
  1938. function PdkRoomView:onResponseGameResult( data )
  1939. -- 收到结算有动画,这个时候不让点击手牌
  1940. self:setCardsNoTouch()
  1941. local msg = data.response
  1942. local maxCards = 0
  1943. for _,v in pairs(msg.players) do
  1944. local pdata = app.room:getPlayer(v.userId)
  1945. v.unionid = pdata.unionid
  1946. v.headimgurl = pdata.headimgurl
  1947. v.gpsInfo = pdata.gpsInfo
  1948. v.sex = pdata.sex
  1949. v.openid = pdata.openid
  1950. v.nickname = pdata.nickname
  1951. v.areano = pdata.areano
  1952. end
  1953. local function __delay( onEnd )
  1954. self.ui:runDelay(0.6, function() if onEnd and type(onEnd)=='function' then onEnd() end end)
  1955. end
  1956. self:addFunction(__delay)
  1957. local function __pre( onEnd )
  1958. -- app.room:dispatchEvent({name = "pdkNormalEvent_show_dissmiss_over"})
  1959. self._gameResult = true
  1960. for _,v in pairs(msg.players) do
  1961. local node = self:getPlayerNode(v.userId)
  1962. --找到本局炸弹得分
  1963. local bombScore = 0
  1964. if msg.playersBombScore then
  1965. for i,j in pairs(msg.playersBombScore) do
  1966. if j.userId and j.userId == v.userId then
  1967. j.turnBombScore = tonumber(j.turnBombScore)
  1968. bombScore = j.turnBombScore or 0
  1969. end
  1970. end
  1971. end
  1972. if node then
  1973. node:setScore(v.totalScore, false,v.turnScore-bombScore)
  1974. node:setTurn(false)
  1975. end
  1976. node:hideLeft()
  1977. v.leftCards = v.leftCards or {}
  1978. if #v.leftCards > maxCards then
  1979. maxCards = #v.leftCards
  1980. end
  1981. end
  1982. local isSpring = false
  1983. local isFanSpring = false
  1984. for _,v in pairs(msg.players) do
  1985. local node = self:getPlayerNode(v.userId)
  1986. self:cleanSelfCards()
  1987. self:showLeftCards(node:getInfo().viewPos, v.leftCards or {})
  1988. if v.bSpring==1 then
  1989. isSpring = true
  1990. end
  1991. if v.bSpring==2 then
  1992. isFanSpring = true
  1993. end
  1994. end
  1995. local delay = maxCards *0.02+0.5
  1996. if isSpring then
  1997. self.ui:runDelay(0.1, function() self:showSpring() end)
  1998. elseif isFanSpring then
  1999. self.ui:runDelay(0.1, function() self:showFanSpring() end)
  2000. end
  2001. local function __onEnd()
  2002. if onEnd and type(onEnd)=='function' then onEnd() end
  2003. end
  2004. self.ui:runDelay(delay, __onEnd )
  2005. end
  2006. self:addFunction(__pre)
  2007. local function __showResult( onEnd )
  2008. local msg = data.response
  2009. --是不是最后一局
  2010. local roomInfo = app.room:getRoomInfo()
  2011. msg.isLast = roomInfo.nGameStartCount>=roomInfo.nTotalGameNum
  2012. msg.isZhaniao = self.ruleZhaniao
  2013. msg.ruleString = PdkRoomViewConfig.getRuleString(roomInfo.nGameInfo)
  2014. if not msg.isLast then
  2015. msg.isLast = msg.stopFlag==8 or msg.stopFlag==9
  2016. end
  2017. self._resultMsg = {}
  2018. self._resultMsg.players = msg.players
  2019. self._resultMsg.isLast = msg.isLast
  2020. self._resultMsg.isZhaniao = msg.isZhaniao
  2021. self._resultMsg.ruleString = msg.ruleString
  2022. self._resultMsg.gameStartCount = msg.gameStartCount
  2023. self._resultMsg.totalGamenum = msg.totalGamenum
  2024. self._resultMsg.stopFlag = msg.stopFlag
  2025. for _,v in pairs(self._playerNodes) do
  2026. v:hideLeft()
  2027. end
  2028. self:showRstComfirm(true)
  2029. if onEnd and type(onEnd)=='function' then onEnd() end
  2030. end
  2031. self:addFunction(__showResult)
  2032. end
  2033. -- 总结算
  2034. function PdkRoomView:onResponseGameOver( data )
  2035. setShowCountAll(true)
  2036. app.room:dispatchEvent({name = GAME_EVENT.DISSMISS_CLOSE});
  2037. local msg = data.response
  2038. for _,player in ipairs(msg.players) do
  2039. local pdata = app.room:getPlayer(player.userId)
  2040. player.unionid = pdata.unionid
  2041. player.headimgurl = pdata.headimgurl
  2042. player.gpsInfo = pdata.gpsInfo
  2043. player.sex = pdata.sex
  2044. player.openid = pdata.openid
  2045. player.nickname = pdata.nickname
  2046. player.areano = pdata.areano
  2047. app.room:updateFlag( player.userId, 0 )
  2048. end
  2049. local function __over( onEnd )
  2050. -- 缓存结算信息
  2051. self._isGameOver = true
  2052. self._gameOverData = msg
  2053. local roomInfo = app.room:getRoomInfo()
  2054. self._gameOverData.nShowTableId = roomInfo.nTableId
  2055. app.room.roomInfo.nShowTableId = roomInfo.nTableId
  2056. self._gameOverData.startCount = roomInfo.nGameStartCount
  2057. self._gameOverData.totalCount = roomInfo.nTotalGameNum
  2058. self._gameOverData.roomRule = PdkRoomViewConfig.getRuleString(roomInfo.nGameInfo)
  2059. self:removeAllTuoGuan()
  2060. if self._gameResult==false then--已经展示过小结算后解散房间
  2061. self:onNormalShowGameOver()
  2062. end
  2063. if onEnd and type(onEnd)=='function' then onEnd() end
  2064. end
  2065. self:addFunction(__over)
  2066. app.club_php:dispatchEvent({name = GAME_EVENT.CLUB_BACK_ROOM})
  2067. end
  2068. --[[先显示小局结算,再显示总结算--]]
  2069. function PdkRoomView:onNormalShowGameOver( data )
  2070. self._gameResult = false
  2071. local showFunc = function (msg)
  2072. local view = import("pk_paodekuai.luaScript.Views.Room.Sub.PdkGameOverView"):new(msg)
  2073. view:setAnchorPoint(cc.p(0.5, 0.5))
  2074. app:showWaitDialog(view)
  2075. stopBGMusic()
  2076. end
  2077. if self._isGameOver and self._gameOverData then
  2078. showFunc(self._gameOverData)
  2079. end
  2080. end
  2081. ----------------------------------------------------------------------------------------------------------------------
  2082. ----------------------------------------------------------------------------------------------------------------------
  2083. -- 单局结算显示剩余牌
  2084. function PdkRoomView:showLeftCards( pos, cards )
  2085. self:showTurnBtn(false)
  2086. if #cards <=0 then return end
  2087. self:clearPosShow(pos)
  2088. if pos==2 then --self:getMode()==1 and
  2089. local tmp = {}
  2090. for _,v in ipairs(cards) do
  2091. table.insert(tmp, 1, v)
  2092. end
  2093. cards = tmp
  2094. end
  2095. local root = cc.Node:create()
  2096. local nodes = {}
  2097. for i,card in ipairs(cards) do
  2098. local node = self:genCard(card)
  2099. local pt = cc.p(0, 25)
  2100. if pos==1 then --self:getMode() == 0 or
  2101. pt.x = pt.x + (i-1)*PdkRoomViewConfig.CARD_DLT_WIDTH*PdkRoomViewConfig.CARD_SCALE[2]
  2102. node:setLocalZOrder(100+i)
  2103. else
  2104. if i>=9 then
  2105. pt.y = pt.y - 80
  2106. if pos ~= 2 then
  2107. pt.x = pt.x + (i-math.floor(i/9)*9)*PdkRoomViewConfig.CARD_DLT_WIDTH*PdkRoomViewConfig.CARD_SCALE[2]
  2108. else
  2109. pt.x = pt.x - (i-math.floor(i/9)*9)*PdkRoomViewConfig.CARD_DLT_WIDTH*PdkRoomViewConfig.CARD_SCALE[2]
  2110. node:setLocalZOrder(36-i)
  2111. end
  2112. else
  2113. if pos ~= 2 then
  2114. pt.x = pt.x + (i-math.floor(i/9)*9-1)*PdkRoomViewConfig.CARD_DLT_WIDTH*PdkRoomViewConfig.CARD_SCALE[2]
  2115. else
  2116. pt.x = pt.x - (i-math.floor(i/9)*9-1)*PdkRoomViewConfig.CARD_DLT_WIDTH*PdkRoomViewConfig.CARD_SCALE[2]
  2117. node:setLocalZOrder(16-i)
  2118. end
  2119. end
  2120. end
  2121. node:setScale(PdkRoomViewConfig.CARD_SCALE[2])
  2122. node:setPosition(pt)
  2123. root:addChild(node)
  2124. node:setVisible(false)
  2125. table.insert(nodes, node)
  2126. end
  2127. local dltWidth = 0
  2128. local rpt = clone(PdkRoomViewConfig.SHOW_CARD_POS[self:getMode()][pos])
  2129. if pos == 1 then
  2130. else
  2131. dltWidth = #cards/2*PdkRoomViewConfig.CARD_DLT_WIDTH*PdkRoomViewConfig.CARD_SCALE[2]
  2132. end
  2133. root:setPosition(rpt)
  2134. self.cardRoot:addChild(root)
  2135. table.insert(self._showCards[pos], root)
  2136. for i,v in ipairs(nodes) do
  2137. v:runAction(cc.Sequence:create(cc.DelayTime:create((i-1)*0.02), cc.CallFunc:create(function ()
  2138. v:setVisible(true)
  2139. end)))
  2140. end
  2141. end
  2142. -- 清除某玩家的出牌
  2143. function PdkRoomView:clearPosShow(pos)
  2144. local pNode = self:getPlayerNodeVpos(pos)
  2145. if pNode then pNode:cleanLastCards() end
  2146. end
  2147. -- 添加玩家节点
  2148. function PdkRoomView:addPlayerNode( pInfo )
  2149. local node = self._playerNodes[pInfo.userId]
  2150. if node then return end
  2151. node = PdkPlayerNode:new()
  2152. node:setPlayMode(self:getMode())
  2153. local gameInfo = app.room:getRoomInfo().nGameInfo
  2154. local data = json.decode(gameInfo)
  2155. local rule = tonumber(data.specialRule)
  2156. node:setGameInfo(gameInfo)
  2157. node:setMaxPlayerCount(app.room:getRoomInfo().nMaxPlayCount)
  2158. node:setShowNum(getNumBand(rule, 0x0020)>0)--是否显示牌张数
  2159. node:setInfo(pInfo)
  2160. node:setReady(pInfo.playFlag==1)
  2161. node:setOffline((pInfo.onlineStatus and pInfo.onlineStatus==0))
  2162. node:setOfflineTime((pInfo.onlineStatus and pInfo.onlineStatus==0),pInfo.offtime or 0)
  2163. node:setHost(pInfo.userId==app.room:getRoomInfo().nRoomOwnedUid)
  2164. node:setPosition(PdkRoomViewConfig.PLAYER_POS[self:getMode()][pInfo.viewPos])
  2165. self._playerNodes[pInfo.userId] = node
  2166. node:setLocalZOrder(10)
  2167. self.ui.Items.toolPanel:addChild(node)
  2168. -- self.panelMenu:getParent():addChild(node)
  2169. -- 将玩家加入到chatView
  2170. self.chatView:addPlayer(pInfo.userId)
  2171. end
  2172. -- 删除玩家节点
  2173. function PdkRoomView:delPlayerNode( uid )
  2174. if self._gameResult or self._isGameOver then return end
  2175. local node = self._playerNodes[uid]
  2176. if not node then return end
  2177. node:removeFromParent()
  2178. self._playerNodes[uid] = nil
  2179. -- 将玩家从chatView移除
  2180. self.chatView:delPlayer(uid)
  2181. end
  2182. -- 获取玩家节点
  2183. function PdkRoomView:getPlayerNode( uid )
  2184. return self._playerNodes[uid]
  2185. end
  2186. -- 根据视图获取玩家节点
  2187. function PdkRoomView:getPlayerNodeVpos( viewPos )
  2188. for _,v in pairs(self._playerNodes) do
  2189. if v:getInfo().viewPos==viewPos then
  2190. return v
  2191. end
  2192. end
  2193. return nil
  2194. end
  2195. ----------------------------------------------------------------------------
  2196. -- 检查拖牌节点
  2197. function PdkRoomView:checkTouches( pt )
  2198. local rect = nil
  2199. local node = nil
  2200. for i,v in ipairs(self._selfCards) do
  2201. if cc.rectContainsPoint(v:getRect(), pt) then
  2202. node = v
  2203. break
  2204. end
  2205. end
  2206. return node
  2207. end
  2208. ----------------------------------------------------------------------------
  2209. function PdkRoomView:touchBegan( pt )
  2210. if self._gameResult then return end
  2211. self._selectCards = {}
  2212. local node = self:checkTouches(pt)
  2213. if node and node:getVal()>0 then
  2214. self._selectCards[node:getVal()] = node
  2215. end
  2216. self:doSelectColor()
  2217. end
  2218. ----------------------------------------------------------------------------
  2219. function PdkRoomView:touchMoved( pt )
  2220. if self._gameResult then return end
  2221. local node = self:checkTouches(pt)
  2222. if node and self._selectCards[node:getVal()]==nil then
  2223. self._selectCards[node:getVal()] = node
  2224. end
  2225. self:doSelectColor()
  2226. end
  2227. ----------------------------------------------------------------------------
  2228. function PdkRoomView:touchEnded( pt )
  2229. if self._gameResult then return end
  2230. self:doSelect()
  2231. if pt.y > PdkRoomViewConfig.NORMAL_HEIGHT + PdkRoomViewConfig.CARD_HEIGHT/2 and (not self:checkTouches(pt)) then
  2232. for _,node in pairs(self._selfCards) do
  2233. if node:isDown() then node:setNormal() end
  2234. end
  2235. end
  2236. end
  2237. ----------------------------------------------------------------------------
  2238. function PdkRoomView:doSelect()
  2239. local i = 0
  2240. for _,node in pairs(self._selectCards) do
  2241. i = i + 1
  2242. if (not tolua.isnull(node)) and node and node.getParent and node:getParent() then
  2243. if node:isDown() then
  2244. node:setNormal()
  2245. else
  2246. node:setDown()
  2247. end
  2248. if i==1 then PdkSoundHelper:selectSnd() end
  2249. end
  2250. end
  2251. end
  2252. ----------------------------------------------------------------------------
  2253. function PdkRoomView:doSelectColor()
  2254. for _,node in pairs(self._selectCards) do
  2255. if not tolua.isnull(node) and node and node.getParent and node:getParent() then
  2256. node:setDownColor()
  2257. end
  2258. end
  2259. end
  2260. ----------------------------------------------------------------------------
  2261. function PdkRoomView:resetSelect()
  2262. local i = 0
  2263. for _,v in pairs(self._selfCards) do
  2264. i = i + 1
  2265. if v:isDown() then
  2266. v:setNormal()
  2267. v:setNormalColor()
  2268. if i==1 then PdkSoundHelper:selectSnd() end
  2269. end
  2270. end
  2271. self._selectCards = {}
  2272. end
  2273. function PdkRoomView:setCardsNoTouch()
  2274. for _,v in pairs(self._selfCards) do
  2275. v:setNoTouch(true)
  2276. v:setNormal()
  2277. v:setNormalColor()
  2278. end
  2279. self:resetSelect()
  2280. end
  2281. ----------------------------------------------------------------------------
  2282. -- 获取选择的牌的集合
  2283. function PdkRoomView:getSelected()
  2284. local sel = {}
  2285. for _,v in pairs(self._selfCards) do
  2286. if v:isDown() then table.insert(sel, v:getVal()) end
  2287. end
  2288. return sel
  2289. end
  2290. -- 添加牌节点监听
  2291. function PdkRoomView:addTouchesListener()
  2292. local function onTouchBegan(touch, event)
  2293. local locationInNode = self:convertToWorldSpace(touch:getLocation())--触点
  2294. self:touchBegan(locationInNode)
  2295. return true
  2296. end
  2297. local function onTouchMoved(touch, event)
  2298. local locationInNode = touch:getLocation()
  2299. self:touchMoved(locationInNode)
  2300. end
  2301. local function onTouchEnded(touch, event)
  2302. local locationInNode = touch:getLocation()
  2303. self:touchEnded(locationInNode)
  2304. end
  2305. local listener1 = cc.EventListenerTouchOneByOne:create()
  2306. listener1:setSwallowTouches(false)
  2307. listener1:registerScriptHandler(onTouchBegan,cc.Handler.EVENT_TOUCH_BEGAN )
  2308. listener1:registerScriptHandler(onTouchMoved,cc.Handler.EVENT_TOUCH_MOVED )
  2309. listener1:registerScriptHandler(onTouchEnded,cc.Handler.EVENT_TOUCH_ENDED )
  2310. local eventDispatcher = self.cardRoot:getEventDispatcher()
  2311. eventDispatcher:addEventListenerWithSceneGraphPriority(listener1, self)
  2312. end
  2313. -- 发牌
  2314. function PdkRoomView:sendCards( cards_ )
  2315. local cards = pokerSortPdkCards(cards_)
  2316. local pos = 1
  2317. local CardsCount = #cards
  2318. for i,card in ipairs(cards) do
  2319. local ac = cc.Sequence:create(cc.DelayTime:create(i*0.02), cc.CallFunc:create(function ()
  2320. self:sendOneCard(card.cid, i, pos, i==CardsCount, CardsCount)
  2321. if self:getMode()==0 then
  2322. if i==CardsCount then self:showOtherCards(true) end
  2323. end
  2324. end))
  2325. self.cardRoot:runAction(ac)
  2326. end
  2327. end
  2328. -- 发一张牌
  2329. function PdkRoomView:sendOneCard( card, i, pos, islast, allCount )
  2330. -- local node = self:genCard(card)
  2331. local node = self:genCard(-1)--back
  2332. node.cid = card
  2333. node:setScale(PdkRoomViewConfig.CARD_SCALE[pos])--PdkRoomViewConfig.CARD_SCALE_START
  2334. node:setLast(islast)
  2335. local endX = CENTER_X + (allCount-allCount/2+1)*PdkRoomViewConfig.CARD_DLT_WIDTH*PdkRoomViewConfig.CARD_SCALE[1]
  2336. local pt = cc.p(0, 0)
  2337. if pos ~= 1 then
  2338. pt = clone(PdkRoomViewConfig.PLAYER_POS[1][pos])
  2339. else
  2340. pt.x = CENTER_X
  2341. local midIdx = allCount/2
  2342. if i<=midIdx then--左边
  2343. pt.x = pt.x - (midIdx-i-1)*PdkRoomViewConfig.CARD_DLT_WIDTH*PdkRoomViewConfig.CARD_SCALE[1]
  2344. else--右边
  2345. pt.x = pt.x + (i-midIdx+1)*PdkRoomViewConfig.CARD_DLT_WIDTH*PdkRoomViewConfig.CARD_SCALE[1]
  2346. end
  2347. pt.x = pt.x - PdkRoomViewConfig.CARD_WIDTH/2*PdkRoomViewConfig.CARD_SCALE[1]
  2348. pt.y = PdkRoomViewConfig.CARD_POS[1][pos].y
  2349. end
  2350. node:setPosition(cc.p(endX, pt.y))
  2351. node:setLocalZOrder(i)
  2352. node:setOpacity(0)
  2353. self.cardRoot:addChild(node)
  2354. local ac = nil
  2355. if pos ~=1 then
  2356. ac = cc.Sequence:create(cc.Spawn:create(cc.MoveTo:create(0.05, pt), cc.ScaleTo:create(0.7, PdkRoomViewConfig.CARD_SCALE[pos])), cc.CallFunc:create(function ()
  2357. node:removeFromParent()
  2358. end))
  2359. node:runAction(ac)
  2360. else
  2361. ac = cc.Sequence:create(cc.Spawn:create(cc.MoveTo:create(0.05, pt), cc.FadeIn:create(0.1)), cc.CallFunc:create(function ()
  2362. table.insert(self._selfCards, node)
  2363. PdkSoundHelper:playSend()
  2364. end), cc.DelayTime:create((i)*0.01), cc.CallFunc:create(function() node:setCard(node.cid) end ))
  2365. node:runAction(ac)
  2366. end
  2367. end
  2368. -- 发一张牌没有动画
  2369. function PdkRoomView:sendOneCardNoAct( card, i, pos, islast, allCount )
  2370. local node = self:genCard(card)
  2371. node:setScale(PdkRoomViewConfig.CARD_SCALE[pos])
  2372. node:setLast(islast)
  2373. local pt = cc.p(0, 0)
  2374. if pos ~= 1 then
  2375. pt = clone(PdkRoomViewConfig.CARD_POS[self:getMode()][pos])
  2376. else
  2377. local midIdx = math.floor(allCount/2)
  2378. if i<midIdx then--左边
  2379. pt.x = CENTER_X - (midIdx-i-1)*PdkRoomViewConfig.CARD_DLT_WIDTH*PdkRoomViewConfig.CARD_SCALE[pos]
  2380. else--右边
  2381. pt.x = CENTER_X + (i-midIdx+1)*PdkRoomViewConfig.CARD_DLT_WIDTH*PdkRoomViewConfig.CARD_SCALE[pos]
  2382. end
  2383. pt.x = pt.x - PdkRoomViewConfig.CARD_WIDTH/2*PdkRoomViewConfig.CARD_SCALE[pos]
  2384. pt.y = PdkRoomViewConfig.CARD_POS[1][pos].y
  2385. end
  2386. node:setPosition(pt)
  2387. node:setLocalZOrder(i)
  2388. self.cardRoot:addChild(node)
  2389. table.insert(self._selfCards, node)
  2390. end
  2391. -- 创建一张牌
  2392. function PdkRoomView:genCard( card )
  2393. local node = PdkCardNode:new()
  2394. node:setCard(card)
  2395. node:setSelectedHeight(PdkRoomViewConfig.SELECTED_HEIGHT)
  2396. node:setNormalHeight(PdkRoomViewConfig.NORMAL_HEIGHT)
  2397. return node
  2398. end
  2399. -- 从手牌中获取一张牌
  2400. function PdkRoomView:getCardNode( card )
  2401. if card > 0x00 and card <= 0x3d then
  2402. for _,v in pairs(self._selfCards) do
  2403. if v:getVal()==card then return v end
  2404. end
  2405. return nil
  2406. else
  2407. return nil
  2408. end
  2409. end
  2410. -- 根据牌ID移除一张手牌,并重新调整手牌位置
  2411. function PdkRoomView:removeCardNode( card )
  2412. local node = self:getCardNode(card)
  2413. if not node then return end
  2414. for i=#self._selfCards,1,-1 do
  2415. if self._selfCards[i]:getVal()==card then
  2416. table.remove(self._selfCards, i)
  2417. break
  2418. end
  2419. end
  2420. node:removeFromParent()
  2421. --reset pos
  2422. self:resetCardsPos()
  2423. end
  2424. -- 获取当前手牌
  2425. function PdkRoomView:getHandCards()
  2426. local handCards = {}
  2427. for _,v in pairs(self._selfCards) do
  2428. table.insert(handCards, v:getVal())
  2429. end
  2430. return handCards
  2431. end
  2432. -- 重置手牌位置
  2433. function PdkRoomView:resetCardsPos( )
  2434. if #self._selfCards<=0 then return end
  2435. local mode = self:getMode()
  2436. local pos = 1
  2437. local scale = PdkRoomViewConfig.CARD_SCALE[pos]
  2438. local dtpx = (16 - #self._selfCards)/2*PdkRoomViewConfig.CARD_DLT_WIDTH*scale
  2439. local allCount = #self._selfCards
  2440. local midIdx = allCount/2
  2441. for i,v in ipairs(self._selfCards) do
  2442. if v and (not tolua.isnull(v)) then
  2443. local pt = cc.p(CENTER_X, 0)
  2444. if i<midIdx then--左边
  2445. pt.x = pt.x - (midIdx-i-1)*PdkRoomViewConfig.CARD_DLT_WIDTH*scale
  2446. else--右边
  2447. pt.x = pt.x + (i-midIdx+1)*PdkRoomViewConfig.CARD_DLT_WIDTH*scale
  2448. end
  2449. pt.x = pt.x - PdkRoomViewConfig.CARD_WIDTH/2*scale
  2450. pt.y = PdkRoomViewConfig.CARD_POS[1][pos].y
  2451. v:setPosition(pt)
  2452. v:setLast(i==allCount)
  2453. v:setNormal()
  2454. end
  2455. end
  2456. end
  2457. -- 提示对应的牌
  2458. function PdkRoomView:tipCards( cards, show )
  2459. if show ~= nil then return "" end
  2460. self:resetSelect()
  2461. self:resetCardsPos()
  2462. for _,v in pairs(cards) do
  2463. local node = self:getCardNode(v.cid)
  2464. if node and node:getVal()>0 then
  2465. self._selectCards[node:getVal()] = node
  2466. node:setDown()
  2467. end
  2468. end
  2469. end
  2470. -- 清除所有牌
  2471. function PdkRoomView:cleanSelfCards()
  2472. for _,v in pairs(self._selfCards) do
  2473. if v:getParent() then v:removeFromParent() end
  2474. end
  2475. self._selfCards = {}
  2476. end
  2477. function PdkRoomView:cleanShowCards()
  2478. for _,v in pairs(self._showCards) do
  2479. for _,vv in pairs(v) do
  2480. if vv and vv:getParent() then
  2481. vv:removeFromParent()
  2482. end
  2483. end
  2484. end
  2485. self._showCards = {{},{},{}}
  2486. for _,v in pairs(self._playerNodes) do
  2487. if v then v:cleanLastCards() end
  2488. end
  2489. end
  2490. -- 二人玩显示另外一组牌
  2491. function PdkRoomView:showOtherCards(is)
  2492. if is then
  2493. self.imgOtherCards:setVisible(true)
  2494. local num = 16
  2495. if self.ruleType==2 then num = 15 end
  2496. self.txtOtherCards:setString(string.format("剩余%d张", num))
  2497. else
  2498. self.imgOtherCards:setVisible(false)
  2499. end
  2500. end
  2501. --发起申请
  2502. function PdkRoomView:onClickFastStart(sender)
  2503. playBtnEffect()
  2504. local request = PdkMessage.FastStartRequest:new()
  2505. request.result = 1
  2506. self.ui:sendMsg(app.room, "requestFastStartGame", request)
  2507. end
  2508. --是否显示2/3人快速开始按钮
  2509. function PdkRoomView:showFastStart(is)
  2510. local roomInfo = app.room:getRoomInfo()
  2511. if roomInfo.gameStatus and roomInfo.gameStatus > PdkRoomViewConfig.GameStatus.GAME_STATE_INIT and roomInfo.gameStatus <= PdkRoomViewConfig.GameStatus.GAME_STATE_GAME_OVER then
  2512. self.ui.Items.Button_fastStart:setVisible(false)
  2513. else
  2514. local playerCount = app.room:getPlayerNum()
  2515. local gameInfo = json.decode(roomInfo.nGameInfo)
  2516. if true == is and playerCount < roomInfo.nMaxPlayCount and roomInfo.nGameStartCount <= 0 and gameInfo.playerNum == 2 then
  2517. self.ui.Items.Button_fastStart:setVisible(playerCount == 2 or playerCount == 3)
  2518. else
  2519. self.ui.Items.Button_fastStart:setVisible(false)
  2520. end
  2521. end
  2522. end
  2523. -- 服务器广播快速开始
  2524. function PdkRoomView:onBroadcastFaststart(data)
  2525. local response = data.response
  2526. local isRemove = false
  2527. if response.nUserId and response.nStatus then
  2528. if response.nStatus == 3 or response.nStatus > 4 then
  2529. isRemove = true
  2530. end
  2531. end
  2532. if not isRemove then
  2533. for _,v in ipairs(response.pList) do
  2534. if v.nStatus == 3 or v.nStatus > 4 then
  2535. isRemove = true
  2536. end
  2537. end
  2538. end
  2539. if response.timeOut <=0 then
  2540. isRemove = true
  2541. end
  2542. logD("PdkRoomView:onBroadcastFaststart isRemove:"..table.tostring(isRemove)..";self.fastStartRequestView = "..table.tostring(self.fastStartRequestView))
  2543. if self.fastStartRequestView == nil then
  2544. if isRemove then
  2545. return ""
  2546. end
  2547. local requesterId = 0
  2548. for _,v in ipairs(response.pList) do
  2549. if v.nStatus == 1 then
  2550. requesterId = v.nUserId
  2551. end
  2552. end
  2553. if requesterId <= 0 then
  2554. return ""
  2555. end
  2556. local view = import("pk_paodekuai.luaScript.Views.Room.PdkRequestStartView"):new(requesterId)
  2557. view:setAnchorPoint(cc.p(0.5, 0.5))
  2558. view:showItems(response)
  2559. app:showWaitDialog(view)
  2560. self.fastStartRequestView = view
  2561. else
  2562. if isRemove then
  2563. local userInfo = app.room.roomInfo.memberList[response.nUserId]
  2564. self.fastStartRequestView:removeFromParent()
  2565. self.fastStartRequestView = nil
  2566. if userInfo then
  2567. local u = json.decode(userInfo.userInfo)
  2568. local txt = string.format("玩家【%s】拒绝立即开局", u.nickname)
  2569. showTooltip(txt)
  2570. end
  2571. app.room.roomInfo.quickStartInfo = nil
  2572. self:showFastStart(true)
  2573. else
  2574. self.fastStartRequestView:updateView(response)
  2575. end
  2576. end
  2577. end
  2578. function PdkRoomView:onFastStartSucc(data)
  2579. if self.fastStartRequestView then
  2580. self.fastStartRequestView:removeFromParent()
  2581. self.fastStartRequestView = nil
  2582. end
  2583. self:showFastStart(false)
  2584. --self.playerView:setPlayerVisible(false)
  2585. --self:updateRoomBaseData()
  2586. --刷新房间玩家位置
  2587. if data.response then
  2588. --删除所有玩家节点
  2589. for k,v in pairs(data.response.pList) do
  2590. self:delPlayerNode(v.nUserId)
  2591. end
  2592. self:initChatView()
  2593. --重新添加玩家节点
  2594. local players = app.room:getPlayers()
  2595. for _, info in pairs(players) do
  2596. self:addPlayerNode( info )
  2597. end
  2598. end
  2599. end
  2600. --是否显示快速开始页面
  2601. function PdkRoomView:isShowFastStartView()
  2602. --快速开始数据
  2603. local roomInfo = app.room:getRoomInfo()
  2604. if roomInfo then
  2605. local fastData = {}
  2606. fastData.response = {}
  2607. fastData.response.nStatus = roomInfo.userFastStartStatus
  2608. fastData.response.timeOut = roomInfo.fastStartTimeout
  2609. fastData.response.pList = {}
  2610. if roomInfo.fastStartPlayersStatus then
  2611. for k,v in pairs(roomInfo.fastStartPlayersStatus) do
  2612. local playerList = {}
  2613. if v.fastStartStatus and v.fastStartStatus == 1 then
  2614. --玩家发起申请
  2615. fastData.response.nUserId = v.userId
  2616. end
  2617. playerList.nStatus = v.fastStartStatus
  2618. playerList.nUserId = v.userId
  2619. table.insert(fastData.response.pList, playerList)
  2620. end
  2621. end
  2622. logD("PdkRoomView:isShowFastStartView roomInfo = "..table.tostring(roomInfo))
  2623. logD("PdkRoomView:isShowFastStartView fastData = "..table.tostring(fastData))
  2624. self:onBroadcastFaststart(fastData)
  2625. end
  2626. end
  2627. function PdkRoomView:onApplicationWillEnterForeground()
  2628. --从后台返回游戏,但未重连,此时数据未改变
  2629. if app.room:getRoomInfo().nGameStartCount and app.room:getRoomInfo().nGameStartCount <= 0 then
  2630. --从后台返回游戏时,如果已经开始游戏,则不处理快速开始view
  2631. self:isShowFastStartView()
  2632. end
  2633. end
  2634. -- 检测玩家与其他玩家之间的距离
  2635. -- 如果不传参数,则检测所有玩家相互之间的距离
  2636. --[[function PdkRoomView:checkGpsDistance(curUserId,isOpenGpsView)
  2637. if self.gpsComponent then
  2638. self.gpsComponent:updateUserInfos(app.room:getUserInfoList())
  2639. end
  2640. if self.gpsComponent then
  2641. local isDanger = self.gpsComponent:checkGpsDistance(curUserId)
  2642. if isDanger and isOpenGpsView then
  2643. self:onClickButtonGps()
  2644. showTooltip("玩家距离过近或者未开启GPS!")
  2645. end
  2646. end
  2647. end--]]
  2648. -- 服务器广播玩家数据发生变化
  2649. function PdkRoomView:onGpsChangeResponse(data)
  2650. logD("PdkRoomView:onGpsChangeResponse()")
  2651. if not data or not data.nUserId then
  2652. return
  2653. end
  2654. local roomInfo = app.room:getRoomInfo()
  2655. local nUserId = data.nUserId
  2656. logD("PdkRoomView:onGpsChangeResponse()", tostring(nUserId))
  2657. --self:checkGpsDistance(nUserId,roomInfo.nGameStartCount==0)
  2658. end
  2659. function PdkRoomView:initGpsComponent()
  2660. if self.isRecordScene then return end--回放场景直接return
  2661. local versionCode = getAppVersionCode()
  2662. versionCode = tonumber(versionCode) or 0
  2663. logD("PdkRoomView:initGpsComponent() versionCode = ", versionCode)
  2664. if isReviewVersion() then
  2665. self.ui.Items.btnGps:setVisible(false)
  2666. return
  2667. end
  2668. local function exitRoomCallback()
  2669. local isGameStart = app.room:getRoomInfo().nGameStartCount > 0
  2670. if isGameStart then
  2671. app.room:requestDismissRoom(1)
  2672. else
  2673. self.ui:sendMsg(app.room, "callLeaveRequest");
  2674. end
  2675. end
  2676. -- 创建 gps 组件
  2677. --self.gpsComponent = RoomGpsComponent:new(self.ui.Items.btnGps)
  2678. self.gpsComponent = import("luaScript.Views.Room.RoomGpsComponentView"):new(3,self.ui.Items.btnGps,exitRoomCallback,exitRoomCallback)
  2679. self.gpsComponent:setLocalZOrder(100)
  2680. self:addChild(self.gpsComponent)
  2681. -- GPS 按钮
  2682. self.ui.Items.btnGps:registerClick(handler(self , self.showGpsView))
  2683. -- 我的GPS数据发生变化时检测是否需要通知服务器
  2684. --self:bindEvent(app, "onGpsInoChanged", handler(self, self.checkMyGpsNeedUpdate))
  2685. --self.isInitCheckGps = false
  2686. -- 进入时检测一遍我的GPS数据是否需要更新
  2687. --self:checkMyGpsNeedUpdate()
  2688. end
  2689. -- 检查服务器记录的我的GPS数据是最新的,如果不是,则请求更新
  2690. --[[function PdkRoomView:checkMyGpsNeedUpdate(event)
  2691. logD("PdkRoomView:checkMyGpsNeedUpdate()")
  2692. if self.isInitCheckGps and not event then
  2693. return
  2694. end
  2695. self.isInitCheckGps = true
  2696. local nMyUserId = app.user.loginInfo.uid
  2697. local myMemberInfo = app.room:getUserInfo(nMyUserId) or nil
  2698. if myMemberInfo then
  2699. local userInfo = json.decode(myMemberInfo)
  2700. if userInfo then
  2701. local gpsInfo = userInfo.gpsInfo
  2702. local isNewest = app.user:isGpsInfoNewest(gpsInfo)
  2703. logD("PdkRoomView:checkMyGpsNeedUpdate() gpsInfo is isNewest = ", tostring(isNewest))
  2704. if not isNewest then
  2705. app.room:onGpsChangeRequest();
  2706. else
  2707. logD("PdkRoomView:checkMyGpsNeedUpdate() gpsInfo is newest")
  2708. end
  2709. else
  2710. logD("PdkRoomView:checkMyGpsNeedUpdate() userInfo is nil")
  2711. end
  2712. else
  2713. logD("PdkRoomView:checkMyGpsNeedUpdate() myMemberInfo is nil")
  2714. end
  2715. end--]]
  2716. -- 更新所有玩家的信息到GPS组件
  2717. function PdkRoomView:updateAllGpsInfo()
  2718. if self.isRecordScene then return end--回放场景直接return
  2719. local userInfoList = app.room:getUserInfoList()
  2720. if self.gpsComponent then
  2721. self.gpsComponent:updateUserInfos(userInfoList)
  2722. end
  2723. end
  2724. --托管结果协议
  2725. function PdkRoomView:onTuoGuanResponse(data)
  2726. --local function runTuoGuanResponse(onEnd)
  2727. log("2000000000-PdkRoomView - (onTuoGuanResponse)")
  2728. local response = data.response
  2729. local entrustType = response.entrustType;--托管状态 1-托管中 0-未托管
  2730. local nUserID = response.nUserId;
  2731. local viewId = app.room:getViewIdByUserId(nUserID)
  2732. local isTuoGuan = entrustType == 1;
  2733. if app.room:isMyself(nUserID) then
  2734. if isTuoGuan then
  2735. self:showTuoGuan(true)
  2736. self.isTuoGuan = true
  2737. else
  2738. self:showTuoGuan(false)
  2739. self.isTuoGuan = false
  2740. end
  2741. end
  2742. local node = self:getPlayerNodeVpos(viewId)
  2743. if node then
  2744. node:setTuoGuan(isTuoGuan)
  2745. end
  2746. --self.PlayerView:showTuoGuanByViewId(viewId,isTuoGuan)
  2747. --[[if onEnd then
  2748. onEnd()
  2749. end
  2750. end
  2751. log("2000000000-PdkRoomView - addCallBack(runTuoGuanResponse)")
  2752. self:addFunction(runTuoGuanResponse)--]]
  2753. end
  2754. --显示隐藏托管(界面)
  2755. function PdkRoomView:showTuoGuan(isShow)
  2756. if isShow then
  2757. if not self.tuoguanView then
  2758. self.tuoguanView = import("pk_paodekuai.luaScript.Views.Room.PdkRoomTuoGuanView"):new()
  2759. self:addChild(self.tuoguanView)
  2760. end
  2761. else
  2762. if self.tuoguanView and not tolua.isnull(self.tuoguanView) then
  2763. self.tuoguanView:removeFromParent()
  2764. self.tuoguanView = nil
  2765. end
  2766. end
  2767. end
  2768. function PdkRoomView:removeAllTuoGuan()
  2769. self:showTuoGuan(false)
  2770. for i, node in pairs(self._playerNodes) do
  2771. if node then
  2772. node:setTuoGuan(false)
  2773. end
  2774. end
  2775. end
  2776. ---
  2777. -- 检测是否可以解散房间
  2778. -- @param
  2779. -- @return
  2780. --
  2781. function PdkRoomView:checkCanDismiss( )
  2782. local onCanDismissCallback = function (info)
  2783. local nUserId = app.room:getMyUserId()
  2784. local roomInfo = app.room.roomInfo or {}
  2785. local canDismiss = (tonumber(info.canDismiss or 1) == 1) or roomInfo.nRoomOwnedUid == nUserId or dd.IClub.isAdmin()
  2786. if roomInfo.nGameStartCount == 0 and roomInfo.nRoomOwnedUid ~= nUserId then
  2787. canDismiss = false
  2788. end
  2789. self:onCanDismissCallback(canDismiss)
  2790. end
  2791. if dd.IClub.getCanDismiss then
  2792. local canDismiss = dd.IClub.getCanDismiss(onCanDismissCallback)
  2793. if canDismiss then
  2794. onCanDismissCallback({canDismiss = canDismiss})
  2795. end
  2796. end
  2797. end
  2798. function PdkRoomView:onCanDismissCallback(canDismiss)
  2799. if self.ui.Items.Button_Dismiss then
  2800. self.ui.Items.Button_Dismiss:setEnabled(canDismiss)
  2801. end
  2802. end
  2803. return PdkRoomView