From 586a18073e714acfe9db753f18e85f75e284bdf4 Mon Sep 17 00:00:00 2001 From: Sokomine Date: Sun, 11 Jul 2021 18:31:58 +0200 Subject: [PATCH] added preconditions quest_step_done and quest_step_not_done --- fs_edit_preconditions.lua | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/fs_edit_preconditions.lua b/fs_edit_preconditions.lua index 021e2c2..5d02c8e 100644 --- a/fs_edit_preconditions.lua +++ b/fs_edit_preconditions.lua @@ -101,11 +101,14 @@ local check_operator = { "is_unset (has no value)", -- 10 "more than x seconds ago", -- 11 "less than x seconds ago", -- 12 + "has completed quest step", -- 13 + "quest step *not* completed", -- 14 } -- how to store these as p_value (the actual variable is stored in p_variable, and the value in p_cmp_value): local values_operator = {"", "==", "~=", ">=", ">", "<=", "<", "not", "is_set", "is_unset", - "more_than_x_seconds_ago","less_than_x_seconds_ago"} + "more_than_x_seconds_ago","less_than_x_seconds_ago", + "quest_step_done", "quest_step_not_done"} -- some internal ones... local check_variable = { @@ -166,6 +169,12 @@ yl_speak_up.show_precondition = function(p, pname) elseif(p.p_operator == "less_than_x_seconds_ago") then return var_name.." was set to current time ".. "*less* than "..tostring(p.p_var_cmp_value).." seconds ago" + elseif(p.p_operator == "quest_step_done") then + return var_name.." shows: player completed quest step \"".. + tostring(p.p_var_cmp_value).."\" successfully" + elseif(p.p_operator == "quest_step_not_done") then + return var_name.." shows: player has not yet completed quest step \"".. + tostring(p.p_var_cmp_value).."\"" end if(p.p_var_cmp_value == "") then return var_name.." "..tostring(p.p_operator).." \"\"" @@ -353,6 +362,32 @@ yl_speak_up.eval_precondition = function(player, n_id, p) end return (tonumber(var_val) + tonumber(p.p_var_cmp_value)) > minetest.get_us_time()/1000000 + -- this is currently equivalent to >= but may change in the future + -- TODO: quest steps may be strings in the future + elseif(p.p_operator == "quest_step_done") then + if(p.p_var_cmp_value == nil) then + return false + end + -- compare numeric if possible + if(tonumber(var_val) and tonumber(p.p_var_cmp_value)) then + return tonumber(var_val) >= tonumber(p.p_var_cmp_value) + -- fallback: compare as strings + else + return tostring(var_val) >= tostring(p.p_var_cmp_value) + end + -- this is currently equivalent to < but may change in the future + -- TODO: quest steps may be strings in the future + elseif(p.p_operator < "quest_step_not_done") then + -- if the variable is not set at all, then the quest step definitely + -- has not been reached yet + if(p.p_var_cmp_value == nil) then + return true + end + if(tonumber(var_val) and tonumber(p.p_var_cmp_value)) then + return tonumber(var_val) < tonumber(p.p_var_cmp_value) + else + return tostring(var_val) < tostring(p.p_var_cmp_value) + end end -- unsupported operator return false