Skip to main content

Event System

Hyperscape uses a strongly-typed event system for decoupled inter-system communication. Over 500 event types enable systems to communicate without direct dependencies.
Event types are defined in packages/shared/src/types/events/events.ts.

Architecture

Systems emit events instead of calling each other directly. This ensures:
  • Loose coupling - Systems don’t know about each other
  • Extensibility - Add listeners without modifying emitters
  • Testability - Mock events for unit tests
  • Replay - Events can be recorded and replayed

Event Types

Events are organized by category in the EventType enum:

Combat Events

Entity Events

Inventory Events

Skill Events

Player Events

Resource Events

Bank Events

Quest Events


Usage

Emitting Events

Subscribing to Events

Typed Event Data

Each event type has a corresponding data interface:

Event Bridge

The EventBridge automatically converts game events to network packets:

Event Flow Example

Here’s how a player picking up an item flows through the system:

Best Practices

1

Use Typed Events

Always define interfaces for event data to catch type errors at compile time.
2

Keep Handlers Fast

Event handlers should complete quickly. Offload heavy work to async tasks.
3

Avoid Circular Emissions

Don’t emit events that trigger handlers that emit the same event.
4

Clean Up Subscriptions

Call unsubscribe() or use autoCleanup: true in SystemBase config.