Calculating RPG Loot Drop Chance?

Started by
8 comments, last by matrisking 11 years ago

I'm trying to figure out the best way to implement a loot drop system for my roguelike. I need individual enemies to have lists of items they can drop, each with different odds of dropping. Here's how I'm doing it now:


 public static Item checkDrop(List<LootChance> loot_list)
        {
            if (checkLootList(loot_list))
            {
                float roll = (float)rand.NextDouble() * 100;
                float chance_count = 0;

                foreach (LootChance lc in loot_list)
                {
                    if (roll <= lc.PercentChance)
                    {
                        return lc.Loot;
                    }
                    chance_count += lc.PercentChance;
                }
            }
            else
            {
                Log.add("Loot odds exceed 100%!");
            }

            return null;
        }

This works for now, but it will stop me from ever having the total odds of all possible loot items to exceed 100. I could see there being other, possibly better ways of handling this. How is this kind of thing usually calculated?

Advertisement

Normalise the values in the list.

Say we have a chance to drop eggs or widgets, with eggs being 10 times more likely than widgets. We have 10 + 1 possibilities, so eggs is 10/11 and widgets 1/11 chance.

Either use a roll from 1 to 11 or multiply up by 100 to get a percentage. Make the last item drop always if the others fail to avoid rounding error, if you use a percentage.

"Most people think, great God will come from the sky, take away everything, and make everybody feel high" - Bob Marley

Thanks for the reply!

I avoided doing that because I use the remaining unused percent to decide when to drop nothing at all. Should I be making that a separate check? Like first roll to see if the enemy will drop an item, and after that roll to see what the item is?

Yeah, that's what I would do (use 2 checks). That's also easily expandable to have a distribution of number of items to drop (10% drop nothing, 50% drop 1 item, 30% drop 2, 10% drop 3, etc.).

"Most people think, great God will come from the sky, take away everything, and make everybody feel high" - Bob Marley

So would the best way to do this be to hold all the possible loot outcomes in a collection that gets generated once when the enemy is instantiated, then just roll for which element of the collection to access?

I'd only generate the collection when you are about to use it (i.e. when the enemy is killed), and then throw it away.

"Most people think, great God will come from the sky, take away everything, and make everybody feel high" - Bob Marley

Yeah I guess that would make more sense. Thanks for the help!

Check out this article, I think it will provide exactly what your looking for, it basically describes how most commercial MMO's implement random loot tables. http://www.codeproject.com/Articles/420046/Loot-Tables-Random-Maps-and-Monsters-Part-I

It may make sense either way. Rolling when a creature dies is much easier and also saves CPU cycles (fewer creatures die than exist).

One should however note that if you give an enemy a weapon to drop, then unless the enemy is entirely braindead, he should actually use it against you, too (99% of all games don't work that way, but I find it a terrible immersion breaker, only topped by skeletons dropping coins (the hell, in which pocket do they keep them?!) and rats dropping pole axes and swords). It just doesn't make sense that a thief dies attacking you with a rusty dagger and then drops a +2 longsword and a wand of fireballs.

Insofar, rolling what items an opponent is carrying when spawning it (as opposed to when it drops dead) may make perfect sense. Same goes for creatures picking up items, which often happens in rogue-likes. If a creature picks something up, this whatever-it-is should drop when the creature dies, too -- probably in addition to some other loot.

Adjusting drop rates similarly to how shop prices adjust to demand/supply in some implementations may be interesting, too. There isn't an endless supply of invisibility cloaks in the world, so after you've had 4 or 5 drops from killing kobolds in 10 minutes, the "supply" should be exhausted, no matter how lucky you are. This might be a good cause for leaky bucket (might possibly/probably even work fine in a multiplayer game that way).

I was thinking each monster for my game would have a random value generated at spawntime that both the server and the users game had. Then when the monster died this value can be used by both the server and the user to determine what loot should be obtained. It can also be used during spawning to make sure its using the right weapons and perhaps if its a skelton persay - has a decaying leather belt with a small coin bag on it?

This topic is closed to new replies.

Advertisement