using Robust.Shared.Containers;
using Robust.Shared.Network;
namespace Content.Shared.EntityEffects.Effects.EntitySpawning;
///
/// Spawns a given number of entities of a given prototype in a specified container owned by this entity.
/// Acts like if it cannot spawn the prototype in the specified container.
/// Amount is modified by scale.
///
///
public sealed partial class SpawnEntityInContainerOrDropEntityEffectSystem : EntityEffectSystem
{
[Dependency] private readonly INetManager _net = default!;
protected override void Effect(Entity entity, ref EntityEffectEvent args)
{
var quantity = args.Effect.Number * (int)Math.Floor(args.Scale);
var proto = args.Effect.Entity;
var container = args.Effect.ContainerName;
var xform = Transform(entity);
if (args.Effect.Predicted)
{
for (var i = 0; i < quantity; i++)
{
PredictedSpawnInContainerOrDrop(proto, entity, container, xform, entity.Comp);
}
}
else if (_net.IsServer)
{
for (var i = 0; i < quantity; i++)
{
SpawnInContainerOrDrop(proto, entity, container, xform, entity.Comp);
}
}
}
}
///
public sealed partial class SpawnEntityInContainerOrDrop : BaseSpawnEntityEntityEffect
{
///
/// Name of the container we're trying to spawn into.
///
[DataField(required: true)]
public string ContainerName;
}