-- 斗地主主界面 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 RoomGpsComponent = require("luaScript.Views.Room.RoomGpsComponent") require("luaScript.Views.Room.RoomFunctions") local DdzMessage = require("pk_zgwrddz.luaScript.Protocol.zgwrDdzMessage") local DdzFunctions = require("pk_zgwrddz.luaScript.zgwrDdzFunctions") local WRDDZDefine=require("luaScript.SubGameDefine.zgwrDdzDefine") local zgwrDdzPokerUtil2 = require("pk_zgwrddz.luaScript.Views.Room.zgwrDdzPokerUtil2") local CENTER_X=640*g_radio_x local CENTER_Y=360*g_radio_y local zgwrDdzRoomView = class("zgwrDdzRoomView", cc.UIView) local STATUS_INFO = { [7] = "等待其他玩家加倍...", [8] = "请在点数6-K中选择一张牌作为暗地主暗号牌", [0] = "等待地主选择暗地主...", } function zgwrDdzRoomView:ctor(params) zgwrDdzRoomView.super.ctor(self) -- 玩家节点 self._playerNodes = {} -- 自己手牌集合 self._selfCards = {} -- 玩家出牌集合 self._showCards = {{},{},{},{},{}} -- 点击选择的牌 self._selectCards = {} -- 上一次出牌viewPos self._lastOutPos = 0 -- 上一次出牌类型 self._lastOutType = 0 -- 上一次出牌类型,只记录服务器下发的类型 app.room.lastOutType = 0 -- 上一次出牌,用于提示 self._lastCards = {} -- 排序轮次用 self._turnsQueue = {} -- 快速开始界面 self.fastStartRequestView = nil --是否是小局结算 self._gameResult = false --是否是地主 self._isLorder = false --是否是暗地主 self._isDarkLorder = false --压牌第一次弹提示 self.firstTip = false end function zgwrDdzRoomView:loadUI() self.ui = loadUI("pk_zgwrddz/res/ui/ui_room/ui_wrddz_gameview.ui") self:addChild(self.ui) end function zgwrDdzRoomView:loadTextureCache() 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") --loadSpriteFrameFile("pk_zgwrddz/res/ui/zy_game/lzroom_add.plist") end --[[ GAME_STATE_INIT =0, --//游戏准备状态 GAME_STATE_SEND_HAND_CARD =1, --//发牌 GAME_STATE_OUT_CARD =2, --//打牌 GAME_STATE_ROUND_OVER =3, --//游戏一局结束 GAME_STATE_GAME_OVER =4, --//游戏结束 ]] function zgwrDdzRoomView:onEnter() zgwrDdzRoomView.super.onEnter() self:loadUI(); self.panelMenu = self.ui.Items.Layout_Menu self.cardRoot = self.ui.Items.cardRoot self.imgOtherCards = self.ui.Items.ImageView_other self.txtOtherCards = self.ui.Items.Text_otherNum self:initChatView() self:loadTextureCache(); self:showOtherCards(false) self:initViews() self:showMenu(false) self:showTurnBtn(false) self:showZiChi(false) self:setRoomInfo(app.room:getRoomInfo()) -- self.functionQueue = require("luaScript.Tools.FunctionQueue"):new() self:initPlayGameAgain(); local roomInfo = app.room:getRoomInfo() if roomInfo.nGameStartCount and roomInfo.nGameStartCount > 0 then setShowCountAll(true) end PokerUtil = require("pk_zgwrddz.luaScript.Views.Room.zgwrDdzPokerUtil"):new({isChai=self.ruleIsChaiBomb, isFAT=self.ruleIsFAT}) self:bindEvents() self:addTouchesListener() local roomInfo = app.room:getRoomInfo() if roomInfo.recoverItem then local recoverData = roomInfo.recoverItem --self:recover(recoverData) self:onGameReconnection() else --self:checkGpsDistance(nil,roomInfo.nGameStartCount==0) end -- GPS组件 self:initGpsComponent() local changeDesk = tonumber(loadUserInfo("wrddz_setting_bg_idx")) or 3 self:onNormalChangeDesktop({idx=changeDesk}) local cacheMusic = "gameBgMusic"..app.gameId local defaultMusic = tonumber(loadUserInfo(cacheMusic)) or 2 DdzSoundHelper:playBgMusic(defaultMusic) --定时器 local roomInfo = app.room:getRoomInfo() if self.ui.Items.systemTime then self.ui.Items.systemTime:setText(string.format("%s", os.date("%y-%m-%d %H:%M:%S", os.time()) ) ) end if not self.Time then self.Time = cc.Director:getInstance():getScheduler():scheduleScriptFunc(function() local roomInfo = app.room:getRoomInfo() self.ui.Items.systemTime:setText(string.format("%s", os.date("%y-%m-%d %H:%M:%S", os.time()) ) ) end,1.0,false) end if app.room.isReconnection == true then --断线重连 --self:isShowFastStartView() end self:doSound() -- if self.chatView and DdzFunctions.isForbidProp() then -- self.chatView:hideBtns() -- end -- todo if self.chatView and DdzFunctions.isForbidProp() then self.chatView:hideFace() end if self.chatView and DdzFunctions.isForbidVoice() then self.chatView:hideVoice() end self:checkCanDismiss() end function zgwrDdzRoomView:doSound()--1 普通话 2 方言 local cacheLan = "LanguageType"..GAME_IDS.zgWuRenDouDiZhu local languageType = tonumber(loadUserInfo(cacheLan)) or 2 saveUserInfo(cacheLan,languageType) end function zgwrDdzRoomView:onExit() self.fastStartRequestView = nil setShowCountAll(false) if self.Time then cc.Director:getInstance():getScheduler():unscheduleScriptEntry(self.Time) self.Time = nil end for _,node in pairs(self._playerNodes) do if node then node:setTurn(false) end end PokerUtil = nil app.room:cleanCache() stopBGMusic() self:cleanCache(); end function zgwrDdzRoomView:addFunction( func ) if self.functionQueue then self.functionQueue:addFunction(func) else func() end end function zgwrDdzRoomView:initChatView() local children = self.panelMenu:getParent():getChildByTag(99) if children then children:removeFromParent() end local messageList = DdzDef.ChatMessages local headInfos = {} headInfos[1] = {headPos = cc.p((62+25)*g_radio_x, (84+20)*g_radio_y), voiceDir = 2} headInfos[2] = {headPos = cc.p((1224-25)*g_radio_x, (366+20)*g_radio_y), voiceDir = 1} headInfos[3] = {headPos = cc.p((1224-25)*g_radio_x, (561+20)*g_radio_y), voiceDir = 1} headInfos[4] = {headPos = cc.p((62+25)*g_radio_x, (561+20)*g_radio_y), voiceDir = 2} headInfos[5] = {headPos = cc.p((62+25)*g_radio_x, (366+20)*g_radio_y), voiceDir = 2} local showBtn = true; self.chatView = import("luaScript.Views.Room.ChatView"):new(messageList, headInfos, showBtn) --self.chatView:setLanguage(false) self.chatView:setLocalZOrder(99) self.chatView:setTag(99) self.chatView:setBtnFace(cc.p(0.9411563, 0.3730273), "room_menu3_room_btn_kjy.png") self.chatView:setBtnVoice(cc.p(0.9411563, 0.2163281), "room_menu3_room_btn_yuyin.png") self.chatView.ui.Items.Button_Face:setPositionPercent(cc.p(0.9411563,0.2630273)) self.chatView.ui.Items.Button_Voice:setPositionPercent(cc.p(0.9411563,0.1300273)) self.panelMenu:getParent():addChild(self.chatView) -- if DdzFunctions.isForbidProp() and self.chatView then -- self.chatView:hideBtns() -- self.chatView:setPropEnabled(false) -- self.chatView:setVoiceEnabled(false) -- end -- todo if self.chatView and DdzFunctions.isForbidProp() then self.chatView:hideFace() self.chatView:setPropEnabled(false) end if self.chatView and DdzFunctions.isForbidVoice() then self.chatView:hideVoice() self.chatView:setVoiceEnabled(false) end end function zgwrDdzRoomView:resetRoundData( ) -- 上一次出牌viewPos self._lastOutPos = 0 -- 上一次出牌类型 self._lastOutType = 0 self._lastCards = {} self.lastOutFlag = -1 --是否是地主 self._isLorder = false --是否是暗地主 self._isDarkLorder = false -- self:showTurnBtn(false) self:cleanSelfCards() self:cleanShowCards() self:resetTopCardStatus() self:showOtherCards(false) -- 清空玩家时钟 for _,v in pairs(self._playerNodes) do v:setTurn(false) v:setHost(false) v:setAnDiZhu(false) v:setMult(false) v:setFanMult(false) end self._resultMsg = nil self:showRstComfirm(false) if self.xiaojuView and (not tolua.isnull(self.xiaojuView)) then self.xiaojuView:removeFromParent() self.xiaojuView = nil end self._gameResult = false; app.room.roomInfo.nDarkLordCard = nil; end function zgwrDdzRoomView:getMode() return app.room:getRoomInfo().nMaxPlayCount or 5 end function zgwrDdzRoomView:initViews() self.ui.Items.btnMenu:registerClick(handler(self , self.onClickButtonMenu)) self.ui.Items.Layout_Leave:registerClick(handler(self , self.onClickButtonLeave)) self.ui.Items.Layout_Dismiss:registerClick(handler(self , self.onClickButtonDismiss)) self.ui.Items.Layout_Set:registerClick(handler(self , self.onClickButtonSetting)) self.ui.Items.Button_Ready:registerClick(handler(self , self.onClickButtonReady)) self.ui.Items.Button_Ready.oPos = self.ui.Items.Button_Ready:getPosition() self.ui.Items.Button_invite:registerClick(handler(self , self.onClickButtonInvite)) self.ui.Items.Button_invite.oPos = self.ui.Items.Button_invite:getPosition() self.ui.Items.Layout_7:registerClick(handler(self , self.onClickMenuOut)) self.ui.Items.Button_rule:registerClick(handler(self, self.onClickButtonDetails)) --self.ui.Items.Button_Copy:registerClick(handler(self, self.onClickCopy)) self.ui.Items.Layout_Menu_1:setTouchEnabled(true) self.ui.Items.Button_tip:registerClick(handler(self , self.onClickButtonTip)) self.ui.Items.Button_out:registerClick(handler(self , self.onClickButtonOut)) self.ui.Items.Button_not_out:registerClick(handler(self , self.onClickButtonNotOut)) --邀请俱乐部成员 self.ui.Items.Button_Invite_Club:registerClick(handler(self , self.onClickInviteClub)) -- self.ui.Items.btnShot:registerClick(handler(self , self.onClickButtonShot)) -- 小局结算展示按钮 self._btnComfirm = self.ui.Items.Button_RstComfirm self._btnComfirm:registerClick(handler(self , self.onClickButtonRstComfirm)) self:showRstComfirm(false) self.ui.Items.imgTip:setVisible(false) self.ui.Items.imgTip:setOpacity(0) self.ui.Items.imgTip:setLocalZOrder(200) --状态提示 self.ui.Items.Layout_tips:setVisible(false) self.ui.Items.btnShowClub:registerClick(handler(self , self.onClickButtonShowClub)) if app.club_php.clubID and app.club_php.clubID~=0 then self.ui.Items.btnShowClub:setVisible(true) self.ui.Items.Button_Invite_Club:setVisible(true) else self.ui.Items.btnShowClub:setVisible(false) self.ui.Items.Button_Invite_Club:setVisible(false) end local roomInfo = app.room:getRoomInfo() --快速开始按钮 self.ui.Items.Button_fastStart:registerClick(handler(self, self.onClickFastStart)) if roomInfo.nGameStartCount and roomInfo.nGameStartCount <= 0 then --游戏未开始 self:showFastStart(true) self:showJiPaiQi(false) else self:showFastStart(false) --self:showJiPaiQi(true) end --添加玩家节点 local players = app.room:getPlayers() for _, info in pairs(players) do self:addPlayerNode( info ) end -- local myself = app.room:getMyself() if myself.playFlag>=1 then self:showSitdownBtn(false) else self:showSitdownBtn(true) end --self.gpsComponent:updateUserInfos(app.room:getUserInfoList()) self.ui.Items.Button_invite:setVisible(app.room:getPlayerNum() ~= roomInfo.nMaxPlayCount) self:updateButtonPosition() -- if not self.LeavePos then self.LeavePos = self.ui.Items.Button_Leave:getPosition() self.DisbandPos = self.ui.Items.Button_Dismiss:getPosition() self.SettingPos = self.ui.Items.Button_Set:getPosition() self.RulePos = self.ui.Items.Button_rule:getPosition() end -- self:showMenu(false, true) self.ui.Items.Layout_Rule:setVisible(false) self.ui.Items.Layout_7:setVisible(false) self.ui.Items.Text_Rule:setVisible(false) --self.ui.Items.btnMenu:setVisible(false) self.ui.Items.Layout_Menu_1:setVisible(false) self.ui.Items.Layout_Menu_1:setLocalZOrder(199) if roomInfo.nGameStartCount > 0 then self.ui.Items.Layout_Rule:setVisible(false) else self.ui.Items.Layout_Rule:setVisible(true) self.ui.Items.Button_rule:setVisible(false) self.ui.Items.Layout_7:setVisible(true) self.ui.Items.Layout_Rule:runAction(cc.Sequence:create( cc.DelayTime:create(2), cc.CallFunc:create(function() self.ui.Items.Layout_7:setVisible(false) self.ui.Items.Layout_Rule:setVisible(false) self.ui.Items.Button_rule:setVisible(true) end))) end local bar = self.ui.Items.ListView:getVBar() -- bar:setPositionX(220) bar:setVisible(false) --解散按钮状态 if roomInfo.nGameStartCount == 0 and not app.room:isMyself(roomInfo.nRoomOwnedUid) then --未开始,且自己不是房主,则解散按钮不可点击 self.ui.Items.Button_Dismiss:setEnabled(false) else self.ui.Items.Button_Dismiss:setEnabled(true) end self:checkCanDismiss() end function zgwrDdzRoomView:onClickInviteClub() playBtnEffect() if app.club_php.clubID and app.club_php.clubID ~= 0 then local roomInfo = app.room:getRoomInfo() local gameInfo = roomInfo.nGameInfo local strInvite = DdzRoomViewConfig.getClubInviteWanFa(roomInfo.gameId or GAME_IDS.zgWuRenDouDiZhu, roomInfo) view = import("luaScript.Views.Club.ClubInvite"):new(roomInfo.nShowTableId, strInvite)--WRDDZDefine.getWanFaInfo(gameInfo) view:setAnchorPoint(cc.p(0.5, 0.5)) app:showWaitDialog(view) end end -- 弹出小结算展示按钮 function zgwrDdzRoomView:showRstComfirm( is ) self.ui.Items.Layout_RstBtn:setVisible(is==true) self._btnComfirm:setVisible(is==true) end -- 设置房间信息 function zgwrDdzRoomView:setRoomInfo( info ) self.ui.Items.roomNum:setString(string.format("房号: %06d", info.nShowTableId)) self.ui.Items.Label_JuShu:setString(string.format("%02d/%02d局", info.nGameStartCount or 0, info.nTotalGameNum or 0)) --设置规则信息 -- local ruleInfo = json.decode(info.nGameInfo) self.ui.Items.ListView:removeAllChildren() self.ui.Items.ListView:setAutoSize(true) local rules = WRDDZDefine.getWanFaInfoTab(info.nGameInfo) 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 zgwrDdzRoomView:updateRoomInfo(startCount, totalCount) local roomInfo = app.room:getRoomInfo() roomInfo.nGameStartCount = startCount roomInfo.nTotalGameNum = totalCount end -- 显示操作按钮 function zgwrDdzRoomView:showTurnBtn( is, isShowPass ,opFlag) --获取开房参数 local roomInfo = app.room:getRoomInfo() local gameInfo = roomInfo.nGameInfo or "" local ruleInfo = json.decode(gameInfo) if not is then self.ui.Items.Layout_tip:setVisible(false) self.ui.Items.Layout_out:setVisible(false) self.ui.Items.Layout_not_out:setVisible(false) return end --显示按钮时,清除一下自己出的牌 self:clearPosShow(1) --[[if (is and (opFlag and opFlag > 0)) then--倒计时 --最后一手牌 local cards = self:getHandCards() local ttp = PokerUtil:checkType(cards) local function __delay( onEnd ) self.ui:runDelay(1, function() if onEnd and type(onEnd)=='function' then onEnd() end end) end local function __lastOut(onEnd) self:resetSelect() app.room:requestOutCards(cards) if onEnd and type(onEnd)=='function' then onEnd() end end if self._lastOutType==ttp then if ttp==ETS.LIAN_DUI or ttp==ETS.SHUN_ZI then--最后一手牌顺子连对保证牌数相等 if #self._lastCards==#cards then self:addFunction(__lastOut) return end elseif ttp==ETS.AIRPLANE then--最后一手飞机校验 if #self._lastCards>=#cards then self:addFunction(__lastOut) return end elseif ttp==ETS.SINGLE_CARD or ttp==ETS.DUI_ZI then--最后一手单张 local result = PokerUtil:getTip(cards, self._lastCards) if result and #result > 0 then self:addFunction(__lastOut) return end end elseif self._lastOutType==0 then local can, handCards = self:checkOnceOut() if can then self:addFunction(__delay) self:addFunction(__lastOut) return end end else end--]] self.ui.Items.Layout_tip:setVisible(true) self.ui.Items.Layout_out:setVisible(true) self.ui.Items.Layout_not_out:setVisible(true) if opFlag == 2 then--第一首牌 self.ui.Items.Layout_tip:setVisible(false) self.ui.Items.Layout_not_out:setVisible(false) elseif opFlag == 1 then self.ui.Items.Button_not_out:loadTextureNormal("pk_zgwrddz/res/ui/zy_wrddz_btns/wrddz_btn_buchu.png"); elseif opFlag == 0 then self.ui.Items.Layout_tip:setVisible(false) self.ui.Items.Layout_out:setVisible(false) self.ui.Items.Button_not_out:loadTextureNormal("pk_zgwrddz/res/ui/zy_wrddz_btns/wrddz_btn_yaobuqi.png"); end self.ui.Items.Layout_operating_menus:requestDoLayout() self.ui.Items.Layout_operating_menus:doLayout() self.curCanOpFlag = opFlag or 1 --0-pass 1-可以出牌也可以pass 2-只能出牌 self:checkOutCardBtnEnabled() if opFlag == 1 then self.firstTip = true end --self.ui.Items.Button_tip:setVisible(is==true) --self.ui.Items.Button_out:setVisible(is==true) --self.ui.Items.Button_not_out:setVisible(is==true) --[[-- 自动提示 if self._lastOutType>0 and is then local cards = self._lastCards if cards and #cards>0 then local handCards = self:getHandCards() local result = PokerUtil:getTip(handCards, cards) if result and #result > 0 then --local result2 = PokerUtil:getOnlyTip(handCards, cards) --if result2 then --有且只有一种提示 自动弹出牌 -- self:tipCards(clone(result2)) --end else result = {} end -- 计算不能出的牌 local canotOuts = {} local tp = self._lastOutType if tp == ETS.SINGLE_CARD or (app.room.isMustBomb and app.room.isMustBomb == 1) then local bombs = PokerUtil:getAllBomb(handCards, isChoiceAAA) local node = self:getPlayerNodeVpos(2) if node then if node:isAlarm() then local max = result[1] for _,v in ipairs(result) do if v.val > max.val then max = v end end local tmpresult = {} if max and (max.val == 13 or max.val == 14) then--2和2王 这时候所有的2和王都要提示 for _,v in ipairs(result) do if v.val >= 13 then table.insert(tmpresult,v) end end result = tmpresult else result = {max} end end end for _,v in pairs(bombs) do table.insert(result, 1, v) end canotOuts = PokerUtil:leftSingleCards(handCards, result) elseif tp == ETS.DUI_ZI or tp == ETS.SHUN_ZI or tp == ETS.LIAN_DUI or tp == ETS.THREE_AND_TWO or tp == ETS.THREE or tp == ETS.THREE_AND_DUI or tp == ETS.AIRPLANE or tp == ETS.AIRPLANE_TOW or tp == ETS.AIRPLANE_DUI then local bombs = PokerUtil:getAllBomb(handCards, isChoiceAAA) for _,v in pairs(bombs) do table.insert(result, 1, v) end if tp == ETS.DUI_ZI or tp == ETS.SHUN_ZI or tp == ETS.LIAN_DUI then --飞机带的牌可以随意 canotOuts = PokerUtil:leftCardsEx(handCards, result) end elseif tp == ETS.BOMB then end local donotTip = false if opFlag and opFlag == 0 then self:downCanotOuts(handCards, true) donotTip = true elseif #canotOuts>0 then if app.room.isMustBomb and app.room.isMustBomb == 1 then--出的牌有多种牌型可能时,所有牌都可以组合打出去 canotOuts = {} elseif tp == ETS.SHUN_ZI then--是顺子且顺子里面有2,所有牌都可以组合打出去 local tLastCards = PokerUtil:parseCards(self._lastCards) for i = #tLastCards,1,-1 do if tLastCards[i].val == 13 then canotOuts = {} break end end end self:downCanotOuts(canotOuts, true) end if result and #result > 0 and (not donotTip) then end end end--]] end function zgwrDdzRoomView:showMenu( is, flag ) -- self.ui.Items.btnMenu.show = is==true -- if flag then -- self.panelMenu:setVisible(is==true) -- return -- end -- if is==true then -- self.panelMenu:setVisible(is==true) -- local actime = 0.08 -- local leavAc = { cc.Spawn:create(cc.MoveTo:create(actime, self.LeavePos), cc.FadeIn:create(actime)) } -- local disbandAc = { cc.Spawn:create(cc.MoveTo:create(actime, self.DisbandPos), cc.FadeIn:create(actime)) } -- local settingAc = { cc.Spawn:create(cc.MoveTo:create(actime, self.SettingPos), cc.FadeIn:create(actime)) } -- local uplogAc = {cc.Spawn:create(cc.MoveTo:create(actime, self.RulePos), cc.FadeIn:create(actime)) } -- self.ui.Items.Button_Leave:runAction(cc.Sequence:create(leavAc)) -- self.ui.Items.Button_Dismiss:runAction(cc.Sequence:create(disbandAc)) -- self.ui.Items.Button_Set:runAction(cc.Sequence:create(settingAc)) -- self.ui.Items.Button_rule:runAction(cc.Sequence:create(uplogAc)) -- else -- local oPos = self.ui.Items.btnMenu:getPosition() -- local actime = 0.08 -- local leavAc = cc.MoveTo:create(actime, oPos) -- self.ui.Items.Button_Leave:runAction(cc.Spawn:create(leavAc:clone(), cc.FadeOut:create(actime))) -- self.ui.Items.Button_Dismiss:runAction(cc.Spawn:create(leavAc:clone(), cc.FadeOut:create(actime))) -- self.ui.Items.Button_Set:runAction(cc.Spawn:create(leavAc:clone(), cc.FadeOut:create(actime))) -- self.ui.Items.Button_rule:runAction(cc.Sequence:create(cc.Spawn:create(leavAc:clone(), cc.FadeOut:create(actime)), cc.CallFunc:create(function() self.panelMenu:setVisible(is==true) end))) -- end end -- 是否显示准备按钮 function zgwrDdzRoomView:showSitdownBtn( is ) if self._isGameOver and true == self._isGameOver then return end self.ui.Items.Button_Ready:setVisible(is == true) local playerNum = app.room:getPlayerNum() if playerNum ~= app.room:getRoomInfo().nMaxPlayCount then--房间人数未满 self.ui.Items.Button_invite:setVisible(true) -- local invitePos = self.ui.Items.Button_invite:getPosition() -- if is then -- self.ui.Items.Button_invite:runAction(cc.MoveTo:create(0.2, self.ui.Items.Button_invite.oPos)) -- self.ui.Items.Button_Ready:runAction(cc.MoveTo:create(0.2, self.ui.Items.Button_Ready.oPos)) -- else -- if invitePos.x < 10 then -- self.ui.Items.Button_invite:stopAllActions() -- self.ui.Items.Button_invite:setPosition(self.ui.Items.Button_invite.oPos) -- self.ui.Items.Button_invite:runAction(cc.MoveTo:create(0.2, cc.p(10, invitePos.y))) -- end -- end else -- local readyPos = self.ui.Items.Button_Ready:getPosition() -- self.ui.Items.Button_Ready:stopAllActions() -- self.ui.Items.Button_Ready:runAction(cc.MoveTo:create(0.2, cc.p(10, readyPos.y))) end self:updateInviteClubButton() self:updateButtonPosition() end function zgwrDdzRoomView:updateButtonPosition() self.ui.Items.Button_Ready:getParent():setVisible(self.ui.Items.Button_Ready:isVisible()) self.ui.Items.Button_invite:getParent():setVisible(self.ui.Items.Button_invite:isVisible()) self.ui.Items.Button_Invite_Club:getParent():setVisible(self.ui.Items.Button_Invite_Club:isVisible()) if isReviewVersion() then self.ui.Items.Button_invite:getParent():setVisible(false) self.ui.Items.Button_Invite_Club:getParent():setVisible(false) end self.ui.Items.Layout_Button:requestDoLayout() self.ui.Items.Layout_Button:doLayout() end function zgwrDdzRoomView:onClickButtonShowClub( sender ) --[[local clubList = app.club_php.clubList if clubList and table.nums(clubList)>0 then local roomInfo = app.room:getRoomInfo() local infoT = json.decode(roomInfo.nGameInfo) local view = import("luaScript.Views.Club.ClubTable"):new(clubList[app.club_php.clubID], infoT.tableIdx) view:setAnchorPoint(cc.p(0.5, 0.5)) app:showWaitDialog(view) else app.club_php:getClubList() end--]] playBtnEffect() if IS_USER_NEW_CLUB then openClub() else local clubList = app.club_php.clubList if clubList and table.nums(clubList) > 0 then --房间号 local roomInfo = app.room:getRoomInfo() if roomInfo then --创建房间时传入的桌子下标 local infoT = json.decode(roomInfo.nGameInfo) self.clubView = import("luaScript.Views.Club.ClubTable"):new(clubList[app.club_php.clubID], infoT.tableIdx) self.clubView:setAnchorPoint(cc.p(0.5, 0.5)) app:showWaitDialog(self.clubView) end else --未找到茶馆列表数据时,请求茶馆列表(可能是断线重连) app.club_php:getClubList(); end end end function zgwrDdzRoomView:onClickButtonRstComfirm( sender ) playBtnEffect() -- 小结算 local showFunc = function (msg) --[[if self.xiaojuView and (not tolua.isnull(self.xiaojuView)) then self.xiaojuView:setVisible(true) return end--]] if msg then local soundFlag = false if not sender then soundFlag = true end self.xiaojuView = import("pk_zgwrddz.luaScript.Views.Room.Sub.zgwrDdzGameResultView"):new(msg,soundFlag) self.xiaojuView:setAnchorPoint(cc.p(0.5, 0.5)) app:showWaitDialog(self.xiaojuView) end end showFunc(self._resultMsg) end -- 显示GPS界面 function zgwrDdzRoomView:showGpsView() if self.isRecordScene then return end--回放场景直接return logD("zgwrDdzRoomView:showGpsView()") playBtnEffect() local isGameStart = app.room:getRoomInfo().nGameStartCount > 0 if self.gpsComponent then self.gpsComponent:showGpsView(isGameStart) end end -- 玩家点击房间详情 function zgwrDdzRoomView:onClickButtonDetails( sender ) playBtnEffect() 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()) self.ui.Items.Layout_Menu_1:setVisible(not self.ui.Items.Layout_Rule:isVisible()) end -- 一键截屏 function zgwrDdzRoomView:onClickButtonShot( sender ) playBtnEffect() showScreenShot() end function zgwrDdzRoomView:onClickButtonMenu( sender ) playBtnEffect() --self:showMenu(not sender.show) self.ui.Items.Layout_Menu_1:setVisible(not self.ui.Items.Layout_Menu_1:isVisible()) self.ui.Items.Layout_7:setVisible(self.ui.Items.Layout_Menu_1:isVisible()) self.ui.Items.Layout_Rule:setVisible(false) self.ui.Items.Button_rule:setVisible(true) end function zgwrDdzRoomView:onClickMenuOut( sender ) -- self:showMenu(false) self.ui.Items.Layout_Rule:setVisible(false) self.ui.Items.Layout_7:setVisible(false) self.ui.Items.Layout_Menu_1:setVisible(false) self.ui.Items.Button_rule:setVisible(true) self.ui.Items.Layout_Rule:stopAllActions() end function zgwrDdzRoomView:onClickButtonLeave( sender ) playBtnEffect() self:showMenu(false, true) self.ui:sendMsg(app.room, "callLeaveRequest") end function zgwrDdzRoomView:onClickButtonDismiss( sender ) playBtnEffect() local function onClickOk() self:showMenu(false, true) app.room:requestDismissRoom(1)--发起解散 end local function onClickCancel() end showConfirmDialog("确定要申请解散房间吗?", onClickOk, onClickCancel) end function zgwrDdzRoomView:onClickButtonSetting( sender ) playBtnEffect() self:showMenu(false, true) local view = import("pk_zgwrddz.luaScript.Views.Room.Sub.zgwrDdzSettingView"):new() view:setAnchorPoint(cc.p(0.5, 0.5)) app:showWaitDialog(view) end function zgwrDdzRoomView:onClickButtonUlog( sender ) playBtnEffect() self:showMenu(false, true) local view = import("luaScript.Views.Room.UplogView"):new() view:setAnchorPoint(cc.p(0.5, 0.5)) app:showWaitDialog(view) end function zgwrDdzRoomView:onClickButtonTip( sender, tag, tipShow ) playBtnEffect() self:resetCardsPos() self:hideCanOutCards() self.firstTip = true self:checkOutCardBtnEnabled() do return end --获取开房参数 local roomInfo = app.room:getRoomInfo() local gameInfo = roomInfo.nGameInfo or "" local ruleInfo = json.decode(gameInfo) --出牌提示 local cards = self._lastCards if cards and #cards>0 then local tp = PokerUtil:checkType(cards) if tp >= ETS.NONE then return nil end -- showTooltip("提示牌型: " .. PokerUtil:getTypeString(tp)) local handCards = self:getHandCards() if #handCards<=0 then return false end if tp == ETS.SINGLE_CARD then if sender._tipCards and #sender._tipCards>0 then local tmp = sender._tipCards[#sender._tipCards] if tmp[1] and type(tmp[1])=='table' then self:tipCards(clone(tmp)) else self:tipCards({clone(tmp)}) end table.remove(sender._tipCards, #sender._tipCards) if #sender._tipCards <= 0 then sender._tipCards = nil end else local result = PokerUtil:getTip(handCards, cards) if result and #result > 0 then else result = {} end -- 判断下家是否报单 local node = self:getPlayerNodeVpos(2) if node then if node:isAlarm() then local max = result[1] for _,v in ipairs(result) do if v.val > max.val then max = v end end local tmpresult = {} if max.val == 13 or max.val == 14 then--2和2王 这时候所有的2和王都要提示 for _,v in ipairs(result) do if v.val >= 13 then table.insert(tmpresult,v) end end result = tmpresult else result = {max} end end end local bombs = PokerUtil:getAllBomb(handCards, isChoiceAAA) local cds = {} for _,v in pairs(bombs) do table.insert(result, 1, v) end if #result <= 0 then return end sender._tipCards = clone(result) local tmp = sender._tipCards[#sender._tipCards] if tag then if #result>=1 then if tmp[1] and type(tmp[1])=='table' then self:tipCards(clone(tmp)) else self:tipCards({clone(tmp)}) end table.remove(sender._tipCards, #sender._tipCards) end else if tmp[1] and type(tmp[1])=='table' then self:tipCards(clone(tmp)) else self:tipCards({clone(tmp)}) end table.remove(sender._tipCards, #sender._tipCards) end end elseif tp == ETS.DUI_ZI or tp == ETS.SHUN_ZI or tp == ETS.LIAN_DUI or tp == ETS.THREE_AND_TWO or tp == ETS.THREE_AND_DUI or tp == ETS.THREE or tp == ETS.AIRPLANE or tp == ETS.AIRPLANE_TOW or tp == ETS.AIRPLANE_DUI then if sender._tipCards and #sender._tipCards>0 then self:tipCards(clone(sender._tipCards[#sender._tipCards])) table.remove(sender._tipCards, #sender._tipCards) if #sender._tipCards <= 0 then sender._tipCards = nil end else local result = PokerUtil:getTip(handCards, cards) if result and #result > 0 then else result = {} end local bombs = PokerUtil:getAllBomb(handCards, isChoiceAAA) for _,v in pairs(bombs) do table.insert(result, 1, v) end if #result <= 0 then return end sender._tipCards = clone(result) if tag then if #result >= 1 then self:tipCards(clone(sender._tipCards[#sender._tipCards])) table.remove(sender._tipCards, #sender._tipCards) end else self:tipCards(clone(sender._tipCards[#sender._tipCards])) table.remove(sender._tipCards, #sender._tipCards) end end elseif DdzRoomViewConfig.isBomb(tp) then if sender._tipCards and #sender._tipCards>0 then self:tipCards(clone(sender._tipCards[#sender._tipCards])) table.remove(sender._tipCards, #sender._tipCards) if #sender._tipCards <= 0 then sender._tipCards = nil end else local result = PokerUtil:getTip(handCards, cards) if result and #result > 0 then else return end sender._tipCards = clone(result) if tag then if #result >= 1 then self:tipCards(clone(sender._tipCards[#sender._tipCards])) table.remove(sender._tipCards, #sender._tipCards) end else self:tipCards(clone(sender._tipCards[#sender._tipCards])) table.remove(sender._tipCards, #sender._tipCards) end end else return nil end else--没有牌,第一手提示 local handCards = self:getHandCards() if sender._tipCards and #sender._tipCards>0 then self:tipCards(clone(sender._tipCards[#sender._tipCards])) table.remove(sender._tipCards, #sender._tipCards) if #sender._tipCards <= 0 then sender._tipCards = nil end else local result = PokerUtil:getFirstTip(handCards) if result and #result > 0 then else return end sender._tipCards = clone(result) self:tipCards(clone(sender._tipCards[#sender._tipCards])) table.remove(sender._tipCards, #sender._tipCards) end end end -- 变暗不能出的牌 function zgwrDdzRoomView:downCanotOuts(canotOuts, isTouch) for _,v in pairs(canotOuts) do local node = self:getCardNode(v) if node and (not tolua.isnull(node)) then node:setNormal() node:setNormalColor() node:setNoTouch(isTouch) end end local tmp = {} for _,v in pairs(self._selectCards) do if v and (not tolua.isnull(v)) and v:isDown() then table.insert(tmp, v) end end self._selectCards = tmp end --出牌 function zgwrDdzRoomView:onClickButtonOut( sender ) self:hideCanOutCards() playBtnEffect() local cards = self:getSelected() if #cards <= 0 then return showTooltip("请选择要出的牌") else local serverLastOuttype if app.room.lastOutType and app.room.lastOutType >0 and app.room.lastOutType < 100 then serverLastOuttype = app.room.lastOutType end local tp = PokerUtil:checkType(cards) if self._lastCards and #self._lastCards>0 then self._lastOutType = serverLastOuttype or PokerUtil:checkType(self._lastCards) end local isHaveGui,guiNum = PokerUtil:checkHaveGui1(cards) local isAllow = true if (self._lastOutType==tp or isHaveGui) or self._lastOutType==0 or DdzRoomViewConfig.isBomb(tp) or isAllow then -- 检测下家是否报单 --获取自己的座位数据 local myself = app.room:getMyself() local pdata = app.room:getPlayerVpos(myself.viewPos) logD("zgwrDdzRoomView:onClickButtonOut pdata = "..table.tostring(pdata)) local node = self:getPlayerNode(pdata.userId) local isAlarm = node:isAlarm() --[[if isAlarm and #cards==1 and tp==ETS.SINGLE_CARD then -- 判断是否是最大单张 if PokerUtil:isMaxCard(self:getHandCards(), cards[1]) then app.room:requestOutCards(cards) else return showTooltip("报单必须出最大牌") end else--]] if isHaveGui then app.room:requestGetOutCards(cards) else app.room:requestOutCards(cards) end --end else return showTooltip("选择的牌型错误") end end end function zgwrDdzRoomView:onClickButtonNotOut( sender ) local cards = {} app.room:requestOutCards(cards) end function zgwrDdzRoomView:onClickButtonReady( sender ) playBtnEffect() self.ui:sendMsg(app.room, "callReadyRequestPdk") --[[local test = { ["bankerSeat"] = 1, --["cardPlayerInfo"] = {"1":2,"10":0,"11":3,"12":1,"13":3,"2":2,"3":2,"4":3,"5":3,"6":3,"7":2,"8":3,"9":1}, ["cards"] = { [1] = 29, [2] = 11, [3] = 27, [4] = 9, [5] = 7, [6] = 6, [7] = 22, [8] = 37, [9] = 4, [10] = 20, [11] = 51, [12] = 2, [13] = 34, [14] = 11, [15] = 27, [16] = 9, [17] = 7, [18] = 6, [19] = 22, [20] = 37, [21] = 4, [22] = 20, [23] = 51, [24] = 2, [25] = 34, }, ["userId"] = 1040236, } self:sendCards(test.cards)--]] end function zgwrDdzRoomView:getInviteData() local strNames = "" local index = 0 local num = app.room:getPlayerNum() for k,v in pairs(app.room:getPlayers()) do index = index + 1 local name = getSubStringNickname(v.nickname) strNames = strNames..name if index < num then strNames = strNames.."," end end local roomInfo = app.room:getRoomInfo() local invitePtr = DdzRoomViewConfig.InviteConfig[roomInfo.nMaxPlayCount][num]--几缺几 local strGameMode = WRDDZDefine.getWanFaInfo(roomInfo.nGameInfo) local strGameNum = string.format("%s局", roomInfo.nTotalGameNum) local desc = string.format("%s,%s 玩家:%s", strGameNum, strGameMode, strNames) print("pdk_invite : ",desc) local title = string.format("五人斗地主 房号[%s] %s", roomInfo.nShowTableId, invitePtr ) if app.club_php.clubID and app.club_php.clubID~=0 then title = string.format("%s 茶馆ID[%d]", title, tonumber(app.club_php.clubID)) end print("pdk_invite : ", title) return title,desc end --邀请好友 function zgwrDdzRoomView:onClickButtonInvite( sender ) playBtnEffect() --[[local strNames = "" local index = 0 local num = app.room:getPlayerNum() for k,v in pairs(app.room:getPlayers()) do index = index + 1 local name = getSubStringNickname(v.nickname) strNames = strNames..name if index < num then strNames = strNames.."," end end local roomInfo = app.room:getRoomInfo() local invitePtr = DdzRoomViewConfig.InviteConfig[roomInfo.nMaxPlayCount][num]--几缺几 local strGameMode = DdzRoomViewConfig.getRuleString(roomInfo.nGameInfo) local strGameNum = string.format("%s局", roomInfo.nTotalGameNum) local desc = string.format("%s,%s 玩家:%s", strGameNum, strGameMode, strNames) print("pdk_invite : ",desc) local title = string.format("欢乐跑得快 房号[%s] %s", roomInfo.nShowTableId, invitePtr ) if app.club_php.clubID and app.club_php.clubID~=0 then title = string.format("%s 茶馆ID[%d]", title, tonumber(app.club_php.clubID)) end print("pdk_invite : ", title)--]] local title,desc = self:getInviteData() local imagePath = cc.FileUtils:getInstance():getWritablePath().."icon.png" --[[ local info = {} info.scene = "talk" info.contentType = "url" info.url = app.config.Setting.appDownloadUrl info.title = title info.description = desc info.image = imagePath info.imageWidth = 100 app.plugin:shareGame(info)--]] local info = {} info.title = title info.description = desc info.copyData={type=2} local view = import("luaScript.Views.Main.ShareView"):new(info) view:setAnchorPoint(cc.p(0.5, 0.5)) app:showWaitDialog(view) end function zgwrDdzRoomView:onClickCopy() playBtnEffect() local title,desc = self:getInviteData() local clubData = "" if app.club_php.clubID and app.club_php.clubID ~= 0 then local clubName = "" local clubList = app.club_php.clubList if clubList and table.nums(clubList) > 0 then clubName = clubList[tonumber(app.club_php.clubID)].clubName; end clubData = string.format("茶馆名:%s \n", clubName) end local tishi = "复制信息打开游戏将自动入座\n<仅供娱乐,严禁赌博>" copyData = string.format("%s%s\n%s\n%s",clubData,title,desc,tishi) logD(copyData) copyStringToClipboard(copyData) app.plugin:gotoWeiXin() end -- 恢复自己手牌 function zgwrDdzRoomView:recoverHandcards(_cards) logD("zgwrDdzRoomView:recoverHandcards:", table.tostring(_cards)) self:cleanSelfCards() local cards = pokerSortPdkCards(_cards) local pos = 1 local allCount = #cards for i,card in ipairs(cards) do self:sendOneCardNoAct(card.cid, i, pos, i==allCount, allCount) end self:resetCardsPos() end --[[WRDDZRoomConfig.GameStatus = { GAME_STATE_INIT =0, --游戏初始状态 GAME_STATUS_WAIT_BANKER_START =1, --等待庄家开始游戏 GAME_STATUS_WAITTING =2, --等待中 GAME_STATUS_READALL =3, --所有玩家准备 GAME_STATUS_SHUFFLE =4, --洗牌中 GAME_STATUS_SENDCARDS =5, --发牌阶段 GAME_STATUS_ASK_LOARD =6, --叫地主 GAME_STATUS_ASK_DOUBLE =7, --加倍状态 GAME_STATUS_SELECT_CARD =8, --选牌(暗地主) GAME_STATUS_PLAYING =9, --开始游戏出牌 GAME_STATE_ROUND_OVER =10, --小局结束 GAME_STATE_GAME_OVER =11, --大局结束 }--]] --断线重连 function zgwrDdzRoomView:onGameReconnection( data ) local roomInfo = app.room:getRoomInfo() --self:checkGpsDistance(nil,roomInfo.nGameStartCount==0) --self:checkMyGpsNeedUpdate(); if roomInfo.nGameStartCount==0 then local tmpPosData = {} tmpPosData.players = {} for _,pdata in ipairs(roomInfo.recoverItem) do table.insert(tmpPosData.players,{nUserId = pdata.userId,nSeatId = pdata.seatId}) end self:onUpdatePlayerPos({response = tmpPosData}) end -- 当前操作玩家 local curOpUserId = -1 local tmpData = {} for _,pdata in ipairs(roomInfo.recoverItem) do tmpData[pdata.userId] = pdata local player = app.room:getPlayer(pdata.userId) local node = self:getPlayerNode(pdata.userId) if not node then self:addPlayerNode(player) else node:setHost(false) node:setAnDiZhu(false) node:cleanPass() node:setTurn(false) node:setScoreNoAnim(pdata.totalScore) node:setBanker(pdata.seatId==roomInfo.reBankerId) node:setOffline(pdata.onlineStatus==0) node:setReady(pdata.playFlag==1) end if pdata.isCanOp==1 then curOpUserId = pdata.userId end end if roomInfo.bUserDisbandGame == 1 then --房间是否是解散状态 app.room:dispatchEvent({name = "pdkNormalEvent_show_dissmiss_over"}) -- 其他玩家的解散状态 local dismissInfo = {} local list = {} for i,v in ipairs(roomInfo.recoverItem) do dismissInfo[v.userId] = v.disbandStatus local l = {} l.nUserId = v.userId l.dismissState = v.disbandStatus table.insert(list, l) end app.room.dismissInfo = dismissInfo local response = {} response.memberList = list response.timeLeft = roomInfo.leftTimeOut response.operateType = 1 self:onDismissResponse({response=response}) end --恢复托管状态 self:refreshPlayerAIStatus() self._isLorder = false self._isDarkLorder = false local myself = app.room:getMyself() if myself.playFlag==1 then--准备状态return return end if roomInfo.gameStatus >= DdzRoomViewConfig.GameStatus.GAME_STATUS_ASK_LOARD and roomInfo.gameStatus <= DdzRoomViewConfig.GameStatus.GAME_STATE_ROUND_OVER then -- 离开房间不可点击 self.ui.Items.Button_Leave:setEnabled(false) self.ui.Items.Layout_Leave:setEnabled(false) if app.room:isMyself(roomInfo.nLordId) then self._isLorder = true end if app.room:isMyself(roomInfo.nDarkLordId) then self._isDarkLorder = true end --自己是否知道暗地主玩家 self.isKnowDarkLord = false for _,pdata in ipairs(roomInfo.recoverItem) do if app.room:isMyself(pdata.userId) then self.isKnowDarkLord = pdata.bKnowDarkLord == 1 end end for _,pdata in ipairs(roomInfo.recoverItem) do local player = app.room:getPlayer(pdata.userId) self:clearPosShow(player.viewPos) local node = self:getPlayerNode(pdata.userId) if app.room:isMyself(pdata.userId) then self:recoverHandcards(pdata.handCards) if node then node:showLeft(#pdata.handCards) end else if node then node:showLeft(#pdata.handCards) node:setOffline(pdata.onlineStatus==0) end end if node then node:setScore(pdata.totalScore) if pdata.userId == roomInfo.nLordId then node:setFanMult(pdata.nMult == 1) else node:setMult(pdata.nMult == 1) end end if pdata.userId == roomInfo.nDarkLordId and self.isKnowDarkLord then node:setAnDiZhu(true) end if pdata.userId == roomInfo.nLordId then node:setHost(true) end end self.ui.Items.TextBMFont_beishu:setText(roomInfo.nHMIShowMult or "1") self.ui.Items.TextBMFont_difen:setText("1") if roomInfo.gameStatus == DdzRoomViewConfig.GameStatus.GAME_STATUS_ASK_LOARD then--叫地主阶段 for _,pdata in ipairs(roomInfo.recoverItem) do local node = self:getPlayerNode(pdata.userId) if pdata.bAskedLord == 1 then--等待叫地主 if app.room:isMyself(pdata.userId) then self:showJiaoDiZhu() end if node then node:setTurn(true) end elseif pdata.bAskedLord == 2 then--操作过叫地主 if node then node:showJiaoDiZhu(false) end end end elseif roomInfo.gameStatus == DdzRoomViewConfig.GameStatus.GAME_STATUS_ASK_DOUBLE then--加倍状态 self:showDiPai(roomInfo.diCards) --自己是否操作过 local selfIsOp = false --0:未操作加倍,1:等待加倍,2:操作过加倍 for _,pdata in ipairs(roomInfo.recoverItem) do local node = self:getPlayerNode(pdata.userId) if pdata.bAskDouble == 1 then--等待加倍 if app.room:isMyself(pdata.userId) then if roomInfo.nLordId and (pdata.userId == roomInfo.nLordId) then self:showFanJiaBei() else self:showJiaBei() end end if node then node:setTurn(true) end elseif pdata.bAskDouble == 2 then--操作过加倍 if node then if roomInfo.nLordId and (pdata.userId == roomInfo.nLordId) then node:showFanJiaBei(pdata.nMult == 1) else node:showJiaBei(pdata.nMult == 1)--0不加倍1加倍 end if roomInfo.nLordId and pdata.userId == roomInfo.nLordId then node:setFanMult(pdata.nMult == 1) else node:setMult(pdata.nMult == 1) end end if app.room:isMyself(pdata.userId) then selfIsOp = true end end end if selfIsOp then self:showBgTips(true,7) end elseif roomInfo.gameStatus == DdzRoomViewConfig.GameStatus.GAME_STATUS_SELECT_CARD then--选牌(暗地主) self:showDiPai(roomInfo.diCards) if app.room:isMyself(roomInfo.nLordId) then self:showXuanAnDiZhu() self:setSelectAnLordCard() --检测选牌是否可点 self:checkSelectCardBtnEnabled() else self:showBgTips(true,0) end local node = self:getPlayerNode(roomInfo.nLordId) node:setTurn(true) elseif roomInfo.gameStatus == DdzRoomViewConfig.GameStatus.GAME_STATUS_PLAYING then--玩牌中 self:showDiPai(roomInfo.diCards) self:showAnDiZhuCard(roomInfo.nDarkLordCard) local startViewPos = 0 local endViewPos = 0 if roomInfo.lastOpUid > 0 and #roomInfo.lastOutCards > 0 then local node = self:getPlayerNode(roomInfo.lastOpUid) node:setLastOp(roomInfo.lastOpType, roomInfo.lastOutCards,nil,roomInfo.lastShowDzFlag) startViewPos = node:getInfo().viewPos self._lastOutPos = startViewPos self._lastOutType = roomInfo.lastOpType app.room.lastOutType = roomInfo.lastOpType self._lastCards = roomInfo.lastOutCards end --当前出牌者 if app.room:isMyself(roomInfo.curOpUid) then self:showTurnBtn(true, roomInfo.curOpType,roomInfo.curOpType)--能否出牌 end local node = self:getPlayerNode(roomInfo.curOpUid) node:setTurn(true, 10) endViewPos = node:getInfo().viewPos if endViewPos == 1 then endViewPos = 6 end if startViewPos > 0 then for i = startViewPos + 1 ,endViewPos-1 do local node = self:getPlayerNodeVpos(i) if node then node:showPass() end end end elseif roomInfo.gameStatus == DdzRoomViewConfig.GameStatus.GAME_STATE_ROUND_OVER then--需要判断是否已经有单局结算页面 self:showSitdownBtn(false) self:showDiPai(roomInfo.diCards) self:showAnDiZhuCard(roomInfo.nDarkLordCard) if roomInfo.lastOpUid > 0 and #roomInfo.lastOutCards > 0 then local node = self:getPlayerNode(roomInfo.lastOpUid) node:setLastOp(roomInfo.lastOpType, roomInfo.lastOutCards,nil,roomInfo.lastShowDzFlag) self._lastOutType = roomInfo.lastOpType app.room.lastOutType = roomInfo.lastOpType self._lastCards = roomInfo.lastOutCards end self.ui.Items.Button_Leave:setEnabled(false) self.ui.Items.Layout_Leave:setEnabled(false) local response = {} response.gameStartCount = roomInfo.nGameStartCount response.totalGamenum = roomInfo.nTotalGameNum local players = {} for i,v in ipairs(roomInfo.recoverItem) do local p = {} p.userId = v.userId p.turnScore = v.turnScore p.totalScore = v.totalScore if v.userId ~= roomInfo.nDarkLordId then p.isMult = v.nMult end p.leftNum = #v.handCards p.handCards = v.handCards p.groupCardInfo = v.groupCardInfo p.allBombTimes = v.allBombTimes table.insert(players, p) local player = app.room:getPlayer(p.userId) local playerNode = self:getPlayerNode(player.userId) if #v.handCards>0 and player then self:showLeftCards(player.viewPos, v.handCards or {}) end end response.players = players --小局信息 response.winUserId = roomInfo.winUserId response.lordId = roomInfo.nLordId response.darkId = roomInfo.nDarkLordId response.baseMult = roomInfo.nBaseMult response.curMult = roomInfo.nGameCurMult response.fourMult = roomInfo.fourBomb response.twoKMult = roomInfo.twoKingBomb response.eightMult = roomInfo.eightBomb response.fourKMult = roomInfo.fourKingBomb response.twelveMult = roomInfo.twelveBomb response.sixKMult = roomInfo.sixKingBomb response.spring = roomInfo.spring response.isSelfEat = roomInfo.isSelfEat response.leftCards = {} self:showGameResultRecover({response=response}) self:showOtherCards(false) end end self.ui.Items.Button_invite:setVisible(app.room:getPlayerNum() ~= roomInfo.nMaxPlayCount) self:updateInviteClubButton() self:updateButtonPosition() end function zgwrDdzRoomView:updateInviteClubButton() if app.club_php.clubID and app.club_php.clubID~=0 then local roomInfo = app.room:getRoomInfo() if roomInfo.nGameStartCount==0 and table.nums(roomInfo.memberList) maxCards then maxCards = #v.leftCards end local pdata = app.room:getPlayer(v.userId) v.unionid = pdata.unionid v.headimgurl = pdata.headimgurl v.gpsInfo = pdata.gpsInfo v.sex = pdata.sex v.openid = pdata.openid v.nickname = pdata.nickname v.areano = pdata.areano end --是不是最后一局 local roomInfo = app.room:getRoomInfo() msg.isLast = roomInfo.nGameStartCount==roomInfo.nTotalGameNum msg.ruleString = WRDDZDefine.getWanFaInfo(roomInfo.nGameInfo) self._resultMsg = msg self._resultMsg.players = msg.players self._resultMsg.isLast = msg.isLast self._resultMsg.ruleString = msg.ruleString or "" self._resultMsg.gameStartCount = msg.gameStartCount self._resultMsg.totalGamenum = msg.totalGamenum -- -- 小结算 local showFunc = function () for _,v in pairs(self._playerNodes) do v:hideLeft() end self:showRstComfirm(true) self:onClickButtonRstComfirm() end self._gameResult = true --中途恢复直接展示 -- showLeftFunc() showFunc() end function zgwrDdzRoomView:bindEvents() self:bindEvent(app.room , "onUserExitResponseRoom" , handler(self , self.onUserExitResponseRoom)) --onDismissResponse self:bindEvent(app.room , "onDismissResponse" , handler(self , self.onDismissResponse)) -- 其他玩家进入房间 self:bindEvent(app.room , "onResponseBroadcastLogin" , handler(self , self.onResponseBroadcastLogin)) -- 玩家离开房间 self:bindEvent(app.room , "onResponseBroadcastLogout" , handler(self , self.onResponseBroadcastLogout)) -- 玩家准备 self:bindEvent(app.room , "onResponseUserReady" , handler(self , self.onResponseUserReady)) -- 游戏开始 self:bindEvent(app.room , "onResponseGameStart" , handler(self , self.onResponseGameStart)) -- 给玩家发牌 self:bindEvent(app.room , "onResponseSendCards" , handler(self , self.onResponseSendCards)) -- 玩家出牌成功 self:bindEvent(app.room , "onResponseOutCards" , handler(self , self.onResponseOutCards)) -- 玩家出牌错误 self:bindEvent(app.room , "onResponseOutCardsErr" , handler(self , self.onResponseOutCardsErr)) -- 单局结算 self:bindEvent(app.room , "onResponseGameResult" , handler(self , self.onResponseGameResult)) -- 总结算 self:bindEvent(app.room , "onResponseGameOver" , handler(self , self.onResponseGameOver)) -- 玩家离线 self:bindEvent(app.room , "onOtherDroppedResponse" , handler(self , self.onOtherDroppedResponse)) -- 游戏设置里更换桌面 self:bindEvent(app.room , "pdkNormalEvent_changeDesktop" , handler(self , self.onNormalChangeDesktop)) -- 服务器通知更新当前玩家分数 self:bindEvent(app.room , "onResponseUpdateScore" , handler(self , self.onResponseUpdateScore)) -- 显示大结算 self:bindEvent(app.room , "ddzNormalEvent_show_game_over" , handler(self , self.onNormalShowGameOver)) -- 断线重连 self:bindEvent(app.room , "onResponseGameRecover" , handler(self , self.onGameReconnection)) -- 玩家请求快速开始广播 self:bindEvent(app.room , "onBroadcastFastRequest", handler(self, self.onBroadcastFaststart)) -- 快速开始成功 self:bindEvent(app.room , "onFastStartSucc", handler(self, self.onFastStartSucc)) --监听从后台进入游戏事件 self:bindEvent(app, "applicationWillEnterForeground", handler(self, self.onApplicationWillEnterForeground)) -- 玩家的GPS信息发生变化 self:bindEvent(app.room , "onGpsChangeResponse" , handler(self , self.onGpsChangeResponse)); -- 游戏状态改变 self:bindEvent(app.room , "onUpdateGameStatus" , handler(self , self.onUpdateGameStatus)); -- 通知玩家抢地主 self:bindEvent(app.room , "onNoticeGrabLord" , handler(self , self.onNoticeGrabLord)); -- 无人抢地主重新洗牌 self:bindEvent(app.room , "onShuffleCards" , handler(self , self.onShuffleCards)); -- 广播抢地主结果 self:bindEvent(app.room , "onBroadGrabLordResult" , handler(self , self.onBroadGrabLordResult)); -- 将底牌发给地主 self:bindEvent(app.room , "onSendDiCardsToLord" , handler(self , self.onSendDiCardsToLord)); -- 通知玩家加倍 self:bindEvent(app.room , "onBroadNoticeDouble" , handler(self , self.onBroadNoticeDouble)); -- 玩家加倍结果 self:bindEvent(app.room , "onAddMultResult" , handler(self , self.onAddMultResult)); -- 广播地主选牌(暗地主) self:bindEvent(app.room , "onBroadLordSelectCard" , handler(self , self.onBroadLordSelectCard)); -- 广播玩家选牌结果 self:bindEvent(app.room , "onLordSelectCardResult" , handler(self , self.onLordSelectCardResult)); -- 告知暗地主玩家 self:bindEvent(app.room , "onNoticeAnLordPlayer" , handler(self , self.onNoticeAnLordPlayer)); -- 服务器通知当前玩家轮次 self:bindEvent(app.room , "onResponseUpdateTurns" , handler(self , self.onResponseUpdateTurns)) -- 获取出牌的牌组 self:bindEvent(app.room , "onGetOutCardsResult" , handler(self , self.onGetOutCardsResult)) -- 广播游戏倍数变化 self:bindEvent(app.room , "onUpdateGameMult" , handler(self , self.onUpdateGameMult)) -- 玩家获取手牌 self:bindEvent(app.room , "onGetUserCards" , handler(self , self.onGetUserCards)) -- 关闭互斥界面 self:bindEvent(app, "onCloseRoomMutexView", handler(self, self.onCloseRoomMutexView)); -- 托管回复 self:bindEvent(app.room , 'onHostingResponse', handler(self, self.onHostingResponse)) end function zgwrDdzRoomView:onCloseRoomMutexView() self:onClickMenuOut() end function zgwrDdzRoomView:onNormalChangeDesktop( data ) if data.idx >4 and data.idx<1 then return end self.ui.Items.ImageView_bg:loadTexture(string.format("pk_zgwrddz/res/ui/zy_game/wrddr_gamebg_%d.jpg", data.idx), 0) self:initLogo() end function zgwrDdzRoomView:initLogo () -- 水印 if not (type(getSubGameRoomLogo) == 'function') then--大厅不支持此方法,则隐藏logo self.ui.Items.ImageView_logo:setVisible(false); return end local logofile = getSubGameRoomLogo(GAME_IDS.zgWuRenDouDiZhu,1) if logofile then self.ui.Items.ImageView_logo:loadTexture(logofile) self.ui.Items.ImageView_logo:setVisible(true); else self.ui.Items.ImageView_logo:setVisible(false); end end -- 服务器通知玩家分数 function zgwrDdzRoomView: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 zgwrDdzRoomView:onOtherDroppedResponse( data ) local msg = data.response local node = self:getPlayerNode(msg.nUserId) local pdata = app.room:getPlayer(msg.nUserId) if node and pdata then if msg.nDroppedStatus == 0 then node:setOffline(true) pdata.onlineStatus = 0 elseif msg.nDroppedStatus == 1 then node:setOffline(false) pdata.onlineStatus = 1 end end end function zgwrDdzRoomView:onUserExitResponseRoom( data ) local function _exit( onEnd ) local response = data.response -- 0: 不退出(回到子游戏), 1: 退出(回到大厅) if not self._isGameOver then if response.logoutFlag == 1 then app:gotoView(import("luaScript.Views.Main.MainView"):new(GAME_IDS.zgWuRenDouDiZhu)) else app:gotoView(import("luaScript.Views.Main.MainView"):new(GAME_IDS.zgWuRenDouDiZhu)) end end if onEnd and type(onEnd)=='function' then onEnd() end end self:addFunction(_exit) end function zgwrDdzRoomView:onDismissResponse( data ) local __dis = function (onEnd) local response = data.response app.room:getRoomInfo().nDismissStateTime = response.timeLeft --剩余时间 app.room:getRoomInfo().nDismissToTalTime = app.room:getRoomInfo().nDisbandTimeout or 60 --总的时间 --显示解散(此标志会影响闹钟时间会冻住) app.room:getRoomInfo().nShowDismiss = true if response.operateType == 1 then if response.memberList ~= nil then for k,v in pairs(response.memberList) do if v.dismissState == 1 then --local view = import("pk_zgwrddz.luaScript.Views.Room.Sub.zgwrDdzDismissView"):new(v.nUserId) local view = require("luaScript.Views.Room.RoomDismissView"):new(v.nUserId,app.room.roomInfo.memberList,response.timeLeft) view:setAnchorPoint(cc.p(0.5, 0.5)) app:showWaitDialog(view) return end end else --local view = import("pk_zgwrddz.luaScript.Views.Room.Sub.zgwrDdzDismissView"):new(response.nUserId) local view = require("luaScript.Views.Room.RoomDismissView"):new(response.nUserId,app.room.roomInfo.memberList,response.timeLeft) view:setAnchorPoint(cc.p(0.5, 0.5)) app:showWaitDialog(view) end else local memberStatus={} if response.memberList ~= nil then for k,v in pairs(response.memberList) do table.insert(memberStatus,{userId = v.nUserId, status = v.dismissState}) end else table.insert(memberStatus,{userId = response.nUserId, status = response.operateType}) end app.room:dispatchEvent({name = GAME_EVENT.DISSMISS_UPDATE_STATUS , memberStatus = memberStatus}); end end __dis() end -- 其他玩家进入 function zgwrDdzRoomView:onResponseBroadcastLogin( data ) self:addPlayerNode(data.pInfo) self.ui.Items.Button_invite:setVisible(app.room:getPlayerNum()~=app.room:getRoomInfo().nMaxPlayCount) local myself = app.room:getMyself() if myself.playFlag>=1 then self:showSitdownBtn(false) else self:showSitdownBtn(true) end self:showFastStart(true) end -- 玩家离开房间 function zgwrDdzRoomView:onResponseBroadcastLogout( data ) local function __logout( onEnd ) self:showFastStart(true) self:delPlayerNode(data.userId) local myself = app.room:getMyself() if myself.playFlag>=1 then self:showSitdownBtn(false) else self:showSitdownBtn(true) end if onEnd and type(onEnd)=='function' then onEnd() end end self:addFunction(__logout) end -- 玩家准备 function zgwrDdzRoomView:onResponseUserReady( data ) local userId = data.userId local node = self:getPlayerNode(userId) if node then node:setReady(true) end if app.room:isMyself(userId) then self:resetRoundData() app.room:addPlayer({playFlag=1, userId=userId}) self:showSitdownBtn(false) for _,node in pairs(self._playerNodes) do node:cleanScore() end end end -- 游戏开始 function zgwrDdzRoomView:onResponseGameStart( data ) local function __start( onEnd ) local roomInfo = app.room:getRoomInfo() if roomInfo.nGameStartCount and roomInfo.nGameStartCount == 0 then self:onUpdatePlayerPos(data) end self._gameResult = false self._passGameResult = nil -- 离开房间不可点击 self.ui.Items.Button_Leave:setEnabled(false) self.ui.Items.Layout_Leave:setEnabled(false) -- 取消玩家的准备标志 for _,node in pairs(self._playerNodes) do node:setReady(false) node:cleanScore() app.room:updateFlag( node:getInfo().userId, 2 ) end self:cleanSelfCards() self:cleanShowCards() self.ui.Items.Button_Ready:setVisible(false) self.ui.Items.Button_invite:setVisible(false) self:updateButtonPosition() self:updateInviteClubButton() -- self:showTurnBtn(false) self:updateRoomInfo(roomInfo.nGameStartCount, roomInfo.nTotalGameNum) self:checkCanDismiss() if onEnd and type(onEnd)=='function' then onEnd() end end self:addFunction(__start) end --更新玩家位置 function zgwrDdzRoomView:onUpdatePlayerPos( data ) if not data then return end local response = data.response if not response then return end -- 更新椅子号 for _,v in pairs(response.players) do app.room:addPlayer({userId = v.nUserId, seatId = v.nSeatId}) end -- 更新视图ID for _,v in pairs(response.players) do app.room:addPlayer({userId = v.nUserId, viewPos = app.room:transPos(v.nSeatId)}) end --刷新房间玩家位置 if response then --删除所有玩家节点 for k,v in pairs(self._playerNodes) do self:delPlayerNode(tonumber(k)) end for k,v in pairs(response.players) do self:delPlayerNode(v.nUserId) end self:initChatView() --重新添加玩家节点 local players = app.room:getPlayers() for _, info in pairs(players) do self:addPlayerNode( info ) end end end -- 给玩家发牌 function zgwrDdzRoomView:onResponseSendCards( data ) if self.xiaojuView and (not tolua.isnull(self.xiaojuView)) then self.xiaojuView:removeFromParent() self.xiaojuView = nil end self:setRoomInfo(app.room:getRoomInfo()) local function __sendCards( onEnd ) self:resetRoundData() self._gameResult = false self._passGameResult = nil self:sendCards(data.response.cards) if onEnd and type(onEnd) == 'function' then onEnd() end end self:addFunction(__sendCards) local function __delay( onEnd ) self.ui:runDelay(1, function() if onEnd and type(onEnd)=='function' then onEnd() end end) self:showJiPaiQi(true,data.response.cardPlayerInfo) end self:addFunction(__delay) local function __showLeft( onEnd ) local left = 25 for uid,v in pairs(self._playerNodes) do v:showLeft(left) end self:resetCardsPos() if onEnd and type(onEnd) == 'function' then onEnd() end end self:addFunction(__showLeft) --[[local function __showTurn( onEnd ) local bankerData = app.room:getPlayerCid(data.response.bankerSeat) if app.room:isMyself(bankerData.userId) then --发完牌后庄家为自己,则不能操作不要按钮 local isShowPass = false self:showTurnBtn(true,isShowPass,2) local node = self:getPlayerNodeVpos(1) if node then node:setTurn(true) end else self:showTurnBtn(false) local node = self:getPlayerNode(bankerData.userId) if node then node:setTurn(true) end end if onEnd and type(onEnd) == 'function' then onEnd() end end self:addFunction(__showTurn) --]] end -- 显示轮次时钟 function zgwrDdzRoomView:showTurns( viewPos, cleanCards ) for _,node in pairs(self._playerNodes) do local is = node:getInfo().viewPos==viewPos node:setTurn(is) -- if cleanCards==nil then cleanCards = true end if cleanCards then self:clearPosShow(viewPos) end--清楚玩家出的牌 if is then node:cleanPass() end end end -- 广播当前桌子轮次@userId@seatId@outFlag function zgwrDdzRoomView:onResponseUpdateTurns( data ) local function __updateTurns( onEnd ) local msg = data.response --self.lastOutFlag = msg.outFlag local node = self:getPlayerNode(msg.userId) local viewPos = node:getInfo().viewPos self:showTurns(viewPos, msg.opType~=2) if app.room:isMyself(msg.userId) then local isShowPass = msg.opType == 1 --0-只能pass 1-可以出牌也可以pass 2-必须出牌(不能pass) if self._isShowZiChi then self._isShowZiChi = nil local actions={ cc.DelayTime:create(1.2), cc.CallFunc:create(function() self:showTurnBtn( true , isShowPass,msg.opType) end), } self.ui:runAction(cc.Sequence:create(actions)) else self:showTurnBtn( true , isShowPass,msg.opType) end if msg.opType == 2 then--如果只能出牌 self._lastCards = {} end end self:clearPosShow(viewPos) if onEnd and type(onEnd)=='function' then onEnd() end end self:addFunction(__updateTurns) end -- 清理上一次的出牌 function zgwrDdzRoomView: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 zgwrDdzRoomView:onResponseOutCards( data ) local function __outCards( onEnd ) if self.tuoguanView and self.tuoguanView:isVisible() then self:hideUI() end local msg = data.response local isContinue = #self._lastCards>0 and self._lastOutType>0 local tplayer = app.room:getPlayer(msg.userId) if not tplayer then return end local viewPos = app.room:getPlayer(msg.userId).viewPos if self._lastOutPos == viewPos or self._lastOutPos == 0 then --连出两轮 for _,v in pairs(self._playerNodes) do v:cleanPass() end -- 清理上一次的出牌 --self:cleanLastCards() isContinue = false end --操作类型,0:pass 1:接牌 2 必须出牌 if msg.opType == 1 or msg.opType == 2 then -- 缓存上次出的牌 self._lastOutPos = viewPos self._lastOutType = msg.cardType app.room.lastOutType = msg.cardType self._lastCards = msg.cards self._opType = msg.opType end self:showTurns(0) local playerNode = self:getPlayerNode(msg.userId) playerNode:setLastOp(msg.cardType, msg.cards, isContinue,msg.showDzFlag) -- playerNode:showLastCards(msg.cards, msg.cardType, isContinue) if msg.cards and #msg.cards > 0 then DdzSoundHelper:playOut() end --玩家剩余牌 local node = self:getPlayerNode(msg.userId) if node and msg.cards and #msg.cards > 0 then 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) end --删完牌后再排位置 self:reCreateHandCards() end if onEnd and type(onEnd)=='function' then onEnd() end end self:addFunction(__outCards) --检查是否多牌 local function checkCardsNums(leftNums) local handCardsNums = self:getHandCardsNums() if leftNums ~= handCardsNums then uploadLogs("doudizhuduopai") self.ui:sendMsg(app.room, "requestGetUserCards"); end end local function __delay( onEnd ) local msg = data.response if msg.userId and app.room:isMyself(msg.userId) then self.ui:runDelay(0.5, function() checkCardsNums(msg.leftNum) end) end self.ui:runDelay(0.5, function() if onEnd and type(onEnd)=='function' then onEnd() end end) end self:addFunction(__delay) end -- 检测手上牌能否一次打出 function zgwrDdzRoomView:checkOnceOut() --获取开房参数 local roomInfo = app.room:getRoomInfo() local gameInfo = roomInfo.nGameInfo local ruleInfo = json.decode(gameInfo) local handCards = self:getHandCards() local bCan, tp = PokerUtil:checkOnceOut(handCards) if bCan then--检测是否少带接完 if tp==ETS.THREE_AND_ONE or tp==ETS.THREE then if not self.ruleIsNotEnough then return false, {} end end -- 是否拥有炸弹 local allBombs = PokerUtil:getAllBomb(handCards, isChoiceAAA) bCan = #allBombs<=0 end return bCan, handCards end -- 玩家自己显示要不起 function zgwrDdzRoomView:showPass() 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 () self:resetSelect() 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:runAction(ac) end -- 春天动画 function zgwrDdzRoomView:showSpring() local node = DdzEffectHelper:getSpring() node:setPosition(cc.p(CENTER_X, CENTER_Y)) self:addChild(node) if node.onEnter and type(node.onEnter)=='function' then node:onEnter() DdzSoundHelper:spring() end end -- 涨水动画 function zgwrDdzRoomView:showZhangShui() local node = DdzEffectHelper:getZhangShui() node:setPosition(cc.p(CENTER_X, CENTER_Y)) self:addChild(node) if node.onEnter and type(node.onEnter)=='function' then node:onEnter() --DdzSoundHelper:spring() end DdzSoundHelper:effectZhangShui() end -- 玩家出牌错误 function zgwrDdzRoomView:onResponseOutCardsErr( data ) local msg = data.response if msg.errFlag == 1 and app.room:isMyself(msg.userId) then self:showTurnBtn(false) elseif msg.errFlag == 5 and app.room:isMyself(msg.userId) then self.ui:sendMsg(app.room, "requestGetUserCards"); end end -- 游戏单局结算 function zgwrDdzRoomView:onResponseGameResult( data ) -- 收到结算有动画,这个时候不让点击手牌 self:setCardsNoTouch() local msg = data.response local maxCards = 0 for _,v in pairs(msg.players) do local pdata = app.room:getPlayer(v.userId) v.unionid = pdata.unionid v.headimgurl = pdata.headimgurl v.gpsInfo = pdata.gpsInfo v.sex = pdata.sex v.openid = pdata.openid v.nickname = pdata.nickname v.areano = pdata.areano end --托管状态有时分数不会刷新,这里刷新容错一下 if self.tuoguanView and self.tuoguanView:isVisible() then for _,v in pairs(msg.players) do local node = self:getPlayerNode(v.userId) if node then node:setScoreNoAnim(v.totalScore) end end end local function __delay( onEnd ) self.ui:runDelay(0.6, function() if onEnd and type(onEnd)=='function' then onEnd() end end) end self:addFunction(__delay) local function __pre( onEnd ) self._gameResult = true for _,v in pairs(msg.players) do local node = self:getPlayerNode(v.userId) if node then node:setScore(v.totalScore, false,v.turnScore) node:setTurn(false) end node:hideLeft() v.leftCards = v.leftCards or {} if #v.leftCards > maxCards then maxCards = #v.leftCards end end local isSpring = msg.spring for _,v in pairs(msg.players) do local node = self:getPlayerNode(v.userId) --self:cleanSelfCards() self:showLeftCards(node:getInfo().viewPos, v.leftCards or {}) end local delay = maxCards *0.02+0.5 + 1--加一秒钟延时显示确认,点确认时有可能还在飘分,防止飘分过程中点确认删掉了飘分动画影响最终分数显示 if tonumber(isSpring) == 1 then self.ui:runDelay(0.1, function() self:showSpring() end) end local function __onEnd() if onEnd and type(onEnd)=='function' then onEnd() end end self.ui:runDelay(delay, __onEnd ) end self:addFunction(__pre) local function __showResult( onEnd ) local msg = data.response --是不是最后一局 local roomInfo = app.room:getRoomInfo() msg.isLast = msg.isGameOver == 1--roomInfo.nGameStartCount>=roomInfo.nTotalGameNum msg.ruleString = WRDDZDefine.getWanFaInfo(roomInfo.nGameInfo) if not msg.isLast then msg.isLast = msg.stopFlag==8 or msg.stopFlag==9 end self._resultMsg = msg self._resultMsg.players = msg.players self._resultMsg.isLast = msg.isLast self._resultMsg.ruleString = msg.ruleString self._resultMsg.gameStartCount = msg.gameStartCount self._resultMsg.totalGamenum = roomInfo.nTotalGameNum --self._resultMsg.stopFlag = msg.stopFlag --self._resultMsg.dipaiCard = msg.dipaiCard for _,v in pairs(self._playerNodes) do v:hideLeft() end self:showRstComfirm(true) self:onClickButtonRstComfirm() if onEnd and type(onEnd)=='function' then onEnd() end end self:addFunction(__showResult) end -- 总结算 function zgwrDdzRoomView:onResponseGameOver( data ) setShowCountAll(true) app.room:dispatchEvent({name = GAME_EVENT.DISSMISS_CLOSE}); local msg = data.response for _,player in ipairs(msg.players) do local pdata = app.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 app.room:updateFlag( player.userId, 0 ) end local function __over( onEnd ) -- 缓存结算信息 self._isGameOver = true self._gameOverData = msg local roomInfo = app.room:getRoomInfo() self._gameOverData.nShowTableId = roomInfo.nShowTableId app.room.roomInfo.nShowTableId = roomInfo.nShowTableId self._gameOverData.startCount = roomInfo.nGameStartCount self._gameOverData.totalCount = roomInfo.nTotalGameNum self._gameOverData.roomRule = WRDDZDefine.getWanFaInfo(roomInfo.nGameInfo) if self.tuoguanView then self:showTuoGuan(false) end if self._gameResult==false then--已经展示过小结算后解散房间 self:onNormalShowGameOver() end if onEnd and type(onEnd)=='function' then onEnd() end end self:addFunction(__over) app.club_php:dispatchEvent({name = GAME_EVENT.CLUB_BACK_ROOM}) end --[[先显示小局结算,再显示总结算--]] function zgwrDdzRoomView:onNormalShowGameOver( data ) self._gameResult = false local showFunc = function (msg) local view = import("pk_zgwrddz.luaScript.Views.Room.Sub.zgwrDdzGameOverView"):new(msg) view:setAnchorPoint(cc.p(0.5, 0.5)) app:showWaitDialog(view) stopBGMusic() self:showGameOverAward() end if self._isGameOver and self._gameOverData then showFunc(self._gameOverData) end end ---------------------------------------------------------------------------------------------------------------------- ---------------------------------------------------------------------------------------------------------------------- -- 单局结算显示剩余牌 function zgwrDdzRoomView:showLeftCards( pos, cards ) --如果是主视角,手牌已经显示了 if pos == 1 then return end self:showTurnBtn(false) if #cards <=0 then return end self:clearPosShow(pos) --if pos==4 or pos == 5 then local tmp = {} for _,v in ipairs(cards) do table.insert(tmp, 1, v) end cards = tmp --end local root = cc.Node:create() local nodes = {} for i,card in ipairs(cards) do local node = self:genCard(card) local pt = cc.p(0, 25) if pos==1 then pt.x = pt.x + (i-1)*DdzRoomViewConfig.CARD_DLT_WIDTH*DdzRoomViewConfig.CARD_SCALE[2] node:setLocalZOrder(100+i) else local rowNum = 13 if i>rowNum then pt.y = pt.y - 40 if i > 2*rowNum then pt.y = pt.y - 40 end if pos == 2 or pos == 3 then --(i-math.floor((i)/rowNum)*rowNum-1) pt.x = pt.x - (i-1)%rowNum*DdzRoomViewConfig.CARD_DLT_WIDTH*DdzRoomViewConfig.CARD_SCALE[2] 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*DdzRoomViewConfig.CARD_SCALE[2] end else if pos == 2 or pos == 3 then pt.x = pt.x - (i-1)%rowNum*DdzRoomViewConfig.CARD_DLT_WIDTH*DdzRoomViewConfig.CARD_SCALE[2] node:setLocalZOrder(16-i) else pt.x = pt.x + (i-1)%rowNum*DdzRoomViewConfig.CARD_DLT_WIDTH*DdzRoomViewConfig.CARD_SCALE[2] 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 else dltWidth = #cards/2*DdzRoomViewConfig.CARD_DLT_WIDTH*DdzRoomViewConfig.CARD_SCALE[2] end root:setPosition(rpt) self.cardRoot: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.02), cc.CallFunc:create(function () v:setVisible(true) end))) end end -- 清除某玩家的出牌 function zgwrDdzRoomView:clearPosShow(pos) local pNode = self:getPlayerNodeVpos(pos) if pNode then pNode:cleanLastCards() end end -- 添加玩家节点 function zgwrDdzRoomView:addPlayerNode( pInfo ) local node = self._playerNodes[pInfo.userId] if node then return end node = DdzPlayerNode:new() node:setPlayMode(self:getMode()) local gameInfo = app.room:getRoomInfo().nGameInfo local data = json.decode(gameInfo) local rule = tonumber(data.playRule) node:setGameInfo(gameInfo) node:setMaxPlayerCount(app.room:getRoomInfo().nMaxPlayCount) node:setShowNum(true) --node:setShowNum(getNumBand(rule, 0x0020)>0)--是否显示牌张数 node:setInfo(pInfo) node:setReady(pInfo.playFlag==1) node:setOffline((pInfo.onlineStatus and pInfo.onlineStatus==0)) --node:setHost(pInfo.userId==app.room:getRoomInfo().nRoomOwnedUid) node:setHost(false) node:setPosition(DdzRoomViewConfig.PLAYER_POS[self:getMode()][pInfo.viewPos]) self._playerNodes[pInfo.userId] = node node:setLocalZOrder(10) if app.room:isMyself(pInfo.userId) then node:setLocalZOrder(12) end self.ui.Items.toolPanel:addChild(node) -- self.panelMenu:getParent():addChild(node) -- 将玩家加入到chatView self.chatView:addPlayer(pInfo.userId) end -- 删除玩家节点 function zgwrDdzRoomView: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 -- 将玩家从chatView移除 self.chatView:delPlayer(uid) end -- 获取玩家节点 function zgwrDdzRoomView:getPlayerNode( uid ) return self._playerNodes[uid] end -- 根据视图获取玩家节点 function zgwrDdzRoomView:getPlayerNodeVpos( viewPos ) for _,v in pairs(self._playerNodes) do if v:getInfo().viewPos==viewPos then return v end end return nil end ---------------------------------------------------------------------------- -- 检查拖牌节点 function zgwrDdzRoomView:checkTouches( pt ) local rect = nil local node = nil --[[for i,v in ipairs(self._selfCards) do if cc.rectContainsPoint(v:getRect(), pt) then node = v break end end--]] for i = #self._selfCards,1,-1 do v = self._selfCards[i] if v and (not tolua.isnull(v)) and cc.rectContainsPoint(v:getRect(), pt) then node = v break end end return node end ---------------------------------------------------------------------------- function zgwrDdzRoomView:touchBegan( pt ) if self._gameResult then return end self._selectCards = {} self.touchDir = 0 local node = self:checkTouches(pt) if not tolua.isnull(node) and node and node:getUniqueFlag() then self._selectCards[node:getUniqueFlag()] = node node.istouching = true if node:isDown() then node:setNormal() else node:setDown() end end --self:doSelectColor() end ---------------------------------------------------------------------------- function zgwrDdzRoomView:touchMoved( pt ) if self._gameResult then return end local node = self:checkTouches(pt) if not tolua.isnull(node) and node and node:getUniqueFlag() and not self._selectCards[node:getUniqueFlag()] and (not node.istouching) then self._selectCards[node:getUniqueFlag()] = node node.istouching = true if node:isDown() then node:setNormal() else node:setDown() end --只要有弹起,第一次弹下置为true self.firstDown = true elseif not tolua.isnull(node) and node and node:getUniqueFlag() and self._selectCards[node:getUniqueFlag()] and (not node.istouching) then if self.firstDown then self.firstDown = false for _,snode in pairs(self._selectCards) do if (snode and not tolua.isnull(snode)) and snode.istouching then snode.istouching = false if snode:isDown() then snode:setNormal() else snode:setDown() end self._selectCards[snode:getUniqueFlag()] = nil break end end end self._selectCards[node:getUniqueFlag()] = nil node.istouching = true if node:isDown() then node:setNormal() else node:setDown() end end if tolua.isnull(node) then for _,snode in pairs(self._selectCards) do snode.istouching = false end else for _,snode in pairs(self._selfCards) do if not tolua.isnull(snode) and snode ~= node then snode.istouching = false end end end --self:doSelectColor() end ---------------------------------------------------------------------------- function zgwrDdzRoomView:touchEnded( pt ) if self._gameResult then return end --self:doSelect() local isPointDesk = false--是否点击了桌面 if pt.y > DdzRoomViewConfig.NORMAL_HEIGHT + DdzRoomViewConfig.CARD_HEIGHT/2 and (not self:checkTouches(pt)) then for _,node in pairs(self._selfCards) do if node:isDown() then node:setNormal() end end self:hideCanOutCards() isPointDesk = true end --智能提示 if self.firstTip then self.firstTip = false self:checkAndTip() end --检测选牌是否可点 self:checkSelectCardBtnEnabled() --检测出牌是否可点 self:checkOutCardBtnEnabled() if isPointDesk == true then self.firstTip = true end --所有牌触摸状态置为false for _,snode in pairs(self._selfCards) do if not tolua.isnull(snode) and snode ~= node then snode.istouching = false end end end ---------------------------------------------------------------------------- function zgwrDdzRoomView:doSelect() local i = 0 for _,node in pairs(self._selectCards) do i = i + 1 if not tolua.isnull(node) and node and node.getParent and node:getParent() then if node:isDown() then node:setNormal() else node:setDown() end if i==1 then DdzSoundHelper:selectSnd() end end end self:hideCanOutCards() end ---------------------------------------------------------------------------- function zgwrDdzRoomView:doSelectColor() for _,node in pairs(self._selectCards) do if not tolua.isnull(node) and node and node.getParent and node:getParent() then node:setDownColor() end end end ---------------------------------------------------------------------------- function zgwrDdzRoomView:resetSelect() local i = 0 for _,v in pairs(self._selfCards) do i = i + 1 if v:isDown() then v:setNormal() v:setNormalColor() if i==1 then DdzSoundHelper:selectSnd() end end end self._selectCards = {} end function zgwrDdzRoomView:setCardsNoTouch() for _,v in pairs(self._selfCards) do v:setNoTouch(true) v:setNormal() v:setNormalColor() end self:resetSelect() end ---------------------------------------------------------------------------- -- 获取选择的牌的集合 function zgwrDdzRoomView:getSelected() local sel = {} for _,v in pairs(self._selfCards) do if v:isDown() then table.insert(sel, v:getVal()) end end return sel end -- 添加牌节点监听 function zgwrDdzRoomView:addTouchesListener() local function onTouchBegan(touch, event) local locationInNode = self:convertToWorldSpace(touch:getLocation())--触点 self:touchBegan(locationInNode) return true end local function onTouchMoved(touch, event) local locationInNode = touch:getLocation() self:touchMoved(locationInNode) end local function onTouchEnded(touch, event) local locationInNode = touch:getLocation() self:touchEnded(locationInNode) end local listener1 = cc.EventListenerTouchOneByOne:create() listener1:setSwallowTouches(false) listener1:registerScriptHandler(onTouchBegan,cc.Handler.EVENT_TOUCH_BEGAN ) listener1:registerScriptHandler(onTouchMoved,cc.Handler.EVENT_TOUCH_MOVED ) listener1:registerScriptHandler(onTouchEnded,cc.Handler.EVENT_TOUCH_ENDED ) local eventDispatcher = self.cardRoot:getEventDispatcher() eventDispatcher:addEventListenerWithSceneGraphPriority(listener1, self) end -- 发牌 function zgwrDdzRoomView:sendCards( cards_ ) local cards = pokerSortPdkCards(cards_) local pos = 1 local CardsCount = #cards for i,card in ipairs(cards) do local ac = cc.Sequence:create(cc.DelayTime:create(i*0.02), cc.CallFunc:create(function () self:sendOneCard(card.cid, i, pos, i==CardsCount, CardsCount) if self:getMode()==0 then if i==CardsCount then self:showOtherCards(true) end end end)) self.cardRoot:runAction(ac) end end -- 发一张牌 function zgwrDdzRoomView:sendOneCard( card, i, pos, islast, allCount ) -- local node = self:genCard(card) local node = self:genCard(-1,i)--back node.cid = card node:setScale(DdzRoomViewConfig.CARD_SCALE[pos])--DdzRoomViewConfig.CARD_SCALE_START node:setLast(islast) local endX = DdzRoomViewConfig.HANDCARD_MIDPOS + (allCount-allCount/2+1)*DdzRoomViewConfig.CARD_DLT_WIDTH*DdzRoomViewConfig.CARD_SCALE[1] local pt = cc.p(0, 0) if pos ~= 1 then pt = clone(DdzRoomViewConfig.PLAYER_POS[self:getMode()][pos]) else if allCount > DdzRoomViewConfig.ROW_MAX_CARDS_NUM then allCount = DdzRoomViewConfig.ROW_MAX_CARDS_NUM end local midIdx = allCount/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.INIT_CARD_POS[self:getMode()][pos].y if i == DdzRoomViewConfig.ROW_MAX_CARDS_NUM then node:setLast(true) end else --这里开始排第二列牌 self:setRow2Card(node) --先算出第一排第一张牌的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.INIT_CARD_POS[self:getMode()][pos].y - DdzRoomViewConfig.ROW_SPACING end end node:setPosition(cc.p(endX, pt.y)) node:setLocalZOrder(i) node:setOpacity(0) node:setTag(i) self.cardRoot:addChild(node) local ac = nil if pos ~=1 then ac = cc.Sequence:create(cc.Spawn:create(cc.MoveTo:create(0.05, pt), cc.ScaleTo:create(0.7, DdzRoomViewConfig.CARD_SCALE[pos])), cc.CallFunc:create(function () node:removeFromParent() end)) node:runAction(ac) else ac = cc.Sequence:create(cc.Spawn:create(cc.MoveTo:create(0.05, pt), cc.FadeIn:create(0.1)), cc.CallFunc:create(function () table.insert(self._selfCards, node) DdzSoundHelper:playSend() end), cc.DelayTime:create((i)*0.01), cc.CallFunc:create(function() node:setCard(node.cid) end )) node:runAction(ac) end end -- 发一张牌没有动画 function zgwrDdzRoomView:sendOneCardNoAct( card, i, pos, islast, allCount ) local node = self:genCard(card,i) node:setScale(DdzRoomViewConfig.CARD_SCALE[pos]) node:setLast(islast) local pt = cc.p(0, 0) if pos ~= 1 then pt = clone(DdzRoomViewConfig.INIT_CARD_POS[self:getMode()][pos]) else if allCount > DdzRoomViewConfig.ROW_MAX_CARDS_NUM then allCount = DdzRoomViewConfig.ROW_MAX_CARDS_NUM end local midIdx = math.floor(allCount/2) if i <= DdzRoomViewConfig.ROW_MAX_CARDS_NUM then if i 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 zgwrDdzRoomView: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 zgwrDdzRoomView:removeHandcards(card) for i,v in pairs(self.cardRoot:getChildren()) do if v:getVal() == card then v:removeFromParent(true) break end end end -- 获取当前手牌 function zgwrDdzRoomView:getHandCards() local handCards1 = {} local handCards2 = {} for _,v in pairs(self._selfCards) do if v and not tolua.isnull(v) then table.insert(handCards1, v:getVal()) end end for i,v in pairs(self.cardRoot:getChildren()) do if v and (not tolua.isnull(v)) and type(v.getVal) == 'function' then table.insert(handCards2, v:getVal()) end end if #handCards1 <= #handCards2 then return handCards1 else return handCards2 end end -- 获取当前手牌张数 function zgwrDdzRoomView:getHandCardsNums() local handCards = {} local num = 0 for _,v in pairs(self._selfCards) do num = num + 1 end return num end --重新生成牌 function zgwrDdzRoomView:reCreateHandCards() local handCards = self:getHandCards() self:recoverHandcards(handCards) end --获取某张牌有几张 function zgwrDdzRoomView:getCardsNumInHand(node) if tolua.isnull(node) then return 0 end --大于2的牌返回0 if PokerUtil:getCardValue(node:getVal()) > 10 then return 0 end local num = 0 for i,v in ipairs(self._selfCards) do if PokerUtil:getCardValue(v:getVal()) == PokerUtil:getCardValue(node:getVal()) then num = num + 1 end end return num end -- 重置手牌位置 function zgwrDdzRoomView: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 if allCount > DdzRoomViewConfig.ROW_MAX_CARDS_NUM then allCount = DdzRoomViewConfig.ROW_MAX_CARDS_NUM end local midIdx = allCount/2 for i,v in ipairs(self._selfCards) do if not tolua.isnull(v) then local pt = cc.p(CENTER_X, 0) v:setLordFlagVisible(false) if i <= DdzRoomViewConfig.ROW_MAX_CARDS_NUM then self:setRow1Card(v) if i=4 then v:setTouMingDu(true) else v:setTouMingDu(false) end if i==#self._selfCards and (self._isLorder or self._isDarkLorder) then v:setLordFlagVisible(true) end end end end -- 提示对应的牌 function zgwrDdzRoomView:tipCards( cards, show ) if show ~= nil then return "" end self:resetSelect() 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 zgwrDdzRoomView:cleanSelfCards() self.cardRoot:stopAllActions() for i,v in pairs(self.cardRoot:getChildren()) do if v and (not tolua.isnull(v)) then v:stopAllActions() v:removeFromParent(true) v = nil end end for i = #self._selfCards,1,-1 do table.remove(self._selfCards,i) end self.cardRoot:removeAllChildren() self._selfCards = nil self._selfCards = {} end function zgwrDdzRoomView:cleanShowCards() self._showCards = {{},{},{},{},{}} for _,v in pairs(self._playerNodes) do if v then v:cleanLastCards() end end end -- 二人玩显示另外一组牌 function zgwrDdzRoomView:showOtherCards(is) if is then self.imgOtherCards:setVisible(true) local num = 16 if self.ruleType==2 then num = 15 end self.txtOtherCards:setString(string.format("剩余%d张", num)) else self.imgOtherCards:setVisible(false) end end --发起申请 function zgwrDdzRoomView:onClickFastStart(sender) playBtnEffect() local request = DdzMessage.FastStartRequest:new() request.result = 1 self.ui:sendMsg(app.room, "requestFastStartGame", request) end --是否显示2/3人快速开始按钮 function zgwrDdzRoomView:showFastStart(is) local roomInfo = app.room:getRoomInfo() if not roomInfo.nGameInfo then return end if roomInfo.gameStatus and roomInfo.gameStatus > DdzRoomViewConfig.GameStatus.GAME_STATE_INIT and roomInfo.gameStatus <= DdzRoomViewConfig.GameStatus.GAME_STATE_GAME_OVER then self.ui.Items.Button_fastStart:setVisible(false) else local playerCount = app.room:getPlayerNum() local gameInfo = json.decode(roomInfo.nGameInfo) if true == is and playerCount < roomInfo.nMaxPlayCount and roomInfo.nGameStartCount <= 0 and gameInfo.playnum == 1 then self.ui.Items.Button_fastStart:setVisible(playerCount == 2 or playerCount == 3) else self.ui.Items.Button_fastStart:setVisible(false) end end end -- 服务器广播快速开始 function zgwrDdzRoomView:onBroadcastFaststart(data) local response = data.response local isRemove = false if response.nUserId and response.nStatus then if response.nStatus and response.nStatus == 3 or response.nStatus > 4 then isRemove = true end end if not isRemove then for _,v in ipairs(response.pList) do if response.nStatus and v.nStatus == 3 or v.nStatus > 4 then isRemove = true end end end if response.timeOut <=0 then isRemove = true end logD("zgwrDdzRoomView:onBroadcastFaststart isRemove:"..table.tostring(isRemove)..";self.fastStartRequestView = "..table.tostring(self.fastStartRequestView)) if self.fastStartRequestView == nil then if isRemove then return "" end local requesterId = 0 for _,v in ipairs(response.pList) do if v.nStatus == 1 then requesterId = v.nUserId end end if requesterId <= 0 then return "" end local view = import("pk_zgwrddz.luaScript.Views.Room.zgwrDdzRequestStartView"):new(requesterId) view:setAnchorPoint(cc.p(0.5, 0.5)) view:showItems(response) app:showWaitDialog(view) self.fastStartRequestView = view else if isRemove then local userInfo = app.room.roomInfo.memberList[response.nUserId] self.fastStartRequestView:removeFromParent() self.fastStartRequestView = nil if userInfo then local u = json.decode(userInfo.userInfo) local txt = string.format("玩家【%s】拒绝立即开局", u.nickname) showTooltip(txt) end app.room.roomInfo.quickStartInfo = nil self:showFastStart(true) else self.fastStartRequestView:updateView(response) end end end function zgwrDdzRoomView:onFastStartSucc(data) if self.fastStartRequestView then self.fastStartRequestView:removeFromParent() self.fastStartRequestView = nil end self:showFastStart(false) --self.playerView:setPlayerVisible(false) --self:updateRoomBaseData() --刷新房间玩家位置 if data.response then --删除所有玩家节点 for k,v in pairs(data.response.pList) do self:delPlayerNode(v.nUserId) end self:initChatView() --重新添加玩家节点 local players = app.room:getPlayers() for _, info in pairs(players) do self:addPlayerNode( info ) end end end --是否显示快速开始页面 function zgwrDdzRoomView:isShowFastStartView() do return end --快速开始数据 local roomInfo = app.room:getRoomInfo() if roomInfo then local fastData = {} fastData.response = {} fastData.response.nStatus = roomInfo.userFastStartStatus fastData.response.timeOut = roomInfo.fastStartTimeout fastData.response.pList = {} if roomInfo.fastStartPlayersStatus then for k,v in pairs(roomInfo.fastStartPlayersStatus) do local playerList = {} if v.fastStartStatus and v.fastStartStatus == 1 then --玩家发起申请 fastData.response.nUserId = v.userId end playerList.nStatus = v.fastStartStatus playerList.nUserId = v.userId table.insert(fastData.response.pList, playerList) end end logD("zgwrDdzRoomView:isShowFastStartView roomInfo = "..table.tostring(roomInfo)) logD("zgwrDdzRoomView:isShowFastStartView fastData = "..table.tostring(fastData)) self:onBroadcastFaststart(fastData) end end function zgwrDdzRoomView:onApplicationWillEnterForeground() --从后台返回游戏,但未重连,此时数据未改变 local roomInfo = app.room:getRoomInfo() if roomInfo and roomInfo.nGameStartCount and roomInfo.nGameStartCount <= 0 then --从后台返回游戏时,如果已经开始游戏,则不处理快速开始view self:isShowFastStartView() end end --解析记牌器数据 function zgwrDdzRoomView:calcJiPaiQiData(data) if not data or data == "" then return "" end local jxData = json.decode(data) if jxData then return jxData end end --设置记牌器显示或隐藏 function zgwrDdzRoomView:showJiPaiQi(vis,data) vis = false if vis and vis == true then local roomInfo = app.room:getRoomInfo() local gameInfo = roomInfo.nGameInfo if not gameInfo then return end local ruleInfo = json.decode(gameInfo) local playernum = app.room:getPlayerNum() if ruleInfo and ruleInfo.specialRule and getNumBand(ruleInfo.specialRule, 0x0001)>0 and playernum>2 then self.ui.Items.Layout_jipaiqi:setVisible(true) local leftcardData = self:calcJiPaiQiData(data) if not data then return end for i=1,14 do if leftcardData[tostring(i)] then local nodeStr = string.format("Lable_leftCard_%d",i) self.ui.Items[nodeStr]:setText(leftcardData[tostring(i)]) end end else self.ui.Items.Layout_jipaiqi:setVisible(false) end else --self.ui.Items.Layout_jipaiqi:setVisible(false) end end -- 服务器广播玩家数据发生变化 function zgwrDdzRoomView:onGpsChangeResponse(data) logD("zgwrDdzRoomView:onGpsChangeResponse()") if not data or not data.nUserId then return end local roomInfo = app.room:getRoomInfo() local nUserId = data.nUserId logD("zgwrDdzRoomView:onGpsChangeResponse()", tostring(nUserId)) --self:checkGpsDistance(nUserId,roomInfo.nGameStartCount==0) end function zgwrDdzRoomView:initGpsComponent() if cc.Application:getInstance():getTargetPlatform() == 0 then -- PC不显示GPS return ; end if self.isRecordScene then return end--回放场景直接return local versionCode = getAppVersionCode() versionCode = tonumber(versionCode) or 0 logD("zgwrDdzRoomView:initGpsComponent() versionCode = ", versionCode) if isReviewVersion() then self.ui.Items.btnGps:setVisible(false) return end local function exitRoomCallback() local isGameStart = app.room:getRoomInfo().nGameStartCount > 0 if isGameStart then app.room:requestDismissRoom(1) else self.ui:sendMsg(app.room, "callLeaveRequest"); end end -- 创建 gps 组件 self.gpsComponent = import("luaScript.Views.Room.RoomGpsComponentView"):new(5,self.ui.Items.btnGps,exitRoomCallback,exitRoomCallback) self.gpsComponent:setLocalZOrder(100) self:addChild(self.gpsComponent) -- GPS 按钮 self.ui.Items.btnGps:registerClick(handler(self , self.showGpsView)) -- 我的GPS数据发生变化时检测是否需要通知服务器 --self:bindEvent(app, "onGpsInoChanged", handler(self, self.checkMyGpsNeedUpdate)) --self.isInitCheckGps = false -- 进入时检测一遍我的GPS数据是否需要更新 --self:checkMyGpsNeedUpdate() end --清楚所有闹钟 function zgwrDdzRoomView:clearAllClock() for _,node1 in pairs(self._playerNodes) do node1:setTurn(false) end end -- 检查服务器记录的我的GPS数据是最新的,如果不是,则请求更新 --[[function zgwrDdzRoomView:checkMyGpsNeedUpdate(event) logD("zgwrDdzRoomView:checkMyGpsNeedUpdate()") if self.isInitCheckGps and not event then return end self.isInitCheckGps = true local nMyUserId = app.user.loginInfo.uid local myMemberInfo = app.room:getUserInfo(nMyUserId) or nil if myMemberInfo then local userInfo = json.decode(myMemberInfo) if userInfo then local gpsInfo = userInfo.gpsInfo local isNewest = app.user:isGpsInfoNewest(gpsInfo) logD("zgwrDdzRoomView:checkMyGpsNeedUpdate() gpsInfo is isNewest = ", tostring(isNewest)) if not isNewest then app.room:onGpsChangeRequest(); else logD("zgwrDdzRoomView:checkMyGpsNeedUpdate() gpsInfo is newest") end else logD("zgwrDdzRoomView:checkMyGpsNeedUpdate() userInfo is nil") end else logD("zgwrDdzRoomView:checkMyGpsNeedUpdate() myMemberInfo is nil") end end--]] -- 更新所有玩家的信息到GPS组件 function zgwrDdzRoomView:updateAllGpsInfo() if self.isRecordScene then return end--回放场景直接return --[[local userInfoList = {} for nUserId, memberInfo in pairs(app.room.roomInfo.memberList) do local nSeatId = memberInfo.nSeatId local userInfo = memberInfo.userInfo if userInfo then local userInfo2 = json.decode(userInfo) if userInfo2 then userInfoList[nUserId] = {nSeatId = nSeatId, userInfo = userInfo} end end end--]] local userInfoList = app.room:getUserInfoList() if self.gpsComponent then self.gpsComponent:updateUserInfos(userInfoList) end end -- 服务器广播玩家游戏状态发生变化 function zgwrDdzRoomView:onUpdateGameStatus(data) logD("zgwrDdzRoomView:onUpdateGameStatus()") if data.response.gameStatus == DdzRoomViewConfig.GameStatus.GAME_STATUS_SELECT_CARD then self:clearAllClock() for _,node1 in pairs(self._playerNodes) do if node1 then node1:cleanPass() end end elseif data.response.gameStatus == DdzRoomViewConfig.GameStatus.GAME_STATUS_PLAYING then self:showBgTips(false) end end -- 通知玩家抢地主 function zgwrDdzRoomView:onNoticeGrabLord(data) logD("zgwrDdzRoomView:onNoticeGrabLord()") local function __qiangdizhu(onEnd) local node = self:getPlayerNode(data.response.userId) if app.room:isMyself(data.response.userId) then self:showJiaoDiZhu() end if node then node:setTurn(true) end if onEnd and type(onEnd)=='function' then onEnd() end end self:addFunction(__qiangdizhu) end --无人抢地主重新洗牌 function zgwrDdzRoomView:onShuffleCards(data) logD("zgwrDdzRoomView:onShuffleCards()") self:resetRoundData() self.ui:runDelay(0.0, function() self:showZhangShui() end) --[[local delay = 1.4 local function __onEnd() if onEnd and type(onEnd)=='function' then onEnd() end end self.ui:runDelay(delay, __onEnd )--]] local function __delay( onEnd ) self.ui:runDelay(1.4, function() if onEnd and type(onEnd)=='function' then onEnd() end end) end self:addFunction(__delay) end --广播抢地主结果 function zgwrDdzRoomView:onBroadGrabLordResult(data) logD("zgwrDdzRoomView:onBroadGrabLordResult()") local node = self:getPlayerNode(data.response.userId) if data.response.opType == 0 then--不抢地主 if node then node:showJiaoDiZhu(false) node:setTurn(false) end else local function callback() --清除抢地主桌面上的操作字 for _,node1 in pairs(self._playerNodes) do if node1 then node1:cleanPass() end if node1 ~= node then node1:setTurn(true) end end if node then node:setTurn(false) node:setHost(true) end if app.room:isMyself(data.response.userId) then self._isLorder = true end local roomInfo = app.room:getRoomInfo() roomInfo.nLordId = data.response.userId DdzSoundHelper:effectJiaoDiZhu(node:getInfo().sex,true) end --显示叫地主动画 self:showEffectJiaoDiZhu(node,callback) end self:hideUI() end --将底牌发给地主 function zgwrDdzRoomView:onSendDiCardsToLord(data) logD("zgwrDdzRoomView:onSendDiCardsToLord()") if app.room:isMyself(data.response.userId) then local handcards = self:getHandCards() for i,v in pairs(data.response.cards) do table.insert(handcards,v) end self:recoverHandcards(handcards) --[[local cards = pokerSortPdkCards(handcards) local allCount = 31 for i,card in ipairs(cards) do local index = i self:sendOneCardNoAct(card.cid, index, 1, index==allCount, allCount) end self:resetCardsPos()--]] local node = self:getPlayerNode(data.response.userId) for _,node1 in pairs(self._playerNodes) do if node1 then node1:cleanPass() end if node1 ~= node then node1:setTurn(true) end end self:showBgTips(true,7) end local node = self:getPlayerNode(data.response.userId) node:showLeft(31) self:showDiPai(data.response.cards) end --玩家获取手牌 function zgwrDdzRoomView:onGetUserCards(data) logD("zgwrDdzRoomView:onGetUserCards()") if app.room:isMyself(data.response.userId) then self:recoverHandcards(data.response.cards) end end --通知玩家加倍 function zgwrDdzRoomView:onBroadNoticeDouble(data) logD("zgwrDdzRoomView:onBroadNoticeDouble()") if data.response.isLord == 0 then--玩家加倍 --清楚抢地主桌面上的操作字 for _,node in pairs(self._playerNodes) do if node then node:cleanPass() end end if not app.room:isMyself(data.response.lordUserId) then self:showJiaBei() end else--地主反加倍 if app.room:isMyself(data.response.lordUserId) then self:showFanJiaBei() self:showBgTips(false) end end --self:showBgTips(true,7) end --玩家加倍结果 function zgwrDdzRoomView:onAddMultResult(data) logD("zgwrDdzRoomView:onAddMultResult()") local node = self:getPlayerNode(data.response.userId) local roomInfo = app.room:getRoomInfo() if node then if roomInfo.nLordId and roomInfo.nLordId == data.response.userId then node:showFanJiaBei(data.response.opMult == 1) node:setFanMult(data.response.opMult == 1) node:setTurn(false) else node:showJiaBei(data.response.opMult == 1) node:setMult(data.response.opMult == 1) node:setTurn(false) end end if app.room:isMyself(data.response.userId) then self:showBgTips(true,7) self:hideUI() end end --广播地主选牌(暗地主) function zgwrDdzRoomView:onBroadLordSelectCard(data) logD("zgwrDdzRoomView:onBroadLordSelectCard()") if app.room:isMyself(data.response.userId) then for k,v in pairs(self._selfCards) do local isCanSelect = false for i,j in pairs(data.response.cards) do if v:getVal() == j then isCanSelect = true break end end if isCanSelect then v:setNormal() v:setTouMingDu(false) else v:setNormal() v:setNoTouch( true ) end end self:showXuanAnDiZhu() self:checkSelectCardBtnEnabled() else --显示等待地主选择暗地主 self:showBgTips(true,0) end local node = self:getPlayerNode(data.response.userId) if node then node:setTurn(true) end end --广播玩家选牌结果 function zgwrDdzRoomView:onLordSelectCardResult(data) logD("zgwrDdzRoomView:onLordSelectCardResult()") local handcards = self:getHandCards() self:recoverHandcards(handcards) if data.response.card == 0x0e then--自吃 local function callback() self:showZiChi(true) end local roomInfo = app.room:getRoomInfo() local node = self:getPlayerNode(roomInfo.nLordId) self:showZiChiAnim() self:showZiChi(true) else local function callback() self:showAnDiZhuCard(data.response.card) end DdzSoundHelper:effectSelectAnLordCard() self:showEffectAnDiZhuCard(self.ui.Items.ImageView_andizhupai,data.response.card,callback) end end -- 显示自吃 function zgwrDdzRoomView:showZiChiAnim(bShowAni) local roomInfo = app.room:getRoomInfo() local player = self:getPlayerNode(roomInfo.nLordId)--roomInfo.nLordId if player then local node = cc.ImageView:createNode(); fileName = "pk_zgwrddz/res/ui/zy_wrddz_btns/wrddz_lab_zichi.png" node:setAnchorPoint(cc.p(0.5,0.5)); node:loadTexture(fileName) node:setTag(2000) local pos = player._info.viewPos local pt = clone(DdzRoomViewConfig.SHOW_CARD_POS[player._PlayMode][pos]) node:setPosition(pt) node:setLocalZOrder(1000) node:setScale(0) self:addChild(node) local myself = app.room:getMyself() if myself and myself.viewPos == pos then self._isShowZiChi = true end local actions={ cc.ScaleTo:create(0.1, 1), cc.DelayTime:create(1.1), cc.CallFunc:create(function() end), cc.RemoveSelf:create() } node:runAction(cc.Sequence:create(actions)) end end --告知暗地主玩家 function zgwrDdzRoomView:onNoticeAnLordPlayer(data) logD("zgwrDdzRoomView:onNoticeAnLordPlayer()") if app.room:isMyself(data.response.userId) then self._isDarkLorder = true self:resetCardsPos() end local function callback() local node = self:getPlayerNode(data.response.userId) node:setAnDiZhu(true) end --显示暗地主动画 local function showAnDiZhu() local node = self:getPlayerNode(data.response.userId) self:showEffectAnDiZhu(node,callback) end self.ui:runDelay(0.5, function() showAnDiZhu() end) end --获取可出牌的组合 function zgwrDdzRoomView:onGetOutCardsResult(data) logD("zgwrDdzRoomView:onGetOutCardsResult()") local canOutCards = data.response.byOutCard if canOutCards and type(canOutCards) == 'table' then if #canOutCards == 1 then local cards = self:getSelected() if data.response.byOutCard[1] then app.room:requestOutCards(cards,data.response.byOutCard[1].byOutCard) end elseif #canOutCards > 1 then self:showCanOutCards(canOutCards) end end end function zgwrDdzRoomView:onUpdateGameMult(data) logD("zgwrDdzRoomView:onUpdateGameMult()") local mult = data.response.gameMult self.ui.Items.TextBMFont_beishu:setText(mult) self.ui.Items.TextBMFont_difen:setText("1") end --显示叫地主 function zgwrDdzRoomView:showJiaoDiZhu() self:hideJiaoDiZhu() local ui=loadUI("pk_zgwrddz/res/ui/ui_room/ui_wrddz_jiaodizhu.ui") self.ui.Items.Layout_Menu:addChild(ui) self.jiaodizhu=ui ui.Items.btn_bujiao:registerClick(function() playBtnEffect() self:hideJiaoDiZhu() local request = DdzMessage.GrabLordRequest:new() request.type = 0 self.ui:sendMsg(app.room,"requestGrabLord",request) end) ui.Items.btn_jiaodizhu:registerClick(function() playBtnEffect() self:hideJiaoDiZhu() local request = DdzMessage.GrabLordRequest:new() request.type = 1 self.ui:sendMsg(app.room,"requestGrabLord",request) end) end function zgwrDdzRoomView:hideJiaoDiZhu() if self.jiaodizhu then self.jiaodizhu:removeFromParent() self.jiaodizhu=nil end end --显示加倍 function zgwrDdzRoomView:showJiaBei() self:hideJiaBei() local ui=loadUI("pk_zgwrddz/res/ui/ui_room/ui_wrddz_jiabei.ui") self.ui.Items.Layout_Menu:addChild(ui) self.jiabei=ui ui.Items.btn_bujiabei:registerClick(function() playBtnEffect() self:hideJiaBei() local request = DdzMessage.AddMultRequest:new() request.mult = 0 self.ui:sendMsg(app.room,"requestAddMult",request) end) ui.Items.btn_jiabei:registerClick(function() playBtnEffect() self:hideJiaBei() local request = DdzMessage.AddMultRequest:new() request.mult = 1 self.ui:sendMsg(app.room,"requestAddMult",request) end) end function zgwrDdzRoomView:hideJiaBei() if self.jiabei then self.jiabei:removeFromParent() self.jiabei=nil end end --显示反加倍 function zgwrDdzRoomView:showFanJiaBei() self:hideFanJiaBei() local ui=loadUI("pk_zgwrddz/res/ui/ui_room/ui_wrddz_fanjiabei.ui") self.ui.Items.Layout_Menu:addChild(ui) self.fanjiabei=ui ui.Items.btn_bufan:registerClick(function() playBtnEffect() self:hideFanJiaBei() local request = DdzMessage.AddMultRequest:new() request.mult = 0 self.ui:sendMsg(app.room,"requestAddMult",request) end) ui.Items.btn_fanjiabei:registerClick(function() playBtnEffect() self:hideFanJiaBei() local request = DdzMessage.AddMultRequest:new() request.mult = 1 self.ui:sendMsg(app.room,"requestAddMult",request) end) end function zgwrDdzRoomView:hideFanJiaBei() if self.fanjiabei then self.fanjiabei:removeFromParent() self.fanjiabei=nil end end --选暗地主牌 function zgwrDdzRoomView:showXuanAnDiZhu() self:showBgTips(true,8) self:hideXuanAnDiZhui() local ui=loadUI("pk_zgwrddz/res/ui/ui_room/ui_wrddz_xuanpai.ui") self.ui.Items.Layout_Menu:addChild(ui) self.xuanandizhu=ui ui.Items.btn_xuanpai:registerClick(function() playBtnEffect() local scard = self:getSelected() local cardVal = 0 if scard and #scard == 1 then cardVal = scard[1] else showTooltip("请选择正确张数的牌!") return end self:hideXuanAnDiZhui() local request = DdzMessage.Card:new() request.card = cardVal self.ui:sendMsg(app.room,"requestSelectCard",request) end) ui.Items.btn_zichi:registerClick(function() playBtnEffect() local cardVal = 0x0e self:hideXuanAnDiZhui() local request = DdzMessage.Card:new() request.card = cardVal self.ui:sendMsg(app.room,"requestSelectCard",request) end) end function zgwrDdzRoomView:hideXuanAnDiZhui() if self.xuanandizhu then self.xuanandizhu:removeFromParent() self.xuanandizhu=nil end end --获取手牌中某个值的牌有几张 function zgwrDdzRoomView:getCardsNumByVal(val) local handCards = self:getHandCards() local valCardNums = 0 for i,v in pairs(handCards) do if val == v then valCardNums = valCardNums + 1 end end return valCardNums end --设置暗地主牌 function zgwrDdzRoomView:setSelectAnLordCard() --[[for k,v in pairs(self._selfCards) do local tp , val = pokerParse(v:getVal()) --6-k当中选暗地主牌,且数量大于1 if val >= 1 and val <=8 and self:getCardsNumByVal(v:getVal()) > 1 then v:setNoTouch(false) v:setTouMingDu(false) else v:setNoTouch(true) end end--]] local roomInfo = app.room:getRoomInfo() for k,v in pairs(self._selfCards) do local isCanSelect = false for i,j in pairs(roomInfo.canSelectCards or {}) do if v:getVal() == j then isCanSelect = true break end end if isCanSelect then v:setNormal() v:setTouMingDu(false) else v:setNormal() v:setNoTouch( true ) end end end --恢复顶部底牌和暗地主牌成默认状态(没翻开) function zgwrDdzRoomView:resetTopCardStatus() for i=1,6 do local dipai = string.format("ImageView_dipai_%d",i) if self.ui.Items[dipai] then self.ui.Items[dipai]:loadTexture("wrddz_lcards_back.png",1) end end self.ui.Items.ImageView_andizhupai:loadTexture("wrddz_lcards_back.png",1) self:showZiChi(false) end --显示地主抓的底牌 function zgwrDdzRoomView: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 zgwrDdzRoomView:showAnDiZhuCard(card) local roomInfo = app.room:getRoomInfo() roomInfo.nDarkLordCard = roomInfo.nDarkLordCard or 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 zgwrDdzRoomView:showZiChi(show) self.ui.Items.ImageView_zichi:setVisible(show) end --展示可出的组合牌 function zgwrDdzRoomView:showCanOutCards(outCards) --[[outCards = { [1] = {1,2,3,4,4}, [2] = {1,2,3,4,4}, [3] = {1,2,3,4,4}, [4] = {1,2,3,4,4}, [5] = {1,2,3,4,4}, }--]] local ui=loadUI("pk_zgwrddz/res/ui/ui_room/ui_wrddz_outCardGroup.ui") self.ui.Items.canOutCardsLayout:addChild(ui) self.selectOutCardUI = ui local layoutMidPos = self.selectOutCardUI.Items.Layout_cardGroup:getContentSize().width/2 local cardsZuHeNum = #outCards --小牌大小 (45,57) local bgImgWidth = 0 local bgImgHeight = 0 local rowMaxNum = 13 local isOneLineRow = false--是否一排只放一组 for i,cards in pairs(outCards) do --创建一个空的layout,layout放到组合牌点上 local mLayout = cc.Layout:createNode() --开启触摸 mLayout:setTouchEnabled(true) --设置锚点 mLayout:setAnchorPoint(cc.p(0,0)) --设置大小 mLayout:setSize(cc.size(30 + 40*(#cards.byOutCard),65)) isOneLineRow = #cards.byOutCard > rowMaxNum for j,k in pairs(cards.byOutCard) do local mCard = cc.ImageView:createNode() local cardPng = pokerLPng(k) mCard:setAnchorPoint(cc.p(0,0)) mCard:loadTextureFromPlist(cardPng) mCard:setPosition(0+(j-1)*40,0); mLayout:addChild(mCard,j); end mLayout:registerClick(function() local scards = self:getSelected() app.room:requestOutCards(scards,cards.byOutCard) self:hideCanOutCards() end) local posx = 0 local posy = 0 if isOneLineRow then--一行一个 posx = layoutMidPos-mLayout:getContentSize().width/2 +15 posy = 0 + (i-1) * mLayout:getContentSize().height else--一行两个 --奇数放左边 posx = layoutMidPos - mLayout:getContentSize().width -20 +30 --偶数放右边 if i%2 == 0 then posx = layoutMidPos + 20 end posy = 0 + math.floor((i-1)/2) * mLayout:getContentSize().height end mLayout:setPosition(cc.p(posx,posy)) self.selectOutCardUI.Items.Layout_cardGroup:addChild(mLayout) if isOneLineRow then bgImgWidth = mLayout:getContentSize().width +100 else bgImgWidth = mLayout:getContentSize().width *2 +100 end end if isOneLineRow then bgImgHeight = cardsZuHeNum * 65 +55 else bgImgHeight = math.floor((cardsZuHeNum-1)/2 + 1) * 65 +55 end self.selectOutCardUI.Items.ImageView_bg:setSize(cc.size(bgImgWidth,bgImgHeight)) end function zgwrDdzRoomView:hideCanOutCards() if self.selectOutCardUI then self.selectOutCardUI:removeFromParent() self.selectOutCardUI=nil end end --检查并提示 function zgwrDdzRoomView:checkAndTip() local cards = self:getSelected() local handCards = self:getHandCards() if cards and #cards > 0 then local cards = zgwrDdzPokerUtil2.getOneTip(cards,handCards,self._lastCards,self._lastOutType) self:tipsCard(cards) end end function zgwrDdzRoomView:checkSelectCardBtnEnabled() if tolua.isnull(self.xuanandizhu) then return end local cards = self:getSelected() if cards and #cards == 1 then self.xuanandizhu.Items.btn_xuanpai:setEnabled(true) else self.xuanandizhu.Items.btn_xuanpai:setEnabled(false) end end function zgwrDdzRoomView:checkOutCardBtnEnabled() --do return end if not self.ui.Items.Layout_out:isVisible() then--出牌按钮不可见 return end local curOpType = self.curCanOpFlag or 1 ----0-pass 1-可以出牌也可以pass 2-只能出牌 if curOpType == 0 then--只能pass不用算 return end local cards = self:getSelected() if cards and #cards == 0 then self.ui.Items.Button_out:setEnabled(false) return end local isAllGui = PokerUtil:checkIsAllGui(cards) if isAllGui then self.ui.Items.Button_out:setEnabled(false) return end local tp = PokerUtil:checkType(cards) if curOpType == 2 then--只能出牌 if tp > 0 and tp <100 then self.ui.Items.Button_out:setEnabled(true) else self.ui.Items.Button_out:setEnabled(false) end return end --self._lastOutType if (not DdzRoomViewConfig.isBomb(self._lastOutType)) and DdzRoomViewConfig.isBomb(tp) then self.ui.Items.Button_out:setEnabled(true) elseif DdzRoomViewConfig.isBomb(self._lastOutType) and DdzRoomViewConfig.isBomb(tp) and tp ~= self._lastOutType then if tp > self._lastOutType then self.ui.Items.Button_out:setEnabled(true) else self.ui.Items.Button_out:setEnabled(false) end else if self._lastCards and type(self._lastCards) == 'table' and #self._lastCards > 0 then if #self._lastCards == #cards then if tp == self._lastOutType then if (tp >= ETS.TWO_SMALL_KING and tp <= ETS.TWO_BIG_KING) or (tp >= ETS.FOUR_SMALL_KING and tp <= ETS.FOUR_BIG_KING) then local isHaveGui,guiNum = PokerUtil:checkHaveGui2(cards) local isHaveGuil,guiNuml = PokerUtil:checkHaveGui2(self._lastCards) if guiNum < guiNuml then--双大王(没有癞子)大于一大王一癞子 self.ui.Items.Button_out:setEnabled(true) else self.ui.Items.Button_out:setEnabled(false) end else --最后一手牌牌型的最小值 local lastMinVal = PokerUtil:getCardsMin(self._lastCards,self._lastOutType) --当前手牌牌型的最小值 local curMinVal = PokerUtil:getCardsMin(cards,tp) if curMinVal > lastMinVal then self.ui.Items.Button_out:setEnabled(true) else self.ui.Items.Button_out:setEnabled(false) end end elseif (self._lastOutType == ETS.AIRPLANE_SINGLE and tp == ETS.SAN_SHUN) then local lastMinVal = PokerUtil:getCardsMin(self._lastCards,self._lastOutType) local curMinVal = PokerUtil:getCardsMin(cards,tp) if curMinVal >= lastMinVal then self.ui.Items.Button_out:setEnabled(true) else self.ui.Items.Button_out:setEnabled(false) end else self.ui.Items.Button_out:setEnabled(false) end else self.ui.Items.Button_out:setEnabled(false) end else --self.ui.Items.Button_out:setEnabled(true) end end end --显示状态提示 function zgwrDdzRoomView:showBgTips(vis,status) if vis then self.ui.Items.Layout_tips:setVisible(true) self.ui.Items.Text_tips:setText(STATUS_INFO[status]) else self.ui.Items.Layout_tips:setVisible(false) end end --显示地主动画 function zgwrDdzRoomView:showEffectJiaoDiZhu(node,callback) if not node then return end local sprDiZhu = cc.ImageView:createNode() sprDiZhu:setScale(0.0) sprDiZhu:setAnchorPoint(cc.p(0.5,0.5)) sprDiZhu:loadTexture("pk_zgwrddz/res/ui/zy_room/wrddz_img_lord.png") sprDiZhu:setPosition(CENTER_X,400*g_radio_y); sprDiZhu:setOpacity(150) local desPos if node and node.imgHost then desPos = node.imgHost:getWorldPosition() else desPos = node:getWorldPosition() end local action={ cc.Spawn:create(cc.EaseBackOut:create(cc.ScaleTo:create(0.1,0.6)),cc.FadeTo:create(0.1,255)), cc.ScaleTo:create(0.1,0.5), cc.DelayTime:create(0.1), cc.MoveTo:create(0.3,desPos), cc.CallFunc:create(function() if callback then callback() end end), cc.RemoveSelf:create(), } sprDiZhu:runAction(cc.Sequence:create(action)) self.ui.Items.canOutCardsLayout:addChild(sprDiZhu); end --显示暗地主动画 function zgwrDdzRoomView:showEffectAnDiZhu(node,callback) if not node then return end local sprDiZhu = cc.ImageView:createNode() sprDiZhu:setScale(0.0) sprDiZhu:setAnchorPoint(cc.p(0.5,0.5)) sprDiZhu:loadTexture("pk_zgwrddz/res/ui/zy_room/wrddz_img_anlord.png") sprDiZhu:setPosition(CENTER_X,400*g_radio_y); sprDiZhu:setOpacity(150) local desPos if node and node.imgAndizhu then desPos = node.imgAndizhu:getWorldPosition() else desPos = node:getWorldPosition() end local action={ cc.Spawn:create(cc.EaseBackOut:create(cc.ScaleTo:create(0.1,0.2)),cc.FadeTo:create(0.1,255)), cc.ScaleTo:create(0.1,1), cc.DelayTime:create(0.1), cc.MoveTo:create(0.3,desPos), cc.CallFunc:create(function() if callback then callback() end end), cc.RemoveSelf:create(), } sprDiZhu:runAction(cc.Sequence:create(action)) self.ui.Items.canOutCardsLayout:addChild(sprDiZhu); end --显示暗地主牌动画 function zgwrDdzRoomView:showEffectAnDiZhuCard(node,card,callback) if self.tuoguanView and self.tuoguanView:isVisible() then self:hideUI() end if not node then return end local sprDiZhu = cc.ImageView:createNode() sprDiZhu:setScale(0.0) sprDiZhu:setAnchorPoint(cc.p(0.5,0.5)) local cardPng = pokerLPng(card) sprDiZhu:loadTexture(cardPng,1) sprDiZhu:setPosition(CENTER_X,400*g_radio_y); sprDiZhu:setOpacity(150) local desPos if node and node.imgAndizhu then desPos = node.imgAndizhu:getWorldPosition() else desPos = node:getWorldPosition() end local action={ cc.Spawn:create(cc.EaseBackOut:create(cc.ScaleTo:create(0.1,0.2)),cc.FadeTo:create(0.1,255)), cc.ScaleTo:create(0.1,1), cc.DelayTime:create(0.1), cc.MoveTo:create(0.3,desPos), cc.CallFunc:create(function() if callback then callback() end end), cc.RemoveSelf:create(), } sprDiZhu:runAction(cc.Sequence:create(action)) self.ui.Items.canOutCardsLayout:addChild(sprDiZhu); end -- 提示对应的牌 function zgwrDdzRoomView:tipsCard( cards ) if type(cards) == 'number' then --啥也不做 elseif type(cards) == 'table' then --self:resetSelect() --self:resetCardsPos() local hadSelectNode = {}--先把已经选出的牌标记出来,在选出的牌周围弹牌 for i,node in pairs(self.cardRoot:getChildren()) do if node and node:isDown() then table.insert(hadSelectNode,node) end end --从算出的牌里面删掉已经弹起来的牌 for i,v in pairs(hadSelectNode) do for j = #cards ,1,-1 do if PokerUtil:getCardValue(v:getVal()) == PokerUtil:getCardValue(cards[j]) then table.remove(cards,j) break end end end if #hadSelectNode == 1 then for i,node in pairs(hadSelectNode) do local uniqueFlag = node:getUniqueFlag() for k = uniqueFlag+1,31 do local tnode = self.cardRoot:getChildByTag(k) if tnode then for j = #cards ,1,-1 do if tnode:getVal() == cards[j] or PokerUtil:getCardValue(tnode:getVal()) == PokerUtil:getCardValue(cards[j]) then tnode:setDown() table.remove(cards,j) break end end end end if #cards == 0 then return end for k = uniqueFlag-1,1,-1 do local tnode = self.cardRoot:getChildByTag(k) if tnode then for j = #cards ,1,-1 do if tnode:getVal() == cards[j] or PokerUtil:getCardValue(tnode:getVal()) == PokerUtil:getCardValue(cards[j]) then tnode:setDown() table.remove(cards,j) break end end end end if #cards == 0 then return end end elseif #hadSelectNode == 2 then local node1 = hadSelectNode[1] local node2 = hadSelectNode[2] local uniqueFlag1 = node1:getUniqueFlag() local uniqueFlag2 = node2:getUniqueFlag() for k = uniqueFlag1+1,uniqueFlag2-1 do local tnode = self.cardRoot:getChildByTag(k) if tnode then for j = #cards ,1,-1 do if tnode:getVal() == cards[j] or PokerUtil:getCardValue(v:getVal()) == PokerUtil:getCardValue(cards[j]) then tnode:setDown() table.remove(cards,j) break end end end end if #cards == 0 then return end for k = uniqueFlag2+1,31 do local tnode = self.cardRoot:getChildByTag(k) if tnode then for j = #cards ,1,-1 do if tnode:getVal() == cards[j] or PokerUtil:getCardValue(v:getVal()) == PokerUtil:getCardValue(cards[j]) then tnode:setDown() table.remove(cards,j) break end end end end if #cards == 0 then return end for k = uniqueFlag1-1,1,-1 do local tnode = self.cardRoot:getChildByTag(k) if tnode then for j = #cards ,1,-1 do if tnode:getVal() == cards[j] or PokerUtil:getCardValue(v:getVal()) == PokerUtil:getCardValue(cards[j]) then tnode:setDown() table.remove(cards,j) break end end end end if #cards == 0 then return end end end end --- -- 检测是否可以解散房间 -- @param -- @return -- function zgwrDdzRoomView:checkCanDismiss( ) local onCanDismissCallback = function (info) local nUserId = app.room:getMyUserId() local roomInfo = app.room.roomInfo or {} local canDismiss = (tonumber(info.canDismiss or 1) == 1) or roomInfo.nRoomOwnedUid == nUserId or dd.IClub.isAdmin() if roomInfo.nGameStartCount == 0 and roomInfo.nRoomOwnedUid ~= nUserId then canDismiss = false end self:onCanDismissCallback(canDismiss) end if dd.IClub.getCanDismiss then local canDismiss = dd.IClub.getCanDismiss(onCanDismissCallback) if canDismiss then onCanDismissCallback({canDismiss = canDismiss}) end end end function zgwrDdzRoomView:onCanDismissCallback(canDismiss) if self.ui.Items.Button_Dismiss then self.ui.Items.Button_Dismiss:setEnabled(canDismiss) self.ui.Items.Layout_Dismiss:setEnabled(canDismiss) end end -- 托管通知 function zgwrDdzRoomView:onHostingResponse( data ) --local function onHostingResponseEx(onEnd) local response = data.response -- 如果是我,则显示托管layout界面 if response.nUserId == app.room:getMyUserId() then if response.status == 1 then --托管状态 self:showTuoGuan(true) self:hideUI() elseif response.status == 0 then--取消托管状态 self:showTuoGuan(false) end end local isTuoGuan = response.status == 1 local viewId = app.room:getViewIdByUserId(response.nUserId) local node = self:getPlayerNodeVpos(viewId) if node then node:setTuoGuan(isTuoGuan) end --if onEnd then -- onEnd() --end --end --self:addCallBack(onHostingResponseEx) end --隐藏ui function zgwrDdzRoomView:hideUI() if self.tuoguanView and self.tuoguanView:isVisible() then self:hideJiaoDiZhu() self:hideJiaBei() self:hideXuanAnDiZhui() self:hideFanJiaBei() self:hideCanOutCards() end end --显示隐藏托管 function zgwrDdzRoomView:showTuoGuan(isShow) if not self.tuoguanView then self.tuoguanView = import("pk_zgwrddz.luaScript.Views.Room.RoomTuoGuanView"):new() self:addChild(self.tuoguanView) self.tuoguanView:setVisible(false) end self.tuoguanView:setVisible(isShow) if isShow and isShow == true then self:showTurnBtn(false) end end function zgwrDdzRoomView:refreshPlayerAIStatus() for _,v in pairs(app.room.roomInfo.memberList) do local isTuoGuan = v.AIStatus == 1 print('zgwrDdzRoomView:refreshPlayerAIStatus', v.nUserId, isTuoGuan) local viewId = app.room:getViewIdByUserId(v.nUserId) local node = self:getPlayerNodeVpos(viewId) if node then node:setTuoGuan(isTuoGuan) end if v.nUserId == app.room:getMyUserId() then if isTuoGuan and isTuoGuan == true then --托管状态 self:showTuoGuan(true) end end end end --- -- 初始化大结算再来一局 -- @return -- function zgwrDdzRoomView:initPlayGameAgain() local strGameInfo = app.room.roomInfo.nGameInfo local isInClub = app.club_php.clubID and app.club_php.clubID ~= 0 if not isInClub then logD("zgwrDdzRoomView.initPlayGameAgain", "当前玩家不在亲友圈内,不能再来一局"); return end local clubGameInfo = json.decode(strGameInfo) or {} if not clubGameInfo.ruleid then logD("RoomView_28.initPlayGameAgain", "游戏包间id不存在,不能再来一局"); return end dd.IPlayGameAgain.setAgainGameBaoJianId(clubGameInfo.ruleid) end --- -- 清空lua缓存 -- function zgwrDdzRoomView:cleanCache() local preload = package.loaded for k, v in pairs(package.loaded or {}) do local res = string.find( k, "pk_zgwrddz.luaScript") or 0 if res > 0 then package.loaded[k] = nil end end end --- -- 显示抽奖界面 -- function zgwrDdzRoomView:showGameOverAward() if not (dd and dd.IGameOverAward) then return end self:runDelay(0.1, function ( ) -- 延迟0.1秒执行,可能有些游戏弹大结算的时候还未收到抽奖消息 dd.IGameOverAward.showAwardView(); end) end return zgwrDdzRoomView