Skip to content

Commit

Permalink
Requested changes but need assistance with test fail
Browse files Browse the repository at this point in the history
  • Loading branch information
VMSolidus committed Feb 9, 2024
1 parent 177bd5c commit 0a67fae
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 28 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
using System.Linq;
using Content.Server.Nyanotrasen.Cloning;
using Content.Shared.Random;
using Robust.Shared.GameObjects;
using Robust.Shared.Map;
using Robust.Shared.Prototypes;

namespace Content.IntegrationTests.Tests.DeltaV;

[TestFixture]
[TestOf(typeof(MetempsychoticMachineSystem))]
public sealed class MetempsychosisTest
{
private readonly IPrototypeManager _prototypeManager = default!;

[Test]
public async Task AllHumanoidPoolSpeciesExist()
{
await using var pair = await PoolManager.GetServerClient();
var server = pair.Server;
// Per RobustIntegrationTest.cs, wait until state is settled to access it.
await server.WaitIdleAsync();

var mapManager = server.ResolveDependency<IMapManager>();
var prototypeManager = server.ResolveDependency<IPrototypeManager>();
var entityManager = server.ResolveDependency<IEntityManager>();
var entitySystemManager = server.ResolveDependency<IEntitySystemManager>();

var metemSystem = entitySystemManager.GetEntitySystem<MetempsychoticMachineSystem>();
var metemComponent = new MetempsychoticMachineComponent();

var testMap = await pair.CreateTestMap();

await server.WaitAssertion(() =>
{
_prototypeManager.TryIndex<WeightedRandomPrototype>(metemComponent.MetempsychoticHumanoidPool, out var humanoidPool);
_prototypeManager.TryIndex<WeightedRandomPrototype>(metemComponent.MetempsychoticNonHumanoidPool, out var nonHumanoidPool);

var coordinates = testMap.GridCoords;

Assert.That(humanoidPool.Weights.Any(), "MetempsychoticHumanoidPool has no valid prototypes!");
Assert.That(nonHumanoidPool.Weights.Any(), "MetempsychoticNonHumanoidPool has no valid prototypes!");

foreach (var (key, weight) in humanoidPool.Weights)
{
Assert.That(prototypeManager.TryIndex(key, out var _),
$"MetempsychoticHumanoidPool has invalid prototype {key}!");

var spawned = entityManager.SpawnEntity(key, coordinates);
}

foreach (var (key, weight) in nonHumanoidPool.Weights)
{
Assert.That(prototypeManager.TryIndex(key, out var _),
$"MetempsychoticNonHumanoidPool has invalid prototype {key}!");

var spawned = entityManager.SpawnEntity(key, coordinates);
}

// Because Server/Client pairs can be re-used between Tests, we
// need to clean up anything that might affect other tests,
// otherwise this pair cannot be considered clean, and the
// CleanReturnAsync call would need to be removed.
mapManager.DeleteMap(testMap.MapId);
});
await pair.CleanReturnAsync();
}
}
5 changes: 3 additions & 2 deletions Content.Server/Cloning/CloningSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
using Content.Server.Nyanotrasen.Cloning;
using Content.Shared.Humanoid.Prototypes;
using Robust.Shared.GameObjects.Components.Localization; //DeltaV End Metem Usings
using Content.Server.EntityList;

