2023-07-08 14:08:32 +10:00
|
|
|
using System.Numerics;
|
2022-10-17 05:43:33 +13:00
|
|
|
using Robust.Shared.Containers;
|
|
|
|
|
using Robust.Shared.Map;
|
|
|
|
|
|
2023-03-24 22:00:29 +13:00
|
|
|
namespace Content.Shared.Containers;
|
2022-10-17 05:43:33 +13:00
|
|
|
|
|
|
|
|
public sealed class ContainerFillSystem : EntitySystem
|
|
|
|
|
{
|
|
|
|
|
[Dependency] private readonly SharedContainerSystem _containerSystem = default!;
|
|
|
|
|
|
|
|
|
|
public override void Initialize()
|
|
|
|
|
{
|
|
|
|
|
base.Initialize();
|
|
|
|
|
SubscribeLocalEvent<ContainerFillComponent, MapInitEvent>(OnMapInit);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnMapInit(EntityUid uid, ContainerFillComponent component, MapInitEvent args)
|
|
|
|
|
{
|
|
|
|
|
if (!TryComp(uid, out ContainerManagerComponent? containerComp))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
var xform = Transform(uid);
|
|
|
|
|
var coords = new EntityCoordinates(uid, Vector2.Zero);
|
|
|
|
|
|
|
|
|
|
foreach (var (contaienrId, prototypes) in component.Containers)
|
|
|
|
|
{
|
|
|
|
|
if (!_containerSystem.TryGetContainer(uid, contaienrId, out var container, containerComp))
|
|
|
|
|
{
|
2023-06-27 23:56:52 +10:00
|
|
|
Log.Error($"Entity {ToPrettyString(uid)} with a {nameof(ContainerFillComponent)} is missing a container ({contaienrId}).");
|
2022-10-17 05:43:33 +13:00
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach (var proto in prototypes)
|
|
|
|
|
{
|
|
|
|
|
var ent = Spawn(proto, coords);
|
2023-12-27 21:30:03 -08:00
|
|
|
if (!_containerSystem.Insert(ent, container, containerXform: xform))
|
2022-10-17 05:43:33 +13:00
|
|
|
{
|
2023-06-27 23:56:52 +10:00
|
|
|
Log.Error($"Entity {ToPrettyString(uid)} with a {nameof(ContainerFillComponent)} failed to insert an entity: {ToPrettyString(ent)}.");
|
2023-09-01 12:30:29 +10:00
|
|
|
Transform(ent).AttachToGridOrMap();
|
2022-10-17 05:43:33 +13:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|