local GoldenHeroFame_Model = {} local private = {} local EventSystem = require 'Event/EventSystem' local operation_activity_gold_hero_pb = require 'Proto.operation_activity_gold_hero_pb' local operation_activity_info_pb = require 'Proto.operation_activity_info_pb' local SortFunction = function(a,b) if a.taskData.state == b.taskData.state then return a.Cfg.TaskID < b.Cfg.TaskID else return a.taskData.state < b.taskData.state end end function GoldenHeroFame_Model.OnStartup() NetManager.RegisterMsgCB(MessageEnums.MessageClaimGoldHeroTaskDataReward, private.ClaimGoldHeroTaskDataRewardResponse) NetManager.RegisterMsgCB(MessageEnums.MessageClaimAllGoldHeroTaskDataReward, private.ClaimAllGoldHeroTaskDataRewardResp) NetManager.RegisterMsgCB(MessageEnums.MessageClaimGoldHeroStateReward, private.ClaimGoldHeroStateRewardResponse) EventSystem.Regist(EventID.UI_OperationActivity_InfoChanged, private.RefreshFameRedPoint) EventSystem.Regist(EventID.AcquireSystemRedAfterUnlock, private.RefreshFameRedPoint) private.initRedPointList = {} -- 初始化红点树的活动ID数组 private.fameActivityDict = {} end function private.SplitConfig(activityID) local taskList = {} local heroType = MDL.GoldenHeroMain.GetHeroTypeByActivityId(activityID) for k,v in DataSheetManager.GoldHeroActivityTaskData[heroType]:GetEnumerator() do if not taskList[v.TabID] then taskList[v.TabID] = {} end local taskStateData = GoldenHeroFame_Model.GetTaskInfoByActivityID_TaskID(activityID, v.TaskID) if v.LastTask <= 0 then table.insert(taskList[v.TabID], {Cfg = v, taskData = taskStateData} ) elseif v.LastTask > 0 then local lastTaskStateData = GoldenHeroFame_Model.GetTaskInfoByActivityID_TaskID(activityID, v.LastTask) if lastTaskStateData then if lastTaskStateData.state == operation_activity_info_pb.StateReward then table.insert(taskList[v.TabID], {Cfg = v, taskData = taskStateData}) end else logging.error(LTAG.ERROR, "GoldHeroActivityTaskData表中上一个任务的taskId:", v.LastTask, " 找不到数据,请策划检查!!!") end end end for k,v in ipairs(taskList) do table.sort(v, SortFunction) end return taskList end function private.RefreshServerData() private.taskCfgList = {} for k,v in pairs(private.fameActivityDict) do private.taskCfgList[v.activityID] = private.SplitConfig(v.activityID) end end --region ******************* 外界获取数据 ********************** ---@return number 声名等级 ---@return number 声明经验 function GoldenHeroFame_Model.GetCurrentFameLevelIDAndExp(activityID, heroType) local fameData = private.fameActivityDict[activityID] if fameData then local cfgLevelExp = 0 for k,v in DataSheetManager.GoldHeroActivityTaskLevel[heroType]:GetEnumerator() do cfgLevelExp = cfgLevelExp + v.LevelExp if cfgLevelExp > fameData.totalExp then return v.LevelID - 1 , fameData.totalExp - (cfgLevelExp - v.LevelExp) elseif cfgLevelExp == fameData.totalExp then return v.LevelID , 0 end if k == DataSheetManager.GoldHeroActivityTaskLevel[heroType]:GetDataCount() and cfgLevelExp < fameData.totalExp then return v.LevelID , v.LevelExp end end else return 1, 0 end end ---@return boolean 是否可领奖 ------@return number 可领奖声名等级 function GoldenHeroFame_Model.HasReward(activityID, heroType) local fameData = private.fameActivityDict[activityID] if fameData then local cfgLevelExp = 0 local passLevelReward = #fameData.stages + 1 -- 1级没奖励,这里加1才是已领过奖励的等级 for k,v in DataSheetManager.GoldHeroActivityTaskLevel[heroType]:GetEnumerator() do cfgLevelExp = cfgLevelExp + v.LevelExp if v.LevelID > passLevelReward then if fameData.totalExp >= cfgLevelExp then return true, v.LevelID end end end return false, passLevelReward + 1 else return false, 1 end end function GoldenHeroFame_Model.GetTaskListByHeroType_TabID(activityID) return private.taskCfgList[activityID] end ---@return table 声明任务状态和进度 function GoldenHeroFame_Model.GetTaskInfoByActivityID_TaskID(activityID, taskID) local fameData = private.fameActivityDict[activityID] if fameData then for k,v in ipairs(fameData.taskDataInfos) do if v.taskID == taskID then return v end end else return {state = operation_activity_info_pb.StateDoing, process = 0} end end ---@return table 声明任务状态和进度 function GoldenHeroFame_Model.GetDesByTriggerID(triggerIDInfo, heroType) local data = triggerIDInfo if tonumber(data.UnlockConditionParamA) == heroType then local param = { data.UnlockConditionParamB } if data.UnlockCondition == LuaConst.TriggerType.GoldenHero_PassLevel then -- 金将体验关:通关金将活动关卡X(非历史) local levelType = DataSheetManager.GoldHeroActivityModeData:GetDataByHeroType(heroType).HeroLevelType if levelType == MDL.GoldenHeroMain.LevelType.Story then param[1] = UIUtils.GetLocalizedTxt(Const_IDS[DataSheetManager.GoldHeroActivityLevel:GetDataByID(tonumber(data.UnlockConditionParamB)).BarrierName]) else param[1] = MDL.GoldenHeroAnecdote.GetAnecdoteWholeName(tonumber(data.UnlockConditionParamB)) end elseif data.UnlockCondition == LuaConst.TriggerType.GoldenHero_PassEnding then -- 金将体验关:达成结局X(非历史) param[1] = UIUtils.GetLocalizedTxt(Const_IDS[DataSheetManager.GoldHeroEndingRecord:GetDataByEndingID(tonumber(param[1])).EndingName]) elseif data.UnlockCondition == LuaConst.TriggerType.GoldenHero_PassAnecdote then -- 金将体验关:通关金将轶事活动关卡X(非历史) param[1] = MDL.GoldenHeroAnecdote.GetAnecdoteWholeName(tonumber(param[1])) elseif data.UnlockCondition == LuaConst.TriggerType.GoldenHero_ParticipationModelBoss -- 金将体验关:累计参与X模板的Y次协同讨伐(非历史) or data.UnlockCondition == LuaConst.TriggerType.GoldenHero_FindModelBoss -- 金将体验关:累计发现X模板的Y次讨伐目标(非历史) or data.UnlockCondition == LuaConst.TriggerType.GoldenHero_GetModelBossScore -- 金将体验关:协同讨伐中累计获得X模板的Y积分(非历史) or data.UnlockCondition == LuaConst.TriggerType.GoldenHero_KillModelBoss -- 金将体验关:累计击杀讨伐目标X模板的Y次(非历史) or data.UnlockCondition == LuaConst.TriggerType.GoldenHero_PassModelLevel then -- 金将体验关:累计通关金将活动X模板的关卡Y次(非历史) param[1] = data.UnlockConditionParamB end return string.FormatByIdsKey(data.UnlockConditionDes, unpack(param)) end return nil end --endregion ******************* 外界获取数据 ********************** --region ******************* 红点 ********************** ---@return boolean 是否有声明等级奖励 function GoldenHeroFame_Model.GetLevelRewardRedPointByActivityID(activityID) local heroType = MDL.GoldenHeroMain.GetHeroTypeByActivityId(activityID) local isReward, _ = GoldenHeroFame_Model.HasReward(activityID, heroType) return isReward end ---@return boolean 是否有任务奖励 function GoldenHeroFame_Model.GetTaskRewardRedPointByActivityID(activityID) if private.fameActivityDict and private.fameActivityDict[activityID] then local fameData = private.fameActivityDict[activityID] for k,v in ipairs(fameData.taskDataInfos) do if v.state == operation_activity_info_pb.StateFinish then return true end end end return false end ---@return boolean 是否有任务奖励 function GoldenHeroFame_Model.GetTaskRewardRedPointByActivityID_TaskType(activityID, heroType, taskType) if private.fameActivityDict and private.fameActivityDict[activityID] then local fameData = private.fameActivityDict[activityID] local taskTypeData = GoldenHeroFame_Model.GetTaskListByHeroType_TabID(activityID)[taskType] for _,taskData in ipairs(taskTypeData) do for _,taskDataInfo in ipairs(fameData.taskDataInfos) do if taskDataInfo.taskID == taskData.Cfg.TaskID and taskDataInfo.state == operation_activity_info_pb.StateFinish then return true end end end end return false end --endregion ******************* 红点 ********************** --region ******************* 协议 ********************** ---@public 登录推送声名鹊起数据 function GoldenHeroFame_Model.SyncGoldHeroFameInfo(msgResp) for k, v in ipairs(msgResp) do local activityId = v.activityID if MDL.GoldenHeroMain.GetHeroTypeByActivityId(activityId) then private.fameActivityDict[activityId] = v if private.initRedPointList[activityId] then local isHasLevelReward = GoldenHeroFame_Model.GetLevelRewardRedPointByActivityID(activityId) MDL.RedPoint.UpdateNodeStateByLogicParams(isHasLevelReward, CTL.GoldenHeroMain.RpEventId[activityId].TownHome, CTL.GoldenHeroMain.RpEventId[activityId].FameLevelReward) local isHasTaskReward = GoldenHeroFame_Model.GetTaskRewardRedPointByActivityID(activityId) MDL.RedPoint.UpdateNodeStateByLogicParams(isHasTaskReward, CTL.GoldenHeroMain.RpEventId[activityId].TownHome, CTL.GoldenHeroMain.RpEventId[activityId].FameTaskReward) else CTL.GoldenHeroMain.InitFameRedPointTreeByActivityId(activityId) private.initRedPointList[activityId] = true end end end private.RefreshServerData() EventSystem.Dispatch(EventID.UI_GoldenHeroFame_RefreshMainPanel) end ---@public 声名鹊起领任务奖励 function GoldenHeroFame_Model.ClaimGoldHeroTaskDataRewardRequest(activityID, heroType, taskID) local msg = operation_activity_gold_hero_pb.ClaimGoldHeroTaskDataRewardReq() msg.ActivityID = activityID msg.HeroType = heroType msg.TaskID = taskID NetManager.SendMessage(MessageEnums.MessageClaimGoldHeroTaskDataReward, msg) end function private.ClaimGoldHeroTaskDataRewardResponse(msgResp) --logging.log(LTAG.LOG," ClaimGoldHeroTaskDataRewardResp ", msgResp) EventSystem.Dispatch(EventID.UI_GoldenHeroFame_RefreshMainPanel) end ---@public 声名鹊起一键领取任务奖励 function GoldenHeroFame_Model.ClaimAllGoldHeroTaskDataRewardReq(activityID, heroType) local msg = operation_activity_gold_hero_pb.ClaimAllGoldHeroTaskDataRewardReq() msg.ActivityID = activityID msg.HeroType = heroType NetManager.SendMessage(MessageEnums.MessageClaimAllGoldHeroTaskDataReward, msg) end function private.ClaimAllGoldHeroTaskDataRewardResp(msgResp) --logging.log(LTAG.LOG," ClaimGoldHeroTaskDataRewardResp ", msgResp) EventSystem.Dispatch(EventID.UI_GoldenHeroFame_RefreshMainPanel) end ---@public 声名鹊起领声明等级奖励 function GoldenHeroFame_Model.ClaimGoldHeroStateRewardRequest(activityID, heroType, stateID) local msg = operation_activity_gold_hero_pb.ClaimGoldHeroStateRewardReq() msg.ActivityID = activityID msg.HeroType = heroType msg.StateID = stateID NetManager.SendMessage(MessageEnums.MessageClaimGoldHeroStateReward, msg) end function private.ClaimGoldHeroStateRewardResponse(msgResp) --logging.log(LTAG.LOG," ClaimGoldHeroStateRewardResp ", msgResp) EventSystem.Dispatch(EventID.UI_GoldenHeroFame_RefreshMainPanel) end --endregion ******************* 协议 ********************** function private.RefreshFameRedPoint() for k,v in pairs(private.fameActivityDict) do local activityId = v.activityID if private.initRedPointList[activityId] then local isHasLevelReward = GoldenHeroFame_Model.GetLevelRewardRedPointByActivityID(activityId) MDL.RedPoint.UpdateNodeStateByLogicParams(isHasLevelReward, CTL.GoldenHeroMain.RpEventId[activityId].TownHome, CTL.GoldenHeroMain.RpEventId[activityId].FameLevelReward) local isHasTaskReward = GoldenHeroFame_Model.GetTaskRewardRedPointByActivityID(activityId) MDL.RedPoint.UpdateNodeStateByLogicParams(isHasTaskReward, CTL.GoldenHeroMain.RpEventId[activityId].TownHome, CTL.GoldenHeroMain.RpEventId[activityId].FameTaskReward) else CTL.GoldenHeroMain.InitFameRedPointTreeByActivityId(activityId) private.initRedPointList[activityId] = true end end end return GoldenHeroFame_Model