Smart Loot Boxes¶
Loot Boxes Package¶
Let’s take a look inside the Loot Box template from our public Loot Boxes package (requires LiveOps and Game Shop packages to be installed):
Note the Reward Script parameter. It is used to store custom script, designed for calculating reward after opening of a Loot Box. That means the Loot Box is smart – a rewarding algorithm is embedded into its settings, allowing game designers to create logic inside Balancy without involving software engineers.
For describing the loot it uses the following Drop Item component:
Item here is represented by Balancy internal Item With Amount template, but with additional parameter Weight to calculate drop chances.
The logic for choosing a random item to drop from a Loot Box could be different from game to game. Here, we will discuss two options: pure random choice (the simplest one), and controlled random. Controlled random provides the way to create Loot Box with guaranteed drop. That means, such an item will be given after not more than a fixed number of openings, depending on the weight of the guaranteed item.
These two types of logic are described by the following enum, RandomiserType:
Using these templates we can create many interesting Loot Boxes:
For example: Ads Chest (opens after watching 1 rewarding video), Free Gift, Rare Chest (being sold for IAP, and – the subject of that article – Epic Chest (being opened for hard currency and having guaranteed drop item).
Scripts¶
All these Loot Boxes use the same Reward Script as the main entrance point for reward calculation, but the logic is different depending on the Logic Type parameter. To make it work, there are 4 scripts:
Let’s take a look into each of them.
It all starts from the LootBox Reward script:
It takes its own LootBox document as an input parameter. Then it checks Logic Type and selects the script for calculation. Whatever the logic is, the reward is acquired and being sent to output as an Item With Amount component.
Pure Random Reward script:
It takes the Loot (the list of possible loot drop) and passes it to the general purpose script Get Random Drop without any additional actions required.
Controlled Random Reward script is more complex:
The logic for controlled reward is the following:
- Count the number of opened Loot Boxes, check it against the drop chance of guaranteed drop item. The total weight of all drop divided by the weight of guaranteed drop item gives the amount of openings until the guaranteed reward;
- If it is time to give the guaranteed drop – give it for sure;
- If it is not the time yet, add the guaranteed drop item to the list of all drop items and take a chance using the Get Random Drop script;
- In case the final reward is the guaranteed one (it doesn’t matter, if it’s given by chance or for sure), reset the counter;
To count the number of opened Loot Boxes of that config (Epic Chest), adding the custom property into User Profile:
This property will serve as a global variable stored in User Profile and available all over the platform.
The core part is the Get Random Drop script:
It uses a temporary list to create the collection of drop items, each existing in an amount based on its weight. The whole process acts like unpacking. For example, if the total weight is 100, that means the Loot Box contains 100 items. If an Item has a weight of 5, that means there will be 5 such items in the list.
After the unpacking is done, a standard Get Random Item node is used to take one random item from the temporary list and return it as a result of opening a Loot Box.
Opening Loot Boxes¶
Having Loot Boxes configured this way, the only thing is left to do on the client side of the game – execute the script of a given Loot Box:
dropItem = epicChest.RewardScript.Run(<document>);