local PdkCardNode = require("pk_hejiangpdk.luaScript.Views.Room.Node.hejiangPdkCardNode") local PdkRoomViewConfig = require("pk_hejiangpdk.luaScript.Views.Room.hejiangPdkRoomViewConfig") local ETS = PdkRoomViewConfig.EffectType local PdkEffectHelper = require("pk_hejiangpdk.luaScript.Views.Room.hejiangPdkEffectHelper"):new() local PdkSoundHelper = require("pk_hejiangpdk.luaScript.Views.Room.hejiangPdkSoundHelper"):new() local PlayerNode = class("PlayerNode", function () return cc.Node:create() end) function PlayerNode:ctor() local ui = loadUI("pk_luzhoupdk/res/ui/ui_room/ui_lzpdk_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.txtCurScore = self.ui.Items.score self.txtCurScore.score = 0 self.imgHost = self.ui.Items.imgHost self.imgTurn = self.ui.Items.ImageView_turn self.imgOfflineTime = self.ui.Items.ImageView_txkYY self.ui.Items.ImageView_alarm:setVisible(false) self.imgTuoGuan = self.ui.Items.ImageView_tuoguan -- self.txtTotalScore = self.ui.Items.totalScore self.ui:setLocalZOrder(10000) self.clockTimer = nil self.nGameInfo = "" 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:setTuoGuan(false) self:setOfflineTime(false) self:hideLeft() if info.viewPos == 2 or (self._PlayMode == 4 and info.viewPos == 3) then --and self.nMaxPlayCount==3 self.imgReady:setPosition(cc.p(-54, 78)) self.imgTurn:setPosition(cc.p(-95, 13))--(cc.p(-55+25, 169-5)) self.ui.Items.ImageView_alarm:setPosition(0, 137) self.ui.Items.imgLeft:setPosition(cc.p(-30, 13)) self.ui.Items.txtLeftNum:setPosition(cc.p(-30, 13)) elseif info.viewPos == 1 then -- local ps = self.imgReady:getPosition() -- local dlt = 1270/2 -- ps.x = dlt -- ps.y = 180 -- self.imgReady:setPosition(ps) local ruleInfo = json.decode(self.nGameInfo or "") or {} if ruleInfo.allowPass and ruleInfo.allowPass > 0 then self.imgTurn:setPosition(cc.p(260, 265)) else self.imgTurn:setPosition(cc.p(360, 265)) end self.imgTurn:setScale(1) end end -- 获取玩家信息 function PlayerNode:getInfo() return self._info end -- 设置最后一组操作牌 function PlayerNode:setLastOp( tp, cards, isContinue ) self._lastOp = {} self._lastOp.tp = tp self._lastOp.cards = cards if tp~=ETS.PASS then self:showLastCards(self._lastOp.cards, self._lastOp.tp, isContinue) 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 = "" --开房参数1:可不要时,0:必须要 if ruleInfo.allowPass and ruleInfo.allowPass == 1 then --可不要时显示不出,必须要时显示要不起 fileName = "pdk_zi_buchu.png" else fileName = "pdk_zi_yaobuqi.png" end local node = cc.ImageView:create() node:loadTexture(fileName, 1) node:setTag(2000) local pos = self._info.viewPos local pt = clone(PdkRoomViewConfig.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) PdkSoundHelper:effectPass( sex, idx ) end -- 显示出牌 function PlayerNode:showLastCards(cards, tp, isContinue) self:cleanLastCards() local root = cc.Node:create() local scale = PdkRoomViewConfig.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) local pt = cc.p(0, 0) if pos == 1 then local midIdx = allCount/2 if i 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:setOfflineTime(is,ptime) self.imgOfflineTime:setVisible(is == true) if is == true and ptime then local ttime = os.date("%M:%S",ptime) self.ui.Items.Text_offLineTime:setText(ttime) --关闭定时器 if self.Time then cc.Director:getInstance():getScheduler():unscheduleScriptEntry(self.Time) self.Time = nil end --当前已离线多长时间 self.curOfftime = ptime self.Time = cc.Director:getInstance():getScheduler():scheduleScriptFunc(function() self.curOfftime = self.curOfftime + 1 if self.curOfftime > 300 then--大于5分钟,恒定显示5分钟 self.curOfftime = 300 end if not tolua.isnull(self.ui.Items.Text_offLineTime) then local time = os.date("%M:%S",self.curOfftime) self.ui.Items.Text_offLineTime:setText(time) else if self.Time then cc.Director:getInstance():getScheduler():unscheduleScriptEntry(self.Time) self.Time = nil end end end,1.0,false) else if self.Time then cc.Director:getInstance():getScheduler():unscheduleScriptEntry(self.Time) self.Time = nil end end end -- 设置是否是房主 function PlayerNode:setHost( is ) --self.imgHost:setVisible(is==true) self.imgHost:setVisible(false)--隐藏房主标签 end -- 设置是否是庄家 function PlayerNode:setBanker( is ) self.imgBanker:setVisible(is==true) end -- 设置是否准备 function PlayerNode:setReady( is ) self.imgReady: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 PdkSoundHelper: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 ) local node = PdkCardNode:new() node:setCard(card) node:setSelectedHeight(PdkRoomViewConfig.SELECTED_HEIGHT) node:setNormalHeight(PdkRoomViewConfig.NORMAL_HEIGHT) 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(PdkRoomViewConfig.PASS_SHOW_POS[self._PlayMode][pos]) if effectType == ETS.PASS then local cb = function () self:setTurn(false) end node = PdkEffectHelper:getPass(cb) local idx = math.random(4) PdkSoundHelper: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 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 if effectType == ETS.PASS then local cb = function () self:setTurn(false) end node = PdkEffectHelper:getPass(cb) local idx = math.random(4) PdkSoundHelper:effectPass( sex, idx ) elseif effectType == ETS.SINGLE_CARD then local _, val = pokerParse(cards[1]) PdkSoundHelper:effectSingle( sex ,val ) elseif effectType == ETS.DUI_ZI then local _, val = pokerParse(cards[1]) if isContinue and rate >= stdRate and PdkSoundHelper:getLanguageType() == 1 then PdkSoundHelper:daNi( sex ) else PdkSoundHelper:effectDouble( sex, val ) end elseif effectType == ETS.SHUN_ZI then node = PdkEffectHelper:getShunzi() -- if viewPos==1 and node then -- node:setScale(1.2) -- end if isContinue and rate>=stdRate and PdkSoundHelper:getLanguageType() == 1 then PdkSoundHelper:daNi( sex ) else PdkSoundHelper:effectShunzi( sex ) end elseif effectType == ETS.LIAN_DUI then node = PdkEffectHelper:getLiandui() if isContinue and rate>=stdRate and PdkSoundHelper:getLanguageType() == 1 then PdkSoundHelper:daNi( sex ) else PdkSoundHelper:effectLiandui( sex ) end elseif effectType == ETS.THREE_AND_TWO or effectType == ETS.THREE_AND_DUI then --根据牌获取是否是三带一或三个 local tp = PokerUtil:checkType(cards) node = PdkEffectHelper:getSandaier() if tp == ETS.THREE_AND_ONE then node = nil node = PdkEffectHelper:getSandaiyi() PdkSoundHelper:effect3And1( sex ) elseif isContinue and rate>=stdRate and PdkSoundHelper:getLanguageType() == 1 then PdkSoundHelper:daNi( sex ) else PdkSoundHelper:effect3And2( sex,effectType ) end elseif effectType == ETS.THREE then local _, val = pokerParse(cards[1]) PdkSoundHelper:effectThree( sex, val ) elseif effectType == ETS.THREE_AND_DUI then if isContinue and rate>=stdRate and PdkSoundHelper:getLanguageType() == 1 then PdkSoundHelper:daNi( sex ) else PdkSoundHelper:effect3And2( sex ,effectType) end elseif effectType == ETS.BOMB then node = PdkEffectHelper:getBomb() pt.y = pt.y + 100 PdkSoundHelper:effectBomb( sex ) elseif effectType == ETS.AIRPLANE or effectType == ETS.AIRPLANE_TOW or effectType == ETS.AIRPLANE_DUI then node = PdkEffectHelper:getPlan() PdkSoundHelper:effectPlane( sex ) --[[ elseif effectType == ETS.SPRING_HUA then node = PdkEffectHelper:getSpring()--]] end if node then if effectType == ETS.SHUN_ZI then pt.x = pt.x - (dltWidth/2+100) end node:setPosition(pt) node:setLocalZOrder(1000) root:addChild(node) if node.onEnter and type(node.onEnter)=='function' then node:onEnter() end end end -- 设置是否是房主 function PlayerNode:setTuoGuan( is ) if not tolua.isnull(self.imgTuoGuan) then self.imgTuoGuan:setVisible(is==true) end end return PlayerNode