Files
tbd-station-14/Content.IntegrationTests/Tests/Storage/EntityStorageTests.cs
Hannah Giovanna Dawson cdbe92d37d Update DamageableSystem to modern standards (#39417)
* Update DamageableSystem to modern standards

* DamageContainerId -> DamageContainerID with lint flag

* Replace strings with protoids

* Make CVar subscription declarations all consistently whitespaced

* ChangeDamage -> TryChangeDamage, cope with C# jank

* Revert event signature changes

* Restore a comment

* Re-add two queries

* Init the queries

* Use appearanceQuery in DamageChanged

* Use damageableQuery in TryChangeDamage

* Use damageableQuery in SetDamageModifierSetId

* Final cleanup, fix sandboxing

* Rectify ExplosionSystem:::ProcessEntity's call to TryChangeDamage

* Re-organize DamageableSystem

* first big fuck you breaking change.

* THATS A LOT OF DAMAGE!!!

* Fix test fails

* test fixes 2

* push it

---------

Co-authored-by: Princess Cheeseballs <66055347+Pronana@users.noreply.github.com>
2025-10-27 19:53:04 +00:00

83 lines
2.6 KiB
C#

using Content.Server.Storage.EntitySystems;
using Content.Shared.Damage;
using Content.Shared.Damage.Systems;
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();
}
}