Client LuaCsForBarotrauma
CharacterAbilityGiveItemStatToTags.cs
1 #nullable enable
2 
3 using System.Collections.Immutable;
4 
5 namespace Barotrauma.Abilities
6 {
7  internal sealed class CharacterAbilityGiveItemStatToTags: CharacterAbility
8  {
9  private readonly ItemTalentStats stat;
10  private readonly float value;
11  private readonly ImmutableHashSet<Identifier> tags;
12  private readonly bool stackable;
13  private readonly bool save;
14 
15  public CharacterAbilityGiveItemStatToTags(CharacterAbilityGroup characterAbilityGroup, ContentXElement abilityElement) : base(characterAbilityGroup, abilityElement)
16  {
17  stat = abilityElement.GetAttributeEnum("stattype", ItemTalentStats.None);
18  value = abilityElement.GetAttributeFloat("value", 0f);
19  tags = abilityElement.GetAttributeIdentifierImmutableHashSet("tags", ImmutableHashSet<Identifier>.Empty);
20  stackable = abilityElement.GetAttributeBool("stackable", true);
21  save = abilityElement.GetAttributeBool("save", false);
22  }
23 
24  public override void InitializeAbility(bool addingFirstTime)
25  {
26  if (addingFirstTime)
27  {
28  VerifyState(conditionsMatched: true, timeSinceLastUpdate: 0.0f);
29  }
30  }
31 
32  protected override void VerifyState(bool conditionsMatched, float timeSinceLastUpdate)
33  {
34  if (conditionsMatched)
35  {
36  ApplyEffect();
37  }
38  }
39 
40  protected override void ApplyEffect()
41  {
42  if (Character is null) { return; }
43 
44  foreach (Item item in Item.ItemList)
45  {
46  if (item.Submarine?.TeamID != Character.TeamID) { continue; }
47  if (item.HasTag(tags) || tags.Contains(item.Prefab.Identifier))
48  {
49  item.StatManager.ApplyStat(stat, stackable, save, value, CharacterTalent);
50  }
51  }
52  }
53  }
54 }
virtual void ApplyEffect(AbilityObject abilityObject)