Client LuaCsForBarotrauma
CheckOrderAction.cs
2 
3 namespace Barotrauma
4 {
9  {
10  public enum OrderPriority
11  {
12  Top,
13  Any
14  }
15 
16  [Serialize("", IsPropertySaveable.Yes, description: "Tag of the character to check.")]
17  public Identifier TargetTag { get; set; }
18 
19  [Serialize("", IsPropertySaveable.Yes, description: "Identifier of the order the target character must have.")]
20  public Identifier OrderIdentifier { get; set; }
21 
22  [Serialize("", IsPropertySaveable.Yes, description: "The option that must be selected for the order. If the order has multiple options (such as turning on or turning off a reactor).")]
23  public Identifier OrderOption { get; set; }
24 
25  [Serialize("", IsPropertySaveable.Yes, description: "Tag of the entity the order must be targeting. Only valid for orders that can target a specific entity (such as orders to operate a specific turret).")]
26  public Identifier OrderTargetTag { get; set; }
27 
28  [Serialize(OrderPriority.Any, IsPropertySaveable.Yes, description: "Does the order need to have top priority, or is any priority fine?")]
29  public OrderPriority Priority { get; set; }
30 
31  public CheckOrderAction(ScriptedEvent parentEvent, ContentXElement element) : base(parentEvent, element) { }
32 
33  protected override bool? DetermineSuccess()
34  {
35  var targetCharacters = ParentEvent.GetTargets(TargetTag);
36  if (targetCharacters.None())
37  {
38  DebugConsole.LogError($"CheckConditionalAction error: {GetEventName()} uses a CheckOrderAction but no valid target characters were found for tag \"{TargetTag}\"! This will cause the check to automatically fail.",
39  contentPackage: ParentEvent.Prefab.ContentPackage);
40  return false;
41  }
42  foreach (var t in targetCharacters)
43  {
44  if (t is not Character c)
45  {
46  continue;
47  }
48  if (Priority == OrderPriority.Top)
49  {
50  if (c.GetCurrentOrderWithTopPriority() is Order topPrioOrder && IsMatch(topPrioOrder))
51  {
52  return true;
53  }
54  }
55  else if (Priority == OrderPriority.Any)
56  {
57  foreach (var order in c.CurrentOrders)
58  {
59  if (IsMatch(order))
60  {
61  return true;
62  }
63  }
64  }
65 
66  bool IsMatch(Order order)
67  {
68  if (order?.Identifier == OrderIdentifier)
69  {
70  if (!OrderTargetTag.IsEmpty && (order.TargetEntity is not Item targetItem || !targetItem.HasTag(OrderTargetTag)))
71  {
72  return false;
73  }
74  if (OrderOption.IsEmpty || order?.Option == OrderOption)
75  {
76  return true;
77  }
78  }
79  return false;
80  }
81  }
82  return false;
83  }
84 
85  private string GetEventName()
86  {
87  return ParentEvent?.Prefab?.Identifier is { IsEmpty: false } identifier ? $"the event \"{identifier}\"" : "an unknown event";
88  }
89  }
90 }
Check whether a specific character has been given a specific order.
CheckOrderAction(ScriptedEvent parentEvent, ContentXElement element)
override? bool DetermineSuccess()
readonly ScriptedEvent ParentEvent
Definition: EventAction.cs:102
EventPrefab Prefab
Definition: Event.cs:16
readonly Entity TargetEntity
Definition: Order.cs:495
readonly Identifier Option
Definition: Order.cs:482
ContentPackage? ContentPackage
Definition: Prefab.cs:37
readonly Identifier Identifier
Definition: Prefab.cs:34
IEnumerable< Entity > GetTargets(Identifier tag)