﻿using UnityEditor;
using UnityEngine;
using System.Collections;

public class GameManager : MonoBehaviour
{

    public GameObject ammo;
    public GameObject blueBot;
    public GameObject health;

    public int ammoAmmount;
    public int botAmmount;
    public int healthAmmount;

    [SerializeField]
    public ArrayList botList = new ArrayList();
    [SerializeField]
    public ArrayList ammoList = new ArrayList();
    [SerializeField]
    public ArrayList healthList = new ArrayList();



	void Start () 
    {
        if (ammo == null || blueBot == null)
	    {
	        Debug.Log("You must set the prefabs");
	        return;
	    }
        //SPAWN CODE
        for (int i = 0; i < ammoAmmount; i++)
	    {
            Vector3 randomPoint = new Vector3(Random.Range(40, -40), 0, Random.Range(27, -27));
            Random.Range(40, -40);
	        GameObject newAmmo = Instantiate(ammo, randomPoint, Quaternion.identity) as GameObject;
            newAmmo.name = "Ammo_" + i;

            ammoList.Add(newAmmo);
	    }

        for (int i = 0; i < botAmmount; i++)
        {
            Vector3 randomPoint = new Vector3(Random.Range(40, -40),0, Random.Range(27, -27));
            Random.Range(40, -40);
            GameObject newBot = Instantiate(blueBot, randomPoint, Quaternion.identity) as GameObject;
            newBot.name = "Bot_" + i;
            botList.Add(newBot);

            //State Machine Code
            newBot.GetComponent<StateMachine>().SwitchState(new PatrolState(newBot));

        }

        for (int i = 0; i < healthAmmount; i++)
        {
            Vector3 randomPoint = new Vector3(Random.Range(40, -40), 0, Random.Range(27, -27));
            Random.Range(40, -40);
            GameObject newHealth = Instantiate(health, randomPoint, Quaternion.identity) as GameObject;
            newHealth.name = "Health_" + i;
            botList.Add(newHealth);
        }


        //GameObject leader = GameObject.FindGameObjectWithTag("leader");
        //GameObject teaser = GameObject.FindGameObjectWithTag("teaser");

        //leader.GetComponent<StateMachine>().SwitchState(new IdleState(leader, teaser));
        //teaser.GetComponent<StateMachine>().SwitchState(new TeaseState(teaser, leader));

        //leader.renderer.material.color = Color.red;
        //teaser.renderer.material.color = Color.blue;

        
	}
	
	void Update () 
    {
	
	}
}
