using UnityEngine;
using System.Collections;

public class Cachorro : Inventario {
	GameObject colidindo;
	// Use this for initialization
	public Texture retrato;
	public Texture vodka, latir;
	public Texture display;
	public Texture[] vidas;
	public int hp = 3;
	public int maxhp = 3;

	void Start () {
		this.adicionaOpcao ("Latir");
		this.adicionaOpcao ("Vodka");
		this.setInformative (this.gameObject);
		display = latir;
	}

	public override void Acao() {
		string s = this.getAtual ();
		switch (s) {
		case "Latir":
			GameObject[] a = GameObject.FindGameObjectsWithTag("inimigo");
			for(int i = 0; i < a.Length; i++) {
				if(Vector3.Distance(transform.position, a[i].transform.position) < 7) {
					a[i].SendMessage("Latido", this.transform.position);
				}
			}
			break;

		case "Vodka":
			if(colidindo != null && tag == "jogador")
				colidindo.SendMessage("Vodka");
			this.remove("Vodka");
			break;
		default:break;
		}
	}

	void OnCollisionEnter(Collision c) {
		base.OnCollisionEnter (c);
		colidindo = c.gameObject;
		if (colidindo.tag == "inimigo") {
			hp--;
			if(hp < 0) this.gameObject.SetActive(false);
		}
	}
	
	void OnCollisionExit(Collision c) {
		Invoke ("Limpa", 1.3f);
	}

	void OnGUI() {
		GUI.Label (new Rect (10, 10, 50, 50), retrato);
		if (this.hasOpcao ("Vodka")) {
			GUI.Label(new Rect(19, 55, 30,19), vodka);
		}
		GUI.Label (new Rect (16, 46, 32, 70), vidas [hp]);
	}
	
	void Limpa() {
		colidindo = null;
	}

	void Vodka() {
		this.adicionaOpcao ("Vodka");
	}

	void Inventario(string s) {
		if (s == "Vodka")
			display = vodka;
		else
			display = latir;
		Debug.Log (s);
	}
}
