Module shop
Adds shops
Functions
get_by_area (aid) | Get a shop by its land area ID |
get_by_pos (pos) | |
add_shop (s) | |
can_admin (pname, pos) | Checks whether a user can use the admin interface for the shop |
create_shop (pname, pos) | Creates shops, checks permissions |
unassign_chest (s, pos, inv) | Unassigns item allocation of chest. |
can_buy (pos, pname, itemname, count, price) | Can user buy from shop, checks permissions |
buy (pos, pname, item, count) | Buy from shop, checks permissions |
Class Shop
Shop.StockedItem | StockedItem |
Shop.Chest | Chest |
Shop:new (obj) | Constructor |
Shop:to_table () | Export to Lua table |
Shop:from_table (tab) | Import from Lua table |
Shop:get_items () | Get table of items sold by this shop |
Shop:get_item (name) | Get StockedItem by item name |
Shop:get_item_or_make (name) | Get stock item table by item name, or make it if it doesn’t exist. |
Shop:add_chest (pos) | Add a chest to store stock in |
Shop:get_chest (pos) | Get a chest by pos |
Shop:get_chests_for_item (name, count, filter) | Get a list of chests which contain enough itmes to fulfill the requested name and count, or nil |
Shop:chest_poll (pos, inv) | Reads chest inventory, and updates stock counts |
Shop:chest_add_item (pos, stack) | An item has been added to a chest, make note of it |
Shop:chest_remove_item (pos, stack) | An item has been removed from a chest, make note of it |
Functions
- get_by_area (aid)
-
Get a shop by its land area ID
Parameters:
- aid int
- get_by_pos (pos)
-
Parameters:
- pos table
- add_shop (s)
-
Parameters:
- s table
- can_admin (pname, pos)
-
Checks whether a user can use the admin interface for the shop
Parameters:
- create_shop (pname, pos)
-
Creates shops, checks permissions
Parameters:
Returns:
-
true
Or
- nil
- string Error message
- unassign_chest (s, pos, inv)
-
Unassigns item allocation of chest. Will return any items.
Parameters:
- can_buy (pos, pname, itemname, count, price)
-
Can user buy from shop, checks permissions
Parameters:
Returns:
-
true
Or
- nil
- string Error message
- buy (pos, pname, item, count)
-
Buy from shop, checks permissions
Parameters:
Returns:
-
true
Or
- nil
- string Error message
Class Shop
- Shop.StockedItem
-
StockedItem
Fields:
- Item string name
- Count int sold
- Set int price, -1 for not for sale
- Count int sold
- Shop.Chest
-
Chest
Fields:
- Shop:new (obj)
-
Constructor
Parameters:
- obj A table to construct an object on top of
Returns:
- Shop:to_table ()
-
Export to Lua table
Returns:
- Shop:from_table (tab)
-
Import from Lua table
Parameters:
- tab table
Returns:
-
bool
true on success, false on failure
- Shop:get_items ()
-
Get table of items sold by this shop
Returns:
-
table
Keys are resolved item names, values are StockedItem.
- Shop:get_item (name)
-
Get StockedItem by item name
Parameters:
- name
Returns:
- Shop:get_item_or_make (name)
-
Get stock item table by item name, or make it if it doesn’t exist.
Parameters:
- name
Returns:
- Shop:add_chest (pos)
-
Add a chest to store stock in
Parameters:
- pos table
Returns:
-
table
chest table
- Shop:get_chest (pos)
-
Get a chest by pos
Parameters:
- pos table
Returns:
-
table
chest table
- Shop:get_chests_for_item (name, count, filter)
-
Get a list of chests which contain enough itmes to
fulfill the requested name and count, or nil
Parameters:
- name string Item name
- count int Number of items, >0
- filter func func(chest_table)
Returns:
-
[table] or nil
- Shop:chest_poll (pos, inv)
-
Reads chest inventory, and updates stock counts This should be avoided, and the incremental methods used instead.
Parameters:
- pos table
- inv InvRef
- Shop:chest_add_item (pos, stack)
-
An item has been added to a chest, make note of it
Parameters:
- pos table
- stack ItemStack
- Shop:chest_remove_item (pos, stack)
-
An item has been removed from a chest, make note of it
Parameters:
- pos table
- stack ItemStack