Fixes dropping item in container (#29900)
* Items droped in containers will end up in containers * Adds integration test for dropping entity while inside container * comment * comment * trim the diff --------- Co-authored-by: plykiya <plykiya@protonmail.com>
This commit is contained in:
@@ -1,8 +1,10 @@
|
||||
using System.Linq;
|
||||
using Content.Server.Storage.EntitySystems;
|
||||
using Content.Shared.Hands.Components;
|
||||
using Content.Shared.Hands.EntitySystems;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Server.Player;
|
||||
using Robust.Shared.Containers;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Map;
|
||||
|
||||
@@ -11,6 +13,19 @@ namespace Content.IntegrationTests.Tests.Hands;
|
||||
[TestFixture]
|
||||
public sealed class HandTests
|
||||
{
|
||||
[TestPrototypes]
|
||||
private const string Prototypes = @"
|
||||
- type: entity
|
||||
id: TestPickUpThenDropInContainerTestBox
|
||||
name: box
|
||||
components:
|
||||
- type: EntityStorage
|
||||
- type: ContainerContainer
|
||||
containers:
|
||||
entity_storage: !type:Container
|
||||
";
|
||||
|
||||
|
||||
[Test]
|
||||
public async Task TestPickupDrop()
|
||||
{
|
||||
@@ -57,4 +72,69 @@ public sealed class HandTests
|
||||
await server.WaitPost(() => mapMan.DeleteMap(data.MapId));
|
||||
await pair.CleanReturnAsync();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task TestPickUpThenDropInContainer()
|
||||
{
|
||||
await using var pair = await PoolManager.GetServerClient(new PoolSettings
|
||||
{
|
||||
Connected = true,
|
||||
DummyTicker = false
|
||||
});
|
||||
var server = pair.Server;
|
||||
var map = await pair.CreateTestMap();
|
||||
await pair.RunTicksSync(5);
|
||||
|
||||
var entMan = server.ResolveDependency<IEntityManager>();
|
||||
var playerMan = server.ResolveDependency<IPlayerManager>();
|
||||
var mapMan = server.ResolveDependency<IMapManager>();
|
||||
var sys = entMan.System<SharedHandsSystem>();
|
||||
var tSys = entMan.System<TransformSystem>();
|
||||
var containerSystem = server.System<SharedContainerSystem>();
|
||||
|
||||
EntityUid item = default;
|
||||
EntityUid box = default;
|
||||
EntityUid player = default;
|
||||
HandsComponent hands = default!;
|
||||
|
||||
// spawn the elusive box and crowbar at the coordinates
|
||||
await server.WaitPost(() => box = server.EntMan.SpawnEntity("TestPickUpThenDropInContainerTestBox", map.GridCoords));
|
||||
await server.WaitPost(() => item = server.EntMan.SpawnEntity("Crowbar", map.GridCoords));
|
||||
// place the player at the exact same coordinates and have them grab the crowbar
|
||||
await server.WaitPost(() =>
|
||||
{
|
||||
player = playerMan.Sessions.First().AttachedEntity!.Value;
|
||||
tSys.PlaceNextTo(player, item);
|
||||
hands = entMan.GetComponent<HandsComponent>(player);
|
||||
sys.TryPickup(player, item, hands.ActiveHand!);
|
||||
});
|
||||
await pair.RunTicksSync(5);
|
||||
Assert.That(hands.ActiveHandEntity, Is.EqualTo(item));
|
||||
|
||||
// Open then close the box to place the player, who is holding the crowbar, inside of it
|
||||
var storage = server.System<EntityStorageSystem>();
|
||||
await server.WaitPost(() =>
|
||||
{
|
||||
storage.OpenStorage(box);
|
||||
storage.CloseStorage(box);
|
||||
});
|
||||
await pair.RunTicksSync(5);
|
||||
Assert.That(containerSystem.IsEntityInContainer(player), Is.True);
|
||||
|
||||
// Dropping the item while the player is inside the box should cause the item
|
||||
// to also be inside the same container the player is in now,
|
||||
// with the item not being in the player's hands
|
||||
await server.WaitPost(() =>
|
||||
{
|
||||
sys.TryDrop(player, item, null!);
|
||||
});
|
||||
await pair.RunTicksSync(5);
|
||||
var xform = entMan.GetComponent<TransformComponent>(player);
|
||||
var itemXform = entMan.GetComponent<TransformComponent>(item);
|
||||
Assert.That(hands.ActiveHandEntity, Is.Not.EqualTo(item));
|
||||
Assert.That(containerSystem.IsInSameOrNoContainer((player, xform), (item, itemXform)));
|
||||
|
||||
await server.WaitPost(() => mapMan.DeleteMap(map.MapId));
|
||||
await pair.CleanReturnAsync();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user