I have a “drop table” / “loot table” / “item table” / “whatever you want to call it” system and I need to solve two Problems. Apologies in advance for the text wall :/
- Calculate the probability of pulling a specific item from a table
- Calculate the probability of pulling ANY item from a table with a specific tag (such as “Epic”, “Rare”, “Weapon”, “Sword”, “Currency”, etc)
A few details about the system:
- Tables are setup with a certain number of ‘Slots’ and ‘Rolls’
- Slots determines the total number of unique items that can be dropped from the table
- Rolls determines how many times we ‘pull’ an item out of the table
- Each row within a table will drop one of a pre-calculated set of items
- Each row can be marked as ‘Guaranteed’, ‘Random’ or both (more on that in a bit)
- Rows have a ‘MaxRollsToConsume’ field (0 == infinite rolls), and a Weight field (used for weighted randomness, 0 Weight = never pulled)
And a bit of pseudo code for how we actually pull items out of the table
create a guaranteed set of rows create a random pool of rows create a result with a set number of slots available to fill (note: adding an item to the result will only fill a slot if that item does not already exist in the result) foreach row in table if row is guaranteed, then add to guaranteed set if row is random, then add to random pool foreach row in guaranteed set pull item out of row and add it to result consume a roll while there are rolls remaining and empty slots in the result select a row from the random set using weighted randomness and respecting the MaxRollsToConsume field pull item out of row and add it to result consume a roll if this row has reached its max rolls then remove it from the random pool while there are rolls remaining select an item from the current result using weighted randomness and respecting the MaxRollsToConsume field add the item to the result consume a roll return the result
I understand how to calculate the probabilities for the ‘Guaranteed’ rows because, well, they are events that are guaranteed to happen so it’s pretty easy to calculate.
Where I’m falling short is on how to calculate the ‘Random’ rows (especially with respect to the MaxRollsToConsume field) and only pulling a certain number of times. For example, I have 5 random rows, but only 2 Rolls to consume. How do I calculate the probability of an item being pulled from one of the those 2 Rolls while also taking into account how many Rolls are allowed per row?
I’m fairly confident that if I can solve Problem 1 with some help then I’ll be able to solve Problem 2 on my own. Any help is appreciated and thanks in advance! If anything is unclear or more info is needed please let me know! 🙂