44 lines
1.7 KiB
C#
44 lines
1.7 KiB
C#
using Microsoft.Xna.Framework;
|
|
|
|
namespace Barotrauma.Abilities
|
|
{
|
|
class CharacterAbilityTandemFire : CharacterAbilityApplyStatusEffectsToNearestAlly
|
|
{
|
|
// this should just be its own class, misleading to inherit here
|
|
private readonly string tag;
|
|
public CharacterAbilityTandemFire(CharacterAbilityGroup characterAbilityGroup, ContentXElement abilityElement) : base(characterAbilityGroup, abilityElement)
|
|
{
|
|
tag = abilityElement.GetAttributeString("tag", "");
|
|
}
|
|
|
|
protected override void ApplyEffect()
|
|
{
|
|
if (!SelectedItemHasTag(Character)) { return; }
|
|
|
|
Character closestCharacter = null;
|
|
float closestDistance = squaredMaxDistance;
|
|
|
|
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 (closestCharacter == null || !SelectedItemHasTag(closestCharacter)) { return; }
|
|
|
|
if (closestDistance < squaredMaxDistance)
|
|
{
|
|
ApplyEffectSpecific(Character);
|
|
ApplyEffectSpecific(closestCharacter);
|
|
}
|
|
|
|
bool SelectedItemHasTag(Character character) =>
|
|
(character.SelectedItem != null && character.SelectedItem.HasTag(tag)) ||
|
|
(character.SelectedSecondaryItem != null && character.SelectedSecondaryItem.HasTag(tag));
|
|
}
|
|
}
|
|
}
|