Client LuaCsForBarotrauma
AbilityConditionAllyNearby.cs
1 using System;
2 using Microsoft.Xna.Framework;
3 
4 namespace Barotrauma.Abilities
5 {
6  internal sealed class AbilityConditionAllyNearby : AbilityConditionDataless
7  {
8  private enum NearbyCharacterTruthy
9  {
10  OneCharacterMatches,
11  NoCharacterMatches
12  }
13 
14  private readonly NearbyCharacterTruthy truthyWhen;
15  private readonly float distance;
16 
17  public AbilityConditionAllyNearby(CharacterTalent characterTalent, ContentXElement conditionElement) : base(characterTalent, conditionElement)
18  {
19  truthyWhen = conditionElement.GetAttributeEnum("truthywhen", NearbyCharacterTruthy.OneCharacterMatches);
20  distance = conditionElement.GetAttributeFloat("distance", 10f);
21  }
22 
23  protected override bool MatchesConditionSpecific()
24  {
25  bool trueCondition = truthyWhen switch
26  {
27  NearbyCharacterTruthy.OneCharacterMatches => true,
28  NearbyCharacterTruthy.NoCharacterMatches => false,
29  _ => throw new ArgumentOutOfRangeException(nameof(truthyWhen))
30  };
31 
32  foreach (Character ally in Character.GetFriendlyCrew(character))
33  {
34  if (ally == character) { continue; }
35 
36  float distanceToCharacter = Vector2.DistanceSquared(ally.WorldPosition, character.WorldPosition);
37 
38  if (distanceToCharacter < distance * distance)
39  {
40  return trueCondition;
41  }
42  }
43 
44  return !trueCondition;
45  }
46  }
47 }
virtual Vector2 WorldPosition
Definition: Entity.cs:49
@ Character
Characters only