2024-06-18 18:16:19 +00:00
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Linq;
|
|
|
|
using UnityEngine;
|
2024-07-22 00:42:29 +00:00
|
|
|
using Random = System.Random;
|
2024-06-18 18:16:19 +00:00
|
|
|
|
2024-07-02 18:27:56 +00:00
|
|
|
namespace BlueWater.Tycoons
|
2024-06-18 18:16:19 +00:00
|
|
|
{
|
2024-10-06 23:41:09 +00:00
|
|
|
public class CustomerTable : MonoBehaviour
|
2024-06-18 18:16:19 +00:00
|
|
|
{
|
|
|
|
[SerializeField]
|
|
|
|
private List<TableSeat> _tableSeats;
|
2024-10-08 13:44:20 +00:00
|
|
|
|
|
|
|
[SerializeField]
|
|
|
|
private int _tableNumber;
|
2024-07-22 00:42:29 +00:00
|
|
|
|
|
|
|
private TableSeat _tableSeat;
|
|
|
|
private Random _random = new();
|
2024-10-06 23:41:09 +00:00
|
|
|
private TycoonManager _tycoonManager;
|
2024-07-20 11:32:54 +00:00
|
|
|
|
2024-10-06 23:41:09 +00:00
|
|
|
private void OnEnable()
|
|
|
|
{
|
2024-10-08 13:44:20 +00:00
|
|
|
foreach (var element in _tableSeats)
|
|
|
|
{
|
|
|
|
element.SetTableNumber(_tableNumber);
|
|
|
|
}
|
|
|
|
|
2024-07-20 11:32:54 +00:00
|
|
|
_tycoonManager = TycoonManager.Instance;
|
|
|
|
_tycoonManager.CustomerTableController.RegisterTable(this);
|
2024-06-18 18:16:19 +00:00
|
|
|
}
|
|
|
|
|
2024-10-06 23:41:09 +00:00
|
|
|
private void OnDisable()
|
2024-06-18 18:16:19 +00:00
|
|
|
{
|
2024-07-20 11:32:54 +00:00
|
|
|
_tycoonManager.CustomerTableController.UnregisterTable(this);
|
2024-06-18 18:16:19 +00:00
|
|
|
}
|
2024-07-20 11:32:54 +00:00
|
|
|
|
2024-06-18 18:16:19 +00:00
|
|
|
public TableSeat FindEmptySeat()
|
|
|
|
{
|
2024-07-22 00:42:29 +00:00
|
|
|
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;
|
2024-06-18 18:16:19 +00:00
|
|
|
}
|
2024-11-07 06:13:57 +00:00
|
|
|
|
|
|
|
public void Show()
|
|
|
|
{
|
|
|
|
gameObject.SetActive(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void Hide()
|
|
|
|
{
|
|
|
|
gameObject.SetActive(false);
|
|
|
|
}
|
2024-06-18 18:16:19 +00:00
|
|
|
}
|
|
|
|
}
|