User Tools

Site Tools


Sidebar

Torchmodders Site


Wiki Navigation

loot_works

Chthon Tut “how loot works”

This is a straight paste! It needs some formating :P

@Chthon said: I was looking into this for modding purposes awhile back. Since there seems to be some interest in the topic on the forums, I thought I'd post some info about how loot generation works in TL2.

Step 0: Kill a Monster The first step in the loot generation process is that you have to kill a monster. When a monster dies, the loot generation process begins. This process is run independently for each player who is close enough (and probably locally on that player's computer). You cannot see, much less steal, other players' loot. How close is close enough is defined in GLOBALS.DAT as LOOT_DISTRIBUTION_RANGE:68.

Step 1: The Monster's Treasure Entries In each monster's data file, there can be up to three entries for “treasure.” Each entry specifies three things: The spawnclass to roll for the drop, the minimum number of times to roll that spawnclass, and the maximum number of times to roll that spawnclass. When the monster dies, for each treasure entry it has, a random number between the entry's minimum and maximum is picked and that entry's spawnclass is rolled that number of times.

In order to keep this example simple, I'm going to proceed as if we're only doing one roll for one treasure entry; but remember that it's entirely possible to end up repeating steps 2 and 3 for multiple rolls for each treasure entry, and that a monster can have up to three treasure entries.

Step 2: Spawnclasses! A spawnclass consists of a list of entries. Each entry contains four major pieces of information:

* First, what you get if the entry is chosen. There are three possibilities:

A specific item. If this entry is chosen, you get this specific item. Example, if the entry says “Mana Potion 3” as a specific item, then you will get a Mana Potion 3 (a/k/a “Giant Mana Potion”). FYI: Gold piles are specific items. A Unit Type. If this entry is chosen, you get a random item from this unit type. See Step 2b for details. FYI: “None” is a unit type, meaning you get nothing. it is by far the most common unit type in the spawnclasses.

A roll from another spawnclass. If this entry is chosen, you go roll the named spawnclass. The process continues recursively until you finally roll a specific item or a unit type. * Second, the “weight” of this entry being chosen. The entry's chance of being chosen is equal to its weight divided by the sum of the weights for all the entries in the spawnclass. Entries with a weight of -1 are always chosen (which means that more than one entry can be chosen when a spawnclass is rolled.) * Third and fourth, a minimum and a maximum. If this entry is for a specific item, you will get a random number, between the minimum and the maximum, of copies of that specific item. If this entry is for a unit type, you will get a random number, between the minimum and the maximum, of items from the unit type. If this entry is for a spawnclass, you will get a random number, between the minimum and the maximum, of rolls of that spawnclass. Entries within a spawnclass can also have some other properties. These aren't very important for understanding the overall picture, but may be helpful to modders and detail-oriented loot seekers: * Beneficiary Unit Type (optional). This entry cannot be selected if the player's character is not of this unit type. Used to make class-specific quest rewards. * Rarity Override (optional). Only applies if this entry is for a unit type. Unknown if this is inherited by recursed spawnclasses. Ignores the rarities defined in items' dat files, causing all eligible items to have the same chance to spawn – including those that would otherwise never spawn due to rarities of 0. * Level Bonus (optional). Applies if this entry is for a unit type. Unknown if it also applies if this entry is for a spawnclass that doesn't specify its own level bonus. Loot gets generated by this entry as if the monster was this many levels higher than it actually was. * Magic Find % (optional). Applies if this entry is for a unit type. Unknown if it also applies if this entry is for a spawnclass that doesn't specify its own MF bonus. Loot gets generated by this entry as if the player has this much more MF% than the player actually has. * Ignore range (true or false). Only applies if this entry is for a unit type. If set to “true,” then all items from the unit type are candidates to drop instead of only items with a level range that includes the dead monster's level. * Force enchant (true or false). If set to true, item cannot be white; must be green or better. * No unique (true or false). Only applies if this entry is for a unit type. Unique items are excluded from being candidates to drop. * No magical (true or false). Only applies if this entry is for a unit type. Blue items are excluded from being candidates to drop. * No set pieces (true or false). Only applies if this entry is for a unit type. Set items are excluded from being candidates to drop. * Only set pieces (true or false). Only applies if this entry is for a unit type. Everything other than set items are excluded from being candidates to drop. Again, for the sake of simplicity, I'm going to be proceeding as if we just picked one spawnclass entry; but remember that we could have had multiple entries picked if some had weights of -1, so it's possible to go through steps 2b, 2c, and 3 multiple times per spawnclass roll. And that's on top of going through step 2 multiple times if the monster had multiple treasure entries and/or multiple rolls for a treasure entry. Step 2b. Magic Find! This step only applies if a spawnclass entry for a unit type gets selected. If a spawnclass entry for a specific item was selected, skip to step 3. Before I describe how magic find works, here's a very important note: Magic find only comes into the picture AFTER a spawnclass entry for a unit type gets selected. It does NOT do anything to steer the random selection of which entry from the spawnclass gets chosen. Two examples to clarify this: 1. A spawnclass contains two entries: one for the unit type “potion” and one for the unit type “legendary sword,” each with equal weight. You will get a potion 50% of the time regardless of your MF%. 2. A spawnclass contains two entries: one for the unit type “potion” and one for the unit type “1H Sword,” each with equal weight. You will get a 1H Sword 50% of the time regardless of your MF%. If you get a 1H Sword, then the rarity of the sword will be affected by your MF%. Because of the way Runic laid out the spawnclasses for “decent” drops, MF usually has no effect on them (i.e., it's useless for “boss running” like in D2), and is only useful for improving the terrible odds on what are supposed to be “**” drops. (This is definitely something that could stand to be improved through modding.)

