236 lines
6.6 KiB
Lua
236 lines
6.6 KiB
Lua
local TaskManager = class("TaskManager", BaseModule)
|
|
|
|
function TaskManager:init()
|
|
self:addEventListener(EventManager.CUSTOM_EVENT.DAILY_TASK_ADD_PROGRESS, function(id, taskId, from, to)
|
|
ModuleManager.TaskToastManager:showToast(id, taskId, from, to)
|
|
end)
|
|
self:addEventListener(EventManager.CUSTOM_EVENT.UI_SHOW_COMPLETE, function()
|
|
ModuleManager.TaskToastManager:checkOnOpenUI()
|
|
end)
|
|
end
|
|
|
|
function TaskManager:showTaskMainUI()
|
|
UIManager:showUI("app/ui/task/task_main_ui")
|
|
end
|
|
|
|
function TaskManager:refreshDailyTask(dailyTaskId)
|
|
SDKManager:showFullScreenAds(BIReport.ADS_CLICK_TYPE.TASK_DAILY_REFRESH, function()
|
|
local parmas = {
|
|
id = dailyTaskId,
|
|
}
|
|
self:sendMessage(ProtoMsgType.FromMsgEnum.TaskDailyRefreshReq, parmas, {}, self.onDailyTaskRefresh, BIReport.ITEM_GET_TYPE.TASK_DAILY_REFRESH)
|
|
end)
|
|
end
|
|
|
|
function TaskManager:onDailyTaskRefresh(result)
|
|
if result.err_code == GConst.ERROR_STR.SUCCESS then
|
|
if result.task then
|
|
DataManager.DailyTaskData:refreshDailyTask(result.task)
|
|
end
|
|
end
|
|
end
|
|
|
|
function TaskManager:claimDailyTask(dailyTaskId)
|
|
local parmas = {
|
|
id = dailyTaskId,
|
|
}
|
|
self:sendMessage(ProtoMsgType.FromMsgEnum.TaskDailyRewardReq, parmas, {}, self.onDailyTaskClaim, BIReport.ITEM_GET_TYPE.TASK_DAILY_REWARD)
|
|
end
|
|
|
|
function TaskManager:onDailyTaskClaim(result)
|
|
if result.err_code == GConst.ERROR_STR.SUCCESS then
|
|
if result.task then
|
|
DataManager.DailyTaskData:refreshDailyTask(result.task)
|
|
end
|
|
if result.rewards then
|
|
GFunc.showRewardBox(result.rewards)
|
|
end
|
|
end
|
|
end
|
|
|
|
function TaskManager:registerTask(moduleName, taskType, callback)
|
|
if not self.registerTaskInfo then
|
|
self.registerTaskInfo = {}
|
|
end
|
|
|
|
if not self.registerTaskInfo[taskType] then
|
|
self.registerTaskInfo[taskType] = {}
|
|
end
|
|
|
|
self.registerTaskInfo[taskType][moduleName] = callback
|
|
end
|
|
|
|
function TaskManager:unRegisterTask(moduleName, taskType)
|
|
if not self.registerTaskInfo then
|
|
return
|
|
end
|
|
|
|
if not self.registerTaskInfo[taskType] then
|
|
return
|
|
end
|
|
|
|
self.registerTaskInfo[taskType][moduleName] = nil
|
|
end
|
|
|
|
function TaskManager:unRegisterAllModuleTask(name)
|
|
if not self.registerTaskInfo then
|
|
return
|
|
end
|
|
for taskType, callbacks in pairs(self.registerTaskInfo) do
|
|
for moduleName, callback in pairs(callbacks) do
|
|
if moduleName == name then
|
|
callbacks[moduleName] = nil
|
|
break
|
|
end
|
|
end
|
|
end
|
|
end
|
|
|
|
function TaskManager:clear()
|
|
self.registerTaskInfo = nil
|
|
end
|
|
|
|
function TaskManager:addTaskProgress(type, ...)
|
|
if not self.registerTaskInfo then
|
|
return
|
|
end
|
|
|
|
local func = TaskManager.TYPE_DEAL_FUNC[type]
|
|
if func then
|
|
func(self, ...)
|
|
end
|
|
end
|
|
|
|
function TaskManager:dispatchTask(type, count)
|
|
if not self.registerTaskInfo then
|
|
return
|
|
end
|
|
if not self.registerTaskInfo[type] then
|
|
return
|
|
end
|
|
|
|
for module, callback in pairs(self.registerTaskInfo[type]) do
|
|
if callback then
|
|
callback(count)
|
|
end
|
|
end
|
|
end
|
|
|
|
------------------------------------------------------ 处理任务 ------------------------------------------------------
|
|
function TaskManager:xKillMonster(params)
|
|
local num = params.num
|
|
if not num then
|
|
return
|
|
end
|
|
|
|
self:dispatchTask(GConst.TaskConst.TASK_TYPE.X_KILL_MONSTER, num)
|
|
end
|
|
|
|
function TaskManager:xWatchAd()
|
|
self:dispatchTask(GConst.TaskConst.TASK_TYPE.X_WATCH_AD, 1)
|
|
end
|
|
|
|
function TaskManager:completeDailyTask()
|
|
self:dispatchTask(GConst.TaskConst.TASK_TYPE.COMPLETED_DALY_TASK, 1)
|
|
end
|
|
|
|
function TaskManager:xGoldGot(count)
|
|
self:dispatchTask(GConst.TaskConst.TASK_TYPE.X_GOLD_GOT, count)
|
|
end
|
|
|
|
function TaskManager:xGoldCost(count)
|
|
self:dispatchTask(GConst.TaskConst.TASK_TYPE.X_GOLD_COST, count)
|
|
end
|
|
|
|
function TaskManager:xGemGot(count)
|
|
self:dispatchTask(GConst.TaskConst.TASK_TYPE.X_GEM_GOT, count)
|
|
end
|
|
|
|
function TaskManager:xGemCost(count)
|
|
self:dispatchTask(GConst.TaskConst.TASK_TYPE.X_GEM_COST, count)
|
|
end
|
|
|
|
function TaskManager:xBattleVictory()
|
|
self:dispatchTask(GConst.TaskConst.TASK_TYPE.X_BATTLE_VICTORY, 1)
|
|
end
|
|
|
|
function TaskManager:xHeroLvUp()
|
|
self:dispatchTask(GConst.TaskConst.TASK_TYPE.X_HERO_LV_UP, 1)
|
|
end
|
|
|
|
function TaskManager:xHeroFragmentGot(count)
|
|
self:dispatchTask(GConst.TaskConst.TASK_TYPE.X_HERO_FRAGMENT_GOT, count)
|
|
end
|
|
|
|
---- 没有特殊说明,方法均返回任务增量
|
|
TaskManager.TYPE_DEAL_FUNC = {
|
|
[GConst.TaskConst.TASK_TYPE.X_WATCH_AD] = TaskManager.xWatchAd,
|
|
[GConst.TaskConst.TASK_TYPE.X_GOLD_GOT] = TaskManager.xGoldGot,
|
|
[GConst.TaskConst.TASK_TYPE.X_GEM_GOT] = TaskManager.xGemGot,
|
|
[GConst.TaskConst.TASK_TYPE.X_GOLD_COST] = TaskManager.xGoldCost,
|
|
[GConst.TaskConst.TASK_TYPE.X_GEM_COST] = TaskManager.xGemCost,
|
|
[GConst.TaskConst.TASK_TYPE.X_BATTLE_VICTORY] = TaskManager.xBattleVictory,
|
|
[GConst.TaskConst.TASK_TYPE.X_HERO_LV_UP] = TaskManager.xHeroLvUp,
|
|
[GConst.TaskConst.TASK_TYPE.X_HERO_FRAGMENT_GOT] = TaskManager.xHeroFragmentGot,
|
|
[GConst.TaskConst.TASK_TYPE.COMPLETED_DALY_TASK] = TaskManager.completeDailyTask,
|
|
|
|
-- [GConst.TaskConst.TASK_TYPE.X_KILL_MONSTER] = TaskManager.xKillMonster,
|
|
}
|
|
|
|
function TaskManager:taskGoto(taskType)
|
|
if TaskManager.gotoFunc[taskType] then
|
|
TaskManager.gotoFunc[taskType](self)
|
|
end
|
|
end
|
|
|
|
function TaskManager:gotoMainUI()
|
|
ModuleManager.MaincityManager:showMainCityUI()
|
|
end
|
|
|
|
TaskManager.gotoFunc = {
|
|
[GConst.TaskConst.TASK_TYPE.X_KILL_MONSTER] = TaskManager.gotoMainUI,
|
|
}
|
|
|
|
function TaskManager:getTaskDesc(type, count, totalCount)
|
|
local cfg = I18N:getConfig("task")[type]
|
|
if not cfg then
|
|
return GConst.EMPTY_STRING
|
|
end
|
|
|
|
local str = "(" .. count .. "/" .. totalCount .. ")"
|
|
return I18N:getText("task", type, "desc", str)
|
|
end
|
|
|
|
function TaskManager:getTaskTutorialDesc(type, count, totalCount)
|
|
local cfg = I18N:getConfig("task")[type]
|
|
if not cfg then
|
|
return GConst.EMPTY_STRING
|
|
end
|
|
|
|
local endStr
|
|
if count then
|
|
endStr = "(" .. count .. "/" .. totalCount .. ")"
|
|
else
|
|
endStr = "(" .. totalCount .. ")"
|
|
end
|
|
|
|
local str = I18N:getText("task", type, "tutorial_desc") .. endStr
|
|
return str
|
|
end
|
|
|
|
|
|
function TaskManager:dealTaskType(taskType, callback, onlyGet)
|
|
if taskType == GConst.TaskConst.TASK_TYPE.X_KILL_MONSTER then
|
|
if onlyGet then
|
|
return taskType
|
|
else
|
|
ModuleManager.ChapterManager:calculateFightImmediately(callback)
|
|
end
|
|
else
|
|
if callback and not onlyGet then
|
|
callback()
|
|
end
|
|
end
|
|
end
|
|
|
|
return TaskManager |