Fix NoMaterialArbitrage crashing when multiple lathe recipes give the same product (#27842)
This commit is contained in:
@@ -1,22 +1,23 @@
|
|||||||
|
using System.Collections.Generic;
|
||||||
using Content.Server.Cargo.Systems;
|
using Content.Server.Cargo.Systems;
|
||||||
using Content.Server.Construction.Completions;
|
using Content.Server.Construction.Completions;
|
||||||
using Content.Server.Construction.Components;
|
using Content.Server.Construction.Components;
|
||||||
using Content.Server.Destructible;
|
using Content.Server.Destructible;
|
||||||
using Content.Server.Destructible.Thresholds.Behaviors;
|
using Content.Server.Destructible.Thresholds.Behaviors;
|
||||||
using Content.Server.Stack;
|
using Content.Server.Stack;
|
||||||
|
using Content.Shared.Chemistry.Reagent;
|
||||||
|
using Content.Shared.Construction.Components;
|
||||||
using Content.Shared.Construction.Prototypes;
|
using Content.Shared.Construction.Prototypes;
|
||||||
using Content.Shared.Construction.Steps;
|
using Content.Shared.Construction.Steps;
|
||||||
|
using Content.Shared.FixedPoint;
|
||||||
using Content.Shared.Lathe;
|
using Content.Shared.Lathe;
|
||||||
|
using Content.Shared.Materials;
|
||||||
using Content.Shared.Research.Prototypes;
|
using Content.Shared.Research.Prototypes;
|
||||||
using Content.Shared.Stacks;
|
using Content.Shared.Stacks;
|
||||||
using Robust.Shared.GameObjects;
|
using Robust.Shared.GameObjects;
|
||||||
using Robust.Shared.Map;
|
using Robust.Shared.Map;
|
||||||
using Robust.Shared.Prototypes;
|
using Robust.Shared.Prototypes;
|
||||||
using System.Collections.Generic;
|
using Robust.Shared.Utility;
|
||||||
using Content.Shared.Chemistry.Reagent;
|
|
||||||
using Content.Shared.Construction.Components;
|
|
||||||
using Content.Shared.FixedPoint;
|
|
||||||
using Content.Shared.Materials;
|
|
||||||
|
|
||||||
namespace Content.IntegrationTests.Tests;
|
namespace Content.IntegrationTests.Tests;
|
||||||
|
|
||||||
@@ -52,10 +53,10 @@ public sealed class MaterialArbitrageTest
|
|||||||
var destructibleName = compFact.GetComponentName(typeof(DestructibleComponent));
|
var destructibleName = compFact.GetComponentName(typeof(DestructibleComponent));
|
||||||
|
|
||||||
// construct inverted lathe recipe dictionary
|
// construct inverted lathe recipe dictionary
|
||||||
Dictionary<string, LatheRecipePrototype> latheRecipes = new();
|
Dictionary<string, List<LatheRecipePrototype>> latheRecipes = new();
|
||||||
foreach (var proto in protoManager.EnumeratePrototypes<LatheRecipePrototype>())
|
foreach (var proto in protoManager.EnumeratePrototypes<LatheRecipePrototype>())
|
||||||
{
|
{
|
||||||
latheRecipes.Add(proto.Result, proto);
|
latheRecipes.GetOrNew(proto.Result).Add(proto);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Lets assume the possible lathe for resource multipliers:
|
// Lets assume the possible lathe for resource multipliers:
|
||||||
@@ -186,13 +187,16 @@ public sealed class MaterialArbitrageTest
|
|||||||
Assert.That(spawnedPrice, Is.LessThanOrEqualTo(price), $"{id} increases in price after being destroyed\nEntities spawned on destruction: {string.Join(',', spawnedEnts)}");
|
Assert.That(spawnedPrice, Is.LessThanOrEqualTo(price), $"{id} increases in price after being destroyed\nEntities spawned on destruction: {string.Join(',', spawnedEnts)}");
|
||||||
|
|
||||||
// Check lathe production
|
// Check lathe production
|
||||||
if (latheRecipes.TryGetValue(id, out var recipe))
|
if (latheRecipes.TryGetValue(id, out var recipes))
|
||||||
{
|
{
|
||||||
foreach (var (matId, amount) in recipe.RequiredMaterials)
|
foreach (var recipe in recipes)
|
||||||
{
|
{
|
||||||
var actualAmount = SharedLatheSystem.AdjustMaterial(amount, recipe.ApplyMaterialDiscount, multiplier);
|
foreach (var (matId, amount) in recipe.RequiredMaterials)
|
||||||
if (spawnedMats.TryGetValue(matId, out var numSpawned))
|
{
|
||||||
Assert.That(numSpawned, Is.LessThanOrEqualTo(actualAmount), $"destroying a {id} spawns more {matId} than required to produce via an (upgraded) lathe.");
|
var actualAmount = SharedLatheSystem.AdjustMaterial(amount, recipe.ApplyMaterialDiscount, multiplier);
|
||||||
|
if (spawnedMats.TryGetValue(matId, out var numSpawned))
|
||||||
|
Assert.That(numSpawned, Is.LessThanOrEqualTo(actualAmount), $"destroying a {id} spawns more {matId} than required to produce via an (upgraded) lathe.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -263,13 +267,16 @@ public sealed class MaterialArbitrageTest
|
|||||||
Assert.That(deconstructedPrice, Is.LessThanOrEqualTo(price), $"{id} increases in price after being deconstructed");
|
Assert.That(deconstructedPrice, Is.LessThanOrEqualTo(price), $"{id} increases in price after being deconstructed");
|
||||||
|
|
||||||
// Check lathe production
|
// Check lathe production
|
||||||
if (latheRecipes.TryGetValue(id, out var recipe))
|
if (latheRecipes.TryGetValue(id, out var recipes))
|
||||||
{
|
{
|
||||||
foreach (var (matId, amount) in recipe.RequiredMaterials)
|
foreach (var recipe in recipes)
|
||||||
{
|
{
|
||||||
var actualAmount = SharedLatheSystem.AdjustMaterial(amount, recipe.ApplyMaterialDiscount, multiplier);
|
foreach (var (matId, amount) in recipe.RequiredMaterials)
|
||||||
if (deconstructedMats.TryGetValue(matId, out var numSpawned))
|
{
|
||||||
Assert.That(numSpawned, Is.LessThanOrEqualTo(actualAmount), $"deconstructing {id} spawns more {matId} than required to produce via an (upgraded) lathe.");
|
var actualAmount = SharedLatheSystem.AdjustMaterial(amount, recipe.ApplyMaterialDiscount, multiplier);
|
||||||
|
if (deconstructedMats.TryGetValue(matId, out var numSpawned))
|
||||||
|
Assert.That(numSpawned, Is.LessThanOrEqualTo(actualAmount), $"deconstructing {id} spawns more {matId} than required to produce via an (upgraded) lathe.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -315,13 +322,16 @@ public sealed class MaterialArbitrageTest
|
|||||||
Assert.That(sumPrice, Is.LessThanOrEqualTo(price), $"{id} increases in price after decomposed into raw materials");
|
Assert.That(sumPrice, Is.LessThanOrEqualTo(price), $"{id} increases in price after decomposed into raw materials");
|
||||||
|
|
||||||
// Check lathe production
|
// Check lathe production
|
||||||
if (latheRecipes.TryGetValue(id, out var recipe))
|
if (latheRecipes.TryGetValue(id, out var recipes))
|
||||||
{
|
{
|
||||||
foreach (var (matId, amount) in recipe.RequiredMaterials)
|
foreach (var recipe in recipes)
|
||||||
{
|
{
|
||||||
var actualAmount = SharedLatheSystem.AdjustMaterial(amount, recipe.ApplyMaterialDiscount, multiplier);
|
foreach (var (matId, amount) in recipe.RequiredMaterials)
|
||||||
if (compositionComponent.MaterialComposition.TryGetValue(matId, out var numSpawned))
|
{
|
||||||
Assert.That(numSpawned, Is.LessThanOrEqualTo(actualAmount), $"The physical composition of {id} has more {matId} than required to produce via an (upgraded) lathe.");
|
var actualAmount = SharedLatheSystem.AdjustMaterial(amount, recipe.ApplyMaterialDiscount, multiplier);
|
||||||
|
if (compositionComponent.MaterialComposition.TryGetValue(matId, out var numSpawned))
|
||||||
|
Assert.That(numSpawned, Is.LessThanOrEqualTo(actualAmount), $"The physical composition of {id} has more {matId} than required to produce via an (upgraded) lathe.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user