added quest_step_possible check in preconditions

This commit is contained in:
Sokomine 2023-08-06 02:56:05 +02:00
parent 312531e8c1
commit 7a98d0c44f
2 changed files with 66 additions and 2 deletions

View File

@ -24,7 +24,7 @@ yl_speak_up.calculate_displayable_options = function(pname, d_options, in_edit_m
if(not(in_edit_mode)) then
local o_v = d_options[ o_k ]
-- Can we display this option?
retval[o_k] = yl_speak_up.eval_all_preconditions(player, o_v.o_prerequisites, o_k, retval)
retval[o_k] = yl_speak_up.eval_all_preconditions(player, o_v.o_prerequisites, o_k, retval,o_v)
-- do we need to take care of an automatic autoanswer?
if(retval[o_k] and retval[o_k] == true and o_v.o_autoanswer and o_v.o_autoanswer == 1
and allow_recursion) then
@ -46,9 +46,28 @@ end
-- Important: If something cannot be determined (i.e. the node is nil),
-- *both* the condition and its inverse condition may be
-- true (or false).
yl_speak_up.eval_all_preconditions = function(player, prereq, o_id, other_options_true_or_false)
yl_speak_up.eval_all_preconditions = function(player, prereq, o_id, other_options_true_or_false, d_option)
local pname = player:get_player_name()
local n_id = yl_speak_up.speak_to[pname].n_id
-- if this is a quest step: check if its preconditions are fulfilled
-- (that way there doesn't have to be a manual precondition set for quests)
if(d_option and d_option.quest_id and d_option.quest_step) then
local d_id = yl_speak_up.speak_to[pname].d_id
yl_speak_up.debug_msg(player, n_id, o_id, "..checking quest step \""..
tostring(d_option.quest_step).."\" of quest \""..
tostring(d_option.quest_id).."\".")
if(not(yl_speak_up.quest_step_possible(player, d_option.quest_step, d_option.quest_id,
n_id, d_id, o_id))) then
yl_speak_up.debug_msg(player, n_id, o_id, "Quest step not available. Aborting.")
-- no need to look any further - once we hit a false, it'll stay false
return false
else
yl_speak_up.debug_msg(player, n_id, o_id, "OK. Quest step available.")
end
end
if(not(prereq)) then
yl_speak_up.debug_msg(player, n_id, o_id, "No preconditions given.")
-- no prerequirements? then they are automaticly fulfilled

View File

@ -682,6 +682,38 @@ yl_speak_up.add_quest = function(owner_name, variable_name, quest_name, descr_lo
end
-- delete a quest if possible
yl_speak_up.del_quest = function(q_id, pname)
local quest = yl_speak_up.load_quest(q_id)
if(not(data)) then
return "Quest "..tostring(q_id).." does not exist."
end
if(quest.owner ~= pname) then
return "Quest "..tostring(q_id).." is owned by "..tostring(quest.owner)..
".\n You can't delete it."
end
if(quest.state ~= "created" and quest.state ~= "testing") then
return "Quest "..tostring(q_id).." is in stage \""..tostring(quest.state)..
"\".\n Only quests in state \"created\" or \"testing\" can be deleted."
end
if(#quest.is_subquest_of > 0) then
return "Quest "..tostring(q_id).." is used by the following subquests:\n"..
table.concat(quest.subquests, ", ")..
".\nPlease remove the subquests first!"
end
local quest_data = yl_speak_up.get_variable_metadata(k_long, "quest_data", true) or {}
if(quest_data and quest_data.steps and #quest_data.steps > 2) then
return "Quest "..tostring(q_id).." contains more than two steps:\n"..
table.concat(quest_data.steps, ", ")..
".\nPlease remove all steps apart from \"start\" and \"finish\" first!"
end
-- TODO: actually delete the file?
-- TODO: set the quest variable back to no type
-- TODO: delete quest variable?
return "OK"
end
-- returns a list of all quest IDs to which the player has write access
yl_speak_up.get_quest_owner_list = function(pname)
local var_list = yl_speak_up.get_quest_variables_with_write_access(pname)
@ -712,3 +744,16 @@ yl_speak_up.get_sorted_quest_list = function(pname)
table.sort(quest_list)
return quest_list
end
-- called for example by yl_speak_up.eval_all_preconditions to see if the player
-- can reach quest_step in quest quest_id
yl_speak_up.quest_step_possible = function(player, quest_step, quest_id, n_id, d_id, o_id)
-- TODO: evaluate that
-- TODO: the *previous* quest step needs to have been reached
-- TODO: the quest step *after* this quest step hasn't been reached (does that work?)
-- TODO: the quest needs to be owned by the player, the player be an authorized tester,
-- or the quest be in the official released stage
-- minetest.chat_send_player("singleplayer", "TESTING quest step "..tostring(quest_step).." for quest "..tostring(quest_id))
return true
end