Store

The store class represents a collection of inventories that are owned by a character for the purpose of trade.
Return to Index
new ( )
__gc ( )
__eq ( am.store rhs ) -> ( boolean )
owner ( ) -> ( am.character )
owner ( am.character owner ) -> ( am.store )
store_id ( ) -> ( string )
buy ( am.character buyer , am.item item , number value_factor = 1.0 ) -> ( am.return_code )
sell ( am.character seller , am.item item , number value_factor = 1.0 , boolean make_new_inventory = false , boolean allow_zero_coin = false ) -> ( am.return_code )
create_inventory ( ) -> ( am.inventory )
add_inventory ( am.inventory inventory ) -> ( boolean )
remove_inventory ( am.inventory inventory ) -> ( boolean )
remove_all_inventories ( ) -> ( am.store )
inventory ( integer index ) -> ( am.inventory )
inventories ( ) -> ( array )
num_inventories ( ) -> ( array )
default_inventory_size ( ) -> ( array )
new ( )
Creates a new store instance.
__gc ( )
Releases the reference counter on this store.
__eq ( am.store rhs ) -> ( boolean )
Compares this store with another store object. Will not return true for equivalent stores.
Parameters:
am.store rhs : The other store to compare with.
Returns:
boolean : True if the stores are the same object.
owner ( ) -> ( am.character )
Returns the stores owner.
Returns:
am.character : The owner.
owner ( am.character owner ) -> ( am.store )
Sets the store owner, can be nil.
Parameters:
am.character owner : The new owner.
Returns:
am.store : This
store_id ( ) -> ( string )
Returns the store's id. Used to uniquely identify the store.
Returns:
string : The store's id.
buy ( am.character buyer , am.item item , number value_factor = 1.0 ) -> ( am.return_code )
Attempts to buy the item from the store using the purse from the buyer character.
Parameters:
am.character buyer : The character buying the item.
am.item item : The item to buy.
number value_factor = 1.0 : A multiplier that affects the cost of the item.
Returns:
am.return_code : Return codes for the purchase:
success The item was bought.
nil_parameter The buyer or item was nil.
no_store_owner Cannot buy the item with no store owner.
no_inventories Could not find the item in the store because there are no inventories.
item_not_in_inventory Could not find the item in the store inventories.
not_enough_coin Buyer does not have enough coin to buy the item.
sell ( am.character seller , am.item item , number value_factor = 1.0 , boolean make_new_inventory = false , boolean allow_zero_coin = false ) -> ( am.return_code )
Attempts to sell the item from the seller character. Has options for allowing the store to automatically expand by making new inventories if need be and allowing for the store owner to sell the item without actually having the coin to pay for the item.
Parameters:
am.character seller : The character selling the item.
am.item item : The item to sell.
number value_factor = 1.0 : A multiplier that affects the cost of the item.
boolean make_new_inventory = false : If there is not enough space in the inventories then a new one is made.
boolean allow_zero_coin = false : As coin is taken from the store owner to give to the seller, this can force the seller to receive the full amount even if the store owner doesn't have the available coin.
Returns:
am.return_code : Return codes for the sale:
success The item was sold.
nil_parameter The seller or item was nil.
no_store_owner Cannot sell the item with no store owner.
no_inventories No inventories and make_new_inventory is false.
not_enough_inventory_space Not enough space in the inventories to fit the item and make_new_inventory is false.
not_enough_coin Store owner does not have enough coin to buy the item and allow_zero_coin is false.
create_inventory ( ) -> ( am.inventory )
Creates a new store inventory using the default inventory size.
Returns:
am.inventory : The new store inventory.
add_inventory ( am.inventory inventory ) -> ( boolean )
Adds the given inventory to the ones controlled by the store.
Parameters:
am.inventory inventory : The inventory to add.
Returns:
boolean : True if the inventory was successfully added, false if the inventory was nil or already part of the store.
remove_inventory ( am.inventory inventory ) -> ( boolean )
Removes the given inventory from the store.
Parameters:
am.inventory inventory : The inventory to remove.
Returns:
boolean : True if the inventory was successfully removed, false if the inventory was nil or not part of the store.
remove_all_inventories ( ) -> ( am.store )
Removes all the inventories from the store.
Returns:
am.store : This
inventory ( integer index ) -> ( am.inventory )
Returns the inventory at the given index, returns nil if outside of the number of inventories.
Parameters:
integer index : The index to get the inventory from.
Returns:
am.inventory : The inventory at the given index.
inventories ( ) -> ( array )
Returns an array of all the inventories in this store.
Returns:
array : All the inventories.
num_inventories ( ) -> ( array )
Returns an array of all the inventories in this store.
Returns:
array : All the inventories.
default_inventory_size ( ) -> ( array )
Returns an array of all the inventories in this store.
Returns:
array : All the inventories.