Skip to main content

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 emits QUEST_START_CONFIRM event:
Client shows quest accept screen with requirements and rewards.

2. Quest Start

Player accepts → Client sends questAccept packet → Server starts quest:
Actions:
  • Creates quest_progress row with status in_progress
  • Sets currentStage to first non-dialogue stage
  • Grants onStart items if defined
  • Emits QUEST_STARTED event
  • Logs to audit trail

3. Progress Tracking

Quest system subscribes to game events:
On progress:
  • Updates stageProgress JSON
  • Emits QUEST_PROGRESSED event
  • Sends chat message when objective complete
  • Saves to database

4. Quest Completion

When all stages complete, player returns to quest NPC:
Actions:
  • Marks quest as completed with timestamp
  • Awards quest points (atomic transaction)
  • Grants reward items
  • Grants skill XP
  • Emits QUEST_COMPLETED event
  • Shows completion screen
  • Logs to audit trail

Security Features

HMAC Kill Token Validation

Prevents spoofed NPC_DIED events from granting quest progress:
Implementation:
  • 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:
Use cases:
  • 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
Quest Complete Screen:
  • 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 player
  • getQuestDetail - Request specific quest details
  • questAccept - Accept a quest
Server → Client:
  • questList - Quest list with status
  • questDetail - Detailed quest information
  • questStartConfirm - Quest accept confirmation screen
  • questProgressed - Progress update
  • questCompleted - 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:

NPC System

How NPCs are defined and how dialogue triggers quests.

Skills System

Skill XP rewards and level requirements for quests.