using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using UnityEngine.UI;

public class MainGameScript : MonoBehaviour {
	private List<Sprite> ingredientsList;
	private int numIngSelected;
	private List<string> mix1;
	private List<string> mix2;
	private List<string> mix3;
	private List<string> mix4;
	private List<string> mix5;
	private List<string> mix6;
	private int maxnumIngSelected;
	public GameObject dropbox;

	public GameObject girl;
	private Animator animgirl;

	public GameObject smoke;

	public GameObject outcome1;
	public GameObject outcome2;
	public GameObject outcome3;
	public GameObject outcome4;
	public GameObject outcome5;
	public GameObject outcome6;
	public GameObject outcomed;

	private int outcomenum;

	public static bool endGame;
	private bool activatedrag;
	private bool soundPlayed;

	SFX soundControl;

	// Use this for initialization
	void Start () {
		animgirl = girl.GetComponent<Animator> ();
		soundControl = dropbox.GetComponent<SFX> ();

		activatedrag = true;
		ingredientsList = new List<Sprite>();
		mix1 = new List<string>();
		mix2 = new List<string>();
		mix3 = new List<string>();
		mix4 = new List<string>();
		mix5 = new List<string>();
		mix6 = new List<string>();
		numIngSelected = 0;
		maxnumIngSelected = 5;
		endGame = false;
		smoke.gameObject.SetActive (false);
		outcome1.gameObject.SetActive (false);
		outcome2.gameObject.SetActive (false);
		outcome3.gameObject.SetActive (false);
		outcome4.gameObject.SetActive (false);
		outcome5.gameObject.SetActive (false);
		outcome6.gameObject.SetActive (false);
		outcomed.gameObject.SetActive (false);
		outcomenum = 0;

		/*
		BloodRuby
		Bone
		Dragon
		DragonEye
		ElfEar
		GriphonFeather
		SphinxFeet
		UniHorn
		VenusFlower
		WolferineClaw
		Wooble
		*/

		soundPlayed = false;

		//Mixing 1 prince
		mix1.Add("BloodRuby");
		mix1.Add("DragonEye");
		mix1.Add("GriphonFeather");
		mix1.Add("UniHorn");
		mix1.Add("VenusFlower");

		//Mixing 2 frog
		mix2.Add("BloodRuby");
		mix2.Add("DragonEye");
		mix2.Add("SphinxFeet");
		mix2.Add("GriphonFeather");
		mix2.Add("WolferineClaw");

		//Mixing 3 dragonfly
		mix3.Add("Bone");
		mix3.Add("DragonEye");
		mix3.Add("ElfEar");
		mix3.Add("VenusFlower");
		mix3.Add("Wooble");

		//Mixing 4 snail
		mix4.Add("WolferineClaw");
		mix4.Add("ElfEar");
		mix4.Add("UniHorn");
		mix4.Add("VenusFlower");
		mix4.Add("Wooble");

		//Mixing 5 gremlin
		mix5.Add("ElfEar");
		mix5.Add("SphinxFeet");
		mix5.Add("UniHorn");
		mix5.Add("WolferineClaw");
		mix5.Add("Wooble");

		//Mixing 6 phoenix
		mix6.Add("BloodRuby");
		mix6.Add("Bone");
		mix6.Add("VenusFlower");
		mix6.Add("SphinxFeet");
		mix6.Add("UniHorn");


		//Debug.Log ("sssstart");

	}

	public bool getActivatedrag ()
	{
		return  activatedrag;
	}

