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-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-20 11:32:54 +00:00
|
|
|
|
|
|
|
private bool _isCleaning;
|
|
|
|
private TableSeat _tableSeat;
|
|
|
|
private TycoonManager _tycoonManager;
|
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()
|
|
|
|
{
|
|
|
|
return _tableSeats.FirstOrDefault(tableSeat => !tableSeat.IsReserved && !tableSeat.IsOccupied && tableSeat.IsCleaned);
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
}
|