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.Uis;
|
|
using UnityEngine;
|
|
|
|
namespace BlueWater.BehaviorTrees.Actions
|
|
{
|
|
[TaskCategory("Custom/Npc/Customer")]
|
|
[Serializable]
|
|
public class OrderBeverage : Conditional
|
|
{
|
|
private Customer _customer;
|
|
private CustomerData _customerData;
|
|
private FoodBalloonUi _foodBalloonUi;
|
|
|
|
public override void OnAwake()
|
|
{
|
|
_customer = GetComponent<Customer>();
|
|
_customerData = _customer.CustomerData;
|
|
}
|
|
|
|
public override void OnStart()
|
|
{
|
|
_foodBalloonUi = _customer.FoodBalloonUi;
|
|
// TODO : 음료가 다양해질 때 수정해야함
|
|
_foodBalloonUi.OrderFood(40001, _customerData.WaitTime, _customerData.HurryTime);
|
|
|
|
_customer.OnInteraction += HandleBeverageInteraction;
|
|
_customer.RegisterPlayerInteraction();
|
|
_customer.Bark("OrderBeverage");
|
|
}
|
|
|
|
public override TaskStatus OnUpdate()
|
|
{
|
|
if (_foodBalloonUi.IsFoodReceive())
|
|
{
|
|
_customer.OnInteraction -= HandleBeverageInteraction;
|
|
_customer.UnregisterPlayerInteraction();
|
|
return TaskStatus.Success;
|
|
}
|
|
|
|
if (_foodBalloonUi.IsWaitTimeOver())
|
|
{
|
|
_customer.OnInteraction -= HandleBeverageInteraction;
|
|
_customer.UnregisterPlayerInteraction();
|
|
_customer.AddHappyPoint(-3);
|
|
if (_customer.HappyPoint <= 0)
|
|
{
|
|
_foodBalloonUi.CancelOrder();
|
|
_customer.Bark("CancelOrder");
|
|
}
|
|
return TaskStatus.Failure;
|
|
}
|
|
|
|
return TaskStatus.Running;
|
|
}
|
|
|
|
private void HandleBeverageInteraction()
|
|
{
|
|
var tycoonPlayer = GameManager.Instance.CurrentTycoonPlayer;
|
|
var carriedBeverageData = tycoonPlayer.GetCurrentItemData();
|
|
if (carriedBeverageData == null)
|
|
{
|
|
Debug.Log("플레이어가 가지고 있는 음식의 데이터가 없습니다.");
|
|
return;
|
|
}
|
|
|
|
// TODO : 음료가 다양해질 때 수정해야함
|
|
if (carriedBeverageData.Idx == 40001)
|
|
{
|
|
tycoonPlayer.GiveItem();
|
|
_foodBalloonUi.ReceiveFood();
|
|
_customer.SetFood(carriedBeverageData);
|
|
if (carriedBeverageData.Quality == ItemQuality.High)
|
|
{
|
|
_customer.AddHappyPoint(1);
|
|
}
|
|
_customer.SpineController.PlayAnimation(CustomerSpineAnimation.Eat.ToString(), true);
|
|
}
|
|
}
|
|
}
|
|
} |