You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

4285 rivejä
132 KiB

  1. -- 斗地主主界面
  2. local DdzDef = require("luaScript.SubGameDefine.zgwrDdzDefine")
  3. local DdzPlayerNode = require("pk_zgwrddz.luaScript.Views.Room.Node.zgwrDdzPlayerNode")
  4. local DdzCardNode = require("pk_zgwrddz.luaScript.Views.Room.Node.zgwrDdzCardNode")
  5. local DdzRoomViewConfig = require("pk_zgwrddz.luaScript.Views.Room.zgwrDdzRoomViewConfig")
  6. local DdzEffectHelper = require("pk_zgwrddz.luaScript.Views.Room.zgwrDdzEffectHelper"):new()
  7. local ETS = DdzRoomViewConfig.EffectType
  8. local DdzSoundHelper = require("pk_zgwrddz.luaScript.Views.Room.zgwrDdzSoundHelper"):new()
  9. local RoomGpsComponent = require("luaScript.Views.Room.RoomGpsComponent")
  10. require("luaScript.Views.Room.RoomFunctions")
  11. local DdzMessage = require("pk_zgwrddz.luaScript.Protocol.zgwrDdzMessage")
  12. local DdzFunctions = require("pk_zgwrddz.luaScript.zgwrDdzFunctions")
  13. local WRDDZDefine=require("luaScript.SubGameDefine.zgwrDdzDefine")
  14. local zgwrDdzPokerUtil2 = require("pk_zgwrddz.luaScript.Views.Room.zgwrDdzPokerUtil2")
  15. local CENTER_X=640*g_radio_x
  16. local CENTER_Y=360*g_radio_y
  17. local zgwrDdzRoomView = class("zgwrDdzRoomView", cc.UIView)
  18. local STATUS_INFO = {
  19. [7] = "等待其他玩家加倍...",
  20. [8] = "请在点数6-K中选择一张牌作为暗地主暗号牌",
  21. [0] = "等待地主选择暗地主...",
  22. }
  23. function zgwrDdzRoomView:ctor(params)
  24. zgwrDdzRoomView.super.ctor(self)
  25. -- 玩家节点
  26. self._playerNodes = {}
  27. -- 自己手牌集合
  28. self._selfCards = {}
  29. -- 玩家出牌集合
  30. self._showCards = {{},{},{},{},{}}
  31. -- 点击选择的牌
  32. self._selectCards = {}
  33. -- 上一次出牌viewPos
  34. self._lastOutPos = 0
  35. -- 上一次出牌类型
  36. self._lastOutType = 0
  37. -- 上一次出牌类型,只记录服务器下发的类型
  38. app.room.lastOutType = 0
  39. -- 上一次出牌,用于提示
  40. self._lastCards = {}
  41. -- 排序轮次用
  42. self._turnsQueue = {}
  43. -- 快速开始界面
  44. self.fastStartRequestView = nil
  45. --是否是小局结算
  46. self._gameResult = false
  47. --是否是地主
  48. self._isLorder = false
  49. --是否是暗地主
  50. self._isDarkLorder = false
  51. --压牌第一次弹提示
  52. self.firstTip = false
  53. end
  54. function zgwrDdzRoomView:loadUI()
  55. self.ui = loadUI("pk_zgwrddz/res/ui/ui_room/ui_wrddz_gameview.ui")
  56. self:addChild(self.ui)
  57. end
  58. function zgwrDdzRoomView:loadTextureCache()
  59. loadSpriteFrameFile("pk_zgwrddz/res/ui/zy_game/wrddz_cards.plist")
  60. loadSpriteFrameFile("pk_zgwrddz/res/ui/zy_effect/lzpdk_effect.plist")
  61. loadSpriteFrameFile("pk_zgwrddz/res/ui/zy_effect/ddz_effect_bomb.plist")
  62. loadSpriteFrameFile("pk_zgwrddz/res/ui/zy_effect/ddz_effect_plan.plist")
  63. loadSpriteFrameFile("pk_zgwrddz/res/ui/zy_effect/ddz_effect_shunziliandui.plist")
  64. loadSpriteFrameFile("pk_zgwrddz/res/ui/zy_effect/ddz_effect_spring.plist")
  65. loadSpriteFrameFile("pk_zgwrddz/res/ui/zy_effect/ddz_effect_sszd.plist")
  66. loadSpriteFrameFile("pk_zgwrddz/res/ui/zy_effect/ddz_effect_zhangshui.plist")
  67. loadSpriteFrameFile("pk_zgwrddz/res/ui/zy_effect/ddz_effect_kingbomb.plist")
  68. loadSpriteFrameFile("pk_zgwrddz/res/ui/zy_effect/ddz_effect_baojing.plist")
  69. --loadSpriteFrameFile("pk_zgwrddz/res/ui/zy_game/lzroom_add.plist")
  70. end
  71. --[[
  72. GAME_STATE_INIT =0, --//游戏准备状态
  73. GAME_STATE_SEND_HAND_CARD =1, --//发牌
  74. GAME_STATE_OUT_CARD =2, --//打牌
  75. GAME_STATE_ROUND_OVER =3, --//游戏一局结束
  76. GAME_STATE_GAME_OVER =4, --//游戏结束
  77. ]]
  78. function zgwrDdzRoomView:onEnter()
  79. zgwrDdzRoomView.super.onEnter()
  80. self:loadUI();
  81. self.panelMenu = self.ui.Items.Layout_Menu
  82. self.cardRoot = self.ui.Items.cardRoot
  83. self.imgOtherCards = self.ui.Items.ImageView_other
  84. self.txtOtherCards = self.ui.Items.Text_otherNum
  85. self:initChatView()
  86. self:loadTextureCache();
  87. self:showOtherCards(false)
  88. self:initViews()
  89. self:showMenu(false)
  90. self:showTurnBtn(false)
  91. self:showZiChi(false)
  92. self:setRoomInfo(app.room:getRoomInfo())
  93. --
  94. self.functionQueue = require("luaScript.Tools.FunctionQueue"):new()
  95. self:initPlayGameAgain();
  96. local roomInfo = app.room:getRoomInfo()
  97. if roomInfo.nGameStartCount and roomInfo.nGameStartCount > 0 then
  98. setShowCountAll(true)
  99. end
  100. PokerUtil = require("pk_zgwrddz.luaScript.Views.Room.zgwrDdzPokerUtil"):new({isChai=self.ruleIsChaiBomb, isFAT=self.ruleIsFAT})
  101. self:bindEvents()
  102. self:addTouchesListener()
  103. local roomInfo = app.room:getRoomInfo()
  104. if roomInfo.recoverItem then
  105. local recoverData = roomInfo.recoverItem
  106. --self:recover(recoverData)
  107. self:onGameReconnection()
  108. else
  109. --self:checkGpsDistance(nil,roomInfo.nGameStartCount==0)
  110. end
  111. -- GPS组件
  112. self:initGpsComponent()
  113. local changeDesk = tonumber(loadUserInfo("wrddz_setting_bg_idx")) or 3
  114. self:onNormalChangeDesktop({idx=changeDesk})
  115. local cacheMusic = "gameBgMusic"..app.gameId
  116. local defaultMusic = tonumber(loadUserInfo(cacheMusic)) or 2
  117. DdzSoundHelper:playBgMusic(defaultMusic)
  118. --定时器
  119. local roomInfo = app.room:getRoomInfo()
  120. if self.ui.Items.systemTime then
  121. self.ui.Items.systemTime:setText(string.format("%s", os.date("%y-%m-%d %H:%M:%S", os.time()) ) )
  122. end
  123. if not self.Time then
  124. self.Time = cc.Director:getInstance():getScheduler():scheduleScriptFunc(function()
  125. local roomInfo = app.room:getRoomInfo()
  126. self.ui.Items.systemTime:setText(string.format("%s", os.date("%y-%m-%d %H:%M:%S", os.time()) ) )
  127. end,1.0,false)
  128. end
  129. if app.room.isReconnection == true then
  130. --断线重连
  131. --self:isShowFastStartView()
  132. end
  133. self:doSound()
  134. -- if self.chatView and DdzFunctions.isForbidProp() then
  135. -- self.chatView:hideBtns()
  136. -- end
  137. -- todo
  138. if self.chatView and DdzFunctions.isForbidProp() then
  139. self.chatView:hideFace()
  140. end
  141. if self.chatView and DdzFunctions.isForbidVoice() then
  142. self.chatView:hideVoice()
  143. end
  144. self:checkCanDismiss()
  145. end
  146. function zgwrDdzRoomView:doSound()--1 普通话 2 方言
  147. local cacheLan = "LanguageType"..GAME_IDS.zgWuRenDouDiZhu
  148. local languageType = tonumber(loadUserInfo(cacheLan)) or 2
  149. saveUserInfo(cacheLan,languageType)
  150. end
  151. function zgwrDdzRoomView:onExit()
  152. self.fastStartRequestView = nil
  153. setShowCountAll(false)
  154. if self.Time then
  155. cc.Director:getInstance():getScheduler():unscheduleScriptEntry(self.Time)
  156. self.Time = nil
  157. end
  158. for _,node in pairs(self._playerNodes) do
  159. if node then node:setTurn(false) end
  160. end
  161. PokerUtil = nil
  162. app.room:cleanCache()
  163. stopBGMusic()
  164. self:cleanCache();
  165. end
  166. function zgwrDdzRoomView:addFunction( func )
  167. if self.functionQueue then
  168. self.functionQueue:addFunction(func)
  169. else
  170. func()
  171. end
  172. end
  173. function zgwrDdzRoomView:initChatView()
  174. local children = self.panelMenu:getParent():getChildByTag(99)
  175. if children then
  176. children:removeFromParent()
  177. end
  178. local messageList = DdzDef.ChatMessages
  179. local headInfos = {}
  180. headInfos[1] = {headPos = cc.p((62+25)*g_radio_x, (84+20)*g_radio_y), voiceDir = 2}
  181. headInfos[2] = {headPos = cc.p((1224-25)*g_radio_x, (366+20)*g_radio_y), voiceDir = 1}
  182. headInfos[3] = {headPos = cc.p((1224-25)*g_radio_x, (561+20)*g_radio_y), voiceDir = 1}
  183. headInfos[4] = {headPos = cc.p((62+25)*g_radio_x, (561+20)*g_radio_y), voiceDir = 2}
  184. headInfos[5] = {headPos = cc.p((62+25)*g_radio_x, (366+20)*g_radio_y), voiceDir = 2}
  185. local showBtn = true;
  186. self.chatView = import("luaScript.Views.Room.ChatView"):new(messageList, headInfos, showBtn)
  187. --self.chatView:setLanguage(false)
  188. self.chatView:setLocalZOrder(99)
  189. self.chatView:setTag(99)
  190. self.chatView:setBtnFace(cc.p(0.9411563, 0.3730273), "room_menu3_room_btn_kjy.png")
  191. self.chatView:setBtnVoice(cc.p(0.9411563, 0.2163281), "room_menu3_room_btn_yuyin.png")
  192. self.chatView.ui.Items.Button_Face:setPositionPercent(cc.p(0.9411563,0.2630273))
  193. self.chatView.ui.Items.Button_Voice:setPositionPercent(cc.p(0.9411563,0.1300273))
  194. self.panelMenu:getParent():addChild(self.chatView)
  195. -- if DdzFunctions.isForbidProp() and self.chatView then
  196. -- self.chatView:hideBtns()
  197. -- self.chatView:setPropEnabled(false)
  198. -- self.chatView:setVoiceEnabled(false)
  199. -- end
  200. -- todo
  201. if self.chatView and DdzFunctions.isForbidProp() then
  202. self.chatView:hideFace()
  203. self.chatView:setPropEnabled(false)
  204. end
  205. if self.chatView and DdzFunctions.isForbidVoice() then
  206. self.chatView:hideVoice()
  207. self.chatView:setVoiceEnabled(false)
  208. end
  209. end
  210. function zgwrDdzRoomView:resetRoundData( )
  211. -- 上一次出牌viewPos
  212. self._lastOutPos = 0
  213. -- 上一次出牌类型
  214. self._lastOutType = 0
  215. self._lastCards = {}
  216. self.lastOutFlag = -1
  217. --是否是地主
  218. self._isLorder = false
  219. --是否是暗地主
  220. self._isDarkLorder = false
  221. --
  222. self:showTurnBtn(false)
  223. self:cleanSelfCards()
  224. self:cleanShowCards()
  225. self:resetTopCardStatus()
  226. self:showOtherCards(false)
  227. -- 清空玩家时钟
  228. for _,v in pairs(self._playerNodes) do
  229. v:setTurn(false)
  230. v:setHost(false)
  231. v:setAnDiZhu(false)
  232. v:setMult(false)
  233. v:setFanMult(false)
  234. end
  235. self._resultMsg = nil
  236. self:showRstComfirm(false)
  237. if self.xiaojuView and (not tolua.isnull(self.xiaojuView)) then
  238. self.xiaojuView:removeFromParent()
  239. self.xiaojuView = nil
  240. end
  241. self._gameResult = false;
  242. app.room.roomInfo.nDarkLordCard = nil;
  243. end
  244. function zgwrDdzRoomView:getMode()
  245. return app.room:getRoomInfo().nMaxPlayCount or 5
  246. end
  247. function zgwrDdzRoomView:initViews()
  248. self.ui.Items.btnMenu:registerClick(handler(self , self.onClickButtonMenu))
  249. self.ui.Items.Layout_Leave:registerClick(handler(self , self.onClickButtonLeave))
  250. self.ui.Items.Layout_Dismiss:registerClick(handler(self , self.onClickButtonDismiss))
  251. self.ui.Items.Layout_Set:registerClick(handler(self , self.onClickButtonSetting))
  252. self.ui.Items.Button_Ready:registerClick(handler(self , self.onClickButtonReady))
  253. self.ui.Items.Button_Ready.oPos = self.ui.Items.Button_Ready:getPosition()
  254. self.ui.Items.Button_invite:registerClick(handler(self , self.onClickButtonInvite))
  255. self.ui.Items.Button_invite.oPos = self.ui.Items.Button_invite:getPosition()
  256. self.ui.Items.Layout_7:registerClick(handler(self , self.onClickMenuOut))
  257. self.ui.Items.Button_rule:registerClick(handler(self, self.onClickButtonDetails))
  258. --self.ui.Items.Button_Copy:registerClick(handler(self, self.onClickCopy))
  259. self.ui.Items.Layout_Menu_1:setTouchEnabled(true)
  260. self.ui.Items.Button_tip:registerClick(handler(self , self.onClickButtonTip))
  261. self.ui.Items.Button_out:registerClick(handler(self , self.onClickButtonOut))
  262. self.ui.Items.Button_not_out:registerClick(handler(self , self.onClickButtonNotOut))
  263. --邀请俱乐部成员
  264. self.ui.Items.Button_Invite_Club:registerClick(handler(self , self.onClickInviteClub))
  265. -- self.ui.Items.btnShot:registerClick(handler(self , self.onClickButtonShot))
  266. -- 小局结算展示按钮
  267. self._btnComfirm = self.ui.Items.Button_RstComfirm
  268. self._btnComfirm:registerClick(handler(self , self.onClickButtonRstComfirm))
  269. self:showRstComfirm(false)
  270. self.ui.Items.imgTip:setVisible(false)
  271. self.ui.Items.imgTip:setOpacity(0)
  272. self.ui.Items.imgTip:setLocalZOrder(200)
  273. --状态提示
  274. self.ui.Items.Layout_tips:setVisible(false)
  275. self.ui.Items.btnShowClub:registerClick(handler(self , self.onClickButtonShowClub))
  276. if app.club_php.clubID and app.club_php.clubID~=0 then
  277. self.ui.Items.btnShowClub:setVisible(true)
  278. self.ui.Items.Button_Invite_Club:setVisible(true)
  279. else
  280. self.ui.Items.btnShowClub:setVisible(false)
  281. self.ui.Items.Button_Invite_Club:setVisible(false)
  282. end
  283. local roomInfo = app.room:getRoomInfo()
  284. --快速开始按钮
  285. self.ui.Items.Button_fastStart:registerClick(handler(self, self.onClickFastStart))
  286. if roomInfo.nGameStartCount and roomInfo.nGameStartCount <= 0 then
  287. --游戏未开始
  288. self:showFastStart(true)
  289. self:showJiPaiQi(false)
  290. else
  291. self:showFastStart(false)
  292. --self:showJiPaiQi(true)
  293. end
  294. --添加玩家节点
  295. local players = app.room:getPlayers()
  296. for _, info in pairs(players) do
  297. self:addPlayerNode( info )
  298. end
  299. --
  300. local myself = app.room:getMyself()
  301. if myself.playFlag>=1 then
  302. self:showSitdownBtn(false)
  303. else
  304. self:showSitdownBtn(true)
  305. end
  306. --self.gpsComponent:updateUserInfos(app.room:getUserInfoList())
  307. self.ui.Items.Button_invite:setVisible(app.room:getPlayerNum() ~= roomInfo.nMaxPlayCount)
  308. self:updateButtonPosition()
  309. --
  310. if not self.LeavePos then
  311. self.LeavePos = self.ui.Items.Button_Leave:getPosition()
  312. self.DisbandPos = self.ui.Items.Button_Dismiss:getPosition()
  313. self.SettingPos = self.ui.Items.Button_Set:getPosition()
  314. self.RulePos = self.ui.Items.Button_rule:getPosition()
  315. end
  316. -- self:showMenu(false, true)
  317. self.ui.Items.Layout_Rule:setVisible(false)
  318. self.ui.Items.Layout_7:setVisible(false)
  319. self.ui.Items.Text_Rule:setVisible(false)
  320. --self.ui.Items.btnMenu:setVisible(false)
  321. self.ui.Items.Layout_Menu_1:setVisible(false)
  322. self.ui.Items.Layout_Menu_1:setLocalZOrder(199)
  323. if roomInfo.nGameStartCount > 0 then
  324. self.ui.Items.Layout_Rule:setVisible(false)
  325. else
  326. self.ui.Items.Layout_Rule:setVisible(true)
  327. self.ui.Items.Button_rule:setVisible(false)
  328. self.ui.Items.Layout_7:setVisible(true)
  329. self.ui.Items.Layout_Rule:runAction(cc.Sequence:create(
  330. cc.DelayTime:create(2),
  331. cc.CallFunc:create(function()
  332. self.ui.Items.Layout_7:setVisible(false)
  333. self.ui.Items.Layout_Rule:setVisible(false)
  334. self.ui.Items.Button_rule:setVisible(true)
  335. end)))
  336. end
  337. local bar = self.ui.Items.ListView:getVBar()
  338. -- bar:setPositionX(220)
  339. bar:setVisible(false)
  340. --解散按钮状态
  341. if roomInfo.nGameStartCount == 0 and not app.room:isMyself(roomInfo.nRoomOwnedUid) then
  342. --未开始,且自己不是房主,则解散按钮不可点击
  343. self.ui.Items.Button_Dismiss:setEnabled(false)
  344. else
  345. self.ui.Items.Button_Dismiss:setEnabled(true)
  346. end
  347. self:checkCanDismiss()
  348. end
  349. function zgwrDdzRoomView:onClickInviteClub()
  350. playBtnEffect()
  351. if app.club_php.clubID and app.club_php.clubID ~= 0 then
  352. local roomInfo = app.room:getRoomInfo()
  353. local gameInfo = roomInfo.nGameInfo
  354. local strInvite = DdzRoomViewConfig.getClubInviteWanFa(roomInfo.gameId or GAME_IDS.zgWuRenDouDiZhu, roomInfo)
  355. view = import("luaScript.Views.Club.ClubInvite"):new(roomInfo.nShowTableId, strInvite)--WRDDZDefine.getWanFaInfo(gameInfo)
  356. view:setAnchorPoint(cc.p(0.5, 0.5))
  357. app:showWaitDialog(view)
  358. end
  359. end
  360. -- 弹出小结算展示按钮
  361. function zgwrDdzRoomView:showRstComfirm( is )
  362. self.ui.Items.Layout_RstBtn:setVisible(is==true)
  363. self._btnComfirm:setVisible(is==true)
  364. end
  365. -- 设置房间信息
  366. function zgwrDdzRoomView:setRoomInfo( info )
  367. self.ui.Items.roomNum:setString(string.format("房号: %06d", info.nShowTableId))
  368. self.ui.Items.Label_JuShu:setString(string.format("%02d/%02d局", info.nGameStartCount or 0, info.nTotalGameNum or 0))
  369. --设置规则信息
  370. -- local ruleInfo = json.decode(info.nGameInfo)
  371. self.ui.Items.ListView:removeAllChildren()
  372. self.ui.Items.ListView:setAutoSize(true)
  373. local rules = WRDDZDefine.getWanFaInfoTab(info.nGameInfo)
  374. for k,v in pairs(rules) do
  375. local text = self.ui.Items.Text_Rule:getCopied()
  376. text:setVisible(true)
  377. text:setString(v)
  378. self.ui.Items.ListView:addChild(text)
  379. end
  380. end
  381. --[[更新房间局数信息--]]
  382. function zgwrDdzRoomView:updateRoomInfo(startCount, totalCount)
  383. local roomInfo = app.room:getRoomInfo()
  384. roomInfo.nGameStartCount = startCount
  385. roomInfo.nTotalGameNum = totalCount
  386. end
  387. -- 显示操作按钮
  388. function zgwrDdzRoomView:showTurnBtn( is, isShowPass ,opFlag)
  389. --获取开房参数
  390. local roomInfo = app.room:getRoomInfo()
  391. local gameInfo = roomInfo.nGameInfo or ""
  392. local ruleInfo = json.decode(gameInfo)
  393. if not is then
  394. self.ui.Items.Layout_tip:setVisible(false)
  395. self.ui.Items.Layout_out:setVisible(false)
  396. self.ui.Items.Layout_not_out:setVisible(false)
  397. return
  398. end
  399. --显示按钮时,清除一下自己出的牌
  400. self:clearPosShow(1)
  401. --[[if (is and (opFlag and opFlag > 0)) then--倒计时 --最后一手牌
  402. local cards = self:getHandCards()
  403. local ttp = PokerUtil:checkType(cards)
  404. local function __delay( onEnd )
  405. self.ui:runDelay(1, function() if onEnd and type(onEnd)=='function' then onEnd() end end)
  406. end
  407. local function __lastOut(onEnd)
  408. self:resetSelect()
  409. app.room:requestOutCards(cards)
  410. if onEnd and type(onEnd)=='function' then onEnd() end
  411. end
  412. if self._lastOutType==ttp then
  413. if ttp==ETS.LIAN_DUI or ttp==ETS.SHUN_ZI then--最后一手牌顺子连对保证牌数相等
  414. if #self._lastCards==#cards then
  415. self:addFunction(__lastOut)
  416. return
  417. end
  418. elseif ttp==ETS.AIRPLANE then--最后一手飞机校验
  419. if #self._lastCards>=#cards then
  420. self:addFunction(__lastOut)
  421. return
  422. end
  423. elseif ttp==ETS.SINGLE_CARD or ttp==ETS.DUI_ZI then--最后一手单张
  424. local result = PokerUtil:getTip(cards, self._lastCards)
  425. if result and #result > 0 then
  426. self:addFunction(__lastOut)
  427. return
  428. end
  429. end
  430. elseif self._lastOutType==0 then
  431. local can, handCards = self:checkOnceOut()
  432. if can then
  433. self:addFunction(__delay)
  434. self:addFunction(__lastOut)
  435. return
  436. end
  437. end
  438. else
  439. end--]]
  440. self.ui.Items.Layout_tip:setVisible(true)
  441. self.ui.Items.Layout_out:setVisible(true)
  442. self.ui.Items.Layout_not_out:setVisible(true)
  443. if opFlag == 2 then--第一首牌
  444. self.ui.Items.Layout_tip:setVisible(false)
  445. self.ui.Items.Layout_not_out:setVisible(false)
  446. elseif opFlag == 1 then
  447. self.ui.Items.Button_not_out:loadTextureNormal("pk_zgwrddz/res/ui/zy_wrddz_btns/wrddz_btn_buchu.png");
  448. elseif opFlag == 0 then
  449. self.ui.Items.Layout_tip:setVisible(false)
  450. self.ui.Items.Layout_out:setVisible(false)
  451. self.ui.Items.Button_not_out:loadTextureNormal("pk_zgwrddz/res/ui/zy_wrddz_btns/wrddz_btn_yaobuqi.png");
  452. end
  453. self.ui.Items.Layout_operating_menus:requestDoLayout()
  454. self.ui.Items.Layout_operating_menus:doLayout()
  455. self.curCanOpFlag = opFlag or 1 --0-pass 1-可以出牌也可以pass 2-只能出牌
  456. self:checkOutCardBtnEnabled()
  457. if opFlag == 1 then
  458. self.firstTip = true
  459. end
  460. --self.ui.Items.Button_tip:setVisible(is==true)
  461. --self.ui.Items.Button_out:setVisible(is==true)
  462. --self.ui.Items.Button_not_out:setVisible(is==true)
  463. --[[-- 自动提示
  464. if self._lastOutType>0 and is then
  465. local cards = self._lastCards
  466. if cards and #cards>0 then
  467. local handCards = self:getHandCards()
  468. local result = PokerUtil:getTip(handCards, cards)
  469. if result and #result > 0 then
  470. --local result2 = PokerUtil:getOnlyTip(handCards, cards)
  471. --if result2 then --有且只有一种提示 自动弹出牌
  472. -- self:tipCards(clone(result2))
  473. --end
  474. else
  475. result = {}
  476. end
  477. -- 计算不能出的牌
  478. local canotOuts = {}
  479. local tp = self._lastOutType
  480. if tp == ETS.SINGLE_CARD or (app.room.isMustBomb and app.room.isMustBomb == 1) then
  481. local bombs = PokerUtil:getAllBomb(handCards, isChoiceAAA)
  482. local node = self:getPlayerNodeVpos(2)
  483. if node then
  484. if node:isAlarm() then
  485. local max = result[1]
  486. for _,v in ipairs(result) do
  487. if v.val > max.val then
  488. max = v
  489. end
  490. end
  491. local tmpresult = {}
  492. if max and (max.val == 13 or max.val == 14) then--2和2王 这时候所有的2和王都要提示
  493. for _,v in ipairs(result) do
  494. if v.val >= 13 then
  495. table.insert(tmpresult,v)
  496. end
  497. end
  498. result = tmpresult
  499. else
  500. result = {max}
  501. end
  502. end
  503. end
  504. for _,v in pairs(bombs) do table.insert(result, 1, v) end
  505. canotOuts = PokerUtil:leftSingleCards(handCards, result)
  506. elseif tp == ETS.DUI_ZI or tp == ETS.SHUN_ZI or tp == ETS.LIAN_DUI or tp == ETS.THREE_AND_TWO
  507. 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
  508. local bombs = PokerUtil:getAllBomb(handCards, isChoiceAAA)
  509. for _,v in pairs(bombs) do table.insert(result, 1, v) end
  510. if tp == ETS.DUI_ZI or tp == ETS.SHUN_ZI or tp == ETS.LIAN_DUI then --飞机带的牌可以随意
  511. canotOuts = PokerUtil:leftCardsEx(handCards, result)
  512. end
  513. elseif tp == ETS.BOMB then
  514. end
  515. local donotTip = false
  516. if opFlag and opFlag == 0 then
  517. self:downCanotOuts(handCards, true)
  518. donotTip = true
  519. elseif #canotOuts>0 then
  520. if app.room.isMustBomb and app.room.isMustBomb == 1 then--出的牌有多种牌型可能时,所有牌都可以组合打出去
  521. canotOuts = {}
  522. elseif tp == ETS.SHUN_ZI then--是顺子且顺子里面有2,所有牌都可以组合打出去
  523. local tLastCards = PokerUtil:parseCards(self._lastCards)
  524. for i = #tLastCards,1,-1 do
  525. if tLastCards[i].val == 13 then
  526. canotOuts = {}
  527. break
  528. end
  529. end
  530. end
  531. self:downCanotOuts(canotOuts, true)
  532. end
  533. if result and #result > 0 and (not donotTip) then
  534. end
  535. end
  536. end--]]
  537. end
  538. function zgwrDdzRoomView:showMenu( is, flag )
  539. -- self.ui.Items.btnMenu.show = is==true
  540. -- if flag then
  541. -- self.panelMenu:setVisible(is==true)
  542. -- return
  543. -- end
  544. -- if is==true then
  545. -- self.panelMenu:setVisible(is==true)
  546. -- local actime = 0.08
  547. -- local leavAc = { cc.Spawn:create(cc.MoveTo:create(actime, self.LeavePos), cc.FadeIn:create(actime)) }
  548. -- local disbandAc = { cc.Spawn:create(cc.MoveTo:create(actime, self.DisbandPos), cc.FadeIn:create(actime)) }
  549. -- local settingAc = { cc.Spawn:create(cc.MoveTo:create(actime, self.SettingPos), cc.FadeIn:create(actime)) }
  550. -- local uplogAc = {cc.Spawn:create(cc.MoveTo:create(actime, self.RulePos), cc.FadeIn:create(actime)) }
  551. -- self.ui.Items.Button_Leave:runAction(cc.Sequence:create(leavAc))
  552. -- self.ui.Items.Button_Dismiss:runAction(cc.Sequence:create(disbandAc))
  553. -- self.ui.Items.Button_Set:runAction(cc.Sequence:create(settingAc))
  554. -- self.ui.Items.Button_rule:runAction(cc.Sequence:create(uplogAc))
  555. -- else
  556. -- local oPos = self.ui.Items.btnMenu:getPosition()
  557. -- local actime = 0.08
  558. -- local leavAc = cc.MoveTo:create(actime, oPos)
  559. -- self.ui.Items.Button_Leave:runAction(cc.Spawn:create(leavAc:clone(), cc.FadeOut:create(actime)))
  560. -- self.ui.Items.Button_Dismiss:runAction(cc.Spawn:create(leavAc:clone(), cc.FadeOut:create(actime)))
  561. -- self.ui.Items.Button_Set:runAction(cc.Spawn:create(leavAc:clone(), cc.FadeOut:create(actime)))
  562. -- 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)))
  563. -- end
  564. end
  565. -- 是否显示准备按钮
  566. function zgwrDdzRoomView:showSitdownBtn( is )
  567. if self._isGameOver and true == self._isGameOver then return end
  568. self.ui.Items.Button_Ready:setVisible(is == true)
  569. local playerNum = app.room:getPlayerNum()
  570. if playerNum ~= app.room:getRoomInfo().nMaxPlayCount then--房间人数未满
  571. self.ui.Items.Button_invite:setVisible(true)
  572. -- local invitePos = self.ui.Items.Button_invite:getPosition()
  573. -- if is then
  574. -- self.ui.Items.Button_invite:runAction(cc.MoveTo:create(0.2, self.ui.Items.Button_invite.oPos))
  575. -- self.ui.Items.Button_Ready:runAction(cc.MoveTo:create(0.2, self.ui.Items.Button_Ready.oPos))
  576. -- else
  577. -- if invitePos.x < 10 then
  578. -- self.ui.Items.Button_invite:stopAllActions()
  579. -- self.ui.Items.Button_invite:setPosition(self.ui.Items.Button_invite.oPos)
  580. -- self.ui.Items.Button_invite:runAction(cc.MoveTo:create(0.2, cc.p(10, invitePos.y)))
  581. -- end
  582. -- end
  583. else
  584. -- local readyPos = self.ui.Items.Button_Ready:getPosition()
  585. -- self.ui.Items.Button_Ready:stopAllActions()
  586. -- self.ui.Items.Button_Ready:runAction(cc.MoveTo:create(0.2, cc.p(10, readyPos.y)))
  587. end
  588. self:updateInviteClubButton()
  589. self:updateButtonPosition()
  590. end
  591. function zgwrDdzRoomView:updateButtonPosition()
  592. self.ui.Items.Button_Ready:getParent():setVisible(self.ui.Items.Button_Ready:isVisible())
  593. self.ui.Items.Button_invite:getParent():setVisible(self.ui.Items.Button_invite:isVisible())
  594. self.ui.Items.Button_Invite_Club:getParent():setVisible(self.ui.Items.Button_Invite_Club:isVisible())
  595. if isReviewVersion() then
  596. self.ui.Items.Button_invite:getParent():setVisible(false)
  597. self.ui.Items.Button_Invite_Club:getParent():setVisible(false)
  598. end
  599. self.ui.Items.Layout_Button:requestDoLayout()
  600. self.ui.Items.Layout_Button:doLayout()
  601. end
  602. function zgwrDdzRoomView:onClickButtonShowClub( sender )
  603. --[[local clubList = app.club_php.clubList
  604. if clubList and table.nums(clubList)>0 then
  605. local roomInfo = app.room:getRoomInfo()
  606. local infoT = json.decode(roomInfo.nGameInfo)
  607. local view = import("luaScript.Views.Club.ClubTable"):new(clubList[app.club_php.clubID], infoT.tableIdx)
  608. view:setAnchorPoint(cc.p(0.5, 0.5))
  609. app:showWaitDialog(view)
  610. else
  611. app.club_php:getClubList()
  612. end--]]
  613. playBtnEffect()
  614. if IS_USER_NEW_CLUB then
  615. openClub()
  616. else
  617. local clubList = app.club_php.clubList
  618. if clubList and table.nums(clubList) > 0 then
  619. --房间号
  620. local roomInfo = app.room:getRoomInfo()
  621. if roomInfo then
  622. --创建房间时传入的桌子下标
  623. local infoT = json.decode(roomInfo.nGameInfo)
  624. self.clubView = import("luaScript.Views.Club.ClubTable"):new(clubList[app.club_php.clubID], infoT.tableIdx)
  625. self.clubView:setAnchorPoint(cc.p(0.5, 0.5))
  626. app:showWaitDialog(self.clubView)
  627. end
  628. else
  629. --未找到茶馆列表数据时,请求茶馆列表(可能是断线重连)
  630. app.club_php:getClubList();
  631. end
  632. end
  633. end
  634. function zgwrDdzRoomView:onClickButtonRstComfirm( sender )
  635. playBtnEffect()
  636. -- 小结算
  637. local showFunc = function (msg)
  638. --[[if self.xiaojuView and (not tolua.isnull(self.xiaojuView)) then
  639. self.xiaojuView:setVisible(true)
  640. return
  641. end--]]
  642. if msg then
  643. local soundFlag = false
  644. if not sender then
  645. soundFlag = true
  646. end
  647. self.xiaojuView = import("pk_zgwrddz.luaScript.Views.Room.Sub.zgwrDdzGameResultView"):new(msg,soundFlag)
  648. self.xiaojuView:setAnchorPoint(cc.p(0.5, 0.5))
  649. app:showWaitDialog(self.xiaojuView)
  650. end
  651. end
  652. showFunc(self._resultMsg)
  653. end
  654. -- 显示GPS界面
  655. function zgwrDdzRoomView:showGpsView()
  656. if self.isRecordScene then return end--回放场景直接return
  657. logD("zgwrDdzRoomView:showGpsView()")
  658. playBtnEffect()
  659. local isGameStart = app.room:getRoomInfo().nGameStartCount > 0
  660. if self.gpsComponent then
  661. self.gpsComponent:showGpsView(isGameStart)
  662. end
  663. end
  664. -- 玩家点击房间详情
  665. function zgwrDdzRoomView:onClickButtonDetails( sender )
  666. playBtnEffect()
  667. self.ui.Items.Layout_Rule:setVisible(not self.ui.Items.Layout_Rule:isVisible())
  668. self.ui.Items.Layout_7:setVisible(self.ui.Items.Layout_Rule:isVisible())
  669. self.ui.Items.Button_rule:setVisible(not self.ui.Items.Layout_Rule:isVisible())
  670. self.ui.Items.Layout_Menu_1:setVisible(not self.ui.Items.Layout_Rule:isVisible())
  671. end
  672. -- 一键截屏
  673. function zgwrDdzRoomView:onClickButtonShot( sender )
  674. playBtnEffect()
  675. showScreenShot()
  676. end
  677. function zgwrDdzRoomView:onClickButtonMenu( sender )
  678. playBtnEffect()
  679. --self:showMenu(not sender.show)
  680. self.ui.Items.Layout_Menu_1:setVisible(not self.ui.Items.Layout_Menu_1:isVisible())
  681. self.ui.Items.Layout_7:setVisible(self.ui.Items.Layout_Menu_1:isVisible())
  682. self.ui.Items.Layout_Rule:setVisible(false)
  683. self.ui.Items.Button_rule:setVisible(true)
  684. end
  685. function zgwrDdzRoomView:onClickMenuOut( sender )
  686. -- self:showMenu(false)
  687. self.ui.Items.Layout_Rule:setVisible(false)
  688. self.ui.Items.Layout_7:setVisible(false)
  689. self.ui.Items.Layout_Menu_1:setVisible(false)
  690. self.ui.Items.Button_rule:setVisible(true)
  691. self.ui.Items.Layout_Rule:stopAllActions()
  692. end
  693. function zgwrDdzRoomView:onClickButtonLeave( sender )
  694. playBtnEffect()
  695. self:showMenu(false, true)
  696. self.ui:sendMsg(app.room, "callLeaveRequest")
  697. end
  698. function zgwrDdzRoomView:onClickButtonDismiss( sender )
  699. playBtnEffect()
  700. local function onClickOk()
  701. self:showMenu(false, true)
  702. app.room:requestDismissRoom(1)--发起解散
  703. end
  704. local function onClickCancel()
  705. end
  706. showConfirmDialog("确定要申请解散房间吗?", onClickOk, onClickCancel)
  707. end
  708. function zgwrDdzRoomView:onClickButtonSetting( sender )
  709. playBtnEffect()
  710. self:showMenu(false, true)
  711. local view = import("pk_zgwrddz.luaScript.Views.Room.Sub.zgwrDdzSettingView"):new()
  712. view:setAnchorPoint(cc.p(0.5, 0.5))
  713. app:showWaitDialog(view)
  714. end
  715. function zgwrDdzRoomView:onClickButtonUlog( sender )
  716. playBtnEffect()
  717. self:showMenu(false, true)
  718. local view = import("luaScript.Views.Room.UplogView"):new()
  719. view:setAnchorPoint(cc.p(0.5, 0.5))
  720. app:showWaitDialog(view)
  721. end
  722. function zgwrDdzRoomView:onClickButtonTip( sender, tag, tipShow )
  723. playBtnEffect()
  724. self:resetCardsPos()
  725. self:hideCanOutCards()
  726. self.firstTip = true
  727. self:checkOutCardBtnEnabled()
  728. do return end
  729. --获取开房参数
  730. local roomInfo = app.room:getRoomInfo()
  731. local gameInfo = roomInfo.nGameInfo or ""
  732. local ruleInfo = json.decode(gameInfo)
  733. --出牌提示
  734. local cards = self._lastCards
  735. if cards and #cards>0 then
  736. local tp = PokerUtil:checkType(cards)
  737. if tp >= ETS.NONE then
  738. return nil
  739. end
  740. -- showTooltip("提示牌型: " .. PokerUtil:getTypeString(tp))
  741. local handCards = self:getHandCards()
  742. if #handCards<=0 then return false end
  743. if tp == ETS.SINGLE_CARD then
  744. if sender._tipCards and #sender._tipCards>0 then
  745. local tmp = sender._tipCards[#sender._tipCards]
  746. if tmp[1] and type(tmp[1])=='table' then
  747. self:tipCards(clone(tmp))
  748. else
  749. self:tipCards({clone(tmp)})
  750. end
  751. table.remove(sender._tipCards, #sender._tipCards)
  752. if #sender._tipCards <= 0 then
  753. sender._tipCards = nil
  754. end
  755. else
  756. local result = PokerUtil:getTip(handCards, cards)
  757. if result and #result > 0 then else result = {} end
  758. -- 判断下家是否报单
  759. local node = self:getPlayerNodeVpos(2)
  760. if node then
  761. if node:isAlarm() then
  762. local max = result[1]
  763. for _,v in ipairs(result) do
  764. if v.val > max.val then
  765. max = v
  766. end
  767. end
  768. local tmpresult = {}
  769. if max.val == 13 or max.val == 14 then--2和2王 这时候所有的2和王都要提示
  770. for _,v in ipairs(result) do
  771. if v.val >= 13 then
  772. table.insert(tmpresult,v)
  773. end
  774. end
  775. result = tmpresult
  776. else
  777. result = {max}
  778. end
  779. end
  780. end
  781. local bombs = PokerUtil:getAllBomb(handCards, isChoiceAAA)
  782. local cds = {}
  783. for _,v in pairs(bombs) do
  784. table.insert(result, 1, v)
  785. end
  786. if #result <= 0 then return end
  787. sender._tipCards = clone(result)
  788. local tmp = sender._tipCards[#sender._tipCards]
  789. if tag then
  790. if #result>=1 then
  791. if tmp[1] and type(tmp[1])=='table' then
  792. self:tipCards(clone(tmp))
  793. else
  794. self:tipCards({clone(tmp)})
  795. end
  796. table.remove(sender._tipCards, #sender._tipCards)
  797. end
  798. else
  799. if tmp[1] and type(tmp[1])=='table' then
  800. self:tipCards(clone(tmp))
  801. else
  802. self:tipCards({clone(tmp)})
  803. end
  804. table.remove(sender._tipCards, #sender._tipCards)
  805. end
  806. end
  807. elseif tp == ETS.DUI_ZI or tp == ETS.SHUN_ZI or tp == ETS.LIAN_DUI or tp == ETS.THREE_AND_TWO
  808. or tp == ETS.THREE_AND_DUI or tp == ETS.THREE or tp == ETS.AIRPLANE or tp == ETS.AIRPLANE_TOW or tp == ETS.AIRPLANE_DUI then
  809. if sender._tipCards and #sender._tipCards>0 then
  810. self:tipCards(clone(sender._tipCards[#sender._tipCards]))
  811. table.remove(sender._tipCards, #sender._tipCards)
  812. if #sender._tipCards <= 0 then sender._tipCards = nil end
  813. else
  814. local result = PokerUtil:getTip(handCards, cards)
  815. if result and #result > 0 then else result = {} end
  816. local bombs = PokerUtil:getAllBomb(handCards, isChoiceAAA)
  817. for _,v in pairs(bombs) do table.insert(result, 1, v) end
  818. if #result <= 0 then return end
  819. sender._tipCards = clone(result)
  820. if tag then
  821. if #result >= 1 then
  822. self:tipCards(clone(sender._tipCards[#sender._tipCards]))
  823. table.remove(sender._tipCards, #sender._tipCards)
  824. end
  825. else
  826. self:tipCards(clone(sender._tipCards[#sender._tipCards]))
  827. table.remove(sender._tipCards, #sender._tipCards)
  828. end
  829. end
  830. elseif DdzRoomViewConfig.isBomb(tp) then
  831. if sender._tipCards and #sender._tipCards>0 then
  832. self:tipCards(clone(sender._tipCards[#sender._tipCards]))
  833. table.remove(sender._tipCards, #sender._tipCards)
  834. if #sender._tipCards <= 0 then sender._tipCards = nil end
  835. else
  836. local result = PokerUtil:getTip(handCards, cards)
  837. if result and #result > 0 then else return end
  838. sender._tipCards = clone(result)
  839. if tag then
  840. if #result >= 1 then
  841. self:tipCards(clone(sender._tipCards[#sender._tipCards]))
  842. table.remove(sender._tipCards, #sender._tipCards)
  843. end
  844. else
  845. self:tipCards(clone(sender._tipCards[#sender._tipCards]))
  846. table.remove(sender._tipCards, #sender._tipCards)
  847. end
  848. end
  849. else
  850. return nil
  851. end
  852. else--没有牌,第一手提示
  853. local handCards = self:getHandCards()
  854. if sender._tipCards and #sender._tipCards>0 then
  855. self:tipCards(clone(sender._tipCards[#sender._tipCards]))
  856. table.remove(sender._tipCards, #sender._tipCards)
  857. if #sender._tipCards <= 0 then sender._tipCards = nil end
  858. else
  859. local result = PokerUtil:getFirstTip(handCards)
  860. if result and #result > 0 then else return end
  861. sender._tipCards = clone(result)
  862. self:tipCards(clone(sender._tipCards[#sender._tipCards]))
  863. table.remove(sender._tipCards, #sender._tipCards)
  864. end
  865. end
  866. end
  867. -- 变暗不能出的牌
  868. function zgwrDdzRoomView:downCanotOuts(canotOuts, isTouch)
  869. for _,v in pairs(canotOuts) do
  870. local node = self:getCardNode(v)
  871. if node and (not tolua.isnull(node)) then
  872. node:setNormal()
  873. node:setNormalColor()
  874. node:setNoTouch(isTouch)
  875. end
  876. end
  877. local tmp = {}
  878. for _,v in pairs(self._selectCards) do
  879. if v and (not tolua.isnull(v)) and v:isDown() then
  880. table.insert(tmp, v)
  881. end
  882. end
  883. self._selectCards = tmp
  884. end
  885. --出牌
  886. function zgwrDdzRoomView:onClickButtonOut( sender )
  887. self:hideCanOutCards()
  888. playBtnEffect()
  889. local cards = self:getSelected()
  890. if #cards <= 0 then
  891. return showTooltip("请选择要出的牌")
  892. else
  893. local serverLastOuttype
  894. if app.room.lastOutType and app.room.lastOutType >0 and app.room.lastOutType < 100 then
  895. serverLastOuttype = app.room.lastOutType
  896. end
  897. local tp = PokerUtil:checkType(cards)
  898. if self._lastCards and #self._lastCards>0 then
  899. self._lastOutType = serverLastOuttype or PokerUtil:checkType(self._lastCards)
  900. end
  901. local isHaveGui,guiNum = PokerUtil:checkHaveGui1(cards)
  902. local isAllow = true
  903. if (self._lastOutType==tp or isHaveGui) or self._lastOutType==0 or DdzRoomViewConfig.isBomb(tp) or isAllow then
  904. -- 检测下家是否报单
  905. --获取自己的座位数据
  906. local myself = app.room:getMyself()
  907. local pdata = app.room:getPlayerVpos(myself.viewPos)
  908. logD("zgwrDdzRoomView:onClickButtonOut pdata = "..table.tostring(pdata))
  909. local node = self:getPlayerNode(pdata.userId)
  910. local isAlarm = node:isAlarm()
  911. --[[if isAlarm and #cards==1 and tp==ETS.SINGLE_CARD then
  912. -- 判断是否是最大单张
  913. if PokerUtil:isMaxCard(self:getHandCards(), cards[1]) then
  914. app.room:requestOutCards(cards)
  915. else
  916. return showTooltip("报单必须出最大牌")
  917. end
  918. else--]]
  919. if isHaveGui then
  920. app.room:requestGetOutCards(cards)
  921. else
  922. app.room:requestOutCards(cards)
  923. end
  924. --end
  925. else
  926. return showTooltip("选择的牌型错误")
  927. end
  928. end
  929. end
  930. function zgwrDdzRoomView:onClickButtonNotOut( sender )
  931. local cards = {}
  932. app.room:requestOutCards(cards)
  933. end
  934. function zgwrDdzRoomView:onClickButtonReady( sender )
  935. playBtnEffect()
  936. self.ui:sendMsg(app.room, "callReadyRequestPdk")
  937. --[[local test = {
  938. ["bankerSeat"] = 1,
  939. --["cardPlayerInfo"] = {"1":2,"10":0,"11":3,"12":1,"13":3,"2":2,"3":2,"4":3,"5":3,"6":3,"7":2,"8":3,"9":1},
  940. ["cards"] = {
  941. [1] = 29,
  942. [2] = 11,
  943. [3] = 27,
  944. [4] = 9,
  945. [5] = 7,
  946. [6] = 6,
  947. [7] = 22,
  948. [8] = 37,
  949. [9] = 4,
  950. [10] = 20,
  951. [11] = 51,
  952. [12] = 2,
  953. [13] = 34,
  954. [14] = 11,
  955. [15] = 27,
  956. [16] = 9,
  957. [17] = 7,
  958. [18] = 6,
  959. [19] = 22,
  960. [20] = 37,
  961. [21] = 4,
  962. [22] = 20,
  963. [23] = 51,
  964. [24] = 2,
  965. [25] = 34,
  966. },
  967. ["userId"] = 1040236,
  968. }
  969. self:sendCards(test.cards)--]]
  970. end
  971. function zgwrDdzRoomView:getInviteData()
  972. local strNames = ""
  973. local index = 0
  974. local num = app.room:getPlayerNum()
  975. for k,v in pairs(app.room:getPlayers()) do
  976. index = index + 1
  977. local name = getSubStringNickname(v.nickname)
  978. strNames = strNames..name
  979. if index < num then strNames = strNames.."," end
  980. end
  981. local roomInfo = app.room:getRoomInfo()
  982. local invitePtr = DdzRoomViewConfig.InviteConfig[roomInfo.nMaxPlayCount][num]--几缺几
  983. local strGameMode = WRDDZDefine.getWanFaInfo(roomInfo.nGameInfo)
  984. local strGameNum = string.format("%s局", roomInfo.nTotalGameNum)
  985. local desc = string.format("%s,%s 玩家:%s", strGameNum, strGameMode, strNames)
  986. print("pdk_invite : ",desc)
  987. local title = string.format("五人斗地主 房号[%s] %s", roomInfo.nShowTableId, invitePtr )
  988. if app.club_php.clubID and app.club_php.clubID~=0 then
  989. title = string.format("%s 茶馆ID[%d]", title, tonumber(app.club_php.clubID))
  990. end
  991. print("pdk_invite : ", title)
  992. return title,desc
  993. end
  994. --邀请好友
  995. function zgwrDdzRoomView:onClickButtonInvite( sender )
  996. playBtnEffect()
  997. --[[local strNames = ""
  998. local index = 0
  999. local num = app.room:getPlayerNum()
  1000. for k,v in pairs(app.room:getPlayers()) do
  1001. index = index + 1
  1002. local name = getSubStringNickname(v.nickname)
  1003. strNames = strNames..name
  1004. if index < num then strNames = strNames.."," end
  1005. end
  1006. local roomInfo = app.room:getRoomInfo()
  1007. local invitePtr = DdzRoomViewConfig.InviteConfig[roomInfo.nMaxPlayCount][num]--几缺几
  1008. local strGameMode = DdzRoomViewConfig.getRuleString(roomInfo.nGameInfo)
  1009. local strGameNum = string.format("%s局", roomInfo.nTotalGameNum)
  1010. local desc = string.format("%s,%s 玩家:%s", strGameNum, strGameMode, strNames)
  1011. print("pdk_invite : ",desc)
  1012. local title = string.format("欢乐跑得快 房号[%s] %s", roomInfo.nShowTableId, invitePtr )
  1013. if app.club_php.clubID and app.club_php.clubID~=0 then
  1014. title = string.format("%s 茶馆ID[%d]", title, tonumber(app.club_php.clubID))
  1015. end
  1016. print("pdk_invite : ", title)--]]
  1017. local title,desc = self:getInviteData()
  1018. local imagePath = cc.FileUtils:getInstance():getWritablePath().."icon.png"
  1019. --[[ local info = {}
  1020. info.scene = "talk"
  1021. info.contentType = "url"
  1022. info.url = app.config.Setting.appDownloadUrl
  1023. info.title = title
  1024. info.description = desc
  1025. info.image = imagePath
  1026. info.imageWidth = 100
  1027. app.plugin:shareGame(info)--]]
  1028. local info = {}
  1029. info.title = title
  1030. info.description = desc
  1031. info.copyData={type=2}
  1032. local view = import("luaScript.Views.Main.ShareView"):new(info)
  1033. view:setAnchorPoint(cc.p(0.5, 0.5))
  1034. app:showWaitDialog(view)
  1035. end
  1036. function zgwrDdzRoomView:onClickCopy()
  1037. playBtnEffect()
  1038. local title,desc = self:getInviteData()
  1039. local clubData = ""
  1040. if app.club_php.clubID and app.club_php.clubID ~= 0 then
  1041. local clubName = ""
  1042. local clubList = app.club_php.clubList
  1043. if clubList and table.nums(clubList) > 0 then
  1044. clubName = clubList[tonumber(app.club_php.clubID)].clubName;
  1045. end
  1046. clubData = string.format("茶馆名:%s \n", clubName)
  1047. end
  1048. local tishi = "复制信息打开游戏将自动入座\n<仅供娱乐,严禁赌博>"
  1049. copyData = string.format("%s%s\n%s\n%s",clubData,title,desc,tishi)
  1050. logD(copyData)
  1051. copyStringToClipboard(copyData)
  1052. app.plugin:gotoWeiXin()
  1053. end
  1054. -- 恢复自己手牌
  1055. function zgwrDdzRoomView:recoverHandcards(_cards)
  1056. logD("zgwrDdzRoomView:recoverHandcards:", table.tostring(_cards))
  1057. self:cleanSelfCards()
  1058. local cards = pokerSortPdkCards(_cards)
  1059. local pos = 1
  1060. local allCount = #cards
  1061. for i,card in ipairs(cards) do
  1062. self:sendOneCardNoAct(card.cid, i, pos, i==allCount, allCount)
  1063. end
  1064. self:resetCardsPos()
  1065. end
  1066. --[[WRDDZRoomConfig.GameStatus = {
  1067. GAME_STATE_INIT =0, --游戏初始状态
  1068. GAME_STATUS_WAIT_BANKER_START =1, --等待庄家开始游戏
  1069. GAME_STATUS_WAITTING =2, --等待中
  1070. GAME_STATUS_READALL =3, --所有玩家准备
  1071. GAME_STATUS_SHUFFLE =4, --洗牌中
  1072. GAME_STATUS_SENDCARDS =5, --发牌阶段
  1073. GAME_STATUS_ASK_LOARD =6, --叫地主
  1074. GAME_STATUS_ASK_DOUBLE =7, --加倍状态
  1075. GAME_STATUS_SELECT_CARD =8, --选牌(暗地主)
  1076. GAME_STATUS_PLAYING =9, --开始游戏出牌
  1077. GAME_STATE_ROUND_OVER =10, --小局结束
  1078. GAME_STATE_GAME_OVER =11, --大局结束
  1079. }--]]
  1080. --断线重连
  1081. function zgwrDdzRoomView:onGameReconnection( data )
  1082. local roomInfo = app.room:getRoomInfo()
  1083. --self:checkGpsDistance(nil,roomInfo.nGameStartCount==0)
  1084. --self:checkMyGpsNeedUpdate();
  1085. if roomInfo.nGameStartCount==0 then
  1086. local tmpPosData = {}
  1087. tmpPosData.players = {}
  1088. for _,pdata in ipairs(roomInfo.recoverItem) do
  1089. table.insert(tmpPosData.players,{nUserId = pdata.userId,nSeatId = pdata.seatId})
  1090. end
  1091. self:onUpdatePlayerPos({response = tmpPosData})
  1092. end
  1093. -- 当前操作玩家
  1094. local curOpUserId = -1
  1095. local tmpData = {}
  1096. for _,pdata in ipairs(roomInfo.recoverItem) do
  1097. tmpData[pdata.userId] = pdata
  1098. local player = app.room:getPlayer(pdata.userId)
  1099. local node = self:getPlayerNode(pdata.userId)
  1100. if not node then
  1101. self:addPlayerNode(player)
  1102. else
  1103. node:setHost(false)
  1104. node:setAnDiZhu(false)
  1105. node:cleanPass()
  1106. node:setTurn(false)
  1107. node:setScoreNoAnim(pdata.totalScore)
  1108. node:setBanker(pdata.seatId==roomInfo.reBankerId)
  1109. node:setOffline(pdata.onlineStatus==0)
  1110. node:setReady(pdata.playFlag==1)
  1111. end
  1112. if pdata.isCanOp==1 then
  1113. curOpUserId = pdata.userId
  1114. end
  1115. end
  1116. if roomInfo.bUserDisbandGame == 1 then --房间是否是解散状态
  1117. app.room:dispatchEvent({name = "pdkNormalEvent_show_dissmiss_over"})
  1118. -- 其他玩家的解散状态
  1119. local dismissInfo = {}
  1120. local list = {}
  1121. for i,v in ipairs(roomInfo.recoverItem) do
  1122. dismissInfo[v.userId] = v.disbandStatus
  1123. local l = {}
  1124. l.nUserId = v.userId
  1125. l.dismissState = v.disbandStatus
  1126. table.insert(list, l)
  1127. end
  1128. app.room.dismissInfo = dismissInfo
  1129. local response = {}
  1130. response.memberList = list
  1131. response.timeLeft = roomInfo.leftTimeOut
  1132. response.operateType = 1
  1133. self:onDismissResponse({response=response})
  1134. end
  1135. --恢复托管状态
  1136. self:refreshPlayerAIStatus()
  1137. self._isLorder = false
  1138. self._isDarkLorder = false
  1139. local myself = app.room:getMyself()
  1140. if myself.playFlag==1 then--准备状态return
  1141. return
  1142. end
  1143. if roomInfo.gameStatus >= DdzRoomViewConfig.GameStatus.GAME_STATUS_ASK_LOARD and
  1144. roomInfo.gameStatus <= DdzRoomViewConfig.GameStatus.GAME_STATE_ROUND_OVER then
  1145. -- 离开房间不可点击
  1146. self.ui.Items.Button_Leave:setEnabled(false)
  1147. self.ui.Items.Layout_Leave:setEnabled(false)
  1148. if app.room:isMyself(roomInfo.nLordId) then
  1149. self._isLorder = true
  1150. end
  1151. if app.room:isMyself(roomInfo.nDarkLordId) then
  1152. self._isDarkLorder = true
  1153. end
  1154. --自己是否知道暗地主玩家
  1155. self.isKnowDarkLord = false
  1156. for _,pdata in ipairs(roomInfo.recoverItem) do
  1157. if app.room:isMyself(pdata.userId) then
  1158. self.isKnowDarkLord = pdata.bKnowDarkLord == 1
  1159. end
  1160. end
  1161. for _,pdata in ipairs(roomInfo.recoverItem) do
  1162. local player = app.room:getPlayer(pdata.userId)
  1163. self:clearPosShow(player.viewPos)
  1164. local node = self:getPlayerNode(pdata.userId)
  1165. if app.room:isMyself(pdata.userId) then
  1166. self:recoverHandcards(pdata.handCards)
  1167. if node then node:showLeft(#pdata.handCards) end
  1168. else
  1169. if node then
  1170. node:showLeft(#pdata.handCards)
  1171. node:setOffline(pdata.onlineStatus==0)
  1172. end
  1173. end
  1174. if node then
  1175. node:setScore(pdata.totalScore)
  1176. if pdata.userId == roomInfo.nLordId then
  1177. node:setFanMult(pdata.nMult == 1)
  1178. else
  1179. node:setMult(pdata.nMult == 1)
  1180. end
  1181. end
  1182. if pdata.userId == roomInfo.nDarkLordId and self.isKnowDarkLord then
  1183. node:setAnDiZhu(true)
  1184. end
  1185. if pdata.userId == roomInfo.nLordId then
  1186. node:setHost(true)
  1187. end
  1188. end
  1189. self.ui.Items.TextBMFont_beishu:setText(roomInfo.nHMIShowMult or "1")
  1190. self.ui.Items.TextBMFont_difen:setText("1")
  1191. if roomInfo.gameStatus == DdzRoomViewConfig.GameStatus.GAME_STATUS_ASK_LOARD then--叫地主阶段
  1192. for _,pdata in ipairs(roomInfo.recoverItem) do
  1193. local node = self:getPlayerNode(pdata.userId)
  1194. if pdata.bAskedLord == 1 then--等待叫地主
  1195. if app.room:isMyself(pdata.userId) then
  1196. self:showJiaoDiZhu()
  1197. end
  1198. if node then
  1199. node:setTurn(true)
  1200. end
  1201. elseif pdata.bAskedLord == 2 then--操作过叫地主
  1202. if node then
  1203. node:showJiaoDiZhu(false)
  1204. end
  1205. end
  1206. end
  1207. elseif roomInfo.gameStatus == DdzRoomViewConfig.GameStatus.GAME_STATUS_ASK_DOUBLE then--加倍状态
  1208. self:showDiPai(roomInfo.diCards)
  1209. --自己是否操作过
  1210. local selfIsOp = false
  1211. --0:未操作加倍,1:等待加倍,2:操作过加倍
  1212. for _,pdata in ipairs(roomInfo.recoverItem) do
  1213. local node = self:getPlayerNode(pdata.userId)
  1214. if pdata.bAskDouble == 1 then--等待加倍
  1215. if app.room:isMyself(pdata.userId) then
  1216. if roomInfo.nLordId and (pdata.userId == roomInfo.nLordId) then
  1217. self:showFanJiaBei()
  1218. else
  1219. self:showJiaBei()
  1220. end
  1221. end
  1222. if node then
  1223. node:setTurn(true)
  1224. end
  1225. elseif pdata.bAskDouble == 2 then--操作过加倍
  1226. if node then
  1227. if roomInfo.nLordId and (pdata.userId == roomInfo.nLordId) then
  1228. node:showFanJiaBei(pdata.nMult == 1)
  1229. else
  1230. node:showJiaBei(pdata.nMult == 1)--0不加倍1加倍
  1231. end
  1232. if roomInfo.nLordId and pdata.userId == roomInfo.nLordId then
  1233. node:setFanMult(pdata.nMult == 1)
  1234. else
  1235. node:setMult(pdata.nMult == 1)
  1236. end
  1237. end
  1238. if app.room:isMyself(pdata.userId) then
  1239. selfIsOp = true
  1240. end
  1241. end
  1242. end
  1243. if selfIsOp then
  1244. self:showBgTips(true,7)
  1245. end
  1246. elseif roomInfo.gameStatus == DdzRoomViewConfig.GameStatus.GAME_STATUS_SELECT_CARD then--选牌(暗地主)
  1247. self:showDiPai(roomInfo.diCards)
  1248. if app.room:isMyself(roomInfo.nLordId) then
  1249. self:showXuanAnDiZhu()
  1250. self:setSelectAnLordCard()
  1251. --检测选牌是否可点
  1252. self:checkSelectCardBtnEnabled()
  1253. else
  1254. self:showBgTips(true,0)
  1255. end
  1256. local node = self:getPlayerNode(roomInfo.nLordId)
  1257. node:setTurn(true)
  1258. elseif roomInfo.gameStatus == DdzRoomViewConfig.GameStatus.GAME_STATUS_PLAYING then--玩牌中
  1259. self:showDiPai(roomInfo.diCards)
  1260. self:showAnDiZhuCard(roomInfo.nDarkLordCard)
  1261. local startViewPos = 0
  1262. local endViewPos = 0
  1263. if roomInfo.lastOpUid > 0 and #roomInfo.lastOutCards > 0 then
  1264. local node = self:getPlayerNode(roomInfo.lastOpUid)
  1265. node:setLastOp(roomInfo.lastOpType, roomInfo.lastOutCards,nil,roomInfo.lastShowDzFlag)
  1266. startViewPos = node:getInfo().viewPos
  1267. self._lastOutPos = startViewPos
  1268. self._lastOutType = roomInfo.lastOpType
  1269. app.room.lastOutType = roomInfo.lastOpType
  1270. self._lastCards = roomInfo.lastOutCards
  1271. end
  1272. --当前出牌者
  1273. if app.room:isMyself(roomInfo.curOpUid) then
  1274. self:showTurnBtn(true, roomInfo.curOpType,roomInfo.curOpType)--能否出牌
  1275. end
  1276. local node = self:getPlayerNode(roomInfo.curOpUid)
  1277. node:setTurn(true, 10)
  1278. endViewPos = node:getInfo().viewPos
  1279. if endViewPos == 1 then endViewPos = 6 end
  1280. if startViewPos > 0 then
  1281. for i = startViewPos + 1 ,endViewPos-1 do
  1282. local node = self:getPlayerNodeVpos(i)
  1283. if node then
  1284. node:showPass()
  1285. end
  1286. end
  1287. end
  1288. elseif roomInfo.gameStatus == DdzRoomViewConfig.GameStatus.GAME_STATE_ROUND_OVER then--需要判断是否已经有单局结算页面
  1289. self:showSitdownBtn(false)
  1290. self:showDiPai(roomInfo.diCards)
  1291. self:showAnDiZhuCard(roomInfo.nDarkLordCard)
  1292. if roomInfo.lastOpUid > 0 and #roomInfo.lastOutCards > 0 then
  1293. local node = self:getPlayerNode(roomInfo.lastOpUid)
  1294. node:setLastOp(roomInfo.lastOpType, roomInfo.lastOutCards,nil,roomInfo.lastShowDzFlag)
  1295. self._lastOutType = roomInfo.lastOpType
  1296. app.room.lastOutType = roomInfo.lastOpType
  1297. self._lastCards = roomInfo.lastOutCards
  1298. end
  1299. self.ui.Items.Button_Leave:setEnabled(false)
  1300. self.ui.Items.Layout_Leave:setEnabled(false)
  1301. local response = {}
  1302. response.gameStartCount = roomInfo.nGameStartCount
  1303. response.totalGamenum = roomInfo.nTotalGameNum
  1304. local players = {}
  1305. for i,v in ipairs(roomInfo.recoverItem) do
  1306. local p = {}
  1307. p.userId = v.userId
  1308. p.turnScore = v.turnScore
  1309. p.totalScore = v.totalScore
  1310. if v.userId ~= roomInfo.nDarkLordId then
  1311. p.isMult = v.nMult
  1312. end
  1313. p.leftNum = #v.handCards
  1314. p.handCards = v.handCards
  1315. p.groupCardInfo = v.groupCardInfo
  1316. p.allBombTimes = v.allBombTimes
  1317. table.insert(players, p)
  1318. local player = app.room:getPlayer(p.userId)
  1319. local playerNode = self:getPlayerNode(player.userId)
  1320. if #v.handCards>0 and player then
  1321. self:showLeftCards(player.viewPos, v.handCards or {})
  1322. end
  1323. end
  1324. response.players = players
  1325. --小局信息
  1326. response.winUserId = roomInfo.winUserId
  1327. response.lordId = roomInfo.nLordId
  1328. response.darkId = roomInfo.nDarkLordId
  1329. response.baseMult = roomInfo.nBaseMult
  1330. response.curMult = roomInfo.nGameCurMult
  1331. response.fourMult = roomInfo.fourBomb
  1332. response.twoKMult = roomInfo.twoKingBomb
  1333. response.eightMult = roomInfo.eightBomb
  1334. response.fourKMult = roomInfo.fourKingBomb
  1335. response.twelveMult = roomInfo.twelveBomb
  1336. response.sixKMult = roomInfo.sixKingBomb
  1337. response.spring = roomInfo.spring
  1338. response.isSelfEat = roomInfo.isSelfEat
  1339. response.leftCards = {}
  1340. self:showGameResultRecover({response=response})
  1341. self:showOtherCards(false)
  1342. end
  1343. end
  1344. self.ui.Items.Button_invite:setVisible(app.room:getPlayerNum() ~= roomInfo.nMaxPlayCount)
  1345. self:updateInviteClubButton()
  1346. self:updateButtonPosition()
  1347. end
  1348. function zgwrDdzRoomView:updateInviteClubButton()
  1349. if app.club_php.clubID and app.club_php.clubID~=0 then
  1350. local roomInfo = app.room:getRoomInfo()
  1351. if roomInfo.nGameStartCount==0 and table.nums(roomInfo.memberList)<roomInfo.nMaxPlayCount then
  1352. self.ui.Items.Button_Invite_Club:setVisible(true)
  1353. else
  1354. self.ui.Items.Button_Invite_Club:setVisible(false)
  1355. end
  1356. end
  1357. if isReviewVersion() then
  1358. self.ui.Items.Button_invite:getParent():setVisible(false)
  1359. self.ui.Items.Button_Invite_Club:getParent():setVisible(false)
  1360. end
  1361. end
  1362. -- 小局结算
  1363. function zgwrDdzRoomView:showGameResultRecover( data )
  1364. -- if self._gameResult then return false end--避免断线重连弹出多个小结算
  1365. local msg = data.response
  1366. local maxCards = 0
  1367. for _,v in pairs(msg.players) do
  1368. local node = self:getPlayerNode(v.userId)
  1369. if node then node:setScore(v.totalScore,false) end
  1370. node:hideLeft()
  1371. v.leftCards = v.leftCards or {}
  1372. if #v.leftCards > maxCards then maxCards = #v.leftCards end
  1373. local pdata = app.room:getPlayer(v.userId)
  1374. v.unionid = pdata.unionid
  1375. v.headimgurl = pdata.headimgurl
  1376. v.gpsInfo = pdata.gpsInfo
  1377. v.sex = pdata.sex
  1378. v.openid = pdata.openid
  1379. v.nickname = pdata.nickname
  1380. v.areano = pdata.areano
  1381. end
  1382. --是不是最后一局
  1383. local roomInfo = app.room:getRoomInfo()
  1384. msg.isLast = roomInfo.nGameStartCount==roomInfo.nTotalGameNum
  1385. msg.ruleString = WRDDZDefine.getWanFaInfo(roomInfo.nGameInfo)
  1386. self._resultMsg = msg
  1387. self._resultMsg.players = msg.players
  1388. self._resultMsg.isLast = msg.isLast
  1389. self._resultMsg.ruleString = msg.ruleString or ""
  1390. self._resultMsg.gameStartCount = msg.gameStartCount
  1391. self._resultMsg.totalGamenum = msg.totalGamenum
  1392. -- -- 小结算
  1393. local showFunc = function ()
  1394. for _,v in pairs(self._playerNodes) do
  1395. v:hideLeft()
  1396. end
  1397. self:showRstComfirm(true)
  1398. self:onClickButtonRstComfirm()
  1399. end
  1400. self._gameResult = true
  1401. --中途恢复直接展示
  1402. -- showLeftFunc()
  1403. showFunc()
  1404. end
  1405. function zgwrDdzRoomView:bindEvents()
  1406. self:bindEvent(app.room , "onUserExitResponseRoom" , handler(self , self.onUserExitResponseRoom))
  1407. --onDismissResponse
  1408. self:bindEvent(app.room , "onDismissResponse" , handler(self , self.onDismissResponse))
  1409. -- 其他玩家进入房间
  1410. self:bindEvent(app.room , "onResponseBroadcastLogin" , handler(self , self.onResponseBroadcastLogin))
  1411. -- 玩家离开房间
  1412. self:bindEvent(app.room , "onResponseBroadcastLogout" , handler(self , self.onResponseBroadcastLogout))
  1413. -- 玩家准备
  1414. self:bindEvent(app.room , "onResponseUserReady" , handler(self , self.onResponseUserReady))
  1415. -- 游戏开始
  1416. self:bindEvent(app.room , "onResponseGameStart" , handler(self , self.onResponseGameStart))
  1417. -- 给玩家发牌
  1418. self:bindEvent(app.room , "onResponseSendCards" , handler(self , self.onResponseSendCards))
  1419. -- 玩家出牌成功
  1420. self:bindEvent(app.room , "onResponseOutCards" , handler(self , self.onResponseOutCards))
  1421. -- 玩家出牌错误
  1422. self:bindEvent(app.room , "onResponseOutCardsErr" , handler(self , self.onResponseOutCardsErr))
  1423. -- 单局结算
  1424. self:bindEvent(app.room , "onResponseGameResult" , handler(self , self.onResponseGameResult))
  1425. -- 总结算
  1426. self:bindEvent(app.room , "onResponseGameOver" , handler(self , self.onResponseGameOver))
  1427. -- 玩家离线
  1428. self:bindEvent(app.room , "onOtherDroppedResponse" , handler(self , self.onOtherDroppedResponse))
  1429. -- 游戏设置里更换桌面
  1430. self:bindEvent(app.room , "pdkNormalEvent_changeDesktop" , handler(self , self.onNormalChangeDesktop))
  1431. -- 服务器通知更新当前玩家分数
  1432. self:bindEvent(app.room , "onResponseUpdateScore" , handler(self , self.onResponseUpdateScore))
  1433. -- 显示大结算
  1434. self:bindEvent(app.room , "ddzNormalEvent_show_game_over" , handler(self , self.onNormalShowGameOver))
  1435. -- 断线重连
  1436. self:bindEvent(app.room , "onResponseGameRecover" , handler(self , self.onGameReconnection))
  1437. -- 玩家请求快速开始广播
  1438. self:bindEvent(app.room , "onBroadcastFastRequest", handler(self, self.onBroadcastFaststart))
  1439. -- 快速开始成功
  1440. self:bindEvent(app.room , "onFastStartSucc", handler(self, self.onFastStartSucc))
  1441. --监听从后台进入游戏事件
  1442. self:bindEvent(app, "applicationWillEnterForeground", handler(self, self.onApplicationWillEnterForeground))
  1443. -- 玩家的GPS信息发生变化
  1444. self:bindEvent(app.room , "onGpsChangeResponse" , handler(self , self.onGpsChangeResponse));
  1445. -- 游戏状态改变
  1446. self:bindEvent(app.room , "onUpdateGameStatus" , handler(self , self.onUpdateGameStatus));
  1447. -- 通知玩家抢地主
  1448. self:bindEvent(app.room , "onNoticeGrabLord" , handler(self , self.onNoticeGrabLord));
  1449. -- 无人抢地主重新洗牌
  1450. self:bindEvent(app.room , "onShuffleCards" , handler(self , self.onShuffleCards));
  1451. -- 广播抢地主结果
  1452. self:bindEvent(app.room , "onBroadGrabLordResult" , handler(self , self.onBroadGrabLordResult));
  1453. -- 将底牌发给地主
  1454. self:bindEvent(app.room , "onSendDiCardsToLord" , handler(self , self.onSendDiCardsToLord));
  1455. -- 通知玩家加倍
  1456. self:bindEvent(app.room , "onBroadNoticeDouble" , handler(self , self.onBroadNoticeDouble));
  1457. -- 玩家加倍结果
  1458. self:bindEvent(app.room , "onAddMultResult" , handler(self , self.onAddMultResult));
  1459. -- 广播地主选牌(暗地主)
  1460. self:bindEvent(app.room , "onBroadLordSelectCard" , handler(self , self.onBroadLordSelectCard));
  1461. -- 广播玩家选牌结果
  1462. self:bindEvent(app.room , "onLordSelectCardResult" , handler(self , self.onLordSelectCardResult));
  1463. -- 告知暗地主玩家
  1464. self:bindEvent(app.room , "onNoticeAnLordPlayer" , handler(self , self.onNoticeAnLordPlayer));
  1465. -- 服务器通知当前玩家轮次
  1466. self:bindEvent(app.room , "onResponseUpdateTurns" , handler(self , self.onResponseUpdateTurns))
  1467. -- 获取出牌的牌组
  1468. self:bindEvent(app.room , "onGetOutCardsResult" , handler(self , self.onGetOutCardsResult))
  1469. -- 广播游戏倍数变化
  1470. self:bindEvent(app.room , "onUpdateGameMult" , handler(self , self.onUpdateGameMult))
  1471. -- 玩家获取手牌
  1472. self:bindEvent(app.room , "onGetUserCards" , handler(self , self.onGetUserCards))
  1473. -- 关闭互斥界面
  1474. self:bindEvent(app, "onCloseRoomMutexView", handler(self, self.onCloseRoomMutexView));
  1475. -- 托管回复
  1476. self:bindEvent(app.room , 'onHostingResponse', handler(self, self.onHostingResponse))
  1477. end
  1478. function zgwrDdzRoomView:onCloseRoomMutexView()
  1479. self:onClickMenuOut()
  1480. end
  1481. function zgwrDdzRoomView:onNormalChangeDesktop( data )
  1482. if data.idx >4 and data.idx<1 then return end
  1483. self.ui.Items.ImageView_bg:loadTexture(string.format("pk_zgwrddz/res/ui/zy_game/wrddr_gamebg_%d.jpg", data.idx), 0)
  1484. self:initLogo()
  1485. end
  1486. function zgwrDdzRoomView:initLogo ()
  1487. -- 水印
  1488. if not (type(getSubGameRoomLogo) == 'function') then--大厅不支持此方法,则隐藏logo
  1489. self.ui.Items.ImageView_logo:setVisible(false);
  1490. return
  1491. end
  1492. local logofile = getSubGameRoomLogo(GAME_IDS.zgWuRenDouDiZhu,1)
  1493. if logofile then
  1494. self.ui.Items.ImageView_logo:loadTexture(logofile)
  1495. self.ui.Items.ImageView_logo:setVisible(true);
  1496. else
  1497. self.ui.Items.ImageView_logo:setVisible(false);
  1498. end
  1499. end
  1500. -- 服务器通知玩家分数
  1501. function zgwrDdzRoomView:onResponseUpdateScore( data )
  1502. local msg = data.response
  1503. for _,pdata in ipairs(msg.players) do
  1504. local node = self:getPlayerNode(pdata.userId)
  1505. if node then node:setScore(pdata.totalScore) end
  1506. end
  1507. end
  1508. -- 玩家掉线
  1509. function zgwrDdzRoomView:onOtherDroppedResponse( data )
  1510. local msg = data.response
  1511. local node = self:getPlayerNode(msg.nUserId)
  1512. local pdata = app.room:getPlayer(msg.nUserId)
  1513. if node and pdata then
  1514. if msg.nDroppedStatus == 0 then
  1515. node:setOffline(true)
  1516. pdata.onlineStatus = 0
  1517. elseif msg.nDroppedStatus == 1 then
  1518. node:setOffline(false)
  1519. pdata.onlineStatus = 1
  1520. end
  1521. end
  1522. end
  1523. function zgwrDdzRoomView:onUserExitResponseRoom( data )
  1524. local function _exit( onEnd )
  1525. local response = data.response -- 0: 不退出(回到子游戏), 1: 退出(回到大厅)
  1526. if not self._isGameOver then
  1527. if response.logoutFlag == 1 then
  1528. app:gotoView(import("luaScript.Views.Main.MainView"):new(GAME_IDS.zgWuRenDouDiZhu))
  1529. else
  1530. app:gotoView(import("luaScript.Views.Main.MainView"):new(GAME_IDS.zgWuRenDouDiZhu))
  1531. end
  1532. end
  1533. if onEnd and type(onEnd)=='function' then onEnd() end
  1534. end
  1535. self:addFunction(_exit)
  1536. end
  1537. function zgwrDdzRoomView:onDismissResponse( data )
  1538. local __dis = function (onEnd)
  1539. local response = data.response
  1540. app.room:getRoomInfo().nDismissStateTime = response.timeLeft --剩余时间
  1541. app.room:getRoomInfo().nDismissToTalTime = app.room:getRoomInfo().nDisbandTimeout or 60 --总的时间
  1542. --显示解散(此标志会影响闹钟时间会冻住)
  1543. app.room:getRoomInfo().nShowDismiss = true
  1544. if response.operateType == 1 then
  1545. if response.memberList ~= nil then
  1546. for k,v in pairs(response.memberList) do
  1547. if v.dismissState == 1 then
  1548. --local view = import("pk_zgwrddz.luaScript.Views.Room.Sub.zgwrDdzDismissView"):new(v.nUserId)
  1549. local view = require("luaScript.Views.Room.RoomDismissView"):new(v.nUserId,app.room.roomInfo.memberList,response.timeLeft)
  1550. view:setAnchorPoint(cc.p(0.5, 0.5))
  1551. app:showWaitDialog(view)
  1552. return
  1553. end
  1554. end
  1555. else
  1556. --local view = import("pk_zgwrddz.luaScript.Views.Room.Sub.zgwrDdzDismissView"):new(response.nUserId)
  1557. local view = require("luaScript.Views.Room.RoomDismissView"):new(response.nUserId,app.room.roomInfo.memberList,response.timeLeft)
  1558. view:setAnchorPoint(cc.p(0.5, 0.5))
  1559. app:showWaitDialog(view)
  1560. end
  1561. else
  1562. local memberStatus={}
  1563. if response.memberList ~= nil then
  1564. for k,v in pairs(response.memberList) do
  1565. table.insert(memberStatus,{userId = v.nUserId, status = v.dismissState})
  1566. end
  1567. else
  1568. table.insert(memberStatus,{userId = response.nUserId, status = response.operateType})
  1569. end
  1570. app.room:dispatchEvent({name = GAME_EVENT.DISSMISS_UPDATE_STATUS , memberStatus = memberStatus});
  1571. end
  1572. end
  1573. __dis()
  1574. end
  1575. -- 其他玩家进入
  1576. function zgwrDdzRoomView:onResponseBroadcastLogin( data )
  1577. self:addPlayerNode(data.pInfo)
  1578. self.ui.Items.Button_invite:setVisible(app.room:getPlayerNum()~=app.room:getRoomInfo().nMaxPlayCount)
  1579. local myself = app.room:getMyself()
  1580. if myself.playFlag>=1 then
  1581. self:showSitdownBtn(false)
  1582. else
  1583. self:showSitdownBtn(true)
  1584. end
  1585. self:showFastStart(true)
  1586. end
  1587. -- 玩家离开房间
  1588. function zgwrDdzRoomView:onResponseBroadcastLogout( data )
  1589. local function __logout( onEnd )
  1590. self:showFastStart(true)
  1591. self:delPlayerNode(data.userId)
  1592. local myself = app.room:getMyself()
  1593. if myself.playFlag>=1 then
  1594. self:showSitdownBtn(false)
  1595. else
  1596. self:showSitdownBtn(true)
  1597. end
  1598. if onEnd and type(onEnd)=='function' then onEnd() end
  1599. end
  1600. self:addFunction(__logout)
  1601. end
  1602. -- 玩家准备
  1603. function zgwrDdzRoomView:onResponseUserReady( data )
  1604. local userId = data.userId
  1605. local node = self:getPlayerNode(userId)
  1606. if node then node:setReady(true) end
  1607. if app.room:isMyself(userId) then
  1608. self:resetRoundData()
  1609. app.room:addPlayer({playFlag=1, userId=userId})
  1610. self:showSitdownBtn(false)
  1611. for _,node in pairs(self._playerNodes) do
  1612. node:cleanScore()
  1613. end
  1614. end
  1615. end
  1616. -- 游戏开始
  1617. function zgwrDdzRoomView:onResponseGameStart( data )
  1618. local function __start( onEnd )
  1619. local roomInfo = app.room:getRoomInfo()
  1620. if roomInfo.nGameStartCount and roomInfo.nGameStartCount == 0 then
  1621. self:onUpdatePlayerPos(data)
  1622. end
  1623. self._gameResult = false
  1624. self._passGameResult = nil
  1625. -- 离开房间不可点击
  1626. self.ui.Items.Button_Leave:setEnabled(false)
  1627. self.ui.Items.Layout_Leave:setEnabled(false)
  1628. -- 取消玩家的准备标志
  1629. for _,node in pairs(self._playerNodes) do
  1630. node:setReady(false)
  1631. node:cleanScore()
  1632. app.room:updateFlag( node:getInfo().userId, 2 )
  1633. end
  1634. self:cleanSelfCards()
  1635. self:cleanShowCards()
  1636. self.ui.Items.Button_Ready:setVisible(false)
  1637. self.ui.Items.Button_invite:setVisible(false)
  1638. self:updateButtonPosition()
  1639. self:updateInviteClubButton()
  1640. --
  1641. self:showTurnBtn(false)
  1642. self:updateRoomInfo(roomInfo.nGameStartCount, roomInfo.nTotalGameNum)
  1643. self:checkCanDismiss()
  1644. if onEnd and type(onEnd)=='function' then onEnd() end
  1645. end
  1646. self:addFunction(__start)
  1647. end
  1648. --更新玩家位置
  1649. function zgwrDdzRoomView:onUpdatePlayerPos( data )
  1650. if not data then return end
  1651. local response = data.response
  1652. if not response then return end
  1653. -- 更新椅子号
  1654. for _,v in pairs(response.players) do
  1655. app.room:addPlayer({userId = v.nUserId, seatId = v.nSeatId})
  1656. end
  1657. -- 更新视图ID
  1658. for _,v in pairs(response.players) do
  1659. app.room:addPlayer({userId = v.nUserId, viewPos = app.room:transPos(v.nSeatId)})
  1660. end
  1661. --刷新房间玩家位置
  1662. if response then
  1663. --删除所有玩家节点
  1664. for k,v in pairs(self._playerNodes) do
  1665. self:delPlayerNode(tonumber(k))
  1666. end
  1667. for k,v in pairs(response.players) do
  1668. self:delPlayerNode(v.nUserId)
  1669. end
  1670. self:initChatView()
  1671. --重新添加玩家节点
  1672. local players = app.room:getPlayers()
  1673. for _, info in pairs(players) do
  1674. self:addPlayerNode( info )
  1675. end
  1676. end
  1677. end
  1678. -- 给玩家发牌
  1679. function zgwrDdzRoomView:onResponseSendCards( data )
  1680. if self.xiaojuView and (not tolua.isnull(self.xiaojuView)) then
  1681. self.xiaojuView:removeFromParent()
  1682. self.xiaojuView = nil
  1683. end
  1684. self:setRoomInfo(app.room:getRoomInfo())
  1685. local function __sendCards( onEnd )
  1686. self:resetRoundData()
  1687. self._gameResult = false
  1688. self._passGameResult = nil
  1689. self:sendCards(data.response.cards)
  1690. if onEnd and type(onEnd) == 'function' then onEnd() end
  1691. end
  1692. self:addFunction(__sendCards)
  1693. local function __delay( onEnd )
  1694. self.ui:runDelay(1, function() if onEnd and type(onEnd)=='function' then onEnd() end end)
  1695. self:showJiPaiQi(true,data.response.cardPlayerInfo)
  1696. end
  1697. self:addFunction(__delay)
  1698. local function __showLeft( onEnd )
  1699. local left = 25
  1700. for uid,v in pairs(self._playerNodes) do
  1701. v:showLeft(left)
  1702. end
  1703. self:resetCardsPos()
  1704. if onEnd and type(onEnd) == 'function' then onEnd() end
  1705. end
  1706. self:addFunction(__showLeft)
  1707. --[[local function __showTurn( onEnd )
  1708. local bankerData = app.room:getPlayerCid(data.response.bankerSeat)
  1709. if app.room:isMyself(bankerData.userId) then
  1710. --发完牌后庄家为自己,则不能操作不要按钮
  1711. local isShowPass = false
  1712. self:showTurnBtn(true,isShowPass,2)
  1713. local node = self:getPlayerNodeVpos(1)
  1714. if node then node:setTurn(true) end
  1715. else
  1716. self:showTurnBtn(false)
  1717. local node = self:getPlayerNode(bankerData.userId)
  1718. if node then node:setTurn(true) end
  1719. end
  1720. if onEnd and type(onEnd) == 'function' then onEnd() end
  1721. end
  1722. self:addFunction(__showTurn)
  1723. --]]
  1724. end
  1725. -- 显示轮次时钟
  1726. function zgwrDdzRoomView:showTurns( viewPos, cleanCards )
  1727. for _,node in pairs(self._playerNodes) do
  1728. local is = node:getInfo().viewPos==viewPos
  1729. node:setTurn(is)
  1730. -- if cleanCards==nil then cleanCards = true end
  1731. if cleanCards then self:clearPosShow(viewPos) end--清楚玩家出的牌
  1732. if is then node:cleanPass() end
  1733. end
  1734. end
  1735. -- 广播当前桌子轮次@userId@seatId@outFlag
  1736. function zgwrDdzRoomView:onResponseUpdateTurns( data )
  1737. local function __updateTurns( onEnd )
  1738. local msg = data.response
  1739. --self.lastOutFlag = msg.outFlag
  1740. local node = self:getPlayerNode(msg.userId)
  1741. local viewPos = node:getInfo().viewPos
  1742. self:showTurns(viewPos, msg.opType~=2)
  1743. if app.room:isMyself(msg.userId) then
  1744. local isShowPass = msg.opType == 1 --0-只能pass 1-可以出牌也可以pass 2-必须出牌(不能pass)
  1745. if self._isShowZiChi then
  1746. self._isShowZiChi = nil
  1747. local actions={
  1748. cc.DelayTime:create(1.2),
  1749. cc.CallFunc:create(function()
  1750. self:showTurnBtn( true , isShowPass,msg.opType)
  1751. end),
  1752. }
  1753. self.ui:runAction(cc.Sequence:create(actions))
  1754. else
  1755. self:showTurnBtn( true , isShowPass,msg.opType)
  1756. end
  1757. if msg.opType == 2 then--如果只能出牌
  1758. self._lastCards = {}
  1759. end
  1760. end
  1761. self:clearPosShow(viewPos)
  1762. if onEnd and type(onEnd)=='function' then onEnd() end
  1763. end
  1764. self:addFunction(__updateTurns)
  1765. end
  1766. -- 清理上一次的出牌
  1767. function zgwrDdzRoomView:cleanLastCards(isClean)
  1768. if isClean==nil then isClean = true end
  1769. -- if self._lastOutPos > 0 then
  1770. if isClean == true then
  1771. -- self:clearPosShow(self._lastOutPos)
  1772. end
  1773. self._lastCards = {}
  1774. self._lastOutType = 0
  1775. self._lastOutPos = 0
  1776. -- end
  1777. end
  1778. -- 玩家出牌成功
  1779. function zgwrDdzRoomView:onResponseOutCards( data )
  1780. local function __outCards( onEnd )
  1781. if self.tuoguanView and self.tuoguanView:isVisible() then
  1782. self:hideUI()
  1783. end
  1784. local msg = data.response
  1785. local isContinue = #self._lastCards>0 and self._lastOutType>0
  1786. local tplayer = app.room:getPlayer(msg.userId)
  1787. if not tplayer then
  1788. return
  1789. end
  1790. local viewPos = app.room:getPlayer(msg.userId).viewPos
  1791. if self._lastOutPos == viewPos or self._lastOutPos == 0 then --连出两轮
  1792. for _,v in pairs(self._playerNodes) do
  1793. v:cleanPass()
  1794. end
  1795. -- 清理上一次的出牌
  1796. --self:cleanLastCards()
  1797. isContinue = false
  1798. end
  1799. --操作类型,0:pass 1:接牌 2 必须出牌
  1800. if msg.opType == 1 or msg.opType == 2 then
  1801. -- 缓存上次出的牌
  1802. self._lastOutPos = viewPos
  1803. self._lastOutType = msg.cardType
  1804. app.room.lastOutType = msg.cardType
  1805. self._lastCards = msg.cards
  1806. self._opType = msg.opType
  1807. end
  1808. self:showTurns(0)
  1809. local playerNode = self:getPlayerNode(msg.userId)
  1810. playerNode:setLastOp(msg.cardType, msg.cards, isContinue,msg.showDzFlag)
  1811. -- playerNode:showLastCards(msg.cards, msg.cardType, isContinue)
  1812. if msg.cards and #msg.cards > 0 then
  1813. DdzSoundHelper:playOut()
  1814. end
  1815. --玩家剩余牌
  1816. local node = self:getPlayerNode(msg.userId)
  1817. if node and msg.cards and #msg.cards > 0 then
  1818. if msg.leftNum == 1 then
  1819. DdzSoundHelper:single( node:getInfo().sex )
  1820. elseif msg.leftNum == 2 then
  1821. DdzSoundHelper:single2( node:getInfo().sex )
  1822. end
  1823. node:showLeft(msg.leftNum)
  1824. end
  1825. if viewPos == 1 then--判断是否自己出牌
  1826. self:showTurnBtn(false)
  1827. for _,v in pairs(msg.cards) do
  1828. self:removeCardNode(v)
  1829. end
  1830. --删完牌后再排位置
  1831. self:reCreateHandCards()
  1832. end
  1833. if onEnd and type(onEnd)=='function' then onEnd() end
  1834. end
  1835. self:addFunction(__outCards)
  1836. --检查是否多牌
  1837. local function checkCardsNums(leftNums)
  1838. local handCardsNums = self:getHandCardsNums()
  1839. if leftNums ~= handCardsNums then
  1840. uploadLogs("doudizhuduopai")
  1841. self.ui:sendMsg(app.room, "requestGetUserCards");
  1842. end
  1843. end
  1844. local function __delay( onEnd )
  1845. local msg = data.response
  1846. if msg.userId and app.room:isMyself(msg.userId) then
  1847. self.ui:runDelay(0.5, function() checkCardsNums(msg.leftNum) end)
  1848. end
  1849. self.ui:runDelay(0.5, function() if onEnd and type(onEnd)=='function' then onEnd() end end)
  1850. end
  1851. self:addFunction(__delay)
  1852. end
  1853. -- 检测手上牌能否一次打出
  1854. function zgwrDdzRoomView:checkOnceOut()
  1855. --获取开房参数
  1856. local roomInfo = app.room:getRoomInfo()
  1857. local gameInfo = roomInfo.nGameInfo
  1858. local ruleInfo = json.decode(gameInfo)
  1859. local handCards = self:getHandCards()
  1860. local bCan, tp = PokerUtil:checkOnceOut(handCards)
  1861. if bCan then--检测是否少带接完
  1862. if tp==ETS.THREE_AND_ONE or tp==ETS.THREE then
  1863. if not self.ruleIsNotEnough then
  1864. return false, {}
  1865. end
  1866. end
  1867. -- 是否拥有炸弹
  1868. local allBombs = PokerUtil:getAllBomb(handCards, isChoiceAAA)
  1869. bCan = #allBombs<=0
  1870. end
  1871. return bCan, handCards
  1872. end
  1873. -- 玩家自己显示要不起
  1874. function zgwrDdzRoomView:showPass()
  1875. self.ui.Items.imgTip:setOpacity(0)
  1876. self.ui.Items.imgTip:setVisible(true)
  1877. local ac = cc.Sequence:create(cc.FadeIn:create(0.2), cc.DelayTime:create(1), cc.FadeOut:create(0.2))
  1878. self.ui.Items.imgTip:runAction(ac)
  1879. --手牌变暗
  1880. local anFunc = function ()
  1881. self:resetSelect()
  1882. for k,v in pairs(self._selfCards) do
  1883. v:setNoTouch(true)
  1884. end
  1885. end
  1886. local mingFunc = function ()
  1887. for k,v in pairs(self._selfCards) do
  1888. v:setNoTouch(false)
  1889. end
  1890. end
  1891. local ac = cc.Sequence:create(cc.CallFunc:create(anFunc), cc.DelayTime:create(0.1), cc.CallFunc:create(mingFunc))
  1892. self.cardRoot:runAction(ac)
  1893. end
  1894. -- 春天动画
  1895. function zgwrDdzRoomView:showSpring()
  1896. local node = DdzEffectHelper:getSpring()
  1897. node:setPosition(cc.p(CENTER_X, CENTER_Y))
  1898. self:addChild(node)
  1899. if node.onEnter and type(node.onEnter)=='function' then
  1900. node:onEnter()
  1901. DdzSoundHelper:spring()
  1902. end
  1903. end
  1904. -- 涨水动画
  1905. function zgwrDdzRoomView:showZhangShui()
  1906. local node = DdzEffectHelper:getZhangShui()
  1907. node:setPosition(cc.p(CENTER_X, CENTER_Y))
  1908. self:addChild(node)
  1909. if node.onEnter and type(node.onEnter)=='function' then
  1910. node:onEnter()
  1911. --DdzSoundHelper:spring()
  1912. end
  1913. DdzSoundHelper:effectZhangShui()
  1914. end
  1915. -- 玩家出牌错误
  1916. function zgwrDdzRoomView:onResponseOutCardsErr( data )
  1917. local msg = data.response
  1918. if msg.errFlag == 1 and app.room:isMyself(msg.userId) then
  1919. self:showTurnBtn(false)
  1920. elseif msg.errFlag == 5 and app.room:isMyself(msg.userId) then
  1921. self.ui:sendMsg(app.room, "requestGetUserCards");
  1922. end
  1923. end
  1924. -- 游戏单局结算
  1925. function zgwrDdzRoomView:onResponseGameResult( data )
  1926. -- 收到结算有动画,这个时候不让点击手牌
  1927. self:setCardsNoTouch()
  1928. local msg = data.response
  1929. local maxCards = 0
  1930. for _,v in pairs(msg.players) do
  1931. local pdata = app.room:getPlayer(v.userId)
  1932. v.unionid = pdata.unionid
  1933. v.headimgurl = pdata.headimgurl
  1934. v.gpsInfo = pdata.gpsInfo
  1935. v.sex = pdata.sex
  1936. v.openid = pdata.openid
  1937. v.nickname = pdata.nickname
  1938. v.areano = pdata.areano
  1939. end
  1940. --托管状态有时分数不会刷新,这里刷新容错一下
  1941. if self.tuoguanView and self.tuoguanView:isVisible() then
  1942. for _,v in pairs(msg.players) do
  1943. local node = self:getPlayerNode(v.userId)
  1944. if node then
  1945. node:setScoreNoAnim(v.totalScore)
  1946. end
  1947. end
  1948. end
  1949. local function __delay( onEnd )
  1950. self.ui:runDelay(0.6, function() if onEnd and type(onEnd)=='function' then onEnd() end end)
  1951. end
  1952. self:addFunction(__delay)
  1953. local function __pre( onEnd )
  1954. self._gameResult = true
  1955. for _,v in pairs(msg.players) do
  1956. local node = self:getPlayerNode(v.userId)
  1957. if node then
  1958. node:setScore(v.totalScore, false,v.turnScore)
  1959. node:setTurn(false)
  1960. end
  1961. node:hideLeft()
  1962. v.leftCards = v.leftCards or {}
  1963. if #v.leftCards > maxCards then
  1964. maxCards = #v.leftCards
  1965. end
  1966. end
  1967. local isSpring = msg.spring
  1968. for _,v in pairs(msg.players) do
  1969. local node = self:getPlayerNode(v.userId)
  1970. --self:cleanSelfCards()
  1971. self:showLeftCards(node:getInfo().viewPos, v.leftCards or {})
  1972. end
  1973. local delay = maxCards *0.02+0.5 + 1--加一秒钟延时显示确认,点确认时有可能还在飘分,防止飘分过程中点确认删掉了飘分动画影响最终分数显示
  1974. if tonumber(isSpring) == 1 then
  1975. self.ui:runDelay(0.1, function() self:showSpring() end)
  1976. end
  1977. local function __onEnd()
  1978. if onEnd and type(onEnd)=='function' then onEnd() end
  1979. end
  1980. self.ui:runDelay(delay, __onEnd )
  1981. end
  1982. self:addFunction(__pre)
  1983. local function __showResult( onEnd )
  1984. local msg = data.response
  1985. --是不是最后一局
  1986. local roomInfo = app.room:getRoomInfo()
  1987. msg.isLast = msg.isGameOver == 1--roomInfo.nGameStartCount>=roomInfo.nTotalGameNum
  1988. msg.ruleString = WRDDZDefine.getWanFaInfo(roomInfo.nGameInfo)
  1989. if not msg.isLast then
  1990. msg.isLast = msg.stopFlag==8 or msg.stopFlag==9
  1991. end
  1992. self._resultMsg = msg
  1993. self._resultMsg.players = msg.players
  1994. self._resultMsg.isLast = msg.isLast
  1995. self._resultMsg.ruleString = msg.ruleString
  1996. self._resultMsg.gameStartCount = msg.gameStartCount
  1997. self._resultMsg.totalGamenum = roomInfo.nTotalGameNum
  1998. --self._resultMsg.stopFlag = msg.stopFlag
  1999. --self._resultMsg.dipaiCard = msg.dipaiCard
  2000. for _,v in pairs(self._playerNodes) do
  2001. v:hideLeft()
  2002. end
  2003. self:showRstComfirm(true)
  2004. self:onClickButtonRstComfirm()
  2005. if onEnd and type(onEnd)=='function' then onEnd() end
  2006. end
  2007. self:addFunction(__showResult)
  2008. end
  2009. -- 总结算
  2010. function zgwrDdzRoomView:onResponseGameOver( data )
  2011. setShowCountAll(true)
  2012. app.room:dispatchEvent({name = GAME_EVENT.DISSMISS_CLOSE});
  2013. local msg = data.response
  2014. for _,player in ipairs(msg.players) do
  2015. local pdata = app.room:getPlayer(player.userId)
  2016. player.unionid = pdata.unionid
  2017. player.headimgurl = pdata.headimgurl
  2018. player.gpsInfo = pdata.gpsInfo
  2019. player.sex = pdata.sex
  2020. player.openid = pdata.openid
  2021. player.nickname = pdata.nickname
  2022. player.areano = pdata.areano
  2023. app.room:updateFlag( player.userId, 0 )
  2024. end
  2025. local function __over( onEnd )
  2026. -- 缓存结算信息
  2027. self._isGameOver = true
  2028. self._gameOverData = msg
  2029. local roomInfo = app.room:getRoomInfo()
  2030. self._gameOverData.nShowTableId = roomInfo.nShowTableId
  2031. app.room.roomInfo.nShowTableId = roomInfo.nShowTableId
  2032. self._gameOverData.startCount = roomInfo.nGameStartCount
  2033. self._gameOverData.totalCount = roomInfo.nTotalGameNum
  2034. self._gameOverData.roomRule = WRDDZDefine.getWanFaInfo(roomInfo.nGameInfo)
  2035. if self.tuoguanView then
  2036. self:showTuoGuan(false)
  2037. end
  2038. if self._gameResult==false then--已经展示过小结算后解散房间
  2039. self:onNormalShowGameOver()
  2040. end
  2041. if onEnd and type(onEnd)=='function' then onEnd() end
  2042. end
  2043. self:addFunction(__over)
  2044. app.club_php:dispatchEvent({name = GAME_EVENT.CLUB_BACK_ROOM})
  2045. end
  2046. --[[先显示小局结算,再显示总结算--]]
  2047. function zgwrDdzRoomView:onNormalShowGameOver( data )
  2048. self._gameResult = false
  2049. local showFunc = function (msg)
  2050. local view = import("pk_zgwrddz.luaScript.Views.Room.Sub.zgwrDdzGameOverView"):new(msg)
  2051. view:setAnchorPoint(cc.p(0.5, 0.5))
  2052. app:showWaitDialog(view)
  2053. stopBGMusic()
  2054. self:showGameOverAward()
  2055. end
  2056. if self._isGameOver and self._gameOverData then
  2057. showFunc(self._gameOverData)
  2058. end
  2059. end
  2060. ----------------------------------------------------------------------------------------------------------------------
  2061. ----------------------------------------------------------------------------------------------------------------------
  2062. -- 单局结算显示剩余牌
  2063. function zgwrDdzRoomView:showLeftCards( pos, cards )
  2064. --如果是主视角,手牌已经显示了
  2065. if pos == 1 then return end
  2066. self:showTurnBtn(false)
  2067. if #cards <=0 then return end
  2068. self:clearPosShow(pos)
  2069. --if pos==4 or pos == 5 then
  2070. local tmp = {}
  2071. for _,v in ipairs(cards) do
  2072. table.insert(tmp, 1, v)
  2073. end
  2074. cards = tmp
  2075. --end
  2076. local root = cc.Node:create()
  2077. local nodes = {}
  2078. for i,card in ipairs(cards) do
  2079. local node = self:genCard(card)
  2080. local pt = cc.p(0, 25)
  2081. if pos==1 then
  2082. pt.x = pt.x + (i-1)*DdzRoomViewConfig.CARD_DLT_WIDTH*DdzRoomViewConfig.CARD_SCALE[2]
  2083. node:setLocalZOrder(100+i)
  2084. else
  2085. local rowNum = 13
  2086. if i>rowNum then
  2087. pt.y = pt.y - 40
  2088. if i > 2*rowNum then
  2089. pt.y = pt.y - 40
  2090. end
  2091. if pos == 2 or pos == 3 then
  2092. --(i-math.floor((i)/rowNum)*rowNum-1)
  2093. pt.x = pt.x - (i-1)%rowNum*DdzRoomViewConfig.CARD_DLT_WIDTH*DdzRoomViewConfig.CARD_SCALE[2]
  2094. if i > 2*rowNum then
  2095. node:setLocalZOrder(56-i)
  2096. else
  2097. node:setLocalZOrder(36-i)
  2098. end
  2099. else
  2100. pt.x = pt.x + (i-1)%rowNum*DdzRoomViewConfig.CARD_DLT_WIDTH*DdzRoomViewConfig.CARD_SCALE[2]
  2101. end
  2102. else
  2103. if pos == 2 or pos == 3 then
  2104. pt.x = pt.x - (i-1)%rowNum*DdzRoomViewConfig.CARD_DLT_WIDTH*DdzRoomViewConfig.CARD_SCALE[2]
  2105. node:setLocalZOrder(16-i)
  2106. else
  2107. pt.x = pt.x + (i-1)%rowNum*DdzRoomViewConfig.CARD_DLT_WIDTH*DdzRoomViewConfig.CARD_SCALE[2]
  2108. end
  2109. end
  2110. end
  2111. node:setScale(DdzRoomViewConfig.CARD_SCALE[2])
  2112. node:setPosition(pt)
  2113. root:addChild(node)
  2114. node:setVisible(false)
  2115. table.insert(nodes, node)
  2116. end
  2117. local dltWidth = 0
  2118. local rpt = clone(DdzRoomViewConfig.SHOW_CARD_POS[self:getMode()][pos])
  2119. if pos == 1 then
  2120. else
  2121. dltWidth = #cards/2*DdzRoomViewConfig.CARD_DLT_WIDTH*DdzRoomViewConfig.CARD_SCALE[2]
  2122. end
  2123. root:setPosition(rpt)
  2124. self.cardRoot:addChild(root)
  2125. table.insert(self._showCards[pos], root)
  2126. for i,v in ipairs(nodes) do
  2127. v:runAction(cc.Sequence:create(cc.DelayTime:create((i-1)*0.02), cc.CallFunc:create(function ()
  2128. v:setVisible(true)
  2129. end)))
  2130. end
  2131. end
  2132. -- 清除某玩家的出牌
  2133. function zgwrDdzRoomView:clearPosShow(pos)
  2134. local pNode = self:getPlayerNodeVpos(pos)
  2135. if pNode then pNode:cleanLastCards() end
  2136. end
  2137. -- 添加玩家节点
  2138. function zgwrDdzRoomView:addPlayerNode( pInfo )
  2139. local node = self._playerNodes[pInfo.userId]
  2140. if node then return end
  2141. node = DdzPlayerNode:new()
  2142. node:setPlayMode(self:getMode())
  2143. local gameInfo = app.room:getRoomInfo().nGameInfo
  2144. local data = json.decode(gameInfo)
  2145. local rule = tonumber(data.playRule)
  2146. node:setGameInfo(gameInfo)
  2147. node:setMaxPlayerCount(app.room:getRoomInfo().nMaxPlayCount)
  2148. node:setShowNum(true)
  2149. --node:setShowNum(getNumBand(rule, 0x0020)>0)--是否显示牌张数
  2150. node:setInfo(pInfo)
  2151. node:setReady(pInfo.playFlag==1)
  2152. node:setOffline((pInfo.onlineStatus and pInfo.onlineStatus==0))
  2153. --node:setHost(pInfo.userId==app.room:getRoomInfo().nRoomOwnedUid)
  2154. node:setHost(false)
  2155. node:setPosition(DdzRoomViewConfig.PLAYER_POS[self:getMode()][pInfo.viewPos])
  2156. self._playerNodes[pInfo.userId] = node
  2157. node:setLocalZOrder(10)
  2158. if app.room:isMyself(pInfo.userId) then
  2159. node:setLocalZOrder(12)
  2160. end
  2161. self.ui.Items.toolPanel:addChild(node)
  2162. -- self.panelMenu:getParent():addChild(node)
  2163. -- 将玩家加入到chatView
  2164. self.chatView:addPlayer(pInfo.userId)
  2165. end
  2166. -- 删除玩家节点
  2167. function zgwrDdzRoomView:delPlayerNode( uid )
  2168. if self._gameResult or self._isGameOver then return end
  2169. local node = self._playerNodes[uid]
  2170. if not node then return end
  2171. node:removeFromParent()
  2172. self._playerNodes[uid] = nil
  2173. -- 将玩家从chatView移除
  2174. self.chatView:delPlayer(uid)
  2175. end
  2176. -- 获取玩家节点
  2177. function zgwrDdzRoomView:getPlayerNode( uid )
  2178. return self._playerNodes[uid]
  2179. end
  2180. -- 根据视图获取玩家节点
  2181. function zgwrDdzRoomView:getPlayerNodeVpos( viewPos )
  2182. for _,v in pairs(self._playerNodes) do
  2183. if v:getInfo().viewPos==viewPos then
  2184. return v
  2185. end
  2186. end
  2187. return nil
  2188. end
  2189. ----------------------------------------------------------------------------
  2190. -- 检查拖牌节点
  2191. function zgwrDdzRoomView:checkTouches( pt )
  2192. local rect = nil
  2193. local node = nil
  2194. --[[for i,v in ipairs(self._selfCards) do
  2195. if cc.rectContainsPoint(v:getRect(), pt) then
  2196. node = v
  2197. break
  2198. end
  2199. end--]]
  2200. for i = #self._selfCards,1,-1 do
  2201. v = self._selfCards[i]
  2202. if v and (not tolua.isnull(v)) and cc.rectContainsPoint(v:getRect(), pt) then
  2203. node = v
  2204. break
  2205. end
  2206. end
  2207. return node
  2208. end
  2209. ----------------------------------------------------------------------------
  2210. function zgwrDdzRoomView:touchBegan( pt )
  2211. if self._gameResult then return end
  2212. self._selectCards = {}
  2213. self.touchDir = 0
  2214. local node = self:checkTouches(pt)
  2215. if not tolua.isnull(node) and node and node:getUniqueFlag() then
  2216. self._selectCards[node:getUniqueFlag()] = node
  2217. node.istouching = true
  2218. if node:isDown() then
  2219. node:setNormal()
  2220. else
  2221. node:setDown()
  2222. end
  2223. end
  2224. --self:doSelectColor()
  2225. end
  2226. ----------------------------------------------------------------------------
  2227. function zgwrDdzRoomView:touchMoved( pt )
  2228. if self._gameResult then return end
  2229. local node = self:checkTouches(pt)
  2230. if not tolua.isnull(node) and node and node:getUniqueFlag() and not self._selectCards[node:getUniqueFlag()] and (not node.istouching) then
  2231. self._selectCards[node:getUniqueFlag()] = node
  2232. node.istouching = true
  2233. if node:isDown() then
  2234. node:setNormal()
  2235. else
  2236. node:setDown()
  2237. end
  2238. --只要有弹起,第一次弹下置为true
  2239. self.firstDown = true
  2240. elseif not tolua.isnull(node) and node and node:getUniqueFlag() and self._selectCards[node:getUniqueFlag()] and (not node.istouching) then
  2241. if self.firstDown then
  2242. self.firstDown = false
  2243. for _,snode in pairs(self._selectCards) do
  2244. if (snode and not tolua.isnull(snode)) and snode.istouching then
  2245. snode.istouching = false
  2246. if snode:isDown() then
  2247. snode:setNormal()
  2248. else
  2249. snode:setDown()
  2250. end
  2251. self._selectCards[snode:getUniqueFlag()] = nil
  2252. break
  2253. end
  2254. end
  2255. end
  2256. self._selectCards[node:getUniqueFlag()] = nil
  2257. node.istouching = true
  2258. if node:isDown() then
  2259. node:setNormal()
  2260. else
  2261. node:setDown()
  2262. end
  2263. end
  2264. if tolua.isnull(node) then
  2265. for _,snode in pairs(self._selectCards) do
  2266. snode.istouching = false
  2267. end
  2268. else
  2269. for _,snode in pairs(self._selfCards) do
  2270. if not tolua.isnull(snode) and snode ~= node then
  2271. snode.istouching = false
  2272. end
  2273. end
  2274. end
  2275. --self:doSelectColor()
  2276. end
  2277. ----------------------------------------------------------------------------
  2278. function zgwrDdzRoomView:touchEnded( pt )
  2279. if self._gameResult then return end
  2280. --self:doSelect()
  2281. local isPointDesk = false--是否点击了桌面
  2282. if pt.y > DdzRoomViewConfig.NORMAL_HEIGHT + DdzRoomViewConfig.CARD_HEIGHT/2 and (not self:checkTouches(pt)) then
  2283. for _,node in pairs(self._selfCards) do
  2284. if node:isDown() then node:setNormal() end
  2285. end
  2286. self:hideCanOutCards()
  2287. isPointDesk = true
  2288. end
  2289. --智能提示
  2290. if self.firstTip then
  2291. self.firstTip = false
  2292. self:checkAndTip()
  2293. end
  2294. --检测选牌是否可点
  2295. self:checkSelectCardBtnEnabled()
  2296. --检测出牌是否可点
  2297. self:checkOutCardBtnEnabled()
  2298. if isPointDesk == true then
  2299. self.firstTip = true
  2300. end
  2301. --所有牌触摸状态置为false
  2302. for _,snode in pairs(self._selfCards) do
  2303. if not tolua.isnull(snode) and snode ~= node then
  2304. snode.istouching = false
  2305. end
  2306. end
  2307. end
  2308. ----------------------------------------------------------------------------
  2309. function zgwrDdzRoomView:doSelect()
  2310. local i = 0
  2311. for _,node in pairs(self._selectCards) do
  2312. i = i + 1
  2313. if not tolua.isnull(node) and node and node.getParent and node:getParent() then
  2314. if node:isDown() then
  2315. node:setNormal()
  2316. else
  2317. node:setDown()
  2318. end
  2319. if i==1 then DdzSoundHelper:selectSnd() end
  2320. end
  2321. end
  2322. self:hideCanOutCards()
  2323. end
  2324. ----------------------------------------------------------------------------
  2325. function zgwrDdzRoomView:doSelectColor()
  2326. for _,node in pairs(self._selectCards) do
  2327. if not tolua.isnull(node) and node and node.getParent and node:getParent() then
  2328. node:setDownColor()
  2329. end
  2330. end
  2331. end
  2332. ----------------------------------------------------------------------------
  2333. function zgwrDdzRoomView:resetSelect()
  2334. local i = 0
  2335. for _,v in pairs(self._selfCards) do
  2336. i = i + 1
  2337. if v:isDown() then
  2338. v:setNormal()
  2339. v:setNormalColor()
  2340. if i==1 then DdzSoundHelper:selectSnd() end
  2341. end
  2342. end
  2343. self._selectCards = {}
  2344. end
  2345. function zgwrDdzRoomView:setCardsNoTouch()
  2346. for _,v in pairs(self._selfCards) do
  2347. v:setNoTouch(true)
  2348. v:setNormal()
  2349. v:setNormalColor()
  2350. end
  2351. self:resetSelect()
  2352. end
  2353. ----------------------------------------------------------------------------
  2354. -- 获取选择的牌的集合
  2355. function zgwrDdzRoomView:getSelected()
  2356. local sel = {}
  2357. for _,v in pairs(self._selfCards) do
  2358. if v:isDown() then table.insert(sel, v:getVal()) end
  2359. end
  2360. return sel
  2361. end
  2362. -- 添加牌节点监听
  2363. function zgwrDdzRoomView:addTouchesListener()
  2364. local function onTouchBegan(touch, event)
  2365. local locationInNode = self:convertToWorldSpace(touch:getLocation())--触点
  2366. self:touchBegan(locationInNode)
  2367. return true
  2368. end
  2369. local function onTouchMoved(touch, event)
  2370. local locationInNode = touch:getLocation()
  2371. self:touchMoved(locationInNode)
  2372. end
  2373. local function onTouchEnded(touch, event)
  2374. local locationInNode = touch:getLocation()
  2375. self:touchEnded(locationInNode)
  2376. end
  2377. local listener1 = cc.EventListenerTouchOneByOne:create()
  2378. listener1:setSwallowTouches(false)
  2379. listener1:registerScriptHandler(onTouchBegan,cc.Handler.EVENT_TOUCH_BEGAN )
  2380. listener1:registerScriptHandler(onTouchMoved,cc.Handler.EVENT_TOUCH_MOVED )
  2381. listener1:registerScriptHandler(onTouchEnded,cc.Handler.EVENT_TOUCH_ENDED )
  2382. local eventDispatcher = self.cardRoot:getEventDispatcher()
  2383. eventDispatcher:addEventListenerWithSceneGraphPriority(listener1, self)
  2384. end
  2385. -- 发牌
  2386. function zgwrDdzRoomView:sendCards( cards_ )
  2387. local cards = pokerSortPdkCards(cards_)
  2388. local pos = 1
  2389. local CardsCount = #cards
  2390. for i,card in ipairs(cards) do
  2391. local ac = cc.Sequence:create(cc.DelayTime:create(i*0.02), cc.CallFunc:create(function ()
  2392. self:sendOneCard(card.cid, i, pos, i==CardsCount, CardsCount)
  2393. if self:getMode()==0 then
  2394. if i==CardsCount then self:showOtherCards(true) end
  2395. end
  2396. end))
  2397. self.cardRoot:runAction(ac)
  2398. end
  2399. end
  2400. -- 发一张牌
  2401. function zgwrDdzRoomView:sendOneCard( card, i, pos, islast, allCount )
  2402. -- local node = self:genCard(card)
  2403. local node = self:genCard(-1,i)--back
  2404. node.cid = card
  2405. node:setScale(DdzRoomViewConfig.CARD_SCALE[pos])--DdzRoomViewConfig.CARD_SCALE_START
  2406. node:setLast(islast)
  2407. local endX = DdzRoomViewConfig.HANDCARD_MIDPOS + (allCount-allCount/2+1)*DdzRoomViewConfig.CARD_DLT_WIDTH*DdzRoomViewConfig.CARD_SCALE[1]
  2408. local pt = cc.p(0, 0)
  2409. if pos ~= 1 then
  2410. pt = clone(DdzRoomViewConfig.PLAYER_POS[self:getMode()][pos])
  2411. else
  2412. if allCount > DdzRoomViewConfig.ROW_MAX_CARDS_NUM then
  2413. allCount = DdzRoomViewConfig.ROW_MAX_CARDS_NUM
  2414. end
  2415. local midIdx = allCount/2
  2416. if i <= DdzRoomViewConfig.ROW_MAX_CARDS_NUM then
  2417. pt.x = DdzRoomViewConfig.HANDCARD_MIDPOS
  2418. if i<=midIdx then--左边
  2419. pt.x = pt.x - (midIdx-i-1)*DdzRoomViewConfig.CARD_DLT_WIDTH*DdzRoomViewConfig.CARD_SCALE[1]
  2420. else--右边
  2421. pt.x = pt.x + (i-midIdx+1)*DdzRoomViewConfig.CARD_DLT_WIDTH*DdzRoomViewConfig.CARD_SCALE[1]
  2422. end
  2423. pt.x = pt.x - DdzRoomViewConfig.CARD_WIDTH/2*DdzRoomViewConfig.CARD_SCALE[1]
  2424. pt.y = DdzRoomViewConfig.INIT_CARD_POS[self:getMode()][pos].y
  2425. if i == DdzRoomViewConfig.ROW_MAX_CARDS_NUM then
  2426. node:setLast(true)
  2427. end
  2428. else
  2429. --这里开始排第二列牌
  2430. self:setRow2Card(node)
  2431. --先算出第一排第一张牌的X位置
  2432. pt.x = DdzRoomViewConfig.HANDCARD_MIDPOS - (midIdx-1-1)*DdzRoomViewConfig.CARD_DLT_WIDTH*DdzRoomViewConfig.CARD_SCALE[1]
  2433. pt.x = pt.x + (i - DdzRoomViewConfig.ROW_MAX_CARDS_NUM-1)*DdzRoomViewConfig.CARD_DLT_WIDTH*DdzRoomViewConfig.CARD_SCALE[1]
  2434. pt.x = pt.x - DdzRoomViewConfig.CARD_WIDTH/2*DdzRoomViewConfig.CARD_SCALE[1]
  2435. pt.y = DdzRoomViewConfig.INIT_CARD_POS[self:getMode()][pos].y - DdzRoomViewConfig.ROW_SPACING
  2436. end
  2437. end
  2438. node:setPosition(cc.p(endX, pt.y))
  2439. node:setLocalZOrder(i)
  2440. node:setOpacity(0)
  2441. node:setTag(i)
  2442. self.cardRoot:addChild(node)
  2443. local ac = nil
  2444. if pos ~=1 then
  2445. ac = cc.Sequence:create(cc.Spawn:create(cc.MoveTo:create(0.05, pt), cc.ScaleTo:create(0.7, DdzRoomViewConfig.CARD_SCALE[pos])), cc.CallFunc:create(function ()
  2446. node:removeFromParent()
  2447. end))
  2448. node:runAction(ac)
  2449. else
  2450. ac = cc.Sequence:create(cc.Spawn:create(cc.MoveTo:create(0.05, pt), cc.FadeIn:create(0.1)), cc.CallFunc:create(function ()
  2451. table.insert(self._selfCards, node)
  2452. DdzSoundHelper:playSend()
  2453. end), cc.DelayTime:create((i)*0.01), cc.CallFunc:create(function() node:setCard(node.cid) end ))
  2454. node:runAction(ac)
  2455. end
  2456. end
  2457. -- 发一张牌没有动画
  2458. function zgwrDdzRoomView:sendOneCardNoAct( card, i, pos, islast, allCount )
  2459. local node = self:genCard(card,i)
  2460. node:setScale(DdzRoomViewConfig.CARD_SCALE[pos])
  2461. node:setLast(islast)
  2462. local pt = cc.p(0, 0)
  2463. if pos ~= 1 then
  2464. pt = clone(DdzRoomViewConfig.INIT_CARD_POS[self:getMode()][pos])
  2465. else
  2466. if allCount > DdzRoomViewConfig.ROW_MAX_CARDS_NUM then
  2467. allCount = DdzRoomViewConfig.ROW_MAX_CARDS_NUM
  2468. end
  2469. local midIdx = math.floor(allCount/2)
  2470. if i <= DdzRoomViewConfig.ROW_MAX_CARDS_NUM then
  2471. if i<midIdx then--左边
  2472. pt.x = DdzRoomViewConfig.HANDCARD_MIDPOS - (midIdx-i-1)*DdzRoomViewConfig.CARD_DLT_WIDTH*DdzRoomViewConfig.CARD_SCALE[pos]
  2473. else--右边
  2474. pt.x = DdzRoomViewConfig.HANDCARD_MIDPOS + (i-midIdx+1)*DdzRoomViewConfig.CARD_DLT_WIDTH*DdzRoomViewConfig.CARD_SCALE[pos]
  2475. end
  2476. pt.x = pt.x - DdzRoomViewConfig.CARD_WIDTH/2*DdzRoomViewConfig.CARD_SCALE[pos]
  2477. pt.y = DdzRoomViewConfig.INIT_CARD_POS[self:getMode()][pos].y
  2478. else
  2479. --这里开始排第二列牌
  2480. self:setRow2Card(node)
  2481. --先算出第一排第一张牌的X位置
  2482. pt.x = DdzRoomViewConfig.HANDCARD_MIDPOS - (midIdx-1-1)*DdzRoomViewConfig.CARD_DLT_WIDTH*DdzRoomViewConfig.CARD_SCALE[1]
  2483. pt.x = pt.x + (i - DdzRoomViewConfig.ROW_MAX_CARDS_NUM-1)*DdzRoomViewConfig.CARD_DLT_WIDTH*DdzRoomViewConfig.CARD_SCALE[1]
  2484. pt.x = pt.x - DdzRoomViewConfig.CARD_WIDTH/2*DdzRoomViewConfig.CARD_SCALE[1]
  2485. pt.y = DdzRoomViewConfig.INIT_CARD_POS[self:getMode()][pos].y - DdzRoomViewConfig.ROW_SPACING
  2486. end
  2487. end
  2488. node:setPosition(pt)
  2489. node:setLocalZOrder(i)
  2490. node:setTag(i)
  2491. self.cardRoot:addChild(node)
  2492. table.insert(self._selfCards, node)
  2493. end
  2494. -- 创建一张牌
  2495. function zgwrDdzRoomView:genCard( card,uniqueFlag)
  2496. local node = DdzCardNode:new(card,uniqueFlag)
  2497. node:setCard(card)
  2498. node:setSelectedHeight(DdzRoomViewConfig.SELECTED_HEIGHT)
  2499. node:setNormalHeight(DdzRoomViewConfig.NORMAL_HEIGHT)
  2500. return node
  2501. end
  2502. -- 设置第一排牌属性
  2503. function zgwrDdzRoomView:setRow1Card( node )
  2504. node:setSelectedHeight(DdzRoomViewConfig.SELECTED_HEIGHT)
  2505. node:setNormalHeight(DdzRoomViewConfig.NORMAL_HEIGHT)
  2506. end
  2507. -- 设置第二排牌属性
  2508. function zgwrDdzRoomView:setRow2Card( node )
  2509. node:setSelectedHeight(DdzRoomViewConfig.ROW2_SELECTED_HEIGHT)
  2510. node:setNormalHeight(DdzRoomViewConfig.ROW2_NORMAL_HEIGHT)
  2511. end
  2512. -- 从手牌中获取一张牌
  2513. function zgwrDdzRoomView:getCardNode( card )
  2514. if card > 0x00 and card <= 0x5d then
  2515. for _,v in pairs(self._selfCards) do
  2516. if v:getVal()==card then
  2517. return v
  2518. end
  2519. end
  2520. return nil
  2521. else
  2522. return nil
  2523. end
  2524. end
  2525. -- 根据牌ID移除一张手牌,并重新调整手牌位置
  2526. function zgwrDdzRoomView:removeCardNode( card )
  2527. --删牌的时候服务器下发的是癞子混出的实际牌取值0x5X(X值为1-C),但是手上只有0x5d的癞子牌,这里全部转换成癞子来删除
  2528. if card >= 0x50 and card <= 0x5d then
  2529. card = 0x5d
  2530. end
  2531. local node = self:getCardNode(card)
  2532. --if not node or tolua.isnull(node) then return end
  2533. for i=#self._selfCards,1,-1 do
  2534. if self._selfCards[i]:getVal()==card then
  2535. table.remove(self._selfCards, i)
  2536. break
  2537. end
  2538. end
  2539. --[[if tolua.isnull(node) then
  2540. node = nil
  2541. self:removeHandcards(card)
  2542. else
  2543. node:removeFromParent(true)
  2544. end--]]
  2545. end
  2546. --直接从手牌中找牌删除
  2547. function zgwrDdzRoomView:removeHandcards(card)
  2548. for i,v in pairs(self.cardRoot:getChildren()) do
  2549. if v:getVal() == card then
  2550. v:removeFromParent(true)
  2551. break
  2552. end
  2553. end
  2554. end
  2555. -- 获取当前手牌
  2556. function zgwrDdzRoomView:getHandCards()
  2557. local handCards1 = {}
  2558. local handCards2 = {}
  2559. for _,v in pairs(self._selfCards) do
  2560. if v and not tolua.isnull(v) then
  2561. table.insert(handCards1, v:getVal())
  2562. end
  2563. end
  2564. for i,v in pairs(self.cardRoot:getChildren()) do
  2565. if v and (not tolua.isnull(v)) and type(v.getVal) == 'function' then
  2566. table.insert(handCards2, v:getVal())
  2567. end
  2568. end
  2569. if #handCards1 <= #handCards2 then
  2570. return handCards1
  2571. else
  2572. return handCards2
  2573. end
  2574. end
  2575. -- 获取当前手牌张数
  2576. function zgwrDdzRoomView:getHandCardsNums()
  2577. local handCards = {}
  2578. local num = 0
  2579. for _,v in pairs(self._selfCards) do
  2580. num = num + 1
  2581. end
  2582. return num
  2583. end
  2584. --重新生成牌
  2585. function zgwrDdzRoomView:reCreateHandCards()
  2586. local handCards = self:getHandCards()
  2587. self:recoverHandcards(handCards)
  2588. end
  2589. --获取某张牌有几张
  2590. function zgwrDdzRoomView:getCardsNumInHand(node)
  2591. if tolua.isnull(node) then return 0 end
  2592. --大于2的牌返回0
  2593. if PokerUtil:getCardValue(node:getVal()) > 10 then return 0 end
  2594. local num = 0
  2595. for i,v in ipairs(self._selfCards) do
  2596. if PokerUtil:getCardValue(v:getVal()) == PokerUtil:getCardValue(node:getVal()) then
  2597. num = num + 1
  2598. end
  2599. end
  2600. return num
  2601. end
  2602. -- 重置手牌位置
  2603. function zgwrDdzRoomView:resetCardsPos( )
  2604. if #self._selfCards<=0 then return end
  2605. local mode = self:getMode()
  2606. local pos = 1
  2607. local scale = DdzRoomViewConfig.CARD_SCALE[pos]
  2608. local dtpx = (16 - #self._selfCards)/2*DdzRoomViewConfig.CARD_DLT_WIDTH*scale
  2609. local allCount = #self._selfCards
  2610. if allCount > DdzRoomViewConfig.ROW_MAX_CARDS_NUM then
  2611. allCount = DdzRoomViewConfig.ROW_MAX_CARDS_NUM
  2612. end
  2613. local midIdx = allCount/2
  2614. for i,v in ipairs(self._selfCards) do
  2615. if not tolua.isnull(v) then
  2616. local pt = cc.p(CENTER_X, 0)
  2617. v:setLordFlagVisible(false)
  2618. if i <= DdzRoomViewConfig.ROW_MAX_CARDS_NUM then
  2619. self:setRow1Card(v)
  2620. if i<midIdx then--左边
  2621. pt.x = pt.x - (midIdx-i-1)*DdzRoomViewConfig.CARD_DLT_WIDTH*scale
  2622. else--右边
  2623. pt.x = pt.x + (i-midIdx+1)*DdzRoomViewConfig.CARD_DLT_WIDTH*scale
  2624. end
  2625. pt.x = pt.x - DdzRoomViewConfig.CARD_WIDTH/2*scale
  2626. pt.y = DdzRoomViewConfig.INIT_CARD_POS[self:getMode()][pos].y
  2627. v:setLast(i==allCount)
  2628. else
  2629. --这里开始排第二列牌
  2630. self:setRow2Card(v)
  2631. --先算出第一排第一张牌的X位置
  2632. pt.x = pt.x - (midIdx-1-1)*DdzRoomViewConfig.CARD_DLT_WIDTH*scale
  2633. pt.x = pt.x + (i - DdzRoomViewConfig.ROW_MAX_CARDS_NUM-1)*DdzRoomViewConfig.CARD_DLT_WIDTH*scale
  2634. pt.x = pt.x - DdzRoomViewConfig.CARD_WIDTH/2*scale
  2635. pt.y = DdzRoomViewConfig.INIT_CARD_POS[self:getMode()][pos].y - DdzRoomViewConfig.ROW_SPACING
  2636. v:setLast(i==#self._selfCards)
  2637. end
  2638. v:setPosition(pt)
  2639. v:setNormal()
  2640. if self:getCardsNumInHand(v) >=4 then
  2641. v:setTouMingDu(true)
  2642. else
  2643. v:setTouMingDu(false)
  2644. end
  2645. if i==#self._selfCards and (self._isLorder or self._isDarkLorder) then
  2646. v:setLordFlagVisible(true)
  2647. end
  2648. end
  2649. end
  2650. end
  2651. -- 提示对应的牌
  2652. function zgwrDdzRoomView:tipCards( cards, show )
  2653. if show ~= nil then return "" end
  2654. self:resetSelect()
  2655. self:resetCardsPos()
  2656. for _,v in pairs(cards) do
  2657. local node = self:getCardNode(v.cid)
  2658. if node and node:getVal()>0 then
  2659. self._selectCards[node:getVal()] = node
  2660. node:setDown()
  2661. end
  2662. end
  2663. end
  2664. -- 清除所有牌
  2665. function zgwrDdzRoomView:cleanSelfCards()
  2666. self.cardRoot:stopAllActions()
  2667. for i,v in pairs(self.cardRoot:getChildren()) do
  2668. if v and (not tolua.isnull(v)) then
  2669. v:stopAllActions()
  2670. v:removeFromParent(true)
  2671. v = nil
  2672. end
  2673. end
  2674. for i = #self._selfCards,1,-1 do
  2675. table.remove(self._selfCards,i)
  2676. end
  2677. self.cardRoot:removeAllChildren()
  2678. self._selfCards = nil
  2679. self._selfCards = {}
  2680. end
  2681. function zgwrDdzRoomView:cleanShowCards()
  2682. self._showCards = {{},{},{},{},{}}
  2683. for _,v in pairs(self._playerNodes) do
  2684. if v then v:cleanLastCards() end
  2685. end
  2686. end
  2687. -- 二人玩显示另外一组牌
  2688. function zgwrDdzRoomView:showOtherCards(is)
  2689. if is then
  2690. self.imgOtherCards:setVisible(true)
  2691. local num = 16
  2692. if self.ruleType==2 then num = 15 end
  2693. self.txtOtherCards:setString(string.format("剩余%d张", num))
  2694. else
  2695. self.imgOtherCards:setVisible(false)
  2696. end
  2697. end
  2698. --发起申请
  2699. function zgwrDdzRoomView:onClickFastStart(sender)
  2700. playBtnEffect()
  2701. local request = DdzMessage.FastStartRequest:new()
  2702. request.result = 1
  2703. self.ui:sendMsg(app.room, "requestFastStartGame", request)
  2704. end
  2705. --是否显示2/3人快速开始按钮
  2706. function zgwrDdzRoomView:showFastStart(is)
  2707. local roomInfo = app.room:getRoomInfo()
  2708. if not roomInfo.nGameInfo then
  2709. return
  2710. end
  2711. if roomInfo.gameStatus and roomInfo.gameStatus > DdzRoomViewConfig.GameStatus.GAME_STATE_INIT and roomInfo.gameStatus <= DdzRoomViewConfig.GameStatus.GAME_STATE_GAME_OVER then
  2712. self.ui.Items.Button_fastStart:setVisible(false)
  2713. else
  2714. local playerCount = app.room:getPlayerNum()
  2715. local gameInfo = json.decode(roomInfo.nGameInfo)
  2716. if true == is and playerCount < roomInfo.nMaxPlayCount and roomInfo.nGameStartCount <= 0 and gameInfo.playnum == 1 then
  2717. self.ui.Items.Button_fastStart:setVisible(playerCount == 2 or playerCount == 3)
  2718. else
  2719. self.ui.Items.Button_fastStart:setVisible(false)
  2720. end
  2721. end
  2722. end
  2723. -- 服务器广播快速开始
  2724. function zgwrDdzRoomView:onBroadcastFaststart(data)
  2725. local response = data.response
  2726. local isRemove = false
  2727. if response.nUserId and response.nStatus then
  2728. if response.nStatus and response.nStatus == 3 or response.nStatus > 4 then
  2729. isRemove = true
  2730. end
  2731. end
  2732. if not isRemove then
  2733. for _,v in ipairs(response.pList) do
  2734. if response.nStatus and v.nStatus == 3 or v.nStatus > 4 then
  2735. isRemove = true
  2736. end
  2737. end
  2738. end
  2739. if response.timeOut <=0 then
  2740. isRemove = true
  2741. end
  2742. logD("zgwrDdzRoomView:onBroadcastFaststart isRemove:"..table.tostring(isRemove)..";self.fastStartRequestView = "..table.tostring(self.fastStartRequestView))
  2743. if self.fastStartRequestView == nil then
  2744. if isRemove then
  2745. return ""
  2746. end
  2747. local requesterId = 0
  2748. for _,v in ipairs(response.pList) do
  2749. if v.nStatus == 1 then
  2750. requesterId = v.nUserId
  2751. end
  2752. end
  2753. if requesterId <= 0 then
  2754. return ""
  2755. end
  2756. local view = import("pk_zgwrddz.luaScript.Views.Room.zgwrDdzRequestStartView"):new(requesterId)
  2757. view:setAnchorPoint(cc.p(0.5, 0.5))
  2758. view:showItems(response)
  2759. app:showWaitDialog(view)
  2760. self.fastStartRequestView = view
  2761. else
  2762. if isRemove then
  2763. local userInfo = app.room.roomInfo.memberList[response.nUserId]
  2764. self.fastStartRequestView:removeFromParent()
  2765. self.fastStartRequestView = nil
  2766. if userInfo then
  2767. local u = json.decode(userInfo.userInfo)
  2768. local txt = string.format("玩家【%s】拒绝立即开局", u.nickname)
  2769. showTooltip(txt)
  2770. end
  2771. app.room.roomInfo.quickStartInfo = nil
  2772. self:showFastStart(true)
  2773. else
  2774. self.fastStartRequestView:updateView(response)
  2775. end
  2776. end
  2777. end
  2778. function zgwrDdzRoomView:onFastStartSucc(data)
  2779. if self.fastStartRequestView then
  2780. self.fastStartRequestView:removeFromParent()
  2781. self.fastStartRequestView = nil
  2782. end
  2783. self:showFastStart(false)
  2784. --self.playerView:setPlayerVisible(false)
  2785. --self:updateRoomBaseData()
  2786. --刷新房间玩家位置
  2787. if data.response then
  2788. --删除所有玩家节点
  2789. for k,v in pairs(data.response.pList) do
  2790. self:delPlayerNode(v.nUserId)
  2791. end
  2792. self:initChatView()
  2793. --重新添加玩家节点
  2794. local players = app.room:getPlayers()
  2795. for _, info in pairs(players) do
  2796. self:addPlayerNode( info )
  2797. end
  2798. end
  2799. end
  2800. --是否显示快速开始页面
  2801. function zgwrDdzRoomView:isShowFastStartView()
  2802. do return end
  2803. --快速开始数据
  2804. local roomInfo = app.room:getRoomInfo()
  2805. if roomInfo then
  2806. local fastData = {}
  2807. fastData.response = {}
  2808. fastData.response.nStatus = roomInfo.userFastStartStatus
  2809. fastData.response.timeOut = roomInfo.fastStartTimeout
  2810. fastData.response.pList = {}
  2811. if roomInfo.fastStartPlayersStatus then
  2812. for k,v in pairs(roomInfo.fastStartPlayersStatus) do
  2813. local playerList = {}
  2814. if v.fastStartStatus and v.fastStartStatus == 1 then
  2815. --玩家发起申请
  2816. fastData.response.nUserId = v.userId
  2817. end
  2818. playerList.nStatus = v.fastStartStatus
  2819. playerList.nUserId = v.userId
  2820. table.insert(fastData.response.pList, playerList)
  2821. end
  2822. end
  2823. logD("zgwrDdzRoomView:isShowFastStartView roomInfo = "..table.tostring(roomInfo))
  2824. logD("zgwrDdzRoomView:isShowFastStartView fastData = "..table.tostring(fastData))
  2825. self:onBroadcastFaststart(fastData)
  2826. end
  2827. end
  2828. function zgwrDdzRoomView:onApplicationWillEnterForeground()
  2829. --从后台返回游戏,但未重连,此时数据未改变
  2830. local roomInfo = app.room:getRoomInfo()
  2831. if roomInfo and roomInfo.nGameStartCount and roomInfo.nGameStartCount <= 0 then
  2832. --从后台返回游戏时,如果已经开始游戏,则不处理快速开始view
  2833. self:isShowFastStartView()
  2834. end
  2835. end
  2836. --解析记牌器数据
  2837. function zgwrDdzRoomView:calcJiPaiQiData(data)
  2838. if not data or data == "" then
  2839. return ""
  2840. end
  2841. local jxData = json.decode(data)
  2842. if jxData then
  2843. return jxData
  2844. end
  2845. end
  2846. --设置记牌器显示或隐藏
  2847. function zgwrDdzRoomView:showJiPaiQi(vis,data)
  2848. vis = false
  2849. if vis and vis == true then
  2850. local roomInfo = app.room:getRoomInfo()
  2851. local gameInfo = roomInfo.nGameInfo
  2852. if not gameInfo then return end
  2853. local ruleInfo = json.decode(gameInfo)
  2854. local playernum = app.room:getPlayerNum()
  2855. if ruleInfo and ruleInfo.specialRule and getNumBand(ruleInfo.specialRule, 0x0001)>0 and playernum>2 then
  2856. self.ui.Items.Layout_jipaiqi:setVisible(true)
  2857. local leftcardData = self:calcJiPaiQiData(data)
  2858. if not data then return end
  2859. for i=1,14 do
  2860. if leftcardData[tostring(i)] then
  2861. local nodeStr = string.format("Lable_leftCard_%d",i)
  2862. self.ui.Items[nodeStr]:setText(leftcardData[tostring(i)])
  2863. end
  2864. end
  2865. else
  2866. self.ui.Items.Layout_jipaiqi:setVisible(false)
  2867. end
  2868. else
  2869. --self.ui.Items.Layout_jipaiqi:setVisible(false)
  2870. end
  2871. end
  2872. -- 服务器广播玩家数据发生变化
  2873. function zgwrDdzRoomView:onGpsChangeResponse(data)
  2874. logD("zgwrDdzRoomView:onGpsChangeResponse()")
  2875. if not data or not data.nUserId then
  2876. return
  2877. end
  2878. local roomInfo = app.room:getRoomInfo()
  2879. local nUserId = data.nUserId
  2880. logD("zgwrDdzRoomView:onGpsChangeResponse()", tostring(nUserId))
  2881. --self:checkGpsDistance(nUserId,roomInfo.nGameStartCount==0)
  2882. end
  2883. function zgwrDdzRoomView:initGpsComponent()
  2884. if cc.Application:getInstance():getTargetPlatform() == 0 then
  2885. -- PC不显示GPS
  2886. return ;
  2887. end
  2888. if self.isRecordScene then return end--回放场景直接return
  2889. local versionCode = getAppVersionCode()
  2890. versionCode = tonumber(versionCode) or 0
  2891. logD("zgwrDdzRoomView:initGpsComponent() versionCode = ", versionCode)
  2892. if isReviewVersion() then
  2893. self.ui.Items.btnGps:setVisible(false)
  2894. return
  2895. end
  2896. local function exitRoomCallback()
  2897. local isGameStart = app.room:getRoomInfo().nGameStartCount > 0
  2898. if isGameStart then
  2899. app.room:requestDismissRoom(1)
  2900. else
  2901. self.ui:sendMsg(app.room, "callLeaveRequest");
  2902. end
  2903. end
  2904. -- 创建 gps 组件
  2905. self.gpsComponent = import("luaScript.Views.Room.RoomGpsComponentView"):new(5,self.ui.Items.btnGps,exitRoomCallback,exitRoomCallback)
  2906. self.gpsComponent:setLocalZOrder(100)
  2907. self:addChild(self.gpsComponent)
  2908. -- GPS 按钮
  2909. self.ui.Items.btnGps:registerClick(handler(self , self.showGpsView))
  2910. -- 我的GPS数据发生变化时检测是否需要通知服务器
  2911. --self:bindEvent(app, "onGpsInoChanged", handler(self, self.checkMyGpsNeedUpdate))
  2912. --self.isInitCheckGps = false
  2913. -- 进入时检测一遍我的GPS数据是否需要更新
  2914. --self:checkMyGpsNeedUpdate()
  2915. end
  2916. --清楚所有闹钟
  2917. function zgwrDdzRoomView:clearAllClock()
  2918. for _,node1 in pairs(self._playerNodes) do
  2919. node1:setTurn(false)
  2920. end
  2921. end
  2922. -- 检查服务器记录的我的GPS数据是最新的,如果不是,则请求更新
  2923. --[[function zgwrDdzRoomView:checkMyGpsNeedUpdate(event)
  2924. logD("zgwrDdzRoomView:checkMyGpsNeedUpdate()")
  2925. if self.isInitCheckGps and not event then
  2926. return
  2927. end
  2928. self.isInitCheckGps = true
  2929. local nMyUserId = app.user.loginInfo.uid
  2930. local myMemberInfo = app.room:getUserInfo(nMyUserId) or nil
  2931. if myMemberInfo then
  2932. local userInfo = json.decode(myMemberInfo)
  2933. if userInfo then
  2934. local gpsInfo = userInfo.gpsInfo
  2935. local isNewest = app.user:isGpsInfoNewest(gpsInfo)
  2936. logD("zgwrDdzRoomView:checkMyGpsNeedUpdate() gpsInfo is isNewest = ", tostring(isNewest))
  2937. if not isNewest then
  2938. app.room:onGpsChangeRequest();
  2939. else
  2940. logD("zgwrDdzRoomView:checkMyGpsNeedUpdate() gpsInfo is newest")
  2941. end
  2942. else
  2943. logD("zgwrDdzRoomView:checkMyGpsNeedUpdate() userInfo is nil")
  2944. end
  2945. else
  2946. logD("zgwrDdzRoomView:checkMyGpsNeedUpdate() myMemberInfo is nil")
  2947. end
  2948. end--]]
  2949. -- 更新所有玩家的信息到GPS组件
  2950. function zgwrDdzRoomView:updateAllGpsInfo()
  2951. if self.isRecordScene then return end--回放场景直接return
  2952. --[[local userInfoList = {}
  2953. for nUserId, memberInfo in pairs(app.room.roomInfo.memberList) do
  2954. local nSeatId = memberInfo.nSeatId
  2955. local userInfo = memberInfo.userInfo
  2956. if userInfo then
  2957. local userInfo2 = json.decode(userInfo)
  2958. if userInfo2 then
  2959. userInfoList[nUserId] = {nSeatId = nSeatId, userInfo = userInfo}
  2960. end
  2961. end
  2962. end--]]
  2963. local userInfoList = app.room:getUserInfoList()
  2964. if self.gpsComponent then
  2965. self.gpsComponent:updateUserInfos(userInfoList)
  2966. end
  2967. end
  2968. -- 服务器广播玩家游戏状态发生变化
  2969. function zgwrDdzRoomView:onUpdateGameStatus(data)
  2970. logD("zgwrDdzRoomView:onUpdateGameStatus()")
  2971. if data.response.gameStatus == DdzRoomViewConfig.GameStatus.GAME_STATUS_SELECT_CARD then
  2972. self:clearAllClock()
  2973. for _,node1 in pairs(self._playerNodes) do
  2974. if node1 then node1:cleanPass() end
  2975. end
  2976. elseif data.response.gameStatus == DdzRoomViewConfig.GameStatus.GAME_STATUS_PLAYING then
  2977. self:showBgTips(false)
  2978. end
  2979. end
  2980. -- 通知玩家抢地主
  2981. function zgwrDdzRoomView:onNoticeGrabLord(data)
  2982. logD("zgwrDdzRoomView:onNoticeGrabLord()")
  2983. local function __qiangdizhu(onEnd)
  2984. local node = self:getPlayerNode(data.response.userId)
  2985. if app.room:isMyself(data.response.userId) then
  2986. self:showJiaoDiZhu()
  2987. end
  2988. if node then
  2989. node:setTurn(true)
  2990. end
  2991. if onEnd and type(onEnd)=='function' then onEnd() end
  2992. end
  2993. self:addFunction(__qiangdizhu)
  2994. end
  2995. --无人抢地主重新洗牌
  2996. function zgwrDdzRoomView:onShuffleCards(data)
  2997. logD("zgwrDdzRoomView:onShuffleCards()")
  2998. self:resetRoundData()
  2999. self.ui:runDelay(0.0, function() self:showZhangShui() end)
  3000. --[[local delay = 1.4
  3001. local function __onEnd()
  3002. if onEnd and type(onEnd)=='function' then onEnd() end
  3003. end
  3004. self.ui:runDelay(delay, __onEnd )--]]
  3005. local function __delay( onEnd )
  3006. self.ui:runDelay(1.4, function() if onEnd and type(onEnd)=='function' then onEnd() end end)
  3007. end
  3008. self:addFunction(__delay)
  3009. end
  3010. --广播抢地主结果
  3011. function zgwrDdzRoomView:onBroadGrabLordResult(data)
  3012. logD("zgwrDdzRoomView:onBroadGrabLordResult()")
  3013. local node = self:getPlayerNode(data.response.userId)
  3014. if data.response.opType == 0 then--不抢地主
  3015. if node then
  3016. node:showJiaoDiZhu(false)
  3017. node:setTurn(false)
  3018. end
  3019. else
  3020. local function callback()
  3021. --清除抢地主桌面上的操作字
  3022. for _,node1 in pairs(self._playerNodes) do
  3023. if node1 then node1:cleanPass() end
  3024. if node1 ~= node then
  3025. node1:setTurn(true)
  3026. end
  3027. end
  3028. if node then
  3029. node:setTurn(false)
  3030. node:setHost(true)
  3031. end
  3032. if app.room:isMyself(data.response.userId) then
  3033. self._isLorder = true
  3034. end
  3035. local roomInfo = app.room:getRoomInfo()
  3036. roomInfo.nLordId = data.response.userId
  3037. DdzSoundHelper:effectJiaoDiZhu(node:getInfo().sex,true)
  3038. end
  3039. --显示叫地主动画
  3040. self:showEffectJiaoDiZhu(node,callback)
  3041. end
  3042. self:hideUI()
  3043. end
  3044. --将底牌发给地主
  3045. function zgwrDdzRoomView:onSendDiCardsToLord(data)
  3046. logD("zgwrDdzRoomView:onSendDiCardsToLord()")
  3047. if app.room:isMyself(data.response.userId) then
  3048. local handcards = self:getHandCards()
  3049. for i,v in pairs(data.response.cards) do
  3050. table.insert(handcards,v)
  3051. end
  3052. self:recoverHandcards(handcards)
  3053. --[[local cards = pokerSortPdkCards(handcards)
  3054. local allCount = 31
  3055. for i,card in ipairs(cards) do
  3056. local index = i
  3057. self:sendOneCardNoAct(card.cid, index, 1, index==allCount, allCount)
  3058. end
  3059. self:resetCardsPos()--]]
  3060. local node = self:getPlayerNode(data.response.userId)
  3061. for _,node1 in pairs(self._playerNodes) do
  3062. if node1 then node1:cleanPass() end
  3063. if node1 ~= node then
  3064. node1:setTurn(true)
  3065. end
  3066. end
  3067. self:showBgTips(true,7)
  3068. end
  3069. local node = self:getPlayerNode(data.response.userId)
  3070. node:showLeft(31)
  3071. self:showDiPai(data.response.cards)
  3072. end
  3073. --玩家获取手牌
  3074. function zgwrDdzRoomView:onGetUserCards(data)
  3075. logD("zgwrDdzRoomView:onGetUserCards()")
  3076. if app.room:isMyself(data.response.userId) then
  3077. self:recoverHandcards(data.response.cards)
  3078. end
  3079. end
  3080. --通知玩家加倍
  3081. function zgwrDdzRoomView:onBroadNoticeDouble(data)
  3082. logD("zgwrDdzRoomView:onBroadNoticeDouble()")
  3083. if data.response.isLord == 0 then--玩家加倍
  3084. --清楚抢地主桌面上的操作字
  3085. for _,node in pairs(self._playerNodes) do
  3086. if node then node:cleanPass() end
  3087. end
  3088. if not app.room:isMyself(data.response.lordUserId) then
  3089. self:showJiaBei()
  3090. end
  3091. else--地主反加倍
  3092. if app.room:isMyself(data.response.lordUserId) then
  3093. self:showFanJiaBei()
  3094. self:showBgTips(false)
  3095. end
  3096. end
  3097. --self:showBgTips(true,7)
  3098. end
  3099. --玩家加倍结果
  3100. function zgwrDdzRoomView:onAddMultResult(data)
  3101. logD("zgwrDdzRoomView:onAddMultResult()")
  3102. local node = self:getPlayerNode(data.response.userId)
  3103. local roomInfo = app.room:getRoomInfo()
  3104. if node then
  3105. if roomInfo.nLordId and roomInfo.nLordId == data.response.userId then
  3106. node:showFanJiaBei(data.response.opMult == 1)
  3107. node:setFanMult(data.response.opMult == 1)
  3108. node:setTurn(false)
  3109. else
  3110. node:showJiaBei(data.response.opMult == 1)
  3111. node:setMult(data.response.opMult == 1)
  3112. node:setTurn(false)
  3113. end
  3114. end
  3115. if app.room:isMyself(data.response.userId) then
  3116. self:showBgTips(true,7)
  3117. self:hideUI()
  3118. end
  3119. end
  3120. --广播地主选牌(暗地主)
  3121. function zgwrDdzRoomView:onBroadLordSelectCard(data)
  3122. logD("zgwrDdzRoomView:onBroadLordSelectCard()")
  3123. if app.room:isMyself(data.response.userId) then
  3124. for k,v in pairs(self._selfCards) do
  3125. local isCanSelect = false
  3126. for i,j in pairs(data.response.cards) do
  3127. if v:getVal() == j then
  3128. isCanSelect = true
  3129. break
  3130. end
  3131. end
  3132. if isCanSelect then
  3133. v:setNormal()
  3134. v:setTouMingDu(false)
  3135. else
  3136. v:setNormal()
  3137. v:setNoTouch( true )
  3138. end
  3139. end
  3140. self:showXuanAnDiZhu()
  3141. self:checkSelectCardBtnEnabled()
  3142. else
  3143. --显示等待地主选择暗地主
  3144. self:showBgTips(true,0)
  3145. end
  3146. local node = self:getPlayerNode(data.response.userId)
  3147. if node then
  3148. node:setTurn(true)
  3149. end
  3150. end
  3151. --广播玩家选牌结果
  3152. function zgwrDdzRoomView:onLordSelectCardResult(data)
  3153. logD("zgwrDdzRoomView:onLordSelectCardResult()")
  3154. local handcards = self:getHandCards()
  3155. self:recoverHandcards(handcards)
  3156. if data.response.card == 0x0e then--自吃
  3157. local function callback()
  3158. self:showZiChi(true)
  3159. end
  3160. local roomInfo = app.room:getRoomInfo()
  3161. local node = self:getPlayerNode(roomInfo.nLordId)
  3162. self:showZiChiAnim()
  3163. self:showZiChi(true)
  3164. else
  3165. local function callback()
  3166. self:showAnDiZhuCard(data.response.card)
  3167. end
  3168. DdzSoundHelper:effectSelectAnLordCard()
  3169. self:showEffectAnDiZhuCard(self.ui.Items.ImageView_andizhupai,data.response.card,callback)
  3170. end
  3171. end
  3172. -- 显示自吃
  3173. function zgwrDdzRoomView:showZiChiAnim(bShowAni)
  3174. local roomInfo = app.room:getRoomInfo()
  3175. local player = self:getPlayerNode(roomInfo.nLordId)--roomInfo.nLordId
  3176. if player then
  3177. local node = cc.ImageView:createNode();
  3178. fileName = "pk_zgwrddz/res/ui/zy_wrddz_btns/wrddz_lab_zichi.png"
  3179. node:setAnchorPoint(cc.p(0.5,0.5));
  3180. node:loadTexture(fileName)
  3181. node:setTag(2000)
  3182. local pos = player._info.viewPos
  3183. local pt = clone(DdzRoomViewConfig.SHOW_CARD_POS[player._PlayMode][pos])
  3184. node:setPosition(pt)
  3185. node:setLocalZOrder(1000)
  3186. node:setScale(0)
  3187. self:addChild(node)
  3188. local myself = app.room:getMyself()
  3189. if myself and myself.viewPos == pos then
  3190. self._isShowZiChi = true
  3191. end
  3192. local actions={
  3193. cc.ScaleTo:create(0.1, 1),
  3194. cc.DelayTime:create(1.1),
  3195. cc.CallFunc:create(function()
  3196. end),
  3197. cc.RemoveSelf:create()
  3198. }
  3199. node:runAction(cc.Sequence:create(actions))
  3200. end
  3201. end
  3202. --告知暗地主玩家
  3203. function zgwrDdzRoomView:onNoticeAnLordPlayer(data)
  3204. logD("zgwrDdzRoomView:onNoticeAnLordPlayer()")
  3205. if app.room:isMyself(data.response.userId) then
  3206. self._isDarkLorder = true
  3207. self:resetCardsPos()
  3208. end
  3209. local function callback()
  3210. local node = self:getPlayerNode(data.response.userId)
  3211. node:setAnDiZhu(true)
  3212. end
  3213. --显示暗地主动画
  3214. local function showAnDiZhu()
  3215. local node = self:getPlayerNode(data.response.userId)
  3216. self:showEffectAnDiZhu(node,callback)
  3217. end
  3218. self.ui:runDelay(0.5, function() showAnDiZhu() end)
  3219. end
  3220. --获取可出牌的组合
  3221. function zgwrDdzRoomView:onGetOutCardsResult(data)
  3222. logD("zgwrDdzRoomView:onGetOutCardsResult()")
  3223. local canOutCards = data.response.byOutCard
  3224. if canOutCards and type(canOutCards) == 'table' then
  3225. if #canOutCards == 1 then
  3226. local cards = self:getSelected()
  3227. if data.response.byOutCard[1] then
  3228. app.room:requestOutCards(cards,data.response.byOutCard[1].byOutCard)
  3229. end
  3230. elseif #canOutCards > 1 then
  3231. self:showCanOutCards(canOutCards)
  3232. end
  3233. end
  3234. end
  3235. function zgwrDdzRoomView:onUpdateGameMult(data)
  3236. logD("zgwrDdzRoomView:onUpdateGameMult()")
  3237. local mult = data.response.gameMult
  3238. self.ui.Items.TextBMFont_beishu:setText(mult)
  3239. self.ui.Items.TextBMFont_difen:setText("1")
  3240. end
  3241. --显示叫地主
  3242. function zgwrDdzRoomView:showJiaoDiZhu()
  3243. self:hideJiaoDiZhu()
  3244. local ui=loadUI("pk_zgwrddz/res/ui/ui_room/ui_wrddz_jiaodizhu.ui")
  3245. self.ui.Items.Layout_Menu:addChild(ui)
  3246. self.jiaodizhu=ui
  3247. ui.Items.btn_bujiao:registerClick(function()
  3248. playBtnEffect()
  3249. self:hideJiaoDiZhu()
  3250. local request = DdzMessage.GrabLordRequest:new()
  3251. request.type = 0
  3252. self.ui:sendMsg(app.room,"requestGrabLord",request)
  3253. end)
  3254. ui.Items.btn_jiaodizhu:registerClick(function()
  3255. playBtnEffect()
  3256. self:hideJiaoDiZhu()
  3257. local request = DdzMessage.GrabLordRequest:new()
  3258. request.type = 1
  3259. self.ui:sendMsg(app.room,"requestGrabLord",request)
  3260. end)
  3261. end
  3262. function zgwrDdzRoomView:hideJiaoDiZhu()
  3263. if self.jiaodizhu then
  3264. self.jiaodizhu:removeFromParent()
  3265. self.jiaodizhu=nil
  3266. end
  3267. end
  3268. --显示加倍
  3269. function zgwrDdzRoomView:showJiaBei()
  3270. self:hideJiaBei()
  3271. local ui=loadUI("pk_zgwrddz/res/ui/ui_room/ui_wrddz_jiabei.ui")
  3272. self.ui.Items.Layout_Menu:addChild(ui)
  3273. self.jiabei=ui
  3274. ui.Items.btn_bujiabei:registerClick(function()
  3275. playBtnEffect()
  3276. self:hideJiaBei()
  3277. local request = DdzMessage.AddMultRequest:new()
  3278. request.mult = 0
  3279. self.ui:sendMsg(app.room,"requestAddMult",request)
  3280. end)
  3281. ui.Items.btn_jiabei:registerClick(function()
  3282. playBtnEffect()
  3283. self:hideJiaBei()
  3284. local request = DdzMessage.AddMultRequest:new()
  3285. request.mult = 1
  3286. self.ui:sendMsg(app.room,"requestAddMult",request)
  3287. end)
  3288. end
  3289. function zgwrDdzRoomView:hideJiaBei()
  3290. if self.jiabei then
  3291. self.jiabei:removeFromParent()
  3292. self.jiabei=nil
  3293. end
  3294. end
  3295. --显示反加倍
  3296. function zgwrDdzRoomView:showFanJiaBei()
  3297. self:hideFanJiaBei()
  3298. local ui=loadUI("pk_zgwrddz/res/ui/ui_room/ui_wrddz_fanjiabei.ui")
  3299. self.ui.Items.Layout_Menu:addChild(ui)
  3300. self.fanjiabei=ui
  3301. ui.Items.btn_bufan:registerClick(function()
  3302. playBtnEffect()
  3303. self:hideFanJiaBei()
  3304. local request = DdzMessage.AddMultRequest:new()
  3305. request.mult = 0
  3306. self.ui:sendMsg(app.room,"requestAddMult",request)
  3307. end)
  3308. ui.Items.btn_fanjiabei:registerClick(function()
  3309. playBtnEffect()
  3310. self:hideFanJiaBei()
  3311. local request = DdzMessage.AddMultRequest:new()
  3312. request.mult = 1
  3313. self.ui:sendMsg(app.room,"requestAddMult",request)
  3314. end)
  3315. end
  3316. function zgwrDdzRoomView:hideFanJiaBei()
  3317. if self.fanjiabei then
  3318. self.fanjiabei:removeFromParent()
  3319. self.fanjiabei=nil
  3320. end
  3321. end
  3322. --选暗地主牌
  3323. function zgwrDdzRoomView:showXuanAnDiZhu()
  3324. self:showBgTips(true,8)
  3325. self:hideXuanAnDiZhui()
  3326. local ui=loadUI("pk_zgwrddz/res/ui/ui_room/ui_wrddz_xuanpai.ui")
  3327. self.ui.Items.Layout_Menu:addChild(ui)
  3328. self.xuanandizhu=ui
  3329. ui.Items.btn_xuanpai:registerClick(function()
  3330. playBtnEffect()
  3331. local scard = self:getSelected()
  3332. local cardVal = 0
  3333. if scard and #scard == 1 then
  3334. cardVal = scard[1]
  3335. else
  3336. showTooltip("请选择正确张数的牌!")
  3337. return
  3338. end
  3339. self:hideXuanAnDiZhui()
  3340. local request = DdzMessage.Card:new()
  3341. request.card = cardVal
  3342. self.ui:sendMsg(app.room,"requestSelectCard",request)
  3343. end)
  3344. ui.Items.btn_zichi:registerClick(function()
  3345. playBtnEffect()
  3346. local cardVal = 0x0e
  3347. self:hideXuanAnDiZhui()
  3348. local request = DdzMessage.Card:new()
  3349. request.card = cardVal
  3350. self.ui:sendMsg(app.room,"requestSelectCard",request)
  3351. end)
  3352. end
  3353. function zgwrDdzRoomView:hideXuanAnDiZhui()
  3354. if self.xuanandizhu then
  3355. self.xuanandizhu:removeFromParent()
  3356. self.xuanandizhu=nil
  3357. end
  3358. end
  3359. --获取手牌中某个值的牌有几张
  3360. function zgwrDdzRoomView:getCardsNumByVal(val)
  3361. local handCards = self:getHandCards()
  3362. local valCardNums = 0
  3363. for i,v in pairs(handCards) do
  3364. if val == v then
  3365. valCardNums = valCardNums + 1
  3366. end
  3367. end
  3368. return valCardNums
  3369. end
  3370. --设置暗地主牌
  3371. function zgwrDdzRoomView:setSelectAnLordCard()
  3372. --[[for k,v in pairs(self._selfCards) do
  3373. local tp , val = pokerParse(v:getVal())
  3374. --6-k当中选暗地主牌,且数量大于1
  3375. if val >= 1 and val <=8 and self:getCardsNumByVal(v:getVal()) > 1 then
  3376. v:setNoTouch(false)
  3377. v:setTouMingDu(false)
  3378. else
  3379. v:setNoTouch(true)
  3380. end
  3381. end--]]
  3382. local roomInfo = app.room:getRoomInfo()
  3383. for k,v in pairs(self._selfCards) do
  3384. local isCanSelect = false
  3385. for i,j in pairs(roomInfo.canSelectCards or {}) do
  3386. if v:getVal() == j then
  3387. isCanSelect = true
  3388. break
  3389. end
  3390. end
  3391. if isCanSelect then
  3392. v:setNormal()
  3393. v:setTouMingDu(false)
  3394. else
  3395. v:setNormal()
  3396. v:setNoTouch( true )
  3397. end
  3398. end
  3399. end
  3400. --恢复顶部底牌和暗地主牌成默认状态(没翻开)
  3401. function zgwrDdzRoomView:resetTopCardStatus()
  3402. for i=1,6 do
  3403. local dipai = string.format("ImageView_dipai_%d",i)
  3404. if self.ui.Items[dipai] then
  3405. self.ui.Items[dipai]:loadTexture("wrddz_lcards_back.png",1)
  3406. end
  3407. end
  3408. self.ui.Items.ImageView_andizhupai:loadTexture("wrddz_lcards_back.png",1)
  3409. self:showZiChi(false)
  3410. end
  3411. --显示地主抓的底牌
  3412. function zgwrDdzRoomView:showDiPai(cards)
  3413. if not cards or type(cards) ~= 'table' then return end
  3414. local index = 1
  3415. for i,v in pairs(cards) do
  3416. local cardPng = pokerLPng(v)
  3417. local dipai = string.format("ImageView_dipai_%d",index)
  3418. if self.ui.Items[dipai] then
  3419. self.ui.Items[dipai]:loadTexture(cardPng,1)
  3420. end
  3421. index = index + 1
  3422. end
  3423. end
  3424. --显示地主选的暗地主牌
  3425. function zgwrDdzRoomView:showAnDiZhuCard(card)
  3426. local roomInfo = app.room:getRoomInfo()
  3427. roomInfo.nDarkLordCard = roomInfo.nDarkLordCard or card
  3428. if card == 0x0e then
  3429. self:showZiChi(true)
  3430. else
  3431. self:showZiChi(false)
  3432. local cardPng = pokerLPng(card)
  3433. self.ui.Items.ImageView_andizhupai:loadTexture(cardPng,1)
  3434. end
  3435. end
  3436. --显示自吃
  3437. function zgwrDdzRoomView:showZiChi(show)
  3438. self.ui.Items.ImageView_zichi:setVisible(show)
  3439. end
  3440. --展示可出的组合牌
  3441. function zgwrDdzRoomView:showCanOutCards(outCards)
  3442. --[[outCards = {
  3443. [1] = {1,2,3,4,4},
  3444. [2] = {1,2,3,4,4},
  3445. [3] = {1,2,3,4,4},
  3446. [4] = {1,2,3,4,4},
  3447. [5] = {1,2,3,4,4},
  3448. }--]]
  3449. local ui=loadUI("pk_zgwrddz/res/ui/ui_room/ui_wrddz_outCardGroup.ui")
  3450. self.ui.Items.canOutCardsLayout:addChild(ui)
  3451. self.selectOutCardUI = ui
  3452. local layoutMidPos = self.selectOutCardUI.Items.Layout_cardGroup:getContentSize().width/2
  3453. local cardsZuHeNum = #outCards
  3454. --小牌大小 (45,57)
  3455. local bgImgWidth = 0
  3456. local bgImgHeight = 0
  3457. local rowMaxNum = 13
  3458. local isOneLineRow = false--是否一排只放一组
  3459. for i,cards in pairs(outCards) do
  3460. --创建一个空的layout,layout放到组合牌点上
  3461. local mLayout = cc.Layout:createNode()
  3462. --开启触摸
  3463. mLayout:setTouchEnabled(true)
  3464. --设置锚点
  3465. mLayout:setAnchorPoint(cc.p(0,0))
  3466. --设置大小
  3467. mLayout:setSize(cc.size(30 + 40*(#cards.byOutCard),65))
  3468. isOneLineRow = #cards.byOutCard > rowMaxNum
  3469. for j,k in pairs(cards.byOutCard) do
  3470. local mCard = cc.ImageView:createNode()
  3471. local cardPng = pokerLPng(k)
  3472. mCard:setAnchorPoint(cc.p(0,0))
  3473. mCard:loadTextureFromPlist(cardPng)
  3474. mCard:setPosition(0+(j-1)*40,0);
  3475. mLayout:addChild(mCard,j);
  3476. end
  3477. mLayout:registerClick(function()
  3478. local scards = self:getSelected()
  3479. app.room:requestOutCards(scards,cards.byOutCard)
  3480. self:hideCanOutCards()
  3481. end)
  3482. local posx = 0
  3483. local posy = 0
  3484. if isOneLineRow then--一行一个
  3485. posx = layoutMidPos-mLayout:getContentSize().width/2 +15
  3486. posy = 0 + (i-1) * mLayout:getContentSize().height
  3487. else--一行两个
  3488. --奇数放左边
  3489. posx = layoutMidPos - mLayout:getContentSize().width -20 +30
  3490. --偶数放右边
  3491. if i%2 == 0 then
  3492. posx = layoutMidPos + 20
  3493. end
  3494. posy = 0 + math.floor((i-1)/2) * mLayout:getContentSize().height
  3495. end
  3496. mLayout:setPosition(cc.p(posx,posy))
  3497. self.selectOutCardUI.Items.Layout_cardGroup:addChild(mLayout)
  3498. if isOneLineRow then
  3499. bgImgWidth = mLayout:getContentSize().width +100
  3500. else
  3501. bgImgWidth = mLayout:getContentSize().width *2 +100
  3502. end
  3503. end
  3504. if isOneLineRow then
  3505. bgImgHeight = cardsZuHeNum * 65 +55
  3506. else
  3507. bgImgHeight = math.floor((cardsZuHeNum-1)/2 + 1) * 65 +55
  3508. end
  3509. self.selectOutCardUI.Items.ImageView_bg:setSize(cc.size(bgImgWidth,bgImgHeight))
  3510. end
  3511. function zgwrDdzRoomView:hideCanOutCards()
  3512. if self.selectOutCardUI then
  3513. self.selectOutCardUI:removeFromParent()
  3514. self.selectOutCardUI=nil
  3515. end
  3516. end
  3517. --检查并提示
  3518. function zgwrDdzRoomView:checkAndTip()
  3519. local cards = self:getSelected()
  3520. local handCards = self:getHandCards()
  3521. if cards and #cards > 0 then
  3522. local cards = zgwrDdzPokerUtil2.getOneTip(cards,handCards,self._lastCards,self._lastOutType)
  3523. self:tipsCard(cards)
  3524. end
  3525. end
  3526. function zgwrDdzRoomView:checkSelectCardBtnEnabled()
  3527. if tolua.isnull(self.xuanandizhu) then
  3528. return
  3529. end
  3530. local cards = self:getSelected()
  3531. if cards and #cards == 1 then
  3532. self.xuanandizhu.Items.btn_xuanpai:setEnabled(true)
  3533. else
  3534. self.xuanandizhu.Items.btn_xuanpai:setEnabled(false)
  3535. end
  3536. end
  3537. function zgwrDdzRoomView:checkOutCardBtnEnabled()
  3538. --do return end
  3539. if not self.ui.Items.Layout_out:isVisible() then--出牌按钮不可见
  3540. return
  3541. end
  3542. local curOpType = self.curCanOpFlag or 1 ----0-pass 1-可以出牌也可以pass 2-只能出牌
  3543. if curOpType == 0 then--只能pass不用算
  3544. return
  3545. end
  3546. local cards = self:getSelected()
  3547. if cards and #cards == 0 then
  3548. self.ui.Items.Button_out:setEnabled(false)
  3549. return
  3550. end
  3551. local isAllGui = PokerUtil:checkIsAllGui(cards)
  3552. if isAllGui then
  3553. self.ui.Items.Button_out:setEnabled(false)
  3554. return
  3555. end
  3556. local tp = PokerUtil:checkType(cards)
  3557. if curOpType == 2 then--只能出牌
  3558. if tp > 0 and tp <100 then
  3559. self.ui.Items.Button_out:setEnabled(true)
  3560. else
  3561. self.ui.Items.Button_out:setEnabled(false)
  3562. end
  3563. return
  3564. end
  3565. --self._lastOutType
  3566. if (not DdzRoomViewConfig.isBomb(self._lastOutType)) and DdzRoomViewConfig.isBomb(tp) then
  3567. self.ui.Items.Button_out:setEnabled(true)
  3568. elseif DdzRoomViewConfig.isBomb(self._lastOutType) and DdzRoomViewConfig.isBomb(tp) and tp ~= self._lastOutType then
  3569. if tp > self._lastOutType then
  3570. self.ui.Items.Button_out:setEnabled(true)
  3571. else
  3572. self.ui.Items.Button_out:setEnabled(false)
  3573. end
  3574. else
  3575. if self._lastCards and type(self._lastCards) == 'table' and #self._lastCards > 0 then
  3576. if #self._lastCards == #cards then
  3577. if tp == self._lastOutType then
  3578. if (tp >= ETS.TWO_SMALL_KING and tp <= ETS.TWO_BIG_KING) or (tp >= ETS.FOUR_SMALL_KING and tp <= ETS.FOUR_BIG_KING) then
  3579. local isHaveGui,guiNum = PokerUtil:checkHaveGui2(cards)
  3580. local isHaveGuil,guiNuml = PokerUtil:checkHaveGui2(self._lastCards)
  3581. if guiNum < guiNuml then--双大王(没有癞子)大于一大王一癞子
  3582. self.ui.Items.Button_out:setEnabled(true)
  3583. else
  3584. self.ui.Items.Button_out:setEnabled(false)
  3585. end
  3586. else
  3587. --最后一手牌牌型的最小值
  3588. local lastMinVal = PokerUtil:getCardsMin(self._lastCards,self._lastOutType)
  3589. --当前手牌牌型的最小值
  3590. local curMinVal = PokerUtil:getCardsMin(cards,tp)
  3591. if curMinVal > lastMinVal then
  3592. self.ui.Items.Button_out:setEnabled(true)
  3593. else
  3594. self.ui.Items.Button_out:setEnabled(false)
  3595. end
  3596. end
  3597. elseif (self._lastOutType == ETS.AIRPLANE_SINGLE and tp == ETS.SAN_SHUN) then
  3598. local lastMinVal = PokerUtil:getCardsMin(self._lastCards,self._lastOutType)
  3599. local curMinVal = PokerUtil:getCardsMin(cards,tp)
  3600. if curMinVal >= lastMinVal then
  3601. self.ui.Items.Button_out:setEnabled(true)
  3602. else
  3603. self.ui.Items.Button_out:setEnabled(false)
  3604. end
  3605. else
  3606. self.ui.Items.Button_out:setEnabled(false)
  3607. end
  3608. else
  3609. self.ui.Items.Button_out:setEnabled(false)
  3610. end
  3611. else
  3612. --self.ui.Items.Button_out:setEnabled(true)
  3613. end
  3614. end
  3615. end
  3616. --显示状态提示
  3617. function zgwrDdzRoomView:showBgTips(vis,status)
  3618. if vis then
  3619. self.ui.Items.Layout_tips:setVisible(true)
  3620. self.ui.Items.Text_tips:setText(STATUS_INFO[status])
  3621. else
  3622. self.ui.Items.Layout_tips:setVisible(false)
  3623. end
  3624. end
  3625. --显示地主动画
  3626. function zgwrDdzRoomView:showEffectJiaoDiZhu(node,callback)
  3627. if not node then return end
  3628. local sprDiZhu = cc.ImageView:createNode()
  3629. sprDiZhu:setScale(0.0)
  3630. sprDiZhu:setAnchorPoint(cc.p(0.5,0.5))
  3631. sprDiZhu:loadTexture("pk_zgwrddz/res/ui/zy_room/wrddz_img_lord.png")
  3632. sprDiZhu:setPosition(CENTER_X,400*g_radio_y);
  3633. sprDiZhu:setOpacity(150)
  3634. local desPos
  3635. if node and node.imgHost then
  3636. desPos = node.imgHost:getWorldPosition()
  3637. else
  3638. desPos = node:getWorldPosition()
  3639. end
  3640. local action={
  3641. cc.Spawn:create(cc.EaseBackOut:create(cc.ScaleTo:create(0.1,0.6)),cc.FadeTo:create(0.1,255)),
  3642. cc.ScaleTo:create(0.1,0.5),
  3643. cc.DelayTime:create(0.1),
  3644. cc.MoveTo:create(0.3,desPos),
  3645. cc.CallFunc:create(function()
  3646. if callback then
  3647. callback()
  3648. end
  3649. end),
  3650. cc.RemoveSelf:create(),
  3651. }
  3652. sprDiZhu:runAction(cc.Sequence:create(action))
  3653. self.ui.Items.canOutCardsLayout:addChild(sprDiZhu);
  3654. end
  3655. --显示暗地主动画
  3656. function zgwrDdzRoomView:showEffectAnDiZhu(node,callback)
  3657. if not node then return end
  3658. local sprDiZhu = cc.ImageView:createNode()
  3659. sprDiZhu:setScale(0.0)
  3660. sprDiZhu:setAnchorPoint(cc.p(0.5,0.5))
  3661. sprDiZhu:loadTexture("pk_zgwrddz/res/ui/zy_room/wrddz_img_anlord.png")
  3662. sprDiZhu:setPosition(CENTER_X,400*g_radio_y);
  3663. sprDiZhu:setOpacity(150)
  3664. local desPos
  3665. if node and node.imgAndizhu then
  3666. desPos = node.imgAndizhu:getWorldPosition()
  3667. else
  3668. desPos = node:getWorldPosition()
  3669. end
  3670. local action={
  3671. cc.Spawn:create(cc.EaseBackOut:create(cc.ScaleTo:create(0.1,0.2)),cc.FadeTo:create(0.1,255)),
  3672. cc.ScaleTo:create(0.1,1),
  3673. cc.DelayTime:create(0.1),
  3674. cc.MoveTo:create(0.3,desPos),
  3675. cc.CallFunc:create(function()
  3676. if callback then
  3677. callback()
  3678. end
  3679. end),
  3680. cc.RemoveSelf:create(),
  3681. }
  3682. sprDiZhu:runAction(cc.Sequence:create(action))
  3683. self.ui.Items.canOutCardsLayout:addChild(sprDiZhu);
  3684. end
  3685. --显示暗地主牌动画
  3686. function zgwrDdzRoomView:showEffectAnDiZhuCard(node,card,callback)
  3687. if self.tuoguanView and self.tuoguanView:isVisible() then
  3688. self:hideUI()
  3689. end
  3690. if not node then return end
  3691. local sprDiZhu = cc.ImageView:createNode()
  3692. sprDiZhu:setScale(0.0)
  3693. sprDiZhu:setAnchorPoint(cc.p(0.5,0.5))
  3694. local cardPng = pokerLPng(card)
  3695. sprDiZhu:loadTexture(cardPng,1)
  3696. sprDiZhu:setPosition(CENTER_X,400*g_radio_y);
  3697. sprDiZhu:setOpacity(150)
  3698. local desPos
  3699. if node and node.imgAndizhu then
  3700. desPos = node.imgAndizhu:getWorldPosition()
  3701. else
  3702. desPos = node:getWorldPosition()
  3703. end
  3704. local action={
  3705. cc.Spawn:create(cc.EaseBackOut:create(cc.ScaleTo:create(0.1,0.2)),cc.FadeTo:create(0.1,255)),
  3706. cc.ScaleTo:create(0.1,1),
  3707. cc.DelayTime:create(0.1),
  3708. cc.MoveTo:create(0.3,desPos),
  3709. cc.CallFunc:create(function()
  3710. if callback then
  3711. callback()
  3712. end
  3713. end),
  3714. cc.RemoveSelf:create(),
  3715. }
  3716. sprDiZhu:runAction(cc.Sequence:create(action))
  3717. self.ui.Items.canOutCardsLayout:addChild(sprDiZhu);
  3718. end
  3719. -- 提示对应的牌
  3720. function zgwrDdzRoomView:tipsCard( cards )
  3721. if type(cards) == 'number' then
  3722. --啥也不做
  3723. elseif type(cards) == 'table' then
  3724. --self:resetSelect()
  3725. --self:resetCardsPos()
  3726. local hadSelectNode = {}--先把已经选出的牌标记出来,在选出的牌周围弹牌
  3727. for i,node in pairs(self.cardRoot:getChildren()) do
  3728. if node and node:isDown() then
  3729. table.insert(hadSelectNode,node)
  3730. end
  3731. end
  3732. --从算出的牌里面删掉已经弹起来的牌
  3733. for i,v in pairs(hadSelectNode) do
  3734. for j = #cards ,1,-1 do
  3735. if PokerUtil:getCardValue(v:getVal()) == PokerUtil:getCardValue(cards[j]) then
  3736. table.remove(cards,j)
  3737. break
  3738. end
  3739. end
  3740. end
  3741. if #hadSelectNode == 1 then
  3742. for i,node in pairs(hadSelectNode) do
  3743. local uniqueFlag = node:getUniqueFlag()
  3744. for k = uniqueFlag+1,31 do
  3745. local tnode = self.cardRoot:getChildByTag(k)
  3746. if tnode then
  3747. for j = #cards ,1,-1 do
  3748. if tnode:getVal() == cards[j] or PokerUtil:getCardValue(tnode:getVal()) == PokerUtil:getCardValue(cards[j]) then
  3749. tnode:setDown()
  3750. table.remove(cards,j)
  3751. break
  3752. end
  3753. end
  3754. end
  3755. end
  3756. if #cards == 0 then return end
  3757. for k = uniqueFlag-1,1,-1 do
  3758. local tnode = self.cardRoot:getChildByTag(k)
  3759. if tnode then
  3760. for j = #cards ,1,-1 do
  3761. if tnode:getVal() == cards[j] or PokerUtil:getCardValue(tnode:getVal()) == PokerUtil:getCardValue(cards[j]) then
  3762. tnode:setDown()
  3763. table.remove(cards,j)
  3764. break
  3765. end
  3766. end
  3767. end
  3768. end
  3769. if #cards == 0 then return end
  3770. end
  3771. elseif #hadSelectNode == 2 then
  3772. local node1 = hadSelectNode[1]
  3773. local node2 = hadSelectNode[2]
  3774. local uniqueFlag1 = node1:getUniqueFlag()
  3775. local uniqueFlag2 = node2:getUniqueFlag()
  3776. for k = uniqueFlag1+1,uniqueFlag2-1 do
  3777. local tnode = self.cardRoot:getChildByTag(k)
  3778. if tnode then
  3779. for j = #cards ,1,-1 do
  3780. if tnode:getVal() == cards[j] or PokerUtil:getCardValue(v:getVal()) == PokerUtil:getCardValue(cards[j]) then
  3781. tnode:setDown()
  3782. table.remove(cards,j)
  3783. break
  3784. end
  3785. end
  3786. end
  3787. end
  3788. if #cards == 0 then return end
  3789. for k = uniqueFlag2+1,31 do
  3790. local tnode = self.cardRoot:getChildByTag(k)
  3791. if tnode then
  3792. for j = #cards ,1,-1 do
  3793. if tnode:getVal() == cards[j] or PokerUtil:getCardValue(v:getVal()) == PokerUtil:getCardValue(cards[j]) then
  3794. tnode:setDown()
  3795. table.remove(cards,j)
  3796. break
  3797. end
  3798. end
  3799. end
  3800. end
  3801. if #cards == 0 then return end
  3802. for k = uniqueFlag1-1,1,-1 do
  3803. local tnode = self.cardRoot:getChildByTag(k)
  3804. if tnode then
  3805. for j = #cards ,1,-1 do
  3806. if tnode:getVal() == cards[j] or PokerUtil:getCardValue(v:getVal()) == PokerUtil:getCardValue(cards[j]) then
  3807. tnode:setDown()
  3808. table.remove(cards,j)
  3809. break
  3810. end
  3811. end
  3812. end
  3813. end
  3814. if #cards == 0 then return end
  3815. end
  3816. end
  3817. end
  3818. ---
  3819. -- 检测是否可以解散房间
  3820. -- @param
  3821. -- @return
  3822. --
  3823. function zgwrDdzRoomView:checkCanDismiss( )
  3824. local onCanDismissCallback = function (info)
  3825. local nUserId = app.room:getMyUserId()
  3826. local roomInfo = app.room.roomInfo or {}
  3827. local canDismiss = (tonumber(info.canDismiss or 1) == 1) or roomInfo.nRoomOwnedUid == nUserId or dd.IClub.isAdmin()
  3828. if roomInfo.nGameStartCount == 0 and roomInfo.nRoomOwnedUid ~= nUserId then
  3829. canDismiss = false
  3830. end
  3831. self:onCanDismissCallback(canDismiss)
  3832. end
  3833. if dd.IClub.getCanDismiss then
  3834. local canDismiss = dd.IClub.getCanDismiss(onCanDismissCallback)
  3835. if canDismiss then
  3836. onCanDismissCallback({canDismiss = canDismiss})
  3837. end
  3838. end
  3839. end
  3840. function zgwrDdzRoomView:onCanDismissCallback(canDismiss)
  3841. if self.ui.Items.Button_Dismiss then
  3842. self.ui.Items.Button_Dismiss:setEnabled(canDismiss)
  3843. self.ui.Items.Layout_Dismiss:setEnabled(canDismiss)
  3844. end
  3845. end
  3846. -- 托管通知
  3847. function zgwrDdzRoomView:onHostingResponse( data )
  3848. --local function onHostingResponseEx(onEnd)
  3849. local response = data.response
  3850. -- 如果是我,则显示托管layout界面
  3851. if response.nUserId == app.room:getMyUserId() then
  3852. if response.status == 1 then --托管状态
  3853. self:showTuoGuan(true)
  3854. self:hideUI()
  3855. elseif response.status == 0 then--取消托管状态
  3856. self:showTuoGuan(false)
  3857. end
  3858. end
  3859. local isTuoGuan = response.status == 1
  3860. local viewId = app.room:getViewIdByUserId(response.nUserId)
  3861. local node = self:getPlayerNodeVpos(viewId)
  3862. if node then
  3863. node:setTuoGuan(isTuoGuan)
  3864. end
  3865. --if onEnd then
  3866. -- onEnd()
  3867. --end
  3868. --end
  3869. --self:addCallBack(onHostingResponseEx)
  3870. end
  3871. --隐藏ui
  3872. function zgwrDdzRoomView:hideUI()
  3873. if self.tuoguanView and self.tuoguanView:isVisible() then
  3874. self:hideJiaoDiZhu()
  3875. self:hideJiaBei()
  3876. self:hideXuanAnDiZhui()
  3877. self:hideFanJiaBei()
  3878. self:hideCanOutCards()
  3879. end
  3880. end
  3881. --显示隐藏托管
  3882. function zgwrDdzRoomView:showTuoGuan(isShow)
  3883. if not self.tuoguanView then
  3884. self.tuoguanView = import("pk_zgwrddz.luaScript.Views.Room.RoomTuoGuanView"):new()
  3885. self:addChild(self.tuoguanView)
  3886. self.tuoguanView:setVisible(false)
  3887. end
  3888. self.tuoguanView:setVisible(isShow)
  3889. if isShow and isShow == true then
  3890. self:showTurnBtn(false)
  3891. end
  3892. end
  3893. function zgwrDdzRoomView:refreshPlayerAIStatus()
  3894. for _,v in pairs(app.room.roomInfo.memberList) do
  3895. local isTuoGuan = v.AIStatus == 1
  3896. print('zgwrDdzRoomView:refreshPlayerAIStatus', v.nUserId, isTuoGuan)
  3897. local viewId = app.room:getViewIdByUserId(v.nUserId)
  3898. local node = self:getPlayerNodeVpos(viewId)
  3899. if node then
  3900. node:setTuoGuan(isTuoGuan)
  3901. end
  3902. if v.nUserId == app.room:getMyUserId() then
  3903. if isTuoGuan and isTuoGuan == true then --托管状态
  3904. self:showTuoGuan(true)
  3905. end
  3906. end
  3907. end
  3908. end
  3909. ---
  3910. -- 初始化大结算再来一局
  3911. -- @return
  3912. --
  3913. function zgwrDdzRoomView:initPlayGameAgain()
  3914. local strGameInfo = app.room.roomInfo.nGameInfo
  3915. local isInClub = app.club_php.clubID and app.club_php.clubID ~= 0
  3916. if not isInClub then
  3917. logD("zgwrDdzRoomView.initPlayGameAgain", "当前玩家不在亲友圈内,不能再来一局");
  3918. return
  3919. end
  3920. local clubGameInfo = json.decode(strGameInfo) or {}
  3921. if not clubGameInfo.ruleid then
  3922. logD("RoomView_28.initPlayGameAgain", "游戏包间id不存在,不能再来一局");
  3923. return
  3924. end
  3925. dd.IPlayGameAgain.setAgainGameBaoJianId(clubGameInfo.ruleid)
  3926. end
  3927. ---
  3928. -- 清空lua缓存
  3929. --
  3930. function zgwrDdzRoomView:cleanCache()
  3931. local preload = package.loaded
  3932. for k, v in pairs(package.loaded or {}) do
  3933. local res = string.find( k, "pk_zgwrddz.luaScript") or 0
  3934. if res > 0 then
  3935. package.loaded[k] = nil
  3936. end
  3937. end
  3938. end
  3939. ---
  3940. -- 显示抽奖界面
  3941. --
  3942. function zgwrDdzRoomView:showGameOverAward()
  3943. if not (dd and dd.IGameOverAward) then
  3944. return
  3945. end
  3946. self:runDelay(0.1, function ( )
  3947. -- 延迟0.1秒执行,可能有些游戏弹大结算的时候还未收到抽奖消息
  3948. dd.IGameOverAward.showAwardView();
  3949. end)
  3950. end
  3951. return zgwrDdzRoomView