# BPC_HealthSystem — Asset Implementation

> **UE5 Asset:** `/Game/Framework/Player/BPC_HealthSystem`
> **Parent Class:** `ActorComponent`
> **Attach To:** Player pawn + Enemy pawns

---

## Create This Asset

1. Content Browser → `Content/Framework/Player/`
2. Right-click → **Blueprint Class** → Parent: `ActorComponent`
3. Name: `BPC_HealthSystem`

---

## Variables to Add

| Variable | Type | Default | Category |
|----------|------|---------|----------|
| `MaxHealth` | `Float` | `100.0` | Config |
| `CurrentHealth` | `Float` | `100.0` | State |
| `bIsDead` | `Boolean` | `false` | State |
| `DamageResistance` | `Float` | `0.0` | Config |
| `bCanHeal` | `Boolean` | `true` | Config |
| `HealthRegenRate` | `Float` | `0.0` | Config |
| `HealthRegenDelay` | `Float` | `5.0` | Config |
| `LastDamageTime` | `Float` | `0.0` | State |

---

## What to Wire

### Override: BeginPlay
```
[Event BeginPlay]
  ├─ Set CurrentHealth = MaxHealth
  └─ Enable Tick (if regen > 0)
```

### Function: ApplyDamage
```
Input: DamageAmount(Float), DamageCauser(AActor), DamageType(GameplayTag)

[BlueprintCallable]
  ├─ Branch: bIsDead? → True: Return 0
  ├─ Calculate: EffectiveDamage = DamageAmount * (1.0 - DamageResistance)
  ├─ Set CurrentHealth = FMax(CurrentHealth - EffectiveDamage, 0)
  ├─ Set LastDamageTime = GetGameTimeInSeconds
  ├─ Call OnHealthChanged(CurrentHealth, MaxHealth, -EffectiveDamage)
  ├─ Branch: CurrentHealth <= 0?
  │   True → Set bIsDead = true → Call OnDeath(DamageCauser)
  └─ Return EffectiveDamage
```

### Function: Heal
```
Input: HealAmount(Float)

[BlueprintCallable]
  ├─ Branch: bIsDead? → True: Return 0
  ├─ Branch: Not bCanHeal? → True: Return 0
  ├─ Calculate: ActualHeal = FMin(HealAmount, MaxHealth - CurrentHealth)
  ├─ Set CurrentHealth += ActualHeal
  ├─ Call OnHealthChanged(CurrentHealth, MaxHealth, ActualHeal)
  └─ Return ActualHeal
```

### Override: Tick
```
[Event Tick]
  ├─ Branch: bIsDead OR HealthRegenRate <= 0 → Return
  ├─ Branch: (GameTime - LastDamageTime) < HealthRegenDelay → Return
  ├─ Heal(HealthRegenRate * DeltaSeconds)
```

### Event Dispatchers to Create
| Dispatcher | Parameters |
|------------|-----------|
| `OnHealthChanged` | `Current` (Float), `Max` (Float), `Delta` (Float) |
| `OnDeath` | `Killer` (AActor) |
| `OnHealed` | `Amount` (Float), `Healer` (AActor) |
| `OnDamageReceived` | `Amount` (Float), `Causer` (AActor), `Type` (GameplayTag) |

---

## Attach to Pawn
1. Open player pawn Blueprint
2. **Add Component → BPC_HealthSystem**
3. Optionally adjust `MaxHealth`, `DamageResistance` in Details panel

---

## Test It
- [ ] PIE: check BeginPlay → CurrentHealth = 100
- [ ] Call ApplyDamage(25) → health drops to 75 → OnHealthChanged fires
- [ ] Call Heal(10) → health rises to 85 → OnHealed fires
- [ ] Call ApplyDamage(100) → death → OnDeath fires → bIsDead = true
