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  if (Operation == OperationType.Add && State == 0)
35  {
36  DebugConsole.AddWarning($"Potential error in event \"{parentEvent.Prefab.Identifier}\": {nameof(MissionStateAction)} is set to add 0 to the mission state, which will do nothing.",
37  contentPackage: element.ContentPackage);
38  }
39  }
40 
41  public override bool IsFinished(ref string goTo)
42  {
43  return isFinished;
44  }
45  public override void Reset()
46  {
47  isFinished = false;
48  }
49 
50  public override void Update(float deltaTime)
51  {
52  if (isFinished) { return; }
53 
54  foreach (Mission mission in GameMain.GameSession.Missions)
55  {
56  if (mission.Prefab.Identifier != MissionIdentifier) { continue; }
57  switch (Operation)
58  {
59  case OperationType.Set:
60  mission.State = State;
61  break;
62  case OperationType.Add:
63  mission.State += State;
64  break;
65  }
66  }
67 
68  isFinished = true;
69  }
70 
71  public override string ToDebugString()
72  {
73  return $"{ToolBox.GetDebugSymbol(isFinished)} {nameof(MissionStateAction)} -> ({(Operation == OperationType.Set ? State : '+' + State)})";
74  }
75  }
76 }
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