yl_speak_up.action_quest_item_take_back
This commit is contained in:
parent
5fecab3ed7
commit
11edcc8b31
@ -301,15 +301,8 @@ yl_speak_up.action_quest_item_prepare = function(player)
|
||||
end
|
||||
|
||||
|
||||
-- strip the quest information from the item and give it back to the NPC;
|
||||
-- returns the modified stack (but also places it in the NPC's inventory)
|
||||
yl_speak_up.action_quest_item_take_back = function(stack, player)
|
||||
-- TODO: implement action_quest_item_take_back
|
||||
end
|
||||
|
||||
|
||||
-- check if the item in the npc_gives slot is the one the NPC wants
|
||||
yl_speak_up.action_quest_item_check = function(stack, player)
|
||||
yl_speak_up.action_quest_item_check = function(player)
|
||||
-- which action are we talking about?
|
||||
local a = yl_speak_up.get_action_by_player(player)
|
||||
if(not(a) or not(a.a_id) or not(a.a_value)) then
|
||||
@ -359,6 +352,47 @@ yl_speak_up.action_quest_item_check = function(stack, player)
|
||||
end
|
||||
|
||||
|
||||
-- strip the quest information from the item and give it back to the NPC;
|
||||
-- returns the modified stack (but also places it in the NPC's inventory)
|
||||
yl_speak_up.action_quest_item_take_back = function(player)
|
||||
-- which action are we talking about?
|
||||
local a = yl_speak_up.get_action_by_player(player)
|
||||
if(not(a) or not(a.a_id) or not(a.a_value)) then
|
||||
return false
|
||||
end
|
||||
-- TODO: what to do with the item? it is something wrong...giving it back might be nice
|
||||
if(not(yl_speak_up.action_quest_item_check(player))) then
|
||||
return false
|
||||
end
|
||||
local pname = player:get_player_name()
|
||||
local n_id = yl_speak_up.speak_to[pname].n_id
|
||||
-- get the item that the NPC shall take back (or accept in npc_wants)
|
||||
local trade_inv = minetest.get_inventory({type="detached", name="yl_speak_up_player_"..pname})
|
||||
local stack = trade_inv:get_stack("npc_wants", 1)
|
||||
-- we already checked that it is the correct item
|
||||
local meta = stack:get_meta()
|
||||
-- if given: set the item stack description
|
||||
if(a.a_item_desc and a.a_item_desc ~= "") then
|
||||
meta:set_string("description", "")
|
||||
end
|
||||
-- delete all the special IDs that where added before
|
||||
if(a.a_item_quest_id and a.a_item_quest_id ~= "") then
|
||||
meta:set_string("yl_speak_up:quest_item_for", "")
|
||||
meta:set_string("yl_speak_up:quest_item_from", "")
|
||||
meta:set_string("yl_speak_up:quest_id", "")
|
||||
end
|
||||
local npc_inv = minetest.get_inventory({type="detached", name="yl_speak_up_npc_"..tostring(n_id)})
|
||||
-- has the NPC room enough for the item?
|
||||
-- TODO: and if he has no room? destory the item?
|
||||
if(npc_inv:room_for_item("npc_main", stack)) then
|
||||
npc_inv:add_item("npc_main", stack)
|
||||
end
|
||||
-- the NPC has accepted the item
|
||||
trade_inv:set_stack("npc_wants", 1, ItemStack())
|
||||
return true
|
||||
end
|
||||
|
||||
|
||||
-- show the diffrent action-related formspecs and handle input to them
|
||||
-- (Note: trade is handled in trade_simple.lua)
|
||||
|
||||
@ -387,10 +421,9 @@ yl_speak_up.input_fs_action_npc_gives = function(player, formname, fields)
|
||||
-- the npc_gives slot does not accept input - so we don't have to check for any misplaced items
|
||||
-- but if the player aborts, give the item back to the NPC
|
||||
if(fields.back_to_talk) then
|
||||
local stack = trade_inv:get_stack("npc_gives", 1)
|
||||
-- strip the quest item info from the stack (so that it may stack again)
|
||||
-- and give that (hopefully) stackable stack back to the NPC
|
||||
yl_speak_up.action_quest_item_take_back(stack, player)
|
||||
yl_speak_up.action_quest_item_take_back(player)
|
||||
-- the action failed
|
||||
yl_speak_up.execute_next_action(player, a_id, false)
|
||||
return
|
||||
@ -462,17 +495,8 @@ yl_speak_up.input_fs_action_npc_wants = function(player, formname, fields)
|
||||
-- the player tried to give something; check if it is the right thing
|
||||
if(not(trade_inv:is_empty("npc_wants"))) then
|
||||
local stack = trade_inv:get_stack("npc_wants", 1)
|
||||
-- check if it really is the item the NPC wanted
|
||||
-- TODO: implement
|
||||
local is_correct_item = yl_speak_up.action_quest_item_check(stack, player)
|
||||
if(is_correct_item) then
|
||||
-- strip the quest item info from the stack (so that it may stack again)
|
||||
-- and give it to the NPC
|
||||
yl_speak_up.action_quest_item_take_back(stack, player)
|
||||
else
|
||||
-- TODO: what to do with the wrong item? -> give back
|
||||
-- (just add back to the player's inv? or drop to ground?
|
||||
end
|
||||
-- check if it really is the item the NPC wanted; let the NPC take it
|
||||
local is_correct_item = yl_speak_up.action_quest_item_take_back(player)
|
||||
-- the action may have been a success or failure
|
||||
yl_speak_up.execute_next_action(player, a_id, is_correct_item)
|
||||
return
|
||||
|
Loading…
Reference in New Issue
Block a user