Platformer Pro  2.3.2
A platform game kit for Unity.
PlatformerPro.Shop Class Reference

A shop where a player can buy and sell items. More...

Inheritance diagram for PlatformerPro.Shop:
PlatformerPro.Persistable PlatformerPro.PlatformerProMonoBehaviour PlatformerPro.ICharacterReference

Public Member Functions

virtual void Init ()
 Init the shop. More...
 
void ShowShop ()
 Initialise and show the shop. More...
 
virtual ShopItemData GetItemInPosition (int pos)
 Gets the item for given slot. More...
 
virtual int GetSellPriceForItemAtPosition (int pos)
 
bool CanSellItem (string itemType)
 
bool WillBuyItemOfType (string itemType)
 
PurchaseFailReason GetPurchaseFailReasonInPosition (int index, Character character)
 Gets the reason why a purcahse of the given slot would fail. More...
 
int PurchaseItemAt (int index, Character character, int desiredAmount)
 Supplied character purchases the item at given shop index and character. More...
 
bool SellItemToShop (ItemInstanceData data, Character character, int slot)
 Supplied character purchases the item at given shop index and character. More...
 
override void ApplySaveData (object t)
 Applies the save data to the object. More...
 
override System.Type SavedObjectType ()
 Get the type of object this Persistable saves. More...
 
override void ResetSaveData ()
 Resets the save data back to default. More...
 
override System.Type[] GetExtraTypes ()
 Support complex object serialisation by passing additional types to seralizer. More...
 
- Public Member Functions inherited from PlatformerPro.PlatformerProMonoBehaviour
virtual void Validate (PlatformerProMonoBehaviour myTarget)
 Override this method if you want to provide custom validation. The actual code should be surrounded by the if UNITY_EDITOR / endif directive. More...
 

Public Attributes

string shopName = "Shop"
 The name of the shop. Must be unique for each shop as its used in persistence. More...
 
string currencyItem
 
List< ShopItemitems
 Items the shop sells. More...
 
int sellMarkUp
 How much do we markup prices as a percentage 0 = no mark, 100 = 100% mark up. More...
 
bool buyAllItems
 If true buy all items, if false buy only items that are listed as buyable in the item list. More...
 
int buyMarkDown
 How much do we markdown prices as a percentage 0 = no mark down, 100 = 100% mark down (nothing paid). More...
 
bool sellAllBoughtItems
 If true bought items which aren't in the item list still appear for sale using default sell price. More...
 
bool neverRestock
 
int baseRestockInterval = 15
 Restock interval in minutes. More...
 
int maxRestock = 3
 Maximum number of times to trigger restock regardless of time elapsed since last restock. More...
 
GameObject visibleContent
 
bool escapeClosesShop = true
 If true pressing escape always closes shop. More...
 
- Public Attributes inherited from PlatformerPro.Persistable
bool usePersistenceDefaults = true
 Should we use the persistence defaults or override with our own values. More...
 
bool enablePersistence = true
 Should we enable persistence. More...
 
bool saveOnAnyChange
 Save whenever this value changes (Note: not supported by all objects). More...
 
PersistenceResetType persistenceType
 When do we reset persistence? More...
 

Static Public Attributes

const string UniqueDataIdentifier = "Shop"
 The player preference identifier. More...
 
- Static Public Attributes inherited from PlatformerPro.Persistable
const string BasePlayerPrefId = "PP.Persistent."
 The base player preference identifier. More...
 

Protected Member Functions

virtual void OnShopSoldItem (string type, Character character)
 Raises the item sold event. More...
 
virtual void OnShopPurchaseFailed (string type, Character character, PurchaseFailReason reason)
 Raises the item sold event. More...
 
virtual void OnShopBoughtItem (string type, Character character)
 Raises the item bought event. More...
 
virtual void OnShopShopRestocked ()
 Raises the shop restocked event. More...
 
virtual void ProcessUserInput ()
 Checks for keys that close the store. More...
 
virtual void HandleUnpause (object sender, System.EventArgs e)
 Make sure we close the shop if the game becomes unpaused for any reason. More...
 
virtual int CalculateSellPriceFor (ShopItemData data)
 
virtual int CalculateBuyPriceFor (ShopItemData data)
 Calculates the buy price for the given item. More...
 
virtual int CalculateBuyPriceFor (ItemTypeData data)
 Calculates the buy price for the given item. More...
 
int DoPurchaseItemAt (int index, Character character, int desiredAmount)
 Purchases 1 or more items returning the amount purchased. More...
 
virtual void UpdateSellableItems ()
 
virtual void Restock ()
 Checks the time since last restock and restocks once for each restock interval up to max restock times. More...
 
