Lootr
Lootr \lutĘ\ is a simple RPG-like looting system.
Lootr provides a way to organize data commonly named loot in a gameplay context. It helps you to manage which items can be found, in a generic and statisticaly controlled system.
It is heavily inspired from the work of Bob Nystrom http://journal.stuffwithstuff.com/2014/07/05/dropping-loot
A JS version is available here https://github.com/vincent/lootr A C# version is available here https://github.com/Sparox/LootrCsharp
In Lootr, lootables are organized in a tree of categories and items.
Then, a collection of Drops describe how items are yield from a loot action.
equipment: 50% chances, stack of 2
This might yield 2 items in the equipment tree, for example 1 Gloves + 1 Boots
Create a loot bag
Create items.
use ;
let mut loot = default;
loot.add;
Items can have properties.
use ;
let mut loot = default;
loot.add;
Each level is composed by a list of .items and nested .branchs.
Organize the loot repository by adding branchs
use Lootr;
let mut loot = default;
let weapons = loot.add_branch;
let armor = loot.add_branch;
Optionnaly with items
use ;
let mut loot = default;
loot.add_branch;
loot.add_branch;
loot.branch_mut
.unwrap
.add_branch;
Looting
Loot against a loot table, described by a like the following.
use ;
let drops = ;
A builder pattern is also available to ease drops creation.
path()selects the root of this dropdepth()max depth to considerluck()the luck we start with, will decrease at each sub treestack()the range of copies to yield
use ;
let mut loot = default;
loot.add_branch;
loot.add_branch;
let drops = ;
// Loot your reward from a dead monster
let rewards = loot.loot;
// rewards = [ "Berries", "Plates", "Uzi", "Uzi", "Staff" ]
Modifiers
The library includes a basic modifiers system.
Add some modifiers to affect the properties of each looted item with addModifiers.
namemodifier will be used as simple suffixes. Or, if it contains one or more$property, each property name will be replaced.- other properties will be handled as the following
loot.add({ name: "Staff", color: "golden" })
loot.addModifiers([
{ name: "from the shadows" },
{ name: "A $color $name from the gods" },
{ agility: 5 },
{ force: "*2" },
{ intell: "2-10" },
{ name: "A $color $name from the gods", force: "+4" }
])
Then, at loot time:
deadMonster.drops = [
{from: "/equipment", stack:2, modify:true }
]
// Loot your reward from a dead monster
var rewards = loot.loot(deadMonster.drops)
rewards = [
// some of these could drop
{name:"Staff from the shadows"},
{name:"Staff", intell: 6},
{name:"A golden staff from the gods"},
{name:"A golden staff from the gods", force:4 }
]
Tests
cargo test