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

public class Level : MonoBehaviour {

	public GameObject boule;
	public GameObject batterie;
	public GameObject essence;
	public GameObject bouleMagique;
	public int nbBoules;
	public int nbBatterie;
	public int nbEssence;
	
    private GameObject conteneur;
	private float xMax=40.0f;
	private float zMax=13.0f;
	public static Level instance;
	public Dictionary <string, int>	dicoPoints = null;
	
	void Start(){
		instance =this;
		initDico();
		
	}
	
	void initDico(){
		dicoPoints= new Dictionary<string, int>();
		dicoPoints.Add("Poussiere",10);
	}
	
	public void GenererItems(){
		conteneur = new GameObject();
		conteneur.name= "conteneur";
		GenererBoules();
		GenererBatteries();
		GenererEssences();
		
		//GenererBouleMagique();
	}
	
	public void GenererBoules(){

		
		for(int i=1;i<=Game.instance.upgradeTab[3].coeff*nbBoules;i++){
			float x=Random.Range(0.0f,xMax);
			float z=Random.Range(0.0f,zMax);
			GameObject cloneBoule = Instantiate(boule, new Vector3(x,4.4f,z),  Quaternion.identity) as GameObject;
			cloneBoule.transform.Rotate(new Vector3(-90.0f,Random.Range(0.0f,360.0f),0.0f));
			cloneBoule.name=boule.name;
			cloneBoule.transform.parent = conteneur.transform;
			
		}

	} 
	
	public void GenererBatteries(){
		
		for(int i=1;i<=Game.instance.upgradeTab[2].coeff*nbBatterie;i++){
			float x=Random.Range(0.0f,xMax);
			float z=Random.Range(0.0f,zMax);
			GameObject cloneBatterie = Instantiate(batterie, new Vector3(x,4.4f,z),  Quaternion.identity) as GameObject;
			cloneBatterie.name=batterie.name;
			cloneBatterie.transform.parent = conteneur.transform;
		}
	}
	
	public void GenererEssences(){
		
		if(Player.instance.TestBoost()){
			for(int i=1;i<=Game.instance.upgradeTab[1].coeff*nbEssence;i++){
				float x=Random.Range(0.0f,xMax);
				float z=Random.Range(0.0f,zMax);
				GameObject cloneEssence = Instantiate(essence, new Vector3(x,4.4f,z),  Quaternion.identity) as GameObject;
				cloneEssence.name=essence.name;
				cloneEssence.transform.parent = conteneur.transform;
			}
		}
	}
	
	public void GenererBouleMagique(){
		
		GameObject cloneBouleMagique = Instantiate(bouleMagique, new Vector3(29.62135f,3.862522f,10.87984f),  Quaternion.identity) as GameObject;
		//GameObject cloneBouleMagique = Instantiate(bouleMagique, new Vector3(18.0f,0.5f,9.0f),  Quaternion.identity) as GameObject;
		cloneBouleMagique.name=bouleMagique.name;
		cloneBouleMagique.transform.parent = conteneur.transform;
		
	}
}
