Make radio jammer block suit sensors (#26046)

* Make radio jammer block suit sensors

* Fix stupid

Use CancellableEventArgs instead of doing what the hell I was doing before.

* Address Reviews.

Change the event from a CancellableEntityEventArgs to a ByRefEvent.
This commit is contained in:
nikthechampiongr
2024-03-14 17:55:14 +02:00
committed by GitHub
parent d674be697e
commit dce24dfd03
5 changed files with 36 additions and 5 deletions

View File

@@ -87,3 +87,9 @@ public sealed partial class SuitSensorComponent : Component
[DataField, ViewVariables] [DataField, ViewVariables]
public bool PreviousControlsLocked = false; public bool PreviousControlsLocked = false;
} }
[ByRefEvent]
public record struct SuitSensorsSendAttemptEvent
{
public bool Cancelled;
};

View File

@@ -73,6 +73,11 @@ public sealed class SuitSensorSystem : EntitySystem
// TODO: This would cause imprecision at different tick rates. // TODO: This would cause imprecision at different tick rates.
sensor.NextUpdate = curTime + sensor.UpdateRate; sensor.NextUpdate = curTime + sensor.UpdateRate;
var canEv = new SuitSensorsSendAttemptEvent();
RaiseLocalEvent(uid, ref canEv);
if (canEv.Cancelled)
continue;
// get sensor status // get sensor status
var status = GetSensorState(uid, sensor); var status = GetSensorState(uid, sensor);
if (status == null) if (status == null)

View File

@@ -1,3 +1,4 @@
using Content.Server.Medical.SuitSensors;
using Content.Server.Popups; using Content.Server.Popups;
using Content.Server.Power.EntitySystems; using Content.Server.Power.EntitySystems;
using Content.Server.PowerCell; using Content.Server.PowerCell;
@@ -23,6 +24,7 @@ public sealed class JammerSystem : EntitySystem
SubscribeLocalEvent<ActiveRadioJammerComponent, PowerCellChangedEvent>(OnPowerCellChanged); SubscribeLocalEvent<ActiveRadioJammerComponent, PowerCellChangedEvent>(OnPowerCellChanged);
SubscribeLocalEvent<RadioJammerComponent, ExaminedEvent>(OnExamine); SubscribeLocalEvent<RadioJammerComponent, ExaminedEvent>(OnExamine);
SubscribeLocalEvent<RadioSendAttemptEvent>(OnRadioSendAttempt); SubscribeLocalEvent<RadioSendAttemptEvent>(OnRadioSendAttempt);
SubscribeLocalEvent<SuitSensorComponent, SuitSensorsSendAttemptEvent>(OnSensorSendAttempt);
} }
public override void Update(float frameTime) public override void Update(float frameTime)
@@ -76,15 +78,33 @@ public sealed class JammerSystem : EntitySystem
private void OnRadioSendAttempt(ref RadioSendAttemptEvent args) private void OnRadioSendAttempt(ref RadioSendAttemptEvent args)
{ {
var source = Transform(args.RadioSource).Coordinates; if (ShouldCancelSend(args.RadioSource))
{
args.Cancelled = true;
}
}
private void OnSensorSendAttempt(EntityUid uid, SuitSensorComponent comp, ref SuitSensorsSendAttemptEvent args)
{
if (ShouldCancelSend(uid))
{
args.Cancelled = true;
}
}
private bool ShouldCancelSend(EntityUid sourceUid)
{
var source = Transform(sourceUid).Coordinates;
var query = EntityQueryEnumerator<ActiveRadioJammerComponent, RadioJammerComponent, TransformComponent>(); var query = EntityQueryEnumerator<ActiveRadioJammerComponent, RadioJammerComponent, TransformComponent>();
while (query.MoveNext(out _, out _, out var jam, out var transform)) while (query.MoveNext(out _, out _, out var jam, out var transform))
{ {
if (source.InRange(EntityManager, _transform, transform.Coordinates, jam.Range)) if (source.InRange(EntityManager, _transform, transform.Coordinates, jam.Range))
{ {
args.Cancelled = true; return true;
return;
} }
} }
return false;
} }
} }

View File

@@ -146,7 +146,7 @@ uplink-clothing-eyes-hud-syndicate-name = Syndicate Visor
uplink-clothing-eyes-hud-syndicate-desc = The syndicate's professional head-up display, designed for better detection of humanoids and their subsequent elimination. uplink-clothing-eyes-hud-syndicate-desc = The syndicate's professional head-up display, designed for better detection of humanoids and their subsequent elimination.
uplink-radio-jammer-name = Radio Jammer uplink-radio-jammer-name = Radio Jammer
uplink-radio-jammer-desc = This device will disrupt any nearby outgoing radio communication when activated. uplink-radio-jammer-desc = This device will disrupt any nearby outgoing radio communication as well as suit sensors when activated.
uplink-syndicate-weapon-module-name = Weapon Cyborg Module uplink-syndicate-weapon-module-name = Weapon Cyborg Module
uplink-syndicate-weapon-module-desc = This module will give a cyborg advanced laser and machete uplink-syndicate-weapon-module-desc = This module will give a cyborg advanced laser and machete

View File

@@ -2,7 +2,7 @@
name: radio jammer name: radio jammer
parent: BaseItem parent: BaseItem
id: RadioJammer id: RadioJammer
description: This device will disrupt any nearby outgoing radio communication when activated. description: This device will disrupt any nearby outgoing radio communication as well as suit sensors when activated.
components: components:
- type: Sprite - type: Sprite
sprite: Objects/Devices/jammer.rsi sprite: Objects/Devices/jammer.rsi