Sheets
tilttek/character-sheetA sheet
A CharacterSheet is a character kept by its owner, outside any campaign:
| Value | Bounds |
|---|---|
id, owner | identifiers: 1 to 128 letters, digits, _, ., : or -, starting with a letter; never a name or an address |
system | the key of its game system in tilttek/rpg-systems |
name | 1 to 120 characters, without control characters or surrounding spaces |
attributes | the value of each attribute of the system, by key, up to 64, each from -1 000 000 to 1 000 000 |
level | 1 to the highest level of the rules, 1 000 at most |
items | up to 500 Item, each identifier once, in the order given |
spent | the charges spent from each pool, by key; a pool with none spent is left out |
campaigns | the fields of each campaign joined, by campaign identifier, up to 32 campaigns |
version | its version in the store, 0 for a new sheet |
A sheet is an immutable value checked for its shape. CharacterSheets checks it against the rules of its system: a
value for every attribute of the system and for no other, each within the attribute's bounds, and the level within the
rules. An attribute without bounds in its system takes any value of the sheet's range.
CharacterSheet::sameAs() says whether two sheets hold the same values, their version aside, each of the same type: a
field "1" is not the field 1.
The rules of a system
SheetRules says how the sheets of one system are computed:
$rules = new SheetRules($system, [
'str_mod' => '(str - 10) / 2',
'defence' => '10 + dex_mod + gear.armour',
'dex_mod' => '(dex - 10) / 2',
'hit_points' => 'max(1, (8 + (con - 10) / 2) * level)',
'ki' => 'level',
], pools: ['hit_points', 'ki'], maxLevel: 20);
- Derived values, up to 200, each a formula by key. A key is 1 to 64 lowercase letters, digits or
_, not starting with a digit, and neverlevel,gear, a function or an attribute of the system. A formula readslevel, the attributes of the system, the other derived values, andgear.<stat>; any other name is refused when the rules are built. The rules order the formulas so that each comes after those it reads, in the order given otherwise —defenceabove is computed afterdex_mod—, and refuse formulas that read one another in a loop. - Pools, up to 32: the derived values a character spends charges from.
- The highest level, 1 to 1 000; 20 when not given.
A system whose attribute is named level or starts with gear. cannot have rules: the formulas read those names
otherwise. An attribute whose key a formula cannot name — 1st, two-handed — is held by the sheet and bounded by the
system, but no formula reads it.
Rules\StaticRuleBook gives the rules of a fixed list of systems, one each.
Equipment
An Item has an identifier on its sheet, a name of 1 to 120 characters, a quantity of 1 to 10 000, whether it is
equipped, and what it gives to up to 16 stats while it is, -1 000 to 1 000 each. A stat is a key like a derived
value's, read by the formulas as gear.<stat>. What an item gives counts once, whatever its quantity, and only while it
is equipped. A stat a formula reads and no equipped item gives counts 0.
CharacterSheets::putItem() adds an item last, or replaces the item of its identifier where it is;
equip() equips it or takes it off; removeItem() removes it.
Charges
A pool is a derived value: its maximum is its formula's value — level, max(1, (8 + con_mod) * level) —, computed
anew each time. spend() spends 1 to 1 000 charges at once, refused beyond what is left; restore() gives back 1 to
1 000, or every one spent when no number is given. A character who loses a level keeps what they spent: a pool never has
fewer than 0 left.
Campaigns
A sheet joins up to 32 campaigns with join(). Each campaign keeps up to 64 fields of its own on the sheet, set with
setField(): a key like a derived value's, and a text of up to 2 000 characters with line breaks, a whole number from
-1 000 000 000 to 1 000 000 000, or a boolean; null erases the field. leave() takes the sheet out of a campaign and
erases that campaign's fields. A field of a campaign the sheet did not join is refused.
Computing a sheet
CharacterSheets::compute() — or SheetCalculator::compute() with a sheet and its rules — gives a
View\ComputedSheet: the level, the attributes, what the equipped items give by stat, the derived values in the order
of the rules, and each pool as a View\Pool — its maximum, what is spent, what is left.
Adjustments are added to attributes before anything is derived from them: what a condition, a spell or a curse changes for a while, kept elsewhere. An adjustment is for an attribute the sheet holds, -1 000 000 to 1 000 000.
$sheets->compute('sheet-1', ['str' => -4])->value('str_mod');
Reading a sheet from other tools
ComputedSheet::values() gives every value by the name a formula reads it — level, the attributes, the derived values
and gear.<stat> —, the statistics other tools take:
tilttek/conditionscomputes the effect of a character's conditions on the statistics it is given:$effective = $conditions->effective('sheet-1', $sheets->compute('sheet-1')->values());
To have what the conditions change on attributes count in the derived values too, the application computes the sheet again with the differences as adjustments:$base = $sheets->compute('sheet-1'); $effective = $conditions->effective('sheet-1', $base->attributes); $adjustments = array_map(static fn ($stat): int => $stat->value - $stat->base, $effective); $computed = $sheets->compute('sheet-1', $adjustments);- An inventory's carrying capacity, such as the
CarrierCapacityoftilttek/inventory, reads a derived value of the carrier's sheet —carryfromstr * 15— and gives the rules' default when the carrier has no sheet. - A character rolled by
tilttek/random-charactergives the attributes of a new sheet;create()checks them against the bounds of the system.