C# Class Soomla.Store.StoreInventory

This class will help you do your day to day virtual economy operations easily. You can give or take items from your users. You can buy items or upgrade them. You can also check their equipping status and change it.
Mostrar archivo Open project: soomla/unity3d-store Class Usage Examples

Public Methods

Method Description
BuyItem ( string itemId ) : void

Buys the item with the given itemId.

BuyItem ( string itemId, string payload ) : void

Buys the item with the given itemId.

CanAfford ( string itemId ) : bool

Checks if there is enough funds to afford itemId.

EquipVirtualGood ( string goodItemId ) : void

Equips the virtual good with the given goodItemId. Equipping means that the user decides to currently use a specific virtual good. For more details and examples com.soomla.store.domain.virtualGoods.EquippableVG.

GetEquippedVirtualGood ( Soomla.Store.VirtualCategory category ) : Soomla.Store.EquippableVG

Checks currently equipped good in given category

GetEquippedVirtualGood ( string categoryName ) : Soomla.Store.EquippableVG

Checks currently equipped good in given category

GetGoodCurrentUpgrade ( string goodItemId ) : string

Retrieves the current upgrade of the good with the given id.

GetGoodUpgradeLevel ( string goodItemId ) : int

Retrieves the upgrade level of the virtual good with the given goodItemId. For Example: Let's say there's a strength attribute to one of the characters in your game and you provide your users with the ability to upgrade that strength on a scale of 1-3. This is what you've created: 1. SingleUseVG for "strength". 2. UpgradeVG for strength 'level 1'. 3. UpgradeVG for strength 'level 2'. 4. UpgradeVG for strength 'level 3'. In the example, this function will retrieve the upgrade level for "strength" (1, 2, or 3).

GetItemBalance ( string itemId ) : int

Retrieves the balance of the virtual item with the given itemId.

GiveItem ( string itemId, int amount ) : void

Gives your user the given amount of the virtual item with the given itemId. For example, when your user plays your game for the first time you GIVE him/her 1000 gems. NOTE: This action is different than buy - You use give(int amount) to give your user something for free. You use buy() to give your user something and you get something in return.

IsVirtualGoodEquipped ( string goodItemId ) : bool

Checks if the virtual good with the given goodItemId is currently equipped.

RefreshLocalInventory ( ) : void

This function refreshes a local set of objects that will hold your user's balances in memory for quick and more efficient fetching for your game UI. This way, we save many JNI or static calls to native platforms. NOTE: You don't need to call this function as it's automatically called when the game initializes. NOTE: This is less useful when you work in editor.

RefreshOnCurrencyBalanceChanged ( Soomla.Store.VirtualCurrency virtualCurrency, int balance, int amountAdded ) : void
RefreshOnGoodBalanceChanged ( Soomla.Store.VirtualGood good, int balance, int amountAdded ) : void
RefreshOnGoodEquipped ( Soomla.Store.EquippableVG equippable ) : void
RefreshOnGoodUnEquipped ( Soomla.Store.EquippableVG equippable ) : void
RefreshOnGoodUpgrade ( Soomla.Store.VirtualGood vg, UpgradeVG uvg ) : void
RemoveGoodUpgrades ( string goodItemId ) : void

Removes all upgrades from the virtual good with the given goodItemId.

TakeItem ( string itemId, int amount ) : void

Takes from your user the given amount of the virtual item with the given itemId. For example, when your user requests a refund, you need to TAKE the item he/she is returning from him/her.

UnEquipVirtualGood ( string goodItemId ) : void

Unequips the virtual good with the given goodItemId. Unequipping means that the user decides to stop using the virtual good he/she is currently using. For more details and examples com.soomla.store.domain.virtualGoods.EquippableVG.

UpgradeGood ( string goodItemId ) : void

Upgrades the virtual good with the given goodItemId by doing the following: 1. Checks if the good is currently upgraded or if this is the first time being upgraded. 2. If the good is currently upgraded, upgrades to the next upgrade in the series. In case there are no more upgrades available(meaning the current upgrade is the last available), the function returns. 3. If the good has never been upgraded before, the function upgrades it to the first available upgrade with the first upgrade of the series.

Private Methods

Method Description
UpdateLocalBalance ( string itemId, int balance ) : void

Method Details

BuyItem() public static method

Buys the item with the given itemId.
Thrown if the item to be bought is not found. Thrown if the user does not have enough funds.
public static BuyItem ( string itemId ) : void
itemId string id of item to be bought
return void

BuyItem() public static method

Buys the item with the given itemId.
Thrown if the item to be bought is not found. Thrown if the user does not have enough funds.
public static BuyItem ( string itemId, string payload ) : void
itemId string id of item to be bought
payload string a string you want to be assigned to the purchase. This string /// is saved in a static variable and will be given bacl to you when the purchase is completed.
return void

CanAfford() public static method

Checks if there is enough funds to afford itemId.
public static CanAfford ( string itemId ) : bool
itemId string id of item to be checked
return bool

EquipVirtualGood() public static method

Equips the virtual good with the given goodItemId. Equipping means that the user decides to currently use a specific virtual good. For more details and examples com.soomla.store.domain.virtualGoods.EquippableVG.
Thrown if the item is not found.
public static EquipVirtualGood ( string goodItemId ) : void
goodItemId string Id of the good to be equipped.
return void

GetEquippedVirtualGood() public static method

