hands ECS (#7081)
This commit is contained in:
@@ -5,6 +5,7 @@ using Content.Shared.ActionBlocker;
|
||||
using Content.Shared.Body.Components;
|
||||
using Content.Shared.Body.Part;
|
||||
using Content.Shared.Buckle.Components;
|
||||
using Content.Shared.Hands.EntitySystems;
|
||||
using Content.Shared.Item;
|
||||
using Content.Shared.Standing;
|
||||
using NUnit.Framework;
|
||||
@@ -251,9 +252,7 @@ namespace Content.IntegrationTests.Tests.Buckle
|
||||
{
|
||||
var akms = entityManager.SpawnEntity(ItemDummyId, coordinates);
|
||||
|
||||
// Equip items
|
||||
Assert.True(entityManager.TryGetComponent(akms, out SharedItemComponent item));
|
||||
Assert.True(hands.PutInHand(item));
|
||||
Assert.True(EntitySystem.Get<SharedHandsSystem>().TryPickupAnyHand(human, akms));
|
||||
}
|
||||
});
|
||||
|
||||
@@ -265,9 +264,9 @@ namespace Content.IntegrationTests.Tests.Buckle
|
||||
Assert.True(buckle.Buckled);
|
||||
|
||||
// With items in all hands
|
||||
foreach (var slot in hands.HandNames)
|
||||
foreach (var hand in hands.Hands.Values)
|
||||
{
|
||||
Assert.NotNull(hands.GetItem(slot));
|
||||
Assert.NotNull(hands.ActiveHandEntity);
|
||||
}
|
||||
|
||||
var legs = body.GetPartsOfType(BodyPartType.Leg);
|
||||
@@ -287,9 +286,9 @@ namespace Content.IntegrationTests.Tests.Buckle
|
||||
Assert.True(buckle.Buckled);
|
||||
|
||||
// Now with no item in any hand
|
||||
foreach (var slot in hands.HandNames)
|
||||
foreach (var hand in hands.Hands.Values)
|
||||
{
|
||||
Assert.Null(hands.GetItem(slot));
|
||||
Assert.Null(hands.ActiveHandEntity);
|
||||
}
|
||||
|
||||
buckle.TryUnbuckle(human, true);
|
||||
|
||||
@@ -81,7 +81,7 @@ namespace Content.IntegrationTests.Tests.GameObjects.Components.ActionBlocking
|
||||
AddHand(cuffed.Owner);
|
||||
|
||||
Assert.That(cuffed.CuffedHandCount, Is.EqualTo(2));
|
||||
Assert.That(hands.HandNames.Count(), Is.EqualTo(4));
|
||||
Assert.That(hands.SortedHands.Count(), Is.EqualTo(4));
|
||||
|
||||
// Test to give a player with 4 hands 2 sets of cuffs
|
||||
cuffed.TryAddNewCuffs(human, secondCuffs);
|
||||
|
||||
@@ -4,6 +4,7 @@ using Content.Client.Items.Components;
|
||||
using Content.Server.Hands.Components;
|
||||
using Content.Server.Interaction;
|
||||
using Content.Shared.Hands.Components;
|
||||
using Content.Shared.Hands.EntitySystems;
|
||||
using Content.Shared.Interaction;
|
||||
using Content.Shared.Item;
|
||||
using Content.Shared.Weapons.Melee;
|
||||
@@ -54,6 +55,8 @@ namespace Content.IntegrationTests.Tests.Interaction.Click
|
||||
|
||||
var sEntities = server.ResolveDependency<IEntityManager>();
|
||||
var mapManager = server.ResolveDependency<IMapManager>();
|
||||
var sysMan = server.ResolveDependency<IEntitySystemManager>();
|
||||
var handSys = sysMan.GetEntitySystem<SharedHandsSystem>();
|
||||
|
||||
var mapId = MapId.Nullspace;
|
||||
var coords = MapCoordinates.Nullspace;
|
||||
@@ -71,7 +74,8 @@ namespace Content.IntegrationTests.Tests.Interaction.Click
|
||||
server.Assert(() =>
|
||||
{
|
||||
user = sEntities.SpawnEntity(null, coords);
|
||||
user.EnsureComponent<HandsComponent>().AddHand("hand", HandLocation.Left);
|
||||
user.EnsureComponent<HandsComponent>();
|
||||
handSys.AddHand(user, "hand", HandLocation.Left);
|
||||
target = sEntities.SpawnEntity(null, coords);
|
||||
item = sEntities.SpawnEntity(null, coords);
|
||||
item.EnsureComponent<ItemComponent>();
|
||||
@@ -98,8 +102,7 @@ namespace Content.IntegrationTests.Tests.Interaction.Click
|
||||
Assert.That(interactUsing, Is.False);
|
||||
Assert.That(interactHand);
|
||||
|
||||
Assert.That(sEntities.TryGetComponent<HandsComponent>(user, out var hands));
|
||||
Assert.That(hands.PutInHand(sEntities.GetComponent<SharedItemComponent>(item)));
|
||||
Assert.That(handSys.TryPickup(user, item));
|
||||
|
||||
interactionSystem.UserInteraction(user, sEntities.GetComponent<TransformComponent>(target).Coordinates, target);
|
||||
Assert.That(interactUsing);
|
||||
@@ -124,6 +127,8 @@ namespace Content.IntegrationTests.Tests.Interaction.Click
|
||||
|
||||
var sEntities = server.ResolveDependency<IEntityManager>();
|
||||
var mapManager = server.ResolveDependency<IMapManager>();
|
||||
var sysMan = server.ResolveDependency<IEntitySystemManager>();
|
||||
var handSys = sysMan.GetEntitySystem<SharedHandsSystem>();
|
||||
|
||||
var mapId = MapId.Nullspace;
|
||||
var coords = MapCoordinates.Nullspace;
|
||||
@@ -142,7 +147,8 @@ namespace Content.IntegrationTests.Tests.Interaction.Click
|
||||
server.Assert(() =>
|
||||
{
|
||||
user = sEntities.SpawnEntity(null, coords);
|
||||
user.EnsureComponent<HandsComponent>().AddHand("hand", HandLocation.Left);
|
||||
user.EnsureComponent<HandsComponent>();
|
||||
handSys.AddHand(user, "hand", HandLocation.Left);
|
||||
target = sEntities.SpawnEntity(null, new MapCoordinates((1.9f, 0), mapId));
|
||||
item = sEntities.SpawnEntity(null, coords);
|
||||
item.EnsureComponent<ItemComponent>();
|
||||
@@ -170,8 +176,7 @@ namespace Content.IntegrationTests.Tests.Interaction.Click
|
||||
Assert.That(interactUsing, Is.False);
|
||||
Assert.That(interactHand, Is.False);
|
||||
|
||||
Assert.That(sEntities.TryGetComponent<HandsComponent?>(user, out var hands));
|
||||
Assert.That(hands.PutInHand(sEntities.GetComponent<SharedItemComponent>(item)));
|
||||
Assert.That(handSys.TryPickup(user, item));
|
||||
|
||||
interactionSystem.UserInteraction(user, sEntities.GetComponent<TransformComponent>(target).Coordinates, target);
|
||||
Assert.That(interactUsing, Is.False);
|
||||
@@ -195,6 +200,8 @@ namespace Content.IntegrationTests.Tests.Interaction.Click
|
||||
|
||||
var sEntities = server.ResolveDependency<IEntityManager>();
|
||||
var mapManager = server.ResolveDependency<IMapManager>();
|
||||
var sysMan = server.ResolveDependency<IEntitySystemManager>();
|
||||
var handSys = sysMan.GetEntitySystem<SharedHandsSystem>();
|
||||
|
||||
var mapId = MapId.Nullspace;
|
||||
var coords = MapCoordinates.Nullspace;
|
||||
@@ -212,7 +219,8 @@ namespace Content.IntegrationTests.Tests.Interaction.Click
|
||||
server.Assert(() =>
|
||||
{
|
||||
user = sEntities.SpawnEntity(null, coords);
|
||||
user.EnsureComponent<HandsComponent>().AddHand("hand", HandLocation.Left);
|
||||
user.EnsureComponent<HandsComponent>();
|
||||
handSys.AddHand(user, "hand", HandLocation.Left);
|
||||
target = sEntities.SpawnEntity(null, new MapCoordinates((InteractionSystem.InteractionRange - 0.1f, 0), mapId));
|
||||
item = sEntities.SpawnEntity(null, coords);
|
||||
item.EnsureComponent<ItemComponent>();
|
||||
@@ -239,8 +247,7 @@ namespace Content.IntegrationTests.Tests.Interaction.Click
|
||||
Assert.That(interactUsing, Is.False);
|
||||
Assert.That(interactHand);
|
||||
|
||||
Assert.That(sEntities.TryGetComponent<HandsComponent>(user, out var hands));
|
||||
Assert.That(hands.PutInHand(sEntities.GetComponent<SharedItemComponent>(item)));
|
||||
Assert.That(handSys.TryPickup(user, item));
|
||||
|
||||
interactionSystem.UserInteraction(user, sEntities.GetComponent<TransformComponent>(target).Coordinates, target);
|
||||
Assert.That(interactUsing);
|
||||
@@ -265,6 +272,8 @@ namespace Content.IntegrationTests.Tests.Interaction.Click
|
||||
|
||||
var sEntities = server.ResolveDependency<IEntityManager>();
|
||||
var mapManager = server.ResolveDependency<IMapManager>();
|
||||
var sysMan = server.ResolveDependency<IEntitySystemManager>();
|
||||
var handSys = sysMan.GetEntitySystem<SharedHandsSystem>();
|
||||
|
||||
var mapId = MapId.Nullspace;
|
||||
var coords = MapCoordinates.Nullspace;
|
||||
@@ -282,7 +291,8 @@ namespace Content.IntegrationTests.Tests.Interaction.Click
|
||||
server.Assert(() =>
|
||||
{
|
||||
user = sEntities.SpawnEntity(null, coords);
|
||||
user.EnsureComponent<HandsComponent>().AddHand("hand", HandLocation.Left);
|
||||
user.EnsureComponent<HandsComponent>();
|
||||
handSys.AddHand(user, "hand", HandLocation.Left);
|
||||
target = sEntities.SpawnEntity(null, new MapCoordinates((SharedInteractionSystem.InteractionRange + 0.01f, 0), mapId));
|
||||
item = sEntities.SpawnEntity(null, coords);
|
||||
item.EnsureComponent<ItemComponent>();
|
||||
@@ -309,8 +319,7 @@ namespace Content.IntegrationTests.Tests.Interaction.Click
|
||||
Assert.That(interactUsing, Is.False);
|
||||
Assert.That(interactHand, Is.False);
|
||||
|
||||
Assert.That(sEntities.TryGetComponent<HandsComponent?>(user, out var hands));
|
||||
Assert.That(hands.PutInHand(sEntities.GetComponent<SharedItemComponent>(item)));
|
||||
Assert.That(handSys.TryPickup(user, item));
|
||||
|
||||
interactionSystem.UserInteraction(user, sEntities.GetComponent<TransformComponent>(target).Coordinates, target);
|
||||
Assert.That(interactUsing, Is.False);
|
||||
@@ -335,6 +344,8 @@ namespace Content.IntegrationTests.Tests.Interaction.Click
|
||||
|
||||
var sEntities = server.ResolveDependency<IEntityManager>();
|
||||
var mapManager = server.ResolveDependency<IMapManager>();
|
||||
var sysMan = server.ResolveDependency<IEntitySystemManager>();
|
||||
var handSys = sysMan.GetEntitySystem<SharedHandsSystem>();
|
||||
|
||||
var mapId = MapId.Nullspace;
|
||||
var coords = MapCoordinates.Nullspace;
|
||||
@@ -354,7 +365,8 @@ namespace Content.IntegrationTests.Tests.Interaction.Click
|
||||
server.Assert(() =>
|
||||
{
|
||||
user = sEntities.SpawnEntity(null, coords);
|
||||
user.EnsureComponent<HandsComponent>().AddHand("hand", HandLocation.Left);
|
||||
user.EnsureComponent<HandsComponent>();
|
||||
handSys.AddHand(user, "hand", HandLocation.Left);
|
||||
target = sEntities.SpawnEntity(null, coords);
|
||||
item = sEntities.SpawnEntity(null, coords);
|
||||
item.EnsureComponent<ItemComponent>();
|
||||
@@ -394,8 +406,7 @@ namespace Content.IntegrationTests.Tests.Interaction.Click
|
||||
Assert.That(interactUsing, Is.False);
|
||||
Assert.That(interactHand);
|
||||
|
||||
Assert.That(sEntities.TryGetComponent<HandsComponent?>(user, out var hands));
|
||||
Assert.That(hands.PutInHand(sEntities.GetComponent<SharedItemComponent>(item)));
|
||||
Assert.That(handSys.TryPickup(user, item));
|
||||
|
||||
interactionSystem.UserInteraction(user, sEntities.GetComponent<TransformComponent>(target).Coordinates, target);
|
||||
Assert.That(interactUsing, Is.False);
|
||||
|
||||
@@ -1,133 +0,0 @@
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Content.Server.Hands.Components;
|
||||
using Content.Server.PDA;
|
||||
using Content.Shared.Access.Components;
|
||||
using Content.Shared.Containers.ItemSlots;
|
||||
using Content.Shared.Inventory;
|
||||
using Content.Shared.Item;
|
||||
using Content.Shared.PDA;
|
||||
using NUnit.Framework;
|
||||
using Robust.Server.Player;
|
||||
using Robust.Shared.GameObjects;
|
||||
|
||||
namespace Content.IntegrationTests.Tests.PDA
|
||||
{
|
||||
public sealed class PDAExtensionsTests : ContentIntegrationTest
|
||||
{
|
||||
private const string IdCardDummy = "DummyIdCard";
|
||||
private const string PdaDummy = "DummyPda";
|
||||
|
||||
private static readonly string Prototypes = $@"
|
||||
- type: entity
|
||||
id: {IdCardDummy}
|
||||
name: {IdCardDummy}
|
||||
components:
|
||||
- type: IdCard
|
||||
- type: Item
|
||||
|
||||
- type: entity
|
||||
id: {PdaDummy}
|
||||
name: {PdaDummy}
|
||||
components:
|
||||
- type: PDA
|
||||
idSlot:
|
||||
name: ID Card
|
||||
whitelist:
|
||||
components:
|
||||
- IdCard
|
||||
- type: Item";
|
||||
|
||||
[Test]
|
||||
public async Task PlayerGetIdComponent()
|
||||
{
|
||||
var clientOptions = new ClientIntegrationOptions
|
||||
{
|
||||
ExtraPrototypes = Prototypes
|
||||
};
|
||||
|
||||
var serverOptions = new ServerIntegrationOptions
|
||||
{
|
||||
ExtraPrototypes = Prototypes
|
||||
};
|
||||
|
||||
var (client, server) = await StartConnectedServerClientPair(clientOptions, serverOptions);
|
||||
|
||||
await Task.WhenAll(client.WaitIdleAsync(), server.WaitIdleAsync());
|
||||
|
||||
var sPlayerManager = server.ResolveDependency<IPlayerManager>();
|
||||
var sEntityManager = server.ResolveDependency<IEntityManager>();
|
||||
|
||||
var invSystem = server.ResolveDependency<IEntitySystemManager>().GetEntitySystem<InventorySystem>();
|
||||
|
||||
await server.WaitAssertion(() =>
|
||||
{
|
||||
var player = sPlayerManager.Sessions.Single().AttachedEntity.GetValueOrDefault();
|
||||
|
||||
Assert.That(player != default);
|
||||
|
||||
// The player spawns with an ID on by default
|
||||
Assert.NotNull(player.GetHeldId());
|
||||
Assert.True(player.TryGetHeldId(out var id));
|
||||
Assert.NotNull(id);
|
||||
|
||||
// Put PDA in hand
|
||||
var dummyPda = sEntityManager.SpawnEntity(PdaDummy, sEntityManager.GetComponent<TransformComponent>(player).MapPosition);
|
||||
var pdaItemComponent = sEntityManager.GetComponent<SharedItemComponent>(dummyPda);
|
||||
sEntityManager.GetComponent<HandsComponent>(player).PutInHand(pdaItemComponent);
|
||||
|
||||
var pdaComponent = sEntityManager.GetComponent<PDAComponent>(dummyPda);
|
||||
var pdaIdCard = sEntityManager.SpawnEntity(IdCardDummy, sEntityManager.GetComponent<TransformComponent>(player).MapPosition);
|
||||
|
||||
var itemSlots = sEntityManager.GetComponent<ItemSlotsComponent>(dummyPda);
|
||||
sEntityManager.EntitySysManager.GetEntitySystem<ItemSlotsSystem>()
|
||||
.TryInsert(dummyPda, pdaComponent.IdSlot, pdaIdCard, null);
|
||||
var pdaContainedId = pdaComponent.ContainedID;
|
||||
|
||||
// The PDA in the hand should be found first
|
||||
Assert.NotNull(player.GetHeldId());
|
||||
Assert.True(player.TryGetHeldId(out id));
|
||||
|
||||
Assert.NotNull(id);
|
||||
Assert.That(id, Is.EqualTo(pdaContainedId));
|
||||
|
||||
// Put ID card in hand
|
||||
var idDummy = sEntityManager.SpawnEntity(IdCardDummy, sEntityManager.GetComponent<TransformComponent>(player).MapPosition);
|
||||
var idItemComponent = sEntityManager.GetComponent<SharedItemComponent>(idDummy);
|
||||
sEntityManager.GetComponent<HandsComponent>(player).PutInHand(idItemComponent);
|
||||
|
||||
var idCardComponent = sEntityManager.GetComponent<IdCardComponent>(idDummy);
|
||||
|
||||
// The ID in the hand should be found first
|
||||
Assert.NotNull(player.GetHeldId());
|
||||
Assert.True(player.TryGetHeldId(out id));
|
||||
Assert.NotNull(id);
|
||||
Assert.That(id, Is.EqualTo(idCardComponent));
|
||||
|
||||
// Remove all IDs and PDAs
|
||||
Assert.That(invSystem.TryGetSlots(player, out var slots));
|
||||
|
||||
foreach (var slot in slots)
|
||||
{
|
||||
if(!invSystem.TryGetSlotEntity(player, slot.Name, out var item))
|
||||
continue;
|
||||
|
||||
if (sEntityManager.HasComponent<PDAComponent>(item))
|
||||
{
|
||||
invSystem.TryUnequip(player, slot.Name, force: true);
|
||||
}
|
||||
}
|
||||
|
||||
var hands = sEntityManager.GetComponent<HandsComponent>(player);
|
||||
|
||||
hands.Drop(dummyPda, false);
|
||||
hands.Drop(idDummy, false);
|
||||
|
||||
// No ID
|
||||
Assert.Null(player.GetHeldId());
|
||||
Assert.False(player.TryGetHeldId(out id));
|
||||
Assert.Null(id);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user