|
- local ZPDef = ZPFramework.ZPImport("zp_base.luaScript.ZPDef")
- local ZPFuc = ZPFramework.ZPImport("zp_base.luaScript.ZPFunctions")
- local ZPSound = ZPFramework.ZPImport("zp_base.luaScript.ZPSound")
- local ZPMessage = ZPFramework.ZPImport("zp_base.luaScript.Protocol.ZPMessage")
- local ZPRoomPlayerView=ZPFramework.ZPImport("zp_base.luaScript.Views.Room.ZPRoomPlayerView")
- local ZPRoomToolView=ZPFramework.ZPImport("zp_base.luaScript.Views.Room.ZPRoomToolView")
- local ZPRoomXiaoJuChaPaiView=ZPFramework.ZPImport("zp_base.luaScript.Views.Room.ZPRoomXiaoJuChaPaiView")
- local ZPRoomXiaoJuView=ZPFramework.ZPImport("zp_base.luaScript.Views.Room.ZPRoomXiaoJuView")
- local ZPRoomOperationView=ZPFramework.ZPImport("zp_base.luaScript.Views.Room.ZPRoomOperationView")
- local ZPRoomCard=ZPFramework.ZPImport("zp_base.luaScript.Views.Room.ZPRoomCard")
- local ZPRoomCountAllView=ZPFramework.ZPImport("zp_base.luaScript.Views.Room.ZPRoomCountAllView")
- local ZPRoomPiaoFenView=ZPFramework.ZPImport("zp_base.luaScript.Views.Room.ZPRoomPiaoFenView")
- local ZPRoomSettingView=ZPFramework.ZPImport("zp_base.luaScript.Views.Room.ZPRoomSettingView")
- local ZPRoomQuickStartView=ZPFramework.ZPImport("zp_base.luaScript.Views.Room.ZPRoomQuickStartView")
- local ZPWanFa=ZPFramework.ImportWanFa("luaScript.SubGameDefine.ZiPai.ZPWanFa")
-
- local ZPRoomView = class("ZPRoomView", cc.UIView)
-
- function ZPRoomView:ctor()
- ZPRoomView.super.ctor(self);
- self.Time = nil
- --枚举矩形区域:用于重新排列
- self.lieshulist = {}
- self.lieshulist[1] = {6}
- self.lieshulist[2] = {6,7}
- self.lieshulist[3] = {5,6,7}
- self.lieshulist[4] = {5,6,7,8}
- self.lieshulist[5] = {4,5,6,7,8}
- self.lieshulist[6] = {4,5,6,7,8,9}
- self.lieshulist[7] = {3,4,5,6,7,8,9}
- self.lieshulist[8] = {3,4,5,6,7,8,9,10}
- self.lieshulist[9] = {2,3,4,5,6,7,8,9,10}
- self.lieshulist[10] = {1,2,3,4,5,6,7,8,9,10}
- self.lieshulist[11] = {1,2,3,4,5,6,7,8,9,10,11}
- self.lieshulist[12] = {1,2,3,4,5,6,7,8,9,10,11,12}
- self.lieshulist[13] = {1,2,3,4,5,6,7,8,9,10,11,12,13}
- self.lieshulist[14] = {1,2,3,4,5,6,7,8,9,10,11,12,13,14}
- self.lieshulist[15] = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15}
-
- --枚举矩形非填充区域
- self.lieshuBlanklist ={}
- self.lieshuBlanklist[1] = {1,2,3,4,5,7,8,9,10,11,12,13,14,15}
- self.lieshuBlanklist[2] = {1,2,3,4,5,8,9,10,11,12,13,14,15}
- self.lieshuBlanklist[3] = {1,2,3,4,8,9,10,11,12,13,14,15}
- self.lieshuBlanklist[4] = {1,2,3,4,9,10,11,12,13,14,15}
- self.lieshuBlanklist[5] = {1,2,3,9,10,11,12,13,14,15}
- self.lieshuBlanklist[6] = {1,2,3,10,11,12,13,14,15}
- self.lieshuBlanklist[7] = {1,2,10,11,12,13,14,15}
- self.lieshuBlanklist[8] = {1,2,11,12,13,14,15}
- self.lieshuBlanklist[9] = {1,11,12,13,14,15}
- self.lieshuBlanklist[10] = {11,12,13,14,15}
- self.lieshuBlanklist[11] = {12,13,14,15}
- self.lieshuBlanklist[12] = {13,14,15}
- self.lieshuBlanklist[13] = {14,15}
- self.lieshuBlanklist[14] = {15}
- self.lieshuBlanklist[15] = {}
-
- --牌Layout UI
- self.handCardRoot = {}
- --手牌数组UI
- self.handCardItem = {}
- --牌数据UI
- self.handCardValueLocal = {}
- --手牌数据备份
- self.handCardValueBak = {}
- --扇形最大列数
- self.lieShuMax = 15
- --扇形最大行数
- self.hangShuMax = 4
- --是否出牌
- self.bOutCard = false
- --出牌缩放倍数
- self.outCardScale = 0.95
- --弃牌桌面牌资源缩放倍数
- self.littleCardScale = 1--35/64 --(35为牌背大小,64为大牌大小)
- --组合牌之间的间隔
- self.cardInterval = 0
- self.verticleInterval = 15
- self.moPaiViewId = 1
- --操作码
- self.operationLocalCode = 0
- --玩家跑牌次数
- self.playerZhao = {}
- --重置跑牌次数
- for i = 1,ZPDef.GameMaxPlayer do
- self.playerZhao[i] = 0
- end
- --是否摸牌操作
- self.isMoPaiOperator = false
- --出牌的值
- self.outCard = 1
- --正在执行删除牌操作的时候,保护删除是正常,避免少牌可能性出现
- self.isGodHand = false
- --是否不需要出牌就听牌了
- self.isNoCardTingPai = false
- --听牌本地数据
- self.tingCardLocal = {}
- --桌面胡息
- self.tableHuXiList = {}
- end
-
- function ZPRoomView:loadRoomUI()
- local ui = loadUI("zp_base/res/ui/ui_fangjian/zipai_ui_fangjian.ui");
- self.ui = ui;
- self:addChild(ui);
- end
-
- function ZPRoomView:onEnter()
- ZPRoomView.super.onEnter(self)
- --ui load
- self:loadRoomUI();
- --self.ui.Items.ImageView_test:setVisible(false)
-
- self:setDiPaiVisible(false)
- --初始化音效类型
- self:doSound()
- -- 初始化GPS组件
- self:initGpsComponent();
-
- --加载纹理缓存
- self:loadTextureCache()
- --房间菜单
- self:initRoomMenu()
- --初始化工具层
- self:initToolLayer()
- --初始化游戏事件按钮
- self:initGameButton()
- --初始化基础节点
- self:initBaseNode()
- --水印
- self:initLogo()
- --默认状态
- self:defaultState()
- --监听事件
- self:bindAllEvent()
- --初始化游戏速度
- self:initGameSpeed();
- self:onGameReconnection()
- --起飞
- self:startGame()
- --播放音乐
- local cacheMusic = "gameBgMusic"..(ZPDef.GameID or app.gameId)
- local defaultValue = tonumber(loadUserInfo(cacheMusic)) or 1
- ZPSound.PlayGameBGM(defaultValue)
-
- self:initPlayGameAgain()
- end
- ---
- -- 初始化大结算再来一局
- -- @return
- --
- function ZPRoomView:initPlayGameAgain()
- local strGameInfo = app.room.roomInfo.strGameInfo
- local isInClub = app.club_php.clubID and app.club_php.clubID ~= 0
- if not isInClub then
- logD("IPlayGameAgain.initPlayGameAgain", "当前玩家不在亲友圈内,不能再来一局");
- return
- end
-
- local clubGameInfo = json.decode(strGameInfo) or {}
- if not clubGameInfo.ruleid then
- logD("IPlayGameAgain.initPlayGameAgain", "游戏包间id不存在,不能再来一局");
- return
- end
-
- dd.IPlayGameAgain.setAgainGameBaoJianId(clubGameInfo.ruleid)
- end
-
- function ZPRoomView:initGameSpeed()
- --速度配置:
- if ZPFuc.getGameSpeed() == ZPDef.SPEED.NORMAL then
- self.gameSpeedConfig = ZPDef.GameTimeConfig;
- elseif ZPFuc.getGameSpeed() == ZPDef.SPEED.SLOW then
- self.gameSpeedConfig = ZPDef.GameTimeConfigSlow;
- else
- self.gameSpeedConfig = ZPDef.GameTimeConfig;
- end
-
- logD("当前游戏的速度配置:",table.tostring(self.gameSpeedConfig));
- end
-
- function ZPRoomView:doSound()--1 普通话 2 方言
- local ZiPaiLanguageType = "ZiPaiLanguageType"..app.gameId
- local languageType = tonumber(loadUserInfo(ZiPaiLanguageType)) or ZPDef.GameLanguageType.PU_TONG_HUA
- ZPSound.setCurLanguage(idx)
- end
-
- function ZPRoomView:startGame()
- --起飞
- app.net:onMsgResume()
- end
-
- function ZPRoomView:loadTextureCache()
- --听牌
- ZPFuc.loadSpriteFromFile("zp_base/res/ui/zy_fangjian/zipai_tingCard.plist")
- ZPFuc.loadSpriteFromFile("zp_base/res/ui/zy_fangjian/zipai_fangjian.plist")
- --字牌
- local cacheGameCard = "ZPCardType"..(ZPDef.GameID or app.gameId)
- local cardTypeRes = tonumber(loadUserInfo(cacheGameCard)) or ZPDef.defaultCardRes
- ZPFuc.loadSpriteFromFile(string.format("zp_base/res/ui/zy_fangjian/card/zp_tp%d_card.plist",cardTypeRes))
- end
-
- function ZPRoomView:initBaseNode()
- --自己的出生坐标,视图是4
- self.boxPosList4 = {}
- local weaveCardPos4 = self.ui.Items.Layout_StartPos:getPosition()
- for i = 1, self.lieShuMax do
- --矩形3
- self.boxPosList4[i] = cc.p(weaveCardPos4.x + 90 * (i - 1),weaveCardPos4.y)--手牌间隙改这里
- end
- --坐标记录
- self.srcOutCardPosList = {}
- self.scorePosList = {}
- for k = 1,ZPDef.GameMaxPlayer do
- local name = string.format("Layout_outCardPoint_%d",k)
- local imgName = string.format("ImageView_outCardImg_%d",k)
- self.ui.Items[name]:setScale(self.outCardScale)
- self.srcOutCardPosList[k] = self.ui.Items[imgName]:getPosition()
- --操作分数坐标
- --name = string.format("TextBMFont_Score_%d",k)
- --self.scorePosList[k] = self.ui.Items[name]:getPosition()
- end
-
- --初始化扎鸟
- self.PlayerView:initPlayerPiaoFenByRule()
-
- local timestr = os.date("%y-%m-%d %H:%M:%S")
- self.ui.Items.Text_systemTime:setText(timestr)
- --定时器
- if not self.Time then
- self.Time = cc.Director:getInstance():getScheduler():scheduleScriptFunc(function ()
- local timestr = os.date("%y-%m-%d %H:%M:%S")
- self.ui.Items.Text_systemTime:setText(timestr)--(getTimeString())
- end,1.0,false)
- end
- --听牌背景原始高度
- self.tingPaibgSrcHeight = self.ui.Items.ImageView_TingPai_bg:getContentSize().height
- end
-
- function ZPRoomView:onExit()
- ZPRoomView.super.onExit(self)
- --关闭定时器
- if self.Time then
- cc.Director:getInstance():getScheduler():unscheduleScriptEntry(self.Time)
- end
-
- if self.taiPaiTimer then
- cc.Director:getInstance():getScheduler():unscheduleScriptEntry(self.taiPaiTimer)
- end
-
- app.room:dispatchEvent({name = "onGameOverResponse"});
-
- stopBGMusic()
- self:cleanCache()
- end
- ---
- -- 子游戏调用
- function ZPRoomView:intCleanCacheList(list)
- logD("ZPRoomView:intCleanCacheList", "弃用,请删除接口相关调用!")
- end
- ---
- -- 子游戏调用
- function ZPRoomView:addCleanCacheList(list)
- logD("ZPRoomView:addCleanCacheList", "弃用,请删除接口相关调用!")
- end
- ---
- -- 清除lua缓存
- -- @return
- --
- function ZPRoomView:cleanCache()
- local clearList = {'zp_base.luaScript'};
- local subGameConfig=getSubGameConfig(app.gameId) or {}
- table.insert(clearList, subGameConfig.rootName)
-
- while (subGameConfig and subGameConfig.fremworkId and subGameConfig.fremworkId > 0) do
- subGameConfig = getSubGameConfig(subGameConfig.fremworkId)
- if not subGameConfig or not subGameConfig.rootName then
- break
- end
- table.insert(clearList, subGameConfig.rootName)
- end
-
- local preload = package.loaded
- for luaPath, _ in pairs(package.loaded or {}) do
- for __, str in ipairs(clearList or {}) do
- local res = string.find( luaPath, str) or 0
- if res > 0 then
- package.loaded[luaPath] = nil
- end
- end
- end
- end
-
- function ZPRoomView:initGameButton()
- --出牌按钮
- self.ui.Items.Button_OutCard:registerClick(function ()
- local k = self.ui.Items.ImageView_handTempCard.cIdx
- local value = self.ui.Items.ImageView_handTempCard.value
- --send sender
- self.isGodHand = true;
- self.handCardItem[k]:setOpacity(0)
- self:setColorWhite()
- self:sendOutCard(value)
- self.bOutCard = false
- end)
- --提牌按钮
- self.ui.Items.Button_tipai:registerClick(function ()
- self:onTransferCard(self.handCardValueBak)
- end)
- --暂时屏蔽提牌功能
- self:showTiPaiBtn(true)
-
- --点击空白
- self.ui.Items.Layout_Touch:registerClick(nil, function ()
- --[[if self.messageView then
- self.messageView:onClickBG()
- end--]]
-
- --隐藏工具界面 详情
- if self.toolView.ui.Items.ImageView_Rule_bg then
- self.toolView.ui.Items.ImageView_Rule_bg:setVisible(false)
- end
- self.ui.Items.Layout_Rule:setVisible(false)
- self.ui.Items.Button_wanfa:setVisible(true)
- end)
-
- -- 玩法
- self.ui.Items.Button_wanfa:registerClick(function ()
- playBtnEffect()
- self.ui.Items.Layout_Rule:setVisible(not self.ui.Items.Layout_Rule:isVisible())
- self.ui.Items.Button_wanfa:setVisible(false)
- end)
-
- if app.room.roomInfo.nGameStartCount and app.room.roomInfo.nGameStartCount > 0 then
- self.ui.Items.Layout_Rule:setVisible(false)
- else
- self.ui.Items.Layout_Rule:setVisible(true)
- self.ui.Items.Button_wanfa:setVisible(false)
- self.ui.Items.Layout_Rule:runAction(cc.Sequence:create(
- cc.DelayTime:create(2),
- cc.CallFunc:create(function ()
- self.ui.Items.Layout_Rule:setVisible(false)
- self.ui.Items.Button_wanfa:setVisible(true)
- end)))
- end
- self.ui.Items.Text_Rule:setVisible(false)
- local bar = self.ui.Items.ListView:getVBar()
- bar:setVisible(false)
- end
-
- -- 设置房间信息
- function ZPRoomView:setRoomInfo()
- self.ui.Items.ListView:removeAllChildren()
- self.ui.Items.ListView:getInnerContainer():setAutoSize(true)
- local rules = ZPWanFa.getClubRuleInfo(app.room.roomInfo.strGameInfo)
- for k,v in pairs(rules) do
- local text = self.ui.Items.Text_Rule:getCopied()
- text:setVisible(true)
- if v.name == "封顶" then
- text:setString(tostring(v.name..v.value[1]))
- else
- text:setString(tostring(v.value[1]))
- end
- self.ui.Items.ListView:addChild(text)
- end
- self.ui.Items.ListView:jumpToTopOnSizeChanged();
- end
-
- function ZPRoomView:initToolLayer()
- --人物头像层
- self.PlayerView = ZPRoomPlayerView:new()
- self.ui.Items.Layout_Player:addChild(self.PlayerView)
-
- --操作界面(吃碰杠胡)
- self.operationView = ZPRoomOperationView:new(self)
- self.ui.Items.Layout_Tool:addChild(self.operationView)
-
- --加载工具层
- self.toolView = ZPRoomToolView:new()
- self.ui.Items.Layout_Tool:addChild(self.toolView)
-
- --[[ -- 添加语音相关的界面
- self.messageView = import("Views.Room.ZiPaiRoomMessageView"):new()
- self:addChild(self.messageView)--]]
- local headInfos = {}
- for k,v in pairs(self.PlayerView.allNodes) do
- if k == 2 then
- local pos = cc.pAdd(v.player:getPosition(),cc.p(39,39))
- table.insert(headInfos,{headPos=pos})
- elseif k == 4 then
- local pos = cc.pAdd(v.player:getPosition(),cc.p(50,50))
- table.insert(headInfos,{headPos=pos})
- elseif k == 3 then
- local pos = cc.pAdd(v.player:getPosition(),cc.p(50,50))
- table.insert(headInfos,{headPos=pos})
- elseif k == 1 then
- local pos = cc.pAdd(v.player:getPosition(),cc.p(185,50))
- table.insert(headInfos,{headPos=pos})
- end
- end
- -- self.messageView = require("luaScript.Views.Room.ChatView"):new({chatList=ZPDef.LUZHOUDAER_GAME_CHAT_TXT},headInfos,false)
- -- self.toolView.ui.Items.Layout_ChatView:addChild(self.messageView)
- -- --self.messageView:setBtnFace(cc.p(1232,134),"zp_room_btn_kjy.png")
- -- --self.messageView:setBtnVoice(cc.p(1232,50),"zp_room_btn_yuyin.png")
- -- self.messageView:setBtnFace(cc.p(0.9625, 0.1861111),"zp_room_btn_kjy.png")
- -- self.messageView:setBtnVoice(cc.p(0.9625, 0.0694444),"zp_room_btn_yuyin.png")
-
- -- 小局查牌界面
- self.xiaojuChaPaiView = ZPRoomXiaoJuChaPaiView:new()
- self.xiaojuChaPaiView:setVisible(false)
- --亮牌界面确定
- local function cb()
- --显示小局结算
- if self.xiaojuView then
- self.xiaojuView:setVisible(true)
- end
- end
- self.xiaojuChaPaiView:setQueDingCallBack(cb)
- self.xiaojuChaPaiView:showHuCardCallBack(handler(self , self.onShowHuCard))
- self:addChild(self.xiaojuChaPaiView)
- end
-
-
- --隐藏剩余牌层
- function ZPRoomView:setCircleCardLeftPanelView(bVisible,viewId,leftNum)
- self.leftNum = leftNum
- --[[self.ui.Items.Layout_circleCardLeft:setVisible(bVisible)
-
- for i = 1, ZPDef.GameMaxPlayer do
- local name = string.format("ImageView_arrow_%d",i)
- self.ui.Items[name]:setVisible(false)
- end
-
- self.ui.Items.Text_num:setText(tostring(self.leftNum))
-
- --乌龟壳
- if bVisible then
- local name = string.format("ImageView_arrow_%d",viewId)
- self.ui.Items[name]:setVisible(true)
- end--]]
- self:setFaPaiQiPanelView(bVisible,viewId,leftNum)
- if viewId and not self.isRecordStart then
- self.PlayerView:setPClockVisible(viewId,true)
- end
- end
-
- function ZPRoomView:setFaPaiQiPanelView(bVisible,viewId,leftNum)
- if viewId and leftNum then
- if not self.fapaiqiLeftCard then
- self.fapaiqiLeftCard = {}
- local bgsize = self.ui.Items.ImageView_card_bg:getContentSize()
- for i = 1,tonumber(leftNum) do
- self.fapaiqiLeftCard[i] = cc.ImageView:createNode()
- self.fapaiqiLeftCard[i]:loadTextureFromPlist("zp_room_fapaiqi_cardBg1.png")
- self.ui.Items.ImageView_card_bg:addChild(self.fapaiqiLeftCard[i])
- self.fapaiqiLeftCard[i]:setPosition(cc.p(bgsize.width/2,bgsize.height/2+i))
- end
- else
- for i = #self.fapaiqiLeftCard,leftNum+1,-1 do
- if self.fapaiqiLeftCard[i] then
- self.fapaiqiLeftCard[i]:removeFromParent()
- self.fapaiqiLeftCard[i] = nil
- end
- end
- end
- self.ui.Items.TextBMFont_leftCardNum:setText(tostring(self.leftNum))
- end
- end
-
- function ZPRoomView:defaultState()
- --队列初始化
- self.callbackQueue = {}
- self.callbackRunning = false
-
- self.PlayerView:setOffLine(false)
- self.PlayerView:setPlayerVisible(false)
- self:resetGameData()
- --第一局清理托管标志,后面每局开始不清理(不然会出现没有取消托管,托管标志不显示bug)
- self.PlayerView:setTuoGuanFlagVisible(false)
- end
-
- function ZPRoomView:resetGameData()
- logE("===========重置游戏数据===============")
- self.handCardRoot = {}
- self.handCardValueLocal = {}
- self.handCardValueBak = {}
- self:setOutCardLineVisible(false)
- self:setWetChatVisible(false)
- self:setBtnSitDownVisible(false)
- self:setOutCardVisible(false)
- self:setOperatorPanelView(false)
- self:setGuideView(false)
- self:setHandTempCardVisible(false)
- self:setCircleCardLeftPanelView(false)
- self:setLiangPaiVisible(false)
- self:setTingCardViewVisible(false)
- self:setDingPiaoVisible(false)
- self:setLayoutScoreTipVisible(false)
- if self.PlayerView then
- self.PlayerView:setReadyStateVisible(false)
- self.PlayerView:setBankerVisible()
- self.PlayerView:setOperatorTipVisible(false)
- self.PlayerView:setAllClockVisible(false)
- self.PlayerView:hideLeftCard()
- end
-
- --隐藏工具界面 详情
- if self.toolView.ui.Items.ImageView_Rule_bg then
- self.toolView.ui.Items.ImageView_Rule_bg:setVisible(false)
- end
- --隐藏操作吃界面
- self.operationView:setAllEatView(false)
-
- --操作码
- self.operationLocalCode = 0
- self.isMoPaiOperator = false
- self.isGameOver = false
- self.isTianHu = false
- self.isGodHand = false
- --听牌重置
- self.isNoCardTingPai = false
- self.tingCardLocal = {}
- self.tableHuXiList = {}
- --弃牌
- self.qiPaiList = {}
- --发牌器
- if self.ui.Items.ImageView_card_bg then
- self.ui.Items.ImageView_card_bg:removeAllChildren()
- end
- self.fapaiqiLeftCard = nil
- self.ui.Items.TextBMFont_leftCardNum:setText("0")
- --庄家爆牌标志
- self.bankerBaoPao = nil
- --移除所有的牌局
- self.ui.Items.LayoutMain_4:removeAllChildren()
- if self.ui.Items.Layout_Player_HuEffect then
- self.ui.Items.Layout_Player_HuEffect:removeAllChildren()
- end
- self:clearXJChaPaiView()
-
- for i = 1, ZPDef.GameMaxPlayer do
- local giveupName = string.format("Layout_giveUp_%d",i)
- local weaveCardName = string.format("Layout_player1Table_%d",i)
- --移除胡牌的时候点炮
- local outCardImgName = string.format("ImageView_outCardLight_%d",i)
- --重置开招次数
- self.playerZhao[i] = 0
- --弃牌数组
- self.qiPaiList[i] = {}
- self.ui.Items[weaveCardName]:removeAllChildren()
- self.ui.Items[giveupName]:removeAllChildren()
- self.ui.Items[outCardImgName]:removeAllChildren()
- end
- self.PlayerView:setHuXizero()
-
- if self.xiaojuView then
- self.xiaojuView:removeFromParent()
- self.xiaojuView = nil
- end
-
- if self.xiaojuChaPaiView then
- self.xiaojuChaPaiView:setVisible(false)
- end
-
- --停止一些动画
- self.ui:stopAllActions()
-
-
- logD("self.ui:stopAllActions()")
- end
-
- function ZPRoomView:setLayoutScoreTipVisible(bVisible,scoreData,isFirstHand,onEnd,isHuPai)
- --self.ui.Items.Layout_ScoreTip:setVisible(bVisible)
- end
-
- function ZPRoomView:setDingPiaoVisible(bVisible)
- if self.piaoView then
- self.piaoView:removeSelf()
- self.piaoView = nil
- end
- if bVisible then
- self.piaoView = ZPRoomPiaoFenView:new()
- self:addChild(self.piaoView)
- end
- end
-
- --重置出牌坐标
- function ZPRoomView:resetOutCardPoint()
- for i = 1 ,ZPDef.GameMaxPlayer do
- local imgName = string.format("ImageView_outCardImg_%d",i)
- local mSprite = self.ui.Items[imgName]
- mSprite:setPosition(self.srcOutCardPosList[i])
- end
- end
-
- --改变外发光颜色
- function ZPRoomView:changeOutCardLight(isMoPai)
- for i = 1 ,ZPDef.GameMaxPlayer do
- local outCardLightName = string.format("ImageView_outCardLight_%d",i)
- local light = self.ui.Items[outCardLightName]
- local fileName
- if isMoPai then
- fileName = ZPDef.LightType.BLUE
- else
- fileName = ZPDef.LightType.YELLOW
- end
- light:loadTextureFromPlist(fileName)
- end
- end
-
- --隐藏出牌点
- function ZPRoomView:setOutCardVisible(bVisible,viewId,card,isSend,onEnd,isNoShowAni)
- for i = 1 ,ZPDef.GameMaxPlayer do
- local name = string.format("Layout_outCardPoint_%d",i)
- self.ui.Items[name]:setVisible(false)
- end
-
- --重置出牌坐标
- self:resetOutCardPoint()
- --显示出牌
- if bVisible then
- self.isMoPaiOperator = false
- self:changeOutCardLight(false)
- local name = string.format("Layout_outCardPoint_%d",viewId)
- local mLayout = self.ui.Items[name]
- mLayout:setVisible(true)
- local imgName = string.format("ImageView_outCardImg_%d",viewId)
- local fileName = ZPFuc.getZPCardImgByValue(card,ZPDef.CardType.CARD_TYPE_OUTCARD)
- local mSprite = self.ui.Items[imgName]
- local srcPos = mSprite:getPosition()
- self.ui.Items[imgName]:loadTextureFromPlist(fileName)
- self.ui.Items[imgName].value = card
-
- local beginPos
- local time = self.gameSpeedConfig.CHU_PAI_TIME
- if viewId == self:getMeViewId() then
- beginPos = self.ui.Items.ImageView_handTempCard:getPosition()
- beginPos = mSprite:getParent():convertToNodeSpace(beginPos)
- else
- if viewId == 1 then
- beginPos = cc.p(srcPos.x + 400,srcPos.y)
- elseif viewId == 2 then
- beginPos = cc.p(srcPos.x,srcPos.y + 200)
- elseif viewId == 3 then
- beginPos = cc.p(srcPos.x - 400,srcPos.y)
- end
- end
-
- mSprite:setPosition(beginPos)
- mSprite:setScale(0)
-
- if isNoShowAni then
- mSprite:setScale(1)
- mSprite:setPosition(srcPos)
- if onEnd then
- onEnd()
- end
- return
- end
-
- local spawn = cc.Spawn:create(cc.ScaleTo:create(time,1,1),cc.MoveTo:create(time,srcPos))
- local seq = cc.Sequence:create(spawn,cc.CallFunc:create(function ()
- if isSend then
- local request = ZPMessage.OutCard:new()
- request.nCard = card
- logE("ZPRoomView:setOutCardVisible"..table.tostring(request))
- self.ui:sendMsg(app.room, "sendOutCard", request, function (status, response)
- logE("ZPRoomView sendOutCard() response = ", table.tostring(response))
- end)
- end
- if onEnd then
- onEnd()
- end
- end))
- mSprite:runAction(seq)
- end
- end
-
- --设置出牌线为隐藏
- function ZPRoomView:setOutCardLineVisible(bVisible)
- self.ui.Items.ImageView_line:setVisible(bVisible)
- end
-
- --隐藏行为操作层
- function ZPRoomView:setOperatorPanelView(bVisible,operations)
- self.operationView:setOperatorPanelView(bVisible,operations)
- end
-
- --隐藏提示界面
- function ZPRoomView:setGuideView(bVisible)
- if app.room:isLittleFamily() then
- bVisible = false
- end
- self.ui.Items.Layout_tips:setVisible(bVisible)
- self.ui.Items.Button_OutCard:setVisible(bVisible)
- self.ui.Items.Button_OutCard:setEnabled(false)
- if bVisible then
- self.ui.Items.ImageView_3:playClip("tip")
- end
- end
-
- function ZPRoomView:setColorWhite()
- if app.room:isLittleFamily() and not ZPFuc.getLittleIsCanLookCard() then
- return
- end
- self.ui.Items.Button_OutCard:setEnabled(false)
- for col = 1, self.lieShuMax do
- for row = 1,self.hangShuMax do
- if not self.handCardRoot[col].imgList[row].isKan then
- self.handCardRoot[col].imgList[row]:setColor(cc.c3b(255,255,255))
- end
- end
- end
- end
-
- --展示牌
- function ZPRoomView:setHandTempCardVisible(bVisible)
- self.ui.Items.ImageView_handTempCard:setVisible(bVisible)
- end
-
- --更新房间基础数据
- function ZPRoomView:updateRoomBaseData()
- --初始化背景
- local ZiPaigameBgPicture = "gameBgPicture"..(ZPDef.GameID or app.gameId)
- local idx2 = tonumber(loadUserInfo(ZiPaigameBgPicture)) or 4
- self:setTableImg(idx2)
-
- local roomInfo = app.room.roomInfo;
-
- -- 房间号
- self.ui.Items.Text_roomNum:setText(tostring(roomInfo.nShowTableId));
-
- --局数
- self:updateGameNums()
-
- --房间玩法
- --local ruleAll = ZPFuc.getRuleInfo();
- --self.toolView.ui.Items.Text_Rule:setText(ruleAll)
- self:setRoomInfo()
-
- self:onUserReadyResponse()
-
- for i = 1,ZPDef.GameMaxPlayer do
- self.PlayerView:updatePlayerInfo(i)
- end
-
- -- 是否显示邀请好友
- self:setWetChatVisible(app.room:getActualPlayerNum() < ZPFuc.getCreateRoomPlayerNum())
- self.toolView:showFastStart(true)
-
- if isReviewVersion() then
- self:setWetChatVisible(false);
- end
-
- -- 更新玩家手牌列表时,按需显示
- if app.room.roomInfo.nGameStartCount > 0 then
- self:setWetChatVisible(false)
- end
- if app.room.roomInfo.nGameStartCount == 0 then
- if self.ui.Items.Button_tipai then
- self.ui.Items.Button_tipai:setVisible(false)
- end
- end
- end
-
- function ZPRoomView:onGameReconnection()
- --logE("ZiPai当前版本号:"..ZPFuc.getZPCurVersion())
- --更新房间基础数据
- self:updateRoomBaseData()
-
- local roomInfo = app.room.roomInfo;
-
- --self:updateAllGpsInfo()
- --self:checkGpsDistance(nil,roomInfo.nGameStartCount==0)
- --self:checkMyGpsNeedUpdate();
-
- --断线重连
- if roomInfo.nGameStartCount > 0 then
- local function runOnGameReconnection(onEnd)
- local roomInfo = app.room.roomInfo;
- --显示庄家
- self:updateBanker()
- self:showOwner()
- local myUserID = app.room:getMyRecordUserId()
- --解散状态
- local isDismiss = false
- local uid = 0
- for k,v in pairs(roomInfo.arrayTableInfo) do
- local viewId = app.room:getViewIdByUserId(k)
- local nOffLineState = v.nOnlineStatus
- --显示离线
- self.PlayerView:setPlayerOffLine(nOffLineState ~= 1,viewId)
-
- local viewId = app.room:getViewIdByUserId(k)
- --记录玩家解散状态 0:初始状态, 1:发起解散 2: 同意解散 3:不同意解散
- app.room.dismissInfo[k] = v.nDisbandStatus;
- --有人发起解散时才显示解散界面
- if v.nDisbandStatus == 1 then
- isDismiss = true
- uid = k
- end
- end
- self.PlayerView:setXiaoJiaFlagVis(true)
-
- --有人发起解散时才显示解散界面
- if isDismiss then
- app.room.roomInfo.nDismissStateTime = roomInfo.nDismissStateTime;
- app.room.roomInfo.nDismissToTalTime = roomInfo.nDismissToTalTime;
-
- local view = require("luaScript.Views.Room.RoomDismissView"):new(uid,app.room.roomInfo.memberList,roomInfo.nDismissStateTime)
- view:setAnchorPoint(cc.p(0.5, 0.5));
- app:showWaitDialog(view);
- end
-
- --如果一局结束,玩家点了准备,不再显示牌信息
- if ZPDef.ReconnectState.GAME_STATUS_ROUND_OVER == roomInfo.nStatus and roomInfo.memberList[myUserID].nPlayerFlag == 1
- or ZPDef.ReconnectState.GAME_STATUS_GAME_OVER == roomInfo.nStatus and roomInfo.memberList[myUserID].nPlayerFlag == 1
- then --游戏为停止或开始状态
- self:onUserReadyResponse()
- self.ui.Items.Button_tipai:setVisible(false)
- if onEnd then
- onEnd()
- end
- return
- end
-
- -- 托管状态恢复
- for k,v in pairs(roomInfo.tuoGuanInfo or {}) do
- local aiStatus = v.aiStatus;
- local nUserID = v.nUserID;
- local viewId = app.room:getViewIdByUserId(nUserID)
- local isTuoGuan = aiStatus == 1;
- if self:getIsMeUId(nUserID) then
- if isTuoGuan then
- self:showTuoGuan(true)
- self.isTuoGuan = true
- else
- self:showTuoGuan(false)
- self.isTuoGuan = false
- end
-
- end
- self.PlayerView:showTuoGuanByViewId(viewId,isTuoGuan)
- end
-
- --胡牌类型
- local huType = ZPDef.ReconnectHuType.NO_HU
-
- --状态显示
- if ZPDef.ReconnectState.GAME_STATUS_ROUND_OVER == roomInfo.nStatus
- or ZPDef.ReconnectState.GAME_STATUS_GAME_OVER == roomInfo.nStatus then --游戏为停止或开始状态
- self.ui.Items.Button_tipai:setVisible(false)
- --显示小局结算亮牌画布
- self:setLiangPaiVisible(true)
- --显示底牌
- self.xiaojuChaPaiView:showDiPai()
- --亮手牌
- huType = self.xiaojuChaPaiView:liangShouPai(true)
-
- local function nextCallBackFun()
- self:resetGameData()
- end
-
- self.xiaojuView = ZPRoomXiaoJuView:new(nextCallBackFun,true)
-
- self:addChild(self.xiaojuView)
-
- --播放黄庄动画
- if roomInfo.stopFlag == ZPDef.XiaoJuEndType.STOP_FLAG_HUANG_ZHUANG then
- self.xiaojuChaPaiView:PlayHuangZhuangAni(false)
- end
-
- self.xiaojuView:setVisible(false)
-
- self:setBtnSitDownVisible(false)
- end
-
- local diPaiMax = table.nums(roomInfo.dipaiList)
- for k,v in pairs(roomInfo.arrayTableInfo) do
- local viewId = app.room:getViewIdByUserId(k)
- local nScore = v.nTotalMoney or 0
-
- --玩家分数
- self.PlayerView:setPlayerScore(viewId,nScore)
- --扎鸟
- self.PlayerView:setPlayerPiaoFen(viewId,v.nZhaBirdScore)
-
- --恢复手牌
- if k == myUserID then
- self:createCard(false,myUserID,nil)
- end
-
- --恢复爆牌动画
- if v.nBaoPaiStatus == 2 and not (ZPDef.ReconnectState.GAME_STATUS_ROUND_OVER == roomInfo.nStatus
- or ZPDef.ReconnectState.GAME_STATUS_GAME_OVER == roomInfo.nStatus) then
- self.PlayerView:playBaoAnim(viewId)
- end
-
- local hushu = 0
- --恢复组合牌
- for key,value in pairsByKeys(v.tableWeaveCard) do
- local list,operationType = ZPFuc.getZPCardList(value.card,value.type)
- local isShow = true
- local card = value.opcard
- hushu = hushu + value.hushu
- --记录真实数据
- --过滤:碰胡和偎胡,坎提胡,坎跑胡 的组合牌不显示,这些组合牌在self:liangShouPai()里后面插回手里
- if ZPDef.ReconnectState.GAME_STATUS_ROUND_OVER == roomInfo.nStatus
- or ZPDef.ReconnectState.GAME_STATUS_GAME_OVER == roomInfo.nStatus then
- if roomInfo.stopFlag == ZPDef.XiaoJuEndType.STOP_FLAG_NORMAL then
- local nUserId = roomInfo.winUserId
- local viewId = app.room:getViewIdByUserId(nUserId)
- local huCard = roomInfo.huCard
- --不等于赢家的ID,组合牌就全部显示,赢家的需要判断
- if nUserId == k then
- if huType == ZPDef.ReconnectHuType.WEI_HU and operationType == ZPDef.OpType.OP_TYPE_MINGWEI and huCard == card then
- isShow = false
- elseif huType == ZPDef.ReconnectHuType.WEI_HU and operationType == ZPDef.OpType.OP_TYPE_ANWEI and huCard == card then
- isShow = false
- elseif huType == ZPDef.ReconnectHuType.PENG_HU and operationType == ZPDef.OpType.OP_TYPE_PENG and huCard == card then
- isShow = false
- elseif huType == ZPDef.ReconnectHuType.KAN_TI_HU and operationType == ZPDef.OpType.OP_TYPE_TI and huCard == card then
- isShow = false
- elseif huType == ZPDef.ReconnectHuType.KAN_PAO_HU and operationType == ZPDef.OpType.OP_TYPE_PAO and huCard == card then
- isShow = false
- end
- end
- end
- end
-
- --对于要显示的牌,除了一些普通的牌需要展示外,特殊的有:偎提胡,偎跑胡,碰跑胡,这个时候,组合牌还是显示偎,偎,跑的原先模样
- if isShow then
- if ZPDef.ReconnectState.GAME_STATUS_ROUND_OVER == roomInfo.nStatus
- or ZPDef.ReconnectState.GAME_STATUS_GAME_OVER == roomInfo.nStatus then
- if roomInfo.stopFlag == ZPDef.XiaoJuEndType.STOP_FLAG_NORMAL or
- roomInfo.stopFlag == ZPDef.XiaoJuEndType.STOP_FLAG_HU_DIRTY then
- local nUserId = roomInfo.winUserId
- local viewId = app.room:getViewIdByUserId(nUserId)
- --如果赢的是当前的人组合牌需要稍微处理下
- if nUserId == k then
- local huCard = roomInfo.huCard
- if operationType == ZPDef.OpType.OP_TYPE_TI and huCard == card and huType == ZPDef.ReconnectHuType.WEI_TI_HU then
- --偎提胡(结算亮一张偎牌,这里处理为明偎)
- operationType = ZPDef.OpType.OP_TYPE_MINGWEI
- elseif operationType == ZPDef.OpType.OP_TYPE_PAO and huCard == card and huType == ZPDef.ReconnectHuType.PENG_PAO_HU then
- --碰跑胡
- operationType = ZPDef.OpType.OP_TYPE_PENG
- elseif operationType == ZPDef.OpType.OP_TYPE_PAO and huCard == card and huType == ZPDef.ReconnectHuType.WEI_PAO_HU then
- --偎跑胡(结算亮一张偎牌,这里处理为明偎)
- operationType = ZPDef.OpType.OP_TYPE_MINGWEI
- end
- end
- end
- end
-
- list = ZPFuc.getOpCardFirstList(operationType,list,card)
-
- --上面吃或不吃不要用if else因为还可能都不成立
- local isMoPaiOrId = value.seatId
- self:recontactDoOperation(operationType,viewId,list,card,isMoPaiOrId)
- end
- end
- self.tableHuXiList[viewId] = hushu
- self.PlayerView:setPlayerHuXi(viewId,hushu)
- --self.PlayerView:setPlayerHuXi("油:"..tostring(hushu))
- end
- self:getLocalHuShu()
-
- for i = 1, 4 do
- local tt = self.qiPaiList[i]
- end
-
- --恢复弃牌
- for k,v in pairs(roomInfo.arrayTableInfo) do
- local viewId = app.room:getViewIdByUserId(v.nUserId)
- local qiList = self.qiPaiList[viewId]
- for key,value in pairs(v.desertedArea) do
- local card = value.card
- local maxQi = table.nums(qiList)
- if maxQi > 0 then
- --染色弃牌
- local isInQiList = false
- for qiK,qiCard in pairs(qiList) do
- if qiCard == value.card then
- --染色弃牌
- self:playQiPaiAni(false,value.card,viewId,nil,true)
- isInQiList = true
- qiList[qiK] = nil
- break
- end
- end
- if not isInQiList then
- self:playQiPaiAni(false,value.card,viewId,nil,false)
- end
- else
- --普通弃牌
- self:playQiPaiAni(false,value.card,viewId,nil,false)
- end
- end
- end
-
- --听牌显示
- local max = table.nums(app.room.roomInfo.tingCards)
- if max > 0 then
- self:setTingCardViewVisible(true,app.room.roomInfo.tingCards)
- end
-
- --显示玩家剩余手牌
- if app.room.roomInfo.offLineInfo and next(app.room.roomInfo.offLineInfo) ~= nil then
- for i,v in pairs(app.room.roomInfo.offLineInfo) do
- if v.extInfo then
- local extIf = json.decode(v.extInfo)
- if extIf.LeftCard and v.nUserId then
- local viewId = app.room:getViewIdByUserId(v.nUserId)
- self.PlayerView:setLeftCardNum(viewId,true,tonumber(extIf.LeftCard))
- end
- end
- end
- end
-
- --状态显示
- if ZPDef.ReconnectState.GAME_STATUS_ROUND_OVER == roomInfo.nStatus
- or ZPDef.ReconnectState.GAME_STATUS_GAME_OVER == roomInfo.nStatus then --游戏为停止或开始状态
- self.PlayerView:hideLeftCard()
- --所有的暗偎默认亮起一张
- self:showLastAnWeiPai()
- --点炮显示
- self:showPaoImage()
- for hi,hv in pairs(app.room.roomInfo.hupaiInfo) do
- if hv.huPaiUid > -1 then
- local winerViewId = app.room:getViewIdByUserId(hv.huPaiUid)
- app.room.roomInfo.huType = hv.huTypes
- self:playHuEffect(winerViewId,nil,true)
- --self:setLayoutScoreTipVisible(true,playerList,false,nil,true)
- end
- end
- elseif ZPDef.ReconnectState.GAME_STATUS_WAIT_OP_TIAN_HU == roomInfo.nStatus
- or ZPDef.ReconnectState.GAME_STATUS_WAIT_OP_AFTER_TURN_OVER == roomInfo.nStatus
- or ZPDef.ReconnectState.GAME_STATUS_WAIT_OP_AFTER_OUTCARD == roomInfo.nStatus then -- 天胡,翻牌后等待玩家操作中,出牌后等待玩家操作中
- local nSeatId = roomInfo.showCardSeatId
- local nCard = roomInfo.showCard
- local operateCode = roomInfo.mainOpCode
- local viewId = app.room:getViewIdBySeatId(nSeatId)
- local nUserId = app.room:getUserIdBySeatId(nSeatId)
-
- --记录真实数据
- self.outCard = nCard
- self.EatOperationCode = operateCode
- self.moPaiViewId = viewId
-
- --显示剩余牌
- self:setCircleCardLeftPanelView(true,viewId,diPaiMax)
-
- if ZPDef.ReconnectState.GAME_STATUS_WAIT_OP_TIAN_HU == roomInfo.nStatus then
- --标记天胡
- self.isTianHu = true
- if viewId == self:getMeViewId() then
- self:showOpeation(ZPDef.OpCode.OP_HU,viewId)
- end
- elseif ZPDef.ReconnectState.GAME_STATUS_WAIT_OP_AFTER_OUTCARD == roomInfo.nStatus then
- --是否已经操作过 0表示没有,非0表示已经提交了操作
- if operateCode ~= ZPDef.OpCode.OP_CANCEL and roomInfo.isSubmitOp == 0 then
- self:showOpeation(operateCode)
- self:setOutCardVisible(true,viewId,nCard,false,nil,true)
- elseif roomInfo.isSubmitOp == 1 or roomInfo.isSubmitOp == 0 then
- self:setOutCardVisible(true,viewId,nCard,false,nil,true)
- --playVoiceCardValue(nCard,nUserId)
- elseif roomInfo.isSubmitOp == 2 then --比牌不显示出牌或者摸牌
- self.operationView:touchEatOneCardCallBack(true)
- end
- elseif ZPDef.ReconnectState.GAME_STATUS_WAIT_OP_AFTER_TURN_OVER == roomInfo.nStatus then
- if roomInfo.isSubmitOp == 1 then
- operateCode = 0
- self:playMoPaiAni(diPaiMax,nCard,viewId,operateCode,roomInfo.showCardFlag,nil,true)
- elseif roomInfo.isSubmitOp == 0 then
- self:playMoPaiAni(diPaiMax,nCard,viewId,operateCode,roomInfo.showCardFlag,nil,true)
- elseif roomInfo.isSubmitOp == 2 then --比牌不显示出牌或者摸牌
- self.operationView:touchEatOneCardCallBack(true)
- end
- end
- elseif ZPDef.ReconnectState.GAME_STATUS_WAIT_OUT_CARDS == roomInfo.nStatus then --等待玩家出牌中
- --显示底牌
- local viewId = app.room:getViewIdBySeatId(roomInfo.showCardSeatId)
- --显示剩余牌
- self:setCircleCardLeftPanelView(true,viewId,diPaiMax)
- if viewId == self:getMeViewId() then
- self:setGuideView(true)
- self.bOutCard = true
- end
- elseif ZPDef.ReconnectState.GAME_STATUS_AUTO_DISCSRD == roomInfo.nStatus then --玩家自动弃牌中
- local nSeatId = roomInfo.showCardSeatId
- local nCard = roomInfo.disCard
- local viewId = app.room:getViewIdBySeatId(nSeatId)
- --显示剩余牌
- self:setCircleCardLeftPanelView(true,viewId,diPaiMax)
- --弃牌
- self:playQiPaiAni(true,nCard,viewId,nil)
- elseif ZPDef.ReconnectState.GAME_STATUS_WAIT_OP_BAO == roomInfo.nStatus then --等待玩家爆牌中
- --爆牌中
- local viewId = app.room:getViewIdBySeatId(roomInfo.showCardSeatId)
- self:setCircleCardLeftPanelView(true,viewId,diPaiMax)
- for k,v in pairs(roomInfo.arrayTableInfo) do
- local viewId = app.room:getViewIdByUserId(k)
- --等待爆牌状态
- if v.nBaoPaiStatus == 1 and k == app.user.loginInfo.uid then
- self.operationView:showBaoPaiOpView(true)
- end
- end
- end
-
- if onEnd then
- onEnd()
- end
- end
- log("2000000000-ZPRoomView - self:addCallBack(runOnGameReconnection)" )
- self:addCallBack(runOnGameReconnection)
-
- else
- --未开局正常坐下这里会进来
- for k,v in pairs(roomInfo.memberList) do
- local viewId = app.room:getViewIdByUserId(k)
- local nOffLineState = v.nOnlineStatus or 1
- --显示离线
- self.PlayerView:setPlayerOffLine(nOffLineState ~= 1,viewId)
- end
-
- --未开局重连坐下
- for k,v in pairs(roomInfo.arrayTableInfo or {}) do
- local viewId = app.room:getViewIdByUserId(k)
- local nOffLineState = v.nOnlineStatus
- --显示离线
- self.PlayerView:setPlayerOffLine(nOffLineState ~= 1,viewId)
- end
- end
- end
-
-
- --断线重连
- function ZPRoomView:recontactDoOperation(operationType,viewId,list,card,isMoPaiOrId)
- if operationType == ZPDef.OpType.OP_TYPE_CHI then
- self:createEatView(card,viewId,list,false,nil,nil)
- elseif operationType == ZPDef.OpType.OP_TYPE_PENG then
- self:createPengView(viewId,list,false,isMoPaiOrId)
- elseif operationType == ZPDef.OpType.OP_TYPE_ANWEI then
- self:createWeiPaiView(viewId,list,false,false)
- elseif operationType == ZPDef.OpType.OP_TYPE_MINGWEI then
- self:createWeiPaiView(viewId,list,false,true)
- elseif operationType == ZPDef.OpType.OP_TYPE_PAO or operationType == ZPDef.OpType.OP_TYPE_CHONG_PAO then
- self:createTiOrPaoView(false,viewId,list,false,nil)
- elseif operationType == ZPDef.OpType.OP_TYPE_TI then
- self:createTiOrPaoView(true,viewId,list,false,nil)
- end
- end
-
- --隐藏微信按钮
- function ZPRoomView:setWetChatVisible(bVisible)
- self.toolView.ui.Items.btnInvite:setVisible(bVisible)
- self.toolView:setInviteClubVisible(bVisible)
- self.toolView:updateButtonPosition()
- end
-
- --隐藏准备按钮
- function ZPRoomView:setBtnSitDownVisible(bVisible)
- self.toolView.ui.Items.Button_Ready:setVisible(bVisible)
- end
-
- function ZPRoomView:bindAllEvent()
- if self.isRecordScene then return end
- --[[
- 消息分类管理
- ]]
- --用户状态(包括准备,其他玩家进入或者离开通知,离线等)
- self:bindUserStatedMessage()
-
- --私人场消息(包括解散等)
- self:bindPrivateMessage()
-
- --游戏消息
- self:bindGameMessage()
-
- --游戏场景消息
- self:bindGameSceneMessage()
-
- --绑定更换桌布事件
- self:bindEvent(app , "onChangeTable" , handler(self , self.onChangeTable));
- --操作按钮点击事件
- self:bindEvent(app , "onClickOpBtn" , handler(self , self.onClickOpBtn));
-
- self:bindEvent(app , ZPDef.ZPEvent.ChangeViewType , handler(self , self.onChangeCard));
- end
-
- function ZPRoomView:onChangeCard(data)
- self:loadTextureCache()
- --手牌
- for k,v in ipairs(self.handCardRoot) do
- if v.ui:isVisible() then
- for _,ui in ipairs(v.imgList) do
- if ui.value then
- local fileName = ZPFuc.getZPCardImgByValue(ui.value,ZPDef.CardType.CARD_TYPE_HAND)
- if fileName ~= "" then
- ui:loadTextureFromPlist(fileName)
- end
- end
- end
- end
- end
- --组合牌
- for i = 1,4 do
- local name = string.format("Layout_player1Table_%d",i)
- local UnitCardNode = self.ui.Items[name]
- if UnitCardNode then
- for k,mLayout in ipairs(UnitCardNode:getChildren()) do
- if mLayout.cardList ~= nil then
- for idx,ui in ipairs(mLayout:getChildren()) do
- if mLayout.cardList[idx] then
- local fileName = ZPFuc.getZPCardImgByValue(mLayout.cardList[idx],ZPDef.CardType.CARD_TYPE_TABLE)
- if fileName ~= "" then
- ui:loadTextureFromPlist(fileName)
- end
- end
- end
- end
- end
- end
- end
-
- --出牌
- for viewId = 1, 4 do
- local imgName = string.format("ImageView_outCardImg_%d",viewId)
- local mSprite = self.ui.Items[imgName]
- if mSprite.value then
- local fileName = ZPFuc.getZPCardImgByValue(mSprite.value,ZPDef.CardType.CARD_TYPE_OUTCARD)
- if fileName ~= "" then
- self.ui.Items[imgName]:loadTextureFromPlist(fileName)
- end
- end
- end
-
- --弃牌
- for i = 1,4 do
- local giveupCardname = string.format("Layout_giveUp_%d",i)
- local giveUpLayout = self.ui.Items[giveupCardname]
- for k,mSprite in ipairs(giveUpLayout:getChildren()) do
- if mSprite.value then
- local fileName = ZPFuc.getZPCardImgByValue(mSprite.value,ZPDef.CardType.CARD_TYPE_TABLE)
- if fileName ~= "" then
- mSprite:loadTextureFromPlist(fileName)
- end
- end
- end
- end
-
- --吃牌
- if self.operationView then
- if self.operationView:getEatCardVisible() then
- self.operationView:setEatBtnEnabledTrue()
- --显示吃牌的节点
- self.operationView:setEatCardView(false)
- self.operationView:setEatCardBiView(false)
- self.operationView:setEatCardSanBiView(false)
- end
- end
-
- end
-
- function ZPRoomView:onChangeTable(data)
- local idx = data.idx
- self:setTableImg(idx)
- end
- --点击了操作按钮,在等服务器下发消息回来之前,禁止拖动操作
- function ZPRoomView:onClickOpBtn(data)
- self.isGodHand = true
- --防止一直卡住的情况
- local seq = cc.Sequence:create(cc.DelayTime:create(2.0),cc.CallFunc:create(function ()
- self.isGodHand = false
- end))
- self:runAction(seq)
- end
-
- function ZPRoomView:setTableImg(idx)
- local name = string.format("res/ui/zy_fangjian/bg/fangjian_di_%d.png",idx)
- --桌布
- self.ui.Items.ImageView_bg:loadTexture(name)
-
- local cacheGameBgPic = "gameBgPicture"..(ZPDef.GameID or app.gameId)
- saveUserInfo(cacheGameBgPic,idx)
- --self.toolView.ui.Items.ImageView_menubg:setVisible(false)
- end
-
- function ZPRoomView:initLogo()
- if tolua.isnull(self.ui.Items.ImageView_Logo) then return end
- if not (type(getSubGameRoomLogo) == 'function') then--大厅不支持此方法,则隐藏logo
- self.ui.Items.ImageView_Logo:setVisible(false);
- return
- end
- local strGameInfo = app.room.roomInfo.strGameInfo or ""
- local gameInfo = json.decode(strGameInfo) or {}
- local gamerule = tonumber(gameInfo.gamerule or 1)
- local logofile = getSubGameRoomLogo(ZPDef.GameID or app.gameId,gamerule)
- 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 ZPRoomView:initRoomMenu()
- if not tolua.isnull(self.roomMenuView) then
- return
- end
-
- local RoomMenuViewClass = require("zp_base.luaScript.Views.Components.ZPRoomMenuView");
- self.roomMenuView = RoomMenuViewClass:new()
- self:addChild(self.roomMenuView)
-
-
- if self.ui.Items.Layout_Menu then
- self.ui.Items.Layout_Menu:setVisible(false)
- end
-
- if self.ui.Items.Layout_menu then
- self.ui.Items.Layout_menu:setVisible(false)
- end
-
- if self.ui.Items.Button_menu then
- self.ui.Items.Button_menu:setVisible(false)
- end
- end
-
- --用户状态消息
- function ZPRoomView:bindUserStatedMessage()
- --默认状态
- self:bindEvent(app.room , "defaultState" , handler(self , self.defaultState));
- -- 玩家准备
- self:bindEvent(app.room , "onUserReadyResponse" , handler(self , self.onUserReadyResponse));
- -- 其他玩家进入房间
- self:bindEvent(app.room , "onOtherSitDownResponse" , handler(self , self.onOtherSitDownResponse));
- -- 其他玩家退出房間
- self:bindEvent(app.room , "onOtherLogoutResponse" , handler(self , self.onOtherLogoutResponse));
- -- 其他玩家掉线
- self:bindEvent(app.room , "onOtherDroppedResponse" , handler(self , self.onOtherDroppedResponse));
- -- 用户T出
- self:bindEvent(app.room , "onUserExitResponseRoom" , handler(self , self.onUserExitResponseRoom));
-
- -- 玩家的GPS信息发生变化
- self:bindEvent(app.room , "onGpsChangeResponse" , handler(self , self.onGpsChangeResponse));
-
- end
-
- --私人场消息
- function ZPRoomView:bindPrivateMessage()
- -- 玩家收到解散房间的请求
- self:bindEvent(app.room , "onDismissResponse" , handler(self , self.onDismissResponse));
- end
-
- --游戏消息
- function ZPRoomView:bindGameMessage()
- -- 游戏开始
- self:bindEvent(app.room , "onGameStartResponse" , handler(self , self.onGameStartResponse));
- -- 开始给桌子上用户发牌
- self:bindEvent(app.room , "onGameSendCardResponse" , handler(self , self.onGameSendCardResponse));
- -- 系统发给自己可串可哨的消息
- self:bindEvent(app.room , "onSystemOperationStart" , handler(self , self.onSystemOperationStart));
- -- 广播桌子上所有玩家庄家起手操作
- self:bindEvent(app.room , "onBankerOutCard", handler(self , self.onBankerOutCard));
- -- 出牌错误
- self:bindEvent(app.room , "onOutCardError", handler(self , self.onOutCardError));
- -- 出牌成功
- self:bindEvent(app.room , "onOutCardSuccess", handler(self , self.onOutCardSuccess));
- -- 摸牌
- self:bindEvent(app.room , "onMoPai", handler(self , self.onMoPai));
- -- 弃牌
- self:bindEvent(app.room , "onQiPai", handler(self , self.onQiPai));
- -- 操作错误
- self:bindEvent(app.room , "onOperationError", handler(self , self.onOperationError));
- -- 先操作玩家
- self:bindEvent(app.room , "onOperationFirst", handler(self , self.onOperationFirst));
- -- 操作成功
- self:bindEvent(app.room , "onOperationCodeSuccess", handler(self , self.onOperationCodeSuccess));
- -- 听牌
- self:bindEvent(app.room , "onTingCardResult",handler(self , self.onTingCardResult));
- --打乱位置
- self:bindEvent(app.room , "onChoicePlace",handler(self , self.onChoicePlace));
- -- 爆牌
- self:bindEvent(app.room , "onBaoPaiResponese",handler(self , self.onBaoPaiResponese));
- -- 最后一张牌
- self:bindEvent(app.room , "onLastCardResponse",handler(self , self.onLastCardResponse));
-
- self:bindEvent(app.room , "onGameXiaoJuResponse" , handler(self , self.onGameXiaoJuResponse));
- self:bindEvent(app.room , "onGameDaJuResponse" , handler(self , self.onGameDaJuResponse));
- -- 立即开局
- self:bindEvent(app.room , "onQuickStartResponse" , handler(self , self.onQuickStartResponse));
- -- 获取刷新手牌
- self:bindEvent(app.room , "onGetHandcardsResponese" , handler(self , self.onGetHandcardsResponese));
- --托管结果
- self:bindEvent(app.room , "onTuoGuanResponse",handler(self , self.onTuoGuanResponse));
- end
-
- --场景恢复
- function ZPRoomView:bindGameSceneMessage()
- local function onEnterRoomSuccess(event)
- if tolua.isnull(self.ui) then
- logE("self.is null")
- return
- end
- logD("ZPRoomView onEnterRoomSuccess")
- logD("ZPRoomView stopAllActions")
- self:stopAllActions()
- self:defaultState()
- self:onGameReconnection()
- self:startGame()
- end
- app.hall:addEventListener("onEnterRoomSuccess", onEnterRoomSuccess)
- end
-
- --自己的视图ID
- function ZPRoomView:getMeViewId()
- return ZPDef.MyViewID
- end
-
- --判断是否是自己的uid
- function ZPRoomView:getIsMeUId(uid)
- return uid == app.user.loginInfo.uid
- end
-
- function ZPRoomView:onGameSendCardResponse()
- local function runGameSendCardResponse(onEnd)
- self.PlayerView:stopAndHideBaoAnim()
- log("2000000000-ZPRoomView - runGameSendCardResponse()" )
- if self.taiPaiTimer then
- cc.Director:getInstance():getScheduler():unscheduleScriptEntry(self.taiPaiTimer)
- end
-
- --显示指示器
- local bankerViewId = app.room:getViewIdBySeatId(app.room.roomInfo.nBankSeatId)
- local leftCardNum = 19
- if app.room:getActualPlayerNum() == 2 then--and GameFunctions.getCurFangShu() == 0
- leftCardNum = 39
- end
- self:setCircleCardLeftPanelView(true,bankerViewId,leftCardNum)
-
- --发牌
- self:createCard(true,app.user.loginInfo.uid,onEnd)
-
- print("ding piao:"..table.tostring(app.room.roomInfo.memberList))
- --self.ui.Items.Button_tipai:setVisible(true)
-
- self.PlayerView:setLeftCardNum(1,true,20)
- self.PlayerView:setLeftCardNum(3,true,20)
- end
- log("2000000000-ZPRoomView - addCallBack(runGameSendCardResponse)" )
- self:addCallBack(runGameSendCardResponse);
- end
-
- function ZPRoomView:createCard(bShowAnimation,nUserID,onEnd)
- logE("====================RoomView:createCard()===================");
-
- local cardList = app.room.cards[nUserID]
- if not cardList or table.nums(cardList) <= 0 then
- --重连当自己没有手牌且有7方门子
- if onEnd then
- onEnd()
- end
- return
- end
- local lieshuMax = table.nums(cardList)
- local RankCardList = {}
- local colList = self.lieshulist[lieshuMax]
- local blankList = self.lieshuBlanklist[lieshuMax]
-
- local wuIndex = 0
- local youIndex = 0
-
- --重新调整
- for k = 1,self.lieShuMax do
- if not cardList[k] then
- cardList[k] = {}
- end
- if table.nums(cardList[k]) <= 0 then
- wuIndex = wuIndex + 1
- local blankIndex = blankList[wuIndex] -- 1,10
- if blankIndex then
- RankCardList[blankIndex] = {}
- end
- else
- youIndex = youIndex + 1
- local index = colList[youIndex] -- 2,3,4,5,6,7,8,9
- RankCardList[index] = cardList[k]
- end
- end
-
- cardList = {}
- cardList = RankCardList
- logE("createCard Rank ok :"..table.tostring(cardList))
-
- local index = 1
- --不管有无数据,默认创建10列数据
- for i = 1,self.lieShuMax do
- local value = cardList[i] or {}
- local isKan = self:getCurrentColIsKan(value)
- local card = ZPRoomCard:new(value,ZPDef.CardType.CARD_TYPE_HAND,i,isKan)
- local pos = self.boxPosList4[i]
- card.ui:setPosition(pos)
- self.ui.Items.LayoutMain_4:addChild(card.ui,1)
- --数据记录
- self.handCardRoot[i] = card
- self.handCardValueLocal[i] = value
- self.handCardValueBak[i] = clone(value)
-
- --存储所有的单牌节点Image
- for k = 1 ,self.hangShuMax do
- self.handCardItem[index] = card.imgList[k]
- index = index + 1
- end
- end
-
- logE("create card finish self.handCardValueLocal : "..table.tostring(self.handCardValueLocal))
-
- if bShowAnimation then
- --发牌动画(10*0.1+ 0.15 = 1.15miao)
- for k,v in ipairs(self.handCardRoot) do
- if v.ui:isVisible() then
- v.ui:setVisible(false)
- local spawnTime = 0.3
- local mSpawn = cc.Spawn:create(cc.FadeIn:create(spawnTime),cc.CallFunc:create(function ()
- v.ui:setVisible(true)
- --播放发牌声音
- if k < table.nums(self.handCardRoot) - 4 then
- playVoiceGiveCard()
- end
- end))
- v.ui:runAction(cc.Sequence:create(cc.DelayTime:create(k * 0.05),mSpawn,cc.DelayTime:create(k * 0.05),cc.CallFunc:create(function ()
- if k == self:getVisibleCardLayoutNum() then
-
- --排序
- self:RankCard()
- --注册点击
- self:registerCardTouch()
- if onEnd then
- onEnd()
- end
- end
- end)))
- end
- end
- else
- --注册点击
- self:registerCardTouch()
- --排序
- self:RankCard()
- if onEnd then
- onEnd()
- end
- end
- end
-
- --牌UI调整
- function ZPRoomView:RankCard(isNotShowAni)
- --如果列小于最大列数则需要调整UI
- local showColNum = self:getVisibleCardLayoutNum()
- if showColNum == 0 then
- self:getLocalHuShu()
- return
- end
- if showColNum <= self.lieShuMax then
- --根据当前存在的列数获取一个枚举列表,让手牌的列数重新旋转到指定新的列数
- local list = self.lieshulist[showColNum]
- local blankList = self.lieshuBlanklist[showColNum]
-
- local youIndex = 0
- local wuIndex = 0
- --card data
- local handCardValueLocalTemp = {}
- local handCardRootTemp = {}
- for k = 1,self.lieShuMax do
- if #self.handCardValueLocal[k] <= 0 then
- wuIndex = wuIndex + 1
- local blankIndex = blankList[wuIndex] -- 1 2 9 10
- local tarPos = self.boxPosList4[blankIndex]
- self.handCardRoot[k].ui:setPosition(tarPos)
-
- --列数修改
- for i = 1,self.hangShuMax do
- self.handCardRoot[k].imgList[i].lieshu = blankIndex
- end
-
- self.handCardRoot[k].ui:setLocalZOrder(blankIndex)
-
- handCardValueLocalTemp[blankIndex] = self.handCardValueLocal[k]
- handCardRootTemp[blankIndex] = self.handCardRoot[k]
- else
- youIndex = youIndex + 1
- local index = list[youIndex] -- 3 4 5 6 7 8
- local tarPos = self.boxPosList4[index]
- if isNotShowAni then
- self.handCardRoot[k].ui:setPosition(tarPos)
- else
- --self.handCardRoot[k].ui:stopAllActions()
- --self.handCardRoot[k].ui:setPosition(tarPos)
- self.handCardRoot[k].ui:runAction(cc.MoveTo:create(self.gameSpeedConfig.OPCARDTIME,tarPos))
- end
- --列数修改
- for i = 1,self.hangShuMax do
- self.handCardRoot[k].imgList[i].lieshu = index
- end
-
- --self.handCardRoot[k].ui:setLocalZOrder(index)
-
- handCardValueLocalTemp[index] = self.handCardValueLocal[k]
- handCardRootTemp[index] = self.handCardRoot[k]
-
- end
- end
-
- --牌数据
- self.handCardValueLocal = handCardValueLocalTemp
- handCardValueLocalTemp = {}
- --牌
- self.handCardRoot = handCardRootTemp
- handCardRootTemp = {}
- --logE("RankCard 排序后: "..table.tostring(self.handCardValueLocal))
- end
- self:getLocalHuShu()
- end
-
-
- --如果牌正在掉落的时候,不允许操作!
- --落牌检测
- function ZPRoomView:downCard()
- if app.room:isLittleFamily() and (not ZPFuc.getLittleIsCanLookCard()) then
- return
- end
- --是否需要掉落
- local bDown = false
- for i = 1,self.lieShuMax do
- if self.handCardRoot[i].ui:isVisible() then
- for j = 1,3 do
- for k = 2,self.hangShuMax do
- if not self.handCardRoot[i].imgList[j]:isVisible() and self.handCardRoot[i].imgList[k]:isVisible() and j < k then
- --底部
- local firstValue = self.handCardRoot[i].imgList[j].value
- --顶部
- local secondeValue = self.handCardRoot[i].imgList[k].value
-
- --插入
- --数据交换
- local tempValue = nil
- tempValue = self.handCardRoot[i].imgList[j].value
- self.handCardRoot[i].imgList[j].value = self.handCardRoot[i].imgList[k].value
- self.handCardRoot[i].imgList[k].value = tempValue
-
- --换底数据
- --[[local tempHuanDi = nil
- tempHuanDi = self.handCardRoot[i].imgList[j].isHuanDi
- self.handCardRoot[i].imgList[j].isHuanDi = self.handCardRoot[i].imgList[k].isHuanDi
- self.handCardRoot[i].imgList[k].isHuanDi = tempHuanDi--]]
- --ui交换
- self.handCardRoot[i].imgList[k]:setVisible(false)
- local cardValue = self.handCardRoot[i].imgList[j].value
- if cardValue then
- local fileName = ZPFuc.getZPCardImgByValue(cardValue,ZPDef.CardType.CARD_TYPE_HAND)
- logD("ZPRoomView:downCard", "fileName:", fileName)
- self.handCardRoot[i].imgList[j]:loadTextureFromPlist(fileName)
- end
- self.handCardRoot[i].imgList[j]:setVisible(true)
-
- --听牌标签
- local visibleA = self.handCardRoot[i].imgList[j]:getChildren()[1]:isVisible()
- local visibleB = self.handCardRoot[i].imgList[k]:getChildren()[1]:isVisible()
- self.handCardRoot[i].imgList[j]:getChildren()[1]:setVisible(visibleB)
- self.handCardRoot[i].imgList[k]:getChildren()[1]:setVisible(visibleA)
-
- --落牌动画
- local lieshu = self.ui.Items.ImageView_handTempCard.lieshu
- local value = self.ui.Items.ImageView_handTempCard.value
- --if self.handCardRoot[i].imgList[j].value == value and i == lieshu then
- -- self:goBackWithAni(self.handCardRoot[i].imgList[j])
- --else
- local recordPos = self.handCardRoot[i].imgList[j]:getParent():getPosition()
- self.handCardRoot[i].imgList[j]:getParent():setPosition(self.handCardRoot[i].imgList[k]:getParent():getPosition())
- local act = cc.MoveTo:create(self.gameSpeedConfig.OPCARDTIME,recordPos)
- --self.handCardRoot[i].imgList[j]:getParent():stopAllActions()
- self.handCardRoot[i].imgList[j]:getParent():runAction(act)
- --end
-
- bDown = true
- end
- end
- end
- end
- end
- --判断是否有掉落
- if not bDown then
- self.isGodHand = false
- else
- local seq = cc.Sequence:create(cc.DelayTime:create(1.25),cc.CallFunc:create(function ()
- self.isGodHand = false
- end))
- self.ui:runAction(seq)
- end
- end
-
- --整理牌
- function ZPRoomView:neatenCard(isNotShowAni)
- --logE("neatenCard -------- ", debug.traceback())
- --是否短暂屏蔽点击牌事件
- self:downCard()
- self:RankCard(isNotShowAni)
- end
-
- function ZPRoomView:getVisibleCardLayoutNum()
- local index = 0
- for i,v in ipairs(self.handCardValueLocal) do
- if #v > 0 then
- index = index + 1
- end
- end
- return index
- end
-
- --获取该列显示了几个
- function ZPRoomView:getRowVisibleCount(lieshu)
- local count = 0
- for k = 1, 4 do
- if self.handCardRoot[lieshu].imgList[k] and self.handCardRoot[lieshu].imgList[k]:isVisible() then
- count = count + 1
- end
- end
- return count
- end
-
- --判断列数是否是砍牌
- function ZPRoomView:getCurrentColIsKan(list)
- local isKan = false
- if list[1] and list[2] and list[3] then
- if list[1] == list[2] and list[2] == list[3] then
- isKan = true
- end
- end
- return isKan
- end
- --判断列数是否是龙
- function ZPRoomView:getCurrentColIsLong(list)
- local isLong = false
- if list[1] and list[2] and list[3] and list[4] then
- if list[1] == list[2] and list[2] == list[3] and list[3] == list[4] then
- isLong = true
- end
- end
- return isLong
- end
-
- function ZPRoomView:onTouchBegan(touch,k,v)
- if self.isGodHand then
- --showTooltip("禁止操作")
- return
- end
- local posOO = self:getPosOO()
- local localPos = touch:getLocation();
- local pos = cc.p(localPos.x - posOO.x, localPos.y - posOO.y);
-
- local lieshu = v.lieshu
- local hangshu = v.hangshu
- local value = v.value
- local isKan = v.isKan
- if isKan then
- showTooltip("坎牌不可移动")
- return
- end
-
- self.handCardRoot[lieshu].ui:setVisible(true)
-
- if value == nil then
- return
- end
- --playZiPaiSelectCardVoice()
- logE("88888888-=============onTouchBegan1================")
- logE("88888888-isKan:")
- logE(isKan)
- logE("88888888-touch lieshu:",lieshu)
- logE("88888888-touch hangshu:",hangshu)
- logE("88888888-touch value:",value)
- if value - 16 > 0 then
- logE("玩家点了"..lieshu.."列"..hangshu.."行的大"..value - 16)
- else
- logE("玩家点了"..lieshu.."列"..hangshu.."行的小"..value)
- end
- if isKan then
- logE("该牌为坎牌")
- else
- logE("该牌不是坎牌")
- end
- logE("88888888-card :"..table.tostring(self.handCardValueLocal))
- logE("88888888-=============onTouchBegan2================")
- v:setOpacity(0)
- if self.ui.Items.ImageView_handTempCard.cIdx ~= k then
- self:setColorWhite()
- v:setColor(ZPDef.ColorConfig.TOUCH_CARD_COLOR)
- self.ui.Items.Button_OutCard:setEnabled(true)
- logE("88888888-=============onTouchBegan3================")
- elseif self.ui.Items.ImageView_handTempCard.cIdx == k then
- if v:getColor().r == ZPDef.ColorConfig.TOUCH_CARD_COLOR.r and v:getColor().g == ZPDef.ColorConfig.TOUCH_CARD_COLOR.g and v:getColor().b == ZPDef.ColorConfig.TOUCH_CARD_COLOR.b then
- self:setColorWhite()
- self.ui.Items.Button_OutCard:setEnabled(false)
- else
- v:setColor(ZPDef.ColorConfig.TOUCH_CARD_COLOR)
- self.ui.Items.Button_OutCard:setEnabled(true)
- end
- logE("88888888-=============onTouchBegan4================")
- end
-
- self:showTingPaiView(v.value)
-
- --出牌线
- self:setOutCardLineVisible(true)
-
- --临时牌
- self.ui.Items.ImageView_handTempCard.cIdx = k
- self.ui.Items.ImageView_handTempCard.lieshu = lieshu
- self.ui.Items.ImageView_handTempCard.hangshu = hangshu
- self.ui.Items.ImageView_handTempCard.value = value
- self.ui.Items.ImageView_handTempCard.index = k
- self.ui.Items.ImageView_handTempCard:setVisible(true)
- self.ui.Items.ImageView_handTempCard:loadTextureFromPlist(ZPFuc.getZPCardImgByValue(value,ZPDef.CardType.CARD_TYPE_HAND))
- self.ui.Items.ImageView_handTempCard:setPosition(pos)
- logE("88888888-=============onTouchBegan5================")
- end
-
- function ZPRoomView:onTouchMove(touch,k,v)
- if self.isGodHand then
- --showTooltip("end 禁止操作")
- return
- end
- local posOO = self:getPosOO()
- local localPos = touch:getLocation();
- local pos = cc.p(localPos.x - posOO.x, localPos.y - posOO.y);
- self.ui.Items.ImageView_handTempCard:setPosition(pos)
- end
-
- function ZPRoomView:onTouchEnd(touch,k,v)
- logE("88888888-=============onTouchEnd1================")
- if not self.ui.Items.ImageView_handTempCard:isVisible() then
- --showTooltip("End 临时牌阻止了事件")
- v:setOpacity(255)
- self.ui.Items.ImageView_handTempCard:setVisible(false)
- return
- end
- if self.isGodHand then
- --showTooltip("end 禁止操作")
- return
- end
- self.ui.Items.ImageView_handTempCard:setVisible(false)
- --出牌线
- self:setOutCardLineVisible(false)
- if v.isKan then
- return
- end
- if not v.value then
- return
- end
- v:setOpacity(255)
- --回到原点动画
- self:goBackWithAni(v,0.15)
- logE("88888888-=============onTouchEnd2================")
- end
-
- function ZPRoomView:onTouchCancel(touch,k,v)
- self:setColorWhite()
- logE("88888888-=============onTouchCancel 1================")
- --出牌线
- self:setOutCardLineVisible(false)
- if not self.ui.Items.ImageView_handTempCard:isVisible() then
- --showTooltip("cancel 临时牌阻止了事件")
- v:setOpacity(255)
- self.ui.Items.ImageView_handTempCard:setVisible(false)
- logE("88888888-=============onTouchCancel11111111111")
- return
- end
- if self.isGodHand then
- --showTooltip("禁止操作")
- return
- end
- self.ui.Items.ImageView_handTempCard:setVisible(false)
- logE("88888888-=============onTouchCancel222222222222")
- if v.isKan then
- return
- end
- logE("88888888-=============onTouchCancel333333333333")
- if not v.value then
- return
- end
- logE("88888888-=============onTouchCancel4444444444444")
- v:setOpacity(255)
- --临时牌
- self.ui.Items.ImageView_handTempCard:setVisible(false)
- local touchPos = touch:getLocation()
- -------------------------------------------------------
- -------------------------------------------------------
- local hitCount = 0
- local hitItem = {}
- for i = #self.handCardItem,1,-1 do
- local mSprite = self.handCardItem[i]
- local posNode = mSprite:convertToNodeSpace(touchPos);
- local width = mSprite:getContentSize().width
- local height = mSprite:getContentSize().height
- --不可以用getWorldPosition(),因为会出现旋转后,可点区域会停留在原来的地方。
- local x = mSprite:getPosition().x
- local y = mSprite:getPosition().y
- local mRect = cc.Rectangle:new(x,y,width,height)
- if mRect:contains(posNode.x,posNode.y) then
- hitCount = hitCount + 1
- hitItem[hitCount] = mSprite
- break
- --[[--干掉for循环
- if hitCount == 3 then
- break
- end--]]
- end
- end
-
- --处理多层点击穿透:如果是3个,取第三个,如果是2个,取第二个,如果是一个,取第一个
- local curItem = hitItem[#hitItem]
- if curItem then
- logE("cancel hitCount :"..hitCount)
- if curItem.value == nil then
- logE("88888888-=============curItem.value == nil 1================")
- logE("88888888-=============执行牌插入,插入位置为空的================")
- --牌插入逻辑:
- --数组数据更新
- local curLieShu = hitItem[#hitItem].lieshu
- local curHangShu = hitItem[#hitItem].hangshu
- local value = hitItem[#hitItem].value
-
- logE("88888888-self.handCardValueLocal[v.lieshu]:"..table.tostring(self.handCardValueLocal[v.lieshu]))
- logE("88888888-self.handCardValueLocal[curLieShu]:"..table.tostring(self.handCardValueLocal[curLieShu]))
-
- --行数
- local row = v.hangshu
- local lieshu = v.lieshu
-
- logE("88888888-touch row :"..row)
- logE("88888888-touch lieshu :"..lieshu)
- --原来的数据删除
- --if self.handCardRoot[lieshu].imgList[row].value == v.value then
- table.remove(self.handCardValueLocal[lieshu],row)
- --end
-
- --在新的数据列里插入新的值
- for i = 1,self.hangShuMax do
- if self.handCardRoot[curLieShu].imgList[i].value == nil then
- table.insert(self.handCardValueLocal[curLieShu],v.value)
- break
- end
- end
-
- --数据交换
- local tempValue = nil
- tempValue = v.value
- v.value = hitItem[#hitItem].value
- hitItem[#hitItem].value = tempValue
-
- --ui更新
- self.ui.Items.ImageView_handTempCard:setVisible(true)
- v:setVisible(false)
- local function callback()
- self.ui.Items.ImageView_handTempCard:setVisible(false)
- local cardvalue = hitItem[#hitItem].value or tempValue
- if cardvalue then
- local fileName = ZPFuc.getZPCardImgByValue(cardvalue,ZPDef.CardType.CARD_TYPE_HAND)
- logD("ZPRoomView:registerCardTouch", "fileName:", fileName)
- hitItem[#hitItem]:loadTextureFromPlist(fileName)
- hitItem[#hitItem]:setVisible(true)
- hitItem[#hitItem]:setOpacity(255)
- end
-
- --听牌标签
- if v:getChildren()[1]:isVisible() then
- v:getChildren()[1]:setVisible(false)
- hitItem[#hitItem]:getChildren()[1]:setVisible(true)
- end
- self.ui.Items.ImageView_handTempCard.lieshu = curLieShu
- self.ui.Items.ImageView_handTempCard.hangshu = curHangShu
- self:neatenCard()
- end
-
- --handTemp->tarPos action
- if self.handCardRoot[curLieShu].imgList[curHangShu - 1] and
- self.handCardRoot[curLieShu].imgList[curHangShu - 1].value then
- local node = hitItem[#hitItem]
- local nodeSize = node:getParent():getContentSize()
- local nodePos = cc.pAdd(node:getWorldPosition(),cc.p(nodeSize.width/2,nodeSize.height/2))
- local seq = cc.Sequence:create(cc.MoveTo:create(0,nodePos),cc.CallFunc:create(callback))--self.gameSpeedConfig.OPCARDTIME
- self.ui.Items.ImageView_handTempCard:runAction(seq)
- else
- callback()
- end
- logE("88888888-=============curItem.value == nil 2================")
- logE("88888888-=============执行牌插入结束================")
-
- else
- logE("88888888-=============cancel curItem.value exist 1================")
-
- --数组数据更新
- local curLieShu = hitItem[#hitItem].lieshu
- local curHangShu = hitItem[#hitItem].hangshu
- local value = hitItem[#hitItem].value
- local isKan = hitItem[#hitItem].isKan
- if isKan then
- showTooltip("坎牌不可拆")
- return
- end
-
- --如果小于3则插入到空的那个
- if self:getRowVisibleCount(curLieShu) < 3 then
- logE("88888888-=============如果小于3则插入到空的那个================")
- logE("88888888-=============执行牌插入到空的位置================")
- --同列有多个牌相同的,找出对应点击的牌
- local row = v.hangshu
- local lieshu = v.lieshu
- logE("88888888-row :"..row)
- logE("88888888-lieshu :"..lieshu)
- --原来的数据删除
- table.remove(self.handCardValueLocal[lieshu],row)
- --在新的数据列里插入新的值
- local newRow = 0
- for i = 1,self.hangShuMax do
- if self.handCardRoot[curLieShu].imgList[i].value == nil then
- newRow = i
- table.insert(self.handCardValueLocal[curLieShu],v.value)
- break
- end
- end
-
- --数据交换
- local tempValue = nil
- tempValue = v.value
- v.value = nil
- self.handCardRoot[curLieShu].imgList[newRow].value = tempValue
- logE("888888888-curLieShu:"..tostring(curLieShu))
- logE("888888888-newRow:"..tostring(newRow))
- --ui更新
- v:setVisible(false)
- local fileName = ZPFuc.getZPCardImgByValue(self.handCardRoot[curLieShu].imgList[newRow].value,ZPDef.CardType.CARD_TYPE_HAND)
- self.handCardRoot[curLieShu].imgList[newRow]:loadTextureFromPlist(fileName)
- self.handCardRoot[curLieShu].imgList[newRow]:setVisible(true)
- self.handCardRoot[curLieShu].imgList[newRow]:setOpacity(255)
-
- --听牌标签
- if v:getChildren()[1]:isVisible() then
- v:getChildren()[1]:setVisible(false)
- self.handCardRoot[curLieShu].imgList[newRow]:getChildren()[1]:setVisible(true)
- end
-
- logE("88888888-======================after insert card=========================")
- logE("88888888-first item lieshu:"..v.lieshu)
- logE("88888888-first item value:"..0)
- self:neatenCard()
- logE("88888888-=============如果小于3则插入到空的那个 结束================")
- logE("88888888-=============执行牌插入到空的位置 结束================")
- else
- logE("88888888-=============该列满3个牌只能交换================")
- logE("88888888-=============执行牌交换================")
- if value - 16 > 0 then
- logE("被交换的牌为大"..value - 16)
- else
- logE("被交换的牌为小"..value)
- end
-
- --牌交换:
- --同列有多个牌相同的,找出对应点击的牌
- local rowFirst = v.hangshu
- local rowSecond = curHangShu
-
- logE("88888888-rowFirst 第一个交换的行数:"..rowFirst)
- logE("88888888-rowSecond 第二个交换的行数:"..rowSecond)
-
- logE("88888888-原始列数数据:"..table.tostring(self.handCardValueLocal[v.lieshu]))
- logE("88888888-交换列数数据:"..table.tostring(self.handCardValueLocal[curLieShu]))
-
- --原来的数据删除
- if self.handCardRoot[v.lieshu].imgList[rowFirst].value == v.value then
- table.remove(self.handCardValueLocal[v.lieshu],rowFirst)
- table.insert(self.handCardValueLocal[v.lieshu],rowFirst,value)
- end
-
- --原来的数据删除
- if self.handCardRoot[curLieShu].imgList[rowSecond].value == value then
- table.remove(self.handCardValueLocal[curLieShu],rowSecond)
- table.insert(self.handCardValueLocal[curLieShu],rowSecond,v.value)
- end
-
- logE("88888888-删除后的原始列数数据:"..table.tostring(self.handCardValueLocal[v.lieshu]))
- logE("88888888-删除后的列数数据:"..table.tostring(self.handCardValueLocal[curLieShu]))
-
- logE("查看数据:")
- logE("88888888-first item lieshu:"..v.lieshu)
- logE("88888888-first item value:"..v.value)
- logE("88888888-second item lieshu:"..curItem.lieshu)
- logE("88888888-second item value:"..curItem.value)
- logE("查看数据完毕")
- --数据交换
- local tempValue = nil
- tempValue = v.value
- v.value = hitItem[#hitItem].value
- hitItem[#hitItem].value = tempValue
-
- --ui交换
- local fileName = ZPFuc.getZPCardImgByValue(v.value,ZPDef.CardType.CARD_TYPE_HAND)
- v:loadTextureFromPlist(fileName)
- fileName = ZPFuc.getZPCardImgByValue(hitItem[#hitItem].value,ZPDef.CardType.CARD_TYPE_HAND)
- hitItem[#hitItem]:loadTextureFromPlist(fileName)
-
- local srcVisible = v:getChildren()[1]:isVisible()
- local changeVisible = hitItem[#hitItem]:getChildren()[1]:isVisible()
-
- --听牌标签
- hitItem[#hitItem]:getChildren()[1]:setVisible(srcVisible)
- v:getChildren()[1]:setVisible(changeVisible)
-
- logE("交换完毕,查看数据:")
- logE("88888888-first item lieshu:"..v.lieshu)
- logE("88888888-first item value:"..v.value)
- logE("88888888-second item lieshu:"..hitItem[#hitItem].lieshu)
- logE("88888888-second item value:"..hitItem[#hitItem].value)
- logE("查看数据完毕")
- logE("88888888-=============牌交换 结束================")
- logE("88888888=============cancel curItem.value exist 2================")
- end
- end
- else
- --@part:牌取消回来,出牌逻辑的实现
- --判断是否大于出牌点
- if touchPos.y > self.ui.Items.ImageView_line:getPosition().y and self.bOutCard then
- if app.room:isLittleFamily() then
- return
- end
- --比牌的时候,在比牌间隔点到了牌,拖出去报错
- if v.value == nil then
- showTooltip("牌已经操作过!")
- return
- end
-
- --send sender
- v:setOpacity(0)
- self:sendOutCard(v.value)
- logE("玩家出牌:"..v.value)
- self.bOutCard = false
- self.isGodHand = true;
- --记录数据
- local lieshu = v.lieshu
- local hangshu = v.hangshu
- local value = v.value
-
- self.ui.Items.ImageView_handTempCard.lieshu = lieshu
- self.ui.Items.ImageView_handTempCard.hangshu = hangshu
- self.ui.Items.ImageView_handTempCard.value = value
- self.ui.Items.ImageView_handTempCard.index = k
-
- else
- logE("牌回到原来的位置")
- --回到原点动画
- self:goBackWithAni(v,0.15)
- end
- end
-
- -------------------------------------------------------
- -------------------------------------------------------
- logE("88888888=============onTouchCancel 2================")
- logE("88888888-onTouchCancel :card :"..table.tostring(self.handCardValueLocal))
- end
-
- function ZPRoomView:getPosOO()
- local nodeTouch = self.ui.Items.Layout_Touch;
- local posTouch = nodeTouch:getWorldPosition()
- local poaAnchor = nodeTouch:getAnchorPoint()
- local sizeTouch = nodeTouch:getContentSize();
- local posOO = { x = posTouch.x - sizeTouch.width * poaAnchor.x , y = posTouch.y - sizeTouch.height * poaAnchor.y}
-
- return posOO;
- end
-
- --注册点击事件
- function ZPRoomView:registerCardTouch()
- --触摸
- for k,v in ipairs(self.handCardItem) do
- v:setTouchEnabled(true)
- v:registerTouchEvent(function (touch)
- self:onTouchBegan(touch,k,v)
- end ,
- function (touch)
- self:onTouchMove(touch,k,v)
- end,
- function (touch)
- self:onTouchEnd(touch,k,v)
- end,
- function (touch)
- self:onTouchCancel(touch,k,v)
- end)
- end
- end
-
- --牌回来动画
- function ZPRoomView:goBackWithAni(node,time)
- local moveTime = nil
- if time then
- moveTime = time
- else
- moveTime = self.gameSpeedConfig.OPCARDTIME
- end
- local recordPos = node:getParent():getPosition()
- local handTempSize = self.ui.Items.ImageView_handTempCard:getContentSize()
- local handTempPos = cc.pSub(self.ui.Items.ImageView_handTempCard:getPosition(), cc.p(handTempSize.width/2,handTempSize.height/2))
- local tranPos = node:getParent():getParent():convertToNodeSpace(handTempPos)
- node:getParent():setPosition(tranPos)
- local act = cc.MoveTo:create(moveTime,recordPos)
- node:getParent():runAction(act)
- end
-
- --玩家出牌操作
- function ZPRoomView:sendOutCard(nCard)
- if self.isGameOver then
- return
- end
- self:IsTingPaiCard(nCard)
- --直接给用户显示出牌效果,数据删除在出牌成功后,如果出牌失败,出牌效果消失,用户可以重新出牌哦
- self:setOutCardVisible(true,self:getMeViewId(),nCard,true,nil,false)
- end
-
-
- -- 系统开局发可串可哨的消息
- function ZPRoomView:onSystemOperationStart(data)
-
- local function runSystemOperation(onEnd)
- if app.room:isLittleFamily() and (not ZPFuc.getLittleIsCanLookCard()) then
- if onEnd then
- onEnd()
- end
- return
- end
- log("2000000000-ZPRoomView - (runSystemOperation)")
- local nUserId = data.response.nUserId
- local tiPaiList = data.response.tiPaiList
- local nTotalYoushu = data.response.nTotalHuShu
-
- local viewId = app.room:getViewIdByUserId(nUserId)
-
- --提
- local hushu = 0
- for k,v in ipairs(tiPaiList) do
- if v.hushu then
- hushu = hushu + v.hushu
- end
- self.systemTiPai = true
- if k == #tiPaiList then
- self:doOperation(ZPDef.OpType.OP_TYPE_TI,viewId,v.card,false,onEnd())
- else
- self:doOperation(ZPDef.OpType.OP_TYPE_TI,viewId,v.card)
- end
- end
- if #tiPaiList == 0 then
- if onEnd then
- onEnd()
- end
- end
- self.tableHuXiList[viewId] = hushu
- self.PlayerView:setPlayerHuXi(viewId,hushu)
-
- if viewId == self:getMeViewId() then
- self:neatenCard(true)
- end
-
- local leftHandCardNum = data.response.leftHandCardNum
- self.PlayerView:setLeftCardNum(viewId,true,leftHandCardNum)
-
-
-
- end
- log("2000000000-ZPRoomView - addCallBack(runSystemOperation)")
-
- self:addCallBack(runSystemOperation);
- end
-
- -- 广播桌子上所有玩家庄家起手操作
- function ZPRoomView:onBankerOutCard(data)
- local function runOnBankerOutCard(onEnd)
- log("2000000000-ZPRoomView - (runOnBankerOutCard)")
- logE("onBankerOutCard :"..table.tostring(data.response))
- if data.response.nUserId == app.room:getMyUserId() then
- if data.response.IsShouldOutCard > 0 then
- self:setGuideView(true)
- self.bOutCard = true
- end
- if data.response.mainOpCode ~= ZPDef.OpCode.OP_CANCEL then
- --操作码
- local viewId = app.room:getViewIdByUserId(data.response.nUserId)
- self.operationLocalCode = data.response.mainOpCode
- self:showOpeation(data.response.mainOpCode,viewId)
- self:setGuideView(false)
- self.bOutCard = false
- self.isTianHu = true
- end
- end
-
- local operations = {}
- --操作码
- local viewId = app.room:getViewIdByUserId(data.response.nUserId)
- operations[viewId] = {}
- operations[viewId].nUserId = data.response.nUserId
- operations[viewId].isCanOpereate = 1
- self:showDelayTimeTip(operations)
-
- if onEnd then
- onEnd()
- end
- end
-
-
- log("2000000000-ZPRoomView - addCallBack(runOnBankerOutCard)")
- self:addCallBack(runOnBankerOutCard);
- end
-
- --庄家最后一张牌
- function ZPRoomView:onLastCardResponse(data)
- self.isGodHand = true
- local function runShowBankerFirstCard(onEnd)
- self:showLastCardAni(data,onEnd)
- --[[if onEnd then
- onEnd()
- end--]]
- end
- self:addCallBack(runShowBankerFirstCard);
- end
-
- --从手牌找与牌值相等的牌,没有再找等值的大小牌,没有返回最后空列
- function ZPRoomView:findCardPos(card)
- local secondDstCard
- if card - 10 > 0 then
- secondDstCard = card - 16
- else
- secondDstCard = card + 16
- end
- --第一目标
- local dstCol1,dstRow1
- --第二目标
- local dstCol2,dstRow2
- --第一次找到值时,赋值一次,
- local firstSet = true
- local isEnd = false
- for col = self.lieShuMax, 1, -1 do
- for row = 4, 1, -1 do
- --if self.handCardRoot[col].imgList[row].value == card then
- if self.handCardValueLocal[col][row] == card and #self.handCardValueLocal[col] < 3 then
- dstCol1 = col
- dstRow1 = #self.handCardValueLocal[col]+1
- isEnd = true
- break
- end
- --if self.handCardRoot[col].imgList[row].value == secondDstCard then
- if self.handCardValueLocal[col][row] == secondDstCard and #self.handCardValueLocal[col] < 3 then
- dstCol2 = col
- dstRow2 = #self.handCardValueLocal[col]+1
- end
- if firstSet and self.handCardValueLocal[col][row] then
- firstSet = false
- dstCol2 = col + 1
- dstRow2 = 1
- end
- end
- if isEnd then
- break
- end
- end
- if dstCol1 then
- return dstCol1,dstRow1
- end
- if dstCol2 then
- return dstCol2,dstRow2
- end
- end
- --显示庄家第一张摸的牌动画
- function ZPRoomView:showLastCardAni(data,onEnd)
- local bankerViewId = app.room:getViewIdByUserId(data.response.nUserId)
- local card = tonumber(data.response.firstCard) or tonumber(data.response.bankFirstGrabCard)
- --自己或者小家且可以看牌的要把牌发到手里
- local isMe = (tonumber(data.response.nUserId) == app.user.loginInfo.uid) or (app.room:isLittleFamily() and ZPFuc.getLittleIsCanLookCard() and app.room:getActualPlayerNum()==4)
-
- if self:getMeViewId() == bankerViewId and isMe then
- self:playMoPaiAni(self.leftNum,card,bankerViewId,0,1,nil,false)
- local seq = cc.Sequence:create(cc.DelayTime:create(self.gameSpeedConfig.MO_PAI_TIME + 0.8),cc.CallFunc:create(function ()
- local name = string.format("Layout_outCardPoint_%d",bankerViewId)
- local mLayout = self.ui.Items[name]
- mLayout:setVisible(false)
- local srcPos = mLayout:getPosition()
- self.ui.Items.ImageView_handTempCard:setVisible(true)
- local fileName = ZPFuc.getZPCardImgByValue(card,ZPDef.CardType.CARD_TYPE_HAND)
- logD("ZPRoomView:showLastCardAni", "fileName:", fileName)
- self.ui.Items.ImageView_handTempCard:loadTextureFromPlist(fileName)
- self.ui.Items.ImageView_handTempCard:setPosition(srcPos)
-
- local firstCol,firstRow = self:findCardPos(card)
- local node = self.handCardRoot[firstCol].imgList[firstRow]
- node.value = card
- local nodeSize = node:getParent():getContentSize()
- local nodePos = cc.pAdd(node:getWorldPosition(),cc.p(nodeSize.width/2,nodeSize.height/2))
- local seq2 = cc.Sequence:create(cc.MoveTo:create(0.2,nodePos),cc.CallFunc:create(function ()
- local firstCol1,firstRow1 = self:findCardPos(card)
- --[[node = self.handCardRoot[firstCol1].imgList[firstCol1]
- node.value = card--]]
- node:loadTextureFromPlist(ZPFuc.getZPCardImgByValue(card,ZPDef.CardType.CARD_TYPE_HAND))
- node:setVisible(true)
- self.ui.Items.ImageView_handTempCard:setVisible(false)
- self.ui.Items.ImageView_handTempCard:setScale(1.0)
- self.ui.Items.ImageView_handTempCard:setOpacity(255)
-
- self.handCardValueLocal[firstCol1][firstRow1] = card
- table.insert(self.handCardValueBak[firstCol1],card)
- --self.handCardValueBak[firstCol1][firstRow1] = card
- if self:getCurrentColIsKan(self.handCardValueLocal[firstCol]) then
- for i=1,3 do
- self.handCardRoot[firstCol].imgList[i].isKan = true
- self.handCardRoot[firstCol].imgList[i]:setColor(cc.c3b(125,125,125))
- end
- end
- self.isGodHand = false
- self:showTiPaiBtn(true)
-
- --排序
- self:RankCard(true)
- if onEnd then
- onEnd()
- end
- end))
- self.ui.Items.ImageView_handTempCard:runAction(seq2)
- end))
- self:runAction(seq)
- else
- self:playMoPaiAni(self.leftNum,0xfa,bankerViewId,0,1,nil,false)
- self.PlayerView:changeLeftCardNum(bankerViewId,1)
- local name = string.format("Layout_outCardPoint_%d",bankerViewId)
- --播放动画
- self.ui.Items.ImageView_handTempCard:loadTextureFromPlist(ZPFuc.getZPCardImgByValue(0xfa,ZPDef.CardType.CARD_TYPE_OUTCARD))--card
- local mSprite = self.ui.Items[name]
- local srcPos = mSprite:getPosition()
- self.ui.Items.ImageView_handTempCard:setPosition(srcPos)
- local tarPos = self.PlayerView:getPlayerPosByViewId(bankerViewId)
- --self.ui.Items.ImageView_handTempCard:setEulerRotation(cc.vec3(0,0,90))
-
- local time = 0.2
- local spawn = cc.Spawn:create(cc.MoveTo:create(time,tarPos),cc.FadeOut:create(time),cc.ScaleTo:create(time,0))
- local seq = cc.Sequence:create(cc.DelayTime:create(self.gameSpeedConfig.MO_PAI_TIME + 0.8),cc.CallFunc:create(function ()
- self.ui.Items.ImageView_handTempCard:setVisible(true)
- local name = string.format("Layout_outCardPoint_%d",bankerViewId)
- local mLayout = self.ui.Items[name]
- mLayout:setVisible(false)
- end),spawn,cc.CallFunc:create(function ()
- self.ui.Items.ImageView_handTempCard:setVisible(false)
- self.ui.Items.ImageView_handTempCard:setScale(1.0)
- self.ui.Items.ImageView_handTempCard:setOpacity(255)
- self.ui.Items.ImageView_handTempCard:setEulerRotation(cc.vec3(0,0,0))
- self.isGodHand = false
- self:showTiPaiBtn(true)
- if onEnd then
- onEnd()
- end
- end))
- self.ui.Items.ImageView_handTempCard:runAction(seq)
- end
- --小家不能看牌时,牌堆牌显示剩余张数
- if app.room:isLittleFamily() and (not ZPFuc.getLittleIsCanLookCard()) then
- if onEnd then
- onEnd()
- end
- self:setCircleCardLeftPanelView(true,bankerViewId,19)
- end
- end
-
- --出牌错误
- function ZPRoomView:onOutCardError(data)
- local function runOnOutCardError(onEnd)
- logE("ZPRoomView:onOutCardError(), response = ", table.tostring(data.response))
- log("2000000000-ZPRoomView - runOnOutCardError")
- self.isGodHand = false--出牌错误了,可以操作牌
- --隐藏出牌效果
- self:setOutCardVisible(false)
- --恢复出的那张牌的透明度
- local index = self.ui.Items.ImageView_handTempCard.index
- self.handCardItem[index]:setOpacity(255)
- self.bOutCard = true
- if onEnd then
- onEnd()
- end
- end
- log("2000000000-ZPRoomView - addCallBack(runOnOutCardError)")
- self:addCallBack(runOnOutCardError)
-
- end
-
- function ZPRoomView:showDelayTimeTip(operations)
-
- end
-
- --出牌成功
- function ZPRoomView:onOutCardSuccess(data)
- logE("ZPRoomView:onOutCardSuccess(), response = ", table.tostring(data.response))
- local function runOnOutCardSuccess(onEnd)
- log("2000000000-ZPRoomView - runOnOutCardSuccess")
- --设置出牌动画隐藏
- self:setGuideView(false)
-
- local response = data.response
- local nUserId = response.nOutCardUserId
- local card = response.byOutCard
- local operateCode = response.mainOpCode
- local operations = response.operations
- local isWuFu = response.nFuWuWarn
- local leftHandCardNum = response.leftHandCardNum
-
- local viewId = app.room:getViewIdByUserId(nUserId)
- self.moPaiViewId = viewId
- --隐藏出牌
- self.bOutCard = false
- --记录真实牌值
- self.outCard = card
- --记录操作码
- self.EatOperationCode = operateCode
-
- self:showDelayTimeTip(operations)
-
- self.PlayerView:setLeftCardNum(viewId,true,leftHandCardNum)
- --self.PlayerView:setNoOpTime(false,viewId)
- logE("my userid :"..app.room:getMyUserId())
- logE("out card response nUserId:"..nUserId)
-
- local userInfo=app.room:getUserInfo(nUserId)
- if userInfo then
- ZPSound.PlayZPSound(userInfo.sex,card)
- end
-
-
- if (nUserId ~= app.room.roomInfo.nUserId and (not app.room:isLittleFamily())) then
-
- if operateCode ~= ZPDef.OpCode.OP_CANCEL then
- self:showOpeation(operateCode,viewId,card)
- end
- --其他玩家显示
- self:setOutCardVisible(true,viewId,card,false,onEnd)
- elseif app.room:isLittleFamily() and (not ZPFuc.getLittleIsCanLookCard()) then
- if operateCode ~= ZPDef.OpCode.OP_CANCEL then
- self:showOpeation(operateCode,viewId,card)
- end
- --其他玩家显示
- self:setOutCardVisible(true,viewId,card,false,onEnd)
- elseif app.room:isLittleFamily() and ZPFuc.getLittleIsCanLookCard() and nUserId ~= app.room.roomInfo.nUserId and app.room.roomInfo.nBankUid ~= nUserId then
- if operateCode ~= ZPDef.OpCode.OP_CANCEL then
- self:showOpeation(operateCode,viewId,card)
- end
- --其他玩家显示
- self:setOutCardVisible(true,viewId,card,false,onEnd)
- else
- if self.isTuoGuan and self.isTuoGuan == true then
- self:IsTingPaiCard(card)
- end
- local isLittleFamily1 = app.room:isLittleFamily() and 1 or 0
- local getLittleIsCanLookCard1 = ZPFuc.getLittleIsCanLookCard() and 1 or 0
- --logE("my print ============= :"..nUserId.." "..app.room.roomInfo.nUserId.." "..app.user.loginInfo.uid.." "..app.room.roomInfo.nBankUid.." "..isLittleFamily1.." "..getLittleIsCanLookCard1)
- self.isGodHand = true
- local function rankDeletOneCard(card)
- local isEnd = false
- --倒叙遍历1-10列
- for col = self.lieShuMax,1,-1 do --列数
- for row = self.hangShuMax,1,-1 do --行数
- if card == self.handCardRoot[col].imgList[row].value then --判断值是否相等
- logE("delete card1 ============= :"..card)
- table.remove(self.handCardValueLocal[col],row)
- --单张图片的值归nil
- self.handCardRoot[col].imgList[row].value = nil
- self.handCardRoot[col].imgList[row].isKan = false
- --单个图片隐藏
- self.handCardRoot[col].imgList[row]:setOpacity(255)
- self.handCardRoot[col].imgList[row]:setVisible(false)
- isEnd = true
- break
- end
- end
- if isEnd then
- break
- end
- end
- end
- local index = self.ui.Items.ImageView_handTempCard.index
- local lieshu = self.ui.Items.ImageView_handTempCard.lieshu
- local row = self.ui.Items.ImageView_handTempCard.hangshu --self:getRowByIndex(index)
- --说明:数据校验:弱网棋牌的通病(麻将出牌等一切可以允许玩家自己插牌的游戏,需要注意弱网情况,出牌会出现删错牌)
- --判断该列是否有牌
- if app.room:isLittleFamily() and ZPFuc.getLittleIsCanLookCard() then
- rankDeletOneCard(card)
- elseif self.handCardValueLocal[lieshu] ~= nil and table.nums(self.handCardValueLocal[lieshu]) > 0 then
- --二次校验牌数据是否是出牌数据
- local recordValue = self.handCardRoot[lieshu].imgList[row].value
- if recordValue == card then
- logE("delete card2 ============= :"..card)
- table.remove(self.handCardValueLocal[lieshu],row)
- --数据干掉
- self.handCardRoot[lieshu].imgList[row].value = nil
- self.handCardRoot[lieshu].imgList[row].isKan = false
- --视图处理
- self.handCardRoot[lieshu].imgList[row]:setOpacity(255)
- self.handCardRoot[lieshu].imgList[row]:setVisible(false)
- else
- --随机删掉手里那张牌
- rankDeletOneCard(card)
- end
- else
- --随机删掉手里那张牌
- rankDeletOneCard(card)
- end
- self:rankDeletOneBakCard(card)
- self:neatenCard()
- if onEnd then
- onEnd()
- end
- --检查是否少牌
- self:checkCardsByUidAndLeftCardNum(nUserId,leftHandCardNum)
- self:checkCardAndRecover()
- end
- end
- log("2000000000-ZPRoomView - addCallBack(runOnOutCardSuccess)")
- self:addCallBack(runOnOutCardSuccess)
- end
-
- function ZPRoomView:showOpeation(mainOpCode,viewId,card)
- self.operationView:setVisible(true)
- self.operationView:setSameParame(self.outCard,self.handCardValueLocal)
- self.operationView:showOpeation(mainOpCode,viewId,card)
- --检测是否少牌
- self:neatenCard(true)--无感知的整理一次手牌
- self:checkCardAndRecover()
- end
-
- --执行操作(不包括过)
- --[[
- operationType:操作类型
- viewId:视图ID
- card:牌
- isMoPaiOrId:为255的值表示从铺里摸的,如果是玩家放炮给人碰,则表示具体的seatId
- ]]
- function ZPRoomView:doOperation(operationType,viewId,card,isMoPaiOrId,onEnd)
- if operationType == ZPDef.OpType.OP_TYPE_CHI then
- self:Chi(viewId,card,onEnd)
- elseif operationType == ZPDef.OpType.OP_TYPE_PENG then
- self:Peng(viewId,card,isMoPaiOrId,onEnd)
- self:showOperatorTip(viewId,operationType)
- elseif operationType == ZPDef.OpType.OP_TYPE_MINGWEI then
- self:WeiPai(viewId,card,true,onEnd)
- self:showOperatorTip(viewId,operationType)
- elseif operationType == ZPDef.OpType.OP_TYPE_ANWEI then
- self:WeiPai(viewId,card,false,onEnd)
- self:showOperatorTip(viewId,operationType)
- elseif operationType == ZPDef.OpType.OP_TYPE_PAO or operationType == ZPDef.OpType.OP_TYPE_CHONG_PAO then
- self:showOperatorTip(viewId,operationType)
- self:PaoPai(viewId,card,onEnd)
- elseif operationType == ZPDef.OpType.OP_TYPE_TI then
- self:showOperatorTip(viewId,operationType)
- self:TiPai(viewId,card,onEnd,self.systemTiPai)
- elseif operationType == ZPDef.OpType.OP_TYPE_HU then
- self:showOperatorTip(viewId,operationType)
- elseif operationType == ZPDef.OpType.BAO then
- self:showOperatorTip(viewId,-55)
- self.PlayerView:playBaoAnim(viewId)
- end
- end
-
- --用户行为提示
- function ZPRoomView:showOperatorTip(viewId,mType)
- self.PlayerView:showOperatorTip(viewId,mType)
- end
-
-
- --用户明偎(自动)
- --[[
- @parm:isMingWei 是否明偎
- ]]
- function ZPRoomView:WeiPai(viewId,card,isMingWei,onEnd,isSystemOperation)
- --是否轮到我
- local bMeTurn = viewId == self:getMeViewId()
-
- --自己是需要做数据删除的,他人不需要的
- if app.room:isLittleFamily() and (not ZPFuc.getLittleIsCanLookCard()) then
- elseif bMeTurn then--and not app.room:isLittleFamily()
- --倒叙遍历1-10列
- for col = self.lieShuMax,1,-1 do --列数
- for row = self.hangShuMax,1,-1 do --行数
- if card == self.handCardRoot[col].imgList[row].value then --判断值是否相等
- table.remove(self.handCardValueLocal[col],row)
- self:rankDeletOneBakCard(card)
- --单张图片的值归nil
- self.handCardRoot[col].imgList[row].value = nil
- self.handCardRoot[col].imgList[row].isKan = false
- --单个图片隐藏
- self.handCardRoot[col].imgList[row]:setVisible(false)
- self.handCardRoot[col].imgList[row]:setOpacity(255)
- end
- end
- end
- if not isSystemOperation then
- self:neatenCard(true)
- end
- end
-
- local list = {card,card,card}
- if isSystemOperation then
- self:createWeiPaiView(viewId,list,false,isMingWei)
- else
- self:createWeiPaiView(viewId,list,true,isMingWei)
- end
- if onEnd then
- onEnd()
- end
- end
-
- --创建偎牌的UI
- function ZPRoomView:createWeiPaiView(viewId,list,isShowAni,isMingWei)
- local card = list[1]
- --是否轮到我
- local bMeTurn = viewId == self:getMeViewId()
- --更新自己(3张暗加一个数字(值分大小写))
- --获取自己的出牌点
- local name = string.format("Layout_player1Table_%d",viewId)
- local UnitCardNode = self.ui.Items[name]
- --获取出牌点的儿子数量
- local count = UnitCardNode:getChildrenCount();
- --数量即为列数
- local col = count;
-
- --牌大小
- local mSprite = cc.ImageView:createNode()
- local FileName = ZPFuc.getZPCardImgByValue(card,ZPDef.CardType.CARD_TYPE_TABLE)
- mSprite:loadTextureFromPlist(FileName)
- local width = mSprite:getContentSize().width * self.littleCardScale + self.cardInterval
- local height = mSprite:getContentSize().height * self.littleCardScale - self.verticleInterval
-
- --创建一个空的layout,layout放到组合牌点上
- local mLayout = cc.Layout:createNode()
- local endPos = nil
- if bMeTurn then
- endPos = cc.p(width * col,0)
- elseif viewId == 1 then
- endPos = cc.p(-width * col,0)
- else
- endPos = cc.p(width * col,0)
- end
- --开启触摸
- mLayout:setTouchEnabled(true)
- --设置锚点
- mLayout:setAnchorPoint(cc.p(0,1))
- --设置大小
- mLayout:setSize(cc.size(width,height*3))
- --layout数据存储:
- --下面的牌数据:
- mLayout.cardList = {}
- if isMingWei then
- mLayout.type = "mingwei"
- else
- mLayout.type = "anwei"
- end
- --查找layout的唯一性
- mLayout:setName(string.format("%d",card))
- --设置类型
- mLayout:setTag(ZPDef.TableConst.TABLE_CONST_CAN_TOUCH)
-
- for i = 1,3 do
- local mWeiCard;
- local row = i - 1;
- if i > 1 then
- --数据
- mLayout.cardList[i] = card
- --界面
- mWeiCard = cc.ImageView:createNode()
- mWeiCard:setScale(self.littleCardScale)
- mWeiCard:loadTextureFromPlist(ZPFuc.getZPCardImgByValue(0xfa,ZPDef.CardType.CARD_TYPE_TABLE))--0xfa为牌背
- mWeiCard:setPosition(width/2,0 + height * row - height /2);
- mWeiCard:setTag(1)
- mLayout:addChild(mWeiCard,3-i+1);
- else
- --数据
- mLayout.cardList[i] = card
- --界面
- mWeiCard = cc.ImageView:createNode()
- if isMingWei then
- --明偎
- mWeiCard:loadTextureFromPlist(ZPFuc.getZPCardImgByValue(mLayout.cardList[i],ZPDef.CardType.CARD_TYPE_TABLE))--0xfa为牌背
- else
- if bMeTurn then
- mWeiCard:loadTextureFromPlist(ZPFuc.getZPCardImgByValue(mLayout.cardList[i],ZPDef.CardType.CARD_TYPE_TABLE))--0xfa为牌背
- else
- --暗偎
- mWeiCard:loadTextureFromPlist(ZPFuc.getZPCardImgByValue(0xfa,ZPDef.CardType.CARD_TYPE_TABLE))--0xfa为牌背
- end
- end
- mWeiCard:setScale(self.littleCardScale)
- mWeiCard:setPosition(width/2,0 + height * row - height /2);
- mWeiCard:setTag(1)
- mLayout:addChild(mWeiCard,3-i+1);
- end
- end
-
- if bMeTurn then
- --注册点击事件
- mLayout:registerClick(function ()
- --获取TAG,name,tag表示类型,name表示抓取那个layout
- for index,child in pairs(UnitCardNode:getChildren()) do
- local tag = child:getTag()
- if tag == ZPDef.TableConst.TABLE_CONST_CAN_TOUCH then
- for i,v in pairs(child:getChildren()) do
- if v:getTag() == 1 and i > 1 then
- v:loadTextureFromPlist(ZPFuc.getZPCardImgByValue(child.cardList[i],ZPDef.CardType.CARD_TYPE_TABLE))
- v:setScale(self.littleCardScale)
- local seq = cc.Sequence:create(cc.DelayTime:create(1.0),cc.CallFunc:create(function ()
- v:loadTextureFromPlist(ZPFuc.getZPCardImgByValue(0xfa,ZPDef.CardType.CARD_TYPE_TABLE))
- end))
- v:runAction(seq)
- end
- end
- end
- end
-
- end)
- end
-
- UnitCardNode:addChild(mLayout);
- --动画
- if isShowAni then
- self:playWeaveCardAni(mLayout,viewId,1,endPos,nil,1.0,true)
- else
- mLayout:setPosition(endPos)
- end
- end
-
- --用户提牌(自动)
- function ZPRoomView:TiPai(viewId,card,onEnd,isSystemOperation)
- --是否轮到我
- local bMeTurn = viewId == self:getMeViewId()
- --自己是需要做数据删除的,他人不需要的
- if app.room:isLittleFamily() and (not ZPFuc.getLittleIsCanLookCard()) then
- elseif bMeTurn then --not app.room:isLittleFamily()
- --倒叙遍历1-10列
- for col = self.lieShuMax,1,-1 do --列数
- for row = 4,1,-1 do --行数
- if card == self.handCardRoot[col].imgList[row].value then
- table.remove(self.handCardValueLocal[col],row)
- self:rankDeletOneBakCard(card)
- --单张图片的值归nil
- self.handCardRoot[col].imgList[row].value = nil
- self.handCardRoot[col].imgList[row].isKan = false
- --单个图片隐藏
- self.handCardRoot[col].imgList[row]:setVisible(false)
- self.handCardRoot[col].imgList[row]:setColor(cc.c3b(255,255,255))
- end
- end
- end
- if not isSystemOperation then
- self:neatenCard(true)
- end
- end
-
- --更新自己
- --1.查找桌面牌 偎提
- --标志:
- local bIsWeiTi = false
- local name = string.format("Layout_player1Table_%d",viewId)
- local UnitCardNode = self.ui.Items[name]
- local chlidLayout = UnitCardNode:getChildByName(string.format("%d",card))
- if chlidLayout then
- local shaoCount = chlidLayout:getChildrenCount();
- if chlidLayout.type == "mingwei" or chlidLayout.type == "anwei" then
- bIsWeiTi = true
- self.playerZhao[viewId] = self.playerZhao[viewId] + 1
- --视图更新
- --第三张
- local mTiCard;
- mTiCard = cc.ImageView:createNode()
- local thirdSprite = chlidLayout:getChildren()[3]
- local tarPos = cc.p(thirdSprite:getPositionX(),thirdSprite:getPositionY() + thirdSprite:getContentSize().height * self.littleCardScale);
- mTiCard:loadTextureFromPlist(ZPFuc.getZPCardImgByValue(card,ZPDef.CardType.CARD_TYPE_TABLE))
- chlidLayout:addChild(mTiCard);
- chlidLayout.cardList[4] = card
-
- local function callback()
- mTiCard:loadTextureFromPlist(ZPFuc.getZPCardImgByValue(0xfa,ZPDef.CardType.CARD_TYPE_TABLE))
- if onEnd then
- onEnd()
- end
- end
- --亮第一张
- local firstSprite = chlidLayout:getChildren()[1]
- firstSprite:loadTextureFromPlist(ZPFuc.getZPCardImgByValue(card,ZPDef.CardType.CARD_TYPE_TABLE))
-
- --标记为提了
- chlidLayout.type = "ti"
- self:playWeaveCardAni(mTiCard,viewId,self.littleCardScale,tarPos,callback,0,false)
- end
- end
-
- --如果桌面没有偎的牌
- if not bIsWeiTi then
- local list = {card,card,card,card}
- if isSystemOperation then
- self:createTiOrPaoView(true,viewId,list,false,onEnd)
- else
- self:createTiOrPaoView(true,viewId,list,true,onEnd)
- end
- end
- end
-
-
- --创建串或者开招的UI
- function ZPRoomView:createTiOrPaoView(isTiPai,viewId,list,isShowAni,onEnd)
- --是否轮到我
- local bMeTurn = viewId == self:getMeViewId()
- local card = list[1]
- local name = string.format("Layout_player1Table_%d",viewId)
- local UnitCardNode = self.ui.Items[name]
- --获取出牌点的儿子数量
- local count = UnitCardNode:getChildrenCount();
- --数量即为列数
- local col = count;
-
- --牌大小
- local mSprite = cc.ImageView:createNode()
- local FileName = ZPFuc.getZPCardImgByValue(card,ZPDef.CardType.CARD_TYPE_TABLE)
- mSprite:loadTextureFromPlist(FileName)
- local width = mSprite:getContentSize().width * self.littleCardScale + self.cardInterval
- local height = mSprite:getContentSize().height * self.littleCardScale - self.verticleInterval
-
- --创建一个空的layout,layout放到组合牌点上
- local mLayout = cc.Layout:createNode()
- local endPos = nil
- if bMeTurn then
- endPos = cc.p(width * col,0)
- elseif viewId == 1 then
- endPos = cc.p(-width * col,0)
- else
- endPos = cc.p(width * col,0)
- end
- --开启触摸
- mLayout:setTouchEnabled(true)
- --设置锚点
- mLayout:setAnchorPoint(cc.p(0,1))
- --设置大小
- mLayout:setSize(cc.size(width,height*4))
- --layout数据存储:
- --下面的牌数据:
- mLayout.cardList = {}
- --查找layout的唯一性
- mLayout:setName(string.format("%d",card))
-
- for i = 1,4 do
- local row = i - 1;
- --数据
- mLayout.cardList[i] = card
- --界面
- local mWeiCard = cc.ImageView:createNode()
- if isTiPai then
- if i > 1 then
- mWeiCard:loadTextureFromPlist(ZPFuc.getZPCardImgByValue(0xfa,ZPDef.CardType.CARD_TYPE_TABLE))
- else
- mWeiCard:loadTextureFromPlist(ZPFuc.getZPCardImgByValue(card,ZPDef.CardType.CARD_TYPE_TABLE))
- end
- else
- mWeiCard:loadTextureFromPlist(ZPFuc.getZPCardImgByValue(card,ZPDef.CardType.CARD_TYPE_TABLE))--显示真实牌值
- end
- mWeiCard:setScale(self.littleCardScale)
- mWeiCard:setPosition(width/2,0 + height * row + height /2);
- mWeiCard:setTag(1)
- mLayout:addChild(mWeiCard,4-i+1);
- end
-
- if isTiPai then
- mLayout.type = "ti"
- --设置类型
- mLayout:setTag(ZPDef.TableConst.TABLE_CONST_CAN_TOUCH)
- else
- mLayout.type = "pao"
- --设置类型
- mLayout:setTag(ZPDef.TableConst.TABLE_CONST_NO_TOUCH)
- end
-
- self.playerZhao[viewId] = self.playerZhao[viewId] + 1
-
- if bMeTurn and isTiPai then
- --注册点击事件
- mLayout:registerClick(function ()
- --获取TAG,name,tag表示类型,name表示抓取那个layout
- for index,child in pairs(UnitCardNode:getChildren()) do
- local tag = child:getTag()
- if tag == ZPDef.TableConst.TABLE_CONST_CAN_TOUCH then
- for i,v in pairs(child:getChildren()) do
- if v:getTag() == 1 and i > 1 then
- v:loadTextureFromPlist(ZPFuc.getZPCardImgByValue(child.cardList[i],ZPDef.CardType.CARD_TYPE_TABLE))
- v:setScale(self.littleCardScale)
- local seq = cc.Sequence:create(cc.DelayTime:create(1.0),cc.CallFunc:create(function ()
- v:loadTextureFromPlist(ZPFuc.getZPCardImgByValue(0xfa,ZPDef.CardType.CARD_TYPE_TABLE))
- end))
- v:runAction(seq)
- elseif v:getTag() == 2 then
- --txt:setText("")
- end
- end
- end
- end
- end)
- end
-
- --动画
- UnitCardNode:addChild(mLayout);
- if isShowAni then
- self:playWeaveCardAni(mLayout,viewId,1,endPos,onEnd,0,true)
- else
- mLayout:setPosition(endPos)
- end
-
- --提完牌置false
- self.systemTiPai = false
- end
-
- --用户跑牌(自动)
- function ZPRoomView:PaoPai(viewId,card,onEnd)
- --逻辑思考1:数据删除
- --逻辑思考2:根据牌查找当前跑的牌是已经偎的牌或者碰牌的牌(桌面牌)
- --是否轮到我
- local bMeTurn = viewId == self:getMeViewId()
- self.playerZhao[viewId] = self.playerZhao[viewId] + 1
-
- --自己是需要做数据删除的,他人不需要的
- if app.room:isLittleFamily() and (not ZPFuc.getLittleIsCanLookCard()) then
- elseif bMeTurn then --and not app.room:isLittleFamily()
- --倒叙遍历1-10列
- for col = self.lieShuMax,1,-1 do --列数
- for row = 4,1,-1 do --行数
- if card == self.handCardRoot[col].imgList[row].value then
- table.remove(self.handCardValueLocal[col],row)
- self:rankDeletOneBakCard(card)
- --单张图片的值归nil
- self.handCardRoot[col].imgList[row].value = nil
- self.handCardRoot[col].imgList[row].isKan = false
- --单个图片隐藏
- self.handCardRoot[col].imgList[row]:setVisible(false)
- self.handCardRoot[col].imgList[row]:setColor(cc.c3b(255,255,255))
- end
- end
- end
-
- self:neatenCard(true)
- end
-
- --更新自己
- --1.查找桌面牌 碰牌
- --标志:
- local name = string.format("Layout_player1Table_%d",viewId)
- local UnitCardNode = self.ui.Items[name]
- local chlidLayout = UnitCardNode:getChildByName(string.format("%d",card))
- local bIsPengPao = false
- if chlidLayout then
- if chlidLayout.type == "peng2" or chlidLayout.type == "peng3" then
- bIsPengPao = true
- --视图更新
- if chlidLayout.type == "peng3" then
- local mTiCard = cc.ImageView:createNode()
- local thirdSprite = chlidLayout:getChildren()[1]
- local height = thirdSprite:getContentSize().height * self.littleCardScale - self.verticleInterval
- local tarPos = cc.p(thirdSprite:getPositionX(),thirdSprite:getPositionY() + height);
- mTiCard:loadTextureFromPlist(ZPFuc.getZPCardImgByValue(card,ZPDef.CardType.CARD_TYPE_TABLE))
- chlidLayout:addChild(mTiCard);
- chlidLayout.cardList[4] = card
-
- --ani
- self:playWeaveCardAni(mTiCard,viewId,self.littleCardScale,tarPos,onEnd,0,false)
- elseif chlidLayout.type == "peng2" then
- --删除弃牌的牌
- local nSeatId = chlidLayout.nSeatId
- local viewId = app.room:getViewIdBySeatId(nSeatId)
- local name = string.format("Layout_giveUp_%d",viewId)
- local list = self.ui.Items[name]:getChildren()
- for k,mCard in ipairs(list) do
- if mCard.value == card then
- mCard:removeFromParent()
- break
- end
- end
-
- self:updateQiPai(viewId)
-
- --创建2个牌
- for i = 1,2 do
- local mTiCard = cc.ImageView:createNode()
- local thirdSprite = chlidLayout:getChildren()[i + 1]
- local tarPos = cc.p(thirdSprite:getPositionX(),thirdSprite:getPositionY() + thirdSprite:getContentSize().height * self.littleCardScale);
- mTiCard:loadTextureFromPlist(ZPFuc.getZPCardImgByValue(card,ZPDef.CardType.CARD_TYPE_TABLE))
- mTiCard:setPosition(tarPos)
- mTiCard:setScale(self.littleCardScale)
- chlidLayout:addChild(mTiCard);
- chlidLayout.cardList[3] = card
- chlidLayout.cardList[4] = card
- if i == 2 then
- self:playWeaveCardAni(mTiCard,viewId,self.littleCardScale,tarPos,onEnd,0,false)
- end
- end
- end
- elseif chlidLayout.type == "mingwei" or chlidLayout.type == "anwei" then
- bIsPengPao = true
- --屏蔽点击
- chlidLayout:setTouchEnabled(false)
- chlidLayout:setTag(ZPDef.TableConst.TABLE_CONST_NO_TOUCH)
- --显示偎起的牌
- for i,v in ipairs(chlidLayout:getChildren()) do
- --前3张
- if v:getTag() == 1 and i < 4 then
- v:loadTextureFromPlist(ZPFuc.getZPCardImgByValue(chlidLayout.cardList[i],ZPDef.CardType.CARD_TYPE_TABLE))
- end
- end
-
- --视图更新
- local mTiCard = cc.ImageView:createNode()
- local thirdSprite = chlidLayout:getChildren()[1]
- local tarPos = cc.p(thirdSprite:getPositionX(),thirdSprite:getPositionY() + thirdSprite:getContentSize().height * self.littleCardScale);
- mTiCard:loadTextureFromPlist(ZPFuc.getZPCardImgByValue(card,ZPDef.CardType.CARD_TYPE_TABLE))
- chlidLayout:addChild(mTiCard);
- chlidLayout.cardList[4] = card
- self:playWeaveCardAni(mTiCard,viewId,self.littleCardScale,tarPos,onEnd,0,false)
- end
- chlidLayout.type = "pao"
- end
-
- if not bIsPengPao then
- local list = {card,card,card,card}
- self:createTiOrPaoView(false,viewId,list,true,onEnd)
- end
- end
-
- --用户碰(自动)
- function ZPRoomView:Peng(viewId,card,isMoPaiOrId,onEnd)
- --是否轮到我
- local bMeTurn = viewId == self:getMeViewId()
- --自己是需要做数据删除的,他人不需要的
- if app.room:isLittleFamily() and (not ZPFuc.getLittleIsCanLookCard()) then
- elseif bMeTurn then --and not app.room:isLittleFamily()
- --倒叙遍历1-10列
- for col = self.lieShuMax,1,-1 do --列数
- for row = self.hangShuMax,1,-1 do --行数
- if card == self.handCardRoot[col].imgList[row].value then --判断值是否相等
- table.remove(self.handCardValueLocal[col],row)
- self:rankDeletOneBakCard(card)
- --单张图片的值归nil
- self.handCardRoot[col].imgList[row].value = nil
- self.handCardRoot[col].imgList[row].isKan = false
- --单个图片隐藏
- logE("RoomView:Peng col:"..col)
- logE("RoomView:Peng row:"..row)
- self.handCardRoot[col].imgList[row]:setVisible(false)
- self.handCardRoot[col].imgList[row]:setOpacity(255)
- end
- end
- end
- self:neatenCard(true)
- end
-
- local list = {card,card,card}
- self:createPengView(viewId,list,true,isMoPaiOrId)
-
- if onEnd then
- onEnd()
- end
- end
-
- --创建碰的UI
- function ZPRoomView:createPengView(viewId,list,isShowAni,isMoPaiOrId)
- --是否轮到我
- local bMeTurn = viewId == self:getMeViewId()
- local card = list[1]
- --更新自己(3张暗加一个数字(值分大小写))
- --获取自己的出牌点
- local name = string.format("Layout_player1Table_%d",viewId)
- local UnitCardNode = self.ui.Items[name]
- --获取出牌点的儿子数量
- local count = UnitCardNode:getChildrenCount();
- --数量即为列数
- local col = count;
-
- --牌大小
- local mSprite = cc.ImageView:createNode()
- local FileName = ZPFuc.getZPCardImgByValue(card,ZPDef.CardType.CARD_TYPE_TABLE)
- mSprite:loadTextureFromPlist(FileName)
- local width = mSprite:getContentSize().width * self.littleCardScale + self.cardInterval
- local height = mSprite:getContentSize().height * self.littleCardScale - self.verticleInterval
-
- --创建一个空的layout,layout放到组合牌点上
- local mLayout = cc.Layout:createNode()
- --1.记录坐标
- local endPos = nil
- if bMeTurn then
- endPos = cc.p(width * col,0)
- elseif viewId == 1 then
- endPos = cc.p(-width * col,0)
- else
- endPos = cc.p(width * col,0)
- end
- --设置锚点
- mLayout:setAnchorPoint(cc.p(0,1))
- --设置大小
- mLayout:setSize(cc.size(width,height*3))
- --layout数据存储:
- --下面的牌数据:
- mLayout.cardList = {}
- --查找layout的唯一性
- mLayout:setName(string.format("%d",card))
- mLayout.type = "peng3"
- mLayout:setTag(ZPDef.TableConst.TABLE_CONST_NO_TOUCH)
- --判断是不是摸牌,如果是摸牌碰就3张,不是就2张,放炮的人显示一张牌为弃牌
- local forTimeS = 3
-
- for i = 1,forTimeS do
- local mPengCard;
- local row = i - 1;
- --数据
- mLayout.cardList[i] = card
- --界面
- mPengCard = cc.ImageView:createNode()
- mPengCard:loadTextureFromPlist(ZPFuc.getZPCardImgByValue(card,ZPDef.CardType.CARD_TYPE_TABLE))
- mPengCard:setScale(self.littleCardScale)
- mPengCard:setPosition(width/2,0 + height * row - height /2);
- mLayout:addChild(mPengCard,forTimeS-i+1);
- end
-
- UnitCardNode:addChild(mLayout);
-
- --2.全部拷贝动画
- if isShowAni then
- self:playWeaveCardAni(mLayout,viewId,1,endPos,nil,1.0,true)
- else
- mLayout:setPosition(endPos)
- end
- end
-
-
- --[[
- node:节点
- viewId:视图ID
- targetBeiShu:起始倍数
- tarPos:目标点
- callback:回调
- offY:坐标偏移倍数(高度)
- isLayout:是否是容器true,单个牌是false
- ]]
- function ZPRoomView:playWeaveCardAni(node,viewId,targetBeiShu,tarPos,callback,offY,isLayout)
- local childLayout = node:getParent()
- local size
- if isLayout then
- size = node:getSize()
- else
- size = childLayout:getSize()
- end
- local pos = self.PlayerView.allNodes[viewId].tip:getWorldPosition()
- local beginPos = childLayout:convertToNodeSpace(pos)
- beginPos = cc.p(beginPos.x - size.width/2,beginPos.y + size.height * offY)
- node:setPosition(beginPos);
-
- --移动时间
- local moveTime = 0.35
- --初始倍数
- local spawn = cc.Spawn:create(cc.ScaleTo:create(moveTime,targetBeiShu),cc.MoveTo:create(moveTime,tarPos))
- local seq = cc.Sequence:create(cc.ScaleTo:create(0,1.5),cc.DelayTime:create(0.5),spawn,cc.CallFunc:create(function ()
- if callback then
- callback()
- end
- end))
- node:runAction(seq)
- end
-
- --用户吃(手动)
- function ZPRoomView:Chi(viewId,card,onEnd)
- --根据code解码吃的种类
- local list = {}
- local index = 1
- local operateCodeNum = table.nums(self.operationSuccessCode)
- logE("ZPRoomView:Chi operateCodeNum:")
- logE(operateCodeNum)
-
- for k,v in ipairs(self.operationSuccessCode) do
- local mType = v.nOperationCode
- --左吃顺子
- local ret1 = bit32.band(mType,ZPDef.OpCode.OP_CHI_LEFT_SHUN_ZI)
- --中吃顺子
- local ret2 = bit32.band(mType,ZPDef.OpCode.OP_CHI_MID_SHUN_ZI)
- --右吃顺子
- local ret3 = bit32.band(mType,ZPDef.OpCode.OP_CHI_RIGHT_SHUN_ZI)
- --吃同色搭子(壹壹一,吃牌为一)
- local ret4 = bit32.band(mType,ZPDef.OpCode.OP_CHI_DA_ZI_BY_SAME)
- --大小搭吃
- local ret5 = bit32.band(mType,ZPDef.OpCode.OP_CHI_DA_ZI_BY_MIX)
- --二七十
- local ret6 = bit32.band(mType,ZPDef.OpCode.OP_CHI_TWO_SEVEN_TEN)
-
- --判断是否有吃牌组合
- if ret1 > 0 then
- list[index] = ZPFuc.getZPEatCardWeave(card,ZPDef.OpCode.OP_CHI_LEFT_SHUN_ZI)
- index = index + 1
- end
- if ret2 > 0 then
- list[index] = ZPFuc.getZPEatCardWeave(card,ZPDef.OpCode.OP_CHI_MID_SHUN_ZI)
- index = index + 1
- end
- if ret3 > 0 then
- list[index] = ZPFuc.getZPEatCardWeave(card,ZPDef.OpCode.OP_CHI_RIGHT_SHUN_ZI)
- index = index + 1
- end
- if ret4 > 0 then
- list[index] = ZPFuc.getZPEatCardWeave(card,ZPDef.OpCode.OP_CHI_DA_ZI_BY_SAME)
- index = index + 1
- end
- if ret5 > 0 then
- list[index] = ZPFuc.getZPEatCardWeave(card,ZPDef.OpCode.OP_CHI_DA_ZI_BY_MIX)
- index = index + 1
- end
- if ret6 > 0 then
- list[index] = ZPFuc.getZPEatCardWeave(card,ZPDef.OpCode.OP_CHI_TWO_SEVEN_TEN)
- index = index + 1
- end
- end
- logE("RoomView:Chi onEatCardCallBack list data:"..table.tostring(list))
-
-
- --吃的牌数组
- local chiPaiList = {}
- local chiShowPaiList = {}
- --比的牌数组
- local biPaiList = {}
- --下标
- local nforCount = 1
- for i = 1, #list do
- for j = 1, 3 do
- if i == 1 then
- chiPaiList[nforCount] = list[i][j]
-
- else
- biPaiList[nforCount] = list[i][j]
- end
-
- nforCount = nforCount + 1
- end
- end
-
- logE("RoomView: chi chiPaiList : "..table.tostring(chiPaiList))
- logE("RoomView: chi biPaiList : "..table.tostring(biPaiList))
-
- chiShowPaiList = DeepCopy(chiPaiList)
-
- --是否轮到我
- local bMeTurn = viewId == self:getMeViewId()
- --自己是需要做数据删除的,他人不需要的
- if app.room:isLittleFamily() and (not ZPFuc.getLittleIsCanLookCard()) then
- elseif bMeTurn then--and not app.room:isLittleFamily()
- self.isGodHand = true
- --删除吃的那个牌
- for i = #chiPaiList,1,-1 do
- if chiPaiList[i] == card then
- table.remove(chiPaiList,i)
- break
- end
- end
-
- logE("RoomView:Chi chiPaiList after delete: "..table.tostring(chiPaiList))
-
- local isEnd = false
- local i = 1
- local indexWhile = 1
- while chiPaiList[i] do
- if indexWhile > 8 then
- logE("RoomView:Chi death while")
- break
- end
-
- indexWhile = indexWhile + 1
-
- for col = self.lieShuMax,1,-1 do --列数
- for row = self.hangShuMax,1,-1 do --行数
- if chiPaiList[i] == self.handCardValueLocal[col][row] then --判断值是否相等
- table.remove(self.handCardValueLocal[col],row)
- self:rankDeletOneBakCard(chiPaiList[i])
- --单张图片的值归nil
- self.handCardRoot[col].imgList[row].value = nil
- self.handCardRoot[col].imgList[row].isKan = false
- --单个图片隐藏
- self.handCardRoot[col].imgList[row]:setVisible(false)
- self.handCardRoot[col].imgList[row]:setColor(cc.c3b(255,255,255))
- self.handCardRoot[col].imgList[row]:setOpacity(255)
- i = i + 1
- isEnd = true
- self:downCard()
- break
- end
- end
- if isEnd then
- isEnd = false
- break
- end
- end
- end
- logE("RoomView:Chi Pai do end")
- self:neatenCard(true)
- end
-
- --比牌操作
- local function callback(onEnd)
- if app.room:isLittleFamily() and (not ZPFuc.getLittleIsCanLookCard()) then
- elseif bMeTurn then--and not app.room:isLittleFamily()
- local isEnd = false
- local i = 4
- local indexWhile = 1
- while biPaiList[i] do
- if indexWhile > 16 then
- logE("RoomView:Bi death while")
- --self.toolView:onClickLog()
- break
- end
-
- indexWhile = indexWhile + 1
-
- for col = self.lieShuMax,1,-1 do --列数
- for row = self.hangShuMax,1,-1 do --行数
- if biPaiList[i] == self.handCardValueLocal[col][row] then --判断值是否相等
- table.remove(self.handCardValueLocal[col],row)
- self:rankDeletOneBakCard(biPaiList[i])
- --单张图片的值归nil
- self.handCardRoot[col].imgList[row].value = nil
- self.handCardRoot[col].imgList[row].isKan = false
- --单个图片隐藏
- self.handCardRoot[col].imgList[row]:setVisible(false)
- self.handCardRoot[col].imgList[row]:setColor(cc.c3b(255,255,255))
- self.handCardRoot[col].imgList[row]:setOpacity(255)
- i = i + 1
- isEnd = true
- self:downCard()
- break
- end
- end
- if isEnd then
- isEnd = false
- break
- end
- end
- end
- self:neatenCard(true)
- logE("RoomView:Bi Pai do end")
- end
- logE("biPaiList"..table.tostring(biPaiList))
- self:createEatView(card,viewId,biPaiList,true,nil,nil)
- if onEnd then
- onEnd()
- end
- end
-
- if operateCodeNum > 1 then
- self:showOperatorTip(viewId,ZPDef.OpType.OP_TYPE_CHI)
- local nUserID = app.room:getUserIdByViewId(viewId)
- self:createEatView(card,viewId,chiShowPaiList,true,callback,onEnd)
- else
- self:showOperatorTip(viewId,ZPDef.OpType.OP_TYPE_CHI)
- local nUserID = app.room:getUserIdByViewId(viewId)
- self:createEatView(card,viewId,chiShowPaiList,true)
- if onEnd then
- onEnd()
- end
- end
-
- end
-
- --创建吃的UI
- function ZPRoomView:createEatView(card,viewId,list,isShowAni,callbackFunc,onEnd)
- --是否轮到我
- local bMeTurn = viewId == self:getMeViewId()
- --更新视图
- --获取自己的出牌点
- local name = string.format("Layout_player1Table_%d",viewId)
- local UnitCardNode = self.ui.Items[name]
-
- --牌大小
- local mSprite = cc.ImageView:createNode()
- local FileName = ZPFuc.getZPCardImgByValue(card,ZPDef.CardType.CARD_TYPE_TABLE)
- mSprite:loadTextureFromPlist(FileName)
- local width = mSprite:getContentSize().width * self.littleCardScale + self.cardInterval
- local height = mSprite:getContentSize().height * self.littleCardScale - self.verticleInterval
- local mLayout = nil
-
- --list 反向操作
- local tempList = {}
- for k,v in pairsByKeys(list) do
- table.insert(tempList,v)
- end
-
- local max = tempList[3]
- tempList[3] = tempList[1]
- tempList[1] = max
-
- if #tempList > 4 then
- local max = tempList[6]
- tempList[6] = tempList[4]
- tempList[4] = max
- end
-
- local endPos = nil
- logE("tempList:"..table.tostring(tempList))
- for k,weaveCard in pairsByKeys(tempList) do
- if k % 3 == 1 then
- --获取出牌点的儿子数量
- local count = UnitCardNode:getChildrenCount();
- --数量即为列数
- local col = count;
- --创建一个空的layout,layout放到组合牌点上
- mLayout = cc.Layout:createNode()
- mLayout:setTag(ZPDef.TableConst.TABLE_CONST_NO_TOUCH)
- if bMeTurn then
- endPos = cc.p(width * col,0)
- elseif viewId == 1 then
- endPos = cc.p(-width * col,0)
- else
- endPos = cc.p(width * col,0)
- end
- --设置锚点
- mLayout:setAnchorPoint(cc.p(0,1))
- --设置大小
- mLayout:setSize(cc.size(width,height*3))
- --layout数据存储:
- mLayout.type = "chi"
- mLayout.cardList = tempList
- --顺子没用到
- mLayout:setName("10086")
- end
-
- local cardShow = weaveCard
- local row = (k % 3) - 1
- if k % 3 == 0 then
- row = 2
- end
- --界面
- local mWeiCard = cc.ImageView:createNode()
- mWeiCard:loadTextureFromPlist(ZPFuc.getZPCardImgByValue(cardShow,ZPDef.CardType.CARD_TYPE_TABLE))
- mWeiCard:setScale(self.littleCardScale)
- mWeiCard:setPosition(width/2,0 + height * row - height /2);
- mLayout:addChild(mWeiCard,#tempList-k+1);
- if row == 2 then
- --mWeiCard:setOpacity(125)
- end
-
- if k % 3 == 0 then
- --动画
- UnitCardNode:addChild(mLayout);
- if isShowAni then
- self:playWeaveCardAni(mLayout,viewId,1,endPos,nil,1.0,true)
- else
- mLayout:setPosition(endPos)
- end
- end
- end
-
- if callbackFunc then
- logE("RoomView:bi Pai will do start")
- self.ui:runAction(cc.Sequence:create(cc.DelayTime:create(0.5),cc.CallFunc:create(function ()
- callbackFunc(onEnd)
- end)))
- end
- end
-
-
- --摸牌
- function ZPRoomView:onMoPai(data)
- local function runOnMoPai(onEnd)
- local response = data.response
- local nUserId = response.nUserId
- local turnOverCard = response.turnOverCard
- local code = response.mainOpCode
- local leftCardNum = response.leftCardNum
- local operations = response.operations
- local showCardFlag = response.showCardFlag
-
- local viewId = app.room:getViewIdByUserId(nUserId)
- self.EatOperationCode = code
- self.outCard = turnOverCard
- self.moPaiViewId = viewId
-
- self:showDelayTimeTip(operations)
-
- --更新剩余牌数
- self:playMoPaiAni(leftCardNum,turnOverCard,viewId,code,showCardFlag,onEnd)
-
- if self.bankerBaoPao then
- self.bankerBaoPao = nil
- self:showTiPaiBtn(true)
- --小家不能看牌时,牌堆牌显示剩余张数
- if app.room:isLittleFamily() and (not ZPFuc.getLittleIsCanLookCard()) then
- self:setCircleCardLeftPanelView(true,viewId,19)
- end
- end
- if self:getIsMeUId(nUserId) then
- --检测是否少牌
- self:checkCardAndRecover()
- end
- end
- log("2000000000-ZPRoomView - addCallBack(runOnMoPai)")
-
- self:setLiangPaiVisible(false)--解决托管自动出牌的时候,查牌界面还存在
- self:addCallBack(runOnMoPai)
- end
-
- --播放摸牌动画
- --[[
- leftCardNum:剩余牌
- turnOverCard: 摸的牌
- viewId:视图ID
- mainOpCode:操作码
- showCardFlag:是否显示牌 0;不能 1:能
- isNotShowAni:不显示动画
- ]]
- function ZPRoomView:playMoPaiAni(leftCardNum,turnOverCard,viewId,mainOpCode,showCardFlag,onEnd,isNotShowAni)
- self.isMoPaiOperator = true
-
- --重置出牌坐标
- self:resetOutCardPoint()
-
- --图片
- local outCardname = string.format("ImageView_outCardImg_%d",viewId)
- local outCardLayoutName = string.format("Layout_outCardPoint_%d",viewId)
- local mSprite = self.ui.Items[outCardname]
- local srcPos = mSprite:getPosition()
- local fileName = ZPFuc.getZPCardImgByValue(0xfa,ZPDef.CardType.CARD_TYPE_OUTCARD)
- local fileNameReal = ZPFuc.getZPCardImgByValue(turnOverCard,ZPDef.CardType.CARD_TYPE_OUTCARD)
-
- self.ui.Items[outCardLayoutName]:setVisible(true)
-
-
- if viewId == self:getMeViewId() then
- mSprite:loadTextureFromPlist(fileNameReal)
- end
-
- --公谱出牌不串不哨立马亮牌,看到亮牌的听得到牌的音效
- if mainOpCode ~= ZPDef.OpCode.OP_CANCEL then
- mSprite:loadTextureFromPlist(fileNameReal)
- mSprite.value = turnOverCard
- else
- if showCardFlag == 1 then
- mSprite:loadTextureFromPlist(fileNameReal)
- mSprite.value = turnOverCard
- if not isNotShowAni then
- local nUserId = app.room:getUserIdByViewId(viewId)
- local userInfo=app.room:getUserInfo(nUserId)
- if userInfo then
- if turnOverCard > 0 and turnOverCard < 32 then
- ZPSound.PlayZPSound(userInfo.sex,turnOverCard)
- end
- end
- end
- else
- mSprite:loadTextureFromPlist(fileName)
- mSprite.value = 0xfa
- end
- end
-
- self:changeOutCardLight(true)
-
- local function callback()
- if mainOpCode ~= ZPDef.OpCode.OP_CANCEL then
- self.EatOperationCode = mainOpCode
- self:showOpeation(mainOpCode,viewId,turnOverCard)
- end
- end
-
- if isNotShowAni then
- mSprite:setPosition(srcPos)
- callback()
- if onEnd then
- onEnd()
- end
- return
- else
- local outCardLightName = string.format("ImageView_outCardLight_%d",viewId)
- self.ui.Items[outCardLightName]:setVisible(false)
- mSprite:setScale(0)
-
- if showCardFlag ~= 1 then
- mSprite:loadTextureFromPlist(fileName)
-
- --起始坐标调整和角度,扫为横的出来
- if viewId == self:getMeViewId() then
- mSprite:setEulerRotation(cc.vec3(0,0,0))
- beginPos = cc.p(srcPos.x,srcPos.y + 200)
- elseif viewId == 1 then
- mSprite:setEulerRotation(cc.vec3(0,0,-90))
- beginPos = cc.p(srcPos.x - 200 ,srcPos.y)
- elseif viewId == 2 then
- mSprite:setEulerRotation(cc.vec3(0,0,0))
- beginPos = cc.p(srcPos.x,srcPos.y - 100)
- elseif viewId == 3 then
- mSprite:setEulerRotation(cc.vec3(0,0,-90))
- beginPos = cc.p(srcPos.x + 200 ,srcPos.y-50)
- end
-
- mSprite:setPosition(beginPos)
-
- --目标调整、角度
- if viewId == 1 then
- srcPos = cc.p(srcPos.x + 250,srcPos.y)
- elseif viewId == 2 then
- srcPos = cc.p(srcPos.x,srcPos.y+50)
- elseif viewId == 3 then
- srcPos = cc.p(srcPos.x - 250,srcPos.y-50)
- elseif viewId == 4 then
- srcPos = cc.p(srcPos.x,srcPos.y-100)
- end
-
- mSprite:setScale(1)
- mSprite:runAction(cc.Sequence:create(cc.MoveTo:create(0.3,srcPos),cc.CallFunc:create(function ()
- self.ui.Items[outCardLightName]:setVisible(true)
- end),cc.CallFunc:create(function ()
- --恢复原来的角度
- if viewId == self:getMeViewId() then
- mSprite:setEulerRotation(cc.vec3(0,0,90))
- elseif viewId == 1 then
- mSprite:setEulerRotation(cc.vec3(0,0,0))
- elseif viewId == 2 then
- mSprite:setEulerRotation(cc.vec3(0,0,90))
- elseif viewId == 3 then
- mSprite:setEulerRotation(cc.vec3(0,0,0))
- end
- self.ui.Items[outCardLayoutName]:setVisible(false)
- self:setCircleCardLeftPanelView(true,viewId,leftCardNum)
- callback()
- if onEnd then
- onEnd()
- end
- end)))
- else
- if mainOpCode ~= ZPDef.OpCode.OP_CANCEL then
- local nUserId = app.room:getUserIdByViewId(viewId)
- local userInfo=app.room:getUserInfo(nUserId)
- if userInfo then
- ZPSound.PlayZPSound(userInfo.sex,turnOverCard)
- end
- end
- --播放摸牌动画(这里最好用出牌器的坐标进行转换,暂时这样调整吧)
- if viewId == self:getMeViewId() then
- beginPos = cc.p(srcPos.x,srcPos.y + 200)
- elseif viewId == 1 then
- beginPos = cc.p(srcPos.x - 300 ,srcPos.y)
- elseif viewId == 2 then
- beginPos = cc.p(srcPos.x ,srcPos.y - 200)
- elseif viewId == 3 then
- beginPos = cc.p(srcPos.x + 300 ,srcPos.y)
- end
-
- mSprite:setPosition(beginPos)
- local mSpawn = cc.Spawn:create(cc.ScaleTo:create(self.gameSpeedConfig.MO_PAI_TIME,1.0),cc.MoveTo:create(self.gameSpeedConfig.MO_PAI_TIME,srcPos))
- mSprite:runAction(cc.Sequence:create(mSpawn,cc.CallFunc:create(function ()
- self.ui.Items[outCardLightName]:setVisible(true)
- --显示指示器
- self:setCircleCardLeftPanelView(true,viewId,leftCardNum)
- end),cc.DelayTime:create(0.15),cc.CallFunc:create(function ()
- callback()
- if onEnd then
- onEnd()
- end
- end)))
- end
- end
- end
-
- --弃牌
- function ZPRoomView:onQiPai(data)
- local function runOnQiPai(onEnd)
- logE("2000000000-ZPRoomView onQiPai : "..table.tostring(data.response))
- local response = data.response
- local nUserId = response.nUserId
- local disCard = response.disCard
- local viewId = app.room:getViewIdByUserId(nUserId)
- self:playQiPaiAni(true,disCard,viewId,onEnd)
- self.isGodHand = false
- end
- log("2000000000-ZPRoomView - addCallBack(runOnQiPai)")
- self:addCallBack(runOnQiPai)
- end
-
- --弃牌动画
- --断线重连的时候,不需要动画
- --[[
- isShowAni:是否展示弃牌动画
- disCard:弃牌
- viewId:视图ID
- isDianPaoPeng:碰胡规则,点炮碰,弃牌要显示透明形态
- ]]
- function ZPRoomView:playQiPaiAni(isShowAni,disCard,viewId,onEnd,isDianPaoPeng)
- local outCardname = string.format("ImageView_outCardImg_%d",viewId)
- local outCardPoint = string.format("Layout_outCardPoint_%d",viewId)
- local giveupCardname = string.format("Layout_giveUp_%d",viewId)
-
- --牌的图片
- local outCardImg = self.ui.Items[outCardname]
- --牌的图片父节点
- local outCardLayout = self.ui.Items[outCardPoint]
-
- --弃牌的layout
- local giveUpLayout = self.ui.Items[giveupCardname]
- --获取弃牌节点存在的数量
- local count = giveUpLayout:getChildrenCount()
- --创建一张精灵
- local mSprite = cc.ImageView:createNode()
- mSprite:setScale(self.littleCardScale)
- local finalFileName = ZPFuc.getZPCardImgByValue(disCard,ZPDef.CardType.CARD_TYPE_TABLE)
- mSprite:loadTextureFromPlist(finalFileName)
- mSprite:setVisible(false)
- mSprite:setAnchorPoint(cc.p(0,0))
- mSprite.value = disCard
- giveUpLayout:addChild(mSprite)
-
-
- local width = mSprite:getContentSize().width * self.littleCardScale;
- local height = mSprite:getContentSize().height * self.littleCardScale;
-
- local getHeightCount = function (count)
- if count >= 6 then
- return math.floor(count/6)
- else
- return 0
- end
- end
- local x = count % 6
-
- local tarPos
- if viewId == 1 then
- local adjustPos = cc.p(width * x,height * getHeightCount(count))
- tarPos = cc.p(0 - adjustPos.x,0 - adjustPos.y)
- elseif viewId == 2 then
- local adjustPos = cc.p(width * x,getHeightCount(count) * height)
- tarPos = cc.p(0 - adjustPos.x,0 - adjustPos.y)
- elseif viewId == 3 then
- local adjustPos = cc.p(width * x,height * getHeightCount(count))
- tarPos = cc.p(0 + adjustPos.x,0 - adjustPos.y)
- elseif viewId == self:getMeViewId() then
- local adjustPos = cc.p(width * x,height * getHeightCount(count))
- tarPos = cc.p(0 - adjustPos.x,0 - adjustPos.y)
- end
-
- mSprite:setPosition(tarPos)
-
- --动画显示
- if not isShowAni then
- mSprite:setVisible(true)
- if isDianPaoPeng then
- mSprite:setColor(cc.c3b(125,125,125))
- end
- else
- local fileName = ZPFuc.getZPCardImgByValue(disCard,ZPDef.CardType.CARD_TYPE_OUTCARD)
- --弃牌
- local giveSprite = cc.ImageView:createNode()
- giveSprite:loadTextureFromPlist(fileName)
- giveSprite:setScale(self.outCardScale)
- giveUpLayout:addChild(giveSprite)
- giveSprite:setVisible(false)
-
- local spriteSizeWidth = giveSprite:getContentSize().width * self.outCardScale
- local spriteSizeHeight = giveSprite:getContentSize().height * self.outCardScale
- local worldPos = outCardImg:convertToWorldSpace(outCardImg:getPosition())
- local nodePos = giveUpLayout:convertToNodeSpace(worldPos)
- --调整上下2个玩家的坐标和牌的角度
- if viewId == 2 or viewId == 4 then
- --nodePos = cc.p(nodePos.x - spriteSizeWidth,nodePos.y - spriteSizeHeight/2)
- --giveSprite:setEulerRotation(cc.vec3(0,0,90))
- end
- giveSprite:setPosition(nodePos)
-
-
- local mSpawn = cc.Spawn:create(cc.MoveTo:create(self.gameSpeedConfig.QI_PAI_TIME,tarPos),cc.ScaleTo:create(self.gameSpeedConfig.QI_PAI_TIME,self.outCardScale - 0.7))
- giveSprite:runAction(cc.Sequence:create(cc.DelayTime:create(0.3),cc.CallFunc:create(function ()
- outCardLayout:setVisible(false)
- giveSprite:setVisible(true)
- end),mSpawn,cc.CallFunc:create(function ()
- mSprite:setVisible(true)
- if isDianPaoPeng then
- mSprite:setColor(cc.c3b(125,125,125))
- end
- end),cc.RemoveSelf:create()))
-
- --要求弃牌飞到一半,摸牌就开始摸了
- mSprite:runAction(cc.Sequence:create(cc.DelayTime:create(0.4 + self.gameSpeedConfig.QI_PAI_TIME/2),cc.CallFunc:create(function ()
- if onEnd then
- onEnd()
- end
- end)))
- end
- end
-
- --更新弃牌区
- function ZPRoomView:updateQiPai(viewId)
- local giveupCardname = string.format("Layout_giveUp_%d",viewId)
- local node = self.ui.Items[giveupCardname]
- local list = node:getChildren()
- local tt = {}
- for k,mCard in pairs(list) do
- table.insert(tt,mCard.value)
- end
- node:removeAllChildren()
- for k,card in ipairs(tt) do
- self:playQiPaiAni(false,card,viewId,nil)
- end
- end
-
- --操作错误
- function ZPRoomView:onOperationError(data)
- local function runOnOperationError(onEnd)
- log("2000000000-ZPRoomView - (runOnOperationError)")
- --恢复操作面板
- self.operationView:touchEatOneCardCallBack()
-
- if onEnd then
- onEnd()
- end
- end
- log("2000000000-ZPRoomView - addCallBack(runOnOperationError)")
-
- self:addCallBack(runOnOperationError)
- end
-
- --听牌结果
- function ZPRoomView:onTingCardResult(data)
- local function runTingCardResult(onEnd)
- log("2000000000-ZPRoomView - (runTingCardResult)")
- local response = data.response
- local outCard = response.outCard
- local tingCards = response.tingCards
- app.room.roomInfo.tingCards = response.tingCards
- local max = table.nums(tingCards)
- if max > 0 then
- self:setTingCardViewVisible(true,tingCards)
- else
- self:setTingCardViewVisible(false)
- end
- if onEnd then
- onEnd()
- end
- local isCanBao = response.canBaoPai
- if isCanBao == 1 then
- self.operationView:showBaoPaiOpView(true)
- end
- end
- log("2000000000-ZPRoomView - addCallBack(runTingCardResult)")
-
- self:addCallBack(runTingCardResult)
- end
-
- function ZPRoomView:onChoicePlace(data)
- local function runChoicePlace(onEnd)
- log("2000000000-ZPRoomView - (runChoicePlace)")
- local response = data.response
- local placeList = response.place
-
- --修改椅子号
- local playerInfo = app.room.roomInfo.memberList
-
- for k,v in pairs(placeList) do
- playerInfo[v.nUserId].nSeatId = v.nSeatId
- end
-
- app.room:updateUserSeateShowId()
-
- self:resetGameData()
- self:onGameReconnection()
- if onEnd then
- onEnd()
- end
- end
- log("2000000000-ZPRoomView - addCallBack(runChoicePlace)")
-
- self:addCallBack(runChoicePlace)
- end
-
- function ZPRoomView:setTingCardViewVisible(bVisible,tingCards)
- if app.room:isLittleFamily() then
- bVisible = false
- end
- self.ui.Items.Layout_TingPai:setVisible(bVisible)
- if bVisible then
- self.ui.Items.Layout_TingCard:removeAllChildren()
- self.ui.Items.Layout_TingCardItem:setVisible(false)
-
- --因为需要添加张数显示而增加的背景高度差
- local tingCardOffHeight = 0
- --听牌本地数据
- self.tingCardLocal = {}
- --只听模式
- self.isNoCardTingPai = false
- --显示听或者多
- self:dealTingCard(tingCards)
- for k,list in pairs(tingCards) do
- local outCard = list.outCard
- local valueList = list.tingCardValue
- local imgType = list.imgType
- --不显示标签,比如地胡,直接显示界面
- if outCard == 0 then
- self.isNoCardTingPai = true
- for i,j in pairs(valueList) do
- local tingCardNum = j.tingCardNum
- local tingCard = j.tingCard
- local tingPaiUI = self.ui.Items.Layout_TingCardItem:getCopied()
- tingPaiUI.Items = getUIItems(tingPaiUI);
- tingPaiUI:setVisible(true)
- self.ui.Items.Layout_TingCard:addChild(tingPaiUI)
- if tingCard then
- local name = ZPFuc.getZPCardImgByValue(tingCard,ZPDef.CardType.CARD_TYPE_TABLE)
- tingPaiUI.Items.ImageView_TingCard:loadTextureFromPlist(name)
- end
- tingPaiUI.Items.Text_TingCardNum:setText(tostring(tingCardNum).."张")
- --听牌剩余多少张,隐藏,但代码保留吧
- if self:setTingCardZhangShuVisible(tingPaiUI.Items.Text_TingCardNum) then
- tingCardOffHeight = 20
- end
- end
- --背景拉伸
- local maxNum = table.nums(valueList)
- if maxNum > 4 then
- local newSizeWidth = maxNum * self.ui.Items.Layout_TingCardItem:getContentSize().width + 43
- local srcHeight = self.tingPaibgSrcHeight + tingCardOffHeight
- self.ui.Items.ImageView_TingPai_bg:setSize(cc.size(newSizeWidth,srcHeight))
- self.ui.Items.Layout_TingCard:setPositionX(newSizeWidth/2)
- else
- local srcWidth = self.ui.Items.ImageView_TingPai_bg:getContentSize().width
- local srcHeight = self.tingPaibgSrcHeight + tingCardOffHeight
- self.ui.Items.ImageView_TingPai_bg:setSize(cc.size(srcWidth,srcHeight))
- end
- else
- --需要显示标签,但不显示听牌界面,需要玩家点击标签后,出现听牌界面
- self.ui.Items.Layout_TingPai:setVisible(false)
- self.tingCardLocal[outCard] = valueList
- --倒叙遍历1-10列
- for col = self.lieShuMax,1,-1 do --列数
- for row = self.hangShuMax,1,-1 do --行数
- local card = self.handCardRoot[col].imgList[row].value
- if outCard == card then --判断值是否相等
- local node = self.handCardRoot[col].imgList[row]:getChildren()[1]
- node:setVisible(true)
- self:showMutilTypeTingFlag(imgType,node)
- end
- end
- end
- end
- end
-
- self.ui.Items.Layout_TingCard:requestDoLayout()
- self.ui.Items.Layout_TingCard:doLayout()
- else
- self.isNoCardTingPai = false
- self.tingCardLocal = {}
- --所有的标签设置隐藏
- if self.handCardRoot and table.nums(self.handCardRoot) > 0 then
- for col = self.lieShuMax,1,-1 do --列数
- for row = self.hangShuMax,1,-1 do --行数
- if self.handCardRoot[col].imgList[row]:getChildren() then
- local card = self.handCardRoot[col].imgList[row]:getChildren()[1]
- if card then
- self.handCardRoot[col].imgList[row]:getChildren()[1]:setVisible(false)
- end
- end
- end
- end
- end
- end
- end
-
-
- function ZPRoomView:dealTingCard(tingCards)
- if not tingCards or table.nums(tingCards) == 0 then
- return
- end
- local imgType = {
- ting = 1,
- duo = 2
- }
- local tt = {}
- for k,v in ipairs(tingCards) do
- table.insert(tt,v)
- end
- table.sort(tt, function (a,b)
- if not a or not b then
- return
- end
- return table.nums(a.tingCardValue) < table.nums(b.tingCardValue)
- end)
-
- local maxIdx = table.nums(tt)
-
- for k,v in ipairs(tt) do
- v.imgType = imgType.ting
- end
-
- if #tt[1].tingCardValue ~= #tt[maxIdx].tingCardValue then
- for k,v in ipairs(tt) do
- if #v.tingCardValue == #tt[maxIdx].tingCardValue then
- v.imgType = imgType.duo
- end
- end
- end
-
- tingCards = tt
- end
-
- function ZPRoomView:setTingCardZhangShuVisible(node)
- if node then
- node:setVisible(false)
- end
- return false
- end
-
- function ZPRoomView:showMutilTypeTingFlag(imgType,node)
- --[[if tingCardTypeNum and tingCardTypeNum > 1 then
- node:loadTexture("zp_base/res/ui/zy_fangjian/zipai_fangjian_new/zipai_fangjian_new_duo.png")
- else
- node:loadTexture("zp_base/res/ui/zy_fangjian/zipai_fangjian_new/zipai_fangjian_new_ting.png")
- end--]]
- end
-
- --[[
- touchcCard:触摸传进来的牌
- 功能:点击哪个牌显示听什么牌
- ]]
- function ZPRoomView:showTingPaiView(touchcCard)
- if touchcCard then
- local valueList = self.tingCardLocal[touchcCard]
- if valueList then
- --因为需要添加张数显示而增加的背景高度差
- local tingCardOffHeight = 0
- logE("showTingPaiView valueList"..table.tostring(valueList))
- self.ui.Items.Layout_TingCard:removeAllChildren()
- self.ui.Items.Layout_TingCardItem:setVisible(false)
-
- for i,j in pairs(valueList) do
- local tingCardNum = j.tingCardNum
- local tingCard = j.tingCard
- local tingPaiUI = self.ui.Items.Layout_TingCardItem:getCopied()
- tingPaiUI.Items = getUIItems(tingPaiUI);
- tingPaiUI:setVisible(true)
- self.ui.Items.Layout_TingCard:addChild(tingPaiUI)
- if tingCard then
- local name = ZPFuc.getZPCardImgByValue(tingCard,ZPDef.CardType.CARD_TYPE_TABLE)
- tingPaiUI.Items.ImageView_TingCard:loadTextureFromPlist(name)
- end
- tingPaiUI.Items.Text_TingCardNum:setText(tostring(tingCardNum).."张")
- --听牌剩余多少张,隐藏,但代码保留吧
- if self:setTingCardZhangShuVisible(tingPaiUI.Items.Text_TingCardNum) then
- tingCardOffHeight = 20
- end
- end
-
- --背景拉伸
- local maxNum = table.nums(valueList)
- if maxNum > 4 then
- local newSizeWidth = maxNum * self.ui.Items.Layout_TingCardItem:getContentSize().width + 43
- local srcHeight = self.tingPaibgSrcHeight + tingCardOffHeight
- self.ui.Items.ImageView_TingPai_bg:setSize(cc.size(newSizeWidth,srcHeight))
- self.ui.Items.Layout_TingCard:setPositionX(newSizeWidth/2)
- else
- local srcWidth = self.ui.Items.ImageView_TingPai_bg:getContentSize().width
- local srcHeight = self.tingPaibgSrcHeight + tingCardOffHeight
- self.ui.Items.ImageView_TingPai_bg:setSize(cc.size(srcWidth,srcHeight))
- end
-
- self.ui.Items.Layout_TingCard:requestDoLayout()
- self.ui.Items.Layout_TingCard:doLayout()
- self.ui.Items.Layout_TingPai:setVisible(true)
- else
- if not self.isNoCardTingPai then
- self.ui.Items.Layout_TingPai:setVisible(false)
- end
- end
- end
- end
-
- --[[
- outCard:出的牌
- ]]
- function ZPRoomView:IsTingPaiCard(outCard)
- if outCard then
- local data = self.tingCardLocal[outCard]
- if data then
- --标记只听模式
- self.isNoCardTingPai = true
- else
- self.isNoCardTingPai = false
- end
- self.tingCardLocal = {}
- --倒叙遍历1-10列
- for col = self.lieShuMax,1,-1 do --列数
- for row = self.hangShuMax,1,-1 do --行数
- local card = self.handCardRoot[col].imgList[row]:getChildren()[1]
- if card then
- self.handCardRoot[col].imgList[row]:getChildren()[1]:setVisible(false)
- end
- end
- end
- end
- end
-
- -- 先操作玩家
- function ZPRoomView:onOperationFirst(data)
- local function runOnOperationFirst(onEnd)
- log("2000000000-ZPRoomView - (runOnOperationFirst)")
-
- local nUserId = data.response.nUserId
-
- local viewId = app.room:getViewIdByUserId(nUserId)
- if viewId == self:getMeViewId() then
- --隐藏出牌面板
- self:setOperatorPanelView(false,nil)
- --隐藏吃牌面板
- self.operationView:setEatCardView(false)
- end
-
- local operations = {}
- operations[viewId] = {}
- operations[viewId].nUserId = nUserId
- operations[viewId].isCanOpereate = 0
- self:showDelayTimeTip(operations)
-
- if onEnd then
- onEnd()
- end
- end
- log("2000000000-ZPRoomView - addCallBack(runOnOperationFirst)")
-
- self:addCallBack(runOnOperationFirst)
- end
-
- -- 操作成功
- function ZPRoomView:onOperationCodeSuccess(data)
- local function runOnOperationSuccess(onEnd)
- log("2000000000-ZPRoomView - (runOnOperationSuccess)")
- logE("ZPRoomView:onOperationCodeSuccess :"..table.tostring(data.response))
- local response = data.response
- local nUserID = response.nUserId
- local card = response.card
- local bIsOutCard = response.isShouldOutCard > 0
- local codeCountList = response.OperationCodeList
- local weaveCardList = response.weaveCardList
- local playerList = response.playerList
- local maxWeave = table.nums(weaveCardList)
- local totalHuShu = response.totalHuShu
- local leftHandCardNum = response.leftHandCardNum
- local isMoPaiOrId = -1
- --app.room.roomInfo.huType = response.huType
-
- --点炮胡时,表示为点炮用户
- app.room.roomInfo.dianPaoSeatId = response.dianPaoSeatId
-
- --碰胡规则
- if maxWeave > 0 then
- isMoPaiOrId = weaveCardList[maxWeave].seatId
- end
-
- --记录操作成功
- self.operationSuccessCode = codeCountList
- self.outCard = card
-
- --视图ID
- local viewId = app.room:getViewIdByUserId(nUserID)
- self.tableHuXiList[viewId] = totalHuShu
- self.PlayerView:setPlayerHuXi(viewId,totalHuShu)
- self.PlayerView:setLeftCardNum(viewId,true,leftHandCardNum)
- --self.PlayerView:setNoOpTime(false,viewId)
- if bIsOutCard then
- for k,v in pairs(app.room.roomInfo.memberList) do
- local operations = {}
- operations[viewId] = {}
- operations[viewId].nUserId = v.nUserId
- operations[viewId].isCanOpereate = 0
- self:showDelayTimeTip(operations)
- end
- end
- local operations = {}
- operations[viewId] = {}
- operations[viewId].nUserId = nUserID
- operations[viewId].isCanOpereate = bIsOutCard and 1 or 0
- self:showDelayTimeTip(operations)
-
-
- --隐藏handTemp
- if viewId == self:getMeViewId() then
- self.isGodHand = true
- --出牌动画 setGuideView延迟了0.5
- self:runAction(cc.Sequence:create(cc.DelayTime:create(0.5),cc.CallFunc:create(function ()
- self:setColorWhite()
- if #codeCountList == 1 and codeCountList[1].nOperationCode == 0 then--点击过的时候设置可以点牌
- self.isGodHand = false
- end
- end)))
- self.ui.Items.ImageView_handTempCard:setVisible(false)
- end
-
- --显示指示器
- if bIsOutCard and codeCountList[1].nOperationCode ~= 0 then
- self:setCircleCardLeftPanelView(true,viewId,self.leftNum)
- end
-
- --隐藏操作层
- self:setOperatorPanelView(false,nil)
-
- --判断自己是否需要出牌
- if bIsOutCard and viewId == self:getMeViewId()
- and codeCountList[1].nOperationCode ~= 0
- and codeCountList[1].nOperationCode ~= ZPDef.OpCode.OP_HU then
- self:runAction(cc.Sequence:create(cc.DelayTime:create(0.5),cc.CallFunc:create(function ()
- self:setGuideView(true)
- end)))
- self.bOutCard = true
- end
-
- if self.isTianHu and viewId == self:getMeViewId() then
- self.isTianHu = false
- self:setGuideView(true)
- self.bOutCard = true
- end
-
- --隐藏吃牌层
- self.operationView:setEatCardView(false)
-
- --执行操作
- local code = codeCountList[1].nOperationCode
- logE("ZPRoomView:onOperationCodeSuccess nOperationCode:"..code)
- local operations = ZPFuc.getZPOperationType(code,false,self.playerZhao[viewId] > 0)
- local operationType = operations[1]
-
- --体验:等待0.5秒结束
- if operationType == ZPDef.OpType.OP_TYPE_MINGWEI
- or operationType == ZPDef.OpType.OP_TYPE_ANWEI
- or operationType == ZPDef.OpType.OP_TYPE_PAO
- or operationType == ZPDef.OpType.OP_TYPE_CHONG_PAO
- or operationType == ZPDef.OpType.OP_TYPE_TI
- or operationType == ZPDef.OpType.OP_TYPE_PENG then
- --明偎,暗偎,跑,重跑,提牌
- self:runAction(cc.Sequence:create(cc.DelayTime:create(self.gameSpeedConfig.CAO_ZUO_PAI_TIME),cc.CallFunc:create(function ()
- --隐藏出牌层
- self:setOutCardVisible(false)
- self:doOperation(operationType,viewId,card,isMoPaiOrId,onEnd)
- --检查是否少牌
- self:checkCardsByUidAndLeftCardNum(nUserID,leftHandCardNum)
- if codeCountList[1].nOperationCode ~= 0 then
- self:runAction(cc.Sequence:create(cc.DelayTime:create(0.3),cc.CallFunc:create(function ()
- self:setLayoutScoreTipVisible(true,playerList)
- end)))
- end
- end)))
- elseif operationType ~= ZPDef.OpType.OP_TYPE_HU and operationType ~= ZPDef.OpType.OP_TYPE_CANCEL and operationType ~= nil then
- --吃碰操作
- --隐藏出牌层
- self:setOutCardVisible(false)
- self:doOperation(operationType,viewId,card,isMoPaiOrId,onEnd)
- --检查是否少牌
- --self:checkCardsByUidAndLeftCardNum(nUserID,leftHandCardNum)
- elseif operationType == ZPDef.OpType.OP_TYPE_HU then
- --胡牌操作
- --1.隐藏引导出牌动画2.显示胡了哪张牌,3.播放胡牌特效
- self:setGuideView(false)
- local imgName = string.format("ImageView_outCardImg_%d",self.moPaiViewId)
- local mSprite = self.ui.Items[imgName]
- if self.outCard ~= 0 then
- local fileName = ZPFuc.getZPCardImgByValue(self.outCard,ZPDef.CardType.CARD_TYPE_OUTCARD)
- mSprite:loadTextureFromPlist(fileName)
- end
-
- if codeCountList[1].nOperationCode ~= 0 then
- self:runAction(cc.Sequence:create(cc.DelayTime:create(0),cc.CallFunc:create(function ()
- self:setLayoutScoreTipVisible(true,playerList,false,onEnd,true)
- app.room.roomInfo.winUserId = nUserID
- --self:playHuEffect(viewId,onEnd)
- if self.leftNum and not self.isTianHu and card ~= 0 and app.room.roomInfo.dianPaoSeatId == -1 and viewId == self.moPaiViewId then
- self:playMoPaiAni(self.leftNum,card,viewId,0,1,nil,true)
- end
- if onEnd then
- onEnd()
- end
- --点炮显示
- --[[if app.room.roomInfo.dianPaoSeatId >= 0 then
- local dianPaoViewId = app.room:getViewIdBySeatId(app.room.roomInfo.dianPaoSeatId)
- local name = string.format("ImageView_outCardLight_%d",dianPaoViewId)
- local img = self.ui.Items[name]
- local size = img:getContentSize()
- --点炮精灵
- local mSprite = cc.ImageView:createNode()
- mSprite:loadTextureFromPlist("zipai_room_pao.png")
- img:addChild(mSprite)
- mSprite:setPosition(cc.p(size.width/2,size.height/2))
- if dianPaoViewId == 2 or dianPaoViewId == 4 then
- --旋转为正常
- mSprite:setEulerRotation(cc.vec3(0,0,-90))
- end
- end--]]
- end)))
- end
- else
- --self:showOperatorTip(viewId,ZPDef.OpType.OP_TYPE_CANCEL)
- --过
- self:doOperation(ZPDef.OpType.OP_TYPE_CANCEL,viewId,card,isMoPaiOrId,nil)
- if onEnd then
- onEnd()
- end
- --检查是否少牌
- self:checkCardsByUidAndLeftCardNum(nUserID,leftHandCardNum)
- end
- end
- log("2000000000-ZPRoomView - addCallBack(runOnOperationSuccess)")
-
- self:addCallBack(runOnOperationSuccess)
- end
-
- --检测是否少牌
- function ZPRoomView:checkCardsByUidAndLeftCardNum(nUserID,leftHandCardNum)
- if nUserID == app.user.loginInfo.uid then
- local a = leftHandCardNum
- local b = self:getBakCardsNum()
- if leftHandCardNum and leftHandCardNum > 0 and self:getBakCardsNum() ~= leftHandCardNum then
- self.ui:sendMsg(app.room, "callGetHandcardsRequest");
- end
- end
- end
-
- --点炮显示
- function ZPRoomView:showPaoImage()
- if app.room.roomInfo.dianPaoUserId and app.room.roomInfo.dianPaoUserId >= 0 then
- local dianPaoViewId = app.room:getViewIdByUserId(app.room.roomInfo.dianPaoUserId)
- local name = string.format("ImageView_outCardLight_%d",dianPaoViewId)
- local img = self.ui.Items[name]
- local size = img:getContentSize()
- --点炮精灵
- local mSprite = cc.ImageView:createNode()
- mSprite:loadTextureFromPlist("zp_room_chapai_dianpao.png")
- img:addChild(mSprite)
- mSprite:setPosition(cc.p(size.width/2,size.height/2))
- if dianPaoViewId == 1 or dianPaoViewId == 3 then
- mSprite:setPositionY(35)
- end
- end
- end
-
- --胡牌特效
- function ZPRoomView:playHuEffect(viewId,onEnd,isRecontect)
- --[[ --黄庄了直接return
- if app.room.roomInfo.stopFlag == ZPDef.XiaoJuEndType.STOP_FLAG_HUANG_ZHUANG then
- return
- end--]]
- local nUserID = app.room:getUserIdByViewId(viewId)
- if (app.room.roomInfo.huType and app.room.roomInfo.huType >= 0) and (not (app.room.roomInfo.stopFlag == ZPDef.XiaoJuEndType.STOP_FLAG_HUANG_ZHUANG)) then
- local userInfo=app.room:getUserInfo(nUserID)
- if userInfo then
- if ZPFuc.isZiMo(app.room.roomInfo.huType) then
- ZPSound.PlayOperateSound(userInfo.sex,11)
- else
- ZPSound.PlayOperateSound(userInfo.sex,4)
- end
- end
- end
-
- local name = string.format("Layout_outCardPoint_%d",viewId)
- local mLayout = self.ui.Items[name]
-
- local huEffectUI = loadUI("zp_base/res/ui/ui_fangjian/zipai_ui_effectHu.ui")
- local pos = mLayout:getPosition()
-
- if viewId == self:getMeViewId() then
- local centerPos = cc.Director:getInstance():getVisibleSize()
- local pos = cc.p(centerPos.width/2,centerPos.height/2 - 70)
- huEffectUI:setPosition(pos)
- elseif viewId == 1 then
- huEffectUI:setPosition(cc.pAdd(pos,cc.p(90,-30)))
- elseif viewId == 2 then
- huEffectUI:setPosition(cc.pAdd(pos,cc.p(0,20)))
- elseif viewId == 3 then
- huEffectUI:setPosition(cc.pAdd(pos,cc.p(-70,-30)))
- end
-
- self.ui.Items.Layout_Player_HuEffect:addChild(huEffectUI,2)
-
- --动画展现
- if app.room.roomInfo.huType and app.room.roomInfo.huType >= 0 then
- local name = ""
- local bankerViewId = app.room:getViewIdBySeatId(app.room.roomInfo.nBankSeatId)
- local nWinerId = app.room.roomInfo.winUserId
- local winerViewId = app.room:getViewIdByUserId(nWinerId)
- if app.room.roomInfo.stopFlag == ZPDef.XiaoJuEndType.STOP_FLAG_HUANG_ZHUANG then--app.room.roomInfo.huType == 0 and
- name = "zp_room_chapai_jiao.png"--显示叫(表示听牌了)
- elseif ZPFuc.isZiMo(app.room.roomInfo.huType) then
- name = "zp_room_chapai_zimo.png"
- else
- name = "zp_room_chapai_hu.png"--string.format(ZPDef.TipFile.HU,app.room.roomInfo.huType)
- end
- huEffectUI.Items.ImageView_huType:loadTextureFromPlist(name)
- end
- isRecontect = true--不显示动画
- if isRecontect then
- huEffectUI.Items.ImageView_Light:setVisible(false)
- huEffectUI.Items.ImageView_Point:setVisible(false)
- huEffectUI.Items.ImageView_Coin:setVisible(false)
- self:showPaoImage()
- self:runAction(cc.Sequence:create(cc.DelayTime:create(0.8),cc.CallFunc:create(function ()
- if onEnd then
- onEnd()
- end
- end)))
- return
- end
- local mSpawn1 = cc.Spawn:create(cc.ScaleTo:create(0.3,1.0),cc.RotateBy:create(2,-120*6))
- huEffectUI.Items.ImageView_Point:runAction(mSpawn1)
-
- local mSpawn2 = cc.Spawn:create(cc.ScaleTo:create(0.3,1.0),cc.RotateBy:create(2,120*6))
- huEffectUI.Items.ImageView_Light:runAction(mSpawn2)
-
- huEffectUI.Items.ImageView_Coin:setScale(0)
- local mSeq1 = cc.Sequence:create(cc.ScaleTo:create(0.3,1))
- huEffectUI.Items.ImageView_Coin:runAction(mSeq1)
-
- huEffectUI.Items.ImageView_huType:setScale(2)
- huEffectUI.Items.ImageView_huType:setOpacity(0)
- local mSeq2 = cc.Sequence:create(cc.DelayTime:create(0.6),cc.FadeIn:create(0),cc.ScaleTo:create(0.2,1.0))
- huEffectUI.Items.ImageView_huType:runAction(mSeq2)
-
- huEffectUI:runAction(cc.Sequence:create(cc.DelayTime:create(2.2),cc.CallFunc:create(function ()
- huEffectUI.Items.ImageView_Light:setVisible(false)
- huEffectUI.Items.ImageView_Point:setVisible(false)
- huEffectUI.Items.ImageView_Coin:setVisible(false)
- self:showPaoImage()
- if onEnd then
- onEnd()
- end
- end)))
- end
-
-
- function ZPRoomView:addCallBack(callback)
- table.insert(self.callbackQueue, callback)
- logE(" #self.callbackQueue:".. #self.callbackQueue)
- --高延迟情况下,执行快速播放,15条是没有标准,根据实际调整的
- --if #self.callbackQueue >= 15 then
- --cc.Director:getInstance():getScheduler():setTimeScale(5.0)
- --else
- cc.Director:getInstance():getScheduler():setTimeScale(1.0)
- --end
- local function runFunc()
-
- log("2000000000 - runNextFunc() size = ", #self.callbackQueue )
-
- if #self.callbackQueue <= 0 then
- self.callbackRunning = false
- return
- end
-
- --logE("2000000001 - ", debug.traceback())
-
- local func = self.callbackQueue[1]
- table.remove(self.callbackQueue,1)
- self.callbackRunning = true
- func(function ()
- self.callbackRunning = false;
- runFunc();
- end)
- end
- log("self.callbackRunning:",self.callbackRunning)
- if not self.callbackRunning then
- runFunc();
- end
- end
-
- -- 其他玩家坐下成功
- function ZPRoomView:onOtherSitDownResponse(data)
- if not data or not data.nSeatShowId then
- return
- end
-
- --local nSeatShowId = data.nSeatShowId;
- --local nUserId = app.room:getUserIdByViewId(nSeatShowId)
- --self:checkGpsDistance(nUserId,true);
-
- self:onUserReadyResponse()
-
- -- 是否显示邀请好友
- self:setWetChatVisible(app.room:getActualPlayerNum() < ZPFuc.getCreateRoomPlayerNum())
- if isReviewVersion() then
- self:setWetChatVisible(false);
- end
- if app.room.roomInfo.nGameStartCount > 0 then
- self:setWetChatVisible(false)
- end
- self.toolView:showFastStart(true)
-
- if not tolua.isnull(self.quickStartView) then
- self.quickStartView:removeView()
- self.quickStartView = nil
- end
- end
-
- function ZPRoomView:onOtherLogoutResponse(data)
- local jushu = app.room.roomInfo.nGameStartCount or 0
- if (not data or not data.nUserId or not data.nSeatShowId) or jushu > 0 then
- return
- end
-
- local function test(onEnd)
- local memberList = app.room.roomInfo.memberList
- memberList[data.nUserId] = nil
- app.room:updateUserSeateShowId()
-
- self:onUserReadyResponse()
-
- --更新GPS
- --self:updateAllGpsInfo()
- --self:checkGpsDistance()
-
- -- 是否显示邀请好友
- self:setWetChatVisible(app.room:getActualPlayerNum() < ZPFuc.getCreateRoomPlayerNum())
- if isReviewVersion() then
- self:setWetChatVisible(false);
- end
- if app.room.roomInfo.nGameStartCount > 0 then
- self:setWetChatVisible(false)
- end
- self.toolView:updateButtonPosition()
- self.toolView:showFastStart(true)
-
- if not tolua.isnull(self.quickStartView) then
- self.quickStartView:removeView()
- self.quickStartView = nil
- end
-
- logE("88888-onOtherLogoutResponse onEnd")
- if onEnd then
- onEnd()
- end
- end
- self:addCallBack(test)
- end
-
- function ZPRoomView:updateGameNums()
- -- 更新当前局数
- local roomInfo = app.room.roomInfo
- local curCount = roomInfo.nGameStartCount or 0
- local str = string.format("%02d/%02d局", curCount, roomInfo.nTotalGameNum)
- self.ui.Items.Text_JuShu:setText(str);
- end
-
- -- 游戏开始
- function ZPRoomView:onGameStartResponse()
-
- local function runGameStartResponse(onEnd)
- log("2000000000-ZPRoomView - runGameStartResponse()" )
-
- --重置玩家数据
- self:resetGameData()
- app.room.roomInfo.tingCards = {}
- --标志一局结束
- app.room.roomInfo.nStatus = ZPDef.ReconnectState.GAME_STATUS_INIT
-
- --写入数据
- for k,v in pairs(app.room.roomInfo.memberList) do
- v.nPlayerFlag = 2
- end
-
- --更新玩家状态状态
- self:onUserReadyResponse()
-
- -- 隐藏邀请好友
- self:setWetChatVisible(false)
- self.toolView:showFastStart(false)
-
- -- 更新局数
- self:updateGameNums()
- --更新位置
- if app.room.roomInfo.xiaoSeatId and app.room.roomInfo.xiaoSeatId >= 0 and app.room:getActualPlayerNum()==4 then
- app.room:updateUserSeateShowId(app.room.roomInfo.xiaoSeatId)
- self.PlayerView:setXiaoJiaFlagVis(true)
- else
- app.room:updateTableView(true)
- end
-
- self.PlayerView:setPlayerVisible(false)
- for k,v in pairs(app.room.roomInfo.memberList) do
- local nSeatShowId = app.room:getViewIdByUserId(v.nUserId)
- self.PlayerView:updatePlayerInfo(nSeatShowId)
- end
-
- --更新庄家
- self:updateBanker()
-
- if onEnd then
- onEnd()
- end
- end
- log("2000000000-ZPRoomView - addCallBack(runGameStartResponse)" )
- self:addCallBack(runGameStartResponse);
- end
-
- function ZPRoomView:setLiangPaiVisible(bVisible)
- if not tolua.isnull(self.xiaojuChaPaiView) then
- self.xiaojuChaPaiView:setVisible(bVisible)
- end
- end
-
-
- -- 小局结算
- function ZPRoomView:onGameXiaoJuResponse(data)
- local function runGameXiaoJuResponse(onEnd)
- self.ui.Items.Button_tipai:setVisible(false)
- self.PlayerView:stopAndHideBaoAnim()
- self.PlayerView:hideLeftCard()
- --显示所有底牌
- local response = data.response;
-
- --标记单局结束
- self.isGameOver = true
- --禁止出牌
- self.bOutCard = false
-
- local roomInfo = app.room.roomInfo
- --结束原因
- roomInfo.stopFlag = response.stopFlag
- --是否是解散结束的
- app.room.roomInfo.nShowDismiss = (roomInfo.stopFlag == 8 or roomInfo.stopFlag == 9)
- --赢家uid, -1则下面6个字段是无用
- roomInfo.winUserId = response.winUserId
- --点炮胡时,表示为点炮用户
- roomInfo.dianPaoUserId = response.dianPaoUserId
- --胡的类型(如天胡、地胡 ,自摸胡等)
- roomInfo.huType = response.huTypes
- --多少个玩家
- roomInfo.playList = response.playList
- --底牌信息
- roomInfo.dipaiList = response.dipaiList
- --胡牌牌值
- roomInfo.huCard = response.huCard
- --是否大局结束,结束是1
- roomInfo.isGameOver = response.isGameOver
- --胡牌信息
- roomInfo.hupaiInfo = response.hupaiInfo or {}
- local function showChaPai()
- self:setLiangPaiVisible(true)
- end
- for i,v in pairs(roomInfo.hupaiInfo) do
- local viewId = app.room:getViewIdByUserId(v.huPaiUid)
- roomInfo.dianPaoUserId = v.dianPaoUid
- roomInfo.huCard = v.huCard
- self.PlayerView:setPlayerHuXi(v.huPaiHuShu)
- roomInfo.huType = v.huTypes
- self:playHuEffect(viewId,showChaPai)
- end
- --所有的暗偎默认亮起一张
- self:showLastAnWeiPai()
-
- --完成底牌展示
- self.xiaojuChaPaiView:showDiPai()
-
- --如果大局结算了
- if roomInfo.isGameOver == 1 then
- showChaPai()
- end
-
- --完成手牌展示
- for k,v in pairs(roomInfo.playList) do
- local cardData = app.room:serverCardToMyCard(v.handCard)
- if not roomInfo.memberList[v.nUserId] then
- roomInfo.memberList[v.nUserId] = {}
- end
- roomInfo.memberList[v.nUserId].cardList = {}
- roomInfo.memberList[v.nUserId].cardList = cardData
- local viewId = app.room:getViewIdByUserId(k)
- roomInfo.memberList[v.nUserId].weaveCardNum = self:getWeaveCardsNum(viewId)
- --[[logE("XiaoJu nUserID:"..v.nUserId)
- logE("XiaoJu cardList:"..table.tostring(cardData))--]]
- end
- self.xiaojuChaPaiView:liangShouPai(false)
-
- --玩家分数
- for k,v in pairs(roomInfo.playList) do
- local viewId = app.room:getViewIdByUserId(k)
- local nScore = v.nTotalMoney
- local memberInfo = app.room.roomInfo.memberList[k]
-
- --[[roomInfo.memberList[v.nUserId].nPlayerFlag = 0--]]
- memberInfo.nTotalMoney = nScore
- self.PlayerView:setPlayerScore(viewId,nScore)
- end
-
-
- --结束原因表现
- if roomInfo.stopFlag == ZPDef.XiaoJuEndType.STOP_FLAG_HUANG_ZHUANG then
- showChaPai()
- --播放黄庄动画
- self.xiaojuChaPaiView:PlayHuangZhuangAni(true)
- elseif roomInfo.stopFlag == ZPDef.XiaoJuEndType.STOP_FLAG_LONG_NOT_END then
- logD("游戏长久未打完,超过房间存在时间,本局结束")
- -- showConfirmDialog("游戏长久未打完,超过房间存在时间,本局结束",function()
- -- logE("超时回到大厅")
- -- self:runAction(cc.Sequence:create(cc.DelayTime:create(1.0),cc.CallFunc:create(function ()
- -- --房间号
- -- local roomid = app.room.roomInfo.nShowTableId
- -- --app:gotoView(import("luaScript.Views.Main.MainView"):new(app.gameId, roomid))
- -- gotoMainView(app.gameId,roomid)
- -- end)))
- -- end,nil)
- end
-
- local function nextCallBackFun()
- self:resetGameData()
- app.room.roomInfo.tingCards = {}
- end
-
- local function showAllJieSuan()
- if self.RoomCountAllViewUI then
- if not self.RoomCountAllViewUI:isVisible() then
- self.RoomCountAllViewUI:playAni()
- end
- self.RoomCountAllViewUI:setVisible(true)
- self:showGameOverAward()
- end
- end
-
- if not tolua.isnull(self.xiaojuView) then
- self.xiaojuView:removeFromParent()
- self.xiaojuView = nil
- end
-
- if app.room.roomInfo.isGameOver == 0 then
- self.xiaojuView = ZPRoomXiaoJuView:new(nextCallBackFun)
- else
- self.xiaojuView = ZPRoomXiaoJuView:new(showAllJieSuan)
- end
-
- self:addChild(self.xiaojuView)
- self.xiaojuView:setVisible(false)
- --结束
- if onEnd then
- onEnd()
- end
- end
- log("2000000000-ZPRoomView - addCallBack(runGameXiaoJuResponse)" )
- self:addCallBack(runGameXiaoJuResponse);
- end
-
- --显示暗偎的最后一个牌
- function ZPRoomView:showLastAnWeiPai()
- for i = 1 ,ZPDef.GameMaxPlayer do
- local name = string.format("Layout_player1Table_%d",i)
- local UnitCardNode = self.ui.Items[name]
- for k,chlidLayout in pairs(UnitCardNode:getChildren()) do
- if chlidLayout.type == "anwei" then
- local node = chlidLayout:getChildren()[1]
- local card = chlidLayout.cardList[1]
- node:loadTextureFromPlist(ZPFuc.getZPCardImgByValue(card,ZPDef.CardType.CARD_TYPE_TABLE))--0xfa为牌背
- end
- end
- end
- end
-
- -- 大局结算
- function ZPRoomView:onGameDaJuResponse(data)
- local function runGameDaJuResponse(onEnd)
- local response = data.response.playList
- -- 打开结算
- local view = ZPRoomCountAllView:new(response,data.response.endTime);
- view:setAnchorPoint(cc.p(0.5, 0.5));
- local visibleSize = getVisibleSize()
- view:setPosition(cc.p(visibleSize.width/2,visibleSize.height/2))
- self:addChild(view);
-
- self.RoomCountAllViewUI = view;
-
- app.room:dispatchEvent({name = GAME_EVENT.DISSMISS_CLOSE});
- if true then--app.room.roomInfo.nGameStartCount == app.room.roomInfo.nTotalGameNum and not app.room.roomInfo.nShowDismiss
- log("2000000000-onGameDaJuResponse --------- zhengchangjiesu ")
- view:setVisible(false);
- else
- log("2000000000-onGameDaJuResponse --------- yichangjiesu ")
- --结算直接播放动画
- view:playAni()
- self:showGameOverAward()
- end
-
- if onEnd then
- onEnd()
- end
- app.club_php:dispatchEvent({name = GAME_EVENT.CLUB_BACK_ROOM})
- end
- log("2000000000-ZPRoomView - addCallBack(runGameDaJuResponse)")
- self:showTuoGuan(false)--大结算隐藏托管界面
- self:addCallBack(runGameDaJuResponse);
- end
-
- function ZPRoomView:onUserReadyResponse()
- self.PlayerView:setPlayerVisible(false)
- local uids = {}
- for k,v in pairs(app.room.roomInfo.memberList) do
- local nSeatShowId = app.room:getViewIdByUserId(v.nUserId)
- self.PlayerView:setPlayerReadyState(nSeatShowId,(v.nPlayerFlag == 1))
- self.PlayerView:updatePlayerInfo(nSeatShowId)
- if v.nUserId and v.nUserId > 0 then
- uids[v.nUserId] = true
- end
- end
-
- local nUserId = app.user.loginInfo.uid
-
- local memberInfo = app.room.roomInfo.memberList[nUserId]
- if app.room.roomInfo.nGameStartCount > 0 then
- self:setBtnSitDownVisible(false)
- else
- self:setBtnSitDownVisible(memberInfo.nPlayerFlag == 0)
- end
-
- --邀请按钮
- if not self.toolView.ui.Items.Button_Ready:isVisible() then
- self.toolView:updateButtonPosition()
- end
-
- if not tolua.isnull(self.roomMenuView) then
- if app.room.roomInfo.nGameStartCount > 0 then
- self.roomMenuView:setButtonEnabled("Leave", false)
- end
- if app.room.roomInfo.nGameStartCount == 0 and app.room.roomInfo.nRoomOwnedUid ~= app.user.loginInfo.uid then
- self.roomMenuView:setButtonEnabled("Dismiss", false)
- else
- self.roomMenuView:setButtonEnabled("Dismiss", true)
- end
-
- self.roomMenuView:checkCanDismiss()
- end
- end
-
-
-
- -- 玩家收到解散房间的请求
- function ZPRoomView:onDismissResponse(event)
- if not event or not event.response then
- return
- end
-
- logD("onDismissResponse() response = ", table.tostring(event.response))
-
- local response = event.response
-
- --当前时间
- app.room.roomInfo.nDismissStateTime = response.timeLeft
- --总的时间
- app.room.roomInfo.nDismissToTalTime = response.timeLeft --服务器没发解散总时间来。那么就和一开始收到的解散剩余时间一致
- --显示解散(此标志会影响闹钟时间会冻住)
- app.room.roomInfo.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 = 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 = 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
-
- --更新庄家
- function ZPRoomView:updateBanker()
- --隐藏所有的庄家标志
- self.PlayerView:setBankerVisible()
- --只显示当前的庄家座位号
- local nBankerSeatId = app.room.roomInfo.nBankSeatId
- local viewId = app.room:getViewIdBySeatId(nBankerSeatId)
- if self.PlayerView:setPlayerBankerVisible(viewId,true) then
-
- else
- showTooltip("庄家椅子号"..nBankerSeatId.."不匹配")
- end
- end
-
- --显示房主
- function ZPRoomView:showOwner()
- self.PlayerView:setOwnerVisible()
- --只显示当前的庄家座位号
- local nBankerSeatId = app.room.roomInfo.nRoomOwnedUid
- local viewId = app.room:getViewIdBySeatId(nBankerSeatId)
- self.PlayerView:setPlayerBankerVisible(viewId,true)
- end
-
- function ZPRoomView:onOtherDroppedResponse(data)
- if not data.response.nUserId then
- return
- end
- local nUserId = data.response.nUserId
- local nDroppedStatus = data.response.nDroppedStatus
- local memberInfo = app.room.roomInfo.memberList[nUserId]
- if memberInfo then
- memberInfo.nOnlineStatus = nDroppedStatus == 1 and 0 or 1
- end
- local viewId = app.room:getViewIdByUserId(nUserId)
- app.room.offLineUid[tonumber(nUserId)] = (nDroppedStatus == 1)
- if nDroppedStatus == 0 then--如果上线了 离线时间置0
- app.room.offLineTime[tonumber(nUserId)] = 0
- self.PlayerView:reSetClockTime(viewId)
- end
- self.PlayerView:setPlayerOffLine(nDroppedStatus == 1,viewId)
- end
-
- function ZPRoomView:onUserExitResponseRoom(data)
- local function runUserExitResponseRoom(onEnd)
- log("2000000000-ZPRoomView - runUserExitResponseRoom()" )
- local response = data.response
-
- --房间号
- local roomid = app.room.roomInfo.nShowTableId
-
- -- 0: 不退出, 1: 退出
- if response.logoutFlag == 1 then
- --app:gotoView(import("luaScript.Views.Main.MainView"):new(app.gameId, roomid));
- gotoMainView(app.gameId,roomid)
- end
- app.room:dispatchEvent({name = "onUserExitResponseHall"});
- logE("88888-onUserExitResponseRoom onEnd")
- if onEnd then
- onEnd()
- end
- end
- log("2000000000-ZPRoomView - addCallBack(runUserExitResponseRoom)" )
- self:addCallBack(runUserExitResponseRoom);
- end
-
- -- 服务器广播玩家数据发生变化
- function ZPRoomView:onGpsChangeResponse(data)
- logD("ZPRoomView:onGpsChangeResponse()")
- if not data or not data.nUserId then
- return
- end
- local roomInfo = app.room.roomInfo
- local nUserId = data.nUserId
- logD("ZPRoomView:onGpsChangeResponse()", tostring(nUserId))
-
- self:checkGpsDistance(nUserId,roomInfo.nGameStartCount==0)
- end
-
- function ZPRoomView:initGpsComponent()
- if self.isRecordScene then return end--回放场景直接return
- local versionCode = getAppVersionCode()
- versionCode = tonumber(versionCode) or 0
-
- logD("ZPRoomView:initGpsComponent() versionCode = ", versionCode)
- logD("ZPRoomView:initGpsComponent() isReviewVersion = ", isReviewVersion()==true and 1 or 0)
-
- if isReviewVersion() or cc.Application:getInstance():getTargetPlatform() == 0 then
- self.ui.Items.Button_GPS:setVisible(false)
- return
- end
-
- -- 创建 gps 组件
- --self.gpsComponent = import("luaScript.Views.Room.RoomGpsComponent"):new(self.ui.Items.Button_GPS)
-
- local function exitRoomCallback()
- local isGameStart = app.room.roomInfo.nGameStartCount > 0
- if isGameStart then
- app.room:requestDismissRoom(1)
- else
- self.ui:sendMsg(app.room, "callLeaveRequest");
- end
- end
-
- local function dismissCallback()
- app.room:requestDismissRoom(1)
- end
-
- self.gpsComponent = import("luaScript.Views.Room.RoomGpsComponentView"):new(4,self.ui.Items.Button_GPS,exitRoomCallback,exitRoomCallback)
- self:addChild(self.gpsComponent)
-
- -- GPS 按钮
- self.ui.Items.Button_GPS:registerClick(handler(self, self.showGpsView))
-
- -- 我的GPS数据发生变化时检测是否需要通知服务器
- --self:bindEvent(app, "onGpsInoChanged", handler(self, self.checkMyGpsNeedUpdate))
-
- --self.isInitCheckGps = false
-
- -- 进入时检测一遍我的GPS数据是否需要更新
- --self:checkMyGpsNeedUpdate()
- end
-
- -- 检查服务器记录的我的GPS数据是最新的,如果不是,则请求更新
- --[[function ZPRoomView:checkMyGpsNeedUpdate(event)
- if self.isRecordScene then return end--回放场景直接return
- logD("ZPRoomView:checkMyGpsNeedUpdate()")
-
- if self.isInitCheckGps and not event then
- return
- end
-
- self.isInitCheckGps = true
-
- local nMyUserId = app.user.loginInfo.uid
- local myMemberInfo = app.room.roomInfo.memberList[nMyUserId]
- if myMemberInfo then
- local userInfo = json.decode(myMemberInfo.userInfo)
- if userInfo then
- local gpsInfo = userInfo.gpsInfo
- local isNewest = app.user:isGpsInfoNewest(gpsInfo)
- logD("ZPRoomView:checkMyGpsNeedUpdate() gpsInfo is isNewest = ", tostring(isNewest))
- if not isNewest then
- app.room:onGpsChangeRequest();
- else
- logD("ZPRoomView:checkMyGpsNeedUpdate() gpsInfo is newest")
- end
- else
- logD("ZPRoomView:checkMyGpsNeedUpdate() userInfo is nil")
- end
- else
- logD("ZPRoomView:checkMyGpsNeedUpdate() myMemberInfo is nil")
- end
- end--]]
-
- -- 更新所有玩家的信息到GPS组件
- function ZPRoomView: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
- if self.gpsComponent then
- self.gpsComponent:updateUserInfos(userInfoList)
- end
- end
-
- -- 检测玩家与其他玩家之间的距离
- -- 如果不传参数,则检测所有玩家相互之间的距离
- --[[function ZPRoomView:checkGpsDistance(curUserId,isOpenGpsView)
- if self.isRecordScene then return end--回放场景直接return
- self:updateAllGpsInfo()
- if self.gpsComponent then
- local isDanger = self.gpsComponent:checkGpsDistance(curUserId)
- if isDanger and isOpenGpsView then
- self:showGpsView()
- showTooltip("玩家距离过近或者未开启GPS!")
- end
- end
- end--]]
-
- -- 显示GPS界面
- function ZPRoomView:showGpsView()
- if self.isRecordScene then return end--回放场景直接return
- logD("ZPRoomView:showGpsView()")
- playBtnEffect()
- local isGameStart = app.room.roomInfo.nGameStartCount > 0
- -- self:updateAllGpsInfo()
- if self.gpsComponent then
- self.gpsComponent:showGpsView(isGameStart)
- end
- end
-
- --清理小局查牌界面
- function ZPRoomView:clearXJChaPaiView()
- self.xiaojuChaPaiView:clearView()
- end
- --爆牌结果
- function ZPRoomView:onBaoPaiResponese(data)
- local function runBaoPai(onEnd)
- log("2000000000-ZPRoomView - (runBaoPai)")
- local response = data.response
- local uid = response.nUserId
- local viewId = app.room:getViewIdByUserId(uid)
- --玩家选择了爆牌 播放爆牌动画
- if response.optType == 1 then
- self:showOperatorTip(viewId,-55)
- self.PlayerView:playBaoAnim(viewId)
-
- local bankerViewId = app.room:getViewIdBySeatId(app.room.roomInfo.nBankSeatId)
- if bankerViewId == viewId then
- self.bankerBaoPao = true
- end
- end
- if uid == app.user.loginInfo.uid or app.room:isLittleFamily() then
- self.operationView:showBaoPaiOpView(false)
- end
-
- self:runAction(cc.Sequence:create(cc.DelayTime:create(1.0),cc.CallFunc:create(function ()
- if onEnd then
- onEnd()
- end
- end)))
- end
- self:addCallBack(runBaoPai)
- end
- --显示胡的牌
- function ZPRoomView:onShowHuCard(showViewId,huCard)
- local roomInfo = app.room.roomInfo
- if roomInfo.dianPaoUserId == -1 and showViewId then
- if huCard ~= 0 then
- self:playMoPaiAni(table.nums(roomInfo.dipaiList),huCard,showViewId,0,1,nil,true)
- end
- else
- self:setOutCardVisible(true,showViewId,huCard,false,nil,true)
- end
- end
- --totalHuShu桌面油数
- function ZPRoomView:showLocalHuXi(totalHuShu)
- local viewId = self:getMeViewId()
- local myHuXi = self.tableHuXiList[viewId] or 0
- local huShuLocal = totalHuShu--self:getLocalHuShu(self.handCardValueLocal)
- --只显示桌面胡数
- myHuXi = myHuXi-- + huShuLocal
- self.PlayerView:setPlayerHuXi(viewId,myHuXi)
- end
-
- --@parm:手牌列表
- function ZPRoomView:getLocalHuShu(list)
- local function calcHuShu(sList)
- --[[if not list then
- list = self.handCardValueLocal
- end--]]
- local hushu = 0
- local xiaoOneErSan,xiaoErQiShi,daOneErSan,daErQiShi,xiaoYiWuShi,daYiWuShi = 0,0,0,0,0,0
- --扑克多少张,从1-20,key分别代表小写到大写的1-10,value代表有多少张数
- local m_cbCardIndex = ZPFuc.switchToCardIndex(sList)
- --坎牌判断
- if self:getCurrentColIsLong(sList) then--比砍多6,手牌龙会自动放下去,所以这里暂时不用计算
- elseif self:getCurrentColIsKan(sList) then
- if sList[1] - 16 > 0 then
- if ZPFuc.getIsErQiShi(sList[1]) then
- return 12
- else
- return 9
- end
- else
- if ZPFuc.getIsErQiShi(sList[1]) then
- return 9
- else
- return 6
- end
- end
- else
- --油数判断:以列为单位
- --判断有多少个123
- local lieMaxNum = table.nums(sList)
- if lieMaxNum == 3 and m_cbCardIndex[1] >= 1 and m_cbCardIndex[2] >= 1 and m_cbCardIndex[3] >= 1 then
- return 3
- elseif lieMaxNum == 3 and m_cbCardIndex[11] >= 1 and m_cbCardIndex[12] >= 1 and m_cbCardIndex[13] >= 1 then
- return 6
- elseif lieMaxNum == 3 and m_cbCardIndex[2] >= 1 and m_cbCardIndex[7] >= 1 and m_cbCardIndex[10] >= 1 then
- return 6
- elseif lieMaxNum == 3 and m_cbCardIndex[12] >= 1 and m_cbCardIndex[17] >= 1 and m_cbCardIndex[20] >= 1 then
- return 9
- --泸州大贰没有1,5,10
- elseif lieMaxNum == 3 and m_cbCardIndex[1] >= 1 and m_cbCardIndex[5] >= 1 and m_cbCardIndex[10] >= 1 then
- --return 3
- elseif lieMaxNum == 3 and m_cbCardIndex[11] >= 1 and m_cbCardIndex[15] >= 1 and m_cbCardIndex[20] >= 1 then
- --return 6
- end
- end
- return 0
- end
-
- local totalHuShu = 0
- for i,handCard in ipairs(self.handCardRoot) do
- local tCards = {}
- local hushu = 0
- for j=1,4 do
- if handCard.imgList[j] and handCard.imgList[j].value and handCard.imgList[j]:isVisible() then
- table.insert(tCards,handCard.imgList[j].value)
- handCard.imgList[j]:setOpacity(255)
- end
- end
- hushu = calcHuShu(tCards)
- totalHuShu = totalHuShu + hushu
- if next(tCards) == nil then
- handCard.textHuShuBg:setVisible(false)
- else
- handCard.textHuShuBg:setVisible(true)
- handCard.textHuShu:setText(hushu.."胡")
- end
- end
- self:showLocalHuXi(totalHuShu)
- --self.PlayerView:setPlayerHuXi(self:getMeViewId(),totalHuShu)
- return totalHuShu
- end
-
- -- 立即开始
- function ZPRoomView:onQuickStartResponse(event)
- log("2000000000-ZPRoomView - runnQuickStartResponse()" )
- if not event or not event.response then
- return
- end
- logE("onQuickStartResponse() response = ", event.response)
- local response = event.response
- local isStart = true
- local selectNums = table.nums(app.room.quickStartInfo)
-
- for i,v in pairs(app.room.quickStartInfo) do
- if v > 1 then
- --有人投过票
- isStart = false
- end
- end
-
- if tolua.isnull(self.quickStartView) and isStart then
- for i,v in pairs(app.room.quickStartInfo) do
- if v == 1 then
- self.quickStartView = ZPRoomQuickStartView:new(i);
- self.quickStartView:setAnchorPoint(cc.p(0.5, 0.5));
- app:showWaitDialog(self.quickStartView);
- log("onQuickStartResponse() v = 1 "..i )
- return
- else
- local startuid = 0
- for i,v in pairs(app.room.quickStartInfo) do
- if v == 1 then
- startuid = i
- end
- end
- self.quickStartView = ZPRoomQuickStartView:new(startuid);
- self.quickStartView:setAnchorPoint(cc.p(0.5, 0.5));
- app:showWaitDialog(self.quickStartView);
- log("onQuickStartResponse() v ~= 1 "..i )
- return
- end
- end
- end
- end
-
- --刷新手牌
- function ZPRoomView:onGetHandcardsResponese(event)
- log("2000000000-ZPRoomView - onGetHandcardsResponese()" )
-
- logD("onGetHandcardsResponese self.handCardValueBak---",table.tostring(self.handCardValueBak));
- logD("onGetHandcardsResponese self.handCardValueLocal---",table.tostring(self.handCardValueLocal));
- uploadLogs("zipaishaopai2")
-
- self.ui.Items.LayoutMain_4:removeAllChildren()
- self.handCardRoot = {}
- self.handCardItem = {}
- self.handCardValueLocal = {}
- self.handCardValueBak = {}
- local myUserID = app.room:getMyUserId()
- self:createCard(false,myUserID,nil)
- end
-
- function ZPRoomView:setDiPaiVisible(vis)
- self.ui.Items.ImageView_DiPai:setVisible(vis)
- self.ui.Items.Layout_dipai:setVisible(vis)
- end
-
- --多维数组转 一维数组
- function ZPRoomView:ChangeDataToVector(data)
- local tt = {}
- for i = 1, self.lieShuMax do
- for j = 1, self.hangShuMax do
- if data[i][j] then
- table.insert(tt,data[i][j])
- end
- end
- end
- return tt
- end
-
- function ZPRoomView:onTransferCard(list,type1)--提牌 恢复至发牌阶段时的牌
- if self.isGodHand then--此字段为true时,禁止拖动操作
- return
- end
- if self.clickSpaceT then
- return
- end
- if app.room:isLittleFamily() and not ZPFuc.getLittleIsCanLookCard() then--小家且不能看牌时,不能提牌
- return
- end
- logD("ZPRoomView:onTransferCard self.handCardValueBak---",table.tostring(list));
- logD("ZPRoomView:onTransferCard self.handCardValueLocal---",table.tostring(self.handCardValueLocal));
- self:runAction(cc.Sequence:create(cc.DelayTime:create(2.0),cc.CallFunc:create(function ()
- self.clickSpaceT = nil
- end)))
- self.clickSpaceT = true
- if #list <= 0 then
- return
- end
- local handCard = self:ChangeDataToVector(list)
- local cardList = ZPFuc.switchToCardIndexForRecord(handCard)
- local sendCardResult = app.room:rankHandCard(cardList)
- local newCardList
- newCardList = app.room:serverCardToMyCard(sendCardResult)
- self.curCardSortRule = 1
-
- self.ui.Items.LayoutMain_4:removeAllChildren()
- self.handCardRoot = {}
- self.handCardItem = {}
- self.handCardValueLocal = {}
- self.handCardValueBak = {}
- local myUserID = app.room:getMyUserId()
- app.room.cards[myUserID] = newCardList
- self:createCard(false,myUserID,nil)
- self:getLocalHuShu()
- if app.room.roomInfo.tingCards then
- if self.bOutCard then
- local max = table.nums(app.room.roomInfo.tingCards)
- if max > 0 then
- self:setTingCardViewVisible(true,app.room.roomInfo.tingCards)
- end
- else
- end
- end
- end
-
- --备份的手牌数据,只对此数据使用的接口
- function ZPRoomView:rankDeletOneBakCard(card)
- local isEnd = false
- --倒叙遍历1-10列
- for col = self.lieShuMax,1,-1 do --列数
- for row = self.hangShuMax,1,-1 do --行数
- if self.handCardValueBak[col] and self.handCardValueBak[col][row] and card == self.handCardValueBak[col][row] then --判断值是否相等
- logE("delete bakcard ============= :"..card)
- table.remove(self.handCardValueBak[col],row)
-
- isEnd = true
- break
- end
- end
- if isEnd then
- break
- end
- end
- end
-
- --显示提牌按钮
- function ZPRoomView:showTiPaiBtn(vis)
- vis = vis or false
- if ZPDef.GameID == GAME_IDS.xuyongDaEr then
- self.ui.Items.Button_tipai:setVisible(vis)
- else
- self.ui.Items.Button_tipai:setVisible(false)
- end
- end
-
- --检测是否少牌,如果少牌则恢复 --目前在抓牌,出牌成功,和显示操作三个地方检测少牌情况
- function ZPRoomView:checkCardAndRecover()
- --当前的手牌数
- local curCardNum = 0
- --当前显示的手牌数
- local curShowNum = 0
- --实际手牌数
- local factCardNum = 0
- --计算当前手牌数
- for i,cards in pairs(self.handCardValueLocal) do
- for j,card in pairs(cards) do
- if card and card > 0 then
- curCardNum = curCardNum + 1
- end
- end
- end
- --计算当前显示的手牌数
- for i = 1,self.lieShuMax do
- if self.handCardRoot[i].ui:isVisible() then
- for j = 1,self.hangShuMax do
- if self.handCardRoot[i].imgList[j]:isVisible() and self.handCardRoot[i].imgList[j]:getOpacity() == 255
- and self.handCardRoot[i].imgList[j].value then
- curShowNum = curShowNum + 1
- end
- end
- end
- end
-
- --计算备份数据的手牌数(以这个数据为准)
- factCardNum = self:getBakCardsNum()
-
- if curCardNum ~= factCardNum and curShowNum ~= factCardNum then
- print("checkCardAndRecover curCardNum="..curCardNum.." curShowNum="..curShowNum.." factCardNum="..factCardNum)
- logD("checkCardAndRecover self.handCardValueBak---",table.tostring(self.handCardValueBak));
- logD("checkCardAndRecover self.handCardValueLocal---",table.tostring(self.handCardValueLocal));
- self:onTransferCard(self.handCardValueBak)
- uploadLogs("zipaishaopai")
- end
- end
-
- --获取备份数据里面的牌的数量
- function ZPRoomView:getBakCardsNum()
- --实际手牌数
- local factCardNum = 0
- for i,cards in pairs(self.handCardValueBak) do
- for j,card in pairs(cards) do
- if card and card > 0 then
- factCardNum = factCardNum + 1
- end
- end
- end
- return factCardNum
- end
-
- --获取吃碰牌的数量(桌面组合牌)
- function ZPRoomView:getWeaveCardsNum(viewId)
- if not viewId then return 0 end
- local name = string.format("Layout_player1Table_%d",viewId)
- local UnitCardNode = self.ui.Items[name]
- if UnitCardNode then
- local count = UnitCardNode:getChildrenCount();
- return count
- end
- return 0
- end
-
- --显示隐藏托管
- function ZPRoomView:showTuoGuan(isShow)
- if isShow then
- if not self.tuoguanView then
- self.tuoguanView = import("zp_base.luaScript.Views.Room.ZPRoomTuoGuanView"):new()
- self:addChild(self.tuoguanView)
- end
- else
- if self.tuoguanView and not tolua.isnull(self.tuoguanView) then
- self.tuoguanView:removeFromParent()
- self.tuoguanView = nil
- end
- end
- end
-
- --托管结果协议
- function ZPRoomView:onTuoGuanResponse(data)
- local function runTuoGuanResponse(onEnd)
- log("2000000000-ZPRoomView - (runTuoGuanResponse)")
- local response = data.response
-
- local userCnt = response.userCnt;
- if userCnt then
- --self:setTuoGuanAllVisible()
- self.PlayerView:setTuoGuanFlagVisible(false)
- for k,v in pairs(userCnt) do
- local aiStatus = v.aiStatus;
- local nUserID = v.nUserID;
- local viewId = app.room:getViewIdByUserId(nUserID)
- local isTuoGuan = aiStatus == 1;
- if self:getIsMeUId(nUserID) then
- if isTuoGuan then
- self:showTuoGuan(true)
- self.isTuoGuan = true
- else
- self:showTuoGuan(false)
- self.isTuoGuan = false
- end
-
- end
- self.PlayerView:showTuoGuanByViewId(viewId,isTuoGuan)
- --self:showTuoGuanByViewId(viewId,isTuoGuan)
- end
- end
-
- if onEnd then
- onEnd()
- end
- end
- log("2000000000-ZPRoomView - addCallBack(runTuoGuanResponse)")
-
- self:addCallBack(runTuoGuanResponse)
- end
-
- --获取托管状态
- function ZPRoomView:getTuoGuanState()
- return self.isTuoGuan or false
- end
- ---
- -- 显示抽奖界面
- --
- function ZPRoomView:showGameOverAward()
- if not (dd and dd.IGameOverAward) then
- return
- end
- self:runDelay(0.1, function ( )
- -- 延迟0.1秒执行,可能有些游戏弹大结算的时候还未收到抽奖消息
- dd.IGameOverAward.showAwardView();
- end)
- end
-
- return ZPRoomView;
|