Loot, affixes, uniques, runewords and a pile only you can see

D2-style treasure classes, rarity rolls and diminishing magic find, instanced per-player piles, runes and the Gloam Anvil, and a live item database, with measured drop rates.

Gold loot beams rise from a dead boss in a sandstone tomb while a hero stands over the pile
Contents
  1. What's in the tables
  2. Treasure classes
  3. Rarity first, then the body
  4. Magic find with diminishing returns
  5. A pile only you can see
  6. Sockets, runes and runewords
  7. The Gloam Anvil
  8. The item database
  9. Where the counts come from
  10. Validation at save and at boot
  11. Versioned sync
  12. The admin editor
  13. Why flat treasure classes
  14. Related posts

Diablo II's loot model (treasure classes, a rarity roll, ilvl-gated affixes, uniques, sets, sockets, runewords) with one co-op change: every player gets their own pile. Drop rates below come from running the real roller a few hundred thousand times.

Four item tooltips side by side: a magic two-hand sword, a green set body armor, a yellow rare helm and the Kindle runeword on an axe
The four tooltip colors: blue magic, green set, yellow rare and the gold runeword. These are the real ItemTooltip component on the landing page, fed items rolled from the same tables the server uses.

What's in the tables

All TypeScript under shared/data/items/ and shared/endgame/:

Table Count
Equipment bases (weapons, armor, jewelry) 118
Affixes (prefixes and suffixes) 161
Uniques 83
Sets / set pieces 5 / 15
Runes 20
Gems (7 types, 5 grades) 35
Runewords 16

Bases have D2 footprints (1×1 rings to 2×4 polearms) and a qlvl. Affixes have a level requirement and a group, so no double "+life" prefixes. Uniques and set pieces list mod ranges, rolled once per copy.

Treasure classes

Normal, champion and unique elite each have a class; each of the 18 bosses has its own:

shared/data/treasure.tsTypeScript
{ id: 'normal', picks: 1, weights: { none: 100, gold: 32, potion: 22, item: 18, scroll: 3 }, qualityMult: 1, goldMult: 1 },
{ id: 'champion', picks: 2, weights: { none: 40, gold: 30, potion: 20, item: 32, scroll: 3 }, qualityMult: 1.5, goldMult: 1.5 },
{
  id: 'boss_bone_king', picks: 7, weights: { none: 0, gold: 30, potion: 20, item: 50, scroll: 5 }, qualityMult: 4, goldMult: 7,
  guaranteed: [{ minRarity: 'unique', count: 1 }, { minRarity: 'rare', count: 2 }, { minRarity: 'magic', count: 2 }],
},
  • none: 100 of 175 makes over half of trash kills empty, on purpose: empty kills make drops feel like drops.
  • qualityMult scales magic/rare/unique chances; the Bone King is 4× plus a guaranteed unique, two rares and two magics.
  • At ilvl ≤ 12, potion weight ×1.5 (EARLY_POTION_MULT), part of the early-game tuning.

Rarity first, then the body

shared/items/roll.tsTypeScript
export function rollRarity(rng: Rng, magicFind: number, qualityMult: number): RolledRarity {
  const c = rarityChances(magicFind, qualityMult)
  if (rng.chance(c.unique)) return 'unique'
  if (rng.chance(c.set)) return 'set'
  if (rng.chance(c.rare)) return 'rare'
  if (rng.chance(c.magic)) return 'magic'
  return 'normal'
}
  • Base chances: 1% unique, 1% set, 7% rare, 30% magic.
  • A unique must have base qlvl ≤ ilvl, else it becomes a rare. Hollowmere's Last Light (level-5 sword) comes from ~1 in 10 Bone King kills, ~1 in 20 from later bosses with bigger pools.
  • Bases within 15 qlvl of ilvl weigh ×3; jewelry ×0.5; white rings and amulets promote to magic.
  • Magic: 75% prefix, 75% suffix, at least one. Rare: 3–6 affixes weighted 40/30/20/10, max three per kind, two-word name by base type.
A diagram: monster death, treasure class, loot eligibility, per-player drop rolls, rarity, body, sockets and spawnDrop, ending on the client
The whole pipeline, from the kill to a pile only one player can see. Every box names the function that does the work.

