actually call the trade dialog

This commit is contained in:
Sokomine 2021-05-23 23:24:47 +02:00
parent 6f5a84e6de
commit e38044c6ff

View File

@ -3050,6 +3050,11 @@ yl_speak_up.input_talk = function(player, formname, fields)
local d_option = n_dialog.d_options[o]
-- which dialog do we have to show next? default: keep this one
local target_dialog = d_id
-- currently not trading; but a new trade may be started here
yl_speak_up.trade[pname] = nil
-- Let's do something if results exist
if d_option.o_results ~= nil then
for k, v in pairs(d_option.o_results) do
@ -3171,9 +3176,7 @@ yl_speak_up.input_talk = function(player, formname, fields)
end
if v.r_type == "dialog" then
if dialog.n_dialogs[v.r_value] ~= nil then
-- if there are any changes done: ask first and don't switch to the new dialog yet
yl_speak_up.save_changes_and_switch_to_other_dialog(player, fields, v.r_value)
return
target_dialog = v.r_value
else
say("This dialog does not exist")
end
@ -3181,6 +3184,46 @@ yl_speak_up.input_talk = function(player, formname, fields)
if v.r_type == "auto" then
say("auto forward")
end
if v.r_type == "trade" then
-- prepare a trade
-- TODO: this may not be a simple trade but instead a more complex one
yl_speak_up.trade[pname] = {
-- trade_simple is a fallback
trade_type = v.r_trade_type,
-- we will create a new trade
player_gives = v.r_player_gives,
npc_gives = v.r_npc_gives,
-- can be determined from other variables, but it is easier to store it here
n_id = n_id,
npc_name = dialog.n_npc,
-- for statistics and in order to determine which dialog to show next
trade_done = 0,
-- we need to know which option this is
o_id = o,
-- we are iterateing over the results right now; the key k is what we need
r_id = k,
-- we do not know yet which target dialog to choose; it may have
-- shown up already or come later on in this loop
target_dialog = d_id,
}
end
end -- end of loop over d_option.o_results
-- if there is a trade in the results/effects, show that trade now
if(yl_speak_up.trade[pname]) then
-- we now know the right arget dialog for this trade
yl_speak_up.trade[pname].target_dialog = target_dialog
-- show the trade dialog
minetest.show_formspec(pname, "yl_speak_up:do_trade_simple",
yl_speak_up.get_fs_trade_simple(player))
return
end
-- else switch to the target dialog as stated in results/effects
if(target_dialog ~= d_id) then
-- if there are any changes done: ask first and don't switch to the new dialog yet
yl_speak_up.save_changes_and_switch_to_other_dialog(player, fields, target_dialog)
return
end
end
end