106 lines
3.8 KiB
C#
106 lines
3.8 KiB
C#
using System;
|
|
using BlueWater.Interfaces;
|
|
using BlueWater.Npcs.Crews;
|
|
using BlueWater.Utility;
|
|
using UnityEngine;
|
|
|
|
namespace BlueWater.Tycoons
|
|
{
|
|
public class ServingTable : InteractionFurniture, ICrewInteraction
|
|
{
|
|
[SerializeField]
|
|
private SpriteRenderer _cocktailGlassImage;
|
|
|
|
// 서빙 테이블 기준 아이템이 있는지 없는지
|
|
private IPickup _currentPickupItem;
|
|
public IPickup CurrentPickupItem
|
|
{
|
|
get => _currentPickupItem;
|
|
set
|
|
{
|
|
_currentPickupItem = value;
|
|
|
|
if (_currentPickupItem != null)
|
|
{
|
|
var crewController = TycoonManager.Instance.CrewController;
|
|
Utils.StartUniqueCoroutine(this, ref _findServerCrewInstance,
|
|
crewController.FindClosestCrewCoroutine(CenterTransform.position, crewController.ServerCrews, crew => crew.OnMission(this)));
|
|
}
|
|
}
|
|
}
|
|
|
|
private Material _originalCocktailGlassMaterial;
|
|
private Coroutine _findServerCrewInstance;
|
|
|
|
protected override void Awake()
|
|
{
|
|
base.Awake();
|
|
|
|
_originalCocktailGlassMaterial = _cocktailGlassImage.material;
|
|
}
|
|
|
|
public override void Interaction()
|
|
{
|
|
// 테이블의 칵테일을 가져가는 경우
|
|
if (CurrentPickupItem != null)
|
|
{
|
|
EventManager.InvokeTakeFromServingTable();
|
|
CurrentTycoonPlayer.TycoonPickupHandler.PickupItem(CurrentPickupItem);
|
|
CurrentTycoonPlayer.InteractionCanvas.BalloonUi.SetItemImage(CurrentPickupItem);
|
|
_cocktailGlassImage.enabled = false;
|
|
InteractionCanvas.BalloonUi.DiscardItem();
|
|
CurrentPickupItem = null;
|
|
}
|
|
// 테이블에 칵테일을 놓는 경우
|
|
else
|
|
{
|
|
EventManager.InvokePlaceOnServingTable();
|
|
CurrentPickupItem = CurrentTycoonPlayer.TycoonPickupHandler.GetCurrentPickupItem();
|
|
CurrentTycoonPlayer.TycoonPickupHandler.GiveItem(CurrentPickupItem);
|
|
CurrentTycoonPlayer.InteractionCanvas.BalloonUi.DiscardItem();
|
|
InteractionCanvas.BalloonUi.SetItemImage(CurrentPickupItem);
|
|
_cocktailGlassImage.enabled = true;
|
|
}
|
|
}
|
|
|
|
public override bool CanInteraction()
|
|
{
|
|
// 1. 테이블에 칵테일이 있고, 플레이어가 칵테일을 들고 있지 않은 경우
|
|
// 2. 테이블에 칵테일이 없고, 플레이어가 칵테일을 들고 있는 경우 (정상적인 칵테일만)
|
|
return (CurrentPickupItem != null && !CurrentTycoonPlayer.TycoonPickupHandler.IsPickedUpCocktail())||
|
|
(CurrentPickupItem == null && CurrentTycoonPlayer.TycoonPickupHandler.IsServablePickupItem());
|
|
}
|
|
|
|
public override void ShowInteractionUi()
|
|
{
|
|
InteractionMessage = CurrentPickupItem != null ? "음료 들기" : "음료 내려놓기";
|
|
base.ShowInteractionUi();
|
|
|
|
_cocktailGlassImage.material = OutlineMaterial;
|
|
}
|
|
|
|
public override void HideInteractionUi()
|
|
{
|
|
base.HideInteractionUi();
|
|
|
|
_cocktailGlassImage.material = _originalCocktailGlassMaterial;
|
|
}
|
|
|
|
public void InteractionCrew(Crew crew)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
public void CancelInteractionCrew()
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
public bool CanInteractionCrew()
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
public event Action OnInteractionCompleted;
|
|
}
|
|
} |