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

lootr

v0.0.3

Published

A simple rpg-like looting system

Downloads

9

Readme

Lootr

A simple RPG-like looting system.

Heavily inspired from http://journal.stuffwithstuff.com/2014/07/05/dropping-loot

Lootr !

Adding items

Lootr is organized as a tree. Get a new instance with

var loot = new Lootr('/equipment')

loot.add({ name: 'Stuff' })

Each level is composed by a list of items in loot.items and nested branchs in loot.branchs.

Organize the loot repository by adding branchs

loot.branch('weapons')
loot.branch('armor')

The branch method returns itself, on which you can add items or nested branchs.

loot.branch('/equipment/weapons')
    .add({ name: 'Pistol' })
    .branch('automatic')
        .add({ name: 'Uzi' })

loot.branch('/equipment/armor')
    .add({ name: 'Plates' })
    .add({ name: 'Leather' })

Rollin'

Random-pick something at top level with Lootr.roll( path, depth = 0, chance = 1 )

It will yield an item in the path branch or, if depth is given, in an up to depth deep branchs, if the depth-decreasing chance is greater than a Math.random()

// Loot something from top level
loot.roll('/equipment')                        // only 'Stuff'

// Loot something from anywhere
loot.roll('/equipment', Infinity, Infinity)    // any item

// Loot an armor
loot.roll('/equipment/armor')                  // one of [ 'Plates', 'Leather' ]

// Loot a weapon
loot.roll('/equipment/weapons', 3)             // one of [ 'Pistol', 'Uzi' ]

Lootin'

Loot against a loot table, described by a definition array like the following. The string stack value allow random stacks in the specified range.

deadMonster.drops = [
    {from: '/equipment',         luck:1.0, stack:1 },
    {from: '/equipment/armor',   luck:0.5, stack:2 },
    {from: '/equipment/weapons', luck:0.8, stack:'2-10' }
]

// Loot your reward from a dead monster
var rewards = loot.loot(deadMonster.drops)

rewards = [ {name:'Stuff'}, {name:'Plates'}, {name:'Uzi'}, {name:'Uzi'} ]

Modifiers

The library includes a basic modifiers system.

Add some modifiers to affect the name of each looted item with addNameModifiers. They will be used as simple suffixes. Or, if they contain a $property, each property name will be replaced.

loot.add({ name: 'Staff', color: 'golden' })
loot.addNameModifiers([ 'from the shadows', 'A $color $name from the gods' ])

Then, at loot time:

deadMonster.drops = [
    {from: '/equipment', stack:2, modify:{name:true} }
]

// Loot your reward from a dead monster
var rewards = loot.loot(deadMonster.drops)

rewards = [
    {name:'Staff from the shadows'},
    {name:'A golden staff from the gods'}
]

Tests

A simple test suite is available here

It also works with npm test