using Mirror;
using Unity.Mathematics;
using UnityEngine;
using Random = UnityEngine.Random;
public class EnergyCellManager : NetworkBehaviour
{
    public GameObject prefab;
        
    private Vector3 _offset = new Vector3(3, -1, 3);
    private int _levelSize;
    private int _energySpawnChance;
    void Start()
    {
        if (!isServer) return;
        
        _levelSize = PlayerPrefs.GetInt("LevelSize");
        _energySpawnChance = PlayerPrefs.GetInt("EnergySpawnChance");

        int randomValue = Random.Range(0, _levelSize);
        float threshold = _levelSize * (_energySpawnChance / 100f);

        if (randomValue < threshold)
        {
            SpawnEnergyCell();
        }
    }

    void SpawnEnergyCell()
    {
        Vector3 randomPosition = new Vector3(Random.Range(-6, 6), 0f, Random.Range(-6, 6));
        GameObject go = Instantiate(prefab, transform.position + _offset + randomPosition, quaternion.identity);
        NetworkServer.Spawn(go);
    }
}