Destructible spawning fix redux (#2892)
* Fix SpawnEntitiesBehavior crash and add test * Fix comparer, add duplicated behavior Turns out this isn't Java * Threshold behaviors are now "linearly" executed * Fixes YAML threshold behaviors to be linear Co-authored-by: DrSmugleaf <DrSmugleaf@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
cc4669244d
commit
85add420b0
@@ -20,9 +20,15 @@ namespace Content.IntegrationTests.Tests.Destructible
|
||||
[TestOf(typeof(Threshold))]
|
||||
public class DestructibleTests : ContentIntegrationTest
|
||||
{
|
||||
private static readonly string SpawnedEntityId = "DestructibleTestsSpawnedEntity";
|
||||
private static readonly string DestructibleEntityId = "DestructibleTestsDestructibleEntity";
|
||||
private static readonly string DestructibleDestructionEntityId = "DestructibleTestsDestructibleDestructionEntity";
|
||||
|
||||
private static readonly string Prototypes = $@"
|
||||
- type: entity
|
||||
id: {SpawnedEntityId}
|
||||
name: {SpawnedEntityId}
|
||||
|
||||
- type: entity
|
||||
id: {DestructibleEntityId}
|
||||
name: {DestructibleEntityId}
|
||||
@@ -35,15 +41,35 @@ namespace Content.IntegrationTests.Tests.Destructible
|
||||
50:
|
||||
triggersOnce: false
|
||||
behaviors:
|
||||
- !type:DoActsBehavior
|
||||
acts: [""Breakage""]
|
||||
- !type:PlaySoundBehavior
|
||||
sound: /Audio/Effects/woodhit.ogg
|
||||
- !type:SpawnEntitiesBehavior
|
||||
spawn:
|
||||
WoodPlank:
|
||||
{SpawnedEntityId}:
|
||||
min: 1
|
||||
max: 1
|
||||
- !type:DoActsBehavior
|
||||
acts: [""Breakage""]
|
||||
- type: TestThresholdListener
|
||||
|
||||
- type: entity
|
||||
id: {DestructibleDestructionEntityId}
|
||||
name: {DestructibleDestructionEntityId}
|
||||
components:
|
||||
- type: Damageable
|
||||
- type: Destructible
|
||||
thresholds:
|
||||
50:
|
||||
behaviors:
|
||||
- !type:PlaySoundBehavior
|
||||
sound: /Audio/Effects/woodhit.ogg
|
||||
- !type:SpawnEntitiesBehavior
|
||||
spawn:
|
||||
{SpawnedEntityId}:
|
||||
min: 1
|
||||
max: 1
|
||||
- !type:DoActsBehavior # This must come last as it destroys the entity.
|
||||
acts: [""Destruction""]
|
||||
- type: TestThresholdListener
|
||||
";
|
||||
|
||||
@@ -147,15 +173,15 @@ namespace Content.IntegrationTests.Tests.Destructible
|
||||
// Check that it matches the YAML prototype
|
||||
Assert.That(threshold.Behaviors, Has.Count.EqualTo(3));
|
||||
|
||||
var actsThreshold = (DoActsBehavior) threshold.Behaviors[0];
|
||||
var soundThreshold = (PlaySoundBehavior) threshold.Behaviors[1];
|
||||
var spawnThreshold = (SpawnEntitiesBehavior) threshold.Behaviors[2];
|
||||
var soundThreshold = (PlaySoundBehavior) threshold.Behaviors[0];
|
||||
var spawnThreshold = (SpawnEntitiesBehavior) threshold.Behaviors[1];
|
||||
var actsThreshold = (DoActsBehavior) threshold.Behaviors[2];
|
||||
|
||||
Assert.That(actsThreshold.Acts, Is.EqualTo(ThresholdActs.Breakage));
|
||||
Assert.That(soundThreshold.Sound, Is.EqualTo("/Audio/Effects/woodhit.ogg"));
|
||||
Assert.That(spawnThreshold.Spawn, Is.Not.Null);
|
||||
Assert.That(spawnThreshold.Spawn.Count, Is.EqualTo(1));
|
||||
Assert.That(spawnThreshold.Spawn.Single().Key, Is.EqualTo("WoodPlank"));
|
||||
Assert.That(spawnThreshold.Spawn.Single().Key, Is.EqualTo(SpawnedEntityId));
|
||||
Assert.That(spawnThreshold.Spawn.Single().Value.Min, Is.EqualTo(1));
|
||||
Assert.That(spawnThreshold.Spawn.Single().Value.Max, Is.EqualTo(1));
|
||||
Assert.That(threshold.Triggered, Is.True);
|
||||
@@ -202,16 +228,16 @@ namespace Content.IntegrationTests.Tests.Destructible
|
||||
// Check that it matches the YAML prototype
|
||||
Assert.That(threshold.Behaviors, Has.Count.EqualTo(3));
|
||||
|
||||
actsThreshold = (DoActsBehavior) threshold.Behaviors[0];
|
||||
soundThreshold = (PlaySoundBehavior) threshold.Behaviors[1];
|
||||
spawnThreshold = (SpawnEntitiesBehavior) threshold.Behaviors[2];
|
||||
soundThreshold = (PlaySoundBehavior) threshold.Behaviors[0];
|
||||
spawnThreshold = (SpawnEntitiesBehavior) threshold.Behaviors[1];
|
||||
actsThreshold = (DoActsBehavior) threshold.Behaviors[2];
|
||||
|
||||
// Check that it matches the YAML prototype
|
||||
Assert.That(actsThreshold.Acts, Is.EqualTo(ThresholdActs.Breakage));
|
||||
Assert.That(soundThreshold.Sound, Is.EqualTo("/Audio/Effects/woodhit.ogg"));
|
||||
Assert.That(spawnThreshold.Spawn, Is.Not.Null);
|
||||
Assert.That(spawnThreshold.Spawn.Count, Is.EqualTo(1));
|
||||
Assert.That(spawnThreshold.Spawn.Single().Key, Is.EqualTo("WoodPlank"));
|
||||
Assert.That(spawnThreshold.Spawn.Single().Key, Is.EqualTo(SpawnedEntityId));
|
||||
Assert.That(spawnThreshold.Spawn.Single().Value.Min, Is.EqualTo(1));
|
||||
Assert.That(spawnThreshold.Spawn.Single().Value.Max, Is.EqualTo(1));
|
||||
Assert.That(threshold.Triggered, Is.True);
|
||||
@@ -254,16 +280,16 @@ namespace Content.IntegrationTests.Tests.Destructible
|
||||
|
||||
Assert.That(threshold.Behaviors, Has.Count.EqualTo(3));
|
||||
|
||||
actsThreshold = (DoActsBehavior) threshold.Behaviors[0];
|
||||
soundThreshold = (PlaySoundBehavior) threshold.Behaviors[1];
|
||||
spawnThreshold = (SpawnEntitiesBehavior) threshold.Behaviors[2];
|
||||
soundThreshold = (PlaySoundBehavior) threshold.Behaviors[0];
|
||||
spawnThreshold = (SpawnEntitiesBehavior) threshold.Behaviors[1];
|
||||
actsThreshold = (DoActsBehavior) threshold.Behaviors[2];
|
||||
|
||||
// Check that it matches the YAML prototype
|
||||
Assert.That(actsThreshold.Acts, Is.EqualTo(ThresholdActs.Breakage));
|
||||
Assert.That(soundThreshold.Sound, Is.EqualTo("/Audio/Effects/woodhit.ogg"));
|
||||
Assert.That(spawnThreshold.Spawn, Is.Not.Null);
|
||||
Assert.That(spawnThreshold.Spawn.Count, Is.EqualTo(1));
|
||||
Assert.That(spawnThreshold.Spawn.Single().Key, Is.EqualTo("WoodPlank"));
|
||||
Assert.That(spawnThreshold.Spawn.Single().Key, Is.EqualTo(SpawnedEntityId));
|
||||
Assert.That(spawnThreshold.Spawn.Single().Value.Min, Is.EqualTo(1));
|
||||
Assert.That(spawnThreshold.Spawn.Single().Value.Max, Is.EqualTo(1));
|
||||
Assert.That(threshold.Triggered, Is.True);
|
||||
@@ -305,5 +331,84 @@ namespace Content.IntegrationTests.Tests.Destructible
|
||||
Assert.That(sThresholdListenerComponent.ThresholdsReached, Is.Empty);
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task DestructibleDestructionTest()
|
||||
{
|
||||
var server = StartServerDummyTicker(new ServerContentIntegrationOption
|
||||
{
|
||||
ExtraPrototypes = Prototypes,
|
||||
ContentBeforeIoC = () =>
|
||||
{
|
||||
IoCManager.Resolve<IComponentFactory>().Register<TestThresholdListenerComponent>();
|
||||
}
|
||||
});
|
||||
|
||||
await server.WaitIdleAsync();
|
||||
|
||||
var sEntityManager = server.ResolveDependency<IEntityManager>();
|
||||
var sMapManager = server.ResolveDependency<IMapManager>();
|
||||
|
||||
IEntity sDestructibleEntity = null;
|
||||
IDamageableComponent sDamageableComponent = null;
|
||||
DestructibleComponent sDestructibleComponent = null;
|
||||
TestThresholdListenerComponent sThresholdListenerComponent = 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<IDamageableComponent>();
|
||||
sDestructibleComponent = sDestructibleEntity.GetComponent<DestructibleComponent>();
|
||||
sThresholdListenerComponent = sDestructibleEntity.GetComponent<TestThresholdListenerComponent>();
|
||||
});
|
||||
|
||||
await server.WaitAssertion(() =>
|
||||
{
|
||||
var coordinates = sDestructibleEntity.Transform.Coordinates;
|
||||
|
||||
Assert.DoesNotThrow(() =>
|
||||
{
|
||||
Assert.True(sDamageableComponent.ChangeDamage(DamageClass.Brute, 50, true));
|
||||
});
|
||||
|
||||
Assert.That(sThresholdListenerComponent.ThresholdsReached.Count, Is.EqualTo(1));
|
||||
|
||||
var threshold = sThresholdListenerComponent.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 = sEntityManager.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);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user