Client LuaCsForBarotrauma
RNGAction.cs
1 namespace Barotrauma
2 {
7  {
8  [Serialize(0.0f, IsPropertySaveable.Yes, description: "The probability of executing the Success actions. A value between 0-1.")]
9  public float Chance { get; set; }
10 
11  public RNGAction(ScriptedEvent parentEvent, ContentXElement element) : base(parentEvent, element)
12  {
13  if (Chance >= 1.0f)
14  {
15  DebugConsole.ThrowError($"Incorrectly configured RNG Action in event \"{parentEvent.Prefab.Identifier}\". Probability is 1.0 (100%) or more, the action will always succeed.",
16  contentPackage: element.ContentPackage);
17  }
18  else if (Chance <= 0.0f)
19  {
20  DebugConsole.ThrowError($"Incorrectly configured RNG Action in event \"{parentEvent.Prefab.Identifier}\". Probability is 0 or less, the action will never succeed.",
21  contentPackage: element.ContentPackage);
22  }
23  }
24 
25  private bool isFinished;
26 
27  protected override bool? DetermineSuccess()
28  {
29  isFinished = true;
30  return Rand.Range(0.0, 1.0) <= Chance;
31  }
32 
33  public override string ToDebugString()
34  {
35  return $"{ToolBox.GetDebugSymbol(isFinished)} {nameof(RNGAction)} -> (Chance: {Chance.ColorizeObject()}, "+
36  $"Succeeded: {succeeded.ColorizeObject()})";
37  }
38  }
39 }
ContentPackage? ContentPackage
Randomly executes either of the child actions (Success or Failure).
Definition: RNGAction.cs:7
override string ToDebugString()
Rich test to display in debugdraw
Definition: RNGAction.cs:33
RNGAction(ScriptedEvent parentEvent, ContentXElement element)
Definition: RNGAction.cs:11
override? bool DetermineSuccess()
Definition: RNGAction.cs:27