# 58 — BP_EnemyBase

## Blueprint Spec — UE 5.5–5.7

---

### Parent Class
`Character`

### Dependencies
- [`BPC_AIControllerBase`](55_BPC_AIControllerBase.md) — AI brain
- [`BPC_HealthComponent`](../02-player/08_BPC_HealthComponent.md) — Health & damage
- [`BPC_StaminaComponent`](../02-player/09_BPC_StaminaComponent.md) — Sprint/action energy
- [`BPC_DamageHandlerComponent`](../08-weapons/53_BPC_DamageHandlerComponent.md) — Damage reception
- [`I_Damageable`](../01-core/03_I_Damageable.md) — Interface
- [`I_Persistable`](../05-save/29_I_Persistable.md) — Save state
- [`DA_AIProfile`](../12-content/63_DA_AIProfileDataAsset.md) — Configuration
- [`BP_PatrolPath`](59_BP_PatrolPath.md) — Waypoint navigation

### Purpose
Base enemy character blueprint. Provides movement, animation, damage reaction, ragdoll, and interaction with the AI controller system. Designed to be extended for specific enemy types (humanoid, creature, drone). All AI logic is in the controller; the pawn provides physical representation and animation state.

### Variables

| Name | Type | Description |
|------|------|-------------|
| `AIProfile` | DA_AIProfile | Enemy configuration asset |
| `HealthComponent` | BPC_HealthComponent | Health pool |
| `StaminaComponent` | BPC_StaminaComponent | Stamina for actions |
| `PatrolPathRef` | BP_PatrolPath | Assigned patrol route |
| `SkeletalMesh` | USkeletalMeshComponent | Visual mesh |
| `AnimationBP` | UAnimInstance | Animation blueprint instance |
| `WeakSpotComponents` | Array<UChildActorComponent> | Weak point references |
| `bIsStaggered` | Bool | Hit reaction state |
| `bIsRagdoll` | Bool | Death ragdoll state |
| `RagdollLifetime` | Float | Seconds before ragdoll cleanup |
| `LootTable` | TArray<FLootEntry> | Dropped items on death |
| `AlertColor` | FLinearColor | VFX color matching alert level |
| `FootstepSounds` | TMap<UPhysicalMaterial, USoundBase> | Surface-based footsteps |
| `EnemyTypeTag` | FGameplayTag | e.g. Tag.Enemy.Humanoid |

### Structs

| Struct | Fields | Description |
|--------|--------|-------------|
| `FLootEntry` | ItemTag: FGameplayTag, DropChance: Float, MinCount: Int, MaxCount: Int | Loot definition |
| `FWeakSpot` | BoneName: FName, DamageMultiplier: Float, bDestroyed: Bool, HitVFX: UParticleSystem | Weak point data |

### Functions

| Name | Inputs | Outputs | Description |
|------|--------|---------|-------------|
| `InitializeEnemy` | Profile: DA_AIProfile | — | Set stats, components, attachment |
| `OnTakeDamage` | DamageResult: FDamageResult | — | React to damage (stagger, VFX) |
| `OnDeath` | — | — | Play death anim or ragdoll |
| `StartRagdoll` | HitLocation: FVector, Impulse: FVector | — | Physics death |
| `EndRagdoll` | — | — | Cleanup and destroy |
| `SpawnLoot` | — | — | Drop items at death location |
| `GetWeakSpotMultiplier` | BoneName: FName | Float | Return damage multiplier |
| `SetEnemyState` | NewState: EAIState | — | Update animation state |
| `PlayFootstep` | Surface: UPhysicalMaterial | — | Footstep sound |
| `GetEyeLocation` | — | FVector | Perception reference point |
| `CanBeStaggered` | — | Bool | Stagger immunity check |
| `PlayStaggerAnimation` | — | — | Hit reaction montage |
| `OnStaggerEnd` | — | — | Return to normal state |
| `SetVisibilityBasedAnimTickOption` | Option: EVisibilityBasedAnimTickOption | — | Performance culling |

### Enums

| Enum | Values | Description |
|------|--------|-------------|
| `EEnemyArchetype` | Humanoid, Creature, Drone, Turret, Boss | Enemy structural type |
| `EHitReactionType` | None, Flinch, Stagger, Knockback, Launch | Reaction severity |

### Blueprint Flow

```
[OnTakeDamage]
  └─► ApplyDamage to HealthComponent
  └─► If HealthComponent.Health <= 0 → OnDeath
  └─► Else:
         HitReaction = DetermineReaction(DamageResult)
         If HitReaction >= Stagger && CanBeStaggered:
             bIsStaggered = true
             PlayStaggerAnimation(DamageResult.HitDirection)
         SpawnHitVFX(DamageResult.HitLocation)
         Notify AIController of damage via dispatcher

[OnDeath]
  └─► Set AIState = Disabled on controller
  └─► Stop all AI logic
  └─► If AIProfile.bUseRagdoll:
         StartRagdoll(DamageResult.HitLocation, DamageResult.Impulse)
         SetLifeSpan(RagdollLifetime)
  └─► Else:
         PlayDeathAnimation()
         SetLifeSpan(DeathAnimTime)
  └─► SpawnLoot()
  └─► Broadcast OnEnemyKilled
  └─► Unregister from AlertSystem

[SpawnLoot]
  └─► For each FLootEntry:
         If Random < DropChance:
             Count = RandomRange(MinCount, MaxCount)
             Spawn pickup actor with ItemTag and Count
```

### Animation State Mapping

| EAIState | Animation State | Notes |
|----------|----------------|-------|
| Idle | Idle | Standing, breathing |
| Patrol | Walk | Speed from profile |
| Suspicious | Walk (slower) | Looking around |
| Alerted | Walk (fast) | Ready stance |
| Combat | Run / Jog | Sprint toward target |
| Searching | Walk (scanning) | Head-turning |
| Fleeing | Sprint | Panic movement |
| Disabled | Stagger / Stun | Hit reaction or downed |

### Communications With

| Target | Method | Why |
|--------|--------|-----|
| [`BPC_AIControllerBase`](55_BPC_AIControllerBase.md) | Possessing controller | AI state and behavior |
| [`BPC_HealthComponent`](../02-player/08_BPC_HealthComponent.md) | Get Component | Health modify and death |
| [`BPC_DamageHandlerComponent`](../08-weapons/53_BPC_DamageHandlerComponent.md) | Get Component | Process incoming damage |
| [`BPC_CombatFeedbackComponent`](../08-weapons/54_BPC_CombatFeedbackComponent.md) | Get Component | Blood, hit FX |
| Animation Blueprint | Direct | State machine query |
| [`BP_PatrolPath`](59_BP_PatrolPath.md) | Direct | Waypoint navigation |
| World Spawning System | Direct | Loot spawning |

### Reuse Notes
- Subclass for different enemy visuals, hitbox setups, and animation sets
- Weak spots defined per blueprint (head, back weak point, glowing core)
- Loot table data-driven: design new enemies by swapping DA_AIProfile
- Ragdoll vs death animation toggle per enemy type
- AnimBP queries AIState for state-driven animation