Client LuaCsForBarotrauma
CharacterAbilityReplaceAffliction.cs
1 #nullable enable
2 
3 namespace Barotrauma.Abilities
4 {
5  internal sealed class CharacterAbilityReplaceAffliction : CharacterAbility
6  {
7  private readonly Identifier afflictionId;
8  private readonly Identifier newAfflictionId;
9  private readonly float strengthMultiplier;
10 
11  public CharacterAbilityReplaceAffliction(CharacterAbilityGroup characterAbilityGroup, ContentXElement abilityElement) : base(characterAbilityGroup, abilityElement)
12  {
13  afflictionId = abilityElement.GetAttributeIdentifier("afflictionid", abilityElement.GetAttributeIdentifier("affliction", Identifier.Empty));
14  newAfflictionId = abilityElement.GetAttributeIdentifier("newafflictionid", abilityElement.GetAttributeIdentifier("newaffliction", Identifier.Empty));
15 
16  strengthMultiplier = abilityElement.GetAttributeFloat("strengthmultiplier", 1.0f);
17 
18  if (afflictionId.IsEmpty)
19  {
20  DebugConsole.ThrowError($"Error in {nameof(CharacterAbilityReplaceAffliction)} - affliction identifier not set.");
21  }
22  }
23 
24  protected override void ApplyEffect()
25  {
26  var affliction = Character.CharacterHealth.GetAffliction(afflictionId);
27  if (affliction != null)
28  {
29  float afflictionStrength = affliction.Strength;
30  Limb limb = Character.CharacterHealth.GetAfflictionLimb(affliction);
31  Character.CharacterHealth.ReduceAfflictionOnAllLimbs(affliction.Identifier, afflictionStrength);
32  if (!newAfflictionId.IsEmpty && AfflictionPrefab.Prefabs.TryGet(newAfflictionId, out var newAfflictionPrefab))
33  {
34  Character.CharacterHealth.ApplyAffliction(targetLimb: limb, newAfflictionPrefab.Instantiate(afflictionStrength * strengthMultiplier));
35  }
36  }
37  }
38 
39  protected override void VerifyState(bool conditionsMatched, float timeSinceLastUpdate)
40  {
41  if (conditionsMatched)
42  {
43  ApplyEffect();
44  }
45  }
46  }
47 }
virtual void ApplyEffect(AbilityObject abilityObject)
virtual float Strength
Definition: Affliction.cs:31
void ApplyAffliction(Limb targetLimb, Affliction affliction, bool allowStacking=true, bool ignoreUnkillability=false, bool recalculateVitality=true)
void ReduceAfflictionOnAllLimbs(Identifier afflictionIdOrType, float amount, ActionType? treatmentAction=null, Character attacker=null)
Affliction GetAffliction(string identifier, bool allowLimbAfflictions=true)