$ show runejs/server
This repository implements a RuneScape game server emulator (build #435, October 2006) in TypeScript/Node.js. It provides a full multiplayer game world with player management, NPCs, skills (mining, woodcutting, smithing, firemaking, runecrafting, crafting, fletching, prayer, etc.), quests (Cook's Assistant, Witch's Potion, Goblin Diplomacy tutorial), combat, banking, shops, and item interactions. The server uses a tick-based game loop (600ms ticks) and supports multiple server roles (game, login, update) that can run standalone or together via a gateway server. The architecture is modular: a core engine provides an action pipeline for handling player events (object interaction, item use, commands, etc.), a task scheduler for delayed/tick-synced actions, a plugin system for content (skills, quests, NPCs, items), and a world manager with chunk-based map, collision detection, and pathfinding (A*). Networking uses custom packet handling with ISAAC cipher encryption. Configuration is data-driven: items, NPCs, shops, spawns, skill guides, and music regions are loaded from JSON/YAML files at startup. The system also integrates with the @runejs/filestore library to decode the game cache. Key entry points include src/server/runner.ts (launches servers), src/server/game/game-server.ts (sets up world and gateway), src/engine/action/action-pipeline.ts (central event dispatcher), and src/engine/plugins/loader.ts (auto-loads plugins from dist/plugins/). The codebase is actively developed but shows signs of technical debt: many TODO references to issue #417 (replacing setInterval with tick-synced code), deprecated patterns (actionsCancelled Subject), incomplete features (Construction skill stubbed, Prayer/Magic partly implemented), and inconsistent plugin module formats. Despite these issues, the core patterns (task system, action pipeline, plugin system) are well-designed and demonstrate non-obvious craftsmanship.
The LLM identified 4 files worth highlighting for reuse:
A generic tick-based task scheduler that manages delayed and periodic tasks for actors. It supports task cancellation on movement (breakTypes), priority queues, and integration with the game's 600ms tick loop. This component is isolated enough to be extracted for any game or simulation requiring scheduled actions, and it demonstrates a clean separation of concerns with the Task and ActorTask hierarchy.
The central event processing pipeline that dispatches player actions (e.g., object interaction, item use, commands) through registered hooks and pipe functions. It uses a filter system (hook-filters.ts) to match actions to the correct handlers. This pattern is reusable for any event-driven system requiring extensible, plugin-based handling of user or system events, and it demonstrates a well-structured chain-of-responsibility pattern.
A generic container class for managing stacks of items (inventory, bank, equipment) with events for add/remove/swap operations, weight calculation, and capacity limits. It is parameterized by item type and supports slot-based and stack-based operations. This component could be reused in any game or application requiring a flexible item storage system, and it demonstrates clean encapsulation and event-driven design.
A skills management class that provides XP-to-level conversion using a precomputed lookup table (0–200M XP), level formulas, and shortcut properties for each skill (attack, strength, defence, etc.). It also calculates total level and combat level. This component is self-contained and could be reused in any RPG or game requiring skill progression with experience points, demonstrating efficient data-driven design.