2023-07-05 21:54:25 -07:00
|
|
|
|
using Content.Server.Stunnable;
|
2021-12-30 22:56:10 +01:00
|
|
|
|
using Content.Shared.Inventory;
|
2021-02-11 01:13:03 -08:00
|
|
|
|
using Robust.Shared.GameObjects;
|
2020-08-21 18:09:47 +02:00
|
|
|
|
using Robust.Shared.IoC;
|
|
|
|
|
|
using Robust.Shared.Map;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Content.IntegrationTests.Tests
|
|
|
|
|
|
{
|
|
|
|
|
|
[TestFixture]
|
2022-06-19 20:22:28 -07:00
|
|
|
|
public sealed class InventoryHelpersTest
|
2020-08-21 18:09:47 +02: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
|
|
|
|
|
|
name: InventoryStunnableDummy
|
|
|
|
|
|
id: InventoryStunnableDummy
|
|
|
|
|
|
components:
|
|
|
|
|
|
- type: Inventory
|
2021-12-30 22:56:10 +01:00
|
|
|
|
- type: ContainerContainer
|
2021-10-15 14:45:04 -07:00
|
|
|
|
- type: StatusEffects
|
|
|
|
|
|
allowed:
|
|
|
|
|
|
- Stun
|
2020-12-03 02:29:50 +01:00
|
|
|
|
|
|
|
|
|
|
- type: entity
|
|
|
|
|
|
name: InventoryJumpsuitJanitorDummy
|
|
|
|
|
|
id: InventoryJumpsuitJanitorDummy
|
|
|
|
|
|
components:
|
|
|
|
|
|
- type: Clothing
|
2022-07-27 03:53:47 -07:00
|
|
|
|
slots: [innerclothing]
|
2020-12-03 02:29:50 +01:00
|
|
|
|
|
|
|
|
|
|
- type: entity
|
|
|
|
|
|
name: InventoryIDCardDummy
|
|
|
|
|
|
id: InventoryIDCardDummy
|
|
|
|
|
|
components:
|
|
|
|
|
|
- type: Clothing
|
|
|
|
|
|
QuickEquip: false
|
2022-07-27 03:53:47 -07:00
|
|
|
|
slots:
|
2020-12-03 02:29:50 +01:00
|
|
|
|
- idcard
|
2023-06-15 03:44:28 +02:00
|
|
|
|
- type: Pda
|
2020-11-18 15:30:36 +01:00
|
|
|
|
";
|
2020-08-21 18:09:47 +02:00
|
|
|
|
[Test]
|
|
|
|
|
|
public async Task SpawnItemInSlotTest()
|
|
|
|
|
|
{
|
2023-08-25 02:56:51 +02:00
|
|
|
|
await using var pair = await PoolManager.GetServerClient();
|
|
|
|
|
|
var server = pair.Server;
|
2021-12-05 18:09:01 +01:00
|
|
|
|
|
|
|
|
|
|
var sEntities = server.ResolveDependency<IEntityManager>();
|
2023-06-07 21:08:52 +10:00
|
|
|
|
var systemMan = sEntities.EntitySysManager;
|
2021-12-05 18:09:01 +01:00
|
|
|
|
|
|
|
|
|
|
await server.WaitAssertion(() =>
|
2020-08-21 18:09:47 +02:00
|
|
|
|
{
|
2021-12-30 22:56:10 +01:00
|
|
|
|
var human = sEntities.SpawnEntity("InventoryStunnableDummy", MapCoordinates.Nullspace);
|
|
|
|
|
|
var invSystem = systemMan.GetEntitySystem<InventorySystem>();
|
2020-08-21 18:09:47 +02:00
|
|
|
|
|
2023-07-05 21:54:25 -07:00
|
|
|
|
Assert.Multiple(() =>
|
|
|
|
|
|
{
|
|
|
|
|
|
// Can't do the test if this human doesn't have the slots for it.
|
|
|
|
|
|
Assert.That(invSystem.HasSlot(human, "jumpsuit"));
|
|
|
|
|
|
Assert.That(invSystem.HasSlot(human, "id"));
|
|
|
|
|
|
});
|
2020-08-21 18:09:47 +02:00
|
|
|
|
|
2021-12-30 22:56:10 +01:00
|
|
|
|
Assert.That(invSystem.SpawnItemInSlot(human, "jumpsuit", "InventoryJumpsuitJanitorDummy", true));
|
2020-08-21 18:09:47 +02:00
|
|
|
|
|
2023-07-05 21:54:25 -07:00
|
|
|
|
#pragma warning disable NUnit2045
|
2020-08-21 18:09:47 +02:00
|
|
|
|
// Do we actually have the uniform equipped?
|
2021-12-30 22:56:10 +01:00
|
|
|
|
Assert.That(invSystem.TryGetSlotEntity(human, "jumpsuit", out var uniform));
|
|
|
|
|
|
Assert.That(sEntities.GetComponent<MetaDataComponent>(uniform.Value).EntityPrototype is
|
2021-12-05 18:09:01 +01:00
|
|
|
|
{
|
|
|
|
|
|
ID: "InventoryJumpsuitJanitorDummy"
|
|
|
|
|
|
});
|
2023-07-05 21:54:25 -07:00
|
|
|
|
#pragma warning restore NUnit2045
|
2020-08-21 18:09:47 +02:00
|
|
|
|
|
2021-12-30 22:56:10 +01:00
|
|
|
|
systemMan.GetEntitySystem<StunSystem>().TryStun(human, TimeSpan.FromSeconds(1f), true);
|
2020-08-21 18:09:47 +02:00
|
|
|
|
|
2023-07-05 21:54:25 -07:00
|
|
|
|
#pragma warning disable NUnit2045
|
2020-08-21 18:09:47 +02:00
|
|
|
|
// Since the mob is stunned, they can't equip this.
|
2021-12-30 22:56:10 +01:00
|
|
|
|
Assert.That(invSystem.SpawnItemInSlot(human, "id", "InventoryIDCardDummy", true), Is.False);
|
2020-08-21 18:09:47 +02:00
|
|
|
|
|
|
|
|
|
|
// Make sure we don't have the ID card equipped.
|
2021-12-30 22:56:10 +01:00
|
|
|
|
Assert.That(invSystem.TryGetSlotEntity(human, "item", out _), Is.False);
|
2020-08-21 18:09:47 +02:00
|
|
|
|
|
|
|
|
|
|
// Let's try skipping the interaction check and see if it equips it!
|
2021-12-30 22:56:10 +01:00
|
|
|
|
Assert.That(invSystem.SpawnItemInSlot(human, "id", "InventoryIDCardDummy", true, true));
|
|
|
|
|
|
Assert.That(invSystem.TryGetSlotEntity(human, "id", out var idUid));
|
|
|
|
|
|
Assert.That(sEntities.GetComponent<MetaDataComponent>(idUid.Value).EntityPrototype is
|
2021-12-05 18:09:01 +01:00
|
|
|
|
{
|
|
|
|
|
|
ID: "InventoryIDCardDummy"
|
|
|
|
|
|
});
|
2023-07-05 21:54:25 -07:00
|
|
|
|
#pragma warning restore NUnit2045
|
2023-08-06 14:30:28 +12:00
|
|
|
|
sEntities.DeleteEntity(human);
|
2020-08-21 18:09:47 +02:00
|
|
|
|
});
|
2023-08-06 14:30:28 +12:00
|
|
|
|
|
2023-08-25 02:56:51 +02:00
|
|
|
|
await pair.CleanReturnAsync();
|
2020-08-21 18:09:47 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|