local ActivityGacha_Model = {} local private = {} local EventSystem = require('Event/EventSystem') local activity_draw_card_opt_pb = require 'Proto.activity_draw_card_opt_pb' ActivityGacha_Model.MovieName = { GoldenHero = "LimitDrawCardMovie.mp4", SuperGold = "SuperLimitDrawCardMovie.mp4" } ---------------------------------------- 系统函数 ------------------------------------ function ActivityGacha_Model.OnStartup() NetManager.RegisterMsgCB(MessageEnums.MessageG2CActivityDrawCardInfos, private.InitGachaParams) NetManager.RegisterMsgCB(MessageEnums.MessageActivityDrawCard, private.ResponseActivityDrawCard) NetManager.RegisterMsgCB(MessageEnums.MessageActivityGetDrawNumReward, private.ResponseActivityDrawNumReward) NetManager.RegisterMsgCB(MessageEnums.MessageActivityGetDrawHistory, private.ResponseActivityGetDrawHistory) NetManager.RegisterMsgCB(MessageEnums.MessageActivityCardPoolChoose, nil) private.activityGachaInfos = {} private.activityGachaRecords = {} end function ActivityGacha_Model.OnShutdown() private.activityGachaInfos = nil private.activityGachaRecords = nil end -- 对外接口 function ActivityGacha_Model.GetActivityDrawInfo(activityId) return private.activityGachaInfos[activityId] end function ActivityGacha_Model.GetActivityDrawHistory(activityId) return private.activityGachaRecords[activityId] end function ActivityGacha_Model.GetSkipState() return private.skipState or false end function private.SortHeroID(a, b) return a < b end function ActivityGacha_Model.GetGoldHeroChooseList(drawCardStoreId, curHeroID) local cardPoolList = {} for _, v in MDL.OperationActivity.StoreGoodsData:GetEnumerator() do if v.TabID == drawCardStoreId then local itemData = DataSheetManager.ItemData:GetDataByID(v.ItemID) if itemData.FirstType == LuaConst.ItemType.HeroFragment then for i, heroData in DataSheetManager.HeroNum:GetEnumerator() do if heroData.PieceItem == itemData.ID then if heroData.ID ~= curHeroID then if table.containValue(cardPoolList, heroData.ID) == false then table.insert(cardPoolList, heroData.ID) end end break end end elseif itemData.FirstType == LuaConst.ItemType.HeroAwaken then if MDL.HeroAwaken.GetIsHeroAwaken(itemData.ThirdType) then if itemData.ThirdType ~= curHeroID then if table.containValue(cardPoolList, itemData.ThirdType) == false then table.insert(cardPoolList, itemData.ThirdType) end end end end end end table.sort(cardPoolList, private.SortHeroID) table.insert(cardPoolList, 1, curHeroID) return cardPoolList end --region -------------------------------------- 协议相关 ------------------------------------ function private.InitGachaParams(msgResp) if IsServerDataNotNil(msgResp.info) then for _, info in ipairs (msgResp.info) do private.SetGachaInfo(info.activityId, info.drawCount, info.rewardIndex, info.rewardList, info) end end end function private.SetGachaInfo(activityId, drawCount, rewardIndex, rewardList, drawCardInfo) local gachaInfo = private.activityGachaInfos[activityId] if not gachaInfo then private.activityGachaInfos[activityId] = { drawCount = drawCount or 0, rewardIndex = rewardIndex or 0, rewardList = rewardList or {}, canChoose = drawCardInfo.canChoose, isOpen = drawCardInfo.isOpen, cardPoolId = drawCardInfo.cardPoolId or 0, } else gachaInfo.drawCount = drawCount or gachaInfo.drawCount gachaInfo.rewardIndex = rewardIndex or gachaInfo.rewardIndex gachaInfo.rewardList = rewardList or gachaInfo.rewardList if drawCardInfo then gachaInfo.canChoose = drawCardInfo.canChoose gachaInfo.isOpen = drawCardInfo.isOpen local lastPoolID = gachaInfo.cardPoolId gachaInfo.cardPoolId = drawCardInfo.cardPoolId if gachaInfo.canChoose and lastPoolID ~= gachaInfo.cardPoolId then EventSystem.Dispatch(EventID.UI_GachaLimit_ChangeCardInfo, activityId) end end end end function ActivityGacha_Model.RequestActivityDrawCard(activityId, activityType, drawNums, isSkip) private.skipState = isSkip or CTL.ActivityGacha.IsSkipAnim(activityType) CTL.DrawCard.UpdateHeroCardState() MDL.Reward.SetCloseRewardTipShow(true) local msg = activity_draw_card_opt_pb.ActivityDrawCardReq() msg.activityId = activityId msg.activityType = activityType msg.drawNums = drawNums NetManager.SendMessage(MessageEnums.MessageActivityDrawCard, msg) end function private.CloseCallBack(msgResp, isSkip) --因为会延迟弹出,刚抽卡后就匹配成功会影响3V3选人界面 if UIManager.IsViewOpened(Const_UI_Lua.UIEnum.UISyncTeamPVPSelectHeroPanel) or UIManager.IsViewOpened(Const_UI_Lua.UIEnum.UISyncTeamPVPMatchSuccessPanel) or UIManager.IsViewOpened(Const_UI_Lua.UIEnum.UISyncSoloMatchSuccessPanel) then return end if UIManager.IsViewOpened(Const_UI_Lua.UIEnum.UIGachaGetLimit) then EventSystem.Dispatch(EventID.UI_GachaLimit_RefreshGet, {result = msgResp}) else UIManager.OpenView(Const_UI_Lua.UIEnum.UIGachaGetLimit, {result = msgResp}) end if isSkip then CTL.Sound.PlayGameSound("MUSiC_empty") end CTL.Sound.ResumeLevelSound() end function private.ResponseActivityDrawCard(msgResp) private.SetGachaInfo(msgResp.activityId, msgResp.curDrawNum) EventSystem.Dispatch(EventID.UI_GachaLimit_Refresh) if private.skipState then private.CloseCallBack(msgResp) else if not UIManager.IsViewOpened(Const_UI_Lua.UIEnum.UISyncSoloMatchSuccessPanel) and not UIManager.IsViewOpened(Const_UI_Lua.UIEnum.UISyncTeamPVPMatchSuccessPanel) then local movieName if msgResp.activityType == MDL.OperationActivity.ActivityType.GoldenHero or msgResp.activityType == MDL.OperationActivity.ActivityType.GoldHeroReprint then movieName = ActivityGacha_Model.MovieName.GoldenHero elseif msgResp.activityType == MDL.OperationActivity.ActivityType.SuperGold then movieName = ActivityGacha_Model.MovieName.SuperGold end UIManager.OpenView(Const_UI_Lua.UIEnum.UICommonPlayMovie, { MovieName = movieName, closeCallBack = function() private.CloseCallBack(msgResp) end }) end end MDL.Reward.SetCloseRewardTipShow(false) end function ActivityGacha_Model.RequestActivityDrawNumReward(activityId, activityType, rewardId) local msg = activity_draw_card_opt_pb.ActivityGetDrawNumRewardReq() msg.activityId = activityId msg.activityType = activityType msg.rewardId = rewardId NetManager.SendMessage(MessageEnums.MessageActivityGetDrawNumReward, msg) end function private.ResponseActivityDrawNumReward(msgResp) private.SetGachaInfo(msgResp.activityId, nil, msgResp.rewardIndex, msgResp.rewardList) EventSystem.Dispatch(EventID.UI_GachaLimit_Refresh) end function ActivityGacha_Model.RequestActivityGetDrawHistory(activityId, activityType) local msg = activity_draw_card_opt_pb.ActivityGetDrawHistoryReq() msg.activityId = activityId msg.activityType = activityType NetManager.SendMessage(MessageEnums.MessageActivityGetDrawHistory, msg) end function private.ResponseActivityGetDrawHistory(msgResp) private.activityGachaRecords[msgResp.activityId] = msgResp.history EventSystem.Dispatch(EventID.UI_GachaShop_RefreshSummaryRecords) end -- 自选卡池 function ActivityGacha_Model.RequestActivityCardPoolChooseRequest(activityId, activityType, cardPoolId) local msg = activity_draw_card_opt_pb.ActivityCardPoolChooseReq() msg.activityId = activityId msg.activityType = activityType msg.cardPoolId = cardPoolId NetManager.SendMessage(MessageEnums.MessageActivityCardPoolChoose, msg) end --endregion -------------------------------- 协议相关 ---------------------------------------------------- return ActivityGacha_Model