-- 增加 checkTaskEnter 内的参数 记得增增加注释 local TaskType = { HangPass = 1, -- id AdvPass = 2, -- id LoveBreak = 3, -- heroType loveL Wake = 4, -- heroType wakeL AddHero = 5, -- heroType wakeL } local function v(value) return {type = "value", value = value} end local function f(field) return {type = "field", value = field} end local StoryListener = { func = "checkStoryStatus", listen = { [TaskType.HangPass] = {v(1), f("id")}, [TaskType.AdvPass] = {v(4), f("id")}, [TaskType.LoveBreak] = {v(2), f("heroType")}, [TaskType.Wake] = {v(3), f("heroType"), f("wakeL")}, [TaskType.AddHero] = {v(3), f("heroType"), f("wakeL")}, } } local TaskListeners = { StoryListener, } local RoleTask = {} function RoleTask.bind(Role) Role.TaskType = TaskType -- 任务相关入口 function Role:checkTaskEnter(taskType, params, notNotify) for _, listener in ipairs(TaskListeners) do if listener and listener.listen and listener.listen[taskType] and listener["func"] then local pms = {} for _, v in ipairs(listener.listen[taskType]) do if type(v) == "table" and v.type then if v.type == "value" then table.insert(pms, v.value) elseif v.type == "field" then table.insert(pms, params[v.value]) else table.insert(pms, v) end else table.insert(pms, v) end end self[listener["func"]](self, notNotify, table.unpack(pms)) end end end function Role:checkDailyTask() end function Role:checkWeekTask() end function Role:checkAchievTask() end --剧情相关----begin------------- local function checkStoryStatusByHang(role, data, status, cond1) -- cond1 carbonId if tonumber(data.unlockData) ~= cond1 then return end status.s = 1 return true end local function checkStoryStatusByLove(role, data, status, cond1) -- cond1 heroType if data.sort ~= cond1 then return end local curL = role:getProperty("loveStatus"):getv(cond1, 0) if curL < tonumber(data.unlockData) then return end status.s = 1 return true end local function checkStoryStatusByMultStar(role, data, status, cond1, cond2) -- cond1 heroType, cond2 wakeL local heroType = cond1 local need = data.unlockData:toArray(true, "=") local had = false for _, v in pairs(need) do if v == heroType then had = true break end end if not had then return end if cond2 > (status["s" .. heroType] or 0) then status["s" .. heroType] = cond2 end local starC = 0 for _, v in pairs(need) do starC = starC + (status["s" .. v] or 0) end if starC >= tonumber(data.unlockData2) then table.clear(status) status.s = 1 end return true end local function checkStoryStatusByAdv(role, data, status, cond1) -- cond1 advId if tonumber(data.unlockData) ~= cond1 then return end status.s = 1 return true end local checkstoryStatusFunc = { [1] = checkStoryStatusByHang, [2] = checkStoryStatusByLove, [3] = checkStoryStatusByMultStar, [4] = checkStoryStatusByAdv, } function Role:checkStoryStatus(notNotify, stype, cond1, cond2, cond3) local storyBookStatus = self:getProperty("storyB") local change = {} for id, data in pairs(csvdb["story_bookCsv"]) do if stype == data.unlockType and checkstoryStatusFunc[stype] then local curStatus = storyBookStatus[id] or {} if not curStatus.s then -- 存在状态就是已经完成 local isChange = checkstoryStatusFunc[stype](self, data, curStatus, cond1, cond2, cond3) if isChange then storyBookStatus[id] = curStatus table.insert(change, {type = "storyB", field = id, value = curStatus, isOnlyToC = true}) end end end end if next(change) then self:setProperty("storyB", storyBookStatus) -- 统一写入数据库 if not notNotify then self:changeUpdates(change) end end end --剧情相关----end------------- end return RoleTask