--主线任务流 --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 TriggerLogic = require("trigger.TriggerLogic") local TriggerDefine = require("trigger.TriggerDefine") local ObjHuman = require("core.ObjHuman") --日志标识 local MAINTASKLOGTAG = "mainTask" --获取某类任务在该活动之前就达成的进度 local function getTaskOldProgress(human, taskType) local progress = 0 if taskType == TriggerDefine.HUANJINGTOWER_LV then local HuanJingTowerLogic = require("huanjingTower.HuanjingTowerLogic") progress = HuanJingTowerLogic.getTowerLevel(human) elseif taskType == TriggerDefine.LIANYU_PASS then local LianyuLogic = require("lianyu.LianyuLogic") progress = LianyuLogic.getMaxLv(human) elseif taskType == TriggerDefine.REALM_UPGRADE then local RoleRealmLogic = require("roleSystem.RoleRealmLogic") progress = RoleRealmLogic.GetNowRealmLv(human) elseif taskType == TriggerDefine.BATTLE_NORMAL_MODE_PASS then local BattleLogic = require("battle.BattleLogic") progress = BattleLogic.GetLevelByType(human) end return progress 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 TaskQuery(human) end end --查询 function TaskQuery(human) local taskData = human.db.mainTaskData.taskData local nowTaskId = human.db.mainTaskData.nowTaskId local maxTaskId = #Config local nowTaskCfg = Config[nowTaskId] local msgRet = Msg.gc.GC_MAINTASK_QUERY msgRet.nowTaskId = nowTaskId msgRet.nowProgess = taskData[nowTaskId] and taskData[nowTaskId].progress or 0 msgRet.condProgess = nowTaskCfg.condProgress msgRet.taskDesc = nowTaskCfg.taskDesc msgRet.panelID = nowTaskCfg.panelID Grid.makeItem(msgRet.taskAward, nowTaskCfg.reward[1], nowTaskCfg.reward[2]) msgRet.isNoTask = 0 if nowTaskId == maxTaskId and taskData[nowTaskId] and taskData[nowTaskId].isGetReward then msgRet.isNoTask = 1 end Msg.send(msgRet, human.fd) end --领奖 function GetReward(human, taskId) local taskData = human.db.mainTaskData.taskData local nowTaskId = human.db.mainTaskData.nowTaskId local nowTaskCfg = Config[nowTaskId] if not taskData[nowTaskId] or taskData[nowTaskId].progress < nowTaskCfg.condProgress then return Broadcast.sendErr(human, Lang.UNION_TASK_NOT_COMPLETE) end if taskData[nowTaskId] and taskData[nowTaskId].isGetReward then return Broadcast.sendErr(human, Lang.FRIEND_HEART_GET_HAD) end taskData[nowTaskId].isGetReward = true local rewardCfg = Config[nowTaskId].reward BagLogic.addItemList(human, { {rewardCfg[1], rewardCfg[2]}}, MAINTASKLOGTAG) nowTaskId = nowTaskId + 1 if Config[nowTaskId] then human.db.mainTaskData.nowTaskId = nowTaskId end TaskQuery(human) end