From 0277223a52ab929995f1c1c4cb5e68f726300d55 Mon Sep 17 00:00:00 2001 From: Debug <49997488+DebugOk@users.noreply.github.com> Date: Tue, 9 Jan 2024 04:57:27 +0100 Subject: [PATCH] Create shipyard tests (#485) * Create ShipyardTests.cs * Fix shipyard test failures * Remove map changes * Update rosebudmki.yml --------- Co-authored-by: Dvir --- .../Tests/_NF/ShipyardTests.cs | 100 ++++++++++++++++++ .../Entities/Clothing/Head/misc.yml | 2 +- .../Prototypes/_NF/Shipyard/marauder.yml | 2 +- .../Prototypes/_NF/Shipyard/svnugget.yml | 2 +- Resources/Prototypes/_NF/Shipyard/svtide.yml | 2 +- 5 files changed, 104 insertions(+), 4 deletions(-) create mode 100644 Content.IntegrationTests/Tests/_NF/ShipyardTests.cs diff --git a/Content.IntegrationTests/Tests/_NF/ShipyardTests.cs b/Content.IntegrationTests/Tests/_NF/ShipyardTests.cs new file mode 100644 index 00000000000..9e3cbac5a9d --- /dev/null +++ b/Content.IntegrationTests/Tests/_NF/ShipyardTests.cs @@ -0,0 +1,100 @@ +using System.Linq; +using Content.Server.Cargo.Systems; +using Content.Shared.Shipyard.Prototypes; +using Robust.Server.GameObjects; +using Robust.Shared.GameObjects; +using Robust.Shared.Map; +using Robust.Shared.Map.Components; +using Robust.Shared.Prototypes; + +namespace Content.IntegrationTests.Tests._NF; + +[TestFixture] +public sealed class ShipyardTest +{ + [Test] + public async Task CheckAllShuttleGrids() + { + await using var pair = await PoolManager.GetServerClient(); + var server = pair.Server; + + var entManager = server.ResolveDependency(); + var protoManager = server.ResolveDependency(); + var mapLoader = entManager.System(); + var mapManager = server.ResolveDependency(); + + await server.WaitPost(() => + { + Assert.Multiple(() => + { + foreach (var vessel in protoManager.EnumeratePrototypes()) + { + var mapId = mapManager.CreateMap(); + + try + { + Assert.That(mapLoader.TryLoad(mapId, vessel.ShuttlePath.ToString(), out var roots)); + Assert.That(roots.Where(uid => entManager.HasComponent(uid)), Is.Not.Empty); + } + catch (Exception ex) + { + throw new Exception($"Failed to load shuttle {vessel.ShuttlePath}", ex); + } + + try + { + mapManager.DeleteMap(mapId); + } + catch (Exception ex) + { + throw new Exception($"Failed to delete map {vessel.ShuttlePath}", ex); + } + } + }); + }); + await server.WaitRunTicks(1); + await pair.CleanReturnAsync(); + } + + [Test] + public async Task NoShipyardShipArbitrage() + { + await using var pair = await PoolManager.GetServerClient(); + var server = pair.Server; + + var entManager = server.ResolveDependency(); + var mapLoader = server.ResolveDependency().GetEntitySystem(); + var mapManager = server.ResolveDependency(); + var protoManager = server.ResolveDependency(); + var pricing = server.ResolveDependency().GetEntitySystem(); + + await server.WaitAssertion(() => + { + Assert.Multiple(() => + { + foreach (var vessel in protoManager.EnumeratePrototypes()) + { + var mapId = mapManager.CreateMap(); + double combinedPrice = 0; + + Assert.That(mapLoader.TryLoad(mapId, vessel.ShuttlePath.ToString(), out var roots)); + var shuttle = roots.FirstOrDefault(uid => entManager.HasComponent(uid)); + + pricing.AppraiseGrid(shuttle, null, (uid, price) => + { + combinedPrice += price; + }); + + Assert.That(combinedPrice, Is.AtMost(vessel.Price), + $"Found arbitrage on {vessel.ID} shuttle! Cost is {vessel.Price} but sell is {combinedPrice}!"); + Assert.That(vessel.Price - combinedPrice, Is.GreaterThan(vessel.Price * 0.05), + $"Arbitrage possible on {vessel.ID}. {vessel.Price} - {combinedPrice} = {vessel.Price - combinedPrice} > 5% of the buy price!"); + + mapManager.DeleteMap(mapId); + } + }); + }); + + await pair.CleanReturnAsync(); + } +} diff --git a/Resources/Prototypes/Entities/Clothing/Head/misc.yml b/Resources/Prototypes/Entities/Clothing/Head/misc.yml index f8c633c5d45..4aa4372b628 100644 --- a/Resources/Prototypes/Entities/Clothing/Head/misc.yml +++ b/Resources/Prototypes/Entities/Clothing/Head/misc.yml @@ -150,7 +150,7 @@ sprite: Clothing/Head/Misc/fancycrown.rsi - type: Clothing sprite: Clothing/Head/Misc/fancycrown.rsi - - type: MobPrice + - type: StaticPrice price: 3000 - type: AddAccentClothing accent: MobsterAccent diff --git a/Resources/Prototypes/_NF/Shipyard/marauder.yml b/Resources/Prototypes/_NF/Shipyard/marauder.yml index 165172c731e..c97a5756715 100644 --- a/Resources/Prototypes/_NF/Shipyard/marauder.yml +++ b/Resources/Prototypes/_NF/Shipyard/marauder.yml @@ -2,7 +2,7 @@ id: Marauder name: NSF Marauder description: A heavy corvette, the marauder class is a dedicated deep space patrol vessel outfitted with a reduced radar cross-section and heavily fortified against hostile assault. - price: 100220 + price: 111550 category: Large group: Security shuttlePath: /Maps/Shuttles/marauder.yml diff --git a/Resources/Prototypes/_NF/Shipyard/svnugget.yml b/Resources/Prototypes/_NF/Shipyard/svnugget.yml index 745546f3c31..b8b06329a9e 100644 --- a/Resources/Prototypes/_NF/Shipyard/svnugget.yml +++ b/Resources/Prototypes/_NF/Shipyard/svnugget.yml @@ -2,7 +2,7 @@ id: svnugget name: SV Nugget description: A flying hunk of wood and metal disguised as a kitchen shuttle. Not FDA approved. - price: 12250 + price: 12985 category: Small group: Scrap shuttlePath: /Maps/Shuttles/svnugget.yml diff --git a/Resources/Prototypes/_NF/Shipyard/svtide.yml b/Resources/Prototypes/_NF/Shipyard/svtide.yml index 5795fc84319..b2d4a6390ae 100644 --- a/Resources/Prototypes/_NF/Shipyard/svtide.yml +++ b/Resources/Prototypes/_NF/Shipyard/svtide.yml @@ -2,7 +2,7 @@ id: svtide name: SV Tide description: A cheaply made mass-produced shuttle made from salvaged wrecks. For the seasoned assistant. - price: 9150 + price: 9700 category: Small group: Scrap shuttlePath: /Maps/Shuttles/svtide.yml