Client LuaCsForBarotrauma
ReputationAction.cs
1 namespace Barotrauma
2 {
7  {
8  public enum ReputationType
9  {
10  None,
11  Location,
12  Faction
13  }
14 
15  public ReputationAction(ScriptedEvent parentEvent, ContentXElement element) : base(parentEvent, element) { }
16 
17  [Serialize(0.0f, IsPropertySaveable.Yes, description: "Amount of reputation to add or remove.")]
18  public float Increase { get; set; }
19 
20  [Serialize("", IsPropertySaveable.Yes, description: "Identifier of the faction you want to adjust the reputation for. Ignored if TargetType is set to Location.")]
21  public Identifier Identifier { get; set; }
22 
23  [Serialize(ReputationType.None, IsPropertySaveable.Yes, description: "Do you want to adjust the reputation for a specific faction, or whichever faction controls the current location?")]
24  public ReputationType TargetType { get; set; }
25 
26  private bool isFinished;
27 
28  public override bool IsFinished(ref string goTo)
29  {
30  return isFinished;
31  }
32  public override void Reset()
33  {
34  isFinished = false;
35  }
36 
37  public override void Update(float deltaTime)
38  {
39  if (isFinished) { return; }
40 
41  if (GameMain.GameSession?.GameMode is CampaignMode campaign)
42  {
43  switch (TargetType)
44  {
45  case ReputationType.Faction:
46  {
47  Faction faction = campaign.Factions.Find(faction1 => faction1.Prefab.Identifier == Identifier);
48  if (faction != null)
49  {
51  }
52  else
53  {
54  DebugConsole.ThrowError($"Faction with the identifier \"{Identifier}\" was not found.",
55  contentPackage: ParentEvent.Prefab.ContentPackage);
56  }
57 
58  break;
59  }
60  case ReputationType.Location:
61  {
62  campaign.Map.CurrentLocation?.Reputation?.AddReputation(Increase);
63  break;
64  }
65  default:
66  {
67  DebugConsole.ThrowError("ReputationAction requires a \"TargetType\" but none were specified.",
68  contentPackage: ParentEvent.Prefab.ContentPackage);
69  break;
70  }
71  }
72  }
73 
74  isFinished = true;
75  }
76 
77  public override string ToDebugString()
78  {
79  return $"{ToolBox.GetDebugSymbol(isFinished)} {nameof(ReputationAction)} -> (FactionIdentifier: {Identifier.ColorizeObject()}, TargetType: {TargetType.ColorizeObject()}, Increase: {Increase.ColorizeObject()})";
80  }
81  }
82 }
readonly ScriptedEvent ParentEvent
Definition: EventAction.cs:106
EventPrefab Prefab
Definition: Event.cs:16
Reputation Reputation
Definition: Factions.cs:17
static GameSession?? GameSession
Definition: GameMain.cs:88
ContentPackage? ContentPackage
Definition: Prefab.cs:37
Adjusts the crew's reputation by some value.
override void Update(float deltaTime)
ReputationAction(ScriptedEvent parentEvent, ContentXElement element)
override bool IsFinished(ref string goTo)
Has the action finished.
override string ToDebugString()
Rich test to display in debugdraw
void AddReputation(float reputationChange, float maxReputationChangePerRound=float.MaxValue)
Definition: Reputation.cs:95