NymphSystem.cs 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. using Content.Server.Mind;
  2. using Content.Shared.Species.Components;
  3. using Content.Shared.Body.Events;
  4. using Content.Shared.Zombies;
  5. using Content.Server.Zombies;
  6. using Robust.Shared.Prototypes;
  7. using Robust.Shared.Timing;
  8. namespace Content.Server.Species.Systems;
  9. public sealed partial class NymphSystem : EntitySystem
  10. {
  11. [Dependency] private readonly IPrototypeManager _protoManager= default!;
  12. [Dependency] private readonly MindSystem _mindSystem = default!;
  13. [Dependency] private readonly IGameTiming _timing = default!;
  14. [Dependency] private readonly ZombieSystem _zombie = default!;
  15. public override void Initialize()
  16. {
  17. base.Initialize();
  18. SubscribeLocalEvent<NymphComponent, OrganRemovedFromBodyEvent>(OnRemovedFromPart);
  19. }
  20. private void OnRemovedFromPart(EntityUid uid, NymphComponent comp, ref OrganRemovedFromBodyEvent args)
  21. {
  22. if (!_timing.IsFirstTimePredicted)
  23. return;
  24. if (TerminatingOrDeleted(uid) || TerminatingOrDeleted(args.OldBody))
  25. return;
  26. if (!_protoManager.TryIndex<EntityPrototype>(comp.EntityPrototype, out var entityProto))
  27. return;
  28. // Get the organs' position & spawn a nymph there
  29. var coords = Transform(uid).Coordinates;
  30. var nymph = EntityManager.SpawnAtPosition(entityProto.ID, coords);
  31. if (HasComp<ZombieComponent>(args.OldBody)) // Zombify the new nymph if old one is a zombie
  32. _zombie.ZombifyEntity(nymph);
  33. // Move the mind if there is one and it's supposed to be transferred
  34. if (comp.TransferMind == true && _mindSystem.TryGetMind(args.OldBody, out var mindId, out var mind))
  35. _mindSystem.TransferTo(mindId, nymph, mind: mind);
  36. // Delete the old organ
  37. QueueDel(uid);
  38. }
  39. }