using UnityEngine;
using System.Collections.Generic;
using System.Linq;
using ScrambleKit.Extensions;

public class MonsterPlacer : MonoBehaviour 
{

    public ChunkLibrary Monsters;
    public int MonsterCount = 1;

    private List<Transform> spawnSlots = new List<Transform>();

    public void PlaceMonsters()
    {
        spawnSlots.Clear();
        spawnSlots.AddRange(GameObject.FindGameObjectsWithTag("SpawnSlot").Select(go => go.transform));

        int bonus = (Random.Range(0f, 1f) > 0.6f) ? 1 : 0;

        if (Score.Depth >= 5)
            bonus++;

        if (Score.Depth == 1)
            bonus = 0;

        for (int i = 0; i < MonsterCount + bonus; i++)
            PlaceMonster();
    }

    private void PlaceMonster()
    {
        Transform slot = spawnSlots.DrawFromAtRandom();
        spawnSlots.Remove(slot);

        Instantiate(Monsters.ChunkPrefabs.DrawFromAtRandom(), slot.position, Quaternion.identity);
        Destroy(slot.gameObject);
    }

}
