using DoomDeathmatch.Component.MVC.Health;
using DoomDeathmatch.Component.Physics.Collision;
using Engine.Util;

namespace DoomDeathmatch.Component.Util;

public class FireballComponent : Engine.Scene.Component.Component
{
  public float Damage { get; set; }

  public override void Awake()
  {
    var collider = GameObject.GetComponent<AABBColliderComponent>()!;

    ArgumentNullException.ThrowIfNull(collider);

    collider.OnCollision += OnCollision;
  }

  private void OnCollision(AABBColliderComponent parCollider)
  {
    var healthController = parCollider.GameObject.GetComponent<HealthController>();
    healthController?.TakeDamage(Damage);

    EngineUtil.SceneManager.CurrentScene!.Remove(GameObject);
  }
}