]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Fix NoMaterialArbitrage crashing when multiple lathe recipes give the same product...
authorDrSmugleaf <10968691+DrSmugleaf@users.noreply.github.com>
Thu, 9 May 2024 21:53:05 +0000 (14:53 -0700)
committerGitHub <noreply@github.com>
Thu, 9 May 2024 21:53:05 +0000 (17:53 -0400)
Content.IntegrationTests/Tests/MaterialArbitrageTest.cs

index 51be2fb4311e725c7468449c8d2dbb462b492d69..7f9c02fc13bcdc4875b256526970c9ebad2b3ef7 100644 (file)
@@ -1,22 +1,23 @@
+using System.Collections.Generic;
 using Content.Server.Cargo.Systems;
 using Content.Server.Construction.Completions;
 using Content.Server.Construction.Components;
 using Content.Server.Destructible;
 using Content.Server.Destructible.Thresholds.Behaviors;
 using Content.Server.Stack;
+using Content.Shared.Chemistry.Reagent;
+using Content.Shared.Construction.Components;
 using Content.Shared.Construction.Prototypes;
 using Content.Shared.Construction.Steps;
+using Content.Shared.FixedPoint;
 using Content.Shared.Lathe;
+using Content.Shared.Materials;
 using Content.Shared.Research.Prototypes;
 using Content.Shared.Stacks;
 using Robust.Shared.GameObjects;
 using Robust.Shared.Map;
 using Robust.Shared.Prototypes;
-using System.Collections.Generic;
-using Content.Shared.Chemistry.Reagent;
-using Content.Shared.Construction.Components;
-using Content.Shared.FixedPoint;
-using Content.Shared.Materials;
+using Robust.Shared.Utility;
 
 namespace Content.IntegrationTests.Tests;
 
@@ -52,10 +53,10 @@ public sealed class MaterialArbitrageTest
         var destructibleName = compFact.GetComponentName(typeof(DestructibleComponent));
 
         // construct inverted lathe recipe dictionary
-        Dictionary<string, LatheRecipePrototype> latheRecipes = new();
+        Dictionary<string, List<LatheRecipePrototype>> latheRecipes = new();
         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:
@@ -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)}");
 
                 // 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);
-                        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.");
+                        foreach (var (matId, amount) in recipe.RequiredMaterials)
+                        {
+                            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");
 
                 // 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);
-                        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.");
+                        foreach (var (matId, amount) in recipe.RequiredMaterials)
+                        {
+                            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");
 
                 // 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);
-                        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.");
+                        foreach (var (matId, amount) in recipe.RequiredMaterials)
+                        {
+                            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.");
+                        }
                     }
                 }