Sign In Register

How can we help you today?

Start a new topic
Answered

Xp and levels up

Hi,


I'd like to implement for the player a Xp level system, where all the the logic for increment and check for levels upgrade are handled by Cloud Code.

I was wondering if there are best practice for that or if can give a some advice.


At the moment the approach I though it is to upload a metadata table contains all the levels with something like that:

{ 
  "Level": LevelName,
  "XpPoint": Xp
  "EventTrigger": Trigger,
  "Currency1Award": 1,
  "Currency2Award: 2,
  ..
  "VirtualGoodAward": ShortCode
}

I though using Currency3 for Xp. That will let to add other custom stuff that may awards the player with XP without the needs to add custom code as well (for ex: achievements etc)


Others Cloud Code scripts will invoke a IncrementXp function/script with the Xp earned (due to a particular action) and there I will do all the custom logic: 


- Fetch the player current XP

- Check what level is in

- modify the Xp

- Check the level he fit into

- for every levels in the range apply the actions / rewards that apply (by verifying any kind condition/eligibility etc).


That is quite generic and can be reused (a specific module is a good fit for that).


I was wondering a bit regarding the kind of DB model. Probably for a collection with 100 elements or so, it would be better to use a single document

with an embedded array of objects.

The difference, of course, is in how I will go to find the level. In case of collection I will have to perform two queries like to find the current and next level

{Xp: {$lte: xx}} ascending
{Xp: {$gt: xx}} descending

 

With an embedded array, just a binary search. While the collection is cached in VM, I think it is still faster to just grab one document at once (a bit bigger) instead of relying on the query (and also has other advantages of course). 

While I started with the collections with multiple level entries now I don't see any particular advantages of using it (correct me if I'm wrong) so I think I will go with the second option. I'm not so expert using Mongo (I've used other kind of NoSql and potentially the modelling pattern are different a bit).


In case the user level change, a new message is triggered so the client is informed about that and can update accordingly (one message for each level change). 


After some thought, In order to avoid problems due to Levels table changes (for example: a change in the Xp level progression curve), I choose to do not store the current player level as custom internal data / script data. The level will be re-computed on the fly when needed and at every login / account details request and sent to the client via ScriptData (for client sake).


Do you se any major flaw in that design ?









Best Answer

I happen to be working on the same thing for my game now and have been intending on going with something that is basically your second idea, the single document with arrays. An additional plus is that if you want to have a completely different set of progression values (probably for A/B testing) all you do is add a second document with a different _id, keeping all different sets of progression in a single collection, which seems far more appropriate than multiple collections. 


On a side note you may want to keep track of the most recent level up that a player has witnessed. Assuming XP can be gained offline or if the XP curve changes resulting in some gained levels, you need to know if the user should see a level up upon login, or in the case of multiple level changes while offline see more than one level up back to back.


Answer

I happen to be working on the same thing for my game now and have been intending on going with something that is basically your second idea, the single document with arrays. An additional plus is that if you want to have a completely different set of progression values (probably for A/B testing) all you do is add a second document with a different _id, keeping all different sets of progression in a single collection, which seems far more appropriate than multiple collections. 


On a side note you may want to keep track of the most recent level up that a player has witnessed. Assuming XP can be gained offline or if the XP curve changes resulting in some gained levels, you need to know if the user should see a level up upon login, or in the case of multiple level changes while offline see more than one level up back to back.

Hi James,


I really didn't though about the additional plus for the A/B testing, thank for the hint! Regarding the side note, it definitively worth keeping track of the last level.