Client LuaCsForBarotrauma
BinaryOptionAction.cs
1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 
5 namespace Barotrauma
6 {
7  abstract class BinaryOptionAction : EventAction
8  {
9  public SubactionGroup Success = null;
10  public SubactionGroup Failure = null;
11  protected bool? succeeded = null;
12 
13  public BinaryOptionAction(ScriptedEvent parentEvent, ContentXElement element) : base(parentEvent, element)
14  {
15  foreach (var elem in element.Elements())
16  {
17  string elemName = elem.Name.LocalName;
18  if (elemName.Equals("success", StringComparison.InvariantCultureIgnoreCase))
19  {
20  Success ??= new SubactionGroup(ParentEvent, elem);
21  }
22  else if (elemName.Equals("failure", StringComparison.InvariantCultureIgnoreCase))
23  {
24  Failure ??= new SubactionGroup(ParentEvent, elem);
25  }
26  }
27  }
28 
29  public override IEnumerable<EventAction> GetSubActions()
30  {
31  IEnumerable<EventAction> actions = Success?.Actions ?? Enumerable.Empty<EventAction>();
32  actions = actions.Concat(Failure?.Actions ?? Enumerable.Empty<EventAction>());
33  return actions;
34  }
35 
36  public override bool IsFinished(ref string goTo)
37  {
38  return DetermineFinished(ref goTo);
39  }
40 
41  protected bool DetermineFinished()
42  {
43  string throwaway = null;
44  return DetermineFinished(ref throwaway);
45  }
46 
47  protected bool DetermineFinished(ref string goTo)
48  {
49  if (succeeded.HasValue)
50  {
51  if (succeeded.Value)
52  {
53  if (Success == null || Success.IsFinished(ref goTo))
54  {
55  return true;
56  }
57  }
58  else
59  {
60  if (Failure == null || Failure.IsFinished(ref goTo))
61  {
62  return true;
63  }
64  }
65  }
66  return false;
67  }
68 
69  protected bool HasBeenDetermined()
70  {
71  return succeeded.HasValue;
72  }
73 
74  public override bool SetGoToTarget(string goTo)
75  {
76  if (Success != null && Success.SetGoToTarget(goTo))
77  {
78  succeeded = true;
79  return true;
80  }
81  else if (Failure != null && Failure.SetGoToTarget(goTo))
82  {
83  succeeded = false;
84  return true;
85  }
86  return false;
87  }
88 
89  public override void Reset()
90  {
91  Success?.Reset();
92  Failure?.Reset();
93  succeeded = null;
94  }
95 
96  public override void Update(float deltaTime)
97  {
98  if (succeeded.HasValue)
99  {
100  if (succeeded.Value)
101  {
102  Success?.Update(deltaTime);
103  }
104  else
105  {
106  Failure?.Update(deltaTime);
107  }
108  }
109  else
110  {
112  }
113  }
114 
115  protected abstract bool? DetermineSuccess();
116  }
117 }
bool DetermineFinished(ref string goTo)
override IEnumerable< EventAction > GetSubActions()
override void Update(float deltaTime)
override bool IsFinished(ref string goTo)
Has the action finished.
abstract ? bool DetermineSuccess()
override bool SetGoToTarget(string goTo)
BinaryOptionAction(ScriptedEvent parentEvent, ContentXElement element)
bool IsFinished(ref string goTo)
Definition: EventAction.cs:52
readonly ScriptedEvent ParentEvent
Definition: EventAction.cs:106