52 lines
1.5 KiB
C#
52 lines
1.5 KiB
C#
using System;
|
|
using BehaviorDesigner.Runtime.Tasks;
|
|
using BlueWater.Npcs.Customers;
|
|
using BlueWater.Tycoons;
|
|
using UnityEngine;
|
|
using Action = BehaviorDesigner.Runtime.Tasks.Action;
|
|
using Random = UnityEngine.Random;
|
|
|
|
namespace BlueWater.BehaviorTrees.Actions
|
|
{
|
|
[TaskCategory("Custom/Npc/Customer")]
|
|
[Serializable]
|
|
public class Vomit : Action
|
|
{
|
|
private Customer _customer;
|
|
private bool _canVomit;
|
|
private bool _isVomiting;
|
|
private Vector3 _vomitingPosition;
|
|
|
|
public override void OnAwake()
|
|
{
|
|
_customer = GetComponent<Customer>();
|
|
}
|
|
|
|
public override void OnStart()
|
|
{
|
|
var random = Random.Range(0f, 100f);
|
|
if (random <= TycoonManager.Instance.TycoonStageController.StageDataSo.VomitingPercent)
|
|
{
|
|
_canVomit = true;
|
|
_vomitingPosition = _customer.AIMovement.SetRandomPoint();
|
|
_customer.AIMovement.Move(_vomitingPosition);
|
|
}
|
|
}
|
|
|
|
public override TaskStatus OnUpdate()
|
|
{
|
|
if (!_canVomit) return TaskStatus.Success;
|
|
|
|
if (!_customer.AIMovement.HasReachedDestination()) return TaskStatus.Running;
|
|
|
|
if (!_isVomiting)
|
|
{
|
|
_customer.Vomit();
|
|
_isVomiting = true;
|
|
return TaskStatus.Running;
|
|
}
|
|
|
|
return _customer.IsVomited ? TaskStatus.Success : TaskStatus.Running;
|
|
}
|
|
}
|
|
} |