Occupation: Add ability to set some of the NPCs properties.

Currently, you can set:
 - Trader status
 - Whether to show or hide gift items hints
NPC: Add enable/disable gift item hints flag
Schedules: Allow to set the enable/disable gift item hints flag
Dialogues: Add ability to choose from normal dialogues if hint dialogues are disabled.
This commit is contained in:
Hector Franqui 2017-09-05 19:02:50 -04:00
parent 8e5d6d03f4
commit 6c3988a731
3 changed files with 251 additions and 222 deletions

View File

@ -445,8 +445,15 @@ function npc.dialogue.start_dialogue(self, player, show_married_dialogue)
-- Choose a random dialogue from the common ones
dialogue = self.dialogues.normal[math.random(1, #self.dialogues.normal)]
elseif chance >= 90 then
-- Check if gift items hints are enabled
minetest.log("Self gift data enable: "..dump(self.gift_data.enable_gift_items_hints))
if self.gift_data.enable_gift_items_hints then
-- Choose a random dialogue line from the favorite/disliked item hints
dialogue = self.dialogues.hints[math.random(1, 4)]
else
-- Choose a random dialogue from the common ones
dialogue = self.dialogues.normal[math.random(1, #self.dialogues.normal)]
end
end
local dialogue_result = npc.dialogue.process_dialogue(self, dialogue, player:get_player_name())
@ -577,13 +584,13 @@ local function get_response_object_by_id_recursive(dialogue, current_depth, resp
elseif dialogue.responses ~= nil then
-- Get current depth and response ID
local d_i1, d_i2 = string.find(response_id, ":")
minetest.log("N1: "..dump(string.sub(response_id, 0, d_i1))..", N2: "..dump(string.sub(response_id, 1, d_i1-1)))
--minetest.log("N1: "..dump(string.sub(response_id, 0, d_i1))..", N2: "..dump(string.sub(response_id, 1, d_i1-1)))
local depth = tonumber(string.sub(response_id, 0, d_i1-1))
local id = tonumber(string.sub(response_id, d_i2 + 1))
minetest.log("Depth: "..dump(depth)..", id: "..dump(id))
--minetest.log("Depth: "..dump(depth)..", id: "..dump(id))
-- Check each response
for key,value in ipairs(dialogue.responses) do
minetest.log("Key: "..dump(key)..", value: "..dump(value)..", comp1: "..dump(current_depth == depth))
--minetest.log("Key: "..dump(key)..", value: "..dump(value)..", comp1: "..dump(current_depth == depth))
if value.action_type == "function" then
-- Check if we are on correct response and correct depth
if current_depth == depth then
@ -592,7 +599,7 @@ local function get_response_object_by_id_recursive(dialogue, current_depth, resp
end
end
else
minetest.log("Entering again...")
--minetest.log("Entering again...")
-- We have a dialogue action type. Need to check if dialogue has further responses
if value.action.responses ~= nil then
local response = get_response_object_by_id_recursive(value.action, current_depth + 1, response_id)

View File

@ -344,6 +344,8 @@ function npc.initialize(entity, pos, is_lua_entity, npc_stats, occupation_name)
favorite_items = npc.relationships.select_random_favorite_items(ent.sex, "phase1"),
-- Choose disliked items. Choose phase1 per default
disliked_items = npc.relationships.select_random_disliked_items(ent.sex),
-- Enable/disable gift item hints dialogue lines
enable_gift_items_hints = true
}
-- Flag that determines if NPC can have a relationship
@ -845,7 +847,8 @@ npc.schedule_properties = {
take_item = "take_item",
trader_status = "trader_status",
can_receive_gifts = "can_receive_gifts",
flag = "flag"
flag = "flag",
enable_gift_items_hints = "enable_gift_items_hints"
}
local function get_time_in_hours()
@ -1012,6 +1015,8 @@ function npc.schedule_change_property(self, property, args)
self.flags[args.flag_name] = false
end
end
elseif property == npc.schedule_properties.enable_gift_item_hints then
self.gift_data.enable_gift_items_hints = args.value
end
end

View File

@ -30,6 +30,9 @@
-- occupation that can be used to initialize NPCs. The format is the following:
-- {
-- dialogues = {
-- enable_gift_item_dialogues = true,
-- -- This flag enables/disables gift item dialogues.
-- -- If not set, it defaults to true.
-- type = "",
-- -- The type can be "given", "mix" or "tags"
-- data = {},
@ -374,6 +377,11 @@ function npc.occupations.initialize_occupation_values(self, occupation_name)
-- Initialize dialogues
if def.dialogues then
-- Check for gift item dialogues enable
if def.dialogues.disable_gift_item_dialogues then
self.dialogues.hints = {}
end
local dialogue_keys = {}
-- Check which type of dialogues we have
if def.dialogues.type == "given" and def.dialogues.keys then
@ -421,10 +429,19 @@ function npc.occupations.initialize_occupation_values(self, occupation_name)
end
end
-- Initialize properties
minetest.log("def.properties: "..dump(def.properties))
if def.properties then
-- Initialize trader status
if def.initial_trader_status then
self.trader_data.trader_status = def.initial_trader_status
if def.properties.initial_trader_status then
self.trader_data.trader_status = def.properties.initial_trader_status
end
-- Enable/disable gift items hints
if def.properties.enable_gift_items_hints ~= nil then
self.gift_data.enable_gift_items_hints = def.properties.enable_gift_items_hints
end
end
-- Initialize schedule entries
if def.schedules_entries and table.getn(npc.utils.get_map_keys(def.schedules_entries)) > 0 then