/// <summary>
/// Pyre script.
/// all a trigger that gives a player +1 point for their pyre
/// </summary>

using UnityEngine;
using System.Collections;

public class pyreScript : MonoBehaviour {

	public AudioClip chickenDeath;
	public AudioClip pigDeath;
	public AudioClip cowDeath;
	public AudioClip holyDeath;
	public AudioClip pureDeath;
	public AudioClip babyDeath;
	public AudioClip humanDeath;
	public AudioClip Ghost;


	public bool player1;
	public float pointIncrease;
	public GameObject gameCon;
	private gameController controller;
	public GameObject playerOne;
	public GameObject playerTwo;

	public GameObject curseOne;
	public GameObject curseTwo;
	public GameObject curseThree;
	private GameObject runCurse;

	public ParticleSystem animalParti;
	public ParticleSystem humanParti;

	private BoxCollider2D tpArea;

	// Use this for initialization
	void Start () {
		tpArea = GameObject.Find ("PlayArea").GetComponent<BoxCollider2D>();
	}
	
	// Update is called once per frame
	void Update () {
		
	}
		
	void RecieveObj(int p){
		switch (p) {
		case 1:
			AudioSource.PlayClipAtPoint (chickenDeath, transform.position);

			if (player1) {
				gameCon.SendMessage ("Player1Add", 1);
			} else {
				gameCon.SendMessage ("Player2Add", 1);
			}
			animalParti.Play ();
			break;
		case 2:
			AudioSource.PlayClipAtPoint (pigDeath, transform.position);

			if (player1) {
				gameCon.SendMessage ("Player1Add", 2);
			} else {
				gameCon.SendMessage ("Player2Add", 2);
			}
			animalParti.Play ();
			break;
		case 3:
			AudioSource.PlayClipAtPoint (cowDeath, transform.position);

			if (player1) {
				gameCon.SendMessage ("Player1Add", 3);
			} else {
				gameCon.SendMessage ("Player2Add", 3);
			}
			animalParti.Play ();
			break;
		case 4:
			AudioSource.PlayClipAtPoint (Ghost, transform.position);

			int r = Random.Range (1, 4);

			humanParti.Play ();

			switch (r) {
			case 1:
				runCurse = curseOne;
				if (player1) {
					GameObject c = Instantiate(runCurse, transform.position, transform.rotation) as GameObject;
					c.SendMessage ("Player", 2);
					playerTwo.SendMessage ("Slow");
				} else {
					GameObject c = Instantiate(runCurse, transform.position, transform.rotation) as GameObject;
					c.SendMessage ("Player", 1);
					playerOne.SendMessage ("Slow");
				}

				break;
			case 2:
				runCurse = curseTwo;
				if (player1) {
					GameObject c = Instantiate(runCurse, transform.position, transform.rotation) as GameObject;
					c.SendMessage ("Player", 2);
					playerTwo.SendMessage ("Reverse");
				} else {
					GameObject c = Instantiate(runCurse, transform.position, transform.rotation) as GameObject;
					c.SendMessage ("Player", 1);
					playerOne.SendMessage ("Reverse");
				}
				break;
			case 3:
				runCurse = curseThree;
				if (player1) {
					GameObject c = Instantiate(runCurse, transform.position, transform.rotation) as GameObject;
					c.SendMessage ("Player", 2);
					playerTwo.transform.position = new Vector3 (Random.Range(tpArea.bounds.min.x, tpArea.bounds.max.x), Random.Range(tpArea.bounds.min.y, tpArea.bounds.max.y));
				} else {
					GameObject c = Instantiate(runCurse, transform.position, transform.rotation) as GameObject;
					c.SendMessage ("Player", 1);
					playerOne.transform.position = new Vector3 (Random.Range(tpArea.bounds.min.x, tpArea.bounds.max.x), Random.Range(tpArea.bounds.min.y, tpArea.bounds.max.y));
				}
				break;
			}
				
			break;
		
		case 5:
			AudioSource.PlayClipAtPoint (holyDeath, transform.position);

			humanParti.Play ();
			if (player1) {
				gameObject.SendMessage ("RunFamine", 2);
			} else {
				gameObject.SendMessage ("RunFamine", 1);
			}
			break;
		case 6:
			AudioSource.PlayClipAtPoint (pureDeath, transform.position);

			humanParti.Play ();
			if (player1) {
				gameObject.SendMessage ("RunRepentance",1);
			} else {
				gameObject.SendMessage ("RunRepentance",2);
			}

			break;
		case 7:
			AudioSource.PlayClipAtPoint (babyDeath, transform.position);

			humanParti.Play ();
			gameObject.SendMessage ("RunHaunting");
			break;
		}

	}

}
