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:
parent
8e5d6d03f4
commit
6c3988a731
35
dialogue.lua
35
dialogue.lua
@ -231,10 +231,10 @@ end
|
|||||||
-- Creates and shows a multi-option dialogue based on the number of responses
|
-- Creates and shows a multi-option dialogue based on the number of responses
|
||||||
-- that the dialogue object contains
|
-- that the dialogue object contains
|
||||||
function npc.dialogue.show_options_dialogue(self,
|
function npc.dialogue.show_options_dialogue(self,
|
||||||
dialogue_key,
|
dialogue_key,
|
||||||
dialogue,
|
dialogue,
|
||||||
dismiss_option_label,
|
dismiss_option_label,
|
||||||
player_name)
|
player_name)
|
||||||
local responses = dialogue.responses
|
local responses = dialogue.responses
|
||||||
local options_length = table.getn(responses) + 1
|
local options_length = table.getn(responses) + 1
|
||||||
local formspec_height = (options_length * 0.7) + 0.4
|
local formspec_height = (options_length * 0.7) + 0.4
|
||||||
@ -269,12 +269,12 @@ end
|
|||||||
|
|
||||||
-- This function is used for showing a yes/no dialogue formspec
|
-- This function is used for showing a yes/no dialogue formspec
|
||||||
function npc.dialogue.show_yes_no_dialogue(self,
|
function npc.dialogue.show_yes_no_dialogue(self,
|
||||||
prompt,
|
prompt,
|
||||||
positive_answer_label,
|
positive_answer_label,
|
||||||
positive_callback,
|
positive_callback,
|
||||||
negative_answer_label,
|
negative_answer_label,
|
||||||
negative_callback,
|
negative_callback,
|
||||||
player_name)
|
player_name)
|
||||||
|
|
||||||
npc.lock_actions(self)
|
npc.lock_actions(self)
|
||||||
|
|
||||||
@ -445,8 +445,15 @@ function npc.dialogue.start_dialogue(self, player, show_married_dialogue)
|
|||||||
-- Choose a random dialogue from the common ones
|
-- Choose a random dialogue from the common ones
|
||||||
dialogue = self.dialogues.normal[math.random(1, #self.dialogues.normal)]
|
dialogue = self.dialogues.normal[math.random(1, #self.dialogues.normal)]
|
||||||
elseif chance >= 90 then
|
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
|
-- Choose a random dialogue line from the favorite/disliked item hints
|
||||||
dialogue = self.dialogues.hints[math.random(1, 4)]
|
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
|
end
|
||||||
|
|
||||||
local dialogue_result = npc.dialogue.process_dialogue(self, dialogue, player:get_player_name())
|
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
|
elseif dialogue.responses ~= nil then
|
||||||
-- Get current depth and response ID
|
-- Get current depth and response ID
|
||||||
local d_i1, d_i2 = string.find(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 depth = tonumber(string.sub(response_id, 0, d_i1-1))
|
||||||
local id = tonumber(string.sub(response_id, d_i2 + 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
|
-- Check each response
|
||||||
for key,value in ipairs(dialogue.responses) do
|
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
|
if value.action_type == "function" then
|
||||||
-- Check if we are on correct response and correct depth
|
-- Check if we are on correct response and correct depth
|
||||||
if current_depth == depth then
|
if current_depth == depth then
|
||||||
@ -592,7 +599,7 @@ local function get_response_object_by_id_recursive(dialogue, current_depth, resp
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
minetest.log("Entering again...")
|
--minetest.log("Entering again...")
|
||||||
-- We have a dialogue action type. Need to check if dialogue has further responses
|
-- We have a dialogue action type. Need to check if dialogue has further responses
|
||||||
if value.action.responses ~= nil then
|
if value.action.responses ~= nil then
|
||||||
local response = get_response_object_by_id_recursive(value.action, current_depth + 1, response_id)
|
local response = get_response_object_by_id_recursive(value.action, current_depth + 1, response_id)
|
||||||
|
7
npc.lua
7
npc.lua
@ -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"),
|
favorite_items = npc.relationships.select_random_favorite_items(ent.sex, "phase1"),
|
||||||
-- Choose disliked items. Choose phase1 per default
|
-- Choose disliked items. Choose phase1 per default
|
||||||
disliked_items = npc.relationships.select_random_disliked_items(ent.sex),
|
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
|
-- Flag that determines if NPC can have a relationship
|
||||||
@ -845,7 +847,8 @@ npc.schedule_properties = {
|
|||||||
take_item = "take_item",
|
take_item = "take_item",
|
||||||
trader_status = "trader_status",
|
trader_status = "trader_status",
|
||||||
can_receive_gifts = "can_receive_gifts",
|
can_receive_gifts = "can_receive_gifts",
|
||||||
flag = "flag"
|
flag = "flag",
|
||||||
|
enable_gift_items_hints = "enable_gift_items_hints"
|
||||||
}
|
}
|
||||||
|
|
||||||
local function get_time_in_hours()
|
local function get_time_in_hours()
|
||||||
@ -1012,6 +1015,8 @@ function npc.schedule_change_property(self, property, args)
|
|||||||
self.flags[args.flag_name] = false
|
self.flags[args.flag_name] = false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
elseif property == npc.schedule_properties.enable_gift_item_hints then
|
||||||
|
self.gift_data.enable_gift_items_hints = args.value
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -30,6 +30,9 @@
|
|||||||
-- occupation that can be used to initialize NPCs. The format is the following:
|
-- occupation that can be used to initialize NPCs. The format is the following:
|
||||||
-- {
|
-- {
|
||||||
-- dialogues = {
|
-- dialogues = {
|
||||||
|
-- enable_gift_item_dialogues = true,
|
||||||
|
-- -- This flag enables/disables gift item dialogues.
|
||||||
|
-- -- If not set, it defaults to true.
|
||||||
-- type = "",
|
-- type = "",
|
||||||
-- -- The type can be "given", "mix" or "tags"
|
-- -- The type can be "given", "mix" or "tags"
|
||||||
-- data = {},
|
-- data = {},
|
||||||
@ -374,6 +377,11 @@ function npc.occupations.initialize_occupation_values(self, occupation_name)
|
|||||||
|
|
||||||
-- Initialize dialogues
|
-- Initialize dialogues
|
||||||
if def.dialogues then
|
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 = {}
|
local dialogue_keys = {}
|
||||||
-- Check which type of dialogues we have
|
-- Check which type of dialogues we have
|
||||||
if def.dialogues.type == "given" and def.dialogues.keys then
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Initialize properties
|
||||||
|
minetest.log("def.properties: "..dump(def.properties))
|
||||||
|
if def.properties then
|
||||||
-- Initialize trader status
|
-- Initialize trader status
|
||||||
if def.initial_trader_status then
|
if def.properties.initial_trader_status then
|
||||||
self.trader_data.trader_status = def.initial_trader_status
|
self.trader_data.trader_status = def.properties.initial_trader_status
|
||||||
end
|
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
|
-- Initialize schedule entries
|
||||||
if def.schedules_entries and table.getn(npc.utils.get_map_keys(def.schedules_entries)) > 0 then
|
if def.schedules_entries and table.getn(npc.utils.get_map_keys(def.schedules_entries)) > 0 then
|
||||||
|
Loading…
Reference in New Issue
Block a user