#nullable enable
using System;
using Content.Server.GameObjects.Components.Stack;
using Content.Shared.GameObjects.Components;
using Content.Shared.Stacks;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Map;
namespace Content.Server.Construction
{
public static class StackHelpers
{
///
/// Spawns a stack of a specified type given an amount.
///
public static IEntity SpawnStack(StackPrototype stack, int amount, EntityCoordinates coordinates, IEntityManager? entityManager = null)
{
entityManager ??= IoCManager.Resolve();
// TODO: Add more.
string prototype = stack.Spawn ?? throw new ArgumentOutOfRangeException(nameof(stack),
"Stack type doesn't have a prototype specified yet!");
var ent = entityManager.SpawnEntity(prototype, coordinates);
var stackComponent = ent.GetComponent();
stackComponent.Count = Math.Min(amount, stackComponent.MaxCount);
return ent;
}
}
}