using UnityEngine;
using System.Collections;

public class Treasure : Entity {

	public RampagingRhino rhinoPrefab; // inspector

	public ChildExploder exploder; // inspector

	private int ID;

	public void Init() {
		fixYAxis();
		this.ID = networkController.controller.GetNextTreasureID();
		networkController.controller.SendSpawnTreasure (this);
	}
	          
	// Update is called once per frame
	void Update () {

	}

	public void OnCollisionEnter(Collision collision) {
		collision.collider.SendMessage ("OnTreasure", this, SendMessageOptions.DontRequireReceiver);
	}

	public int destroy() {
		networkController.controller.SendDestroyTreasure (this);
		int n = Random.Range (3, 5);
		for (int i = 0; i < n; ++i) {
			RampagingRhino rhino = Instantiate (rhinoPrefab) as RampagingRhino;
			rhino.init (transform.position);
		}
		exploder.explode();
		return n;
	}

	public int GetTreasureID() {
		return ID;
	}
}
