Shock collar

(cherry picked from commit e34770d7e5399195b8f762e545eddab8a3c2dd4f)
This commit is contained in:
Aviu00
2023-12-28 17:15:23 +03:00
committed by Cinka
parent d5b3f707d1
commit a935aa2242
5 changed files with 257 additions and 11 deletions

View File

@@ -0,0 +1,15 @@
using Content.Shared.DeviceLinking;
using Robust.Shared.Audio;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
namespace Content.Server.White.ShockClothing;
[RegisterComponent]
public sealed partial class ShockClothingComponent : Component
{
[DataField("triggerPort", customTypeSerializer: typeof(PrototypeIdSerializer<SinkPortPrototype>))]
public string TriggerPort = "Trigger";
[ViewVariables(VVAccess.ReadWrite), DataField("zapSound")]
public SoundSpecifier? ZapSound = new SoundPathSpecifier("/Audio/Weapons/Guns/Hits/taser_hit.ogg");
}

View File

@@ -0,0 +1,42 @@
using Content.Server.DeviceLinking.Events;
using Content.Server.DeviceLinking.Systems;
using Content.Server.Electrocution;
using Robust.Server.Containers;
using Robust.Shared.Audio.Systems;
namespace Content.Server.White.ShockClothing;
public sealed class ShockClothingSystem : EntitySystem
{
[Dependency] private readonly DeviceLinkSystem _deviceLink = default!;
[Dependency] private readonly ElectrocutionSystem _electrocution = default!;
[Dependency] private readonly ContainerSystem _containerSystem = default!;
[Dependency] private readonly SharedAudioSystem _audio = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<ShockClothingComponent, ComponentInit>(OnInit);
SubscribeLocalEvent<ShockClothingComponent, SignalReceivedEvent>(OnSignalReceived);
}
private void OnInit(EntityUid uid, ShockClothingComponent component, ComponentInit args)
{
_deviceLink.EnsureSinkPorts(uid, component.TriggerPort);
}
private void OnSignalReceived(EntityUid uid, ShockClothingComponent component, ref SignalReceivedEvent args)
{
if (args.Port != component.TriggerPort)
return;
_audio.PlayPvs(component.ZapSound, uid);
if (!_containerSystem.TryGetContainingContainer(uid, out var container))
return;
_electrocution.TryDoElectrocution(container.Owner, uid, 0, TimeSpan.FromSeconds(5), true,
ignoreInsulation: true);
}
}