|
- 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 zigongRoomView = class("zigongRoomView", MJRoomView)
-
- local zhongNiaoTime=1.33
- local HU_EFFECT_TAG = 100
-
- function zigongRoomView:ctor()
- zigongRoomView.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_zg_desktop_2d_mjType")
- if value=="" or not value then
- value = MJDefine.DesktopType.TwoD
- saveUserInfo("mj_zg_desktop_2d_mjType", value)
- end
- self.desktopType = value
- else
- self.desktopType = app.systemSetting.info.viewType
- end
- MJDefine.MJConfig = MJDefine.loadMJConfig(self.desktopType)
- end
-
- function zigongRoomView:loadUi()
- local ui = loadUI("mj_zigong/res/ui_fangjian/mj_zigong_roomView.ui")
- self.ui = ui
- self:addChild(ui)
- end
-
- function zigongRoomView:onEnter()
- zigongRoomView.super.onEnter(self)
-
- --获取是否贴鬼杠和是否自动对齐
- self:setCheckDefault()
- self:doSound()
- end
-
- function zigongRoomView:initView ()
- zigongRoomView.super.initView(self);
-
- self:initRuleView();
- end
- ---
- -- 初始化规则弹框
- -- @return
- --
- function zigongRoomView:initRuleView ()
- if self._ruleView then
- -- 已经创建过了
- return ;
- end
-
- local RuleViewClass = require("mj.luaScript.Views.Room.MJRuleViewVertical");
- local ruleView = RuleViewClass:new();
- self:addChild(ruleView);
-
- local roomInfo = app.room.roomInfo or {};
- local ruleList = MJWanFa.getWanFaInfoTab(roomInfo.strGameInfo, roomInfo.nTotalGameNum)
- ruleView:setRuleList(ruleList or {});
- ruleView:setBtnRuleOffset(60, nil);
-
- self._ruleView = ruleView;
- end
-
- function zigongRoomView:onExit()
- zigongRoomView.super.onExit(self)
- self:cleanCache()
- end
-
- function zigongRoomView: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_zigong.luaScript") or 0
- if res1 > 0 or res2 > 0 then
- package.loaded[k] = nil
- end
- end
- end
-
- function zigongRoomView:doSound()--1 普通话 2 方言
- local cacheLan = "mj_language"..(MJDefine.GameID or app.gameId)
- local defaultValue = tonumber(loadUserInfo(cacheLan)) or 2
- saveUserInfo(cacheLan,defaultValue)
- MJSound.setSoundType(defaultValue)
- end
-
- function zigongRoomView:setCheckDefault()
- MJDefine.isAutomatic = true
- end
-
-
- -- 一键截屏
- function zigongRoomView:onClickButtonShot( sender )
- playBtnEffect()
- showScreenShot()
- end
-
- --隐藏俱乐部
- function zigongRoomView: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 zigongRoomView:changeGameBg(isUpdateViewType)
- if isUpdateViewType then
- if app.systemSetting.info.viewType == MJDefine.DesktopType.TwoD then --更新2D麻将类型 金色还是绿色
- local value = loadUserInfo("mj_zg_desktop_2d_mjType") --or MJDefine.DesktopType.TwoD
- if value=="" or not value then
- value = MJDefine.DesktopType.TwoD
- saveUserInfo("mj_zg_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("zigong_mj_desktop_group")) or 2
- local bgData = MJDefine.CHANGE_GAME_BG[defaultValue]
- if self.desktopType==MJDefine.DesktopType.TwoD or self.desktopType==MJDefine.DesktopType.TwoDGold then
- self.ui.Items.ImageView_bg:loadTexture(bgData['2d'])
- else
- self.ui.Items.ImageView_bg:loadTexture(bgData['3d'])
- end
- end
-
- function zigongRoomView: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 zigongRoomView:loadTextureCache()
- zigongRoomView.super.loadTextureCache(self)
- -- local defaultValue = tonumber(loadUserInfo("luzhou_mj_majhong")) or 1
-
- loadSpriteFrameFile("mj_zigong/res/zy_fangjian/zigong_operateEffect.plist")
- loadSpriteFrameFile("mj_zigong/res/zy_fangjian/effect_guangxiao.plist")
- loadSpriteFrameFile("mj_zigong/res/zy_fangjian/effect_guafeng.plist")
- loadSpriteFrameFile("mj_zigong/res/zy_fangjian/effect_xiayu.plist")
-
- end
-
-
- function zigongRoomView: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 zigongRoomView: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 zigongRoomView: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]: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()
- if (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
- end
-
- function zigongRoomView:onGameSendCardResponse()
- --发牌的时候清除桌面上的飘
- self.ui.Items.Layout_Effect_luobo:removeAllChildren()
- local function runGameSendCardResponse(onEnd)
- log("2000000000-zigongRoomView - runGameSendCardResponse()" )
- --走过重连标志值为false
- self.isRunGameReconnection = false
-
- 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
-
- -- local effect=MJAnimationCompnent.CreateGameStart()
- -- self.ui.Items.Layout_Player:addChild(effect,5)
- -- MJSound.PlayStartGame()
-
- MJAnimationCompnent.CreateStartSendCards(self.playerHandCards,onEnd)
-
- -- if onEnd then
- -- onEnd()
- -- end
- self.toolView:showTuoGuan(app.room.roomInfo.hosting==1)
- end
- log("2000000000-zigongRoomView - addCallBack(runGameSendCardResponse)" )
- self:addCallBack(runGameSendCardResponse);
- end
-
- function zigongRoomView:onUserReadyResponse(response)
- zigongRoomView.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()
- 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 zigongRoomView: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("zigongRoomView 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]: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]: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})
-
- local curHandCards = self.playerHandCards[viewId]:getHandCardsNum()
- if curHandCards%3 ~= 2 then--抓了牌之后,手牌不正确,主动重连一下
- app.room.roomInfo.requestGetTableInfo = true
- self.ui:sendMsg(app.room, MJDefine.MJEvent.GetTableInfo);
- end
- 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-zigongRoomView - addCallBack(runOnBankerOutCard)")
- self:addCallBack(runOnBankerOutCard);
-
- end
-
- function zigongRoomView: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 zigongRoomView:onOutCardSuccess(data)
- logE("zigongRoomView:onOutCardSuccess(), response = ", table.tostring(data.response))
- local function runOnOutCardSuccess(onEnd)
- log("2000000000-zigongRoomView - 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)
- 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]
- self.playerHandCards[viewId]:setTing(false)
- local curHandCards = self.playerHandCards[viewId]:getHandCardsNum() or 0
- if ((player.isBaoPai==1 or player.isBaoPai==2) and app.room.roomInfo.lastOutViewId~=MJDefine.MyViewId) or app.room.roomInfo.hosting == 1 then --点击爆牌的时候 前端已经打出牌 要判断上次出牌的人是不是自己 避免重复出牌
- self.playerHandCards[viewId]:onOutCard(card,callback)
- --音效
- local userInfo=app.room:getUserInfoByViewId(viewId)
- if userInfo then
- MJSound.PlayMJSound(userInfo.sex,card)
- end
- elseif self.needDeleteOutCard and true == self.needDeleteOutCard then
- self.needDeleteOutCard = nil
- uploadLogs("mjduopai")
- self.playerHandCards[viewId]:onOutCard(card,callback)
- elseif self.isRunGameReconnection and true ==self.isRunGameReconnection and curHandCards%3 == 2 then--重连后,手牌是可以出牌的,则删除一张牌
- self.playerHandCards[viewId]:onOutCard(card,callback)
- else
- callback()
- end
- self.isRunGameReconnection = false
-
- 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-zigongRoomView - addCallBack(runOnOutCardSuccess)")
- self:addCallBack(runOnOutCardSuccess)
- end
-
- --已经发送了过操作,此时就算再勾选贴鬼碰,也不会显示操作
- function zigongRoomView:onSendGuo()
- --发牌重置,主要用于贴鬼碰/杠
- MJDefine.isSendGuo = false
- self.operates = {}
- end
-
- -- 操作成功
- function zigongRoomView: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 = 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={}
- 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 zigongRoomView: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 zigongRoomView: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 zigongRoomView:onGameReconnection()
- zigongRoomView.super.onGameReconnection(self)
- self.isRunGameReconnection = true
- local roomInfo = app.room.roomInfo
- local gameInfo=json.decode(roomInfo.strGameInfo)
- local piaoMode = gameInfo.piaomode
- -- 显示玩家头像上的托管标识
- for k,v in pairs(roomInfo.memberList) do
- local viewId = app.room:getViewIdByUserId(v.nUserId)
- local extInfo = roomInfo.extJson or ""
- if extInfo and 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
-
- local myUserId = app.room:getMyUserId()
- local isMyGetCard = false
-
- if roomInfo.nStatus and roomInfo.nStatus>=MJDefine.GameStatus.GAME_STATUS_WAIT_BANKER_START and roomInfo.nStatus<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)
- --已爆牌玩家
- if player.isBaoPai ~= 0 then
- --self.playerView:playBaoAnim(viewId)
- end
- local effect
- if player.result>0 and self.playerHandCards[viewId] then
- effect = MJAnimationCompnent.CreateHuOrderEffect(player.result,player.huOrder)
- if myUserId == player.nUserId then
- self.playerHandCards[viewId]:createHandCards(player.huCard)
- self.playerHandCards[viewId]:moveLastCard()
- else
- 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
-
- --[[local luoboCards = roomInfo.luoboCards
- if luoboCards and #luoboCards>0 then
- local luoNum = #luoboCards
- for i,v in pairs(luoboCards) do
- local mj=MJ:new(v,MJDefine.MJType.Out,MJDefine.MyViewId,self.desktopType)
- if MJDefine.LuoBoPos[luoNum] and MJDefine.LuoBoPos[luoNum][i] then
- mj:setPosition(MJDefine.LuoBoPos[luoNum][i])
- mj:setPositionY(mj:getPositionY()+25)
- self.ui.Items.Layout_Effect:addChild(mj)
- local mjSize = mj:getContentSize()
- local sprite = cc.Sprite:createWithSpriteFrameName("zg_room_luoboyezi.png")
- sprite:setScale(0.6)
- sprite:setPosition(cc.p(mjSize.width/2,mjSize.height+14))
- mj:addChild(sprite,-1)
- mj:setScale(1.5)
- end
- 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) == 1)
- else
- if piaoMode == 1 then--可以飘 还没有飘 显示飘按钮
- self:showPiao()
- end
- end
- else
- self.playerView:showPiao(viewId,tonumber(player.isPiao) == 1)
- end
- if tonumber(player.isPiao) == 1 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.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 == 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)
- elseif v.isBaoPai == 2 then-- 博自摸
- self.playerView:showBoZiMo(viewId,true)
- 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
- --if roomInfo.outCardUserId == myUserId and table.nums(roomInfo.operates)>0 then
- -- self.playerHandCards[viewId]:onGetCard(roomInfo.operates)
- --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
- local handcardNum = #v.handCards
- if handcardNum%3 == 2 then
- isMyGetCard = true
- end
- if app.room.roomInfo.requestGetTableInfo and app.room.roomInfo.requestGetTableInfo == true then
- --如果是主动请求的重连,什么都不干
- app.room.roomInfo.requestGetTableInfo = nil
- else
- if isMyGetCard and isMyGetCard == true then
- showTooltip("重连成功,现在轮到您出牌了,注意看牌哦!!!")
- end
- end
- end
- if roomInfo.outCardUserId == v.nUserId then
- if v.nUserId == myUserId and roomInfo.lastOpCard~=0 and roomInfo.isNeedOutCard > 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
- --需要出牌且听牌状态为1时,需要请求服务器推送听牌数据
- --[[if roomInfo.isNeedOutCard==MJDefine.NeedOutCard.Need and v.nUserId == myUserId then
- if roomInfo.tingStatus == MJDefine.MJTingStatus.Ting then
- self.ui:sendMsg(app.room,MJDefine.MJEvent.Ting)
- end
- end--]]
- --显示飘状态
- self.playerView:showPiao(viewId,tonumber(v.isPiao) == 1)
- 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
- if viewId == MJDefine.MyViewId then
- self.playerHandCards[viewId]:createHandCards(player.huCard)
- self.playerHandCards[viewId]:moveLastCard()
- 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
- --显示出牌角标(需要服务器修改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});
- --如果有操作显示操作按钮
- if self.playerHandCards[MJDefine.MyViewId] then
- self.playerHandCards[MJDefine.MyViewId]:showOperate(roomInfo.operates,roomInfo.lastOpCard,isMyGetCard);
- 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
- end
-
- function zigongRoomView: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 --触发操作玩家
- 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 zigongRoomView: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 zigongRoomView: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 zigongRoomView: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 then 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 zigongRoomView:setChaTingCardViewVisible(bVisible,tingCards)
- end
-
- function zigongRoomView: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:setChaTingCardViewVisible(true)
- -- self:setTingCardViewVisible(true, )
- --self._isTingStateChanged = true--防止出现听牌提示闪一下的bug
- --self.ui:sendMsg(app.room,MJDefine.MJEvent.Ting)
- 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 zigongRoomView: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 zigongRoomView:showTing(evet)
- local roomInfo=app.room.roomInfo
- -- if evet.card and roomInfo.tings and roomInfo.tings[evet.card] then
- -- self:setTingCardViewVisible(true,roomInfo.tings[evet.card])
- -- else
- -- self:setTingCardViewVisible(false)
- -- 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)
- end
- end
-
- function zigongRoomView: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 zigongRoomView: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.dianganghua == 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.playerHandCards[viewId]:setTing(false)
-
- 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 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 zigongRoomView: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)
- 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 zigongRoomView:onQiangDuanOperates(data)
- local function runOnQiangDuanOperates(onEnd)
- logD("zigongRoomView: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("zigongRoomView:onQiangDuanOperates")
- self:addCallBack(runOnQiangDuanOperates)
- end
-
- --游戏消息
- function zigongRoomView: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 ))
- -- 托管
- self:bindEvent(app.room , MJDefine.MJEvent.HostingRequest, handler(self, self.onHostingRequest))
- end
-
- function zigongRoomView: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 zigongRoomView: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 zigongRoomView:onGameStartResponse()
- zigongRoomView.super.onGameStartResponse(self)
- self._gameoverview = nil
- end
-
- -- 大局结算
- function zigongRoomView: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 zigongRoomView: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 zigongRoomView: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()
-
- if self._fastRequestView then
- self._fastRequestView:removeSelf()
- self._fastRequestView = nil
- end
-
- logE("88888-onOtherLogoutResponse onEnd")
- if onEnd then
- onEnd()
- end
- end
- self:addCallBack(test)
- end
-
-
- function zigongRoomView:resetGame()
- zigongRoomView.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()
- end
-
- function zigongRoomView: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_zigong/res/ui_fangjian/mj_zigong_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)
-
- ui.Items.Button_Piao:registerClick(function()
- playBtnEffect()
- self:hidePiao()
- local request = MJMessage.PiaoRequest:new()
- request.isPiao = 1
- self.ui:sendMsg(app.room,MJDefine.MJEvent.PiaoRequest,request)
- end)
-
- end
-
- function zigongRoomView:hidePiao()
- if self.piao then
- self.piao:removeFromParent()
- self.piao=nil
- end
- end
-
- --显示飘操作按钮
- function zigongRoomView:onStartPiao(response)
- local function runPiao(onEnd)
- logD("zigongRoomView:onStartPiao")
- self:showPiao()
- if onEnd then
- onEnd()
- end
- end
- logD("zigongRoomView:runPiao")
- self:addCallBack(runPiao)
- end
-
- --飘结果
- function zigongRoomView:onPiaoResponse(response)
- local function runonPiaoResponse(onEnd)
- logD("zigongRoomView: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==1)
- if v.piaostate==1 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==1)
- if data.piaostate and data.piaostate == 1 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("zigongRoomView:runonPiaoResponse--------")
- self:addCallBack(runonPiaoResponse)
- end
-
- function zigongRoomView:showBaoJiao()
- self:hideBaoJiao()
- local ui=loadUI("mj_zigong/res/ui_fangjian/mj_zigong_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.Layout_baojiao:requestDoLayout()
- ui.Items.Layout_baojiao:doLayout();
- end
-
- function zigongRoomView:hideBaoJiao()
- if self.baojiao then
- self.baojiao:removeFromParent()
- self.baojiao=nil
- end
- end
-
- function zigongRoomView: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 zigongRoomView:onChangeChatEnable()
- if not self.messageView or tolua.isnull(self.messageView) then
- return
- end
- local voiceEnable = tonumber(loadUserInfo("zigongPingBiYuYinKG")) or 1
- local propEnable = tonumber(loadUserInfo("zigongHuDongBiaoQingKG")) or 1
- self.messageView:setVoiceEnabled(voiceEnable==1)
- self.messageView:setPropEnabled(propEnable==1)
- end
-
- function zigongRoomView:onEventChangeViewType(data)
-
- MJDefine.MJConfig = MJDefine.loadMJConfig()
-
- self:changeGameBg(true)
-
- app.room.roomInfo.requestGetTableInfo = true
- self.ui:sendMsg(app.room, MJDefine.MJEvent.GetTableInfo);
- end
-
- function zigongRoomView:onHostingRequest( data )
- local response = data.response
- if response.nUserId == app.user.loginInfo.uid then
- if response.status == 1 then --托管状态
- self.toolView:showTuoGuan(true)
- 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:hidePiao()
- self:hideBaoJiao()
- end
- end
-
- return zigongRoomView
|