How do you handle loot tables and drop chances?

Hey,

The question is in the title; How do you handle loot tables and drop chances?

The way I’m currently handling them can be seen in the link below within the getNextDrop method. It seems like a pretty bad way to do loot tables/drop chances but it works for the moment.
https://github.com/Valkryst/Project_02/blob/master/src/main/java/valkryst/systems/Drops.java

I dont get what you are asking. I usually just make there a 0.1/100 chance. Not much else to it. Do you mean making an organized table of chances? In that case, just have an int array (not float array! less memory used, so just use multiplication knowledge), and reference them with constants corresponding to each drop.


public static final int APPLE=0, IRON=1, GOLD=2, DIAMOND=3
public static final int[] chances = new int[10, 6, 4, 1]

public static float getDropChance(int type) {
    return chances[type]*.01f;
}

What I mean is how do you, whoever is reading, go about creating a bunch of drop tables, fill them with items and drop chances and then figure out which items to draw in your games.

The way I do it is above in the github link but I basically fill an int array with the itemIDs and a double array with the drop chances. Then send those into a method to set everything up. Then to figure out what items to drop I create a random float between 0.0 and 1.0 then multiply the float by 100 and any items with drop chances higher than the float will be dropped.

That really depends on your object framework. There are so many, Ill just let you find them yourself. I don’t mean the broad term kinds, but the high level frameworks that differ with each programmer, unless you are copying someone else. Really, there are a ton of ways. Just experiment!

Here is how we did it some years ago - This was for a game with lots of items

We had a Webinterface on which we could add items to a Boss / Mob. The Lootable could be exported and looked kind of like this:

[bossID].table

[tr][td]tdID[/td][td]lnItemID[/td][td]tdDropChance[/td][/tr]
[tr][td]0[/td][td]1262[/td][td]0.01[/td][/tr]
[tr][td]1[/td][td]1337[/td][td]0.50[/td][/tr]

Every time a boss was loaded (start of level) , a random number between 1 and 100 was drawn for each item on the list.
DropChance was multiplied by the random number. If it was >= 1 we added it to a Collection.

Every Boss/Mobb had a chance to drop say 3 -6 items.
We would than randomly pick (random.nextInt(3) + 3) items from that Collection and wait for the boss to go down.

In the loottable were always enough dropChance = 1.0 items to guarantee something would drop.

Crazy times… :slight_smile:

Yeah basically like that

every enemy has a droplist: a list of items and the chance in percent.
In my case thise has to be a per enemy list because in my game enemy A could drop a potion with 10% while enemy b could drop it at 30%
if in our game you would say: well no matter who drops it, they always have fixed chances, then you could simplify.
then I would do this per text file - you CAN use xml or json, and you would like to write a small tool for it…

i guess you should loop trough all droppable items.
Each item gets checked against its own random value.
This way not all items with > 30% drop when the number is 30;

Like this:
Chance / CurrentRandom / Item
.01 .0324 1
.10 .1243 2
.22 .3679 3

So this pass only item 1 drops, while the other items had a bigger chance.