SpawnMultiple cleanup in stacksystem (#13441)
This commit is contained in:
@@ -6,6 +6,9 @@ using Content.Server.Power.Components;
|
||||
using Content.Server.Construction.Components;
|
||||
using Content.Server.Stack;
|
||||
using Content.Shared.Database;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Prototypes;
|
||||
|
||||
namespace Content.Server.Materials;
|
||||
|
||||
@@ -15,6 +18,7 @@ namespace Content.Server.Materials;
|
||||
public sealed class MaterialStorageSystem : SharedMaterialStorageSystem
|
||||
{
|
||||
[Dependency] private readonly IAdminLogManager _adminLogger = default!;
|
||||
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
|
||||
[Dependency] private readonly SharedAudioSystem _audio = default!;
|
||||
[Dependency] private readonly SharedPopupSystem _popup = default!;
|
||||
[Dependency] private readonly StackSystem _stackSystem = default!;
|
||||
@@ -32,7 +36,7 @@ public sealed class MaterialStorageSystem : SharedMaterialStorageSystem
|
||||
|
||||
foreach (var (material, amount) in component.Storage)
|
||||
{
|
||||
_stackSystem.SpawnMultipleFromMaterial(amount, material, Transform(uid).Coordinates);
|
||||
SpawnMultipleFromMaterial(amount, material, Transform(uid).Coordinates);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -56,4 +60,42 @@ public sealed class MaterialStorageSystem : SharedMaterialStorageSystem
|
||||
$"{ToPrettyString(user):player} inserted {count} {ToPrettyString(toInsert):inserted} into {ToPrettyString(receiver):receiver}");
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Spawn an amount of a material in stack entities.
|
||||
/// Note the 'amount' is material dependent.
|
||||
/// 1 biomass = 1 biomass in its stack,
|
||||
/// but 100 plasma = 1 sheet of plasma, etc.
|
||||
/// </summary>
|
||||
[PublicAPI]
|
||||
public List<EntityUid> SpawnMultipleFromMaterial(int amount, string material, EntityCoordinates coordinates)
|
||||
{
|
||||
if (!_prototypeManager.TryIndex<MaterialPrototype>(material, out var stackType))
|
||||
{
|
||||
Logger.Error("Failed to index material prototype " + material);
|
||||
return new List<EntityUid>();
|
||||
}
|
||||
|
||||
return SpawnMultipleFromMaterial(amount, stackType, coordinates);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Spawn an amount of a material in stack entities.
|
||||
/// Note the 'amount' is material dependent.
|
||||
/// 1 biomass = 1 biomass in its stack,
|
||||
/// but 100 plasma = 1 sheet of plasma, etc.
|
||||
/// </summary>
|
||||
public List<EntityUid> SpawnMultipleFromMaterial(int amount, MaterialPrototype materialProto, EntityCoordinates coordinates)
|
||||
{
|
||||
if (amount <= 0)
|
||||
return new List<EntityUid>();
|
||||
|
||||
var entProto = _prototypeManager.Index<EntityPrototype>(materialProto.StackEntity);
|
||||
if (!entProto.TryGetComponent<MaterialComponent>(out var material))
|
||||
return new List<EntityUid>();
|
||||
|
||||
var materialPerStack = material.Materials[materialProto.ID];
|
||||
var amountToSpawn = amount / materialPerStack;
|
||||
return _stackSystem.SpawnMultiple(materialProto.StackEntity, amountToSpawn, coordinates);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user