forked from space-wizards/space-station-14
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix storage destruction/deletion bug (space-wizards#24882)
- Loading branch information
Showing
2 changed files
with
94 additions
and
0 deletions.
There are no files selected for viewing
81 changes: 81 additions & 0 deletions
81
Content.IntegrationTests/Tests/Storage/EntityStorageTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
using Content.Server.Storage.EntitySystems; | ||
using Content.Shared.Damage; | ||
using Robust.Shared.Containers; | ||
using Robust.Shared.GameObjects; | ||
|
||
namespace Content.IntegrationTests.Tests.Storage; | ||
|
||
[TestFixture] | ||
public sealed class EntityStorageTests | ||
{ | ||
[TestPrototypes] | ||
private const string Prototypes = @" | ||
- type: entity | ||
id: EntityStorageTest | ||
name: box | ||
components: | ||
- type: EntityStorage | ||
- type: Damageable | ||
damageContainer: Inorganic | ||
- type: Destructible | ||
thresholds: | ||
- trigger: | ||
!type:DamageTrigger | ||
damage: 10 | ||
behaviors: | ||
- !type:DoActsBehavior | ||
acts: [ Destruction ] | ||
"; | ||
|
||
[Test] | ||
public async Task TestContainerDestruction() | ||
{ | ||
await using var pair = await PoolManager.GetServerClient(); | ||
var server = pair.Server; | ||
var map = await pair.CreateTestMap(); | ||
|
||
EntityUid box = default; | ||
EntityUid crowbar = default; | ||
await server.WaitPost(() => box = server.EntMan.SpawnEntity("EntityStorageTest", map.GridCoords)); | ||
await server.WaitPost(() => crowbar = server.EntMan.SpawnEntity("Crowbar", map.GridCoords)); | ||
|
||
// Initially the crowbar is not in a contaienr. | ||
var sys = server.System<SharedContainerSystem>(); | ||
Assert.That(sys.IsEntityInContainer(crowbar), Is.False); | ||
|
||
// Open then close the storage entity | ||
var storage = server.System<EntityStorageSystem>(); | ||
await server.WaitPost(() => | ||
{ | ||
storage.OpenStorage(box); | ||
storage.CloseStorage(box); | ||
}); | ||
|
||
// Crowbar is now in the box | ||
Assert.That(sys.IsEntityInContainer(crowbar)); | ||
|
||
// Damage the box | ||
var damage = new DamageSpecifier(); | ||
damage.DamageDict.Add("Blunt", 100); | ||
await server.WaitPost(() => server.System<DamageableSystem>().TryChangeDamage(box, damage)); | ||
|
||
// Box has been destroyed, contents have been emptied. Destruction uses deffered deletion. | ||
Assert.That(server.EntMan.IsQueuedForDeletion(box)); | ||
Assert.That(sys.IsEntityInContainer(crowbar), Is.False); | ||
|
||
// Opening and closing the soon-to-be-deleted box should not re-insert the crowbar | ||
await server.WaitPost(() => | ||
{ | ||
storage.OpenStorage(box); | ||
storage.CloseStorage(box); | ||
}); | ||
Assert.That(sys.IsEntityInContainer(crowbar), Is.False); | ||
|
||
// Entity gets deleted after a few ticks | ||
await server.WaitRunTicks(5); | ||
Assert.That(server.EntMan.Deleted(box)); | ||
Assert.That(server.EntMan.Deleted(crowbar), Is.False); | ||
|
||
await pair.CleanReturnAsync(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters