using UnityEngine;
using System.Collections;

public class CastManager : MonoBehaviour {
	public float waitTime;
	private float lastUse;

	private int counter;

	public GameObject ruby;
	public GameObject saphire;
	public GameObject emerald;
	public GameObject topaz;
	public GameObject diamond;
	public GameObject stick;
	public GameObject weed;
	public GameObject hair;
	public GameObject horn;
	public GameObject blood;

	void OnTriggerEnter(Collider col) {
		ruby.GetComponent<ItemSlot> ().setCastManager (this);
		saphire.GetComponent<ItemSlot> ().setCastManager (this);
		emerald.GetComponent<ItemSlot> ().setCastManager (this);
		topaz.GetComponent<ItemSlot> ().setCastManager (this);
		diamond.GetComponent<ItemSlot> ().setCastManager (this);
		//stick.GetComponent<ItemSlot> ().setCastManager (this);
		//weed.GetComponent<ItemSlot> ().setCastManager (this);
		//hair.GetComponent<ItemSlot> ().setCastManager (this);
		//horn.GetComponent<ItemSlot> ().setCastManager (this);
		//blood.GetComponent<ItemSlot> ().setCastManager (this);
	}

	void OnTriggerExit(Collider col) {
		ruby.GetComponent<ItemSlot> ().setCastManager (null);
		saphire.GetComponent<ItemSlot> ().setCastManager (null);
		emerald.GetComponent<ItemSlot> ().setCastManager (null);
		topaz.GetComponent<ItemSlot> ().setCastManager (null);
		diamond.GetComponent<ItemSlot> ().setCastManager (null);
		//stick.GetComponent<ItemSlot> ().setCastManager (null);
		//weed.GetComponent<ItemSlot> ().setCastManager (null);
		//hair.GetComponent<ItemSlot> ().setCastManager (null);
		//horn.GetComponent<ItemSlot> ().setCastManager (null);
		//blood.GetComponent<ItemSlot> ().setCastManager (null);
	}

	public void useItem(string type)
	{
		counter++;
	}

	IEnumerator finishIfNoAction(float callTime)
	{
		// suspend for waitTime
		yield return new WaitForSeconds(waitTime);
		if (callTime == lastUse) finish ();
	}

	void finish ()
	{
		counter = 0;
		print (Time.time);
	}
}
