2024-07-20 11:32:54 +00:00
|
|
|
using System.Collections;
|
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-07-20 11:32:54 +00:00
|
|
|
public class CustomerTable : InteractionFurniture
|
2024-06-18 18:16:19 +00:00
|
|
|
{
|
|
|
|
[SerializeField]
|
|
|
|
private List<TableSeat> _tableSeats;
|
2024-07-22 00:42:29 +00:00
|
|
|
|
2024-07-20 11:32:54 +00:00
|
|
|
private TycoonManager _tycoonManager;
|
2024-07-22 00:42:29 +00:00
|
|
|
private TableSeat _tableSeat;
|
|
|
|
private Random _random = new();
|
|
|
|
private bool _isCleaning;
|
2024-06-18 18:16:19 +00:00
|
|
|
|
2024-07-20 11:32:54 +00:00
|
|
|
protected override void OnEnable()
|
2024-06-18 18:16:19 +00:00
|
|
|
{
|
2024-07-20 11:32:54 +00:00
|
|
|
base.OnEnable();
|
|
|
|
|
|
|
|
_tycoonManager = TycoonManager.Instance;
|
|
|
|
_tycoonManager.CustomerTableController.RegisterTable(this);
|
2024-06-18 18:16:19 +00:00
|
|
|
}
|
|
|
|
|
2024-07-20 11:32:54 +00:00
|
|
|
protected override void OnDisable()
|
2024-06-18 18:16:19 +00:00
|
|
|
{
|
2024-07-20 11:32:54 +00:00
|
|
|
base.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
|
|
|
|
|
|
|
public override void Interaction()
|
|
|
|
{
|
|
|
|
StartCoroutine(CleanUpTable(_tableSeat));
|
|
|
|
}
|
|
|
|
|
|
|
|
public override bool CanInteraction()
|
|
|
|
{
|
|
|
|
if (_isCleaning) return false;
|
|
|
|
|
|
|
|
_tableSeat = _tableSeats.Find(table => !table.IsOccupied && !table.IsCleaned);
|
|
|
|
if (_tableSeat == null) return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
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-07-20 11:32:54 +00:00
|
|
|
|
|
|
|
private IEnumerator CleanUpTable(TableSeat tableSeat)
|
|
|
|
{
|
|
|
|
// TODO : n초간 테이블 청소 애니메이션 (청소 중에 키 작동 금지)
|
|
|
|
_isCleaning = true;
|
|
|
|
PlayerInputKeyManager.Instance.DisableCurrentPlayerInput();
|
|
|
|
|
|
|
|
var elapsedTime = 0f;
|
|
|
|
while (elapsedTime <= 2f)
|
|
|
|
{
|
|
|
|
elapsedTime += Time.deltaTime;
|
|
|
|
yield return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
tableSeat.CleanUpFood();
|
|
|
|
PlayerInputKeyManager.Instance.EnableCurrentPlayerInput();
|
|
|
|
_isCleaning = false;
|
|
|
|
}
|
2024-06-18 18:16:19 +00:00
|
|
|
}
|
|
|
|
}
|