Lootr
A simple RPG-like looting system.
Heavily inspired from http://journal.stuffwithstuff.com/2014/07/05/dropping-loot
Adding items
Lootr is organized as a tree. Get a new instance with
var loot = '/equipment' loot
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
lootloot
The branch
method returns itself, on which you can add
items or nested branchs.
loot loot
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 levelloot // only 'Stuff' // Loot something from anywhereloot // any item // Loot an armorloot // one of [ 'Plates', 'Leather' ] // Loot a weaponloot // 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.
deadMonsterdrops = from: '/equipment' luck:10 stack:1 from: '/equipment/armor' luck:05 stack:2 from: '/equipment/weapons' luck:08 stack:'2-10' // Loot your reward from a dead monstervar rewards = loot 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.
lootloot
Then, at loot time:
deadMonsterdrops = from: '/equipment' stack:2 modify:name:true // Loot your reward from a dead monstervar rewards = loot 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