2023-10-16 16:54:10 +11:00
|
|
|
using Content.Server.Spawners.Components;
|
2022-01-29 22:45:40 +11:00
|
|
|
using Content.Server.Storage.Components;
|
2023-10-16 16:54:10 +11:00
|
|
|
using Content.Shared.Prototypes;
|
2022-03-28 09:58:13 -07:00
|
|
|
using Content.Shared.Storage;
|
2023-09-11 21:20:46 +10:00
|
|
|
using Content.Shared.Storage.Components;
|
2023-10-16 16:54:10 +11:00
|
|
|
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);
|
2022-03-28 09:58:13 -07:00
|
|
|
foreach (var item in spawnItems)
|
2022-01-29 22:45:40 +11:00
|
|
|
{
|
2023-10-16 16:54:10 +11:00
|
|
|
// No, you are not allowed to fill a container with entity spawners.
|
|
|
|
|
DebugTools.Assert(!_prototype.Index<EntityPrototype>(item)
|
|
|
|
|
.HasComponent(typeof(RandomSpawnerComponent)));
|
2022-03-28 09:58:13 -07:00
|
|
|
var ent = EntityManager.SpawnEntity(item, coordinates);
|
2022-01-29 22:45:40 +11:00
|
|
|
|
2022-04-28 06:11:15 -06:00
|
|
|
// handle depending on storage component, again this should be unified after ECS
|
2023-10-16 16:54:10 +11:00
|
|
|
if (entityStorageComp != null && EntityStorage.Insert(ent, uid, entityStorageComp))
|
2023-09-11 21:20:46 +10:00
|
|
|
continue;
|
2022-04-28 06:11:15 -06:00
|
|
|
|
2023-09-12 22:34:04 +10:00
|
|
|
if (storageComp != null && Insert(uid, ent, out _, storageComp: storageComp, playSound: false))
|
2022-04-28 06:11:15 -06:00
|
|
|
continue;
|
2022-01-29 22:45:40 +11:00
|
|
|
|
2023-09-11 21:20:46 +10:00
|
|
|
Log.Error($"Tried to StorageFill {item} inside {ToPrettyString(uid)} but can't.");
|
2022-03-28 09:58:13 -07:00
|
|
|
EntityManager.DeleteEntity(ent);
|
2022-03-27 16:04:58 -05:00
|
|
|
}
|
|
|
|
|
}
|
2022-01-29 22:45:40 +11:00
|
|
|
}
|