Files
OldThink/Content.Server/Storage/EntitySystems/StorageSystem.Fill.cs

40 lines
1.4 KiB
C#
Raw Normal View History

2022-01-29 22:45:40 +11:00
using Content.Server.Storage.Components;
using Content.Shared.Storage;
2022-01-29 22:45:40 +11:00
namespace Content.Server.Storage.EntitySystems;
public sealed partial class StorageSystem
{
private void OnStorageFillMapInit(EntityUid uid, StorageFillComponent component, MapInitEvent args)
{
if (component.Contents.Count == 0) return;
2022-07-13 19:11:59 -04:00
TryComp<ServerStorageComponent>(uid, out var serverStorageComp);
2022-07-13 19:11:59 -04:00
TryComp<EntityStorageComponent>(uid, out var entityStorageComp);
if (entityStorageComp == null && serverStorageComp == null)
2022-01-29 22:45:40 +11:00
{
Logger.Error($"StorageFillComponent couldn't find any StorageComponent ({uid})");
return;
}
var coordinates = Transform(uid).Coordinates;
var spawnItems = EntitySpawnCollection.GetSpawns(component.Contents, _random);
foreach (var item in spawnItems)
2022-01-29 22:45:40 +11:00
{
var ent = EntityManager.SpawnEntity(item, coordinates);
2022-01-29 22:45:40 +11:00
// handle depending on storage component, again this should be unified after ECS
if (entityStorageComp != null && _entityStorage.Insert(ent, uid))
continue;
if (serverStorageComp != null && Insert(uid, ent, serverStorageComp, false))
continue;
2022-01-29 22:45:40 +11:00
Logger.ErrorS("storage", $"Tried to StorageFill {item} inside {ToPrettyString(uid)} but can't.");
EntityManager.DeleteEntity(ent);
}
}
2022-01-29 22:45:40 +11:00
}