stack cleanup and mild refactoring (#11717)

* stack cleanup

* fix tests and ulong

* somehow did half a commit

* ulong got usmall. (it's ints now)

* sussy baka cleanup

* mirror's review

* make da tests pass again

* shadowcommander review

* sloth por favor

* Update StoreSystem.Ui.cs
This commit is contained in:
Nemanja
2022-11-08 21:24:23 -05:00
committed by GitHub
parent eebb31493c
commit 9428d4b341
31 changed files with 252 additions and 115 deletions

View File

@@ -28,7 +28,7 @@ namespace Content.Server.Stack
public override void SetCount(EntityUid uid, int amount, SharedStackComponent? component = null)
{
if (!Resolve(uid, ref component))
if (!Resolve(uid, ref component, false))
return;
base.SetCount(uid, amount, component);
@@ -46,6 +46,9 @@ namespace Content.Server.Stack
if (!Resolve(uid, ref stack))
return null;
if (stack.StackTypeId == null)
return null;
// Get a prototype ID to spawn the new entity. Null is also valid, although it should rarely be picked...
var prototype = _prototypeManager.TryIndex<StackPrototype>(stack.StackTypeId, out var stackType)
? stackType.Spawn
@@ -87,38 +90,21 @@ namespace Content.Server.Stack
/// Say you want to spawn 97 stacks of something that has a max stack count of 30.
/// This would spawn 3 stacks of 30 and 1 stack of 7.
/// </summary>
public void SpawnMultiple(int amount, int maxCountPerStack, StackPrototype prototype, EntityCoordinates spawnPosition)
public List<EntityUid> SpawnMultiple(string entityPrototype, int amount, EntityCoordinates spawnPosition)
{
var proto = _prototypeManager.Index<EntityPrototype>(entityPrototype);
proto.TryGetComponent<StackComponent>(out var stack);
var maxCountPerStack = GetMaxCount(stack);
var spawnedEnts = new List<EntityUid>();
while (amount > 0)
{
if (amount > maxCountPerStack)
{
var entity = Spawn("MaterialBiomass", spawnPosition);
var stack = Comp<StackComponent>(entity);
SetCount(entity, maxCountPerStack, stack);
amount -= maxCountPerStack;
}
else
{
var entity = Spawn("MaterialBiomass", spawnPosition);
var stack = Comp<StackComponent>(entity);
SetCount(entity, amount, stack);
amount = 0;
}
var entity = Spawn(entityPrototype, spawnPosition);
spawnedEnts.Add(entity);
var countAmount = Math.Min(maxCountPerStack, amount);
SetCount(entity, countAmount);
amount -= countAmount;
}
}
public void SpawnMultiple(int amount, int maxCountPerStack, string prototype, EntityCoordinates spawnPosition)
{
if (!_prototypeManager.TryIndex<StackPrototype>(prototype, out var stackType))
{
Logger.Error("Failed to index stack prototype " + prototype);
return;
}
SpawnMultiple(amount, maxCountPerStack, stackType, spawnPosition);
return spawnedEnts;
}
private void OnStackAlternativeInteract(EntityUid uid, StackComponent stack, GetVerbsEvent<AlternativeVerb> args)