119 lines
4.4 KiB
Plaintext
119 lines
4.4 KiB
Plaintext
|
-- Modified by Banjaji's Task givers demise
|
||
|
-- 2022.04.01
|
||
|
-- * Added a check for cancelled tasks so that tm_dynamic.ltx can have "condlist_[nr] = {condition_to_check} cancel"
|
||
|
-- to fail a quest with different outcome from ordinary task failure. In essence when condition is true then the task
|
||
|
-- can have on_fail or on_cancel functions run.
|
||
|
|
||
|
-------------------------------------------------------------------
|
||
|
-- Monkeypatches
|
||
|
-------------------------------------------------------------------
|
||
|
|
||
|
--' Checking the current execution of the quest
|
||
|
task_objects.CGeneralTask.check_task = function(self, tm)
|
||
|
|
||
|
-- original code in separate function for potential monkeypatching
|
||
|
local not_return = self:check_start(tm)
|
||
|
if not not_return then return end
|
||
|
|
||
|
-- Iterate over condlist
|
||
|
for k,v in pairs(self.condlist) do
|
||
|
local t = xr_logic.pick_section_from_condlist(db.actor, db.actor, v)
|
||
|
if (t) and (t == "complete" or t == "fail" or t == "reversed" or t == "cancel") then -- added cancel option
|
||
|
self.last_check_task = t
|
||
|
return
|
||
|
end
|
||
|
end
|
||
|
|
||
|
-- status functor
|
||
|
if (self.status_functor and task_status_functor[self.status_functor]) then
|
||
|
local t = task_status_functor[self.status_functor](self,self.id)
|
||
|
if (t) and (t == "complete" or t == "fail" or t == "reversed") then -- not sure if I should add cancel option, so far it works
|
||
|
self.last_check_task = t
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
|
||
|
|
||
|
--' Deactivation of the quest
|
||
|
task_objects.CGeneralTask.deactivate_task_original = task_objects.CGeneralTask.deactivate_task -- save vanilla function
|
||
|
task_objects.CGeneralTask.deactivate_task = function(self, tsk)
|
||
|
|
||
|
-- Banjaji: tm_dynamic.ltx can have "condlist_[nr] = condition_to_check cancel" to fail a quest with different outcome from ordinary task failure (on_fail vs on_cancel)
|
||
|
if self.last_check_task == "cancel" then
|
||
|
if (self.on_cancel) then
|
||
|
xr_logic.pick_section_from_condlist(db.actor, db.actor, self.on_cancel)
|
||
|
end
|
||
|
news_manager.send_task(db.actor, "fail", tsk) -- this just says that the task failed, no point in adding extra cancelled task text
|
||
|
end
|
||
|
|
||
|
self:deactivate_task_original(tsk) -- Run the vanilla code
|
||
|
end
|
||
|
|
||
|
-------------------------------------------------------------------
|
||
|
-- Normal functions
|
||
|
-------------------------------------------------------------------
|
||
|
|
||
|
-- Do what check_task function did originally. This is separate function just for potential monkeypatching
|
||
|
function task_objects.CGeneralTask:check_start(tm)
|
||
|
local tg = time_global()
|
||
|
|
||
|
if (self.check_time and self.last_check_task == nil and tg < self.check_time) then
|
||
|
return
|
||
|
end
|
||
|
|
||
|
if (not db.actor) then
|
||
|
return
|
||
|
end
|
||
|
|
||
|
self.t = self.t or db.actor and db.actor:get_task(self.id,true)
|
||
|
|
||
|
if (self.t == nil) then -- task is most likely in timeout
|
||
|
return
|
||
|
end
|
||
|
|
||
|
self.check_time = tg + math.random(500,1000) --+ (self.prior*10)
|
||
|
local task_updated = false
|
||
|
|
||
|
local t_tile = task_functor[self.title_functor](self.id, "title", self.title, self) -- comes from task_functor.script
|
||
|
if self.current_title ~= t_tile then
|
||
|
--printf("task [%s] updated due to title change from [%s] to [%s]", tostring(self.id), tostring(self.current_title), tostring(t_tile))
|
||
|
task_updated = true
|
||
|
self.current_title = t_tile
|
||
|
self.t:set_title(game.translate_string(t_tile))
|
||
|
end
|
||
|
|
||
|
local t_descr = task_functor[self.descr_functor](self.id, "descr", self.descr, self)
|
||
|
if self.current_descr ~= t_descr then
|
||
|
--printf("task [%s] updated due to description change from [%s] to [%s]", tostring(self.id), tostring(self.current_descr), tostring(t_descr))
|
||
|
task_updated = true
|
||
|
self.current_descr = t_descr
|
||
|
self.t:set_description(game.translate_string(t_descr))
|
||
|
end
|
||
|
|
||
|
local t_target = task_functor[self.target_functor](self.id, "target", self.target, self)
|
||
|
self:check_level(t_target)
|
||
|
|
||
|
--printf("%s map_location=%s id=%s target=%s",self.current_title,self.t:get_map_location(),self.t:get_map_object_id(),t_target)
|
||
|
|
||
|
if (self.current_target ~= t_target) then
|
||
|
task_updated = true
|
||
|
if (t_target == nil) then
|
||
|
self.t:remove_map_locations(false)
|
||
|
else
|
||
|
self.t:change_map_location(self.spot, t_target)
|
||
|
if(self.storyline) then
|
||
|
level.map_add_object_spot(t_target, "ui_storyline_task_blink", "")
|
||
|
else
|
||
|
level.map_add_object_spot(t_target, "ui_secondary_task_blink", "")
|
||
|
end
|
||
|
end
|
||
|
self.current_target = t_target
|
||
|
end
|
||
|
|
||
|
if task_updated and not(self.dont_send_update_news) then
|
||
|
news_manager.send_task(db.actor, "updated", self.t)
|
||
|
end
|
||
|
|
||
|
return true -- if code reaches this then don't return in check_task function
|
||
|
end
|