Skip to content

Endings

tilttek/character-retirement

Ending a character

CharacterEndings::end() ends the story of a character in a campaign its sheet joined:

$endings->end('ending-1', 'sheet-1', 'campaign-7', Fate::Died, $at, cause: 'Fell at the bridge of Kel', session: 'session-12');
ValueWhat it holds
The identifierThe ending's own identifier, given by the application.
The sheetThe identifier of a sheet of tilttek/character-sheet; its owner becomes the ending's owner.
The campaignA campaign the sheet joined.
FateRetired, Died or Lost — vanished, captured, its fate unknown.
The dateWhen the story ended, as the application dates it.
The causeWhat ended it, 1 to 500 characters, line breaks allowed; or nothing.
The sessionThe identifier of the session where it ended; or nothing.

A character ends once at a time: while one of its endings is open, in any campaign, another is refused with EndingRefused. A sheet ends 50 times at most over its life, and a campaign keeps 5 000 endings at most, open or not. Every identifier is 1 to 128 letters, digits, _, ., : or -, starting with a letter, never an address.

The library does not change the sheet: current() gives the open ending of a sheet, or null while its story goes on, and the application refuses the changes it would not make to a character out of play.

The frozen sheet

At the end, the sheet is frozen as it stands, computed by the rules of its system, into a FrozenSheet:

  • its name, its system and its level;
  • the value of each attribute;
  • every value its rules derive, the maxima of its pools among them;
  • the charges left in each pool — the hit points it fell with;
  • its equipment, each item with its name and quantity;
  • the fields the campaign kept on it — a faction, a downtime count.

The frozen sheet never changes again: a sheet renamed, levelled or erased afterwards leaves it as it was. It holds the bounds of tilttek/character-sheet.

FrozenSheet::toArray() writes it as plain values — strings, integers and booleans in maps — for a store to keep as JSON; FrozenSheet::fromArray() reads them back and checks every key, every type and every bound, so a document changed outside the library is refused with InvalidEnding rather than shown.

Cause and epitaph

setCause() sets or erases what ended the character. writeEpitaph() sets or erases its epitaph, 1 to 1 000 characters with line breaks: the words its owner writes for the memorial. Both are texts written by people, without control characters other than line breaks, nor spaces around them.

Who reads an ending

An ending has a Visibility:

VisibilityWho reads it
PrivateIts owner and the game master of the campaign. The default.
CampaignThe members of the campaign.
PublicAnyone, those outside the campaign included.

share() changes it. A Viewer says who reads: Viewer::gameMaster() reads every ending of the campaign, Viewer::member($id) reads those shared with the campaign or the public and its own, Viewer::outsider() reads the public ones. Whether a member is the game master or belongs to the campaign is the application's to know.

The memorial

memorial() gives a page of the memorial of a campaign: its open endings the viewer reads, by the date they ended, the latest first, those of the same date in the order they were kept. A page holds 1 to 200 endings, 50 by default, from an offset of 0 or more. countMemorial() says how many endings the viewer reads in all.

Coming back

bringBack() brings a character back — raised, out of retirement, found — at a date that is not before its end:

  • its ending leaves the memorial, and stays in history(), every ending of the sheet by the date it came;
  • the character goes on from its sheet, which never stopped;
  • it can end again later, with a new ending and a new frozen sheet.

A character that already came back is refused with EndingRefused.

Changes and facts

Each change reads the ending, checks it, keeps it at the next version and tells the observer once. A change that changes nothing — the same cause, the same epitaph, the same visibility — keeps nothing and tells nothing. Nothing rewards an ending: the library gives no points, badges or rewards for a character's death.

Forgetting

remove() erases one ending with its frozen sheet, its cause and its epitaph. forgetSheet() erases every ending of a sheet, once the sheet itself is erased — on the SheetDeleted event of tilttek/character-sheet —, and forgetOwner() every ending of the sheets a member keeps, once the member is erased. Each says how many endings it erased, and each erased ending is told to the observer.