Client LuaCsForBarotrauma
AbilityConditionNearbyCharacterCount.cs
1 #nullable enable
2 using System;
3 using System.Collections.Immutable;
4 using Microsoft.Xna.Framework;
5 
6 namespace Barotrauma.Abilities;
7 
8 internal sealed class AbilityConditionNearbyCharacterCount : AbilityConditionDataless
9 {
10  private readonly float distance;
11  private readonly int count;
12  private readonly ImmutableHashSet<TargetType> targetTypes;
13 
14  public AbilityConditionNearbyCharacterCount(CharacterTalent characterTalent, ContentXElement conditionElement) : base(characterTalent, conditionElement)
15  {
16  distance = conditionElement.GetAttributeFloat("distance", 10f);
17  count = conditionElement.GetAttributeInt("count", 1);
18  targetTypes = ParseTargetTypes(conditionElement.GetAttributeStringArray("targettypes", Array.Empty<string>(), convertToLowerInvariant: true)).ToImmutableHashSet();
19  }
20 
21  protected override bool MatchesConditionSpecific()
22  {
23  int amountNeeded = count;
24  foreach (Character otherCharacter in Character.CharacterList)
25  {
26  if (character.Submarine != otherCharacter.Submarine) { continue; }
27  if (!IsViableTarget(targetTypes, otherCharacter)) { continue; }
28 
29  if (Vector2.DistanceSquared(character.WorldPosition, otherCharacter.WorldPosition) < distance * distance)
30  {
31  amountNeeded--;
32 
33  if (amountNeeded <= 0) { return true; }
34  }
35  }
36 
37  return false;
38  }
39 }
@ Character
Characters only