VESTRA CODAThe Codex
vestracoda.com ↗

Creature AI

Every creature thinks with one of 7 behaviour trees. A tree is checked from the top each tick: a selector tries its children until one succeeds, a sequence runs them in order until one fails, conditions test the world and actions do something.

Boss Phased

53 creatures

Multi-phase boss AI. Features: 1. Phase transitions based on HP/time/mechanics 2. Phase-specific ability pools 3. Transition invulnerability and animations 4. Add spawning during transitions 5. Mechanic execution

Designer's notes

Complex boss behavior tree supporting industry-standard features:

Phase System: - Phases defined in creature's phases.phase_list - Each phase can enable/disable abilities - Stat modifiers apply per phase - Transitions can be invulnerable

Mechanics: - Referenced from creature's mechanics array - Can be phase-specific or always active - Execute with priority over normal abilities

Threat: - Uses threat table for target selection - Players generate threat through damage/healing - Tank classes have threat-generating abilities

Add Management: - Adds spawned during transitions - Can trigger phase transitions when killed - Inherit boss threat table initially

Enrage: - Optional hard timer - When reached, boss deals massively increased damage - Intended as DPS check

Tunable per creature
ParameterMeaningDefault
enrage_damage_multiplierDamage multiplier when enraged5
enrage_timerTime until enrage (0 = no enrage)0 seconds
leash_rangeBosses have larger leash range100 meters
reset_delayTime without threat before reset5 seconds
The tree
  • selectorSelector
    • sequenceDeath Handler
      • conditionself.hp <= 0
      • condition!is_in_transition
      • actionBoss Deathannounce kill true · drop loot true · play death animation true
    • sequencePhase Transition
      • conditionshould_transition_phase
      • actionBegin Phase Transitionset invulnerable current_phase.transition.invulnerable
      • sequenceTransition Sequence
        • actionPlay Animationanimation current_phase.transition.animation
        • actionBoss Dialoguetext current_phase.transition.dialogue
        • actionSpawn Transition Adds
        • actionWaitduration current_phase.transition.duration
      • actionComplete Phase Transition
    • sequenceIn Transition
      • conditionis_in_transition
      • actionWaitduration 0.1
    • sequenceMechanic Execution
      • conditionhas_active_mechanic
      • actionExecute Mechanic
    • sequenceBoss Combat
      • conditionhas_valid_target
      • actionApply Phase Modifiers
      • selectorCombat Actions
        • sequencePhase Mechanics
          • conditionshould_trigger_mechanic
          • actionTrigger Mechanic
        • sequenceConditional Ability
          • conditionhas_ready_conditional_ability_for_phase
          • actionUse Conditional Ability
        • sequencePhase Attack
          • conditiondistance_to_target <= self.attack_range
          • actionUse Phase Ability
        • sequenceChase
          • conditiondistance_to_target > self.attack_range
          • actionMove To Target
    • sequenceAcquire Target
      • condition!has_valid_target
      • conditionthreat_table_not_empty
      • actionSet Target Highest Threat
    • sequenceReset No Threat
      • conditionthreat_table_empty
      • conditiontime_since_combat > 5.0
      • actionReset Bossheal to full true · reset phase true
    • actionBoss Idle
Creatures using it
Id boss_phased · version 1

Melee Aggressive

128 creatures

Standard aggressive melee AI. Creature will: 1. Detect enemies within aggro range 2. Call for help (if enabled) 3. Chase target to melee range 4. Select and use abilities based on weights/conditions 5. Reset if target escapes leash range

Designer's notes

This is the default behavior tree for aggressive melee creatures.

Ability Selection: - Conditional abilities (from ability_conditions) are checked first - If no conditional ability is ready, weighted random selection is used - Weights are defined in creature's ai.ability_weights

Call for Help: - If enabled, alerts creatures with same venery_category within help_range - Alerted creatures will switch to attacking the same target

Leash System: - If creature moves too far from spawn, it resets - Reset heals to full and clears all threat

