added formspec for precondition player_offered_item

This commit is contained in:
Sokomine 2022-01-04 04:00:08 +01:00
parent e33f713f54
commit d4e7870c05
3 changed files with 61 additions and 16 deletions

View File

@ -52,13 +52,23 @@ yl_speak_up.action_inv_changed = function(inv, listname, index, stack, player, h
return
end
-- is the player in the process of editing an action of the npc_gives/npc_wants type?
local target_fs = "edit_actions"
local data = yl_speak_up.speak_to[pname][ "tmp_action" ]
if(not(data) or (data.what ~= 4 and data.what ~= 5)) then
return
-- we are editing an action
if(data) then
return
end
-- it might be a precondition
data = yl_speak_up.speak_to[pname][ "tmp_prereq" ]
if(not(data) or (data.what ~= 8)) then
return
end
target_fs = "edit_preconditions"
end
-- "The NPC gives something to the player (i.e. a quest item).", -- 4
-- "The player is expected to give something to the NPC (i.e. a quest item).", -- 5
if(how == "put" and (data.what == 4 or data.what == 5)) then
if(how == "put") then
data.item_node_name = stack:get_name().." "..stack:get_count()
local meta = stack:get_meta()
if(meta and meta:get_string("description")) then
@ -81,7 +91,7 @@ yl_speak_up.action_inv_changed = function(inv, listname, index, stack, player, h
data.item_node_name = ""
end
-- show the updated formspec to the player
yl_speak_up.show_fs(player, "edit_actions", nil)
yl_speak_up.show_fs(player, target_fs, nil)
-- no need to check anything more here; the real checks need to be done
-- when the player presses the save/store/execute button
end

View File

@ -889,6 +889,10 @@ yl_speak_up.input_fs_edit_option_related = function(player, formname, fields,
return
end
elseif(fields.select_accept_group
and data and data.what and what_type == "player_offered_item" and id_prefix == "p_") then
data.item_group = fields.select_accept_group
-- comparison value for a variable (same for both preconditions and effects)
elseif(fields.var_cmp_value
and data and data.what and what_type == "state" and id_prefix ~= "a_") then
@ -1148,6 +1152,7 @@ yl_speak_up.input_fs_edit_option_related = function(player, formname, fields,
and (fields.change_element or fields.select_what or fields.select_trade
or fields.select_inv or fields.select_block
or fields.inv_list_name
or fields.select_accept_group
or fields.select_variable or fields.select_operator
or fields.select_on_failure
or fields.select_on_action_failure
@ -1439,8 +1444,10 @@ yl_speak_up.get_fs_edit_option_related = function(player, table_click_result,
-- "The player is expected to give something to the NPC (i.e. a quest item).", -- 5
-- (only for actions)
elseif(data.what and id_prefix == "a_" and what_type == "npc_wants") then
return yl_speak_up.get_fs_edit_option_action_npc_wants(
-- "an item the player offered/gave to the NPC", (as precondition)
elseif(data.what and ((id_prefix == "a_" and what_type == "npc_wants")
or (id_prefix == "p_" and what_type == "player_offered_item"))) then
return yl_speak_up.get_fs_edit_option_action_npc_wants_or_accepts(
pname, dialog, formspec, data, id_prefix, save_button, e)
-- "The player has to manually enter a password or passphrase or some other text.", -- 6
@ -2020,21 +2027,50 @@ end
-- "The player is expected to give something to the NPC (i.e. a quest item).", -- 5
-- (only for actions)
yl_speak_up.get_fs_edit_option_action_npc_wants = function(
-- "an item the player offered/gave to the NPC", (as precondition)
yl_speak_up.get_fs_edit_option_action_npc_wants_or_accepts = function(
pname, dialog, formspec, data, id_prefix, save_button, e)
local bg_img = ""
local node_name = ""
if(e) then
data.item_quest_id = data.item_quest_id or e["item_quest_id"]
data.item_desc = data.item_desc or e["item_desc"]
data.item_group = data.item_group or e["item_group"]
end
if(data and (data.item_node_name or data.item_string)) then
bg_img = "item_image[1.15,3.65;0.7,0.7;"..
tostring(data.item_node_name or data.item_string).."]"
node_name = tostring(data.item_node_name or data.item_string)
bg_img = "item_image[1.15,3.65;0.7,0.7;"..node_name.."]"
end
wants_or_accepts = "wants"
action_failure_info = ""
if(id_prefix == "p_") then
wants_or_accepts = "accepts"
local group_list = {minetest.formspec_escape("- no, just this one item -")}
-- get node name without amount
local parts = node_name:split(" ")
local nr = 1
-- prepare group_list
if(data and parts and minetest.registered_items[ parts[1] ]) then
for k,v in pairs(minetest.registered_items[ parts[1] ].groups) do
table.insert(group_list, k)
end
nr = table.indexof(minetest.registered_items[ parts[1] ].groups, data.item_group)
if(nr == -1) then
nr = 1
end
end
-- use this for the group selection dialog as well
action_failure_info = "label[1,4.8;...and also all other items of the group:]"..
"dropdown[2,5.1;5.0,0.6;select_accept_group;"..
table.concat(group_list, ",")..";"..tostring(nr)..";]"
else
action_failure_info = yl_speak_up.set_on_action_failure_dialog(pname, data,
"The player shall give the NPC this item.")
end
return formspec..
"label[8,2.6;Your inventory:]"..
"list[current_player;main;8,3;8,4;]"..
"label[1,3.1;"..minetest.formspec_escape(dialog.n_npc or "?").." wants:]"..
"label[1,3.1;"..minetest.formspec_escape(dialog.n_npc or "?").." "..wants_or_accepts..":]"..
"list[detached:yl_speak_up_player_"..pname..";npc_wants;2,3.5;1,1;]"..
"label[3.2,4.0;"..
minetest.formspec_escape(
@ -2055,8 +2091,7 @@ yl_speak_up.get_fs_edit_option_action_npc_wants = function(
data.item_desc
or "- none set -").."]"..
bg_img..
yl_speak_up.set_on_action_failure_dialog(pname, data,
"The player shall give the NPC this item.")..
action_failure_info..
save_button
end

View File

@ -1,5 +1,4 @@
-- TODO: check inscription of a sign?
-- TODO: invlist as dropdown of inventory lists at detected position
-- Which diffrent types of preconditions are available?
-- -> The following fields are part of a precondition:
@ -40,14 +39,15 @@ local check_what = {
"the inventory of the player", -- 5
"the inventory of the NPC", -- 6
"the inventory of a block somewhere", -- 7
"execute Lua code (requires npc_master priv)", -- 7 -> 8
"Call custom functions that are supposed to be overridden by the server.", -- 8 -> 9
"The preconditions of another dialog option are fulfilled/not fulfilled.", -- 9 -> 10
"an item the player offered/gave to the NPC", -- 8
"execute Lua code (requires npc_master priv)", -- 7 -> 9
"Call custom functions that are supposed to be overridden by the server.", -- 8 -> 10
"The preconditions of another dialog option are fulfilled/not fulfilled.", -- 9 -> 11
}
-- how to store these as p_type in the precondition:
local values_what = {"", "state", "block", "trade", "player_inv", "npc_inv",
"block_inv",
"block_inv", "player_offered_item",
-- requires npc_master priv
"function",
-- custom function (does not require npc_master priv)