2024-06-18 18:16:19 +00:00
|
|
|
using System;
|
|
|
|
using BehaviorDesigner.Runtime.Tasks;
|
2024-07-06 12:13:58 +00:00
|
|
|
using BlueWater.Items;
|
2024-06-18 18:16:19 +00:00
|
|
|
using BlueWater.Npcs.Customers;
|
2024-07-02 18:27:56 +00:00
|
|
|
using BlueWater.Uis;
|
2024-07-06 12:13:58 +00:00
|
|
|
using PixelCrushers.DialogueSystem;
|
2024-07-02 18:27:56 +00:00
|
|
|
using UnityEngine;
|
2024-06-18 18:16:19 +00:00
|
|
|
using Action = BehaviorDesigner.Runtime.Tasks.Action;
|
|
|
|
|
|
|
|
namespace BlueWater.BehaviorTrees.Actions
|
|
|
|
{
|
|
|
|
[TaskCategory("Custom/Npc/Customer")]
|
|
|
|
[Serializable]
|
|
|
|
public class OrderFood : Action
|
|
|
|
{
|
|
|
|
private Customer _customer;
|
2024-07-06 12:13:58 +00:00
|
|
|
private CustomerData _customerData;
|
2024-06-18 18:16:19 +00:00
|
|
|
private FoodBalloonUi _foodBalloonUi;
|
2024-07-02 18:27:56 +00:00
|
|
|
private int _orderFoodIdx;
|
2024-06-18 18:16:19 +00:00
|
|
|
|
|
|
|
public override void OnAwake()
|
|
|
|
{
|
|
|
|
_customer = GetComponent<Customer>();
|
2024-07-06 12:13:58 +00:00
|
|
|
_customerData = _customer.CustomerData;
|
2024-06-18 18:16:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public override void OnStart()
|
|
|
|
{
|
|
|
|
_foodBalloonUi = _customer.FoodBalloonUi;
|
2024-07-02 18:27:56 +00:00
|
|
|
_orderFoodIdx = 40001;
|
2024-07-06 12:13:58 +00:00
|
|
|
_foodBalloonUi.OrderFood(_orderFoodIdx, _customerData.WaitTime, _customerData.HurryTime);
|
2024-07-02 18:27:56 +00:00
|
|
|
|
|
|
|
_customer.OnInteraction += HandleFoodInteraction;
|
|
|
|
_customer.RegisterPlayerInteraction();
|
2024-07-06 12:13:58 +00:00
|
|
|
DialogueManager.Bark("OrderFood", _customer.transform);
|
2024-06-18 18:16:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public override TaskStatus OnUpdate()
|
|
|
|
{
|
|
|
|
if (_foodBalloonUi.IsFoodReceive())
|
|
|
|
{
|
2024-07-02 18:27:56 +00:00
|
|
|
_customer.OnInteraction -= HandleFoodInteraction;
|
|
|
|
_customer.UnregisterPlayerInteraction();
|
2024-06-18 18:16:19 +00:00
|
|
|
return TaskStatus.Success;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_foodBalloonUi.IsWaitTimeOver())
|
|
|
|
{
|
|
|
|
_foodBalloonUi.CancelOrder();
|
2024-07-02 18:27:56 +00:00
|
|
|
_customer.OnInteraction -= HandleFoodInteraction;
|
|
|
|
_customer.UnregisterPlayerInteraction();
|
2024-06-18 18:16:19 +00:00
|
|
|
return TaskStatus.Failure;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TaskStatus.Running;
|
|
|
|
}
|
2024-07-02 18:27:56 +00:00
|
|
|
|
|
|
|
private void HandleFoodInteraction()
|
|
|
|
{
|
|
|
|
var tycoonPlayer = GameManager.Instance.CurrentTycoonPlayer;
|
2024-07-08 20:06:22 +00:00
|
|
|
var carriedFoodData = tycoonPlayer.GetCurrentItemData();
|
2024-07-02 18:27:56 +00:00
|
|
|
if (carriedFoodData == null)
|
|
|
|
{
|
|
|
|
Debug.Log("플레이어가 가지고 있는 음식의 데이터가 없습니다.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (carriedFoodData.Idx == _orderFoodIdx)
|
|
|
|
{
|
2024-07-08 20:06:22 +00:00
|
|
|
tycoonPlayer.GiveItem();
|
2024-07-02 18:27:56 +00:00
|
|
|
_foodBalloonUi.ReceiveFood();
|
|
|
|
_customer.SetFood(carriedFoodData);
|
2024-07-06 12:13:58 +00:00
|
|
|
if (carriedFoodData.Quality == ItemQuality.High)
|
|
|
|
{
|
|
|
|
_customer.AddHappyPoint(1);
|
|
|
|
}
|
2024-07-02 18:27:56 +00:00
|
|
|
// TODO : 음식을 테이블에 깔고 먹는 행동
|
|
|
|
}
|
|
|
|
}
|
2024-06-18 18:16:19 +00:00
|
|
|
}
|
|
|
|
}
|