Files
tbd-station-14/Content.Server/Shuttles/EntitySystems/SpaceGarbageSystem.cs
metalgearsloth 8d46dc42e7 Add a garbage collection component for grid movement (#7776)
If we move a station and there's thousands of bullets in the way we shouldn't just indefinitely lag the server as a result.
2022-04-26 18:25:57 +10:00

29 lines
913 B
C#

using Content.Server.Shuttles.Components;
using Robust.Shared.Physics;
using Robust.Shared.Physics.Dynamics;
namespace Content.Server.Shuttles.EntitySystems;
/// <summary>
/// Deletes anything with <see cref="SpaceGarbageComponent"/> that has a cross-grid collision with a static body.
/// </summary>
public sealed class SpaceGarbageSystem : EntitySystem
{
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<SpaceGarbageComponent, StartCollideEvent>(OnCollide);
}
private void OnCollide(EntityUid uid, SpaceGarbageComponent component, StartCollideEvent args)
{
var ourXform = Transform(args.OurFixture.Body.Owner);
var otherXform = Transform(args.OtherFixture.Body.Owner);
if (ourXform.GridID == otherXform.GridID ||
args.OtherFixture.Body.BodyType != BodyType.Static) return;
QueueDel(uid);
}
}