2021-12-30 22:56:10 +01:00
|
|
|
using Content.Shared.Inventory;
|
2021-02-11 01:13:03 -08:00
|
|
|
using Robust.Shared.GameObjects;
|
2023-08-13 09:22:57 +12:00
|
|
|
using Robust.Shared.Map;
|
2020-01-20 22:16:34 +01:00
|
|
|
|
|
|
|
|
namespace Content.IntegrationTests.Tests
|
|
|
|
|
{
|
2021-12-30 22:56:10 +01:00
|
|
|
// Tests the behavior of InventoryComponent.
|
2020-01-20 22:16:34 +01:00
|
|
|
// i.e. the interaction between uniforms and the pocket/ID slots.
|
|
|
|
|
// and also how big items don't fit in pockets.
|
|
|
|
|
[TestFixture]
|
2022-06-19 20:22:28 -07:00
|
|
|
public sealed class HumanInventoryUniformSlotsTest
|
2020-01-20 22:16:34 +01:00
|
|
|
{
|
2023-08-05 16:16:48 +12:00
|
|
|
[TestPrototypes]
|
2021-02-09 22:04:47 +01:00
|
|
|
private const string Prototypes = @"
|
2020-11-18 15:30:36 +01:00
|
|
|
- type: entity
|
2023-08-05 16:16:48 +12:00
|
|
|
name: HumanUniformDummy
|
|
|
|
|
id: HumanUniformDummy
|
2020-11-18 15:30:36 +01:00
|
|
|
components:
|
|
|
|
|
- type: Inventory
|
2021-12-30 22:56:10 +01:00
|
|
|
- type: ContainerContainer
|
2020-11-18 15:30:36 +01:00
|
|
|
|
|
|
|
|
- type: entity
|
|
|
|
|
name: UniformDummy
|
|
|
|
|
id: UniformDummy
|
|
|
|
|
components:
|
|
|
|
|
- type: Clothing
|
2022-07-27 03:53:47 -07:00
|
|
|
slots: [innerclothing]
|
|
|
|
|
- type: Item
|
2023-10-30 23:55:55 -04:00
|
|
|
size: Tiny
|
2020-11-18 15:30:36 +01:00
|
|
|
|
|
|
|
|
- type: entity
|
|
|
|
|
name: IDCardDummy
|
|
|
|
|
id: IDCardDummy
|
|
|
|
|
components:
|
|
|
|
|
- type: Clothing
|
2022-07-27 03:53:47 -07:00
|
|
|
slots:
|
2020-11-18 15:30:36 +01:00
|
|
|
- idcard
|
2022-07-27 03:53:47 -07:00
|
|
|
- type: Item
|
2023-10-30 23:55:55 -04:00
|
|
|
size: Tiny
|
2020-11-18 15:30:36 +01:00
|
|
|
- type: IdCard
|
|
|
|
|
|
|
|
|
|
- type: entity
|
|
|
|
|
name: FlashlightDummy
|
|
|
|
|
id: FlashlightDummy
|
|
|
|
|
components:
|
|
|
|
|
- type: Item
|
2023-10-30 23:55:55 -04:00
|
|
|
size: Tiny
|
2020-11-18 15:30:36 +01:00
|
|
|
|
|
|
|
|
- type: entity
|
|
|
|
|
name: ToolboxDummy
|
|
|
|
|
id: ToolboxDummy
|
|
|
|
|
components:
|
|
|
|
|
- type: Item
|
2023-10-30 23:55:55 -04:00
|
|
|
size: Huge
|
2020-11-18 15:30:36 +01:00
|
|
|
";
|
2020-01-20 22:16:34 +01:00
|
|
|
[Test]
|
|
|
|
|
public async Task Test()
|
|
|
|
|
{
|
2023-08-25 02:56:51 +02:00
|
|
|
await using var pair = await PoolManager.GetServerClient();
|
|
|
|
|
var server = pair.Server;
|
2023-08-25 04:13:11 +02:00
|
|
|
var testMap = await pair.CreateTestMap();
|
2022-10-31 12:05:34 +13:00
|
|
|
var coordinates = testMap.GridCoords;
|
2020-01-20 22:16:34 +01:00
|
|
|
|
2021-12-05 18:09:01 +01:00
|
|
|
EntityUid human = default;
|
|
|
|
|
EntityUid uniform = default;
|
|
|
|
|
EntityUid idCard = default;
|
|
|
|
|
EntityUid pocketItem = default;
|
2020-01-20 22:16:34 +01:00
|
|
|
|
2021-12-30 22:56:10 +01:00
|
|
|
InventorySystem invSystem = default!;
|
2023-08-13 09:22:57 +12:00
|
|
|
var mapMan = server.ResolveDependency<IMapManager>();
|
2023-06-07 21:08:52 +10:00
|
|
|
var entityMan = server.ResolveDependency<IEntityManager>();
|
2021-12-30 22:56:10 +01:00
|
|
|
|
2022-06-19 20:22:28 -07:00
|
|
|
await server.WaitAssertion(() =>
|
2020-01-20 22:16:34 +01:00
|
|
|
{
|
2023-06-07 21:08:52 +10:00
|
|
|
invSystem = entityMan.System<InventorySystem>();
|
2020-01-20 22:16:34 +01:00
|
|
|
|
2023-08-05 16:16:48 +12:00
|
|
|
human = entityMan.SpawnEntity("HumanUniformDummy", coordinates);
|
2022-10-31 12:05:34 +13:00
|
|
|
uniform = entityMan.SpawnEntity("UniformDummy", coordinates);
|
|
|
|
|
idCard = entityMan.SpawnEntity("IDCardDummy", coordinates);
|
|
|
|
|
pocketItem = entityMan.SpawnEntity("FlashlightDummy", coordinates);
|
|
|
|
|
var tooBigItem = entityMan.SpawnEntity("ToolboxDummy", coordinates);
|
2020-01-20 22:16:34 +01:00
|
|
|
|
|
|
|
|
|
2023-07-05 21:54:25 -07:00
|
|
|
Assert.Multiple(() =>
|
|
|
|
|
{
|
|
|
|
|
Assert.That(invSystem.CanEquip(human, uniform, "jumpsuit", out _));
|
2020-01-20 22:16:34 +01:00
|
|
|
|
2023-07-05 21:54:25 -07:00
|
|
|
// Can't equip any of these since no uniform!
|
|
|
|
|
Assert.That(invSystem.CanEquip(human, idCard, "id", out _), Is.False);
|
|
|
|
|
Assert.That(invSystem.CanEquip(human, pocketItem, "pocket1", out _), Is.False);
|
|
|
|
|
Assert.That(invSystem.CanEquip(human, tooBigItem, "pocket2", out _), Is.False); // This one fails either way.
|
|
|
|
|
});
|
2020-01-20 22:16:34 +01:00
|
|
|
|
2023-07-05 21:54:25 -07:00
|
|
|
Assert.Multiple(() =>
|
|
|
|
|
{
|
|
|
|
|
Assert.That(invSystem.TryEquip(human, uniform, "jumpsuit"));
|
|
|
|
|
Assert.That(invSystem.TryEquip(human, idCard, "id"));
|
|
|
|
|
});
|
2020-01-20 22:16:34 +01:00
|
|
|
|
2023-07-05 21:54:25 -07:00
|
|
|
#pragma warning disable NUnit2045
|
2021-12-30 22:56:10 +01:00
|
|
|
Assert.That(invSystem.CanEquip(human, tooBigItem, "pocket1", out _), Is.False); // Still failing!
|
|
|
|
|
Assert.That(invSystem.TryEquip(human, pocketItem, "pocket1"));
|
2023-07-05 21:54:25 -07:00
|
|
|
#pragma warning restore NUnit2045
|
2020-01-20 22:16:34 +01:00
|
|
|
|
2023-07-05 21:54:25 -07:00
|
|
|
Assert.Multiple(() =>
|
|
|
|
|
{
|
|
|
|
|
Assert.That(IsDescendant(idCard, human, entityMan));
|
|
|
|
|
Assert.That(IsDescendant(pocketItem, human, entityMan));
|
|
|
|
|
});
|
2020-01-20 22:16:34 +01:00
|
|
|
|
|
|
|
|
// Now drop the jumpsuit.
|
2021-12-30 22:56:10 +01:00
|
|
|
Assert.That(invSystem.TryUnequip(human, "jumpsuit"));
|
2020-01-20 22:16:34 +01:00
|
|
|
});
|
|
|
|
|
|
2022-06-19 20:22:28 -07:00
|
|
|
await server.WaitRunTicks(2);
|
2020-01-20 22:16:34 +01:00
|
|
|
|
2022-06-19 20:22:28 -07:00
|
|
|
await server.WaitAssertion(() =>
|
2020-01-20 22:16:34 +01:00
|
|
|
{
|
2023-07-05 21:54:25 -07:00
|
|
|
Assert.Multiple(() =>
|
|
|
|
|
{
|
|
|
|
|
// Items have been dropped!
|
|
|
|
|
Assert.That(IsDescendant(uniform, human, entityMan), Is.False);
|
|
|
|
|
Assert.That(IsDescendant(idCard, human, entityMan), Is.False);
|
|
|
|
|
Assert.That(IsDescendant(pocketItem, human, entityMan), Is.False);
|
|
|
|
|
|
|
|
|
|
// Ensure everything null here.
|
|
|
|
|
Assert.That(!invSystem.TryGetSlotEntity(human, "jumpsuit", out _));
|
|
|
|
|
Assert.That(!invSystem.TryGetSlotEntity(human, "id", out _));
|
|
|
|
|
Assert.That(!invSystem.TryGetSlotEntity(human, "pocket1", out _));
|
|
|
|
|
});
|
2023-08-13 09:22:57 +12:00
|
|
|
|
|
|
|
|
mapMan.DeleteMap(testMap.MapId);
|
2020-01-20 22:16:34 +01:00
|
|
|
});
|
|
|
|
|
|
2023-08-25 02:56:51 +02:00
|
|
|
await pair.CleanReturnAsync();
|
2020-01-20 22:16:34 +01:00
|
|
|
}
|
|
|
|
|
|
2023-06-07 21:08:52 +10:00
|
|
|
private static bool IsDescendant(EntityUid descendant, EntityUid parent, IEntityManager entManager)
|
2020-01-20 22:16:34 +01:00
|
|
|
{
|
2023-06-07 21:08:52 +10:00
|
|
|
var xforms = entManager.GetEntityQuery<TransformComponent>();
|
2023-01-14 13:48:48 +13:00
|
|
|
var tmpParent = xforms.GetComponent(descendant).ParentUid;
|
|
|
|
|
while (tmpParent.IsValid())
|
2020-01-20 22:16:34 +01:00
|
|
|
{
|
2023-01-14 13:48:48 +13:00
|
|
|
if (tmpParent == parent)
|
2020-01-20 22:16:34 +01:00
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-14 13:48:48 +13:00
|
|
|
tmpParent = xforms.GetComponent(tmpParent).ParentUid;
|
2020-01-20 22:16:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|