virtual void DoRestock (ShopItem item, ShopItemData data)
 Does the actual restocking for the given item with no checks on time, etc (usually called from Restock). More...
 
virtual void ShowUI ()
 
virtual void HideShop ()
 
- Protected Member Functions inherited from PlatformerPro.Persistable
virtual void OnLoaded ()
 Raises the loaded event. More...
 
virtual void ConfigureEventListeners ()
 Init this instance. More...
 
virtual void DoPendingSaves (object sender, PersistenceEventArgs e)
 Trigger any pending saves. More...
 
virtual void PhaseChange (object sender, GamePhaseEventArgs e)
 Handle a change of game phase, look for persistence event and apply. More...
 
virtual void HandleRespawn (object sender, CharacterEventArgs e)
 Handle a change of game phase, look for persistence event and apply. More...
 
virtual void HandleWillExitScene (object sender, SceneEventArgs e)
 Handles the will exit scene event More...
 
virtual void HandleGameOver (object sender, CharacterEventArgs e)
 Handles the game over event More...
 
virtual void HandleDied (object sender, DamageInfoEventArgs e)
 Handles the died event. More...
 

Protected Attributes

List< ShopItemDataitemData
 Data about the actual items in the shop. More...
 
List< string > sellableItems
 Cached list of things we sell. More...
 
- Protected Attributes inherited from PlatformerPro.Persistable
bool loaded
 Have we loaded the data yet? More...
 
bool readyToSave
 Are we ready to save on the next save tick? More...
 
Persistable latestSaveData
 Data to save when we trigger the next save tick. More...
 

Properties

override string Header [get]
 Gets the header string used to describe the component. More...
 
List< string > SellableItem [get]
 Get a list of all items this shop sells, including items that are usually sold but that aren't in stock, and including bought items even if they aren't usually sold. More...
 
override string PlayerPrefsIdentifier [get]
 
override Character Character [get, set]
 Gets the character reference. More...
 
override object SaveData [get]
 Gets the data to save. More...
 
override string Identifier [get]
 Get a unique identifier to use when saving the data (for example this could be used for part of the file name or player prefs name). More...
 
- Properties inherited from PlatformerPro.Persistable
virtual string PlayerPrefsIdentifier [get]
 The player preference identifier. More...
 
virtual bool EnablePersistence [get]
 Gets the value for persistence type taking in to account defaults. More...
 
virtual PersistenceResetType PersistenceType [get]
 Gets the value for persistence type taking in to account defaults. More...
 
virtual bool SaveOnChange [get]
 Gets the value for save on change type taking in to account defaults. More...
 
abstract Character Character [get, set]
 Gets the character. More...
 
abstract object SaveData [get]
 Gets the data to save. More...
 
abstract string Identifier [get]
 Get a unique identifier to use when saving the data (for example this could be used for part of the file name or player prefs name). More...
 
- Properties inherited from PlatformerPro.PlatformerProMonoBehaviour
virtual string Header [get]
 Gets the header string used to describe the component. More...
 
virtual string DocLink [get]
 Gets a link to documentation site. More...
 
virtual string VideoLink [get]
 Gets a link to a youtube video. More...
 
virtual string Deprecated [get]
 If non-null this component is deprecated. The string shows a message indicating how it should be replaced. More...
 
- Properties inherited from PlatformerPro.ICharacterReference
Character Character [get, set]
 Get the character. More...
 

Events

System.EventHandler< ItemEventArgsShopSoldItem
 Item sold by shop. More...
 
System.EventHandler< PurchaseFailEventArgsShopPurchaseFailed
 Player tried to buy item but didn't have enough space or cash. More...
 
System.EventHandler< ItemEventArgsShopBoughtItem
 Item purchased by shop More...
 
System.EventHandler< EmptyEventArgsShopRestocked
 Item purchased. More...
 
- Events inherited from PlatformerPro.Persistable
System.EventHandler< EmptyEventArgsLoaded
 Sent when this persistable is loaded. More...
 

Additional Inherited Members

- Static Public Member Functions inherited from PlatformerPro.Persistable
static void Save (Persistable p)
 Save the given persistable. More...
 
static void SaveXml (Persistable p)
 Save the given persistable in XML format. More...
 
static void SaveBinary (Persistable p)
 Save the given persistable in XML format. More...
 
static void Load (Persistable p)
 Load the given persistable. More...
 
static void Reset (Persistable p)
 Resets the given persistable. More...
 
- Static Protected Member Functions inherited from PlatformerPro.Persistable
static object LoadSavedDataXml (Persistable p)
 Does the actual load and returns raw object. More...
 
