Update StackSystem and add SpawnMultiple targeting EntityUid (#29686)
* Update StackSystem and add SpawnMultiple targeting EntityUid * Update Content.Server/Stack/StackSystem.cs * Update Content.Server/Stack/StackSystem.cs --------- Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com>
This commit is contained in:
@@ -100,19 +100,55 @@ namespace Content.Server.Stack
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public List<EntityUid> SpawnMultiple(string entityPrototype, int amount, EntityCoordinates spawnPosition)
|
public List<EntityUid> SpawnMultiple(string entityPrototype, int amount, EntityCoordinates spawnPosition)
|
||||||
{
|
{
|
||||||
var proto = _prototypeManager.Index<EntityPrototype>(entityPrototype);
|
var spawns = CalculateSpawns(entityPrototype, amount);
|
||||||
proto.TryGetComponent<StackComponent>(out var stack);
|
|
||||||
var maxCountPerStack = GetMaxCount(stack);
|
|
||||||
var spawnedEnts = new List<EntityUid>();
|
var spawnedEnts = new List<EntityUid>();
|
||||||
|
foreach (var count in spawns)
|
||||||
|
{
|
||||||
|
var entity = SpawnAtPosition(entityPrototype, spawnPosition);
|
||||||
|
spawnedEnts.Add(entity);
|
||||||
|
SetCount(entity, count);
|
||||||
|
}
|
||||||
|
|
||||||
|
return spawnedEnts;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc cref="SpawnMultiple(string,int,EntityCoordinates)"/>
|
||||||
|
public List<EntityUid> SpawnMultiple(string entityPrototype, int amount, EntityUid target)
|
||||||
|
{
|
||||||
|
var spawns = CalculateSpawns(entityPrototype, amount);
|
||||||
|
|
||||||
|
var spawnedEnts = new List<EntityUid>();
|
||||||
|
foreach (var count in spawns)
|
||||||
|
{
|
||||||
|
var entity = SpawnNextToOrDrop(entityPrototype, target);
|
||||||
|
spawnedEnts.Add(entity);
|
||||||
|
SetCount(entity, count);
|
||||||
|
}
|
||||||
|
|
||||||
|
return spawnedEnts;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Calculates how many stacks to spawn that total up to <paramref name="amount"/>.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="entityPrototype">The stack to spawn.</param>
|
||||||
|
/// <param name="amount">The amount of pieces across all stacks.</param>
|
||||||
|
/// <returns>The list of stack counts per entity.</returns>
|
||||||
|
private List<int> CalculateSpawns(string entityPrototype, int amount)
|
||||||
|
{
|
||||||
|
var proto = _prototypeManager.Index<EntityPrototype>(entityPrototype);
|
||||||
|
proto.TryGetComponent<StackComponent>(out var stack, EntityManager.ComponentFactory);
|
||||||
|
var maxCountPerStack = GetMaxCount(stack);
|
||||||
|
var amounts = new List<int>();
|
||||||
while (amount > 0)
|
while (amount > 0)
|
||||||
{
|
{
|
||||||
var entity = Spawn(entityPrototype, spawnPosition);
|
|
||||||
spawnedEnts.Add(entity);
|
|
||||||
var countAmount = Math.Min(maxCountPerStack, amount);
|
var countAmount = Math.Min(maxCountPerStack, amount);
|
||||||
SetCount(entity, countAmount);
|
|
||||||
amount -= countAmount;
|
amount -= countAmount;
|
||||||
|
amounts.Add(countAmount);
|
||||||
}
|
}
|
||||||
return spawnedEnts;
|
|
||||||
|
return amounts;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnStackAlternativeInteract(EntityUid uid, StackComponent stack, GetVerbsEvent<AlternativeVerb> args)
|
private void OnStackAlternativeInteract(EntityUid uid, StackComponent stack, GetVerbsEvent<AlternativeVerb> args)
|
||||||
|
|||||||
Reference in New Issue
Block a user