require("luaScript.Views.Room.RoomFunctions") local MJRoomToolView = MJFramework.MJImport("mj.luaScript.Views.Room.MJRoomToolView") local MJRoomPlayerView = MJFramework.MJImport("mj.luaScript.Views.Room.MJRoomPlayerView") local MJDefine = MJFramework.MJImport("mj.luaScript.MJDefine") local MJMessage = MJFramework.MJImport("mj.luaScript.Protocol.MJMessage") local MJFunction = MJFramework.MJImport("mj.luaScript.MJFunction") -- 布局相关 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 MJRoomDirection = MJFramework.MJImport("mj.luaScript.Views.Room.MJRoomDirection") -- 中间方位 local MJAnimationCompnent = MJFramework.MJImport("mj.luaScript.Views.Compnent.MJAnimationCompnent") -- 动画? local MJBenJinView = MJFramework.MJImport("mj.luaScript.Views.Components.MJFanBenJinView") -- 本金动画 local MJPiaoView = MJFramework.MJImport("mj.luaScript.Views.Components.MJPiaoView") -- 飘操作界面 local MJDingQueView = MJFramework.MJImport("mj.luaScript.Views.Components.MJDingQueView") -- 定缺操作界面 local MJDingQueAniView = MJFramework.MJImport("mj.luaScript.Views.Components.MJDingQueAniView") -- 定缺动画界面 local MJSound = MJFramework.MJImport("mj.luaScript.MJSound") local MJRoomView = MJFramework.MJFrameworkClassImprot("mj.luaScript.Views.Room.MJRoomView") local yibinmajiangRoomView = class("yibinmajiangRoomView", MJRoomView) local zhongNiaoTime = 1.33 local HU_EFFECT_TAG = 100 function yibinmajiangRoomView:ctor() yibinmajiangRoomView.super.ctor(self) self.operates = {} self._isReplay = false -- 是否处于回放 MJDefine.MJConfig = MJDefine.loadMJConfig(self.desktopType) end function yibinmajiangRoomView:onEnter() yibinmajiangRoomView.super.onEnter(self) self.ZOrder = {} self:setCheckDefault() self:doSound() end function yibinmajiangRoomView:onExit() yibinmajiangRoomView.super.onExit(self) self:cleanCache() end -- 加载UI function yibinmajiangRoomView:loadUi() local ui = loadUI("mj_yibinmajiang/res/ui_fangjian/mj_yibinmajiang_roomView.ui") self.ui = ui self:addChild(ui) end -- 设置默认值 function yibinmajiangRoomView:setCheckDefault() MJDefine.isAutomatic = true end -- 播放声音(1 普通话 2 方言) function yibinmajiangRoomView:doSound() local bgmType = tonumber(loadUserInfo("yibinmajiang_bgm")) or 1 MJSound.PlayGameBGM(bgmType) local cacheLan = "mj_language"..(MJDefine.GameID or app.gameId) local defaultValue = tonumber(loadUserInfo(cacheLan)) or 2 -- saveUserInfo("mj_language", defaultValue) MJSound.setSoundType(defaultValue) end -- 添加节点至指定层 -- @param layerName 指定层级的名称,background(背景层)、game(游戏层)、anim(动画特效层)、popup(弹框层)、system(系统弹框层) -- @param node 要添加的节点 -- @param zorder 指定的zorder function yibinmajiangRoomView:addToLayer(layerName, node, zorder) if layerName == "background" then layerName = "Layout_Background" elseif layerName == "game" then layerName = "Layout_Game" elseif layerName == "anim" then layerName = "Layout_Anim" elseif layerName == "popup" then layerName = "Layout_PopUp" elseif layerName == "system" then layerName = "Layout_System" end local layer = self.ui.Items[layerName] if not layer then self:addChild(node) return end self.ZOrder = self.ZOrder or {} self.ZOrder[layerName] = self.ZOrder[layerName] or 0 self.ZOrder[layerName] = zorder or (self.ZOrder[layerName] + 1) node:setLocalZOrder(self.ZOrder[layerName]) layer:addChild(node) end -- 清除缓存 function yibinmajiangRoomView: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_yibinmajiang.luaScript") or 0 if res1 > 0 or res2 > 0 then package.loaded[k] = nil end end end -- 初始化试图 function yibinmajiangRoomView:initView() --暂时隐藏牌数 self.ui.Items.ImageView_CardNum:setVisible(false) -- 初始化玩家层 self:initPlayerView(); --加载工具层 self:initToolView() -- 初始化方向 self:initDirectionView() -- 初始化听牌组件 self:initTingCardView() -- 初始化听牌按钮,动态创建的 self:initTingBtnView() --定时器 self.ui.Items.Text_Time:setText(MJFunction.getTimeString()) if not self.Time then self.Time = cc.Director:getInstance():getScheduler():scheduleScriptFunc(function() self.ui.Items.Text_Time:setText(MJFunction.getTimeString()) end,1.0,false) end self.ui.Items.Layout_Ting_Tip_Card_Panel:setVisible(false) end -- 初始化玩家playerView function yibinmajiangRoomView:initPlayerView() if not self.playerView then self.playerView = MJRoomPlayerView:new() self:addToLayer("game", self.playerView, 6); end end -- 初始化手牌playerhandcard function yibinmajiangRoomView:initHandCardNodes() local maxPlayCount = app.room.roomInfo:getMaxPlayerCount(); if MJDefine.MJRoomPlayerSitConfig[maxPlayCount] then for k,v in pairs(MJDefine.MJRoomPlayerSitConfig[maxPlayCount]) do if self.playerHandCards[v] then self.playerHandCards[v]:removeFromParent(); end self.playerHandCards[v] = MJHandCardView:new(v, self.desktopType); self:addToLayer("game", self.playerHandCards[v], v + 1); end end end -- 初始化工具栏toolview function yibinmajiangRoomView:initToolView() if not self.toolView then self.toolView = MJRoomToolView:new(self.desktopType) self:addToLayer("game", self.toolView, 7); end end -- 初始化中间方向指示器direcionView function yibinmajiangRoomView:initDirectionView() if not self.direcionView then self.direcionView = MJRoomDirection:new(self.desktopType) self:addToLayer("background", self.direcionView); self.direcionView:setVisible(false) end end -- 初始化听牌组件_tingCardView function yibinmajiangRoomView:initTingCardView() if not self._tingCardView then self._tingCardView = require("mj_yibinmajiang.luaScript.Views.Components.yibinmajiangTingCardView"):new(); self:addToLayer("game", self._tingCardView, 6); self._tingCardView:setData(nil); self:setTingCardVisible(false); end end -- 初始化听牌按钮 function yibinmajiangRoomView:initTingBtnView() local yibinmajiangTingBtnView = import("mj_yibinmajiang.luaScript.Views.Components.yibinmajiangTingBtnView"); local btnTing = yibinmajiangTingBtnView:new(); btnTing:setCallback(handler(self, self.onBtnTingInfoClicked)); btnTing:setPosition(cc.p(230, 158)); self.btnTing = btnTing; self:addToLayer("game", self.btnTing, 8) end -- 听按钮点击事件 function yibinmajiangRoomView:onBtnTingInfoClicked( ) playBtnEffect() if self._tingCardView:isVisible() then self:setTingCardVisible(false); else self:setTingCardVisible(true); end end -- 更换背景 function yibinmajiangRoomView:changeGameBg() if app.systemSetting.info.viewType == MJDefine.DesktopType.TwoD then --更新2D麻将类型 金色还是绿色 local value = loadUserInfo("mj_desktop_2d_mjType") --or MJDefine.DesktopType.TwoD if value=="" or not value then value = MJDefine.DesktopType.TwoD saveUserInfo("mj_desktop_2d_mjType", value) end self.desktopType = value else self.desktopType = app.systemSetting.info.viewType end self:loadTextureCache() local defaultValue = tonumber(loadUserInfo("yibinmajiang_desktop_background")) or 2 local bgData = MJDefine.CHANGE_GAME_BG[defaultValue] --更换2D桌面 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 --记录当前的桌布类型(2d/3d) self.curDeskType = self.desktopType end -- 一键截屏 function yibinmajiangRoomView:onClickButtonShot( sender ) playBtnEffect() showScreenShot() end -- 隐藏俱乐部 function yibinmajiangRoomView: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 yibinmajiangRoomView: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 yibinmajiangRoomView:loadTextureCache() yibinmajiangRoomView.super.loadTextureCache(self) loadSpriteFrameFile("mj_yibinmajiang/res/zy_fangjian/anim/yibinmajiang_effect_guangxiao.plist") loadSpriteFrameFile("mj_yibinmajiang/res/zy_fangjian/anim/yibinmajiang_effect_guafeng.plist") loadSpriteFrameFile("mj_yibinmajiang/res/zy_fangjian/anim/yibinmajiang_effect_xiayu.plist") end -- 初始化游戏按钮 function yibinmajiangRoomView:initGameButton() --点击空白 self.ui.Items.Layout_Touch:registerClick(nil,function() -- 隐藏个人信息 self.playerView:removePlayerInfoView() self.toolView:setMenuVisible(false) if self.playerHandCards[MJDefine.MyViewId] then self.playerHandCards[MJDefine.MyViewId]:hideOperateItem() end self.toolView:hideRule() self:setTingCardVisible(false) end) --隐藏听牌模板 self.ui.Items.Item_Ting:setVisible(false) self:setButtonTingInfoVisible(false) end -- 中间转盘停止 function yibinmajiangRoomView:stopDirection() self.direcionView:stopAllActions() if self.direcionView.ui then 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)) end end -- 获得组合牌数据 function yibinmajiangRoomView:getChangeGruopDatas(g) local opType = g.opType local showType = MJDefine.MJOperateToGroupType[g.opType] local opCard = g.opCard local cardNum = g.cardNum local fromViewId = nil local targetSeatId = g.targetSeatId--操作位置座位号 local fromUserId = g.opUserId or g.fromUserId --触发操作玩家 local fromViewId1 = app.room:getViewIdByUserId(fromUserId) local useRedNum = g.useRedNum local lziCard = g.lziCard if fromUserId > 0 and targetSeatId then 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 fromViewId = showType == MJDefine.MJGroupType.Peng and 2 or 4; end end --组合一下牌 local group={ opType = opType, showType = showType, values = {}, opCard = opCard, cardNum = cardNum, fromViewId = fromViewId, fromViewId1 = fromViewId1,--真正的来源viewID } if MJDefine.MJGroupType.Chi==showType then elseif MJDefine.MJGroupType.Peng==showType then group.values={opCard,opCard,opCard} elseif MJDefine.MJGroupType.Fei==showType then for i = 1, 3 do if i <= useRedNum then table.insert(group.values, lziCard) else table.insert(group.values, opCard) end end elseif MJDefine.MJGroupType.Ti==showType then group.values={opCard,opCard,opCard} else group.values={opCard,opCard,opCard,opCard} end return group end -- 设置听牌按钮状态 function yibinmajiangRoomView:setButtonTingInfoVisible (isVisible) if self.btnTing then self.btnTing:setVisible(isVisible); end end -- 设置听牌界面是否可见 function yibinmajiangRoomView:setTingCardVisible (isVisible) if not self._tingCardView then return end self._tingCardView:setVisible(isVisible); end -- 设置听箭头 function yibinmajiangRoomView:pushTing() local function runPushTing(onEnd) local myUserId = app.room:getMyUserId(); local player = app.room.roomInfo.memberList[myUserId] local huCards = player.huCards; if self.playerHandCards[MJDefine.MyViewId] then if not (table.nums(huCards) > 0) then -- 已经胡牌,不显示听牌箭头 self.playerHandCards[MJDefine.MyViewId]:pushTing() end end if onEnd then onEnd() end end self:addCallBack(runPushTing); end -- 显示操作分 function yibinmajiangRoomView:showOperateScore( optScore ) if not optScore then return ; end for k, v in ipairs(optScore or {}) do v.viewId = app.room:getViewIdByUserId(v.uid); end self._scoreAnim = MJFramework.MJImport("mj_yibinmajiang.luaScript.Views.Animation.yibinmajiangScoreAnimation"):new(); self._scoreAnim:play(optScore, function () self.playerView:refreshPlayerScore(optScore) end); self:addToLayer("anim", self._scoreAnim); end -- 胡牌动画 function yibinmajiangRoomView:playHuAni(response) -- 不需要播放胡牌顺序 -- 需要可以从自贡麻将同步 end -- 更新准备状态 function yibinmajiangRoomView:updateReady() local roomInfo = app.room.roomInfo; local nUserId = app.room:getMyUserId()--app.user.loginInfo.uid local gameStartCount = roomInfo:getGameStartCount(); if gameStartCount > 0 then self.toolView.ui.Items.Button_Leave:setEnabled(false) self:setBtnSitDownVisible(false) else self.toolView.ui.Items.Button_Leave:setEnabled(true) end if gameStartCount == 0 and roomInfo:getRoomOwnedUid() ~= nUserId then self.toolView.ui.Items.Button_Dismiss:setEnabled(false) else self.toolView.ui.Items.Button_Dismiss:setEnabled(true) end end -- 重置游戏 function yibinmajiangRoomView:resetGame() yibinmajiangRoomView.super.resetGame(self) app.room.roomInfo:setLastOutViewId(nil); self.ui.Items.Layout_Effect:removeAllChildren() self.ui.Items.Layout_Effect_piao:removeAllChildren() -- self.playerView:clearBao() self.playerView:clearAllPiao() self.playerView:clearDingQue() self.playerView:clearHu() if self._benjinView then self._benjinView:removeFromParent() self._benjinView = nil end self.isTing = false; if self._tingCardView then self:setTingCardVisible(false); end end -- 显示漂 function yibinmajiangRoomView:showPiao() self:stopDirection() local roomInfo = app.room.roomInfo local gameInfo = roomInfo:getGameRule() if not gameInfo.piaomode or tonumber(gameInfo.piaomode)==0 then return end if not self._piaoView then self._piaoView = MJPiaoView:new() self:addToLayer("game", self._piaoView) end self._piaoView:setVisible(true) end -- 显示定缺 function yibinmajiangRoomView:showDingQue(response) local roomInfo = app.room.roomInfo local gameInfo = roomInfo:getGameRule() local isDingqueRule = (getNumBand(gameInfo.specialrule, 0x01) or 0) > 0 if not isDingqueRule then return end if not self._dingqueView then self._dingqueView = MJDingQueView:new() self:addToLayer("game", self._dingqueView) end local data = response and response.response or {} local nice_choose = data.nice_choose self._dingqueView:showDingQueOpreate(nice_choose) end -- 显示定缺结果 function yibinmajiangRoomView:showDingQueResult(response) if not self._dingqueAniView then self._dingqueAniView = MJDingQueAniView:new() self:addToLayer("anim", self._dingqueAniView) end -- local data = response.response local data = app.room.roomInfo:getDingQueInfo() for i, v in pairs(data) do local viewId = app.room:getViewIdByUserId(i) local result = v local posTable = {} local function endCallback() self.playerView:showDingQue(viewId, result) end posTable = self.playerView:getDingQuePos()[viewId] self.playerView:clearDingQue(viewId) self._dingqueAniView:showDingQueResultAniOneByOne(viewId, result, posTable, endCallback) if viewId == MJDefine.MyViewId then if self:checkMyCardHaveDingQue() then if self.playerHandCards and self.playerHandCards[MJDefine.MyViewId] then for i, v in pairs(self.playerHandCards[MJDefine.MyViewId]:getHandCardNodes()) do local colorType = v:getMJColorType() if colorType ~= result and not v:getIsTingYongCard() then v:setStatus(MJDefine.MJStatus.Disable) else v:setIsDingQueCard(true) end end end -- 刷新一下手牌排序 self.playerHandCards[MJDefine.MyViewId]:resetHandCards() self.playerHandCards[MJDefine.MyViewId]:cleanTouchMJ() else for i, v in pairs(self.playerHandCards[MJDefine.MyViewId]:getHandCardNodes()) do if not v:getIsTingYongCard() then v:setStatus(MJDefine.MJStatus.Normal) end end end end end end -- 开始本金 isAni是否要播本金动画 function yibinmajiangRoomView:showBenJin(response, isAni, endFun) logD("yibinmajiangRoomView:showBenJin") local data = response.response local isAni = (false ~= isAni) and true or false MJSound.PlayBenJinSound() local benjinCard = app.room.roomInfo:getBenJinCard() if self._benjinView then self._benjinView:removeFromParent() self._benjinView = nil end local showCards = data.benjinCard local tingCardTable = data.tingCard local endCallback = function() -- 结束回调 -- 设置听用牌 if self.playerHandCards and self.playerHandCards[MJDefine.MyViewId] then for _, j in ipairs(tingCardTable) do for i, v in pairs(self.playerHandCards[MJDefine.MyViewId]:getHandCardNodes()) do local value = v:getValue() if j.card == value then v:setIsTingYongCard(true) end end end -- 刷新一下手牌排序 self.playerHandCards[MJDefine.MyViewId]:resetHandCards() self.playerHandCards[MJDefine.MyViewId]:cleanTouchMJ() end -- 如果是回放中,也要把其他玩家手牌给设置为听用牌 if self._isReplay then for _, viewId in pairs(MJDefine.PlayerViewType) do if viewId ~= MJDefine.MyViewId then -- 如果不是自己,这里只做其他的人听用牌 if self.playerHandCards and self.playerHandCards[viewId] then for _, j in ipairs(tingCardTable) do for i, v in pairs(self.playerHandCards[viewId]:getHandCardNodes()) do local value = v:getValue() if j.card == value then v:setIsTingYongCard(true) end end end -- 刷新一下手牌排序 self.playerHandCards[viewId]:resetHandCards() end end end end -- 如果有另传结束,那么也使用 if endFun then endFun() end end self._benjinView = MJBenJinView:new(self.desktopType) self._benjinView:setEndCallback(endCallback) self._benjinView:setIsShowAni(isAni) self._benjinView:setCards(showCards, tingCardTable) self:addToLayer("game", self._benjinView, 6) -- 由于tool在game层上,需要跟这个做zorder上区别,所以放置在了game层上 end -- 显示查听的牌,弃用 function yibinmajiangRoomView:setChaTingCardViewVisible(bVisible,tingCards) end -- 显示听牌框,弃用 function yibinmajiangRoomView:setTingCardViewVisible(bVisible,tingCards) end -- 检查手牌中是否有定缺 function yibinmajiangRoomView:checkMyCardHaveDingQue() -- 检查规则 local roomInfo = app.room.roomInfo local gameInfo = roomInfo:getGameRule() local isDingqueRule = (getNumBand(gameInfo.specialrule, 0x01) or 0) > 0 if not isDingqueRule then return false end -- 检查定缺信息 local myUserId = app.room:getMyUserId() local que = app.room.roomInfo:getDingQueInfo(myUserId) if not que then return false end -- 如果是回放,那么也不显示定缺 if self._isReplay then return false end -- 检查手牌 if self.playerHandCards and self.playerHandCards[MJDefine.MyViewId] then for i, v in pairs(self.playerHandCards[MJDefine.MyViewId]:getHandCardNodes()) do local colorType = v:getMJColorType() if colorType == que and not v:getIsTingYongCard() then return true end end end return false end -- 重写倒牌,倒完牌后,如果有胡牌,则还要显示胡牌 function yibinmajiangRoomView:showOpenCard() local roomInfo = app.room.roomInfo 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 -- 我自己则屏蔽触摸事件 self.playerHandCards[viewId]:removeTouchEvent() else --倒牌 self.playerHandCards[viewId]:removeAllHandCards() self.playerHandCards[viewId]:createOpenHandCards(v.handCards) if next(v.huCards) and next(v.huCards[1]) and v.huCards[1].huCard and v.huCards[1].huCard > 0 then local huCardValue = v.huCards[1].huCard self.playerHandCards[viewId]:createHandCards(huCardValue, true) end end end end end ------------------------------------------------------------------------------------------------- -- 游戏消息 -------------------------------------------------------------------------------------- ------------------------------------------------------------------------------------------------- -- 开始发牌 function yibinmajiangRoomView:onGameSendCardResponse() logD("yibinmajiangRoomView:onGameSendCardResponse", "开始发牌") --发牌的时候清除桌面上的飘 self.ui.Items.Layout_Effect_piao:removeAllChildren() local function runGameSendCardResponse(onEnd) log("2000000000-yibinmajiangRoomView - 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 end -- MJSound.PlayStartGame() MJAnimationCompnent.CreateStartSendCards(self.playerHandCards, function() if onEnd then onEnd(); end end) local count = table.nums(app.room.roomInfo.memberList); local totalCards = MJDefine.totalCard self.direcionView:updateCardNums(totalCards - count * 13); end log("2000000000-yibinmajiangRoomView - addCallBack(runGameSendCardResponse)" ) self:addCallBack(runGameSendCardResponse); end -- 有玩家准备 function yibinmajiangRoomView:onUserReadyResponse(response) logD("yibinmajiangRoomView:onUserReadyResponse", "有玩家准备了") yibinmajiangRoomView.super.onUserReadyResponse(self,response) local roomInfo = app.room.roomInfo; local myUserId = app.room:getMyUserId() if response and response.nUserId==myUserId then self.playerView:clearAllPiao() local totalCards = MJDefine.totalCard self.direcionView:updateCardNums(totalCards); end self:setButtonTingInfoVisible(false); end -- 广播桌子上所有玩家庄家起手操作,这里其实是发牌 function yibinmajiangRoomView:onBankerOutCard(data) local function runOnBankerOutCard(onEnd) logD("yibinmajiangRoomView:onBankerOutCard", "玩家抓牌", table.tostring(data.response)) local nUserId = data.response.nUserId local viewId = app.room:getViewIdByUserId(nUserId) local card= data.response.card local operates=data.response.operates local nSeatId=data.response.nSeatId local roomInfo = app.room.roomInfo; -- 抓牌 if self.playerHandCards[viewId] then self.playerHandCards[viewId]:onGetCard(operates,card) end if viewId == MJDefine.MyViewId then local huCards = roomInfo.memberList[nUserId].huCards or {}; -- 默认抓牌隐藏听牌按钮 self:setButtonTingInfoVisible(false); if table.nums(huCards) > 0 then -- 如果玩家已经胡了,则不隐藏听牌按钮 self:setButtonTingInfoVisible(true); end 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 = roomInfo.memberList[data.response.nUserId] end app.room:dispatchEvent({name = MJDefine.MJEvent.SelectCard}) app.room:dispatchEvent({name = MJDefine.MJEvent.PushTing}) -- app.room:dispatchEvent({name = MJDefine.MJEvent.ShowTing}) self:setTingCardVisible(false); -- 抓牌后,需要判断抓的牌是否是听用牌 local lastCard = self.playerHandCards[MJDefine.MyViewId]:getLastCard() for i, v in ipairs(app.room.roomInfo:getTingYongCard()) do if v.card == lastCard:getValue() then lastCard:setIsTingYongCard(true) end end -- 抓牌后需要判断遍历手中,有缺的话,只显示缺,不然就全部显示 if self:checkMyCardHaveDingQue() then local myUserId = app.room:getMyUserId() for i, v in pairs(self.playerHandCards[MJDefine.MyViewId]:getHandCardNodes()) do local colorType = v:getMJColorType() if colorType ~= app.room.roomInfo:getDingQueInfo(myUserId) and not v:getIsTingYongCard() then v:setStatus(MJDefine.MJStatus.Disable) else v:setIsDingQueCard(true) end end else for i, v in pairs(self.playerHandCards[MJDefine.MyViewId]:getHandCardNodes()) do if not v:getIsTingYongCard() then v:setStatus(MJDefine.MJStatus.Normal) end end end -- 清除所有操作按钮 -- self.playerHandCards[MJDefine.MyViewId]:hideOperate() self.playerHandCards[MJDefine.MyViewId]:hideOperateItem() self.playerHandCards[MJDefine.MyViewId]:showOperate(operates,card,true) else -- 如果是回放,也需要判断其他玩家抓的牌是否是听用牌 if self._isReplay then if self.playerHandCards and self.playerHandCards[viewId] then local lastCard = self.playerHandCards[viewId]:getLastCard() for i, v in ipairs(app.room.roomInfo:getTingYongCard()) do if v.card == lastCard:getValue() then lastCard:setIsTingYongCard(true) end end end 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 if type(data.response.nLeaveCardNum) == "number" then roomInfo:setLeaveCardNum(data.response.nLeaveCardNum) self.direcionView:updateCardNums(data.response.nLeaveCardNum) end self:updateGameNums() self.direcionView:updateDirection(nSeatId) if onEnd then onEnd() end end log("2000000000-yibinmajiangRoomView - addCallBack(runOnBankerOutCard)") self:addCallBack(runOnBankerOutCard); end -- 庄家初始操作(由于有定缺,所以一开始时候会发送8106<获取手牌>和811a<只获取操作和听牌数据>来区别分开来,之后就全部都是8106来读手牌和操作) function yibinmajiangRoomView:onGameRoundStartOperate(data) local function runOnGameRoundStartOperate(onEnd) logD("yibinmajiangRoomView:runOnGameRoundStartOperate", "811a开始操作", table.tostring(data.response)) local nUserId = data.response.nUserId local viewId = app.room:getViewIdByUserId(nUserId) local card= data.response.card local operates=data.response.operates local nSeatId=data.response.nSeatId local roomInfo = app.room.roomInfo; if viewId == MJDefine.MyViewId then local huCards = roomInfo.memberList[nUserId].huCards or {}; if operates and table.nums(operates)>0 then self.operates = operates else self.operates = {} end self.playerHandCards[MJDefine.MyViewId]:setOutCardEnable(true) self.playerHandCards[MJDefine.MyViewId]:hideOperateItem() self.playerHandCards[MJDefine.MyViewId]:showOperate(operates,card,true) -- if self.playerHandCards[MJDefine.MyViewId] then -- self.playerHandCards[MJDefine.MyViewId]:pushTing() -- end app.room:dispatchEvent({name = MJDefine.MJEvent.PushTing}) end if onEnd then onEnd() end end log("2000000000-yibinmajiangRoomView - addCallBack(runOnGameRoundStartOperate)") self:addCallBack(runOnGameRoundStartOperate); end function yibinmajiangRoomView:onTurnOutCard(data) local function runOnTurnOutCard(onEnd) logE("MJRoomView:runOnOutCard(), response = ", table.tostring(data.response)) log("2000000000-MJRoomView - runOnOutCard") if app.room.roomInfo:getLastOutViewId() ~= 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 yibinmajiangRoomView:onOutCardSuccess(data) logE("yibinmajiangRoomView:onOutCardSuccess(), response = ", table.tostring(data.response)) local function runOnOutCardSuccess(onEnd) log("2000000000-yibinmajiangRoomView - runOnOutCardSuccess---------") -- app.room.roomInfo.outCardUserId = data.response.nUserId local roomInfo = app.room.roomInfo; local nUserId = data.response.nUserId local viewId = app.room:getViewIdByUserId(nUserId) local card= data.response.card local operates=data.response.operates local opType = operates.opType if operates and table.nums(operates)>0 then self.operates = operates self:setTingCardVisible(false); else self.operates = {} end local function callback() -- 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) and roomInfo:getLastOutViewId()~=MJDefine.MyViewId if viewId==MJDefine.MyViewId then local gameInfo = roomInfo:getGameRule(); local zidonghu = getNumBand(gameInfo.specialrule, 0x08) or 0; local player = roomInfo.memberList[nUserId] callback() -- 显示操作 self.playerHandCards[viewId]:setTing(false) if gameInfo.tingpai > 0 then -- 检查是否可听 self.ui:sendMsg(app.room, MJDefine.MJEvent.Ting) -- 每次出牌都请求一次是否可听 end if table.nums(player.huCards) > 0 then -- 胡牌后,显示听牌按钮 self:setButtonTingInfoVisible(true); end -- self.ui:sendMsg(app.room,MJDefine.MJEvent.Ting) self:setTingCardVisible(false); -- self.isTing = true; -- self:setButtonTingInfoVisible(true); -- 如果出牌后,自己还是听状态,则显示听按钮 -- local nTingStatus = player.nTingStatus -- if nTingStatus == MJDefine.MJTingStatus.Ting then -- self:setButtonTingInfoVisible(true) -- end -- 自己出牌后,需要判断是否还有定缺牌,没有的话则亮起所有手牌 if not self:checkMyCardHaveDingQue() then for i, v in pairs(self.playerHandCards[MJDefine.MyViewId]:getHandCardNodes()) do if not v:getIsTingYongCard() then v:setStatus(MJDefine.MJStatus.Normal) end end end else self.playerHandCards[viewId]:onOutCard(card,callback) end app.room:dispatchEvent({name = MJDefine.MJEvent.OutCardFalg, value=card ,viewId=viewId}) else callback() end roomInfo:setLastOutViewId(viewId); end log("2000000000-yibinmajiangRoomView - addCallBack(runOnOutCardSuccess)") self:addCallBack(runOnOutCardSuccess, 0.5) end -- 已经发送了过操作 function yibinmajiangRoomView:onSendGuo() self.operates = {} end -- 操作成功 function yibinmajiangRoomView: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 cardNum = response.cardNum or 0; local useRedNum = response.useRedNum local lziCard = response.lziCard 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, cardNum = cardNum, targetSeatId=opSeatId, opUserId=fromUserId, useRedNum=useRedNum, lziCard=lziCard}) } --删除手中对应的牌 local deleteCards for k,v in pairs(groups) do if v.showType==MJDefine.MJGroupType.Peng then self.playerHandCards[viewId]:removeHandCardByNum(opCard,2,v.cardNum) elseif v.showType==MJDefine.MJGroupType.Chi then --TODO:吃的牌删除两张 elseif v.showType==MJDefine.MJGroupType.AnGang or v.showType==MJDefine.MJGroupType.MAnGang then if v.cardNum <= 4 then self.playerHandCards[viewId]:removeHandCardByNum(opCard,4,v.cardNum) else -- 多头杠移除1张手牌 self.playerHandCards[viewId]:removeHandCardByNum(opCard,1,v.cardNum) end elseif v.showType==MJDefine.MJGroupType.Fei then self.playerHandCards[viewId]:removeHandCardByNum(lziCard,useRedNum,v.cardNum) self.playerHandCards[viewId]:removeHandCardByNum(opCard,2-useRedNum,v.cardNum) elseif v.showType==MJDefine.MJGroupType.Ti then -- 做互换的操作 else if opType==MJDefine.MJOperateType.OPREATE_BAGANG then self.playerHandCards[viewId]:removeHandCardByNum(opCard,1,v.cardNum) else self.playerHandCards[viewId]:removeHandCardByNum(opCard,3,v.cardNum) 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,cardNum) elseif opType==MJDefine.MJOperateType.OPREATE_TI then self.playerHandCards[viewId]:ti(opCard,lziCard) else self.playerHandCards[viewId]:createGroupCards(groups)--创建显示的牌 end -- 提操作不需要刷新手牌 if opType ~= MJDefine.MJOperateType.OPREATE_TI then self.playerHandCards[viewId]:resetHandCards() end self.playerHandCards[viewId]:hideOperate() self.playerHandCards[viewId]:setOutCardEnable(bIsOutCard) if self.playerHandCards[viewId]:isLock() then self.playerHandCards[viewId]:lockHandCard(); end 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 effectCallback = function () guafengxiayuEffect(); end --播放动画 local effect=MJAnimationCompnent.CreateOperareEffect(opType, effectCallback) if effect then self.ui.Items.Layout_Player:addChild(effect); effect:setLocalZOrder(1000); effect:setPosition(self.playerHandCards[viewId]:getAnimationPostion()); end end self:showOperateScore(response.optScore); --音效 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:setButtonTingInfoVisible(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 yibinmajiangRoomView:onGameReconnection() local function onGameReconnectionCallback(onEnd) --更新房间基础数据 local roomInfo = app.room.roomInfo; self:updateRoomBaseData() if (not isReviewVersion()) and cc.Application:getInstance():getTargetPlatform() ~= 0 then self:updateAllGpsInfo() end -- self:checkGpsDistance(nil,roomInfo:getGameStartCount() == 0) -- self:checkMyGpsNeedUpdate(); self.toolView:updateButton() --显示离线状态 for k,v in pairs(roomInfo.memberList) do local viewId = app.room:getViewIdByUserId(k) self.playerView:setPlayerOffLineVisible(v.nOnlineStatus ~= MJDefine.PlayerOnlineStatus.Online, viewId) end -- local gameStatus = roomInfo:getGameStatus(); -- showTooltip('当前游戏状态是'..gameStatus..' startCount是'..roomInfo:getGameStartCount()) if roomInfo:getGameStartCount() > 0 then -- 当前局数大于0,处于重连状态 self:handleGameReconnection(); else -- 游戏未开始,非重连 self:handleGameNormal(); end if onEnd then onEnd(); end end self:addCallBack(onGameReconnectionCallback); end -- 重连游戏的逻辑处理 function yibinmajiangRoomView:handleGameReconnection() local roomInfo = app.room.roomInfo; local myUserId = app.room:getMyUserId(); local memberStatus = {}; local dismissUserId = 0; local gameStatus = roomInfo:getGameStatus(); local isOperated = false local meIsHu = false -- 当前局数大于0,子游戏重连 if self._fastRequestView then -- 隐藏快速开局 self._fastRequestView:removeSelf() self._fastRequestView = nil end --隐藏俱乐部 self:hideClub() for k,v in pairs(roomInfo.memberList) do -- local nOffLineState = v.nOnlineStatus -- --显示离线 -- self.playerView:setPlayerOffLineVisible(nOffLineState ~= MJDefine.PlayerOnlineStatus.Online,viewId) --发起解散状态的ID dismissUserId = (v.nDisbandStatus == 1) and v.nUserId or dismissUserId; if v.nDisbandStatus ~= 0 then table.insert(memberStatus,{userId = v.nUserId , status = v.nDisbandStatus}) end end --显示解散界面 if roomInfo:getIsUserDisbandGame() == 1 and dismissUserId ~= 0 and roomInfo:getIsGameOver() ~= 1 then local view = require("luaScript.Views.Room.RoomDismissView"):new(dismissUserId, roomInfo.memberList, roomInfo:getDismissStateTime()); -- self:addChild(view,1); self:addToLayer("popup", view, 10); app.room:dispatchEvent({name = GAME_EVENT.DISSMISS_UPDATE_STATUS, memberStatus = memberStatus}); end --如果一局结束,玩家点了准备,不再显示牌信息 if MJDefine.GameStatus.GAME_STATUS_ROUND_OVER == gameStatus or MJDefine.GameStatus.GAME_STATUS_GAME_OVER == gameStatus then if roomInfo.memberList[myUserId].nPlayerFlag == 1 then --游戏为停止或开始状态 self:onUserReadyResponse({nUserId = myUserId}); return end end -- 刷新庄家显示 self:updateBanker() -- 初始化玩家手牌节点 self:initHandCardNodes() --初始化方位 self.direcionView:initDirection(self.desktopType) self.direcionView:updateDirection(app.room:getSeatIdByUserId(roomInfo:getNeedOutCardId())); self.direcionView:updateCardNums(roomInfo:getLeaveCardNum()) --显示用户的牌和信息 for userId,v in pairs(roomInfo.memberList) do local viewId = app.room:getViewIdByUserId(userId) if self.playerHandCards[viewId] then --组合一下牌 local groups={} for k, v in ipairs(v.operates) do table.insert(groups, self:getChangeGruopDatas(v)); end self.playerHandCards[viewId]:createGroupCards(groups); self.playerHandCards[viewId]:createOutCards(v.outCards); if table.nums(v.huCards) > 0 and viewId ~= MJDefine.MyViewId then self.playerHandCards[viewId]:createOpenHandCards(v.handCards); else self.playerHandCards[viewId]:createHandCards(v.handCards); -- self.playerHandCards[viewId]:moveLastCard() end if v.nPlayerFlag > 1 then if viewId == MJDefine.MyViewId then -- self.playerHandCards[viewId]:resetHandCards(); local operates = roomInfo:getOperates(); self.operates = (operates and table.nums(operates)>0) and operates or {}; -- 已经胡牌的玩家,不能操作手牌 if table.nums(v.huCards) > 0 then self.playerHandCards[viewId]:lockHandCard(true) end -- 判断断线重连前,如果有操作话,是否有操作过 local operateTable = json.decode(v.isOperated) if operateTable.subOpt and operateTable.subOpt > 0 then isOperated = true end end local isHu = table.nums(v.huCards) > 0 self.playerView:showHu(viewId, isHu) self.playerView:showHuFlag(viewId, isHu) -- 显示定缺 -- if v.isDingQue == 1 then -- self.playerView:showDingQue(viewId, v.dingquetype) -- end end --显示飘状态 self.playerView:showPiao(viewId,tonumber(v.piaostate) == 1) -- 刷新胡牌 -- self.playerHandCards[viewId]:onGetHuCard(v.huCards, true); if next(v.huCards) and next(v.huCards[1]) and v.huCards[1].huCard and v.huCards[1].huCard > 0 then local huCardValue = v.huCards[1].huCard self.playerHandCards[viewId]:createHandCards(huCardValue, true) self.playerView:showHu(viewId, true) self.playerView:showHuFlag(viewId, true) if viewId == MJDefine.MyViewId then meIsHu = true end end end end --显示出牌角标 local lastOutCardViewId = app.room:getViewIdByUserId(roomInfo:getOutCardUserId()); app.room:dispatchEvent({name = MJDefine.MJEvent.OutCardFalg, value = roomInfo:getLastOpCard(), viewId = lastOutCardViewId}); -- 显示本金和听用牌 local benjinCard = app.room.roomInfo:getBenJinCard() if benjinCard and benjinCard > 0 then local tingCard = app.room.roomInfo:getTingYongCard() local data = {response = {benjinCard = benjinCard, tingCard = tingCard}} self:showBenJin(data, false) end -- 还没胡牌,遍历手牌,让定缺牌先出 if not meIsHu then if self:checkMyCardHaveDingQue() then if app.room:checkIsAllChooseDingQue() then local result = app.room.roomInfo:getDingQueInfo(myUserId) if self.playerHandCards and self.playerHandCards[MJDefine.MyViewId] then for i, v in pairs(self.playerHandCards[MJDefine.MyViewId]:getHandCardNodes()) do local colorType = v:getMJColorType() if colorType ~= result and not v:getIsTingYongCard() then v:setStatus(MJDefine.MJStatus.Disable) else v:setIsDingQueCard(true) end end end end else for i, v in pairs(self.playerHandCards[MJDefine.MyViewId]:getHandCardNodes()) do if not v:getIsTingYongCard() then v:setStatus(MJDefine.MJStatus.Normal) end end end self.playerHandCards[MJDefine.MyViewId]:resetHandCards() end -- 如果我胡了,锁定手牌 if meIsHu then self.playerHandCards[MJDefine.MyViewId]:lockHandCard() end -- 将重连前最后操作的牌,放到最后一张 -- 这里要特殊处理,提操作后,发来的操作牌还是提牌,但是这个提牌已经被放下去了,所以要判断手牌是否包含这张牌(?) -- 如果当前是有操作,并且是自己可以出牌的情况,那么needOutCardid会发0 if roomInfo:getNeedOutCardId() == myUserId or roomInfo:getNeedOutCardId() == 0 then local lastOpCardValue = roomInfo:getLastOpCard(); if lastOpCardValue ~= 0 then if self.playerHandCards[MJDefine.MyViewId]:getMjByValue(lastOpCardValue) then self.playerHandCards[MJDefine.MyViewId]:removeHandCard(lastOpCardValue); self.playerHandCards[MJDefine.MyViewId]:resetHandCards(); self.playerHandCards[MJDefine.MyViewId]:createHandCards(lastOpCardValue); -- 设置最后一张是否为听用牌 local tingCardTable = app.room.roomInfo:getTingYongCard() local lastOpCard = self.playerHandCards[MJDefine.MyViewId]:getLastCard() for _, j in ipairs(tingCardTable) do if j.card == lastOpCardValue then lastOpCard:setIsTingYongCard(true) break end end end end self.playerHandCards[MJDefine.MyViewId]:setOutCardEnable(true); end -- 如果我还没胡牌,并且当前不是我出牌,请求一次听数据(不能放在上面,因为中间还有个移除最后一张牌并刷新) if not meIsHu then -- if not (roomInfo:getNeedOutCardId() == myUserId or roomInfo:getNeedOutCardId() then -- 这里不能用getNeedOutCard来判断,因为有时候会发userid,如果玩家有操作或者其他玩家有操作(胡之类的),那么也会发0 local isMyTurn = table.nums(self.playerHandCards[MJDefine.MyViewId]:getHandCardNodes()) % 3 == 2 if not isMyTurn then self.ui:sendMsg(app.room, MJDefine.MJEvent.Ting) end end --设置可以出牌的人 -- local outCardViewId = app.room:getViewIdBySeatId(roomInfo.outCardSeatId) -- if outCardViewId then -- if (outCardViewId~=MJDefine.MyViewId and roomInfo.lastOpCard==0) or (outCardViewId == MJDefine.MyViewId or roomInfo.isNeedOutCard) then -- self.playerHandCards[outCardViewId]:setOutCardEnable(true) -- end -- end --显示听标示 app.room:dispatchEvent({name = MJDefine.MJEvent.PushTing}); -- 如果有操作显示操作按钮 -- 如果断线前有操作过就不显示了 if not isOperated then local isMyTurn = table.nums(self.playerHandCards[MJDefine.MyViewId]:getHandCardNodes()) % 3 == 2 self.playerHandCards[MJDefine.MyViewId]:showOperate(roomInfo:getOperates(), roomInfo:getLastOpCard(), isMyTurn) end -- 等待缺状态(8) if gameStatus == MJDefine.GameStatus.GAME_STATUS_WAIT_SELECT_QUE then local gameInfo = roomInfo:getGameRule(); for i, player in pairs(roomInfo.memberList) do local viewId = app.room:getViewIdByUserId(player.nUserId) if myUserId == player.nUserId then if tonumber(player.dingquetype) ~= -1 then -- self.playerView:showDingQue(viewId, player.dingquetype) else if getNumBand(gameInfo.specialrule, 0x01) > 0 then local myNiceChoose = player.nice_choose self:showDingQue({response = {nice_choose = myNiceChoose}}) end end else if tonumber(player.dingquetype) ~= -1 then -- self.playerView:showDingQue(viewId, player.dingquetype) end end end else for i, player in pairs(roomInfo.memberList) do local viewId = app.room:getViewIdByUserId(player.nUserId) if tonumber(player.dingquetype) ~= -1 then self.playerView:showDingQue(viewId, player.dingquetype) end end end -- 等待漂状态(12) if gameStatus == MJDefine.GameStatus.GAME_STATUS_WAIT_PIAO then local gameInfo = roomInfo:getGameRule(); for i, player in pairs(roomInfo.memberList) do local viewId = app.room:getViewIdByUserId(player.nUserId) if myUserId == player.nUserId then if tonumber(player.isPiao) == 1 then -- 操作过飘了 self.playerView:showPiao(viewId,tonumber(player.piaostate) == 1) else if gameInfo.piaomode == 1 then--可以飘 还没有飘 显示飘按钮 self:showPiao() end end else self.playerView:showPiao(viewId,tonumber(player.piaostate) == 1) end if tonumber(player.piaostate) == 1 then local effect = MJAnimationCompnent.CreatePiaoEffect() if effect then self.ui.Items.Layout_Effect_piao:addChild(effect) effect:setLocalZOrder(1000) effect:setPosition(self.playerHandCards[viewId]:getAnimationPostion()) end end end end --显示结算界面 if gameStatus == MJDefine.GameStatus.GAME_STATUS_ROUND_OVER or gameStatus == MJDefine.GameStatus.GAME_STATUS_GAME_OVER then -- 摊开手牌 self:showOpenCard() -- 显示小局结算 self:showXiaoJuView(); end self:setBtnSitDownVisible(false) end -- 游戏未开始时重连的逻辑处理 function yibinmajiangRoomView:handleGameNormal() local roomInfo = app.room.roomInfo; local gameStatus = roomInfo:getGameStatus(); local gameInfo = roomInfo:getGameRule(); local myUserId = app.room:getMyUserId(); if gameStatus and gameStatus < MJDefine.GameStatus.GAME_STATUS_WAIT_BANKER_START then --self.toolView:enableHosting(false) local quickStartInfo = roomInfo:getQuickStartInfo(); if quickStartInfo then if quickStartInfo.tablefaststate == 1 then local tmpInfo = {} for uid,status in pairs(quickStartInfo.list) do table.insert(tmpInfo, {nUserId=tonumber(uid), nStatus = status}) end local response = {} response.pList = tmpInfo response.timeOut = roomInfo:getQuickStartInfo().time self:onBroadcastFaststart({response=response}) else --self.toolView:showFastStart(true) end else if self._fastRequestView then self._fastRequestView:removeSelf() self._fastRequestView = nil end --self.toolView:showFastStart(true) end elseif gameStatus == MJDefine.GameStatus.GAME_STATUS_ROUND_OVER or gameStatus == MJDefine.GameStatus.GAME_STATUS_GAME_OVER then local mySelf = roomInfo.memberList[myUserId]; if mySelf.nPlayerFlag ~= 1 then --显示哪些玩家胡牌 for i,player in pairs(roomInfo.memberList) do local viewId = app.room:getViewIdByUserId(player.nUserId) end end end end -- 小局结算消息 function yibinmajiangRoomView: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:setTingCardVisible(false); app.room:resetTings() app.room:cleanTingStatus() --如果是解散直接return --[[if roomInfo:getStopFlag() == MJDefine.StopFlag.STOP_FLAG_LONG_NOT_END or roomInfo:getStopFlag() == 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() --被抢杠的人回退补杠 -- if resultInfo.hutype==MJDefine.MJHuType.QiangGangHu and roomInfo:getStopFlag() == MJDefine.StopFlag.STOP_FLAG_NORMAL then -- self.playerHandCards[failViewId]:retoreBuGang(resultInfo.hucard) -- end local function callback() local roomInfo = app.room.roomInfo local memberList = roomInfo.memberList; local hasHandcards = true; for k, v in pairs(memberList) do if v.handCards and #v.handCards == 0 then hasHandcards = false; break; end end if not hasHandcards then -- 还没发牌就结束游戏,直接返回大厅 app.room.roomInfo.needJieSuanInfo = 1; app.room:dispatchEvent({name = GAME_EVENT.DISSMISS_CLOSE}); return ; end self:showXiaoJuView() if onEnd then onEnd() end self.ui.Items.Layout_Effect_piao:removeAllChildren() end if roomInfo:getStopFlag() == 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 local delayTime = 1.5; if roomInfo:getStopFlag() == MJDefine.StopFlag.STOP_FLAG_LONG_NOT_END or roomInfo:getStopFlag() == MJDefine.StopFlag.STOP_FLAG_DISBAND_GAME then delayTime = 0; end runDelay(delayTime, function () callback() end) end end self:addCallBack(runGameXiaoJuResponse); end -- 显示小局结算 function yibinmajiangRoomView:showXiaoJuView() self.direcionView:stopAllActions() self:setTingCardVisible(false); if self.xiaojuView then self.xiaojuView:removeFromParent() end local roomInfo = app.room.roomInfo -- 打开胡牌 local memberList = roomInfo.memberList for k, v in pairs(memberList) do local viewId = app.room:getViewIdByUserId(v.nUserId) local huCards = v.huCards if self.playerHandCards[viewId] then -- 需要判断玩家是否有胡牌并且有值 if next(huCards) and next(huCards[1]) and huCards[1].huCard and huCards[1].huCard > 0 then local huCardValue = huCards[1].huCard -- self.playerHandCards[viewId]:onGetHuCard(huCards, true); -- self.playerHandCards[viewId]:createHandCards(huCardValue, true) end end end self.xiaojuView = MJRoomXiaoJuView:new(self.desktopType) self:addToLayer("popup", self.xiaojuView,1); app.room:dispatchEvent({name = MJDefine.MJEvent.EVENT_XIAOJU_VIEW_SHOWED}); end -- 大局结算消息 function yibinmajiangRoomView:onGameDaJuResponse(data) if self._gameoverview then return end runDelay(0.3, function () if app.room.roomInfo.needJieSuanInfo == 1 then--显示总结算 self:showGameOverResult(data.response) else --[[local roomInfo=app.room.roomInfo --如果是解散直接跳转总结算 if roomInfo:getStopFlag() == MJDefine.StopFlag.STOP_FLAG_LONG_NOT_END or roomInfo:getStopFlag() == MJDefine.StopFlag.STOP_FLAG_DISBAND_GAME then self:showGameOverResult(data.response) end --]] app.room:dispatchEvent({name = GAME_EVENT.DISSMISS_CLOSE}) end end) end -- 显示大局结算 function yibinmajiangRoomView: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 app.room:dispatchEvent({name = MJDefine.MJEvent.EVENT_DAJU_VIEW_SHOWED}); end -- 听牌状态 function yibinmajiangRoomView:onTingCardStatus() local myUserId=app.user.loginInfo.uid local memberList=app.room.roomInfo.memberList local player = memberList[myUserId] if not player then return end local nTingStatus = player.nTingStatus -- showTooltip('收到听状态'..nTingStatus) if nTingStatus == MJDefine.MJTingStatus.Ting then print("---------onTingCardStatus-----------1 "..myUserId) -- if player.isBaoPai == 1 then self.ui:sendMsg(app.room,MJDefine.MJEvent.Ting) -- end self.isTing = true self:setButtonTingInfoVisible(true) else print("---------onTingCardStatus-----------0 "..myUserId) self:setButtonTingInfoVisible(false) end end -- 听牌结果 function yibinmajiangRoomView:onTingCardResult(data) print("---------听牌结果-------------") local tingCards = data.response.tingCards or {}; self.isTing = table.nums(tingCards) > 0; self:setButtonTingInfoVisible(self.isTing); self._tingCardView:setData(tingCards); end -- 显示听 function yibinmajiangRoomView:showTing(evet) local roomInfo=app.room.roomInfo; local selectCard = evet.card; if not selectCard or evet.card <= 0 then return; end local curTingCards = roomInfo:getTingCardsByCard(selectCard); if not self._tingCardView then return ; end self._tingCardView:setData(curTingCards); self.isTing = table.nums(curTingCards) > 0; if self.isTing and (not self:isMySelfHu()) then self:setTingCardVisible(true); else self:setTingCardVisible(false); end end -- 判断我是否胡了 function yibinmajiangRoomView:isMySelfHu() local myUserId = app.room:getMyUserId() local player = app.room.roomInfo.memberList[myUserId] if not player then return false end local huCards = player.huCards or {} return table.nums(huCards) > 0 end -- 胡牌消息 function yibinmajiangRoomView:onHuResponse(data) local function runHuResponse(onEnd) local response = data.response local function callback() self:playHuAni(response) if onEnd then onEnd() end end --删除等待操作的显示 if self.waitOperates and #self.waitOperates>0 then for k,v in pairs(self.waitOperates) do v:removeFromParent() end self.waitOperates={} end local viewId = app.room:getViewIdByUserId(response.nUserId) local userInfo=app.room:getUserInfoByViewId(viewId) local roomInfo = app.room.roomInfo; local isNeedRemoveCard = false local isPlayHuEffect = false; local huInfos = {}; -- 添加胡牌数据 if response.huType == MJDefine.MJGameHuType.HU_ZIMO then isPlayHuEffect = true; local huData = {}; huData.huType = response.huType huData.viewId = viewId; huData.userInfo = app.room:getUserInfoByViewId(viewId); table.insert(huInfos, huData); else local ext = roomInfo.memberList[response.nUserId].ext or {}; local huIndex = roomInfo.memberList[response.nUserId].huIndex; if response.isReplay then local seat = app.room:getSeatIdByUserId(response.nUserId); ext.seat = string.format("%s;", seat); huIndex = 1; end isNeedRemoveCard = true isPlayHuEffect = true local huData = {}; huData.huType = response.huType huData.viewId = viewId huData.userInfo = app.room:getUserInfoByViewId(viewId) table.insert(huInfos, huData) -- local huSeats = string.split(ext.seat, ";"); -- if huSeats and huIndex then -- if (#huSeats - 1) == huIndex then -- 因为最后一个是空格,所以要减一 -- isNeedRemoveCard = true -- isPlayHuEffect = true; -- for k, v in ipairs(huSeats) do -- if string.len(v) > 0 then -- local seat = tonumber(v); -- local huData = {}; -- huData.huType = MJDefine.MJGameHuType.HU_DIANPAO; -- huData.viewId = app.room:getViewIdBySeatId(seat); -- huData.userInfo = app.room:getUserInfoByViewId(huData.viewId); -- table.insert(huInfos, huData); -- end -- end -- end -- end end -- 胡牌动画 if isPlayHuEffect then local function showHuFlag() self.playerView:showHuFlag(viewId, true) end for k, v in ipairs(huInfos) do --先播放胡牌动画和音效,再显示胡牌顺序 local effect = MJAnimationCompnent.CreateHuEffect(v.huType, showHuFlag) if v.huType == MJDefine.MJGameHuType.HU_ZIMO then MJSound.PlayOperateSound(v.userInfo.sex,MJDefine.MJOperateType.OPREATE_ZIMOHU) else MJSound.PlayOperateSound(v.userInfo.sex,MJDefine.MJOperateType.OPREATE_DIANPAOHU) end self.ui.Items.Layout_Effect:addChild(effect) effect:setTag(HU_EFFECT_TAG) effect:setLocalZOrder(1000) effect:setPosition(self.playerHandCards[v.viewId]:getAnimationPostion()) end self:showOperateScore(response.optScore); --放炮动画 if response.huType ~= MJDefine.MJGameHuType.HU_ZIMO then local failViewId = app.room:getViewIdByUserId(response.dpUserId) local effect=MJAnimationCompnent.CreateDianPaoEffect(showHuFlag) self.ui.Items.Layout_Effect:addChild(effect) effect:setLocalZOrder(1000) effect:setPosition(self.playerHandCards[failViewId]:getAnimationPostion()) end end -- 创建胡牌 local huCards = roomInfo.memberList[response.nUserId].huCards; local huCard = response.huCard; if response.huType==MJDefine.MJGameHuType.HU_DIANPAO then local failViewId = app.room:getViewIdByUserId(response.dpUserId) --点炮胡或抢杠胡,胡牌类型都是发 点炮胡 if response.isQiangGng > 0 then -- logD("isQiangGng huCard:"..huCard) --抢杠胡 -- self.playerHandCards[viewId]:onGetCard(nil,huCard) -- self.playerHandCards[viewId]:onGetHuCard({huCard}); self.playerHandCards[viewId]:createHandCards(huCard.huCard, true) --被抢杠的人回退补杠 self.playerHandCards[failViewId]:retoreBuGang(huCard.huCard,1) -- self.playerHandCards[failViewId]:removeHandCardByNum(huCard, 1); self.playerHandCards[failViewId]:resetHandCards(); -- 自动胡情况下,抢杠会自动出牌,此处需设置被抢杠玩家为上次出牌玩家 -- 否则会出现多牌情况 -- local gameInfo = roomInfo:getGameRule(); -- local zidonghu = getNumBand(gameInfo.specialrule, 0x08) or 0; -- if zidonghu > 0 then -- roomInfo:setLastOutViewId(failViewId); -- end elseif response.isGspHu and response.isGspHu > 0 then--点杠炮事手上已经有杠的牌 不需要再加一张胡的牌 --将胡的牌收走 if not self.playerHandCards[viewId]:removeLastHandCard() then if isNeedRemoveCard then self.playerHandCards[failViewId]:removeOutCard(huCard.huCard); end end -- self.playerHandCards[viewId]:onGetHuCard({huCard}); self.playerHandCards[viewId]:createHandCards(huCard.huCard, true) else -- self.playerHandCards[viewId]:onGetCard(nil,response.huCard) -- self.playerHandCards[viewId]:onGetHuCard({huCard}); self.playerHandCards[viewId]:createHandCards(huCard.huCard, true) --将胡的牌收走 if isNeedRemoveCard then self.playerHandCards[failViewId]:removeOutCard(huCard.huCard); end end if failViewId==MJDefine.MyViewId and roomInfo:getLastOutViewId() == MJDefine.MyViewId then --修改点炮的人连续二次出牌 不删除牌 roomInfo:setLastOutViewId(nil); end --此处仅做保留,没有实际意义 elseif response.huType==MJDefine.MJGameHuType.HU_QIANGGANG then local failViewId = app.room:getViewIdByUserId(response.dpUserId) if response.redRealCard > 0 then --抢杠胡时,胡牌的人将胡的牌加入手中 -- self.playerHandCards[viewId]:onGetCard(nil,response.redRealCard) -- self.playerHandCards[viewId]:onGetHuCard({huCard}); self.playerHandCards[viewId]:createHandCards(huCard.huCard, true) --被抢杠的人回退补杠 self.playerHandCards[failViewId]:retoreBuGang(response.redRealCard,1) end end if response.nUserId == app.room:getMyUserId() then if response.huType == MJDefine.MJGameHuType.HU_ZIMO then -- 自摸时,把最后一张牌去掉,胡牌区 self.playerHandCards[viewId]:removeLastHandCard(); -- self.playerHandCards[viewId]:onGetHuCard({huCard}); self.playerHandCards[viewId]:createHandCards(huCard.huCard, true) end self.playerHandCards[viewId]:setOutCardEnable(false) self:setTingCardVisible(false); self.playerHandCards[viewId]:setTing(false) self:setButtonTingInfoVisible(false) self.playerHandCards[viewId]:lockHandCard(); -- local specialrule = roomInfo:getGameRuleByKey("specialrule") or 0; -- if getNumBand(specialrule, 0x08) > 0 then -- self.playerHandCards[viewId]:lockHandCard(true); -- end -- 胡牌之后,显示听牌按钮,并拉取新的数据 -- 胡牌之后,不显示听牌按钮,不拉取新的数据 -- self.ui:sendMsg(app.room,MJDefine.MJEvent.Ting) -- self:setButtonTingInfoVisible(true); else if response.huType == MJDefine.MJGameHuType.HU_ZIMO then self.playerHandCards[viewId]:removeLastHandCard(); local huCard = huCards[#huCards]; local tmpCard = { huCard = huCard.huCard; huType = huCard.huType; dpSeatId = huCard.dpSeatId; }; if not response.isReplay then -- 其他玩家自摸也要显示牌 -- tmpCard.huCard = 0; end -- self.playerHandCards[viewId]:onGetHuCard({tmpCard}); self.playerHandCards[viewId]:createHandCards(huCard.huCard, true) end -- 其他人胡了倒牌 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 then --如果是自摸胡 把最后一张替换为胡的牌 -- handCards[#handCards] = {card = response.huCard} -- end self.playerHandCards[viewId]:removeAllHandCards() self.playerHandCards[viewId]:createOpenHandCards(handCards) -- self.playerHandCards[viewId]:removeLastHandCard(); end self.playerHandCards[MJDefine.MyViewId]:hideOperate() self.playerView:showHu(viewId, true); callback(); end self:addCallBack(runHuResponse, 0.5); end -- 游戏开始 function yibinmajiangRoomView:onGameStartResponse() yibinmajiangRoomView.super.onGameStartResponse(self) self._gameoverview = nil self:changeGameBg() -- self:playGameStartAnim() end -- 游戏开始动画 function yibinmajiangRoomView:playGameStartAnim () if self.gameStartAnim then self.gameStartAnim = nil; end -- 整起音效 local userInfo=app.room:getUserInfoByViewId(MJDefine.MyViewId); MJSound.PlayGameStartSound(userInfo.sex) local visibleSize = cc.Director:getInstance():getVisibleSize(); local GameStartAnim = import("mj_yibinmajiang.luaScript.Views.Animation.yibinmajiangGameStartAnimation"); self.gameStartAnim = GameStartAnim:new(); self.gameStartAnim:play(nil); self:addToLayer("anim", self.gameStartAnim); end -- 有玩家退出房间 function yibinmajiangRoomView:onOtherLogoutResponse(data) 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 yibinmajiangRoomView:onStartPiao(response) local function runPiao(onEnd) logD("yibinmajiangRoomView:onStartPiao") self:showPiao() if onEnd then onEnd() end end logD("yibinmajiangRoomView:runPiao") self:addCallBack(runPiao) end -- 飘结果消息 function yibinmajiangRoomView:onPiaoResponse(response) local function runonPiaoResponse(onEnd) logD("yibinmajiangRoomView: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 userInfo=app.room:getUserInfoByViewId(viewId) self.playerView:showPiao(viewId, v.piaostate == 1) if userId == v.nUserId then --飘音效 MJSound.PlayPiaoSound(userInfo.sex, v.piaostate) if v.piaostate == 1 then local effect = MJAnimationCompnent.CreatePiaoEffect() if effect then self.ui.Items.Layout_Effect_piao:addChild(effect) effect:setLocalZOrder(1000) effect:setPosition(self.playerHandCards[viewId]:getAnimationPostion()) end end end end else local viewId = app.room:getViewIdByUserId(userId) self.playerView:showPiao(viewId,data.piaostate==1) if data.piaostate then --飘音效 local userInfo=app.room:getUserInfoByViewId(viewId) MJSound.PlayPiaoSound(userInfo.sex, data.piaostate) if data.piaostate == 1 then local effect = MJAnimationCompnent.CreatePiaoEffect() if effect then self.ui.Items.Layout_Effect_piao:addChild(effect) effect:setLocalZOrder(1000) effect:setPosition(self.playerHandCards[viewId]:getAnimationPostion()) end end end end if onEnd then onEnd() end end logD("yibinmajiangRoomView:runonPiaoResponse--------") self:addCallBack(runonPiaoResponse) end -- 等待操作 function yibinmajiangRoomView:onWaitOperate(data) if true then -- 不需要显示“我要碰”、“我要杠”等操作 return end yibinmajiangRoomView.super.onWaitOperate(self, data); --等待操作的UID local nUserId = data.response.nUserId -- 有操作,则不能操作手牌 local viewId = app.room:getViewIdByUserId(nUserId); if viewId == MJDefine.MyViewId and data.response and data.response.opType > 0 then self.playerHandCards[viewId]:setOutCardEnable(false); end end -- 改变试图 function yibinmajiangRoomView:onEventChangeViewType(data) MJDefine.MJConfig = MJDefine.loadMJConfig() self:changeGameBg(true) self.ui:sendMsg(app.room, MJDefine.MJEvent.GetTableInfo); end -- 开始定缺 function yibinmajiangRoomView:onDingQueStart(response) local function runDingQue(onEnd) logD("yibinmajiangRoomView:onDingQueStart") self:showDingQue(response) if onEnd then onEnd() end end logD("yibinmajiangRoomView:runDingQue") self:addCallBack(runDingQue, 1.45) -- 因为是与本金动画同时播放的,所以要延迟本金动画的始末时间1.45s end -- 定缺结果 function yibinmajiangRoomView:onDingQueResponse(response) local function runDingQueResponse(onEnd) logD("yibinmajiangRoomView:onDingQueResponse") self:showDingQueResult(response) if onEnd then onEnd() end end logD("yibinmajiangRoomView:runDingQueResponse") self:addCallBack(runDingQueResponse) end -- 开始播放本金动画 function yibinmajiangRoomView:onBenJinStart(response) local function runBenJinStart(onEnd) logD("yibinmajiangRoomView:onBenJinStart") self:showBenJin(response, true) if onEnd then onEnd() end end logD("yibinmajiangRoomView:runBenJinStart") self:addCallBack(runBenJinStart) end -- 提操作成功后收到操作 function yibinmajiangRoomView:onNoticeTiAfterOpResponse(response) local function runNoticeTiAfterOp(onEnd) local data = response.response local nUserId = data.nUserId local viewId = app.room:getViewIdByUserId(nUserId) local operates = data.operates if viewId == MJDefine.MyViewId then if operates and table.nums(operates)>0 then self.operates = operates else self.operates = {} end self.playerHandCards[MJDefine.MyViewId]:setOutCardEnable(true) self.playerHandCards[MJDefine.MyViewId]:hideOperateItem() self.playerHandCards[MJDefine.MyViewId]:showOperate(operates, nil, true) end if onEnd then onEnd() end end logD("yibinmajiangRoomView:runNoticeTiAfterOp") self:addCallBack(runNoticeTiAfterOp) end -- 游戏消息 function yibinmajiangRoomView:bindExtendMessage() 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.room, MJDefine.MJEvent.BenJinStart, handler(self, self.onBenJinStart)) -- 开始本金动画 self:bindEvent(app.room, MJDefine.MJEvent.DingQueStart, handler(self, self.onDingQueStart)) -- 开始定缺 self:bindEvent(app.room, MJDefine.MJEvent.DingQueResponse, handler(self, self.onDingQueResponse)) -- 定缺结果 self:bindEvent(app.room, MJDefine.MJEvent.HuResponse, handler(self , self.onHuResponse)) -- 玩家胡牌 self:bindEvent(app.room, MJDefine.MJEvent.OutCardTings, handler(self , self.pushTing)) -- 出牌/操作后听操作 self:bindEvent(app.room, MJDefine.MJEvent.GameRoundStartOperate, handler(self , self.onGameRoundStartOperate)) -- 庄家初始操作 self:bindEvent(app.room, MJDefine.MJEvent.NoticeTiAfterOp, handler(self, self.onNoticeTiAfterOpResponse)) -- 待定 self:bindEvent(app.room, MJDefine.MJEvent.SendGuo, handler(self , self.onSendGuo)) self:bindEvent(app, MJDefine.MJEvent.ChangeTableBg , handler(self , self.changeGameBg)); --更换桌布 -- 未定的一些信息,待用 self:bindEvent(app, MJDefine.MJEvent.ChangeLanguage , handler(self , self.doSound)) self:bindEvent(app, MJDefine.MJEvent.ChangeChatEnable , handler(self , self.onChangeChatEnable)) self:bindEvent(app, "applicationWillEnterForeground", handler(self, self.onApplicationWillEnterForeground )) self:bindEvent(app, "applicationDidEnterBackground", handler(self, self.onApplicationDidEnterBackground )) self:bindEvent(app, MJDefine.MJEvent.ChangeViewType, handler(self, self.onEventChangeViewType)) self:bindEvent(app.room , MJDefine.MJEvent.QiangDuanOperates, handler(self , self.onQiangDuanOperates)) end function yibinmajiangRoomView: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 yibinmajiangRoomView:onApplicationWillEnterForeground () end function yibinmajiangRoomView:onApplicationDidEnterBackground( ) end -- 抢断操作,因为会收到二次确认消息,所以强制发过给服务端 function yibinmajiangRoomView:onQiangDuanOperates(data) local function runOnQiangDuanOperates(onEnd) logD("yibinmajiangRoomView:runOnQiangDuanOperates") local response = data.response -- if response.operates and self.playerHandCards[MJDefine.MyViewId] then -- self.playerHandCards[MJDefine.MyViewId]:showOperate(response.operates) -- end local card = 0 if response.operates then card = response.operates[1].opCard end local data = { opType = MJDefine.MJOperateType.OPREATE_CANCEL, opCard = card, useRedNum = 0, } if self.playerHandCards[MJDefine.MyViewId] then self.playerHandCards[MJDefine.MyViewId]:sendOp(data) end -- 强制发过给服务端 if onEnd then onEnd() end end logD("yibinmajiangRoomView:onQiangDuanOperates") self:addCallBack(runOnQiangDuanOperates) end return yibinmajiangRoomView