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

public class IslandGenerator : MonoBehaviour {

    public GameObject treePrefab;
    public int minTrees = 3;
    public int maxTrees = 60;
    int numberOfTrees;

    public GameObject itemPrefab;

    private void Start() {
        if (treePrefab) {
            numberOfTrees = Random.Range(minTrees, maxTrees);

            for (int i = numberOfTrees; i >= 0; i--) {
                Vector3 newTreePos = new Vector3(
                    Random.Range(-10, 10),
                    -0.1f,
                    Random.Range(-10, 10)
                );
                GameObject thisTree = Instantiate(treePrefab, newTreePos, Quaternion.identity);
            }
        }

        if (itemPrefab) {
            for (int i = 30; i >= 0; i--) {
                Vector3 newItemPos = new Vector3(
                    Random.Range(-10, 10),
                    1,
                    Random.Range(-10, 10)
                );
                GameObject thisItem = Instantiate(itemPrefab, newItemPos, Quaternion.identity);

                int itemRoll = (int)Random.Range(1, 6);

                //Set item type
                switch (itemRoll) {
                    case 1:
                        thisItem.GetComponent<Item>().itemName = Item.ItemName.WOOD;
                        break;
                    case 2:
                        thisItem.GetComponent<Item>().itemName = Item.ItemName.LEAVES;
                        break;
                    case 3:
                        thisItem.GetComponent<Item>().itemName = Item.ItemName.SAND;
                        break;
                    case 4:
                        thisItem.GetComponent<Item>().itemName = Item.ItemName.SHELL;
                        break;
                    case 5:
                        thisItem.GetComponent<Item>().itemName = Item.ItemName.ROCKS;
                        break;
                }
            }
        }
    }
}
