Purchasing Stackable Items in a Store #
In this section, we’ll create a store with items to purchase with our gold coins. For demonstration purposes, we’ll be manually simulating service calls with Postman.
Prerequisites:
- The previous Stackable Items tutorial section for Creating Stackable Items must be completed.
Create stackable ores #
- Open
5-ext/content/src/StackableSpecs.json. - Edit the JSON to add in
copper_ore,tin_ore, andiron_ore:
The stackable item gold_coins should have been previously added in the Creating Stackable Items section.[
{
"catalogId": "gold_coins",
"name": "gold coins",
"limit": 1000000,
"tags": ["currency"],
"removeIfNone": false
},
{
"catalogId": "copper_ore",
"name": "copper ore",
"limit": 1000000,
"tags": ["resource"],
"removeIfNone": true
},
{
"catalogId": "tin_ore",
"name": "tin ore",
"limit": 1000000,
"tags": ["resource"],
"removeIfNone": true
},
{
"catalogId": "iron_ore",
"name": "iron ore",
"limit": 1000000,
"tags": ["resource"],
"removeIfNone": true
}
]
Create a store #
- Open
5-ext/content/src/Stores.json. - Add the following code to create a store called
shopkeeper:
[
{
"id": "shopkeeper",
"name": "Shopkeeper",
"storeEntries": []
}
]
- Add the following entries into the
storeEntriessquare brackets to give ourshopkeeper6 possible item transactions:
{
"id": "buy_copper_ore",
"receivedQuantityByCatalogId": {
"copper_ore": 1
},
"costByCatalogId": {
"gold_coins": {
"cost": 30
}
}
},
{
"id": "sell_copper_ore",
"receivedQuantityByCatalogId": {
"gold_coins": 30
},
"costByCatalogId": {
"copper_ore": {
"cost": 1
}
}
},
{
"id": "buy_tin_ore",
"receivedQuantityByCatalogId": {
"tin_ore": 1
},
"costByCatalogId": {
"gold_coins": {
"cost": 20
}
}
},
{
"id": "sell_tin_ore",
"receivedQuantityByCatalogId": {
"gold_coins": 20
},
"costByCatalogId": {
"tin_ore": {
"cost": 1
}
}
},
{
"id": "buy_iron_ore",
"receivedQuantityByCatalogId": {
"iron_ore": 1
},
"costByCatalogId": {
"gold_coins": {
"cost": 10
}
}
},
{
"id": "sell_iron_ore",
"receivedQuantityByCatalogId": {
"gold_coins": 10
},
"costByCatalogId": {
"iron_ore": {
"cost": 1
}
}
}
Apply content data #
In order to register the content you just defined with Pragma Engine, you must apply your content data changes. You may apply content data either using the command line with make or via an IntelliJ run configuration.
Start Pragma Engine #
Run Pragma Engine via one of the following methods.
Once the engine has started successfully, it prints the message [main] INFO main - Pragma server startup complete.
Simulate purchasing ores #
- Open Postman.
- Navigate to the two service calls
PragmaDev ➨ Public ➨ Operator - AuthenticateOrCreateV2andPragmaDev ➨ Public ➨ Player - AuthenticateOrCreateV2. - Click Send for both service calls and check that the response body for each call has given us
pragmaTokenswith a filledpragmaGameTokenandpragmaSocialToken. - Open
PragmaDev ➨ Game ➨ RPC - Operator ➨Inventory ➨ GrantItemsOperatorV1and editcatalogIdto have a value ofgold_coinsandamountwith1000. This ensures the player has enough currency when purchasing stackable items from the store we’ve just created. - Navigate to
PragmaDev ➨ Game ➨ RPC - Player ➨ Inventory ➨ StorePurchaseV4.
- Edit the
storeIdto have the valueshopkeeper. - Edit the
storeEntryIdto have the valuebuy_copper_ore. - Edit the
amountto have the value5.
- Click Send to purchase 5 copper ores.
- Repeat steps 5-6 two more times, replacing
buy_copper_orewithbuy_iron_oreand thenbuy_tin_ore. - Confirm the player has the items (5
copper_ore, 5iron_ore, and 5tin_ore) they’ve purchased in their inventory by using theGetInventoryOperatorV1call.