Client LuaCsForBarotrauma
CheckMissionAction.cs
1 using System;
2 using System.Linq;
3 
4 namespace Barotrauma;
5 
9 class CheckMissionAction : BinaryOptionAction
10 {
11  public enum MissionType
12  {
13  Current,
14  Selected,
15  Available
16  }
17 
18  [Serialize(MissionType.Current, IsPropertySaveable.Yes, description: "Does the mission need to be currently active, selected for the next round or available.")]
19  public MissionType Type { get; set; }
20 
21  [Serialize("", IsPropertySaveable.Yes, description: "Identifier of the mission.")]
22  public Identifier MissionIdentifier { get; set; }
23 
24  [Serialize("", IsPropertySaveable.Yes, description: "Tag of the mission. Ignored if MissionIdentifier is set.")]
25  public Identifier MissionTag { get; set; }
26 
27  [Serialize(1, IsPropertySaveable.Yes, description: "Minimum number of matching missions for the check to succeed.")]
28  public int MissionCount { get; set; }
29 
30  public CheckMissionAction(ScriptedEvent parentEvent, ContentXElement element) : base(parentEvent, element)
31  {
32  MissionCount = Math.Max(MissionCount, 0);
33  }
34 
35  protected override bool? DetermineSuccess()
36  {
37  var missions = Type switch
38  {
39  MissionType.Current => GameMain.GameSession?.Missions,
40  MissionType.Selected => GameMain.GameSession?.Campaign?.Missions,
41  MissionType.Available => GameMain.GameSession?.Map?.CurrentLocation?.AvailableMissions,
42  _ => null
43  };
44  if (missions is not null)
45  {
46  if (!MissionIdentifier.IsEmpty)
47  {
48  return missions.Any(m => m.Prefab.Identifier == MissionIdentifier);
49  }
50  else if (!MissionTag.IsEmpty)
51  {
52  return missions.Count(m => m.Prefab.Tags.Contains(MissionTag.Value)) >= MissionCount;
53  }
54  else
55  {
56  return missions.Count() >= MissionCount;
57  }
58  }
59  return MissionIdentifier.IsEmpty && MissionTag.IsEmpty && MissionCount == 0;
60  }
61 }
Check whether a specific mission is currently active, selected for the next round or available.
override? bool DetermineSuccess()
Identifier MissionIdentifier
CheckMissionAction(ScriptedEvent parentEvent, ContentXElement element)