using System.Linq; using System.Threading.Tasks; using Content.Server.Destructible.Thresholds; using Content.Server.Destructible.Thresholds.Behaviors; using Content.Shared.Damage; using Content.Shared.Damage.Prototypes; using NUnit.Framework; using Robust.Shared.GameObjects; using Robust.Shared.IoC; using Robust.Shared.Map; using Robust.Shared.Prototypes; using static Content.IntegrationTests.Tests.Destructible.DestructibleTestPrototypes; namespace Content.IntegrationTests.Tests.Destructible { public class DestructibleDestructionTest : ContentIntegrationTest { [Test] public async Task Test() { var server = StartServerDummyTicker(new ServerContentIntegrationOption { ExtraPrototypes = Prototypes }); await server.WaitIdleAsync(); var sEntityManager = server.ResolveDependency(); var sMapManager = server.ResolveDependency(); var sPrototypeManager = server.ResolveDependency(); var sEntitySystemManager = server.ResolveDependency(); IEntity sDestructibleEntity = null; DamageableComponent sDamageableComponent = null; TestDestructibleListenerSystem sTestThresholdListenerSystem = null; await server.WaitPost(() => { var mapId = new MapId(1); var coordinates = new MapCoordinates(0, 0, mapId); sMapManager.CreateMap(mapId); sDestructibleEntity = sEntityManager.SpawnEntity(DestructibleDestructionEntityId, coordinates); sDamageableComponent = sDestructibleEntity.GetComponent(); sTestThresholdListenerSystem = sEntitySystemManager.GetEntitySystem(); }); await server.WaitAssertion(() => { var coordinates = sDestructibleEntity.Transform.Coordinates; var bruteDamageGroup = sPrototypeManager.Index("TestBrute"); DamageSpecifier bruteDamage = new(bruteDamageGroup,50); Assert.DoesNotThrow(() => { EntitySystem.Get().TryChangeDamage(sDestructibleEntity.Uid, bruteDamage, true); }); Assert.That(sTestThresholdListenerSystem.ThresholdsReached.Count, Is.EqualTo(1)); var threshold = sTestThresholdListenerSystem.ThresholdsReached[0].Threshold; Assert.That(threshold.Triggered, Is.True); Assert.That(threshold.Behaviors.Count, Is.EqualTo(3)); var spawnEntitiesBehavior = (SpawnEntitiesBehavior) threshold.Behaviors.Single(b => b is SpawnEntitiesBehavior); Assert.That(spawnEntitiesBehavior.Spawn.Count, Is.EqualTo(1)); Assert.That(spawnEntitiesBehavior.Spawn.Keys.Single(), Is.EqualTo(SpawnedEntityId)); Assert.That(spawnEntitiesBehavior.Spawn.Values.Single(), Is.EqualTo(new MinMax {Min = 1, Max = 1})); var entitiesInRange = IoCManager.Resolve().GetEntitiesInRange(coordinates, 2); var found = false; foreach (var entity in entitiesInRange) { if (entity.Prototype == null) { continue; } if (entity.Prototype.Name != SpawnedEntityId) { continue; } found = true; break; } Assert.That(found, Is.True); }); } } }