2023-03-13 19:34:26 -04:00
|
|
|
|
using Content.Server.Cuffs;
|
|
|
|
|
|
using Content.Shared.Cuffs.Components;
|
2022-11-20 01:49:37 -05:00
|
|
|
|
using Content.Shared.Implants;
|
|
|
|
|
|
using Content.Shared.Implants.Components;
|
2022-11-20 21:51:44 -05:00
|
|
|
|
using Content.Shared.Interaction.Events;
|
2023-01-13 16:57:10 -08:00
|
|
|
|
using Content.Shared.Mobs;
|
2022-11-20 01:49:37 -05:00
|
|
|
|
using Robust.Shared.Containers;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Content.Server.Implants;
|
|
|
|
|
|
|
|
|
|
|
|
public sealed class SubdermalImplantSystem : SharedSubdermalImplantSystem
|
|
|
|
|
|
{
|
2023-03-13 19:34:26 -04:00
|
|
|
|
[Dependency] private readonly CuffableSystem _cuffable = default!;
|
2022-11-20 01:49:37 -05:00
|
|
|
|
[Dependency] private readonly SharedContainerSystem _container = default!;
|
|
|
|
|
|
|
|
|
|
|
|
public override void Initialize()
|
|
|
|
|
|
{
|
|
|
|
|
|
base.Initialize();
|
|
|
|
|
|
|
|
|
|
|
|
SubscribeLocalEvent<SubdermalImplantComponent, UseFreedomImplantEvent>(OnFreedomImplant);
|
|
|
|
|
|
|
|
|
|
|
|
SubscribeLocalEvent<ImplantedComponent, MobStateChangedEvent>(RelayToImplantEvent);
|
2022-11-20 21:51:44 -05:00
|
|
|
|
SubscribeLocalEvent<ImplantedComponent, SuicideEvent>(RelayToImplantEvent);
|
2022-11-20 01:49:37 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void OnFreedomImplant(EntityUid uid, SubdermalImplantComponent component, UseFreedomImplantEvent args)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!TryComp<CuffableComponent>(component.ImplantedEntity, out var cuffs) || cuffs.Container.ContainedEntities.Count < 1)
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
2023-03-13 19:34:26 -04:00
|
|
|
|
_cuffable.Uncuff(component.ImplantedEntity.Value, cuffs.LastAddedCuffs, cuffs.LastAddedCuffs);
|
2023-03-24 08:07:20 +05:00
|
|
|
|
args.Handled = true;
|
2022-11-20 01:49:37 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#region Relays
|
|
|
|
|
|
|
|
|
|
|
|
//Relays from the implanted to the implant
|
2023-01-13 16:57:10 -08:00
|
|
|
|
private void RelayToImplantEvent<T>(EntityUid uid, ImplantedComponent component, T args) where T: notnull
|
2022-11-20 01:49:37 -05:00
|
|
|
|
{
|
|
|
|
|
|
if (!_container.TryGetContainer(uid, ImplanterComponent.ImplantSlotId, out var implantContainer))
|
|
|
|
|
|
return;
|
|
|
|
|
|
foreach (var implant in implantContainer.ContainedEntities)
|
|
|
|
|
|
{
|
|
|
|
|
|
RaiseLocalEvent(implant, args);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-01-13 16:57:10 -08:00
|
|
|
|
//Relays from the implanted to the implant
|
|
|
|
|
|
private void RelayToImplantEventByRef<T>(EntityUid uid, ImplantedComponent component, ref T args) where T: notnull
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!_container.TryGetContainer(uid, ImplanterComponent.ImplantSlotId, out var implantContainer))
|
|
|
|
|
|
return;
|
|
|
|
|
|
foreach (var implant in implantContainer.ContainedEntities)
|
|
|
|
|
|
{
|
|
|
|
|
|
RaiseLocalEvent(implant,ref args);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-11-20 01:49:37 -05:00
|
|
|
|
//Relays from the implant to the implanted
|
|
|
|
|
|
private void RelayToImplantedEvent<T>(EntityUid uid, SubdermalImplantComponent component, T args) where T : EntityEventArgs
|
|
|
|
|
|
{
|
|
|
|
|
|
if (component.ImplantedEntity != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
RaiseLocalEvent(component.ImplantedEntity.Value, args);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-01-13 16:57:10 -08:00
|
|
|
|
private void RelayToImplantedEventByRef<T>(EntityUid uid, SubdermalImplantComponent component, ref T args) where T : EntityEventArgs
|
|
|
|
|
|
{
|
|
|
|
|
|
if (component.ImplantedEntity != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
RaiseLocalEvent(component.ImplantedEntity.Value, ref args);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-11-20 01:49:37 -05:00
|
|
|
|
#endregion
|
|
|
|
|
|
}
|