Client LuaCsForBarotrauma
MissionStateAction.cs
1 namespace Barotrauma
2 {
3 
8  {
9  [Serialize("", IsPropertySaveable.Yes, description: "Identifier of the mission whose state to change.")]
10  public Identifier MissionIdentifier { get; set; }
11 
12  public enum OperationType
13  {
14  Set,
15  Add
16  }
17 
18  [Serialize(OperationType.Set, IsPropertySaveable.Yes, description: "Should the value be added to the state of the mission, or should the state be set to the specified value.")]
19  public OperationType Operation { get; set; }
20 
21  [Serialize(0, IsPropertySaveable.Yes, description: "The state to set the mission to, or how much to add to the state of the mission.")]
22  public int State { get; set; }
23 
24  private bool isFinished;
25 
26  public MissionStateAction(ScriptedEvent parentEvent, ContentXElement element) : base(parentEvent, element)
27  {
28  State = element.GetAttributeInt("value", State);
29  if (MissionIdentifier.IsEmpty)
30  {
31  DebugConsole.ThrowError($"Error in event \"{parentEvent.Prefab.Identifier}\": MissionIdentifier has not been configured.",
32  contentPackage: element.ContentPackage);
33  }
34  }
35 
36  public override bool IsFinished(ref string goTo)
37  {
38  return isFinished;
39  }
40  public override void Reset()
41  {
42  isFinished = false;
43  }
44 
45  public override void Update(float deltaTime)
46  {
47  if (isFinished) { return; }
48 
49  foreach (Mission mission in GameMain.GameSession.Missions)
50  {
51  if (mission.Prefab.Identifier != MissionIdentifier) { continue; }
52  switch (Operation)
53  {
54  case OperationType.Set:
55  mission.State = State;
56  break;
57  case OperationType.Add:
58  mission.State += 1;
59  break;
60  }
61  }
62 
63  isFinished = true;
64  }
65 
66  public override string ToDebugString()
67  {
68  return $"{ToolBox.GetDebugSymbol(isFinished)} {nameof(MissionStateAction)} -> ({(Operation == OperationType.Set ? State : '+' + State)})";
69  }
70  }
71 }
ContentPackage? ContentPackage
int GetAttributeInt(string key, int def)
static GameSession?? GameSession
Definition: GameMain.cs:88
Changes the state of a specific active mission. The way the states are used depends on the type of mi...
override void Update(float deltaTime)
override bool IsFinished(ref string goTo)
Has the action finished.
MissionStateAction(ScriptedEvent parentEvent, ContentXElement element)
override string ToDebugString()
Rich test to display in debugdraw
readonly Identifier Identifier
Definition: Prefab.cs:34