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

public class Round : MonoBehaviour
{
    Wave[] waves;
    //AudioSource[] limitSounds;
    int currentWave = -1;

    void Awake()
    {
        waves = GetComponentsInChildren<Wave>();
        //limitSounds = GetComponents<AudioSource>();
    }

    void Update()
    {
        if ((currentWave >= 0) && (currentWave < waves.Length))
        {
            if (waves[currentWave].WaveHasEnded())
            {
                currentWave++;

                if (currentWave < waves.Length) { Invoke("ActivateNextWave", waves[currentWave].BreakTime); }
                /*else
                {
                    limitSounds[1].Play();
                }*/
            }
        }
    }

    public void StartRound()
    {
        Debug.Log("Comienza nueva ronda");
        currentWave = 0;
        waves[currentWave].ActivateWave();
        //limitSounds[0].Play();
    }

    private void ActivateNextWave()
    {
        waves[currentWave].ActivateWave();
    }

    internal bool RoundHasEnded()
    {
        bool NoEnemies = GameObject.FindWithTag("Enemy") == null;
        return (currentWave >= waves.Length) && NoEnemies;
    }

    internal void ActivateRound()
    {
        currentWave = 0;
    }
}
