โ ๏ธ EXPERIMENTAL PROJECT: This is an experimental RuneScape-inspired MMORPG built with SpacetimeDB to explore AI-human gameplay parity, token-efficient observability, and serverless WASM game architecture.
Toonscape is a proof-of-concept MMORPG demonstrating:
- SpacetimeDB as Game Server: Rust WASM modules handling all game logic, no traditional backend needed
- AI-First Architecture: AI agents and human players share identical APIs, state access, and observability
- Token-Efficient Telemetry: TOON format reduces AI/LLM context costs by 70-80%
- OSRS-Accurate Formulas: Authentic Old School RuneScape combat and progression mechanics
This is NOT a production game - it's a research platform for multiplayer game architecture with AI actors.
Backend (SpacetimeDB):
- ~20,000 lines of Rust WASM compiled to SpacetimeDB module
- 105 tables, 147 reducers
- Tick system (600ms OSRS-accurate timing)
- Full combat system (melee, ranged, magic with OSRS formulas)
- All 23 skills (Attack, Strength, Mining, Fishing, etc.)
- NPC spawning, combat AI, drops, respawning
- Item system with 16,353 definitions from OSRS data
- Quest framework (10+ quests defined)
- Observability:
game_eventtable +tick_event_batch(TOON-encoded)
Content Pipeline:
- TOON compiler (Rust) - Converts OSRS JSON โ .toonw format
- 16,353 items compiled from osrsbox data
- NPCs, quests, skills, drops all seeded via SpacetimeDB tables
- AI comprehension testing suite (validates LLM understanding of TOON format)
Development Tools:
- SpacetimeDB CLI integration (build, deploy, SQL query)
- Cargo workspace (3 Rust crates: server, formulas, toon-compiler)
- Bun workspace (TypeScript packages)
- Auto-generated TypeScript client SDK (389 files)
Client (React Three Fiber):
- Project scaffolding exists (
apps/client/) - SpacetimeDB TypeScript bindings auto-generated
- Benchmark framework for testing server load
- NOT playable - no 3D renderer, no UI, no WebSocket connection active
AI Agents:
ai_agent_stateandllm_request_queuetables in serverprocess_ai_agentsscheduled reducerpackages/ai-agent-service/Node.js service (not tested)- ElizaOS plugin stub (
packages/plugin-toonscape/) with generated types - NOT working - service untested, no live AI agents
- 3D world rendering (Three.js/R3F planned but not built)
- Player authentication beyond username/password
- Real-time multiplayer UI (inventory, chat, minimap)
- Asset streaming pipeline
- Production deployment (Railway, cloud hosting)
- Minigames (Pest Control, Barbarian Assault, etc. - tables defined but no logic)
- Trading, Grand Exchange (tables exist, minimal logic)
- PvP systems
This project is built entirely on SpacetimeDB, a database that replaces your entire backend:
- No traditional server: Game logic runs in a Rust WASM module
- No REST/GraphQL: Clients subscribe to tables via WebSocket
- No ORM: Tables are defined as Rust structs, queries are type-safe
- No deployment complexity:
spacetime publishdeploys database + logic together
Key Concept: In traditional architecture, you'd have PostgreSQL + Node.js/Python server + WebSocket server. With SpacetimeDB, you compile Rust to WASM and the database itself runs your game logic.
Learn more: spacetimedb.com
New to the project? See SETUP.md for complete setup instructions.
Important: This is experimental software. The server works, but there's no playable client yet.
# Install Rust
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
rustup target add wasm32-unknown-unknown
# Install SpacetimeDB CLI
curl -fsSL https://install.spacetimedb.com | bash
# Install Bun (for TypeScript packages)
curl -fsSL https://bun.sh/install | bash# Install all dependencies
bun run setup
# Or manually:
cargo build # Rust dependencies
bun install # TypeScript dependenciesBuild order: formulas โ server โ client types โ client
# Build everything (from root)
bun run build
# Or step-by-step:
# 1. Build server (includes formulas via workspace)
make build
# 2. Generate client types
cd apps/client && bun run generate
# 3. Build client
cd ../.. && bun run --filter='./apps/client' build
# Deploy server locally
make deploy-local
# Or deploy to cloud
cd packages/server && spacetime publish toonscape-server# Terminal 1: Start SpacetimeDB
spacetime start
# Terminal 2: Build & deploy server
make build && make deploy-local
# Terminal 3: Run client dev server
bun run dev:client# View logs
spacetime logs toonscape-server --follow
# Query game state
spacetime sql toonscape-server "SELECT * FROM player LIMIT 10"
# Call reducers for testing
spacetime call toonscape-server inittoonscape/
โโโ packages/ # Shared libraries and packages
โ โโโ server/ # SpacetimeDB module (Rust WASM)
โ โ โโโ src/
โ โ โ โโโ lib.rs # Main module (all tables, reducers, game logic)
โ โ โ โโโ content.rs # Content builder framework
โ โ โ โโโ formulas.rs # Skill-specific formulas
โ โ โ โโโ combat_calculations.rs # Combat formulas
โ โ โ โโโ toon_encoder.rs # AI-optimized event encoding
โ โ โโโ Cargo.toml
โ โโโ formulas/ # Shared combat/skill formulas (benchmarkable)
โ โโโ ai-agent/ # ElizaOS plugin for AI agents
โ โโโ assets/ # Asset pipeline (optimization, CDN deployment)
โโโ apps/ # Runnable applications
โ โโโ client/ # React Three Fiber frontend
โ โโโ docs/ # Mintlify documentation site
โ โโโ ARCHITECTURE.md # System architecture
โ โโโ OBSERVABILITY.md # Observability system
โ โโโ CODE_MAP.md # Code navigation
โ โโโ TESTING.md # Testing guide
โ โโโ CI_CD.md # CI/CD pipeline
โ โโโ TOON_FORMAT.md # Toon encoding format
โ โโโ QUICK_START.md # Metadata population guide
โ โโโ examples/ # Example integrations
โ โโโ reports/ # Historical reports
โโโ Cargo.toml # Rust workspace configuration
โโโ package.json # Bun workspace configuration
โโโ CLAUDE.md # Project-specific instructions for Claude Code
- Combat Triangle: Melee โ Ranged โ Magic โ Melee
- Formulas: Authentic OSRS max hit, accuracy, and damage calculations
- Weapon Speeds: 3-7 tick attack speeds (1.8s - 4.2s)
- Auto-retaliate: Configurable automatic combat
- Attack Styles: Accurate, Aggressive, Defensive, Controlled, Rapid, Longrange
- Gathering: Mining, Woodcutting, Fishing, Farming, Hunter
- Artisan: Smithing, Crafting, Cooking, Fletching, Herblore, Runecraft, Construction
- Combat: Attack, Strength, Defence, Hitpoints, Ranged, Magic, Prayer
- Support: Firemaking, Agility, Thieving, Slayer
- XP Formula: Authentic OSRS experience curve (level 99 cap)
- NPCs: 100+ definitions with combat AI, drops, and respawning
- Items: 140+ definitions with equipment stats, prices, and metadata
- Objects: Trees, rocks, fishing spots with resource depletion
- Quests: 10+ quest definitions with requirements and rewards
- Music: 50+ region-based music tracks
- game_event table: SQL-queryable event log with full context
- tick_event_batch table: Toon-encoded batches (70-80% token reduction for AI/LLM)
- Native SpacetimeDB: WASM-compatible, no HTTP dependencies
- Event Types: 20+ types (combat, skills, items, player actions)
- Metadata: JSON metadata fields for AI context
TICK_DURATION_MS = 600 // 0.6 seconds per tick (OSRS-accurate)
TICKS_PER_MINUTE = 100 // Theoretical maximumAll server-side actions are tick-based:
- Movement: 1 tile per tick (walking) or 2 tiles per tick (running)
- Combat: Weapon-speed dependent (3-7 ticks between attacks)
- Skills: Action times vary (e.g., 5 ticks for woodcutting)
// Effective Level = Base + Prayer + Potion + Style Bonus
effective_attack = base_attack + prayer_bonus + potion_bonus + style_bonus;
// Max Hit (Melee/Ranged)
max_hit = floor(0.5 + effective_strength * (gear_strength_bonus + 64) / 640);
// Accuracy Roll
player_accuracy = effective_attack * (gear_attack_bonus + 64);
opponent_defence = target_defence * (target_defence_bonus + 64);
// Hit Chance
if player_accuracy > opponent_defence {
hit_chance = 1.0 - (opponent_defence + 2) / (2 * (player_accuracy + 1));
} else {
hit_chance = player_accuracy / (2 * (opponent_defence + 1));
}// XP required for level L
xp_for_level = sum(floor((L + 300 * 2^(L/7)) / 4) for L in 1..level)
// Combat XP rates per damage dealt
MELEE_XP_PER_DAMAGE = 4.0
RANGED_XP_PER_DAMAGE = 4.0
MAGIC_XP_PER_DAMAGE = 2.0
HP_XP_PER_DAMAGE = 1.33- SETUP.md - Complete setup guide for new developers
- BUILD.md - Build system, dependencies, and build order
- QUICK_START.md - Quick start guide
- ARCHITECTURE.md - System architecture, tech stack, and design principles
- OBSERVABILITY.md - Native SpacetimeDB observability system
- CODE_MAP.md - Navigation guide for the codebase
- TESTING.md - Testing approaches and patterns
- CI_CD.md - CI/CD pipeline documentation
- CLAUDE.md - Project-specific instructions for Claude Code
- TOON_FORMAT.md - Token-efficient encoding format for AI/LLM
- QUICK_START.md - Metadata population guide
- examples/INTEGRATION.md - Integration examples
Historical implementation reports are in apps/docs/reports/
cd packages/server
# Check code
cargo check
# Format code
cargo fmt --all
# Lint code
cargo clippy --all-targets --all-features
# Build WASM
cargo build --target wasm32-unknown-unknown --release
# Or use SpacetimeDB CLI
spacetime build
# Or from root with workspace
cargo build --target wasm32-unknown-unknown --release# Unit tests (formulas crate)
cd packages/formulas && cargo test
# Reducer testing
cd packages/server
spacetime publish --local toonscape-server
spacetime call toonscape-server test_reducer_name# Local deployment
spacetime publish --local toonscape-server
# Cloud deployment
spacetime publish toonscape-server
# View status
spacetime list
spacetime logs toonscape-server --follow- SpacetimeDB 1.11: Combined database + server runtime
- Rust 1.85+: WASM module development language
- WASM32: wasm32-unknown-unknown target (no_std compatible)
- Cargo Workspace: 3 Rust crates (server, formulas, toon-compiler)
- Native Tables:
game_event(SQL-queryable),tick_event_batch(TOON-encoded) - TOON Format: 70-80% token reduction for AI/LLM context
- SpacetimeDB Logs: Built-in logging with
logcrate - Event Types: 20+ game event types (combat, skills, items, etc.)
- packages/formulas: Separate crate for combat/skill calculations (no SpacetimeDB deps)
- Criterion: Benchmark framework (~500ns per combat calculation)
- OSRS-Accurate: Max hit, accuracy, XP curves match Old School RuneScape
- TOON Compiler: Rust binary that converts OSRS JSON โ .toonw format
- osrsbox Data: 16,353 items, NPCs, quests from osrsbox-db
- SpacetimeDB Seeding:
initreducer populates tables on first publish - AI Testing: Python scripts validate LLM comprehension of TOON format
- Bun 1.1+: Package manager (faster than npm/yarn)
- TypeScript 5.7+: Client code language
- React Three Fiber: Planned 3D renderer (NOT BUILT)
- SpacetimeDB SDK: Auto-generated TypeScript types (389 files)
- Vite: Build tool (configured but no UI exists)
- ElizaOS: Plugin framework (stub exists, untested)
- OpenAI/Anthropic APIs: LLM providers (configured but no live agents)
- Node.js Service:
packages/ai-agent-service/(not deployed) - TOON Context: Token-efficient game state for LLMs (format ready, not tested with live agents)
AI agents and human players use identical:
- SpacetimeDB reducers (actions)
- Subscription queries (state access)
- Rate limits (tick-based)
- Validation rules
All telemetry captures the same data for both:
actor_typeis metadata, not a behavioral switch- Events have identical schemas
- No hidden advantages for either actor type
Both actors receive the same game context:
- Same visibility rules
- Same state representation
- Same available action set
The tick system ensures fairness:
- All actions process in tick order
- No actor can exceed tick-rate actions
- Server authoritative on all state
This project explores several research questions:
Hypothesis: A Rust WASM module compiled to SpacetimeDB can handle MMORPG-scale game logic without Node.js/Python backends.
Status: โ Validated - 20,000 lines of game logic running in WASM with zero traditional backend code.
Hypothesis: AI agents and humans can use identical APIs, state access, and rate limits without special-casing.
Status: ๐ง Partially validated - Server architecture supports parity, but no live AI agents tested yet.
Hypothesis: Schema-first TOON format can reduce LLM context costs by 70-80% vs JSON.
Status: โ
Validated - TOON compiler working, AI comprehension tests passing, tick_event_batch table functional.
Hypothesis: Complex combat/skill formulas can compile to WASM without performance degradation.
Status: โ Validated - All formulas benchmarked, running at ~500ns per calculation in native Rust (WASM overhead minimal).
- SpacetimeDB module with 105 tables, 147 reducers
- Tick system (600ms OSRS-accurate)
- Combat system (melee, ranged, magic with OSRS formulas)
- All 23 skills implemented
- NPC AI, spawning, respawning, drops
- Item/equipment system (16,353 items)
- Native observability (game_event + tick_event_batch)
- TOON compiler and AI comprehension tests
- SpacetimeDB TypeScript SDK integration
- Auto-generated client types (389 files)
- WebSocket connection to SpacetimeDB
- Basic 3D renderer (Three.js/R3F)
- Minimal UI (inventory, skills, chat)
- Client-side interpolation
Goal: Prove a human can connect and perform basic actions (walk, attack, skill).
- AI agent service deployment
- ElizaOS plugin activation
- Live AI agent performing autonomous actions
- AI fairness testing (APM limits, reaction times)
- Multi-agent coordination experiments
Goal: Prove AI agents can play alongside humans with true parity.
- 50+ concurrent AI agents
- 10+ human players
- Performance benchmarks (tick processing time)
- Token cost analysis ($/hour per AI agent)
- SpacetimeDB hosting cost analysis
Goal: Determine if this architecture scales economically.
This is an experimental research project by a single developer. Contributions are welcome, but be aware:
- The client is not functional yet (Phase 2)
- AI agents are untested (Phase 3)
- No production deployment exists
- Architecture may change dramatically based on experiments
If you want to contribute:
- Fork the repository
- Create a feature branch
- Submit a pull request with clear explanation of what you're testing/validating
- Include any performance benchmarks or token cost measurements
See LICENSE file (to be added)
- ElizaOS Framework
- OpenRouter API (for multi-model LLM testing)
For questions or issues:
- Check apps/docs/ for detailed documentation
- Review SpacetimeDB logs:
spacetime logs toonscape-server - Open an issue in the repository
- Join SpacetimeDB Discord for SpacetimeDB-specific questions
This is an experimental project for research and learning purposes. It is:
- Not affiliated with Jagex Ltd. or Old School RuneScape
- Not intended for production use - it's a proof-of-concept
- Not feature-complete - client and AI agents are not working yet
- MIT Licensed (to be added) - use at your own risk
OSRS game mechanics are used for educational purposes under fair use. All OSRS-related trademarks and copyrights belong to Jagex Ltd.
Last Updated: 2026-01-10