using UnityEngine;
using System.Collections;

public class WaesOnlyPhase : MonoBehaviour {

	public GameObject gameManager;
	//public int TimeBetweenTentacleAttacks = 8;
	public float NumberOfWavesInEachWave = 8;

	public float TimeBetweenSetOfWaves = 3;

	public float BossIsVulnerableTime = 2;

	public float TimeBetweenEachWave = 1f;

	int currentWavesThrown = 0;

	public int MaximumWaves = 6;



	void Start () {
		InvokeWave ();

	}


	void Update () {

	}

	void InvokeWave()
	{
		Invoke ("AttackPattern", TimeBetweenEachWave);
	}
	void AttackPattern()
	{
		if (currentWavesThrown < NumberOfWavesInEachWave) 
		{
			StartCoroutine (WaitASecond());	
		}
		if (currentWavesThrown >= NumberOfWavesInEachWave) 
		{
			StartCoroutine (SpawnNewWave ());
		}

	}

	IEnumerator WaitASecond()
	{

		yield return new WaitForSeconds (TimeBetweenEachWave);

		int choice = Random.Range (1, 4);

		if (choice == 1) 
		{
			gameManager.GetComponent<GameManagerScript> ().SpawnWaveInLane1 ();
		}
		else if (choice == 2) 
		{
			gameManager.GetComponent<GameManagerScript> ().SpawnWaveInLane2 ();
		}
		else if (choice == 3) 
		{
			gameManager.GetComponent<GameManagerScript> ().SpawnWaveInLane3 ();
		}
		//Debug.Log (choice);
		currentWavesThrown = currentWavesThrown + 1;
		if (currentWavesThrown < MaximumWaves) 
		{
			Invoke ("AttackPattern", TimeBetweenEachWave);
		}


	}

	IEnumerator SpawnNewWave()
	{
		yield return new WaitForSeconds (TimeBetweenSetOfWaves);
		//currentWavesThrown = 0;


	}
}

