Trade: Working buy/sell trade mechanism.
Various cleanups and modularizations for supporting dedicated traders. Data: Added more favorite items for phase 1.
This commit is contained in:
13
npc.lua
13
npc.lua
@ -39,12 +39,14 @@ end
|
||||
|
||||
-- Utility function to get item name from a string
|
||||
local function get_item_name(item_string)
|
||||
return item_string.sub(item_string, 1, string.find(item_string, " "))
|
||||
local i,j = string.find(item_string, " ")
|
||||
return item_string.sub(item_string, 1, i-1)
|
||||
end
|
||||
|
||||
-- Utility function to get item count from a string
|
||||
local function get_item_count(item_string)
|
||||
return tonumber(item_string.sub(item_string, string.find(item_string, " ")))
|
||||
local i,j = string.find(item_string, " ")
|
||||
return tonumber(item_string.sub(item_string, i+1))
|
||||
end
|
||||
|
||||
local function initialize_inventory()
|
||||
@ -98,6 +100,13 @@ function npc.add_item_to_inventory(self, item_name, count)
|
||||
end
|
||||
end
|
||||
|
||||
-- Same add method but with itemstring for convenience
|
||||
function npc.add_item_to_inventory_itemstring(self, item_string)
|
||||
local item_name = get_item_name(item_string)
|
||||
local item_count = get_item_count(item_string)
|
||||
npc.add_item_to_inventory(self, item_name, item_count)
|
||||
end
|
||||
|
||||
-- Checks if an item is contained in the inventory. Returns
|
||||
-- the item string or nil if not found
|
||||
function npc.inventory_contains(self, item_name)
|
||||
|
Reference in New Issue
Block a user