using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;

[SerializeField]
public class AttackerAndDamageable : Damageable, IAttacker {
  [SerializeField] public int BaseDamage { get; protected set; } = 0;

  public void StartAttackPreparation() => AttackReadyAt = Time.time + AttackPreparationTime;
  public bool AttackIsReady => AttackPreparationTimeLeft == 0;
  public float AttackReadyAt { get; protected set; }
  [SerializeField] public float AttackPreparationTime { get; protected set; } = 0;
  public float AttackPreparationTimeLeft => Math.Max(0, AttackReadyAt - Time.time);
  public float AttackPreparationTimeLeftNormalized => Math.Max(0, (AttackReadyAt - Time.time) / AttackPreparationTime);
  public float AttackPreparationTimeElapsed => AttackPreparationTime - AttackPreparationTimeLeft;
  public float AttackPreparationTimeElapsedNormalized => 1 - AttackPreparationTimeLeftNormalized;

  public void StartAttackCooldown() => AttackCooldown = Time.time + AttackCooldownDuration;
  public bool CanAttack => Time.time > AttackCooldown;
  public float AttackCooldown { get; protected set; }
  public float AttackCooldownLeft => Math.Max(0, AttackCooldown - Time.time);
  [SerializeField] public float AttackCooldownDuration { get; protected set; } = 1f;
}
