using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public abstract class BaseAttack : MonoBehaviour
{
    public Wave Wave;
    public float Cooldown;
    public AttackState State;

    protected float _shootTime;

    public bool IsReady { get { return State == AttackState.READY; } }

    public abstract void OnButtonPressed(PlayerController player);

    void Update()
    {
        if (!IsReady && Time.time - _shootTime > Cooldown)
            State = AttackState.READY;
    }

    public void SetDirection(Vector3 direction)
    {
        transform.right = direction;
    }

    protected virtual void Execute(PlayerController player, Vector3 spawnPos)
    {
        Wave spawnedWave = Instantiate(Wave.gameObject, spawnPos, Quaternion.identity).GetComponent<Wave>();

        OnWaveSpawned(spawnedWave);

        spawnedWave.Launch(player.Transform.right);
        _shootTime = Time.time;

        State = AttackState.COOLDOWN;
        player.OnCooldownStarted();
    }

    protected virtual void OnWaveSpawned(Wave wave) { }
}

public enum AttackState
{
    CHARGING,
    READY,
    COOLDOWN
}