Client LuaCsForBarotrauma
AbilityConditionItem.cs
2 using System;
3 using System.Collections.Immutable;
4 using System.Linq;
5 
6 namespace Barotrauma.Abilities
7 {
9  {
10  private readonly ImmutableArray<Identifier> identifiers;
11  private readonly ImmutableArray<Identifier> tags;
12  private readonly MapEntityCategory category = MapEntityCategory.None;
13 
14  public AbilityConditionItem(CharacterTalent characterTalent, ContentXElement conditionElement) : base(characterTalent, conditionElement)
15  {
16  identifiers = conditionElement.GetAttributeIdentifierArray("identifiers", Array.Empty<Identifier>()).ToImmutableArray();
17  tags = conditionElement.GetAttributeIdentifierArray("tags", Array.Empty<Identifier>()).ToImmutableArray();
18  category = conditionElement.GetAttributeEnum("category", MapEntityCategory.None);
19 
20  if (identifiers.None() && tags.None() && category == MapEntityCategory.None)
21  {
22  DebugConsole.ThrowError($"Error in talent \"{characterTalent}\". No identifiers, tags or category defined.",
23  contentPackage: conditionElement.ContentPackage);
24  }
25  }
26 
27  protected override bool MatchesConditionSpecific(AbilityObject abilityObject)
28  {
29  ItemPrefab itemPrefab = null;
30  if ((abilityObject as IAbilityItemPrefab)?.ItemPrefab is ItemPrefab abilityItemPrefab)
31  {
32  itemPrefab = abilityItemPrefab;
33  }
34  else if ((abilityObject as IAbilityItem)?.Item is Item abilityItem)
35  {
36  itemPrefab = abilityItem.Prefab;
37  }
38 
39  if (itemPrefab != null)
40  {
41  return MatchesItem(itemPrefab);
42  }
43  else
44  {
45  LogAbilityConditionError(abilityObject, typeof(IAbilityItemPrefab));
46  return false;
47  }
48  }
49 
50  public bool MatchesItem(ItemPrefab itemPrefab)
51  {
52  if (category != MapEntityCategory.None)
53  {
54  if (!itemPrefab.Category.HasFlag(category)) { return false; }
55  }
56 
57  if (identifiers.Any())
58  {
59  if (!identifiers.Any(t => itemPrefab.Identifier == t))
60  {
61  return false;
62  }
63  }
64  return !tags.Any() || tags.Any(t => itemPrefab.Tags.Any(p => t == p));
65  }
66  }
67 }
void LogAbilityConditionError(AbilityObject abilityObject, Type expectedData)
AbilityConditionItem(CharacterTalent characterTalent, ContentXElement conditionElement)
override bool MatchesConditionSpecific(AbilityObject abilityObject)
Identifier[] GetAttributeIdentifierArray(Identifier[] def, params string[] keys)
ContentPackage? ContentPackage
override ImmutableHashSet< Identifier > Tags
Prefab(ContentFile file, Identifier identifier)
Definition: Prefab.cs:40
readonly Identifier Identifier
Definition: Prefab.cs:34