CapersProject/Assets/02.Scripts/Prop/Tycoon/CustomerTable.cs
2024-10-07 08:41:09 +09:00

49 lines
1.3 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using Random = System.Random;
namespace BlueWater.Tycoons
{
public class CustomerTable : MonoBehaviour
{
[SerializeField]
private List<TableSeat> _tableSeats;
private TableSeat _tableSeat;
private Random _random = new();
private TycoonManager _tycoonManager;
private void OnEnable()
{
_tycoonManager = TycoonManager.Instance;
_tycoonManager.CustomerTableController.RegisterTable(this);
}
private void OnDisable()
{
_tycoonManager.CustomerTableController.UnregisterTable(this);
}
public TableSeat FindEmptySeat()
{
var seatCount = _tableSeats.Count;
var indices = new List<int>(Enumerable.Range(0, seatCount));
while (indices.Count > 0)
{
var randomIndex = _random.Next(indices.Count);
var seatIndex = indices[randomIndex];
indices.RemoveAt(randomIndex);
var tableSeat = _tableSeats[seatIndex];
if (!tableSeat.IsReserved && !tableSeat.IsOccupied && tableSeat.IsCleaned)
{
return tableSeat;
}
}
return null;
}
}
}