Shop

Shops are used to buy and sell items using currency. The currency could be anything. By default the shop can be used with Currency Collection currency. But you can create a new shop with different types of currency.

Buying and selling items from/to a shop is as simple as calling the following functions:

/// <summary>
/// Buy an item from the shop.
/// </summary>
/// <param name="buyerInventory">The inventory of the buyer.</param>
/// <param name="currencyOwnerBase">The currency owner of the buyer.</param>
/// <param name="item">The item to buy.</param>
/// <param name="amount">The amount to buy.</param>
/// <returns>The process can fail returning false.</returns>        	
BuyItem(Inventory buyerInventory, ICurrencyOwner currencyOwnerBase, Item item, int amount)

/// <summary>
/// Sell an item to the shop.
/// </summary>
/// <param name="sellerInventory">The inventory of the seller.</param>
/// <param name="currencyOwnerBase">The currency owner of the seller.</param>
/// <param name="item">The item being sold.</param>
/// <param name="amount">The amount being sold.</param>
/// <returns>The process can fail returning false.</returns>
SellItem(Inventory sellerInventory, ICurrencyOwner currencyOwnerBase, Item item, int amount)

The item prices are defined directly in the editor using attributes. It is recommended to define the buy price and sell price as Item Definition attributes with the name “BuyPrice” and “SellPrice” respectively. If you do not want to define a sell price you can go the the Shop Currency Collection component and change the sell price attribute name to “BuyPrice”. This will allow both the buy and sell price values will be fetched from the “BuyPrice” attribute.

The Shop component allows you to set a price modifier for buying and selling. This allows you to easily create a shop which sell prices are 20% lower than the sell price by setting sell modifier to “-0.2”.

The shop is designed to be extremely flexbile so you can customize the items being sold, the sell and buy prices, and more. It can even be extended to have a custom price depending on who is buying or selling items

There are many ways a shop could work. By default the shopkeeper has an Inventory that contains the items that can be sold. When an item is sold it is duplicated so the shop has a never ending supply of items. The functionality can be changed so that the are not duplicated and therefore sets a limit on the number of items that can be bought. You could also make it dynamic in the sense that you could buy back items that you just sold. These are ideas that are not implemented by default but can be by extending the Shop Currency Collection class.

 

Shop Add Remove Binding

The Shop Add Remove Binding component allows you to remove items that are bought, setting a limit on how many items are in stock. You can also set to add items that are sold, such that they can be bought back.