238 lines
7.1 KiB
C#
238 lines
7.1 KiB
C#
using System;
|
|
using BlueWater.Interfaces;
|
|
using BlueWater.Npcs.Crews;
|
|
using BlueWater.Npcs.Crews.Cleaner;
|
|
using BlueWater.Uis;
|
|
using BlueWater.Utility;
|
|
using UnityEngine;
|
|
|
|
namespace BlueWater.Tycoons
|
|
{
|
|
[Serializable]
|
|
public class TableSeat : InteractionFurniture, ICrewInteraction
|
|
{
|
|
[SerializeField]
|
|
private PayMoneyUi _payMoneyUiObject;
|
|
|
|
[SerializeField]
|
|
private Vector3 _offset = new(0f, 1.5f, 0f);
|
|
|
|
[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 float _playerHoldingTime = 3f;
|
|
|
|
[SerializeField]
|
|
private float _crewHoldingTime = 9f;
|
|
|
|
private LevelData _currentLevelData;
|
|
private Sprite _fullBeerGlass;
|
|
private Sprite _emptyBeerGlass;
|
|
private Coroutine _findCleanerCrewInstance;
|
|
private bool _isPlayerInteracting;
|
|
private bool _isCrewInteracting;
|
|
|
|
public event Action OnInteractionCompleted;
|
|
|
|
protected override void OnEnable()
|
|
{
|
|
base.OnEnable();
|
|
|
|
Initialize();
|
|
}
|
|
|
|
protected override void Start()
|
|
{
|
|
base.Start();
|
|
|
|
EventManager.OnCleaningAll += Cleaning;
|
|
|
|
_fullBeerGlass = DataManager.Instance.SpriteDataSo.FullBeerGlass;
|
|
_emptyBeerGlass = DataManager.Instance.SpriteDataSo.EmptyBeerGlass;
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
if (InteractionCanvas.BalloonUi.IsWaitTimeOver())
|
|
{
|
|
var damageable = GameManager.Instance.CurrentTycoonPlayer.GetComponent<IDamageable>();
|
|
damageable?.TakeDamage(1);
|
|
CleanTable();
|
|
}
|
|
|
|
if (IsCleaned) return;
|
|
|
|
if (IsShowing)
|
|
{
|
|
EventManager.InvokeHoldInteracting(HoldingElapsedTime);
|
|
}
|
|
|
|
if (HoldingElapsedTime >= 1f)
|
|
{
|
|
if (_isPlayerInteracting)
|
|
{
|
|
if (TycoonManager.Instance.TycoonStatus.CurrentPassiveCard == PassiveCard.CleaningBonus)
|
|
{
|
|
TycoonManager.Instance.TycoonStageController.CleaningBonus();
|
|
}
|
|
|
|
var tip = (int)(_currentLevelData.Gold * TycoonManager.Instance.TycoonStatus.TipMultiplier);
|
|
if (tip > 0)
|
|
{
|
|
var payMoneyUi = Instantiate(_payMoneyUiObject, transform.position + _offset,
|
|
Quaternion.identity, TycoonUiManager.Instance.WorldCanvas.transform);
|
|
payMoneyUi.Initialize(tip);
|
|
}
|
|
}
|
|
|
|
if (_isCrewInteracting)
|
|
{
|
|
OnInteractionCompleted?.Invoke();
|
|
OnInteractionCompleted = null;
|
|
}
|
|
|
|
CleanTable();
|
|
}
|
|
|
|
if (_isPlayerInteracting)
|
|
{
|
|
HoldingElapsedTime += Time.deltaTime / _playerHoldingTime;
|
|
}
|
|
if (_isCrewInteracting)
|
|
{
|
|
HoldingElapsedTime += Time.deltaTime / (_crewHoldingTime - TycoonManager.Instance.TycoonStatus.CleanerCleaningReduction);
|
|
}
|
|
|
|
if (!_isPlayerInteracting && !_isCrewInteracting)
|
|
{
|
|
if (HoldingElapsedTime > 0f)
|
|
{
|
|
HoldingElapsedTime -= Time.deltaTime;
|
|
}
|
|
}
|
|
}
|
|
|
|
private void OnDestroy()
|
|
{
|
|
EventManager.OnCleaningAll -= Cleaning;
|
|
}
|
|
|
|
public void Initialize()
|
|
{
|
|
UnreserveSeat();
|
|
VacateSeat();
|
|
CleanTable();
|
|
Food.enabled = false;
|
|
InteractionMessage = "치우기";
|
|
}
|
|
|
|
public void SetTableNumber(int number) => TableNumber = number;
|
|
|
|
public void SetFood()
|
|
{
|
|
Food.sprite = _fullBeerGlass;
|
|
Food.enabled = true;
|
|
}
|
|
|
|
public override void Interaction()
|
|
{
|
|
GameManager.Instance.CurrentTycoonPlayer.IsCleaningTable = true;
|
|
_isPlayerInteracting = true;
|
|
}
|
|
|
|
public override void CancelInteraction()
|
|
{
|
|
GameManager.Instance.CurrentTycoonPlayer.IsCleaningTable = false;
|
|
_isPlayerInteracting = false;
|
|
}
|
|
|
|
public override bool CanInteraction()
|
|
{
|
|
return !GameManager.Instance.CurrentTycoonPlayer.TycoonPickupHandler.IsPickedUpAnything() && !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;
|
|
_isCrewInteracting = false;
|
|
InteractionCanvas.BalloonUi.HideUi();
|
|
InteractionCanvas.BalloonUi.ResetUi();
|
|
HoldingElapsedTime = 0f;
|
|
}
|
|
|
|
public void DirtyTable()
|
|
{
|
|
_currentLevelData = TycoonManager.Instance.GetCurrentLevelData();
|
|
Food.sprite = _emptyBeerGlass;
|
|
Food.enabled = true;
|
|
InteractionCanvas.BalloonUi.OrderItem(DataManager.Instance.SpriteDataSo.Cleaning, 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 Purify()
|
|
{
|
|
if (IsCleaned)
|
|
{
|
|
Food.sprite = null;
|
|
Food.enabled = false;
|
|
}
|
|
|
|
UnreserveSeat();
|
|
VacateSeat();
|
|
}
|
|
|
|
public void InteractionCrew(Crew crew)
|
|
{
|
|
_isCrewInteracting = true;
|
|
((CleanerCrew)crew).SetIsCleaningTable(true);
|
|
}
|
|
|
|
public void CancelInteractionCrew()
|
|
{
|
|
_isCrewInteracting = false;
|
|
}
|
|
|
|
public bool CanInteractionCrew(Crew crew = null)
|
|
{
|
|
return !IsCleaned;
|
|
}
|
|
|
|
public void Cleaning()
|
|
{
|
|
if (IsCleaned) return;
|
|
|
|
CleanTable();
|
|
}
|
|
}
|
|
} |