namespace Content.Server.Cloning
{
Expand Down Expand Up @@ -265,7 +266,7 @@ public bool TryCloning(EntityUid uid, EntityUid bodyToClone, Entity<MindComponen

AddComp<ActiveCloningPodComponent>(uid);

// TODO: Ideally, components like this should be on a mind entity so this isn't neccesary.
// TODO: Ideally, components like this should be components on the mind entity so this isn't necessary.
// Add on special job components to the mob.
if (_jobs.MindTryGetJob(mindEnt, out _, out var prototype))
{
Expand Down Expand Up @@ -384,7 +385,7 @@ private EntityUid FetchAndSpawnMob(CloningPodComponent clonePod, HumanoidCharact

if (TryComp<MetempsychoticMachineComponent>(clonePod.Owner, out var metem))
{
toSpawn = _metem.GetSpawnEntity(clonePod.Owner, karmaBonus, speciesPrototype, out var newSpecies, oldKarma?.Score, metem);
toSpawn = _metem.GetSpawnEntity(clonePod.Owner, karmaBonus, metem, speciesPrototype, out var newSpecies, oldKarma?.Score);
applyKarma = true;

if (newSpecies != null)
Expand Down
8 changes: 1 addition & 7 deletions Content.Server/Medical/Components/MedicalScannerComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,6 @@ public sealed partial class MedicalScannerComponent : SharedMedicalScannerCompon
public float CloningFailChanceMultiplier = 1f;

// Nyano, needed for Metem Machine.
public float MetemKarmaBonus = 0.25f;

[DataField("machinePartCloningFailChance", customTypeSerializer: typeof(PrototypeIdSerializer<MachinePartPrototype>))]
public string MachinePartCloningFailChance = "Capacitor";

[DataField("partRatingCloningFailChanceMultiplier")]
public float PartRatingFailMultiplier = 0.75f;
public float MetemKarmaBonus = 0.25f;
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using Content.Shared.Random;

namespace Content.Server.Nyanotrasen.Cloning
{
[RegisterComponent]
Expand All @@ -8,5 +10,13 @@ public sealed partial class MetempsychoticMachineComponent : Component
/// </summary>
[DataField("humanoidBaseChance")]
public float HumanoidBaseChance = 0.75f;

[ValidatePrototypeId<WeightedRandomPrototype>]
[DataField("metempsychoticHumanoidPool")]
public string MetempsychoticHumanoidPool = "MetempsychoticHumanoidPool";

[ValidatePrototypeId<WeightedRandomPrototype>]
[DataField("metempsychoticNonHumanoidPool")]
public string MetempsychoticNonHumanoidPool = "MetempsychoticNonhumanoidPool";
}
}
18 changes: 2 additions & 16 deletions Content.Server/Nyanotrasen/Cloning/MetempsychoticMachineSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,13 @@ namespace Content.Server.Nyanotrasen.Cloning
{
public sealed class MetempsychoticMachineSystem : EntitySystem
{
[ValidatePrototypeId<WeightedRandomPrototype>]
public const string MetempsychoticHumanoidPool = "MetempsychoticHumanoidPool";

[ValidatePrototypeId<WeightedRandomPrototype>]
public const string MetempsychoticNonHumanoidPool = "MetempsychoticNonhumanoidPool";

[Dependency] private readonly IRobustRandom _random = default!;
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;

private ISawmill _sawmill = default!;

public string GetSpawnEntity(EntityUid uid, float karmaBonus, SpeciesPrototype oldSpecies, out SpeciesPrototype? species, int? karma = null, MetempsychoticMachineComponent? component = null)
public string GetSpawnEntity(EntityUid uid, float karmaBonus, MetempsychoticMachineComponent component, SpeciesPrototype oldSpecies, out SpeciesPrototype? species, int? karma = null)
{
if (!Resolve(uid, ref component))
{
Logger.Error("Tried to get a spawn target from someone that was not a metempsychotic machine...");
species = null;
return "MobHuman";
}

var chance = component.HumanoidBaseChance + karmaBonus;

if (karma != null)
Expand All @@ -42,9 +29,8 @@ public string GetSpawnEntity(EntityUid uid, float karmaBonus, SpeciesPrototype o
chance = 1;

chance = Math.Clamp(chance, 0, 1);

if (_random.Prob(chance) &&
_prototypeManager.TryIndex<WeightedRandomPrototype>(MetempsychoticHumanoidPool, out var humanoidPool) &&
_prototypeManager.TryIndex<WeightedRandomPrototype>(component.MetempsychoticHumanoidPool, out var humanoidPool) &&
_prototypeManager.TryIndex<SpeciesPrototype>(humanoidPool.Pick(), out var speciesPrototype))
{
species = speciesPrototype;
Expand Down
4 changes: 1 addition & 3 deletions Resources/Prototypes/Nyanotrasen/metempsychoticHumanoids.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@
Arachnid: 1
Harpy: 1
Moth: 1
Diona: 0.5
Reptilian: 0.5
Dwarf: 0.5
SlimePerson: 0.5
Vulpkanin: 0.5
Vox: 0.1
Skeleton: 0.05

0 comments on commit 0a67fae

Please sign in to comment.