2024-07-20 11:32:54 +00:00
|
|
|
using System;
|
|
|
|
using BehaviorDesigner.Runtime.Tasks;
|
|
|
|
using BlueWater.Npcs.Customers;
|
|
|
|
using BlueWater.Uis;
|
|
|
|
using PixelCrushers.DialogueSystem;
|
|
|
|
|
|
|
|
namespace BlueWater.BehaviorTrees.Actions
|
|
|
|
{
|
|
|
|
[TaskCategory("Custom/Npc/Customer")]
|
|
|
|
[Serializable]
|
|
|
|
public class PayMoney : Conditional
|
|
|
|
{
|
|
|
|
private Customer _customer;
|
|
|
|
private CustomerData _customerData;
|
2024-09-10 10:25:05 +00:00
|
|
|
private BalloonUi _balloonUi;
|
2024-07-20 11:32:54 +00:00
|
|
|
private int _goldIdx;
|
|
|
|
private bool _isPaidMoney;
|
|
|
|
|
|
|
|
public override void OnAwake()
|
|
|
|
{
|
|
|
|
_customer = GetComponent<Customer>();
|
|
|
|
_customerData = _customer.CustomerData;
|
|
|
|
}
|
|
|
|
|
|
|
|
public override void OnStart()
|
|
|
|
{
|
2024-09-10 10:25:05 +00:00
|
|
|
_balloonUi = _customer.BalloonUi;
|
|
|
|
_balloonUi.PayMoney(_customerData.WaitTime, _customerData.HurryTime);
|
2024-07-20 11:32:54 +00:00
|
|
|
_customer.OnInteraction += HandlePayMoneyInteraction;
|
|
|
|
_customer.RegisterPlayerInteraction();
|
|
|
|
}
|
|
|
|
|
|
|
|
public override TaskStatus OnUpdate()
|
|
|
|
{
|
|
|
|
if (_isPaidMoney)
|
|
|
|
{
|
|
|
|
return TaskStatus.Success;
|
|
|
|
}
|
|
|
|
|
2024-09-10 10:25:05 +00:00
|
|
|
if (_balloonUi.IsWaitTimeOver())
|
2024-07-20 11:32:54 +00:00
|
|
|
{
|
|
|
|
_customer.OnInteraction -= HandlePayMoneyInteraction;
|
|
|
|
_customer.UnregisterPlayerInteraction();
|
2024-09-10 10:25:05 +00:00
|
|
|
_balloonUi.CancelOrder();
|
|
|
|
_balloonUi.HideUi();
|
2024-07-20 11:32:54 +00:00
|
|
|
// _customer.AddHappyPoint(-3);
|
|
|
|
// if (_customer.HappyPoint <= 0)
|
|
|
|
// {
|
|
|
|
// _foodBalloonUi.CancelOrder();
|
|
|
|
// _customer.Bark("CancelOrder");
|
|
|
|
// }
|
|
|
|
return TaskStatus.Failure;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TaskStatus.Running;
|
|
|
|
}
|
|
|
|
|
2024-07-20 18:55:30 +00:00
|
|
|
private void HandlePayMoneyInteraction()
|
2024-07-20 11:32:54 +00:00
|
|
|
{
|
|
|
|
var tycoonPlayer = GameManager.Instance.CurrentTycoonPlayer;
|
|
|
|
var foodPrice = _customer.ItemData.Price;
|
2024-07-22 00:42:29 +00:00
|
|
|
float tipCoefficient;
|
2024-07-20 18:55:30 +00:00
|
|
|
string barkName;
|
|
|
|
switch (_customer.HappyPoint)
|
2024-07-20 11:32:54 +00:00
|
|
|
{
|
2024-07-20 18:55:30 +00:00
|
|
|
case >= 3:
|
2024-07-22 00:42:29 +00:00
|
|
|
tipCoefficient = 2f;
|
2024-07-20 18:55:30 +00:00
|
|
|
barkName = "SatisfactoryEvaluation";
|
|
|
|
break;
|
|
|
|
case >= 2:
|
2024-07-22 00:42:29 +00:00
|
|
|
tipCoefficient = 1.5f;
|
2024-07-20 18:55:30 +00:00
|
|
|
barkName = "MediocreEvaluation";
|
|
|
|
break;
|
|
|
|
case >= 1:
|
2024-07-22 00:42:29 +00:00
|
|
|
tipCoefficient = 1.1f;
|
2024-07-20 18:55:30 +00:00
|
|
|
barkName = "MediocreEvaluation";
|
|
|
|
break;
|
|
|
|
default:
|
2024-07-22 00:42:29 +00:00
|
|
|
tipCoefficient = 1f;
|
2024-07-20 18:55:30 +00:00
|
|
|
barkName = "UnsatisfactoryEvaluation";
|
|
|
|
break;
|
|
|
|
}
|
2024-07-22 00:42:29 +00:00
|
|
|
|
|
|
|
var tipAmount = foodPrice * (int)tipCoefficient;
|
|
|
|
var paidAmount = foodPrice + tipAmount;
|
|
|
|
tycoonPlayer.GetMoney(paidAmount);
|
|
|
|
_customer.PayMoney(foodPrice, tipAmount);
|
2024-09-10 10:25:05 +00:00
|
|
|
_balloonUi.HideUi();
|
2024-07-20 11:32:54 +00:00
|
|
|
_customer.OnInteraction -= HandlePayMoneyInteraction;
|
2024-07-20 18:55:30 +00:00
|
|
|
_customer.Bark(barkName, BarkOrder.FirstValid);
|
2024-07-20 11:32:54 +00:00
|
|
|
_customer.UnregisterPlayerInteraction();
|
2024-09-10 10:25:05 +00:00
|
|
|
_balloonUi.CancelOrder();
|
2024-07-20 11:32:54 +00:00
|
|
|
|
|
|
|
_isPaidMoney = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|