CatStation/Content.Shared/Whistle/WhistleSystem.cs
Pieter-Jan Briers 5168b5f3d4
IoC source gen compatibility (#43863)
* IoC source gen compatibility

Can be merged before or after https://github.com/space-wizards/RobustToolbox/pull/6549 doesn't really matter.

* Missed a spot
2026-05-09 03:29:58 +00:00

63 lines
1.9 KiB
C#

using Content.Shared.Coordinates;
using Content.Shared.Humanoid;
using Content.Shared.Interaction.Events;
using Content.Shared.Stealth.Components;
using JetBrains.Annotations;
using Robust.Shared.Timing;
namespace Content.Shared.Whistle;
public sealed partial class WhistleSystem : EntitySystem
{
[Dependency] private EntityLookupSystem _entityLookup = default!;
[Dependency] private IGameTiming _timing = default!;
[Dependency] private SharedTransformSystem _transform = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<WhistleComponent, UseInHandEvent>(OnUseInHand);
}
private void ExclamateTarget(EntityUid target, WhistleComponent component)
{
SpawnAttachedTo(component.Effect, target.ToCoordinates());
}
public void OnUseInHand(EntityUid uid, WhistleComponent component, UseInHandEvent args)
{
if (args.Handled || !_timing.IsFirstTimePredicted)
return;
args.Handled = TryMakeLoudWhistle(uid, args.User, component);
}
public bool TryMakeLoudWhistle(EntityUid uid, EntityUid owner, WhistleComponent? component = null)
{
if (!Resolve(uid, ref component, false) || component.Distance <= 0)
return false;
MakeLoudWhistle(uid, owner, component);
return true;
}
private void MakeLoudWhistle(EntityUid uid, EntityUid owner, WhistleComponent component)
{
StealthComponent? stealth = null;
foreach (var iterator in
_entityLookup.GetEntitiesInRange<HumanoidProfileComponent>(_transform.GetMapCoordinates(uid), component.Distance))
{
//Avoid pinging invisible entities
if (TryComp(iterator, out stealth) && stealth.Enabled)
continue;
//We don't want to ping user of whistle
if (iterator.Owner == owner)
continue;
ExclamateTarget(iterator, component);
}
}
}