Magic find with diminishing returns

D2's curve: magic gets full MF, rare MF·500/(MF+500), unique and set MF·250/(MF+250):

shared/data/treasure.tsTypeScript
export function effectiveMagicFind(mf: number): { magic: number; rare: number; unique: number } {
  const m = Math.max(0, mf)
  return { magic: m, rare: (m * 500) / (m + 500), unique: (m * 250) / (m + 250) }
}

300% MF → 136% effective unique; 1200% → 207%. Clamps: unique and set 50%, rare 60%, magic 90%.

Two curves bending away from a straight line: effective rare and unique magic find against gear magic find
The magic line is straight. Rare bends toward 500 and unique toward 250. Past about 300% gear MF, each extra point buys less.

Real rollDrop, real tables, fixed seed, ilvl 30:

Per 1,000 kills White Magic Rare Set Unique
Normal monster, MF 0 65.0 29.3 6.6 1.1 1.0
Normal monster, MF 100 34.9 53.0 12.6 1.8 1.8
Normal monster, MF 300 7.6 70.8 19.9 2.4 2.3
Champion, MF 0 241.6 202.3 51.7 7.4 7.7
Champion, MF 300 33.3 301.3 143.3 17.5 17.8
Unique elite, MF 0 542.6 1,608 458.4 67.7 68.7
Unique elite, MF 300 75.4 1,134 1,224.8 152.6 163.6
  • MF 0 normals also give 571 empty kills, 182 gold piles, 126 potions per 1,000.
  • At 300% MF, magic hits its 90% clamp and whites nearly vanish, a real cost since whites are runeword bases.
  • A trash unique is ~1 per 1,000 kills; one unique elite is worth ~70 trash kills in uniques. Go for the named monster.
  • Average Bone King pile, one player: 2.52 white, 2.68 magic, 3.55 rare, 1.26 unique, 2.0 gold piles, plus potions and scrolls.
The Bone King's pile in the Ashen Throne. Everything on the floor belongs to the one player who sees it. Captured in-engine for the trailer.

A pile only you can see

D2 parties shared one pile and the fastest clicker won. Duskbound rolls the whole pile once per eligible player, with that player's MF:

server/game/sim/loot.tsTypeScript
/** Damagers plus anyone alive within LOOT_RANGE (party members are naturally included). */
export function lootEligible(w: World, m: SimMonster): SimPlayer[] {
  const out: SimPlayer[] = []
  const r2 = LOOT_RANGE * LOOT_RANGE
  for (const p of w.players.values()) {
    if (p.bot) continue // companions: never get loot
    const dx = p.x - m.x
    const dy = p.y - m.y
    if (m.damagers.has(p.id) || (!p.dead && dx * dx + dy * dy <= r2)) out.push(p)
  }
  return out
}
  • Eligible: anyone who hit it, or anyone alive within 25 tiles. Companions never.
  • Each drop has an ownerId and is added only to its owner's Colyseus StateView; other players' items never reach your client.
  • Rares and up send the owner a loot_beam. Alt shows labels.
  • Hand-dropped items get ownerId '', which anyone can take: that's how you give an item to another player.
A set body armor tooltip over the inventory in a red-lit town
A set piece on the equipment doll: Plate of the Winter Court. Green lines are the set bonuses, which turn on at two and three pieces worn. The names of the pieces show which ones you're wearing.

Sockets, runes and runewords

Sockets roll from a stream seeded by the item uid, so adding them didn't shift the shared RNG and break every seeded expectation:

shared/items/roll.tsTypeScript
export function rollItem(rng: Rng, opts: RollItemOptions): ItemInstance {
  // endgame: sockets roll from the item's own uid, so the shared rng stream is untouched
  const item = rollItemBody(rng, opts)
  const sockets = rollSockets(new Rng(hash32('sockets', item.uid)), item)
  return sockets > 0 ? { ...item, sockets, socketed: [] } : item
}
White Magic Rare Unique Set
Socket chance 35% 18% 8% 3% 0
Rarity cap 6 4 2 1 0