Tunable per creature
ParameterMeaningDefault
aggro_on_sightWhether to aggro on sight or wait for attackyes
call_for_helpWhether to alert nearby allies when entering combatno
flee_at_hp_percentHP percentage to flee at (0 = never flee)0
help_rangeRange for call for help15 meters
The tree
  • selectorSelector
    • sequenceDeath Handler
      • conditionself.hp <= 0
      • actionDie
    • sequenceLeash Handler
      • conditiondistance_to_spawn > self.leash_range
      • actionReset To Spawnclear threat true · heal to full true
    • sequenceCombat Sequence
      • conditionhas_valid_target
      • selectorCombat Actions
        • sequenceConditional Ability
          • conditionhas_ready_conditional_ability
          • actionUse Conditional Ability
        • sequenceIn Range Attack
          • conditiondistance_to_target <= self.attack_range
          • actionUse Weighted Ability
        • sequenceChase Target
          • conditiondistance_to_target > self.attack_range
          • actionMove To Targetstop distance self.attack_range * 0.8
    • sequenceAcquire Target
      • condition!has_valid_target
      • conditionenemy_in_range(self.aggro_range)
      • selectorSelector
        • sequenceCall For Help
          • conditionself.call_for_help == true
          • actionAlert Nearby Alliesrange self.help_range
        • actionNoop
      • actionSet Target Nearest Enemy
    • selectorIdle Behavior
      • sequencePatrol
        • conditionself.patrol.type != 'stationary'
        • actionPatrol
      • actionIdle
Creatures using it
Id melee_aggressive · version 1

Passive Flee

1 creatures

Never fights. Flees anything that damages it and forgets it once 35 m clear; roams inside its wander radius when idle.

The tree
  • selectorSelector
    • sequenceDeath Handler
      • conditionself.hp <= 0
      • actionDie
    • sequenceLeash Handler
      • conditiondistance_to_spawn > self.leash_range
      • actionReset To Spawnclear threat true · heal to full true
    • sequenceFlee
      • conditionhas_valid_target
      • selectorSelector
        • sequenceFlee Done
          • conditiondistance_to_target > 35
          • actionDrop Threat
        • actionFlee
    • selectorIdle Behavior
      • sequencePatrol
        • conditionself.patrol.type != 'stationary'
        • actionPatrol
      • actionIdle
Creatures using it
Id passive_flee · version 1

Passive Until Attacked

29 creatures

Prey / neutral animal AI. Never aggros on sight; fights back when struck, flees when its HP drops to the authored flee threshold, roams when idle.

Tunable per creature
ParameterMeaningDefault
flee_at_hp_percentHP percent at or below which the creature flees instead of fighting (0 = never)0 percent
The tree
  • selectorSelector
    • sequenceDeath Handler
      • conditionself.hp <= 0
      • actionDie
    • sequenceLeash Handler
      • conditiondistance_to_spawn > self.leash_range
      • actionReset To Spawnclear threat true · heal to full true
    • sequenceFlee When Hurt
      • conditionhas_valid_target
      • conditionself.hp <= self.flee_at_hp_percent
      • selectorSelector
        • sequenceFlee Done
          • conditiondistance_to_target > 35
          • actionDrop Threat
        • actionFlee
    • sequenceFight Back
      • conditionhas_valid_target
      • selectorCombat Actions
        • sequenceIn Range Attack
          • conditiondistance_to_target <= self.attack_range
          • actionUse Weighted Ability
        • sequenceChase Target
          • conditiondistance_to_target > self.attack_range
          • actionMove To Targetstop distance self.attack_range * 0.8
    • selectorIdle Behavior
      • sequencePatrol
        • conditionself.patrol.type != 'stationary'
        • actionPatrol
      • actionIdle
Creatures using it
Id passive_until_attacked · version 1

Ranged Kite

17 creatures

Ranged AI that maintains distance. Creature will: 1. Detect enemies within aggro range 2. Move to optimal attack range 3. Attack from range 4. Kite away if enemies get too close 5. Flee if HP is low (if configured)

Designer's notes

Ranged kiting behavior for archers, mages, etc.

Range Management: - min_range: Too close, will kite away - optimal_range: Preferred distance, will position here - attack_range: Maximum attack distance

Kiting: - When target is closer than min_range, moves away - Maintains line of sight while moving - Can attack while moving (if animation supports)

