1
0

LoadoutTests.cs 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. using System.Collections.Generic;
  2. using Content.Server.Station.Systems;
  3. using Content.Shared.Inventory;
  4. using Content.Shared.Preferences;
  5. using Content.Shared.Preferences.Loadouts;
  6. using Robust.Shared.GameObjects;
  7. using Robust.Shared.Prototypes;
  8. namespace Content.IntegrationTests.Tests.Preferences;
  9. [TestFixture]
  10. public sealed class LoadoutTests
  11. {
  12. [TestPrototypes]
  13. private const string Prototypes = @"
  14. - type: playTimeTracker
  15. id: PlayTimeLoadoutTester
  16. - type: loadout
  17. id: TestJumpsuit
  18. equipment:
  19. jumpsuit: ClothingUniformJumpsuitColorGrey
  20. - type: loadoutGroup
  21. id: LoadoutTesterJumpsuit
  22. name: generic-unknown
  23. loadouts:
  24. - TestJumpsuit
  25. - type: roleLoadout
  26. id: JobLoadoutTester
  27. groups:
  28. - LoadoutTesterJumpsuit
  29. - type: job
  30. id: LoadoutTester
  31. playTimeTracker: PlayTimeLoadoutTester
  32. ";
  33. private readonly Dictionary<string, EntProtoId> _expectedEquipment = new()
  34. {
  35. ["jumpsuit"] = "ClothingUniformJumpsuitColorGrey"
  36. };
  37. /// <summary>
  38. /// Checks that an empty loadout still spawns with default gear and not naked.
  39. /// </summary>
  40. [Test]
  41. public async Task TestEmptyLoadout()
  42. {
  43. var pair = await PoolManager.GetServerClient(new PoolSettings()
  44. {
  45. Dirty = true,
  46. });
  47. var server = pair.Server;
  48. var entManager = server.ResolveDependency<IEntityManager>();
  49. // Check that an empty role loadout spawns gear
  50. var stationSystem = entManager.System<StationSpawningSystem>();
  51. var inventorySystem = entManager.System<InventorySystem>();
  52. var testMap = await pair.CreateTestMap();
  53. await server.WaitAssertion(() =>
  54. {
  55. var profile = new HumanoidCharacterProfile();
  56. profile.SetLoadout(new RoleLoadout("LoadoutTester"));
  57. var tester = stationSystem.SpawnPlayerMob(testMap.GridCoords, job: "LoadoutTester", profile, station: null);
  58. var slotQuery = inventorySystem.GetSlotEnumerator(tester);
  59. var checkedCount = 0;
  60. while (slotQuery.NextItem(out var item, out var slot))
  61. {
  62. // Make sure the slot is valid
  63. Assert.That(_expectedEquipment.TryGetValue(slot.Name, out var expectedItem), $"Spawned item in unexpected slot: {slot.Name}");
  64. // Make sure that the item is the right one
  65. var meta = entManager.GetComponent<MetaDataComponent>(item);
  66. Assert.That(meta.EntityPrototype.ID, Is.EqualTo(expectedItem.Id), $"Spawned wrong item in slot {slot.Name}!");
  67. checkedCount++;
  68. }
  69. // Make sure the number of items is the same
  70. Assert.That(checkedCount, Is.EqualTo(_expectedEquipment.Count), "Number of items does not match expected!");
  71. entManager.DeleteEntity(tester);
  72. });
  73. await pair.CleanReturnAsync();
  74. }
  75. }