local Hegemony_Controller = {} local private = {} local EventSystem = require('Event/EventSystem') ---红点 local HegemonyScoreReward = "HegemonyScoreReward" Hegemony_Controller.HegemonyRpEventId = { TownHome = "Hegemony_TownHome", --主城界面红点 NewDay = "Hegemony_NewDay", --新开启一天有一个红点 Group = "Hegemony_Group", --该组有红点 ScoreReward = "Hegemony_ScoreReward", --当前组可领取积分奖励 Day = "Hegemony_Day", --该天有红点 Page = "Hegemony_Page", --该页签有红点 Task = "Hegemony_Task", --该任务可领取奖励 } function Hegemony_Controller.OnStartup() EventSystem.Regist(EventID.UI_OperationActivity_DataChanged, private.RefreshHegemonyRedTree) EventSystem.Regist(EventID.UI_OperationActivity_InfoChanged, private.RefreshHegemonyRedTree) --EventSystem.Regist(EventID.UI_Hegemony_InfoRefresh, private.RefreshHegemonyRedTree) private.ActivityType = MDL.OperationActivity.ActivityType.Hegemony private.isInit = false private.hegemonyTimeHandle = nil end local function DispatchCloseEvent() EventSystem.Dispatch(EventID.UI_OperationActivity_InfoChanged) end function Hegemony_Controller.CheckCloseCountDown() if private.hegemonyTimeHandle then TimerUtil.Remove(private.hegemonyTimeHandle) end local leftTime = CTL.Hegemony.GetLeftTime() if leftTime > 0 then TimerUtil.Interval(DispatchCloseEvent, leftTime, 1) end end function Hegemony_Controller.CheckHasReward() for groupId, groupData in MDL.OperationActivity.HegemonyTab:GetEnumeratorByActivityID(MDL.Hegemony.GetHegemonyActivityId()) do if MDL.RedPoint.GetNodeStateByMultiKey(CTL.Hegemony.HegemonyRpEventId.TownHome, groupId) then return true end end return false end --region 红点相关 function Hegemony_Controller.InitHegemonyRedPointTree() if private.isInit then --检测是否已经初始化 return end --检查是否有活动需要的数据 if not MDL.OperationActivity.HegemonyParam or MDL.OperationActivity.HegemonyParam:GetDataLengthByActivityID(MDL.Hegemony.GetHegemonyActivityId()) == 0 then return end local townRoot = MDL.RedPoint.AddRootRpNode(Hegemony_Controller.HegemonyRpEventId.TownHome) townRoot:AddChildRpNode(Hegemony_Controller.HegemonyRpEventId.NewDay, Hegemony_Controller.HegemonyRpEventId.NewDay, nil, {Hegemony_Controller.HegemonyRpEventId.NewDay}, private.IsHegemonyNewDayUnlock()) local activityId = MDL.Hegemony.GetHegemonyActivityId() for groupId, groupData in MDL.OperationActivity.HegemonyTab:GetEnumeratorByActivityID(activityId) do local groupNode = townRoot:AddChildRpNode(Hegemony_Controller.HegemonyRpEventId.Group, groupId, {group = groupId}) groupNode:AddChildRpNode(Hegemony_Controller.HegemonyRpEventId.ScoreReward, HegemonyScoreReward, {group = groupId}, {groupId, Hegemony_Controller.HegemonyRpEventId.ScoreReward}, Hegemony_Controller.IsGroupHaveScoreRewardToCollect(groupId)) for dayId, dayData in pairs(groupData) do --如果是第二组开始,则dayId则不会从1开始,没有前后顺序要求,只有上下层级要求,所以可以用pairs local dayNode = groupNode:AddChildRpNode(Hegemony_Controller.HegemonyRpEventId.Day, dayId, {group = groupId, day = dayId}) for pageId, pageData in ipairs(dayData) do local pageNode = dayNode:AddChildRpNode(Hegemony_Controller.HegemonyRpEventId.Page, pageId, {group = groupId, day = dayId, page = pageId}) local taskDataList = MDL.OperationActivity.HegemonyParam:GetDataByActivityID_StageID_PageID_NumID(activityId, dayId, pageId) for taskIndex, taskData in ipairs(taskDataList) do local isHasReward = false local index = MDL.Hegemony.GetTaskIndexByData(taskData) local taskInfo = MDL.Hegemony.GetTaskInfo(dayId, pageId, index) if taskInfo and taskInfo.state == MDL.Hegemony.HegemonyTaskState.Finished then isHasReward = true end pageNode:AddChildRpNode(Hegemony_Controller.HegemonyRpEventId.Task, taskIndex, {group = groupId, day = dayId, page = pageId, task = taskData}, {dayId, pageId, index}, isHasReward) end end end end MDL.RedPoint.InitAllNodes(Hegemony_Controller.HegemonyRpEventId.TownHome) private.isInit = true end function private.RefreshHegemonyRedTree() local activityId = MDL.Hegemony.GetHegemonyActivityId() if not activityId or activityId == 0 then return end if not MDL.OperationActivity.HegemonyParam or MDL.OperationActivity.HegemonyParam:GetDataLengthByActivityID(activityId) == 0 then logging.error(LTAG.ERROR, "ActivityId为:", activityId, "的霸业之始hot3Param表找不到或没有数据了!!!") return end if not private.isInit then Hegemony_Controller.InitHegemonyRedPointTree() end if next(MDL.Hegemony.GetHegemonyInfo()) then for groupId, groupData in MDL.OperationActivity.HegemonyTab:GetEnumeratorByActivityID(activityId) do MDL.RedPoint.UpdateNodeStateByLogicParams(Hegemony_Controller.IsGroupHaveScoreRewardToCollect(groupId), Hegemony_Controller.HegemonyRpEventId.TownHome, groupId, Hegemony_Controller.HegemonyRpEventId.ScoreReward) for dayId, dayData in pairs(groupData) do --如果是第二组开始,则dayId则不会从1开始,没有前后顺序要求,只有上下层级要求,所以可以用pairs for pageId, pageData in ipairs(dayData) do local taskDataList = MDL.OperationActivity.HegemonyParam:GetDataByActivityID_StageID_PageID_NumID(activityId, dayId, pageId) for taskIndex, taskData in ipairs(taskDataList) do local isHasReward = false local index = MDL.Hegemony.GetTaskIndexByData(taskData) local taskInfo = MDL.Hegemony.GetTaskInfo(dayId, pageId, index) if taskInfo and taskInfo.state == MDL.Hegemony.HegemonyTaskState.Finished then isHasReward = true end MDL.RedPoint.UpdateNodeStateByLogicParams(isHasReward, Hegemony_Controller.HegemonyRpEventId.TownHome, dayId, pageId, index) end end end end MDL.RedPoint.UpdateNodeStateByLogicParams(private.IsHegemonyNewDayUnlock(), Hegemony_Controller.HegemonyRpEventId.TownHome, Hegemony_Controller.HegemonyRpEventId.NewDay) else logging.error(LTAG.ERROR, "霸业之始活动的ActivityId:", activityId, "不正确了!或霸业之始玩家信息数据没有,", MDL.Hegemony.GetHegemonyInfo()) end end --endregion --region 逻辑判断代码 local HegemonyNewDay = "HegemonyNewDay" --是否新的一天解锁了 function private.IsHegemonyNewDayUnlock() local dayNums = #MDL.Hegemony.GetHegemonyInfo() local oldNums = PersistentData.PlayerData:Get(HegemonyNewDay,0) return dayNums > oldNums end function Hegemony_Controller.SetHegemonyNewDayValue() local dayNums = #MDL.Hegemony.GetHegemonyInfo() PersistentData.PlayerData:Set(HegemonyNewDay, dayNums, true) MDL.RedPoint.UpdateNodeStateByLogicParams(private.IsHegemonyNewDayUnlock(), Hegemony_Controller.HegemonyRpEventId.TownHome, Hegemony_Controller.HegemonyRpEventId.NewDay) end function Hegemony_Controller.GetLeftTime() local info = MDL.OperationActivity.GetOperationActivityInfo(private.ActivityType, MDL.Hegemony.GetHegemonyActivityId()) return info and info.endTime - UTL.Time.GetServerTimestamp() or 0 end --获得默认选中组的逻辑 function Hegemony_Controller.GetDefaultSelectGroup() local groupData = MDL.OperationActivity.HegemonyTab:GetDataByActivityID_GroupID_StageID_PageID(MDL.Hegemony.GetHegemonyActivityId()) --优先选中有红点的组 for group, v in ipairs(groupData) do local isShowRp = MDL.RedPoint.GetNodeStateByMultiKey(Hegemony_Controller.HegemonyRpEventId.TownHome, group) if isShowRp then return group end end --优先选中还有任务没有完成的组 for group, v in ipairs(groupData) do local isFinished = Hegemony_Controller.IsGroupFinished(group) if not isFinished then return group end end return MDL.Hegemony.GetGroupIdByDay(#MDL.Hegemony.GetHegemonyInfo()) end function Hegemony_Controller.GetDefaultSelectDay(group) local groupDayNum = MDL.Hegemony.GetDayNumInGroup(group) local beforeDayNum = MDL.Hegemony.GetDayNumBeforeGroup(group) for i = 1, groupDayNum do local day = beforeDayNum + i local isShowRp = MDL.RedPoint.GetNodeStateByMultiKey(Hegemony_Controller.HegemonyRpEventId.TownHome, group, day) if isShowRp then return day end end for i = 1, groupDayNum do local day = beforeDayNum + i local isFinished = Hegemony_Controller.IsDayFinished(day) if not isFinished then return day end end return #MDL.Hegemony.GetHegemonyInfo() end function Hegemony_Controller.GetDefaultSelectPage(day) local dayData = MDL.OperationActivity.HegemonyTab:GetDataByActivityID_GroupID_StageID_PageID(MDL.Hegemony.GetHegemonyActivityId(), MDL.Hegemony.GetGroupIdByDay(day), day) for pageId, v in ipairs(dayData) do local page = pageId local isShowRp = MDL.RedPoint.GetNodeStateByMultiKey(Hegemony_Controller.HegemonyRpEventId.TownHome, MDL.Hegemony.GetGroupIdByDay(day), day, page) if isShowRp then return page end end for pageId, v in ipairs(dayData) do local isFinished = Hegemony_Controller.IsPageFinished(v.StageID, v.PageID) if not isFinished then return pageId end end return 1 end --组是否解锁 function Hegemony_Controller.IsGroupUnlock(group) local groupData = MDL.OperationActivity.HegemonyBackGround:GetDataByActivityID(MDL.Hegemony.GetHegemonyActivityId()).Group_Table local data = groupData[group] if data then if MDL.Hegemony.GetDayInfo(data.OpenDay) then return true end end return false end --活动积分是否有奖励可以领取 function Hegemony_Controller.IsGroupHaveScoreRewardToCollect(group) local score = MDL.Hegemony.GetScoreByGroupId(group) local scoreRewardInfo = MDL.Hegemony.GetScoreInfoByGroupId(group) local pointData = MDL.OperationActivity.HegemonyPoints:GetDataByActivityID_GroupID_StageID(MDL.Hegemony.GetHegemonyActivityId(), group) for i, v in ipairs(pointData) do if score >= v.NeedPoint and not scoreRewardInfo[i] then return true end end return false end --该页签任务是否全部完成 function Hegemony_Controller.IsPageFinished(day, page) local pageData = MDL.OperationActivity.HegemonyParam:GetDataByActivityID_StageID_PageID_NumID(MDL.Hegemony.GetHegemonyActivityId(), day, page) for i, v in ipairs(pageData) do local taskInfo = MDL.Hegemony.GetTaskInfo(v.StageID, v.PageID, i - 1) if taskInfo and taskInfo.state ~= MDL.Hegemony.HegemonyTaskState.Claimed then return false end end return true end --该天任务是否全部完成 function Hegemony_Controller.IsDayFinished(day) local dayData = MDL.OperationActivity.HegemonyTab:GetDataByActivityID_GroupID_StageID_PageID(MDL.Hegemony.GetHegemonyActivityId(), MDL.Hegemony.GetGroupIdByDay(day), day) for i, v in ipairs(dayData) do if not Hegemony_Controller.IsPageFinished(v.StageID, v.PageID) then return false end end return true end --该组的所有天的任务是否全部完成 function Hegemony_Controller.IsGroupFinished(group) local groupDayNum = MDL.Hegemony.GetDayNumInGroup(group) local beforeDayNum = MDL.Hegemony.GetDayNumBeforeGroup(group) for i = 1, groupDayNum do local day = beforeDayNum + i if not MDL.Hegemony.GetDayInfo(day) or not Hegemony_Controller.IsDayFinished(day) then return false end end return true end --endregion --region Trigger处理相关 local DigTreasureAnyTypeIDS = 3 local TeamPveAnyDungeonIDS = "IDS_HorseActivity_Task_TeamDungeon" ---此方法用于运营活动的HotGenCondID表使用,仅索引到TriggerType表 ---@param progress 目前的进度(有此参数说明要显示成m/n) ---@param isColorProgress 是否将进度数字变色 ---不需要特殊处理的,现在默认进度会填充在第一个位置,需要特殊处理的就特殊处理 function Hegemony_Controller.GetTriggerContentById(conditionId, progress, isColorProgress) local conditionData = MDL.OperationActivity.HotGenCondID:GetDataByCondID(conditionId) --目前都只有一个条件,所以临时写成[1] local data = conditionData.Task_Table[1] return private.GetTriggerContent(data.Trigger, progress, isColorProgress, data.Param1, data.Param2) end function private.GetTriggerContent(triggerId, progress, isColorProgress, ...) local data = DataSheetManager.TriggerType:GetDataByID(triggerId) local sourceId = data.ItemSourceID local targetParam = select(1, ...) local param1 = tonumber(targetParam) local strParam = {} if triggerId == LuaConst.TriggerType.MainLevel_Pass then table.insert(strParam, CTL.LevelSelect.GetLevelWholeNameById(param1)) targetParam = 1 elseif triggerId == LuaConst.TriggerType.Team_Level then -- 战队等级 table.insert(strParam, UTL.Item.GetNobilityByTeamLevel(param1)) elseif triggerId == LuaConst.TriggerType.BossChallenge_Complete then local bossLevelData = DataSheetManager.BossChallengeLevel:GetDataByID(param1) local bossName = UIUtils.GetLocalizedTxt(Const_IDS[bossLevelData.BossName]) table.insert(strParam, bossName) targetParam = 1 elseif triggerId == LuaConst.TriggerType.HeroBiography_Complete then table.insert(strParam, UIUtils.GetLocalizedTxt(Const_IDS[DataSheetManager.HeroBiographyData:GetDataByID(param1).BiographyName])) targetParam = 1 elseif triggerId == LuaConst.TriggerType.ClimbTower_Level then table.insert(strParam, CTL.ClimbTower.GetClimbTowerProgressName(param1)) targetParam = 1 --elseif triggerId == LuaConst.UnlockConditionType.MaterialLevel then -- local resourceData = DataSheetManager.ResourcesChapterStage:GetDataByID(param1) -- local difficult = string.format(UIUtils.GetLocalizedTxt(Const_IDS[resourceData.StageName]), UIUtils.GetLocalizedTxt(Const_IDS["IDS_Number_Written_"..resourceData.StageNum])) -- local stageName = UIUtils.GetLocalizedTxt(Const_IDS[DataSheetManager.ActivityData:GetDataByID(resourceData.DungeonType).Activity]) -- table.insert(strParam, stageName .. difficult) -- targetParam = 1 --elseif triggerId == LuaConst.UnlockConditionType.GuildLevel then -- local guildData = DataSheetManager.GuildReputation:GetDataByID(param1) -- table.insert(strParam, UIUtils.GetLocalizedTxt(Const_IDS[guildData.Name])) elseif triggerId == LuaConst.TriggerType.WorldBoss_DefeatBoss or triggerId == LuaConst.TriggerType.ReuseWorldBoss_DefeatBoss then local bossData = DataSheetManager.WorldBoss:GetDataByID(param1) table.insert(strParam, UIUtils.GetLocalizedTxt(Const_IDS[bossData.WordBossName])) targetParam = 1 elseif triggerId == LuaConst.TriggerType.OfficialPosition_Level then local opData for i, v in DataSheetManager.OfficialPosition:GetEnumerator() do if v.GradeID == param1 then opData = v break end end local title = CTL.OfficialPosition.GetTitleFullTxt(opData) table.insert(strParam, title) targetParam = 1 elseif triggerId == LuaConst.TriggerType.PersonalBoss_FirstPass then local personalBossData = DataSheetManager.PersonalBoss:GetDataByID(param1) local name = UIUtils.GetLocalizedTxt(Const_IDS[personalBossData.WordBossName]) table.insert(strParam, name) targetParam = 1 elseif triggerId == LuaConst.TriggerType.Hero_WithQuality then local qualityId = tonumber(select(2, ...)) local qualityData = DataSheetManager.QualityColor:GetDataByID(qualityId) if progress then if isColorProgress then if progress >= param1 then strParam[1] = UTL.Color.FormatGreenColor(progress) .. "/" .. param1 else strParam[1] = UTL.Color.FormatRedColor(progress) .. "/" .. param1 end end else table.insert(strParam, param1) end table.insert(strParam, UIUtils.GetLocalizedTxt(Const_IDS[qualityData.ColorText])) elseif triggerId == LuaConst.TriggerType.Hero_WithAdvance then local advanceId = tonumber(select(2, ...)) local advancedData = DataSheetManager.HeroAdvance:GetDataByAdvanceID(advanceId) local title = string.format(UIUtils.GetLocalizedTxt(Const_IDS[advancedData.AdvanceDesc]), advancedData.Stage, advancedData.LightStar) if progress then if isColorProgress then if progress >= param1 then strParam[1] = UTL.Color.FormatGreenColor(progress) .. "/" .. param1 else strParam[1] = UTL.Color.FormatRedColor(progress) .. "/" .. param1 end end else table.insert(strParam, param1) end table.insert(strParam, title) elseif triggerId == LuaConst.TriggerType.Equipment_WithLevel then local level = tonumber(select(2, ...)) strParam[1] = param1 strParam[2] = UTL.Item.GetNobilityByTeamLevel(level) elseif triggerId == LuaConst.TriggerType.Equipment_WithQuality then local qualityId = tonumber(select(2, ...)) local qualityData = DataSheetManager.QualityColor:GetDataByID(qualityId) if progress then if isColorProgress then if progress >= param1 then strParam[1] = UTL.Color.FormatGreenColor(progress) .. "/" .. param1 else strParam[1] = UTL.Color.FormatRedColor(progress) .. "/" .. param1 end end else table.insert(strParam, param1) end table.insert(strParam, UIUtils.GetLocalizedTxt(Const_IDS[qualityData.ColorText])) elseif triggerId == LuaConst.TriggerType.Pve_PassTimes or triggerId == LuaConst.TriggerType.ReusePve_PassTimes then local pveId = tonumber(select(2, ...)) local name if pveId then name = UIUtils.GetLocalizedTxt(Const_IDS[DataSheetManager.TeamDungeonData:GetDataByID(pveId).DungeonName]) else name = UIUtils.GetLocalizedTxt(Const_IDS[TeamPveAnyDungeonIDS]) end if progress then if isColorProgress then if progress >= param1 then strParam[1] = UTL.Color.FormatGreenColor(progress) .. "/" .. param1 else strParam[1] = UTL.Color.FormatRedColor(progress) .. "/" .. param1 end end else table.insert(strParam, param1) end table.insert(strParam, name) elseif triggerId == LuaConst.TriggerType.Dig_TreasureTimes or triggerId == LuaConst.TriggerType.DigTreasureTimes_Count then local param2 = select(2, ...) if not tonumber(param2) then param2 = DigTreasureAnyTypeIDS end if progress then if isColorProgress then if progress >= param1 then strParam[1] = UTL.Color.FormatGreenColor(progress) .. "/" .. param1 else strParam[1] = UTL.Color.FormatRedColor(progress) .. "/" .. param1 end end else table.insert(strParam, param1) end table.insert(strParam, UIUtils.GetLocalizedTxt(Const_IDS["IDS_DigTreasure_LevelDes" .. param2])) elseif triggerId == LuaConst.TriggerType.SyncTeamPVP_ArriveRank then local name = UIUtils.GetLocalizedTxt(Const_IDS[DataSheetManager.ThreeBattleLevelData:GetDataByLevelID(param1).LevelName]) table.insert(strParam, name) targetParam = 1 elseif triggerId == LuaConst.TriggerType.ItemGained_Count or triggerId == LuaConst.TriggerType.ItemConsume_Count then local param2 = select(2, ...) local itemData = DataSheetManager.ItemData:GetDataByID(tonumber(param2)) if progress then if isColorProgress then if progress >= param1 then strParam[1] = UTL.Color.FormatGreenColor(progress) .. "/" .. param1 else strParam[1] = UTL.Color.FormatRedColor(progress) .. "/" .. param1 end end else table.insert(strParam, param1) end table.insert(strParam, UIUtils.GetLocalizedTxt(Const_IDS[itemData.Name])) elseif triggerId == LuaConst.TriggerType.SuperGold_PassLevel then local levelData = DataSheetManager.SuperGoldStoryLevel:GetDataByLevelID(param1) table.insert(strParam, UIUtils.GetLocalizedTxt(Const_IDS[levelData.BarrierName])) elseif triggerId == LuaConst.TriggerType.SuperGold_LevelEnding then for i, v in pairs(DataSheetManager.SuperGoldEndingRecord) do if v:GetDataByEndingID(param1) then table.insert(strParam, UIUtils.GetLocalizedTxt(Const_IDS[v:GetDataByEndingID(param1).EndingName])) break end end else strParam = table.pack(...) targetParam = (type(param1) == "string" or param1 == 0 or param1 == nil) and 1 or param1 ---不需要特殊处理的,现在默认进度会填充在第一个位置,需要特殊处理的就特殊处理 if progress then if isColorProgress then if progress >= param1 then strParam[1] = UTL.Color.FormatGreenColor(progress) .. "/" .. param1 else strParam[1] = UTL.Color.FormatRedColor(progress) .. "/" .. param1 end end end end local des = string.FormatByIdsKey(data.TaskDesText, unpack(strParam)) return targetParam, des, sourceId end --endregion return Hegemony_Controller