Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create shipyard tests #485

Merged
merged 4 commits into from
Jan 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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: NT 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
4 changes: 2 additions & 2 deletions 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: Civilian
shuttlePath: /Maps/Shuttles/svnugget.yml
Expand All @@ -24,4 +24,4 @@
- type: StationJobs
overflowJobs: []
availableJobs:
Passenger: [ 0, 0 ]
Passenger: [ 0, 0 ]
4 changes: 2 additions & 2 deletions 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: Civilian
shuttlePath: /Maps/Shuttles/svtide.yml
Expand All @@ -24,4 +24,4 @@
- type: StationJobs
overflowJobs: []
availableJobs:
Passenger: [ 0, 0 ]
Passenger: [ 0, 0 ]
Loading