2020-12-03 22:49:00 +01:00
|
|
|
|
#nullable enable
|
|
|
|
|
|
using System;
|
|
|
|
|
|
using Content.Server.GameObjects.Components.Stack;
|
|
|
|
|
|
using Content.Shared.GameObjects.Components;
|
2021-02-25 06:18:29 +01:00
|
|
|
|
using Content.Shared.Stacks;
|
2021-02-11 01:13:03 -08:00
|
|
|
|
using Robust.Shared.GameObjects;
|
2020-12-03 22:49:00 +01:00
|
|
|
|
using Robust.Shared.IoC;
|
|
|
|
|
|
using Robust.Shared.Map;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Content.Server.Construction
|
|
|
|
|
|
{
|
|
|
|
|
|
public static class StackHelpers
|
|
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Spawns a stack of a specified type given an amount.
|
|
|
|
|
|
/// </summary>
|
2021-02-25 06:18:29 +01:00
|
|
|
|
public static IEntity SpawnStack(StackPrototype stack, int amount, EntityCoordinates coordinates, IEntityManager? entityManager = null)
|
2020-12-03 22:49:00 +01:00
|
|
|
|
{
|
|
|
|
|
|
entityManager ??= IoCManager.Resolve<IEntityManager>();
|
|
|
|
|
|
|
2021-02-25 06:18:29 +01:00
|
|
|
|
// TODO: Add more.
|
|
|
|
|
|
string prototype = stack.Spawn ?? throw new ArgumentOutOfRangeException(nameof(stack),
|
|
|
|
|
|
"Stack type doesn't have a prototype specified yet!");
|
2020-12-03 22:49:00 +01:00
|
|
|
|
|
|
|
|
|
|
var ent = entityManager.SpawnEntity(prototype, coordinates);
|
|
|
|
|
|
var stackComponent = ent.GetComponent<StackComponent>();
|
|
|
|
|
|
|
|
|
|
|
|
stackComponent.Count = Math.Min(amount, stackComponent.MaxCount);
|
|
|
|
|
|
|
|
|
|
|
|
return ent;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|