ImplantedSystem.cs 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. using Content.Server.Body.Components;
  2. using Content.Shared.Implants.Components;
  3. using Content.Shared.Storage;
  4. using Robust.Shared.Containers;
  5. namespace Content.Server.Implants;
  6. public sealed partial class ImplanterSystem
  7. {
  8. public void InitializeImplanted()
  9. {
  10. SubscribeLocalEvent<ImplantedComponent, ComponentInit>(OnImplantedInit);
  11. SubscribeLocalEvent<ImplantedComponent, ComponentShutdown>(OnShutdown);
  12. SubscribeLocalEvent<ImplantedComponent, BeingGibbedEvent>(OnGibbed);
  13. }
  14. private void OnImplantedInit(Entity<ImplantedComponent> ent, ref ComponentInit args)
  15. {
  16. ent.Comp.ImplantContainer = _container.EnsureContainer<Container>(ent.Owner, ImplanterComponent.ImplantSlotId);
  17. ent.Comp.ImplantContainer.OccludesLight = false;
  18. }
  19. private void OnShutdown(Entity<ImplantedComponent> ent, ref ComponentShutdown args)
  20. {
  21. //If the entity is deleted, get rid of the implants
  22. _container.CleanContainer(ent.Comp.ImplantContainer);
  23. }
  24. private void OnGibbed(Entity<ImplantedComponent> ent, ref BeingGibbedEvent args)
  25. {
  26. // Drop the storage implant contents before the implants are deleted by the body being gibbed
  27. foreach (var implant in ent.Comp.ImplantContainer.ContainedEntities)
  28. {
  29. if (TryComp<StorageComponent>(implant, out var storage))
  30. _container.EmptyContainer(storage.Container, destination: Transform(ent).Coordinates);
  31. }
  32. }
  33. }