using UnityEngine;
using System.Collections;

public class EventController : MonoBehaviour {

	public bool requiresPreviousChapters = false;
	public int[] Chapters;
	public new bool active;
	public int maxEvents = 4;
	public bool chapterFinished = false;

	//[HideInInspector]
	public int currentEvent = 0;

	
	void Start ()
	{
		if(currentEvent == 0)
			currentEvent++;
	}

	void Update ()
	{
		// If all event within the chapter have been complete chapterFinished = true;
		if(currentEvent == maxEvents)
			chapterFinished = true;

		// If requires previous chapters check them here.
		if(requiresPreviousChapters == true)
		{
			foreach(int chapter in Chapters)
			{
				// If returns false set active to false
				if(!checkChapter (chapter))
					break;
				else
					active = true;
			}
		}
		else
			active = true;
	}

	// Check see if the required Chapters have been completd before hand
	bool checkChapter(int i)
	{
		if(GameObject.Find("Chapter"+i).GetComponent<EventController>().chapterFinished)
		{
			return true;
		}
		else
			return false;
	}
}
