Elixir/OTP microservice for boss AI, behavior trees, and instance management in the RABBIT game.
Built on Elixir/OTP for superior AI state management:
- GenServer per boss instance - Each boss runs in isolated process
- Dynamic Supervisor - Fault-tolerant boss spawning/despawning
- Behavior Trees - Hierarchical AI decision making
- Process Registry - Fast boss instance lookup
- Pattern Matching - Clean condition evaluation
- BossDefinitions - Static boss data (stats, phases, abilities, loot)
- BossInstance (GenServer) - Individual boss state and AI execution
- BehaviorTree - Tree evaluation engine for AI decisions
- InstanceManager (GenServer) - Boss spawning and lifecycle
- BossRegistry - Boss definition cache and process registry
- Router (Plug) - HTTP API endpoints
- HP: 10,000
- Phases: 2
- Abilities: Heavy Strike, Protective Aura, Ground Slam, Summon Adds
- Required For: Super Bunny evolution
- HP: 50,000
- Phases: 3
- Abilities: Flame Breath, Flame Wave, Meteor Shower, Inferno Mode
- Required For: Flame Warren Knight evolution
- HP: 500,000
- Phases: 4
- Abilities: Cosmic Ray, Star Field, Gravity Well, Black Hole, Time Dilation, Cosmic Annihilation
- Drops: Cosmic Essence, Mirda Blessing, Evolution Unlocks
- HP: 10,000,000
- Phases: 5
- Abilities: Golden Judgment, Divine Cascade, Reality Fracture, Dimension Collapse, Omega Annihilation, Eternal Apocalypse
- Drops: Golden Essence, Omega Token, Mythic Gear Set, Godslayer Title
Bosses use hierarchical behavior trees for AI:
%BehaviorNode{
type: :selector, # Try children in priority order
children: [
# Priority 1: Use ultimate ability if available
%BehaviorNode{
type: :sequence,
condition: {:ability_ready, "ultimate"},
action: {:use_ability, "ultimate"}
},
# Priority 2: Attack if in range
%BehaviorNode{
type: :sequence,
condition: {:target_in_range, 5},
action: {:basic_attack}
},
# Priority 3: Chase target
%BehaviorNode{
type: :action,
action: {:move_toward_target}
}
]
}- Selector: Execute first succeeding child
- Sequence: Execute all children if condition met
- Action: Execute an action directly
{:ability_ready, ability_id}- Ability off cooldown{:hp_below, percent}- HP threshold check{:target_in_range, range}- Distance check{:enemies_in_range, range, count}- Multiple target check{:and, conditions}- All conditions must be true{:or, conditions}- Any condition must be true
GET /bosses # Get all boss definitions
GET /bosses/:boss_id # Get specific boss definition
GET /instances # List all active instances
POST /instances/spawn # Spawn new boss instance
GET /instances/:instance_id # Get instance state
DELETE /instances/:instance_id # Despawn instance
POST /instances/:instance_id/damage # Apply damage to boss
POST /instances/:instance_id/target # Set boss target
POST /instances/:instance_id/ability # Force ability use (testing)
Spawn Boss:
curl -X POST http://localhost:8005/instances/spawn \
-H "Content-Type: application/json" \
-d '{
"boss_id": "flame-titan",
"position": {"x": 100, "y": 50, "z": 200}
}'Response:
{
"instance_id": "a3f2c8d1-...",
"boss_id": "flame-titan",
"position": {"x": 100, "y": 50, "z": 200}
}Apply Damage:
curl -X POST http://localhost:8005/instances/a3f2c8d1-.../damage \
-H "Content-Type: application/json" \
-d '{
"amount": 5000,
"attacker_id": "player-123"
}'Response:
{
"current_hp": 45000,
"phase": 2
}Get Boss State:
curl http://localhost:8005/instances/a3f2c8d1-...Response:
{
"instance_id": "a3f2c8d1-...",
"boss_id": "flame-titan",
"name": "Flame Titan",
"current_hp": 45000,
"max_hp": 50000,
"hp_percent": 90,
"current_phase": 2,
"state": "combat",
"cooldowns": {
"flame-breath": 1234567890,
"meteor-shower": 1234567900
}
}- Spawning: InstanceManager creates new BossInstance GenServer under DynamicSupervisor
- AI Loop: Boss executes behavior tree every 100ms (10 ticks/second)
- Combat: Players apply damage, boss maintains aggro table
- Phase Transitions: HP thresholds trigger new phases with different abilities
- Death: Boss defeated → loot generated → process terminates gracefully
- Respawn: Timer triggers new spawn (handled by World Service)
- 10,000+ concurrent boss instances supported (one process per boss)
- 10 AI ticks/second per boss (100ms interval)
- Sub-millisecond behavior tree evaluation
- Microsecond condition checking via pattern matching
- Zero GC pauses thanks to BEAM VM
combat.damage-dealt- Updates boss HPplayer.died- Removes from aggro table
boss.spawned- New boss instance createdboss.phase-change- Boss entered new phaseboss.ability-used- Boss used ability (includes damage/effects)boss.defeated- Boss killed (includes loot)
- Elixir 1.14+
- Erlang/OTP 25+
mix deps.get
mix compilemix run --no-halt
# or with custom port
PORT=8005 mix run --no-haltmix test# Start service
mix run --no-halt
# In another terminal
curl -X POST http://localhost:8005/instances/spawn \
-H "Content-Type: application/json" \
-d '{"boss_id": "warren-guardian"}'docker build -t rabbit-boss-service .
docker run -p 8005:8005 rabbit-boss-servicePORT- HTTP server port (default: 8005)REDIS_URL- Redis connection for state persistenceCOMBAT_SERVICE_URL- Combat Service endpoint for damage calculations
Bosses use behavior trees instead of state machines for flexibility:
State Machine Problems:
- Rigid state transitions
- Difficult to add new behaviors
- Hard to prioritize actions
Behavior Tree Benefits:
- Hierarchical decision making
- Easy to add new nodes
- Natural priority system
- Reusable subtrees
- Clean condition composition
- Behavior Tree Editor - Visual tool for designing boss AI
- Machine Learning - Adaptive boss behavior based on player patterns
- Scripting Support - Lua/Elixir scripts for custom boss logic
- Networked AI - Bosses coordinate with each other
- Player AI - Use same system for NPC allies
Proprietary - RABBIT Game