Client LuaCsForBarotrauma
CharacterAbilityGiveAffliction.cs
1 namespace Barotrauma.Abilities
2 {
4  {
5  private readonly Identifier afflictionId;
6  private readonly float strength;
7  private readonly string multiplyStrengthBySkill;
8  private readonly bool setValue;
9 
10  public CharacterAbilityGiveAffliction(CharacterAbilityGroup characterAbilityGroup, ContentXElement abilityElement) : base(characterAbilityGroup, abilityElement)
11  {
12  afflictionId = abilityElement.GetAttributeIdentifier("afflictionid", abilityElement.GetAttributeIdentifier("affliction", Identifier.Empty));
13  strength = abilityElement.GetAttributeFloat("strength", 0f);
14  multiplyStrengthBySkill = abilityElement.GetAttributeString("multiplystrengthbyskill", string.Empty);
15  setValue = abilityElement.GetAttributeBool("setvalue", false);
16 
17  if (afflictionId.IsEmpty)
18  {
19  DebugConsole.ThrowError($"Error in talent {CharacterTalent.DebugIdentifier}, CharacterAbilityGiveAffliction - affliction identifier not set.",
20  contentPackage: abilityElement.ContentPackage);
21  }
22  }
23 
24  protected override void VerifyState(bool conditionsMatched, float timeSinceLastUpdate)
25  {
26  if (conditionsMatched)
27  {
28  ApplyEffect();
29  }
30  }
31 
32  protected override void ApplyEffect()
33  {
34  ApplyAfflictionToCharacter(Character);
35  }
36 
37  protected override void ApplyEffect(AbilityObject abilityObject)
38  {
39  if (abilityObject is IAbilityCharacter character)
40  {
41  ApplyAfflictionToCharacter(character.Character);
42  }
43  }
44 
45  private void ApplyAfflictionToCharacter(Character character)
46  {
47  var afflictionPrefab = AfflictionPrefab.Prefabs.Find(a => a.Identifier == afflictionId);
48  if (afflictionPrefab == null)
49  {
50  DebugConsole.ThrowError($"Error in CharacterAbilityGiveAffliction - could not find an affliction with the identifier \"{afflictionId}\".",
51  contentPackage: CharacterTalent.Prefab.ContentPackage);
52  return;
53  }
54  float strength = this.strength;
55  if (!string.IsNullOrEmpty(multiplyStrengthBySkill))
56  {
57  strength *= Character.GetSkillLevel(multiplyStrengthBySkill);
58  }
59  character.CharacterHealth.ApplyAffliction(null, afflictionPrefab.Instantiate(strength), allowStacking: !setValue);
60  }
61  }
62 }
override void ApplyEffect(AbilityObject abilityObject)
override void VerifyState(bool conditionsMatched, float timeSinceLastUpdate)
CharacterAbilityGiveAffliction(CharacterAbilityGroup characterAbilityGroup, ContentXElement abilityElement)
AfflictionPrefab is a prefab that defines a type of affliction that can be applied to a character....
static readonly PrefabCollection< AfflictionPrefab > Prefabs
void ApplyAffliction(Limb targetLimb, Affliction affliction, bool allowStacking=true, bool ignoreUnkillability=false)
float GetSkillLevel(string skillIdentifier)
readonly TalentPrefab Prefab
string? GetAttributeString(string key, string? def)
float GetAttributeFloat(string key, float def)
ContentPackage? ContentPackage
bool GetAttributeBool(string key, bool def)
Identifier GetAttributeIdentifier(string key, string def)
ContentPackage? ContentPackage
Definition: Prefab.cs:37