Thanks to visit codestin.com
Credit goes to github.com

Skip to content

RABBIT Boss Service - AI and behavior trees in Elixir/OTP

Notifications You must be signed in to change notification settings

toddllm/rabbit-boss-service

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Boss Service

Elixir/OTP microservice for boss AI, behavior trees, and instance management in the RABBIT game.

Architecture

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

Core Components

  1. BossDefinitions - Static boss data (stats, phases, abilities, loot)
  2. BossInstance (GenServer) - Individual boss state and AI execution
  3. BehaviorTree - Tree evaluation engine for AI decisions
  4. InstanceManager (GenServer) - Boss spawning and lifecycle
  5. BossRegistry - Boss definition cache and process registry
  6. Router (Plug) - HTTP API endpoints

Boss Definitions

Tier 4: Warren Guardian

  • HP: 10,000
  • Phases: 2
  • Abilities: Heavy Strike, Protective Aura, Ground Slam, Summon Adds
  • Required For: Super Bunny evolution

Tier 6: Flame Titan

  • HP: 50,000
  • Phases: 3
  • Abilities: Flame Breath, Flame Wave, Meteor Shower, Inferno Mode
  • Required For: Flame Warren Knight evolution

Tier 7: Mirda (Cosmic Goddess)

  • 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

Tier 10: Golden Mirda (OMEGA)

  • 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

Behavior Trees

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}
    }
  ]
}

Node Types

  • Selector: Execute first succeeding child
  • Sequence: Execute all children if condition met
  • Action: Execute an action directly

Condition Types

  • {: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

API Endpoints

Boss Definitions

GET /bosses                    # Get all boss definitions
GET /bosses/:boss_id          # Get specific boss definition

Boss Instances

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

Combat

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)

Request/Response Examples

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
  }
}

Boss Instance Lifecycle

  1. Spawning: InstanceManager creates new BossInstance GenServer under DynamicSupervisor
  2. AI Loop: Boss executes behavior tree every 100ms (10 ticks/second)
  3. Combat: Players apply damage, boss maintains aggro table
  4. Phase Transitions: HP thresholds trigger new phases with different abilities
  5. Death: Boss defeated → loot generated → process terminates gracefully
  6. Respawn: Timer triggers new spawn (handled by World Service)

Performance

  • 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

Integration

Subscribes to Events:

  • combat.damage-dealt - Updates boss HP
  • player.died - Removes from aggro table

Publishes Events:

  • boss.spawned - New boss instance created
  • boss.phase-change - Boss entered new phase
  • boss.ability-used - Boss used ability (includes damage/effects)
  • boss.defeated - Boss killed (includes loot)

Development

Prerequisites

  • Elixir 1.14+
  • Erlang/OTP 25+

Setup

mix deps.get
mix compile

Run

mix run --no-halt
# or with custom port
PORT=8005 mix run --no-halt

Test

mix test

Spawn Test Boss

# 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"}'

Production Deployment

Docker

docker build -t rabbit-boss-service .
docker run -p 8005:8005 rabbit-boss-service

Environment Variables

  • PORT - HTTP server port (default: 8005)
  • REDIS_URL - Redis connection for state persistence
  • COMBAT_SERVICE_URL - Combat Service endpoint for damage calculations

AI Design Philosophy

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

Future Enhancements

  • 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

License

Proprietary - RABBIT Game

About

RABBIT Boss Service - AI and behavior trees in Elixir/OTP

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published