Client LuaCsForBarotrauma
CharacterAbilityGiveResistance.cs
1 namespace Barotrauma.Abilities
2 {
4  {
5  private readonly Identifier resistanceId;
6  private readonly float multiplier;
7 
8  public CharacterAbilityGiveResistance(CharacterAbilityGroup characterAbilityGroup, ContentXElement abilityElement) : base(characterAbilityGroup, abilityElement)
9  {
10  resistanceId = abilityElement.GetAttributeIdentifier("resistanceid", abilityElement.GetAttributeIdentifier("resistance", Identifier.Empty));
11  multiplier = abilityElement.GetAttributeFloat("multiplier", 1f);
12 
13  if (resistanceId.IsEmpty)
14  {
15  DebugConsole.ThrowError("Error in CharacterAbilityGiveResistance - resistance identifier not set.",
16  contentPackage: abilityElement.ContentPackage);
17  }
18 
19  // NOTE: The resistance value is a multiplier here, so 1.0 == 0% resistance
20  if (MathUtils.NearlyEqual(multiplier, 1))
21  {
22  DebugConsole.AddWarning($"Possible error in talent {CharacterTalent.DebugIdentifier} - multiplier set to 1, which will do nothing.",
23  contentPackage: abilityElement.ContentPackage);
24  }
25  }
26 
27  public override void InitializeAbility(bool addingFirstTime)
28  {
29  TalentResistanceIdentifier identifier = new(resistanceId, CharacterTalent.Prefab.Identifier);
30  Character.ChangeAbilityResistance(identifier, multiplier);
31  }
32  }
33 }
CharacterAbilityGiveResistance(CharacterAbilityGroup characterAbilityGroup, ContentXElement abilityElement)
void ChangeAbilityResistance(TalentResistanceIdentifier identifier, float value)
readonly TalentPrefab Prefab
float GetAttributeFloat(string key, float def)
ContentPackage? ContentPackage
Identifier GetAttributeIdentifier(string key, string def)
readonly Identifier Identifier
Definition: Prefab.cs:34
readonly record struct TalentResistanceIdentifier(Identifier ResistanceIdentifier, Identifier TalentIdentifier)