Max sockets is the lowest of the base cap, the ilvl cap (2 below 15, up to 6 at 55+) and the rarity cap. Fewer is always likelier.

Runes (Ash through Vex) roll on their own table: 0.4% rune and 1.2% gem per trash kill on Normal (0.8% / 1.4% in Nightmare and Hell), ×3 champions, ×6 unique elites, ×25 bosses. Each rune is 1.35× rarer than the last, so Vex is ~300× rarer than Ash; qlvl must be ≤ monster level.

A runeword is exact runes, in order, in a white item of the right type with exactly that many sockets:

shared/endgame/runewords.tsTypeScript
{
  id: 'kindle',
  name: 'Kindle',
  runes: rw('Ash', 'Ember'),
  categories: WEAPON,
  mods: m([['attackDmgPct', 30], ['fireMin', 10], ['fireMax', 20], ['firePct', 15], ['lightRadius', 2]]),
  pitch: 'A first flame for any weapon: fire on every swing and spell',
},

Runeword mods stack on the runes' own: Kindle's "Adds 15-30 Fire Damage" is Ember's 5–10 plus the runeword's 10–20. Runes and gems stack by qty, or they'd fill the 10×4 bag.

The Gloam Anvil

  • Fuses three of a rune into the next, or three of a gem grade into the next
  • Free up to Jarn (rune 10); then index² × 100 gold (Thal → Vex: 36,100)
  • Unsockets everything for 1,000 gold per stone, returning a runeword's runes
The Gloam Anvil panel in Hollowmere: two fuse recipes and an unsocket row
The anvil lists only what you can do right now: fuse three Ash into a Brin, three Flawless Topaz into a Perfect Topaz, or unsocket the Short Sword's Ash for 1,000 gold.

One Vex from Ash is 3¹⁹ ≈ 1.16 billion Ash. The anvil is for the last step or two, like the Horadric Cube.

The item database

292 browsable entries at /items, with an editor at /admin/items.

The public items page: a search box, kind chips, filters and a grid of unique item cards
/items: search, filters by kind, type, class, act and level, and every card is the real in-game tooltip. The badges under each card are live counts.

One catalog. shared/data/items/catalog.ts is the only lookup, server and client. It layers admin overrides (ItemOverride rows) over the TypeScript tables.

  • Lookups always resolve, even disabled items, so old saves never break
  • Disabled items leave drop pools; existing copies still work
  • Nothing is deleted. Revert drops the override; reverting a custom item disables it

Rolled values stay on the item. Built-in uniques store only uniqueRolls; lines come from the definition at read time. An edited definition would misalign old rolls, so copies rolled from edited definitions store the resolved fixedMods:

shared/items/roll.tsTypeScript
function rollFixed(rng: Rng, mods: readonly UniqueMod[], edited: boolean): Pick<ItemInstance, 'uniqueRolls' | 'fixedMods'> {
  if (!edited) {
    const rolls: number[] = []
    for (const m of mods) if (m.max !== m.min) rolls.push(rng.int(m.min, m.max))
    return { uniqueRolls: rolls }
  }
  const fixedMods = mods.map((m): Mod => {
    const mod: Mod = { stat: m.stat, value: m.max !== m.min ? rng.int(m.min, m.max) : m.min }
    if (m.param !== undefined) mod.param = m.param
    if (m.level !== undefined) mod.level = m.level
    return mod
  })
  return { uniqueRolls: [], fixedMods }
}

Live counts without scanning saves.

  • ItemHolding (owner, item key, count) is rebuilt per owner on save, skipped if unchanged
  • ItemDaily (per item per UTC day, drops and crafts) feeds the 30-day sparkline
  • ItemFirstFind: first writer wins
  • The sim writes to memory; a timer folds it into Postgres every few seconds, so the tick never waits
An item detail page for Hollowmere's Last Light: the tooltip with a lowest/highest roll toggle, stat ranges, related items and a boss drop-chance table
The item page. The lowest/highest toggle rolls the tooltip at each end of its ranges. The boss table is computed from the treasure classes, not measured: 1 in 10 from the Bone King on Normal, 1 in 49 on Nightmare.

