Client LuaCsForBarotrauma
CheckReputationAction.cs
1 #nullable enable
2 using System.Diagnostics;
3 
4 namespace Barotrauma
5 {
10  {
11  [Serialize(ReputationAction.ReputationType.None, IsPropertySaveable.Yes, description: "Should the action check the reputation for a given faction, or whichever faction owns the current location.")]
13 
14  public CheckReputationAction(ScriptedEvent parentEvent, ContentXElement element) : base(parentEvent, element) { }
15 
16  protected override float GetFloat(CampaignMode campaignMode)
17  {
18  switch (TargetType)
19  {
20  case ReputationAction.ReputationType.Faction:
21  {
22  Faction? faction = campaignMode.Factions.Find(f => f.Prefab.Identifier == Identifier);
23  if (faction != null) { return faction.Reputation.Value; }
24  break;
25  }
26  case ReputationAction.ReputationType.Location:
27  {
28  Location? location = campaignMode.Map.CurrentLocation;
29  Debug.Assert(location?.Reputation != null, "location?.Reputation != null");
30  if (location?.Reputation != null) { return location.Reputation.Value; }
31  break;
32  }
33  default:
34  {
35  DebugConsole.ThrowError("CheckReputationAction requires a \"TargetType\" but none were specified.",
36  contentPackage: ParentEvent.Prefab.ContentPackage);
37  break;
38  }
39  }
40 
41  return 0.0f;
42  }
43 
44  protected override bool GetBool(CampaignMode campaignMode)
45  {
46  DebugConsole.ThrowError("Boolean comparison cannot be applied to reputations.",
47  contentPackage: ParentEvent.Prefab.ContentPackage);
48  return false;
49  }
50 
51  public override string ToDebugString()
52  {
53  string condition = "?";
54  if (value2 != null && value1 != null)
55  {
56  condition = $"{value1.ColorizeObject()} {Operator.ColorizeObject()} {value2.ColorizeObject()}";
57  }
58 
59  return $"{ToolBox.GetDebugSymbol(succeeded.HasValue)} {nameof(CheckReputationAction)} -> (Type: {TargetType.ColorizeObject()}, " +
60  $"{(Identifier.IsEmpty ? string.Empty : $"Identifier: {Identifier.ColorizeObject()}, ")}" +
61  $"Success: {succeeded.ColorizeObject()}, Expression: {condition})";
62  }
63  }
64 }
Can be used to check arbitrary campaign metadata set using SetDataAction.
Check whether the reputation of the crew for a specific faction meets some criteria (e....
override string ToDebugString()
Rich test to display in debugdraw
override bool GetBool(CampaignMode campaignMode)
ReputationAction.ReputationType TargetType
CheckReputationAction(ScriptedEvent parentEvent, ContentXElement element)
override float GetFloat(CampaignMode campaignMode)
readonly ScriptedEvent ParentEvent
Definition: EventAction.cs:106
EventPrefab Prefab
Definition: Event.cs:16
Reputation Reputation
Definition: Factions.cs:17
Reputation Reputation
Definition: Location.cs:106
ContentPackage? ContentPackage
Definition: Prefab.cs:37
Adjusts the crew's reputation by some value.
float??????? Value
Definition: Reputation.cs:44