Client LuaCsForBarotrauma
CharacterAbilityModifyResistance.cs
1 namespace Barotrauma.Abilities
2 {
4  {
5  private readonly Identifier resistanceId;
6  private readonly float multiplier;
7  bool lastState;
8  public override bool AllowClientSimulation => true;
9 
10  // should probably be split to different classes
11  public CharacterAbilityModifyResistance(CharacterAbilityGroup characterAbilityGroup, ContentXElement abilityElement) : base(characterAbilityGroup, abilityElement)
12  {
13  resistanceId = abilityElement.GetAttributeIdentifier("resistanceid", abilityElement.GetAttributeIdentifier("resistance", Identifier.Empty));
14  multiplier = abilityElement.GetAttributeFloat("multiplier", 1f);
15 
16  if (resistanceId.IsEmpty)
17  {
18  DebugConsole.ThrowError($"Error in talent {CharacterTalent.DebugIdentifier} - resistance identifier not set in {nameof(CharacterAbilityModifyResistance)}.",
19  contentPackage: abilityElement.ContentPackage);
20  }
21  if (MathUtils.NearlyEqual(multiplier, 1.0f))
22  {
23  DebugConsole.AddWarning($"Possible error in talent {CharacterTalent.DebugIdentifier} - resistance set to 1, which will do nothing.",
24  contentPackage: abilityElement.ContentPackage);
25  }
26  }
27 
28  public override void UpdateCharacterAbility(bool conditionsMatched, float timeSinceLastUpdate)
29  {
30  if (conditionsMatched != lastState)
31  {
32  TalentResistanceIdentifier identifier = new(resistanceId, CharacterTalent.Prefab.Identifier);
33  if (conditionsMatched)
34  {
35  Character.ChangeAbilityResistance(identifier, multiplier);
36  }
37  else
38  {
40  }
41  lastState = conditionsMatched;
42  }
43  }
44  }
45 }
override void UpdateCharacterAbility(bool conditionsMatched, float timeSinceLastUpdate)
CharacterAbilityModifyResistance(CharacterAbilityGroup characterAbilityGroup, ContentXElement abilityElement)
void RemoveAbilityResistance(TalentResistanceIdentifier identifier)
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)