static object LoadSavedDataBinary (Persistable p)
 Does the actual load and returns raw object. More...
 

Detailed Description

A shop where a player can buy and sell items.

Member Function Documentation

◆ ApplySaveData()

override void PlatformerPro.Shop.ApplySaveData ( object  t)
virtual

Applies the save data to the object.

Implements PlatformerPro.Persistable.

◆ CalculateBuyPriceFor() [1/2]

virtual int PlatformerPro.Shop.CalculateBuyPriceFor ( ItemTypeData  data)
protectedvirtual

Calculates the buy price for the given item.

Returns
The buy price for item or zero if the item wont be bought.
Parameters
dataItem data.

◆ CalculateBuyPriceFor() [2/2]

virtual int PlatformerPro.Shop.CalculateBuyPriceFor ( ShopItemData  data)
protectedvirtual

Calculates the buy price for the given item.

Returns
The buy price for item or zero if the item wont be bought.
Parameters
dataItem data.

◆ CalculateSellPriceFor()

virtual int PlatformerPro.Shop.CalculateSellPriceFor ( ShopItemData  data)
protectedvirtual

◆ CanSellItem()

bool PlatformerPro.Shop.CanSellItem ( string  itemType)

◆ DoPurchaseItemAt()

int PlatformerPro.Shop.DoPurchaseItemAt ( int  index,
Character  character,
int  desiredAmount 
)
protected

Purchases 1 or more items returning the amount purchased.

Returns
The amount purchased.
Parameters
indexIndex of the item in shop.
characterCharacter doings the purchasing.

◆ DoRestock()

virtual void PlatformerPro.Shop.DoRestock ( ShopItem  item,
ShopItemData  data 
)
protectedvirtual

Does the actual restocking for the given item with no checks on time, etc (usually called from Restock).

◆ GetExtraTypes()

override System.Type [] PlatformerPro.Shop.GetExtraTypes ( )
virtual

Support complex object serialisation by passing additional types to seralizer.

Reimplemented from PlatformerPro.Persistable.

◆ GetItemInPosition()

virtual ShopItemData PlatformerPro.Shop.GetItemInPosition ( int  pos)
virtual

Gets the item for given slot.

Returns
The item for slot.
Parameters
posposition.

◆ GetPurchaseFailReasonInPosition()

PurchaseFailReason PlatformerPro.Shop.GetPurchaseFailReasonInPosition ( int  index,
Character  character 
)

Gets the reason why a purcahse of the given slot would fail.

Returns
The purchase fail reason in position.
Parameters
indexIndex.

◆ GetSellPriceForItemAtPosition()

virtual int PlatformerPro.Shop.GetSellPriceForItemAtPosition ( int  pos)
virtual

◆ HandleUnpause()

virtual void PlatformerPro.Shop.HandleUnpause ( object  sender,
System.EventArgs  e 
)
protectedvirtual

Make sure we close the shop if the game becomes unpaused for any reason.

◆ HideShop()

virtual void PlatformerPro.Shop.HideShop ( )
protectedvirtual

◆ Init()

virtual void PlatformerPro.Shop.Init ( )
virtual

Init the shop.

◆ OnShopBoughtItem()

virtual void PlatformerPro.Shop.OnShopBoughtItem ( string  type,
Character  character 
)
protectedvirtual

Raises the item bought event.

Parameters
typeType.
characterCharacter.

◆ OnShopPurchaseFailed()

virtual void PlatformerPro.Shop.OnShopPurchaseFailed ( string  type,
Character  character,
PurchaseFailReason  reason 
)
protectedvirtual

Raises the item sold event.

Parameters
typeType.
characterCharacter.

◆ OnShopShopRestocked()

virtual void PlatformerPro.Shop.OnShopShopRestocked ( )
protectedvirtual

Raises the shop restocked event.

◆ OnShopSoldItem()

virtual void PlatformerPro.Shop.OnShopSoldItem ( string  type,
Character  character 
)
protectedvirtual

Raises the item sold event.

Parameters
typeType.
characterCharacter.

◆ ProcessUserInput()

virtual void PlatformerPro.Shop.ProcessUserInput ( )
protectedvirtual

Checks for keys that close the store.

◆ PurchaseItemAt()

int PlatformerPro.Shop.PurchaseItemAt ( int  index,
Character  character,
int  desiredAmount 
)

Supplied character purchases the item at given shop index and character.

Returns
Amount purcahsed (0 if no purchase made).
Parameters
indexIndex.
characterCharacter.
desiredAmountNumber to purcahse or 0 for default.

◆ ResetSaveData()