Checks currently equipped good in given category
public static GetEquippedVirtualGood ( Soomla.Store.VirtualCategory category ) : Soomla.Store.EquippableVG
category Soomla.Store.VirtualCategory Category we want to check
return Soomla.Store.EquippableVG

GetEquippedVirtualGood() public static method

Checks currently equipped good in given category
public static GetEquippedVirtualGood ( string categoryName ) : Soomla.Store.EquippableVG
categoryName string
return Soomla.Store.EquippableVG

GetGoodCurrentUpgrade() public static method

Retrieves the current upgrade of the good with the given id.
Thrown if the item is not found.
public static GetGoodCurrentUpgrade ( string goodItemId ) : string
goodItemId string Id of the good whose upgrade we want to fetch.
return string

GetGoodUpgradeLevel() public static method

Retrieves the upgrade level of the virtual good with the given goodItemId. For Example: Let's say there's a strength attribute to one of the characters in your game and you provide your users with the ability to upgrade that strength on a scale of 1-3. This is what you've created: 1. SingleUseVG for "strength". 2. UpgradeVG for strength 'level 1'. 3. UpgradeVG for strength 'level 2'. 4. UpgradeVG for strength 'level 3'. In the example, this function will retrieve the upgrade level for "strength" (1, 2, or 3).
Thrown if the item is not found.
public static GetGoodUpgradeLevel ( string goodItemId ) : int
goodItemId string Good item identifier.
return int

GetItemBalance() public static method

Retrieves the balance of the virtual item with the given itemId.
Thrown if the item is not found.
public static GetItemBalance ( string itemId ) : int
itemId string Id of the virtual item to be fetched.
return int

GiveItem() public static method

Gives your user the given amount of the virtual item with the given itemId. For example, when your user plays your game for the first time you GIVE him/her 1000 gems. NOTE: This action is different than buy - You use give(int amount) to give your user something for free. You use buy() to give your user something and you get something in return.
Thrown if the item is not found.
public static GiveItem ( string itemId, int amount ) : void
itemId string Id of the item to be given.
amount int Amount of the item to be given.
return void

IsVirtualGoodEquipped() public static method

Checks if the virtual good with the given goodItemId is currently equipped.
Thrown if the item is not found.
public static IsVirtualGoodEquipped ( string goodItemId ) : bool
goodItemId string Id of the virtual good who we want to know if is equipped.
return bool

RefreshLocalInventory() public static method

This function refreshes a local set of objects that will hold your user's balances in memory for quick and more efficient fetching for your game UI. This way, we save many JNI or static calls to native platforms. NOTE: You don't need to call this function as it's automatically called when the game initializes. NOTE: This is less useful when you work in editor.
public static RefreshLocalInventory ( ) : void
return void

RefreshOnCurrencyBalanceChanged() public static method

public static RefreshOnCurrencyBalanceChanged ( Soomla.Store.VirtualCurrency virtualCurrency, int balance, int amountAdded ) : void
virtualCurrency Soomla.Store.VirtualCurrency
balance int
amountAdded int
return void

RefreshOnGoodBalanceChanged() public static method

public static RefreshOnGoodBalanceChanged ( Soomla.Store.VirtualGood good, int balance, int amountAdded ) : void
good Soomla.Store.VirtualGood
balance int
amountAdded int
return void

RefreshOnGoodEquipped() public static method

public static RefreshOnGoodEquipped ( Soomla.Store.EquippableVG equippable ) : void
equippable Soomla.Store.EquippableVG
return void

RefreshOnGoodUnEquipped() public static method

public static RefreshOnGoodUnEquipped ( Soomla.Store.EquippableVG equippable ) : void
equippable Soomla.Store.EquippableVG
return void

RefreshOnGoodUpgrade() public static method

public static RefreshOnGoodUpgrade ( Soomla.Store.VirtualGood vg, UpgradeVG uvg ) : void
vg Soomla.Store.VirtualGood
uvg UpgradeVG
return void

RemoveGoodUpgrades() public static method

Removes all upgrades from the virtual good with the given goodItemId.
Thrown if the item is not found.
public static RemoveGoodUpgrades ( string goodItemId ) : void
goodItemId string Id of the good whose upgrades are to be removed.
return void

TakeItem() public static method

Takes from your user the given amount of the virtual item with the given itemId. For example, when your user requests a refund, you need to TAKE the item he/she is returning from him/her.
Thrown if the item is not found.
public static TakeItem ( string itemId, int amount ) : void
itemId string Item identifier.
amount int Amount.
return void

UnEquipVirtualGood() public static method

Unequips the virtual good with the given goodItemId. Unequipping means that the user decides to stop using the virtual good he/she is currently using. For more details and examples com.soomla.store.domain.virtualGoods.EquippableVG.
Thrown if the item is not found.
public static UnEquipVirtualGood ( string goodItemId ) : void
goodItemId string Id of the good to be unequipped.
return void

UpgradeGood() public static method

Upgrades the virtual good with the given goodItemId by doing the following: 1. Checks if the good is currently upgraded or if this is the first time being upgraded. 2. If the good is currently upgraded, upgrades to the next upgrade in the series. In case there are no more upgrades available(meaning the current upgrade is the last available), the function returns. 3. If the good has never been upgraded before, the function upgrades it to the first available upgrade with the first upgrade of the series.
Thrown if the item is not found.
public static UpgradeGood ( string goodItemId ) : void
goodItemId string Good item identifier.
return void