mirror of
https://gitea.your-land.de/Sokomine/yl_speak_up.git
synced 2025-08-19 18:55:49 +02:00
added yl_speak_up.get_one_npc_property; added yl_speak_up.get_npc_properties_long_version for easier access to properties
This commit is contained in:
parent
b9e6a8a74c
commit
e842960830
@ -26,11 +26,6 @@ yl_speak_up.calculate_available_generic_dialogs = function(current_n_id, player)
|
||||
|
||||
-- cache the properties of the NPC
|
||||
local properties = yl_speak_up.get_npc_properties(pname)
|
||||
if(not(properties)) then
|
||||
properties = {}
|
||||
else
|
||||
properties = properties.properties
|
||||
end
|
||||
|
||||
-- Let's go through all the options and see if we need to display them to the user
|
||||
-- check all options: option key (n_id), option value/data (list of preconditions)
|
||||
|
@ -504,8 +504,9 @@ yl_speak_up.execute_effect = function(player, n_id, o_id, r)
|
||||
-- "the value of a property of the NPC (for generic NPC)", -- property
|
||||
elseif(r.r_type == "property") then
|
||||
local pname = player:get_player_name()
|
||||
local property_data = yl_speak_up.get_npc_properties(pname)
|
||||
if(not(property_data)) then
|
||||
-- get the properties of the NPC
|
||||
local properties = yl_speak_up.get_npc_properties(pname)
|
||||
if(not(properties)) then
|
||||
yl_speak_up.debug_msg(player, n_id, o_id, tostring(r.r_id).." "..
|
||||
"property: Failed to access properties of NPC "..tostring(n_id))
|
||||
return false
|
||||
@ -515,7 +516,7 @@ yl_speak_up.execute_effect = function(player, n_id, o_id, r)
|
||||
"property: No name of property given")
|
||||
return false
|
||||
end
|
||||
local var_val = property_data.properties[r.r_value]
|
||||
local var_val = properties[r.r_value]
|
||||
-- set the value of the variable
|
||||
local new_value = yl_speak_up.execute_effect_get_new_value(r, var_val, nil)
|
||||
local res = yl_speak_up.set_npc_property(pname, r.r_value, new_value, "effect")
|
||||
|
@ -59,11 +59,6 @@ yl_speak_up.eval_all_preconditions = function(player, prereq, o_id, other_option
|
||||
-- we need to be fast and efficient here - and the properties stay fixed for the NPC
|
||||
-- during this call, so we can cache them
|
||||
local properties = yl_speak_up.get_npc_properties(pname)
|
||||
if(not(properties)) then
|
||||
properties = {}
|
||||
else
|
||||
properties = properties.properties
|
||||
end
|
||||
|
||||
for k, p in pairs(prereq) do
|
||||
yl_speak_up.debug_msg(player, n_id, o_id, "..checking "..
|
||||
@ -252,12 +247,6 @@ yl_speak_up.eval_precondition = function(player, n_id, p, other_options_true_or_
|
||||
if(not(properties)) then
|
||||
local pname = player:get_player_name()
|
||||
properties = yl_speak_up.get_npc_properties(pname)
|
||||
-- if there are no properties: return false
|
||||
if(not(properties)) then
|
||||
properties = {}
|
||||
else
|
||||
properties = properties.properties
|
||||
end
|
||||
end
|
||||
return yl_speak_up.eval_precondition_with_operator(p, properties[p.p_value])
|
||||
|
||||
|
@ -3,22 +3,35 @@
|
||||
-- This is used when an NPC doesn't have a specific dialog but still wants to
|
||||
-- make use of a (or some) generic dialog(es)
|
||||
|
||||
-- helper function:
|
||||
-- get one property value of the NPC
|
||||
yl_speak_up.get_one_npc_property = function(pname, property_name)
|
||||
if(not(pname)) then
|
||||
return nil
|
||||
end
|
||||
-- get just the property data
|
||||
return yl_speak_up.get_npc_properties(pname, false)[property_name]
|
||||
end
|
||||
|
||||
|
||||
-- helper function;
|
||||
-- adds "normal" properties of the npc with a self.<property_name> prefix as well
|
||||
yl_speak_up.get_npc_properties = function(pname)
|
||||
-- if long_version is not set, a table containing all properties is returned;
|
||||
-- if long_version *is* set, a table containing the table above plus additional entries is returned
|
||||
yl_speak_up.get_npc_properties_long_version = function(pname, long_version)
|
||||
if(not(pname) or not(yl_speak_up.speak_to[pname])) then
|
||||
return
|
||||
return {}
|
||||
end
|
||||
local obj = yl_speak_up.speak_to[pname].obj
|
||||
if(not(obj)) then
|
||||
return
|
||||
return {}
|
||||
end
|
||||
local entity = obj:get_luaentity()
|
||||
if(not(entity)) then
|
||||
return
|
||||
return {}
|
||||
end
|
||||
if(not(entity.yl_speak_up)) then
|
||||
return
|
||||
return {}
|
||||
end
|
||||
local properties = entity.yl_speak_up.properties
|
||||
if(not(properties)) then
|
||||
@ -33,6 +46,10 @@ yl_speak_up.get_npc_properties = function(pname)
|
||||
end
|
||||
end
|
||||
properties["self.name"] = tostring(entity.name)
|
||||
if(not(long_version)) then
|
||||
return properties
|
||||
end
|
||||
-- the long version contains additional information
|
||||
local prop_names = {}
|
||||
for k, v in pairs(properties) do
|
||||
table.insert(prop_names, k)
|
||||
@ -42,11 +59,19 @@ yl_speak_up.get_npc_properties = function(pname)
|
||||
end
|
||||
|
||||
|
||||
-- most of the time we don't need object, entity or a list of the names of properties;
|
||||
-- this returns just the properties themshelves
|
||||
yl_speak_up.get_npc_properties = function(pname)
|
||||
return yl_speak_up.get_npc_properties_long_version(pname, false)
|
||||
end
|
||||
|
||||
|
||||
yl_speak_up.set_npc_property = function(pname, property_name, property_value, reason)
|
||||
if(not(pname) or not(property_name) or property_name == "") then
|
||||
return "No player name or property name given. Cannot load property data."
|
||||
end
|
||||
local property_data = yl_speak_up.get_npc_properties(pname)
|
||||
-- here we want a table with additional information
|
||||
local property_data = yl_speak_up.get_npc_properties_long_version(pname, true)
|
||||
if(not(property_data)) then
|
||||
return "Failed to load property data of NPC."
|
||||
end
|
||||
@ -119,7 +144,8 @@ yl_speak_up.get_fs_properties = function(pname, selected)
|
||||
return ""
|
||||
end
|
||||
|
||||
local property_data = yl_speak_up.get_npc_properties(pname)
|
||||
-- we want the long version with additional information
|
||||
local property_data = yl_speak_up.get_npc_properties_long_version(pname, true)
|
||||
if(not(property_data)) then
|
||||
-- something went wrong - there really is nothing useful we can do
|
||||
-- if the NPC we want to interact with doesn't exist or is broken
|
||||
|
Loading…
Reference in New Issue
Block a user