What is the proper way to implement an "Energy" system for a casual mobile game?
-
Most mobile games have a energy system that limits a user from being able to play constantly, so as to limit progress. This resource can usually be bought as well up to a certain number of times per day, but otherwise replenishes on a time-loop when a user doesn't have max energy.
I know some ways I could implement this, but I'm curious what braincloud suggests as the optimal way to do this (to minimize usage) since this is a relatively common scenario? Other BaaS recognize this as such a common scenario that they have built-in functionality for this (ie lootlocker) - so assuming this is a popular use-case.
Any advice? Thanks!
-
Save a (current millis) timestamp, the recharge rate and the energy available in a user entity. Everytime the player makes an action, create a method that checks if he has the available energy, consume it & re-calculate the energy based on time passed from last timestamp to current. You can get the timestamp on the cloud using new Date().getTime(). Sync this process to the client for the player to see his energy.
(Total API Consumption = Read + write user entity in a cloud script = 1 API call)
If you want to have microtransactions upon the energy, create a virtual currency that the player can use it to buy energy. Since the energy is directly related to gameplay, i would want to keep it separately from my virtual currency.
-
@kuabs Exactly. Always use braincloud server time for features that rely on time passed. Also, if you want to modify your recharge rate during gameplay, you might want to consider keeping it in a global entity instead so every user will be affected by it.