MaterialComponent cleanup (#13326)

This commit is contained in:
Leon Friedrich
2023-01-08 11:36:32 +13:00
committed by GitHub
parent 89301629f5
commit 1f5bae751f
12 changed files with 70 additions and 75 deletions

View File

@@ -163,6 +163,16 @@ public sealed class PricingSystem : EntitySystem
return price;
}
public double GetMaterialPrice(MaterialComponent component)
{
double price = 0;
foreach (var (id, quantity) in component.Materials)
{
price += _prototypeManager.Index<MaterialPrototype>(id).Price * quantity;
}
return price;
}
/// <summary>
/// Appraises an entity, returning it's price.
/// </summary>
@@ -181,10 +191,11 @@ public sealed class PricingSystem : EntitySystem
if (TryComp<MaterialComponent>(uid, out var material) && !HasComp<StackPriceComponent>(uid))
{
var matPrice = GetMaterialPrice(material);
if (TryComp<StackComponent>(uid, out var stack))
ev.Price += stack.Count * material.Materials.Sum(x => x.Price * material._materials[x.ID]);
else
ev.Price += material.Materials.Sum(x => x.Price);
matPrice *= stack.Count;
ev.Price += matPrice;
}
if (TryComp<ContainerManagerComponent>(uid, out var containers))

View File

@@ -217,7 +217,7 @@ namespace Content.Server.Lathe
private void OnMaterialEntityInserted(EntityUid uid, LatheComponent component, MaterialEntityInsertedEvent args)
{
var lastMat = args.Materials.Keys.Last();
var lastMat = args.MaterialComp.Materials.Keys.Last();
// We need the prototype to get the color
_proto.TryIndex(lastMat, out MaterialPrototype? matProto);
EnsureComp<LatheInsertingComponent>(uid).TimeRemaining = component.InsertionTime;

View File

@@ -27,6 +27,9 @@ public sealed class MaterialStorageSystem : SharedMaterialStorageSystem
private void OnDeconstructed(EntityUid uid, MaterialStorageComponent component, MachineDeconstructedEvent args)
{
if (!component.DropOnDeconstruct)
return;
foreach (var (material, amount) in component.Storage)
{
_stackSystem.SpawnMultipleFromMaterial(amount, material, Transform(uid).Coordinates);

View File

@@ -110,7 +110,7 @@ namespace Content.Server.Stack
return list;
int maxCountPerStack = _sharedStack.GetMaxCount(stack);
var materialPerStack = material._materials[materialProto.ID];
var materialPerStack = material.Materials[materialProto.ID];
var materialPerMaxCount = maxCountPerStack * materialPerStack;