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

public class ScenarioManager : MonoBehaviour
{

    private GameObject SpawnMonster(int index, bool SwingVariance)
    {
        GameObject monster = GetComponent<MonsterFactory>().CreateMonster(index);
        if (monster != null && SwingVariance)
        {
            monster.GetComponent<SwingTimerComponent>().TurnsRemaining += Random.Range(-1, 2);
        }

        return monster;
    }

    public void SpawnScenario(int level)
    {

        if (level == 1)
        {
            SpawnMonster(0, false);
        }
        else if (level == 2)
        {
            SpawnMonster(0, false);
            SpawnMonster(1, false);
        }
        else
        {
            int Budget = level * 15;

            while (Budget > 0)
            {
                GameObject spawnedMonster = SpawnMonster(Random.Range(0, 3), true);
                if (spawnedMonster)
                {
                    Budget -= spawnedMonster.GetComponent<MonsterStats>().SpawnBudget;
                }
                else
                {
                    break; // Error spawning a monster
                }
            }
        }
    }
}
