
¶ Enchanter — Doppelgangers

¶ Enchanter Doppelganger AI Behavior
¶ Overview
The Enchanter’s Doppelganger is an AI-controlled pet that automatically casts spells using the Enchanter’s memorized spells. The Doppelganger operates intelligently, prioritizing healing and support for the group while efficiently managing harmful spells on enemies.
¶ Core Behavior
¶ Spell Casting Priority System
The Doppelganger follows a strict priority system when selecting spells to cast:
Beneficial Spells (Priority Order):
- Heal Over Time (HoT) spells - Highest priority
- Direct healing spells - Second priority
- Protective runes - Third priority
- Other beneficial spells - Lowest priority
Harmful Spells (Priority Order):
- Resistance debuffs - Highest priority
- Other debuffs - Second priority
- Damage over Time (DOT) spells - Third priority
- Direct damage spells - Fourth priority
¶ Healing Behavior
¶ Target Selection
The Doppelganger will attempt to heal the following targets in order:
- The Enchanter (owner)
- Group members
- All pets (owner’s pets and group members’ pets)
¶ Healing Logic
- Critical Healing (Below 50% HP): Prioritizes direct heal spells
- Regular Healing (50–75% HP): Uses Heal over Time spells
- No Healing (Above 75% HP): Will not cast healing spells
¶ Smart Healing Features
- Spell Interruption: Will interrupt current healing spell if:
- Direct heal being cast and target’s HP rises above 75%
- HoT being cast and target’s HP drops below 40% (switches to direct healing)
- Swarm Coordination: Multiple Doppelgangers will not cast the same type of healing spell on the same target simultaneously
- Buff Stacking: Checks existing buffs to avoid overwriting or redundant casting
¶ Combat Behavior
¶ Harmful Spell Casting
- Casts debuffs and damage spells on the Enchanter’s current target
- DOT Spreading: Will cast DOT spells on additional enemies that are aggressive toward the owner
- Stackable DOTs: Multiple Doppelgangers can apply the same DOT spell to the same target
- Non-stackable Debuffs: Only one instance per target regardless of caster
¶ Spell Cooldown Management
- Respects individual spell recast timers
- Manages global cooldown periods between spell casts
- Tracks cooldowns per spell to optimize casting rotation
¶ Positioning System
¶ Swarm Coordination
When multiple Doppelgangers are active:
- Equidistant Positioning: Automatically positions around the target in a circle
- Consistent Formation: Uses sorted NPC IDs to ensure stable positioning
¶ Movement Behavior
- Uses advanced pathing when available
- Falls back to basic movement if advanced pathing is unavailable
- Adjusts Z-coordinate to match target height when possible
¶ Advanced Features
¶ Multi-Target DOT Casting
- Identifies enemies aggressive toward the owner
- Applies DOT spells to multiple targets beyond the primary target
- Optimizes damage output across multiple enemies
¶ Spell Interruption System
- Continuously monitors casting progress every 1 second
- Makes intelligent decisions about when to interrupt spells based on changing conditions
- Prevents wasted mana on unnecessary heals
¶ Swarm Intelligence
- Communicates casting intentions between Doppelganger instances
- Prevents duplicate beneficial spell casting
- Allows coordinated harmful spell application
¶ Limitations
¶ Spell Access
- Only uses spells currently memorized by the Enchanter
- Cannot cast spells the Enchanter doesn't have access to
- Respects the Enchanter's mana limitations (spell failure will occur if insufficient mana)
¶ Target Restrictions
- Will not cast spells on itself (the Doppelganger NPC)
- Cannot heal or buff enemies
- Limited to line-of-sight and spell range restrictions
¶ Coordination Limits
- Coordination only works between Doppelgangers of the same type and owner
- Cannot coordinate with other types of pets or AI entities
¶ Spell Selection Process
- Gets all memorized spells from the Enchanter using
$owner->GetMemmedSpells()
- Separates spells by type (beneficial vs harmful)
- Sorts each type by priority using custom priority functions
- Casts the highest priority available spell that meets the current situation
¶ Priority System Used
Beneficial Spells Priority:
- Heal Over Time spells (priority 1)
- Direct heal spells (priority 2)
- Rune spells (priority 3)
- Other beneficial spells (priority 99)
Harmful Spells Priority:
- Resistance debuffs (priority 1)
- Other debuffs (priority 2)
- Stackable DOTs (priority 3)
- Direct damage spells (priority 4)
Level-Based Sub-Priority:
Within each category, higher level spells get slightly better priority using this formula:
final_priority = base_priority - (spell_level / 1000)
¶ Example Scenario
If an Enchanter has these spells memorized in gems 1–8:
- Gem 1: Lightning Bolt (direct damage)
- Gem 2: Greater Heal (direct heal)
- Gem 3: Charm (other)
- Gem 4: Regeneration (HoT)
- Gem 5: Slow (debuff)
- Gem 6: Malaise (resist debuff)
- Gem 7: Poison DOT (DOT)
- Gem 8: Rune (protective)
The AI would prioritize them as:
- Malaise (resist debuff - priority 1)
- Slow (debuff - priority 2)
- Poison DOT (DOT - priority 3)
- Lightning Bolt (direct damage - priority 4)
- Regeneration (HoT - priority 1 for beneficial)
- Greater Heal (direct heal - priority 2 for beneficial)
- Rune (rune - priority 3 for beneficial)
- Charm (other - priority 99 for beneficial)
So spell gem position is completely ignored – the AI makes intelligent decisions based on spell type and effectiveness rather than the arbitrary order the player memorized them.