using Content.Shared.Actions; using Content.Shared.Implants; using Content.Shared.Storage; using Content.Shared.Storage.EntitySystems; using Robust.Shared.Containers; namespace Content.Shared.DeltaV.Implants.Radio; /// /// This handles radio implants, which you can implant to get access to a radio channel. /// public abstract class SharedRadioImplantSystem : EntitySystem { /// public override void Initialize() { SubscribeLocalEvent(OnImplanted); SubscribeLocalEvent(OnPossiblyUnimplanted); } /// /// Handles implantation of the implant. /// private void OnImplanted(EntityUid uid, RadioImplantComponent component, ImplantImplantedEvent args) { if (args.Implanted is not { Valid: true }) return; component.Implantee = args.Implanted.Value; Dirty(uid, component); // make sure the person entity gets slapped with a component so it can react to it talking. var hasRadioImplantComponent = EnsureComp(args.Implanted.Value); hasRadioImplantComponent.Implant = uid; Dirty(component.Implantee.Value, hasRadioImplantComponent); } /// /// Handles removal of the implant from its containing mob. /// /// Done via because there is no specific event for an implant being removed. private void OnPossiblyUnimplanted(EntityUid uid, RadioImplantComponent component, EntGotRemovedFromContainerMessage args) { if (Terminating(uid)) return; // this gets fired if it gets removed from ANY container but really, we just want to know if it was removed from its owner... // so check if the ent we got implanted into matches the container's owner (here, the container's owner is the entity) if (component.Implantee is not null && component.Implantee == args.Container.Owner) { RemComp(component.Implantee.Value); component.Implantee = null; } } }