Relationships: Added favorite and disliked items hints to dialogues.
This commit is contained in:
parent
216c77ca81
commit
f956101f61
61
dialogue.lua
61
dialogue.lua
@ -30,9 +30,11 @@ function npc.dialogue.show_options_dialogue(self, responses, dismiss_option_labe
|
|||||||
if i > 1 then
|
if i > 1 then
|
||||||
y = (y * i)
|
y = (y * i)
|
||||||
end
|
end
|
||||||
formspec = formspec.."button_exit[0.5,"..(y - 0.5)..";6,0.5;opt"..tostring(i)..";"..responses[i].text.."]"
|
formspec = formspec.."button_exit[0.5,"
|
||||||
|
..(y - 0.5)..";6,0.5;opt"..tostring(i)..";"..responses[i].text.."]"
|
||||||
end
|
end
|
||||||
formspec = formspec.."button_exit[0.5,"..(formspec_height - 0.7)..";6,0.5;exit;"..dismiss_option_label.."]"
|
formspec = formspec.."button_exit[0.5,"
|
||||||
|
..(formspec_height - 0.7)..";6,0.5;exit;"..dismiss_option_label.."]"
|
||||||
|
|
||||||
-- Create entry on options_dialogue table
|
-- Create entry on options_dialogue table
|
||||||
npc.dialogue.dialogue_results.options_dialogue[player_name] = {
|
npc.dialogue.dialogue_results.options_dialogue[player_name] = {
|
||||||
@ -68,8 +70,17 @@ end
|
|||||||
-- Dialogue methods
|
-- Dialogue methods
|
||||||
-- Select random dialogue objects for an NPC based on sex
|
-- Select random dialogue objects for an NPC based on sex
|
||||||
-- and the relationship phase with player
|
-- and the relationship phase with player
|
||||||
function npc.dialogue.select_random_dialogues_for_npc(sex, phase)
|
function npc.dialogue.select_random_dialogues_for_npc(sex,
|
||||||
local result = {}
|
phase,
|
||||||
|
favorite_items,
|
||||||
|
disliked_items,
|
||||||
|
only_hints)
|
||||||
|
local result = {
|
||||||
|
normal = {},
|
||||||
|
hints = {}
|
||||||
|
}
|
||||||
|
|
||||||
|
if only_hints == false then
|
||||||
local dialogues = npc.data.DIALOGUES.female
|
local dialogues = npc.data.DIALOGUES.female
|
||||||
if sex == npc.MALE then
|
if sex == npc.MALE then
|
||||||
dialogues = npc.data.DIALOGUES.male
|
dialogues = npc.data.DIALOGUES.male
|
||||||
@ -79,29 +90,42 @@ function npc.dialogue.select_random_dialogues_for_npc(sex, phase)
|
|||||||
-- Determine how many dialogue lines the NPC will have
|
-- Determine how many dialogue lines the NPC will have
|
||||||
local number_of_dialogues = math.random(npc.dialogue.MIN_DIALOGUES, npc.dialogue.MAX_DIALOGUES)
|
local number_of_dialogues = math.random(npc.dialogue.MIN_DIALOGUES, npc.dialogue.MAX_DIALOGUES)
|
||||||
|
|
||||||
minetest.log("Dialogues by string: "..dump(dialogues["1"]))
|
|
||||||
minetest.log("Dialogues by int: "..dump(dialogues[1]))
|
|
||||||
minetest.log("Dialogues: "..dump(dialogues))
|
|
||||||
|
|
||||||
for i = 1,number_of_dialogues do
|
for i = 1,number_of_dialogues do
|
||||||
local dialogue_id = math.random(1, #dialogues)
|
local dialogue_id = math.random(1, #dialogues)
|
||||||
result[i] = dialogues[dialogue_id]
|
result.normal[i] = dialogues[dialogue_id]
|
||||||
|
|
||||||
-- Check if this particular dialogue has responses
|
-- Check if this particular dialogue has responses
|
||||||
if result[i].responses then
|
if result.normal[i].responses then
|
||||||
-- Check each response to see if they have action_type == "function".
|
-- Check each response to see if they have action_type == "function".
|
||||||
-- This way the indices for this particular response will be stored
|
-- This way the indices for this particular response will be stored
|
||||||
-- and the function can be retrieved for execution later.
|
-- and the function can be retrieved for execution later.
|
||||||
for key,value in ipairs(result[i].responses) do
|
for key,value in ipairs(result.normal[i].responses) do
|
||||||
if value.action_type == "function" then
|
if value.action_type == "function" then
|
||||||
result[i].responses[key].dialogue_id = dialogue_id
|
result.normal[i].responses[key].dialogue_id = dialogue_id
|
||||||
result[i].responses[key].response_id = key
|
result.normal[i].responses[key].response_id = key
|
||||||
minetest.log("Storing dialogue and response id: "..dump(result[i].responses[key]))
|
minetest.log("Storing dialogue and response id: "
|
||||||
|
..dump(result.normal[i].responses[key]))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Add item hints.
|
||||||
|
-- Favorite items
|
||||||
|
for i = 1, 2 do
|
||||||
|
result.hints[i] = {}
|
||||||
|
result.hints[i].text =
|
||||||
|
npc.get_hint_for_favorite_item(favorite_items["fav"..tostring(i)], sex, phase)
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Disliked items
|
||||||
|
for i = 3, 4 do
|
||||||
|
result.hints[i] = {}
|
||||||
|
result.hints[i].text =
|
||||||
|
npc.get_hint_for_disliked_item(disliked_items["dis"..tostring(i-2)], sex)
|
||||||
|
end
|
||||||
|
|
||||||
return result
|
return result
|
||||||
end
|
end
|
||||||
@ -112,7 +136,14 @@ function npc.dialogue.start_dialogue(self, player)
|
|||||||
-- Choose a dialogue randomly
|
-- Choose a dialogue randomly
|
||||||
-- TODO: Add support for favorite items hints
|
-- TODO: Add support for favorite items hints
|
||||||
-- Add support for flags
|
-- Add support for flags
|
||||||
local dialogue = self.dialogues[math.random(1, #self.dialogues)]
|
local dialogue = {}
|
||||||
|
local chance = math.random(1, 100)
|
||||||
|
if chance < 90 then
|
||||||
|
dialogue = self.dialogues.normal[math.random(1, #self.dialogues.normal)]
|
||||||
|
elseif chance >= 90 then
|
||||||
|
dialogue = self.dialogues.hints[math.random(1, 4)]
|
||||||
|
end
|
||||||
|
|
||||||
npc.dialogue.process_dialogue(self, dialogue, player:get_player_name())
|
npc.dialogue.process_dialogue(self, dialogue, player:get_player_name())
|
||||||
end
|
end
|
||||||
|
|
||||||
|
115
npc.lua
115
npc.lua
@ -28,91 +28,119 @@ npc.FAVORITE_ITEMS = {
|
|||||||
-- Female
|
-- Female
|
||||||
npc.FAVORITE_ITEMS.female["phase1"] = {
|
npc.FAVORITE_ITEMS.female["phase1"] = {
|
||||||
{item = "default:apple",
|
{item = "default:apple",
|
||||||
response = "Hey, I really wanted an apple, thank you!"},
|
response = "Hey, I really wanted an apple, thank you!",
|
||||||
|
hint = "I could really do with an apple..."},
|
||||||
{item = "farming:bread",
|
{item = "farming:bread",
|
||||||
response = "Thanks, you didn't have to, but thanks..."}
|
response = "Thanks, you didn't have to, but thanks...",
|
||||||
|
hint = "Some fresh bread would be good!"}
|
||||||
}
|
}
|
||||||
npc.FAVORITE_ITEMS.female["phase2"] = {
|
npc.FAVORITE_ITEMS.female["phase2"] = {
|
||||||
{item = "farming:cotton",
|
{item = "farming:cotton",
|
||||||
response = "This is going to be very helpful, thank you!"},
|
response = "This is going to be very helpful, thank you!",
|
||||||
{item = "wool:wool",
|
hint = "If I just had some cotton lying around..."},
|
||||||
response = "Thanks, you didn't have to, but thanks..."}
|
{item = "wool:white",
|
||||||
|
response = "Thanks, you didn't have to, but thanks...",
|
||||||
|
hint = "Have you seen a white sheep? I need some wool."}
|
||||||
}
|
}
|
||||||
npc.FAVORITE_ITEMS.female["phase3"] = {
|
npc.FAVORITE_ITEMS.female["phase3"] = {
|
||||||
{item = "default:apple",
|
{item = "default:apple",
|
||||||
response = "Hey, I really wanted an apple, thank you!"},
|
response = "Hey, I really wanted an apple, thank you!",
|
||||||
|
hint = "I could really do with an apple..."},
|
||||||
{item = "farming:bread",
|
{item = "farming:bread",
|
||||||
response = "Thanks, you didn't have to, but thanks..."}
|
response = "Thanks, you didn't have to, but thanks...",
|
||||||
|
hint = "Some fresh bread would be good!"}
|
||||||
}
|
}
|
||||||
npc.FAVORITE_ITEMS.female["phase4"] = {
|
npc.FAVORITE_ITEMS.female["phase4"] = {
|
||||||
{item = "default:apple",
|
{item = "default:apple",
|
||||||
response = "Hey, I really wanted an apple, thank you!"},
|
response = "Hey, I really wanted an apple, thank you!",
|
||||||
|
hint = "I could really do with an apple..."},
|
||||||
{item = "farming:bread",
|
{item = "farming:bread",
|
||||||
response = "Thanks, you didn't have to, but thanks..."}
|
response = "Thanks, you didn't have to, but thanks...",
|
||||||
|
hint = "SOme fresh bread would be good!"}
|
||||||
}
|
}
|
||||||
npc.FAVORITE_ITEMS.female["phase5"] = {
|
npc.FAVORITE_ITEMS.female["phase5"] = {
|
||||||
{item = "default:apple",
|
{item = "default:apple",
|
||||||
response = "Hey, I really wanted an apple, thank you!"},
|
response = "Hey, I really wanted an apple, thank you!",
|
||||||
|
hint = "I could really do with an apple..."},
|
||||||
{item = "farming:bread",
|
{item = "farming:bread",
|
||||||
response = "Thanks, you didn't have to, but thanks..."}
|
response = "Thanks, you didn't have to, but thanks...",
|
||||||
|
hint = "Some fresh bread would be good!"}
|
||||||
}
|
}
|
||||||
npc.FAVORITE_ITEMS.female["phase6"] = {
|
npc.FAVORITE_ITEMS.female["phase6"] = {
|
||||||
{item = "default:apple",
|
{item = "default:apple",
|
||||||
response = "Hey, I really wanted an apple, thank you!"},
|
response = "Hey, I really wanted an apple, thank you!",
|
||||||
|
hint = "I could really do with an apple..."},
|
||||||
{item = "farming:bread",
|
{item = "farming:bread",
|
||||||
response = "Thanks, you didn't have to, but thanks..."}
|
response = "Thanks, you didn't have to, but thanks...",
|
||||||
|
hint = "Some fresh bread would be good!"}
|
||||||
}
|
}
|
||||||
-- Male
|
-- Male
|
||||||
npc.FAVORITE_ITEMS.male["phase1"] = {
|
npc.FAVORITE_ITEMS.male["phase1"] = {
|
||||||
{item = "default:apple",
|
{item = "default:apple",
|
||||||
response = "Hey, I really wanted an apple, thank you!"},
|
response = "Hey, I really wanted an apple, thank you!",
|
||||||
|
hint = "I could really do with an apple..."},
|
||||||
{item = "farming:bread",
|
{item = "farming:bread",
|
||||||
response = "Thanks, you didn't have to, but thanks..."}
|
response = "Thanks, you didn't have to, but thanks...",
|
||||||
|
hint = "Some fresh bread would be good!"}
|
||||||
}
|
}
|
||||||
npc.FAVORITE_ITEMS.male["phase2"] = {
|
npc.FAVORITE_ITEMS.male["phase2"] = {
|
||||||
{item = "farming:cotton",
|
{item = "farming:cotton",
|
||||||
response = "This is going to be very helpful, thank you!"},
|
response = "This is going to be very helpful, thank you!",
|
||||||
{item = "wool:wool",
|
hint = "If I just had some cotton lying around..."},
|
||||||
response = "Thanks, you didn't have to, but thanks..."}
|
{item = "wool:white",
|
||||||
|
response = "Thanks, you didn't have to, but thanks...",
|
||||||
|
hint = "Have you seen a white sheep? I need some wool."}
|
||||||
}
|
}
|
||||||
npc.FAVORITE_ITEMS.male["phase3"] = {
|
npc.FAVORITE_ITEMS.male["phase3"] = {
|
||||||
{item = "default:apple",
|
{item = "default:apple",
|
||||||
response = "Hey, I really wanted an apple, thank you!"},
|
response = "Hey, I really wanted an apple, thank you!",
|
||||||
|
hint = "I could really do with an apple..."},
|
||||||
{item = "farming:bread",
|
{item = "farming:bread",
|
||||||
response = "Thanks, you didn't have to, but thanks..."}
|
response = "Thanks, you didn't have to, but thanks...",
|
||||||
|
hint = "Some fresh bread would be good!"}
|
||||||
}
|
}
|
||||||
npc.FAVORITE_ITEMS.male["phase4"] = {
|
npc.FAVORITE_ITEMS.male["phase4"] = {
|
||||||
{item = "default:apple",
|
{item = "default:apple",
|
||||||
response = "Hey, I really wanted an apple, thank you!"},
|
response = "Hey, I really wanted an apple, thank you!",
|
||||||
|
hint = "I could really do with an apple..."},
|
||||||
{item = "farming:bread",
|
{item = "farming:bread",
|
||||||
response = "Thanks, you didn't have to, but thanks..."}
|
response = "Thanks, you didn't have to, but thanks...",
|
||||||
|
hint = "SOme fresh bread would be good!"}
|
||||||
}
|
}
|
||||||
npc.FAVORITE_ITEMS.male["phase5"] = {
|
npc.FAVORITE_ITEMS.male["phase5"] = {
|
||||||
{item = "default:apple",
|
{item = "default:apple",
|
||||||
response = "Hey, I really wanted an apple, thank you!"},
|
response = "Hey, I really wanted an apple, thank you!",
|
||||||
|
hint = "I could really do with an apple..."},
|
||||||
{item = "farming:bread",
|
{item = "farming:bread",
|
||||||
response = "Thanks, you didn't have to, but thanks..."}
|
response = "Thanks, you didn't have to, but thanks...",
|
||||||
|
hint = "Some fresh bread would be good!"}
|
||||||
}
|
}
|
||||||
npc.FAVORITE_ITEMS.male["phase6"] = {
|
npc.FAVORITE_ITEMS.male["phase6"] = {
|
||||||
{item = "default:apple",
|
{item = "default:apple",
|
||||||
response = "You always know what I want to eat honey... thanks!"},
|
response = "Hey, I really wanted an apple, thank you!",
|
||||||
|
hint = "I could really do with an apple..."},
|
||||||
{item = "farming:bread",
|
{item = "farming:bread",
|
||||||
response = "Thanks, you didn't have to, but thanks..."}
|
response = "Thanks, you didn't have to, but thanks...",
|
||||||
|
hint = "Some fresh bread would be good!"}
|
||||||
}
|
}
|
||||||
|
|
||||||
-- Disliked items
|
-- Disliked items
|
||||||
npc.DISLIKED_ITEMS = {
|
npc.DISLIKED_ITEMS = {
|
||||||
female = {
|
female = {
|
||||||
{item = "default:stone",
|
{item = "default:stone",
|
||||||
response = "Stone, oh... why do you give me this?"},
|
response = "Stone, oh... why do you give me this?",
|
||||||
|
hint = "Why would someone want a stone?"},
|
||||||
{item = "default:cobble",
|
{item = "default:cobble",
|
||||||
response = "Cobblestone? No, no, why?"}
|
response = "Cobblestone? No, no, why?",
|
||||||
|
hint = "Anything worst than stone is cobblestone."}
|
||||||
},
|
},
|
||||||
male = {
|
male = {
|
||||||
{item = "default:stone",
|
{item = "default:stone",
|
||||||
response = "Bah! Stone? I don't need this thing!"},
|
response = "Bah! Stone? I don't need this thing!",
|
||||||
|
hint = "Stones are useless!"},
|
||||||
{item = "default:cobble",
|
{item = "default:cobble",
|
||||||
response = "Cobblestone!? Wow, you sure think a lot before giving a gift..."}
|
response = "Cobblestone!? Wow, you sure think a lot before giving a gift...",
|
||||||
|
hint = "If I really hate something, that's cobblestone!"}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -187,6 +215,27 @@ function npc.get_response_for_disliked_item(item_name, sex)
|
|||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Gets the item hint for a favorite item
|
||||||
|
function npc.get_hint_for_favorite_item(item_name, sex, phase)
|
||||||
|
for i = 1, #npc.FAVORITE_ITEMS[sex][phase] do
|
||||||
|
if npc.FAVORITE_ITEMS[sex][phase][i].item == item_name then
|
||||||
|
return npc.FAVORITE_ITEMS[sex][phase][i].hint
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Gets the item hint for a disliked item
|
||||||
|
function npc.get_hint_for_disliked_item(item_name, sex)
|
||||||
|
for i = 1, #npc.DISLIKED_ITEMS[sex] do
|
||||||
|
if npc.DISLIKED_ITEMS[sex][i].item == item_name then
|
||||||
|
return npc.DISLIKED_ITEMS[sex][i].hint
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
-- Functions on right click
|
-- Functions on right click
|
||||||
---------------------------------------------------------------------------------------
|
---------------------------------------------------------------------------------------
|
||||||
-- Gift and relationship system
|
-- Gift and relationship system
|
||||||
@ -776,7 +825,11 @@ local function npc_spawn(self, pos)
|
|||||||
ent.is_married_to = nil
|
ent.is_married_to = nil
|
||||||
|
|
||||||
-- Initialize dialogues
|
-- Initialize dialogues
|
||||||
ent.dialogues = npc.dialogue.select_random_dialogues_for_npc(ent.sex, "phase1")
|
ent.dialogues = npc.dialogue.select_random_dialogues_for_npc(ent.sex,
|
||||||
|
"phase1",
|
||||||
|
ent.gift_data.favorite_items,
|
||||||
|
ent.gift_data.disliked_items,
|
||||||
|
false)
|
||||||
|
|
||||||
minetest.log(dump(ent))
|
minetest.log(dump(ent))
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user