Add RequiresGrid component (#23394)

* saving working code

* add checks for deletion

(cherry picked from commit 487dd113b05aa54a8683f6be980a60f3e431d226)
This commit is contained in:
HoofedEar 2024-02-22 03:26:02 -08:00 committed by Debug
parent 2c441ff66a
commit e96254fb4c
No known key found for this signature in database
GPG Key ID: 271270A74EF9C350
2 changed files with 40 additions and 0 deletions

View File

@ -0,0 +1,11 @@
namespace Content.Server.RequiresGrid;
/// <summary>
/// Destroys an entity when they no longer are part of a Grid
/// </summary>
[RegisterComponent]
[Access(typeof(RequiresGridSystem))]
public sealed partial class RequiresGridComponent : Component
{
}

View File

@ -0,0 +1,29 @@
using Content.Server.Destructible;
namespace Content.Server.RequiresGrid;
public sealed class RequiresGridSystem : EntitySystem
{
[Dependency] private readonly DestructibleSystem _destructible = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<RequiresGridComponent, EntParentChangedMessage>(OnEntParentChanged);
}
private void OnEntParentChanged(EntityUid owner, RequiresGridComponent component, EntParentChangedMessage args)
{
if (args.OldParent == null)
return;
if (args.Transform.GridUid != null)
return;
if (TerminatingOrDeleted(owner))
return;
_destructible.DestroyEntity(owner);
}
}