75 lines
2.2 KiB
C#
75 lines
2.2 KiB
C#
using System;
|
|
using BehaviorDesigner.Runtime.Tasks;
|
|
using BlueWater.Npcs.Customers;
|
|
using BlueWater.Uis;
|
|
using UnityEngine;
|
|
using Action = BehaviorDesigner.Runtime.Tasks.Action;
|
|
|
|
namespace BlueWater.BehaviorTrees.Actions
|
|
{
|
|
[TaskCategory("Custom/Npc/Customer")]
|
|
[Serializable]
|
|
public class OrderFood : Action
|
|
{
|
|
private Customer _customer;
|
|
private FoodBalloonUi _foodBalloonUi;
|
|
private int _orderFoodIdx;
|
|
|
|
public override void OnAwake()
|
|
{
|
|
_customer = GetComponent<Customer>();
|
|
}
|
|
|
|
public override void OnStart()
|
|
{
|
|
_foodBalloonUi = _customer.FoodBalloonUi;
|
|
_orderFoodIdx = 40001;
|
|
_foodBalloonUi.OrderFood(_orderFoodIdx, 15f);
|
|
|
|
_customer.OnInteraction += HandleFoodInteraction;
|
|
_customer.RegisterPlayerInteraction();
|
|
}
|
|
|
|
public override TaskStatus OnUpdate()
|
|
{
|
|
if (_foodBalloonUi.IsFoodReceive())
|
|
{
|
|
_customer.OnInteraction -= HandleFoodInteraction;
|
|
_customer.UnregisterPlayerInteraction();
|
|
return TaskStatus.Success;
|
|
}
|
|
|
|
if (_foodBalloonUi.IsWaitTimeOver())
|
|
{
|
|
_foodBalloonUi.CancelOrder();
|
|
_customer.OnInteraction -= HandleFoodInteraction;
|
|
_customer.UnregisterPlayerInteraction();
|
|
return TaskStatus.Failure;
|
|
}
|
|
|
|
return TaskStatus.Running;
|
|
}
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
private void HandleFoodInteraction()
|
|
{
|
|
var tycoonPlayer = GameManager.Instance.CurrentTycoonPlayer;
|
|
var carriedFoodData = tycoonPlayer.GetCurrentFoodData();
|
|
if (carriedFoodData == null)
|
|
{
|
|
Debug.Log("플레이어가 가지고 있는 음식의 데이터가 없습니다.");
|
|
return;
|
|
}
|
|
|
|
if (carriedFoodData.Idx == _orderFoodIdx)
|
|
{
|
|
tycoonPlayer.GiveFood();
|
|
_foodBalloonUi.ReceiveFood();
|
|
_customer.SetFood(carriedFoodData);
|
|
// TODO : 음식을 테이블에 깔고 먹는 행동
|
|
}
|
|
}
|
|
}
|
|
} |