Overview
Hyperscape features an OSRS-style quest system with multi-stage quests, progress tracking, and rewards. Quests are defined in JSON manifests and tracked server-side with database persistence.Quest definitions are stored in
packages/server/world/assets/manifests/quests.json.Quest Structure
Quests are defined with the following structure:Quest Stages
Quests consist of multiple stages that must be completed in order:Stage Types
Stage Definition
Quest Status
Quests have four possible statuses:ready_to_complete is a derived status computed when status === "in_progress" AND the current stage objective is met.Progress Tracking
Quest progress is tracked per-player in the database:Database Schema
Stage Progress Format
Progress is stored as JSON with stage-specific counters:Quest Flow
1. Quest Request
Player talks to quest NPC → Server emitsQUEST_START_CONFIRM event:
2. Quest Start
Player accepts → Client sendsquestAccept packet → Server starts quest:
- Creates
quest_progressrow with statusin_progress - Sets
currentStageto first non-dialogue stage - Grants
onStartitems if defined - Emits
QUEST_STARTEDevent - Logs to audit trail
3. Progress Tracking
Quest system subscribes to game events:- Updates
stageProgressJSON - Emits
QUEST_PROGRESSEDevent - Sends chat message when objective complete
- Saves to database
4. Quest Completion
When all stages complete, player returns to quest NPC:- Marks quest as
completedwith timestamp - Awards quest points (atomic transaction)
- Grants reward items
- Grants skill XP
- Emits
QUEST_COMPLETEDevent - Shows completion screen
- Logs to audit trail
Security Features
HMAC Kill Token Validation
Prevents spoofedNPC_DIED events from granting quest progress:
- Uses HMAC-SHA256 for cryptographic validation
- Tokens include:
mobId,killedBy,timestamp - Validates timestamp within 5-second window
- Server-only (uses Node.js crypto module)
Quest Audit Logging
All quest state changes are logged for security auditing:- Fraud detection and investigation
- Debugging quest progression bugs
- Analytics data for game design
- Customer support inquiries
Rate Limiting
Quest network handlers are rate-limited:Quest Journal UI
Players access quests via the Quest Journal (📜 icon in sidebar):Features
- Color-coded status: Red (not started), Yellow (in progress), Green (completed)
- Quest points tracking: Total quest points displayed
- Progress visualization: Strikethrough for completed steps
- Dynamic counters: Shows progress like “Kill goblins (7/15)”
- Quest details: Requirements, rewards, and stage descriptions
Quest Screens
Quest Start Screen:- Shows quest name, description, difficulty
- Lists requirements (quests, skills, items)
- Displays rewards (quest points, items, XP)
- Accept/Decline buttons
- Congratulations message
- Quest name
- Rewards summary
- Parchment/scroll aesthetic
- Click anywhere to dismiss
Example Quest Definition
API Reference
QuestSystem Methods
Network Packets
Client → Server:getQuestList- Request all quests for playergetQuestDetail- Request specific quest detailsquestAccept- Accept a quest
questList- Quest list with statusquestDetail- Detailed quest informationquestStartConfirm- Quest accept confirmation screenquestProgressed- Progress updatequestCompleted- Quest completion screen
Performance Optimizations
O(1) Stage Lookups
Stage lookups use pre-allocated Map caches instead of O(n)find() calls:
Object Spread Elimination
Direct mutation in hot paths eliminates object allocations:Log Verbosity Reduction
Debug-level logging for frequent events, info-level only for milestones:Related Documentation
NPC System
How NPCs are defined and how dialogue triggers quests.
Skills System
Skill XP rewards and level requirements for quests.