84 lines
2.8 KiB
C#
84 lines
2.8 KiB
C#
![]() |
using System;
|
||
|
using BehaviorDesigner.Runtime.Tasks;
|
||
|
using BlueWater.Items;
|
||
|
using BlueWater.Npcs.Customers;
|
||
|
using BlueWater.Players.Tycoons;
|
||
|
using BlueWater.Tycoons;
|
||
|
using BlueWater.Uis;
|
||
|
using PixelCrushers.DialogueSystem;
|
||
|
using UnityEngine;
|
||
|
|
||
|
namespace BlueWater.BehaviorTrees.Actions
|
||
|
{
|
||
|
[TaskCategory("Custom/Npc/Customer")]
|
||
|
[Serializable]
|
||
|
public class OrderCocktail : Conditional
|
||
|
{
|
||
|
private Customer _customer;
|
||
|
private LevelData _levelData;
|
||
|
private BalloonUi _customerBalloonUi;
|
||
|
private CocktailData _orderedCocktail;
|
||
|
|
||
|
private bool _isReceived;
|
||
|
private bool _isSucceed;
|
||
|
|
||
|
public override void OnAwake()
|
||
|
{
|
||
|
_customer = GetComponent<Customer>();
|
||
|
}
|
||
|
|
||
|
public override void OnStart()
|
||
|
{
|
||
|
_levelData = _customer.LevelData;
|
||
|
_customerBalloonUi = _customer.BalloonUi;
|
||
|
|
||
|
_orderedCocktail = TycoonManager.Instance.TycoonIngredientController.GetRandomCocktailData();
|
||
|
Debug.Log($"_orderedCocktail : {_orderedCocktail.Idx}");
|
||
|
_customerBalloonUi.OrderItem(_orderedCocktail.Idx, _levelData.WaitTime, _levelData.HurryTime);
|
||
|
_customer.OnInteraction += HandleCocktailInteraction;
|
||
|
_customer.RegisterPlayerInteraction();
|
||
|
// _customer.Bark("OrderBeverage", BarkOrder.FirstValid);
|
||
|
}
|
||
|
|
||
|
public override TaskStatus OnUpdate()
|
||
|
{
|
||
|
if (_customerBalloonUi.IsWaitTimeOver())
|
||
|
{
|
||
|
_customer.OnInteraction -= HandleCocktailInteraction;
|
||
|
_customer.UnregisterPlayerInteraction();
|
||
|
return TaskStatus.Failure;
|
||
|
}
|
||
|
|
||
|
if (!_isReceived) return TaskStatus.Running;
|
||
|
|
||
|
_customer.OnInteraction -= HandleCocktailInteraction;
|
||
|
if (_isSucceed)
|
||
|
{
|
||
|
_customer.UnregisterPlayerInteraction();
|
||
|
return TaskStatus.Success;
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
return TaskStatus.Failure;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
private void HandleCocktailInteraction()
|
||
|
{
|
||
|
var currentPickupItem = GameManager.Instance.CurrentTycoonPlayer.TycoonPickupHandler.GetCurrentPickupItem();
|
||
|
if (currentPickupItem == null)
|
||
|
{
|
||
|
Debug.Log("플레이어가 가지고 있는 음식의 데이터가 없습니다.");
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
var servedCocktailData = ItemManager.Instance.CocktailDataSo.GetDataByIdx(currentPickupItem.Idx);
|
||
|
EventManager.OnCocktailServedToCustomer?.Invoke(servedCocktailData);
|
||
|
_customer.ServedItem(servedCocktailData);
|
||
|
_customerBalloonUi.ReceiveFood(servedCocktailData);
|
||
|
_isSucceed = currentPickupItem.Idx == _orderedCocktail.Idx;
|
||
|
|
||
|
_isReceived = true;
|
||
|
}
|
||
|
}
|
||
|
}
|