using UnityEngine;
using System.Collections;
using Framework.Entities;

public class WatcherSpawnerDirector : CoreBehaviour
{
    public int threatLevel = 1;
    public GameObject lowThreatSpawners;
    public GameObject mediumThreatSpawners;
    public GameObject highThreatSpawners; 

    protected override void InnerAwake()
    {
        AddGlobalActionHandler<DayDirector.NewDayAction>(this, NewDay);
        AddGlobalActionHandler<TravellerResponsive.RecoveredAction>(this, TravellerRecovered);
    }

    protected override void InnerUpdate()
    {

    }

    private void TravellerRecovered(TravellerResponsive.RecoveredAction action)
    {
        threatLevel++;
    }

    private void NewDay(DayDirector.NewDayAction action)
    {
        WatcherLogic[] objects = GameObject.FindObjectsOfType<WatcherLogic>();
        for (int i = 0; i < objects.Length; i++)
        {
            Destroy(objects[i].gameObject);
        }
        if (GameObject.FindObjectsOfType<Villager>().Length > 0)
        {
            if (threatLevel >= 1 && threatLevel < 3)
            {
                Debug.Log("Low threat.");
                lowThreatSpawners.SetActive(true);
                lowThreatSpawners.SetActive(false);
            }
            else if (threatLevel >= 3 && threatLevel < 6)
            {
                Debug.Log("Medium threat.");
                mediumThreatSpawners.SetActive(true);
                mediumThreatSpawners.SetActive(false);
            }
            else if (threatLevel >= 6)
            {
                Debug.Log("High threat.");
                highThreatSpawners.SetActive(true);
                highThreatSpawners.SetActive(false);
            }
        }
    }
}
