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

public class PokaemonCreation : MonoBehaviour {

	public List <GameObject> prefabs;

	// Use this for initialization
	void Start () {
		createPrefab (0);
		createPrefab (1);
	}

	// Update is called once per frame
	void Update () {
	
	}

	public void createPrefab(int pl) {
		if (pl == 0) {
			int pl1 = GameMaster.players[0].GetActiveMonster();
			List<Monster> monsterArray = GameMaster.players [0].GetMonsters();
			List<Elements> elementArray = monsterArray[pl1].GetElements ();
			GameObject head;
			for (int i = 0; i < 3; i++) {
				switch (elementArray [i].ToString ()) {
					case "FIRE":
						head = (GameObject)Instantiate (prefabs [0 + i * 4], new Vector3 (0, 0, 0), Quaternion.identity);
						head.transform.parent = GameObject.Find ("MonsterContainer0").GetComponent<Transform> ();
						head.transform.localPosition = new Vector3 (0, 0, 0);
						head.transform.localRotation = Quaternion.identity;
						break;
					case "EARTH":
						head = (GameObject)Instantiate (prefabs [1+i*4], new Vector3 (0, 0, 0), Quaternion.identity);
						head.transform.parent = GameObject.Find ("MonsterContainer0").GetComponent<Transform> ();
						head.transform.localPosition = new Vector3(0,0,0);
						head.transform.localRotation = Quaternion.identity;
						break;
					case "AIR":
						head = (GameObject)Instantiate (prefabs [2+i*4], new Vector3 (0, 0, 0), Quaternion.identity);
						head.transform.parent = GameObject.Find ("MonsterContainer0").GetComponent<Transform> ();
						head.transform.localPosition = new Vector3(0,0,0);
						head.transform.localRotation = Quaternion.identity;
						break;
					case "WATER":
						head = (GameObject)Instantiate (prefabs [3+i*4], new Vector3 (0, 0, 0), Quaternion.identity);
						head.transform.parent = GameObject.Find ("MonsterContainer0").GetComponent<Transform> ();
						head.transform.localPosition = new Vector3(0,0,0);
						head.transform.localRotation = Quaternion.identity;
						break;
				}
				Debug.Log (elementArray [i].ToString ());
				GameObject.Find("MonsterContainer0").GetComponent<DemonControl>().GetParts ();
			}
		} else {
			int pl2 = GameMaster.players[1].GetActiveMonster();
			List<Monster> monsterArray = GameMaster.players [1].GetMonsters();
			List<Elements> elementArray = monsterArray[pl2].GetElements ();
			GameObject head;
			for (int i = 0; i < 3; i++) {
				switch (elementArray [i].ToString ()) {
					case "FIRE":
						head = (GameObject)Instantiate (prefabs [0 + i * 4], new Vector3 (0, 0, 0), Quaternion.identity);
						head.transform.parent = GameObject.Find ("MonsterContainer1").GetComponent<Transform> ();
						head.transform.localPosition = new Vector3(0,0,0);
						head.transform.localRotation = Quaternion.identity;
						break;
					case "EARTH":
						head = (GameObject)Instantiate (prefabs [1+i*4], new Vector3 (0, 0, 0), Quaternion.identity);
						head.transform.parent = GameObject.Find ("MonsterContainer1").GetComponent<Transform> ();
						head.transform.localPosition = new Vector3(0,0,0);
						head.transform.localRotation = Quaternion.identity;
						break;
					case "AIR":
						head = (GameObject)Instantiate (prefabs [2+i*4], new Vector3 (0, 0, 0), Quaternion.identity);
						head.transform.parent = GameObject.Find ("MonsterContainer1").GetComponent<Transform> ();
						head.transform.localPosition = new Vector3(0,0,0);
						head.transform.localRotation = Quaternion.identity;
						break;
					case "WATER":
						head = (GameObject)Instantiate (prefabs [3+i*4], new Vector3 (0, 0, 0), Quaternion.identity);
						head.transform.parent = GameObject.Find ("MonsterContainer1").GetComponent<Transform> ();
						head.transform.localPosition = new Vector3(0,0,0);
						head.transform.localRotation = Quaternion.identity;
						break;
				}
				GameObject.Find("MonsterContainer1").GetComponent<DemonControl>().GetParts ();
				Debug.Log (elementArray [i].ToString ());
			}
		}
	}
}
