GenerateChildPartSystem.cs 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. // SPDX-FileCopyrightText: 2024 gluesniffler <159397573+gluesniffler@users.noreply.github.com>
  2. // SPDX-FileCopyrightText: 2025 Aiden <28298836+Aidenkrz@users.noreply.github.com>
  3. //
  4. // SPDX-License-Identifier: AGPL-3.0-or-later
  5. using Content.Shared.Body.Part;
  6. using Content.Shared.Body.Systems;
  7. using Content.Shared._Shitmed.Body.Events;
  8. using Robust.Shared.Map;
  9. using Robust.Shared.Timing;
  10. using Robust.Shared.Network;
  11. using System.Numerics;
  12. namespace Content.Shared._Shitmed.BodyEffects.Subsystems;
  13. public sealed class GenerateChildPartSystem : EntitySystem
  14. {
  15. [Dependency] private readonly SharedBodySystem _bodySystem = default!;
  16. [Dependency] private readonly IGameTiming _timing = default!;
  17. [Dependency] private readonly INetManager _net = default!;
  18. public override void Initialize()
  19. {
  20. base.Initialize();
  21. SubscribeLocalEvent<GenerateChildPartComponent, BodyPartComponentsModifyEvent>(OnPartComponentsModify);
  22. }
  23. private void OnPartComponentsModify(EntityUid uid, GenerateChildPartComponent component, ref BodyPartComponentsModifyEvent args)
  24. {
  25. if (args.Add)
  26. CreatePart(uid, component);
  27. //else
  28. //DeletePart(uid, component);
  29. }
  30. private void CreatePart(EntityUid uid, GenerateChildPartComponent component)
  31. {
  32. if (!TryComp(uid, out BodyPartComponent? partComp)
  33. || partComp.Body is null
  34. || component.Active)
  35. return;
  36. // I pinky swear to also move this to the server side properly next update :)
  37. if (_net.IsServer)
  38. {
  39. var childPart = Spawn(component.Id, new EntityCoordinates(partComp.Body.Value, Vector2.Zero));
  40. if (!TryComp(childPart, out BodyPartComponent? childPartComp))
  41. return;
  42. var slotName = _bodySystem.GetSlotFromBodyPart(childPartComp);
  43. _bodySystem.TryCreatePartSlot(uid, slotName, childPartComp.PartType, out var _);
  44. _bodySystem.AttachPart(uid, slotName, childPart, partComp, childPartComp);
  45. component.ChildPart = childPart;
  46. component.Active = true;
  47. Dirty(childPart, childPartComp);
  48. }
  49. }
  50. // Still unusued, gotta figure out what I want to do with this function outside of fuckery with mantis blades.
  51. private void DeletePart(EntityUid uid, GenerateChildPartComponent component)
  52. {
  53. if (!TryComp(uid, out BodyPartComponent? partComp))
  54. return;
  55. _bodySystem.DropSlotContents((uid, partComp));
  56. var ev = new BodyPartDroppedEvent((uid, partComp));
  57. RaiseLocalEvent(uid, ref ev);
  58. QueueDel(uid);
  59. }
  60. }