OpenRoads Spell System

The OpenRoads spell system is a comprehensive, flexible magic system that allows content creators to design spells using YAML and JSON configuration files without writing Go code. The system supports everything from simple damage spells to complex multi-effect magical abilities.

๐Ÿš€ Quick Navigation

๐ŸŽฏ System Overview

The OpenRoads spell system is built around three core principles:

  1. Accessibility - Content creators can add spells without programming knowledge

  2. Flexibility - Support for simple and complex spell behaviors

  3. Performance - Efficient loading and execution of spells

๐Ÿ—๏ธ Architecture Components

  • ๐Ÿ“ Custom Spell Files (spells/custom/*.yaml) - Individual spell files (recommended approach)

  • ๐Ÿ“„ YAML Configuration (world/spells.yaml) - Legacy bulk spell definitions

  • โš™๏ธ JSON Configuration (world/spells.json) - Hardcoded spells and overrides

  • โšก Effect System - Modular spell effects (damage, heal, summon, teleport, stat modification)

  • โฑ๏ธ Cooldown System - Per-player, per-spell cooldown tracking

  • ๐Ÿ• Cast Time System - Spells with casting delays and interruption support

  • โœ… Validation System - Element, level, resource, and target requirements

  • ๐Ÿ’ฌ Message System - Customizable feedback for all spell interactions

  • ๐Ÿšซ Restriction System - Combat, location, and instance limitations

File Structure

Each spell in its own file:

Legacy YAML Spells (world/spells.yaml)

Bulk spell definitions (still supported):

JSON Spells (world/spells.json)

File Loading Order

The spell system loads files in this order:

  1. Main YAML file (world/spells.yaml) - Legacy bulk definitions

  2. Custom YAML files (spells/custom/*.yaml) - Individual spell files (loaded alphabetically)

  3. JSON files (world/spells.json) - Hardcoded spells and overrides

Later files can override earlier ones if they use the same spell name.

Creating Custom Spells

  1. Create a new .yaml file in spells/custom/

  2. Use a descriptive filename: meteor.yaml, heal.yaml, etc.

  3. Define your spell using the single-spell format

  4. Test in-game with the spells command

Example: Creating a New Spell

Create spells/custom/frost_bolt.yaml:

Benefits of Individual Files

  • Easy Management: Each spell is self-contained

  • Version Control: Better Git diffs and merge conflict resolution

  • Collaboration: Multiple people can work on different spells

  • Organization: Easy to find and edit specific spells

  • Hot Reloading: Easier to reload individual spells (future feature)

Spell Properties

Basic Properties

  • name: Display name of the spell

  • description: Detailed description

  • element_required: Required element (fire, water, air, earth, or empty for any)

  • min_spell_level: Minimum spell level required

  • min_phys_level: Minimum physical level required

  • sp_cost: Spell point cost

  • cast_time: Casting time in seconds (0 for instant)

  • cooldown: Cooldown time in seconds

  • target_type: Type of target required

Target Types

  • self: Targets the caster

  • enemy: Requires an enemy target

  • player: Requires a player target

  • room: Requires a room ID

  • none: No target required

Required Items

List of item names that must be in the caster's inventory:

Effect Types

Damage Effects

Healing Effects

Summoning Effects

Teleportation Effects

Stat Modification Effects

Messages

Standard Messages

  • success: Successful cast message

  • miss: Failed effect message

  • failure_element: Wrong element message

  • failure_level: Insufficient level message

  • failure_sp: Insufficient spell points message

  • failure_items: Missing required items message

  • failure_cooldown: Spell on cooldown message

  • failure_target: Invalid/missing target message

Cast Time Messages

  • cast_start: Message when casting begins

  • cast_complete: Message when casting completes

  • cast_interrupt: Message when casting is interrupted

Broadcast Messages

  • broadcast_effect: Message sent to other players in room

Message Formatting

Messages support %s placeholders for targets and %d for numbers:

Restrictions

Combat Restrictions

Instance Restrictions

Location Restrictions

Hardcoded Spells

For complex spells that require custom logic, use the JSON format with a custom_handler:

The handler function must be implemented in spell_engine.go in the handleCustomSpell function.

Commands

Player Commands

  • cast - Show available spells

  • cast <spell> - Cast a spell (if no target required)

  • cast <spell> <target> - Cast a spell with target

  • spells - Show detailed spell information

Admin Commands

Debug spells are available in spells.json for testing:

  • debug_heal - Full heal

  • debug_damage <enemy> - High damage

  • debug_teleport <room> - Instant teleport

  • debug_summon <room> - Summon debug creature

Examples

Simple Damage Spell

Healing Spell with Cast Time

Teleport Spell with Requirements

๐Ÿ”„ Hot Reloading

Spells can be reloaded without restarting the server by calling ReloadSpells() from the admin interface or by restarting the spell loading process. This feature is planned for future implementation.

๐Ÿ”— System Integration

The spell system seamlessly integrates with all major game systems:

Core Game Systems

  • ๐Ÿ‘ค Player System: Level and element validation, stat modifications

  • ๐ŸŽ’ Inventory System: Required item checking and consumption

  • โš”๏ธ Combat System: Damage dealing, healing effects, combat state tracking

  • ๐ŸŒ World System: Room targeting, teleportation, location restrictions

  • ๐Ÿ‘น Enemy System: Enemy targeting, health management, summoning

Advanced Integrations

  • ๐Ÿƒ Routine Engine: Background spell processing, cooldown management

  • ๐Ÿ’พ Save System: Persistent spell cooldowns and effects

  • ๐Ÿ“Š Statistics: Spell usage tracking and analytics

  • ๐Ÿ” Permission System: Admin spell access control

  • ๐Ÿ“ Logging System: Comprehensive spell event logging

๐Ÿ“š Complete Documentation Suite

๐ŸŽฏ Getting Started

๐Ÿ“– Reference Documentation

๐ŸŽฎ Content Creation

๐ŸŽ‰ Success Stories

The spell system has successfully enabled:

  • 19+ Spells: Currently loaded and functional

  • 8 Custom Files: Individual YAML spell files

  • Multiple Effect Types: Damage, healing, teleportation, summoning, stat modification

  • Zero Downtime: Hot-reloadable spell definitions

  • Easy Maintenance: Non-programmers can create and modify spells

Last updated

Was this helpful?