Files
crystall-punk-14/Content.IntegrationTests/Tests/_CP14/CP14Workbench.cs
Red b51e80c335 economy testing (#1507)
* pricing check 1

* Update CP14Economy.cs

* seed and dye

* mini tweak

* seed and test mithril

* hammer and pickaxe

* blade

* expensive check

* fix test

* Update CP14Workbench.cs

* misc

* misc 2

* Update CP14Workbench.cs

* Update CP14Workbench.cs

* misc 3

* misc 4

* misc 5

* meat

* food

* dough

* Clothing

* misc

* food 2

* food 3

* Wallpaper

* Wallpape 2

* Floor

* Floor 2

* carpet

* plushie

* Plushie 2

* meat 66

* food 4

* misc 9

* misc 10

* Bucket

* meat 8

* meat 10

* rope

* TagResource deleted

* meat 11

* meat 12

* meat 13

* meat 14

* meat 15

* fix

* meat 16

---------

Co-authored-by: Nimfar11 <nimfiar@gmail.com>
Co-authored-by: Nim <128169402+Nimfar11@users.noreply.github.com>
2025-07-11 18:54:36 +03:00

67 lines
2.6 KiB
C#

using Content.Server.Cargo.Systems;
using Content.Shared._CP14.Workbench.Prototypes;
using Robust.Shared.GameObjects;
using Robust.Shared.Prototypes;
namespace Content.IntegrationTests.Tests._CP14;
#nullable enable
[TestFixture]
public sealed class CP14Workbench
{
/// <summary>
/// Check that the price of all resources to craft the item on the workbench is lower than the price of the result.
/// </summary>
[Test]
public async Task CheckRecipePricingReduction()
{
await using var pair = await PoolManager.GetServerClient();
var server = pair.Server;
var entManager = server.ResolveDependency<IEntityManager>();
var protoMan = server.ResolveDependency<IPrototypeManager>();
var pricingSystem = entManager.System<PricingSystem>();
await server.WaitAssertion(() =>
{
Assert.Multiple(() =>
{
foreach (var recipe in protoMan.EnumeratePrototypes<CP14WorkbenchRecipePrototype>())
{
double resourcePrice = 0;
foreach (var req in recipe.Requirements)
{
resourcePrice += req.GetPrice(entManager, protoMan);
}
var result = entManager.Spawn(recipe.Result);
var resultPrice = pricingSystem.GetPrice(result) * recipe.ResultCount;
resourcePrice = Math.Round(resourcePrice, 3);
resultPrice = Math.Round(resultPrice, 3);
if (resourcePrice == 0 && resultPrice == 0)
continue;
var minLimit = resourcePrice;
var maxLimit = resourcePrice * 2;
if (resultPrice < minLimit)
{
Assert.Fail($"The ingredients to craft the [{recipe.ID}] cost more than the result of the crafting. \nCrafting: [{recipe.Result.Id} x{recipe.ResultCount}]. \nExpected price range: from {minLimit} to {maxLimit}. \nCurrent price: {resultPrice}");
}
if (resultPrice > maxLimit)
{
Assert.Fail($"The result of crafting [{recipe.ID}] is too expensive! After crafting, the final cost exceeds the cost of all resources more than 2 times! \nCrafting: [{recipe.Result.Id} x{recipe.ResultCount}]. \nExpected price range: from {minLimit} to {maxLimit}. \nCurrent price: {resultPrice}");
}
entManager.DeleteEntity(result);
}
});
});
await pair.CleanReturnAsync();
}
}