With that out of the way, magic find works as follows:

Assuming that a spawnclass entry for a unit type has been selected, the next step is to choose a rarity level. The rarity levels are defined in GLOBALS.DAT as: NORMAL_ITEM_WEIGHT:10000 (white items) MAGIC_ITEM_WEIGHT:90 (blue items) UNIQUE_ITEM_WEIGHT:7 (gold and red items) RANDOMMAGIC_ITEM_WEIGHT:100 (green items)

So, for example, the baseline chance for a blue item is 90 / (10k + 100 + 90 + 7) ~= 0.0088.

Magic find effects these weights as follows: new_weight = old_weight * (1 + (MF/100 * bonus/100)), where the bonuses are also defined in GLOBALS.DAT as: MAGICFIND_MAGIC_INFLUENCE:2000 (blue items) MAGICFIND_UNIQUE_INFLUENCE:2000 (gold and red items) MAGICFIND_RANDOM_INFLUENCE:1000 (green items)

So, for example, with 10% MF, your chance to find a blue item would increase to 270 / (10k + 200 + 270 + 21) ~= 0.026.

A couple observations here, mostly based on the fact that MF% modifies the weights for the rarity levels (rather than a more intuitive system like modifying the threshholds for a waterfall):

1. There is no plain English way to express what MF% does in TL2. Intuitive statements like “100% MF doubles your chance to find magic items” are nowhere near accurate.

2. The relationship between MF% and the actual chance of getting a particular rarity is non-linear with diminishing returns.

3. The hidden bonus multipliers mean that low amounts of MF% have a much, much bigger influence than you would intuitively expect from the number displayed. For instance, our example with 10% MF nearly tripled the actual odds of getting a blue item.

Step 2c: From Unit Types to Items

This step only applies if a spawnclass entry for a unit type gets selected. If a spawnclass entry for a specific item was selected, skip to step 3.

Again assuming that a spawnclass entry for a unit type has been selected, after the rarity is selected, it's time to pick the actual item. This is a two step-process:

First, unless the spawnclass entry had “ignore range” set to true, the pool of items in the unit type is filtered by level. Items have a level range bracketed by a minimum and maximum in their dat file. (I don't remember the default values for if these fields are left blank, but they're something like item's level +/- 4.) Items are only allowed to stay in the pool of candidates if the monster's level (as modified by any level bonus in the spawnclass entry) falls within that range.

Second, the rarities of the items remaining in the candidate pool are added up, and each item has the chance to drop equal to its rarity divided by the sum of all the rarities. Items with a rarity of 0 cannot spawn unless a rarity override is specified in the spawnclass entry (in which case all items will have an equal chance).

Step 3: Affixes and Sockets

At this point, we know what kind of item is going to drop – either because our chosen spawnclass entry specified a particular item to start with, or because we went through the whole process of picking an item from a unit type. What's left to figure out is what kind of magical properties the item is going to have. There are three general possibilities: First, a plain white item will never have anything added to it. Easy enough. Second, an item that has one or more affixes already assigned in its dat file will get exactly what the dat file says it will get, nothing more or less. (All unique items fit into this category. So do 4-socket weapons, due to a hidden “blank” affix.) The third category is the random blues and greens, where the rules get interesting:

The affixes providing magical properties are defined with a list of item types and a range of item levels they can appear on. Affixes are selected by a system that should be familiar to you by now – the weights for all eligible affixes are added up, and each affix's chance to appear equals its weight divided by the sum of all the weights.

Each affix has a defined cost called “slots occupy.” Typical values are 1, 2, 3, and 5. Items have a number of “slots” to spend on affixes picked randomly from the ranges for their rarity defined in GLOBALS.DAT: MIN_RANDOM_ENCHANT_SLOTS:2 (green items)

MAX_RANDOM_ENCHANT_SLOTS:2 (green items) MIN_MAGIC_ITEM_SLOTS:5 (blue items) MAX_MAGIC_ITEM_SLOTS:6 (blue items) MIN_UNIQUE_ITEM_SLOTS:10 (gold and red items, but never matters b/c these items all have predefined affixes) MAX_UNIQUE_ITEM_SLOTS:12 (gold and red items, but never matters b/c these items all have predefined affixes)

The process of rolling for affixes continues until the item does not have enough “slots” left to pay for any of the available affixes.

Randomly generated items may also get sockets, up to the maximum allowed in that item's dat file, based on the following odds defined in GLOBALS.DAT: RANDOM_SOCKET_CHANCE:25

SECOND_SOCKET_CHANCE:33 (8.25% overall) THIRD_SOCKET_CHANCE:33 (~2.7% overall)

(These numbers strike me as somewhat higher than what I'm used to seeing in game, so that may be another factor hidden somewhere that lowers the odds.)

An Example:

I think an example may help make sense of the system, so let's do one.

This example is quite long, so I'm going to put it in a spoiler. I do recommend reading it though, since it really helps to clear things up.

loot_works.txt · Last modified: 2019/02/10 17:00 by phanjam