mirror of
https://github.com/WWhiteDreamProject/wwdpublic.git
synced 2026-04-20 06:58:55 +03:00
<!-- Please read these guidelines before opening your PR: https://docs.spacestation14.io/en/getting-started/pr-guideline --> <!-- The text between the arrows are comments - they will not be visible on your PR. --> ## About the PR <!-- What did you change in this PR? --> EMP has been changed to target APC-powered-devices (most electrical devices) as well as batteries to disable them. This means EMP can interfere with autolathes, airlocks, atmos devices, substations and SMES. The power draw of a single EMP grenade now cuts out a substation, and the disabling effect prevents further recharge until it subsides. EMP duration now also stacks, which creates a novel way to quietly black out the station by attacking engineering SMES with 3 EMP grenades (6tc EMP bundle) to black out the station for 3 minutes. Edit, here's a detailed changelog of the PR, Functionality: - EMP disable has been generalised to kill and prevent further function of every device/battery by interrupting recharge - As a result of the above, some hard coded interactions have been culled - EMP disable duration now stacks with multiple EMP blasts - EMP is now capable of draining from gravity generators - The Charger system has been slightly reworked to facilitate communication between batteries and chargers Results: - EMP grenade can disable basically every powered machine, most notably doors - EMP grenade has had its power drain upped to 2.7MW, which is slightly more than a substation and 1/3 a SMES - EMP grenade can now instantly kill substations - EMP grenade can now instantly kill gravity generators - 3 EMP grenades (6tc) can be used to kill SMES and disable recharge for 3 minutes with no evidence on the power monitor. ## Why / Balance <!-- Why was it changed? Link any discussions or issues here. Please discuss how this would affect game balance. --> EMP at 2tc has a relatively low value-proposition when compared to C4 which is also 2tc. While EMP can probably black out one (or two if you're lucky) APCs and can be used as a defensive option against Stun/Lasers. C4 can be used to cut wires, substations, SMES, generators, doors, reinforced walls, people and the list probably continues. New EMP can be used to soft-bomb station power in an explosion that isn't globally alarming (salv boom). Targeting the captain's office directly may let you crowbar in and steal the locker but it leaves ephemeral evidence in the form of everything electrical shimmering blue. Opting to bomb substations blacks out a wider area, providing several degrees of separation from your target. That is to say, new EMP grenade favours map knowledge and rewards better stealth. ## Technical details <!-- If this is a code change, summarize at high level how your new code works. This makes it easier to review. --> - `C.S/.../EmpSystem.cs` uses TryComp to turn on/off charging for `C.S/Power/Components/PowerNetworkBatteryComponent` - `C.S/Power/EntitySystems/PowerReceiverSystem.cs` listens to `EmpPulseEvent` to turn off. Requests to turn back on are additionally intercepted by `EmpSystem.cs` and cancelled. - `C.S/.../GravityGeneratorSystem.cs` listens to `EmpPulseEvent` and converts energy consumption to a normalised charge - `C.S/Power/EntitySystems/ApcSystem.cs` no longer toggles its breaker, but still listens to `EmpPulseEvent` for updating visuals. - `C.S/Power/EntitySystems/ChargerSystem.cs` was refactored to add a `ChargingComponent` flag to power cells instead of `ActiveCharger` on itself. Battery and Charger communicate through this flag. Listens to `EmpPulseEvent` for updating its state machine. New `ChargerUpdateStatusEvent` allows batteries to update the charger's status. - `C.S/Power/EntitySystems/BatterySystem.cs` can now be disabled, and checks for disabling before updating its charge. Raises `ChargerUpdateStatusEvent` when hearing `EmpDisabledRemoved` to tell its charger to start charging again. - `C.S/Power/PowerWireAction.cs` checks for `EmpDisabledComponent` before turning power back on. - `C.S/SurveillanceCamera/Systems/SurveillanceCameraSystem.cs` and `C.S/VendingMachines/VendingMachineSystem.cs` had redundant `EmpPulseEvent` listeners culled. - `Resources/Prototypes/Entities/Objects/Weapons/Throwable/grenades.yml` buffed EMP grenade. ## Media <!-- PRs which make ingame changes (adding clothing, items, new features, etc) are required to have media attached that showcase the changes. Small fixes/refactors are exempt. Any media may be used in SS14 progress reports, with clear credit given. If you're unsure whether your PR will require media, ask a maintainer. Check the box below to confirm that you have in fact seen this (put an X in the brackets, like [X]): --> https://www.youtube.com/embed/rSVph6OIg1s?si=8o4bx9Vx16B6usuu - outdated video demonstrating changes on a wizden map https://www.youtube.com/embed/B3iPhLcfs-0?si=trB1HY2ccjMf96Bj - electrical anomaly crit with updated emp - [x] I have added screenshots/videos to this PR showcasing its changes ingame, **or** this PR does not require an ingame showcase **Changelog** <!-- Make players aware of new features and changes that could affect how they play the game by adding a Changelog entry. Please read the Changelog guidelines located at: https://docs.spacestation14.io/en/getting-started/pr-guideline#changelog --> 🆑 - tweak: EMP Grenades can now disable basically any electrical device, and stack in disable duration. --------- Signed-off-by: VMSolidus <evilexecutive@gmail.com> Co-authored-by: VMSolidus <evilexecutive@gmail.com>
424 lines
14 KiB
C#
424 lines
14 KiB
C#
using Content.Server.DeviceNetwork;
|
|
using Content.Server.DeviceNetwork.Components;
|
|
using Content.Server.DeviceNetwork.Systems;
|
|
using Content.Server.Power.Components;
|
|
using Content.Shared.ActionBlocker;
|
|
using Content.Shared.DeviceNetwork;
|
|
using Content.Shared.SurveillanceCamera;
|
|
using Content.Shared.Verbs;
|
|
using Robust.Server.GameObjects;
|
|
using Robust.Shared.Player;
|
|
using Robust.Shared.Prototypes;
|
|
|
|
namespace Content.Server.SurveillanceCamera;
|
|
|
|
public sealed class SurveillanceCameraSystem : EntitySystem
|
|
{
|
|
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
|
|
[Dependency] private readonly ActionBlockerSystem _actionBlocker = default!;
|
|
[Dependency] private readonly ViewSubscriberSystem _viewSubscriberSystem = default!;
|
|
[Dependency] private readonly DeviceNetworkSystem _deviceNetworkSystem = default!;
|
|
[Dependency] private readonly UserInterfaceSystem _userInterface = default!;
|
|
[Dependency] private readonly SharedAppearanceSystem _appearance = default!;
|
|
|
|
// Pings a surveillance camera subnet. All cameras will always respond
|
|
// with a data message if they are on the same subnet.
|
|
public const string CameraPingSubnetMessage = "surveillance_camera_ping_subnet";
|
|
|
|
// Pings a surveillance camera. Useful to ensure that the camera is still on
|
|
// before connecting fully.
|
|
public const string CameraPingMessage = "surveillance_camera_ping";
|
|
|
|
// Camera heartbeat. Monitors ping this to ensure that a camera is still able to
|
|
// be contacted. If this doesn't get sent after some time, the monitor will
|
|
// automatically disconnect.
|
|
public const string CameraHeartbeatMessage = "surveillance_camera_heartbeat";
|
|
|
|
// Surveillance camera data. This generally should contain nothing
|
|
// except for the subnet that this camera is on -
|
|
// this is because of the fact that the PacketEvent already
|
|
// contains the sender UID, and that this will always be targeted
|
|
// towards the sender that pinged the camera.
|
|
public const string CameraDataMessage = "surveillance_camera_data";
|
|
public const string CameraConnectMessage = "surveillance_camera_connect";
|
|
public const string CameraSubnetConnectMessage = "surveillance_camera_subnet_connect";
|
|
public const string CameraSubnetDisconnectMessage = "surveillance_camera_subnet_disconnect";
|
|
|
|
public const string CameraAddressData = "surveillance_camera_data_origin";
|
|
public const string CameraNameData = "surveillance_camera_data_name";
|
|
public const string CameraSubnetData = "surveillance_camera_data_subnet";
|
|
|
|
public const int CameraNameLimit = 32;
|
|
|
|
public override void Initialize()
|
|
{
|
|
SubscribeLocalEvent<SurveillanceCameraComponent, ComponentShutdown>(OnShutdown);
|
|
SubscribeLocalEvent<SurveillanceCameraComponent, PowerChangedEvent>(OnPowerChanged);
|
|
SubscribeLocalEvent<SurveillanceCameraComponent, DeviceNetworkPacketEvent>(OnPacketReceived);
|
|
SubscribeLocalEvent<SurveillanceCameraComponent, SurveillanceCameraSetupSetName>(OnSetName);
|
|
SubscribeLocalEvent<SurveillanceCameraComponent, SurveillanceCameraSetupSetNetwork>(OnSetNetwork);
|
|
SubscribeLocalEvent<SurveillanceCameraComponent, GetVerbsEvent<AlternativeVerb>>(AddVerbs);
|
|
}
|
|
|
|
private void OnPacketReceived(EntityUid uid, SurveillanceCameraComponent component, DeviceNetworkPacketEvent args)
|
|
{
|
|
if (!component.Active)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (!TryComp(uid, out DeviceNetworkComponent? deviceNet))
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (args.Data.TryGetValue(DeviceNetworkConstants.Command, out string? command))
|
|
{
|
|
var payload = new NetworkPayload()
|
|
{
|
|
{ DeviceNetworkConstants.Command, string.Empty },
|
|
{ CameraAddressData, deviceNet.Address },
|
|
{ CameraNameData, component.CameraId },
|
|
{ CameraSubnetData, string.Empty }
|
|
};
|
|
|
|
var dest = string.Empty;
|
|
|
|
switch (command)
|
|
{
|
|
case CameraConnectMessage:
|
|
if (!args.Data.TryGetValue(CameraAddressData, out dest)
|
|
|| string.IsNullOrEmpty(args.Address))
|
|
{
|
|
return;
|
|
}
|
|
|
|
payload[DeviceNetworkConstants.Command] = CameraConnectMessage;
|
|
break;
|
|
case CameraHeartbeatMessage:
|
|
if (!args.Data.TryGetValue(CameraAddressData, out dest)
|
|
|| string.IsNullOrEmpty(args.Address))
|
|
{
|
|
return;
|
|
}
|
|
|
|
payload[DeviceNetworkConstants.Command] = CameraHeartbeatMessage;
|
|
break;
|
|
case CameraPingMessage:
|
|
if (!args.Data.TryGetValue(CameraSubnetData, out string? subnet))
|
|
{
|
|
return;
|
|
}
|
|
|
|
dest = args.SenderAddress;
|
|
payload[CameraSubnetData] = subnet;
|
|
payload[DeviceNetworkConstants.Command] = CameraDataMessage;
|
|
break;
|
|
}
|
|
|
|
_deviceNetworkSystem.QueuePacket(
|
|
uid,
|
|
dest,
|
|
payload);
|
|
}
|
|
}
|
|
|
|
private void AddVerbs(EntityUid uid, SurveillanceCameraComponent component, GetVerbsEvent<AlternativeVerb> verbs)
|
|
{
|
|
if (!_actionBlocker.CanInteract(verbs.User, uid))
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (component.NameSet && component.NetworkSet)
|
|
{
|
|
return;
|
|
}
|
|
|
|
AlternativeVerb verb = new();
|
|
verb.Text = Loc.GetString("surveillance-camera-setup");
|
|
verb.Act = () => OpenSetupInterface(uid, verbs.User, component);
|
|
verbs.Verbs.Add(verb);
|
|
}
|
|
|
|
|
|
|
|
private void OnPowerChanged(EntityUid camera, SurveillanceCameraComponent component, ref PowerChangedEvent args)
|
|
{
|
|
SetActive(camera, args.Powered, component);
|
|
}
|
|
|
|
private void OnShutdown(EntityUid camera, SurveillanceCameraComponent component, ComponentShutdown args)
|
|
{
|
|
Deactivate(camera, component);
|
|
}
|
|
|
|
private void OnSetName(EntityUid uid, SurveillanceCameraComponent component, SurveillanceCameraSetupSetName args)
|
|
{
|
|
if (args.UiKey is not SurveillanceCameraSetupUiKey key
|
|
|| key != SurveillanceCameraSetupUiKey.Camera
|
|
|| string.IsNullOrEmpty(args.Name)
|
|
|| args.Name.Length > CameraNameLimit)
|
|
{
|
|
return;
|
|
}
|
|
|
|
component.CameraId = args.Name;
|
|
component.NameSet = true;
|
|
UpdateSetupInterface(uid, component);
|
|
}
|
|
|
|
private void OnSetNetwork(EntityUid uid, SurveillanceCameraComponent component,
|
|
SurveillanceCameraSetupSetNetwork args)
|
|
{
|
|
if (args.UiKey is not SurveillanceCameraSetupUiKey key
|
|
|| key != SurveillanceCameraSetupUiKey.Camera)
|
|
{
|
|
return;
|
|
}
|
|
if (args.Network < 0 || args.Network >= component.AvailableNetworks.Count)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (!_prototypeManager.TryIndex<DeviceFrequencyPrototype>(component.AvailableNetworks[args.Network],
|
|
out var frequency))
|
|
{
|
|
return;
|
|
}
|
|
|
|
_deviceNetworkSystem.SetReceiveFrequency(uid, frequency.Frequency);
|
|
component.NetworkSet = true;
|
|
UpdateSetupInterface(uid, component);
|
|
}
|
|
|
|
private void OpenSetupInterface(EntityUid uid, EntityUid player, SurveillanceCameraComponent? camera = null, ActorComponent? actor = null)
|
|
{
|
|
if (!Resolve(uid, ref camera) || !Resolve(player, ref actor))
|
|
return;
|
|
if (!_userInterface.TryGetUi(uid, SurveillanceCameraSetupUiKey.Camera, out var bui))
|
|
return;
|
|
|
|
_userInterface.OpenUi(bui, actor.PlayerSession);
|
|
UpdateSetupInterface(uid, camera);
|
|
}
|
|
|
|
private void UpdateSetupInterface(EntityUid uid, SurveillanceCameraComponent? camera = null, DeviceNetworkComponent? deviceNet = null)
|
|
{
|
|
if (!Resolve(uid, ref camera, ref deviceNet))
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (camera.NameSet && camera.NetworkSet)
|
|
{
|
|
_userInterface.TryCloseAll(uid, SurveillanceCameraSetupUiKey.Camera);
|
|
return;
|
|
}
|
|
|
|
if (camera.AvailableNetworks.Count == 0)
|
|
{
|
|
if (deviceNet.ReceiveFrequencyId != null)
|
|
{
|
|
camera.AvailableNetworks.Add(deviceNet.ReceiveFrequencyId);
|
|
}
|
|
else if (!camera.NetworkSet)
|
|
{
|
|
_userInterface.TryCloseAll(uid, SurveillanceCameraSetupUiKey.Camera);
|
|
return;
|
|
}
|
|
}
|
|
|
|
var state = new SurveillanceCameraSetupBoundUiState(camera.CameraId, deviceNet.ReceiveFrequency ?? 0,
|
|
camera.AvailableNetworks, camera.NameSet, camera.NetworkSet);
|
|
_userInterface.TrySetUiState(uid, SurveillanceCameraSetupUiKey.Camera, state);
|
|
}
|
|
|
|
// If the camera deactivates for any reason, it must have all viewers removed,
|
|
// and the relevant event broadcast to all systems.
|
|
private void Deactivate(EntityUid camera, SurveillanceCameraComponent? component = null)
|
|
{
|
|
if (!Resolve(camera, ref component))
|
|
{
|
|
return;
|
|
}
|
|
|
|
var ev = new SurveillanceCameraDeactivateEvent(camera);
|
|
|
|
RemoveActiveViewers(camera, new(component.ActiveViewers), null, component);
|
|
component.Active = false;
|
|
|
|
// Send a targetted event to all monitors.
|
|
foreach (var monitor in component.ActiveMonitors)
|
|
{
|
|
RaiseLocalEvent(monitor, ev, true);
|
|
}
|
|
|
|
component.ActiveMonitors.Clear();
|
|
|
|
// Send a local event that's broadcasted everywhere afterwards.
|
|
RaiseLocalEvent(ev);
|
|
|
|
UpdateVisuals(camera, component);
|
|
}
|
|
|
|
public void SetActive(EntityUid camera, bool setting, SurveillanceCameraComponent? component = null)
|
|
{
|
|
if (!Resolve(camera, ref component))
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (setting)
|
|
{
|
|
var attemptEv = new SurveillanceCameraSetActiveAttemptEvent();
|
|
RaiseLocalEvent(camera, ref attemptEv);
|
|
if (attemptEv.Cancelled)
|
|
return;
|
|
component.Active = setting;
|
|
}
|
|
else
|
|
{
|
|
Deactivate(camera, component);
|
|
}
|
|
|
|
UpdateVisuals(camera, component);
|
|
}
|
|
|
|
public void AddActiveViewer(EntityUid camera, EntityUid player, EntityUid? monitor = null, SurveillanceCameraComponent? component = null, ActorComponent? actor = null)
|
|
{
|
|
if (!Resolve(camera, ref component)
|
|
|| !component.Active
|
|
|| !Resolve(player, ref actor))
|
|
{
|
|
return;
|
|
}
|
|
|
|
_viewSubscriberSystem.AddViewSubscriber(camera, actor.PlayerSession);
|
|
component.ActiveViewers.Add(player);
|
|
|
|
if (monitor != null)
|
|
{
|
|
component.ActiveMonitors.Add(monitor.Value);
|
|
}
|
|
|
|
UpdateVisuals(camera, component);
|
|
}
|
|
|
|
public void AddActiveViewers(EntityUid camera, HashSet<EntityUid> players, EntityUid? monitor = null, SurveillanceCameraComponent? component = null)
|
|
{
|
|
if (!Resolve(camera, ref component) || !component.Active)
|
|
{
|
|
return;
|
|
}
|
|
|
|
foreach (var player in players)
|
|
{
|
|
AddActiveViewer(camera, player, monitor, component);
|
|
}
|
|
}
|
|
|
|
// Switch the set of active viewers from one camera to another.
|
|
public void SwitchActiveViewers(EntityUid oldCamera, EntityUid newCamera, HashSet<EntityUid> players, EntityUid? monitor = null, SurveillanceCameraComponent? oldCameraComponent = null, SurveillanceCameraComponent? newCameraComponent = null)
|
|
{
|
|
if (!Resolve(oldCamera, ref oldCameraComponent)
|
|
|| !Resolve(newCamera, ref newCameraComponent)
|
|
|| !oldCameraComponent.Active
|
|
|| !newCameraComponent.Active)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (monitor != null)
|
|
{
|
|
oldCameraComponent.ActiveMonitors.Remove(monitor.Value);
|
|
newCameraComponent.ActiveMonitors.Add(monitor.Value);
|
|
}
|
|
|
|
foreach (var player in players)
|
|
{
|
|
RemoveActiveViewer(oldCamera, player, null, oldCameraComponent);
|
|
AddActiveViewer(newCamera, player, null, newCameraComponent);
|
|
}
|
|
}
|
|
|
|
public void RemoveActiveViewer(EntityUid camera, EntityUid player, EntityUid? monitor = null, SurveillanceCameraComponent? component = null, ActorComponent? actor = null)
|
|
{
|
|
if (!Resolve(camera, ref component)
|
|
|| !Resolve(player, ref actor))
|
|
{
|
|
return;
|
|
}
|
|
|
|
_viewSubscriberSystem.RemoveViewSubscriber(camera, actor.PlayerSession);
|
|
component.ActiveViewers.Remove(player);
|
|
|
|
if (monitor != null)
|
|
{
|
|
component.ActiveMonitors.Remove(monitor.Value);
|
|
}
|
|
|
|
UpdateVisuals(camera, component);
|
|
}
|
|
|
|
public void RemoveActiveViewers(EntityUid camera, HashSet<EntityUid> players, EntityUid? monitor = null, SurveillanceCameraComponent? component = null)
|
|
{
|
|
if (!Resolve(camera, ref component))
|
|
{
|
|
return;
|
|
}
|
|
|
|
foreach (var player in players)
|
|
{
|
|
RemoveActiveViewer(camera, player, monitor, component);
|
|
}
|
|
}
|
|
|
|
private void UpdateVisuals(EntityUid uid, SurveillanceCameraComponent? component = null, AppearanceComponent? appearance = null)
|
|
{
|
|
// Don't log missing, because otherwise tests fail.
|
|
if (!Resolve(uid, ref component, ref appearance, false))
|
|
{
|
|
return;
|
|
}
|
|
|
|
var key = SurveillanceCameraVisuals.Disabled;
|
|
|
|
if (component.Active)
|
|
{
|
|
key = SurveillanceCameraVisuals.Active;
|
|
}
|
|
|
|
if (component.ActiveViewers.Count > 0 || component.ActiveMonitors.Count > 0)
|
|
{
|
|
key = SurveillanceCameraVisuals.InUse;
|
|
}
|
|
|
|
_appearance.SetData(uid, SurveillanceCameraVisualsKey.Key, key, appearance);
|
|
}
|
|
}
|
|
|
|
public sealed class OnSurveillanceCameraViewerAddEvent : EntityEventArgs
|
|
{
|
|
|
|
}
|
|
|
|
public sealed class OnSurveillanceCameraViewerRemoveEvent : EntityEventArgs
|
|
{
|
|
|
|
}
|
|
|
|
// What happens when a camera deactivates.
|
|
public sealed class SurveillanceCameraDeactivateEvent : EntityEventArgs
|
|
{
|
|
public EntityUid Camera { get; }
|
|
|
|
public SurveillanceCameraDeactivateEvent(EntityUid camera)
|
|
{
|
|
Camera = camera;
|
|
}
|
|
}
|
|
|
|
[ByRefEvent]
|
|
public record struct SurveillanceCameraSetActiveAttemptEvent(bool Cancelled);
|