miduo_client/Assets/ManagedResources/~Lua/Modules/Task/TaskManager.lua

493 lines
19 KiB
Lua
Raw Normal View History

2021-04-20 13:58:00 +08:00
--[[
2020-05-09 13:31:21 +08:00
* @ClassName TaskManager
* @Description
* @Date 2019/6/5 10:54
* @Author MagicianJoker, fengliudianshao@outlook.com
* @Copyright Copyright (c) 2019, MagicianJoker
--]]
TaskManager = {}
local this = TaskManager
local TypeTaskData = {}
local SLrefreshTime = {}
--初始化
function this.Initialize()
for _, v in pairs(TaskTypeDef) do
TypeTaskData[v] = {}
end
this.LateUpdateTime = Time.realtimeSinceStartup
2020-05-09 13:31:21 +08:00
end
--missionId =1;
--progress =2; //进度
--state = 3; //0:未完成 1完成未领取 2已达成已领取
--type =4 ;// 任务类型 1vip任务 2每日任务 3: 4:孙龙的宝藏
function this.InitTypeTaskList(_userMissionList)
for i = 1, #_userMissionList do
local userMissionList ={}
userMissionList.missionId = _userMissionList[i].missionId
userMissionList.progress = _userMissionList[i].progress
userMissionList.state = _userMissionList[i].state
userMissionList.type = _userMissionList[i].type
userMissionList.takeTimes = _userMissionList[i].takeTimes
userMissionList.heroId = _userMissionList[i].heroId
2020-12-30 18:08:44 +08:00
userMissionList.lock = _userMissionList[i].lock
2021-12-29 20:17:45 +08:00
--LogRed("任务 类型:"..userMissionList.type.." ID:"..userMissionList.missionId.." 状态:"..userMissionList.state.." lock "..userMissionList.lock.. " progress:".._userMissionList[i].progress)
2020-08-21 18:30:44 +08:00
if not TypeTaskData[_userMissionList[i].type] then
TypeTaskData[_userMissionList[i].type] = {}
end
2020-05-09 13:31:21 +08:00
table.insert(TypeTaskData[_userMissionList[i].type], userMissionList)
--this.AddTypeData(_userMissionList[i].type, userMissionList)
end
2021-03-24 17:06:20 +08:00
Game.GlobalEvent:DispatchEvent(GameEvent.Mission.NiuQiChongTianTask)
2020-05-09 13:31:21 +08:00
end
--function this.AddTypeData(type, data)
-- if TypeTaskData[type] then
-- table.insert(TypeTaskData[type], data)
-- end
--end
--任务数据重置
function this.ResetTaskData(type)
TypeTaskData[type] = {}
end
--初始化拉去并设定本地type类型的任务数据
function this.SetTypeTaskList(type, data)
TypeTaskData[type] = {}
for i = 1, #data do
2020-05-25 19:16:23 +08:00
local t ={}
t.missionId = data[i].missionId
t.progress = data[i].progress
t.state = data[i].state
t.type = data[i].type
t.takeTimes = data[i].takeTimes
t.heroId = data[i].heroId
2020-12-30 18:08:44 +08:00
t.lock = data[i].lock
2020-05-25 19:16:23 +08:00
table.insert(TypeTaskData[type], t)
2021-05-25 20:37:12 +08:00
-- --LogRed("任务 类型:"..data[i].type.." 类型:"..data[i].missionId.." 状态:"..data[i].state)
2020-05-09 13:31:21 +08:00
end
this.SetDirty()
2020-05-09 13:31:21 +08:00
end
2020-06-03 19:09:01 +08:00
local achievementConfig = ConfigManager.GetConfig(ConfigName.AchievementConfig)
local curShowAllAchievementData = {}
local curShowAllOkAchievementData = {}
--获取本地存储的type任务类型数据 前端展示用 红点检测用 飘弹窗提示用
function this.GetCurShowAllAchievementData(type)
curShowAllAchievementData = {}
curShowAllOkAchievementData = {}
if TypeTaskData[type] then
for i = 1, #TypeTaskData[type] do
local curTaskData = TypeTaskData[type][i]
if TypeTaskData[type][i].state == 2 then
curShowAllOkAchievementData[curTaskData.missionId] = curTaskData
end
end
for i = 1, #TypeTaskData[type] do
local curTaskData = TypeTaskData[type][i]
local curTaskConFigData = achievementConfig[curTaskData.missionId]
2021-01-05 20:44:14 +08:00
-- --LogGreen("curTaskData.missionId `````1 "..curTaskData.missionId)
2020-06-03 19:09:01 +08:00
if ActTimeCtrlManager.SingleFuncState(curTaskConFigData.RefSysId) then
2021-01-05 20:44:14 +08:00
--LogGreen("curTaskData.missionId `````2 "..curTaskData.missionId.." curTaskData.state "..curTaskData.state)
2020-06-03 19:09:01 +08:00
if curTaskConFigData.PreId == -1 or curShowAllOkAchievementData[curTaskConFigData.PreId] then
if curTaskData.state ~= 2 then
-- --LogGreen("curTaskData.missionId "..curTaskData.missionId)
2020-06-03 19:09:01 +08:00
curShowAllAchievementData[curTaskData.missionId] = curTaskData
end
end
end
end
return curShowAllAchievementData
else
Log("type类型错误未定义或未初始化查询不到数据:" .. type)
2020-06-03 19:09:01 +08:00
end
end
2020-05-09 13:31:21 +08:00
--获取本地存储的type任务类型数据
function this.GetTypeTaskList(type)
if TypeTaskData[type] then
return TypeTaskData[type]
else
Log("type类型错误未定义或未初始化查询不到数据:" .. type)
2020-05-09 13:31:21 +08:00
end
end
--获取对应type类型任务和对应Id的数据信息
function this.GetTypeTaskInfo(type, Id)
for _, taskInfo in pairs(TypeTaskData[type]) do
if taskInfo.missionId == Id then
return taskInfo
end
end
Log(string.format("未找到任务类型为%s任务Id为%s的数据请检查服务器数据信息", type, Id))
2020-05-09 13:31:21 +08:00
return nil
end
--(客户端领取任务奖励调用)设定对应type类型任务和对应Id的状态信息state,不存在progress的设定情况
function this.SetTypeTaskState(type, Id, state, progress, takeTimes,heroId)
for _, taskInfo in pairs(TypeTaskData[type]) do
if taskInfo.missionId == Id then
taskInfo.state = state
if progress then
taskInfo.progress = progress
end
if takeTimes then
taskInfo.takeTimes = takeTimes
end
taskInfo.heroId = heroId
end
end
this.SetDirty()
2020-05-09 13:31:21 +08:00
Game.GlobalEvent:DispatchEvent(GameEvent.MissionDaily.OnMissionDailyChanged)
Game.GlobalEvent:DispatchEvent(GameEvent.DynamicTask.OnMissionChange)
2021-03-24 17:06:20 +08:00
Game.GlobalEvent:DispatchEvent(GameEvent.Mission.NiuQiChongTianTask)
2021-05-21 16:39:08 +08:00
Game.GlobalEvent:DispatchEvent(GameEvent.EndLess.MissonChange)
2020-05-09 13:31:21 +08:00
end
function this.SetMissionIdState(type, Id, state)
for _, taskInfo in pairs(TypeTaskData[type]) do
if taskInfo.missionId == Id then
taskInfo.state = state
end
end
end
--(后台推送刷新调用)
2020-12-30 18:08:44 +08:00
function this.SetTypeTaskInfo(type, Id, state, progress, takeTimes,heroId,lock)
2020-08-21 11:23:46 +08:00
if not TypeTaskData[type] then
TypeTaskData[type] = {}
end
2020-05-09 13:31:21 +08:00
local index = table.keyvalueindexof(TypeTaskData[type], "missionId", Id)
if not index then
--整体清空重载数据
table.insert(TypeTaskData[type], {
missionId = Id,
progress = progress,
state = state,
type = type,
takeTimes = takeTimes,
heroId = heroId,
2020-12-30 18:08:44 +08:00
lock = lock,
2020-05-09 13:31:21 +08:00
})
else
--部分数据刷新
for _, taskInfo in pairs(TypeTaskData[type]) do
if taskInfo.missionId == Id then
-- 发送副本成就完成事件
if type == TaskTypeDef.EliteCarbonTask then
if taskInfo.state == VipTaskStatusDef.NotFinished and state == VipTaskStatusDef.CanReceive then
Game.GlobalEvent:DispatchEvent(GameEvent.EliteAchieve.OnAchieveDone, Id)
end
end
taskInfo.state = state
taskInfo.progress = progress
taskInfo.takeTimes = takeTimes
2020-12-30 18:08:44 +08:00
taskInfo.lock = lock
2020-05-09 13:31:21 +08:00
--taskInfo.heroId = heroId
--taskInfo.heroId = {}
--for i = 1, #heroId do
-- table.insert(taskInfo.heroId,heroId[i])
--end
end
end
end
if type == TaskTypeDef.SevenDayCarnival then
SevenDayCarnivalManager.CheckScoreChange(Id, progress)
2020-06-03 19:09:01 +08:00
elseif type == TaskTypeDef.DayTask or type == TaskTypeDef.Achievement then--推送时检测 是否达成 飘弹窗提示
2020-06-13 11:47:13 +08:00
this.SetAllShowTipMission(type, Id, state)
2020-05-09 13:31:21 +08:00
end
this.SetDirty()
2020-05-09 13:31:21 +08:00
end
--刷新本地的任务数据
function this.RefreshTypeTaskInfo(taskInfoList)
for i = 1, #taskInfoList do
local taskInfo = taskInfoList[i]
2021-12-29 20:17:45 +08:00
--LogRed("服务器推送任务刷新type:"..taskInfo.type.."missionId:"..taskInfo.missionId.."state:"..taskInfo.state.."progress:"..taskInfo.progress.."takeTimes:"..taskInfo.takeTimes)
2020-12-30 18:08:44 +08:00
this.SetTypeTaskInfo(taskInfo.type, taskInfo.missionId, taskInfo.state, taskInfo.progress, taskInfo.takeTimes,taskInfo.heroId,taskInfo.lock)
2020-05-09 13:31:21 +08:00
end
Game.GlobalEvent:DispatchEvent(GameEvent.MissionDaily.OnMissionDailyChanged)
2020-09-23 17:41:48 +08:00
Game.GlobalEvent:DispatchEvent(GameEvent.DynamicTask.OnMissionChange)
2021-03-24 17:06:20 +08:00
Game.GlobalEvent:DispatchEvent(GameEvent.Mission.NiuQiChongTianTask)
2021-05-21 16:39:08 +08:00
Game.GlobalEvent:DispatchEvent(GameEvent.EndLess.MissonChange)
this.SetDirty()
2020-05-09 13:31:21 +08:00
end
-- 返回已经完成的成就数量和总数量
function this.GetAchiveNum(mapId)
local totalNum = 0
local doneNum = 0
2021-04-02 14:46:31 +08:00
-- local taskInfoList = ConfigManager.GetAllConfigsDataByKey(ConfigName.AccomplishmentConfig, "MapId", mapId)
-- for _, data in ipairs(taskInfoList) do
-- local taskData = TaskManager.GetTypeTaskInfo(TaskTypeDef.EliteCarbonTask, data.id)
-- if taskData then
-- totalNum = totalNum + 1
-- if taskData.state > 0 then
-- doneNum = doneNum + 1
-- end
-- end
-- end
2020-05-09 13:31:21 +08:00
return doneNum, totalNum
end
function this.SetDirty()
this.isRedDirty = true
this.LateUpdateTime = Time.realtimeSinceStartup
end
-- 生命周期函数
-- override
function this.LateUpdate()
if this.isRedDirty and Time.realtimeSinceStartup - this.LateUpdateTime > 1 then
this.ChangeVipRedPointState()
this.isRedDirty = false
end
end
2020-05-09 13:31:21 +08:00
-- 检测红点状态
function this.ChangeVipRedPointState()
CheckRedPointStatus(RedPointType.VipPrivilege)
CheckRedPointStatus(RedPointType.DailyTask)
2020-10-21 18:24:17 +08:00
--CheckRedPointStatus(RedPointType.TreasureOfSl)
2020-05-09 13:31:21 +08:00
CheckRedPointStatus(RedPointType.SevenDayCarnival)
2020-06-03 19:09:01 +08:00
CheckRedPointStatus(RedPointType.Achievement_Main)
2020-08-20 17:36:19 +08:00
CheckRedPointStatus(RedPointType.QinglongSerectTreasureTrail)
CheckRedPointStatus(RedPointType.QinglongSerectTreasure)
2021-07-24 18:16:05 +08:00
CheckRedPointStatus(RedPointType.DynamicActTask_MeiZhou)
CheckRedPointStatus(RedPointType.DynamicActTask_MeiRi)
2021-05-21 16:39:08 +08:00
CheckRedPointStatus(RedPointType.wujinMission)
2021-06-02 11:08:03 +08:00
CheckRedPointStatus(RedPointType.EndlessPanel)
2020-06-03 19:09:01 +08:00
--CheckRedPointStatus(RedPointType.Achievement_One)
--CheckRedPointStatus(RedPointType.Achievement_Two)
--CheckRedPointStatus(RedPointType.Achievement_Three)
--CheckRedPointStatus(RedPointType.Achievement_Four)
--CheckRedPointStatus(RedPointType.Achievement_Five)
2020-05-09 13:31:21 +08:00
--CheckRedPointStatus(RedPointType.HeroExplore)
end
function this.GetVipRedPointState()
local redPointStatus = false
local taskListInfo = this.GetTypeTaskList(TaskTypeDef.VipTask)
local taskFinishNum = 0
for i = 1, #taskListInfo do
if taskListInfo[i].state == VipTaskStatusDef.CanReceive then
redPointStatus = redPointStatus or true
elseif taskListInfo[i].state == VipTaskStatusDef.Received then
taskFinishNum = taskFinishNum + 1
end
end
redPointStatus = redPointStatus or taskFinishNum >= #taskListInfo
if taskFinishNum==0 and #taskListInfo==0 then --特殊处理
redPointStatus=false
end
if VipManager.GetTakeLevelBoxStatus() == GiftReceivedStatus.NotReceive then
redPointStatus = redPointStatus or true
end
if VipManager.GetTakeDailyBoxStatus() == -1 then
redPointStatus = redPointStatus or true
end
return redPointStatus
end
--获取当前主线任务数据
function this.GetMianTaskCurActiveTaskData()
local allMainTask = TypeTaskData[TaskTypeDef.MainTask]
if not allMainTask then
return
end
table.sort(allMainTask, function(a, b)
return a.missionId < b.missionId
end)
for _, taskInfo in pairs(TypeTaskData[TaskTypeDef.MainTask]) do
if taskInfo.state == 0 or taskInfo.state == 1 then
--Log("&&&&& 当前主线任务 id 进度 " .. taskInfo.missionId .. " " .. taskInfo.progress)
return taskInfo
end
end
return nil
end
function this.ResetTreasureTaskInfo(taskList)
--type,tasks
for i = 1, #taskList do
local taskInfoList = TypeTaskData[TaskTypeDef.TreasureOfSomeBody]
for k = #taskInfoList, 1, -1 do
2020-10-15 18:18:46 +08:00
if taskInfoList[k].missionId == 0 then
2021-05-25 20:37:12 +08:00
--LogRed("服务器传来了id为0的青龙秘宝任务")
2020-10-15 18:18:46 +08:00
else
local taskConfig = ConfigManager.GetConfigData(ConfigName.TreasureSunLongTaskConfig, taskInfoList[k].missionId)
if taskConfig.Type == taskList[i].type then
table.remove(TypeTaskData[TaskTypeDef.TreasureOfSomeBody], k)
end
2020-05-09 13:31:21 +08:00
end
end
2020-08-27 14:53:27 +08:00
table.insert(TypeTaskData[TaskTypeDef.TreasureOfSomeBody], taskList[i].tasks[i])
2020-05-09 13:31:21 +08:00
end
2020-09-23 17:41:48 +08:00
Game.GlobalEvent:DispatchEvent(GameEvent.DynamicTask.OnMissionChange)
2020-08-27 14:53:27 +08:00
CheckRedPointStatus(RedPointType.QinglongSerectTreasureTrail)
CheckRedPointStatus(RedPointType.QinglongSerectTreasure)
2020-05-09 13:31:21 +08:00
end
--迷宫寻宝前端刷新任务自行赋值
function this.RefreshFindTreasureData(msg)
TypeTaskData[TaskTypeDef.FindTreasure] = {}
--整体清空重载数据
for i = 1, #msg.infos do
table.insert(TypeTaskData[TaskTypeDef.FindTreasure], {
missionId = msg.infos[i].missionId,
progress = msg.infos[i].progress,
state = msg.infos[i].state,
type = msg.infos[i].type,
takeTimes = msg.infos[i].takeTimes,
heroId = msg.infos[i].heroId,
2020-12-30 18:08:44 +08:00
lock = msg.infos[i].lock,
2020-05-09 13:31:21 +08:00
})
end
end
--迷宫寻宝前端派遣自行赋值
function this.RefreshFindTreasureHerosData(missionId,heroIds,progress)
for _, taskInfo in pairs(TypeTaskData[TaskTypeDef.FindTreasure]) do
if taskInfo.missionId == missionId then
--for i = 1, #heroIds do
-- taskInfo.heroId:append(heroIds[i])
--end
taskInfo.heroId = heroIds
taskInfo.progress = GetTimeStamp() + progress
end
end
end
--迷宫寻宝前端派遣自行赋值
function this.RefreshFindTreasureStatrData(missionId,state)
for _, taskInfo in pairs(TypeTaskData[TaskTypeDef.FindTreasure]) do
if taskInfo.missionId == missionId then
taskInfo.state = state
if state == 2 then--已领取
taskInfo.heroId = {}
end
end
end
Game.GlobalEvent:DispatchEvent(GameEvent.FindTreasure.RefreshFindTreasureRedPot)
2020-07-16 18:01:03 +08:00
CheckRedPointStatus(RedPointType.SecretTer_FindTreasure)
2020-05-09 13:31:21 +08:00
end
2020-12-30 18:08:44 +08:00
--迷宫寻宝前端派遣自行赋值
function this.RefreshFindTreasureStatrData2(missionId,lockState)
for _, taskInfo in pairs(TypeTaskData[TaskTypeDef.FindTreasure]) do
if taskInfo.missionId == missionId then
taskInfo.lock = lockState
end
end
end
2020-05-09 13:31:21 +08:00
--刷新下可领取状态
function this.SetFindTreasureDataState()
for _, taskInfo in pairs(TypeTaskData[TaskTypeDef.FindTreasure]) do
if taskInfo.state == 0 and #taskInfo.heroId > 0 then--未完成 已派遣
local timeDown = taskInfo.progress - GetTimeStamp()
if timeDown <= 0 then
taskInfo.state = 1
end
end
end
end
--孙龙宝藏时间数据
function this.SetSLrefreshTime(msg)
SLrefreshTime = {dayTime = msg.dayTime,weekTime = msg.weekTime}--,monthTime = msg.monthTime} 月时间就是活动结束时间
end
function this.SetSLrefreshTime2(type,refreshTime)
if type == 1 then
SLrefreshTime.dayTime = refreshTime
elseif type == 2 then
SLrefreshTime.weekTime = refreshTime
end
end
function this.GetSLrefreshTime()
if LengthOfTable(SLrefreshTime) <=0 then
return nil
end
local actInfo = ActivityGiftManager.GetActivityTypeInfo(ActivityTypeDef.TreasureOfSomeBody)
if not actInfo then
return nil
end
SLrefreshTime.monthTime = actInfo.endTime
return SLrefreshTime
end
--检测成就红点
2020-06-03 19:09:01 +08:00
function this.GetAchievementState()
local AllData = TaskManager.GetCurShowAllAchievementData(TaskTypeDef.Achievement)
for i, v in pairs(AllData) do
if v then
if v.state == 1 then
return true
2020-05-09 13:31:21 +08:00
end
end
end
return false
end
2020-06-13 11:47:13 +08:00
local allShowTipMission = {}
function this.SetAllShowTipMission(_type, _Id, _state)
--LogGreen("_type, _Id, _state ".._type.." ".._Id.." ".._state)
if _state == 1 then--刚刚完成
2020-06-03 19:09:01 +08:00
if ActTimeCtrlManager.SingleFuncState(FUNCTION_OPEN_TYPE.Achiecement) and ActTimeCtrlManager.SingleFuncState(FUNCTION_OPEN_TYPE.MISSIONDAILY) then
2020-06-13 11:47:13 +08:00
if _type == TaskTypeDef.DayTask then
local curConfig = ConfigManager.TryGetConfigData(ConfigName.DailyTasksConfig,_Id)
2020-06-05 16:16:22 +08:00
if curConfig and curConfig.SortId ~= 2 then
-- --LogGreen("ADD ".._type.." ".._Id.." ".._state)
2020-06-13 11:47:13 +08:00
table.insert(allShowTipMission,{type = _type,Id = _Id,state = _state})
this.RefreshShowDailyMissionTipPanel()
2020-06-03 19:09:01 +08:00
end
end
2020-06-13 11:47:13 +08:00
if _type == TaskTypeDef.Achievement then
--if curShowAllAchievementData[_Id] then
-- --LogGreen("ADD ".._type.." ".._Id.." ".._state)
2020-06-13 11:47:13 +08:00
table.insert(allShowTipMission,{type = _type,Id = _Id,state = _state})
this.RefreshShowDailyMissionTipPanel()
--end
end
end
end
end
function this.RefreshShowDailyMissionTipPanel()
if #allShowTipMission > 0 and not UIManager.IsOpen(UIName.BattlePanel) and not UIManager.IsOpen(UIName.MissionDailyTipPanel) and
not UIManager.IsOpen(UIName.FormationPanelV2) and not UIManager.IsOpen(UIName.RewardItemPopup) then
--LogGreen("allShowTipMission[1] "..allShowTipMission[1].type.." "..allShowTipMission[1].Id.." "..allShowTipMission[1].state)
this.ShowDailyAndAchievementTipPanel(allShowTipMission[1])
end
end
--推送时检测 是否达成 飘弹窗提示
function this.ShowDailyAndAchievementTipPanel(data)
if data.type == TaskTypeDef.DayTask then
local curConfig = ConfigManager.TryGetConfigData(ConfigName.DailyTasksConfig,data.Id)
if curConfig and curConfig.SortId ~= 2 then
--LogGreen("日常 back or battleClose "..data.type.." "..data.Id.." "..data.state)
2021-01-26 17:08:39 +08:00
MissionDailyTipPanel.ShowInfo(1,string.format(GetLanguageStrById(curConfig.Desc),curConfig.Values[2][1]))
2020-06-13 11:47:13 +08:00
--LogGreen("remove "..data.type.." "..data.Id.." "..data.state)
this.DelAllShowTipMissionOne()
end
elseif data.type == TaskTypeDef.Achievement then
local curConfig = ConfigManager.TryGetConfigData(ConfigName.AchievementConfig,data.Id)
if curConfig then
--LogGreen("成就 back or battleClose "..data.type.." "..data.Id.." "..data.state)
2021-01-26 17:08:39 +08:00
MissionDailyTipPanel.ShowInfo(2,GetLanguageStrById(curConfig.ContentsShow))
2020-06-13 11:47:13 +08:00
--LogGreen("remove "..data.type.." "..data.Id.." "..data.state)
this.DelAllShowTipMissionOne()
2020-06-03 19:09:01 +08:00
end
end
end
2020-06-13 11:47:13 +08:00
function this.GetAllShowTipMission()
return allShowTipMission
end
function this.DelAllShowTipMissionOne()
table.remove(allShowTipMission,1)
end
function this.ResetEndlessMissionState()
for k,v in ipairs(TypeTaskData[TaskTypeDef.wujinfuben]) do
v.progress = 0
v.state = 0
end
end
2020-06-23 18:36:24 +08:00
return this