override void PlatformerPro.Shop.ResetSaveData ( )
virtual

Resets the save data back to default.

Implements PlatformerPro.Persistable.

◆ Restock()

virtual void PlatformerPro.Shop.Restock ( )
protectedvirtual

Checks the time since last restock and restocks once for each restock interval up to max restock times.

◆ SavedObjectType()

override System.Type PlatformerPro.Shop.SavedObjectType ( )
virtual

Get the type of object this Persistable saves.

Implements PlatformerPro.Persistable.

◆ SellItemToShop()

bool PlatformerPro.Shop.SellItemToShop ( ItemInstanceData  data,
Character  character,
int  slot 
)

Supplied character purchases the item at given shop index and character.

◆ ShowShop()

void PlatformerPro.Shop.ShowShop ( )

Initialise and show the shop.

◆ ShowUI()

virtual void PlatformerPro.Shop.ShowUI ( )
protectedvirtual

◆ UpdateSellableItems()

virtual void PlatformerPro.Shop.UpdateSellableItems ( )
protectedvirtual

◆ WillBuyItemOfType()

bool PlatformerPro.Shop.WillBuyItemOfType ( string  itemType)

Member Data Documentation

◆ baseRestockInterval

int PlatformerPro.Shop.baseRestockInterval = 15

Restock interval in minutes.

◆ buyAllItems

bool PlatformerPro.Shop.buyAllItems

If true buy all items, if false buy only items that are listed as buyable in the item list.

◆ buyMarkDown

int PlatformerPro.Shop.buyMarkDown

How much do we markdown prices as a percentage 0 = no mark down, 100 = 100% mark down (nothing paid).

◆ currencyItem

string PlatformerPro.Shop.currencyItem

◆ escapeClosesShop

bool PlatformerPro.Shop.escapeClosesShop = true

If true pressing escape always closes shop.

◆ itemData

List<ShopItemData> PlatformerPro.Shop.itemData
protected

Data about the actual items in the shop.

◆ items

List<ShopItem> PlatformerPro.Shop.items

Items the shop sells.

◆ maxRestock

int PlatformerPro.Shop.maxRestock = 3

Maximum number of times to trigger restock regardless of time elapsed since last restock.

◆ neverRestock

bool PlatformerPro.Shop.neverRestock

◆ sellableItems

List<string> PlatformerPro.Shop.sellableItems
protected

Cached list of things we sell.

◆ sellAllBoughtItems

bool PlatformerPro.Shop.sellAllBoughtItems

If true bought items which aren't in the item list still appear for sale using default sell price.

◆ sellMarkUp

int PlatformerPro.Shop.sellMarkUp

How much do we markup prices as a percentage 0 = no mark, 100 = 100% mark up.

◆ shopName

string PlatformerPro.Shop.shopName = "Shop"

The name of the shop. Must be unique for each shop as its used in persistence.

◆ UniqueDataIdentifier

const string PlatformerPro.Shop.UniqueDataIdentifier = "Shop"
static

The player preference identifier.

◆ visibleContent

GameObject PlatformerPro.Shop.visibleContent

Property Documentation

◆ Character

override Character PlatformerPro.Shop.Character
getset

Gets the character reference.

The character.

◆ Header

override string PlatformerPro.Shop.Header
get

Gets the header string used to describe the component.

The header.

◆ Identifier

override string PlatformerPro.Shop.Identifier
get

Get a unique identifier to use when saving the data (for example this could be used for part of the file name or player prefs name).

The identifier.

◆ PlayerPrefsIdentifier

override string PlatformerPro.Shop.PlayerPrefsIdentifier
get

◆ SaveData

override object PlatformerPro.Shop.SaveData
get

Gets the data to save.

◆ SellableItem

List<string> PlatformerPro.Shop.SellableItem
get

Get a list of all items this shop sells, including items that are usually sold but that aren't in stock, and including bought items even if they aren't usually sold.

The sellable item.

Event Documentation

◆ ShopBoughtItem

System.EventHandler<ItemEventArgs> PlatformerPro.Shop.ShopBoughtItem

Item purchased by shop

◆ ShopPurchaseFailed

System.EventHandler<PurchaseFailEventArgs> PlatformerPro.Shop.ShopPurchaseFailed

Player tried to buy item but didn't have enough space or cash.

◆ ShopRestocked

System.EventHandler<EmptyEventArgs> PlatformerPro.Shop.ShopRestocked

Item purchased.

◆ ShopSoldItem

System.EventHandler<ItemEventArgs> PlatformerPro.Shop.ShopSoldItem

Item sold by shop.


The documentation for this class was generated from the following file: