forked from Sokomine/yl_speak_up
added quest_step_reached
This commit is contained in:
parent
7a98d0c44f
commit
dd5ea7e38f
@ -77,6 +77,7 @@ yl_speak_up.execute_next_action = function(player, a_id, result_of_a_id)
|
|||||||
local actions = {}
|
local actions = {}
|
||||||
local effects = {}
|
local effects = {}
|
||||||
local sorted_key_list = {}
|
local sorted_key_list = {}
|
||||||
|
local d_option = {}
|
||||||
if(dialog
|
if(dialog
|
||||||
and dialog.n_dialogs
|
and dialog.n_dialogs
|
||||||
and dialog.n_dialogs[d_id]
|
and dialog.n_dialogs[d_id]
|
||||||
@ -86,6 +87,8 @@ yl_speak_up.execute_next_action = function(player, a_id, result_of_a_id)
|
|||||||
actions = dialog.n_dialogs[d_id].d_options[o_id].actions
|
actions = dialog.n_dialogs[d_id].d_options[o_id].actions
|
||||||
-- needed later on when all actions are executed
|
-- needed later on when all actions are executed
|
||||||
effects = dialog.n_dialogs[d_id].d_options[o_id].o_results
|
effects = dialog.n_dialogs[d_id].d_options[o_id].o_results
|
||||||
|
-- needed later for setting quest_step (optional)
|
||||||
|
d_option = dialog.n_dialogs[d_id].d_options[o_id]
|
||||||
end
|
end
|
||||||
if(actions) then
|
if(actions) then
|
||||||
-- sort the actions so that we can execute them always in the
|
-- sort the actions so that we can execute them always in the
|
||||||
@ -256,7 +259,7 @@ yl_speak_up.execute_next_action = function(player, a_id, result_of_a_id)
|
|||||||
yl_speak_up.debug_msg(player, n_id, o_id, "All actions have been executed successfully. "..
|
yl_speak_up.debug_msg(player, n_id, o_id, "All actions have been executed successfully. "..
|
||||||
"Doing effects/results now.")
|
"Doing effects/results now.")
|
||||||
-- execute all effects/results
|
-- execute all effects/results
|
||||||
local res = yl_speak_up.execute_all_relevant_effects(player, effects, o_id, true)
|
local res = yl_speak_up.execute_all_relevant_effects(player, effects, o_id, true, d_option)
|
||||||
local target_dialog = res.next_dialog
|
local target_dialog = res.next_dialog
|
||||||
yl_speak_up.speak_to[pname].o_id = nil
|
yl_speak_up.speak_to[pname].o_id = nil
|
||||||
yl_speak_up.speak_to[pname].a_id = nil
|
yl_speak_up.speak_to[pname].a_id = nil
|
||||||
|
@ -44,11 +44,20 @@ end
|
|||||||
-- was encountered after an unsuccessful action *or* right after an
|
-- was encountered after an unsuccessful action *or* right after an
|
||||||
-- effect that returned false.
|
-- effect that returned false.
|
||||||
-- Note: In edit mode, effects will *not* be executed.
|
-- Note: In edit mode, effects will *not* be executed.
|
||||||
yl_speak_up.execute_all_relevant_effects = function(player, effects, o_id, action_was_successful)
|
yl_speak_up.execute_all_relevant_effects = function(player, effects, o_id, action_was_successful, d_option)
|
||||||
local target_dialog = ""
|
local target_dialog = ""
|
||||||
local pname = player:get_player_name()
|
local pname = player:get_player_name()
|
||||||
local n_id = yl_speak_up.speak_to[pname].n_id
|
local n_id = yl_speak_up.speak_to[pname].n_id
|
||||||
if(not(effects)) then
|
if(not(effects)) then
|
||||||
|
-- it may still be necessary to set the quest step
|
||||||
|
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, "Setting quest step \""..
|
||||||
|
tostring(d_option.quest_step).."\" in quest \""..
|
||||||
|
tostring(d_option.quest_id).."\".")
|
||||||
|
yl_speak_up.quest_step_reached(player, d_option.quest_step, d_option.quest_id,
|
||||||
|
n_id, d_id, o_id)
|
||||||
|
end
|
||||||
yl_speak_up.debug_msg(player, n_id, o_id, "No effects given.")
|
yl_speak_up.debug_msg(player, n_id, o_id, "No effects given.")
|
||||||
-- no effects? Then...return to the start dialog
|
-- no effects? Then...return to the start dialog
|
||||||
return {next_dialog = "", alternate_text = nil}
|
return {next_dialog = "", alternate_text = nil}
|
||||||
@ -127,6 +136,7 @@ yl_speak_up.execute_all_relevant_effects = function(player, effects, o_id, actio
|
|||||||
yl_speak_up.debug_msg(player, n_id, o_id, "Aborted executing effects at "..
|
yl_speak_up.debug_msg(player, n_id, o_id, "Aborted executing effects at "..
|
||||||
tostring(r.r_id)..". New target dialog: "..tostring(r.r_value)..".")
|
tostring(r.r_id)..". New target dialog: "..tostring(r.r_value)..".")
|
||||||
-- we also stop execution here
|
-- we also stop execution here
|
||||||
|
-- any quest step is NOT set (because effects and/or action weren't successful)
|
||||||
return {next_dialog = r.r_value, alternate_text = r.alternate_text}
|
return {next_dialog = r.r_value, alternate_text = r.alternate_text}
|
||||||
end
|
end
|
||||||
last_result = res
|
last_result = res
|
||||||
@ -141,6 +151,16 @@ yl_speak_up.execute_all_relevant_effects = function(player, effects, o_id, actio
|
|||||||
target_dialog = "d_got_item"
|
target_dialog = "d_got_item"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- it may still be necessary to set the quest step
|
||||||
|
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, "Setting quest step \""..
|
||||||
|
tostring(d_option.quest_step).."\" in quest \""..
|
||||||
|
tostring(d_option.quest_id).."\".")
|
||||||
|
yl_speak_up.quest_step_reached(player, d_option.quest_step, d_option.quest_id,
|
||||||
|
n_id, d_id, o_id)
|
||||||
|
end
|
||||||
return {next_dialog = target_dialog, alternate_text = alternate_text}
|
return {next_dialog = target_dialog, alternate_text = alternate_text}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -871,8 +871,9 @@ yl_speak_up.get_fs_talkdialog = function(player, n_id, d_id, alternate_text, rec
|
|||||||
-- no actions shall be executed
|
-- no actions shall be executed
|
||||||
local o_id = go_to_next_dialog
|
local o_id = go_to_next_dialog
|
||||||
local effects = active_dialog.d_options[o_id].o_results
|
local effects = active_dialog.d_options[o_id].o_results
|
||||||
|
local d_option = active_dialog.d_options[o_id]
|
||||||
-- execute all effects/results
|
-- execute all effects/results
|
||||||
local res = yl_speak_up.execute_all_relevant_effects(player, effects, o_id, true)
|
local res = yl_speak_up.execute_all_relevant_effects(player, effects, o_id, true, d_option)
|
||||||
local target_dialog = res.next_dialog
|
local target_dialog = res.next_dialog
|
||||||
yl_speak_up.speak_to[pname].o_id = nil
|
yl_speak_up.speak_to[pname].o_id = nil
|
||||||
yl_speak_up.speak_to[pname].a_id = nil
|
yl_speak_up.speak_to[pname].a_id = nil
|
||||||
|
@ -130,10 +130,11 @@ yl_speak_up.get_fs_trade_list = function(player, show_dialog_option_trades)
|
|||||||
local do_o_id = yl_speak_up.eval_trade_list_preconditions(player)
|
local do_o_id = yl_speak_up.eval_trade_list_preconditions(player)
|
||||||
if(do_o_id) then
|
if(do_o_id) then
|
||||||
local effects = dialog.n_dialogs["d_trade"].d_options[do_o_id].o_results
|
local effects = dialog.n_dialogs["d_trade"].d_options[do_o_id].o_results
|
||||||
|
local d_option = dialog.n_dialogs["d_trade"].d_options[do_o_id]
|
||||||
-- the return value is of no intrest here - we won't be showing another dialog,
|
-- the return value is of no intrest here - we won't be showing another dialog,
|
||||||
-- and alternate_text isn't relevant either; we just do the effects and then show
|
-- and alternate_text isn't relevant either; we just do the effects and then show
|
||||||
-- the trade list
|
-- the trade list
|
||||||
local res = yl_speak_up.execute_all_relevant_effects(player, effects, do_o_id, true)
|
local res = yl_speak_up.execute_all_relevant_effects(player, effects, do_o_id, true, d_option)
|
||||||
end
|
end
|
||||||
|
|
||||||
if(not(yl_speak_up.may_edit_npc(player, n_id))) then
|
if(not(yl_speak_up.may_edit_npc(player, n_id))) then
|
||||||
|
@ -757,3 +757,12 @@ yl_speak_up.quest_step_possible = function(player, quest_step, quest_id, n_id, d
|
|||||||
-- minetest.chat_send_player("singleplayer", "TESTING quest step "..tostring(quest_step).." for quest "..tostring(quest_id))
|
-- minetest.chat_send_player("singleplayer", "TESTING quest step "..tostring(quest_step).." for quest "..tostring(quest_id))
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
-- sets quest_step in quest_id for player as achieved
|
||||||
|
-- called for example by yl_speak_up.execute_all_relevant_effects if the action was
|
||||||
|
yl_speak_up.quest_step_reached = function(player, quest_step, quest_id, n_id, d_id, o_id)
|
||||||
|
-- TODO: check again if it's possible? we don't want to step back in the quest_step chain
|
||||||
|
-- TODO: actually store the quest progress
|
||||||
|
-- minetest.chat_send_player("singleplayer", "SETTING quest step "..tostring(quest_step).." for quest "..tostring(quest_id))
|
||||||
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user