using UnityEngine;
using System.Collections;

public abstract class Inventario : MonoBehaviour {
	private ArrayList pertences = new ArrayList();
	private ArrayList chaves = new ArrayList();
	private Rect r;
	private int atual = 0;
	private bool continuo;
	private GameObject informe;

	void Awake() {
		r = new Rect (0, Screen.height - 20, Screen.width, 20);
	}
	// Update is called once per frame
	public void Update () {
		if (!GetComponent<Movimentacao> ().ativo)
						return;
		if (informe != null && informe.name == "Militar") {
						if (Input.GetKeyDown (KeyCode.Z)) {
								atual = (atual + 1) % (pertences.Count);
								if (informe != null)
										informe.SendMessage ("Inventario", getAtual ());
						}
						if (informe != null && informe.name == "Militar" && (
			((continuo && Input.GetKey (KeyCode.X)) || 
								(!continuo && Input.GetKeyDown (KeyCode.X)))
								&& this.GetComponent<Movimentacao> ().ativo)) {
								Acao ();
						}
				} else {

						if (Input.GetKeyDown (KeyCode.Z)) {
								atual = 0;
								Acao ();
						} else if (Input.GetKeyDown (KeyCode.X)) {
								atual = 1;
								Acao ();
						}
				}
	}


	protected void setInformative(GameObject g) {
		informe = g;
	}

	void OnGUI() {
		if (this.GetComponent<Movimentacao> ().ativo)
			GUI.Label (r, pertences [atual].ToString());
	}

	protected void adicionaOpcao(string o) {
		pertences.Add (o);
	}

	protected string getAtual() {
		return (string) pertences [atual];
	}

	protected void setContinuo(bool continuo) {
		this.continuo = true;
	}

	public void OnCollisionEnter(Collision c) {
		if (c.gameObject.tag == "chave") {
			chaves.Add(c.gameObject);
			c.gameObject.SetActive(false);
			Debug.Log ("chave");
		}

	}

	public bool temChave(GameObject chave) {

		foreach (GameObject g in chaves) {
			if(g == chave) return true;
		}
		return false;
	}

	public bool hasOpcao(object o) {
		return pertences.Contains (o);
	}

	public void remove(string s) {
		pertences.Remove (s);
	}

	public abstract void Acao ();
}
