A play-limiting mechanic (similar to lives / hearts from Candy Crush) that slowly refills to a maximum over time. This also is often accompanied with a way to purchase additional lives for VC or IAP. PlayFab offers services to enable both.
In this example we are mimicking gameplay through a Cloud Script method called "Battle". While battling the player can receive Gems at the cost of sometimes losing a life. Logic in Cloud Script prevents players from battling if they do not have any lives. Extra lives regenerate every five minutes and are also available to purchase in exchange for Gems.
Ingredients (Building Blocks):
- Player Data
- Player Inventory
- Virtual Currency
- Catalog & CatalogItems (Bundle / Container)
- Cloud Script
- Under the Economy > Currencies section of the Game Manager add a Virtual Currency to match the following parameters:
|Code||LV||Abbreviation for our VC|
|Name||Lives||Name of our VC|
|Initial Deposit||1||ensure that the player can spin on their first login|
|Recharge Rate||288||Every 5 minutes: 24hr*60min / 5min|
|Recharge Max||5||this caps the regeneration to the specified number|
- Under the Economy > Currencies section of the Game Manager add a second Virtual Currency to match the following parameters:
|Code||GM||Abbreviation for our VC|
|Name||Gems||Name of our VC|
|Initial Deposit||5||How many each player gets with a new account|
- Next, under the Catalog tab, add a new catalog called RegeneratingCurrency.
- Navigate back to the top-level catalogs view and click on the small black arrow in the top-right corner of the "RegeneratingCurrency Catalog". Choose the Upload JSON option and provide this catalog file or use your own. * If using your own, ensure that you have items that can be granted to a player.
- Under the Servers > CloudScript section of the Game Manager, upload & deploy this .js file, or ensure that yours has corresponding methods.
- Client obtains a valid session ticket via one of the various authentication pathways (required to make Client API Calls)
- Client battles via calling into the Cloud Script method "Battle".
- Cloud Script calculates Battle results and makes any Gem Additions, Life Losses and data updates to reflect results.
- Results passed back to client for updating the player.
- If a player loses all their lives, they must wait or purchase more in exchange for gems.
In this example we are using Cloud Script to act as the secure server ensuring that the battle logic processing and item grants happen on a trusted machine. The results of any actions performed in Cloud Script are then passed back to inform the client.
Unity 3d Example Setup Instructions:
Import the following asset packages into a new or existing Unity project:
- Add assets to your project.
- Open to the RegeneratingCurrency scene.
- Add your title ID to the RegeneratingCurrency.cs script via the Unity Inspector.
- Run the scene and observe the console for call-by-call status updates.
- Copy this folder to your web server.
- Navigate to index.html
- Enter in your title ID * This example automatically generates a GUID on login; however, You may choose any id you like. * After logging in whatever id was used will be saved into your browser's localstorage
- Observe your browser's developer console for call-by-call status updates.