mirror of
https://github.com/tym1116/BH3.git
synced 2025-12-19 09:54:46 +01:00
50 lines
1.1 KiB
C#
50 lines
1.1 KiB
C#
using System;
|
|
|
|
namespace BehaviorDesigner.Runtime.Tasks
|
|
{
|
|
[TaskDescription("The random probability task will return success when the random probability is above the succeed probability. It will otherwise return failure.")]
|
|
[HelpURL("http://www.opsive.com/assets/BehaviorDesigner/documentation.php?id=33")]
|
|
public class RandomProbability : Conditional
|
|
{
|
|
[Tooltip("The chance that the task will return success")]
|
|
public SharedFloat successProbability = 0.5f;
|
|
|
|
[Tooltip("Seed the random number generator to make things easier to debug")]
|
|
public SharedInt seed;
|
|
|
|
[Tooltip("Do we want to use the seed?")]
|
|
public SharedBool useSeed;
|
|
|
|
private Random random;
|
|
|
|
public override void OnAwake()
|
|
{
|
|
if (useSeed.Value)
|
|
{
|
|
random = new Random(seed.Value);
|
|
}
|
|
else
|
|
{
|
|
random = new Random();
|
|
}
|
|
}
|
|
|
|
public override TaskStatus OnUpdate()
|
|
{
|
|
float num = (float)random.NextDouble();
|
|
if (num < successProbability.Value)
|
|
{
|
|
return TaskStatus.Success;
|
|
}
|
|
return TaskStatus.Failure;
|
|
}
|
|
|
|
public override void OnReset()
|
|
{
|
|
successProbability = 0.5f;
|
|
seed = 0;
|
|
useSeed = false;
|
|
}
|
|
}
|
|
}
|