ranged-list

0.0.9 • Public • Published

Reason for existance.

I needed a simple way to generate lists that I can roll a dice against, and get a result. Typical example is a table top rpg, loot table.

Example of Usage:

 
const RangedList = require('rangedlist');
const RangedListEntry = require('rangedlistentry');
 
let rangedList = new RangedList();
 
//Add Entry, object / relevance
rangedList.add( new RangedListEntry({name:"glove of strength", strength:2}, 5) );
rangedList.add( new RangedListEntry({name:"rusty dagger", atk:-2}, 25) );
rangedList.add( new RangedListEntry({name:"healing potion", life:+2}, 15) );
rangedList.add( new RangedListEntry({name:"unicorn feather", tempSkill:"Flight"}, 2) );
rangedList.add( new RangedListEntry({name:"bag of gold", money:15}, 30) );
 
//You can set the range any time during your script, 
 
rangedListRandomRelevance.setRange(20);
rangedListRandomRelevance.printToLog();
 
});
 

Example of generated list printed to log:

1 - 6: {"name":"glove of strength","strength":2}

7 - 38: {"name":"rusty dagger","atk":-2}

39 - 57: {"name":"healing potion","life":2}

58 - 59: {"name":"unicorn feather","tempSkill":"Flight"}

60 - 97: {"name":"bag of gold","money":15}

98 - 100: "Re-Roll"

The call will log a warn if the range is smaller then the number of entries, or if your relevance for one object is extremly high Example:

obj1 = relevance 1000 obj2 = relevance 1 obj3 = relevace 1

1 - 99: obj1,

99-100: obj2

100-101: obj3

This is due to the fact that we floor values, but allow no value below zero.

Readme

Keywords

none

Package Sidebar

Install

npm i ranged-list

Weekly Downloads

4

Version

0.0.9

License

MIT

Last publish

Collaborators

  • thespaceman