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.

1960 lines
57 KiB

  1. -- xx : 2018/5/7
  2. -- 跑得快回放界面
  3. local DdzDef = require("luaScript.SubGameDefine.zgwrDdzDefine")
  4. local DdzPlayerNode = require("pk_zgwrddz.luaScript.Views.Room.Node.zgwrDdzPlayerNode")
  5. local DdzCardNode = require("pk_zgwrddz.luaScript.Views.Room.Node.zgwrDdzCardNode")
  6. local DdzRoomViewConfig = require("pk_zgwrddz.luaScript.Views.Room.zgwrDdzRoomViewConfig")
  7. local DdzEffectHelper = require("pk_zgwrddz.luaScript.Views.Room.zgwrDdzEffectHelper"):new()
  8. local ETS = DdzRoomViewConfig.EffectType
  9. local DdzSoundHelper = require("pk_zgwrddz.luaScript.Views.Room.zgwrDdzSoundHelper"):new()
  10. --local WRDDZDefine=require("luaScript.SubGameDefine.zgwrDdzDefine")
  11. require("luaScript.Views.Room.RoomFunctions")
  12. local CENTER_X=640*g_radio_x
  13. local CENTER_Y=360*g_radio_y
  14. -- 表ta中是否包含元素x
  15. local function ownX( ta, x )
  16. local rst = false
  17. for _,v in ipairs(ta) do
  18. if tonumber(v) == tonumber(x) then
  19. rst = true
  20. break
  21. end
  22. end
  23. return rst
  24. end
  25. -- 获取ta表中移除tb表的结果
  26. local function getDelAdB( ta, tb )
  27. -- print("------------------getDelAdB---------------------------")
  28. -- print("----ta: ", table.concat(ta, "_"))
  29. -- print("----tb: ", table.concat(tb, "_"))
  30. --[[local tmp = {}
  31. for _,v in ipairs(ta) do
  32. if not ownX(tb, v) then
  33. table.insert(tmp, v)
  34. end
  35. end--]]
  36. -- print("----tmp: ", table.concat(tmp, "_"))
  37. -- print("------------------------------------------------------")
  38. local tmp = clone(ta)
  39. for _,v in pairs(tb) do
  40. if v >= 0x50 and v <= 0x5d then
  41. v = 0x5d
  42. end
  43. for i=#tmp,1,-1 do
  44. if tmp[i] == v then
  45. table.remove(tmp, i)
  46. break
  47. end
  48. end
  49. end
  50. return tmp
  51. end
  52. local OP_TYPE_STRING_NO = {
  53. single_card = ETS.SINGLE_CARD,
  54. three_and_two = ETS.THREE_AND_TWO,
  55. dui_zi = ETS.DUI_ZI,
  56. lian_dui = ETS.LIAN_DUI,
  57. airplane = ETS.AIRPLANE,
  58. shun_zi = ETS.SHUN_ZI,
  59. bomb = ETS.BOMB,
  60. four_and_three = ETS.FOUR_AND_THREE,
  61. }
  62. --------------------------------------------------------------------------------------------------------------------------------------------
  63. --------------------------------------------------------------------------------------------------------------------------------------------
  64. --------------------------------------------------------------------------------------------------------------------------------------------
  65. --------------------------------------------------------------------------------------------------------------------------------------------
  66. --------------------------------------------------------------------------------------------------------------------------------------------
  67. --------------------------------------------------------------------------------------------------------------------------------------------
  68. local PRoom = class("DdzRoomPlay")
  69. function PRoom:ctor( )
  70. -- 玩家信息
  71. self._players = {}
  72. -- 房间信息
  73. self.roomInfo = {}
  74. end
  75. -- 添加玩家,如果玩家存在则更新数据
  76. -- key - value 缓存
  77. function PRoom:addPlayer( pl )--and update
  78. self._players = self._players or {}
  79. local player = self._players[tostring(pl.userId)]
  80. if player then
  81. for k,v in pairs(pl) do
  82. player[k] = v
  83. end
  84. else
  85. self._players[tostring(pl.userId)] = pl
  86. end
  87. end
  88. -- 删除玩家
  89. function PRoom:delPlayer( uid )
  90. local player = self._players[tostring(uid)]
  91. if player then
  92. self._players[tostring(uid)] = nil
  93. end
  94. end
  95. -- 获取玩家
  96. function PRoom:getPlayer( uid )
  97. local player = self._players[tostring(uid)]
  98. return player
  99. end
  100. -- 根据座位号获取玩家数据
  101. function PRoom:getPlayerCid( cid )
  102. for _,v in pairs(self._players) do
  103. if v.seatId == cid then
  104. return v
  105. end
  106. end
  107. return nil
  108. end
  109. -- 根据视角获取玩家数据
  110. function PRoom:getPlayerVpos( viewPos )
  111. for _,v in pairs(self._players) do
  112. if v.viewPos == viewPos then
  113. return v
  114. end
  115. end
  116. return nil
  117. end
  118. -- 获取所有玩家
  119. function PRoom:getPlayers()
  120. return self._players or {}
  121. end
  122. -- 获取玩家数量
  123. function PRoom:getPlayerNum()
  124. local count = 0
  125. for _,_ in pairs(self._players) do
  126. count = count + 1
  127. end
  128. return count
  129. end
  130. -- 根据id判断是否是自己
  131. function PRoom:isMyself( uid )
  132. return tonumber(app.user.loginInfo.uid) == tonumber(uid)
  133. end
  134. -- 获取自己信息
  135. function PRoom:getMyself()
  136. return self._players[tostring(app.user.loginInfo.uid)] or self._players[tostring(app.firstRecordUid)]
  137. end
  138. -- 视角转换
  139. function PRoom:transPos( pos )
  140. local myself = self:getMyself()
  141. local MaxCount = self:getRoomInfo().nMaxPlayCount
  142. local showPos = 0
  143. local myPos = myself.seatId
  144. if myPos <= pos then
  145. showPos = pos - myPos
  146. elseif myPos > pos then
  147. showPos = MaxCount - myPos + pos
  148. end
  149. return showPos+1
  150. end
  151. -- 获取房间信息
  152. function PRoom:getRoomInfo()
  153. return self.roomInfo
  154. end
  155. -- 缓存房间信息
  156. function PRoom:setRoomInfo( roominfo )
  157. self.roomInfo = self.roomInfo or {}
  158. for k,v in pairs(roominfo) do
  159. self.roomInfo[k] = v
  160. end
  161. end
  162. -- 获取下一个轮次
  163. function PRoom:getNextTurn(viewPos)
  164. local MaxCount = self:getRoomInfo().nMaxPlayCount
  165. if MaxCount == 5 then
  166. if viewPos == 5 then
  167. return 1
  168. else
  169. return viewPos+1
  170. end
  171. elseif MaxCount == 4 then
  172. if viewPos == 4 then
  173. return 1
  174. else
  175. return viewPos+1
  176. end
  177. elseif MaxCount == 3 then
  178. if viewPos == 3 then
  179. return 1
  180. else
  181. return viewPos+1
  182. end
  183. else
  184. if viewPos == 2 then
  185. return 1
  186. else
  187. return viewPos+1
  188. end
  189. end
  190. --return (viewPos+1)%MaxCount==0 and MaxCount or (viewPos+1)%MaxCount
  191. end
  192. --------------------------------------------------------------------------------------------------------------------------------------------
  193. --------------------------------------------------------------------------------------------------------------------------------------------
  194. --------------------------------------------------------------------------------------------------------------------------------------------
  195. --------------------------------------------------------------------------------------------------------------------------------------------
  196. --------------------------------------------------------------------------------------------------------------------------------------------
  197. --------------------------------------------------------------------------------------------------------------------------------------------
  198. local DdzRoomView = class("DdzRoomView", cc.UIView)
  199. function DdzRoomView:ctor(recordData)
  200. DdzRoomView.super.ctor(self)
  201. self._recordData = recordData
  202. --房间信息
  203. self.roomInfo = {}
  204. -- 玩家节点
  205. self._playerNodes = {}
  206. -- 自己手牌集合
  207. self._selfCards = {}
  208. -- 玩家手牌集合
  209. self._otherCards = {{}, {}, {}, {} ,{}}
  210. -- 玩家出牌集合
  211. self._showCards = {{},{},{},{},{}}
  212. -- 上一次出牌viewPos
  213. self._lastOutPos = 0
  214. -- 上一次出牌类型
  215. self._lastOutType = 0
  216. -- 上一次出牌,用于提示
  217. self._lastCards = {}
  218. -- 排序轮次用
  219. self._turnsQueue = {}
  220. -- 是否开始播放
  221. self._playStart = false
  222. -- 数据备份,以便重复播放
  223. self._backupData = nil
  224. -- 是否已经最后展示
  225. self._gameResult = nil
  226. -- 本轮所有操作次数
  227. self._allOps = 0
  228. -- 当前所剩操作数
  229. self._leftOps = 0
  230. -- 结算数据
  231. self._resultData = nil
  232. -- 房间缓存
  233. self._room = PRoom:new()
  234. self:parseData(self._recordData)
  235. self.ui = loadUI("pk_zgwrddz/res/ui/ui_room/ui_wrddz_recordplayview.ui")
  236. self:addChild(self.ui)
  237. --loadSpriteFrameFile("pk_zgwrddz/res/ui/zy_game/lzroom_add.plist")
  238. self:initUi()
  239. self.roomInfo = self._room:getRoomInfo()
  240. self:setRoomInfo(self.roomInfo)
  241. loadSpriteFrameFile("pk_zgwrddz/res/ui/zy_game/wrddz_cards.plist")
  242. loadSpriteFrameFile("pk_zgwrddz/res/ui/zy_effect/lzpdk_effect.plist")
  243. loadSpriteFrameFile("pk_zgwrddz/res/ui/zy_effect/ddz_effect_bomb.plist")
  244. loadSpriteFrameFile("pk_zgwrddz/res/ui/zy_effect/ddz_effect_plan.plist")
  245. loadSpriteFrameFile("pk_zgwrddz/res/ui/zy_effect/ddz_effect_shunziliandui.plist")
  246. loadSpriteFrameFile("pk_zgwrddz/res/ui/zy_effect/ddz_effect_spring.plist")
  247. loadSpriteFrameFile("pk_zgwrddz/res/ui/zy_effect/ddz_effect_sszd.plist")
  248. loadSpriteFrameFile("pk_zgwrddz/res/ui/zy_effect/ddz_effect_zhangshui.plist")
  249. loadSpriteFrameFile("pk_zgwrddz/res/ui/zy_effect/ddz_effect_kingbomb.plist")
  250. loadSpriteFrameFile("pk_zgwrddz/res/ui/zy_effect/ddz_effect_baojing.plist")
  251. DdzRoomViewConfig.CARD_SCALE[1] = 0.8
  252. --
  253. local rule = self.roomInfo.specialRule
  254. end
  255. --[[
  256. "recordData" = {
  257. "dipai" = ""
  258. "endtime" = 1525689769
  259. "ext" = {
  260. "banker" = "1025568"
  261. "clubId" = 206231
  262. "deductRule" = 0
  263. "gamerule" = 1
  264. "playerNum" = 1
  265. "specialRule" = 65
  266. "tableIdx" = 1
  267. }
  268. "flag" = 0
  269. "gameid" = 9
  270. "idx" = 1
  271. "ops" = "1025568,outCard:{ 0x21 0x31 },handType: dui_zi|1024796,outCard:{ 0x03 0x33 },handType: dui_zi|1024798,outCard:{ 0x05 0x25 },handType: dui_zi|1025568,outCard:{ 0x26 0x36 },handType: dui_zi|1024796,outCard:{ 0x28 0x38 },handType: dui_zi|1025568,outCard:{ 0x1c 0x3c },handType: dui_zi|1025568,outCard:{ 0x15 0x19 0x29 0x09 0x2a },handType: three_and_two|1024796,outCard:{ 0x11 0x14 0x3b 0x1b 0x2b },handType: three_and_two|1024796,outCard:{ 0x02 0x12 0x32 0x35 0x0d },handType: three_and_two|1024796,outCard:{ 0x0a 0x3a },handType: dui_zi"
  272. "pid" = "2568504031125505"
  273. "score" = {
  274. "1024796" = 33
  275. "1024798" = -28
  276. "1025568" = -5
  277. }
  278. "subid" = "2550911843082241"
  279. "turn" = 1
  280. "user" = {
  281. "1024796" = {
  282. "hand" = "0x0d 0x1b 0x2b 0x3b 0x0a 0x3a 0x28 0x38 0x35 0x14 0x03 0x33 0x02 0x12 0x32 0x11"
  283. "seatid" = 1
  284. }
  285. "1024798" = {
  286. "hand" = "0x2c 0x1a 0x39 0x08 0x18 0x07 0x27 0x06 0x16 0x05 0x25 0x34 0x13 0x23 0x22 0x01"
  287. "seatid" = 2
  288. }
  289. "1025568" = {
  290. "hand" = "0x1c 0x3c 0x0b 0x2a 0x09 0x19 0x29 0x17 0x37 0x26 0x36 0x15 0x04 0x24 0x21 0x31"
  291. "seatid" = 0
  292. }
  293. }
  294. }
  295. "playerInfo" = {
  296. "head" = "http://thirdwx.qlogo.cn/mmopen/vi_32/Q0j4TwGTfTK9s9890abV3nHDBgZFOXuO3eAoCs2SsuFFbp0NUzChuCM4wAEUf02IQI7TYW8gelo75fTxKRQdDA/132"
  297. "name" = "名52688"
  298. "sex" = 1
  299. }
  300. ]]
  301. function DdzRoomView:parseData( data )
  302. local roomInfo = {}
  303. roomInfo.nTableId = data.roomid
  304. roomInfo.clubId = data.ext.clubId
  305. roomInfo.banker = data.ext.banker--庄家
  306. roomInfo.gamerule = data.ext.gamerule
  307. roomInfo.playnum = data.ext.playnum or 5
  308. roomInfo.specialRule = data.ext.specialRule
  309. roomInfo.tableIdx = data.ext.tableIdx
  310. roomInfo.allowPass = data.ext.allowPass
  311. roomInfo.nGameStartCount = data.turn
  312. roomInfo.nTotalGameNum = data.nbound----------------------------
  313. roomInfo.deductRule = data.ext.deductRule
  314. roomInfo.endtime = data.endtime
  315. roomInfo.nMaxPlayCount = 0
  316. local tdipai = string.split(data.dipai," ")
  317. for i = #tdipai,1,-1 do
  318. if tdipai[i] == "" then
  319. table.remove(tdipai,i)
  320. end
  321. end
  322. roomInfo.dipai = tdipai
  323. roomInfo.nMaxPlayCount = roomInfo.playnum
  324. for k,v in pairs(data.user) do
  325. local user = {}
  326. user.userId = tonumber(k)
  327. user.seatId = v.seatid
  328. local cstr = string.split(v.hand, " ")
  329. user.handCards = {}
  330. for _,v in ipairs(cstr) do
  331. if string.len(v) > 0 then
  332. table.insert(user.handCards, tonumber(v))
  333. end
  334. end
  335. user.leftCards = clone(user.handCards)
  336. user.leftNum = #user.handCards
  337. local oinfo = app.playerInfoManager:getPlayerInfo(tonumber(k))
  338. if oinfo then
  339. user.headimgurl = oinfo.head
  340. user.sex = oinfo.sex
  341. user.nickname = oinfo.name
  342. end
  343. self._room:addPlayer(user)
  344. end
  345. roomInfo.nMaxPlayCount = table.nums(data.user)
  346. self._room:setRoomInfo(roomInfo)
  347. local firstId = false
  348. app.firstRecordUid = 0
  349. for k,v in pairs(data.user) do
  350. local user = {}
  351. user.userId = tonumber(k)
  352. if not firstId then
  353. app.firstRecordUid = user.userId--找到一个uid代替自己的uid,防止没有参加游戏的人看回放了报错
  354. firstId = true
  355. end
  356. user.viewPos = self._room:transPos(v.seatid)
  357. user.score = data.score[k]
  358. self._room:addPlayer(user)
  359. end
  360. if string.len(data.ops) <=0 then --没开始,提前解散
  361. -- result data
  362. local result = {}
  363. local players = self._room:getPlayers()
  364. local pt = {}
  365. for k,v in pairs(players) do
  366. local d = {}
  367. d.userId = tonumber(k)
  368. d.leftCards = clone(v.leftCards)
  369. d.totalScore = v.score
  370. d.sex = v.sex
  371. d.headimgurl = v.headimgurl
  372. d.nickname = v.nickname
  373. table.insert(pt, d)
  374. end
  375. result.players = pt
  376. self._resultData = {response=result}
  377. return
  378. end
  379. --op data
  380. local opStrST = string.split(data.ops, "|")--1025568,outCard:{ 0x21 0x31 },handType: dui_zi
  381. for _,opstr in ipairs(opStrST) do
  382. local opT = string.split(opstr, ",")
  383. local uid = opT[1]
  384. local opstr1,opType,opstr1Value
  385. local cardstr = string.gsub(opT[2], "outCard:{ ", "")
  386. if opT[2] and not string.find(opT[2],"outCard") then
  387. local topstr = string.split(opT[2], ":")
  388. opstr1 = topstr[1]
  389. opType = 1
  390. opstr1Value = tonumber(topstr[2]) or 0
  391. end
  392. cardstr = string.gsub(cardstr, " }", "")
  393. local cardstrT = string.split(cardstr, " ")
  394. local cards = {}
  395. for _,cid in ipairs(cardstrT) do
  396. table.insert(cards, tonumber(cid))
  397. end
  398. if opT[3] then
  399. opstr1 = string.gsub(opT[3], "handType:", "")
  400. opType = tonumber(opstr1) or 0
  401. end
  402. --
  403. local user = self._room:getPlayer(uid)
  404. if user then
  405. local pdata = {}
  406. pdata.userId = tonumber(uid)
  407. pdata.viewPos = user.viewPos
  408. pdata.seatId = user.seatId
  409. pdata.cards = cards
  410. pdata.opType = opType
  411. pdata.opstr1 = opstr1
  412. pdata.opstr1Value = opstr1Value
  413. pdata.leftNum = user.leftNum-#cards
  414. local tmpLeft = getDelAdB(user.leftCards, cards)
  415. user.leftCards = clone(tmpLeft)
  416. user.leftNum = #tmpLeft
  417. self._room:addPlayer(user)
  418. local preData = self:getTurnLast()
  419. if preData then
  420. --local preViewPos = preData.viewPos
  421. --local nextTurn = self._room:getNextTurn(preViewPos)
  422. --if nextTurn==pdata.viewPos then
  423. self:addTurnData(pdata)
  424. --[[else--添加要不起
  425. while nextTurn~=pdata.viewPos do
  426. preData = self:getTurnLast()
  427. if preData then
  428. preViewPos = preData.viewPos
  429. nextTurn = self._room:getNextTurn(preViewPos)
  430. local player = self._room:getPlayerVpos(nextTurn)
  431. local passData = {}
  432. passData.userId = tonumber(player.userId)
  433. passData.viewPos = nextTurn
  434. passData.seatId = player.seatId
  435. passData.cards = {}
  436. passData.opType = 0
  437. passData.opstr1 = ""
  438. passData.leftNum = player.leftNum
  439. self:addTurnData(passData)
  440. nextTurn = self._room:getNextTurn(nextTurn)
  441. else
  442. break
  443. end
  444. end
  445. self:addTurnData(pdata)--]]
  446. --end
  447. else
  448. self:addTurnData(pdata)
  449. end
  450. else
  451. local pdata = {}
  452. pdata.opType = opType
  453. pdata.opstr1 = opstr1
  454. pdata.opstr1Value = opstr1Value
  455. self:addTurnData(pdata)
  456. end
  457. end
  458. -- result data
  459. local result = {}
  460. local players = self._room:getPlayers()
  461. local pt = {}
  462. for k,v in pairs(players) do
  463. local d = {}
  464. d.userId = tonumber(k)
  465. d.leftCards = clone(v.leftCards)
  466. d.totalScore = v.score
  467. d.sex = v.sex
  468. d.headimgurl = v.headimgurl
  469. d.nickname = v.nickname
  470. table.insert(pt, d)
  471. end
  472. result.players = pt
  473. self._resultData = {response=result}
  474. -- 数据备份
  475. self._backupData = clone(self._turnsQueue)
  476. -- 总步骤
  477. self._allOps = #self._turnsQueue
  478. end
  479. function DdzRoomView:resetRoundData()
  480. -- 上一次出牌viewPos
  481. self._lastOutPos = 0
  482. -- 上一次出牌类型
  483. self._lastOutType = 0
  484. self._lastCards = {}
  485. self.lastOutFlag = -1
  486. self:cleanSelfCards()
  487. self:cleanShowCards()
  488. self:stopTurn()
  489. self:showOtherCards(false)
  490. -- 清空玩家时钟
  491. for _,v in pairs(self._playerNodes) do
  492. v:setTurn(false)
  493. end
  494. end
  495. function DdzRoomView:getMode()
  496. return self._room:getRoomInfo().nMaxPlayCount or 5
  497. end
  498. function DdzRoomView:initUi()
  499. self.cardRoot = {}
  500. --1-5存放手牌 --10存放出的牌等
  501. self.cardRoot[1] = self.ui.Items.cardRoot_1
  502. self.cardRoot[2] = self.ui.Items.cardRoot_2
  503. self.cardRoot[3] = self.ui.Items.cardRoot_3
  504. self.cardRoot[4] = self.ui.Items.cardRoot_4
  505. self.cardRoot[5] = self.ui.Items.cardRoot_5
  506. self.cardRoot[10] = self.ui.Items.cardRoot_0
  507. --self.cardRoot = self.ui.Items.cardRoot
  508. self.imgOtherCards = self.ui.Items.ImageView_other
  509. self.txtOtherCards = self.ui.Items.Text_otherNum
  510. self:showOtherCards(false)
  511. self.ui.Items.toolPanel:setLocalZOrder(101)
  512. self.ui.Items.btnReturn:registerClick(handler(self , self.onClickButtonReturn))
  513. self.ui.Items.btnPlay:registerClick(handler(self , self.onClickButtonPlay))
  514. self.ui.Items.ButtonToward:registerClick(handler(self , self.onClickButtonToward))
  515. self.ui.Items.btnDetail:registerClick(handler(self , self.onClickButtonDetails))
  516. self.ui.Items.btnDetail:setVisible(false)
  517. self.ui.Items.Button_rule:registerClick(handler(self, self.onClickButtonDetails))
  518. self.ui.Items.Layout_Rule:setVisible(false)
  519. self.ui.Items.Layout_7:setVisible(false)
  520. self.ui.Items.Text_Rule:setVisible(false)
  521. self.ui.Items.Layout_7:registerClick(handler(self , self.onClickMenuOut))
  522. local bar = self.ui.Items.ListView:getVBar()
  523. bar:setVisible(false)
  524. self.ui.Items.imgTip:setVisible(false)
  525. self.ui.Items.imgTip:setOpacity(0)
  526. self.ui.Items.imgTip:setLocalZOrder(200)
  527. --添加玩家节点
  528. local players = self._room:getPlayers()
  529. for _, info in pairs(players) do
  530. self:addPlayerNode( info )
  531. end
  532. self:showZiChi(false)
  533. end
  534. function DdzRoomView:onClickMenuOut( sender )
  535. self.ui.Items.Layout_Rule:setVisible(false)
  536. self.ui.Items.Layout_7:setVisible(false)
  537. self.ui.Items.Button_rule:setVisible(true)
  538. self.ui.Items.Layout_Rule:stopAllActions()
  539. end
  540. function DdzRoomView:updateProgress()
  541. local over = 0
  542. local overOps = self._allOps - self._leftOps
  543. -- local percent = math.floor((overOps/self._allOps)*100)
  544. self.ui.Items.Text_jindu:setString(string.format("进度:%d/%d", overOps, self._allOps))
  545. if overOps==self._allOps then
  546. showTooltip("回放结束")
  547. end
  548. end
  549. function DdzRoomView:onClickButtonPlay( sender, flag )
  550. if flag ~= 1 then
  551. playBtnEffect()
  552. end
  553. if sender.play == nil then
  554. sender.play = false
  555. end
  556. if sender.play then
  557. sender.play = false
  558. sender:loadTextureNormal("record_play.png", 1)
  559. self:stopTurn(false)
  560. else
  561. sender.play = true
  562. sender:loadTextureNormal("record_pause.png", 1)
  563. if self._gameResult == true then
  564. self:resetRoundData()
  565. self._turnsQueue = clone(self._backupData)
  566. end
  567. if self._playStart==true then
  568. self:stopTurn(false)
  569. self:startTurns()
  570. else
  571. local myself = self._room:getMyself()
  572. if myself then
  573. local data = {}
  574. data.response = {}
  575. data.response.cards = myself.handCards
  576. local playerCards = {}
  577. local players = self._room:getPlayers()
  578. for _,v in pairs(players) do
  579. playerCards[v.viewPos] = clone(v.handCards)
  580. end
  581. data.response.playerCards = playerCards
  582. --local banker = self._room:getPlayer(self._room:getRoomInfo().banker)
  583. --data.response.bankerSeat = banker.seatId
  584. self:onResponseSendCards(data)
  585. self.ui:runDelay(4.5, function() self:startTurns() end )
  586. end
  587. end
  588. end
  589. end
  590. function DdzRoomView:onClickButtonToward( sender )
  591. playBtnEffect()
  592. if self.ui.Items.btnPlay.play == nil then
  593. return
  594. end
  595. self.ui.Items.btnPlay.play = true
  596. self:onClickButtonPlay( self.ui.Items.btnPlay )
  597. local data = self:getTurnData()
  598. if data then
  599. self:updateTurns(data)
  600. else
  601. self:onResponseGameResult(self._resultData)
  602. end
  603. self._leftOps = #self._turnsQueue
  604. -- show
  605. self:updateProgress()
  606. self:stopTurn(false)
  607. end
  608. -- 玩家点击房间详情
  609. function DdzRoomView:onClickButtonDetails( sender )
  610. playBtnEffect()
  611. --[[local node = self.ui.Items.btnDetail:getChildByTag(101)
  612. if node then
  613. else
  614. local rule = self:getRuleString()
  615. local view = import("pk_zgwrddz.luaScript.Views.Room.Sub.luzhouPdkGameDetailView"):new(rule)
  616. view:setPosition(cc.p(view:getSizeWidth()+60, 60))
  617. view:setTag(101)
  618. self.ui.Items.btnDetail:addChild(view)
  619. end--]]
  620. self.ui.Items.Layout_Rule:setVisible(not self.ui.Items.Layout_Rule:isVisible())
  621. self.ui.Items.Layout_7:setVisible(self.ui.Items.Layout_Rule:isVisible())
  622. self.ui.Items.Button_rule:setVisible(not self.ui.Items.Layout_Rule:isVisible())
  623. end
  624. function DdzRoomView:onClickButtonReturn( sender )
  625. playBtnEffect()
  626. self:removeFromParent()
  627. end
  628. --[[获取房间详情字符串--]]
  629. function DdzRoomView:getRuleString()
  630. local rule = self.roomInfo.specialRule
  631. local ruleStr = ""
  632. ruleStr = ruleStr..DdzRoomViewConfig.RoonInfoConfig.play[tonumber(self.roomInfo.gamerule)]..","
  633. ruleStr = ruleStr..DdzRoomViewConfig.RoonInfoConfig.num[tonumber(self.roomInfo.playnum)]..","
  634. if getNumBand(rule, 0x0001)>0 then
  635. ruleStr = ruleStr..DdzRoomViewConfig.CreateParamsMean[0x0001]..","
  636. end
  637. if getNumBand(rule, 0x0002)>0 then
  638. ruleStr = ruleStr..DdzRoomViewConfig.CreateParamsMean[0x0002]..","
  639. end
  640. if string.len(ruleStr) > 0 then
  641. ruleStr = string.sub(ruleStr, 1, string.len(ruleStr)-1)
  642. end
  643. return ruleStr
  644. end
  645. -- 设置房间信息
  646. function DdzRoomView:setRoomInfo( info )
  647. self.ui.Items.roomNum:setString(string.format("房号:%06d", info.nTableId))
  648. self.ui.Items.ListView:removeAllChildren()
  649. self.ui.Items.ListView:setAutoSize(true)
  650. local multLimit={
  651. [30] = "封顶30倍",
  652. [60] = "封顶60倍",
  653. }
  654. local playRule={
  655. [1] = "加底1",
  656. [2] = "加底2",
  657. [4] = "加倍",
  658. }
  659. if self._recordData.ext.multLimit then
  660. local text = self.ui.Items.Text_Rule:getCopied()
  661. text:setVisible(true)
  662. text:setString(multLimit[self._recordData.ext.multLimit])
  663. self.ui.Items.ListView:addChild(text)
  664. end
  665. local playrl = self._recordData.ext.playRule
  666. if playrl and playrl > 0 then
  667. if getNumBand(playrl, 1) > 0 then
  668. local text = self.ui.Items.Text_Rule:getCopied()
  669. text:setVisible(true)
  670. text:setString(playRule[1])
  671. self.ui.Items.ListView:addChild(text)
  672. elseif getNumBand(playrl, 2) > 0 then
  673. local text = self.ui.Items.Text_Rule:getCopied()
  674. text:setVisible(true)
  675. text:setString(playRule[2])
  676. self.ui.Items.ListView:addChild(text)
  677. end
  678. if getNumBand(playrl, 4) > 0 then
  679. local text = self.ui.Items.Text_Rule:getCopied()
  680. text:setVisible(true)
  681. text:setString(playRule[4])
  682. self.ui.Items.ListView:addChild(text)
  683. end
  684. end
  685. if self._recordData.ext.baseMulti then
  686. local text = self.ui.Items.Text_Rule:getCopied()
  687. text:setVisible(true)
  688. text:setString("积分倍数×" .. self._recordData.ext.baseMulti)
  689. self.ui.Items.ListView:addChild(text)
  690. end
  691. --[[local rules = WRDDZDefine.getWanFaInfoTab(self._recordData.ext)
  692. for k,v in pairs(rules) do
  693. local text = self.ui.Items.Text_Rule:getCopied()
  694. text:setVisible(true)
  695. text:setString(v)
  696. self.ui.Items.ListView:addChild(text)
  697. end--]]
  698. end
  699. -- 显示轮次
  700. function DdzRoomView:showTurnBtn( is )
  701. if is then --回放出牌
  702. end
  703. end
  704. -- 一键截屏
  705. function DdzRoomView:onClickButtonShot( sender )
  706. playBtnEffect()
  707. showScreenShot()
  708. end
  709. -- 设置点击
  710. function DdzRoomView:onClickButtonSetting( sender )
  711. playBtnEffect()
  712. self:showMenu(false)
  713. local view = import("pk_zgwrddz.luaScript.Views.Room.Sub.luzhouPdkSettingView"):new()
  714. view:setAnchorPoint(cc.p(0.5, 0.5))
  715. app:showWaitDialog(view)
  716. end
  717. -- 上传日志点击
  718. function DdzRoomView:onClickButtonUlog( sender )
  719. playBtnEffect()
  720. self:showMenu(false)
  721. local view = import("luaScript.Views.Room.UplogView"):new()
  722. view:setAnchorPoint(cc.p(0.5, 0.5))
  723. app:showWaitDialog(view)
  724. end
  725. -- 变暗不能出的牌
  726. function DdzRoomView:downCanotOuts(canotOuts, isTouch)
  727. for _,v in pairs(canotOuts) do
  728. local node = self:getCardNode(v)
  729. if node then node:setNoTouch(isTouch) end
  730. end
  731. end
  732. function DdzRoomView:bindEvents()
  733. -- 游戏设置里更换桌面
  734. -- self:bindEvent(app.room , "pdkNormalEvent_changeDesktop" , handler(self , self.onNormalChangeDesktop))
  735. end
  736. -- 更换桌面
  737. function DdzRoomView:onNormalChangeDesktop( data )
  738. --if data.idx >5 and data.idx<1 then return end
  739. local changeDesk = tonumber(loadUserInfo("wrddz_setting_bg_idx")) or 3
  740. self.ui.Items.ImageView_bg:loadTexture(string.format("pk_zgwrddz/res/ui/zy_game/wrddr_gamebg_%d.jpg", changeDesk), 0)
  741. --self.ui.Items.ImageView_logo:loadTexture(string.format("pk_zgwrddz/res/ui/zy_game/wwddz_img_logo_%d.png", changeDesk), 0)
  742. end
  743. -- 通知玩家分数
  744. function DdzRoomView:onResponseUpdateScore( data )
  745. local msg = data.response
  746. for _,pdata in ipairs(msg.players) do
  747. local node = self:getPlayerNode(pdata.userId)
  748. if node then node:setScore(pdata.totalScore) end
  749. end
  750. end
  751. -- 给玩家发牌
  752. function DdzRoomView:onResponseSendCards( data )
  753. self._leftOps = self._allOps
  754. self:updateProgress()
  755. self:cleanOtherHands()
  756. self._gameResult = false
  757. self._passGameResult = nil
  758. self._playStart = true
  759. self.ui.Items.ButtonToward:setEnabled(false)
  760. self.ui.Items.btnPlay:setEnabled(false)
  761. for viewPos,v in pairs(data.response.playerCards) do
  762. self:sendCards(v, viewPos)
  763. end
  764. local bankerData = self._room:getPlayerCid(data.response.bankerSeat)
  765. for _,v in pairs( self._playerNodes ) do
  766. --v:setBanker(v:getInfo().userId==bankerData.userId)
  767. v:setBanker(false)
  768. v:setTurn(false)
  769. v:setScore(0)
  770. end
  771. if bankerData and bankerData.userId then
  772. if self._room:isMyself(bankerData.userId) then
  773. self:runAction(cc.Sequence:create(cc.DelayTime:create(1), cc.CallFunc:create(function ()
  774. self:showTurnBtn(true)
  775. local node = self:getPlayerNodeVpos(1)
  776. if node then node:setTurn(true) end
  777. end)))
  778. else
  779. self:showTurnBtn(false)
  780. self:runAction(cc.Sequence:create(cc.DelayTime:create(1), cc.CallFunc:create(function ()
  781. local node = self:getPlayerNode(bankerData.userId)
  782. if node then node:setTurn(true) end
  783. end)))
  784. end
  785. end
  786. -- 发完牌后显示牌张数
  787. self:runDelay(3, function ()
  788. local left = 25
  789. --if self.ruleType==2 then left = 15 end
  790. for uid,v in pairs(self._playerNodes) do
  791. local viewPos =v:getInfo().viewPos
  792. if viewPos and self._otherCards[viewPos] then
  793. v:showLeft(#self._otherCards[viewPos])
  794. end
  795. self.ui.Items.ButtonToward:setEnabled(true)
  796. self.ui.Items.btnPlay:setEnabled(true)
  797. end
  798. end)
  799. end
  800. -- 将回放数据按照先后顺序处理成串行以便调度器调用
  801. function DdzRoomView:addTurnData( data )
  802. table.insert(self._turnsQueue, data)
  803. end
  804. function DdzRoomView:getTurnData( isRemove )
  805. local data = nil
  806. if #self._turnsQueue > 0 then
  807. data = clone(self._turnsQueue[1])
  808. if isRemove==nil then
  809. table.remove(self._turnsQueue, 1)
  810. end
  811. end
  812. return data
  813. end
  814. function DdzRoomView:getTurnLast()
  815. local data = nil
  816. if #self._turnsQueue > 0 then
  817. data = clone(self._turnsQueue[#self._turnsQueue])
  818. end
  819. return data
  820. end
  821. function DdzRoomView:startTurns()
  822. local data = self:getTurnData()
  823. if data then
  824. self:updateTurns(data)
  825. else
  826. return
  827. end
  828. if not self._turnTimer then
  829. self._turnTimer = cc.Director:getInstance():getScheduler():scheduleScriptFunc(function()
  830. ----------------------
  831. local data = self:getTurnData()
  832. if data then
  833. self:updateTurns(data)
  834. else
  835. self:stopTurn()
  836. self:onResponseGameResult(self._resultData)
  837. end
  838. end,2,false)
  839. end
  840. end
  841. function DdzRoomView:stopTurn(isClean)
  842. isClean = isClean or true
  843. if self._turnTimer then
  844. cc.Director:getInstance():getScheduler():unscheduleScriptEntry(self._turnTimer)
  845. self._turnTimer = nil
  846. if isClean then self._cmdQueue = {} end
  847. end
  848. end
  849. --[[
  850. ,defVar("selfId", VT_Int, 0)--自己ID
  851. ,defVar("userId", VT_Int, 0)
  852. ,defVar("cardType", VT_Short, 0)
  853. ,defVar("leftNum", VT_Short, 0)--出牌者剩余多少张牌
  854. ,defVar("cards", VT_Vector(VT_UChar), {})
  855. passData.userId = tonumber(player.userId)
  856. passData.viewPos = nextTurn
  857. passData.seatId = player.seatId
  858. passData.cards = {}
  859. passData.opType = 0
  860. ]]
  861. -- 处理是否是出牌,如果出牌,则显示对应玩家出牌,如果是pass,显示对应玩家pass
  862. function DdzRoomView:updateTurns( data )
  863. local msg = data
  864. self._leftOps = #self._turnsQueue
  865. self:updateProgress()
  866. self.lastOutFlag = msg.opType--操作类型
  867. local viewPos = data.viewPos
  868. local node = self:getPlayerNode(data.userId)
  869. self:showTurns(viewPos)
  870. if node then
  871. local function show()
  872. if msg.opstr1 and msg.opstr1 == "askLord" then--显示叫地主
  873. self.opAskLord = self.opAskLord or 0
  874. self.opAskLord = self.opAskLord + 1
  875. if self.opAskLord == 6 then
  876. self:clearJdzJbInfo()
  877. self.opAskLord = 1
  878. end
  879. node:showJiaoDiZhu(msg.opstr1Value == 1)
  880. node:setHost(msg.opstr1Value == 1)
  881. if msg.opstr1Value == 1 then
  882. local dipai = self._room:getRoomInfo().dipai
  883. self:showDiPai(self._room:getRoomInfo().dipai)
  884. end
  885. self.isNeedClearJDZJB = true
  886. return
  887. elseif msg.opstr1 and msg.opstr1 == "askDouble" then--显示加倍
  888. self:clearJdzJbInfo()
  889. node:showJiaBei(msg.opstr1Value == 1)
  890. if node:isHost() then
  891. node:setFanMult(msg.opstr1Value == 1)
  892. else
  893. node:setMult(msg.opstr1Value == 1)
  894. end
  895. self.isNeedClearJDZJB = true
  896. return
  897. elseif msg.opstr1 and msg.opstr1 == "selectDark" then--显示暗地主和暗地主牌
  898. self:clearJdzJbInfo()
  899. node:setAnDiZhu(msg.opstr1Value ~= 0x0e) -- 自吃时,不显示暗地主标识
  900. self:showAnDiZhuCard(msg.opstr1Value)
  901. self.isNeedClearJDZJB = true
  902. return
  903. end
  904. if self.isNeedClearJDZJB and self.isNeedClearJDZJB == true then
  905. self.isNeedClearJDZJB = nil
  906. self:clearJdzJbInfo()
  907. end
  908. if viewPos == 1 then--自己能出牌
  909. if self._lastOutPos == 1 then
  910. self:cleanLastCards()
  911. self.lastOutFlag = -1
  912. end
  913. self:clearPosShow(1)
  914. self:showTurnBtn(true)
  915. else--别人能出牌,对应位置出牌
  916. self:showTurnBtn(false)
  917. end
  918. local outData = {}
  919. outData.selfId = self._room:getMyself().userId
  920. outData.userId = msg.userId
  921. outData.cardType = msg.opType
  922. outData.leftNum = msg.leftNum
  923. outData.cards = clone(msg.cards)
  924. self:onResponseOutCards({response=outData})
  925. end
  926. local function passShow()
  927. if viewPos == 1 then
  928. self:showEffect(viewPos, ETS.PASS)
  929. self:showPass()
  930. self:cleanLastCards(false)
  931. else
  932. self:showEffect(viewPos, ETS.PASS)
  933. end
  934. end
  935. if msg.opType == 0 then
  936. node:runAction(cc.Sequence:create(cc.DelayTime:create(0.1), cc.CallFunc:create(passShow)))
  937. else
  938. show()
  939. end
  940. else
  941. if msg.opstr1 and msg.opstr1 == "totalMult" then--显示叫地主
  942. self:onUpdateGameMult(msg.opstr1Value)
  943. end
  944. end
  945. end
  946. --显示加倍
  947. function DdzRoomView:onUpdateGameMult(mult)
  948. self.ui.Items.TextBMFont_beishu:setText(mult)
  949. end
  950. -- 显示轮次时钟
  951. function DdzRoomView:showTurns( viewPos )
  952. for _,node in pairs(self._playerNodes) do
  953. local is = node:getInfo().viewPos==viewPos
  954. node:setTurn(is)
  955. if is then self:clearPosShow(viewPos) end
  956. end
  957. end
  958. -- 清除叫地主加倍信息
  959. function DdzRoomView:clearJdzJbInfo()
  960. for _,node in pairs(self._playerNodes) do
  961. if node then
  962. node:cleanPass()
  963. end
  964. end
  965. end
  966. -- 广播当前桌子轮次@userId@seatId@outFlag
  967. function DdzRoomView:onResponseUpdateTurns( data )
  968. self:addTurn(data)
  969. end
  970. -- 清理上一次的出牌
  971. function DdzRoomView:cleanLastCards(isClean)
  972. if isClean==nil then isClean = true end
  973. if self._lastOutPos > 0 then
  974. if isClean == true then
  975. self:clearPosShow(self._lastOutPos)
  976. end
  977. self._lastCards = {}
  978. self._lastOutType = 0
  979. self._lastOutPos = 0
  980. end
  981. end
  982. -- 玩家出牌成功
  983. function DdzRoomView:onResponseOutCards( data )
  984. local msg = data.response
  985. local isContinue = #self._lastCards>0 and self._lastOutType>0
  986. -- 清理上一次的出牌
  987. self:cleanLastCards()
  988. if msg.isMustBomb and msg.isMustBomb == 1 then
  989. msg.cardType = ETS.NONE
  990. end
  991. local viewPos = self._room:getPlayer(msg.userId).viewPos
  992. -- 缓存上次出的牌
  993. self._lastOutPos = viewPos
  994. self._lastOutType = msg.cardType
  995. self._lastCards = msg.cards
  996. self:showTurns(0)
  997. if #msg.cards <= 0 then
  998. msg.cardType = 0
  999. end
  1000. self:showCards(msg.cards, viewPos, msg.cardType, isContinue)
  1001. --玩家剩余牌
  1002. local node = self:getPlayerNode(msg.userId)
  1003. if node and msg.cards and #msg.cards > 0 then
  1004. --[[if not node:isAlarm() and msg.leftNum==1 then
  1005. if self:getMode()==0 then
  1006. if node:getInfo().viewPos==2 then DdzSoundHelper:single( node:getInfo().sex ) end
  1007. elseif self:getMode()==1 then
  1008. if node:getInfo().viewPos==3 then DdzSoundHelper:single( node:getInfo().sex ) end
  1009. end
  1010. end--]]
  1011. if msg.leftNum==1 then
  1012. DdzSoundHelper:single( node:getInfo().sex )
  1013. elseif msg.leftNum==2 then
  1014. DdzSoundHelper:single2( node:getInfo().sex )
  1015. end
  1016. node:showLeft(msg.leftNum)
  1017. end
  1018. if viewPos == 1 then--判断是否自己出牌
  1019. self:showTurnBtn(false)
  1020. for _,v in pairs(msg.cards) do
  1021. --self:removeCardNode(v)
  1022. if v >= 0x50 and v <= 0x5d then
  1023. v = 0x5d
  1024. end
  1025. for i=#self._selfCards,1,-1 do
  1026. if self._selfCards[i]:getVal()==v then
  1027. table.remove(self._selfCards, i)
  1028. break
  1029. end
  1030. end
  1031. end
  1032. local tccards = self:getCardsByUi(self._selfCards)
  1033. self:recoverHandcardsByPos(tccards,1)
  1034. --[[if msg.leftNum==1 then
  1035. DdzSoundHelper:single( node:getInfo().sex )
  1036. elseif msg.leftNum==2 then
  1037. DdzSoundHelper:single2( node:getInfo().sex )
  1038. end--]]
  1039. --还原不可点
  1040. self:downCanotOuts(self:getHandCards(), false)
  1041. --self:resetCardsPos()
  1042. else
  1043. self:removeOtherCards(viewPos, msg.cards)
  1044. end
  1045. end
  1046. -- 将ui数据转换为纯数据
  1047. function DdzRoomView:getCardsByUi(cards)
  1048. local tCards = {}
  1049. for _,v in pairs(cards) do
  1050. table.insert(tCards, v:getVal())
  1051. end
  1052. return tCards
  1053. end
  1054. -- 恢复自己手牌
  1055. function DdzRoomView:recoverHandcardsByPos(_cards,pos)
  1056. if pos == 1 then
  1057. self.cardRoot[1]:removeAllChildren()
  1058. self._selfCards = {}
  1059. else
  1060. self.cardRoot[pos]:removeAllChildren()
  1061. self._otherCards[pos] = {}
  1062. end
  1063. local cards = pokerSortPdkCards(_cards)
  1064. local allCount = #cards
  1065. for i,card in ipairs(cards) do
  1066. self:sendOneCardNoAct(card.cid, i, pos, i==allCount, allCount)
  1067. end
  1068. end
  1069. -- 玩家自己显示要不起
  1070. function DdzRoomView:showPass()
  1071. do return end
  1072. --self.ui.Items.imgTip:setOpacity(0)
  1073. --self.ui.Items.imgTip:setVisible(true)
  1074. --local ac = cc.Sequence:create(cc.FadeIn:create(0.2), cc.DelayTime:create(1), cc.FadeOut:create(0.2))
  1075. --self.ui.Items.imgTip:runAction(ac)
  1076. --手牌变暗
  1077. local anFunc = function ()
  1078. for k,v in pairs(self._selfCards) do
  1079. v:setNoTouch(true)
  1080. end
  1081. end
  1082. local mingFunc = function ()
  1083. for k,v in pairs(self._selfCards) do
  1084. v:setNoTouch(false)
  1085. end
  1086. end
  1087. local ac = cc.Sequence:create(cc.CallFunc:create(anFunc), cc.DelayTime:create(0.1), cc.CallFunc:create(mingFunc))
  1088. self.cardRoot[1]:runAction(ac)
  1089. end
  1090. -- cards@单张或者对子需要
  1091. function DdzRoomView:showEffect( viewPos, effectType, dltWidth, cards, isContinue )
  1092. if dltWidth == nil then
  1093. dltWidth = 50
  1094. end
  1095. local rate = math.random(100)
  1096. local stdRate = 70
  1097. isContinue = isContinue or false
  1098. local pNode = self:getPlayerNodeVpos(viewPos)
  1099. if pNode==nil then return end
  1100. local pInfo = pNode:getInfo()
  1101. local sex = pInfo.sex
  1102. local node = nil
  1103. if effectType == ETS.PASS then
  1104. local cb = function ()
  1105. local node = self:getPlayerNodeVpos(viewPos)
  1106. if node then node:setTurn(false) end
  1107. end
  1108. node = DdzEffectHelper:getPass(cb)
  1109. local idx = math.random(4)
  1110. DdzSoundHelper:effectPass( sex, idx )
  1111. elseif effectType == ETS.SINGLE_CARD then
  1112. local _, val = pokerParse(cards[1])
  1113. DdzSoundHelper:effectSingle( sex ,val )
  1114. elseif effectType == ETS.DUI_ZI then
  1115. local _, val = pokerParse(cards[1])
  1116. if isContinue and rate >= stdRate and DdzSoundHelper:getLanguageType() == 1 then
  1117. DdzSoundHelper:daNi( sex )
  1118. else
  1119. DdzSoundHelper:effectDouble( sex, val )
  1120. end
  1121. elseif effectType == ETS.SHUN_ZI then
  1122. node = DdzEffectHelper:getShunzi()
  1123. if viewPos==1 and node then
  1124. node:setScale(1.2)
  1125. end
  1126. if isContinue and rate>=stdRate and DdzSoundHelper:getLanguageType() == 1 then
  1127. DdzSoundHelper:daNi( sex )
  1128. else
  1129. DdzSoundHelper:effectShunzi( sex )
  1130. end
  1131. elseif effectType == ETS.LIAN_DUI then
  1132. node = DdzEffectHelper:getLiandui()
  1133. if isContinue and rate>=stdRate and DdzSoundHelper:getLanguageType() == 1 then
  1134. DdzSoundHelper:daNi( sex )
  1135. else
  1136. DdzSoundHelper:effectLiandui( sex )
  1137. end
  1138. elseif effectType == ETS.THREE_AND_ONE then
  1139. node = DdzEffectHelper:getSandaiyi()
  1140. DdzSoundHelper:effect3And1( sex )
  1141. elseif effectType == ETS.THREE_AND_TWO or effectType == ETS.THREE_AND_DUI then
  1142. node = DdzEffectHelper:getSandaier()
  1143. if isContinue and rate>=stdRate and DdzSoundHelper:getLanguageType() == 1 then
  1144. DdzSoundHelper:daNi( sex )
  1145. else
  1146. DdzSoundHelper:effect3And2( sex,effectType )
  1147. end
  1148. elseif effectType == ETS.THREE then
  1149. local _, val = pokerParse(cards[1])
  1150. DdzSoundHelper:effectThree( sex, val )
  1151. elseif DdzRoomViewConfig.isBomb(effectType) then
  1152. node = DdzEffectHelper:getBomb()
  1153. if effectType >= ETS.TWO_SMALL_KING and effectType <= ETS.TWO_BIG_KING or effectType >= ETS.FOUR_SMALL_KING and effectType <= ETS.FOUR_BIG_KING then
  1154. node = DdzEffectHelper:getKingBomb()
  1155. isKingBomb = true
  1156. DdzSoundHelper:effectKingBomb( sex )
  1157. elseif effectType >= ETS.SIX_SMALL_KING and effectType <= ETS.SIX_BIG_KING then
  1158. node = DdzEffectHelper:getShenShuiBomb()
  1159. DdzSoundHelper:effectShenShuiZha( sex )
  1160. else
  1161. DdzSoundHelper:effectBomb( sex )
  1162. end
  1163. elseif effectType == ETS.SAN_SHUN or effectType == ETS.AIRPLANE_SINGLE or effectType == ETS.AIRPLANE_DUI then
  1164. node = DdzEffectHelper:getPlan()
  1165. if effectType == ETS.SAN_SHUN then
  1166. DdzSoundHelper:effectSanShun( sex )
  1167. else
  1168. DdzSoundHelper:effectPlane( sex )
  1169. end
  1170. end
  1171. if node then
  1172. local pt = clone(DdzRoomViewConfig.RECORD_SHOW_CARD_POS5[self:getMode()][viewPos])
  1173. if effectType~=ETS.PASS then
  1174. if effectType==ETS.SHUN_ZI then
  1175. if viewPos == 2 or viewPos == 3 then
  1176. pt.x = pt.x - dltWidth*2
  1177. elseif viewPos == 4 or viewPos == 5 then
  1178. pt.x = pt.x
  1179. else
  1180. pt.x = pt.x-50
  1181. pt.y = 320*g_radio_y
  1182. end
  1183. else
  1184. if viewPos == 2 or viewPos == 3 then
  1185. pt.x = pt.x - dltWidth
  1186. elseif viewPos == 4 or viewPos == 5 then
  1187. pt.x = pt.x + dltWidth
  1188. end
  1189. end
  1190. pt.y = pt.y - (DdzRoomViewConfig.CARD_HEIGHT/5*1)*DdzRoomViewConfig.CARD_SCALE[2]
  1191. if effectType==ETS.BOMB then
  1192. pt.y = (pt.y+120)*g_radio_y
  1193. end
  1194. if viewPos == 1 then
  1195. pt.x = CENTER_X
  1196. pt.y = 220*g_radio_y
  1197. end
  1198. else
  1199. pt.y = pt.y + 40
  1200. if effectType==ETS.PASS then
  1201. if viewPos == 1 then
  1202. pt.y = 220*g_radio_y--自己pass位置调整
  1203. pt.x = CENTER_X
  1204. else
  1205. pt.y = (pt.y - 50)*g_radio_y
  1206. end
  1207. end
  1208. end
  1209. node:setPosition(pt)
  1210. self:addChild(node)
  1211. if node.onEnter and type(node.onEnter)=='function' then
  1212. node:onEnter()
  1213. end
  1214. end
  1215. end
  1216. function DdzRoomView:cleanOtherHands()
  1217. for _,hands in ipairs(self._otherCards) do
  1218. for _,node in ipairs(hands) do
  1219. if node and node.getParent and node:getParent() then
  1220. node:removeFromParent()
  1221. end
  1222. end
  1223. end
  1224. self._otherCards = {{}, {}, {}, {},{}}
  1225. end
  1226. -- 游戏单局结算
  1227. function DdzRoomView:onResponseGameResult( data )
  1228. if self._gameResult==true then
  1229. return
  1230. end
  1231. self.ui.Items.btnPlay.play = false
  1232. self.ui.Items.btnPlay:loadTextureNormal("record_play.png", 1)
  1233. self:stopTurn(false)
  1234. self._playStart = false
  1235. self._gameResult = true
  1236. local msg = data.response
  1237. for _,v in pairs(msg.players) do
  1238. local node = self:getPlayerNode(v.userId)
  1239. if node then
  1240. node:setScore(v.totalScore)
  1241. node:setTurn(false)
  1242. end
  1243. node:hideLeft()
  1244. end
  1245. end
  1246. -- 总结算
  1247. function DdzRoomView:onResponseGameOver( data )
  1248. local msg = data.response
  1249. for _,player in ipairs(msg.players) do
  1250. local pdata = self._room:getPlayer(player.userId)
  1251. player.unionid = pdata.unionid
  1252. player.headimgurl = pdata.headimgurl
  1253. player.gpsInfo = pdata.gpsInfo
  1254. player.sex = pdata.sex
  1255. player.openid = pdata.openid
  1256. player.nickname = pdata.nickname
  1257. player.areano = pdata.areano
  1258. end
  1259. -- 缓存结算信息
  1260. self._isGameOver = true
  1261. self._gameOverData = msg
  1262. local roomInfo = self.roomInfo
  1263. self._gameOverData.nShowTableId = roomInfo.nTableId
  1264. self._gameOverData.startCount = roomInfo.nGameStartCount
  1265. self._gameOverData.totalCount = roomInfo.nTotalGameNum
  1266. self._gameOverData.roomRule = self:getRuleString()
  1267. if self._gameResult==false then--已经展示过小结算后解散房间
  1268. self:onNormalShowGameOver()
  1269. end
  1270. end
  1271. --[[先显示小局结算,再显示总结算--]]
  1272. function DdzRoomView:onNormalShowGameOver( data )
  1273. self._gameResult = false
  1274. local showFunc = function (msg)
  1275. local view = import("pk_zgwrddz.luaScript.Views.Room.Sub.luzhouPdkGameOverView"):new(msg)
  1276. view:setAnchorPoint(cc.p(0.5, 0.5))
  1277. app:showWaitDialog(view)
  1278. end
  1279. if self._isGameOver and self._gameOverData then
  1280. showFunc(self._gameOverData)
  1281. end
  1282. end
  1283. ----------------------------------------------------------------------------------------------------------------------
  1284. ----------------------------------------------------------------------------------------------------------------------
  1285. -- 单局结算显示剩余牌
  1286. function DdzRoomView:showLeftCards( pos, cards )
  1287. self:showTurnBtn(false)
  1288. if #cards <=0 then return end
  1289. self:clearPosShow(pos)
  1290. if pos==2 then --self:getMode()==1 and
  1291. local tmp = {}
  1292. for _,v in ipairs(cards) do
  1293. table.insert(tmp, 1, v)
  1294. end
  1295. cards = tmp
  1296. end
  1297. local scaleWdt = DdzRoomViewConfig.CARD_DLT_WIDTH*DdzRoomViewConfig.CARD_SCALE[2]
  1298. local root = cc.Node:create()
  1299. local nodes = {}
  1300. for i,card in ipairs(cards) do
  1301. local node = self:genCard(card)
  1302. local pt = cc.p(0, 0)
  1303. if pos==1 then --self:getMode() == 0 or
  1304. pt.x = pt.x + (i-1)*scaleWdt
  1305. node:setLocalZOrder(100+i)
  1306. else
  1307. if i>=9 then
  1308. pt.y = pt.y - 80
  1309. if pos ~= 2 then
  1310. pt.x = pt.x + (i-math.floor(i/9)*9)*scaleWdt
  1311. else
  1312. pt.x = pt.x - (i-math.floor(i/9)*9)*scaleWdt
  1313. node:setLocalZOrder(36-i)
  1314. end
  1315. else
  1316. if pos ~= 2 then
  1317. pt.x = pt.x + (i-math.floor(i/9)*9-1)*scaleWdt
  1318. else
  1319. pt.x = pt.x - (i-math.floor(i/9)*9-1)*scaleWdt
  1320. node:setLocalZOrder(16-i)
  1321. end
  1322. end
  1323. end
  1324. node:setScale(DdzRoomViewConfig.CARD_SCALE[2])
  1325. node:setPosition(pt)
  1326. root:addChild(node)
  1327. node:setVisible(false)
  1328. table.insert(nodes, node)
  1329. end
  1330. local dltWidth = 0
  1331. local rpt = clone(DdzRoomViewConfig.SHOW_CARD_POS[self:getMode()][pos])
  1332. if pos == 1 then
  1333. rpt.x = 200
  1334. rpt.y = 110
  1335. else
  1336. dltWidth = #cards/2*scaleWdt
  1337. end
  1338. root:setPosition(rpt)
  1339. self.cardRoot[10]:addChild(root)
  1340. table.insert(self._showCards[pos], root)
  1341. for i,v in ipairs(nodes) do
  1342. v:runAction(cc.Sequence:create(cc.DelayTime:create((i-1)*0.05), cc.CallFunc:create(function ()
  1343. v:setVisible(true)
  1344. end)))
  1345. end
  1346. end
  1347. -- 根据位置显示一组牌 cards@出牌牌组 pos@出牌视角位置 tp@出牌的类型isContinue@是否接牌
  1348. function DdzRoomView:showCards( cards, pos, tp, isContinue )
  1349. self:clearPosShow(pos)
  1350. self._lastCards =cards
  1351. self._lastOutType = tp
  1352. if pos==2 or pos==3 then -- self:getMode()==1 and
  1353. local tmp = {}
  1354. for _,v in ipairs(cards) do
  1355. table.insert(tmp, 1, v)
  1356. end
  1357. cards = tmp
  1358. end
  1359. local root = cc.Node:create()
  1360. local scale = DdzRoomViewConfig.CARD_SCALE[2]
  1361. local allCount = #cards
  1362. for i,card in ipairs(cards) do
  1363. local node = self:genCard(card)
  1364. local pt = cc.p(0, 0)
  1365. if pos == 1 then
  1366. local midIdx = allCount/2
  1367. if i<midIdx then--左边
  1368. pt.x = 0 - (midIdx-i-1)*DdzRoomViewConfig.CARD_DLT_WIDTH*scale
  1369. else--右边
  1370. pt.x = 0 + (i-midIdx+1)*DdzRoomViewConfig.CARD_DLT_WIDTH*scale
  1371. end
  1372. pt.x = pt.x - DdzRoomViewConfig.CARD_WIDTH/2*scale
  1373. else
  1374. --[[if pos ==2 or pos ==3 then --
  1375. node:setLocalZOrder(36-i)
  1376. pt.x = pt.x - (i-1)*DdzRoomViewConfig.CARD_DLT_WIDTH*scale
  1377. else
  1378. pt.x = pt.x + (i-1)*DdzRoomViewConfig.CARD_DLT_WIDTH*scale
  1379. end--]]
  1380. local rowNum = 13
  1381. if i>rowNum then
  1382. pt.y = pt.y - 40
  1383. if pos == 2 or pos == 3 then
  1384. pt.x = pt.x - (i-1)%rowNum*DdzRoomViewConfig.CARD_DLT_WIDTH*scale
  1385. node:setLocalZOrder(36-i)
  1386. else
  1387. pt.x = pt.x + (i-1)%rowNum*DdzRoomViewConfig.CARD_DLT_WIDTH*scale
  1388. end
  1389. else
  1390. if pos == 2 or pos == 3 then
  1391. pt.x = pt.x - (i-1)%rowNum*DdzRoomViewConfig.CARD_DLT_WIDTH*scale
  1392. node:setLocalZOrder(16-i)
  1393. else
  1394. pt.x = pt.x + (i-1)%rowNum*DdzRoomViewConfig.CARD_DLT_WIDTH*scale
  1395. end
  1396. end
  1397. end
  1398. node:setScale(scale)
  1399. node:setPosition(pt)
  1400. root:addChild(node)
  1401. end
  1402. local dltWidth = 0
  1403. rpt = clone(DdzRoomViewConfig.RECORD_SHOW_CARD_POS5[self:getMode()][pos])
  1404. if pos == 1 then
  1405. rpt = cc.p(CENTER_X, 220*g_radio_y)
  1406. else
  1407. dltWidth = math.floor(#cards/2)*DdzRoomViewConfig.CARD_DLT_WIDTH*scale
  1408. end
  1409. root:setPosition(rpt)
  1410. self.cardRoot[10]:addChild(root)
  1411. table.insert(self._showCards[pos], root)
  1412. --牌型动画
  1413. self:showEffect(pos, tp, dltWidth, cards, isContinue)
  1414. end
  1415. -- 清除某玩家的出牌
  1416. function DdzRoomView:clearPosShow(pos)
  1417. local nodes = self._showCards[pos]
  1418. if nodes and type(nodes) == 'table' then
  1419. for _,v in ipairs(nodes) do
  1420. if v:getParent() then v:removeFromParent() end
  1421. end
  1422. end
  1423. self._showCards[pos] = {}
  1424. end
  1425. -- 添加玩家节点
  1426. function DdzRoomView:addPlayerNode( pInfo )
  1427. local node = self._playerNodes[tonumber(pInfo.userId)]
  1428. if node then return end
  1429. node = DdzPlayerNode:new()
  1430. local rule = self._room:getRoomInfo().specialRule
  1431. local allowPass = self._room:getRoomInfo().allowPass
  1432. node:setGameInfo(json.encode({allowPass=allowPass}))
  1433. node:setMaxPlayerCount(self._room:getRoomInfo().nMaxPlayCount)
  1434. node:setShowNum(true)--是否显示牌张数
  1435. node:setInfo(pInfo)
  1436. node:setPlayMode(self:getMode())
  1437. node:setReady(pInfo.playFlag==1)
  1438. node:setHost(pInfo.userId==self.roomInfo.nRoomOwnedUid)
  1439. node:setPosition(DdzRoomViewConfig.PLAYER_POS[self:getMode()][pInfo.viewPos])
  1440. self._playerNodes[pInfo.userId] = node
  1441. node:setLocalZOrder(10)
  1442. self.ui.Items.toolPanel:getParent():addChild(node)
  1443. end
  1444. -- 删除玩家节点
  1445. function DdzRoomView:delPlayerNode( uid )
  1446. if self._gameResult or self._isGameOver then return end
  1447. local node = self._playerNodes[uid]
  1448. if not node then return end
  1449. node:removeFromParent()
  1450. self._playerNodes[uid] = nil
  1451. end
  1452. -- 获取玩家节点
  1453. function DdzRoomView:getPlayerNode( uid )
  1454. return self._playerNodes[tonumber(uid)]
  1455. end
  1456. -- 根据视图获取玩家节点
  1457. function DdzRoomView:getPlayerNodeVpos( viewPos )
  1458. for _,v in pairs(self._playerNodes) do
  1459. if v:getInfo().viewPos==viewPos then
  1460. return v
  1461. end
  1462. end
  1463. return nil
  1464. end
  1465. -- 发牌
  1466. function DdzRoomView:sendCards( cards_, pos )
  1467. local cards = pokerSortPdkCards(cards_)
  1468. local CardsCount = #cards
  1469. for i,card in ipairs(cards) do
  1470. local ac = cc.Sequence:create(cc.DelayTime:create(i*0.05), cc.CallFunc:create(function ()
  1471. self:sendOneCard(card.cid, i, pos, i==CardsCount, CardsCount)
  1472. end))
  1473. self.cardRoot[pos]:runAction(ac)
  1474. end
  1475. end
  1476. -- 发一张牌
  1477. function DdzRoomView:sendOneCard( card, i, pos, islast, allCount )
  1478. -- local node = self:genCard(card)
  1479. local node = self:genCard(-1,i)--back
  1480. if pos~=1 then
  1481. node = self:genCard(-1,i,2)
  1482. else
  1483. node:setScale(DdzRoomViewConfig.CARD_SCALE[pos])--DdzRoomViewConfig.CARD_SCALE_START
  1484. end
  1485. node.cid = card
  1486. node:setLast(islast)
  1487. local endX = CENTER_X + (allCount-allCount/2+1)*DdzRoomViewConfig.CARD_DLT_WIDTH*DdzRoomViewConfig.CARD_SCALE[1]
  1488. local pt = cc.p(0, 0)
  1489. local mode = self:getMode()
  1490. local otherScale = 0.4
  1491. local rowNum = 16
  1492. if pos ~= 1 then
  1493. pt = clone(DdzRoomViewConfig.RECORD_INIT_CARD_POS[mode][pos])
  1494. if i>rowNum then
  1495. pt.y = pt.y - 40
  1496. --[[if pos == 2 or pos == 3 then
  1497. pt.x = pt.x - (i-1)%rowNum*DdzRoomViewConfig.LCARD_DLT_WIDTH
  1498. node:setLocalZOrder(36-i)
  1499. else--]]
  1500. pt.x = pt.x + (i-1)%rowNum*DdzRoomViewConfig.LCARD_DLT_WIDTH
  1501. --end
  1502. else
  1503. --[[if pos == 2 or pos == 3 then
  1504. pt.x = pt.x - (i-1)%rowNum*DdzRoomViewConfig.LCARD_DLT_WIDTH
  1505. node:setLocalZOrder(16-i)
  1506. else--]]
  1507. pt.x = pt.x + (i-1)%rowNum*DdzRoomViewConfig.LCARD_DLT_WIDTH
  1508. --end
  1509. end
  1510. else
  1511. local tAllCount = allCount
  1512. if tAllCount > DdzRoomViewConfig.ROW_MAX_CARDS_NUM then
  1513. tAllCount = DdzRoomViewConfig.ROW_MAX_CARDS_NUM
  1514. end
  1515. local midIdx = tAllCount/2
  1516. if i <= DdzRoomViewConfig.ROW_MAX_CARDS_NUM then
  1517. pt.x = DdzRoomViewConfig.HANDCARD_MIDPOS
  1518. if i<=midIdx then--左边
  1519. pt.x = pt.x - (midIdx-i-1)*DdzRoomViewConfig.CARD_DLT_WIDTH*DdzRoomViewConfig.CARD_SCALE[1]
  1520. else--右边
  1521. pt.x = pt.x + (i-midIdx+1)*DdzRoomViewConfig.CARD_DLT_WIDTH*DdzRoomViewConfig.CARD_SCALE[1]
  1522. end
  1523. pt.x = pt.x - DdzRoomViewConfig.CARD_WIDTH/2*DdzRoomViewConfig.CARD_SCALE[1]
  1524. pt.y = DdzRoomViewConfig.RECORD_INIT_CARD_POS[mode][pos].y
  1525. else
  1526. --先算出第一排第一张牌的X位置
  1527. pt.x = DdzRoomViewConfig.HANDCARD_MIDPOS - (midIdx-1-1)*DdzRoomViewConfig.CARD_DLT_WIDTH*DdzRoomViewConfig.CARD_SCALE[1]
  1528. pt.x = pt.x + (i - DdzRoomViewConfig.ROW_MAX_CARDS_NUM-1)*DdzRoomViewConfig.CARD_DLT_WIDTH*DdzRoomViewConfig.CARD_SCALE[1]
  1529. pt.x = pt.x - DdzRoomViewConfig.CARD_WIDTH/2*DdzRoomViewConfig.CARD_SCALE[1]
  1530. pt.y = DdzRoomViewConfig.RECORD_INIT_CARD_POS[mode][pos].y - DdzRoomViewConfig.ROW_SPACING
  1531. end
  1532. node:setLocalZOrder(i)
  1533. end
  1534. node:setPosition(cc.p(endX, pt.y))
  1535. node:setOpacity(0)
  1536. self.cardRoot[pos]:addChild(node)
  1537. local ac = nil
  1538. if pos ~=1 then
  1539. ac = cc.Sequence:create(cc.Spawn:create(cc.MoveTo:create(0.1, pt), cc.FadeIn:create(0.1)), cc.CallFunc:create(function ()
  1540. table.insert(self._otherCards[pos], node)
  1541. DdzSoundHelper:playSend()
  1542. end), cc.DelayTime:create((allCount-i)*0.08), cc.CallFunc:create(function() node:setCard(node.cid) end ))
  1543. node:runAction(ac)
  1544. else
  1545. ac = cc.Sequence:create(cc.Spawn:create(cc.MoveTo:create(0.1, pt), cc.FadeIn:create(0.1)), cc.CallFunc:create(function ()
  1546. table.insert(self._selfCards, node)
  1547. DdzSoundHelper:playSend()
  1548. end), cc.DelayTime:create((allCount-i)*0.08), cc.CallFunc:create(function() node:setCard(node.cid) end ))
  1549. node:runAction(ac)
  1550. end
  1551. end
  1552. -- 发一张牌没有动画
  1553. function DdzRoomView:sendOneCardNoAct( card, i, pos, islast, allCount )
  1554. local node = self:genCard(card,i)--back
  1555. if pos~=1 then
  1556. node = self:genCard(card,i,2)
  1557. else
  1558. node:setScale(DdzRoomViewConfig.CARD_SCALE[pos])--DdzRoomViewConfig.CARD_SCALE_START
  1559. end
  1560. local mode = self:getMode()
  1561. node:setLast(islast)
  1562. local pt = cc.p(0, 0)
  1563. local rowNum = 16
  1564. if pos ~= 1 then
  1565. pt = clone(DdzRoomViewConfig.RECORD_INIT_CARD_POS[mode][pos])
  1566. if i>rowNum then
  1567. pt.y = pt.y - 40
  1568. pt.x = pt.x + (i-1)%rowNum*DdzRoomViewConfig.LCARD_DLT_WIDTH
  1569. else
  1570. pt.x = pt.x + (i-1)%rowNum*DdzRoomViewConfig.LCARD_DLT_WIDTH
  1571. end
  1572. else
  1573. local tAllCount = allCount
  1574. if tAllCount > DdzRoomViewConfig.ROW_MAX_CARDS_NUM then
  1575. tAllCount = DdzRoomViewConfig.ROW_MAX_CARDS_NUM
  1576. end
  1577. local midIdx = tAllCount/2
  1578. if i <= DdzRoomViewConfig.ROW_MAX_CARDS_NUM then
  1579. pt.x = DdzRoomViewConfig.HANDCARD_MIDPOS
  1580. if i<=midIdx then--左边
  1581. pt.x = pt.x - (midIdx-i-1)*DdzRoomViewConfig.CARD_DLT_WIDTH*DdzRoomViewConfig.CARD_SCALE[1]
  1582. else--右边
  1583. pt.x = pt.x + (i-midIdx+1)*DdzRoomViewConfig.CARD_DLT_WIDTH*DdzRoomViewConfig.CARD_SCALE[1]
  1584. end
  1585. pt.x = pt.x - DdzRoomViewConfig.CARD_WIDTH/2*DdzRoomViewConfig.CARD_SCALE[1]
  1586. pt.y = DdzRoomViewConfig.RECORD_INIT_CARD_POS[mode][pos].y
  1587. else
  1588. --先算出第一排第一张牌的X位置
  1589. pt.x = DdzRoomViewConfig.HANDCARD_MIDPOS - (midIdx-1-1)*DdzRoomViewConfig.CARD_DLT_WIDTH*DdzRoomViewConfig.CARD_SCALE[1]
  1590. pt.x = pt.x + (i - DdzRoomViewConfig.ROW_MAX_CARDS_NUM-1)*DdzRoomViewConfig.CARD_DLT_WIDTH*DdzRoomViewConfig.CARD_SCALE[1]
  1591. pt.x = pt.x - DdzRoomViewConfig.CARD_WIDTH/2*DdzRoomViewConfig.CARD_SCALE[1]
  1592. pt.y = DdzRoomViewConfig.RECORD_INIT_CARD_POS[mode][pos].y - DdzRoomViewConfig.ROW_SPACING
  1593. end
  1594. --node:setLocalZOrder(i)
  1595. end
  1596. node:setPosition(pt)
  1597. node:setLocalZOrder(i)
  1598. self.cardRoot[pos]:addChild(node)
  1599. if pos == 1 then
  1600. table.insert(self._selfCards, node)
  1601. else
  1602. table.insert(self._otherCards[pos], node)
  1603. end
  1604. end
  1605. -- 创建一张牌
  1606. function DdzRoomView:genCard( card,uniqueFlag,ctype)
  1607. local node = DdzCardNode:new(card,uniqueFlag,ctype)
  1608. node:setCard(card)
  1609. node:setSelectedHeight(DdzRoomViewConfig.SELECTED_HEIGHT)
  1610. node:setNormalHeight(DdzRoomViewConfig.NORMAL_HEIGHT)
  1611. return node
  1612. end
  1613. -- 从手牌中获取一张牌
  1614. function DdzRoomView:getCardNode( card )
  1615. if card > 0x00 and card <= 0x5d then
  1616. for _,v in pairs(self._selfCards) do
  1617. if v:getVal()==card then
  1618. return v
  1619. end
  1620. end
  1621. return nil
  1622. else
  1623. return nil
  1624. end
  1625. end
  1626. -- 根据牌ID移除一张手牌,并重新调整手牌位置
  1627. function DdzRoomView:removeCardNode( card )
  1628. --删牌的时候服务器下发的是癞子混出的实际牌取值0x5X(X值为1-C),但是手上只有0x5d的癞子牌,这里全部转换成癞子来删除
  1629. if card >= 0x50 and card <= 0x5d then
  1630. card = 0x5d
  1631. end
  1632. local node = self:getCardNode(card)
  1633. --if not node or tolua.isnull(node) then return end
  1634. for i=#self._selfCards,1,-1 do
  1635. if self._selfCards[i]:getVal()==card then
  1636. table.remove(self._selfCards, i)
  1637. break
  1638. end
  1639. end
  1640. if tolua.isnull(node) then
  1641. node = nil
  1642. self:removeHandcards(card)
  1643. else
  1644. node:removeFromParent(true)
  1645. end
  1646. end
  1647. --直接从手牌中找牌删除
  1648. function DdzRoomView:removeHandcards(card)
  1649. for i,v in pairs(self.cardRoot:getChildren()) do
  1650. if v:getVal() == card then
  1651. v:removeFromParent(true)
  1652. break
  1653. end
  1654. end
  1655. end
  1656. --移除牌
  1657. function DdzRoomView:removeOtherCards( viewPos, cards )
  1658. local nodeSet = self._otherCards[viewPos]
  1659. for _,card in ipairs(cards) do
  1660. if card >= 0x50 and card <= 0x5d then
  1661. card = 0x5d
  1662. end
  1663. --[[if card > 0x00 and card <= 0x5d then
  1664. for _,v in pairs(nodeSet) do
  1665. if v:getVal()==card then
  1666. for i=#nodeSet,1,-1 do
  1667. if nodeSet[i]:getVal()==card then
  1668. table.remove(nodeSet, i)
  1669. break
  1670. end
  1671. end
  1672. v:removeFromParent()
  1673. end
  1674. end
  1675. end--]]
  1676. for i=#nodeSet,1,-1 do
  1677. if nodeSet[i]:getVal()==card then
  1678. table.remove(nodeSet, i)
  1679. break
  1680. end
  1681. end
  1682. end
  1683. local tccards = self:getCardsByUi(self._otherCards[viewPos])
  1684. self:recoverHandcardsByPos(tccards,viewPos)
  1685. --[[local pos = viewPos
  1686. local mode = self:getMode()
  1687. local otherScale = 0.4
  1688. local rowNum = 16
  1689. for i,v in ipairs(nodeSet) do
  1690. local pt = cc.p(0, 0)
  1691. if pos ~= 1 then
  1692. pt = clone(DdzRoomViewConfig.RECORD_INIT_CARD_POS[mode][pos])
  1693. if i>rowNum then
  1694. pt.y = pt.y - 40
  1695. pt.x = pt.x + (i-1)%rowNum*DdzRoomViewConfig.LCARD_DLT_WIDTH
  1696. else
  1697. pt.x = pt.x + (i-1)%rowNum*DdzRoomViewConfig.LCARD_DLT_WIDTH
  1698. end
  1699. v:setLocalZOrder(i)
  1700. v:setPosition(pt)
  1701. end
  1702. end--]]
  1703. end
  1704. -- 获取当前手牌
  1705. function DdzRoomView:getHandCards()
  1706. local handCards = {}
  1707. for _,v in pairs(self._selfCards) do
  1708. table.insert(handCards, v:getVal())
  1709. end
  1710. return handCards
  1711. end
  1712. -- 重置手牌位置
  1713. function DdzRoomView:resetCardsPos( )
  1714. if #self._selfCards<=0 then return end
  1715. local mode = self:getMode()
  1716. local pos = 1
  1717. local scale = DdzRoomViewConfig.CARD_SCALE[pos]
  1718. local dtpx = (16 - #self._selfCards)/2*DdzRoomViewConfig.CARD_DLT_WIDTH*scale
  1719. local allCount = #self._selfCards
  1720. local midIdx = allCount/2
  1721. for i,v in ipairs(self._selfCards) do
  1722. local pt = cc.p(CENTER_X, 0)
  1723. if i<midIdx then--左边
  1724. pt.x = pt.x - (midIdx-i-1)*DdzRoomViewConfig.CARD_DLT_WIDTH*scale
  1725. else--右边
  1726. pt.x = pt.x + (i-midIdx+1)*DdzRoomViewConfig.CARD_DLT_WIDTH*scale
  1727. end
  1728. pt.x = pt.x - DdzRoomViewConfig.CARD_WIDTH/2*scale
  1729. pt.y = DdzRoomViewConfig.RECORD_INIT_CARD_POS[self:getMode()][pos].y
  1730. v:setPosition(pt)
  1731. v:setLast(i==allCount)
  1732. v:setNormal()
  1733. end
  1734. end
  1735. -- 提示对应的牌
  1736. function DdzRoomView:tipCards( cards )
  1737. self:resetCardsPos()
  1738. for _,v in pairs(cards) do
  1739. local node = self:getCardNode(v.cid)
  1740. if node and node:getVal()>0 then
  1741. self._selectCards[node:getVal()] = node
  1742. node:setDown()
  1743. end
  1744. end
  1745. end
  1746. -- 清除所有牌
  1747. function DdzRoomView:cleanSelfCards()
  1748. for _,v in pairs(self._selfCards) do
  1749. if v:getParent() then v:removeFromParent() end
  1750. end
  1751. self._selfCards = {}
  1752. end
  1753. function DdzRoomView:cleanShowCards()
  1754. for _,v in pairs(self._showCards) do
  1755. for _,vv in pairs(v) do
  1756. if vv and vv:getParent() then
  1757. vv:removeFromParent()
  1758. end
  1759. end
  1760. end
  1761. self._showCards = {{},{},{},{},{}}
  1762. end
  1763. -- 二人玩显示另外一组牌
  1764. function DdzRoomView:showOtherCards(is)
  1765. if is then
  1766. self.imgOtherCards:setVisible(true)
  1767. local num = 13
  1768. --if self.ruleType==2 then num = 15 end
  1769. self.txtOtherCards:setString(string.format("剩余%d张", num))
  1770. else
  1771. self.imgOtherCards:setVisible(false)
  1772. end
  1773. end
  1774. function DdzRoomView:onEnter()
  1775. DdzRoomView.super.onEnter()
  1776. PokerUtil = require("pk_zgwrddz.luaScript.Views.Room.zgwrDdzPokerUtil"):new({isChai=self.ruleIsChaiBomb, isFAT=self.ruleIsFAT})
  1777. self:bindEvents()
  1778. local changeDesk = tonumber(loadUserInfo("wrddz_setting_bg_idx")) or 3
  1779. self:onNormalChangeDesktop({idx=changeDesk-1})
  1780. DdzSoundHelper:playBgMusic()
  1781. local roomInfo = self._room:getRoomInfo()
  1782. self.ui.Items.systemTime:setText(string.format("%s 局数:%d/%d", os.date("%m-%d %H:%M:%S", roomInfo.endtime), roomInfo.nGameStartCount or 0, roomInfo.nTotalGameNum or 0 ))
  1783. -- 默认开始回放
  1784. self:onClickButtonPlay( self.ui.Items.btnPlay, 1 )
  1785. end
  1786. function DdzRoomView:onExit()
  1787. if self.Time then
  1788. cc.Director:getInstance():getScheduler():unscheduleScriptEntry(self.Time)
  1789. self.Time = nil
  1790. end
  1791. if self._gameResultTimer then
  1792. cc.Director:getInstance():getScheduler():unscheduleScriptEntry(self._gameResultTimer)
  1793. self._gameResultTimer = nil
  1794. end
  1795. for _,node in pairs(self._playerNodes) do
  1796. if node then node:setTurn(false) end
  1797. end
  1798. self:stopTurn()
  1799. PokerUtil = nil
  1800. stopBGMusic()
  1801. end
  1802. --显示地主抓的底牌
  1803. function DdzRoomView:showDiPai(cards)
  1804. if not cards or type(cards) ~= 'table' then return end
  1805. local index = 1
  1806. for i,v in pairs(cards) do
  1807. local cardPng = pokerLPng(v)
  1808. local dipai = string.format("ImageView_dipai_%d",index)
  1809. if self.ui.Items[dipai] then
  1810. self.ui.Items[dipai]:loadTexture(cardPng,1)
  1811. end
  1812. index = index + 1
  1813. end
  1814. end
  1815. --显示地主选的暗地主牌
  1816. function DdzRoomView:showAnDiZhuCard(card)
  1817. logD("DdzRoomView:showAnDiZhuCard", card);
  1818. if card == 0x0e then
  1819. self:showZiChi(true)
  1820. else
  1821. self:showZiChi(false)
  1822. local cardPng = pokerLPng(card)
  1823. self.ui.Items.ImageView_andizhupai:loadTexture(cardPng,1)
  1824. end
  1825. end
  1826. --显示自吃
  1827. function DdzRoomView:showZiChi(show)
  1828. self.ui.Items.ImageView_zichi:setVisible(show)
  1829. end
  1830. return DdzRoomView