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

public class SpawnData
{

    public List<int> ResourceIDs = new();
    public List<int> Tickets = new();
    public List<int> TicketsPerUpgrade = new();

    public SpawnData()
    {

    }

    public void Add(int resourceID, int tickets, int ticketsPerUpgrade)
    {
        ResourceIDs.Add(resourceID);
        Tickets.Add(tickets);
        TicketsPerUpgrade.Add(ticketsPerUpgrade);
    }

    public int Generate(int upgradeLevel)
    {
        var sum = 0f;
        for (var i = 0; i < Tickets.Count; i++)
            sum += Tickets[i] + TicketsPerUpgrade[i] * upgradeLevel;
        var r = (float)Global.Rng.NextDouble();
        var current = 0f;
        for (var i = 0; i < Tickets.Count; i++)
        {
            current += (Tickets[i] + TicketsPerUpgrade[i] * upgradeLevel) / (float)sum;
            if (r <= current)
                return ResourceIDs[i];
        }
        return ResourceIDs[0];
    }

}
