|
- 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 xzddRoomView = class("xzddRoomView", MJRoomView)
-
- local zhongNiaoTime=1.33
- local HU_EFFECT_TAG = 100
-
- function xzddRoomView:ctor()
- xzddRoomView.super.ctor(self)
- self.operates = {}
- self._isReplay = false
-
- if app.systemSetting.info.viewType == MJDefine.DesktopType.TwoD then -- viewType只保存2d 3d类型 mj_desktop_2d_mjType保存2d麻将类型
- local value = loadUserInfo("mj_desktop_2d_mjType_" .. (MJDefine.GameID or app.gameId))
- if value=="" or not value then
- value = MJDefine.DesktopType.TwoD
- saveUserInfo("mj_desktop_2d_mjType_" .. (MJDefine.GameID or app.gameId), value)
- end
- self.desktopType = value
- else
- self.desktopType = app.systemSetting.info.viewType
- end
- MJDefine.MJConfig = MJDefine.loadMJConfig(self.desktopType)
- end
-
- function xzddRoomView:loadUi()
- local ui = loadUI("mj_xzdd/res/ui_fangjian/mj_xzdd_roomView.ui")
- self.ui = ui
- self:addChild(ui)
- end
-
- function xzddRoomView:onEnter()
- xzddRoomView.super.onEnter(self)
-
- self:initLogo()
- --获取是否贴鬼杠和是否自动对齐
- self:setCheckDefault()
- self:doSound()
- end
-
- function xzddRoomView:onExit()
- xzddRoomView.super.onExit(self)
- self:cleanCache()
- end
-
- function xzddRoomView: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_xzdd.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_xzdd/res/zy_fangjian/mj_2d_cards.plist",
- "mj_xzdd/res/zy_fangjian/mj_2d_lgold.plist",
- }
- -- 删除缓存,防止与其他麻将资源混淆(例如南充麻将的墨绿大麻将和邻水麻将的金黄大麻将)
- for i, v in ipairs(temp) do
- cc.SpriteFrameCache:getInstance():removeSpriteFramesFromFile(v)
- end
- end
-
- function xzddRoomView:doSound()--1 普通话 2 方言
- local cacheLan = "mj_language"..(MJDefine.GameID or app.gameId)
- logD("xzddRoomView:doSound", cacheLan)
- local defaultValue = tonumber(loadUserInfo(cacheLan)) or 2
- saveUserInfo(cacheLan, defaultValue)
- MJSound.setSoundType(defaultValue)
- end
-
- function xzddRoomView:setCheckDefault()
- MJDefine.isAutomatic = true
- end
-
-
- -- 一键截屏
- function xzddRoomView:onClickButtonShot( sender )
- playBtnEffect()
- showScreenShot()
- end
-
- --隐藏俱乐部
- function xzddRoomView: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 xzddRoomView:changeGameBg(isUpdateViewType)
- if isUpdateViewType then
- if app.systemSetting.info.viewType == MJDefine.DesktopType.TwoD then --更新2D麻将类型 金色还是绿色
- local value = loadUserInfo("mj_desktop_2d_mjType_" .. (MJDefine.GameID or app.gameId)) --or MJDefine.DesktopType.TwoD
- if value=="" or not value then
- value = MJDefine.DesktopType.TwoD
- saveUserInfo("mj_desktop_2d_mjType_" .. (MJDefine.GameID or app.gameId), 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("mj_desktop_group_" .. (MJDefine.GameID or app.gameId))) or 2
- 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 xzddRoomView: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 xzddRoomView:loadTextureCache()
- xzddRoomView.super.loadTextureCache(self)
- -- local defaultValue = tonumber(loadUserInfo("luzhou_mj_majhong")) or 1
-
- loadSpriteFrameFile("mj_xzdd/res/zy_fangjian/mj_operateEffect.plist")
- loadSpriteFrameFile("mj_xzdd/res/zy_fangjian/effect_guafeng.plist")
- loadSpriteFrameFile("mj_xzdd/res/zy_fangjian/effect_xiayu.plist")
- end
-
-
- function xzddRoomView: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: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 xzddRoomView: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 xzddRoomView:onBaoPai(data)
- if data.response.isBaoPai == 1 then
- local effect=MJAnimationCompnent.CreateBaoEffect()
- 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]:setBaoPai(1)
- self.playerHandCards[viewId]:lockHandCard(true)
- -- self.playerHandCards[viewId]:setOutCardEnable(false)
- else
- --self.playerHandCards[viewId]:setOutCardEnable(true)
- end
- 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)
- 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);
- app.room.roomInfo.memberList[data.response.nUserId].nTingStatus = MJDefine.MJTingStatus.Ting;
- --end
- end
- end
-
- function xzddRoomView:onGameSendCardResponse()
- --发牌的时候清除桌面上的飘
- self.ui.Items.Layout_Effect_luobo:removeAllChildren()
- local function runGameSendCardResponse(onEnd)
- log("2000000000-xzddRoomView - runGameSendCardResponse()" )
-
- 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.toolView:showTuoGuan(app.room.roomInfo.hosting==1)
- end
- log("2000000000-xzddRoomView - addCallBack(runGameSendCardResponse)" )
- self:addCallBack(runGameSendCardResponse);
- end
-
- function xzddRoomView:onUserReadyResponse(response)
- xzddRoomView.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()
- 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);
- end
-
-
- -- 广播桌子上所有玩家庄家起手操作 这里其实是发牌
- function xzddRoomView: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("xzddRoomView 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
-
- --检测定缺牌(如果是在回放中,就不置灰牌了)
- if not self._isReplay then
- self.playerHandCards[MJDefine.MyViewId]:checkQueAndDisableOtherCard()
- end
-
- --先清除所有操作按钮
- --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)
- 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]:setBaoPai(1)
- 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-xzddRoomView - addCallBack(runOnBankerOutCard)")
- self:addCallBack(runOnBankerOutCard);
-
- end
-
- function xzddRoomView:onAfterDingQue(data)
- local function runOnAfterDingQue(onEnd)
- logE("xzddRoomView 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.playerHandCards[MJDefine.MyViewId]:setOutCardEnable(true)
- if operates and table.nums(operates)>0 then
- self.operates = operates
- self.playerHandCards[MJDefine.MyViewId]:setOutCardEnable(true)
- else
- 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()
- if onEnd then
- onEnd()
- end
- end
- self:addCallBack(runOnAfterDingQue)
- end
-
- function xzddRoomView:onTurnOutCard(data)
- local function runOnTurnOutCard(onEnd)
- logE("MJRoomView:runOnTurnOutCard(), response = ", table.tostring(data.response))
- log("2000000000-MJRoomView - runOnTurnOutCard")
-
- self.playerHandCards[MJDefine.MyViewId]:setOutCardEnable(true)
-
- if onEnd then
- onEnd()
- end
- end
-
- log("2000000000-MJRoomView - addCallBack(runOnTurnOutCard)")
- self:addCallBack(runOnTurnOutCard)
- end
-
- --出牌成功
- function xzddRoomView:onOutCardSuccess(data)
- logE("xzddRoomView:onOutCardSuccess(), response = ", table.tostring(data.response))
- local function runOnOutCardSuccess(onEnd)
- log("2000000000-xzddRoomView - 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]: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) and app.room.roomInfo.lastOutViewId~=MJDefine.MyViewId then --点击爆牌的时候 前端已经打出牌 要判断上次出牌的人是不是自己 避免重复出牌
- 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")
- self.playerHandCards[viewId]:onOutCard(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-xzddRoomView - addCallBack(runOnOutCardSuccess)")
- self:addCallBack(runOnOutCardSuccess)
- end
-
- function xzddRoomView: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
- ]]
- local player = app.room.roomInfo.memberList[data.response.nUserId]
- local isBao = (player.isBaoPai and player.isBaoPai == 1)
- --如果是托管状态需要删除一次手牌 或者 托管状态
- if (isBao or 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 xzddRoomView:onSendGuo()
- --发牌重置,主要用于贴鬼碰/杠
- MJDefine.isSendGuo = false
- self.operates = {}
- end
-
- -- 操作成功
- function xzddRoomView: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 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)
- 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 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.operates={}
- --碰等操作后检查定缺牌
- self.playerHandCards[MJDefine.MyViewId]:checkQueAndDisableOtherCard()
- 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 xzddRoomView: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 xzddRoomView: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 xzddRoomView:onGameReconnection()
- xzddRoomView.super.onGameReconnection(self)
- local roomInfo = app.room.roomInfo
- local gameInfo=json.decode(roomInfo.strGameInfo)
- local piaoMode = gameInfo.piaomode
-
- local myUserId = app.room:getMyUserId()
- local isMyGetCard = false
- local meIsHu = false
-
-
-
-
- for k,v in pairs(roomInfo.memberList) do
- local viewId = app.room:getViewIdByUserId(k)
-
- local extInfo = roomInfo.extJson or ""
- if type(extInfo)=='table' and extInfo[tostring(v.nUserId)] then
- local info = extInfo[tostring(v.nUserId)]
- local host = info.hosted or 0--托管状态
- local isTuoGuan = host == 1;
- self.playerView:showTuoGuanByViewId(viewId,isTuoGuan)
- end
- end
-
- if gameStatus and gameStatus >= MJDefine.GameStatus.GAME_STATUS_WAIT_BANKER_START and gameStatus < MJDefine.GameStatus.GAME_STATUS_GAME_OVER then
- -- 游戏开始后才显示托管状态
- self.toolView:showTuoGuan(app.room.roomInfo.hosting == 1)
- end
-
- if (roomInfo.nStatus==MJDefine.GameStatus.GAME_STATUS_ROUND_OVER or roomInfo.nStatus==MJDefine.GameStatus.GAME_STATUS_GAME_OVER) and
- roomInfo.memberList[myUserId].nPlayerFlag ~= 1 then
-
- --显示哪些玩家胡牌
- for i,player in pairs(roomInfo.memberList) do
- local viewId = app.room:getViewIdByUserId(player.nUserId)
- local effect
- if player.result>0 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 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
- 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})
- self:createSwapCards(viewId)
- 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.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);
- --end
- end
-
- for k,v in pairs(roomInfo.memberList) do
- local viewId = app.room:getViewIdByUserId(v.nUserId)
- --可以爆牌玩家显示爆牌
- if v.canBaoPai and v.canBaoPai == 1 and v.nUserId == myUserId then
- self:showBaoJiao()
- end
-
- self.playerView:showQue(v.nQue,viewId,true)
- self.playerHandCards[viewId]:setQueType(v.nQue)
- if viewId == MJDefine.MyViewId then
- if roomInfo.operates and table.nums(roomInfo.operates)>0 then
- self.operates = roomInfo.operates
- else
- self.operates = {}
- end
- local handcardNum = #v.handCards
- if handcardNum%3 == 2 then
- isMyGetCard = true
- end
- end
-
- self.playerHandCards[viewId]:resetHandCards()
- -- if roomInfo.outCardUserId == v.nUserId then
- -- if v.nUserId == myUserId and roomInfo.lastOpCard~=0 and roomInfo.isNeedOutCard > 0 then
-
- --设置可以出牌(如果是胡的状态重启,needOutCard会发0,所以多添加一个当前需要出牌玩家是否是自己的判断)
- if roomInfo.needOutCard == 1 or (roomInfo.outCardUserId == myUserId and self.playerHandCards[viewId]:getHandCardsNum() % 3 == 2) then
- if roomInfo.lastOpCard ~= 0 then
- self.playerHandCards[viewId]:removeHandCard(roomInfo.lastOpCard)
- self.playerHandCards[viewId]:resetHandCards()
- self.playerHandCards[viewId]:createHandCards(roomInfo.lastOpCard)
- end
-
- if roomInfo.isNeedOutCard > 0 then
- self.playerHandCards[viewId]:setOutCardEnable(true)
- end
- end
-
- --已爆牌玩家不能出牌
- if v.isBaoPai and v.isBaoPai ~= 0 then
- if v.isBaoPai == 1 then-- 报叫
- self.playerView:playBaoAnim(viewId)
- end
- if v.nUserId == myUserId then --自己爆牌
- self.playerHandCards[viewId]:setBaoPai(1)
- 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
- 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 self.playerHandCards[MJDefine.MyViewId] then
- self.playerHandCards[MJDefine.MyViewId]:showOperate(roomInfo.operates,roomInfo.lastOpCard,isMyGetCard);
- if table.nums(roomInfo.operates) > 0 and isMyGetCard then
- self.playerHandCards[MJDefine.MyViewId]:setOutCardEnable(true)
- 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.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.nStatus<MJDefine.GameStatus.GAME_STATUS_WAIT_BANKER_START then
- if roomInfo.bUserFastStartGame then
- if roomInfo.bUserFastStartGame == 1 then
- --[[local tmpInfo = {}
- for uid,status in pairs(roomInfo.pList) do
- table.insert(tmpInfo, {nUserId=tonumber(uid), nStatus = status})
- end--]]
- local response = {}
- response.pList = roomInfo.pList
- response.timeOut = roomInfo.leftFastStartGameTime
- self:onBroadcastFaststart({response=response})
- end
- else
- if self._fastRequestView then
- self._fastRequestView:removeSelf()
- self._fastRequestView = nil
- end
- end
- end
- end
- end
-
- function xzddRoomView:getChangeGruopDatas(g)
- local opType=g.opType
- local showType=MJDefine.MJOperateToGroupType[g.opType]
- local opCard=g.opCard
- local redNum = g.redNum
-
- local fromViewId = nil
- local targetSeatId = g.targetSeatId--操作位置座位号
- local fromUserId = g.opUserId or g.fromUserId or 0 --触发操作玩家
- local fromViewId1 = app.room:getViewIdByUserId(fromUserId)
- if fromUserId<=0 or not targetSeatId then
- else
- fromViewId = app.room:transPos( targetSeatId, app.room:getSeatIdByUserId(fromUserId))
- --判断是否是对面玩家,对面玩家的话要做一次翻转
- local opViewId = app.room:getViewIdBySeatId(targetSeatId)
- if opViewId == 2 then --对面
- if fromViewId==1 then fromViewId = 3
- elseif fromViewId==3 then fromViewId = 1 end
- end
- --三人玩只有上下家
- if app.room:getMaxPlayerCount()==3 and fromViewId==2 then fromViewId = 3 end
- if app.room:getMaxPlayerCount()==2 and fromViewId~=0 then
- if showType == MJDefine.MJGroupType.Peng then
- fromViewId = 2
- else
- fromViewId = 4
- end
- end
- end
- --组合一下牌
- local group={
- opType=opType,
- showType=showType,
- values={},
- opCard = opCard,
- redNum = redNum,
- fromViewId = fromViewId,
- fromViewId1 = fromViewId1,--真正的来源viewID
- }
- if MJDefine.MJGroupType.Chi==showType then
-
- elseif MJDefine.MJGroupType.Peng==showType then
- group.values={opCard,opCard,opCard}
- else
- group.values={opCard,opCard,opCard,opCard}
- end
-
- return group
- end
-
- -- 小局结算
- function xzddRoomView:onGameXiaoJuResponse(data)
- local function runGameXiaoJuResponse(onEnd)
- if not tolua.isnull(self.firstTingTipsView) then
- self.firstTingTipsView:killSelf()
- self.firstTingTipsView = nil
- end
- -- 取消操作按钮
- if self.playerHandCards and self.playerHandCards[MJDefine.MyViewId] then
- self.playerHandCards[MJDefine.MyViewId]:hideOperate()
- end
-
- local roomInfo = app.room.roomInfo
- self.direcionView:stopAllActions()
- self.operates = {}
- self:setTingCardViewVisible(false)
- app.room:resetTings()
- app.room:cleanTingStatus()
- --如果是解散直接return
- --[[if roomInfo.stopFlag==MJDefine.StopFlag.STOP_FLAG_LONG_NOT_END or roomInfo.stopFlag==MJDefine.StopFlag.STOP_FLAG_DISBAND_GAME then
- if onEnd then
- onEnd()
- end
- return
- end --]]
-
- --所有胡牌的人 考虑抢杠胡的问题
- local viewIds={}
- local failViewId=0
- for k,v in pairs(roomInfo.memberList) do
- local viewId = app.room:getViewIdByUserId(v.nUserId)
- if v.result>0 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.huCard and v.huCard ~= 0 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 xzddRoomView: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 xzddRoomView:setTingCardViewVisible(bVisible,tingCards)
-
- log("setTingCardViewVisible :"..table.tostring(tingCards))
- self.ui.Items.Layout_Ting_Tip_Card_Panel:setVisible(bVisible)
- -- self.ui.Items.ListView_Ting:removeAllItems()
- -- self.ui.Items.ListView_Ting:getHBar():setVisible(false)
- self.ui.Items.ListView_Ting:removeAllChildren()
- -- self.ui.Items.Item_Ting:setVisible(false)
- -- self.toolView:setVisible(false)
- if (not tingCards) or (type(tingCards) == 'table' and #tingCards==0) or (not bVisible) then
- self.ui.Items.Layout_Ting_Tip_Card_Panel:setVisible(false)
- return
- end
-
- local count = #tingCards
- local row = math.ceil(count/5) --几行
-
- self.ui.Items.ListView_Ting:setSize(cc.size(670,80*row))
-
- self.ui.Items.Layout_Ting_Tip_Card_Panel:setSize(cc.size(row>1 and 786 or count*134+116,80*row+40))
-
- self.ui.Items.ImageView_Ting:setPositionY(self.ui.Items.Layout_Ting_Tip_Card_Panel:getContentSize().height-60)
- for k,v in pairs(tingCards) do
- local item = self.ui.Items.Item_Ting:getCopied()
- item:setVisible(true)
- local items = getUIItems(item)
- items.Text_Num:setString(v.count.."张")
- items.Text_Fan:setString(v.fanshu.."番")
- local mj=MJ:new(v.card,MJDefine.MJType.Stand,MJDefine.MyViewId,self.desktopType)
- mj:setPosition(cc.p(20,30))
- mj:setScale(0.5)
- items.Node:addChild(mj)
- self.ui.Items.ListView_Ting:addChild(item)
- end
-
- self.ui.Items.ListView_Ting:requestDoLayout()
- self.ui.Items.ListView_Ting:doLayout()
-
- end
-
- --显示查听的牌
- function xzddRoomView:setChaTingCardViewVisible(bVisible,tingCards)
- end
-
- function xzddRoomView:onTingCardStatus()
- local myUserId=app.user.loginInfo.uid
- local memberList=app.room.roomInfo.memberList
- if memberList[myUserId] then
- local nTingStatus=memberList[myUserId].nTingStatus
- if nTingStatus == MJDefine.MJTingStatus.Ting then
- print("---------onTingCardStatus-----------1 "..myUserId)
- self.ui.Items.Button_Ting_Info:setVisible(true);
- else
- print("---------onTingCardStatus-----------0 "..myUserId)
- -- self:setChaTingCardViewVisible(false)
- self:setTingCardViewVisible(false)
- self.ui.Items.Button_Ting_Info:setVisible(false);
- end
- end
- end
-
- function xzddRoomView: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:setTingCardViewVisible(false, data.response.tingCards)
- else
- self:setTingCardViewVisible(true, data.response.tingCards)
- end
- end
- end
-
- function xzddRoomView:showTing(evet)
- local roomInfo=app.room.roomInfo
- 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) and (not self._isOutCardTingCheck) then--游戏中,不是摸牌阶段
- self._isOutCardTingCheck = true;
- self.ui:sendMsg(app.room,MJDefine.MJEvent.Ting)
- end
- end
- end
-
- function xzddRoomView: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 xzddRoomView: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
-
- --放炮动画
- effect=MJAnimationCompnent.CreateDianPaoEffect()
- 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.playerHandCards[viewId]:setTing(false)
- self.playerHandCards[viewId]:lockHandCard(true);
- 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 xzddRoomView: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 xzddRoomView:onQiangDuanOperates(data)
- local function runOnQiangDuanOperates(onEnd)
- logD("xzddRoomView: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("xzddRoomView:onQiangDuanOperates")
- self:addCallBack(runOnQiangDuanOperates)
- end
-
- --游戏消息
- function xzddRoomView: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.HostingRequest, handler(self, self.onHostingRequest))
- end
-
- function xzddRoomView: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 xzddRoomView: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 xzddRoomView:onGameStartResponse()
- xzddRoomView.super.onGameStartResponse(self)
- self._gameoverview = nil
- end
-
- -- 大局结算
- function xzddRoomView: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 xzddRoomView: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
- self:showGameOverAward()
- end
-
- function xzddRoomView: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 xzddRoomView:resetGame()
- xzddRoomView.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
- end
-
- --显示换三张
- function xzddRoomView:showSwapCard(isOpered)--是否已经操作过
- self:stopDirection()
- local roomInfo=app.room.roomInfo
- local gameInfo=json.decode(roomInfo.strGameInfo)
-
- if not gameInfo.swapcard or tonumber(gameInfo.swapcard)==0 then
- return
- end
- isOpered = isOpered or false
-
- self:hideSwapCard()
- local ui=loadUI("mj_xzdd/res/ui_fangjian/mj_xzdd_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
-
- for k, v in pairs(app.room.roomInfo.memberList) do
- local viewId = app.room:getViewIdByUserId(v.nUserId)
- if self.playerHandCards[viewId] and v.isSwapCard == 1 then
- self:createSwapCards(viewId)
-
- 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 xzddRoomView:hideSwapCard()
- if self.swapCard then
- self.swapCard:removeFromParent()
- self.swapCard=nil
- end
- end
-
- --换三张,服务器会通过0x8122通知换牌
- function xzddRoomView:onNoticeSwapCardResponse(response)
- local function runNoticeSwapCard(onEnd)
- logD("xzddRoomView:onNoticeSwapCardResponse")
- local data = response.response
- self:showSwapCard(true)
- --弹出推荐牌
- self.playerHandCards[MJDefine.MyViewId]:resetHandCards()
- self.playerHandCards[MJDefine.MyViewId]:initSwapCardTouchEvent()
- self.playerHandCards[MJDefine.MyViewId]:selectCardsByCards(data.swapCards)
- self.swapCard.Items.Button_sure:setEnabled(true)
-
- if onEnd then
- onEnd()
- end
- end
- logD("xzddRoomView:runNoticeSwapCard")
- self:addCallBack(runNoticeSwapCard)
- end
- --换三张失败
- function xzddRoomView:onChangeCardFail(response)
- local function runChangeCardFail(onEnd)
- logD("xzddRoomView:onChangeCardFail")
- self:showSwapCard(true)
- self.playerHandCards[MJDefine.MyViewId]:resetHandCards()
- self.swapCard.Items.Button_sure:setEnabled(false)
-
- if onEnd then
- onEnd()
- end
- end
- logD("xzddRoomView:runChangeCardFail")
- self:addCallBack(runChangeCardFail)
- end
- --换三张成功
- function xzddRoomView:onChangeCardSucc(response)
- local function runChangeCardSucc(onEnd)
- logD("xzddRoomView: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()
-
- self.playerHandCards[viewId]:removeHandCard(data.selectCards)
- self.playerHandCards[viewId]:resetHandCards()
- else
- self:setSwapCardSucc(true,viewId)
- local tmpCards = {}
- for i=1, self:getSwapCardCount() do
- table.insert(tmpCards,{card = 0})
- end
- self.playerHandCards[viewId]:removeHandCard(tmpCards)
- self.playerHandCards[viewId]:resetHandCards()
- end
- -- self.playerHandCards[viewId]:createSwapCards({0,0,0})
- self:createSwapCards(viewId)
-
- if onEnd then
- onEnd()
- end
- end
- logD("xzddRoomView:runChangeCardSucc--------")
- self:addCallBack(runChangeCardSucc)
- end
- --换三张成功后的信息
- function xzddRoomView:onChangeCardInfo(response)
- local function runChangeCardInfo(onEnd)
- logD("xzddRoomView: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("xzddRoomView:runChangeCardInfo--------")
- self:addCallBack(runChangeCardInfo)
- end
- --设置换牌成功 isSwaped:true显示有勾的,false显示换牌中
- function xzddRoomView: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 xzddRoomView:showSwapDirection(dir)
- if not dir then return end
- self:hideSwapDirection()
- local ui=loadUI("mj_xzdd/res/ui_fangjian/mj_xzdd_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(2.0),cc.CallFunc:create(function()
- self:hideSwapDirection()
- end)))
- end
-
- function xzddRoomView:hideSwapDirection()
- if self.swapDirection then
- self.swapDirection:removeFromParent()
- self.swapDirection = nil
- end
- end
-
- -- 创建交换牌(如果没有_cards数据,默认为牌背)
- function xzddRoomView:createSwapCards(viewId, _cards, _isReplay)
- local count = self:getSwapCardCount() -- 牌的数量
- local cards = {}
-
- local isBlack = false
- if not _cards then
- isBlack = true
- for i = 1, count do
- table.insert(cards, 0)
- end
- else
- for i, v in ipairs(_cards) do
- table.insert(cards, tonumber(v))
- end
- end
-
- -- 默认起点坐标
- local winSize = getWinSize()
- local temp = {
- [1] = cc.p(winSize.width-300, winSize.height/2 + 50),
- [2] = cc.p(winSize.width/2, winSize.height-150),
- [3] = cc.p(300, winSize.height/2 + 50),
- [4] = cc.p(winSize.width/2, 200),
- }
-
- local node = cc.Node:create()
- self.swapCard.Items.Layout_Swap_MJ:addChild(node)
-
- -- 间距
- local offSetTemp_3d = {
- [1] = cc.p(5, -6),
- [2] = cc.p(-9, 0),
- [3] = cc.p(-5, -6),
- [4] = cc.p(-9, 0),
- }
-
- -- 回放间距(不知道为什么使用同样的代码,正常流程和回放的位置会不同。可能是牌背与有数据的那面大小对不上)
- if _isReplay then
- offSetTemp_3d = {
- [1] = cc.p(5, -12),
- [2] = cc.p(-14, 0),
- [3] = cc.p(-4, -6),
- [4] = cc.p(-14, 0),
- }
- end
-
- local offset_X = 0
- local offset_Y = 0
- if self.desktopType == MJDefine.DesktopType.ThreeD then
- offset_X = offSetTemp_3d[viewId].x
- offset_Y = offSetTemp_3d[viewId].y
- end
-
- -- 牌的idx值
- local idx = 9
- -- if viewId == MJDefine.MyViewId then
- -- idx = 9
- -- end
-
- for i, v in ipairs(cards) do
- local cardNode = self.playerHandCards[viewId]:createSwapCards(v, idx)
- node:addChild(cardNode)
-
- if isBlack and (type(cardNode.setOutBackImage) == 'function') then
- cardNode:setOutBackImage()
- end
-
- local pos = clone(temp[viewId])
- if viewId % 2 == 0 then -- 上下玩家
- pos.x = pos.x + ((i - #cards/2) * 2 - 1) * (cardNode:getContentSize().width/2 + offset_X)
- else
- if self.desktopType == MJDefine.DesktopType.ThreeD then
- offset_X = offSetTemp_3d[viewId].x * (i) -- 注意这个,若是3d情况下,则配置的x是要与i相乘,而不是固定值(因为左右两家是有斜的)
- end
-
- pos.x = pos.x + offset_X
- pos.y = pos.y - ((i - #cards/2) * 2 - 1) * (cardNode:getContentSize().height/2 - 8 + offset_Y)
- end
- cardNode:setPosition(pos)
-
- idx = idx + 1
- end
- end
-
- -- 换牌张数
- function xzddRoomView:getSwapCardCount()
- return 3
- end
-
- --显示定缺界面
- function xzddRoomView:showDingQue(tp)
- --self:hideSwapDirection()
- self:hideSwapCard()
- self:hideDingQue()
- local ui=loadUI("mj_xzdd/res/ui_fangjian/mj_xzdd_dingque.ui")
- self.ui.Items.Layout_Effect: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 xzddRoomView:hideDingQue()
- if tolua.isnull(self.dingque) then
- return
- end
- self.dingque:removeFromParent()
- self.dingque=nil
- end
- --显示定缺界面操作按钮特效
- function xzddRoomView: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 xzddRoomView: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 xzddRoomView: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 xzddRoomView: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
- end
-
- function xzddRoomView:onChangeChatEnable()
- if not self.messageView or tolua.isnull(self.messageView) then
- return
- end
- local voiceEnable = tonumber(loadUserInfo("xzddPingBiYuYinKG")) or 1
- local propEnable = tonumber(loadUserInfo("xzddHuDongBiaoQingKG")) or 1
- self.messageView:setVoiceEnabled(voiceEnable==1)
- self.messageView:setPropEnabled(propEnable==1)
- end
-
- function xzddRoomView:onEventChangeViewType(data)
- self:changeGameBg(true)
-
- MJDefine.MJConfig = MJDefine.loadMJConfig(self.desktopType)
-
- self.ui:sendMsg(app.room, MJDefine.MJEvent.GetTableInfo);
- end
-
-
- --服务器通知定缺
- function xzddRoomView:onNoticeDingQueResponse(response)
- local function runNoticeDingQue(onEnd)
- logD("xzddRoomView: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("xzddRoomView:runNoticeDingQue")
- self:addCallBack(runNoticeDingQue)
- end
- --当玩家操作成功后,通过0x8131广播定缺成功
- function xzddRoomView:onDingQueSuccResponse(response)
- local function runDingQueSucc(onEnd)
- logD("xzddRoomView: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("xzddRoomView:runDingQueSucc")
- self:addCallBack(runDingQueSucc)
- end
- --当所有玩家定缺成功后,服务器会通过广播告诉玩家定缺类型
- function xzddRoomView:onDingQueSuccInfoResponse(response)
- local function runDingQueSuccInfo(onEnd)
- logD("xzddRoomView: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("xzddRoomView:runDingQueSuccInfo")
- self:addCallBack(runDingQueSuccInfo)
- end
-
- function xzddRoomView:onCheckIsInSwapRule(data)
- if not data then return end
- if not self.swapCard then return end
- self.swapCard.Items.Button_sure:setEnabled(data.canCommit)
- end
- ---
- -- 托管通知
- -- @param data
- -- @return
- --
- function xzddRoomView:onHostingRequest( data )
- local response = data.response
- if response.nUserId == app.user.loginInfo.uid then
- if response.status == 1 then --托管状态
- self.toolView:showTuoGuan(true)
- -- self:hideSwapDirection()
- -- self:hideSwapCard()
- -- self:hideDingQue()
- 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)
- if isTuoGuan then
- self:hideBaoJiao()
- end
- end
-
- function xzddRoomView:showBaoJiao()
- self:hideBaoJiao()
- local ui=loadUI("mj_xzdd/res/ui_fangjian/mj_xzdd_baojiao.ui")
- self:addChild(ui)
- self.baojiao=ui
-
- ui.Items.Button_bozimo:registerClick(function()
- playBtnEffect()
- self:hideBaoJiao()
- local request = MJMessage.BaoPaiRequest:new()
- request.isBaoPai = 2
- logD(request.isBaoPai,"发送爆:2")
- self.ui:sendMsg(app.room, MJDefine.MJEvent.BaoPaiRequest, request)
- end)
-
- 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
- --[[if gameInfo.specrule then
- local bozimo = getNumBand(gameInfo.specrule, 0x0002) > 0
- ui.Items.Button_bozimo:setVisible(bozimo);
- end--]]
- ui.Items.Button_bozimo:setVisible(false);
- ui.Items.Layout_baojiao:requestDoLayout()
- ui.Items.Layout_baojiao:doLayout();
- end
-
- function xzddRoomView:hideBaoJiao()
- if self.baojiao then
- self.baojiao:removeFromParent()
- self.baojiao=nil
- end
- end
-
- --操作错误
- function xzddRoomView:onOperationError(data)
- local function runOnOperationError(onEnd)
- log("2000000000-MJRoomView - (runOnOperationError)")
-
-
- if onEnd then
- onEnd()
- end
- self.ui:sendMsg(app.room, MJDefine.MJEvent.GetTableInfo);
- end
- log("2000000000-MJRoomView - addCallBack(runOnOperationError)")
-
- self:addCallBack(runOnOperationError)
- end
-
- function xzddRoomView:onWaitOperate(data)
- --xzddRoomView.super.onWaitOperate(data)
- end
-
- return xzddRoomView
|