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.
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
Recommended Approach: Individual Files
Create a new .yaml file in spells/custom/
Use a descriptive filename: meteor.yaml, heal.yaml, etc.
Define your spell using the single-spell format
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
effects:
- type: "teleport"
teleport:
element_room: true # Teleport to element room
target_room: "123" # Specific room
random_room: true # Random room in range
room_range: [1, 100]
effects:
- type: "stat_mod"
stat_mod:
str: 5 # Increase strength by 5
dex: -2 # Decrease dexterity by 2
duration: 300 # Duration in seconds
success: "Your fireball engulfs %s in flames!"
failure_level: "You need spell level %d or higher. (Current: %d)"
restrictions:
combat_only: true # Can only cast during combat
non_combat_only: true # Cannot cast during combat
restrictions:
max_instances: 1 # Maximum active instances of this spell
restrictions:
required_rooms: ["1", "2", "3"] # Can only cast in these rooms
forbidden_rooms: ["10", "11"] # Cannot cast in these rooms