For the challenge this week we were tasked with utilising prototyping techniques to reverse engineer an existing creative artefact and then rebuild it as a quick prototyped representation.

For this challenge I chose to look at the chest mechanics from the Fortnite Battle Royale video game. My reasoning behind this was because while simple in its final recreation I had a feeling there was a lot more going on in the background in order to produce the results we see on screen when playing.

Figure 1: Chest mechanics from Fortnite

So as you can see from the image above the chest mechanic simply delivers loot to the player upon interaction, however the contents of chest are randomly generated and its contents are contrived from a large pool of possibilities.

So my first port of call on this one was to try and break down the different things that are happening on both a mathematical and aesthetic level. I decided to utilise one of my most trusted prototyping methods in order to do this so cracked out the Post It Notes and went at it.

So I broke it down as much as I could and I took a few liberties at this point, so not all the weapons are in there and the visuals are not 100% identical to the original. I also began to throw down a few ideas on how I might be able to rebuild this mechanic back up. Dey (2021) produced an article on data gathering by a group of Fortnite data miners that detailed some of the mathematical mechanics that are being utilised within the source code, however as this is not a first hand source of information I only used it as an informative starting point, this is why some liberties were taken. I also really only wanted to understand the basics of the mechanics and recreate it exactly.

Once I had this exercise finished I was relieved to see that my initial ideas of it being a two part system, mathematical and aesthetic, were correct, so I decide to approach the mathematics first.

Weighted Random Number Generation

So at its core the system uses random number generation to determine what it selects to put in to the chest, however this randomness is not really 100% random. HYPEX (2021) detailed the data-mined numbers for the Season 2 Chapter 5 loot pool, however this information quickly went out of data as new weapons and content were added to the game, but it does highlight that the chances of specific weapons and weapon rarities are not evenly spread and certain bias is placed upon different aspects of the loot pool in order to balance out the spread of loot.

This is where I needed to do a little research into how to accomplish this within code. I discovered, as with anything in code, there are a few ways to achieve a result but one method that seemed to come up more than often was to utilise different weights or percentages to generate an array with multiple instances of the different choices. Once this array has been created you can use its length to generate a random number that will decide which element would be picked.

This method was detailed in a StackOverflow (2021) post by contributor Drake, who demonstrated it using Javascript.

This method produces an array with the following contents, as you can see the chance of pulling out a C over a D is statistically more common:

While this method seemed like it would be suitable I did not want to specifically create more arrays than needed and wanted to maintain the use of inputted data in order to achieve a similar result. With this in mind I did some more research and found a different solution exampled by Groote (2017) on StackOverflow that utilised a Weighted Chance Parameter class which was then used to execute a mathematical ratio function to produce a result based on entered data. While this method looked to be a direction I could head in, it was the original question in the thread that made me realise I was over thinking this problem and that I could do this very simply by simply generating a number from 100 and use percentage based if statements to decide a result.

So at this point I cracked open Unity and began making things. Firstly I just wanted to work on deciding on a weapon rarity. My data pool consisted of 5 strings, Uncommon, Common, Rare, Epic and Legendary as these are the main rarities in the video game, with their probability spread as 50%, 20%, 15%, 10%, 5%. So I created a function that randomly generated a float between 0 and 100 and used this to decide which if statement it was going to run. The result of this if statement would produce a string to let me know which one had been chosen.

This produced a result that looked like it did what I need it to. I ran the program 1000 times and it returned the following results. Pretty close to what I would expect given the percentages.

Uncommon490
Common204
Rare154
Epic108
Legendary 44

So once I had a working version of the mathematics I just had to work out the order in which to run them, and produce similar functions to generate weighted randomness at each stage. The stages I decide upon was to decide the weapon rarity first, then to move on to decide the weapon group (weighted) from which I would pick a specific weapon (unweighted). I then added in the other elements of the chest such as health and utility items. I also added in an ammo choice but this was done through the weapon group choice.

All I needed then was a way to display all this data, and what I ended up with was one of the messiest Unity Inspector windows I have ever created. So I tidied it up a little and the end result looked a lot nicer.

Figure 3: Chest Manager script in inspector

I created a quick UI in order to display this data on screen and added a button in order to manually generate a chest on click. I was still using my debug code to automatically generate results so I decided to run it a million times to see what happened. This is what got pumped out the other side (it stalled my machine for about 5 seconds so I was happy with code efficiency).

Figure 4: Visual demonstration of the mathematics

So all in all I had the mathematics working to a point that I was happy with. I did realise it was not a 100% exact recreation of the Fortnite mechanic because there are certain weapon groups that are not always available at every weapon rarity, for example you cannot get an uncommon Grenade Launcher, so I know there are improvements to be made in there. Obviously the major improvement would be to actually have the design written down for you and not have to try and reverse engineer it, but still I think I have made a pretty good and close recreation.

Below is the final script for the game and you can try out a version of it by following this link https://defconsoft.itch.io/fortnite-chest-simulator-1

I will be detailing how I went about the aesthetic side of this prototype in my next post.

References

Dey, D., 2021. Fortnite data miner reveals how chest loot pool works in Chapter 2 Season 5. [online] Sportskeeda.com. Available at: <https://www.sportskeeda.com/esports/fortnite-data-miner-reveals-chest-loot-pool-works-chapter-2-season-5> [Accessed 14 June 2021].

HYPEX, 2021. [Twitter] 27th February. Available at: <https://twitter.com/HYPEX/status/1365778033773281283> [Accessed 14th June 2021].

Stack Overflow. 2021. How to generate a random weighted distribution of elements. [online] Available at: <https://stackoverflow.com/questions/30203362/how-to-generate-a-random-weighted-distribution-of-elements> [Accessed 14 June 2021].

Groote, T., 2017. C# weighted random numbers. [online] Stack Overflow. Available at: <https://stackoverflow.com/questions/46563490/c-sharp-weighted-random-numbers> [Accessed 14 June 2021].

Figures

Feature Image: FortniteIntel, 2019. Fortnite chest graphic. [image] Available at: <https://fortniteintel.com/wp-content/uploads/2019/03/chest.jpg> [Accessed 19 June 2021].

Figure 1: Charlish, R (2021) ‘Fortnite chest opening animation’ Created on 19th June 2021

Figure 2: Charlish, R (2021) ‘Idea Generation Images’ Created on 19th June 2021

Figure 3: Charlish, R (2021) ‘Chest Manager inspector window’ Created on 19th June 2021

Figure 4: Charlish, R (2021) ‘Chest content generator’ Created on 19th June 2021


0 Comments

Leave a Reply

Avatar placeholder

Your email address will not be published. Required fields are marked *