A new Player Data service has been released that is more up to date and supported with this current release of Pragma Engine. We recommend you check it out by viewing the Player Data Overview page.
Stackable Items #
Stackable items represent stacks of items with a count and limit such as currencies or health potions. Stackable items of the same type only vary in their amount and do not behave differently from one another (i.e. one stack of gold coins acts the same as another stack of gold coins).
Stackable specs #
Stackable specs are generally straightforward since there’s a limited amount of behavior that needs to be defined, because stackable items of the same type do not vary from one another.
Here’s an example of a stackable spec for an in-game currency.
{
"catalogId": "gold-coins", // id, cannot be changed
"name": "Gold Coins", // display name, can be changed.
"limit": 10000, // the maximum amount of gold a player
// can have
"tags": ["currency"], // used to group and filter content
"removeIfNone": false // determines if a stack is deleted
// when the amount goes to 0. Useful
// for consumables.
"ext": {
"conversion_to_silver": 100 // custom properties that you
// can define that will be true for
// all Stackables of this type
}
}
Stackable Item Plugin #
The Stackable Item Plugin is used to define custom behavior when updating a stackable item. In the following sections, we’ll take a look at the different components that make up the Stackable Item Plugin’s interface.
Member | Section |
---|---|
onUpdate | Chaining inventory operations on update |
StackableItemPluginResult | Returning the result |
Chaining inventory operations on update #
The StackableItemPlugin.onUpdate
function is called when a stackable item is granted or updated.
Below are the parameters and their descriptions for onUpdate
:
Parameter | Description |
---|---|
preUpdateAmount | View of stackable item with all prior chained updates applied with catalog limited enforced. |
delta | The difference to add or subtract from the stackable item amount. |
stackableSpec | An object that contains spec content for your stackable item catalog (JSON files). |
inventoryContent | A reference object for all the content in the Inventory service. This can be used to look up specs for other related items. |
startingInventory | A snapshot of the player’s inventory prior to any updates. |
pendingInventory | A snapshop of the player’s inventory after all updates are processed with enforced catalog limits. |
Returning the result #
The onUpdate
function returns the InventoryModifications
data class. This data class can be to used for chaining additional item operations such as granting, updating, or destroying items.
Below are the possible item operations:
Property | Type | Description |
---|---|---|
rewardGrants | List<RewardGrant> | List of rewards to be granted. |
instancedItemServerGrants | List<InstancedItemServerGrant> | List of instanced item to be granted. |
stackableItemGrants | List<StackableItemGrant> | List of stackable item grants to be granted. |
serverInstancedItemUpdates | List<ServerInstancedItemUpdate> | List of instanced items to be updated. |
instancedItemsToDestroy | List<InstanceId> | List of instanced items to be destroyed. |