CatStation/Content.Server/Radio/EntitySystems/JammerSystem.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

49 lines
1.5 KiB
C#

using Content.Shared.Radio.EntitySystems;
using Content.Shared.Radio.Components;
namespace Content.Server.Radio.EntitySystems;
public sealed partial class JammerSystem : SharedJammerSystem
{
[Dependency] private SharedTransformSystem _transform = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<RadioSendAttemptEvent>(OnRadioSendAttempt);
SubscribeLocalEvent<RadioReceiveAttemptEvent>(OnRadioReceiveAttempt);
}
private void OnRadioSendAttempt(ref RadioSendAttemptEvent args)
{
if (ShouldCancel(args.RadioSource, args.Channel.Frequency))
args.Cancelled = true;
}
private void OnRadioReceiveAttempt(ref RadioReceiveAttemptEvent args)
{
if (ShouldCancel(args.RadioReceiver, args.Channel.Frequency))
args.Cancelled = true;
}
private bool ShouldCancel(EntityUid sourceUid, int frequency)
{
var source = Transform(sourceUid).Coordinates;
var query = EntityQueryEnumerator<ActiveRadioJammerComponent, RadioJammerComponent, TransformComponent>();
while (query.MoveNext(out var uid, out _, out var jam, out var transform))
{
// Check if this jammer excludes the frequency
if (jam.FrequenciesExcluded.Contains(frequency))
continue;
if (_transform.InRange(source, transform.Coordinates, GetCurrentRange((uid, jam))))
{
return true;
}
}
return false;
}
}