In this post I wanted to go over how I designed the loot tables in Heroes' Journey. This was one area where I was having a lot of trouble coming up with a good way to implement random loot at the end of battle. So, I turned to the Internet in hopes of finding examples of how other games/people had approached this before. I found a lot of good examples of loot systems, like the ones here at Gamasutra, the Game Development Stack Exchange, and several others. I really liked the table style implementation, like the main example in the Gamasutra article, and decided to go with a variation of that one. I'll go through the logic first, then show a code example of how I implemented that logic.

I was going to do this as one long post, but it being a little too long. Instead I'll do an overview of the logic behind my Loot Tables, and in the next post go over how I actually implemented it in code. This can be found here.

###
__Logic __

The first thing that is needed is a list that holds the entries to our loot table. My entries consist of a probability (weight) and an item collection (this allows me to drop sets of items). For this example loot table we will have the following entries:If you noticed the Weights do not add up to 100. As the linked tutorials explain, these numbers are more to show how probable that entry is to be dropped compared to the other entries in the list. We'll get the 0%-100% percentages next. To do this all we have to do is get the sum of all of the weights, then divide each of the weights by the total. Next multiply by 100, and round it to get a whole number percentage.

This means we have a 6% chance to get the Simple Cloth Jerkin/Leather Cap set, a 19% chance to get a Simple Long Sword, and a 75% chance to get nothing. So we have the different probabilities of each of our entries, now we need to put them into a table that we can check our random number against. To do this you start at 0, and for each entry just add that percent to the running total. The last one should always end up at 100.

This table gives us an upper and lower bound to check our random number against. Say we got a random number of 17. So we have 0 - 6 is the armor set, 7 - 25 is the long sword, and 26 - 100 is nothing. We can see that the random number would fall in the 7 - 25 range, therefore we would get the Simple Long Sword as our drop.

This way also allows you to order the entries which ever way you'd like. If you wanted the rarer items to be at the lower end of the 0 - 100 range then you just add them to the list first. In this case, since the lower the number the rarer the drop, anything you take off the random number will increase your chance of getting a rarer item.

That is the logic I am using for determining which drop the player will get at the end of the battle.

## No comments:

## Post a Comment