From 7d602fccf261e346fadd2ae017bf111d4e637329 Mon Sep 17 00:00:00 2001 From: Sokomine Date: Thu, 21 Sep 2023 22:05:51 +0200 Subject: [PATCH] make sure all relevant tables exist inside quest step data inside quest_api.lua --- fs_manage_quest_steps.lua | 10 ---------- quest_api.lua | 28 ++++++++++++++++++++++++++-- 2 files changed, 26 insertions(+), 12 deletions(-) diff --git a/fs_manage_quest_steps.lua b/fs_manage_quest_steps.lua index b9aaecd..0622ef7 100644 --- a/fs_manage_quest_steps.lua +++ b/fs_manage_quest_steps.lua @@ -24,16 +24,6 @@ yl_speak_up.player_is_working_on_quest = function(player) -- TODO: check if the player has access to that data t.step_data = yl_speak_up.quests[t.q_id].step_data t.current_step = yl_speak_up.speak_to[t.pname].quest_step - if(t.quest_step and t.step_data[t.quest_step]) then - local data = t.step_data[t.quest_step] - -- make sure needed tables exist - if(not(data.one_step_required) or type(data.one_step_required) ~= "table") then - yl_speak_up.quests[t.q_id].step_data[t.current_step].one_step_required = {} - end - if(not(data.all_steps_required) or type(data.one_step_required) ~= "table") then - yl_speak_up.quests[t.q_id].step_data[t.current_step].all_steps_required = {} - end - end -- t contains pname, q_id, quest, step_data and current_step - or error_msg return t end diff --git a/quest_api.lua b/quest_api.lua index 810bb75..1953c6b 100644 --- a/quest_api.lua +++ b/quest_api.lua @@ -589,6 +589,25 @@ yl_speak_up.load_quest = function(q_id) return end yl_speak_up.quests[q_id] = yl_speak_up.handle_json_nil_values(data) + -- make sure all required fields exist + local quest = yl_speak_up.quests[q_id] + if(quest and not(quest.step_data)) then + quest.step_data = {} + end + if(quest) then + for s, d in pairs(quest.step_data) do + if(not(d.where)) then + quest.step_data[s].where = {} + end + if(not(d.one_step_required)) then + quest.step_data[s].one_step_required = {} + end + if(not(d.all_steps_required)) then + quest.step_data[s].all_steps_required = {} + end + end + end + yl_speak_up.quests[q_id] = quest return yl_speak_up.quests[q_id] end @@ -879,8 +898,13 @@ yl_speak_up.quest_step_add_quest_step = function(pname, q_id, quest_step_name) if(not(yl_speak_up.quests[q_id].step_data[quest_step_name])) then yl_speak_up.quests[q_id].step_data[quest_step_name] = { -- where (NPCs, locations) can this quest step be set? - where = {}} - yl_speak_up.save_quest(q_id) + where = {}, + -- at least one of this quest steps has to be achieved before this one is possible + one_step_required = {}, + -- all of these quest steps have to be achieved before this one is possible + all_steps_required = {} + } + yl_speak_up.save_quest(q_id) end -- return OK even if the quest step existed already return "OK"