2024-06-18 18:16:19 +00:00
|
|
|
using System;
|
2024-10-14 11:13:08 +00:00
|
|
|
using System.Collections;
|
|
|
|
using System.Linq;
|
2024-10-06 23:41:09 +00:00
|
|
|
using BlueWater.Interfaces;
|
2024-10-14 11:13:08 +00:00
|
|
|
using BlueWater.Npcs.Crews;
|
2024-10-22 12:41:31 +00:00
|
|
|
using BlueWater.Npcs.Crews.Cleaner;
|
2024-10-14 11:13:08 +00:00
|
|
|
using BlueWater.Utility;
|
2024-06-18 18:16:19 +00:00
|
|
|
using UnityEngine;
|
|
|
|
|
2024-07-02 18:27:56 +00:00
|
|
|
namespace BlueWater.Tycoons
|
2024-06-18 18:16:19 +00:00
|
|
|
{
|
|
|
|
[Serializable]
|
2024-10-14 11:13:08 +00:00
|
|
|
public class TableSeat : InteractionFurniture, ICrewInteraction
|
2024-06-18 18:16:19 +00:00
|
|
|
{
|
|
|
|
[field: SerializeField]
|
|
|
|
public bool IsOccupied { get; private set; }
|
|
|
|
|
|
|
|
[field: SerializeField]
|
|
|
|
public bool IsReserved { get; private set; }
|
|
|
|
|
|
|
|
[field: SerializeField]
|
|
|
|
public bool IsCleaned { get; private set; } = true;
|
|
|
|
|
|
|
|
[field: SerializeField]
|
|
|
|
public Transform SeatTransform { get; private set; }
|
|
|
|
|
|
|
|
[field: SerializeField]
|
|
|
|
public SpriteRenderer Food { get; private set; }
|
|
|
|
|
|
|
|
[field: SerializeField]
|
|
|
|
public Vector3 TableDirection;
|
2024-10-06 23:41:09 +00:00
|
|
|
|
2024-10-08 13:44:20 +00:00
|
|
|
[field: SerializeField]
|
|
|
|
public int TableNumber;
|
|
|
|
|
2024-10-06 23:41:09 +00:00
|
|
|
[SerializeField]
|
|
|
|
private Sprite _foodImage;
|
|
|
|
|
|
|
|
[SerializeField]
|
|
|
|
private Sprite _dirtyImage;
|
2024-10-14 11:13:08 +00:00
|
|
|
|
|
|
|
[SerializeField]
|
|
|
|
private float _interactionHoldingTime = 3f;
|
2024-10-06 23:41:09 +00:00
|
|
|
|
2024-10-14 11:13:08 +00:00
|
|
|
private Coroutine _findCleanerCrewInstance;
|
|
|
|
private bool _isPlayerInteracting;
|
|
|
|
private bool _isCrewInteracting;
|
|
|
|
private float _playerElapsedTime;
|
|
|
|
private float _crewElapsedTime;
|
|
|
|
|
|
|
|
public event Action OnInteractionCompleted;
|
2024-10-06 23:41:09 +00:00
|
|
|
|
|
|
|
protected override void OnEnable()
|
|
|
|
{
|
|
|
|
base.OnEnable();
|
|
|
|
|
|
|
|
Initialize();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void Update()
|
|
|
|
{
|
2024-10-14 11:13:08 +00:00
|
|
|
if (InteractionCanvas.BalloonUi.IsWaitTimeOver())
|
|
|
|
{
|
|
|
|
var damageable = GameManager.Instance.CurrentTycoonPlayer.GetComponent<IDamageable>();
|
|
|
|
damageable?.TakeDamage(1);
|
|
|
|
CleanTable();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_isPlayerInteracting)
|
2024-10-06 23:41:09 +00:00
|
|
|
{
|
2024-10-14 11:13:08 +00:00
|
|
|
if (_playerElapsedTime > _interactionHoldingTime)
|
2024-10-06 23:41:09 +00:00
|
|
|
{
|
|
|
|
CleanTable();
|
|
|
|
}
|
2024-10-14 11:13:08 +00:00
|
|
|
|
|
|
|
_playerElapsedTime += Time.deltaTime;
|
|
|
|
}
|
2024-10-24 08:05:32 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
if (_playerElapsedTime > 0f)
|
|
|
|
{
|
|
|
|
_playerElapsedTime -= Time.deltaTime;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var holdingGauge = 0f;
|
|
|
|
if (_playerElapsedTime > 0f)
|
|
|
|
{
|
|
|
|
holdingGauge = Mathf.Clamp(_playerElapsedTime / _interactionHoldingTime, 0f, 1f);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (IsShowing)
|
|
|
|
{
|
|
|
|
EventManager.InvokeHoldInteracting(holdingGauge);
|
|
|
|
}
|
2024-10-14 11:13:08 +00:00
|
|
|
|
|
|
|
if (_isCrewInteracting)
|
|
|
|
{
|
|
|
|
if (_crewElapsedTime > _interactionHoldingTime)
|
2024-10-06 23:41:09 +00:00
|
|
|
{
|
2024-10-14 11:13:08 +00:00
|
|
|
OnInteractionCompleted?.Invoke();
|
2024-10-22 12:41:31 +00:00
|
|
|
OnInteractionCompleted = null;
|
2024-10-06 23:41:09 +00:00
|
|
|
CleanTable();
|
|
|
|
}
|
|
|
|
|
2024-10-14 11:13:08 +00:00
|
|
|
_crewElapsedTime += Time.deltaTime;
|
2024-10-06 23:41:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void Initialize()
|
|
|
|
{
|
|
|
|
UnreserveSeat();
|
|
|
|
VacateSeat();
|
|
|
|
CleanTable();
|
|
|
|
Food.enabled = false;
|
|
|
|
InteractionMessage = "치우기";
|
|
|
|
}
|
|
|
|
|
2024-10-08 13:44:20 +00:00
|
|
|
public void SetTableNumber(int number) => TableNumber = number;
|
|
|
|
|
2024-10-22 12:41:31 +00:00
|
|
|
public void SetFood()
|
2024-10-06 23:41:09 +00:00
|
|
|
{
|
|
|
|
Food.sprite = _foodImage;
|
|
|
|
Food.enabled = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public override void Interaction()
|
|
|
|
{
|
2024-10-20 17:21:39 +00:00
|
|
|
GameManager.Instance.CurrentTycoonPlayer.IsCleaningTable = true;
|
2024-10-14 11:13:08 +00:00
|
|
|
_isPlayerInteracting = true;
|
2024-10-06 23:41:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public override void CancelInteraction()
|
|
|
|
{
|
2024-10-20 17:21:39 +00:00
|
|
|
GameManager.Instance.CurrentTycoonPlayer.IsCleaningTable = false;
|
2024-10-14 11:13:08 +00:00
|
|
|
_isPlayerInteracting = false;
|
2024-10-06 23:41:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public override bool CanInteraction()
|
|
|
|
{
|
|
|
|
return !GameManager.Instance.CurrentTycoonPlayer.TycoonPickupHandler.IsPickedUpCocktail() && !IsCleaned;
|
|
|
|
}
|
2024-06-18 18:16:19 +00:00
|
|
|
|
|
|
|
public void ReserveSeat() => IsReserved = true;
|
|
|
|
public void UnreserveSeat() => IsReserved = false;
|
|
|
|
public void OccupySeat() => IsOccupied = true;
|
|
|
|
public void VacateSeat() => IsOccupied = false;
|
|
|
|
|
2024-10-06 23:41:09 +00:00
|
|
|
public void CleanTable()
|
2024-06-18 18:16:19 +00:00
|
|
|
{
|
2024-10-06 23:41:09 +00:00
|
|
|
Food.sprite = null;
|
|
|
|
Food.enabled = false;
|
|
|
|
IsCleaned = true;
|
2024-10-14 11:13:08 +00:00
|
|
|
_isPlayerInteracting = false;
|
2024-10-22 12:41:31 +00:00
|
|
|
_isCrewInteracting = false;
|
2024-10-06 23:41:09 +00:00
|
|
|
InteractionCanvas.BalloonUi.HideUi();
|
2024-10-14 11:13:08 +00:00
|
|
|
InteractionCanvas.BalloonUi.ResetUi();
|
2024-10-24 08:05:32 +00:00
|
|
|
_playerElapsedTime = 0f;
|
2024-06-18 18:16:19 +00:00
|
|
|
}
|
|
|
|
|
2024-10-06 23:41:09 +00:00
|
|
|
public void DirtyTable()
|
2024-06-18 18:16:19 +00:00
|
|
|
{
|
2024-10-06 23:41:09 +00:00
|
|
|
Food.sprite = _dirtyImage;
|
|
|
|
Food.enabled = true;
|
|
|
|
InteractionCanvas.BalloonUi.OrderItem(_dirtyImage, 0, TycoonManager.Instance.TycoonStageController.StageDataSo.DirtyTableWaitTime);
|
|
|
|
IsCleaned = false;
|
2024-10-14 11:13:08 +00:00
|
|
|
|
2024-10-15 18:01:16 +00:00
|
|
|
var crewController = TycoonManager.Instance.CrewController;
|
|
|
|
Utils.StartUniqueCoroutine(this, ref _findCleanerCrewInstance,
|
|
|
|
crewController.FindClosestCrewCoroutine(CenterTransform.position, crewController.CleanerCrews, crew => crew.OnMission(this)));
|
2024-10-14 11:13:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void InteractionCrew(Crew crew)
|
|
|
|
{
|
|
|
|
_crewElapsedTime = 0f;
|
|
|
|
_isCrewInteracting = true;
|
2024-10-22 12:41:31 +00:00
|
|
|
((CleanerCrew)crew).SetIsCleaningTable(true);
|
2024-10-14 11:13:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void CancelInteractionCrew()
|
|
|
|
{
|
|
|
|
_crewElapsedTime = 0f;
|
|
|
|
_isCrewInteracting = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public bool CanInteractionCrew()
|
|
|
|
{
|
|
|
|
return !_isPlayerInteracting;
|
2024-06-18 18:16:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|