Skip to content

Commit

Permalink
Create shipyard tests (#485)
Browse files Browse the repository at this point in the history
* Create ShipyardTests.cs

* Fix shipyard test failures

* Remove map changes

* Update rosebudmki.yml

---------

Co-authored-by: Dvir <[email protected]>
  • Loading branch information
DebugOk and dvir001 committed Jan 9, 2024
1 parent 3f1465e commit 0277223
Show file tree
Hide file tree
Showing 5 changed files with 104 additions and 4 deletions.
100 changes: 100 additions & 0 deletions Content.IntegrationTests/Tests/_NF/ShipyardTests.cs
Original file line number Diff line number Diff line change
@@ -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<IEntityManager>();
var protoManager = server.ResolveDependency<IPrototypeManager>();
var mapLoader = entManager.System<MapLoaderSystem>();
var mapManager = server.ResolveDependency<IMapManager>();

await server.WaitPost(() =>
{
Assert.Multiple(() =>
{
foreach (var vessel in protoManager.EnumeratePrototypes<VesselPrototype>())
{
var mapId = mapManager.CreateMap();
try
{
Assert.That(mapLoader.TryLoad(mapId, vessel.ShuttlePath.ToString(), out var roots));
Assert.That(roots.Where(uid => entManager.HasComponent<MapGridComponent>(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<IEntityManager>();
var mapLoader = server.ResolveDependency<IEntitySystemManager>().GetEntitySystem<MapLoaderSystem>();
var mapManager = server.ResolveDependency<IMapManager>();
var protoManager = server.ResolveDependency<IPrototypeManager>();
var pricing = server.ResolveDependency<IEntitySystemManager>().GetEntitySystem<PricingSystem>();

await server.WaitAssertion(() =>
{
Assert.Multiple(() =>
{
foreach (var vessel in protoManager.EnumeratePrototypes<VesselPrototype>())
{
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<MapGridComponent>(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();
}
}
2 changes: 1 addition & 1 deletion Resources/Prototypes/Entities/Clothing/Head/misc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Resources/Prototypes/_NF/Shipyard/marauder.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Resources/Prototypes/_NF/Shipyard/svnugget.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Resources/Prototypes/_NF/Shipyard/svtide.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 0277223

Please sign in to comment.