Client LuaCsForBarotrauma
CharacterAbilitySetMetadataInt.cs
1 #nullable enable
2 
3 namespace Barotrauma.Abilities
4 {
5  internal sealed class CharacterAbilitySetMetadataInt : CharacterAbility
6  {
7  private readonly Identifier identifier;
8  private readonly int value;
9 
10  public CharacterAbilitySetMetadataInt(CharacterAbilityGroup characterAbilityGroup, ContentXElement abilityElement) : base(characterAbilityGroup, abilityElement)
11  {
12  identifier = abilityElement.GetAttributeIdentifier("identifier", Identifier.Empty);
13  value = abilityElement.GetAttributeInt("value", 0);
14  if (identifier.IsEmpty)
15  {
16  DebugConsole.ThrowError($"Error in talent {CharacterTalent.DebugIdentifier}, {nameof(CharacterAbilitySetMetadataInt)} - identifier is empty.",
17  contentPackage: abilityElement.ContentPackage);
18  }
19  }
20 
21  public override void InitializeAbility(bool addingFirstTime)
22  {
23  ApplyEffect();
24  }
25 
26  protected override void ApplyEffect()
27  {
28  if (identifier == Identifier.Empty) { return; }
29  if (GameMain.GameSession?.Campaign?.CampaignMetadata is not { } metadata) { return; }
30 
31  metadata.SetValue(identifier, value);
32  }
33 
34  protected override void ApplyEffect(AbilityObject abilityObject)
35  {
36  ApplyEffect();
37  }
38  }
39 }