Drop odds are closed-form: dropSources walks each boss class per difficulty (pick lands × rarity chance × this item's share of the pool, over every pick and guaranteed roll), assuming one hero and no MF. Nightmare drops the Last Light less because the ilvl is higher and the pool bigger.

Where the counts come from

Three one-line // items: hooks: spawnDrop, the inventory move handler, the Anvil. Runewords have no drop event, so the hook diffs before and after the move:

server/items/hooks.tsTypeScript
export function onRunewordsMade(w: World, p: SimPlayer, before: MoveState, after: MoveState): void {
  const had = withRuneword(before)
  for (const [uid, id] of withRuneword(after)) {
    if (had.get(uid) === id) continue
    const key = `runeword:${id}`
    tallyItem({ itemKey: key, how: 'craft', characterId: p.id, name: p.name, zoneId: w.zoneId })
    recordGameEvent({ kind: 'craft', characterId: p.id, name: p.name, zoneId: w.zoneId, detail: 'runeword', itemKey: key, data: { item: getRuneword(id)?.name ?? id } })
  }
}

withRuneword scans grid, equipment and open stash, so moving a runeword between them never double-counts. Runes from index 14 up are logged on drop for the rare-rune pages.

Validation at save and at boot

Overrides are untrusted JSON. catalogSchema.ts defines UniqueDefZ, SetItemDefZ, RunewordDefZ, base and affix patches and a discriminated OverrideInputZ. overrideProblems checks what a schema can't (base exists and is wearable, runes are real, some allowed category fits that many sockets, one range per affix line) and returns plain sentences; the editor runs it live. checkOverride runs on every save and on every row at boot:

server/items/overrides.tsTypeScript
for (const r of dbRows) {
  const checked = checkOverride({ kind: r.kind, id: r.itemId, enabled: r.enabled, def: r.def }, r.custom)
  if (checked.ok) {
    good.push(checked.entry)
    live.push({ kind: r.kind, id: r.itemId, version: r.version, enabled: r.enabled })
  } else {
    log.warn(`[items] override ${r.kind}:${r.itemId} rejected: ${checked.problems.join('; ')}`)
  }
}
applyCatalog({ version: versionOf(live), entries: good })

A row that references a base a later deploy renamed is skipped, logged and shown as invalid. If the whole load fails, the server runs on built-ins.

Versioned sync

versionOf hashes sorted kind:id:version:enabled to 16 hex chars (empty catalog = empty string). Each admin write bumps the row, reloads and broadcasts catalog {version}; clients refetch items.catalog only on mismatch and re-validate with CatalogOverridesZ. Edits reach every player within a round trip, no deploy.

The admin editor

  • Every item badged built-in, edited, custom, disabled or invalid
  • Uniques, set pieces, runewords edited as full definitions; bases and affixes as safe patches (damage yes, size no, since rolled copies occupy cells)
  • Live preview is the real tooltip rendered from the draft
  • Create, enable/disable, revert, give-to-self; every write audited with the admin's name
The admin item editor: the definition form for Lastlight Reforged on the left, its live tooltip preview on the right
Editing a unique. The tooltip on the right is rendered from the unsaved draft by the component the game uses.

Two end-to-end checks:

  • Last Light disabled: 20,000 simulated Bone King kills, 0 copies. Enabled: ~1 in 10.
  • Emberbrand, a runeword made entirely in the editor (Ash + Cael in a two-socket sword, axe or mace), was socketed by a live character and showed up on its page as crafted once.
The in-game inventory with an Emberbrand short sword tooltip: its runeword mods and Socketed (2/2): Ash, Cael
Emberbrand in a live inventory. The runeword doesn't exist in the TypeScript tables.
The Emberbrand item page: the runeword's recipe, its fitting bases, and In the Reach counts of 1 made and 1 held
Its item page right after. The craft hook recorded it as made, and the character's next save put it in the holdings index.

More in the admin console.

Why flat treasure classes

D2 nested classes. A flat array lets dropSources compute every item's odds with one Math.pow per pick, instead of a recursive walk over a class graph. "The Bone King gives a 1 in 10 shot at the Act 1 sword" is the number a designer wants to set, and here it's one function call from the data.