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:
@@ -467,7 +467,7 @@ public sealed partial class AdminVerbSystem
|
||||
Act = () =>
|
||||
{
|
||||
// Unbounded intentionally.
|
||||
_quickDialog.OpenDialog(player, "Adjust stack", $"Amount (max {stack.MaxCount})", (int newAmount) =>
|
||||
_quickDialog.OpenDialog(player, "Adjust stack", $"Amount (max {_stackSystem.GetMaxCount(stack)})", (int newAmount) =>
|
||||
{
|
||||
_stackSystem.SetCount(args.Target, newAmount, stack);
|
||||
});
|
||||
@@ -485,7 +485,7 @@ public sealed partial class AdminVerbSystem
|
||||
IconTexture = "/Textures/Interface/AdminActions/fill-stack.png",
|
||||
Act = () =>
|
||||
{
|
||||
_stackSystem.SetCount(args.Target, stack.MaxCount, stack);
|
||||
_stackSystem.SetCount(args.Target, _stackSystem.GetMaxCount(stack), stack);
|
||||
},
|
||||
Impact = LogImpact.Medium,
|
||||
Message = Loc.GetString("admin-trick-fill-stack-description"),
|
||||
|
||||
@@ -97,7 +97,7 @@ namespace Content.Server.Cloning.Systems
|
||||
|
||||
private void OnDeconstruct(EntityUid uid, CloningPodComponent component, MachineDeconstructedEvent args)
|
||||
{
|
||||
_serverStackSystem.SpawnMultiple(_material.GetMaterialAmount(uid, "Biomass"), 100, "Biomass", Transform(uid).Coordinates);
|
||||
_serverStackSystem.SpawnMultiple(component.MaterialCloningOutput, _material.GetMaterialAmount(uid, component.RequiredMaterial), Transform(uid).Coordinates);
|
||||
}
|
||||
|
||||
internal void TransferMindToClone(Mind.Mind mind)
|
||||
@@ -149,7 +149,7 @@ namespace Content.Server.Cloning.Systems
|
||||
if (!args.IsInDetailsRange || !_powerReceiverSystem.IsPowered(uid))
|
||||
return;
|
||||
|
||||
args.PushMarkup(Loc.GetString("cloning-pod-biomass", ("number", _material.GetMaterialAmount(uid, "Biomass"))));
|
||||
args.PushMarkup(Loc.GetString("cloning-pod-biomass", ("number", _material.GetMaterialAmount(uid, component.RequiredMaterial))));
|
||||
}
|
||||
|
||||
public bool TryCloning(EntityUid uid, EntityUid bodyToClone, Mind.Mind mind, CloningPodComponent? clonePod)
|
||||
@@ -193,7 +193,7 @@ namespace Content.Server.Cloning.Systems
|
||||
cloningCost = (int) Math.Round(cloningCost * EasyModeCloningCost);
|
||||
|
||||
// biomass checks
|
||||
var biomassAmount = _material.GetMaterialAmount(uid, "Biomass");
|
||||
var biomassAmount = _material.GetMaterialAmount(uid, clonePod.RequiredMaterial);
|
||||
|
||||
if (biomassAmount < cloningCost)
|
||||
{
|
||||
@@ -202,7 +202,7 @@ namespace Content.Server.Cloning.Systems
|
||||
return false;
|
||||
}
|
||||
|
||||
_material.TryChangeMaterialAmount(uid, "Biomass", -cloningCost);
|
||||
_material.TryChangeMaterialAmount(uid, clonePod.RequiredMaterial, -cloningCost);
|
||||
clonePod.UsedBiomass = cloningCost;
|
||||
// end of biomass checks
|
||||
|
||||
@@ -319,7 +319,7 @@ namespace Content.Server.Cloning.Systems
|
||||
}
|
||||
_spillableSystem.SpillAt(uid, bloodSolution, "PuddleBlood");
|
||||
|
||||
var biomassStack = Spawn("MaterialBiomass", transform.Coordinates);
|
||||
var biomassStack = Spawn(clonePod.MaterialCloningOutput, transform.Coordinates);
|
||||
_stackSystem.SetCount(biomassStack, _robustRandom.Next(1, (int) (clonePod.UsedBiomass / 2.5)));
|
||||
|
||||
clonePod.UsedBiomass = 0;
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
using Content.Shared.Cloning;
|
||||
using Content.Shared.Construction.Prototypes;
|
||||
using Content.Shared.Materials;
|
||||
using Robust.Shared.Containers;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
|
||||
|
||||
namespace Content.Server.Cloning.Components
|
||||
@@ -25,6 +27,18 @@ namespace Content.Server.Cloning.Components
|
||||
[ViewVariables]
|
||||
public bool FailedClone = false;
|
||||
|
||||
/// <summary>
|
||||
/// The material that is used to clone entities.
|
||||
/// </summary>
|
||||
[DataField("requiredMaterial", customTypeSerializer: typeof(PrototypeIdSerializer<MaterialPrototype>)), ViewVariables(VVAccess.ReadWrite)]
|
||||
public string RequiredMaterial = "Biomass";
|
||||
|
||||
/// <summary>
|
||||
/// The entity that is spawned on machine deconstruct as well as failed cloning.
|
||||
/// </summary>
|
||||
[DataField("materialCloningOutput", customTypeSerializer: typeof(PrototypeIdSerializer<EntityPrototype>)), ViewVariables(VVAccess.ReadWrite)]
|
||||
public string MaterialCloningOutput = "MaterialBiomass";
|
||||
|
||||
/// <summary>
|
||||
/// The base amount of time it takes to clone a body
|
||||
/// </summary>
|
||||
|
||||
@@ -85,6 +85,8 @@ public sealed class MachineFrameSystem : EntitySystem
|
||||
if (TryComp<StackComponent?>(args.Used, out var stack))
|
||||
{
|
||||
var type = stack.StackTypeId;
|
||||
if (type == null)
|
||||
return;
|
||||
if (!component.MaterialRequirements.ContainsKey(type))
|
||||
return;
|
||||
|
||||
@@ -262,6 +264,8 @@ public sealed class MachineFrameSystem : EntitySystem
|
||||
{
|
||||
var type = stack.StackTypeId;
|
||||
// Check this is part of the requirements...
|
||||
if (type == null)
|
||||
continue;
|
||||
if (!component.MaterialRequirements.ContainsKey(type))
|
||||
continue;
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using Content.Shared.Storage;
|
||||
using System.Threading;
|
||||
using Content.Shared.Construction.Prototypes;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
|
||||
|
||||
namespace Content.Server.Medical.BiomassReclaimer
|
||||
@@ -35,7 +36,7 @@ namespace Content.Server.Medical.BiomassReclaimer
|
||||
/// This is calculated from the YieldPerUnitMass.
|
||||
/// </summary>
|
||||
[ViewVariables]
|
||||
public uint CurrentExpectedYield = default;
|
||||
public int CurrentExpectedYield = default;
|
||||
|
||||
/// <summary>
|
||||
/// The reagent that will be spilled while processing a mob.
|
||||
@@ -54,6 +55,12 @@ namespace Content.Server.Medical.BiomassReclaimer
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public float YieldPerUnitMass = default;
|
||||
|
||||
/// <summary>
|
||||
/// The entity that is output by the reclaimer
|
||||
/// </summary>
|
||||
[DataField("outputEntityId", customTypeSerializer: typeof(PrototypeIdSerializer<EntityPrototype>)), ViewVariables(VVAccess.ReadWrite)]
|
||||
public string OutputEntityId = "MaterialBiomass";
|
||||
|
||||
/// <summary>
|
||||
/// The base yield per mass unit when no components are upgraded.
|
||||
/// </summary>
|
||||
|
||||
@@ -78,7 +78,7 @@ namespace Content.Server.Medical.BiomassReclaimer
|
||||
continue;
|
||||
}
|
||||
|
||||
_stackSystem.SpawnMultiple((int) reclaimer.CurrentExpectedYield, 100, "Biomass", Transform(reclaimer.Owner).Coordinates);
|
||||
_stackSystem.SpawnMultiple(reclaimer.OutputEntityId, reclaimer.CurrentExpectedYield, Transform(reclaimer.Owner).Coordinates);
|
||||
|
||||
reclaimer.BloodReagent = null;
|
||||
reclaimer.SpawnedEntities.Clear();
|
||||
@@ -234,7 +234,7 @@ namespace Content.Server.Medical.BiomassReclaimer
|
||||
component.SpawnedEntities = butcherableComponent.SpawnedEntities;
|
||||
}
|
||||
|
||||
component.CurrentExpectedYield = (uint) Math.Max(0, physics.FixturesMass * component.YieldPerUnitMass);
|
||||
component.CurrentExpectedYield = (int) Math.Max(0, physics.FixturesMass * component.YieldPerUnitMass);
|
||||
component.ProcessingTimer = physics.FixturesMass * component.ProcessingTimePerUnitMass;
|
||||
QueueDel(toProcess);
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -10,9 +10,7 @@ using Content.Shared.Database;
|
||||
using Robust.Server.GameObjects;
|
||||
using System.Linq;
|
||||
using Content.Server.Stack;
|
||||
using Content.Shared.Prototypes;
|
||||
using Robust.Shared.Player;
|
||||
using Robust.Shared.Prototypes;
|
||||
|
||||
namespace Content.Server.Store.Systems;
|
||||
|
||||
@@ -133,7 +131,9 @@ public sealed partial class StoreSystem : EntitySystem
|
||||
}
|
||||
//subtract the cash
|
||||
foreach (var currency in listing.Cost)
|
||||
{
|
||||
component.Balance[currency.Key] -= currency.Value;
|
||||
}
|
||||
|
||||
//spawn entity
|
||||
if (listing.ProductEntity != null)
|
||||
@@ -191,7 +191,7 @@ public sealed partial class StoreSystem : EntitySystem
|
||||
|
||||
if (msg.Session.AttachedEntity is not { Valid: true} buyer)
|
||||
return;
|
||||
|
||||
|
||||
FixedPoint2 amountRemaining = msg.Amount;
|
||||
var coordinates = Transform(buyer).Coordinates;
|
||||
|
||||
@@ -199,35 +199,9 @@ public sealed partial class StoreSystem : EntitySystem
|
||||
foreach (var value in sortedCashValues)
|
||||
{
|
||||
var cashId = proto.Cash[value];
|
||||
|
||||
if (!_proto.TryIndex<EntityPrototype>(cashId, out var cashProto))
|
||||
continue;
|
||||
|
||||
//how many times this subdivision fits in the amount remaining
|
||||
var amountToSpawn = (int) Math.Floor((double) (amountRemaining / value));
|
||||
if (cashProto.HasComponent<StackComponent>())
|
||||
{
|
||||
var amountToRemove = amountToSpawn; //we don't want to modify amountToSpawn, as we use it for calculations
|
||||
while (amountToRemove > 0)
|
||||
{
|
||||
var ent = Spawn(cashId, coordinates);
|
||||
if (!TryComp<StackComponent>(ent, out var stack))
|
||||
return; //you really fucked up if you got here
|
||||
|
||||
var maxAmount = Math.Min(amountToRemove, stack.MaxCount); //limit it based on max stack amount
|
||||
_stack.SetCount(ent, maxAmount, stack);
|
||||
_hands.PickupOrDrop(buyer, ent);
|
||||
amountToRemove -= maxAmount;
|
||||
}
|
||||
}
|
||||
else //please for the love of christ give your currency stack component
|
||||
{
|
||||
for (var i = 0; i < amountToSpawn; i++)
|
||||
{
|
||||
var ent = Spawn(cashId, coordinates);
|
||||
_hands.PickupOrDrop(buyer, ent);
|
||||
}
|
||||
}
|
||||
var amountToSpawn = (int) MathF.Floor((float) (amountRemaining / value));
|
||||
var ents = _stack.SpawnMultiple(cashId, amountToSpawn, coordinates);
|
||||
_hands.PickupOrDrop(buyer, ents.First());
|
||||
amountRemaining -= value * amountToSpawn;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user