Shopkeeper
Scripting with the Shopkeeper class.
A Shopkeeper
is a merchant that buys and sells items.
Fields & Properties
items
A list of items that this shopkeeper sells.
List<Item>
public
activeItemTypeFilter
The active item type filter.
ItemType
public
Creating Shopkeepers
It's not recommended to create shopkeepers at runtime, but it is possible. Shopkeeper
's are scriptable objects which cannot be created as assets at runtime for later use.
Filters
Get Filters
You can get all ItemType
filters of a shopkeeper with the GetFilterTypes
methods.
Set Filter
By setting the filter, only the items that match the filter will be returned by the GetItems
method. You will need a reference to an Item Type to set the filter.
Remove Filter
Get Items
You can get items wit the GetItems
method. If no filter is active, all items will be returned. Otherwise, only the items that match the filter will be returned.
Buying Items
You can but an item from a shopkeeper with the TryBuyItem
method. This method returns true
if the item was bought successfully. You will need a reference to an Item
. Buying may fail if the player does not have sufficient funds, lacking space in their inventory, or the shopkeeper does not sell the item. If successful, the item will appear in the player's inventory, and the cost will be subtracted from their funds.
quantity
is an int
that sets the amount of the item to purchase.
Before committing to this method, you have the option of checking if the item can be bought with CanBuyItem
method.
Selling Items
You can sell an ItemStack
to a shopkeeper with the TrySellItem
method. This method returns true
if the item was sold successfully. You will need a reference to an ItemStack
. Selling may fail if the player does not own the item or the item is not sellable. If successful, the item will be removed from the player's inventory and the selling cost will be added to the player's funds.
quantity
is an int
that sets the amount of the item to sell.
Before committing to this method, you have the option of checking if the item can be sold with CanSellItem
method.
Last updated