2020-02-22 15:40:09 -08:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using Robust.Server.Interfaces.GameObjects;
|
|
|
|
|
|
using Robust.Shared.GameObjects;
|
|
|
|
|
|
using Robust.Shared.Interfaces.GameObjects;
|
|
|
|
|
|
using Robust.Shared.IoC;
|
|
|
|
|
|
using Robust.Shared.Serialization;
|
2020-09-08 13:30:22 +02:00
|
|
|
|
using Robust.Shared.ViewVariables;
|
2020-02-22 15:40:09 -08:00
|
|
|
|
|
|
|
|
|
|
namespace Content.Server.GameObjects.Components.Items.Storage.Fill
|
|
|
|
|
|
{
|
|
|
|
|
|
[RegisterComponent]
|
|
|
|
|
|
internal sealed class StorageFillComponent : Component, IMapInit
|
|
|
|
|
|
{
|
2020-08-24 14:10:28 +02:00
|
|
|
|
[Dependency] private readonly IEntityManager _entityManager = default!;
|
|
|
|
|
|
|
2020-02-22 15:40:09 -08:00
|
|
|
|
public override string Name => "StorageFill";
|
|
|
|
|
|
|
2020-09-08 13:30:22 +02:00
|
|
|
|
[ViewVariables]
|
2020-02-22 15:40:09 -08:00
|
|
|
|
private List<string> _contents = new List<string>();
|
|
|
|
|
|
|
|
|
|
|
|
public override void ExposeData(ObjectSerializer serializer)
|
|
|
|
|
|
{
|
|
|
|
|
|
base.ExposeData(serializer);
|
|
|
|
|
|
|
|
|
|
|
|
serializer.DataField(ref _contents, "contents", new List<string>());
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void IMapInit.MapInit()
|
|
|
|
|
|
{
|
|
|
|
|
|
if (_contents.Count == 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var storage = Owner.GetComponent<IStorageComponent>();
|
|
|
|
|
|
|
|
|
|
|
|
void Spawn(string prototype)
|
|
|
|
|
|
{
|
2020-09-06 16:11:53 +02:00
|
|
|
|
storage.Insert(_entityManager.SpawnEntity(prototype, Owner.Transform.Coordinates));
|
2020-02-22 15:40:09 -08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
foreach (var prototype in _contents)
|
|
|
|
|
|
{
|
|
|
|
|
|
Spawn(prototype);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|