using UnityEngine;
using UnityEngine.UI;
using System.Collections;

public class ShamanStateUpdate : MonoBehaviour {

	private Image myImage;

	public Sprite shamanGoodStatus;
	public Sprite shamanBadStatus;
	public Sprite shamanStaticNormalStatus;

	private Animator myAnimator;

	// Use this for initialization
	void Start () 
	{
		// Adding Basic GameOver handlers
		RitualManager.instance.OnBadRitual += ShamanBadStatus;
		RitualManager.instance.OnGoodRitual += ShamanGoodStatus;

		myImage = GetComponent<Image>();
		myAnimator = GetComponent<Animator>();

		Invoke ("ShamanTIIIIICK", Random.Range(1f,3f));
	}

	void ShamanGoodStatus()
	{
		myImage.sprite = shamanGoodStatus;

		StartCoroutine(RestoreShamanStatus());

	}

	void ShamanBadStatus()
	{
		myImage.sprite = shamanBadStatus;

		StartCoroutine(RestoreShamanStatus());

	}

	IEnumerator RestoreShamanStatus() 
	{
		yield return new WaitForSeconds(0.5f);

		ShamanStaticNormalStatus();
	
	}

	void ShamanStaticNormalStatus()
	{
		myImage.sprite  = shamanStaticNormalStatus;
	}

	//  :)

	void Update()
	{
	}

	void ShamanTIIIIICK()
	{
		Debug.Log ("PLAY TICK");

		myAnimator.Play("ShamanTickAnim", -1, 0f);

		Invoke ("ShamanTIIIIICK", Random.Range(1f,3f));
	}
}
