From 7225027879e9a6f2efb3b1479b73bd575fbb40cc Mon Sep 17 00:00:00 2001 From: Wouters Dorian Date: Sat, 25 Jul 2015 11:26:45 +0200 Subject: [PATCH] Fix bugs --- core.lua | 26 +++++++++++-------- formspecs.lua | 54 ++++++++++++++++++++++----------------- hud.lua | 70 ++++++++++++++++++++++++++------------------------- 3 files changed, 82 insertions(+), 68 deletions(-) diff --git a/core.lua b/core.lua index 2111ac1..6839a80 100644 --- a/core.lua +++ b/core.lua @@ -19,23 +19,27 @@ local function compute_tasks(playername, questname, nocallback) if task.requires == nil then plr_task.visible = true else + plr_task.visible = false local was_visible = task.visible local final_enabler = "" for _, enabler_name in ipairs(task.requires) do if type(enabler_name) == "table" then plr_task.visible = true - for _, subena_name in ipairs(plr_task[enabler_name]) do + for _, subena_name in ipairs(plr_quest[enabler_name]) do local plr_subena = plr_task[subena_name] - if not plr_subena.visible or not plr_subena.finished then + if plr_task.visible and plr_subena and (not plr_subena.visible or not plr_subena.finished) then plr_task.visible = false - break end end else - plr_task.visible = plr_task[enabler_name].finished + if plr_quest[enabler_name] then + plr_task.visible = plr_quest[enabler_name].finished or false + else + plr_task.visible = true + end end if plr_task.visible then - final_enabler = enabler + final_enabler = enabler_name break end end @@ -50,17 +54,16 @@ local function compute_tasks(playername, questname, nocallback) if type(disabler) == "table" then plr_task.disabled = true for _, subdis_name in ipairs(disabler) do - local plr_subdis = plr_task[subdis_name] - if plr_subdis.visible and plr_subdis.finished then - plr_task.disabled = false - break + local plr_subdis = plr_quest[subdis_name] + if not plr_task.disabled and plr_subdis.visible and plr_subdis.finished then + plr_task.disabled = true end end else - plr_task.disabled = plr_task[disabler_name].finished + plr_task.disabled = plr_quest[disabler_name].finished end if plr_task.disabled then - final_disabler = disabler + final_disabler = disabler_name break end end @@ -313,6 +316,7 @@ function quests.update_quest_task(playername, questname, taskname, value) -- Check for quest completion local all_tasks_finished = true for taskname, task in pairs(quest.tasks) do + local plr_task = plr_quest[taskname] if plr_task.visible and not plr_task.disabled and not plr_task.finished then all_tasks_finished = false end diff --git a/formspecs.lua b/formspecs.lua index e4d6d91..1a87a03 100644 --- a/formspecs.lua +++ b/formspecs.lua @@ -29,23 +29,25 @@ function quests.create_formspec(playername, tab, integrated) for questname,questspecs in pairs(questlist) do if not questspecs.finished then local quest = quests.registered_quests[questname] - local queststring = quest.title - if quest.simple then - if questspecs.count and questspecs.count > 1 then - queststring = queststring .. " - " .. questspecs.count - elseif not questspecs.count and quest.max ~= 1 then - queststring = queststring .. " - (" .. quests.round(questspecs.value, 2) .. "/" .. quest.max .. ")" - end - else - if questspecs.count and questspecs.count > 1 then - queststring = queststring .. " - " .. questspecs.count - elseif not questspecs.count and quest.max ~= 1 then - queststring = queststring .. " - (...)" + if quest then -- Quest might have been deleted + local queststring = quest.title + if quest.simple then + if questspecs.count and questspecs.count > 1 then + queststring = queststring .. " - " .. questspecs.count + elseif not questspecs.count and quest.max ~= 1 then + queststring = queststring .. " - (" .. quests.round(questspecs.value, 2) .. "/" .. quest.max .. ")" + end + else + if questspecs.count and questspecs.count > 1 then + queststring = queststring .. " - " .. questspecs.count + elseif not questspecs.count and quest.max ~= 1 then + queststring = queststring .. " - (...)" + end end + table.insert(queststringlist, queststring) + table.insert(quests.formspec_lists[playername].list, questname) + no_quests = false end - table.insert(queststringlist, queststring) - table.insert(quests.formspec_lists[playername].list, questname) - no_quests = false end end local formspec = "" @@ -56,12 +58,13 @@ function quests.create_formspec(playername, tab, integrated) if no_quests then formspec = formspec .. "label[0.25,0.25;" .. S("There are no quests in this category.") .. "]" else - formspec = formspec .. "textlist[0.25,0.25;6.5,6.5;quests_questlist;"..table.concat(queststringlist, ",") .. ";1;false]" + formspec = formspec .. "textlist[0.25,0.25;6.5,6;quests_questlist;"..table.concat(queststringlist, ",") .. ";1;false]" end if quests.formspec_lists[playername].tab == "1" then - formspec = formspec .."button[0.25,7;3,.7;quests_abort;" .. S("Abort quest") .. "]" + formspec = formspec .."button[0.25,7.1;3,.7;quests_abort;" .. S("Abort quest") .. "]" .. + "checkbox[.25,6.2;quests_show_quest_in_hud;" .. S("Show in HUD") .. ";" .. "false" .. "]" end - formspec = formspec .. "button[3.75,7;3,.7;quests_config;" .. S("Configure") .. "]".. + formspec = formspec .. "button[3.75,7.1;3,.7;quests_config;" .. S("Configure") .. "]".. "button[.25,8;3,.7;quests_info;" .. S("Info") .. "]".. "button_exit[3.75,8;3,.7;quests_exit;" .. S("Exit") .. "]" return formspec @@ -145,11 +148,15 @@ function quests.create_info(playername, questname, taskid, integrated) local taskidlist = {} local taskstringlist = {} for taskname, task in pairs(quest.tasks) do - local plr_task = quests.active_quests[playername][questname][taskname] + local plr_task = nil + if quests.active_quests[playername] and quests.active_quests[playername][questname] then + plr_task = quests.active_quests[playername][questname][taskname] + end if not plr_task or (plr_task and plr_task.visible) then -- not plr_task => quest is finished, display all tasks table.insert(taskidlist, taskname) local color = "" + local suffix = "" if plr_task then if plr_task.finished then color = "#00BB00" @@ -157,8 +164,9 @@ function quests.create_info(playername, questname, taskid, integrated) if plr_task.disabled then color = "#AAAAAA" end + suffix = " - " .. quests.round(plr_task.value, 2) .. "/" .. task.max end - table.insert(taskstringlist, color .. task.title .. " - " .. quests.round(plr_task.value, 2) .. "/" .. task.max) + table.insert(taskstringlist, color .. task.title .. suffix) end end local task = false @@ -311,8 +319,8 @@ minetest.register_on_player_receive_fields(function(player, formname, fields) if fields.quest_info_tasklist then local event = minetest.explode_textlist_event(fields.quest_info_tasklist) if event.type == "CHG" then - if formname == "quests:questlog" then - minetest.show_formspec(playername, "quests:info", quests.create_info(playername, quests.formspec_lists[playername].list[quests.formspec_lists[playername].id]), event.index, false) + if formname == "quests:info" then + minetest.show_formspec(playername, "quests:info", quests.create_info(playername, quests.formspec_lists[playername].list[quests.formspec_lists[playername].id], event.index, false)) else quests.formspec_lists[playername].taskid = event.index unified_inventory.set_inventory_formspec(player, "quests_info") @@ -320,7 +328,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields) end end if fields.quests_info_abort then - if (quests.formspec_lists[playername].id == nil) then + if quests.formspec_lists[playername].id == nil then return end quests.abort_quest(playername, quests.formspec_lists[playername].list[quests.formspec_lists[playername].id]) diff --git a/hud.lua b/hud.lua index ce40f18..427bfc2 100644 --- a/hud.lua +++ b/hud.lua @@ -150,43 +150,45 @@ function quests.update_hud(playername) for questname,questspecs in pairs(quests.active_quests[playername]) do if not visible[questname] then local quest = quests.registered_quests[questname] - if quest.simple then - local id = player:hud_add({ hud_elem_type = "text", - alignment = { x=1, y= 1 }, - position = {x = hud_config.position.x, y = hud_config.position.y}, - offset = {x = hud_config.offset.x, y = hud_config.offset.y + counter * 40}, - number = hud_config.number, - text = get_quest_hud_string(questname, questspecs) }) - local id_background - local id_bar - if quest.max ~= 1 then - id_background = player:hud_add({ hud_elem_type = "image", - scale = { x = 1, y = 1 }, - size = { x = 2, y = 4 }, + if quest then -- Quest might have been deleted + if quest.simple then + local id = player:hud_add({ hud_elem_type = "text", + alignment = { x=1, y= 1 }, + position = {x = hud_config.position.x, y = hud_config.position.y}, + offset = {x = hud_config.offset.x, y = hud_config.offset.y + counter * 40}, + number = hud_config.number, + text = get_quest_hud_string(questname, questspecs) }) + local id_background + local id_bar + if quest.max ~= 1 then + id_background = player:hud_add({ hud_elem_type = "image", + scale = { x = 1, y = 1 }, + size = { x = 2, y = 4 }, + alignment = { x = 1, y = 1 }, + position = { x = hud_config.position.x, y = hud_config.position.y }, + offset = { x = hud_config.offset.x, y = hud_config.offset.y + counter * 40 + 22 }, + text = "quests_questbar_background.png" }) + id_bar = player:hud_add({hud_elem_type = "image", + scale = { x = math.floor(20 * questspecs.value / quest.max), + y = 1 }, alignment = { x = 1, y = 1 }, position = { x = hud_config.position.x, y = hud_config.position.y }, - offset = { x = hud_config.offset.x, y = hud_config.offset.y + counter * 40 + 22 }, - text = "quests_questbar_background.png" }) - id_bar = player:hud_add({hud_elem_type = "image", - scale = { x = math.floor(20 * questspecs.value / quest.max), - y = 1 }, - alignment = { x = 1, y = 1 }, - position = { x = hud_config.position.x, y = hud_config.position.y }, - offset = { x = hud_config.offset.x + 2, y = hud_config.offset.y + counter * 40 + 24 }, - text = "quests_questbar.png" }) - end + offset = { x = hud_config.offset.x + 2, y = hud_config.offset.y + counter * 40 + 24 }, + text = "quests_questbar.png" }) + end - table.insert(quests.hud[playername].list, { name = questname, - id = id, - id_background = id_background, - id_bar = id_bar, - value = questspecs.value }) - else - -- TODO - end - counter = counter + 1 - if (counter >= show_max + 1) then - break + table.insert(quests.hud[playername].list, { name = questname, + id = id, + id_background = id_background, + id_bar = id_bar, + value = questspecs.value }) + else + -- TODO + end + counter = counter + 1 + if (counter >= show_max + 1) then + break + end end end end