Convert materials to use PhysicalComposition (#15414)
This commit is contained in:
@@ -121,10 +121,10 @@ public sealed class PricingSystem : EntitySystem
|
||||
return price;
|
||||
}
|
||||
|
||||
private double GetMaterialPrice(MaterialComponent component)
|
||||
private double GetMaterialPrice(PhysicalCompositionComponent component)
|
||||
{
|
||||
double price = 0;
|
||||
foreach (var (id, quantity) in component.Materials)
|
||||
foreach (var (id, quantity) in component.MaterialComposition)
|
||||
{
|
||||
price += _prototypeManager.Index<MaterialPrototype>(id).Price * quantity;
|
||||
}
|
||||
@@ -213,9 +213,10 @@ public sealed class PricingSystem : EntitySystem
|
||||
{
|
||||
double price = 0;
|
||||
|
||||
if (TryComp<MaterialComponent>(uid, out var material))
|
||||
if (HasComp<MaterialComponent>(uid) &&
|
||||
TryComp<PhysicalCompositionComponent>(uid, out var composition))
|
||||
{
|
||||
var matPrice = GetMaterialPrice(material);
|
||||
var matPrice = GetMaterialPrice(composition);
|
||||
if (TryComp<StackComponent>(uid, out var stack))
|
||||
matPrice *= stack.Count;
|
||||
|
||||
@@ -229,10 +230,11 @@ public sealed class PricingSystem : EntitySystem
|
||||
{
|
||||
double price = 0;
|
||||
|
||||
if (prototype.Components.TryGetValue(_factory.GetComponentName(typeof(MaterialComponent)), out var materials))
|
||||
if (prototype.Components.ContainsKey(_factory.GetComponentName(typeof(MaterialComponent))) &&
|
||||
prototype.Components.TryGetValue(_factory.GetComponentName(typeof(PhysicalCompositionComponent)), out var composition))
|
||||
{
|
||||
var materialsComp = (MaterialComponent) materials.Component;
|
||||
var matPrice = GetMaterialPrice(materialsComp);
|
||||
var compositionComp = (PhysicalCompositionComponent) composition.Component;
|
||||
var matPrice = GetMaterialPrice(compositionComp);
|
||||
|
||||
if (prototype.Components.TryGetValue(_factory.GetComponentName(typeof(StackComponent)), out var stackProto))
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user