local DdzCardNode = require("pk_zgwrddz.luaScript.Views.Room.Node.zgwrDdzCardNode") local DdzRoomViewConfig = require("pk_zgwrddz.luaScript.Views.Room.zgwrDdzRoomViewConfig") local ETS = DdzRoomViewConfig.EffectType local DdzEffectHelper = require("pk_zgwrddz.luaScript.Views.Room.zgwrDdzEffectHelper"):new() local DdzSoundHelper = require("pk_zgwrddz.luaScript.Views.Room.zgwrDdzSoundHelper"):new() local PlayerNode = class("PlayerNode", function () return cc.Node:create() end) function PlayerNode:ctor() local ui = loadUI("pk_zgwrddz/res/ui/ui_room/ui_wrddz_playernode.ui") self.ui = ui self:addChild(ui) self.txtNickname = self.ui.Items.name self.imgHead = self.ui.Items.headImg self.imgBanker = self.ui.Items.banker self.imgOffline = self.ui.Items.offLine self.imgReady = self.ui.Items.readyState self.mult = self.ui.Items.multState self.fanMult = self.ui.Items.fanMultState self.txtCurScore = self.ui.Items.score self.txtCurScore.score = 0 self.imgHost = self.ui.Items.imgHost self.imgAndizhu = self.ui.Items.imgAndizhu self.imgTurn = self.ui.Items.ImageView_turn self.ui.Items.ImageView_alarm:setVisible(false) -- self.txtTotalScore = self.ui.Items.totalScore self.ui:setLocalZOrder(10000) self.clockTimer = nil self.nGameInfo = "" self.imgTuoGuan = self.ui.Items.ImageView_tuoguan end function PlayerNode:setGameInfo(str) self.nGameInfo = str end function PlayerNode:setPlayMode( mode ) self._PlayMode = mode end -- 房间最大玩家数 function PlayerNode:setMaxPlayerCount( count ) self.nMaxPlayCount = count end -- 是否显示牌张数 function PlayerNode:setShowNum( is ) --暂时改为默认显示剩余牌张数 self.ruleIsShowNum = true end -- 设置玩家信息 function PlayerNode:setInfo( info ) self._info = info local nickname = info.nickname or "" self.txtNickname:setString(getSubStringNickname(nickname)) setPlayerHeadImage(info.userId, info.headimgurl, self.imgHead) -- self:setScore(0) self:setOffline(false) self:setBanker(false) self:setReady(false) self:setHost(false) self:setTurn(false) self.isAnDiZhu = false self:setAnDiZhu(false) self:setMult(false) self:setFanMult(false) self:hideLeft() self:setTuoGuan(false) if info.viewPos == 2 or info.viewPos == 3 then --and self.nMaxPlayCount==3 self.imgReady:setPosition(cc.p(-54, 78)) --self.mult:setPosition(cc.p(-26, 52)) self.imgTurn:setPosition(cc.p(-95, 13))--(cc.p(-55+25, 169-5)) self.ui.Items.ImageView_alarm:setPosition(-26, 96) self.ui.Items.imgLeft:setPosition(cc.p(-26, 13)) self.ui.Items.txtLeftNum:setPosition(cc.p(-26, 13)) elseif info.viewPos == 1 then self.imgTurn:setPosition(cc.p((623-26)*g_radio_x, 340*g_radio_y))--(cc.p(45, 180)) self.imgTurn:setScale(1) end end -- 获取玩家信息 function PlayerNode:getInfo() return self._info end -- 设置最后一组操作牌 function PlayerNode:setLastOp( tp, cards, isContinue,isShowDzFlag ) self._lastOp = {} self._lastOp.tp = tp self._lastOp.cards = cards if tp~=ETS.PASS then self:showLastCards(self._lastOp.cards, self._lastOp.tp, isContinue,isShowDzFlag) else self:showPass() end end function PlayerNode:isShowPass() if self._lastOp then return self._lastOp.tp==ETS.PASS end return false end -- 显示牌背 function PlayerNode:showCardbg(is) end -- 显示Pass function PlayerNode:showPass() self:cleanLastCards() local ruleInfo = json.decode(self.nGameInfo) local fileName = "pk_zgwrddz/res/ui/zy_wrddz_btns/wrddz_lab_buyao.png" local node = cc.ImageView:create() node:loadTexture(fileName, 0) node:setTag(2000) local pos = self._info.viewPos local pt = clone(DdzRoomViewConfig.PASS_SHOW_POS[self._PlayMode][pos]) node:setPosition(pt) node:setLocalZOrder(1000) node:setScale(0) self:addChild(node) node:runAction(cc.ScaleTo:create(0.1, 1)) local pInfo = self:getInfo() local sex = pInfo.sex local idx = math.random(4) DdzSoundHelper:effectPass( sex, idx ) end -- 显示出牌 function PlayerNode:showLastCards(cards, tp, isContinue,dzFlag) self:cleanLastCards() local root = cc.Node:create() local scale = DdzRoomViewConfig.CARD_SCALE[2] local allCount = #cards local pos = self._info.viewPos local firstPos = cc.p(0, 0) for i,card in ipairs(cards) do local node = self:genCard(card,dzFlag) local pt = cc.p(0, 0) if pos == 1 then local midIdx = allCount/2 if irowNum then pt.y = pt.y - 50 if i > 2*rowNum then pt.y = pt.y - 50 end if pos == 2 or pos == 3 then pt.x = pt.x - (i-1)%rowNum*DdzRoomViewConfig.CARD_DLT_WIDTH*scale pt.x = pt.x + DdzRoomViewConfig.OUT_CARD_POS[self._PlayMode][pos].x if i > 2*rowNum then node:setLocalZOrder(56-i) else node:setLocalZOrder(36-i) end else pt.x = pt.x + (i-1)%rowNum*DdzRoomViewConfig.CARD_DLT_WIDTH*scale pt.x = pt.x + DdzRoomViewConfig.OUT_CARD_POS[self._PlayMode][pos].x - self.imgHead:getContentSize().width - 10 end if i==1 then firstPos = pt end else if pos == 2 or pos == 3 then pt.x = pt.x - (i-1)%rowNum*DdzRoomViewConfig.CARD_DLT_WIDTH*scale pt.x = pt.x + DdzRoomViewConfig.OUT_CARD_POS[self._PlayMode][pos].x node:setLocalZOrder(16-i) else pt.x = pt.x + (i-1)%rowNum*DdzRoomViewConfig.CARD_DLT_WIDTH*scale pt.x = pt.x + DdzRoomViewConfig.OUT_CARD_POS[self._PlayMode][pos].x - self.imgHead:getContentSize().width - 10 end if i==1 then firstPos = pt end end --[[if pos == 2 or pos == 3 then --self._PlayMode == 1 and node:setLocalZOrder(16-i) pt.x = pt.x - (i-1)*DdzRoomViewConfig.CARD_DLT_WIDTH*scale pt.x = pt.x + DdzRoomViewConfig.OUT_CARD_POS[self._PlayMode][pos].x else pt.x = pt.x + (i-1)*DdzRoomViewConfig.CARD_DLT_WIDTH*scale pt.x = pt.x + DdzRoomViewConfig.OUT_CARD_POS[self._PlayMode][pos].x - self.imgHead:getContentSize().width - 10 end--]] end if (dzFlag and dzFlag == 1) or self.isAnDiZhu then if pos == 2 or pos == 3 then if i == 1 then node:setLordFlagVisible(true) end else if i == #cards then node:setLordFlagVisible(true) end end end node:setScale(scale) node:setPosition(pt) root:addChild(node) end root:setTag(1001) self:addChild(root) local dltWidth = ((#cards-1)*DdzRoomViewConfig.CARD_DLT_WIDTH + DdzRoomViewConfig.CARD_WIDTH) * DdzRoomViewConfig.CARD_SCALE[2] local pt = cc.p(firstPos.x,firstPos.y-30) if pos==2 or pos == 3 then pt.x = pt.x - dltWidth/2 + DdzRoomViewConfig.CARD_WIDTH * DdzRoomViewConfig.CARD_SCALE[2]/2 else pt.x = pt.x + dltWidth/2 - DdzRoomViewConfig.CARD_WIDTH * DdzRoomViewConfig.CARD_SCALE[2]/2 end self:showEffect(root, cards, tp, pt, isContinue, dltWidth ) end -- 清除出牌 function PlayerNode:cleanLastCards() do local node = self:getChildByTag(1001) if node then node:removeFromParent() end end self:cleanPass() end function PlayerNode:cleanPass() do local node = self:getChildByTag(2000) if node then node:removeFromParent() end end end -- 显示剩余牌数量 function PlayerNode:showLeft( num ) self.ui.Items.ImageView_alarm:setVisible(num <= 2 and num > 0) if num <= 2 and num > 0 then--报单 self.ui.Items.imgLeft:setVisible(true) self.ui.Items.txtLeftNum:setVisible(true) self.ui.Items.txtLeftNum:setString(string.format("%d", num or 0)) self.ui.Items.imgLeft:loadTexture("pk_zgwrddz/res/ui/zy_room/wrddz_img_warn.png", 0) self.ui.Items.ImageView_alarm:stopAllActions() self:playBaoJingAnim() --self.ui.Items.ImageView_alarm:setRotation(0) --local ac = cc.Sequence:create(cc.RotateBy:create(0.1, 30/180), cc.RotateBy:create(0.2, -60/180), cc.RotateBy:create(0.1, 30/180)) --self.ui.Items.ImageView_alarm:runAction(cc.RepeatForever:create(cc.Sequence:create(ac, ac:clone(), cc.DelayTime:create(1)))) else self.ui.Items.imgLeft:setVisible(true) self.ui.Items.txtLeftNum:setVisible(true) self.ui.Items.imgLeft:loadTexture("pk_zgwrddz/res/ui/zy_room/wrddz_img_leftbg.png", 0) end if not self.ruleIsShowNum then self.ui.Items.imgLeft:setVisible(false) self.ui.Items.txtLeftNum:setVisible(false) else local show = true if self._info.viewPos == 1 then show = false end self.ui.Items.imgLeft:setVisible(show) self.ui.Items.txtLeftNum:setVisible(show) self.ui.Items.txtLeftNum:setString(string.format("%d", num or 0)) end end function PlayerNode:playBaoJingAnim() -- 循环修改图片 local nodeImage = self.ui.Items.ImageView_alarm local everyFrame = 0.1 local indexFace = 0 local indexMax = 17 local action1 = cc.Sequence:create(cc.DelayTime:create(everyFrame),cc.CallFunc:create(function () indexFace = indexFace + 1 if 0 < indexFace and indexFace <= indexMax then else indexFace = 1 end local name = string.format("ddz_effect_baojing_%d.png",indexFace) if not tolua.isnull(nodeImage) then nodeImage:loadTexture(name, cc.TextureResType.plistType) end end)) local action2 = cc.Repeat:create(action1, indexMax) nodeImage:stopAllActions() nodeImage:runAction(cc.RepeatForever:create(action2)); nodeImage:setVisible(true) end -- 是否报单 function PlayerNode:isAlarm() return self.ui.Items.ImageView_alarm:isVisible() end -- 隐藏剩余拍数量 function PlayerNode:hideLeft() self.ui.Items.imgLeft:setVisible(false) self.ui.Items.txtLeftNum:setVisible(false) self.ui.Items.ImageView_alarm:setVisible(false) end -- 设置分数 remove飘的分数是否移除 function PlayerNode:setScore( scol, remove ,turnScore) turnScore = tonumber(turnScore) if remove == nil then remove = true end local dlt = (scol - self.txtCurScore.score) local curScol = tonumber(self.txtCurScore:getString()) if curScol and curScol ~= self.txtCurScore.score then logD("PlayerNode:setScore ================curScol = "..curScol) dlt = scol - curScol --uploadLogs("lzpdkfenshucuowu") end logD("PlayerNode:setScore ================scol = "..scol.."self.txtCurScore.score = "..self.txtCurScore.score) if turnScore then logD("PlayerNode:setScore ================turnScore = "..turnScore) dlt = turnScore end if math.abs(dlt) > 0 then local txt = cc.TextBMFont:createNode() if dlt > 0 then txt:setFntFile("res/fonts/dt_jia_num.fnt") txt:setString(string.format("+%0.1f", dlt)) else txt:setFntFile("res/fonts/dt_jian_num.fnt") txt:setString(string.format("%0.1f", dlt)) end txt:setScale(0.7) txt:setTag(166) txt:setLocalZOrder(10001) self:addChild(txt) local ac = cc.Sequence:create(cc.Spawn:create(cc.MoveBy:create(1, cc.p(0, 100))), cc.CallFunc:create(function () self.txtCurScore:setString(string.format("%0.1f", scol or 0)) self.txtCurScore.score = scol if remove then txt:removeFromParent() end end)) txt:runAction(ac) else self.txtCurScore:setString(string.format("%0.1f", scol or 0)) self.txtCurScore.score = scol end end function PlayerNode:setScoreNoAnim( scol) self.txtCurScore:setString(string.format("%0.1f", scol or 0)) self.txtCurScore.score = scol end -- 移除飘的分数 function PlayerNode:cleanScore() local node = self:getChildByTag(166) if node then node:removeFromParent() end end -- 设置总分数 function PlayerNode:setTotalScore( scol ) -- self.txtTotalScore:setString(string.format("%d", scol or 0)) end -- 设置是否离线 function PlayerNode:setOffline( is ) self.imgOffline:setVisible(is==true) end -- 设置是否是地主 function PlayerNode:setHost( is ) self.imgHost:setVisible(is==true) --self.imgHost:setVisible(false)--这不是房主,是地主 end -- 是否是地主 function PlayerNode:isHost() return self.imgHost:isVisible() end -- 设置是否是暗地主 function PlayerNode:setAnDiZhu( is ) self.isAnDiZhu = is self.imgAndizhu:setVisible(is==true) end -- 设置是否是庄家 function PlayerNode:setBanker( is ) self.imgBanker:setVisible(is==true) end -- 设置是否准备 function PlayerNode:setReady( is ) self.imgReady:setVisible(is==true) end -- 设置是否显示加倍 function PlayerNode:setMult( is ) self.mult:setVisible(is==true) end -- 设置是否显示反加倍 function PlayerNode:setFanMult( is ) self.fanMult:setVisible(is==true) end -- 设置轮次时钟 function PlayerNode:setTurn( is, time ) if is then if self.clockTimer then cc.Director:getInstance():getScheduler():unscheduleScriptEntry(self.clockTimer) self.clockTimer = nil end self.imgTurn:setVisible(true) if self.clockTimer==nil then self.ui.Items.txtLimitTime.time = time or 10 self.ui.Items.txtLimitTime:setString(string.format("%d", self.ui.Items.txtLimitTime.time)) self.clockTimer = cc.Director:getInstance():getScheduler():scheduleScriptFunc(function() if self.ui.Items.txtLimitTime.time > 0 then self.ui.Items.txtLimitTime.time = self.ui.Items.txtLimitTime.time - 1 if self.ui.Items.txtLimitTime.time<=5 and self._info.viewPos==1 then DdzSoundHelper:alarm() end else if self.clockTimer then cc.Director:getInstance():getScheduler():unscheduleScriptEntry(self.clockTimer) self.clockTimer = nil end end self.ui.Items.txtLimitTime:setString(string.format("%d", self.ui.Items.txtLimitTime.time)) end,1.0,false) end else if self.clockTimer then self.ui.Items.txtLimitTime.time = self.ui.Items.txtLimitTime.time - 1 self.ui.Items.txtLimitTime:setString(string.format("%d", self.ui.Items.txtLimitTime.time)) cc.Director:getInstance():getScheduler():unscheduleScriptEntry(self.clockTimer) self.clockTimer = nil end self.imgTurn:setVisible(false) end end -- 创建一张牌 function PlayerNode:genCard( card ,dzFlag) local node = DdzCardNode:new() node:setCard(card) node:setSelectedHeight(DdzRoomViewConfig.SELECTED_HEIGHT) node:setNormalHeight(DdzRoomViewConfig.NORMAL_HEIGHT) local roomInfo = app.room:getRoomInfo() if card == roomInfo.nDarkLordCard and (not self:isHost()) then --给暗地主牌加光圈 node:setGuangQuan() end return node end function PlayerNode:showEffectExt( effectType ) local function __show() local node = nil local pInfo = self:getInfo() local sex = pInfo.sex local pos = self._info.viewPos local pt = clone(DdzRoomViewConfig.PASS_SHOW_POS[self._PlayMode][pos]) if effectType == ETS.PASS then local cb = function () self:setTurn(false) end node = DdzEffectHelper:getPass(cb) local idx = math.random(4) DdzSoundHelper:effectPass( sex, idx ) end if node then node:setPosition(pt) node:setLocalZOrder(1000) self:addChild(node) if node.onEnter and type(node.onEnter)=='function' then node:onEnter() end end end self.ui:runAction(cc.Sequence:create(cc.DelayTime:create(1), cc.CallFunc:create(__show))) end -- 显示牌型 function PlayerNode:showEffect(root, cards, effectType, pt, isContinue, dltWidth ) local roomInfo = app.room:getRoomInfo() if roomInfo.gameStatus == DdzRoomViewConfig.GameStatus.GAME_STATE_ROUND_OVER then return end local rate = math.random(100) local stdRate = 70 isContinue = isContinue or false local viewPos = self._info.viewPos local pInfo = self:getInfo() local sex = pInfo.sex local node = nil local isKingBomb = false if effectType == ETS.PASS then local cb = function () self:setTurn(false) 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 --根据牌获取是否是三带一或三个 local tp = PokerUtil:checkType(cards) 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 pt.y = pt.y + 100 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 if effectType == ETS.SHUN_ZI then pt.x = pt.x - (dltWidth/2+100) end node:setPosition(pt) node:setLocalZOrder(1000) if isKingBomb then node:setPosition(640*g_radio_x,520*g_radio_y) app.mainScene:addChild(node) else local pos = root:getWorldPosition() pos.x = pos.x + pt.x pos.y = pos.y + pt.y node:setPosition(pos) app.mainScene:addChild(node) --root:addChild(node) end if node.onEnter and type(node.onEnter)=='function' then node:onEnter() end end end -- 显示叫地主或不叫 function PlayerNode:showJiaoDiZhu(isJiao) local fileName = "" if isJiao then fileName = "pk_zgwrddz/res/ui/zy_wrddz_btns/wrddz_lab_jiaodizhu.png" else fileName = "pk_zgwrddz/res/ui/zy_wrddz_btns/wrddz_lab_bujiao.png" end local node = cc.ImageView:create() node:loadTexture(fileName) node:setTag(2000) local pos = self._info.viewPos local pt = clone(DdzRoomViewConfig.PASS_SHOW_POS[self._PlayMode][pos]) node:setPosition(pt) node:setLocalZOrder(1000) node:setScale(0) self:addChild(node) node:runAction(cc.ScaleTo:create(0.1, 1)) local pInfo = self:getInfo() local sex = pInfo.sex DdzSoundHelper:effectJiaoDiZhu( sex, isJiao ) end -- 显示加倍或不加倍 function PlayerNode:showJiaBei(isJiaBei) local fileName = "" if isJiaBei then fileName = "pk_zgwrddz/res/ui/zy_wrddz_btns/wrddz_lab_jiabei.png" else fileName = "pk_zgwrddz/res/ui/zy_wrddz_btns/wrddz_lab_bujiabei.png" end local node = cc.ImageView:create() node:loadTexture(fileName) node:setTag(2000) local pos = self._info.viewPos local pt = clone(DdzRoomViewConfig.PASS_SHOW_POS[self._PlayMode][pos]) node:setPosition(pt) node:setLocalZOrder(1000) node:setScale(0) self:addChild(node) node:runAction(cc.ScaleTo:create(0.1, 1)) local pInfo = self:getInfo() local sex = pInfo.sex DdzSoundHelper:effectJiaBei( sex, isJiaBei ) end -- 显示反加倍或不反 function PlayerNode:showFanJiaBei(isJiaBei) local fileName = "" if isJiaBei then fileName = "pk_zgwrddz/res/ui/zy_wrddz_btns/wrddz_lab_fanjiabei.png" else fileName = "pk_zgwrddz/res/ui/zy_wrddz_btns/wrddz_lab_bufan.png" end local node = cc.ImageView:create() node:loadTexture(fileName) node:setTag(2000) local pos = self._info.viewPos local pt = clone(DdzRoomViewConfig.PASS_SHOW_POS[self._PlayMode][pos]) node:setPosition(pt) node:setLocalZOrder(1000) node:setScale(0) self:addChild(node) node:runAction(cc.ScaleTo:create(0.1, 1)) local pInfo = self:getInfo() local sex = pInfo.sex DdzSoundHelper:effectJiaBei( sex, isJiaBei ) end -- 设置是否是托管 function PlayerNode:setTuoGuan( is ) self.imgTuoGuan:setVisible(is==true) end return PlayerNode