local GodBeastActivity_Model = {} local private = {} local EventSystem = require('Event/EventSystem') local activity_god_beast_op_pb = require('Proto.activity_god_beast_op_pb') local GODBEAST_CHOOSE_POPUP_OPENED = "GODBEAST_CHOOSE_POPUP_OPENED" function GodBeastActivity_Model.OnStartup() NetManager.RegisterMsgCB(MessageEnums.MessageGetGodBeastInfo, private.GetGodBeastInfoResponse) NetManager.RegisterMsgCB(MessageEnums.MessageBeastRear, private.BeastRearResponse) NetManager.RegisterMsgCB(MessageEnums.MessageBeastLvRwd, private.BeastLevelRewardResponse) NetManager.RegisterMsgCB(MessageEnums.MessageChooseRewardBeast, private.ChooseRewardBeastResp) EventSystem.Regist(EventID.New_Day_Refresh, GodBeastActivity_Model.GodBeastActivityInfoRequest) private.ActivityType = MDL.OperationActivity.ActivityType.GodBeastActivity --[[ private.GodBeastInfoList = { activityId, rearLevel, curExpNum, rearLevelRewards }]] private.GodBeastInfoList = {} private.activityId = nil end function GodBeastActivity_Model.GetActivityId() if private.activityId then return private.activityId else local godBeastData = MDL.OperationActivity.GetOperationActivityInfo(private.ActivityType) if godBeastData then for i, v in pairs(godBeastData) do local info = MDL.OperationActivity.GetOperationActivityInfo(private.ActivityType, v.activityId) if CTL.OperationActivity.IsOperationActivityOpen(info) then private.activityId = v.activityId return private.activityId end end end end end function GodBeastActivity_Model.GetGodBeastRearLevel(activityId) if private.GodBeastInfoList[activityId] then return private.GodBeastInfoList[activityId].rearLevel end return 0 end function GodBeastActivity_Model.GetGodBeastCurExpNum(activityId) if private.GodBeastInfoList[activityId] then return private.GodBeastInfoList[activityId].curExpNum end return 0 end function GodBeastActivity_Model.GetGodBeastRearLevelReward(activityId, level) if private.GodBeastInfoList[activityId] and private.GodBeastInfoList[activityId].rearLevelRewards then if level then return private.GodBeastInfoList[activityId].rearLevelRewards[level] else return private.GodBeastInfoList[activityId].rearLevelRewards end end return nil end function GodBeastActivity_Model.GetGodBeastIsCanChoose(activityId) if private.GodBeastInfoList[activityId] then if private.GodBeastInfoList[activityId].canChoose then local chooseId = GodBeastActivity_Model.GetGodBeastChooseId(activityId) local cardPoolList = CTL.GodBeastActivity.GetActivitySameQualityGodBeast(activityId, chooseId) return #cardPoolList > 0 end return false end return false end function GodBeastActivity_Model.GetGodBeastChooseId(activityId) if private.GodBeastInfoList[activityId] then if private.GodBeastInfoList[activityId].chooseId == 0 then local basicData = MDL.OperationActivity.ActivityBaseData[private.ActivityType]:GetDataByActivityID(activityId) return basicData.GodBeastID end return private.GodBeastInfoList[activityId].chooseId end return 0 end function GodBeastActivity_Model.IsGodBeastChoosePopUpAutoOpened(activityId) local str = GODBEAST_CHOOSE_POPUP_OPENED..activityId return PersistentData.PlayerData:Get(str, false) end function GodBeastActivity_Model.SetGodBeastChoosePopUpAutoOpened(activityId) local str = GODBEAST_CHOOSE_POPUP_OPENED..activityId PersistentData.PlayerData:Set(str, true, true) end function private.SetHorseRearInfo(info) if not private.GodBeastInfoList[info.activityId] then private.GodBeastInfoList[info.activityId] = {} end private.GodBeastInfoList[info.activityId] = { activityId = info.activityId, rearLevel = info.lv, curExpNum = info.exp, rearLevelRewards = {}, canChoose = info.canChoose, chooseId = info.chooseId, } for i, v in ipairs(info.lvRwds) do private.GodBeastInfoList[info.activityId].rearLevelRewards[v] = true end end --region ***************** 协议 ******************** function GodBeastActivity_Model.GodBeastActivityInfoRequest() local isClear = true if MDL.Unlock.IsUnlock(MDL.Unlock.FunctionType.GodBeastActivity) then local info = MDL.OperationActivity.GetOperationActivityInfo(private.ActivityType) if info then for activityId, v in pairs(info) do if CTL.OperationActivity.IsOperationActivityOpen(v) then private.GetGodBeastInfoRequest(activityId) isClear = false end end end end if isClear then CTL.GodBeastActivity.ShutDownPartActivityView() end end --- 打开神兽活动喂养界面请求信息 function private.GetGodBeastInfoRequest(activityId) local msg = activity_god_beast_op_pb.GetGodBeastInfoReq() msg.activityId = activityId NetManager.SendMessage(MessageEnums.MessageGetGodBeastInfo, msg) end function private.GetGodBeastInfoResponse(msgResp) if msgResp.Resp.Code == 0 then if msgResp.activityId > 0 then private.SetHorseRearInfo(msgResp) else CTL.GodBeastActivity.ShutDownPartActivityView() end EventSystem.Dispatch(EventID.UI_GodBeastActivity_InfoUpdate) end end --- 神兽活动喂养请求 function GodBeastActivity_Model.BeastRearRequest(activityId, times) local msg = activity_god_beast_op_pb.BeastRearReq() msg.activityId = activityId msg.times = times MDL.Reward.SetCloseRewardTipShow(true) NetManager.SendMessage(MessageEnums.MessageBeastRear, msg) end function private.BeastRearResponse(msgResp) if msgResp.Resp.Code == 0 then local newLevel = msgResp.lv local oldLevel = private.GodBeastInfoList[msgResp.activityId].rearLevel private.GodBeastInfoList[msgResp.activityId].curExpNum = msgResp.exp private.GodBeastInfoList[msgResp.activityId].rearLevel = newLevel private.GodBeastInfoList[msgResp.activityId].canChoose = msgResp.canChoose private.GodBeastInfoList[msgResp.activityId].chooseId = msgResp.chooseId EventSystem.Dispatch(EventID.UI_GodBeastActivity_PlayEventPerform, msgResp, oldLevel, newLevel) EventSystem.Dispatch(EventID.UI_GodBeastActivity_InfoUpdate) end MDL.Reward.SetCloseRewardTipShow(false) end --- 神兽活动领取登记奖励请求 function GodBeastActivity_Model.BeastLevelRewardRequest(activityId) local msg = activity_god_beast_op_pb.BeastLvRwdReq() msg.activityId = activityId NetManager.SendMessage(MessageEnums.MessageBeastLvRwd, msg) end function private.BeastLevelRewardResponse(msgResp) if msgResp.Resp.Code == 0 then for i, v in ipairs(msgResp.lvRwds) do private.GodBeastInfoList[msgResp.activityId].rearLevelRewards[v] = true end EventSystem.Dispatch(EventID.UI_GodBeastActivity_InfoUpdate) end end ---选择心愿神兽 function GodBeastActivity_Model.ChooseRewardBeastReq(activityId, beastId) local msg = activity_god_beast_op_pb.ChooseRewardBeastReq() msg.activityId = activityId msg.beastId = beastId NetManager.SendMessage(MessageEnums.MessageChooseRewardBeast, msg) end function private.ChooseRewardBeastResp(msgResp) if msgResp.Resp.Code == 0 then private.GodBeastInfoList[msgResp.activityId].canChoose = msgResp.canChoose private.GodBeastInfoList[msgResp.activityId].chooseId = msgResp.chooseId EventSystem.Dispatch(EventID.UI_GodBeastActivity_ChooseGodBeast) CTL.Tips.AddTipsMsg(Const_IDS["IDS_OptionalHorseAndTreasure_Title22"]) end end --endregion ***************** 协议 ******************** return GodBeastActivity_Model