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

public class CrewSpawner : MonoBehaviour
{
  //public int CrewPerPlayerToSpawn;
  public Crew CrewObjectToSpawn;

  // Start is called before the first frame update
  void Start()
  {
    System.Array crewTypes = System.Enum.GetValues(typeof(Crew.CrewType));
    GameLogic gl = FindObjectOfType<GameLogic>();
    int numPlayers = gl.NumberOfPlayers;
    for (int i = 0; i < numPlayers; i++)
    {
            for (int crewIndex = 0; crewIndex < crewTypes.Length; crewIndex++)
            {
                Crew.CrewType ct = (Crew.CrewType)crewTypes.GetValue(crewIndex);
                SpawnCrew(ct, i).transform.SetParent(this.transform.parent);
            }
    }
  }

  public Crew SpawnCrew(Crew.CrewType ct, int playerNum = 1)
    {
        Crew newCrew = Instantiate(this.CrewObjectToSpawn);
        newCrew.PlayerNum = playerNum;
        float randomAngle = Random.Range(0f, 360f);
        newCrew.transform.SetPositionAndRotation(newCrew.transform.position, Quaternion.Euler(0, 0, randomAngle));
        newCrew.CType = ct;

        return newCrew;
    }

  // Update is called once per frame
  void Update()
  {

  }
}
