namespace DoomDeathmatch.Component;

public class HealthComponent : Engine.Scene.Component.Component
{
  public float MaxHealth { get; set; } = 100;
  public float Health { get; private set; } = 100;
  public event Action<HealthComponent>? HealthChanged;
  public event Action<HealthComponent>? Died;

  public void TakeDamage(float parDamage)
  {
    Health -= parDamage;
    if (Health <= 0)
    {
      Died?.Invoke(this);
    }
    else
    {
      HealthChanged?.Invoke(this);
    }
  }

  public void Heal(float parHeal)
  {
    Health += parHeal;
    if (Health > MaxHealth)
    {
      Health = MaxHealth;
    }

    HealthChanged?.Invoke(this);
  }
}