Jump to content

  • Log In with Google      Sign In   
  • Create Account


Calculating RPG Loot Drop Chance?


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
10 replies to this topic

#1 Ntwiles   Members   -  Reputation: 144

Like
0Likes
Like

Posted 14 April 2013 - 03:33 AM

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? 



Sponsor:

#2 Paradigm Shifter   Crossbones+   -  Reputation: 5252

Like
4Likes
Like

Posted 14 April 2013 - 04:04 AM

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.


Edited by Paradigm Shifter, 14 April 2013 - 04:04 AM.

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

#3 Ntwiles   Members   -  Reputation: 144

Like
0Likes
Like

Posted 14 April 2013 - 04:14 AM

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?



#4 Paradigm Shifter   Crossbones+   -  Reputation: 5252

Like
0Likes
Like

Posted 14 April 2013 - 04:18 AM

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

#5 Ntwiles   Members   -  Reputation: 144

Like
0Likes
Like

Posted 14 April 2013 - 04:48 AM

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?



#6 Paradigm Shifter   Crossbones+   -  Reputation: 5252

Like
1Likes
Like

Posted 14 April 2013 - 04:51 AM

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

#7 Ntwiles   Members   -  Reputation: 144

Like
0Likes
Like

Posted 14 April 2013 - 04:53 AM

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



#8 LordRhys   Members   -  Reputation: 349

Like
0Likes
Like

Posted 15 April 2013 - 07:07 AM

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

#9 samoth   Crossbones+   -  Reputation: 4683

Like
1Likes
Like

Posted 15 April 2013 - 11:16 AM

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).


Edited by samoth, 15 April 2013 - 11:20 AM.


#10 MichaelNIII   Members   -  Reputation: 195

Like
0Likes
Like

Posted 15 April 2013 - 06:32 PM

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?

#11 matrisking   Members   -  Reputation: 282

Like
0Likes
Like

Posted 16 April 2013 - 09:14 AM

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.

 

I'm the words of Bill Lumbergh: "Yyyyyeahhhh... I'm going to go ahead and sort of disagree with you."

 

It's interesting advice, but highly subjective and probably better suited for a thread on game design than one on game programming.  Not every game is meant to be highly immersive, so unless immersion is your top priority I personally would just go with whatever's most fun.

 

(ugh and sorry, I just can't help myself: sure it makes sense for a thief to attack you with a rusty dagger if that's the only weapon he knows how to use and/or is able to equip biggrin.png )






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS