Misc implant fixes (#17172)
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
using System.Linq;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Content.Shared.Containers.ItemSlots;
|
||||
using Content.Shared.DoAfter;
|
||||
using Content.Shared.IdentityManagement;
|
||||
@@ -39,38 +41,48 @@ public abstract class SharedImplanterSystem : EntitySystem
|
||||
component.ImplantData = (implantData.EntityName, implantData.EntityDescription);
|
||||
}
|
||||
|
||||
|
||||
//Instantly implant something and add all necessary components and containers.
|
||||
//Set to draw mode if not implant only
|
||||
public void Implant(EntityUid implanter, EntityUid target, ImplanterComponent component)
|
||||
public void Implant(EntityUid user, EntityUid target, EntityUid implanter, ImplanterComponent component)
|
||||
{
|
||||
var implanterContainer = component.ImplanterSlot.ContainerSlot;
|
||||
|
||||
if (implanterContainer is null)
|
||||
return;
|
||||
|
||||
var implant = implanterContainer.ContainedEntities.FirstOrDefault();
|
||||
|
||||
if (!TryComp<SubdermalImplantComponent>(implant, out var implantComp))
|
||||
if (!CanImplant(user, target, implanter, component, out var implant, out var implantComp))
|
||||
return;
|
||||
|
||||
//If the target doesn't have the implanted component, add it.
|
||||
var implantedComp = EnsureComp<ImplantedComponent>(target);
|
||||
var implantContainer = implantedComp.ImplantContainer;
|
||||
|
||||
implanterContainer.Remove(implant);
|
||||
component.ImplanterSlot.ContainerSlot?.Remove(implant.Value);
|
||||
implantComp.ImplantedEntity = target;
|
||||
implantContainer.OccludesLight = false;
|
||||
implantContainer.Insert(implant);
|
||||
implantContainer.Insert(implant.Value);
|
||||
|
||||
if (component.CurrentMode == ImplanterToggleMode.Inject && !component.ImplantOnly)
|
||||
DrawMode(component);
|
||||
|
||||
else
|
||||
ImplantMode(component);
|
||||
|
||||
Dirty(component);
|
||||
}
|
||||
|
||||
public bool CanImplant(
|
||||
EntityUid user,
|
||||
EntityUid target,
|
||||
EntityUid implanter,
|
||||
ImplanterComponent component,
|
||||
[NotNullWhen(true)] out EntityUid? implant,
|
||||
[NotNullWhen(true)] out SubdermalImplantComponent? implantComp)
|
||||
{
|
||||
implant = component.ImplanterSlot.ContainerSlot?.ContainedEntities?.FirstOrDefault();
|
||||
if (!TryComp<SubdermalImplantComponent>(implant, out implantComp))
|
||||
return false;
|
||||
|
||||
var ev = new AddImplantAttemptEvent(user, target, implant.Value, implanter);
|
||||
RaiseLocalEvent(target, ev);
|
||||
return !ev.Cancelled;
|
||||
}
|
||||
|
||||
//Draw the implant out of the target
|
||||
//TODO: Rework when surgery is in so implant cases can be a thing
|
||||
public void Draw(EntityUid implanter, EntityUid user, EntityUid target, ImplanterComponent component)
|
||||
@@ -167,3 +179,19 @@ public sealed class ImplantEvent : SimpleDoAfterEvent
|
||||
public sealed class DrawEvent : SimpleDoAfterEvent
|
||||
{
|
||||
}
|
||||
|
||||
public sealed class AddImplantAttemptEvent : CancellableEntityEventArgs
|
||||
{
|
||||
public readonly EntityUid User;
|
||||
public readonly EntityUid Target;
|
||||
public readonly EntityUid Implant;
|
||||
public readonly EntityUid Implanter;
|
||||
|
||||
public AddImplantAttemptEvent(EntityUid user, EntityUid target, EntityUid implant, EntityUid implanter)
|
||||
{
|
||||
User = user;
|
||||
Target = target;
|
||||
Implant = implant;
|
||||
Implanter = implanter;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user