mirror of
https://github.com/DeltaV-Station/Delta-v.git
synced 2026-09-30 16:17:27 +00:00
48 lines
1.5 KiB
C#
48 lines
1.5 KiB
C#
using System.Numerics;
|
|
using Robust.Shared.Containers;
|
|
using Robust.Shared.Map;
|
|
|
|
namespace Content.Shared.Body;
|
|
|
|
public sealed class InitialBodySystem : EntitySystem
|
|
{
|
|
[Dependency] private readonly SharedContainerSystem _container = default!;
|
|
|
|
public override void Initialize()
|
|
{
|
|
base.Initialize();
|
|
|
|
SubscribeLocalEvent<InitialBodyComponent, MapInitEvent>(OnMapInit);
|
|
}
|
|
|
|
private void OnMapInit(Entity<InitialBodyComponent> ent, ref MapInitEvent args)
|
|
{
|
|
if (!TryComp<ContainerManagerComponent>(ent, out var containerComp))
|
|
return;
|
|
|
|
if (TerminatingOrDeleted(ent) || !Exists(ent))
|
|
return;
|
|
|
|
if (!_container.TryGetContainer(ent, BodyComponent.ContainerID, out var container, containerComp))
|
|
{
|
|
Log.Error($"Entity {ToPrettyString(ent)} with a {nameof(InitialBodyComponent)} is missing a container ({BodyComponent.ContainerID}).");
|
|
return;
|
|
}
|
|
|
|
var xform = Transform(ent);
|
|
var coords = new EntityCoordinates(ent, Vector2.Zero);
|
|
|
|
foreach (var proto in ent.Comp.Organs.Values)
|
|
{
|
|
// TODO: When e#6192 is merged replace this all with TrySpawnInContainer...
|
|
var spawn = Spawn(proto, coords);
|
|
|
|
if (!_container.Insert(spawn, container, containerXform: xform))
|
|
{
|
|
Log.Error($"Entity {ToPrettyString(ent)} with a {nameof(InitialBodyComponent)} failed to insert an entity: {ToPrettyString(spawn)}.\n");
|
|
Del(spawn);
|
|
}
|
|
}
|
|
}
|
|
}
|