2024-03-25 03:59:16 +02:00
|
|
|
using Content.Server.DeviceNetwork.Components;
|
|
|
|
|
using Content.Server.DeviceNetwork.Systems;
|
|
|
|
|
using Content.Server.Medical.CrewMonitoring;
|
2023-04-14 22:50:19 +03:00
|
|
|
using Content.Server.Popups;
|
2024-03-06 00:34:50 -05:00
|
|
|
using Content.Server.Power.EntitySystems;
|
2023-04-14 22:50:19 +03:00
|
|
|
using Content.Server.PowerCell;
|
|
|
|
|
using Content.Server.Radio.Components;
|
2024-03-25 03:59:16 +02:00
|
|
|
using Content.Server.Station.Systems;
|
|
|
|
|
using Content.Shared.DeviceNetwork.Components;
|
2023-04-14 22:50:19 +03:00
|
|
|
using Content.Shared.Examine;
|
|
|
|
|
using Content.Shared.Interaction;
|
|
|
|
|
using Content.Shared.PowerCell.Components;
|
|
|
|
|
|
|
|
|
|
namespace Content.Server.Radio.EntitySystems;
|
|
|
|
|
|
|
|
|
|
public sealed class JammerSystem : EntitySystem
|
|
|
|
|
{
|
|
|
|
|
[Dependency] private readonly PowerCellSystem _powerCell = default!;
|
2024-03-06 00:34:50 -05:00
|
|
|
[Dependency] private readonly BatterySystem _battery = default!;
|
2023-04-14 22:50:19 +03:00
|
|
|
[Dependency] private readonly PopupSystem _popup = default!;
|
|
|
|
|
[Dependency] private readonly SharedTransformSystem _transform = default!;
|
2024-03-25 03:59:16 +02:00
|
|
|
[Dependency] private readonly StationSystem _stationSystem = default!;
|
|
|
|
|
[Dependency] private readonly SingletonDeviceNetServerSystem _singletonServerSystem = default!;
|
2023-04-14 22:50:19 +03:00
|
|
|
|
|
|
|
|
public override void Initialize()
|
|
|
|
|
{
|
|
|
|
|
base.Initialize();
|
|
|
|
|
|
|
|
|
|
SubscribeLocalEvent<RadioJammerComponent, ActivateInWorldEvent>(OnActivate);
|
|
|
|
|
SubscribeLocalEvent<ActiveRadioJammerComponent, PowerCellChangedEvent>(OnPowerCellChanged);
|
|
|
|
|
SubscribeLocalEvent<RadioJammerComponent, ExaminedEvent>(OnExamine);
|
|
|
|
|
SubscribeLocalEvent<RadioSendAttemptEvent>(OnRadioSendAttempt);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void Update(float frameTime)
|
|
|
|
|
{
|
2023-04-23 11:29:08 +03:00
|
|
|
var query = EntityQueryEnumerator<ActiveRadioJammerComponent, RadioJammerComponent>();
|
2023-04-14 22:50:19 +03:00
|
|
|
while (query.MoveNext(out var uid, out var _, out var jam))
|
|
|
|
|
{
|
2024-03-06 08:44:14 -05:00
|
|
|
if (_powerCell.TryGetBatteryFromSlot(uid, out var batteryUid, out var battery) &&
|
|
|
|
|
!_battery.TryUseCharge(batteryUid.Value, jam.Wattage * frameTime, battery))
|
2023-04-14 22:50:19 +03:00
|
|
|
{
|
|
|
|
|
RemComp<ActiveRadioJammerComponent>(uid);
|
2024-03-25 03:59:16 +02:00
|
|
|
RemComp<DeviceNetworkJammerComponent>(uid);
|
2023-04-14 22:50:19 +03:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnActivate(EntityUid uid, RadioJammerComponent comp, ActivateInWorldEvent args)
|
|
|
|
|
{
|
2024-03-06 00:34:50 -05:00
|
|
|
var activated = !HasComp<ActiveRadioJammerComponent>(uid) &&
|
2023-04-14 22:50:19 +03:00
|
|
|
_powerCell.TryGetBatteryFromSlot(uid, out var battery) &&
|
|
|
|
|
battery.CurrentCharge > comp.Wattage;
|
|
|
|
|
if (activated)
|
|
|
|
|
{
|
|
|
|
|
EnsureComp<ActiveRadioJammerComponent>(uid);
|
2024-04-01 02:13:51 +00:00
|
|
|
EnsureComp<DeviceNetworkJammerComponent>(uid, out var jammingComp);
|
|
|
|
|
jammingComp.Range = comp.Range;
|
|
|
|
|
jammingComp.JammableNetworks.Add(DeviceNetworkComponent.DeviceNetIdDefaults.Wireless.ToString());
|
|
|
|
|
Dirty(uid, jammingComp);
|
2023-04-14 22:50:19 +03:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
RemComp<ActiveRadioJammerComponent>(uid);
|
2024-03-25 03:59:16 +02:00
|
|
|
RemComp<DeviceNetworkJammerComponent>(uid);
|
2023-04-14 22:50:19 +03:00
|
|
|
}
|
|
|
|
|
var state = Loc.GetString(activated ? "radio-jammer-component-on-state" : "radio-jammer-component-off-state");
|
|
|
|
|
var message = Loc.GetString("radio-jammer-component-on-use", ("state", state));
|
|
|
|
|
_popup.PopupEntity(message, args.User, args.User);
|
|
|
|
|
args.Handled = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnPowerCellChanged(EntityUid uid, ActiveRadioJammerComponent comp, PowerCellChangedEvent args)
|
|
|
|
|
{
|
|
|
|
|
if (args.Ejected)
|
|
|
|
|
RemComp<ActiveRadioJammerComponent>(uid);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnExamine(EntityUid uid, RadioJammerComponent comp, ExaminedEvent args)
|
|
|
|
|
{
|
|
|
|
|
if (args.IsInDetailsRange)
|
|
|
|
|
{
|
|
|
|
|
var msg = HasComp<ActiveRadioJammerComponent>(uid)
|
|
|
|
|
? Loc.GetString("radio-jammer-component-examine-on-state")
|
|
|
|
|
: Loc.GetString("radio-jammer-component-examine-off-state");
|
|
|
|
|
args.PushMarkup(msg);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnRadioSendAttempt(ref RadioSendAttemptEvent args)
|
|
|
|
|
{
|
2024-03-14 17:55:14 +02:00
|
|
|
if (ShouldCancelSend(args.RadioSource))
|
|
|
|
|
{
|
|
|
|
|
args.Cancelled = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private bool ShouldCancelSend(EntityUid sourceUid)
|
|
|
|
|
{
|
|
|
|
|
var source = Transform(sourceUid).Coordinates;
|
2023-04-23 11:29:08 +03:00
|
|
|
var query = EntityQueryEnumerator<ActiveRadioJammerComponent, RadioJammerComponent, TransformComponent>();
|
2024-03-14 17:55:14 +02:00
|
|
|
|
2023-04-14 22:50:19 +03:00
|
|
|
while (query.MoveNext(out _, out _, out var jam, out var transform))
|
|
|
|
|
{
|
|
|
|
|
if (source.InRange(EntityManager, _transform, transform.Coordinates, jam.Range))
|
|
|
|
|
{
|
2024-03-14 17:55:14 +02:00
|
|
|
return true;
|
2023-04-14 22:50:19 +03:00
|
|
|
}
|
|
|
|
|
}
|
2024-03-14 17:55:14 +02:00
|
|
|
|
|
|
|
|
return false;
|
2023-04-14 22:50:19 +03:00
|
|
|
}
|
|
|
|
|
}
|