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

[CreateAssetMenu(menuName="Broken Tile")]
public class BrokenTile : Tile
{
    private static List<Vector3Int> m_AvailablePositions = new List<Vector3Int>();
    private static List<Vector3Int> m_TakenPositions = new List<Vector3Int>();

    public static bool GetRandom(out Vector3Int pos)
    {
        if (m_AvailablePositions.Count > 0)
        {
            pos = m_AvailablePositions[Random.Range(0, m_AvailablePositions.Count)];
            m_AvailablePositions.Remove(pos);
            m_TakenPositions.Add(pos);
            return true;
        }

        pos = Vector3Int.zero;
        return false;
    }

    public static void Release(Vector3Int pos)
    {
        m_AvailablePositions.Add(pos);
        m_TakenPositions.Remove(pos);
    }

    public override bool StartUp(Vector3Int position, ITilemap tilemap, GameObject go)
    {
        m_AvailablePositions.Add(position);

        return base.StartUp(position, tilemap, go);
    }
}
