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 MJFunction=MJFramework.MJImport("mj.luaScript.MJFunction") local MJHandCardView=MJFramework.MJImport("mj.luaScript.Views.Game.MJHandCardView") local MJRoomDirection=MJFramework.MJImport("mj.luaScript.Views.Room.MJRoomDirection") local MJWanFa=MJFramework.MJImport("luaScript.SubGameDefine.MaJiang.MJWanFa") local MJAnimationCompnent=MJFramework.MJImport("mj.luaScript.Views.Compnent.MJAnimationCompnent") local MJSound=MJFramework.MJImport("mj.luaScript.MJSound") local MJRoomReplayView=MJFramework.MJFrameworkClassImprot("mj.luaScript.Views.Room.MJRoomReplayView") local linshuiRoomReplayView = class("linshuiRoomReplayView", MJRoomReplayView) function linshuiRoomReplayView:ctor(data) linshuiRoomReplayView.super.ctor(self,data) -- --玩家牌局面板 -- self.playerHandCards={} -- self.data=data -- app:changeGameProtocol(app.gameId,1) end function linshuiRoomReplayView:loadUI() local ui = loadUI("mj_linshui/res/ui_fangjian/mj_linshui_roomView.ui") self.ui = ui; self:addChild(ui); end function linshuiRoomReplayView:onEnter() linshuiRoomReplayView.super.onEnter(self) self:setCheckDefault() self.huOrder = 0 --self.ui.Items.Button_Ting_Info:setVisible(false); end function linshuiRoomReplayView:parseData() self.piaotimes = 0--记录有几次飘操作,为了飘完后删除飘字 local data = self.data --战报解析 self.reports={} local ops=string.split(data.ops,"|") for k,v in pairs(ops) do local op=string.split(v,",") local nUserId=tonumber(op[1]) local opType=op[2] local opStr = op[3] if opType == "PreOpt" then local opList = {} if nUserId==0 then local temp = string.split(opStr, ";") for k,v in pairs(temp) do local temp2 = string.split(v, " ") local userId = tonumber(temp2[1]) table.remove(temp2,1) local operates = temp2 table.insert(opList,{nUserId = userId,operates = self:margeOperates(operates) }) end else local operates = string.split(opStr, " ") table.insert(opList,{nUserId = nUserId,operates = self:margeOperates(operates) }) end table.insert(self.reports,{opType=opType,opList=opList}) elseif opType == "TangCard" then local opList = {} local tangCards = {} local tCards = string.split(opStr, "_") for i,v in pairs(tCards) do if v and tonumber(v) then local card = {} card.card = tonumber(v) table.insert(tangCards,card) end end table.insert(self.reports,{nUserId=nUserId,opType=opType,tangCards = tangCards }) --[[elseif opType == "PaoCard" then local opList = {} local paoCards = {} local tCards = string.split(opStr, "_") for i,v in pairs(tCards) do if v and tonumber(v) then local card = {} card.card = tonumber(v) table.insert(paoCards,card) end end table.insert(self.reports,{nUserId=nUserId,opType=opType,paoCards = paoCards })--]] elseif opType == "HuanPai" then self.huanPai = self.huanPai or {} local huanCards = {} local tCards = string.split(opStr, "_") for i,v in pairs(tCards) do if v and tonumber(v) then table.insert(huanCards,tonumber(v)) end end table.insert(self.huanPai,{nUserId=nUserId,opType="HuanPai",cards = huanCards }) local op=string.split(ops[k+1],",") local opType=op[2] if opType ~= "HuanPai" then table.insert(self.reports,{huanPaiInfo=self.huanPai,opType="HuanPai" }) end elseif opType == "HuanPaiType" then local temp = string.split(opStr, "_") local huanPaiType = tonumber(temp[1]) table.insert(self.reports,{nUserId=nUserId,opType=opType,huanPaiType = huanPaiType }) elseif opType == "HuanPaiDone" then self.huanPaiDone = self.huanPaiDone or {} local huanCards = {} local tCards = string.split(opStr, "_") for i,v in pairs(tCards) do if v and tonumber(v) then table.insert(huanCards,tonumber(v)) end end table.insert(self.huanPaiDone,{nUserId=nUserId,opType="HuanPaiDone",cards = huanCards }) local op=string.split(ops[k+1],",") local opType=op[2] if opType ~= "HuanPaiDone" then table.insert(self.reports,{huanPaiInfo=self.huanPaiDone,opType="HuanPaiDone" }) end elseif opType == "DingQue" then local opList = {} local temp2 = {} table.insert(temp2,tonumber(0)) table.insert(temp2,tonumber(1)) table.insert(temp2,tonumber(2)) table.insert(opList,{nUserId = nUserId,operates = self:margeOperates(temp2) }) table.insert(self.reports,{opType="ShowDingQueOpt",opList=opList}) table.insert(self.reports,{nUserId=nUserId,opType="SubOp",submitOp = tonumber(opStr) }) local tCards = string.split(opStr, "_") local card,redNum = nil,0 if tCards[1] then card = tonumber(tCards[1]) end if tCards[2] then redNum = tonumber(tCards[2]) end table.insert(self.reports,{nUserId=nUserId,opType=opType,card=card,redNum=redNum}) elseif opType == "BaoPai" then local opList = {} local temp2 = {} table.insert(temp2,tonumber(1)) --table.insert(temp2,tonumber(2)) table.insert(opList,{nUserId = nUserId,operates = self:margeOperates(temp2) }) table.insert(self.reports,{opType="ShowBaoOpt",opList=opList}) table.insert(self.reports,{nUserId=nUserId,opType="SubOp",submitOp = tonumber(opStr) }) local tCards = string.split(opStr, "_") local card,redNum = nil,0 if tCards[1] then card = tonumber(tCards[1]) end if tCards[2] then redNum = tonumber(tCards[2]) end table.insert(self.reports,{nUserId=nUserId,opType=opType,card=card,redNum=redNum}) elseif opType == "SubOp" then --提交的操作 local temp = string.split(opStr, "_") local submitOp = tonumber(temp[1]) table.insert(self.reports,{nUserId=nUserId,opType=opType,submitOp = submitOp }) elseif opType == "PiaoOpt" then self.piaotimes = self.piaotimes + 1 local ops = string.split(opStr, "_") local piaostate = tonumber(ops[1]) table.insert(self.reports,{nUserId=nUserId,opType=opType,piaostate = piaostate }) elseif "Dis"~=opType then local tCards = string.split(opStr, "_") local card,redNum = nil,0 if tCards[1] then card = tonumber(tCards[1]) end if tCards[2] then redNum = tonumber(tCards[2]) end table.insert(self.reports,{nUserId=nUserId,opType=opType,card=card,redNum=redNum}) end end if self.data.ext.luoboCards then local luoboCards=MJFunction.convertToCards(self.data.ext.luoboCards) if #luoboCards > 0 then table.insert(self.reports,{opType="BaLuoBo"}) end end end --合并操作 只显示一个杠 function linshuiRoomReplayView:margeOperates(operates) local ops = {} local isGang = false for k,v in pairs(operates) do local op = tonumber(v) if (op==MJDefine.MJOperateType.OPREATE_ZHIGANG) or (op==MJDefine.MJOperateType.OPREATE_BAGANG) or (op==MJDefine.MJOperateType.OPREATE_ANGANG) then if not isGang then table.insert(ops,op) isGang = true end else table.insert(ops,op) end end return ops end function linshuiRoomReplayView:startGame() self:onGameStartResponse() --设置为回放模式 for k,v in pairs(self.playerHandCards) do v:setReplay(true) end app.room.roomInfo.laizi = tonum(self.data.ext.laizi) self:onGameSendCardResponse() self.playerHandCards[MJDefine.MyViewId]:removeTouchEvent() end function linshuiRoomReplayView:initHanders() linshuiRoomReplayView.super.initHanders(self) self.handers ["In"]=handler(self,self.onGetCard) -- 发牌 self.handers ["Out"]=handler(self,self.onOutCard) -- 出牌 self.handers ["PiaoOpt"] = handler(self,self.onPiaoRes) self.handers ["BaoPai"] = handler(self,self.onBaoPaiRes) self.handers ["DingQue"] = handler(self,self.onSelectedQueRes) self.handers ["DianPao"] = handler(self,self.onDianPao) self.handers ["PaoHu"] = handler(self,self.onPlayerHu) self.handers ["QiangGHu"] = handler(self,self.onPlayerHu) self.handers ["ZiMo"] = handler(self,self.onPlayerHu) self.handers ["PreOpt"] = handler(self,self.onShowOperates) self.handers ["ShowBaoOpt"] = handler(self,self.onShowBaoOpt) self.handers ["SubOp"] = handler(self,self.onSubmitOperate) self.handers ["OpWait"] = handler(self,self.onActionWait) self.handers ["BaLuoBo"]=handler(self,self.onBaLuoBo) self.handers ["ShowDingQueOpt"]=handler(self,self.onSelectedQueOpt) self.handers ["HuanPaiType"]=handler(self,self.onHuanPaiType) --self.handers ["HuanPaiType"]=handler(self,self.onHuanPaiType) self.handers ["HuanPaiDone"]=handler(self,self.onHuanPaiDone) self.handers ["HuanPai"]=handler(self,self.onHuanPai) self.handers ["TangCard"]=handler(self,self.onTangPaiResponse) self.handers ["PaoCard"]=handler(self,self.onSetPaoCards) end function linshuiRoomReplayView:onActionWait(data) local response = { nUserId = data.nUserId, opType = data.card, } self:onWaitOperate({response = response}) end function linshuiRoomReplayView:onSubmitOperate(data) local viewId = app.room:getViewIdByUserId(data.nUserId) local Layout_Operate = self.playerHandCards[viewId].ui.Items.Layout_Operate local btn = Layout_Operate:getChildByTag(data.submitOp) if btn then local hand = cc.Sprite:create("mj/res/ui/zy_fangjian/mj_room_hand.png") btn:addChild(hand) local size = btn:getContentSize() hand:setPosition(cc.p(size.width/2+20,size.height/2-20)) local action = cc.Sequence:create(cc.MoveBy:create(0.5,cc.p(-10,10)),cc.MoveBy:create(0.5,cc.p(10,-10))) hand:runAction(cc.RepeatForever:create(action)) -- if data.submitOp == MJDefine.MJOperateType.OPREATE_CANCEL then btn:runAction(cc.Sequence:create(cc.DelayTime:create(1),cc.CallFunc:create(function() self.playerHandCards[viewId]:hideOperate() end))) -- end end end function linshuiRoomReplayView:onShowOperates(data) local opList = data.opList for k,v in pairs(opList) do local nUserId = v.nUserId local operates = v.operates local viewId=app.room:getViewIdByUserId(nUserId) local Layout_Operate = self.playerHandCards[viewId].ui.Items.Layout_Operate Layout_Operate:removeAllChildren() Layout_Operate:setVisible(true) local x=Layout_Operate:getContentSize().width if viewId==MJDefine.PlayerViewType.Left then x = 0 end --判断是否有胡操作 local isHaveHuOp = false local isTang = self.playerHandCards[viewId].isTangCard for i,v in pairs(operates) do if tonumber(v) == MJDefine.MJOperateType.OPREATE_DIANPAOHU or tonumber(v) == MJDefine.MJOperateType.OPREATE_ZIMOHU then isHaveHuOp = true break end end --if not (isHaveHuOp) then--没有胡操作,才显示过,有胡必胡isTang and isTang == true and table.insert(operates,1,MJDefine.MJOperateType.OPREATE_CANCEL) --end if table.nums(operates) >= 2 then local function sortOperate(opA,opB) if opA 0 then local index = 1 local playerNum = table.nums(self.data.ext.userExtInfo) for k,v in pairs(self.data.ext.userExtInfo) do local viewId = app.room:getViewIdByUserId(tonumber(k)) local effect if index == playerNum then effect = MJAnimationCompnent.CreateLoBoLabel(v.luoboCount,callback) else effect = MJAnimationCompnent.CreateLoBoLabel(v.luoboCount) 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 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) 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(MJDefine.LuoBoPos[luoNum][i]) self.ui.Items.Layout_Effect_luobo:addChild(effect) end end else callback() end end luoboCallBack() end --出牌成功 function linshuiRoomReplayView:onOutCardSuccess(data) logE("linshuiRoomReplayView:onOutCardSuccess(), response = ", table.tostring(data.response)) --[[ -- 出牌用户id , defVar("nOutCardUserId", VT_Int, -1) -- 出的牌 , defVar("byOutCard", VT_UChar, -1) -- 可以的操作ma , defVar("mainOpCode", VT_Short, -1) -- 玩家操作 , defVar("operations", VT_Vector(ChuPaiPlayerOperation), {})--]] local function runOnOutCardSuccess(onEnd) log("2000000000-linshuiRoomReplayView - runOnOutCardSuccess---------") 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() self.playerHandCards[MJDefine.MyViewId]:showOperate(operates,card) if onEnd then onEnd() end end -- self.lastOutCard = card self.lastOutViewId = viewId local player = app.room.roomInfo.memberList[data.response.nUserId] if self.playerHandCards[viewId] then --and (viewId~=MJDefine.MyViewId or player.isBaoPai == 1) self.playerHandCards[viewId]:onOutCard(card,callback)--onOutCard(data.response,true) app.room:dispatchEvent({name = MJDefine.MJEvent.OutCardFalg, value=card ,viewId=viewId}) if viewId==MJDefine.MyViewId then self.playerHandCards[viewId]:setTing(false) self.playerHandCards[viewId]:resetHandCards() end else callback() end end log("2000000000-linshuiRoomReplayView - addCallBack(runOnOutCardSuccess)") self:addCallBack(runOnOutCardSuccess) end function linshuiRoomReplayView:onGameEnd(data) local function runGameXiaoJuResponse(onEnd) local function callback() --self:endReplay() --:showXiaoJuView() if onEnd then onEnd() end end local roomInfo = app.room.roomInfo local hutype=self.data.ext.huTypes local hucard=data.card self.direcionView:stopAllActions() -- local resultInfo=json.decode(roomInfo.strResultInfo) --所有胡牌的人 考虑抢杠胡的问题 --所有胡牌的人 考虑抢杠胡的问题 local viewIds={} local failViewId=0 for k,v in pairs(roomInfo.memberList) do local viewId = app.room:getViewIdByUserId(v.nUserId) if v.result==MJDefine.MJGameResultType.Win then table.insert(viewIds,viewId) --处理掉huCard, 不加入手牌 --播放音效 if viewId==MJDefine.MyViewId then MJSound.PlayWinGame() end elseif v.result==MJDefine.MJGameResultType.Fail then failViewId=viewId if viewId==MJDefine.MyViewId then MJSound.PlayLoseGame() end end end self:showOpenCard() local function callback() self:showXiaoJuView() if onEnd then onEnd() end end if #viewIds>0 then for k,viewId in pairs(viewIds) do local effect local resultInfo = roomInfo.resultInfos local userId = app.room:getUserIdByViewId(viewId) if k == #viewIds then --只有最后播放胡牌动画的回调一次就可以了 if resultInfo[userId].result == MJDefine.MJGameHuType.HU_ZIMO then effect = MJAnimationCompnent.CreateHuEffect("zimo",callback) else effect = MJAnimationCompnent.CreateHuEffect("hu",callback) end else end if effect then self:addChild(effect) effect:setPosition(self.playerHandCards[viewId]:getAnimationPostion()) effect:setVisible(false) end end else if roomInfo.stopFlag==MJDefine.StopFlag.STOP_FLAG_HUANG_ZHUANG then local effect=MJAnimationCompnent.CreateLiuJuEffect(callback) self:addChild(effect) else callback() end end end log("2000000000-MJRoomView - addCallBack(runGameXiaoJuResponse)" ) self:addCallBack(runGameXiaoJuResponse); end --换牌完成 function linshuiRoomReplayView:onHuanPaiDone(data) if not data.huanPaiInfo or type(data.huanPaiInfo) ~= 'table' then return end for i,v in pairs(data.huanPaiInfo) do local viewId=app.room:getViewIdByUserId(v.nUserId) self.playerHandCards[viewId]:createSwapCards(v.cards) for i,v in pairs(v.cards) do self.playerHandCards[viewId]:onGetCard(nil,tonumber(v),true) end local action = cc.Sequence:create(cc.DelayTime:create(1),cc.CallFunc:create(function() self.playerHandCards[viewId]:deleteSwapCards() end)) self.playerHandCards[viewId]:resetHandCards() self:runAction(action) end end --开始换牌 function linshuiRoomReplayView:onHuanPai(data) if not data.huanPaiInfo or type(data.huanPaiInfo) ~= 'table' then return end for i,v in pairs(data.huanPaiInfo) do local viewId=app.room:getViewIdByUserId(v.nUserId) self.playerHandCards[viewId]:createSwapCards(v.cards) local tselCards = {} for j,k in pairs(v.cards) do table.insert(tselCards,{card = k}) end self.playerHandCards[viewId]:removeHandCard(tselCards) self.playerHandCards[viewId]:resetHandCards() local action = cc.Sequence:create(cc.DelayTime:create(1),cc.CallFunc:create(function() self.playerHandCards[viewId]:deleteSwapCards() end)) self:runAction(action) end end function linshuiRoomReplayView:onPiaoRes(data) local response={ nUserId=data.nUserId, piaostate=data.piaostate, } local viewId=app.room:getViewIdByUserId(data.nUserId) self.playerHandCards[viewId]:hideOperate() self:onPiaoResponse({response=response}) local viewId = app.room:getViewIdByUserId(data.nUserId) local ui=loadUI("mj_linshui/res/ui_fangjian/mj_linshui_replay_piao.ui") local pos = self.playerHandCards[viewId]:getAnimationPostion() ui:setPosition(pos) self.ui.Items.Layout_Effect_luobo:addChild(ui) local btn if tonumber(data.piaostate) > 0 then local str = string.format("Button_Piao_%d",data.piaostate) btn = ui.Items[str] elseif tonumber(data.piaostate) == 0 then btn = ui.Items.Button_BuPiao end if btn then local hand = cc.Sprite:create("mj/res/ui/zy_fangjian/mj_room_hand.png") btn:addChild(hand) local size = btn:getContentSize() hand:setPosition(cc.p(size.width/2+20,size.height/2-20)) local action = cc.Sequence:create(cc.MoveBy:create(0.5,cc.p(-10,10)),cc.MoveBy:create(0.5,cc.p(10,-10))) hand:runAction(cc.RepeatForever:create(action)) btn:runAction(cc.Sequence:create(cc.DelayTime:create(1),cc.CallFunc:create(function() ui:removeFromParent() ui = nil self.piaotimes = self.piaotimes - 1 if self.piaotimes == 0 then--所有飘操作已经完成了,删除桌面上的飘字 --清除桌面上的飘 self.ui.Items.Layout_Effect_luobo:removeAllChildren() end end))) end end --躺牌结果 function linshuiRoomReplayView:onTangPaiResponse(data) if not data then return end local opUserId = data.nUserId local viewId = app.room:getViewIdByUserId(opUserId) local tangCards = data.tangCards --躺的人手牌躺牌变色 self.playerHandCards[viewId]:setTangCard(true,tangCards) local effect=MJAnimationCompnent.CreateTangEffect() if effect then self.ui.Items.Layout_Player:addChild(effect) effect:setLocalZOrder(1000) effect:setPosition(self.playerHandCards[viewId]:getAnimationPostion()) end --躺音效 local userInfo=app.room:getUserInfoByViewId(viewId) MJSound.PlayTangSound(userInfo.sex) end --设置炮牌 function linshuiRoomReplayView:onSetPaoCards(data) if not data then return end local opUserId = data.nUserId --local viewId = app.room:getViewIdByUserId(opUserId) local paoCards = data.paoCards for k,v in pairs(self.playerHandCards) do v:setPaoCard(true,paoCards) end end return linshuiRoomReplayView