using UnityEngine;
using System.Collections;

public class Priest : MonoBehaviour {

    private GameObject m_wololoWave;
    public SpriteRenderer m_wololoRenderer;
    public LensFlare m_lensFlare;
    public float m_wololoTimer = 0.0f;
    public const float m_wololoMaxTimer = 2.0f;

    public bool m_isWololoing = false;

    public int m_masterID;

    public bool m_isStun = false;
    public float m_stunTime = 0.0f;
    public float m_stunMaxTime = 2.0f;

    // Use this for initialization
    void Start () {
        m_stunTime = m_stunMaxTime;
        m_wololoTimer = m_wololoMaxTimer;

        m_wololoWave = new GameObject();
        m_wololoRenderer = m_wololoWave.AddComponent<SpriteRenderer>();
        m_lensFlare = m_wololoWave.AddComponent<LensFlare>();

        switch (m_masterID)
        {
            case 0:
                m_lensFlare.color = Color.blue;
                m_lensFlare.flare = Resources.Load("Flare/Sun", typeof(Flare)) as Flare;
                m_lensFlare.enabled = false;
                m_lensFlare.brightness = 3.5f;
                break;
            case 1:
                m_lensFlare.color = Color.yellow;
                m_lensFlare.flare = Resources.Load("Flare/Sun", typeof(Flare)) as Flare;
                m_lensFlare.enabled = false;
                m_lensFlare.brightness = 3.5f;
                break;
            case 2:
                m_lensFlare.color = Color.green;
                m_lensFlare.flare = Resources.Load("Flare/Sun", typeof(Flare)) as Flare;
                m_lensFlare.enabled = false;
                m_lensFlare.brightness = 3.5f;
                break;
            case 3:
                m_lensFlare.color = Color.red;
                m_lensFlare.flare = Resources.Load("Flare/Sun", typeof(Flare)) as Flare;
                m_lensFlare.enabled = false;
                m_lensFlare.brightness = 3.5f;
                break;
        }

        m_wololoRenderer.enabled = false;

        m_wololoWave.transform.position = transform.position;
    }
	
	// Update is called once per frame
	void Update () {

        float delta = Time.deltaTime;

        if (m_isStun)
        {
            m_stunTime -= delta;

            if(m_stunTime <= 0.0f)
            {
                m_isStun = false;
                m_stunTime = m_stunMaxTime;
            }
        }

        m_wololoWave.transform.position = transform.position;

        if (m_isWololoing)
        {

            m_wololoTimer -= delta;
            if(m_wololoTimer <= 0.0f)
            {
                m_isWololoing = false;
                m_wololoRenderer.enabled = false;
                m_wololoTimer = m_wololoMaxTimer;
                m_lensFlare.enabled = false;
            }
        }
	}

    void OnCollisionEnter2D(Collision2D coll)
    {
        //Debug.Log("Coll Detection");
    }

    public void Wololo()
    {
        m_isWololoing = true;
        m_lensFlare.enabled = true;
        m_wololoRenderer.enabled = true;
    }
}
