diff --git a/dialogue.lua b/dialogue.lua index 9acbce4..99c02d2 100644 --- a/dialogue.lua +++ b/dialogue.lua @@ -30,9 +30,11 @@ function npc.dialogue.show_options_dialogue(self, responses, dismiss_option_labe if i > 1 then y = (y * i) 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 - 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 npc.dialogue.dialogue_results.options_dialogue[player_name] = { @@ -68,39 +70,61 @@ end -- Dialogue methods -- Select random dialogue objects for an NPC based on sex -- and the relationship phase with player -function npc.dialogue.select_random_dialogues_for_npc(sex, phase) - local result = {} - local dialogues = npc.data.DIALOGUES.female - if sex == npc.MALE then - dialogues = npc.data.DIALOGUES.male - end - dialogues = dialogues[phase] - - -- Determine how many dialogue lines the NPC will have - 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 - local dialogue_id = math.random(1, #dialogues) - result[i] = dialogues[dialogue_id] - - -- Check if this particular dialogue has responses - if result[i].responses then - -- Check each response to see if they have action_type == "function". - -- This way the indices for this particular response will be stored - -- and the function can be retrieved for execution later. - for key,value in ipairs(result[i].responses) do - if value.action_type == "function" then - result[i].responses[key].dialogue_id = dialogue_id - result[i].responses[key].response_id = key - minetest.log("Storing dialogue and response id: "..dump(result[i].responses[key])) - end - end +function npc.dialogue.select_random_dialogues_for_npc(sex, + phase, + favorite_items, + disliked_items, + only_hints) + local result = { + normal = {}, + hints = {} + } + if only_hints == false then + local dialogues = npc.data.DIALOGUES.female + if sex == npc.MALE then + dialogues = npc.data.DIALOGUES.male end + dialogues = dialogues[phase] + + -- Determine how many dialogue lines the NPC will have + local number_of_dialogues = math.random(npc.dialogue.MIN_DIALOGUES, npc.dialogue.MAX_DIALOGUES) + + for i = 1,number_of_dialogues do + local dialogue_id = math.random(1, #dialogues) + result.normal[i] = dialogues[dialogue_id] + + -- Check if this particular dialogue has responses + if result.normal[i].responses then + -- Check each response to see if they have action_type == "function". + -- This way the indices for this particular response will be stored + -- and the function can be retrieved for execution later. + for key,value in ipairs(result.normal[i].responses) do + if value.action_type == "function" then + result.normal[i].responses[key].dialogue_id = dialogue_id + result.normal[i].responses[key].response_id = key + minetest.log("Storing dialogue and response id: " + ..dump(result.normal[i].responses[key])) + 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 @@ -112,7 +136,14 @@ function npc.dialogue.start_dialogue(self, player) -- Choose a dialogue randomly -- TODO: Add support for favorite items hints -- 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()) end diff --git a/npc.lua b/npc.lua index ff89a07..2871858 100755 --- a/npc.lua +++ b/npc.lua @@ -28,91 +28,119 @@ npc.FAVORITE_ITEMS = { -- Female npc.FAVORITE_ITEMS.female["phase1"] = { {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", - 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"] = { {item = "farming:cotton", - response = "This is going to be very helpful, thank you!"}, - {item = "wool:wool", - response = "Thanks, you didn't have to, but thanks..."} + response = "This is going to be very helpful, thank you!", + hint = "If I just had some cotton lying around..."}, + {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"] = { {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", - 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"] = { {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", - 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"] = { {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", - 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"] = { {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", - 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 npc.FAVORITE_ITEMS.male["phase1"] = { {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", - 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"] = { {item = "farming:cotton", - response = "This is going to be very helpful, thank you!"}, - {item = "wool:wool", - response = "Thanks, you didn't have to, but thanks..."} + response = "This is going to be very helpful, thank you!", + hint = "If I just had some cotton lying around..."}, + {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"] = { {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", - 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"] = { {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", - 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"] = { {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", - 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"] = { {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", - 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 npc.DISLIKED_ITEMS = { female = { {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", - response = "Cobblestone? No, no, why?"} + response = "Cobblestone? No, no, why?", + hint = "Anything worst than stone is cobblestone."} }, male = { {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", - 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 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 --------------------------------------------------------------------------------------- -- Gift and relationship system @@ -776,7 +825,11 @@ local function npc_spawn(self, pos) ent.is_married_to = nil -- 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))