107 lines
3.5 KiB
C#
107 lines
3.5 KiB
C#
using System;
|
|
using BehaviorDesigner.Runtime.Tasks;
|
|
using BlueWater.Items;
|
|
using BlueWater.Npcs.Customers;
|
|
using BlueWater.Uis;
|
|
using UnityEngine;
|
|
using Random = UnityEngine.Random;
|
|
|
|
namespace BlueWater.BehaviorTrees.Actions
|
|
{
|
|
[TaskCategory("Custom/Npc/Customer")]
|
|
[Serializable]
|
|
public class OrderFood : Conditional
|
|
{
|
|
private Customer _customer;
|
|
private CustomerData _customerData;
|
|
private FoodBalloonUi _foodBalloonUi;
|
|
private int _orderFoodIdx;
|
|
|
|
public override void OnAwake()
|
|
{
|
|
_customer = GetComponent<Customer>();
|
|
_customerData = _customer.CustomerData;
|
|
}
|
|
|
|
public override void OnStart()
|
|
{
|
|
var dailyFoodSlotUis = TycoonUiManager.Instance.TycoonManagementUi.CookMenuUi.DailyFoodMenuUi.DailyFoodSlotUis;
|
|
for (var i = 0; i < 3; i++)
|
|
{
|
|
for (var j = 0; j < dailyFoodSlotUis.Count; j++)
|
|
{
|
|
if (dailyFoodSlotUis[j].FoodData.Taste != _customerData.GetPreferredFood(i)) continue;
|
|
|
|
_orderFoodIdx = dailyFoodSlotUis[j].FoodData.Idx;
|
|
break;
|
|
}
|
|
|
|
if (_orderFoodIdx != 0)
|
|
{
|
|
break;
|
|
}
|
|
|
|
if (i == 2)
|
|
{
|
|
var randomIndex = Random.Range(0, dailyFoodSlotUis.Count);
|
|
_orderFoodIdx = dailyFoodSlotUis[randomIndex].FoodData.Idx;
|
|
}
|
|
}
|
|
|
|
_foodBalloonUi = _customer.FoodBalloonUi;
|
|
_foodBalloonUi.OrderFood(_orderFoodIdx, _customerData.WaitTime, _customerData.HurryTime);
|
|
_customer.OnInteraction += HandleFoodInteraction;
|
|
_customer.RegisterPlayerInteraction();
|
|
_customer.Bark("OrderFood");
|
|
}
|
|
|
|
public override TaskStatus OnUpdate()
|
|
{
|
|
if (_foodBalloonUi.IsFoodReceive())
|
|
{
|
|
_customer.OnInteraction -= HandleFoodInteraction;
|
|
_customer.UnregisterPlayerInteraction();
|
|
return TaskStatus.Success;
|
|
}
|
|
|
|
if (_foodBalloonUi.IsWaitTimeOver())
|
|
{
|
|
_customer.OnInteraction -= HandleFoodInteraction;
|
|
_customer.UnregisterPlayerInteraction();
|
|
_customer.AddHappyPoint(-3);
|
|
if (_customer.HappyPoint <= 0)
|
|
{
|
|
_foodBalloonUi.CancelOrder();
|
|
_customer.Bark("CancelOrder");
|
|
}
|
|
return TaskStatus.Failure;
|
|
}
|
|
|
|
return TaskStatus.Running;
|
|
}
|
|
|
|
private void HandleFoodInteraction()
|
|
{
|
|
var tycoonPlayer = GameManager.Instance.CurrentTycoonPlayer;
|
|
var carriedFoodData = tycoonPlayer.GetCurrentItemData();
|
|
if (carriedFoodData == null)
|
|
{
|
|
Debug.Log("플레이어가 가지고 있는 음식의 데이터가 없습니다.");
|
|
return;
|
|
}
|
|
|
|
if (carriedFoodData.Idx == _orderFoodIdx)
|
|
{
|
|
tycoonPlayer.GiveItem();
|
|
_foodBalloonUi.ReceiveFood();
|
|
_customer.SetFood(carriedFoodData);
|
|
if (carriedFoodData.Quality == ItemQuality.High)
|
|
{
|
|
_customer.AddHappyPoint(1);
|
|
}
|
|
|
|
_customer.SpineController.PlayAnimation(CustomerSpineAnimation.Eat2.ToString(), true);
|
|
}
|
|
}
|
|
}
|
|
} |