Fix bug in marriage check for receiving gifts

This commit is contained in:
zorman2000 2016-11-29 14:05:09 -05:00
parent f53abf7072
commit 47847d2951
3 changed files with 44 additions and 15 deletions

View File

@ -24,7 +24,27 @@
-- chatline2 = { text = "Q2", options = nil } -- chatline2 = { text = "Q2", options = nil }
-- } -- }
local options = {"Question 1","Question 2","Question 3","Question 4"} local options = {"Question 1","Question 2","Question 3","Question 4"}
npc.dialogue = {}
npc.dialogue.YES_GIFT_ANSWER_LABEL = "Yes, give wielded item"
npc.dialogue.NO_GIFT_ANSWER_LAEBL = "Nevermind"
-- Yes/No dialogue declaration
npc.dialogue.gift_dialogue = smartfs.create("advanced_npc:gift_dialogue", function(state)
state:size(7, 2.4)
state:button(0.5, 0.7, 6, 0.5, "yes_option", npc.dialogue.YES_GIFT_ANSWER_LABEL)
state:button(0.5, 1.4, 6, 0.5, "no_option", npc.dialogue.NO_GIFT_ANSWER_LAEBL, true)
local dialogue_result
state:get("yes_option"):click(function(self, state)
dialogue_result = true
end)
state:get("no_option"):click(function(self, state)
dialogue_result = false
end)
end)
--------------------------------------------------------------------- ---------------------------------------------------------------------
-- Creates a formspec for dialog -- Creates a formspec for dialog
@ -45,13 +65,16 @@ local function create_formspec(options, close_option)
end end
-- New function for getting dialogue formspec -- New function for getting dialogue formspec
local l = smartfs.create("smartfs:load", function(state) function npc.dialogue.show_yes_no_dialogue(prompt, player_name)
state:load(minetest.get_modpath("smartfs").."/docs/example.smartfs") local dialogue_form = npc.dialogue.gift_dialogue
state:get("btn"):click(function(self,state)
print("Button clicked!") -- Send prompt message to player
end) minetest.chat_send_player(player_name, prompt)
return true
end) dialogue_form:show(player_name)
return dialogue_result
end
--------------------------------------------------------------------- ---------------------------------------------------------------------
-- Returns all chatlines for a specific NPC -- Returns all chatlines for a specific NPC

View File

@ -2,7 +2,7 @@
local path = minetest.get_modpath("advanced_npc") local path = minetest.get_modpath("advanced_npc")
-- Load SmartFS library by rubenwardy -- Load SmartFS library by rubenwardy
dofile(path .. "lib/smartfs.lua") dofile(path .. "/lib/smartfs.lua")
-- Intllib -- Intllib
local S local S

18
npc.lua
View File

@ -124,7 +124,7 @@ mobs.npc_drops = {
-- General functions -- General functions
-- Gets name of player or NPC -- Gets name of player or NPC
local function get_entity_name(entity) function npc.get_entity_name(entity)
if entity:is_player() then if entity:is_player() then
return entity:get_player_name() return entity:get_player_name()
else else
@ -314,8 +314,9 @@ end
local function check_npc_can_receive_gift(self, clicker_name) local function check_npc_can_receive_gift(self, clicker_name)
for i = 1, #self.relationships do for i = 1, #self.relationships do
if self.relationships[i].name == clicker_name then if self.relationships[i].name == clicker_name then
-- This checks avoid married NPC to receive from others -- Checks avoid married NPC to receive from others
if clicker_name == self.is_married_to then if self.is_married_to == nil
or (self.is_married ~= nil and self.is_married_to == clicker_name) then
return self.relationships[i].gift_timer_value >= self.relationships[i].gift_interval return self.relationships[i].gift_timer_value >= self.relationships[i].gift_interval
else else
return false return false
@ -381,7 +382,7 @@ local function receive_gift(self, clicker)
if item:get_name() == "" then return false end if item:get_name() == "" then return false end
-- Get clicker name -- Get clicker name
local clicker_name = get_entity_name(clicker) local clicker_name = npc.get_entity_name(clicker)
-- Create relationship if it doesn't exists -- Create relationship if it doesn't exists
if check_relationship_exists(self, clicker_name) == false then if check_relationship_exists(self, clicker_name) == false then
@ -517,7 +518,7 @@ end
-- Chat functions -- Chat functions
local function start_chat(self, clicker) local function start_chat(self, clicker)
local name = get_entity_name(clicker) local name = npc.get_entity_name(clicker)
-- Married player can tell NPC to follow or to stay at a given place -- Married player can tell NPC to follow or to stay at a given place
-- TODO: Improve this. There should be a dialogue box for this -- TODO: Improve this. There should be a dialogue box for this
if self.owner and self.owner == name then if self.owner and self.owner == name then
@ -600,6 +601,11 @@ mobs:register_mob("advanced_npc:npc", {
-- Receive gift or start chat -- Receive gift or start chat
if self.can_have_relationship then if self.can_have_relationship then
-- Show dialogue to confirm that player is giving item as gift
-- local result = npc.dialogue.show_yes_no_dialogue(
-- "Do you want to give your currently wielded item to "..self.nametag.."?",
-- name)
-- minetest.log("Dialogue outcome: "..dump(result))
if receive_gift(self, clicker) == false then if receive_gift(self, clicker) == false then
start_chat(self, clicker) start_chat(self, clicker)
end end
@ -615,8 +621,8 @@ mobs:register_mob("advanced_npc:npc", {
-- Gift timer check -- Gift timer check
if relationship.gift_timer_value < relationship.gift_interval then if relationship.gift_timer_value < relationship.gift_interval then
relationship.gift_timer_value = relationship.gift_timer_value + dtime relationship.gift_timer_value = relationship.gift_timer_value + dtime
-- Relationship decrease timer
else else
-- Relationship decrease timer
if relationship.relationship_decrease_timer_value if relationship.relationship_decrease_timer_value
< relationship.relationship_decrease_interval then < relationship.relationship_decrease_interval then
relationship.relationship_decrease_timer_value = relationship.relationship_decrease_timer_value =