Objectives, missions and progression tracking. Quests as data with ordered or parallel objectives driven by game events, counters, optional objectives, prerequisites that unlock follow-up quests, quest states (locked, available, active, completed, turned in, failed), timers, abandoning, rewards, a HUD tracker and quest log, save and load, and validation. Includes tested quests.js. Use for RPG q...
Download skill (.zip) Files on GitHubQuest system
Drop-in: assets/quests.js (tests: locked until the prerequisite is done, ordered objectives, counters, completion and
rewards, follow-up quests unlock, time limit fails, save and load).
import { createQuests } from "./core/quests.js";
const quests = createQuests({
rats: { name: "Rat problem", giver: "baker", ordered: true, rewards: { xp: 50, gold: 20 }, objectives: [
{ id: "kill", text: "Defeat rats", on: "enemyKilled", when: (e) => e.type === "rat", count: 5 },
{ id: "back", text: "Return to the baker", on: "talked", when: (e) => e.npc === "baker" } ] },
cellar: { name: "The cellar", requires: ["rats"], objectives: [{ id: "find", text: "Explore the cellar", on: "enteredArea", when: (e) => e.area === "cellar" }] },
}, { onComplete: (id, r) => toast(`Quest complete: ${id}`), onUpdate: () => hud.refreshQuests() });
console.assert(quests.validate().length === 0);
for (const e of ["enemyKilled", "talked", "enteredArea"]) game.events.on(e, (d) => quests.event(e, d)); // forward the events quests use
quests.start("rats"); quests.turnIn("rats") → rewards HUD: quests.tracked() save: quests.toJSON() / load()
States
locked → (prerequisites done) → available → start → active → objectives done → completed → turnIn → turnedIn
(rewards). Active quests can fail (timer, an NPC died) or be abandoned (back to available).
Design
- Objectives say exactly what to do and where (marker on the map or an arrow). Show counters: “Rats 3/5”.
- Mix verbs: defeat, collect, reach, talk, escort, protect, craft. Avoid “collect 20 of X” chains.
- Optional objectives for extra rewards. Ordered objectives tell a little story.
- Rewards visible before accepting. Turn-in by talking to the giver, or auto-complete for small games.
- Track 1–3 quests in the HUD; full log in the pause menu.
- Daily or repeatable quests: reset state on a date seed (procedural-generation
dailySeed).
Rules
Quests react to events; gameplay code never calls the quest system directly. Quest state is in the save (with a version:
game-save-migration). Removing a quest in an update: load drops unknown quests safely.