require("luaScript.Views.Room.RoomFunctions") local MJRoomToolView=MJFramework.MJImport("mj.luaScript.Views.Room.MJRoomToolView") local MJRoomMessageView=MJFramework.MJImport("mj.luaScript.Views.Room.MJRoomMessageView") local MJRoomPlayerView=MJFramework.MJImport("mj.luaScript.Views.Room.MJRoomPlayerView") local MJDefine=MJFramework.MJImport("mj.luaScript.MJDefine") local MJHandCardView=MJFramework.MJImport("mj.luaScript.Views.Game.MJHandCardView") local MJRoomXiaoJuView=MJFramework.MJImport("mj.luaScript.Views.Room.MJRoomXiaoJuView") local MJRoomDaJuView=MJFramework.MJImport("mj.luaScript.Views.Room.MJRoomDaJuView") local MJRoomDismissView=MJFramework.MJImport("mj.luaScript.Views.Room.MJRoomDismissView") local MJRoomDirection=MJFramework.MJImport("mj.luaScript.Views.Room.MJRoomDirection") local MJMessage=MJFramework.MJImport("mj.luaScript.Protocol.MJMessage") local MJ=MJFramework.MJImport("mj.luaScript.Views.Game.MJ") local MJWanFa=MJFramework.ImportWanFa("luaScript.SubGameDefine.MaJiang.MJWanFa") local MJAnimationCompnent=MJFramework.MJImport("mj.luaScript.Views.Compnent.MJAnimationCompnent") local MJFunction=MJFramework.MJImport("mj.luaScript.MJFunction") local MJSound = MJFramework.MJImport("mj.luaScript.MJSound") local MJRoomView = MJFramework.MJFrameworkClassImprot("mj.luaScript.Views.Room.MJRoomView") local linshuiRoomView = class("linshuiRoomView", MJRoomView) local zhongNiaoTime=1.33 local HU_EFFECT_TAG = 100 function linshuiRoomView:ctor() linshuiRoomView.super.ctor(self) self.operates = {} if app.systemSetting.info.viewType == MJDefine.DesktopType.TwoD then -- viewType只保存2d 3d类型 mj_desktop_2d_mjType保存2d麻将类型 local value = loadUserInfo("mj_linshui_desktop_2d_mjType") if value=="" or not value then value = MJDefine.DesktopType.TwoDL saveUserInfo("mj_linshui_desktop_2d_mjType", value) end self.desktopType = value else self.desktopType = app.systemSetting.info.viewType end MJDefine.MJConfig = MJDefine.loadMJConfig(self.desktopType) end function linshuiRoomView:loadUi() local ui = loadUI("mj_linshui/res/ui_fangjian/mj_linshui_roomView.ui") self.ui = ui self:addChild(ui) end function linshuiRoomView:onEnter() linshuiRoomView.super.onEnter(self) -- 初始化听牌组件 self:initTingCardView(); -- 初始化听牌按钮,动态创建的 self:initTingBtnView(); self:setButtonTingInfoVisible(false); --获取是否贴鬼杠和是否自动对齐 self:setCheckDefault() self:doSound() end function linshuiRoomView:onExit() linshuiRoomView.super.onExit(self) self:cleanCache() end function linshuiRoomView:cleanCache() local preload = package.loaded for k, v in pairs(package.loaded or {}) do local res1 = string.find( k, "mj.luaScript") or 0 local res2 = string.find( k, "mj_linshui.luaScript") or 0 if res1 > 0 or res2 > 0 then package.loaded[k] = nil end end local temp = { "mj/res/ui/zy_fangjian/mj.plist", "mj/res/ui/zy_fangjian/mahjong/mj_2d_cards.plist", "mj/res/ui/zy_fangjian/mj_2d.plist", "mj/res/ui/zy_fangjian/mahjong/mj_3d_cards_1.plist", "mj/res/ui/zy_fangjian/mahjong/mj_3d_cards_2.plist", "mj/res/ui/zy_fangjian/mj_2d_gold.plist", "mj/res/ui/zy_fangjian/mahjong/mj_2d_cards_l.plist", "mj_linshui/res/zy_fangjian/mj_2d_cards.plist", "mj_linshui/res/zy_fangjian/mj_2d_gold.plist", "mj_linshui/res/zy_fangjian/mj_2d_lgold.plist", } -- 删除缓存,防止与其他麻将资源混淆(例如南充麻将的墨绿大麻将和邻水麻将的金黄大麻将) for i, v in ipairs(temp) do cc.SpriteFrameCache:getInstance():removeSpriteFramesFromFile(v) end end function linshuiRoomView:doSound()--1 普通话 2 方言 local cacheLan = "mj_language"..(GAME_IDS.linshuiMJ or MJDefine.GameID) --saveUserInfo(cacheLan,1)--恒定为普通话 local defaultValue = tonumber(loadUserInfo(cacheLan)) or 2 saveUserInfo(cacheLan,defaultValue) logD("doSound:"..defaultValue.." "..cacheLan) MJSound.setSoundType(defaultValue) end function linshuiRoomView:setCheckDefault() MJDefine.isAutomatic = true end -- 一键截屏 function linshuiRoomView:onClickButtonShot( sender ) playBtnEffect() showScreenShot() end --隐藏俱乐部 function linshuiRoomView:hideClub() -- self.ui.Items.Button_Club:setVisible(false) if self.clubView and not tolua.isnull(self.clubView) then self.clubView:removeFromParent() self.clubView=nil end end --更换桌布(同维度) function linshuiRoomView:changeGameBg(isUpdateViewType) if isUpdateViewType then if app.systemSetting.info.viewType == MJDefine.DesktopType.TwoD then --更新2D麻将类型 金色还是绿色 local value = loadUserInfo("mj_linshui_desktop_2d_mjType") --or MJDefine.DesktopType.TwoD if value=="" or not value then value = MJDefine.DesktopType.TwoDL saveUserInfo("mj_linshui_desktop_2d_mjType", value) end logD("changeGameBg value:"..value) self.desktopType = value else self.desktopType = app.systemSetting.info.viewType end self:loadTextureCache() logD("changeGameBg"..self.desktopType) end local defaultValue = tonumber(loadUserInfo("linshui_mj_desktop_group")) or 3 local bgData = MJDefine.CHANGE_GAME_BG[defaultValue] if self.desktopType==MJDefine.DesktopType.TwoD or self.desktopType==MJDefine.DesktopType.TwoDGold or self.desktopType==MJDefine.DesktopType.TwoDL then self.ui.Items.ImageView_bg:loadTexture(bgData['2d']) else self.ui.Items.ImageView_bg:loadTexture(bgData['3d']) end end function linshuiRoomView:defaultState() --队列初始化 self.callbackQueue = {} self.callbackRunning = false self.playerView:setOffLineVisible(false) self.playerView:setPlayerVisible(false) if self.waitOperates and #self.waitOperates>0 then for k,v in pairs(self.waitOperates) do v:removeFromParent() end end self.waitOperates = {} self:resetGame() end function linshuiRoomView:loadTextureCache() linshuiRoomView.super.loadTextureCache(self) -- local defaultValue = tonumber(loadUserInfo("luzhou_mj_majhong")) or 1 loadSpriteFrameFile("mj_linshui/res/zy_fangjian/mj_operateEffect.plist") loadSpriteFrameFile("mj_linshui/res/zy_fangjian/effect_guafeng.plist") loadSpriteFrameFile("mj_linshui/res/zy_fangjian/effect_xiayu.plist") end function linshuiRoomView:initGameButton() --点击空白 self.ui.Items.Layout_Touch:registerClick(nil,function() -- 隐藏个人信息 self.playerView:removePlayerInfoView() self.toolView:setMenuVisible(false) if self.playerHandCards[MJDefine.MyViewId] then self.playerHandCards[MJDefine.MyViewId]:hideOperateItem() end self.toolView:hideRule() self:setTingCardVisible(false); self:setTingCardViewVisible(false); end) --隐藏听牌模板 self.ui.Items.Item_Ting:setVisible(false) --self.ui.Items.Button_Ting_Info:setVisible(false); --self.ui.Items.Button_Ting_Info:registerClick(handler(self, self.onBtnTingInfoClicked)) self.toolView.ui.Items.Button_Face:setPosition(cc.p(1208*g_radio_x,(322+25)*g_radio_y)) self.toolView.ui.Items.Button_Voice:setPosition(cc.p(1208*g_radio_x,(237+30)*g_radio_y)) end --通知庄家可以爆牌 function linshuiRoomView:onBankerBaoPai(data) local function runBankerBaoPai(onEnd) local myUserId = app.room:getMyUserId() local viewId = app.room:getViewIdByUserId(myUserId) if data.response.nUserId == myUserId then self:showBaoJiao() self.playerHandCards[viewId]:setOutCardEnable(false) end if onEnd then onEnd() end end self:addCallBack(runBankerBaoPai) end --广播玩家爆牌 function linshuiRoomView:onBaoPai(data) local myUserId = app.room:getMyUserId() if data.response.isBaoPai == 1 then local effect=MJAnimationCompnent.CreateBaoEffect() local viewId = app.room:getViewIdByUserId(data.response.nUserId) local userInfo=app.room:getUserInfoByViewId(viewId) --爆牌音效 MJSound.PlayBaoSound(userInfo.sex) if effect then self.ui.Items.Layout_Player:addChild(effect) effect:setLocalZOrder(1000) effect:setPosition(self.playerHandCards[viewId]:getAnimationPostion()) end if myUserId == data.response.nUserId then --self.playerHandCards[viewId]:lockHandCard(true) self.playerHandCards[viewId]:setBaoPai(1) -- self.playerHandCards[viewId]:setOutCardEnable(false) else --self.playerHandCards[viewId]:setOutCardEnable(true) end self.playerHandCards[viewId]:setOutCardEnable(true) self.playerView:playBaoAnim(viewId) elseif data.response.isBaoPai == 2 then--博自摸 local effect=MJAnimationCompnent.CreateBoZiMoEffect() local viewId = app.room:getViewIdByUserId(data.response.nUserId) local myUserId = app.room:getMyUserId() local userInfo=app.room:getUserInfoByViewId(viewId) --爆牌音效 MJSound.PlayBaoSound(userInfo.sex) if effect then self.ui.Items.Layout_Player:addChild(effect) effect:setLocalZOrder(1000) effect:setPosition(self.playerHandCards[viewId]:getAnimationPostion()) end if myUserId == data.response.nUserId then self.playerHandCards[viewId]:lockHandCard(true) else end self.playerView:showBoZiMo(viewId,true) elseif self.reShowBao and self.reShowBao == true then--过爆 self.guobao = true--重连过爆要显示打出的第一张牌 end if myUserId == data.response.nUserId then--报牌后可以躺 self.playerHandCards[MJDefine.MyViewId]:showOperate(data.response.operates) self.playerHandCards[MJDefine.MyViewId]:setOutCardEnable(true) end if app.room:getMyUserId() == data.response.nUserId then self:hideBaoJiao() end --[[if app.room:getMyUserId() == data.response.nUserId and (data.response.isBaoPai == 1 or data.response.isBaoPai == 2) then local gameInfo =json.decode(app.room.roomInfo.strGameInfo); --if gameInfo.tingpai > 0 then --self.ui.Items.Button_Ting_Info:setVisible(true); self:setButtonTingInfoVisible(true) app.room.roomInfo.memberList[data.response.nUserId].nTingStatus = MJDefine.MJTingStatus.Ting; self.ui:sendMsg(app.room, MJDefine.MJEvent.Ting) self.isTing = true; --end end--]] end function linshuiRoomView:onGameSendCardResponse() --发牌的时候清除桌面上的飘 self.ui.Items.Layout_Effect_luobo:removeAllChildren() local function runGameSendCardResponse(onEnd) log("2000000000-linshuiRoomView - runGameSendCardResponse()" ) self:hidePiao() local myUserId = app.room:getMyUserId() for k,v in pairs(app.room.roomInfo.memberList) do local viewId = app.room:getViewIdByUserId(v.nUserId) if self.playerHandCards[viewId] then self.playerHandCards[viewId]:createHandCards(v.handCards) self.playerHandCards[viewId]:resetHandCards() end if v.isBaoPai == 1 and myUserId == v.nUserId then --self.playerHandCards[viewId]:showBaoPai() self:showBaoJiao() end end self.playerHandCards[MJDefine.MyViewId]:initSwapCardTouchEvent() MJAnimationCompnent.CreateStartSendCards(self.playerHandCards,onEnd) self.isTang = false -- if onEnd then -- onEnd() -- end self.toolView:showTuoGuan(app.room.roomInfo.hosting==1) self:doSound() --每次发牌检测一次是否牌出去了,需要重连解决一下 self:checkIsNeddAdapt() end log("2000000000-linshuiRoomView - addCallBack(runGameSendCardResponse)" ) self:addCallBack(runGameSendCardResponse); end function linshuiRoomView:checkIsNeddAdapt() log("linshuiRoomView:checkIsNeddAdapt" ) local callFunc = function(onEnd) if self.playerHandCards[MJDefine.MyViewId].isUseNew3D then if self.playerHandCards[MJDefine.MyViewId]:isUseNew3D() then MJDefine.loadMJConfig(self.desktopType) end end self:requestReconnect() if onEnd then onEnd() end end local winSize = cc.Director:getInstance():getWinSize() for i, v in pairs(self.playerHandCards) do log("v:getHandCardPosInitY = "..v:getHandCardPosInitY().." winSize.height = "..winSize.height ) if v:getHandCardPosInitY() > winSize.height then self:addCallBack(callFunc) break end end end function linshuiRoomView:onUserReadyResponse(response) linshuiRoomView.super.onUserReadyResponse(self,response) local myUserId = app.room:getMyUserId() if response and response.nUserId==myUserId then self.playerView:clearBao() self.playerView:clearAllPiao() --self.playerView:clearAllBoZiMo() self.playerView:clearAllQue() self.playerView:clearAllHuOrder() self:setTingCardVisible(false); self:setTingCardViewVisible(false); if self.playerHandCards[MJDefine.MyViewId] then self.playerHandCards[MJDefine.MyViewId]:setQueType(-1)--设置缺牌类型为空 end app.room.roomInfo.luoboCards = nil -- local roomInfo = app.room.roomInfo -- for k,v in pairs(roomInfo.memberList) do -- self.ui.Items.Layout_Player:removeChildByTag(HU_EFFECT_TAG) -- end end --self.ui.Items.Button_Ting_Info:setVisible(false); self:setButtonTingInfoVisible(false) end -- 广播桌子上所有玩家庄家起手操作 这里其实是发牌 function linshuiRoomView:onBankerOutCard(data) --[[ -- 庄家uid , defVar("nUserId", VT_Int, 0) -- 庄家操作类型 , defVar("mainOpCode", VT_Short, 0) --庄家是否需要出牌0不需要 1:需要 , defVar("IsShouldOutCard", VT_UChar, 0)--]] local function runOnBankerOutCard(onEnd) logE("linshuiRoomView onBankerOutCard :"..table.tostring(data.response)) -- if not data.response.nUserId then -- showTooltip("庄家起手操作nUserId is not exist") -- end local viewId = app.room:getViewIdByUserId(data.response.nUserId) local card= data.response.card local operates=data.response.operates local nSeatId=data.response.nSeatId -- app.room.roomInfo.outCardUserId = data.response.nUserId if self.playerHandCards[viewId] then self.playerHandCards[viewId]:onGetCard(operates,card) end --检测定缺牌 self.playerHandCards[MJDefine.MyViewId]:checkQueAndDisableOtherCard() --先清除所有操作按钮 --self.playerHandCards[MJDefine.MyViewId]:hideOperate() self.playerHandCards[MJDefine.MyViewId]:hideOperateItem() self.playerHandCards[MJDefine.MyViewId]:showOperate(operates,card,true) if viewId == MJDefine.MyViewId then --self.ui.Items.Button_Ting_Info:setVisible(false) self:setButtonTingInfoVisible(false) if operates and table.nums(operates)>0 then self.operates = operates else self.operates = {} end if self.playerHandCards[MJDefine.MyViewId] then self.playerHandCards[MJDefine.MyViewId]:setTing(false) local player = app.room.roomInfo.memberList[data.response.nUserId] if player and player.isBaoPai==1 then --self.playerHandCards[MJDefine.MyViewId]:lockHandCard(true) end end app.room:dispatchEvent({name = MJDefine.MJEvent.SelectCard}) app.room:dispatchEvent({name = MJDefine.MJEvent.PushTing}) -- app.room:dispatchEvent({name = MJDefine.MJEvent.ShowTing}) end -- local myUserId = app.room:getMyUserId() -- if data.response.nUserId == myUserId then -- if self.playerHandCards[MJDefine.MyViewId] then -- self.playerHandCards[MJDefine.MyViewId]:pushTing() -- end -- end self:updateGameNums() self.direcionView:updateDirection(nSeatId) if onEnd then onEnd() end end log("2000000000-linshuiRoomView - addCallBack(runOnBankerOutCard)") self:addCallBack(runOnBankerOutCard); end function linshuiRoomView:onAfterDingQue(data) local function runOnAfterDingQue(onEnd) logE("linshuiRoomView onAfterDingQue :"..table.tostring(data.response)) local viewId = app.room:getViewIdByUserId(data.response.nUserId) local card= data.response.card local operates=data.response.operates local nSeatId=data.response.nSeatId self.playerHandCards[MJDefine.MyViewId]:hideOperateItem() self.playerHandCards[MJDefine.MyViewId]:showOperate(operates,card,true) if viewId == MJDefine.MyViewId then --self.ui.Items.Button_Ting_Info:setVisible(false) self:setButtonTingInfoVisible(false) if operates and table.nums(operates)>0 then self.operates = operates local isCanHu = false for k,v in pairs(operates.Datas) do if (v.opType == MJDefine.MJOperateType.OPREATE_DIANPAOHU) or (v.opType == MJDefine.MJOperateType.OPREATE_ZIMOHU) then isCanHu = true break end end if isCanHu == true then self.playerHandCards[MJDefine.MyViewId]:setOutCardEnable(false) else self.playerHandCards[MJDefine.MyViewId]:setOutCardEnable(true) end else self.playerHandCards[MJDefine.MyViewId]:setOutCardEnable(true) self.operates = {} end if self.playerHandCards[MJDefine.MyViewId] then self.playerHandCards[MJDefine.MyViewId]:setTing(false) end app.room:dispatchEvent({name = MJDefine.MJEvent.SelectCard}) app.room:dispatchEvent({name = MJDefine.MJEvent.PushTing}) end self:updateGameNums() self.direcionView:updateDirection(nSeatId) self.playerHandCards[MJDefine.MyViewId]:checkQueAndDisableOtherCard() self.playerHandCards[MJDefine.MyViewId]:initTouchEvent() if onEnd then onEnd() end end self:addCallBack(runOnAfterDingQue) end function linshuiRoomView:onTurnOutCard(data) local function runOnTurnOutCard(onEnd) logE("MJRoomView:runOnOutCard(), response = ", table.tostring(data.response)) log("2000000000-MJRoomView - runOnOutCard") if app.room.roomInfo.lastOutViewId~=MJDefine.MyViewId then self.playerHandCards[MJDefine.MyViewId]:setOutCardEnable(true) end -- local viewId = app.room:getViewIdByUserId(data.response.nUserId) -- local card= data.response.card -- if self.playerHandCards[viewId] then -- self.playerHandCards[viewId]:createOutCards(card) -- end if onEnd then onEnd() end end log("2000000000-MJRoomView - addCallBack(runOnTurnOutCard)") self:addCallBack(runOnTurnOutCard) end --出牌成功 function linshuiRoomView:onOutCardSuccess(data) logE("linshuiRoomView:onOutCardSuccess(), response = ", table.tostring(data.response)) local function runOnOutCardSuccess(onEnd) log("2000000000-linshuiRoomView - runOnOutCardSuccess---------") -- app.room.roomInfo.outCardUserId = data.response.nUserId local viewId = app.room:getViewIdByUserId(data.response.nUserId) local card= data.response.card local operates=data.response.operates local typr = operates.opType if operates and table.nums(operates)>0 then self.operates = operates else self.operates = {} end local function callback() -- app.room.roomInfo.lastOutViewId = nil self.playerHandCards[MJDefine.MyViewId]:showOperate(operates,card) self.playerHandCards[MJDefine.MyViewId]:checkQueAndDisableOtherCard() --self.playerHandCards[MJDefine.MyViewId]:checkBaoAndDisableCard() self.playerHandCards[MJDefine.MyViewId]:setTing(false) if onEnd then onEnd() end end -- self.lastOutCard = card if self.playerHandCards[viewId] then --(viewId~=MJDefine.MyViewId or player.isBaoPai == 1) and app.room.roomInfo.lastOutViewId~=MJDefine.MyViewId if viewId==MJDefine.MyViewId then local player = app.room.roomInfo.memberList[data.response.nUserId] local function doOutCard(viewId, card, callback) self.playerHandCards[viewId]:onOutCard(card,callback) --音效 local userInfo=app.room:getUserInfoByViewId(viewId) if userInfo then MJSound.PlayMJSound(userInfo.sex,card) end end self.playerHandCards[viewId]:setTing(false) --点击爆牌的时候 前端已经打出牌 要判断上次出牌的人是不是自己 避免重复出牌 if ((player.isBaoPai==1 or player.isBaoPai==2 or (self.isTang and self.isTang == true) or (self.guobao and self.guobao == true)) and app.room.roomInfo.lastOutViewId~=MJDefine.MyViewId) then self.guobao = nil doOutCard(viewId, card, callback) elseif app.room.roomInfo.hosting == 1 then -- 托管状态下 doOutCard(viewId, card, callback) elseif self.needDeleteOutCard and true == self.needDeleteOutCard then self.needDeleteOutCard = nil uploadLogs("mjduopai") doOutCard(viewId, card, callback) else callback() end local gameInfo = json.decode(app.room.roomInfo.strGameInfo); --if gameInfo.tingpai > 0 then self._isOutCardTingCheck = true; self.ui:sendMsg(app.room,MJDefine.MJEvent.Ting) --end else self.playerHandCards[viewId]:onOutCard(card,callback) end app.room:dispatchEvent({name = MJDefine.MJEvent.OutCardFalg, value=card ,viewId=viewId}) else callback() end app.room.roomInfo.lastOutViewId = viewId end log("2000000000-linshuiRoomView - addCallBack(runOnOutCardSuccess)") self:addCallBack(runOnOutCardSuccess) end function linshuiRoomView:onOutCard(data) local function runOnOutCard(onEnd) if app.room:getViewIdByUserId(data.response.nUserId) == MJDefine.MyViewId then --[[ --隐藏听牌 self:setTingCardViewVisible(false) --显示查听 if app.room.roomInfo.tings then for k,v in pairs(app.room.roomInfo.tings) do if tonumber(k) == data.response.card then self:setChaTingCardViewVisible(true) break end end end ]] --如果是托管状态需要删除一次手牌 if app.room.roomInfo.hosting == 1 and data.response.card and tonumber(data.response.card) ~= 0 then local viewId = app.room:getViewIdByUserId(data.response.nUserId) local card = data.response.card if viewId == MJDefine.MyViewId then self.playerHandCards[viewId]:setTing(false) self.playerHandCards[viewId]:onOutCard(data.response.card,nil,true) app.room:dispatchEvent({name = MJDefine.MJEvent.OutCardFalg, value = card ,viewId = viewId}) end end end if onEnd then onEnd() end end self:addCallBack(runOnOutCard) end --已经发送了过操作,此时就算再勾选贴鬼碰,也不会显示操作 function linshuiRoomView:onSendGuo() --发牌重置,主要用于贴鬼碰/杠 MJDefine.isSendGuo = false self.operates = {} end -- 操作成功 function linshuiRoomView:onOperationCodeSuccess(data) local function runOnOperationSuccess(onEnd) local response = data.response local nUserId = response.nUserId local opType = response.opType local opCard = response.opCard local bIsOutCard = response.isNeedOutCard > 0 local fromSeatId = response.fromSeatId local isNeedTang = response.isNeedTang or 0 local redNum = 0 or response.redNum local viewId = app.room:getViewIdByUserId(nUserId) local fromViewId = app.room:getViewIdBySeatId(fromSeatId) local opSeatId = app.room:getSeatIdByViewId(viewId) local fromUserId = app.room:getUserIdBySeatId(fromSeatId) -- 是否是胡牌一起的操作 1是 0不是 (1时不需要清掉出牌区域的牌) local huAndOpreate = response.huAndOpreate logD('是否是胡牌一起的操作', huAndOpreate) if self.playerHandCards[viewId] then --组合一下牌 local groups={ self:getChangeGruopDatas({opType=opType, opCard=opCard, redNum = redNum, targetSeatId=opSeatId, opUserId=fromUserId}) } --删除手中对应的牌 local deleteCards for k,v in pairs(groups) do if v.showType==MJDefine.MJGroupType.Peng then self.playerHandCards[viewId]:removeHandCardByNum(opCard,2,v.redNum) elseif v.showType==MJDefine.MJGroupType.Chi then --TODO:吃的牌删除两张 elseif v.showType==MJDefine.MJGroupType.AnGang or v.showType==MJDefine.MJGroupType.MAnGang then self.playerHandCards[viewId]:removeHandCardByNum(opCard,4,v.redNum) else if opType==MJDefine.MJOperateType.OPREATE_BAGANG then self.playerHandCards[viewId]:removeHandCardByNum(opCard,1,v.redNum) else self.playerHandCards[viewId]:removeHandCardByNum(opCard,3,v.redNum) end end end --删除出去的牌 遍历哪些操作需要删除牌 for k,v in pairs(MJDefine.MJOperateNeedRemoveCard) do if v==opType and huAndOpreate == 0 then self.playerHandCards[fromViewId]:removeOutCard(opCard) break end end if opType==MJDefine.MJOperateType.OPREATE_BAGANG then self.playerHandCards[viewId]:buGang(opCard,redNum) else self.playerHandCards[viewId]:createGroupCards(groups)--创建显示的牌 end self.playerHandCards[viewId]:resetHandCards() self.playerHandCards[viewId]:hideOperate() self.playerHandCards[viewId]:setOutCardEnable(bIsOutCard) self.direcionView:updateDirection(app.room:getSeatIdByViewId(viewId)) end local function guafengxiayuEffect() local effect if (opType==MJDefine.MJOperateType.OPREATE_ZHIGANG) or (opType==MJDefine.MJOperateType.OPREATE_BAGANG) or (opType==MJDefine.MJOperateType.OPREATE_MINGGANG) then effect=MJAnimationCompnent.createGuaFengEffect() MJSound.PlayWindSound() elseif (opType==MJDefine.MJOperateType.OPREATE_ANGANG) then effect=MJAnimationCompnent.createXiaYuEffect() MJSound.PlayRainSound() end if effect then self.ui.Items.Layout_Player:addChild(effect) effect:setLocalZOrder(1000) effect:setPosition(self.playerHandCards[viewId]:getAnimationPostion()) end end --[[if (opType==MJDefine.MJOperateType.OPREATE_ZHIGANG) or (opType==MJDefine.MJOperateType.OPREATE_BAGANG) or (opType==MJDefine.MJOperateType.OPREATE_MINGGANG) or (opType==MJDefine.MJOperateType.OPREATE_ANGANG) then guafengxiayuEffect() else--]] --播放动画 local effect=MJAnimationCompnent.CreateOperareEffect(opType)--,onEnd) if effect then self.ui.Items.Layout_Player:addChild(effect) effect:setLocalZOrder(1000) effect:setPosition(self.playerHandCards[viewId]:getAnimationPostion()) -- else -- if onEnd then -- onEnd() -- end end --end --音效 local userInfo=app.room:getUserInfo(nUserId) if userInfo then MJSound.PlayOperateSound(userInfo.sex,opType) end if viewId == MJDefine.MyViewId then self.playerHandCards[MJDefine.MyViewId]:setTing(false) self:setTingCardViewVisible(false) --self.ui.Items.Button_Ting_Info:setVisible(false) self:setButtonTingInfoVisible(false) self.operates={} --碰等操作后检查定缺牌 self.playerHandCards[MJDefine.MyViewId]:checkQueAndDisableOtherCard() --self.playerHandCards[MJDefine.MyViewId]:checkBaoAndDisableCard() end --删除等待操作的显示 if self.waitOperates and #self.waitOperates>0 then for k,v in pairs(self.waitOperates) do v:removeFromParent() end self.waitOperates={} end --[[if viewId == MJDefine.MyViewId and opType==MJDefine.MJOperateType.OPREATE_PENG then local cards = {opCard} self.playerHandCards[viewId]:cardEnabled(cards, true) end--]] -- 取消操作按钮 self.playerHandCards[MJDefine.MyViewId]:hideOperate() if onEnd then onEnd() end end self:addCallBack(runOnOperationSuccess) end function linshuiRoomView:test() self.playerHandCards={} self.playerHandCards[MJDefine.MyViewId] = MJHandCardView:new(MJDefine.MyViewId) self:addChild(self.playerHandCards[MJDefine.MyViewId]) self.playerView = MJRoomPlayerView:new() self:addChild(self.playerView) end --飘状态停止 function linshuiRoomView:stopDirection() self.direcionView:stopAllActions() self.direcionView.ui.Items.ImageView_Dir_Down:setVisible(false) self.direcionView.ui.Items.ImageView_Dir_Up:setVisible(false) self.direcionView.ui.Items.ImageView_Dir_Left:setVisible(false) self.direcionView.ui.Items.ImageView_Dir_Right:setVisible(false) self.direcionView.ui.Items.Text_Time:setString(string.format("%02d",0)) --self.direcionView.ui.Items.Text_Leave_Card_Num:setText("72") end function linshuiRoomView:onGameReconnection() linshuiRoomView.super.onGameReconnection(self) self:doSound() local roomInfo = app.room.roomInfo local gameInfo=json.decode(roomInfo.strGameInfo) local piaoMode = gameInfo.piaomode local isDingQue = getNumBand(gameInfo.specRule, 0x0004)>0 local myUserId = app.room:getMyUserId() -- 托管状态恢复 for k,v in pairs(roomInfo.hostInfos or {}) do local aiStatus = v.aiStatus; local nUserID = v.nUserID; local viewId = app.room:getViewIdByUserId(nUserID) local isTuoGuan = aiStatus == 1; self.playerView:showTuoGuanByViewId(viewId,isTuoGuan) end local isMyGetCard = false local meIsHu = false if roomInfo.nStatus and roomInfo.nStatus>=MJDefine.GameStatus.GAME_STATUS_WAIT_BANKER_START and roomInfo.nStatus0 and self.playerHandCards[viewId] then self.playerView:showHuOrder(viewId,player.result,player.huOrder) --effect = MJAnimationCompnent.CreateHuOrderEffect(player.result,player.huOrder) if myUserId == player.nUserId then --self.playerHandCards[viewId]:removeHandCard(player.huCard) --self.playerHandCards[viewId]:resetHandCards() self.playerHandCards[viewId]:createHandCards(player.huCard) self.playerHandCards[viewId]:moveLastCard() else --self.playerHandCards[viewId]:removeHandCard(player.huCard) --self.playerHandCards[viewId]:resetHandCards() self.playerHandCards[viewId]:createOpenHandCards(player.huCard) self.playerHandCards[viewId]:moveLastOpenCard() end end --[[if nSeatId == fpSeatId then effect = MJAnimationCompnent.CreateFangPaoEffect() end--]] if effect then self.ui.Items.Layout_Effect:addChild(effect) effect:setTag(HU_EFFECT_TAG) effect:setLocalZOrder(1000) local pos = self.playerHandCards[viewId]:getAnimationPostion() if viewId==MJDefine.PlayerViewType.My then effect:setPosition(pos.x,pos.y-60) elseif viewId==MJDefine.PlayerViewType.Left then effect:setPosition(pos.x-20,pos.y) elseif viewId==MJDefine.PlayerViewType.Right then effect:setPosition(pos.x+10,pos.y) elseif viewId==MJDefine.PlayerViewType.Top then effect:setPosition(pos.x,pos.y+10) end end if gameInfo.luobonum and gameInfo.luobonum > 0 then local effect1 = MJAnimationCompnent.CreateLoBoLabel(player.luoboNum or 0) local pos = self.playerHandCards[viewId]:getAnimationPostion() if viewId==MJDefine.PlayerViewType.My then effect1:setPosition(pos.x+130,pos.y-60) elseif viewId==MJDefine.PlayerViewType.Left then effect1:setPosition(pos.x-20-30,pos.y-70) elseif viewId==MJDefine.PlayerViewType.Right then effect1:setPosition(pos.x+10-30,pos.y-70) elseif viewId==MJDefine.PlayerViewType.Top then effect1:setPosition(pos.x+130,pos.y+10-50) end self.ui.Items.Layout_Effect:addChild(effect1) end --显示飘状态 self.playerView:showPiao(viewId,tonumber(player.isPiao)) end elseif roomInfo.nStatus==MJDefine.GameStatus.GAME_STATUS_WAIT_SWAP_CARDS then--等待换牌 self.playerHandCards[MJDefine.MyViewId]:initSwapCardTouchEvent() self:showSwapCard(true) self.swapCard.Items.Button_sure:setEnabled(false) for i,player in pairs(roomInfo.memberList) do local viewId = app.room:getViewIdByUserId(player.nUserId) if player.nUserId == myUserId then if player.isSwapCard == 1 and self.swapCard and self.swapCard.Items.ImageView_bg then--操作过换牌 self.swapCard.Items.ImageView_bg:setVisible(false) end else self:setSwapCardSucc(player.isSwapCard == 1,viewId) end if player.isSwapCard == 1 then self.playerHandCards[viewId]:createSwapCards({0,0,0}) end end elseif roomInfo.nStatus==MJDefine.GameStatus.GAME_STATUS_WAIT_SELECT_QUE then--等待选缺 -- 服务端没有给当前最优选,所以由客户端来自行判断 local t = {[0] = 'wan', [1] = 'tong', [2] = 'tiao'} local temp = {wan = 0, tiao = 0, tong = 0} for _, mj in ipairs(self.playerHandCards[MJDefine.MyViewId]:getHandCardNodes()) do local mjType = mj:getMJColorType() if mjType <= 2 and mjType >= 0 and t[mjType] then temp[t[mjType]] = temp[t[mjType]] + 1 end end local min = temp.wan for i, mType in pairs(t) do if min > temp[mType] then min = temp[mType] roomInfo.memberList[myUserId].nQue = i end end self.playerHandCards[MJDefine.MyViewId]:setHandCardsDidable() self:showDingQue(roomInfo.memberList[myUserId].nQue) for i,player in pairs(roomInfo.memberList) do local viewId = app.room:getViewIdByUserId(player.nUserId) if viewId == MJDefine.MyViewId then self.playerHandCards[viewId]:moveLastCard() end if player.nUserId == myUserId then if player.isDingQue == 1 then--操作过定缺 self:hideDingQueOp() self.playerView:showQue(player.nQue,viewId,true) self.playerHandCards[viewId]:setQueType(player.nQue) end else self:setDingQueSucc(player.isDingQue == 1,viewId) end end --[[elseif roomInfo.nStatus==MJDefine.GameStatus.GAME_STATUS_WAIT_PIAO then self:stopDirection() for i,player in pairs(roomInfo.memberList) do local viewId = app.room:getViewIdByUserId(player.nUserId) if myUserId == player.nUserId then if tonumber(player.canPiao) == 1 then -- 操作过飘了 self.playerView:showPiao(viewId,tonumber(player.isPiao)) else --随飘或者固定飘的第一局,恢复显示飘 if piaoMode == 1 or (piaoMode == 2 and roomInfo.nGameStartCount == 1) then--可以飘 还没有飘 显示飘按钮 self:showPiao() end end else self.playerView:showPiao(viewId,tonumber(player.isPiao)) end if tonumber(player.isPiao) > 0 then local effect = MJAnimationCompnent.CreatePiaoEffect() if effect then self.ui.Items.Layout_Effect_luobo:addChild(effect) effect:setLocalZOrder(1000) effect:setPosition(self.playerHandCards[viewId]:getAnimationPostion()) end end end elseif roomInfo.nStatus==MJDefine.GameStatus.GAME_STATUS_WAIT_OP_BAO then--等待爆牌 for k,v in pairs(roomInfo.memberList) do local viewId = app.room:getViewIdByUserId(v.nUserId) --可以爆牌玩家显示爆牌 if v.canBaoPai == 1 and v.nUserId == myUserId then --self.playerHandCards[viewId]:showBaoPai() self:showBaoJiao() end --已爆牌玩家不能出牌 if v.isBaoPai ~= 0 then if v.isBaoPai == 1 then-- 报叫 self.playerView:playBaoAnim(viewId) end if v.nUserId == myUserId then --自己爆牌 self.playerHandCards[viewId]:lockHandCard(true) -- self.playerHandCards[viewId]:setOutCardEnable(false) end app.room:dispatchEvent({name = MJDefine.MJEvent.OutCardFalg,value = roomInfo.lastOpCard,viewId = viewId}) else end --显示飘状态 self.playerView:showPiao(viewId,tonumber(v.isPiao)) end--]] elseif roomInfo.nGameStartCount > 0 and roomInfo.memberList[myUserId].nPlayerFlag ~= 1 then--游戏中 --local outCardUserId = app.room:getUserIdBySeatId(roomInfo.needOutCardId) local bIsOutCard = roomInfo.isNeedOutCard > 0 or false if (not bIsOutCard) and roomInfo.memberList[myUserId].nTingStatus == MJDefine.MJTingStatus.Ting then local gameInfo =json.decode(app.room.roomInfo.strGameInfo); --if gameInfo.tingpai > 0 then --self.ui.Items.Button_Ting_Info:setVisible(true); self:setButtonTingInfoVisible(true) --end end for k,v in pairs(roomInfo.memberList) do local viewId = app.room:getViewIdByUserId(v.nUserId) if isDingQue then--如果选择了定缺玩法 self.playerView:showQue(v.nQue,viewId,true) self.playerHandCards[viewId]:setQueType(v.nQue) end --可以爆牌玩家显示爆牌 if v.canBaoPai and v.canBaoPai == 1 and v.nUserId == myUserId then self.reShowBao = true--重连显示报叫操作标志 self:showBaoJiao() end --已爆牌玩家不能出牌 if v.isBaoPai and v.isBaoPai ~= 0 then if v.isBaoPai == 1 then-- 报叫 self.playerView:playBaoAnim(viewId) self.playerHandCards[viewId]:setBaoPai(1) end if v.nUserId == myUserId then --自己爆牌 --self.playerHandCards[viewId]:lockHandCard(true) end app.room:dispatchEvent({name = MJDefine.MJEvent.OutCardFalg,value = roomInfo.lastOpCard,viewId = viewId}) end local handcardNum = #v.handCards if handcardNum%3 == 2 and v.nUserId == myUserId then isMyGetCard = true end if roomInfo.outCardUserId == v.nUserId then if v.nUserId == myUserId and roomInfo.lastOpCard~=0 and isMyGetCard then self.playerHandCards[viewId]:removeHandCard(roomInfo.lastOpCard) self.playerHandCards[viewId]:resetHandCards() if v.isBaoPai == 1 then self.playerHandCards[viewId]:setNotTingCardDidable(true) end self.playerHandCards[viewId]:createHandCards(roomInfo.lastOpCard) end if roomInfo.isNeedOutCard > 0 then self.playerHandCards[viewId]:setOutCardEnable(true) end end if viewId == MJDefine.MyViewId then if roomInfo.operates and table.nums(roomInfo.operates)>0 then self.operates = roomInfo.operates else self.operates = {} end end --显示飘状态 self.playerView:showPiao(viewId,tonumber(v.isPiao)) if (v.nTingStatus==MJDefine.MJTingStatus.Ting or v.isBaoPai ~= 0) and (not isMyGetCard) then -- 听牌、报叫、胡牌情况下,显示听牌按钮 -- 此时需重新请求一下听牌数据,否则显示为空 self.ui:sendMsg(app.room, MJDefine.MJEvent.Ting) self.isTing = true; self:setButtonTingInfoVisible(true); end end --显示哪些玩家胡牌 for i,player in pairs(roomInfo.memberList) do local viewId = app.room:getViewIdByUserId(player.nUserId) local effect if player.result>0 then --胡的类型大于0 if player.result == MJDefine.MJGameHuType.HU_ZIMO then --effect=MJAnimationCompnent.CreateHuOrderEffect(player.result,player.huOrder) else --effect=MJAnimationCompnent.CreateHuOrderEffect(player.result,player.huOrder) end self.playerView:showHuOrder(viewId,player.result,player.huOrder) if viewId == MJDefine.MyViewId then self.playerHandCards[viewId]:createHandCards(player.huCard) self.playerHandCards[viewId]:moveLastCard() meIsHu = true else self.playerHandCards[viewId]:removeAllHandCards() self.playerHandCards[viewId]:createOpenHandCards(player.handCards) self.playerHandCards[viewId]:createOpenHandCards(player.huCard) self.playerHandCards[viewId]:moveLastOpenCard() end end if effect then self.ui.Items.Layout_Effect:addChild(effect) effect:setTag(HU_EFFECT_TAG) effect:setLocalZOrder(1000) local pos = self.playerHandCards[viewId]:getAnimationPostion() if viewId==MJDefine.PlayerViewType.My then effect:setPosition(pos.x,pos.y-60) elseif viewId==MJDefine.PlayerViewType.Left then effect:setPosition(pos.x-20,pos.y) elseif viewId==MJDefine.PlayerViewType.Right then effect:setPosition(pos.x+10,pos.y) elseif viewId==MJDefine.PlayerViewType.Top then effect:setPosition(pos.x,pos.y+10) end end end end if isMyGetCard and(not meIsHu) then self.playerHandCards[MJDefine.MyViewId]:checkQueAndDisableOtherCard() self.playerHandCards[MJDefine.MyViewId]:setOutCardEnable(true) end --显示出牌角标(需要服务器修改outCardUserId为最后一位出牌玩家的id,而不是当前需要出牌玩家的ID) local lastOutCardViewId = app.room:getViewIdByUserId(roomInfo.outCardUserId); app.room:dispatchEvent({name = MJDefine.MJEvent.OutCardFalg, value = roomInfo.lastOpCard, viewId = lastOutCardViewId}); --显示听标示 app.room:dispatchEvent({name = MJDefine.MJEvent.PushTing}); app.room:dispatchEvent({name = MJDefine.MJEvent.ShowTing}) --如果有操作显示操作按钮 if not (roomInfo.nStatus==MJDefine.GameStatus.GAME_STATUS_WAIT_OP_BAO) then if self.playerHandCards[MJDefine.MyViewId] then self.playerHandCards[MJDefine.MyViewId]:showOperate(roomInfo.operates,roomInfo.lastOpCard,isMyGetCard); end if table.nums(roomInfo.operates) > 0 and isMyGetCard then --self.playerHandCards[MJDefine.MyViewId]:setOutCardEnable(false) end end --如果一局结束,玩家点了准备,不再显示牌信息 if MJDefine.GameStatus.GAME_STATUS_ROUND_OVER == roomInfo.nStatus and roomInfo.memberList[myUserId].nPlayerFlag == 1 or MJDefine.GameStatus.GAME_STATUS_GAME_OVER == roomInfo.nStatus and roomInfo.memberList[myUserId].nPlayerFlag == 1 then --游戏为停止或开始状态 self:onUserReadyResponse({nUserId=myUserId}) end if meIsHu and meIsHu == true then self.playerHandCards[MJDefine.MyViewId]:setOutCardEnable(false) self:setTingCardViewVisible(false) --self.ui.Items.Button_Ting_Info:setVisible(false) self:setButtonTingInfoVisible(false) self.playerHandCards[MJDefine.MyViewId]:setTing(false) self.playerHandCards[MJDefine.MyViewId]:lockHandCard(true); self.playerHandCards[MJDefine.MyViewId]:checkQueAndDisableOtherCard() end --快速成局 if roomInfo.nGameStartCount == 0 then -- 游戏未开始 if roomInfo.nStatus and roomInfo.nStatus0 then table.insert(viewIds,viewId) --处理掉huCard, 不加入手牌 --播放音效 if viewId==MJDefine.MyViewId then --MJSound.PlayWinGame() end if v.result==MJDefine.MJGameHuType.HU_DIANPAO then failViewId = app.room:getViewIdBySeatId(v.dpSeatId) end end end self:showOpenCard() for k,v in pairs(roomInfo.memberList) do local viewId = app.room:getViewIdByUserId(v.nUserId) if viewId and self.playerHandCards[viewId] then if viewId==MJDefine.MyViewId then else --倒牌 if v.result and v.result>0 or (v.huCard and v.huCard ~= 0 and (not (roomInfo.stopFlag==MJDefine.StopFlag.STOP_FLAG_HUANG_ZHUANG))) then self.playerHandCards[viewId]:createOpenHandCards(v.huCard) self.playerHandCards[viewId]:moveLastOpenCard() end end end end --被抢杠的人回退补杠 -- if resultInfo.hutype==MJDefine.MJHuType.QiangGangHu and roomInfo.stopFlag==MJDefine.StopFlag.STOP_FLAG_NORMAL then -- self.playerHandCards[failViewId]:retoreBuGang(resultInfo.hucard) -- end local function callback() self:showXiaoJuView() if onEnd then onEnd() end self.ui.Items.Layout_Effect_luobo:removeAllChildren() end local function luoboNumCallBack() local strGameInfo = json.decode(app.room.roomInfo.strGameInfo) if strGameInfo.luobonum and strGameInfo.luobonum > 0 then local index = 1 for k,v in pairs(roomInfo.memberList) do local viewId = app.room:getViewIdByUserId(v.nUserId) local effect if index == app.room.roomInfo.nMaxPlayCount then effect = MJAnimationCompnent.CreateLoBoLabel(v.luoboNum,callback) else effect = MJAnimationCompnent.CreateLoBoLabel(v.luoboNum) end local pos = self.playerHandCards[viewId]:getAnimationPostion() if viewId==MJDefine.PlayerViewType.My then effect:setPosition(pos.x+130,pos.y-60) elseif viewId==MJDefine.PlayerViewType.Left then effect:setPosition(pos.x-20-30,pos.y-70) elseif viewId==MJDefine.PlayerViewType.Right then effect:setPosition(pos.x+10-30,pos.y-70) elseif viewId==MJDefine.PlayerViewType.Top then effect:setPosition(pos.x+130,pos.y+10-50) end self.ui.Items.Layout_Effect_luobo_Lable:addChild(effect) index = index + 1 end else callback() end end local luoboCards = roomInfo.luoboCards local function luoboCallBack() if luoboCards and #luoboCards>0 then local luoNum = #luoboCards --加一个黑底 local layer = cc.LayerColor:create(cc.c4b(0,0,0,120)) layer:setAnchorPoint(cc.p(0.5,0.5)) layer:ignoreAnchorPointForPosition(false) local tPos = self.ui.Items.ImageView_Logo:getPosition() local tLuoBoPos = { [1] = {[1] = cc.p(tPos.x,360-40)}, [2] = {[1] = cc.p(tPos.x-50,360),[2] = cc.p(tPos.x+50,360)}, } layer:setPosition(cc.p(getWinSize().width/2,getWinSize().height/2)) self.ui.Items.Layout_Effect_luobo:addChild(layer) for i,v in pairs(luoboCards) do local effect if i == #luoboCards then effect = MJAnimationCompnent.CreateLoBoEffect(v,self.desktopType,luoboNumCallBack) else effect = MJAnimationCompnent.CreateLoBoEffect(v,self.desktopType) end if MJDefine.LuoBoPos[luoNum] and MJDefine.LuoBoPos[luoNum][i] then effect:setPosition(tLuoBoPos[luoNum][i]) self.ui.Items.Layout_Effect_luobo:addChild(effect) end end else self:runDelay(1.0,function() callback() end) end end if #viewIds>0 then if roomInfo.stopFlag==MJDefine.StopFlag.STOP_FLAG_LONG_NOT_END or roomInfo.stopFlag==MJDefine.StopFlag.STOP_FLAG_DISBAND_GAME then self:runDelay(1.0,function() callback() end) else luoboCallBack() end local userInfo=app.room:getUserInfo(app.room:getMyUserId()) if userInfo then --拔萝卜音效 end else if roomInfo.stopFlag==MJDefine.StopFlag.STOP_FLAG_HUANG_ZHUANG then local effect=MJAnimationCompnent.CreateLiuJuEffect(callback) self.ui.Items.Layout_Player:addChild(effect) effect:setLocalZOrder(1000) MJSound.PlayHuangZhuang() else callback() end end end self:addCallBack(runGameXiaoJuResponse); end -- 显示小局结算 function linshuiRoomView:showXiaoJuView() self.direcionView:stopAllActions() self:setTingCardViewVisible(false) if self.xiaojuView then self.xiaojuView:removeFromParent() end local roomInfo = app.room.roomInfo self.xiaojuView = MJRoomXiaoJuView:new(self.desktopType) self:addChild(self.xiaojuView) end function linshuiRoomView:setTingCardViewVisible(bVisible,tingCards) self.ui.Items.Layout_Ting_Tip_Card_Panel:setVisible(false) --[[if self._tingCardView and (not tolua.isnull(self._tingCardView)) then self._tingCardView:setData(tingCards) if (not tingCards) or (type(tingCards) == 'table' and #tingCards==0) then self:setTingCardVisible(false) return end self:setTingCardVisible(bVisible) end--]] end --显示查听的牌 function linshuiRoomView:setChaTingCardViewVisible(bVisible,tingCards) end function linshuiRoomView:onTingCardStatus() local myUserId=app.user.loginInfo.uid; local memberList=app.room.roomInfo.memberList; local player = memberList[myUserId]; if not player then return ; end local nTingStatus = player.nTingStatus if nTingStatus == MJDefine.MJTingStatus.Ting then print("---------onTingCardStatus-----------1 "..myUserId) if player.isBaoPai == 1 then self.ui:sendMsg(app.room,MJDefine.MJEvent.Ting) end self.isTing = true; self:setButtonTingInfoVisible(true); else print("---------onTingCardStatus-----------0 "..myUserId) self:setButtonTingInfoVisible(false); end end function linshuiRoomView:onTingCardResult(data) print("---------听牌结果-------------") --[[if data.response.tingType==MJDefine.MJTingType.QuanTing then -- self:setChaTingCardViewVisible(true,{}) else if self._isOutCardTingCheck then self._isOutCardTingCheck = false local count = table.nums(data.response.tingCards); local isTing = count > 0; --self.ui.Items.Button_Ting_Info:setVisible(isTing); self:setButtonTingInfoVisible(isTing) self:setTingCardViewVisible(false, data.response.tingCards) else self:setTingCardViewVisible(true, data.response.tingCards) end self._tingCardView:setData(tingCards); end--]] local tingCards = data.response.tingCards or {}; self.isTing = table.nums(tingCards) > 0; self:setButtonTingInfoVisible(self.isTing); self._tingCardView:setData(tingCards); self:setTingCardVisible(false); end function linshuiRoomView:showTing(evet) --[[local roomInfo=app.room.roomInfo local selectCard = evet.card; if not selectCard or evet.card <= 0 then return; end if evet.card and roomInfo.tings and #roomInfo.tings>0 then local isTing = false for k,v in pairs(roomInfo.tings) do if evet.card==v.outCard then self:setTingCardViewVisible(true,v.tingCards) isTing = true end end if not isTing then self:setTingCardViewVisible(false) end else self:setTingCardViewVisible(false) local isMyGetCard = true if self.playerHandCards[MJDefine.MyViewId] then local handCards = self.playerHandCards[MJDefine.MyViewId]:getHandCardNodes() if handCards and type(handCards) == 'table' then isMyGetCard = (#handCards%3==2) end end local myUserId = app.room:getMyUserId() if roomInfo.nGameStartCount > 0 and roomInfo.memberList[myUserId].nPlayerFlag == 2 and (not isMyGetCard) then--游戏中,不是摸牌阶段 self._isOutCardTingCheck = true; self.ui:sendMsg(app.room,MJDefine.MJEvent.Ting) end end--]] local roomInfo=app.room.roomInfo; local selectCard = evet.card; if not selectCard or evet.card <= 0 then return; end local curTingCards = app.room:getTingCardsByCard(selectCard); if not self._tingCardView then return ; end self._tingCardView:setData(curTingCards); self.isTing = table.nums(curTingCards) > 0; if self.isTing and (not self:isMySelfHu()) then self:setTingCardVisible(true); else self:setTingCardVisible(false); end end function linshuiRoomView:isMySelfHu() local myUserId = app.room:getMyUserId(); local player = app.room.roomInfo.memberList[myUserId]; if not player then return false; end local huCards = player.huCards or {}; return table.nums(huCards) > 0; end function linshuiRoomView:pushTing() local function runPushTing(onEnd) if self.playerHandCards[MJDefine.MyViewId] then self.playerHandCards[MJDefine.MyViewId]:pushTing() end if onEnd then onEnd() end end self:addCallBack(runPushTing); end function linshuiRoomView:onHuResponse(data) local function runHuResponse(onEnd) local response = data.response local function callback() self:playHuAni(response) if onEnd then onEnd() end end local viewId = app.room:getViewIdByUserId(response.nUserId) local userInfo=app.room:getUserInfoByViewId(viewId) --先播放胡牌动画和音效,再显示胡牌顺序 local effect = MJAnimationCompnent.CreateHuEffect(response.huType,callback) if response.huType == MJDefine.MJGameHuType.HU_ZIMO then MJSound.PlayOperateSound(userInfo.sex,MJDefine.MJOperateType.OPREATE_ZIMOHU) -- effect=MJAnimationCompnent.CreateHuEffect("zimo",callback) -- elseif response.huType == MJDefine.MJGameHuType.HU_QIANGGANG then else MJSound.PlayOperateSound(userInfo.sex,MJDefine.MJOperateType.OPREATE_DIANPAOHU) -- effect=MJAnimationCompnent.CreateHuEffect("hu",callback) -- --点炮显示 end if effect then self.ui.Items.Layout_Effect:addChild(effect) effect:setTag(HU_EFFECT_TAG) effect:setLocalZOrder(1000) effect:setPosition(self.playerHandCards[viewId]:getAnimationPostion()) end --删除等待操作的显示 if self.waitOperates and #self.waitOperates>0 then for k,v in pairs(self.waitOperates) do v:removeFromParent() end self.waitOperates={} end if response.huType==MJDefine.MJGameHuType.HU_DIANPAO and response.curOpType ~= 1 then local failViewId = app.room:getViewIdByUserId(response.dpId) --点炮胡或抢杠胡,胡牌类型都是发 点炮胡 if response.isQiangGng > 0 then local huCard = response.huCard == 65 and response.redRealCard or response.huCard --如果胡的牌是红中 用真实的牌 否则用胡的牌 -- logD("isQiangGng huCard:"..huCard) --抢杠胡 self.playerHandCards[viewId]:onGetCard(nil,huCard) --被抢杠的人回退补杠 --self.playerHandCards[failViewId]:retoreBuGang(huCard,1) elseif response.isGspHu and response.isGspHu > 0 then local gameInfo =json.decode(app.room.roomInfo.strGameInfo); if gameInfo.gshmode == 1 then dghDianPao = true --点杠炮(选择的点杠花)时手上已经有杠的牌 不需要再加一张胡的牌 else self.playerHandCards[viewId]:onGetCard(nil,response.huCard) --将胡的牌收走 self.playerHandCards[failViewId]:removeOutCard(response.huCard) end else self.playerHandCards[viewId]:onGetCard(nil,response.huCard) --将胡的牌收走 self.playerHandCards[failViewId]:removeOutCard(response.huCard) end local function fangpaoCallback() self:playFangPaoAni(failViewId) end --放炮动画 effect=MJAnimationCompnent.CreateDianPaoEffect()--fangpaoCallback self.ui.Items.Layout_Effect:addChild(effect) effect:setLocalZOrder(1000) effect:setPosition(self.playerHandCards[failViewId]:getAnimationPostion()) if failViewId==MJDefine.MyViewId and app.room.roomInfo.lastOutViewId==MJDefine.MyViewId then --修改点炮的人连续二次出牌 不删除牌 app.room.roomInfo.lastOutViewId = nil end --此处仅做保留,没有实际意义 elseif response.huType==MJDefine.MJGameHuType.HU_QIANGGANG then local failViewId = app.room:getViewIdByUserId(response.dpId) if response.redRealCard > 0 then --抢杠胡时,胡牌的人将胡的牌加入手中 self.playerHandCards[viewId]:onGetCard(nil,response.redRealCard) --被抢杠的人回退补杠 --self.playerHandCards[failViewId]:retoreBuGang(response.redRealCard,1) end end if response.nUserId == app.room:getMyUserId() then self.playerHandCards[viewId]:setOutCardEnable(false) self:setTingCardViewVisible(false) --self.ui.Items.Button_Ting_Info:setVisible(false) self:setButtonTingInfoVisible(false) self.playerHandCards[viewId]:setTing(false) self.playerHandCards[viewId]:lockHandCard(true); self.playerHandCards[MJDefine.MyViewId]:hideOperate() else -- 其他人胡了倒牌 local handCards = {} for k,v in pairs(self.playerHandCards[viewId]:getHandCardNodes() or {}) do table.insert(handCards,{card = v.value or v:getValue()}) end if response.huType==MJDefine.MJGameHuType.HU_ZIMO or response.curOpType == 1 or (response.isGspHu and response.isGspHu > 0) then --如果是自摸胡 把最后一张替换为胡的牌或点杠花点炮 handCards[#handCards] = {card = response.huCard} end self.playerHandCards[viewId]:removeAllHandCards() self.playerHandCards[viewId]:createOpenHandCards(handCards) self.playerHandCards[viewId]:moveLastOpenCard() end --self.playerHandCards[MJDefine.MyViewId]:hideOperate() end self:addCallBack(runHuResponse); end function linshuiRoomView:playHuAni(response) local strGameInfo = json.decode(app.room.roomInfo.strGameInfo) --local effect = MJAnimationCompnent.CreateHuOrderEffect(response.huType,response.huOrder) -- if response.huType == 1 then -- effect=MJAnimationCompnent.CreateHuOrderEffect("zimo",response.huOrder) -- else -- effect=MJAnimationCompnent.CreateHuOrderEffect("hu",response.huOrder) -- end local viewId = app.room:getViewIdByUserId(response.nUserId) self.playerView:showHuOrder(viewId,response.huType,response.huOrder) if effect then self.ui.Items.Layout_Effect:addChild(effect) effect:setTag(HU_EFFECT_TAG) effect:setLocalZOrder(1000) local pos = self.playerHandCards[viewId]:getAnimationPostion() if viewId==MJDefine.PlayerViewType.My then effect:setPosition(pos.x,pos.y-60) elseif viewId==MJDefine.PlayerViewType.Left then effect:setPosition(pos.x-20,pos.y) elseif viewId==MJDefine.PlayerViewType.Right then effect:setPosition(pos.x+10,pos.y) elseif viewId==MJDefine.PlayerViewType.Top then effect:setPosition(pos.x,pos.y+10) end end end function linshuiRoomView:playFangPaoAni(viewId) local effect = MJAnimationCompnent.CreateFangPaoEffect() --local viewId = app.room:getViewIdByUserId(response.nUserId) if effect then self.ui.Items.Layout_Effect:addChild(effect) effect:setTag(HU_EFFECT_TAG) effect:setLocalZOrder(1000) local pos = self.playerHandCards[viewId]:getAnimationPostion() if viewId==MJDefine.PlayerViewType.My then effect:setPosition(pos.x,pos.y-60) elseif viewId==MJDefine.PlayerViewType.Left then effect:setPosition(pos.x-20,pos.y) elseif viewId==MJDefine.PlayerViewType.Right then effect:setPosition(pos.x+10,pos.y) elseif viewId==MJDefine.PlayerViewType.Top then effect:setPosition(pos.x,pos.y+10) end end end function linshuiRoomView:onQiangDuanOperates(data) local function runOnQiangDuanOperates(onEnd) logD("linshuiRoomView:runOnQiangDuanOperates") local response = data.response if response.operates and self.playerHandCards[MJDefine.MyViewId] then self.playerHandCards[MJDefine.MyViewId]:showOperate(response.operates) end if onEnd then onEnd() end end logD("linshuiRoomView:onQiangDuanOperates") self:addCallBack(runOnQiangDuanOperates) end --游戏消息 function linshuiRoomView:bindExtendMessage() self:bindEvent(app.room , MJDefine.MJEvent.OutCardTings, handler(self , self.pushTing)); self:bindEvent(app.room , MJDefine.MJEvent.HuResponse, handler(self , self.onHuResponse)) self:bindEvent(app.room , MJDefine.MJEvent.BaoPaiResponse, handler(self , self.onBaoPai)) self:bindEvent(app.room , MJDefine.MJEvent.BankerBaoPai, handler(self , self.onBankerBaoPai)) self:bindEvent(app.room , MJDefine.MJEvent.SendGuo, handler(self , self.onSendGuo)) self:bindEvent(app.room , MJDefine.MJEvent.QiangDuanOperates, handler(self , self.onQiangDuanOperates)) self:bindEvent(app , MJDefine.MJEvent.ChangeLanguage , handler(self , self.doSound)) self:bindEvent(app.room , MJDefine.MJEvent.StartPiao, handler(self , self.onStartPiao)) self:bindEvent(app.room , MJDefine.MJEvent.PiaoResponse, handler(self , self.onPiaoResponse)) self:bindEvent(app, MJDefine.MJEvent.ChangeViewType, handler(self, self.onEventChangeViewType )) --换三张,服务器会通过0x8122通知换牌 self:bindEvent(app.room , MJDefine.MJEvent.NoticeSwapCard,handler(self,self.onNoticeSwapCardResponse)) --换三张失败 self:bindEvent(app.room , MJDefine.MJEvent.SwapCardErr,handler(self,self.onChangeCardFail)) --换三张成功 self:bindEvent(app.room , MJDefine.MJEvent.SwapCardSucc,handler(self,self.onChangeCardSucc)) --换三张成功后的信息 self:bindEvent(app.room , MJDefine.MJEvent.SwapCardSuccInfo,handler(self,self.onChangeCardInfo)) --服务器通知定缺 self:bindEvent(app.room , MJDefine.MJEvent.NoticeDingQue,handler(self,self.onNoticeDingQueResponse)) --当玩家操作成功后,通过0x8131广播定缺成功 self:bindEvent(app.room , MJDefine.MJEvent.DingQueSucc,handler(self,self.onDingQueSuccResponse)) --当所有玩家定缺成功后,服务器会通过广播告诉玩家定缺类型 self:bindEvent(app.room , MJDefine.MJEvent.DingQueSuccInfo,handler(self,self.onDingQueSuccInfoResponse)) --内容和0x8106保持统一 广播桌子上所有玩家庄家起手操作 self:bindEvent(app.room , MJDefine.MJEvent.AfterDingQue,handler(self , self.onAfterDingQue)) --检测是否符合换三张规则 self:bindEvent(app.room , MJDefine.MJEvent.CheckIsInSwapRule,handler(self , self.onCheckIsInSwapRule)) --躺牌 self:bindEvent(app.room , MJDefine.MJEvent.TangPaiResponse,handler(self,self.onTangPaiResponse)) -- 托管 self:bindEvent(app.room , MJDefine.MJEvent.HostingRequest, handler(self, self.onHostingRequest)) end function linshuiRoomView:clean() self.playerView:init() -- --默认状态 self:defaultState() app.room:resetRoomInfo() self:setBtnSitDownVisible(false) self.ui:sendMsg(app.room, MJDefine.MJEvent.CallReadyRequest) -- self._gameoverview = nil end function linshuiRoomView:updateReady() local nUserId = app.room:getMyUserId()--app.user.loginInfo.uid if app.room.roomInfo.nGameStartCount > 0 then self.toolView.ui.Items.Button_Leave:setEnabled(false) self:setBtnSitDownVisible(false) else self.toolView.ui.Items.Button_Leave:setEnabled(true) end if app.room.roomInfo.nGameStartCount == 0 and app.room.roomInfo.nRoomOwnedUid ~= nUserId then self.toolView.ui.Items.Button_Dismiss:setEnabled(false) else self.toolView.ui.Items.Button_Dismiss:setEnabled(true) end self:checkCanDismiss() end -- 游戏开始 function linshuiRoomView:onGameStartResponse() linshuiRoomView.super.onGameStartResponse(self) self._gameoverview = nil end -- 大局结算 function linshuiRoomView:onGameDaJuResponse(data) app.club_php:dispatchEvent({name = GAME_EVENT.CLUB_BACK_ROOM}) if self._gameoverview then return end if app.room.roomInfo.needJieSuanInfo == 1 then--显示总结算 self:showGameOverResult(data.response) else --[[local roomInfo=app.room.roomInfo --如果是解散直接跳转总结算 if roomInfo.stopFlag==MJDefine.StopFlag.STOP_FLAG_LONG_NOT_END or roomInfo.stopFlag==MJDefine.StopFlag.STOP_FLAG_DISBAND_GAME then self:showGameOverResult(data.response) end --]] local roomInfo=app.room.roomInfo local isNoCard = false--没有手牌 for i,player in pairs(roomInfo.memberList) do if type(player.handCards) == 'table' and #player.handCards <= 0 then local a = #player.handCards isNoCard = true break end end if isNoCard then self:showGameOverResult(data.response) end app.room:dispatchEvent({name = GAME_EVENT.DISSMISS_CLOSE}) end end -- 大局结算 function linshuiRoomView:showGameOverResult(data) if self._gameoverview ~= nil then return end self.direcionView:stopAllActions() self:resetGame() local view=MJRoomDaJuView:new(data) view:setAnchorPoint(cc.p(0.5, 0.5)) app:showWaitDialog(view) self._gameoverview = view end function linshuiRoomView:onOtherLogoutResponse(data) -- local jushu = app.room.roomInfo.nGameStartCount or 0 if (not data or not data.nUserId or not data.nSeatShowId) then return end local function test(onEnd) self.playerView:updatePlayerInfo(data.nSeatShowId) self:onUserReadyResponse() --更新GPS --self:updateAllGpsInfo() --self:checkGpsDistance() -- 是否显示邀请好友 self.toolView:updateButton() logE("88888-onOtherLogoutResponse onEnd") if onEnd then onEnd() end end self:addCallBack(test) end function linshuiRoomView:resetGame() linshuiRoomView.super.resetGame(self) self.ui.Items.Layout_Effect:removeAllChildren() self.ui.Items.Layout_Effect_luobo_Lable:removeAllChildren() self.ui.Items.Layout_Effect_luobo:removeAllChildren() self.playerView:clearBao() self.playerView:clearAllPiao() --self.playerView:clearAllBoZiMo() self.playerView:clearAllQue() self.playerView:clearAllHuOrder() if self.playerHandCards[MJDefine.MyViewId] then self.playerHandCards[MJDefine.MyViewId]:setQueType(-1)--设置缺牌类型为空 self.playerHandCards[MJDefine.MyViewId]:setBaoPai(0)--重置报状态 end self:setTingCardVisible(false); self:setTingCardViewVisible(false); self.isTang = false app.room.roomInfo.lastOutViewId = 0 self.reShowBao = nil --重连显示报操作标志 self.guobao = nil--重连过报标志 end --显示换三张 function linshuiRoomView:showSwapCard(isOpered)--是否已经操作过 self:stopDirection() local roomInfo=app.room.roomInfo local gameInfo=json.decode(roomInfo.strGameInfo) if not gameInfo.specRule or (not (getNumBand(gameInfo.specRule, 0x0002)>0)) then return end isOpered = isOpered or false self:hideSwapCard() local ui=loadUI("mj_linshui/res/ui_fangjian/mj_linshui_swap_card.ui") self.ui.Items.Layout_Player:addChild(ui) self.swapCard=ui self.swapCard.Items.ImageView_bg:setVisible(isOpered) for i=1,4 do--先隐藏全部 if self.swapCard.Items["Layout_swapCard_"..i] then self.swapCard.Items["Layout_swapCard_"..i]:setVisible(false) end self:setSwapCardSucc(false,i) end for k,v in pairs(app.room.roomInfo.memberList) do--根据人数显示 local viewId = app.room:getViewIdByUserId(v.nUserId) if self.playerHandCards[viewId] then if self.swapCard.Items["Layout_swapCard_"..viewId] then self.swapCard.Items["Layout_swapCard_"..viewId]:setVisible(true) end else if self.swapCard.Items["Layout_swapCard_"..viewId] then self.swapCard.Items["Layout_swapCard_"..viewId]:setVisible(false) end end end --确定换牌按钮 ui.Items.Button_sure:registerClick(function() playBtnEffect() self.swapCard.Items.ImageView_bg:setVisible(false) --请求换牌 local cards = self.playerHandCards[MJDefine.MyViewId]:getSelectedCards() app.room:requestSwapCards(cards) --[[local request = MJMessage.PiaoRequest:new() request.isPiao = 0 self.ui:sendMsg(app.room,MJDefine.MJEvent.PiaoRequest,request)--]] end) end --隐藏换三张 function linshuiRoomView:hideSwapCard() if self.swapCard then self.swapCard:removeFromParent() self.swapCard=nil end end --换三张,服务器会通过0x8122通知换牌 function linshuiRoomView:onNoticeSwapCardResponse(response) local function runNoticeSwapCard(onEnd) logD("linshuiRoomView:onNoticeSwapCardResponse") local data = response.response self:showSwapCard(true) self.playerHandCards[MJDefine.MyViewId]:initSwapCardTouchEvent() --弹出推荐牌 self.playerHandCards[MJDefine.MyViewId]:resetHandCards() self.playerHandCards[MJDefine.MyViewId]:selectCardsByCards(data.swapCards) self.swapCard.Items.Button_sure:setEnabled(true) if onEnd then onEnd() end end logD("linshuiRoomView:runNoticeSwapCard") self:addCallBack(runNoticeSwapCard) end --换三张失败 function linshuiRoomView:onChangeCardFail(response) local function runChangeCardFail(onEnd) logD("linshuiRoomView:onChangeCardFail") self:showSwapCard(true) self.playerHandCards[MJDefine.MyViewId]:resetHandCards() self.swapCard.Items.Button_sure:setEnabled(false) if onEnd then onEnd() end end logD("linshuiRoomView:runChangeCardFail") self:addCallBack(runChangeCardFail) end --换三张成功 function linshuiRoomView:onChangeCardSucc(response) local function runChangeCardSucc(onEnd) logD("linshuiRoomView:onChangeCardSucc") local data = response.response local userId = data.nUserId--操作的玩家 local viewId = app.room:getViewIdByUserId(userId) if viewId == MJDefine.MyViewId then if self.swapCard and self.swapCard.Items.ImageView_bg then self.swapCard.Items.ImageView_bg:setVisible(false) end self.playerHandCards[MJDefine.MyViewId]:deleteSelectedCards() else self:setSwapCardSucc(true,viewId) local tmpCards = {} for i=1,3 do table.insert(tmpCards,{card = 0}) end self.playerHandCards[viewId]:removeHandCard(tmpCards) self.playerHandCards[viewId]:resetHandCards() end self.playerHandCards[viewId]:createSwapCards({0,0,0}) if onEnd then onEnd() end end logD("linshuiRoomView:runChangeCardSucc--------") self:addCallBack(runChangeCardSucc) end --换三张成功后的信息 function linshuiRoomView:onChangeCardInfo(response) local function runChangeCardInfo(onEnd) logD("linshuiRoomView:onChangeCardInfo") self:hideSwapCard() local data = response.response self:showSwapDirection(data.swapType) for i,v in pairs(data.swapCards) do for i=1,4 do if i == MJDefine.MyViewId and self.playerHandCards[MJDefine.MyViewId] then self.playerHandCards[MJDefine.MyViewId]:onGetCard(nil,tonumber(v.card),true) elseif self.playerHandCards[i] then self.playerHandCards[i]:onGetCard(nil,0,true) end end end --self.playerHandCards[MJDefine.MyViewId]:resetHandCards() for i=1,4 do if self.playerHandCards[i] then self.playerHandCards[i]:deleteSwapCards() end end self.playerHandCards[MJDefine.MyViewId]:removeTouchEventOnly() for i,v in pairs(data.swapCards) do local handCards = self.playerHandCards[MJDefine.MyViewId]:getHandCardNodes() or {} for j,mjCard in pairs(handCards) do if mjCard:getValue() == tonumber(v.card) and mjCard:getSelected() ~= MJDefine.MJStatus.Select then --local mjCard = self.playerHandCards[MJDefine.MyViewId]:getMjByValue(tonumber(v.card)) --if mjCard and mjCard:getSelected() ~= MJDefine.MJStatus.Select then mjCard:setSelected(MJDefine.MJStatus.Select) mjCard:recordPostion() local initPos = mjCard:getPosition() local toPos = cc.p(initPos.x, initPos.y + 25) mjCard:setPosition(toPos) mjCard:runDeSelectAnimationWithTime(1.0) mjCard:runAction(cc.Sequence:create(cc.DelayTime:create(1.0),cc.CallFunc:create(function() mjCard:setSelected(MJDefine.MJStatus.Normal) end))) break end --end end end --[[self:runAction(cc.Sequence:create(cc.DelayTime:create(1.0),cc.CallFunc:create(function() self.playerHandCards[MJDefine.MyViewId]:initTouchEvent() end)))--]] if onEnd then onEnd() end end logD("linshuiRoomView:runChangeCardInfo--------") self:addCallBack(runChangeCardInfo) end --设置换牌成功 isSwaped:true显示有勾的,false显示换牌中 function linshuiRoomView:setSwapCardSucc(isSwaped,viewId) isSwaped = isSwaped or false if not self.swapCard or tolua.isnull(self.swapCard) then return end if self.swapCard.Items["ImageView_swaping_"..viewId] then self.swapCard.Items["ImageView_swaping_"..viewId]:setVisible(not isSwaped) end if self.swapCard.Items["ImageView_swaped_"..viewId] then self.swapCard.Items["ImageView_swaped_"..viewId]:setVisible(false)--isSwaped 不显示选牌中了 end end --换牌方式 1顺时针 2对家换牌 3逆时针 function linshuiRoomView:showSwapDirection(dir) if not dir then return end self:hideSwapDirection() local ui=loadUI("mj_linshui/res/ui_fangjian/mj_linshui_swap_direction.ui") self.ui.Items.Layout_Player:addChild(ui) self.swapDirection=ui self.swapDirection.Items.Layout_ShunShiZhen:setVisible(dir == 1) self.swapDirection.Items.Layout_NiShiZhen:setVisible(dir == 3) self.swapDirection.Items.Layout_DuiJia:setVisible(dir == 2) self.swapDirection.Items.ImageView_s:playClip("shunshizhen") self.swapDirection.Items.ImageView_n:playClip("nishizhen") self.swapDirection.Items.Layout_DuiJia:playClip("duijia") self.swapDirection:runAction(cc.Sequence:create(cc.DelayTime:create(1.0),cc.CallFunc:create(function() self:hideSwapDirection() end))) end function linshuiRoomView:hideSwapDirection() if self.swapDirection then self.swapDirection:removeFromParent() self.swapDirection = nil end end --显示定缺界面 function linshuiRoomView:showDingQue(tp) self:hideDingQue() local ui=loadUI("mj_linshui/res/ui_fangjian/mj_linshui_dingque.ui") self:addChild(ui) self.dingque=ui self:showDingQueOpEffect(tp) for i=1,4 do--先隐藏全部 if self.dingque.Items["Layout_DingQue_"..i] then self.dingque.Items["Layout_DingQue_"..i]:setVisible(false) end end for k,v in pairs(app.room.roomInfo.memberList) do--根据人数显示 local viewId = app.room:getViewIdByUserId(v.nUserId) if self.playerHandCards[viewId] then if self.dingque.Items["Layout_DingQue_"..viewId] then self.dingque.Items["Layout_DingQue_"..viewId]:setVisible(true) end else if self.dingque.Items["Layout_DingQue_"..viewId] then self.dingque.Items["Layout_DingQue_"..viewId]:setVisible(false) end end end ui.Items.Button_Wan:registerClick(function() playBtnEffect() self:hideDingQueOp() local request = MJMessage.QueCard:new() request.queCard = 0 logD(request.isDingQue,"发送定缺:0") self.ui:sendMsg(app.room, MJDefine.MJEvent.RequestDingQue, request) end) ui.Items.Button_Tong:registerClick(function() playBtnEffect() self:hideDingQueOp() local request = MJMessage.QueCard:new() request.queCard = 1 logD(request.isDingQue,"发送定缺:1") self.ui:sendMsg(app.room, MJDefine.MJEvent.RequestDingQue, request) end) ui.Items.Button_Tiao:registerClick(function() playBtnEffect() self:hideDingQueOp() local request = MJMessage.QueCard:new() request.queCard = 2 logD(request.isDingQue,"发送定缺:2") self.ui:sendMsg(app.room, MJDefine.MJEvent.RequestDingQue, request) end) end --隐藏定缺界面 function linshuiRoomView:hideDingQue() if self.dingque then self.dingque:removeFromParent() self.dingque=nil end end --显示定缺界面操作按钮特效 function linshuiRoomView:showDingQueOpEffect(tp) if not self.dingque or tolua.isnull(self.dingque) then return end self.dingque.Items.Layout_Wan_Effect:setVisible(tp==0) self.dingque.Items.Layout_Tong_Effect:setVisible(tp==1) self.dingque.Items.Layout_Tiao_Effect:setVisible(tp==2) self.dingque.Items.ImageView_Wan_Effect1:playClip("neiquan") self.dingque.Items.ImageView_Wan_Effect2:playClip("waiquan") self.dingque.Items.ImageView_Tong_Effect1:playClip("neiquan") self.dingque.Items.ImageView_Tong_Effect2:playClip("waiquan") self.dingque.Items.ImageView_Tiao_Effect1:playClip("neiquan") self.dingque.Items.ImageView_Tiao_Effect2:playClip("waiquan") end --隐藏定缺界面操作按钮 function linshuiRoomView:hideDingQueOp() if not self.dingque or tolua.isnull(self.dingque) then return end self.dingque.Items.Button_Wan:setVisible(false) self.dingque.Items.Button_Tong:setVisible(false) self.dingque.Items.Button_Tiao:setVisible(false) self.dingque.Items.Layout_Wan_Effect:setVisible(false) self.dingque.Items.Layout_Tong_Effect:setVisible(false) self.dingque.Items.Layout_Tiao_Effect:setVisible(false) end --设置定缺成功 isDingque:true显示有勾的,false显示定缺中 function linshuiRoomView:setDingQueSucc(isDingque,viewId) isDingque = isDingque or false if not self.dingque or tolua.isnull(self.dingque) then return end if self.dingque.Items["ImageView_dingquez_"..viewId] then self.dingque.Items["ImageView_dingquez_"..viewId]:setVisible(not isDingque) end if self.dingque.Items["ImageView_dingquew_"..viewId] then self.dingque.Items["ImageView_dingquew_"..viewId]:setVisible(isDingque) end end function linshuiRoomView:onBtnTingInfoClicked( ) --[[playBtnEffect() if self.ui.Items.Layout_Ting_Tip_Card_Panel:isVisible() then self.ui.Items.Layout_Ting_Tip_Card_Panel:setVisible(false) else self.ui:sendMsg(app.room,MJDefine.MJEvent.Ting) end--]] playBtnEffect() if self._tingCardView:isVisible() then self:setTingCardVisible(false); else self:setTingCardVisible(true); end end function linshuiRoomView:onChangeChatEnable() if not self.messageView or tolua.isnull(self.messageView) then return end local voiceEnable = tonumber(loadUserInfo("linshuiPingBiYuYinKG")) or 1 local propEnable = tonumber(loadUserInfo("linshuiHuDongBiaoQingKG")) or 1 self.messageView:setVoiceEnabled(voiceEnable==1) self.messageView:setPropEnabled(propEnable==1) end function linshuiRoomView:onEventChangeViewType(data) self:changeGameBg(true) logD("linshuiRoomView:onEventChangeViewType "..self.desktopType) MJDefine.MJConfig = MJDefine.loadMJConfig(self.desktopType) logD("linshuiRoomView:onEventChangeViewType "..MJDefine.MJConfig_2d.MAHJONG_CARD) self.ui:sendMsg(app.room, MJDefine.MJEvent.GetTableInfo); end --服务器通知定缺 function linshuiRoomView:onNoticeDingQueResponse(response) local function runNoticeDingQue(onEnd) logD("linshuiRoomView:onNoticeDingQueResponse") local data = response.response self:showDingQue(data.queCard) for i=1,4 do--置为定缺中 self:setDingQueSucc(false,i) end self.playerHandCards[MJDefine.MyViewId]:setHandCardsDidable() if onEnd then onEnd() end end logD("linshuiRoomView:runNoticeDingQue") self:addCallBack(runNoticeDingQue) end --当玩家操作成功后,通过0x8131广播定缺成功 function linshuiRoomView:onDingQueSuccResponse(response) local function runDingQueSucc(onEnd) logD("linshuiRoomView:onDingQueSuccResponse") local data = response.response local userId = data.nUserId--操作的玩家 local viewId = app.room:getViewIdByUserId(userId) if viewId == MJDefine.MyViewId then self:hideDingQueOp() self.playerView:showQue(data.queCard,viewId,true) self.playerHandCards[viewId]:setQueType(data.queCard) else self:setDingQueSucc(true,viewId) end if onEnd then onEnd() end end logD("linshuiRoomView:runDingQueSucc") self:addCallBack(runDingQueSucc) end --当所有玩家定缺成功后,服务器会通过广播告诉玩家定缺类型 function linshuiRoomView:onDingQueSuccInfoResponse(response) local function runDingQueSuccInfo(onEnd) logD("linshuiRoomView:onDingQueSuccInfoResponse") self:hideDingQue() local data = response.response for i,v in pairs(data.dingQueInfo) do local userId = v.nUserId--操作的玩家 local viewId = app.room:getViewIdByUserId(userId) self.playerView:showQue(v.queCard,viewId,true) self.playerHandCards[viewId]:setQueType(v.queCard) if viewId == MJDefine.MyViewId then self.playerHandCards[viewId]:initTouchEvent() end self.playerHandCards[viewId]:resetHandCards() end self.playerHandCards[MJDefine.MyViewId]:checkQueAndDisableOtherCard() if onEnd then onEnd() end end logD("linshuiRoomView:runDingQueSuccInfo") self:addCallBack(runDingQueSuccInfo) end function linshuiRoomView:onCheckIsInSwapRule(data) if not data then return end if not self.swapCard then return end self.swapCard.Items.Button_sure:setEnabled(data.canCommit) end --躺牌结果 function linshuiRoomView:onTangPaiResponse(response) if not response then return end local data = response.response if not data then return end local opUserId = data.nUserId local viewId = app.room:getViewIdByUserId(opUserId) local isTang = data.isTang local tangCards = data.tangCards local paoCards = data.paoCards --躺的人手牌躺牌变色 其他人看到躺牌倒下 local myUserId = app.room:getMyUserId() self.playerHandCards[MJDefine.MyViewId]:setPaoCard(true,paoCards) if opUserId == myUserId then self.isTang = true self.playerHandCards[viewId]:setTangSuccess(true) self.playerHandCards[viewId]:setTangCard(true,tangCards) else self.playerHandCards[viewId]:showTangCard(true,tangCards) end local effect=MJAnimationCompnent.CreateTangEffect() if effect then self.ui.Items.Layout_Player:addChild(effect) effect:setLocalZOrder(1000) effect:setPosition(self.playerHandCards[viewId]:getAnimationPostion()) end --躺音效 local userInfo=app.room:getUserInfoByViewId(viewId) MJSound.PlayTangSound(userInfo.sex) end -- 初始化听牌组件 function linshuiRoomView:initTingCardView () if not self._tingCardView then self._tingCardView = require("mj_linshui.luaScript.Views.Compnent.linshuiTingCardView"):new(); self:addChild(self._tingCardView) self._tingCardView:setData(nil); self:setTingCardVisible(false); end end -- 初始化听牌按钮 function linshuiRoomView:initTingBtnView () local linshuiTingBtnView = import("mj_linshui.luaScript.Views.Compnent.linshuiTingBtnView"); local btnTing = linshuiTingBtnView:new(); btnTing:setCallback(handler(self, self.onBtnTingInfoClicked)); btnTing:setPosition(cc.p(230, 158)); self.btnTing = btnTing; self.ui.Items.Layout_record:addChild(self.btnTing) end function linshuiRoomView:setButtonTingInfoVisible(isVisible) if self.btnTing then self.btnTing:setVisible(isVisible); end end function linshuiRoomView:setTingCardVisible (isVisible) if not self._tingCardView then return ; end self._tingCardView:setVisible(isVisible); end -- 飘操作--------------------------------------------------------------- function linshuiRoomView:showPiao() self:stopDirection() local roomInfo=app.room.roomInfo local gameInfo=json.decode(roomInfo.strGameInfo) if not gameInfo.piaomode or tonumber(gameInfo.piaomode)==0 then return end self:hidePiao() local ui=loadUI("mj_linshui/res/ui_fangjian/mj_linshui_piao.ui") self.ui.Items.Layout_Player:addChild(ui) self.piao=ui ui.Items.Button_BuPiao:registerClick(function() playBtnEffect() self:hidePiao() local request = MJMessage.PiaoRequest:new() request.isPiao = 0 self.ui:sendMsg(app.room,MJDefine.MJEvent.PiaoRequest,request) end) for i=1,5 do local uiButton = string.format("Button_Piao_%d",i) ui.Items[uiButton]:registerClick(function() playBtnEffect() self:hidePiao() local request = MJMessage.PiaoRequest:new() request.isPiao = i self.ui:sendMsg(app.room,MJDefine.MJEvent.PiaoRequest,request) end) end end function linshuiRoomView:hidePiao() if self.piao then self.piao:removeFromParent() self.piao=nil end end --显示飘操作按钮 function linshuiRoomView:onStartPiao(response) local function runPiao(onEnd) logD("linshuiRoomView:onStartPiao") self:showPiao() if onEnd then onEnd() end end logD("linshuiRoomView:runPiao") self:addCallBack(runPiao) end --飘结果 function linshuiRoomView:onPiaoResponse(response) local function runonPiaoResponse(onEnd) logD("linshuiRoomView:runonPiaoResponse") local data = response.response local userId = data.nUserId--操作的玩家 local playersPiaostate = data.playerPiaoState--所有玩家的飘状态 if playersPiaostate then for i,v in pairs(playersPiaostate) do local viewId = app.room:getViewIdByUserId(v.nUserId) local myUserId = app.room:getMyUserId() local userInfo=app.room:getUserInfoByViewId(viewId) if myUserId == data.nUserId then else end self.playerView:showPiao(viewId,v.piaostate) app.room.roomInfo.memberList[v.nUserId].isPiao = v.piaostate if v.piaostate>0 and userId == v.nUserId then --飘音效 MJSound.PlayPiaoSound(userInfo.sex) local effect = MJAnimationCompnent.CreatePiaoEffect() if effect then self.ui.Items.Layout_Effect_luobo:addChild(effect) effect:setLocalZOrder(1000) effect:setPosition(self.playerHandCards[viewId]:getAnimationPostion()) end end end else local viewId = app.room:getViewIdByUserId(userId) self.playerView:showPiao(viewId,data.piaostate) app.room.roomInfo.memberList[userId].isPiao = data.piaostate if data.piaostate and data.piaostate > 0 then --飘音效 local userInfo=app.room:getUserInfoByViewId(viewId) MJSound.PlayPiaoSound(userInfo.sex) local effect = MJAnimationCompnent.CreatePiaoEffect() if effect then self.ui.Items.Layout_Effect_luobo:addChild(effect) effect:setLocalZOrder(1000) effect:setPosition(self.playerHandCards[viewId]:getAnimationPostion()) end end end if onEnd then onEnd() end end logD("linshuiRoomView:runonPiaoResponse--------") self:addCallBack(runonPiaoResponse) end function linshuiRoomView:showBaoJiao() self:hideBaoJiao() local ui=loadUI("mj_linshui/res/ui_fangjian/mj_linshui_baojiao.ui") self:addChild(ui) self.baojiao=ui ui.Items.Button_Bao:registerClick(function() playBtnEffect() self:hideBaoJiao() local request = MJMessage.BaoPaiRequest:new() request.isBaoPai = 1 logD(request.isBaoPai,"发送爆:1") self.ui:sendMsg(app.room, MJDefine.MJEvent.BaoPaiRequest, request) end) ui.Items.Button_guo:registerClick(function() playBtnEffect() self:hideBaoJiao() local request = MJMessage.BaoPaiRequest:new() request.isBaoPai = 0 logD(request.isBaoPai,"发送爆:0") self.ui:sendMsg(app.room, MJDefine.MJEvent.BaoPaiRequest, request) end) --[[local gameInfo =json.decode(app.room.roomInfo.strGameInfo); if gameInfo.baojiao then ui.Items.Button_Bao:setVisible(gameInfo.baojiao == 1); end--]] ui.Items.Layout_baojiao:requestDoLayout() ui.Items.Layout_baojiao:doLayout(); end function linshuiRoomView:hideBaoJiao() if self.baojiao then self.baojiao:removeFromParent() self.baojiao=nil end end --- -- 托管通知 -- @param data -- @return -- function linshuiRoomView:onHostingRequest( data ) local response = data.response if response.nUserId == app.user.loginInfo.uid then if response.status == 1 then --托管状态 self.toolView:showTuoGuan(true) self:hidePiao() elseif response.status == 0 then--取消托管状态 self.toolView:showTuoGuan(false) end end local isTuoGuan = response.status == 1; local viewId = app.room:getViewIdByUserId(response.nUserId) self.playerView:showTuoGuanByViewId(viewId,isTuoGuan) end function linshuiRoomView:onWaitOperate(data) --什么都不做 end return linshuiRoomView