Skip to content

DIM's New Stat Calculations

Ben Hollis edited this page Sep 23, 2019 · 2 revisions

Hi folks, this is Ben, one of the people who builds DIM. I wanted to talk about some changes I made to DIM recently, and how they affect what you see in the stat bars and perk/mod tooltips.

A few weeks ago we shipped a change to how we calculate stats for DIM that brings it more in line with how Destiny actually works (though not perfectly, as we'll discuss). This means that our stat bars and perk/mod values are more true to the effects you'll actually see in game. This can lead to some unintuitive results, for example a tier 10 masterwork mod adding +9 to a stat (instead of +10).

DIM works by using the Bungie.net API, which is the same API that all other Destiny apps and websites use, including the Companion App. Bungie generously makes this API available to everyone to build on, and within it is a wealth of information about how the items and systems of Destiny work. DIM reads your live API data about your characters and their inventory, and combines that information with "the manifest" which is a mostly static database (also from Bungie) with information about all the different parts of the game.

For each item, there are a number of stats (Impact, Resistance, Magazine Size, etc.) which have different effects on how the item works. Each stat has a value called the "investment value" which is the raw value of the stat, usually from 0-100. Then, this investment value gets transformed by per-item scaling functions that map them into the value you see in the game UI. It's actually more complicated than that - there are scripts that can run in the game that modify these values further!

The Bungie.net API provides apps with "calculated stats" which precalculate the effects of these per-item scaling functions. This gives a pretty accurate view of most stats, but even they cannot make use of the scripts that are used in game, so what Bungie.net (and DIM) reports as the stat values cannot ever be 100% accurate. Magazine Size is one of the stats that's notorious for being impossible to calculate accurately from just this data.

DIM used these calculated stats up until recently, with a few exceptions. First, we show a handful of "hidden stats", like Aim Assistance, Zoom, and Recoil Direction. These are never surfaced in the game UI, and the Bungie.net API doesn't provide them as calculated stats. Instead, we showed the raw investment value for those stats. Second, we also showed the value that perks and mods would apply to your stats. In game this is only vague text like "increases range", but we wanted to show the actual numbers. However, we only had access to the investment values, not the calculated values, so that's what we showed.

The recent change in DIM was to switch to calculating all stats on our own, using the per-item scaling functions to transform the investment stats into calculated stats. This let us show the proper value even for hidden stats, and we can also show the actual amount perks and mods contribute. You may have noticed that before this change, perks like "Extended Mag" would show "+20 Magazine" when it really couldn't add +20 - the real value is only a few extra bullets in the mag.

So let's explain the math. I'll use one of the puzzles I mentioned before - how can a +10 masterwork only add +9 to a stat? My New City submachine gun is masterworked for Reload Speed, and before my recent change hovering over the mod would say it adds +10 Reload Speed. But now it shows +9 Reload Speed. Why?

First, we look up the inventory item definition for New City in the manifest. You can see it here. Under stats there is a statGroupHash that points to the table of stat scaling functions for this weapon. You can see the stat group definition here. This has a table of scaledStats which defines a piecewise linear function for each stat that maps its 1-100 investment value to its real in-game value.

Going back to the inventory item definition's, we can see in investmentStats that the base investment value for the Reload Speed stat is 48. But there are also perks and mods, which are modeled as sockets, that add to that value. The tier 10 masterwork adds +10, and the active Tactical Mag perk adds another +10. This gives us an investment value of 68.

Now we look up the Reload Speed scaling function from scaledStats table in the stat group. It looks like this:

value  |  0 | 100
weight | 10 | 100

This is a simple table with only one segment - some stats have multiple segments. What this is saying is that when the investment stat is at 0, the game stat is actually 10, and when the investment stat is at 100, the game value is also 100. Inbetween, we linearly interpolate the weight. This means that every point of investment stat actually only adds 0.9 points in game.

To calculate this out, we figure out the start and end of the segment our value lies in (which is easy in this case, since we only have one segment). Then we apply this function:

t = (value - start.value) / (end.value - start.value);
gameValue = round(start.weight + t * (end.weight - start.weight));

Substituting in the real values, we get:

(68 - 0) / 100 = .68
10 + .68 * (100 - 10) = 71.2 (rounds to 71)

So the final Reload Speed for my New City is going to be 71. But where did we get +9 for the masterwork mod? In DIM, we figure out how much an individual perk or mod would add by subtracting the investment value of the perk or mod from the total investment value of the stat (after adding all perks and mods) and then recalculate the stat as if that perk or mod wasn't active. Then we subtract the two numbers to find out how much the mod added. In this case, without the +10 masterwork the investment value for Reload Speed would have been 58 (we still have Tactical Mag), and running it through the formulas above produces a calculated stat value of 62. 71 - 62 is 9, so our tier 10 masterwork actually only adds 10 to Reload Speed.

If you stuck with me through this long post, hopefully you have some understanding for how apps like DIM work, how we figure out stats, and why DIM now shows different values than it (and many other tools) used to.