Client LuaCsForBarotrauma
CharacterAbilityGiveReputation.cs
1 #nullable enable
2 
3 namespace Barotrauma.Abilities
4 {
5  internal sealed class CharacterAbilityGiveReputation : CharacterAbility
6  {
7  private readonly Identifier factionIdentifier;
8  private readonly float amount;
9 
10  public CharacterAbilityGiveReputation(CharacterAbilityGroup characterAbilityGroup, ContentXElement abilityElement) : base(characterAbilityGroup, abilityElement)
11  {
12  factionIdentifier = abilityElement.GetAttributeIdentifier("identifier", Identifier.Empty);
13  amount = abilityElement.GetAttributeFloat("amount", 0f);
14  if (factionIdentifier.IsEmpty)
15  {
16  DebugConsole.ThrowError($"Error in talent {CharacterTalent.DebugIdentifier}, faction identifier not defined.",
17  contentPackage: abilityElement.ContentPackage);
18  }
19  if (amount == 0)
20  {
21  DebugConsole.ThrowError($"Error in talent {CharacterTalent.DebugIdentifier}, amount of reputation to give is 0.",
22  contentPackage: abilityElement.ContentPackage);
23  }
24  }
25 
26  protected override void ApplyEffect()
27  {
28  if (GameMain.GameSession?.Campaign is not { } campaign) { return; }
29 
30  foreach (Faction faction in campaign.Factions)
31  {
32  if (faction.Prefab.Identifier != factionIdentifier) { continue; }
33 
34  faction.Reputation.AddReputation(amount);
35  break;
36  }
37  }
38 
39  protected override void ApplyEffect(AbilityObject abilityObject) => ApplyEffect();
40  }
41 }