ECS damageable (#4529)

* ECS and damage Data

* Comments and newlines

* Added Comments

* Make TryChangeDamageEvent immutable

* Remove SetAllDamage event

Use public SetAllDamage function instead

* Undo destructible mistakes

That was some shit code.

* Rename DamageData to DamageSpecifier

And misc small edits

misc

* Cache trigger prototypes.

* Renaming destructible classes & functions

* Revert "Cache trigger prototypes."

This reverts commit 86bae15ba6616884dba75f552dfdfbe2d1fb6586.

* Replace prototypes with prototype IDs.

* Split damage.yml into individual files

* move get/handle component state to system

* Update HealthChange doc

* Make godmode call Dirty() on damageable component

* Add Initialize() to fix damage test

* Make non-static

* uncache resistance set prototype and trim DamageableComponentState

* Remove unnecessary Dirty() calls during initialization

* RemoveTryChangeDamageEvent

* revert Dirty()

* Fix MobState relying on DamageableComponent.Dirty()

* Fix DisposalUnit Tests.

These were previously failing, but because the async was not await-ed, this never raised the exception.

After I fixed MobState component, this exception stopped happening and instead the assertions started being tested & failing

* Disposal test 2: electric boogaloo

* Fix typos/mistakes

also add comments and fix spacing.

* Use Uids instead of IEntity

* fix merge

* Comments, a merge issue, and making some damage ignore resistances

* Extend DamageSpecifier and use it for DamageableComponent

* fix master merge

* Fix Disposal unit test. Again.

Snapgrids were removed in master

* Execute Exectute
This commit is contained in:
Leon Friedrich
2021-09-15 03:07:37 +10:00
committed by GitHub
parent 22cc42ff50
commit df584ad446
212 changed files with 2876 additions and 3441 deletions

View File

@@ -1,15 +1,16 @@
#nullable enable
#nullable enable
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Content.Server.Disposal.Tube.Components;
using Content.Server.Disposal.Unit.Components;
using Content.Server.Disposal.Unit.EntitySystems;
using Content.Server.Power.Components;
using Content.Shared.Coordinates;
using NUnit.Framework;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Map;
using Robust.Shared.Physics;
using Robust.Shared.Timing;
namespace Content.IntegrationTests.Tests.Disposal
{
@@ -19,13 +20,13 @@ namespace Content.IntegrationTests.Tests.Disposal
[TestOf(typeof(DisposalUnitComponent))]
public class DisposalUnitTest : ContentIntegrationTest
{
private void UnitInsert(DisposalUnitComponent unit, bool result, params IEntity[] entities)
private async Task UnitInsert(DisposalUnitComponent unit, bool result, params IEntity[] entities)
{
List<Task> insertionTasks = new();
foreach (var entity in entities)
{
var insertTask = unit.TryInsert(entity);
Assert.That(EntitySystem.Get<DisposalUnitSystem>().CanInsert(unit, entity), Is.EqualTo(result));
insertTask.ContinueWith(task =>
var insertTask = unit.TryInsert(entity).ContinueWith(task =>
{
Assert.That(task.Result, Is.EqualTo(result));
if (result)
@@ -34,7 +35,9 @@ namespace Content.IntegrationTests.Tests.Disposal
Assert.That(entity.Transform.Parent, Is.EqualTo(unit.Owner.Transform));
}
});
insertionTasks.Add(insertTask);
}
Task.WaitAll(insertionTasks.ToArray());
}
private void UnitContains(DisposalUnitComponent unit, bool result, params IEntity[] entities)
@@ -45,9 +48,9 @@ namespace Content.IntegrationTests.Tests.Disposal
}
}
private void UnitInsertContains(DisposalUnitComponent unit, bool result, params IEntity[] entities)
private async void UnitInsertContains(DisposalUnitComponent unit, bool result, params IEntity[] entities)
{
UnitInsert(unit, result, entities);
await UnitInsert(unit, result, entities);
UnitContains(unit, result, entities);
}
@@ -68,7 +71,9 @@ namespace Content.IntegrationTests.Tests.Disposal
- type: Body
- type: MobState
- type: Damageable
damagePrototype: biologicalDamageContainer
damageContainer: Biological
- type: Physics
bodyType: KinematicController
- type: entity
name: WrenchDummy
@@ -78,6 +83,8 @@ namespace Content.IntegrationTests.Tests.Disposal
- type: Tool
qualities:
- Anchoring
- type: Physics
bodyType: Dynamic
- type: entity
name: DisposalUnitDummy
@@ -94,44 +101,78 @@ namespace Content.IntegrationTests.Tests.Disposal
id: DisposalTrunkDummy
components:
- type: DisposalEntry
- type: Transform
anchored: true
";
[Test]
public async Task Test()
{
var options = new ServerIntegrationOptions{ExtraPrototypes = Prototypes};
var options = new ServerIntegrationOptions { ExtraPrototypes = Prototypes };
var server = StartServerDummyTicker(options);
await server.WaitIdleAsync();
IEntity human;
IEntity wrench;
DisposalUnitComponent unit;
IEntity human = default!;
IEntity wrench = default!;
IEntity disposalUnit = default!;
IEntity disposalTrunk = default!;
DisposalUnitComponent unit = default!;
EntityCoordinates coordinates = default!;
server.Assert(async () =>
var mapManager = server.ResolveDependency<IMapManager>();
var entityManager = server.ResolveDependency<IEntityManager>();
var pauseManager = server.ResolveDependency<IPauseManager>();
var componentFactory = server.ResolveDependency<IComponentFactory>();
var tileDefinitionManager = server.ResolveDependency<ITileDefinitionManager>();
// Build up test environment
server.Post(() =>
{
var mapManager = IoCManager.Resolve<IMapManager>();
// Create a one tile grid to anchor our disposal unit to.
var mapId = mapManager.CreateMap();
mapManager.CreateNewMapEntity(MapId.Nullspace);
pauseManager.AddUninitializedMap(mapId);
var entityManager = IoCManager.Resolve<IEntityManager>();
var gridId = new GridId(1);
if (!mapManager.TryGetGrid(gridId, out var grid))
{
grid = mapManager.CreateGrid(mapId, gridId);
}
var tileDefinition = tileDefinitionManager["underplating"];
var tile = new Tile(tileDefinition.TileId);
coordinates = grid.ToCoordinates();
grid.SetTile(coordinates, tile);
pauseManager.DoMapInitialize(mapId);
});
await server.WaitAssertion(() =>
{
// Spawn the entities
human = entityManager.SpawnEntity("HumanDummy", MapCoordinates.Nullspace);
wrench = entityManager.SpawnEntity("WrenchDummy", MapCoordinates.Nullspace);
var disposalUnit = entityManager.SpawnEntity("DisposalUnitDummy", MapCoordinates.Nullspace);
var disposalTrunk = entityManager.SpawnEntity("DisposalTrunkDummy", disposalUnit.Transform.MapPosition);
human = entityManager.SpawnEntity("HumanDummy", coordinates);
wrench = entityManager.SpawnEntity("WrenchDummy", coordinates);
disposalUnit = entityManager.SpawnEntity("DisposalUnitDummy", coordinates);
disposalTrunk = entityManager.SpawnEntity("DisposalTrunkDummy", disposalUnit.Transform.MapPosition);
// Check that we have a grid, so that we can anchor our unit
Assert.That(mapManager.TryFindGridAt(disposalUnit.Transform.MapPosition, out var _));
// Test for components existing
Assert.True(disposalUnit.TryGetComponent(out unit!));
Assert.True(disposalTrunk.HasComponent<DisposalEntryComponent>());
// Can't insert, unanchored and unpowered
var physics = disposalUnit.GetComponent<IPhysBody>();
physics.BodyType = BodyType.Dynamic;
Assert.False(unit.Owner.Transform.Anchored);
unit.Owner.Transform.Anchored = false;
UnitInsertContains(unit, false, human, wrench, disposalUnit, disposalTrunk);
});
await server.WaitAssertion(() =>
{
// Anchor the disposal unit
physics.BodyType = BodyType.Static;
unit.Owner.Transform.Anchored = true;
// No power
Assert.False(unit.Powered);
@@ -141,19 +182,28 @@ namespace Content.IntegrationTests.Tests.Disposal
// Can insert mobs and items
UnitInsertContains(unit, true, human, wrench);
});
await server.WaitAssertion(() =>
{
// Move the disposal trunk away
disposalTrunk.Transform.WorldPosition += (1, 0);
// Fail to flush with a mob and an item
Flush(unit, false, human, wrench);
});
await server.WaitAssertion(() =>
{
// Move the disposal trunk back
disposalTrunk.Transform.WorldPosition -= (1, 0);
// Fail to flush with a mob and an item, no power
Flush(unit, false, human, wrench);
});
await server.WaitAssertion(() =>
{
// Remove power need
Assert.True(disposalUnit.TryGetComponent(out ApcPowerReceiverComponent? power));
power!.NeedsPower = false;
@@ -161,12 +211,13 @@ namespace Content.IntegrationTests.Tests.Disposal
// Flush with a mob and an item
Flush(unit, true, human, wrench);
});
await server.WaitAssertion(() =>
{
// Re-pressurizing
Flush(unit, false);
});
await server.WaitIdleAsync();
}
}
}