Randomized rewards that feel exciting and fair. Weighted loot tables with nested tables, guaranteed drops plus random rolls, quantity ranges, rarity tiers with colors, level and condition filters, luck modifiers, pity timers (bad-luck protection), drop-rate math (chance in N tries, tries for 90% of players), showing honest odds, and loot feedback (beams, sounds, colors). Includes a tested loot....
Download skill (.zip) Files on GitHubLoot system
Drop-in: assets/loot.js (tests over 20,000 rolls: nested rare table hits its 10% weight, coin quantities average right,
pity never allows more than 4 misses, luck raises legendary rates, drop math matches the formulas).
import { createLoot, RARITY, chanceInN, triesFor } from "./core/loot.js";
const loot = createLoot({ rng: rng.next, tables: {
goblin: { always: [{ item: "coin", min: 1, max: 3 }], rolls: 1, entries: [
{ item: "potion", weight: 30 }, { table: "gems", weight: 10 }, { nothing: true, weight: 60 } ] },
gems: { entries: [{ item: "ruby", weight: 3, rarity: "rare" }, { item: "diamond", weight: 1, rarity: "epic", minLevel: 5 }] },
boss: { rolls: 2, pity: { after: 4, match: (e) => e.item === "crown" }, entries: [{ item: "crown", weight: 5 }, { item: "gold", weight: 95, min: 20, max: 40 }] },
}});
const drops = loot.roll("goblin", { level: player.level, luck: player.luck }); // [{ item, count, rarity? }]
save.set("pity", loot.misses()); // keep bad-luck protection across sessions
Design rules
- Always give something small (coins, XP) plus a chance at something good. “Nothing” drops feel bad in short games.
- Rarity tiers with consistent colors everywhere (
RARITY): drop beam, item name, border, sound pitch. - Pity timers for important items: forced after N misses, so nobody is unlucky forever.
- Use the math: an item at 1% takes
triesFor(0.01, 0.9)= 230 tries for 90% of players to see it. Is that what you want? - Luck shifts weight toward rarer tiers but never guarantees them.
- Scale drops by level/area with
minLevel/maxLevelrather than separate tables everywhere. - Honest odds: if real money is ever involved, show exact rates (and check local laws). For free games, still avoid manipulative near-miss tricks.
Feedback
Rare drops: a beam or glow by rarity, a distinct sound, a short slow-mo or freeze for legendaries, and a toast. Auto-collect common drops (magnet) and make rare ones a deliberate pickup.
Balance
Simulate a session (game-balance-testing): items per hour by rarity, gold income vs prices (game-economy), and time until the first rare.