37 lines
1.4 KiB
C#
37 lines
1.4 KiB
C#
using Microsoft.Xna.Framework;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Xml.Linq;
|
|
|
|
namespace Barotrauma.Abilities
|
|
{
|
|
class CharacterAbilityApplyStatusEffectsToNearestAlly : CharacterAbilityApplyStatusEffects
|
|
{
|
|
protected float squaredMaxDistance;
|
|
public CharacterAbilityApplyStatusEffectsToNearestAlly(CharacterAbilityGroup characterAbilityGroup, XElement abilityElement) : base(characterAbilityGroup, abilityElement)
|
|
{
|
|
squaredMaxDistance = DistanceToSquaredDistance(abilityElement.GetAttributeFloat("maxdistance", float.MaxValue));
|
|
}
|
|
|
|
protected override void ApplyEffect()
|
|
{
|
|
Character closestCharacter = null;
|
|
float closestDistance = float.MaxValue;
|
|
|
|
foreach (Character crewCharacter in Character.GetFriendlyCrew(Character))
|
|
{
|
|
if (crewCharacter != Character && Vector2.DistanceSquared(Character.SimPosition, Character.GetRelativeSimPosition(crewCharacter)) is float tempDistance && tempDistance < closestDistance)
|
|
{
|
|
closestCharacter = crewCharacter;
|
|
closestDistance = tempDistance;
|
|
}
|
|
}
|
|
|
|
if (closestDistance < squaredMaxDistance)
|
|
{
|
|
ApplyEffectSpecific(closestCharacter);
|
|
}
|
|
}
|
|
}
|
|
}
|