Registers a new objective task.
Registers a new objective task.
1 table data
the objective task data to register.
2 string baseClassID
optional, the ID of another task to inherit the methods of.
local objectiveTask = {} objectiveTask.id = "base_task" function objectiveTask:init(objectiveObject) self.objective = objectiveObject self.progressTable = {} end function objectiveTask:initConfig(cfg) self.config = cfg -- abstract end function objectiveTask:onStart() -- abstract end function objectiveTask:onGameLogicStarted() -- abstract, called when finishing loading end function objectiveTask:onFinish() -- check whether we should disable the failstate when this task gets finished if self.config.disableFailStateOnFinish then local failstate = self.objective:getFailState() if failstate then failstate:disable() end end end function objectiveTask:handleEvent(...) -- abstract end function objectiveTask:setHasStarted(state) self.hasStartedTask = state end function objectiveTask:hasStarted() return self.hasStartedTask end function objectiveTask:getProgress() local current, max = self:getProgressValues() self.progressTable[1] = current self.progressTable[2] = math.min(current, max) return self.progressTable end function objectiveTask:getProgressValues() return self.completed and 1 or 0, 1 end function objectiveTask:getProgressData(targetTable) if self.config.getProgressData then self.config:getProgressData(targetTable, self) end end function objectiveTask:getProgressPercentage() local current, max = self:getProgressValues() return current / math.min(current, max) end function objectiveTask:isFinished() return self.completed -- default callback end function objectiveTask:remove() -- abstract end function objectiveTask:save() return { id = self.id, completed = self.completed, hasStartedTask = self.hasStartedTask } -- abstract end function objectiveTask:load(data) self.completed = data.completed self.hasStartedTask = data.hasStartedTask -- abstract end objectiveHandler:registerNewTask(objectiveTask)