175 lines
5.2 KiB
C#
175 lines
5.2 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Linq;
|
|
using BlueWater.Interfaces;
|
|
using BlueWater.Npcs.Crews;
|
|
using BlueWater.Utility;
|
|
using UnityEngine;
|
|
|
|
namespace BlueWater.Tycoons
|
|
{
|
|
[Serializable]
|
|
public class TableSeat : InteractionFurniture, ICrewInteraction
|
|
{
|
|
[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;
|
|
|
|
[field: SerializeField]
|
|
public int TableNumber;
|
|
|
|
[SerializeField]
|
|
private Sprite _foodImage;
|
|
|
|
[SerializeField]
|
|
private Sprite _dirtyImage;
|
|
|
|
[SerializeField]
|
|
private float _interactionHoldingTime = 3f;
|
|
|
|
private Coroutine _findCleanerCrewInstance;
|
|
private bool _isPlayerInteracting;
|
|
private bool _isCrewInteracting;
|
|
private float _playerElapsedTime;
|
|
private float _crewElapsedTime;
|
|
|
|
public event Action OnInteractionCompleted;
|
|
|
|
protected override void OnEnable()
|
|
{
|
|
base.OnEnable();
|
|
|
|
Initialize();
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
if (InteractionCanvas.BalloonUi.IsWaitTimeOver())
|
|
{
|
|
var damageable = GameManager.Instance.CurrentTycoonPlayer.GetComponent<IDamageable>();
|
|
damageable?.TakeDamage(1);
|
|
CleanTable();
|
|
}
|
|
|
|
if (_isPlayerInteracting)
|
|
{
|
|
var clamp = Mathf.Clamp(_playerElapsedTime / _interactionHoldingTime, 0f, 1f);
|
|
EventManager.OnInteracting?.Invoke(clamp);
|
|
if (_playerElapsedTime > _interactionHoldingTime)
|
|
{
|
|
CleanTable();
|
|
}
|
|
|
|
_playerElapsedTime += Time.deltaTime;
|
|
}
|
|
|
|
if (_isCrewInteracting)
|
|
{
|
|
if (_crewElapsedTime > _interactionHoldingTime)
|
|
{
|
|
OnInteractionCompleted?.Invoke();
|
|
CleanTable();
|
|
}
|
|
|
|
_crewElapsedTime += Time.deltaTime;
|
|
}
|
|
}
|
|
|
|
public void Initialize()
|
|
{
|
|
UnreserveSeat();
|
|
VacateSeat();
|
|
CleanTable();
|
|
Food.enabled = false;
|
|
InteractionMessage = "치우기";
|
|
}
|
|
|
|
public void SetTableNumber(int number) => TableNumber = number;
|
|
|
|
public void SetFood(Sprite sprite)
|
|
{
|
|
Food.sprite = _foodImage;
|
|
Food.enabled = true;
|
|
}
|
|
|
|
public override void Interaction()
|
|
{
|
|
_playerElapsedTime = 0f;
|
|
EventManager.OnInteracting?.Invoke(_playerElapsedTime);
|
|
GameManager.Instance.CurrentTycoonPlayer.IsCleaningTable = true;
|
|
_isPlayerInteracting = true;
|
|
}
|
|
|
|
public override void CancelInteraction()
|
|
{
|
|
_playerElapsedTime = 0f;
|
|
EventManager.OnInteracting?.Invoke(_playerElapsedTime);
|
|
GameManager.Instance.CurrentTycoonPlayer.IsCleaningTable = false;
|
|
_isPlayerInteracting = false;
|
|
}
|
|
|
|
public override bool CanInteraction()
|
|
{
|
|
return !GameManager.Instance.CurrentTycoonPlayer.TycoonPickupHandler.IsPickedUpCocktail() && !IsCleaned;
|
|
}
|
|
|
|
public void ReserveSeat() => IsReserved = true;
|
|
public void UnreserveSeat() => IsReserved = false;
|
|
public void OccupySeat() => IsOccupied = true;
|
|
public void VacateSeat() => IsOccupied = false;
|
|
|
|
public void CleanTable()
|
|
{
|
|
Food.sprite = null;
|
|
Food.enabled = false;
|
|
IsCleaned = true;
|
|
_isPlayerInteracting = false;
|
|
InteractionCanvas.BalloonUi.HideUi();
|
|
InteractionCanvas.BalloonUi.ResetUi();
|
|
}
|
|
|
|
public void DirtyTable()
|
|
{
|
|
Food.sprite = _dirtyImage;
|
|
Food.enabled = true;
|
|
InteractionCanvas.BalloonUi.OrderItem(_dirtyImage, 0, TycoonManager.Instance.TycoonStageController.StageDataSo.DirtyTableWaitTime);
|
|
IsCleaned = false;
|
|
|
|
var crewController = TycoonManager.Instance.CrewController;
|
|
Utils.StartUniqueCoroutine(this, ref _findCleanerCrewInstance,
|
|
crewController.FindClosestCrewCoroutine(CenterTransform.position, crewController.CleanerCrews, crew => crew.OnMission(this)));
|
|
}
|
|
|
|
public void InteractionCrew(Crew crew)
|
|
{
|
|
_crewElapsedTime = 0f;
|
|
_isCrewInteracting = true;
|
|
crew.IsCleaningTable = true;
|
|
}
|
|
|
|
public void CancelInteractionCrew()
|
|
{
|
|
_crewElapsedTime = 0f;
|
|
_isCrewInteracting = false;
|
|
}
|
|
|
|
public bool CanInteractionCrew()
|
|
{
|
|
return !_isPlayerInteracting;
|
|
}
|
|
}
|
|
} |