Portable Generator Rework (#19302)

This commit is contained in:
Pieter-Jan Briers
2023-08-25 20:40:42 +02:00
committed by GitHub
parent 50828363fe
commit bf16698efa
73 changed files with 1933 additions and 473 deletions

View File

@@ -1,4 +1,5 @@
using Content.Server.Administration.Logs;
using System.Linq;
using Content.Server.Administration.Logs;
using Content.Shared.Materials;
using Content.Shared.Popups;
using Content.Shared.Stacks;
@@ -129,4 +130,63 @@ public sealed class MaterialStorageSystem : SharedMaterialStorageSystem
overflowMaterial = amount - amountToSpawn * materialPerStack;
return _stackSystem.SpawnMultiple(materialProto.StackEntity, amountToSpawn, coordinates);
}
/// <summary>
/// Eject a material out of this storage. The internal counts are updated.
/// Material that cannot be ejected stays in storage. (e.g. only have 50 but a sheet needs 100).
/// </summary>
/// <param name="entity">The entity with storage to eject from.</param>
/// <param name="material">The material prototype to eject.</param>
/// <param name="maxAmount">The maximum amount to eject. If not given, as much as possible is ejected.</param>
/// <param name="coordinates">The position where to spawn the created sheets. If not given, they're spawned next to the entity.</param>
/// <param name="component">The storage component on <paramref name="entity"/>. Resolved automatically if not given.</param>
/// <returns>The stack entities that were spawned.</returns>
public List<EntityUid> EjectMaterial(
EntityUid entity,
string material,
int? maxAmount = null,
EntityCoordinates? coordinates = null,
MaterialStorageComponent? component = null)
{
if (!Resolve(entity, ref component))
return new List<EntityUid>();
coordinates ??= Transform(entity).Coordinates;
var amount = GetMaterialAmount(entity, material, component);
if (maxAmount != null)
amount = Math.Min(maxAmount.Value, amount);
var spawned = SpawnMultipleFromMaterial(amount, material, coordinates.Value, out var overflow);
TryChangeMaterialAmount(entity, material, -(amount - overflow), component);
return spawned;
}
/// <summary>
/// Eject all material stored in an entity, with the same mechanics as <see cref="EjectMaterial"/>.
/// </summary>
/// <param name="entity">The entity with storage to eject from.</param>
/// <param name="coordinates">The position where to spawn the created sheets. If not given, they're spawned next to the entity.</param>
/// <param name="component">The storage component on <paramref name="entity"/>. Resolved automatically if not given.</param>
/// <returns>The stack entities that were spawned.</returns>
public List<EntityUid> EjectAllMaterial(
EntityUid entity,
EntityCoordinates? coordinates = null,
MaterialStorageComponent? component = null)
{
if (!Resolve(entity, ref component))
return new List<EntityUid>();
coordinates ??= Transform(entity).Coordinates;
var allSpawned = new List<EntityUid>();
foreach (var material in component.Storage.Keys.ToArray())
{
var spawned = EjectMaterial(entity, material, null, coordinates, component);
allSpawned.AddRange(spawned);
}
return allSpawned;
}
}