Skip to content

Commit

Permalink
[Feature] Lathe Arbitrage Integration Test (#997)
Browse files Browse the repository at this point in the history
* Lathe Arbitrage Integration Test

* Fix All argitrage recipes

* Fix pricing?

* Update electronics.yml
  • Loading branch information
Roudenn authored Jan 9, 2025
1 parent f79e04e commit e2be4ed
Show file tree
Hide file tree
Showing 21 changed files with 102 additions and 26 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
using System.Collections.Generic;
using Content.Server.Cargo.Systems;
using Content.Shared.Research.Prototypes;

namespace Content.IntegrationTests.Tests.Backmen.Lathe;

[TestFixture]
public sealed class LatheRecipyCostTest
{
private const double Tolerance = 10;

[Test]
public async Task LatheRecipesNoArbitrageTest()
{
await using var pair = await PoolManager.GetServerClient();

var server = pair.Server;
var proto = server.ProtoMan;
var entMan = server.EntMan;
var priceSystem = entMan.System<PricingSystem>();

var fails = new List<string>();

await server.WaitAssertion(() =>
{
var recipes = proto.EnumeratePrototypes<LatheRecipePrototype>();
foreach (var recipe in recipes)
{
var resultPrice = Math.Round(priceSystem.GetLatheRecipePrice(recipe));
var matPrice = 0.0;
bool ignoreRecipe = false;
foreach (var (materialId, count) in recipe.Materials)
{
var material = proto.Index(materialId);

if (material.IgnoreArbitrage)
ignoreRecipe = true;

matPrice += material.Price * count;
}

if (ignoreRecipe)
continue;

matPrice = Math.Round(matPrice);

if (resultPrice > matPrice + Tolerance)
{
fails.Add($"ID: {recipe.ID} Materials: {matPrice} Result: {resultPrice} Dif: {resultPrice - matPrice}");
}
}
});

if (fails.Count > 0)
{
var msg = string.Join("\n", fails) + "\n" + "Following RecipePrototypes are giving Arbitrage when printed!";
Assert.Fail(msg);
}

await pair.CleanReturnAsync();
}
}
7 changes: 7 additions & 0 deletions Content.Shared/Materials/MaterialPrototype.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,12 @@ public sealed partial class MaterialPrototype : IPrototype, IInheritingPrototype
/// </summary>
[DataField(required: true)]
public double Price = 0;

/// <summary>
/// Backmen Change: Setting this to true will make
/// this material be ignored in Price Tests.
/// </summary>
[DataField]
public bool IgnoreArbitrage;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@
- type: Sprite
state: cpu_service
- type: StaticPrice
price: 150
price: 100
- type: ComputerBoard
prototype: ComputerMassMedia

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,3 @@
- type: Tag
tags:
- StationMapElectronics
- type: StaticPrice
price: 30
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
sprite: Objects/Misc/module.rsi
state: generic
- type: StaticPrice
price: 100
price: 45
- type: PhysicalComposition
materialComposition:
Glass: 200
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
tags:
- DoorElectronics
- type: DoorElectronics
- type: StaticPrice
price: 55
- type: AccessReader
- type: ActivatableUI
key: enum.DoorElectronicsConfigurationUiKey.Key
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,3 @@
- type: Tag
tags:
- FirelockElectronics
- type: StaticPrice
price: 61
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,3 @@
tags:
- FreezerElectronics
- type: DoorElectronics
- type: StaticPrice
price: 55
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
- type: Tag
tags:
- TimerSignalElectronics
- type: StaticPrice
price: 30

- type: entity
id: ScreenTimerElectronics
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
tags:
- HolofanProjector
- type: StaticPrice
price: 80
price: 60

- type: entity
parent: HolofanProjector
Expand Down
1 change: 1 addition & 0 deletions Resources/Prototypes/Entities/Objects/Misc/space_cash.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
stackEntity: SpaceCash
icon: { sprite: /Textures/Objects/Economy/cash.rsi, state: cash }
price: 1
ignoreArbitrage: true # lathe-test change # uhhhh no

- type: stack
id: Credit
Expand Down
4 changes: 1 addition & 3 deletions Resources/Prototypes/Entities/Objects/Shields/shields.yml
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,4 @@
min: 2
max: 2
- type: StaticPrice
price: 250


price: 170
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,8 @@
- type: Battery
maxCharge: 10000
startingCharge: 10000
- type: StaticPrice
price: 300

- type: entity
name: x-ray cannon
Expand Down
4 changes: 4 additions & 0 deletions Resources/Prototypes/Reagents/Materials/materials.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
icon: { sprite: /Textures/Objects/Misc/monkeycube.rsi, state: cube }
color: "#8A9A5B"
price: 0.1
ignoreArbitrage: true # lathe-test change # We don't care about biomass too much...

- type: material
id: Cardboard
Expand All @@ -14,6 +15,7 @@
icon: { sprite: /Textures/Objects/Materials/materials.rsi, state: cardboard }
color: "#70736c"
price: 0.025
ignoreArbitrage: true # lathe-test change

- type: material
id: Cloth
Expand Down Expand Up @@ -41,6 +43,7 @@
icon: { sprite: Objects/Materials/Sheets/other.rsi, state: paper }
color: "#d9d9d9"
price: 0.01 # it's paper bro what do you expect?
ignoreArbitrage: true # lathe-test change

- type: material
id: Plasma
Expand Down Expand Up @@ -91,6 +94,7 @@
icon: { sprite: Objects/Materials/Sheets/meaterial.rsi, state: meat }
color: "#c53648"
price: 0.05
ignoreArbitrage: true # lathe-test change

- type: material
id: WebSilk
Expand Down
11 changes: 10 additions & 1 deletion Resources/Prototypes/Reagents/Materials/ores.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
unit: materials-unit-chunk
icon: { sprite: Objects/Materials/ore.rsi, state: iron }
price: 0.05
ignoreArbitrage: true # lathe-test change

- type: material
id: RawQuartz
Expand All @@ -14,6 +15,7 @@
icon: { sprite: Objects/Materials/ore.rsi, state: spacequartz }
color: "#a8ccd7"
price: 0.075
ignoreArbitrage: true # lathe-test change

- type: material
id: RawGold
Expand All @@ -23,6 +25,7 @@
icon: { sprite: Objects/Materials/ore.rsi, state: gold }
color: "#FFD700"
price: 0.2
ignoreArbitrage: true # lathe-test change

- type: material
id: RawDiamond
Expand All @@ -32,6 +35,7 @@
icon: { sprite: Objects/Materials/ore.rsi, state: diamond }
color: "#C9D8F2"
price: 0.5
ignoreArbitrage: true # lathe-test change

- type: material
id: RawSilver
Expand All @@ -41,6 +45,7 @@
icon: { sprite: Objects/Materials/ore.rsi, state: silver }
color: "#C0C0C0"
price: 0.15
ignoreArbitrage: true # lathe-test change

- type: material
id: RawPlasma
Expand All @@ -50,6 +55,7 @@
icon: { sprite: Objects/Materials/ore.rsi, state: plasma }
color: "#7e009e"
price: 0.2
ignoreArbitrage: true # lathe-test change

- type: material
id: RawUranium
Expand All @@ -59,6 +65,7 @@
icon: { sprite: Objects/Materials/ore.rsi, state: uranium }
color: "#32a852"
price: 0.2
ignoreArbitrage: true # lathe-test change

- type: material
id: RawBananium
Expand All @@ -68,6 +75,7 @@
icon: { sprite: Objects/Materials/ore.rsi, state: bananium }
color: "#32a852"
price: 0.2
ignoreArbitrage: true # lathe-test change

- type: material
id: RawSalt
Expand All @@ -76,4 +84,5 @@
unit: materials-unit-chunk
icon: { sprite: Objects/Materials/ore.rsi, state: salt }
color: "#f5e7d7"
price: 0.075
price: 0.075
ignoreArbitrage: true # lathe-test change
4 changes: 2 additions & 2 deletions Resources/Prototypes/Recipes/Lathes/electronics.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
parent: BaseElectronicsRecipe
id: BaseCheapElectronicsRecipe
materials:
Steel: 50
Plastic: 50
Steel: 100
Plastic: 150

- type: latheRecipe
abstract: true
Expand Down
2 changes: 1 addition & 1 deletion Resources/Prototypes/Recipes/Lathes/medical.yml
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@
result: ClothingMaskSterile
completetime: 2
materials:
Plastic: 50
Plastic: 100

- type: latheRecipe
id: DiseaseSwab
Expand Down
10 changes: 5 additions & 5 deletions Resources/Prototypes/Recipes/Lathes/security.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@
id: WeaponLaserPistol
result: WeaponEarthGovLaserPistol
materials:
Steel: 500
Glass: 100
Plastic: 200
Steel: 800
Glass: 400
Plastic: 400

- type: latheRecipe
parent: BaseWeaponRecipeLong
Expand Down Expand Up @@ -116,8 +116,8 @@
materials:
Steel: 1500
Glass: 500
Plastic: 250
Gold: 100
Plastic: 400
Gold: 200

- type: latheRecipe
id: ClothingBackpackElectropack
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
- type: ComputerBoard
prototype: ComputerShipyard
- type: StaticPrice
price: 750
price: 150

- type: entity
parent: BaseComputerCircuitboard
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,8 @@
steps: 3
zeroVisible: true
- type: Appearance
- type: StaticPrice
price: 250

- type: entity
name: EarthGov heavy laser rifle
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
name: prize ticket
icon: { sprite: Backmen/Objects/Fun/prizeticket.rsi, state: ticket }
price: 0
ignoreArbitrage: true # lathe-test change

0 comments on commit e2be4ed

Please sign in to comment.