CapersProject/Assets/02.Scripts/Prop/Tycoon/ServingTable.cs

167 lines
6.4 KiB
C#
Raw Normal View History

2024-10-15 18:01:16 +00:00
using System;
2024-10-20 17:21:39 +00:00
using System.Collections;
2024-09-23 02:00:21 +00:00
using BlueWater.Interfaces;
2024-10-15 18:01:16 +00:00
using BlueWater.Npcs.Crews;
2024-10-22 12:41:31 +00:00
using BlueWater.Npcs.Crews.Server;
2024-10-20 17:21:39 +00:00
using BlueWater.Npcs.Customers;
2024-10-15 18:01:16 +00:00
using BlueWater.Utility;
2024-09-23 02:00:21 +00:00
using UnityEngine;
2024-10-20 17:21:39 +00:00
using UnityEngine.Serialization;
2024-09-23 02:00:21 +00:00
namespace BlueWater.Tycoons
{
2024-10-15 18:01:16 +00:00
public class ServingTable : InteractionFurniture, ICrewInteraction
2024-09-23 02:00:21 +00:00
{
2024-10-20 17:21:39 +00:00
[FormerlySerializedAs("_cocktailGlassImage")]
2024-09-23 02:00:21 +00:00
[SerializeField]
2024-10-20 17:21:39 +00:00
protected SpriteRenderer CocktailGlassImage;
2024-09-23 02:00:21 +00:00
2024-09-24 10:35:49 +00:00
// 서빙 테이블 기준 아이템이 있는지 없는지
2024-09-23 02:00:21 +00:00
private IPickup _currentPickupItem;
2024-10-15 18:01:16 +00:00
public IPickup CurrentPickupItem
{
get => _currentPickupItem;
set
{
_currentPickupItem = value;
if (_currentPickupItem != null)
{
2024-10-20 17:21:39 +00:00
Utils.StartUniqueCoroutine(this, ref _findCustomerMatchingItemInstance, FindCustomerMatchingItem());
}
else
{
if (_findCustomerMatchingItemInstance != null)
{
StopCoroutine(_findCustomerMatchingItemInstance);
_findCustomerMatchingItemInstance = null;
}
if (_findServerCrewInstance != null)
{
StopCoroutine(_findServerCrewInstance);
_findServerCrewInstance = null;
}
2024-10-15 18:01:16 +00:00
}
}
}
2024-10-27 09:44:22 +00:00
protected Customer OrderedCustomer;
2024-09-23 02:00:21 +00:00
private Material _originalCocktailGlassMaterial;
2024-10-20 17:21:39 +00:00
private Coroutine _findCustomerMatchingItemInstance;
2024-10-15 18:01:16 +00:00
private Coroutine _findServerCrewInstance;
2024-10-20 17:21:39 +00:00
public event Action OnInteractionCompleted;
2024-09-23 02:00:21 +00:00
protected override void Awake()
{
base.Awake();
2024-10-20 17:21:39 +00:00
_originalCocktailGlassMaterial = CocktailGlassImage.material;
2024-09-23 02:00:21 +00:00
}
public override void Interaction()
{
// 테이블의 칵테일을 가져가는 경우
2024-10-15 18:01:16 +00:00
if (CurrentPickupItem != null)
2024-09-23 02:00:21 +00:00
{
2024-10-15 18:01:16 +00:00
CurrentTycoonPlayer.TycoonPickupHandler.PickupItem(CurrentPickupItem);
CurrentTycoonPlayer.InteractionCanvas.BalloonUi.SetItemImage(CurrentPickupItem);
2024-10-20 17:21:39 +00:00
CocktailGlassImage.enabled = false;
2024-09-26 11:50:39 +00:00
InteractionCanvas.BalloonUi.DiscardItem();
2024-10-15 18:01:16 +00:00
CurrentPickupItem = null;
2024-10-27 09:44:22 +00:00
OrderedCustomer = null;
2024-09-23 02:00:21 +00:00
}
// 테이블에 칵테일을 놓는 경우
else
{
2024-10-10 09:32:18 +00:00
EventManager.InvokePlaceOnServingTable();
2024-10-15 18:01:16 +00:00
CurrentPickupItem = CurrentTycoonPlayer.TycoonPickupHandler.GetCurrentPickupItem();
InteractionCanvas.BalloonUi.SetItemImage(CurrentPickupItem);
2024-10-27 09:44:22 +00:00
CurrentTycoonPlayer.TycoonPickupHandler.DiscardItem();
CurrentTycoonPlayer.InteractionCanvas.BalloonUi.DiscardItem();
2024-10-20 17:21:39 +00:00
CocktailGlassImage.enabled = true;
2024-09-23 02:00:21 +00:00
}
}
public override bool CanInteraction()
{
// 1. 테이블에 칵테일이 있고, 플레이어가 칵테일을 들고 있지 않은 경우
// 2. 테이블에 칵테일이 없고, 플레이어가 칵테일을 들고 있는 경우 (정상적인 칵테일만)
2024-10-22 12:41:31 +00:00
return (CurrentPickupItem != null && !CurrentTycoonPlayer.TycoonPickupHandler.IsPickedUpCocktail()) ||
2024-10-15 18:01:16 +00:00
(CurrentPickupItem == null && CurrentTycoonPlayer.TycoonPickupHandler.IsServablePickupItem());
2024-09-23 02:00:21 +00:00
}
public override void ShowInteractionUi()
{
2024-10-15 18:01:16 +00:00
InteractionMessage = CurrentPickupItem != null ? "음료 들기" : "음료 내려놓기";
2024-09-24 10:35:49 +00:00
base.ShowInteractionUi();
2024-09-23 02:00:21 +00:00
2024-10-20 17:21:39 +00:00
CocktailGlassImage.material = OutlineMaterial;
2024-09-23 02:00:21 +00:00
}
public override void HideInteractionUi()
{
2024-09-24 10:35:49 +00:00
base.HideInteractionUi();
2024-09-23 02:00:21 +00:00
2024-10-20 17:21:39 +00:00
CocktailGlassImage.material = _originalCocktailGlassMaterial;
2024-09-23 02:00:21 +00:00
}
2024-10-15 18:01:16 +00:00
public void InteractionCrew(Crew crew)
{
2024-10-27 09:44:22 +00:00
// 종업원이 테이블의 칵테일을 가져가는 경우
2024-10-20 17:21:39 +00:00
if (CurrentPickupItem != null)
{
var serverCrew = (ServerCrew)crew;
2024-10-27 09:44:22 +00:00
serverCrew.TakeFromServingTable(CurrentPickupItem, OrderedCustomer);
2024-10-20 17:21:39 +00:00
CocktailGlassImage.enabled = false;
InteractionCanvas.BalloonUi.DiscardItem();
CurrentPickupItem = null;
2024-10-27 09:44:22 +00:00
OrderedCustomer = null;
2024-10-20 17:21:39 +00:00
}
2024-10-27 09:44:22 +00:00
// 종업원이 테이블에 칵테일을 놓는 경우
2024-10-20 17:21:39 +00:00
else
{
var serverCrew = (ServerCrew)crew;
CurrentPickupItem = serverCrew.CurrentPickupItem;
CocktailGlassImage.enabled = true;
InteractionCanvas.BalloonUi.SetItemImage(CurrentPickupItem);
serverCrew.ResetMission();
}
2024-10-15 18:01:16 +00:00
}
public void CancelInteractionCrew()
{
throw new NotImplementedException();
}
2024-10-27 09:44:22 +00:00
public virtual bool CanInteractionCrew(Crew crew = null)
2024-10-15 18:01:16 +00:00
{
2024-10-27 09:44:22 +00:00
var servingCrew = (ServerCrew)crew;
if (!servingCrew)
{
throw new Exception("상호작용 오브젝트 오류");
}
return (servingCrew.CurrentActionType == ActionType.TakeCocktail && CurrentPickupItem != null && OrderedCustomer) ||
servingCrew.CurrentActionType == ActionType.PlaceOnServingTable && CurrentPickupItem == null;
2024-10-15 18:01:16 +00:00
}
2024-10-20 17:21:39 +00:00
private IEnumerator FindCustomerMatchingItem()
{
var waitTime = new WaitForSeconds(2f);
while (true)
{
2024-10-27 09:44:22 +00:00
OrderedCustomer = TycoonManager.Instance.CustomerController.FindCustomerMatchingItem(_currentPickupItem);
if (OrderedCustomer && OrderedCustomer.CanInteractionCrew())
2024-10-20 17:21:39 +00:00
{
var crewController = TycoonManager.Instance.CrewController;
Utils.StartUniqueCoroutine(this, ref _findServerCrewInstance,
2024-10-27 09:44:22 +00:00
crewController.FindClosestCrewCoroutine(CenterTransform.position, crewController.ServerCrews,
crew => crew.OnMission(this, OrderedCustomer, ActionType.TakeCocktail)));
2024-10-20 17:21:39 +00:00
}
yield return waitTime;
}
}
2024-09-23 02:00:21 +00:00
}
}