96 lines
3.1 KiB
C#
96 lines
3.1 KiB
C#
using System;
|
|
using BehaviorDesigner.Runtime.Tasks;
|
|
using BlueWater.Npcs.Customers;
|
|
using BlueWater.Uis;
|
|
using PixelCrushers.DialogueSystem;
|
|
using UnityEngine;
|
|
|
|
namespace BlueWater.BehaviorTrees.Actions
|
|
{
|
|
[TaskCategory("Custom/Npc/Customer")]
|
|
[Serializable]
|
|
public class PayMoney : Conditional
|
|
{
|
|
private Customer _customer;
|
|
private CustomerData _customerData;
|
|
private FoodBalloonUi _foodBalloonUi;
|
|
private int _goldIdx;
|
|
private bool _isPaidMoney;
|
|
|
|
public override void OnAwake()
|
|
{
|
|
_customer = GetComponent<Customer>();
|
|
_customerData = _customer.CustomerData;
|
|
}
|
|
|
|
public override void OnStart()
|
|
{
|
|
_foodBalloonUi = _customer.FoodBalloonUi;
|
|
_foodBalloonUi.PayMoney(_customerData.WaitTime, _customerData.HurryTime);
|
|
_customer.OnInteraction += HandlePayMoneyInteraction;
|
|
_customer.RegisterPlayerInteraction();
|
|
}
|
|
|
|
public override TaskStatus OnUpdate()
|
|
{
|
|
if (_isPaidMoney)
|
|
{
|
|
return TaskStatus.Success;
|
|
}
|
|
|
|
if (_foodBalloonUi.IsWaitTimeOver())
|
|
{
|
|
_customer.OnInteraction -= HandlePayMoneyInteraction;
|
|
_customer.UnregisterPlayerInteraction();
|
|
_foodBalloonUi.CancelOrder();
|
|
_foodBalloonUi.HideUi();
|
|
// _customer.AddHappyPoint(-3);
|
|
// if (_customer.HappyPoint <= 0)
|
|
// {
|
|
// _foodBalloonUi.CancelOrder();
|
|
// _customer.Bark("CancelOrder");
|
|
// }
|
|
return TaskStatus.Failure;
|
|
}
|
|
|
|
return TaskStatus.Running;
|
|
}
|
|
|
|
private void HandlePayMoneyInteraction()
|
|
{
|
|
var tycoonPlayer = GameManager.Instance.CurrentTycoonPlayer;
|
|
var foodPrice = _customer.ItemData.Price;
|
|
var tip = 0f;
|
|
string barkName;
|
|
switch (_customer.HappyPoint)
|
|
{
|
|
case >= 3:
|
|
tip = 2f;
|
|
barkName = "SatisfactoryEvaluation";
|
|
break;
|
|
case >= 2:
|
|
tip = 1.5f;
|
|
barkName = "MediocreEvaluation";
|
|
break;
|
|
case >= 1:
|
|
tip = 1.1f;
|
|
barkName = "MediocreEvaluation";
|
|
break;
|
|
default:
|
|
tip = 1f;
|
|
barkName = "UnsatisfactoryEvaluation";
|
|
break;
|
|
}
|
|
var finalPrice = (int)(foodPrice * tip);
|
|
tycoonPlayer.GetMoney(finalPrice);
|
|
_customer.PayMoney(finalPrice);
|
|
_foodBalloonUi.HideUi();
|
|
_customer.OnInteraction -= HandlePayMoneyInteraction;
|
|
_customer.Bark(barkName, BarkOrder.FirstValid);
|
|
_customer.UnregisterPlayerInteraction();
|
|
_foodBalloonUi.CancelOrder();
|
|
|
|
_isPaidMoney = true;
|
|
}
|
|
}
|
|
} |