A simple RPG-like looting system.
Heavily inspired from http://journal.stuffwithstuff.com/2014/07/05/dropping-loot
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
Organize the loot repository by adding branchs
branch method returns itself, on which you can
add items or nested branchs.
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
// 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' ]
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:1from: '/equipment/armor' luck:05 stack:2from: '/equipment/weapons' luck:08 stack:'2-10'// Loot your reward from a dead monstervar rewards = lootrewards = name:'Stuff' name:'Plates' name:'Uzi' name:'Uzi'
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.
Then, at loot time:
deadMonsterdrops =from: '/equipment' stack:2 modify:name:true// Loot your reward from a dead monstervar rewards = lootrewards =name:'Staff from the shadows'name:'A golden staff from the gods'
A simple test suite is available here
It also works with