using UnityEngine;
using System.Collections;

public class Owl : MonoBehaviour {

	public Transform flashQuadPrefab; // inspector

	public Camera camera; // inspector

	public Gas gasPrefab; // inspector

	private Pill currentPill = null;

	private World world;

	private float timeLeft = 1.0f;//10


	public void init(World world) {
		this.world = world;
	}
	
	// Update is called once per frame
	void Update () {
		float dt = Time.deltaTime;
		timeLeft -= dt;
		if (currentPill != null) {
			currentPill.update (dt, timeLeft);
		}
		if (timeLeft <= 0.0f && currentPill != null) {
			currentPill.destroy();
			Destroy (currentPill);
			currentPill = null;
			timeLeft += Random.Range (Data.owlMinPillTime, Data.owlMaxPillTile) / 2.0f;
		}
		if (timeLeft <= 0.0f && currentPill == null) {
			changePill();
			timeLeft += Random.Range (Data.owlMinPillTime, Data.owlMaxPillTile);
		}
	}

	public void changePill() {
		/*if (currentPill != null) {
			currentPill.destroy();
			Destroy (currentPill);
		}

		int pick = Random.Range (0,6);
		if (pick == 0) currentPill = gameObject.AddComponent<RotatePill>();
		if (pick == 1) currentPill = gameObject.AddComponent<ZoomPill>();
		if (pick == 2) currentPill = gameObject.AddComponent<RepeatingZoomPill>();
		//if (pick == 3) currentPill = gameObject.AddComponent<MouseSensitivityPill>();
		//if (pick == 4) currentPill = gameObject.AddComponent<MouseScrollPill>();
		if (pick == 5) currentPill = gameObject.AddComponent<FlashPill>();

		if (currentPill != null) {
			Debug.Log ("LAUNCH GAS!");
			Gas gas = Instantiate (gasPrefab) as Gas;
			gas.transform.position = world.rhino.transform.position;
			gas.init (transform, currentPill.getColor ());
			currentPill.attach (world, camera, this);
		}*/



	}
}