	public void addingredient(Sprite spr) {
		//GameObject sound = GameObject.Find ("Drop Box");
		//SFX soundControl = sound.GetComponent<SFX> ();

		ingredientsList.Add (spr);
		numIngSelected++;

		Image ens = GameObject.Find (spr.name).GetComponent<Image>();
		ens.enabled = false;

		if (spr.name == "BloodRuby") {
			soundControl.sfx[0].Play ();
		}
		else if (spr.name == "Dragon") {
			soundControl.sfx[1].Play ();
		}
		else if (spr.name == "GriphonFeather") {
			soundControl.sfx[2].Play ();
		}
		else if (spr.name == "UniHorn") {
			soundControl.sfx[3].Play ();
		}
		else if (spr.name == "VenusFlower") {
			soundControl.sfx[4].Play ();
		}
		else if (spr.name == "SphinxFeet") {
			soundControl.sfx[5].Play ();
		}
		else if (spr.name == "WolferineClaw") {
			soundControl.sfx[6].Play ();
		}
		else if (spr.name == "Bone") {
			soundControl.sfx[7].Play ();
		}
		else if (spr.name == "ElfEar") {
			soundControl.sfx[8].Play ();
		}
		else if (spr.name == "Wooble") {
			soundControl.sfx[9].Play ();
		}

		//Debug.Log (spr.name.ToString());
		//Debug.Log ("sdsdsd");

		if (numIngSelected == maxnumIngSelected) {
			dropbox.gameObject.SetActive (false);
			endGame = true;
			comparemix ();
			smoke.gameObject.SetActive (true);

			//delete the temmporory object created by DragMe.cs OnBeginDrag
			GameObject ic = GameObject.Find ("icon");
			ic.gameObject.SetActive (false);
		}
	}

	void comparemix()
	{
		int k;

		if (outcomenum == 0) {
			k = 0;
			foreach (string mix in mix1) {
				foreach (Sprite ingredient in ingredientsList) {
					if (mix == ingredient.name.ToString ()) {
						k++;
					}
				}
			}
			if (k == 4) {
				outcome1.gameObject.SetActive (true);
				outcomenum = 1;
				animgirl.SetTrigger ("good");
				soundControl.sfx[20].Play ();
			}
		}

		if (outcomenum == 0) {
			k = 0;
			foreach (string mix in mix2) {
				foreach (Sprite ingredient in ingredientsList) {
					if (mix == ingredient.name.ToString ()) {
						k++;
					}
				}
			}
			if (k == 4) {
				outcome2.gameObject.SetActive (true);
				outcomenum = 2;
				animgirl.SetTrigger ("bad");
				soundControl.sfx[15].Play ();
			}
		}

		if (outcomenum == 0) {
			k = 0;
			foreach (string mix in mix3) {
				foreach (Sprite ingredient in ingredientsList) {
					if (mix == ingredient.name.ToString ()) {
						k++;
					}
				}
			}
			if (k == 4) {
				outcome3.gameObject.SetActive (true);
				outcomenum = 3;
				animgirl.SetTrigger ("good");
				soundControl.sfx[18].Play ();
			}
		}

		if (outcomenum == 0) {
			k = 0;
			foreach (string mix in mix4) {
				foreach (Sprite ingredient in ingredientsList) {
					if (mix == ingredient.name.ToString ()) {
						k++;
					}
				}
			}
			if (k == 4) {
				outcome4.gameObject.SetActive (true);
				outcomenum = 4;
				animgirl.SetTrigger ("bad");
				soundControl.sfx[17].Play ();
			}
		}

		if (outcomenum == 0) {
			k = 0;
			foreach (string mix in mix5) {
				foreach (Sprite ingredient in ingredientsList) {
					if (mix == ingredient.name.ToString ()) {
						k++;
					}
				}
			}
			if (k == 4) {
				outcome5.gameObject.SetActive (true);
				outcomenum = 5;
				animgirl.SetTrigger ("bad");
				soundControl.sfx[16].Play ();
			}
		}

		if (outcomenum == 0) {
			k = 0;
			foreach (string mix in mix6) {
				foreach (Sprite ingredient in ingredientsList) {
					if (mix == ingredient.name.ToString ()) {
						k++;
					}
				}
			}
			if (k == 4) {
				outcome6.gameObject.SetActive (true);
				outcomenum = 6;
				animgirl.SetTrigger ("good");
				soundControl.sfx[19].Play ();
				//Debug.Log ("6666666666666666");
			}
		}

		if 	(outcomenum == 0) {
			outcomed.gameObject.SetActive (true);
			animgirl.SetTrigger ("weird");
			soundControl.sfx[21].Play ();
		}


		Debug.Log (outcomenum);

	}
}