Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

3194 рядки
104 KiB

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