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

50 lines
1.9 KiB
C#
Raw Normal View History

using Content.Server.Spawners.Components;
2022-01-29 22:45:40 +11:00
using Content.Server.Storage.Components;
using Content.Shared.Prototypes;
using Content.Shared.Storage;
2023-09-11 21:20:46 +10:00
using Content.Shared.Storage.Components;
using Robust.Shared.Prototypes;
using Robust.Shared.Utility;
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)
{
2023-09-11 21:20:46 +10:00
if (component.Contents.Count == 0)
return;
2022-07-13 19:11:59 -04:00
2023-09-11 21:20:46 +10:00
TryComp<StorageComponent>(uid, out var storageComp);
2022-07-13 19:11:59 -04:00
TryComp<EntityStorageComponent>(uid, out var entityStorageComp);
2023-09-11 21:20:46 +10:00
if (entityStorageComp == null && storageComp == null)
2022-01-29 22:45:40 +11:00
{
2023-09-11 21:20:46 +10:00
Log.Error($"StorageFillComponent couldn't find any StorageComponent ({uid})");
2022-01-29 22:45:40 +11:00
return;
}
var coordinates = Transform(uid).Coordinates;
2023-09-11 21:20:46 +10:00
var spawnItems = EntitySpawnCollection.GetSpawns(component.Contents, Random);
foreach (var item in spawnItems)
2022-01-29 22:45:40 +11:00
{
// No, you are not allowed to fill a container with entity spawners.
DebugTools.Assert(!_prototype.Index<EntityPrototype>(item)
.HasComponent(typeof(RandomSpawnerComponent)));
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, entityStorageComp))
2023-09-11 21:20:46 +10:00
continue;
var reason = string.Empty;
if (storageComp != null && Insert(uid, ent, out _, out reason, storageComp: storageComp, playSound: false))
continue;
2022-01-29 22:45:40 +11:00
Log.Error($"Tried to StorageFill {item} inside {ToPrettyString(uid)} but can't. Reason: {Loc.GetString(reason ?? "no reason.")}");
EntityManager.DeleteEntity(ent);
}
}
2022-01-29 22:45:40 +11:00
}