using UnityEngine;
using System.Collections;

public class EventManager : MonoBehaviour {

    public delegate void BrightGuideStart(float eventTime);
    public static event BrightGuideStart OnBrightGuideStart;

    public delegate void SpeedStart(float eventTime);
    public static event SpeedStart OnSpeedStart;

    public delegate void BuffStart(float eventTime);
    public static event BuffStart OnBuffStart;

    public delegate void TunnelVisionStart(float eventTime);
    public static event TunnelVisionStart OnTunnelVisionStart;

    public delegate void StronkStart(float eventTime);
    public static event StronkStart OnStronkStart;

    public float eventTime = 60f;

    public GameObject enemy;

    // Use this for initialization
    void Start () {
        
	}
	
	// Update is called once per frame
	void Update () {
	
	}

    public void StartEvent(string eventType, bool appeased)
    {
        if (appeased)
        {
            switch (eventType)
            {
                case "A":
                    Speed();
                    break;
                case "B":
                    BrightGuide();
                    break;
                case "C":
                    Buff();
                    break;
            }
        }
        else
        {
            switch (eventType)
            {
                case "A":
                    StronkEnemies();
                    break;
                case "B":
                    TunnelVision();
                    break;
                case "C":
                    BigBoss();
                    break;
            }
        }
    }

    // I'll come back to the events later.

    // Good Events

    /**
    SPEED
    Increases player speed
    **/
    void Speed()
    {
        if(OnSpeedStart != null)
        {
            OnSpeedStart(eventTime);
        }
    }

    /**
    Buff
    Makes the player have more health
    **/
    void Buff()
    {
        if(OnBuffStart != null)
        {
            OnBuffStart(eventTime);
        }
    }

    /**
    BRIGHT GUIDE
    Makes the staff guide brighten on pointing the right direction
    **/
    void BrightGuide()
    {
        if(OnBrightGuideStart != null)
        {
            OnBrightGuideStart(eventTime);
        }
    }

    // Bad Events

    /**
    TUNNEL VISION
    Puts dark overlay onto screen that limits vision to right in the center
    **/
    void TunnelVision()
    {
        if(OnTunnelVisionStart != null)
        {
            OnTunnelVisionStart(eventTime);
        }
    }

    /**
    STRONK ENEMIES
    Makes enemies have more health and makes them bigger
    **/
    void StronkEnemies()
    {
        if(OnStronkStart != null)
        {
            OnStronkStart(eventTime);
        }
    }

    /**
    BIG BOSS
    Spawns a giant enemy in front of the player that has heaps of health
    **/
    void BigBoss()
    {
        Vector3 pos = transform.position + (transform.forward * 10);
        NavMeshHit hit;
        if (NavMesh.SamplePosition(pos, out hit, 2.5f, NavMesh.AllAreas))
        {
            pos = hit.position;
        }

        GameObject newEnemy = (GameObject)Instantiate(enemy, pos, Quaternion.identity);
        newEnemy.GetComponent<Enemy>().OnSpawn("bigBoss");
    }
}
