--主线任务流 --db --[=[ human.db.mainTaskData = { taskData = { [taskId] = { progress = ni, --当前进度 isGetReward = nil, --是否已领奖, isGetReward为真标识已领奖 }, }, nowTaskId = nil, --当前任务 } ]=]-- local Msg = require("core.Msg") local Grid = require("bag.Grid") local BagLogic = require("bag.BagLogic") local Lang = require("common.Lang") local Broadcast = require("broadcast.Broadcast") local Config = require("excel.mainTask") local TriggerDefine = require("trigger.TriggerDefine") local TriggerLogic = require("trigger.TriggerLogic") local ObjHuman = require("core.ObjHuman") --获取某类任务在该活动之前就达成的进度 local function getTaskOldProgress(human, taskType) end -- 初始化任务 local function initTask(human) if not human.db.mainTaskData then human.db.mainTaskData = {nowTaskId = 1, taskData = {}} local taskData = human.db.mainTaskData.taskData --一些任务需要统计老的进度数据 local type2Val = {} for taskId, taskCfg in ipairs(Config) do if taskCfg.isCalcOldVal then local taskType = taskCfg.type if not type2Val[taskType] then type2Val[taskType] = getTaskOldProgress(human, taskType) end if type2Val[taskType] and type2Val[taskType] > 0 then taskData[taskId] = { progress = type2Val[taskType] } end end end end end --订阅事件 local function subscribeEvents(human) local taskData = human.db.mainTaskData.taskData local nowTaskId = human.db.mainTaskData.nowTaskId local maxTaskId = #Config local maxTaskCfg = Config[maxTaskId] if nowTaskId == maxTaskId and taskData[maxTaskId] and (taskData[maxTaskId].isGetReward or taskData[maxTaskId].progress >= maxTaskCfg.condProgress) then return end local registerTypeList = {} for _, taskCfg in ipairs(Config) do if not registerTypeList[ taskCfg.eventType] and (not taskData[maxTaskId] or not taskData[maxTaskId].isGetReward or taskData[maxTaskId].progress < taskCfg.condProgress) then TriggerLogic.SubscribeEvent(taskCfg.eventType, human.db._id, EventCBFunc) registerTypeList[ taskCfg.eventType] = 1 end end end function onLogin(human) initTask(human) subscribeEvents(human) end --事件处理函数 function EventCBFunc(eventType, uuid, nValue1, nValue2) local human = ObjHuman.onlineUuid[uuid] if not human then return end local isNowTask = false local taskData = human.db.mainTaskData.taskData local nowTaskId = human.db.mainTaskData.nowTaskId for taskId, taskCfg in ipairs(Config) do if taskCfg.eventType == eventType and (not taskData[taskId] or not taskData[taskId].isGetReward or taskData[taskId].progress < taskCfg.condProgress) then taskData[taskId] = taskData[taskId] or {} taskData[taskId].progress = (taskData[taskId].progress or 0) + nValue1 if taskId == nowTaskId then isNowTask = true end end end --推数据给客户端更新 if isNowTask then end end function TaskQuery(human) end function GetReward(human, taskId) end