1
0

SpaceGarbageSystem.cs 1.1 KB

1234567891011121314151617181920212223242526272829303132333435
  1. using Content.Shared.Shuttles.Components;
  2. using Robust.Shared.Physics;
  3. using Robust.Shared.Physics.Dynamics;
  4. using Robust.Shared.Physics.Events;
  5. namespace Content.Server.Shuttles.Systems;
  6. /// <summary>
  7. /// Deletes anything with <see cref="SpaceGarbageComponent"/> that has a cross-grid collision with a static body.
  8. /// </summary>
  9. public sealed class SpaceGarbageSystem : EntitySystem
  10. {
  11. private EntityQuery<TransformComponent> _xformQuery;
  12. public override void Initialize()
  13. {
  14. base.Initialize();
  15. _xformQuery = GetEntityQuery<TransformComponent>();
  16. SubscribeLocalEvent<SpaceGarbageComponent, StartCollideEvent>(OnCollide);
  17. }
  18. private void OnCollide(EntityUid uid, SpaceGarbageComponent component, ref StartCollideEvent args)
  19. {
  20. if (args.OtherBody.BodyType != BodyType.Static)
  21. return;
  22. var ourXform = _xformQuery.GetComponent(uid);
  23. var otherXform = _xformQuery.GetComponent(args.OtherEntity);
  24. if (ourXform.GridUid == otherXform.GridUid)
  25. return;
  26. QueueDel(uid);
  27. }
  28. }