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.

3220 lignes
104 KiB

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