Implanters and Subdermal Implants (#11840)
Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com> Co-authored-by: metalgearsloth <comedian_vs_clown@hotmail.com>
This commit is contained in:
25
Content.Server/Implants/ImplantedSystem.cs
Normal file
25
Content.Server/Implants/ImplantedSystem.cs
Normal file
@@ -0,0 +1,25 @@
|
||||
using Content.Shared.Implants.Components;
|
||||
using Robust.Shared.Containers;
|
||||
|
||||
namespace Content.Server.Implants;
|
||||
|
||||
public sealed partial class ImplanterSystem
|
||||
{
|
||||
public void InitializeImplanted()
|
||||
{
|
||||
SubscribeLocalEvent<ImplantedComponent, ComponentInit>(OnImplantedInit);
|
||||
SubscribeLocalEvent<ImplantedComponent, ComponentShutdown>(OnShutdown);
|
||||
}
|
||||
|
||||
private void OnImplantedInit(EntityUid uid, ImplantedComponent component, ComponentInit args)
|
||||
{
|
||||
component.ImplantContainer = _container.EnsureContainer<Container>(uid, ImplanterComponent.ImplantSlotId);
|
||||
component.ImplantContainer.OccludesLight = false;
|
||||
}
|
||||
|
||||
private void OnShutdown(EntityUid uid, ImplantedComponent component, ComponentShutdown args)
|
||||
{
|
||||
//If the entity is deleted, get rid of the implants
|
||||
_container.CleanContainer(component.ImplantContainer);
|
||||
}
|
||||
}
|
||||
188
Content.Server/Implants/ImplanterSystem.cs
Normal file
188
Content.Server/Implants/ImplanterSystem.cs
Normal file
@@ -0,0 +1,188 @@
|
||||
using System.Threading;
|
||||
using Content.Server.DoAfter;
|
||||
using Content.Server.Guardian;
|
||||
using Content.Server.Popups;
|
||||
using Content.Shared.Hands;
|
||||
using Content.Shared.IdentityManagement;
|
||||
using Content.Shared.Implants;
|
||||
using Content.Shared.Implants.Components;
|
||||
using Content.Shared.Interaction;
|
||||
using Content.Shared.MobState.Components;
|
||||
using Content.Shared.Popups;
|
||||
using Robust.Shared.Containers;
|
||||
using Robust.Shared.GameStates;
|
||||
using Robust.Shared.Player;
|
||||
|
||||
namespace Content.Server.Implants;
|
||||
|
||||
public sealed partial class ImplanterSystem : SharedImplanterSystem
|
||||
{
|
||||
[Dependency] private readonly PopupSystem _popup = default!;
|
||||
[Dependency] private readonly DoAfterSystem _doAfter = default!;
|
||||
[Dependency] private readonly SharedContainerSystem _container = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
InitializeImplanted();
|
||||
|
||||
SubscribeLocalEvent<ImplanterComponent, HandDeselectedEvent>(OnHandDeselect);
|
||||
SubscribeLocalEvent<ImplanterComponent, AfterInteractEvent>(OnImplanterAfterInteract);
|
||||
SubscribeLocalEvent<ImplanterComponent, ComponentGetState>(OnImplanterGetState);
|
||||
|
||||
SubscribeLocalEvent<ImplanterComponent, ImplanterImplantCompleteEvent>(OnImplantAttemptSuccess);
|
||||
SubscribeLocalEvent<ImplanterComponent, ImplanterDrawCompleteEvent>(OnDrawAttemptSuccess);
|
||||
SubscribeLocalEvent<ImplanterComponent, ImplanterCancelledEvent>(OnImplantAttemptFail);
|
||||
}
|
||||
|
||||
private void OnImplanterAfterInteract(EntityUid uid, ImplanterComponent component, AfterInteractEvent args)
|
||||
{
|
||||
if (args.Target == null || !args.CanReach || args.Handled)
|
||||
return;
|
||||
|
||||
if (component.CancelToken != null)
|
||||
{
|
||||
args.Handled = true;
|
||||
return;
|
||||
}
|
||||
|
||||
//Simplemobs and regular mobs should be injectable, but only regular mobs have mind.
|
||||
//So just don't implant/draw anything that isn't living or is a guardian
|
||||
//TODO: Rework a bit when surgery is in to work with implant cases
|
||||
if (!HasComp<MobStateComponent>(args.Target.Value) || HasComp<GuardianComponent>(args.Target.Value))
|
||||
return;
|
||||
|
||||
//TODO: Rework when surgery is in for implant cases
|
||||
if (component.CurrentMode == ImplanterToggleMode.Draw && !component.ImplantOnly)
|
||||
{
|
||||
TryDraw(component, args.User, args.Target.Value, uid);
|
||||
}
|
||||
else
|
||||
{
|
||||
//Implant self instantly, otherwise try to inject the target.
|
||||
if (args.User == args.Target)
|
||||
Implant(uid, args.Target.Value, component);
|
||||
|
||||
else
|
||||
TryImplant(component, args.User, args.Target.Value, uid);
|
||||
}
|
||||
args.Handled = true;
|
||||
}
|
||||
|
||||
private void OnHandDeselect(EntityUid uid, ImplanterComponent component, HandDeselectedEvent args)
|
||||
{
|
||||
component.CancelToken?.Cancel();
|
||||
component.CancelToken = null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Attempt to implant someone else.
|
||||
/// </summary>
|
||||
/// <param name="component">Implanter component</param>
|
||||
/// <param name="user">The entity using the implanter</param>
|
||||
/// <param name="target">The entity being implanted</param>
|
||||
/// <param name="implanter">The implanter being used</param>
|
||||
public void TryImplant(ImplanterComponent component, EntityUid user, EntityUid target, EntityUid implanter)
|
||||
{
|
||||
_popup.PopupEntity(Loc.GetString("injector-component-injecting-user"), target, Filter.Entities(user));
|
||||
|
||||
var userName = Identity.Entity(user, EntityManager);
|
||||
_popup.PopupEntity(Loc.GetString("implanter-component-implanting-target", ("user", userName)), user, Filter.Entities(target), PopupType.LargeCaution);
|
||||
|
||||
component.CancelToken?.Cancel();
|
||||
component.CancelToken = new CancellationTokenSource();
|
||||
|
||||
_doAfter.DoAfter(new DoAfterEventArgs(user, component.ImplantTime, component.CancelToken.Token, target, implanter)
|
||||
{
|
||||
BreakOnUserMove = true,
|
||||
BreakOnTargetMove = true,
|
||||
BreakOnDamage = true,
|
||||
BreakOnStun = true,
|
||||
UsedFinishedEvent = new ImplanterImplantCompleteEvent(implanter, target),
|
||||
UserCancelledEvent = new ImplanterCancelledEvent()
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Try to remove an implant and store it in an implanter
|
||||
/// </summary>
|
||||
/// <param name="component">Implanter component</param>
|
||||
/// <param name="user">The entity using the implanter</param>
|
||||
/// <param name="target">The entity getting their implant removed</param>
|
||||
/// <param name="implanter">The implanter being used</param>
|
||||
//TODO: Remove when surgery is in
|
||||
public void TryDraw(ImplanterComponent component, EntityUid user, EntityUid target, EntityUid implanter)
|
||||
{
|
||||
_popup.PopupEntity(Loc.GetString("injector-component-injecting-user"), target, Filter.Entities(user));
|
||||
|
||||
component.CancelToken?.Cancel();
|
||||
component.CancelToken = new CancellationTokenSource();
|
||||
|
||||
_doAfter.DoAfter(new DoAfterEventArgs(user, component.DrawTime, component.CancelToken.Token, target ,implanter)
|
||||
{
|
||||
BreakOnUserMove = true,
|
||||
BreakOnTargetMove = true,
|
||||
BreakOnDamage = true,
|
||||
BreakOnStun = true,
|
||||
UsedFinishedEvent = new ImplanterDrawCompleteEvent(implanter, user, target),
|
||||
UsedCancelledEvent = new ImplanterCancelledEvent()
|
||||
});
|
||||
}
|
||||
|
||||
private void OnImplanterGetState(EntityUid uid, ImplanterComponent component, ref ComponentGetState args)
|
||||
{
|
||||
args.State = new ImplanterComponentState(component.CurrentMode, component.ImplantOnly);
|
||||
}
|
||||
|
||||
private void OnImplantAttemptSuccess(EntityUid uid, ImplanterComponent component, ImplanterImplantCompleteEvent args)
|
||||
{
|
||||
component.CancelToken?.Cancel();
|
||||
component.CancelToken = null;
|
||||
Implant(args.Implanter, args.Target, component);
|
||||
}
|
||||
|
||||
private void OnDrawAttemptSuccess(EntityUid uid, ImplanterComponent component, ImplanterDrawCompleteEvent args)
|
||||
{
|
||||
component.CancelToken?.Cancel();
|
||||
component.CancelToken = null;
|
||||
Draw(args.Implanter, args.User, args.Target, component);
|
||||
}
|
||||
|
||||
private void OnImplantAttemptFail(EntityUid uid, ImplanterComponent component, ImplanterCancelledEvent args)
|
||||
{
|
||||
component.CancelToken?.Cancel();
|
||||
component.CancelToken = null;
|
||||
}
|
||||
|
||||
private sealed class ImplanterImplantCompleteEvent : EntityEventArgs
|
||||
{
|
||||
public EntityUid Implanter;
|
||||
public EntityUid Target;
|
||||
|
||||
public ImplanterImplantCompleteEvent(EntityUid implanter, EntityUid target)
|
||||
{
|
||||
Implanter = implanter;
|
||||
Target = target;
|
||||
}
|
||||
}
|
||||
|
||||
private sealed class ImplanterCancelledEvent : EntityEventArgs
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private sealed class ImplanterDrawCompleteEvent : EntityEventArgs
|
||||
{
|
||||
public EntityUid Implanter;
|
||||
public EntityUid User;
|
||||
public EntityUid Target;
|
||||
|
||||
public ImplanterDrawCompleteEvent(EntityUid implanter, EntityUid user, EntityUid target)
|
||||
{
|
||||
Implanter = implanter;
|
||||
User = user;
|
||||
Target = target;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
58
Content.Server/Implants/SubdermalImplantSystem.cs
Normal file
58
Content.Server/Implants/SubdermalImplantSystem.cs
Normal file
@@ -0,0 +1,58 @@
|
||||
using Content.Server.Cuffs.Components;
|
||||
using Content.Shared.Implants;
|
||||
using Content.Shared.Implants.Components;
|
||||
using Content.Shared.MobState;
|
||||
using Robust.Shared.Containers;
|
||||
|
||||
namespace Content.Server.Implants;
|
||||
|
||||
public sealed class SubdermalImplantSystem : SharedSubdermalImplantSystem
|
||||
{
|
||||
[Dependency] private readonly SharedContainerSystem _container = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
SubscribeLocalEvent<SubdermalImplantComponent, UseFreedomImplantEvent>(OnFreedomImplant);
|
||||
|
||||
SubscribeLocalEvent<ImplantedComponent, MobStateChangedEvent>(RelayToImplantEvent);
|
||||
}
|
||||
|
||||
private void OnFreedomImplant(EntityUid uid, SubdermalImplantComponent component, UseFreedomImplantEvent args)
|
||||
{
|
||||
if (!TryComp<CuffableComponent>(component.ImplantedEntity, out var cuffs) || cuffs.Container.ContainedEntities.Count < 1)
|
||||
return;
|
||||
|
||||
if (TryComp<HandcuffComponent>(cuffs.LastAddedCuffs, out var cuff))
|
||||
{
|
||||
cuffs.Uncuff(component.ImplantedEntity.Value, cuffs.LastAddedCuffs, cuff, true);
|
||||
}
|
||||
}
|
||||
|
||||
#region Relays
|
||||
|
||||
|
||||
//Relays from the implanted to the implant
|
||||
private void RelayToImplantEvent<T>(EntityUid uid, ImplantedComponent component, T args) where T : EntityEventArgs
|
||||
{
|
||||
if (!_container.TryGetContainer(uid, ImplanterComponent.ImplantSlotId, out var implantContainer))
|
||||
return;
|
||||
|
||||
foreach (var implant in implantContainer.ContainedEntities)
|
||||
{
|
||||
RaiseLocalEvent(implant, args);
|
||||
}
|
||||
}
|
||||
|
||||
//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);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
Reference in New Issue
Block a user