npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

lootastic

v1.1.2

Published

a loot rolling system

Downloads

32

Readme

Lootastic

A simple and flexible loot rolling system.

Install

npm i lootastic

Usage

You can create a LootTable with:

  • a plain array (all item weights will be set to 1)
  • an array with objects formatted like { chance: X, result: <item> }

You can also pass in a rollModifier into the options object to increase the weights of every item.

Examples:

// plain initialization - all weights are 1
let lootTable = new LootTable(['sword', 'armor', 'potion', 'shield']);

// weight initialization - swords are common, potions are not
let lootTable = new LootTable([
    { chance: 1, result: 'potion' },
    { chance: 5, result: 'armor' },
    { chance: 10, result: 'shield' },
    { chance: 20, result: 'sword' }
]);

// weight initialization with a rollModifier - each weight is 10 higher
// a common use-case here is a "luck bonus" in item drops
let lootTable = new LootTable([
    { chance: 1, result: 'potion' },
    { chance: 5, result: 'armor' },
    { chance: 10, result: 'shield' },
    { chance: 20, result: 'sword', maxChance: 100 }, // always a 1/5 drop rate
    { chance: -1, result: 'gold' } // always drops
], { rollModifier: 10 });

You can roll a table using one of 3 methods:

  • choose X items with replacement
  • choose X items without replacement
  • try to roll for each item in the table using a chance/X probability (where X would be something like 1/10000)

Examples:

let result = lootTable.chooseWithReplacement(1) // 1 random item + gold
let result = lootTable.chooseWithReplacement(5) // 5 random items + gold

let result = lootTable.chooseWithoutReplacement(1) // 1 random item + gold
let result = lootTable.chooseWithoutReplacement(4) // the whole table + gold
let result = lootTable.chooseWithoutReplacement(5) // error - not enough items to choose

let result = lootTable.tryToDropEachItem(1) // all items will drop + gold
let result = lootTable.tryToDropEachItem(10) // shield and sword will guaranteed drop + gold
let result = lootTable.tryToDropEachItem(100) // some items might drop + gold

If you want to roll multiple loot tables at once, or the same loot table multiple times (suppose you have a monster drop table and a zone drop table), you can use the LootRoller class:

let result = LootRoller.rollTables([

    { table: lootTable, func: LootFunctions.WithoutReplacement, args: 1 }, // always picks 1 item (+ gold)
    { table: lootTable, func: LootFunctions.EachItem, args: 1 }, // try to drop each item (+ gold)

]); // 2 gold entries, 1 item, and maybe more depending on the EachItem roll

Usage Notes

  • You can add a property maxChance to an item to customize tryToDropForEachItem when you don't want to scale item probabilities.
  • You can specify a weight of -1 to tell an item to always drop in addition to other random drops.
  • Use plain objects, not classes, since the data is cloned when rolling loot.