What it does
You build a QuestLog over your quests and tell it what happens in the game: a kill with count, a region reached
with flag, a conversation with talk, a scripted moment with mark. The log works out which steps that completes,
which quests are now ready to turn in and whether a new act has begun, and drain hands you the events: accepted,
step, handed, ready, done and act.
Each kind of step has a rule that says how it is judged. A count step needs a counter to reach the step's count,
counted from the moment the quest was accepted unless the rule says lifetime, so wolves killed before you took the
job do not count. A flag step needs a flag set. A held step needs the player to hold enough of an item. A mark
step needs an event that names its target while it is the current step, and with hands it also takes an item from
the player, which is how a delivery works.
Steps are done in order: a step counts only once every step before it is done, and once a later step is done the earlier ones stay done, so handing over a fetched item does not undo the fetch. Acts are the story's chapters: the game starts in act 1 and moves on each time every main quest of the act has been turned in. A giver offers the quests their act allows and takes back the ones that are ready. The log only asks your game how many of an item it holds and to take one away, so it fits any inventory.
Features
- Five built-in step kinds — talk, kill, fetch, reach and deliver.
- Step kinds as data — a rule judged by
count,flag,heldormark, with its own key, so an escort or a crafting step needs no new code. - Counts from acceptance — kill counters start when the quest is taken, or count for life with
lifetime. - Ordered steps that stay done — a step counts once those before it are done, and a later step keeps the earlier ones done.
- Hand-overs — a deliver step takes its item through the host and reports it as
handed; when the step names no item, it hands over the nearest earlier fetched one. - Acts and givers — the act rises as main quests are turned in, and
offers,readyandwaitingsay what each giver has for the player now. - Rewards reported —
turnInreturns the gold and the item for your game to pay. - Events — every change comes out of
drain, for a quest tracker, a toast or a sound. - Careful saves —
snapshotis plain data, andrestoredrops unknown quests and never lets a quest be both active and done.
Good for
- Role-playing games with quest givers in towns, kill and fetch errands, and a main story told in acts.
- Adventure games where talking to the right person or reaching the right place moves the story on.
- Town builders and management games whose characters make requests one after another.
- Story chapters that unlock as the main quests of each act are finished.
- Games with objectives of their own, such as escorting a pilgrim or crafting lanterns, added as rules.
Make it yours
QuestLogOptions takes rules over the built-in STEP_RULES, acts (by default the highest act any quest names),
and a host that says how many of an item the player holds, takes one away, and picks the item a hand-over gives when
the step names none. Quests are plain data: an id, a title, an act, whether it is a main quest, a giver, the steps, and
reward gold and item.
Two different uses: a role-playing game in three acts whose quests are talk, kill, fetch and deliver errands from the
townsfolk, with the party's bag as the host; and a game of its own with five acts, an escort step marked by an arrive
event when the pilgrim reaches the shrine, and crafting counted over the whole game rather than from acceptance.
A quick look
A log over a bag, a quest taken, the game reporting what happened, and the reward:
import { QuestLog } from '@phaser-ae/quests';
const log = new QuestLog(quests, { host: { held: id => bag.count(id), take: id => bag.remove(id) } });
log.offers('mara'); // what Mara can offer now
log.accept(quest); // kills count from here
log.count('kill', 'thicket-wolf'); // the game reports
log.talk('old-sorrel'); // talk and deliver steps naming this npc
const reward = log.turnIn(quest); // { gold, itemId }: the game pays it
for (const e of log.drain()) { /* accepted, step, handed, ready, done, act */ }
Works with
rpg— keeps its quests in a log like this and plays them with no game code.rpg-world— its quests are written in this pack's format.party— a bag and gold to hold quest items and pay rewards.dialogue— for what the characters say while the quests move on.wave-plan— for objectives that compose into a level's win condition rather than quests given by characters.
Good to know
- Steps are in order; a branching quest or a choice is separate quests that your game offers or withholds.
- Rewards are reported, not paid: your game adds the gold and the item.
- A quest is offered by one giver and turned in to the same one.






