|
- -- xx : 2018/5/7
- -- 跑得快回放界面
- local DdzDef = require("luaScript.SubGameDefine.zgwrDdzDefine")
- local DdzPlayerNode = require("pk_zgwrddz.luaScript.Views.Room.Node.zgwrDdzPlayerNode")
- local DdzCardNode = require("pk_zgwrddz.luaScript.Views.Room.Node.zgwrDdzCardNode")
- local DdzRoomViewConfig = require("pk_zgwrddz.luaScript.Views.Room.zgwrDdzRoomViewConfig")
- local DdzEffectHelper = require("pk_zgwrddz.luaScript.Views.Room.zgwrDdzEffectHelper"):new()
- local ETS = DdzRoomViewConfig.EffectType
- local DdzSoundHelper = require("pk_zgwrddz.luaScript.Views.Room.zgwrDdzSoundHelper"):new()
- --local WRDDZDefine=require("luaScript.SubGameDefine.zgwrDdzDefine")
- require("luaScript.Views.Room.RoomFunctions")
- local CENTER_X=640*g_radio_x
- local CENTER_Y=360*g_radio_y
-
- -- 表ta中是否包含元素x
- local function ownX( ta, x )
- local rst = false
- for _,v in ipairs(ta) do
- if tonumber(v) == tonumber(x) then
- rst = true
- break
- end
- end
- return rst
- end
- -- 获取ta表中移除tb表的结果
- local function getDelAdB( ta, tb )
- -- print("------------------getDelAdB---------------------------")
- -- print("----ta: ", table.concat(ta, "_"))
- -- print("----tb: ", table.concat(tb, "_"))
-
- --[[local tmp = {}
- for _,v in ipairs(ta) do
- if not ownX(tb, v) then
- table.insert(tmp, v)
- end
- end--]]
- -- print("----tmp: ", table.concat(tmp, "_"))
- -- print("------------------------------------------------------")
- local tmp = clone(ta)
- for _,v in pairs(tb) do
- if v >= 0x50 and v <= 0x5d then
- v = 0x5d
- end
- for i=#tmp,1,-1 do
- if tmp[i] == v then
- table.remove(tmp, i)
- break
- end
- end
- end
- return tmp
- end
-
-
- local OP_TYPE_STRING_NO = {
- single_card = ETS.SINGLE_CARD,
- three_and_two = ETS.THREE_AND_TWO,
- dui_zi = ETS.DUI_ZI,
- lian_dui = ETS.LIAN_DUI,
- airplane = ETS.AIRPLANE,
- shun_zi = ETS.SHUN_ZI,
- bomb = ETS.BOMB,
- four_and_three = ETS.FOUR_AND_THREE,
- }
- --------------------------------------------------------------------------------------------------------------------------------------------
- --------------------------------------------------------------------------------------------------------------------------------------------
- --------------------------------------------------------------------------------------------------------------------------------------------
- --------------------------------------------------------------------------------------------------------------------------------------------
- --------------------------------------------------------------------------------------------------------------------------------------------
- --------------------------------------------------------------------------------------------------------------------------------------------
- local PRoom = class("DdzRoomPlay")
- function PRoom:ctor( )
- -- 玩家信息
- self._players = {}
- -- 房间信息
- self.roomInfo = {}
- end
-
- -- 添加玩家,如果玩家存在则更新数据
- -- key - value 缓存
- function PRoom:addPlayer( pl )--and update
- self._players = self._players or {}
- local player = self._players[tostring(pl.userId)]
- if player then
- for k,v in pairs(pl) do
- player[k] = v
- end
- else
- self._players[tostring(pl.userId)] = pl
- end
- end
-
- -- 删除玩家
- function PRoom:delPlayer( uid )
- local player = self._players[tostring(uid)]
- if player then
- self._players[tostring(uid)] = nil
- end
- end
-
- -- 获取玩家
- function PRoom:getPlayer( uid )
- local player = self._players[tostring(uid)]
- return player
- end
-
- -- 根据座位号获取玩家数据
- function PRoom:getPlayerCid( cid )
- for _,v in pairs(self._players) do
- if v.seatId == cid then
- return v
- end
- end
- return nil
- end
-
- -- 根据视角获取玩家数据
- function PRoom:getPlayerVpos( viewPos )
- for _,v in pairs(self._players) do
- if v.viewPos == viewPos then
- return v
- end
- end
- return nil
- end
-
- -- 获取所有玩家
- function PRoom:getPlayers()
- return self._players or {}
- end
-
- -- 获取玩家数量
- function PRoom:getPlayerNum()
- local count = 0
- for _,_ in pairs(self._players) do
- count = count + 1
- end
- return count
- end
-
- -- 根据id判断是否是自己
- function PRoom:isMyself( uid )
- return tonumber(app.user.loginInfo.uid) == tonumber(uid)
- end
-
- -- 获取自己信息
- function PRoom:getMyself()
- return self._players[tostring(app.user.loginInfo.uid)] or self._players[tostring(app.firstRecordUid)]
- end
-
- -- 视角转换
- function PRoom:transPos( pos )
- local myself = self:getMyself()
- local MaxCount = self:getRoomInfo().nMaxPlayCount
- local showPos = 0
- local myPos = myself.seatId
- if myPos <= pos then
- showPos = pos - myPos
- elseif myPos > pos then
- showPos = MaxCount - myPos + pos
- end
- return showPos+1
- end
-
- -- 获取房间信息
- function PRoom:getRoomInfo()
- return self.roomInfo
- end
-
- -- 缓存房间信息
- function PRoom:setRoomInfo( roominfo )
- self.roomInfo = self.roomInfo or {}
- for k,v in pairs(roominfo) do
- self.roomInfo[k] = v
- end
- end
-
- -- 获取下一个轮次
- function PRoom:getNextTurn(viewPos)
- local MaxCount = self:getRoomInfo().nMaxPlayCount
- if MaxCount == 5 then
- if viewPos == 5 then
- return 1
- else
- return viewPos+1
- end
- elseif MaxCount == 4 then
- if viewPos == 4 then
- return 1
- else
- return viewPos+1
- end
- elseif MaxCount == 3 then
- if viewPos == 3 then
- return 1
- else
- return viewPos+1
- end
- else
- if viewPos == 2 then
- return 1
- else
- return viewPos+1
- end
- end
- --return (viewPos+1)%MaxCount==0 and MaxCount or (viewPos+1)%MaxCount
- end
- --------------------------------------------------------------------------------------------------------------------------------------------
- --------------------------------------------------------------------------------------------------------------------------------------------
- --------------------------------------------------------------------------------------------------------------------------------------------
- --------------------------------------------------------------------------------------------------------------------------------------------
- --------------------------------------------------------------------------------------------------------------------------------------------
- --------------------------------------------------------------------------------------------------------------------------------------------
-
- local DdzRoomView = class("DdzRoomView", cc.UIView)
- function DdzRoomView:ctor(recordData)
- DdzRoomView.super.ctor(self)
- self._recordData = recordData
- --房间信息
- self.roomInfo = {}
- -- 玩家节点
- self._playerNodes = {}
- -- 自己手牌集合
- self._selfCards = {}
- -- 玩家手牌集合
- self._otherCards = {{}, {}, {}, {} ,{}}
- -- 玩家出牌集合
- self._showCards = {{},{},{},{},{}}
- -- 上一次出牌viewPos
- self._lastOutPos = 0
- -- 上一次出牌类型
- self._lastOutType = 0
- -- 上一次出牌,用于提示
- self._lastCards = {}
- -- 排序轮次用
- self._turnsQueue = {}
- -- 是否开始播放
- self._playStart = false
- -- 数据备份,以便重复播放
- self._backupData = nil
- -- 是否已经最后展示
- self._gameResult = nil
- -- 本轮所有操作次数
- self._allOps = 0
- -- 当前所剩操作数
- self._leftOps = 0
- -- 结算数据
- self._resultData = nil
-
- -- 房间缓存
- self._room = PRoom:new()
- self:parseData(self._recordData)
-
- self.ui = loadUI("pk_zgwrddz/res/ui/ui_room/ui_wrddz_recordplayview.ui")
- self:addChild(self.ui)
-
- --loadSpriteFrameFile("pk_zgwrddz/res/ui/zy_game/lzroom_add.plist")
- self:initUi()
- self.roomInfo = self._room:getRoomInfo()
- self:setRoomInfo(self.roomInfo)
-
- loadSpriteFrameFile("pk_zgwrddz/res/ui/zy_game/wrddz_cards.plist")
- loadSpriteFrameFile("pk_zgwrddz/res/ui/zy_effect/lzpdk_effect.plist")
- loadSpriteFrameFile("pk_zgwrddz/res/ui/zy_effect/ddz_effect_bomb.plist")
- loadSpriteFrameFile("pk_zgwrddz/res/ui/zy_effect/ddz_effect_plan.plist")
- loadSpriteFrameFile("pk_zgwrddz/res/ui/zy_effect/ddz_effect_shunziliandui.plist")
- loadSpriteFrameFile("pk_zgwrddz/res/ui/zy_effect/ddz_effect_spring.plist")
- loadSpriteFrameFile("pk_zgwrddz/res/ui/zy_effect/ddz_effect_sszd.plist")
- loadSpriteFrameFile("pk_zgwrddz/res/ui/zy_effect/ddz_effect_zhangshui.plist")
- loadSpriteFrameFile("pk_zgwrddz/res/ui/zy_effect/ddz_effect_kingbomb.plist")
- loadSpriteFrameFile("pk_zgwrddz/res/ui/zy_effect/ddz_effect_baojing.plist")
-
- DdzRoomViewConfig.CARD_SCALE[1] = 0.8
- --
- local rule = self.roomInfo.specialRule
- end
-
- --[[
- "recordData" = {
- "dipai" = ""
- "endtime" = 1525689769
- "ext" = {
- "banker" = "1025568"
- "clubId" = 206231
- "deductRule" = 0
- "gamerule" = 1
- "playerNum" = 1
- "specialRule" = 65
- "tableIdx" = 1
- }
- "flag" = 0
- "gameid" = 9
- "idx" = 1
- "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"
- "pid" = "2568504031125505"
- "score" = {
- "1024796" = 33
- "1024798" = -28
- "1025568" = -5
- }
- "subid" = "2550911843082241"
- "turn" = 1
- "user" = {
- "1024796" = {
- "hand" = "0x0d 0x1b 0x2b 0x3b 0x0a 0x3a 0x28 0x38 0x35 0x14 0x03 0x33 0x02 0x12 0x32 0x11"
- "seatid" = 1
- }
- "1024798" = {
- "hand" = "0x2c 0x1a 0x39 0x08 0x18 0x07 0x27 0x06 0x16 0x05 0x25 0x34 0x13 0x23 0x22 0x01"
- "seatid" = 2
- }
- "1025568" = {
- "hand" = "0x1c 0x3c 0x0b 0x2a 0x09 0x19 0x29 0x17 0x37 0x26 0x36 0x15 0x04 0x24 0x21 0x31"
- "seatid" = 0
- }
- }
- }
-
- "playerInfo" = {
- "head" = "http://thirdwx.qlogo.cn/mmopen/vi_32/Q0j4TwGTfTK9s9890abV3nHDBgZFOXuO3eAoCs2SsuFFbp0NUzChuCM4wAEUf02IQI7TYW8gelo75fTxKRQdDA/132"
- "name" = "名52688"
- "sex" = 1
- }
- ]]
- function DdzRoomView:parseData( data )
- local roomInfo = {}
- roomInfo.nTableId = data.roomid
- roomInfo.clubId = data.ext.clubId
- roomInfo.banker = data.ext.banker--庄家
- roomInfo.gamerule = data.ext.gamerule
- roomInfo.playnum = data.ext.playnum or 5
- roomInfo.specialRule = data.ext.specialRule
- roomInfo.tableIdx = data.ext.tableIdx
- roomInfo.allowPass = data.ext.allowPass
- roomInfo.nGameStartCount = data.turn
- roomInfo.nTotalGameNum = data.nbound----------------------------
- roomInfo.deductRule = data.ext.deductRule
- roomInfo.endtime = data.endtime
- roomInfo.nMaxPlayCount = 0
- local tdipai = string.split(data.dipai," ")
- for i = #tdipai,1,-1 do
- if tdipai[i] == "" then
- table.remove(tdipai,i)
- end
- end
- roomInfo.dipai = tdipai
-
- roomInfo.nMaxPlayCount = roomInfo.playnum
-
-
- for k,v in pairs(data.user) do
- local user = {}
- user.userId = tonumber(k)
- user.seatId = v.seatid
- local cstr = string.split(v.hand, " ")
- user.handCards = {}
- for _,v in ipairs(cstr) do
- if string.len(v) > 0 then
- table.insert(user.handCards, tonumber(v))
- end
- end
- user.leftCards = clone(user.handCards)
- user.leftNum = #user.handCards
- local oinfo = app.playerInfoManager:getPlayerInfo(tonumber(k))
- if oinfo then
- user.headimgurl = oinfo.head
- user.sex = oinfo.sex
- user.nickname = oinfo.name
- end
- self._room:addPlayer(user)
- end
- roomInfo.nMaxPlayCount = table.nums(data.user)
- self._room:setRoomInfo(roomInfo)
-
- local firstId = false
- app.firstRecordUid = 0
- for k,v in pairs(data.user) do
- local user = {}
- user.userId = tonumber(k)
- if not firstId then
- app.firstRecordUid = user.userId--找到一个uid代替自己的uid,防止没有参加游戏的人看回放了报错
- firstId = true
- end
- user.viewPos = self._room:transPos(v.seatid)
- user.score = data.score[k]
- self._room:addPlayer(user)
- end
- if string.len(data.ops) <=0 then --没开始,提前解散
- -- result data
- local result = {}
- local players = self._room:getPlayers()
- local pt = {}
- for k,v in pairs(players) do
- local d = {}
- d.userId = tonumber(k)
- d.leftCards = clone(v.leftCards)
- d.totalScore = v.score
- d.sex = v.sex
- d.headimgurl = v.headimgurl
- d.nickname = v.nickname
- table.insert(pt, d)
- end
- result.players = pt
- self._resultData = {response=result}
- return
- end
-
- --op data
- local opStrST = string.split(data.ops, "|")--1025568,outCard:{ 0x21 0x31 },handType: dui_zi
- for _,opstr in ipairs(opStrST) do
- local opT = string.split(opstr, ",")
- local uid = opT[1]
- local opstr1,opType,opstr1Value
- local cardstr = string.gsub(opT[2], "outCard:{ ", "")
- if opT[2] and not string.find(opT[2],"outCard") then
- local topstr = string.split(opT[2], ":")
- opstr1 = topstr[1]
- opType = 1
- opstr1Value = tonumber(topstr[2]) or 0
- end
- cardstr = string.gsub(cardstr, " }", "")
- local cardstrT = string.split(cardstr, " ")
- local cards = {}
- for _,cid in ipairs(cardstrT) do
- table.insert(cards, tonumber(cid))
- end
-
- if opT[3] then
- opstr1 = string.gsub(opT[3], "handType:", "")
- opType = tonumber(opstr1) or 0
- end
- --
- local user = self._room:getPlayer(uid)
- if user then
- local pdata = {}
- pdata.userId = tonumber(uid)
- pdata.viewPos = user.viewPos
- pdata.seatId = user.seatId
- pdata.cards = cards
- pdata.opType = opType
- pdata.opstr1 = opstr1
- pdata.opstr1Value = opstr1Value
- pdata.leftNum = user.leftNum-#cards
-
- local tmpLeft = getDelAdB(user.leftCards, cards)
- user.leftCards = clone(tmpLeft)
- user.leftNum = #tmpLeft
- self._room:addPlayer(user)
-
- local preData = self:getTurnLast()
- if preData then
- --local preViewPos = preData.viewPos
- --local nextTurn = self._room:getNextTurn(preViewPos)
- --if nextTurn==pdata.viewPos then
- self:addTurnData(pdata)
- --[[else--添加要不起
- while nextTurn~=pdata.viewPos do
- preData = self:getTurnLast()
- if preData then
- preViewPos = preData.viewPos
- nextTurn = self._room:getNextTurn(preViewPos)
- local player = self._room:getPlayerVpos(nextTurn)
- local passData = {}
- passData.userId = tonumber(player.userId)
- passData.viewPos = nextTurn
- passData.seatId = player.seatId
- passData.cards = {}
- passData.opType = 0
- passData.opstr1 = ""
- passData.leftNum = player.leftNum
- self:addTurnData(passData)
- nextTurn = self._room:getNextTurn(nextTurn)
- else
- break
- end
- end
- self:addTurnData(pdata)--]]
- --end
- else
- self:addTurnData(pdata)
- end
- else
- local pdata = {}
- pdata.opType = opType
- pdata.opstr1 = opstr1
- pdata.opstr1Value = opstr1Value
- self:addTurnData(pdata)
- end
- end
-
- -- result data
- local result = {}
- local players = self._room:getPlayers()
- local pt = {}
- for k,v in pairs(players) do
- local d = {}
- d.userId = tonumber(k)
- d.leftCards = clone(v.leftCards)
- d.totalScore = v.score
- d.sex = v.sex
- d.headimgurl = v.headimgurl
- d.nickname = v.nickname
- table.insert(pt, d)
- end
- result.players = pt
- self._resultData = {response=result}
- -- 数据备份
- self._backupData = clone(self._turnsQueue)
- -- 总步骤
- self._allOps = #self._turnsQueue
- end
-
- function DdzRoomView:resetRoundData()
- -- 上一次出牌viewPos
- self._lastOutPos = 0
- -- 上一次出牌类型
- self._lastOutType = 0
- self._lastCards = {}
- self.lastOutFlag = -1
-
- self:cleanSelfCards()
- self:cleanShowCards()
- self:stopTurn()
- self:showOtherCards(false)
- -- 清空玩家时钟
- for _,v in pairs(self._playerNodes) do
- v:setTurn(false)
- end
- end
-
- function DdzRoomView:getMode()
- return self._room:getRoomInfo().nMaxPlayCount or 5
- end
-
- function DdzRoomView:initUi()
- self.cardRoot = {}
- --1-5存放手牌 --10存放出的牌等
- self.cardRoot[1] = self.ui.Items.cardRoot_1
- self.cardRoot[2] = self.ui.Items.cardRoot_2
- self.cardRoot[3] = self.ui.Items.cardRoot_3
- self.cardRoot[4] = self.ui.Items.cardRoot_4
- self.cardRoot[5] = self.ui.Items.cardRoot_5
- self.cardRoot[10] = self.ui.Items.cardRoot_0
- --self.cardRoot = self.ui.Items.cardRoot
- self.imgOtherCards = self.ui.Items.ImageView_other
- self.txtOtherCards = self.ui.Items.Text_otherNum
- self:showOtherCards(false)
-
- self.ui.Items.toolPanel:setLocalZOrder(101)
-
- self.ui.Items.btnReturn:registerClick(handler(self , self.onClickButtonReturn))
- self.ui.Items.btnPlay:registerClick(handler(self , self.onClickButtonPlay))
- self.ui.Items.ButtonToward:registerClick(handler(self , self.onClickButtonToward))
-
- self.ui.Items.btnDetail:registerClick(handler(self , self.onClickButtonDetails))
- self.ui.Items.btnDetail:setVisible(false)
- self.ui.Items.Button_rule:registerClick(handler(self, self.onClickButtonDetails))
- self.ui.Items.Layout_Rule:setVisible(false)
- self.ui.Items.Layout_7:setVisible(false)
- self.ui.Items.Text_Rule:setVisible(false)
- self.ui.Items.Layout_7:registerClick(handler(self , self.onClickMenuOut))
- local bar = self.ui.Items.ListView:getVBar()
- bar:setVisible(false)
-
- self.ui.Items.imgTip:setVisible(false)
- self.ui.Items.imgTip:setOpacity(0)
- self.ui.Items.imgTip:setLocalZOrder(200)
-
- --添加玩家节点
- local players = self._room:getPlayers()
- for _, info in pairs(players) do
- self:addPlayerNode( info )
- end
-
- self:showZiChi(false)
- end
-
- function DdzRoomView:onClickMenuOut( sender )
- self.ui.Items.Layout_Rule:setVisible(false)
- self.ui.Items.Layout_7:setVisible(false)
- self.ui.Items.Button_rule:setVisible(true)
- self.ui.Items.Layout_Rule:stopAllActions()
- end
-
- function DdzRoomView:updateProgress()
- local over = 0
- local overOps = self._allOps - self._leftOps
- -- local percent = math.floor((overOps/self._allOps)*100)
- self.ui.Items.Text_jindu:setString(string.format("进度:%d/%d", overOps, self._allOps))
- if overOps==self._allOps then
- showTooltip("回放结束")
- end
- end
-
- function DdzRoomView:onClickButtonPlay( sender, flag )
- if flag ~= 1 then
- playBtnEffect()
- end
- if sender.play == nil then
- sender.play = false
- end
- if sender.play then
- sender.play = false
- sender:loadTextureNormal("record_play.png", 1)
- self:stopTurn(false)
- else
- sender.play = true
- sender:loadTextureNormal("record_pause.png", 1)
- if self._gameResult == true then
- self:resetRoundData()
- self._turnsQueue = clone(self._backupData)
- end
- if self._playStart==true then
- self:stopTurn(false)
- self:startTurns()
- else
- local myself = self._room:getMyself()
- if myself then
- local data = {}
- data.response = {}
- data.response.cards = myself.handCards
- local playerCards = {}
- local players = self._room:getPlayers()
- for _,v in pairs(players) do
- playerCards[v.viewPos] = clone(v.handCards)
- end
- data.response.playerCards = playerCards
- --local banker = self._room:getPlayer(self._room:getRoomInfo().banker)
- --data.response.bankerSeat = banker.seatId
- self:onResponseSendCards(data)
- self.ui:runDelay(4.5, function() self:startTurns() end )
- end
- end
- end
- end
-
- function DdzRoomView:onClickButtonToward( sender )
- playBtnEffect()
- if self.ui.Items.btnPlay.play == nil then
- return
- end
- self.ui.Items.btnPlay.play = true
- self:onClickButtonPlay( self.ui.Items.btnPlay )
- local data = self:getTurnData()
- if data then
- self:updateTurns(data)
- else
- self:onResponseGameResult(self._resultData)
- end
- self._leftOps = #self._turnsQueue
- -- show
- self:updateProgress()
- self:stopTurn(false)
- end
-
- -- 玩家点击房间详情
- function DdzRoomView:onClickButtonDetails( sender )
- playBtnEffect()
- --[[local node = self.ui.Items.btnDetail:getChildByTag(101)
- if node then
- else
- local rule = self:getRuleString()
- local view = import("pk_zgwrddz.luaScript.Views.Room.Sub.luzhouPdkGameDetailView"):new(rule)
- view:setPosition(cc.p(view:getSizeWidth()+60, 60))
- view:setTag(101)
- self.ui.Items.btnDetail:addChild(view)
- end--]]
- self.ui.Items.Layout_Rule:setVisible(not self.ui.Items.Layout_Rule:isVisible())
- self.ui.Items.Layout_7:setVisible(self.ui.Items.Layout_Rule:isVisible())
- self.ui.Items.Button_rule:setVisible(not self.ui.Items.Layout_Rule:isVisible())
- end
-
- function DdzRoomView:onClickButtonReturn( sender )
- playBtnEffect()
- self:removeFromParent()
- end
-
- --[[获取房间详情字符串--]]
- function DdzRoomView:getRuleString()
- local rule = self.roomInfo.specialRule
- local ruleStr = ""
- ruleStr = ruleStr..DdzRoomViewConfig.RoonInfoConfig.play[tonumber(self.roomInfo.gamerule)]..","
- ruleStr = ruleStr..DdzRoomViewConfig.RoonInfoConfig.num[tonumber(self.roomInfo.playnum)]..","
- if getNumBand(rule, 0x0001)>0 then
- ruleStr = ruleStr..DdzRoomViewConfig.CreateParamsMean[0x0001]..","
- end
- if getNumBand(rule, 0x0002)>0 then
- ruleStr = ruleStr..DdzRoomViewConfig.CreateParamsMean[0x0002]..","
- end
-
- if string.len(ruleStr) > 0 then
- ruleStr = string.sub(ruleStr, 1, string.len(ruleStr)-1)
- end
- return ruleStr
- end
-
- -- 设置房间信息
- function DdzRoomView:setRoomInfo( info )
- self.ui.Items.roomNum:setString(string.format("房号:%06d", info.nTableId))
-
- self.ui.Items.ListView:removeAllChildren()
- self.ui.Items.ListView:setAutoSize(true)
- local multLimit={
- [30] = "封顶30倍",
- [60] = "封顶60倍",
- }
- local playRule={
- [1] = "加底1",
- [2] = "加底2",
- [4] = "加倍",
- }
-
- if self._recordData.ext.multLimit then
- local text = self.ui.Items.Text_Rule:getCopied()
- text:setVisible(true)
- text:setString(multLimit[self._recordData.ext.multLimit])
- self.ui.Items.ListView:addChild(text)
- end
- local playrl = self._recordData.ext.playRule
- if playrl and playrl > 0 then
- if getNumBand(playrl, 1) > 0 then
- local text = self.ui.Items.Text_Rule:getCopied()
- text:setVisible(true)
- text:setString(playRule[1])
- self.ui.Items.ListView:addChild(text)
- elseif getNumBand(playrl, 2) > 0 then
- local text = self.ui.Items.Text_Rule:getCopied()
- text:setVisible(true)
- text:setString(playRule[2])
- self.ui.Items.ListView:addChild(text)
- end
- if getNumBand(playrl, 4) > 0 then
- local text = self.ui.Items.Text_Rule:getCopied()
- text:setVisible(true)
- text:setString(playRule[4])
- self.ui.Items.ListView:addChild(text)
- end
- end
-
- if self._recordData.ext.baseMulti then
- local text = self.ui.Items.Text_Rule:getCopied()
- text:setVisible(true)
- text:setString("积分倍数×" .. self._recordData.ext.baseMulti)
- self.ui.Items.ListView:addChild(text)
- end
- --[[local rules = WRDDZDefine.getWanFaInfoTab(self._recordData.ext)
- for k,v in pairs(rules) do
- local text = self.ui.Items.Text_Rule:getCopied()
- text:setVisible(true)
- text:setString(v)
- self.ui.Items.ListView:addChild(text)
- end--]]
- end
-
- -- 显示轮次
- function DdzRoomView:showTurnBtn( is )
- if is then --回放出牌
- end
- end
-
- -- 一键截屏
- function DdzRoomView:onClickButtonShot( sender )
- playBtnEffect()
- showScreenShot()
- end
- -- 设置点击
- function DdzRoomView:onClickButtonSetting( sender )
- playBtnEffect()
- self:showMenu(false)
- local view = import("pk_zgwrddz.luaScript.Views.Room.Sub.luzhouPdkSettingView"):new()
- view:setAnchorPoint(cc.p(0.5, 0.5))
- app:showWaitDialog(view)
- end
- -- 上传日志点击
- function DdzRoomView:onClickButtonUlog( sender )
- playBtnEffect()
- self:showMenu(false)
- local view = import("luaScript.Views.Room.UplogView"):new()
- view:setAnchorPoint(cc.p(0.5, 0.5))
- app:showWaitDialog(view)
- end
-
- -- 变暗不能出的牌
- function DdzRoomView:downCanotOuts(canotOuts, isTouch)
- for _,v in pairs(canotOuts) do
- local node = self:getCardNode(v)
- if node then node:setNoTouch(isTouch) end
- end
- end
-
- function DdzRoomView:bindEvents()
- -- 游戏设置里更换桌面
- -- self:bindEvent(app.room , "pdkNormalEvent_changeDesktop" , handler(self , self.onNormalChangeDesktop))
- end
-
- -- 更换桌面
- function DdzRoomView:onNormalChangeDesktop( data )
- --if data.idx >5 and data.idx<1 then return end
- local changeDesk = tonumber(loadUserInfo("wrddz_setting_bg_idx")) or 3
- self.ui.Items.ImageView_bg:loadTexture(string.format("pk_zgwrddz/res/ui/zy_game/wrddr_gamebg_%d.jpg", changeDesk), 0)
- --self.ui.Items.ImageView_logo:loadTexture(string.format("pk_zgwrddz/res/ui/zy_game/wwddz_img_logo_%d.png", changeDesk), 0)
- end
-
- -- 通知玩家分数
- function DdzRoomView:onResponseUpdateScore( data )
- local msg = data.response
- for _,pdata in ipairs(msg.players) do
- local node = self:getPlayerNode(pdata.userId)
- if node then node:setScore(pdata.totalScore) end
- end
- end
-
- -- 给玩家发牌
- function DdzRoomView:onResponseSendCards( data )
- self._leftOps = self._allOps
- self:updateProgress()
- self:cleanOtherHands()
- self._gameResult = false
- self._passGameResult = nil
- self._playStart = true
- self.ui.Items.ButtonToward:setEnabled(false)
- self.ui.Items.btnPlay:setEnabled(false)
- for viewPos,v in pairs(data.response.playerCards) do
- self:sendCards(v, viewPos)
- end
-
- local bankerData = self._room:getPlayerCid(data.response.bankerSeat)
- for _,v in pairs( self._playerNodes ) do
- --v:setBanker(v:getInfo().userId==bankerData.userId)
- v:setBanker(false)
- v:setTurn(false)
- v:setScore(0)
- end
- if bankerData and bankerData.userId then
- if self._room:isMyself(bankerData.userId) then
- self:runAction(cc.Sequence:create(cc.DelayTime:create(1), cc.CallFunc:create(function ()
- self:showTurnBtn(true)
- local node = self:getPlayerNodeVpos(1)
- if node then node:setTurn(true) end
- end)))
- else
- self:showTurnBtn(false)
- self:runAction(cc.Sequence:create(cc.DelayTime:create(1), cc.CallFunc:create(function ()
- local node = self:getPlayerNode(bankerData.userId)
- if node then node:setTurn(true) end
- end)))
- end
- end
- -- 发完牌后显示牌张数
- self:runDelay(3, function ()
- local left = 25
- --if self.ruleType==2 then left = 15 end
- for uid,v in pairs(self._playerNodes) do
- local viewPos =v:getInfo().viewPos
- if viewPos and self._otherCards[viewPos] then
- v:showLeft(#self._otherCards[viewPos])
- end
- self.ui.Items.ButtonToward:setEnabled(true)
- self.ui.Items.btnPlay:setEnabled(true)
- end
- end)
- end
-
- -- 将回放数据按照先后顺序处理成串行以便调度器调用
- function DdzRoomView:addTurnData( data )
- table.insert(self._turnsQueue, data)
- end
-
- function DdzRoomView:getTurnData( isRemove )
- local data = nil
- if #self._turnsQueue > 0 then
- data = clone(self._turnsQueue[1])
- if isRemove==nil then
- table.remove(self._turnsQueue, 1)
- end
- end
- return data
- end
-
- function DdzRoomView:getTurnLast()
- local data = nil
- if #self._turnsQueue > 0 then
- data = clone(self._turnsQueue[#self._turnsQueue])
- end
- return data
- end
-
- function DdzRoomView:startTurns()
- local data = self:getTurnData()
- if data then
- self:updateTurns(data)
- else
- return
- end
- if not self._turnTimer then
- self._turnTimer = cc.Director:getInstance():getScheduler():scheduleScriptFunc(function()
- ----------------------
- local data = self:getTurnData()
- if data then
- self:updateTurns(data)
- else
- self:stopTurn()
- self:onResponseGameResult(self._resultData)
- end
- end,2,false)
- end
- end
-
- function DdzRoomView:stopTurn(isClean)
- isClean = isClean or true
- if self._turnTimer then
- cc.Director:getInstance():getScheduler():unscheduleScriptEntry(self._turnTimer)
- self._turnTimer = nil
- if isClean then self._cmdQueue = {} end
- end
- end
-
- --[[
- ,defVar("selfId", VT_Int, 0)--自己ID
- ,defVar("userId", VT_Int, 0)
- ,defVar("cardType", VT_Short, 0)
- ,defVar("leftNum", VT_Short, 0)--出牌者剩余多少张牌
- ,defVar("cards", VT_Vector(VT_UChar), {})
-
- passData.userId = tonumber(player.userId)
- passData.viewPos = nextTurn
- passData.seatId = player.seatId
- passData.cards = {}
- passData.opType = 0
- ]]
- -- 处理是否是出牌,如果出牌,则显示对应玩家出牌,如果是pass,显示对应玩家pass
- function DdzRoomView:updateTurns( data )
- local msg = data
- self._leftOps = #self._turnsQueue
- self:updateProgress()
- self.lastOutFlag = msg.opType--操作类型
- local viewPos = data.viewPos
- local node = self:getPlayerNode(data.userId)
- self:showTurns(viewPos)
- if node then
- local function show()
- if msg.opstr1 and msg.opstr1 == "askLord" then--显示叫地主
- self.opAskLord = self.opAskLord or 0
- self.opAskLord = self.opAskLord + 1
- if self.opAskLord == 6 then
- self:clearJdzJbInfo()
- self.opAskLord = 1
- end
- node:showJiaoDiZhu(msg.opstr1Value == 1)
- node:setHost(msg.opstr1Value == 1)
- if msg.opstr1Value == 1 then
- local dipai = self._room:getRoomInfo().dipai
- self:showDiPai(self._room:getRoomInfo().dipai)
- end
- self.isNeedClearJDZJB = true
- return
- elseif msg.opstr1 and msg.opstr1 == "askDouble" then--显示加倍
- self:clearJdzJbInfo()
- node:showJiaBei(msg.opstr1Value == 1)
- if node:isHost() then
- node:setFanMult(msg.opstr1Value == 1)
- else
- node:setMult(msg.opstr1Value == 1)
- end
- self.isNeedClearJDZJB = true
- return
- elseif msg.opstr1 and msg.opstr1 == "selectDark" then--显示暗地主和暗地主牌
- self:clearJdzJbInfo()
- node:setAnDiZhu(msg.opstr1Value ~= 0x0e) -- 自吃时,不显示暗地主标识
- self:showAnDiZhuCard(msg.opstr1Value)
- self.isNeedClearJDZJB = true
- return
- end
- if self.isNeedClearJDZJB and self.isNeedClearJDZJB == true then
- self.isNeedClearJDZJB = nil
- self:clearJdzJbInfo()
- end
- if viewPos == 1 then--自己能出牌
- if self._lastOutPos == 1 then
- self:cleanLastCards()
- self.lastOutFlag = -1
- end
- self:clearPosShow(1)
- self:showTurnBtn(true)
- else--别人能出牌,对应位置出牌
- self:showTurnBtn(false)
- end
- local outData = {}
- outData.selfId = self._room:getMyself().userId
- outData.userId = msg.userId
- outData.cardType = msg.opType
- outData.leftNum = msg.leftNum
- outData.cards = clone(msg.cards)
- self:onResponseOutCards({response=outData})
- end
- local function passShow()
- if viewPos == 1 then
- self:showEffect(viewPos, ETS.PASS)
- self:showPass()
- self:cleanLastCards(false)
- else
- self:showEffect(viewPos, ETS.PASS)
- end
- end
- if msg.opType == 0 then
- node:runAction(cc.Sequence:create(cc.DelayTime:create(0.1), cc.CallFunc:create(passShow)))
- else
- show()
- end
- else
- if msg.opstr1 and msg.opstr1 == "totalMult" then--显示叫地主
- self:onUpdateGameMult(msg.opstr1Value)
- end
- end
- end
-
- --显示加倍
- function DdzRoomView:onUpdateGameMult(mult)
- self.ui.Items.TextBMFont_beishu:setText(mult)
- end
-
- -- 显示轮次时钟
- function DdzRoomView:showTurns( viewPos )
- for _,node in pairs(self._playerNodes) do
- local is = node:getInfo().viewPos==viewPos
- node:setTurn(is)
- if is then self:clearPosShow(viewPos) end
- end
- end
-
- -- 清除叫地主加倍信息
- function DdzRoomView:clearJdzJbInfo()
- for _,node in pairs(self._playerNodes) do
- if node then
- node:cleanPass()
- end
- end
- end
-
- -- 广播当前桌子轮次@userId@seatId@outFlag
- function DdzRoomView:onResponseUpdateTurns( data )
- self:addTurn(data)
- end
-
- -- 清理上一次的出牌
- function DdzRoomView:cleanLastCards(isClean)
- if isClean==nil then isClean = true end
- if self._lastOutPos > 0 then
- if isClean == true then
- self:clearPosShow(self._lastOutPos)
- end
- self._lastCards = {}
- self._lastOutType = 0
- self._lastOutPos = 0
- end
- end
-
- -- 玩家出牌成功
- function DdzRoomView:onResponseOutCards( data )
- local msg = data.response
- local isContinue = #self._lastCards>0 and self._lastOutType>0
- -- 清理上一次的出牌
- self:cleanLastCards()
- if msg.isMustBomb and msg.isMustBomb == 1 then
- msg.cardType = ETS.NONE
- end
- local viewPos = self._room:getPlayer(msg.userId).viewPos
- -- 缓存上次出的牌
- self._lastOutPos = viewPos
- self._lastOutType = msg.cardType
- self._lastCards = msg.cards
-
- self:showTurns(0)
- if #msg.cards <= 0 then
- msg.cardType = 0
- end
- self:showCards(msg.cards, viewPos, msg.cardType, isContinue)
-
- --玩家剩余牌
- local node = self:getPlayerNode(msg.userId)
- if node and msg.cards and #msg.cards > 0 then
- --[[if not node:isAlarm() and msg.leftNum==1 then
- if self:getMode()==0 then
- if node:getInfo().viewPos==2 then DdzSoundHelper:single( node:getInfo().sex ) end
- elseif self:getMode()==1 then
- if node:getInfo().viewPos==3 then DdzSoundHelper:single( node:getInfo().sex ) end
- end
- end--]]
- if msg.leftNum==1 then
- DdzSoundHelper:single( node:getInfo().sex )
- elseif msg.leftNum==2 then
- DdzSoundHelper:single2( node:getInfo().sex )
- end
- node:showLeft(msg.leftNum)
- end
- if viewPos == 1 then--判断是否自己出牌
- self:showTurnBtn(false)
- for _,v in pairs(msg.cards) do
- --self:removeCardNode(v)
- if v >= 0x50 and v <= 0x5d then
- v = 0x5d
- end
- for i=#self._selfCards,1,-1 do
- if self._selfCards[i]:getVal()==v then
- table.remove(self._selfCards, i)
- break
- end
- end
- end
- local tccards = self:getCardsByUi(self._selfCards)
- self:recoverHandcardsByPos(tccards,1)
- --[[if msg.leftNum==1 then
- DdzSoundHelper:single( node:getInfo().sex )
- elseif msg.leftNum==2 then
- DdzSoundHelper:single2( node:getInfo().sex )
- end--]]
- --还原不可点
- self:downCanotOuts(self:getHandCards(), false)
- --self:resetCardsPos()
- else
- self:removeOtherCards(viewPos, msg.cards)
- end
- end
-
- -- 将ui数据转换为纯数据
- function DdzRoomView:getCardsByUi(cards)
- local tCards = {}
- for _,v in pairs(cards) do
- table.insert(tCards, v:getVal())
- end
- return tCards
- end
-
- -- 恢复自己手牌
- function DdzRoomView:recoverHandcardsByPos(_cards,pos)
- if pos == 1 then
- self.cardRoot[1]:removeAllChildren()
- self._selfCards = {}
- else
- self.cardRoot[pos]:removeAllChildren()
- self._otherCards[pos] = {}
- end
- local cards = pokerSortPdkCards(_cards)
- local allCount = #cards
- for i,card in ipairs(cards) do
- self:sendOneCardNoAct(card.cid, i, pos, i==allCount, allCount)
- end
- end
-
- -- 玩家自己显示要不起
- function DdzRoomView:showPass()
- do return end
- --self.ui.Items.imgTip:setOpacity(0)
- --self.ui.Items.imgTip:setVisible(true)
- --local ac = cc.Sequence:create(cc.FadeIn:create(0.2), cc.DelayTime:create(1), cc.FadeOut:create(0.2))
- --self.ui.Items.imgTip:runAction(ac)
- --手牌变暗
- local anFunc = function ()
- for k,v in pairs(self._selfCards) do
- v:setNoTouch(true)
- end
- end
-
- local mingFunc = function ()
- for k,v in pairs(self._selfCards) do
- v:setNoTouch(false)
- end
- end
- local ac = cc.Sequence:create(cc.CallFunc:create(anFunc), cc.DelayTime:create(0.1), cc.CallFunc:create(mingFunc))
- self.cardRoot[1]:runAction(ac)
- end
-
- -- cards@单张或者对子需要
- function DdzRoomView:showEffect( viewPos, effectType, dltWidth, cards, isContinue )
- if dltWidth == nil then
- dltWidth = 50
- end
- local rate = math.random(100)
- local stdRate = 70
- isContinue = isContinue or false
- local pNode = self:getPlayerNodeVpos(viewPos)
- if pNode==nil then return end
- local pInfo = pNode:getInfo()
- local sex = pInfo.sex
- local node = nil
- if effectType == ETS.PASS then
- local cb = function ()
- local node = self:getPlayerNodeVpos(viewPos)
- if node then node:setTurn(false) end
- end
- node = DdzEffectHelper:getPass(cb)
- local idx = math.random(4)
- DdzSoundHelper:effectPass( sex, idx )
- elseif effectType == ETS.SINGLE_CARD then
- local _, val = pokerParse(cards[1])
- DdzSoundHelper:effectSingle( sex ,val )
- elseif effectType == ETS.DUI_ZI then
- local _, val = pokerParse(cards[1])
- if isContinue and rate >= stdRate and DdzSoundHelper:getLanguageType() == 1 then
- DdzSoundHelper:daNi( sex )
- else
- DdzSoundHelper:effectDouble( sex, val )
- end
- elseif effectType == ETS.SHUN_ZI then
- node = DdzEffectHelper:getShunzi()
- if viewPos==1 and node then
- node:setScale(1.2)
- end
- if isContinue and rate>=stdRate and DdzSoundHelper:getLanguageType() == 1 then
- DdzSoundHelper:daNi( sex )
- else
- DdzSoundHelper:effectShunzi( sex )
- end
- elseif effectType == ETS.LIAN_DUI then
- node = DdzEffectHelper:getLiandui()
- if isContinue and rate>=stdRate and DdzSoundHelper:getLanguageType() == 1 then
- DdzSoundHelper:daNi( sex )
- else
- DdzSoundHelper:effectLiandui( sex )
- end
- elseif effectType == ETS.THREE_AND_ONE then
- node = DdzEffectHelper:getSandaiyi()
- DdzSoundHelper:effect3And1( sex )
- elseif effectType == ETS.THREE_AND_TWO or effectType == ETS.THREE_AND_DUI then
- node = DdzEffectHelper:getSandaier()
- if isContinue and rate>=stdRate and DdzSoundHelper:getLanguageType() == 1 then
- DdzSoundHelper:daNi( sex )
- else
- DdzSoundHelper:effect3And2( sex,effectType )
- end
- elseif effectType == ETS.THREE then
- local _, val = pokerParse(cards[1])
- DdzSoundHelper:effectThree( sex, val )
- elseif DdzRoomViewConfig.isBomb(effectType) then
- node = DdzEffectHelper:getBomb()
- 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
- node = DdzEffectHelper:getKingBomb()
- isKingBomb = true
- DdzSoundHelper:effectKingBomb( sex )
- elseif effectType >= ETS.SIX_SMALL_KING and effectType <= ETS.SIX_BIG_KING then
- node = DdzEffectHelper:getShenShuiBomb()
- DdzSoundHelper:effectShenShuiZha( sex )
- else
- DdzSoundHelper:effectBomb( sex )
- end
- elseif effectType == ETS.SAN_SHUN or effectType == ETS.AIRPLANE_SINGLE or effectType == ETS.AIRPLANE_DUI then
- node = DdzEffectHelper:getPlan()
- if effectType == ETS.SAN_SHUN then
- DdzSoundHelper:effectSanShun( sex )
- else
- DdzSoundHelper:effectPlane( sex )
- end
- end
- if node then
- local pt = clone(DdzRoomViewConfig.RECORD_SHOW_CARD_POS5[self:getMode()][viewPos])
- if effectType~=ETS.PASS then
- if effectType==ETS.SHUN_ZI then
- if viewPos == 2 or viewPos == 3 then
- pt.x = pt.x - dltWidth*2
- elseif viewPos == 4 or viewPos == 5 then
- pt.x = pt.x
- else
- pt.x = pt.x-50
- pt.y = 320*g_radio_y
- end
- else
- if viewPos == 2 or viewPos == 3 then
- pt.x = pt.x - dltWidth
- elseif viewPos == 4 or viewPos == 5 then
- pt.x = pt.x + dltWidth
- end
-
- end
- pt.y = pt.y - (DdzRoomViewConfig.CARD_HEIGHT/5*1)*DdzRoomViewConfig.CARD_SCALE[2]
- if effectType==ETS.BOMB then
- pt.y = (pt.y+120)*g_radio_y
- end
- if viewPos == 1 then
- pt.x = CENTER_X
- pt.y = 220*g_radio_y
- end
- else
- pt.y = pt.y + 40
- if effectType==ETS.PASS then
- if viewPos == 1 then
- pt.y = 220*g_radio_y--自己pass位置调整
- pt.x = CENTER_X
- else
- pt.y = (pt.y - 50)*g_radio_y
- end
- end
- end
- node:setPosition(pt)
- self:addChild(node)
- if node.onEnter and type(node.onEnter)=='function' then
- node:onEnter()
- end
- end
- end
-
- function DdzRoomView:cleanOtherHands()
- for _,hands in ipairs(self._otherCards) do
- for _,node in ipairs(hands) do
- if node and node.getParent and node:getParent() then
- node:removeFromParent()
- end
- end
- end
- self._otherCards = {{}, {}, {}, {},{}}
- end
- -- 游戏单局结算
- function DdzRoomView:onResponseGameResult( data )
- if self._gameResult==true then
- return
- end
- self.ui.Items.btnPlay.play = false
- self.ui.Items.btnPlay:loadTextureNormal("record_play.png", 1)
- self:stopTurn(false)
- self._playStart = false
- self._gameResult = true
- local msg = data.response
- for _,v in pairs(msg.players) do
- local node = self:getPlayerNode(v.userId)
- if node then
- node:setScore(v.totalScore)
- node:setTurn(false)
- end
- node:hideLeft()
- end
- end
-
- -- 总结算
- function DdzRoomView:onResponseGameOver( data )
- local msg = data.response
- for _,player in ipairs(msg.players) do
- local pdata = self._room:getPlayer(player.userId)
- player.unionid = pdata.unionid
- player.headimgurl = pdata.headimgurl
- player.gpsInfo = pdata.gpsInfo
- player.sex = pdata.sex
- player.openid = pdata.openid
- player.nickname = pdata.nickname
- player.areano = pdata.areano
- end
- -- 缓存结算信息
- self._isGameOver = true
- self._gameOverData = msg
- local roomInfo = self.roomInfo
- self._gameOverData.nShowTableId = roomInfo.nTableId
- self._gameOverData.startCount = roomInfo.nGameStartCount
- self._gameOverData.totalCount = roomInfo.nTotalGameNum
- self._gameOverData.roomRule = self:getRuleString()
- if self._gameResult==false then--已经展示过小结算后解散房间
- self:onNormalShowGameOver()
- end
- end
-
- --[[先显示小局结算,再显示总结算--]]
- function DdzRoomView:onNormalShowGameOver( data )
- self._gameResult = false
- local showFunc = function (msg)
- local view = import("pk_zgwrddz.luaScript.Views.Room.Sub.luzhouPdkGameOverView"):new(msg)
- view:setAnchorPoint(cc.p(0.5, 0.5))
- app:showWaitDialog(view)
- end
- if self._isGameOver and self._gameOverData then
- showFunc(self._gameOverData)
- end
- end
-
- ----------------------------------------------------------------------------------------------------------------------
- ----------------------------------------------------------------------------------------------------------------------
- -- 单局结算显示剩余牌
- function DdzRoomView:showLeftCards( pos, cards )
- self:showTurnBtn(false)
- if #cards <=0 then return end
- self:clearPosShow(pos)
- if pos==2 then --self:getMode()==1 and
- local tmp = {}
- for _,v in ipairs(cards) do
- table.insert(tmp, 1, v)
- end
- cards = tmp
- end
- local scaleWdt = DdzRoomViewConfig.CARD_DLT_WIDTH*DdzRoomViewConfig.CARD_SCALE[2]
- local root = cc.Node:create()
- local nodes = {}
- for i,card in ipairs(cards) do
- local node = self:genCard(card)
- local pt = cc.p(0, 0)
- if pos==1 then --self:getMode() == 0 or
- pt.x = pt.x + (i-1)*scaleWdt
- node:setLocalZOrder(100+i)
- else
- if i>=9 then
- pt.y = pt.y - 80
- if pos ~= 2 then
- pt.x = pt.x + (i-math.floor(i/9)*9)*scaleWdt
- else
- pt.x = pt.x - (i-math.floor(i/9)*9)*scaleWdt
- node:setLocalZOrder(36-i)
- end
- else
- if pos ~= 2 then
- pt.x = pt.x + (i-math.floor(i/9)*9-1)*scaleWdt
- else
- pt.x = pt.x - (i-math.floor(i/9)*9-1)*scaleWdt
- node:setLocalZOrder(16-i)
- end
- end
- end
- node:setScale(DdzRoomViewConfig.CARD_SCALE[2])
- node:setPosition(pt)
- root:addChild(node)
- node:setVisible(false)
- table.insert(nodes, node)
- end
- local dltWidth = 0
- local rpt = clone(DdzRoomViewConfig.SHOW_CARD_POS[self:getMode()][pos])
- if pos == 1 then
- rpt.x = 200
- rpt.y = 110
- else
- dltWidth = #cards/2*scaleWdt
- end
- root:setPosition(rpt)
- self.cardRoot[10]:addChild(root)
- table.insert(self._showCards[pos], root)
- for i,v in ipairs(nodes) do
- v:runAction(cc.Sequence:create(cc.DelayTime:create((i-1)*0.05), cc.CallFunc:create(function ()
- v:setVisible(true)
- end)))
- end
- end
-
- -- 根据位置显示一组牌 cards@出牌牌组 pos@出牌视角位置 tp@出牌的类型isContinue@是否接牌
- function DdzRoomView:showCards( cards, pos, tp, isContinue )
- self:clearPosShow(pos)
- self._lastCards =cards
- self._lastOutType = tp
- if pos==2 or pos==3 then -- self:getMode()==1 and
- local tmp = {}
- for _,v in ipairs(cards) do
- table.insert(tmp, 1, v)
- end
- cards = tmp
- end
- local root = cc.Node:create()
- local scale = DdzRoomViewConfig.CARD_SCALE[2]
- local allCount = #cards
- for i,card in ipairs(cards) do
- local node = self:genCard(card)
- local pt = cc.p(0, 0)
- if pos == 1 then
- local midIdx = allCount/2
- if i<midIdx then--左边
- pt.x = 0 - (midIdx-i-1)*DdzRoomViewConfig.CARD_DLT_WIDTH*scale
- else--右边
- pt.x = 0 + (i-midIdx+1)*DdzRoomViewConfig.CARD_DLT_WIDTH*scale
- end
- pt.x = pt.x - DdzRoomViewConfig.CARD_WIDTH/2*scale
- else
- --[[if pos ==2 or pos ==3 then --
- node:setLocalZOrder(36-i)
- pt.x = pt.x - (i-1)*DdzRoomViewConfig.CARD_DLT_WIDTH*scale
- else
- pt.x = pt.x + (i-1)*DdzRoomViewConfig.CARD_DLT_WIDTH*scale
- end--]]
- local rowNum = 13
- if i>rowNum then
- pt.y = pt.y - 40
- if pos == 2 or pos == 3 then
- pt.x = pt.x - (i-1)%rowNum*DdzRoomViewConfig.CARD_DLT_WIDTH*scale
- node:setLocalZOrder(36-i)
- else
- pt.x = pt.x + (i-1)%rowNum*DdzRoomViewConfig.CARD_DLT_WIDTH*scale
- end
- else
- if pos == 2 or pos == 3 then
- pt.x = pt.x - (i-1)%rowNum*DdzRoomViewConfig.CARD_DLT_WIDTH*scale
- node:setLocalZOrder(16-i)
- else
- pt.x = pt.x + (i-1)%rowNum*DdzRoomViewConfig.CARD_DLT_WIDTH*scale
- end
- end
- end
- node:setScale(scale)
- node:setPosition(pt)
- root:addChild(node)
- end
- local dltWidth = 0
- rpt = clone(DdzRoomViewConfig.RECORD_SHOW_CARD_POS5[self:getMode()][pos])
-
- if pos == 1 then
- rpt = cc.p(CENTER_X, 220*g_radio_y)
- else
- dltWidth = math.floor(#cards/2)*DdzRoomViewConfig.CARD_DLT_WIDTH*scale
- end
- root:setPosition(rpt)
- self.cardRoot[10]:addChild(root)
- table.insert(self._showCards[pos], root)
- --牌型动画
- self:showEffect(pos, tp, dltWidth, cards, isContinue)
- end
-
- -- 清除某玩家的出牌
- function DdzRoomView:clearPosShow(pos)
- local nodes = self._showCards[pos]
- if nodes and type(nodes) == 'table' then
- for _,v in ipairs(nodes) do
- if v:getParent() then v:removeFromParent() end
- end
- end
- self._showCards[pos] = {}
- end
-
-
- -- 添加玩家节点
- function DdzRoomView:addPlayerNode( pInfo )
- local node = self._playerNodes[tonumber(pInfo.userId)]
- if node then return end
- node = DdzPlayerNode:new()
- local rule = self._room:getRoomInfo().specialRule
- local allowPass = self._room:getRoomInfo().allowPass
- node:setGameInfo(json.encode({allowPass=allowPass}))
- node:setMaxPlayerCount(self._room:getRoomInfo().nMaxPlayCount)
- node:setShowNum(true)--是否显示牌张数
- node:setInfo(pInfo)
- node:setPlayMode(self:getMode())
-
- node:setReady(pInfo.playFlag==1)
- node:setHost(pInfo.userId==self.roomInfo.nRoomOwnedUid)
- node:setPosition(DdzRoomViewConfig.PLAYER_POS[self:getMode()][pInfo.viewPos])
- self._playerNodes[pInfo.userId] = node
- node:setLocalZOrder(10)
- self.ui.Items.toolPanel:getParent():addChild(node)
- end
-
- -- 删除玩家节点
- function DdzRoomView:delPlayerNode( uid )
- if self._gameResult or self._isGameOver then return end
- local node = self._playerNodes[uid]
- if not node then return end
- node:removeFromParent()
- self._playerNodes[uid] = nil
- end
-
- -- 获取玩家节点
- function DdzRoomView:getPlayerNode( uid )
- return self._playerNodes[tonumber(uid)]
- end
-
- -- 根据视图获取玩家节点
- function DdzRoomView:getPlayerNodeVpos( viewPos )
- for _,v in pairs(self._playerNodes) do
- if v:getInfo().viewPos==viewPos then
- return v
- end
- end
- return nil
- end
-
- -- 发牌
- function DdzRoomView:sendCards( cards_, pos )
- local cards = pokerSortPdkCards(cards_)
- local CardsCount = #cards
- for i,card in ipairs(cards) do
- local ac = cc.Sequence:create(cc.DelayTime:create(i*0.05), cc.CallFunc:create(function ()
- self:sendOneCard(card.cid, i, pos, i==CardsCount, CardsCount)
- end))
- self.cardRoot[pos]:runAction(ac)
- end
- end
-
- -- 发一张牌
- function DdzRoomView:sendOneCard( card, i, pos, islast, allCount )
- -- local node = self:genCard(card)
- local node = self:genCard(-1,i)--back
- if pos~=1 then
- node = self:genCard(-1,i,2)
- else
- node:setScale(DdzRoomViewConfig.CARD_SCALE[pos])--DdzRoomViewConfig.CARD_SCALE_START
- end
- node.cid = card
-
- node:setLast(islast)
- local endX = CENTER_X + (allCount-allCount/2+1)*DdzRoomViewConfig.CARD_DLT_WIDTH*DdzRoomViewConfig.CARD_SCALE[1]
- local pt = cc.p(0, 0)
- local mode = self:getMode()
- local otherScale = 0.4
- local rowNum = 16
- if pos ~= 1 then
-
- pt = clone(DdzRoomViewConfig.RECORD_INIT_CARD_POS[mode][pos])
- if i>rowNum then
- pt.y = pt.y - 40
- --[[if pos == 2 or pos == 3 then
- pt.x = pt.x - (i-1)%rowNum*DdzRoomViewConfig.LCARD_DLT_WIDTH
- node:setLocalZOrder(36-i)
- else--]]
- pt.x = pt.x + (i-1)%rowNum*DdzRoomViewConfig.LCARD_DLT_WIDTH
- --end
- else
- --[[if pos == 2 or pos == 3 then
- pt.x = pt.x - (i-1)%rowNum*DdzRoomViewConfig.LCARD_DLT_WIDTH
- node:setLocalZOrder(16-i)
- else--]]
- pt.x = pt.x + (i-1)%rowNum*DdzRoomViewConfig.LCARD_DLT_WIDTH
- --end
- end
- else
- local tAllCount = allCount
- if tAllCount > DdzRoomViewConfig.ROW_MAX_CARDS_NUM then
- tAllCount = DdzRoomViewConfig.ROW_MAX_CARDS_NUM
- end
- local midIdx = tAllCount/2
- if i <= DdzRoomViewConfig.ROW_MAX_CARDS_NUM then
- pt.x = DdzRoomViewConfig.HANDCARD_MIDPOS
- if i<=midIdx then--左边
- pt.x = pt.x - (midIdx-i-1)*DdzRoomViewConfig.CARD_DLT_WIDTH*DdzRoomViewConfig.CARD_SCALE[1]
- else--右边
- pt.x = pt.x + (i-midIdx+1)*DdzRoomViewConfig.CARD_DLT_WIDTH*DdzRoomViewConfig.CARD_SCALE[1]
- end
- pt.x = pt.x - DdzRoomViewConfig.CARD_WIDTH/2*DdzRoomViewConfig.CARD_SCALE[1]
- pt.y = DdzRoomViewConfig.RECORD_INIT_CARD_POS[mode][pos].y
- else
- --先算出第一排第一张牌的X位置
- pt.x = DdzRoomViewConfig.HANDCARD_MIDPOS - (midIdx-1-1)*DdzRoomViewConfig.CARD_DLT_WIDTH*DdzRoomViewConfig.CARD_SCALE[1]
- pt.x = pt.x + (i - DdzRoomViewConfig.ROW_MAX_CARDS_NUM-1)*DdzRoomViewConfig.CARD_DLT_WIDTH*DdzRoomViewConfig.CARD_SCALE[1]
- pt.x = pt.x - DdzRoomViewConfig.CARD_WIDTH/2*DdzRoomViewConfig.CARD_SCALE[1]
- pt.y = DdzRoomViewConfig.RECORD_INIT_CARD_POS[mode][pos].y - DdzRoomViewConfig.ROW_SPACING
- end
- node:setLocalZOrder(i)
- end
- node:setPosition(cc.p(endX, pt.y))
- node:setOpacity(0)
- self.cardRoot[pos]:addChild(node)
-
- local ac = nil
- if pos ~=1 then
- ac = cc.Sequence:create(cc.Spawn:create(cc.MoveTo:create(0.1, pt), cc.FadeIn:create(0.1)), cc.CallFunc:create(function ()
- table.insert(self._otherCards[pos], node)
- DdzSoundHelper:playSend()
- end), cc.DelayTime:create((allCount-i)*0.08), cc.CallFunc:create(function() node:setCard(node.cid) end ))
- node:runAction(ac)
- else
- ac = cc.Sequence:create(cc.Spawn:create(cc.MoveTo:create(0.1, pt), cc.FadeIn:create(0.1)), cc.CallFunc:create(function ()
- table.insert(self._selfCards, node)
- DdzSoundHelper:playSend()
- end), cc.DelayTime:create((allCount-i)*0.08), cc.CallFunc:create(function() node:setCard(node.cid) end ))
- node:runAction(ac)
- end
- end
-
- -- 发一张牌没有动画
- function DdzRoomView:sendOneCardNoAct( card, i, pos, islast, allCount )
- local node = self:genCard(card,i)--back
- if pos~=1 then
- node = self:genCard(card,i,2)
- else
- node:setScale(DdzRoomViewConfig.CARD_SCALE[pos])--DdzRoomViewConfig.CARD_SCALE_START
- end
- local mode = self:getMode()
- node:setLast(islast)
- local pt = cc.p(0, 0)
- local rowNum = 16
- if pos ~= 1 then
-
- pt = clone(DdzRoomViewConfig.RECORD_INIT_CARD_POS[mode][pos])
- if i>rowNum then
- pt.y = pt.y - 40
- pt.x = pt.x + (i-1)%rowNum*DdzRoomViewConfig.LCARD_DLT_WIDTH
- else
- pt.x = pt.x + (i-1)%rowNum*DdzRoomViewConfig.LCARD_DLT_WIDTH
- end
- else
- local tAllCount = allCount
- if tAllCount > DdzRoomViewConfig.ROW_MAX_CARDS_NUM then
- tAllCount = DdzRoomViewConfig.ROW_MAX_CARDS_NUM
- end
- local midIdx = tAllCount/2
- if i <= DdzRoomViewConfig.ROW_MAX_CARDS_NUM then
- pt.x = DdzRoomViewConfig.HANDCARD_MIDPOS
- if i<=midIdx then--左边
- pt.x = pt.x - (midIdx-i-1)*DdzRoomViewConfig.CARD_DLT_WIDTH*DdzRoomViewConfig.CARD_SCALE[1]
- else--右边
- pt.x = pt.x + (i-midIdx+1)*DdzRoomViewConfig.CARD_DLT_WIDTH*DdzRoomViewConfig.CARD_SCALE[1]
- end
- pt.x = pt.x - DdzRoomViewConfig.CARD_WIDTH/2*DdzRoomViewConfig.CARD_SCALE[1]
- pt.y = DdzRoomViewConfig.RECORD_INIT_CARD_POS[mode][pos].y
- else
- --先算出第一排第一张牌的X位置
- pt.x = DdzRoomViewConfig.HANDCARD_MIDPOS - (midIdx-1-1)*DdzRoomViewConfig.CARD_DLT_WIDTH*DdzRoomViewConfig.CARD_SCALE[1]
- pt.x = pt.x + (i - DdzRoomViewConfig.ROW_MAX_CARDS_NUM-1)*DdzRoomViewConfig.CARD_DLT_WIDTH*DdzRoomViewConfig.CARD_SCALE[1]
- pt.x = pt.x - DdzRoomViewConfig.CARD_WIDTH/2*DdzRoomViewConfig.CARD_SCALE[1]
- pt.y = DdzRoomViewConfig.RECORD_INIT_CARD_POS[mode][pos].y - DdzRoomViewConfig.ROW_SPACING
- end
- --node:setLocalZOrder(i)
- end
- node:setPosition(pt)
- node:setLocalZOrder(i)
- self.cardRoot[pos]:addChild(node)
- if pos == 1 then
- table.insert(self._selfCards, node)
- else
- table.insert(self._otherCards[pos], node)
- end
- end
-
- -- 创建一张牌
- function DdzRoomView:genCard( card,uniqueFlag,ctype)
- local node = DdzCardNode:new(card,uniqueFlag,ctype)
- node:setCard(card)
- node:setSelectedHeight(DdzRoomViewConfig.SELECTED_HEIGHT)
- node:setNormalHeight(DdzRoomViewConfig.NORMAL_HEIGHT)
- return node
- end
-
- -- 从手牌中获取一张牌
- function DdzRoomView:getCardNode( card )
- if card > 0x00 and card <= 0x5d then
- for _,v in pairs(self._selfCards) do
- if v:getVal()==card then
- return v
- end
- end
- return nil
- else
- return nil
- end
- end
-
- -- 根据牌ID移除一张手牌,并重新调整手牌位置
- function DdzRoomView:removeCardNode( card )
- --删牌的时候服务器下发的是癞子混出的实际牌取值0x5X(X值为1-C),但是手上只有0x5d的癞子牌,这里全部转换成癞子来删除
- if card >= 0x50 and card <= 0x5d then
- card = 0x5d
- end
- local node = self:getCardNode(card)
- --if not node or tolua.isnull(node) then return end
- for i=#self._selfCards,1,-1 do
- if self._selfCards[i]:getVal()==card then
- table.remove(self._selfCards, i)
- break
- end
- end
- if tolua.isnull(node) then
- node = nil
- self:removeHandcards(card)
- else
- node:removeFromParent(true)
- end
- end
-
- --直接从手牌中找牌删除
- function DdzRoomView:removeHandcards(card)
- for i,v in pairs(self.cardRoot:getChildren()) do
- if v:getVal() == card then
- v:removeFromParent(true)
- break
- end
- end
- end
-
- --移除牌
- function DdzRoomView:removeOtherCards( viewPos, cards )
- local nodeSet = self._otherCards[viewPos]
- for _,card in ipairs(cards) do
- if card >= 0x50 and card <= 0x5d then
- card = 0x5d
- end
- --[[if card > 0x00 and card <= 0x5d then
- for _,v in pairs(nodeSet) do
- if v:getVal()==card then
- for i=#nodeSet,1,-1 do
- if nodeSet[i]:getVal()==card then
- table.remove(nodeSet, i)
- break
- end
- end
- v:removeFromParent()
- end
- end
- end--]]
- for i=#nodeSet,1,-1 do
- if nodeSet[i]:getVal()==card then
- table.remove(nodeSet, i)
- break
- end
- end
- end
- local tccards = self:getCardsByUi(self._otherCards[viewPos])
- self:recoverHandcardsByPos(tccards,viewPos)
-
- --[[local pos = viewPos
- local mode = self:getMode()
- local otherScale = 0.4
- local rowNum = 16
- for i,v in ipairs(nodeSet) do
- local pt = cc.p(0, 0)
- if pos ~= 1 then
- pt = clone(DdzRoomViewConfig.RECORD_INIT_CARD_POS[mode][pos])
-
- if i>rowNum then
- pt.y = pt.y - 40
- pt.x = pt.x + (i-1)%rowNum*DdzRoomViewConfig.LCARD_DLT_WIDTH
- else
- pt.x = pt.x + (i-1)%rowNum*DdzRoomViewConfig.LCARD_DLT_WIDTH
- end
-
- v:setLocalZOrder(i)
- v:setPosition(pt)
- end
- end--]]
- end
-
- -- 获取当前手牌
- function DdzRoomView:getHandCards()
- local handCards = {}
- for _,v in pairs(self._selfCards) do
- table.insert(handCards, v:getVal())
- end
- return handCards
- end
-
- -- 重置手牌位置
- function DdzRoomView:resetCardsPos( )
- if #self._selfCards<=0 then return end
- local mode = self:getMode()
- local pos = 1
- local scale = DdzRoomViewConfig.CARD_SCALE[pos]
- local dtpx = (16 - #self._selfCards)/2*DdzRoomViewConfig.CARD_DLT_WIDTH*scale
- local allCount = #self._selfCards
- local midIdx = allCount/2
- for i,v in ipairs(self._selfCards) do
- local pt = cc.p(CENTER_X, 0)
- if i<midIdx then--左边
- pt.x = pt.x - (midIdx-i-1)*DdzRoomViewConfig.CARD_DLT_WIDTH*scale
- else--右边
- pt.x = pt.x + (i-midIdx+1)*DdzRoomViewConfig.CARD_DLT_WIDTH*scale
- end
- pt.x = pt.x - DdzRoomViewConfig.CARD_WIDTH/2*scale
- pt.y = DdzRoomViewConfig.RECORD_INIT_CARD_POS[self:getMode()][pos].y
- v:setPosition(pt)
- v:setLast(i==allCount)
- v:setNormal()
- end
- end
-
- -- 提示对应的牌
- function DdzRoomView:tipCards( cards )
- self:resetCardsPos()
- for _,v in pairs(cards) do
- local node = self:getCardNode(v.cid)
- if node and node:getVal()>0 then
- self._selectCards[node:getVal()] = node
- node:setDown()
- end
- end
- end
-
- -- 清除所有牌
- function DdzRoomView:cleanSelfCards()
- for _,v in pairs(self._selfCards) do
- if v:getParent() then v:removeFromParent() end
- end
- self._selfCards = {}
- end
- function DdzRoomView:cleanShowCards()
- for _,v in pairs(self._showCards) do
- for _,vv in pairs(v) do
- if vv and vv:getParent() then
- vv:removeFromParent()
- end
- end
- end
- self._showCards = {{},{},{},{},{}}
- end
-
- -- 二人玩显示另外一组牌
- function DdzRoomView:showOtherCards(is)
- if is then
- self.imgOtherCards:setVisible(true)
- local num = 13
- --if self.ruleType==2 then num = 15 end
- self.txtOtherCards:setString(string.format("剩余%d张", num))
- else
- self.imgOtherCards:setVisible(false)
- end
- end
-
- function DdzRoomView:onEnter()
- DdzRoomView.super.onEnter()
- PokerUtil = require("pk_zgwrddz.luaScript.Views.Room.zgwrDdzPokerUtil"):new({isChai=self.ruleIsChaiBomb, isFAT=self.ruleIsFAT})
- self:bindEvents()
-
- local changeDesk = tonumber(loadUserInfo("wrddz_setting_bg_idx")) or 3
- self:onNormalChangeDesktop({idx=changeDesk-1})
- DdzSoundHelper:playBgMusic()
-
- local roomInfo = self._room:getRoomInfo()
- 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 ))
- -- 默认开始回放
- self:onClickButtonPlay( self.ui.Items.btnPlay, 1 )
- end
-
- function DdzRoomView:onExit()
- if self.Time then
- cc.Director:getInstance():getScheduler():unscheduleScriptEntry(self.Time)
- self.Time = nil
- end
-
- if self._gameResultTimer then
- cc.Director:getInstance():getScheduler():unscheduleScriptEntry(self._gameResultTimer)
- self._gameResultTimer = nil
- end
-
- for _,node in pairs(self._playerNodes) do
- if node then node:setTurn(false) end
- end
- self:stopTurn()
- PokerUtil = nil
-
- stopBGMusic()
- end
-
- --显示地主抓的底牌
- function DdzRoomView:showDiPai(cards)
- if not cards or type(cards) ~= 'table' then return end
- local index = 1
- for i,v in pairs(cards) do
- local cardPng = pokerLPng(v)
- local dipai = string.format("ImageView_dipai_%d",index)
- if self.ui.Items[dipai] then
- self.ui.Items[dipai]:loadTexture(cardPng,1)
- end
- index = index + 1
- end
- end
-
- --显示地主选的暗地主牌
- function DdzRoomView:showAnDiZhuCard(card)
- logD("DdzRoomView:showAnDiZhuCard", card);
- if card == 0x0e then
- self:showZiChi(true)
- else
- self:showZiChi(false)
- local cardPng = pokerLPng(card)
- self.ui.Items.ImageView_andizhupai:loadTexture(cardPng,1)
- end
- end
-
- --显示自吃
- function DdzRoomView:showZiChi(show)
- self.ui.Items.ImageView_zichi:setVisible(show)
- end
-
-
- return DdzRoomView
|