Client LuaCsForBarotrauma
AbilityConditionHoldingItem.cs
1 #nullable enable
2 using System.Collections.Immutable;
3 
4 namespace Barotrauma.Abilities;
5 
6 internal sealed class AbilityConditionHoldingItem : AbilityConditionDataless
7 {
8  private readonly ImmutableHashSet<Identifier> tags;
9 
10  public AbilityConditionHoldingItem(CharacterTalent characterTalent, ContentXElement conditionElement) : base(characterTalent, conditionElement)
11  {
12  tags = conditionElement.GetAttributeIdentifierImmutableHashSet("tags", ImmutableHashSet<Identifier>.Empty);
13  }
14 
15  protected override bool MatchesConditionSpecific()
16  {
17  if (tags.Count is 0)
18  {
19  return HasItemInHand(character, Identifier.Empty);
20  }
21 
22  foreach (Identifier tag in tags)
23  {
24  if (HasItemInHand(character, tag)) { return true; }
25  }
26 
27  return false;
28 
29  static bool HasItemInHand(Character character, Identifier tagOrIdentifier) =>
30  character.GetEquippedItem(tagOrIdentifier, InvSlotType.RightHand) is not null ||
31  character.GetEquippedItem(tagOrIdentifier, InvSlotType.LeftHand) is not null;
32 
33  }
34 }