using DoomDeathmatch.Component.MVC.Controller;
using Engine.Util;

namespace DoomDeathmatch.Component.MVC.Model.Enemy.Attack;

public abstract class CooldownAttackBehavior(
  EnemyController parEnemyController,
  HealthController parHealthController,
  float parCooldown)
  : AttackBehavior(parEnemyController, parHealthController)
{
  private readonly TickableTimer _tickableTimer = new(parCooldown);

  public sealed override bool Attack(double parDeltaTime)
  {
    _tickableTimer.Update(parDeltaTime);

    if (CanAttack())
    {
      if (!_tickableTimer.IsFinished)
        return false;

      var result = ActivateAttack();

      _tickableTimer.Reset();

      return result;
    }

    return false;
  }

  protected abstract bool CanAttack();
  protected abstract bool ActivateAttack();
}