Flee Behavior: - If flee_at_hp_percent > 0, will flee when HP drops - Fleeing creatures ignore leash and run until safe

Tunable per creature
ParameterMeaningDefault
aggro_on_sight—yes
flee_at_hp_percentHP percentage to flee at (0 = never flee)20
kite_speed_multiplierSpeed multiplier when kiting1
min_rangeMinimum comfortable distance from target8 meters
optimal_rangePreferred attack distance12 meters
The tree
  • selectorSelector
    • sequenceDeath Handler
      • conditionself.hp <= 0
      • actionDie
    • sequenceLeash Handler
      • conditiondistance_to_spawn > self.leash_range
      • actionReset To Spawnclear threat true · heal to full true
    • sequenceFlee Behavior
      • conditionself.flee_at_hp_percent > 0
      • conditionself.hp_percent <= self.flee_at_hp_percent
      • actionFlee From Targetflee distance 20
    • sequenceCombat Sequence
      • conditionhas_valid_target
      • selectorRanged Combat
        • sequenceKite Away
          • conditiondistance_to_target < self.min_range
          • actionMove Away From Targettarget distance self.optimal_range
        • sequenceAttack At Range
          • conditiondistance_to_target >= self.min_range
          • conditiondistance_to_target <= self.attack_range
          • selectorSelector
            • sequenceSequence
              • conditionhas_ready_conditional_ability
              • actionUse Conditional Ability
            • actionUse Weighted Ability
        • sequenceApproach Target
          • conditiondistance_to_target > self.attack_range
          • actionMove To Targetstop distance self.optimal_range
    • sequenceAcquire Target
      • condition!has_valid_target
      • conditionenemy_in_range(self.aggro_range)
      • actionSet Target Nearest Enemy
    • selectorIdle Behavior
      • sequencePatrol
        • conditionself.patrol.type != 'stationary'
        • actionPatrol
      • actionIdle
Creatures using it
Id ranged_kite · version 1

Stationary Passive

2 creatures

Completely passive, non-mobile AI. Used for: - Training dummies - Target practice - Environmental creatures

Designer's notes

Minimal behavior tree for training targets.

Features: - Never moves - Never attacks - Never dies (infinite HP or respawns instantly) - Optionally heals back to full after combat - Can display DPS tracking for practice

Use Cases: - Combat training dummies in guild halls - Practice targets at combat academies - DPS testing

Tunable per creature
ParameterMeaningDefault
auto_healWhether to heal back to full after not being hityes
heal_delayTime after last hit before healing5 seconds
show_damage_numbersWhether to display damage numbersyes
track_dpsWhether to track and display DPSyes
The tree
  • selectorSelector
    • sequenceHp Reset
      • conditionself.auto_heal == true
      • conditiontime_since_damaged > self.heal_delay
      • actionHeal To Full
    • actionIdleplay ambient true
Creatures using it
Id stationary_passive · version 1

Stationary Reactive

8 creatures

Stationary practice target that fights back. The creature will: 1. Never aggro on sight — activation comes from being damaged 2. Attack back with weighted abilities while the target is in range 3. Never move or chase 4. Deactivate via ai.disengage_after_secs once left alone

Designer's notes

Designed for the training dummies (melee, slam, breath, archer, mage, sparbot). Pair with: ai: behavior_tree: stationary_reactive disengage_after_secs: 10.0 patrol: { type: stationary } Deactivation is NOT in this tree — the AI system clears threat entries whose time_since_action exceeds disengage_after_secs, and the existing threat-empty check exits combat.

The tree
  • selectorSelector
    • sequenceDeath Handler
      • conditionself.hp <= 0
      • actionDie
    • sequenceCombat Sequence
      • conditionhas_valid_target
      • selectorCombat Actions
        • sequenceConditional Ability
          • conditionhas_ready_conditional_ability
          • actionUse Conditional Ability
        • sequenceIn Range Attack
          • conditiondistance_to_target <= self.attack_range
          • actionUse Weighted Ability
        • actionIdle
    • actionIdleplay ambient true
Creatures using it
Id stationary_reactive · version 1