Revert "Refactor Damage to use Protoypes (#4262)"

This reverts commit 20bf5739a9.
This commit is contained in:
Silver
2021-08-24 00:50:39 -06:00
committed by Silver
parent 20bf5739a9
commit e708091518
121 changed files with 711 additions and 10237 deletions

View File

@@ -1,4 +1,4 @@
using System.Threading.Tasks;
using System.Threading.Tasks;
using Content.Server.Damage;
using Content.Shared.Damage;
using Content.Shared.Damage.Components;
@@ -7,7 +7,6 @@ using NUnit.Framework;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Map;
using Robust.Shared.Prototypes;
namespace Content.IntegrationTests.Tests.Commands
{
@@ -21,7 +20,7 @@ namespace Content.IntegrationTests.Tests.Commands
id: DamageableDummy
components:
- type: Damageable
damageContainer: biologicalDamageContainer
damagePrototype: biologicalDamageContainer
- type: MobState
thresholds:
0: !type:NormalMobState {}
@@ -42,7 +41,6 @@ namespace Content.IntegrationTests.Tests.Commands
mapManager.CreateNewMapEntity(MapId.Nullspace);
var entityManager = IoCManager.Resolve<IEntityManager>();
var prototypeManager = IoCManager.Resolve<IPrototypeManager>();
var human = entityManager.SpawnEntity("DamageableDummy", MapCoordinates.Nullspace);
@@ -55,7 +53,7 @@ namespace Content.IntegrationTests.Tests.Commands
Assert.That(mobState.IsIncapacitated, Is.False);
// Kill the entity
damageable.TryChangeDamage(prototypeManager.Index<DamageGroupPrototype>("Toxin"), 10000000, true);
damageable.ChangeDamage(DamageClass.Brute, 10000000, true);
// Check that it is dead
Assert.That(mobState.IsAlive, Is.False);

View File

@@ -1,121 +0,0 @@
using System.Linq;
using System.Threading.Tasks;
using Content.Shared.Damage;
using Content.Shared.Damage.Components;
using NUnit.Framework;
using Robust.Shared.GameObjects;
using Robust.Shared.Map;
using Robust.Shared.Prototypes;
namespace Content.IntegrationTests.Tests.Damageable
{
[TestFixture]
[TestOf(typeof(DamageableComponent))]
public class AllSupportDamageableTest : ContentIntegrationTest
{
private const string AllDamageDamageableEntityId = "TestAllDamageDamageableEntityId";
/// <summary>
/// Test a damageContainer with all types supported.
/// </summary>
/// <remarks>
/// As this should also loads in the damage groups & types in the actual damage.yml, this should also act as a basic test to see if damage.yml is set up properly.
/// </remarks>
[Test]
public async Task TestAllSupportDamageableComponent()
{
var server = StartServerDummyTicker();
await server.WaitIdleAsync();
var sEntityManager = server.ResolveDependency<IEntityManager>();
var sMapManager = server.ResolveDependency<IMapManager>();
var sPrototypeManager = server.ResolveDependency<IPrototypeManager>();
IEntity sFullyDamageableEntity;
IDamageableComponent sFullyDamageableComponent = null;
await server.WaitPost(() =>
{
var mapId = sMapManager.NextMapId();
var coordinates = new MapCoordinates(0, 0, mapId);
sMapManager.CreateMap(mapId);
// When prototypes are loaded using the ExtraPrototypes option, they seem to be loaded first?
// Or at least, no damage prototypes were loaded in by the time that the damageContainer here is loaded.
// So for now doing explicit loading of prototypes.
// I have no idea what I am doing, but it works.
sPrototypeManager.LoadString($@"
# we want to test the all damage container
- type: damageContainer
id: testAllDamageContainer
supportAll: true
# create entities
- type: entity
id: {AllDamageDamageableEntityId}
name: {AllDamageDamageableEntityId}
components:
- type: Damageable
damageContainer: testAllDamageContainer
");
sFullyDamageableEntity = sEntityManager.SpawnEntity(AllDamageDamageableEntityId, coordinates);
sFullyDamageableComponent = sFullyDamageableEntity.GetComponent<IDamageableComponent>();
});
await server.WaitRunTicks(5);
await server.WaitAssertion(() =>
{
// First check that there actually are any damage types/groups
// This test depends on a non-empty damage.yml
Assert.That(sPrototypeManager.EnumeratePrototypes<DamageTypePrototype>().ToList().Count, Is.GreaterThan(0));
Assert.That(sPrototypeManager.EnumeratePrototypes<DamageGroupPrototype>().ToList().Count, Is.GreaterThan(0));
// Can we set and get all damage.
Assert.That(sFullyDamageableComponent.TrySetAllDamage(-10), Is.False);
Assert.That(sFullyDamageableComponent.TrySetAllDamage(0), Is.True);
// Test that the all damage container supports every damage type, and that we can get, set, and change
// every type with the expected results. Notable: if the damage does not change, they all return false
var initialDamage = 10;
foreach (var damageType in sPrototypeManager.EnumeratePrototypes<DamageTypePrototype>())
{
var damage = initialDamage;
Assert.That(sFullyDamageableComponent.IsSupportedDamageType(damageType));
Assert.That(sFullyDamageableComponent.TrySetDamage(damageType, -damage), Is.False);
Assert.That(sFullyDamageableComponent.TrySetDamage(damageType, damage), Is.True);
Assert.That(sFullyDamageableComponent.TrySetDamage(damageType, damage), Is.True); // intentional duplicate
Assert.That(sFullyDamageableComponent.GetDamage(damageType), Is.EqualTo(damage));
Assert.That(sFullyDamageableComponent.TryChangeDamage(damageType, -damage / 2, true), Is.True);
Assert.That(sFullyDamageableComponent.TryGetDamage(damageType, out damage), Is.True);
Assert.That(damage, Is.EqualTo(initialDamage/2));
Assert.That(sFullyDamageableComponent.TryChangeDamage(damageType, damage, true), Is.True);
Assert.That(sFullyDamageableComponent.GetDamage(damageType), Is.EqualTo(2* damage));
Assert.That(sFullyDamageableComponent.TryChangeDamage(damageType, 0, true), Is.False);
}
// And again, for every group
foreach (var damageGroup in sPrototypeManager.EnumeratePrototypes<DamageGroupPrototype>())
{
var damage = initialDamage;
var groupSize = damageGroup.DamageTypes.Count();
Assert.That(sFullyDamageableComponent.IsFullySupportedDamageGroup(damageGroup));
Assert.That(sFullyDamageableComponent.IsApplicableDamageGroup(damageGroup));
Assert.That(sFullyDamageableComponent.TrySetDamage(damageGroup, -damage), Is.False);
Assert.That(sFullyDamageableComponent.TrySetDamage(damageGroup, damage), Is.True);
Assert.That(sFullyDamageableComponent.TrySetDamage(damageGroup, damage), Is.True); // intentional duplicate
Assert.That(sFullyDamageableComponent.GetDamage(damageGroup), Is.EqualTo(damage * groupSize));
Assert.That(sFullyDamageableComponent.TryChangeDamage(damageGroup, -groupSize*damage / 2, true), Is.True);
Assert.That(sFullyDamageableComponent.TryGetDamage(damageGroup, out damage), Is.True);
Assert.That(damage, Is.EqualTo(groupSize* initialDamage/2));
Assert.That(sFullyDamageableComponent.TryChangeDamage(damageGroup, damage, true), Is.True);
Assert.That(sFullyDamageableComponent.GetDamage(damageGroup), Is.EqualTo(2*damage));
Assert.That(sFullyDamageableComponent.TryChangeDamage(damageGroup, 0, true), Is.False);
}
});
}
}
}

View File

@@ -1,11 +1,10 @@
using System.Linq;
using System;
using System.Threading.Tasks;
using Content.Shared.Damage;
using Content.Shared.Damage.Components;
using NUnit.Framework;
using Robust.Shared.GameObjects;
using Robust.Shared.Map;
using Robust.Shared.Prototypes;
namespace Content.IntegrationTests.Tests.Damageable
{
@@ -13,75 +12,18 @@ namespace Content.IntegrationTests.Tests.Damageable
[TestOf(typeof(DamageableComponent))]
public class DamageableTest : ContentIntegrationTest
{
private const string DamageableEntityId = "TestDamageableEntityId";
private const string Group1Id = "TestGroup1";
private const string Group2Id = "TestGroup2";
private const string Group3Id = "TestGroup3";
private string Prototypes = $@"
# Define some damage groups
- type: damageType
id: TestDamage11
- type: damageType
id: TestDamage21
- type: damageType
id: TestDamage22
- type: damageType
id: TestDamage31
- type: damageType
id: TestDamage32
- type: damageType
id: TestDamage33
# Define damage Groups with 1,2,3 damage types
- type: damageGroup
id: {Group1Id}
damageTypes:
- TestDamage11
- type: damageGroup
id: {Group2Id}
damageTypes:
- TestDamage21
- TestDamage22
- type: damageGroup
id: {Group3Id}
damageTypes:
- TestDamage31
- TestDamage32
- TestDamage33
# we want to test a container that supports only full groups
# we will also give full support for group 2 IMPLICITLY by specifying all of its members are supported.
- type: damageContainer
id: testSomeDamageContainer
supportedGroups:
- {Group3Id}
supportedTypes:
- TestDamage21
- TestDamage22
private const string DamageableEntityId = "DamageableEntityId";
private static readonly string Prototypes = $@"
- type: entity
id: {DamageableEntityId}
name: {DamageableEntityId}
components:
- type: Damageable
damageContainer: testSomeDamageContainer
";
damageContainer: allDamageContainer";
/// <summary>
/// Test a standard damageable components
/// </summary>
/// <remarks>
/// Only test scenarios where each damage type is a member of exactly one group, and all damageable components support whole groups, not lone damage types.
/// </remarks>
[Test]
public async Task TestDamageableComponents()
public async Task TestDamageTypeDamageAndHeal()
{
var server = StartServerDummyTicker(new ServerContentIntegrationOption
{
@@ -92,15 +34,10 @@ namespace Content.IntegrationTests.Tests.Damageable
var sEntityManager = server.ResolveDependency<IEntityManager>();
var sMapManager = server.ResolveDependency<IMapManager>();
var sPrototypeManager = server.ResolveDependency<IPrototypeManager>();
IEntity sDamageableEntity;
IDamageableComponent sDamageableComponent = null;
DamageGroupPrototype group1 = default!;
DamageGroupPrototype group2 = default!;
DamageGroupPrototype group3 = default!;
await server.WaitPost(() =>
{
var mapId = sMapManager.NextMapId();
@@ -109,280 +46,51 @@ namespace Content.IntegrationTests.Tests.Damageable
sDamageableEntity = sEntityManager.SpawnEntity(DamageableEntityId, coordinates);
sDamageableComponent = sDamageableEntity.GetComponent<IDamageableComponent>();
group1 = sPrototypeManager.Index<DamageGroupPrototype>(Group1Id);
group2 = sPrototypeManager.Index<DamageGroupPrototype>(Group2Id);
group3 = sPrototypeManager.Index<DamageGroupPrototype>(Group3Id);
});
await server.WaitRunTicks(5);
await server.WaitAssertion(() =>
{
// Check that the correct groups are supported by the container
Assert.That(sDamageableComponent.IsApplicableDamageGroup(group1), Is.False);
Assert.That(sDamageableComponent.IsApplicableDamageGroup(group2), Is.True);
Assert.That(sDamageableComponent.IsApplicableDamageGroup(group3), Is.True);
Assert.That(sDamageableComponent.IsFullySupportedDamageGroup(group1), Is.False);
Assert.That(sDamageableComponent.IsFullySupportedDamageGroup(group2), Is.True);
Assert.That(sDamageableComponent.IsFullySupportedDamageGroup(group3), Is.True);
// Check that the correct types are supported:
foreach (var group in sPrototypeManager.EnumeratePrototypes<DamageGroupPrototype>())
{
foreach(var type in group.DamageTypes)
{
if (sDamageableComponent.IsFullySupportedDamageGroup(group))
{
Assert.That(sDamageableComponent.IsSupportedDamageType(type), Is.True);
}
else
{
Assert.That(sDamageableComponent.IsSupportedDamageType(type), Is.False);
}
}
}
Assert.That(sDamageableComponent.IsFullySupportedDamageGroup(group1), Is.False);
Assert.That(sDamageableComponent.IsFullySupportedDamageGroup(group2), Is.True);
Assert.That(sDamageableComponent.IsFullySupportedDamageGroup(group3), Is.True);
// Check that damage works properly if perfectly divisible among group members
int damageToDeal, groupDamage, typeDamage; ;
Assert.That(sDamageableComponent.TotalDamage, Is.EqualTo(0));
foreach (var damageGroup in sDamageableComponent.FullySupportedDamageGroups)
var damageToDeal = 7;
foreach (var type in Enum.GetValues<DamageType>())
{
var types = damageGroup.DamageTypes;
Assert.That(sDamageableComponent.SupportsDamageType(type));
// Damage
damageToDeal = types.Count() * 5;
Assert.That(sDamageableComponent.TryChangeDamage(damageGroup, damageToDeal, true), Is.True);
Assert.That(sDamageableComponent.ChangeDamage(type, damageToDeal, true), Is.True);
Assert.That(sDamageableComponent.TotalDamage, Is.EqualTo(damageToDeal));
Assert.That(sDamageableComponent.TryGetDamage(damageGroup, out groupDamage), Is.True);
Assert.That(groupDamage, Is.EqualTo(damageToDeal));
foreach (var type in types)
{
Assert.That(sDamageableComponent.TryGetDamage(type, out typeDamage), Is.True);
Assert.That(typeDamage, Is.EqualTo(damageToDeal / types.Count()));
}
Assert.That(sDamageableComponent.TryGetDamage(type, out var damage), Is.True);
Assert.That(damage, Is.EqualTo(damageToDeal));
// Heal
Assert.That(sDamageableComponent.TryChangeDamage(damageGroup, -damageToDeal, true), Is.True);
Assert.That(sDamageableComponent.ChangeDamage(type, -damageToDeal, true), Is.True);
Assert.That(sDamageableComponent.TotalDamage, Is.Zero);
Assert.That(sDamageableComponent.TryGetDamage(damageGroup, out groupDamage), Is.True);
Assert.That(groupDamage, Is.Zero);
foreach (var type in types)
{
Assert.That(sDamageableComponent.TryGetDamage(type, out typeDamage), Is.True);
Assert.That(typeDamage, Is.Zero);
}
Assert.That(sDamageableComponent.TryGetDamage(type, out damage), Is.True);
Assert.That(damage, Is.Zero);
}
// Check that damage works properly if it is NOT perfectly divisible among group members
foreach (var damageGroup in sDamageableComponent.FullySupportedDamageGroups)
{
var types = damageGroup.DamageTypes;
// Damage
damageToDeal = types.Count() * 5 - 1;
Assert.That(sDamageableComponent.TryChangeDamage(damageGroup, damageToDeal, true), Is.True);
Assert.That(sDamageableComponent.TotalDamage, Is.EqualTo(damageToDeal));
Assert.That(sDamageableComponent.TryGetDamage(damageGroup, out groupDamage), Is.True);
Assert.That(groupDamage, Is.EqualTo(damageToDeal));
foreach (var type in types)
{
Assert.That(sDamageableComponent.TryGetDamage(type, out typeDamage), Is.True);
float targetDamage = ((float) damageToDeal) / types.Count();
Assert.That(typeDamage, Is.InRange(targetDamage - 1, targetDamage + 1));
}
// Heal
Assert.That(sDamageableComponent.TryChangeDamage(damageGroup, -damageToDeal, true), Is.True);
Assert.That(sDamageableComponent.TotalDamage, Is.Zero);
Assert.That(sDamageableComponent.TryGetDamage(damageGroup, out groupDamage), Is.True);
Assert.That(groupDamage, Is.Zero);
foreach (var type in types)
{
Assert.That(sDamageableComponent.TryGetDamage(type, out typeDamage), Is.True);
Assert.That(typeDamage, Is.Zero);
}
}
// Test that unsupported groups return false when setting/getting damage (and don't change damage)
Assert.That(sDamageableComponent.TotalDamage, Is.EqualTo(0));
foreach (var damageGroup in sPrototypeManager.EnumeratePrototypes<DamageGroupPrototype>())
{
if (sDamageableComponent.IsFullySupportedDamageGroup(damageGroup))
{
continue;
}
Assert.That(sDamageableComponent.IsApplicableDamageGroup(damageGroup), Is.False);
var types = damageGroup.DamageTypes;
damageToDeal = types.Count() * 5;
foreach (var type in types)
{
Assert.That(sDamageableComponent.IsSupportedDamageType(type), Is.False);
}
;
Assert.That(sDamageableComponent.TryChangeDamage(damageGroup, damageToDeal, true), Is.False);
Assert.That(sDamageableComponent.TryGetDamage(damageGroup, out groupDamage), Is.False);
foreach (var type in types)
{
Assert.That(sDamageableComponent.TryChangeDamage(type, damageToDeal, true), Is.False);
Assert.That(sDamageableComponent.TryGetDamage(type, out typeDamage), Is.False);
}
}
// Did damage change?
Assert.That(sDamageableComponent.TotalDamage, Is.EqualTo(0));
// Test total damage function
damageToDeal = 10;
Assert.True(sDamageableComponent.TryChangeDamage(group3, damageToDeal, true));
Assert.That(sDamageableComponent.TotalDamage, Is.EqualTo(damageToDeal));
var totalTypeDamage = 0;
foreach (var damageType in sDamageableComponent.SupportedDamageTypes)
{
Assert.True(sDamageableComponent.TryGetDamage(damageType, out typeDamage));
Assert.That(typeDamage, Is.LessThanOrEqualTo(damageToDeal));
totalTypeDamage += typeDamage;
}
Assert.That(totalTypeDamage, Is.EqualTo(damageToDeal));
// Test healing all damage
Assert.That(sDamageableComponent.TrySetAllDamage(0));
Assert.That(sDamageableComponent.TotalDamage, Is.EqualTo(0));
// Test preferential healing
damageToDeal = 12;
var damageTypes = group3.DamageTypes.ToArray();
// Deal damage
Assert.True(sDamageableComponent.TryChangeDamage(damageTypes[0], 17));
Assert.True(sDamageableComponent.TryChangeDamage(damageTypes[1], 31));
Assert.That(sDamageableComponent.TotalDamage, Is.EqualTo(48));
// Heal group damage
Assert.True(sDamageableComponent.TryChangeDamage(group3, -11));
// Check healing (3 + 9)
Assert.That(sDamageableComponent.GetDamage(damageTypes[0]), Is.EqualTo(14));
Assert.That(sDamageableComponent.GetDamage(damageTypes[1]), Is.EqualTo(23));
Assert.That(sDamageableComponent.TotalDamage, Is.EqualTo(37));
// Heal group damage
Assert.True(sDamageableComponent.TryChangeDamage(group3, -36));
// Check healing (13 + 23)
Assert.That(sDamageableComponent.GetDamage(damageTypes[0]), Is.EqualTo(1));
Assert.That(sDamageableComponent.GetDamage(damageTypes[1]), Is.EqualTo(0));
Assert.That(sDamageableComponent.TotalDamage, Is.EqualTo(1));
//Check Damage
Assert.True(sDamageableComponent.TryGetDamage(damageTypes[0], out typeDamage));
Assert.That(typeDamage, Is.LessThanOrEqualTo(damageToDeal));
});
}
private const string SharedDamageTypeId = "TestSharedDamage";
private const string UnsupportedDamageTypeId = "TestUnsupportedDamage";
private string Prototypes2 = $@"
- type: damageType
id: {SharedDamageTypeId}
- type: damageType
id: {UnsupportedDamageTypeId}
- type: damageType
id: TestDamage1
- type: damageType
id: TestDamage2
- type: damageGroup
id: {Group1Id}
damageTypes:
- {SharedDamageTypeId}
- type: damageGroup
id: {Group2Id}
damageTypes:
- {SharedDamageTypeId}
- TestDamage1
- type: damageGroup
id: {Group3Id}
damageTypes:
- {SharedDamageTypeId}
- TestDamage2
- {UnsupportedDamageTypeId}
# we want to test a container that only partially supports a group:
- type: damageContainer
id: TestPartiallySupported
supportedGroups:
- {Group2Id}
supportedTypes:
- TestDamage2
- TestDamage1
# does NOT support type {UnsupportedDamageTypeId}, and thus does not fully support group {Group3Id}
# TestDamage1 is added twice because it is also in {Group2Id}. This should not cause errors.
# create entities
- type: entity
id: {DamageableEntityId}
name: {DamageableEntityId}
components:
- type: Damageable
damageContainer: TestPartiallySupported
";
/// <summary>
/// Generalized damageable component tests.
/// </summary>
/// <remarks>
/// Test scenarios where damage types are members of more than one group, or where a component only supports a subset of a group.
/// </remarks>
[Test]
public async Task TestGeneralizedDamageableComponent()
public async Task TestDamageClassDamageAndHeal()
{
var server = StartServerDummyTicker(new ServerContentIntegrationOption
{
ExtraPrototypes = Prototypes2
ExtraPrototypes = Prototypes
});
await server.WaitIdleAsync();
var sEntityManager = server.ResolveDependency<IEntityManager>();
var sMapManager = server.ResolveDependency<IMapManager>();
var sPrototypeManager = server.ResolveDependency<IPrototypeManager>();
IEntity sDamageableEntity;
IDamageableComponent sDamageableComponent = null;
DamageGroupPrototype group1 = default!;
DamageGroupPrototype group2 = default!;
DamageGroupPrototype group3 = default!;
DamageTypePrototype SharedDamageType = default!;
DamageTypePrototype UnsupportedDamageType = default!;
await server.WaitPost(() =>
{
var mapId = sMapManager.NextMapId();
@@ -391,62 +99,99 @@ namespace Content.IntegrationTests.Tests.Damageable
sDamageableEntity = sEntityManager.SpawnEntity(DamageableEntityId, coordinates);
sDamageableComponent = sDamageableEntity.GetComponent<IDamageableComponent>();
group1 = sPrototypeManager.Index<DamageGroupPrototype>(Group1Id);
group2 = sPrototypeManager.Index<DamageGroupPrototype>(Group2Id);
group3 = sPrototypeManager.Index<DamageGroupPrototype>(Group3Id);
SharedDamageType = sPrototypeManager.Index<DamageTypePrototype>(SharedDamageTypeId);
UnsupportedDamageType = sPrototypeManager.Index<DamageTypePrototype>(UnsupportedDamageTypeId);
});
await server.WaitRunTicks(5);
await server.WaitAssertion(() =>
{
// All damage types should be applicable
Assert.That(sDamageableComponent.IsApplicableDamageGroup(group1), Is.True);
Assert.That(sDamageableComponent.IsApplicableDamageGroup(group2), Is.True);
Assert.That(sDamageableComponent.IsApplicableDamageGroup(group3), Is.True);
Assert.That(sDamageableComponent.TotalDamage, Is.EqualTo(0));
// But not all should be fully supported
Assert.That(sDamageableComponent.IsFullySupportedDamageGroup(group1), Is.True);
Assert.That(sDamageableComponent.IsFullySupportedDamageGroup(group2), Is.True);
Assert.That(sDamageableComponent.IsFullySupportedDamageGroup(group3), Is.False);
foreach (var @class in Enum.GetValues<DamageClass>())
{
Assert.That(sDamageableComponent.SupportsDamageClass(@class));
// Check that the correct damage types are supported
Assert.That(sDamageableComponent.IsSupportedDamageType(SharedDamageType), Is.True);
var types = @class.ToTypes();
// Check that if we deal damage using a type appearing in multiple groups, nothing goes wrong.
var damage = 12;
Assert.That(sDamageableComponent.TryChangeDamage(SharedDamageType, damage), Is.True);
Assert.That(sDamageableComponent.GetDamage(SharedDamageType), Is.EqualTo(damage));
Assert.That(sDamageableComponent.GetDamage(group1), Is.EqualTo(damage));
Assert.That(sDamageableComponent.GetDamage(group2), Is.EqualTo(damage));
Assert.That(sDamageableComponent.GetDamage(group3), Is.EqualTo(damage));
Assert.That(sDamageableComponent.TotalDamage, Is.EqualTo(damage));
foreach (var type in types)
{
Assert.That(sDamageableComponent.SupportsDamageType(type));
}
// Check that if we deal damage using a group that is not fully supported, the damage is reduced
// Note that if damage2 were not neatly divisible by 3, the actual damage reduction would be subject to integer rounding.
// How much exactly the damage gets reduced then would depend on the order that the groups were defined in the yaml file
// Here we deal 9 damage. It should apply 3 damage to each type, but one type is ignored, resulting in 6 total damage.
// However, the damage in group2 and group3 only changes because of one type that overlaps, so they only change by 3
Assert.That(sDamageableComponent.TryChangeDamage(group3, 9), Is.True);
Assert.That(sDamageableComponent.GetDamage(group1), Is.EqualTo(damage + 3));
Assert.That(sDamageableComponent.GetDamage(group2), Is.EqualTo(damage + 3));
Assert.That(sDamageableComponent.GetDamage(group3), Is.EqualTo(damage + 6));
Assert.That(sDamageableComponent.TotalDamage, Is.EqualTo(damage + 6));
var damageToDeal = types.Count * 5;
// Now we check that when healing, no damage is wasted.
// Because SharedDamageType has the most damage in group3 (15 vs 3), it will be healed more than the other.
// Expect that, up to integer rounding, one is healed 5* more than the other.
// We will use a number that does not divide nicely, there will be some integer rounding.
Assert.That(sDamageableComponent.TryChangeDamage(group3, -7), Is.True);
Assert.That(sDamageableComponent.GetDamage(group1), Is.EqualTo(damage + 3 - 5));
Assert.That(sDamageableComponent.GetDamage(group2), Is.EqualTo(damage + 3 - 5));
Assert.That(sDamageableComponent.GetDamage(group3), Is.EqualTo(damage + 6 - 7));
Assert.That(sDamageableComponent.TotalDamage, Is.EqualTo(damage + 6 - 7));
// Damage
Assert.That(sDamageableComponent.ChangeDamage(@class, damageToDeal, true), Is.True);
Assert.That(sDamageableComponent.TotalDamage, Is.EqualTo(damageToDeal));
Assert.That(sDamageableComponent.TryGetDamage(@class, out var classDamage), Is.True);
Assert.That(classDamage, Is.EqualTo(damageToDeal));
foreach (var type in types)
{
Assert.That(sDamageableComponent.TryGetDamage(type, out var typeDamage), Is.True);
Assert.That(typeDamage, Is.EqualTo(damageToDeal / types.Count));
}
// Heal
Assert.That(sDamageableComponent.ChangeDamage(@class, -damageToDeal, true), Is.True);
Assert.That(sDamageableComponent.TotalDamage, Is.Zero);
Assert.That(sDamageableComponent.TryGetDamage(@class, out classDamage), Is.True);
Assert.That(classDamage, Is.Zero);
foreach (var type in types)
{
Assert.That(sDamageableComponent.TryGetDamage(type, out var typeDamage), Is.True);
Assert.That(typeDamage, Is.Zero);
}
}
});
}
[Test]
public async Task TotalDamageTest()
{
var server = StartServerDummyTicker(new ServerContentIntegrationOption
{
ExtraPrototypes = Prototypes
});
await server.WaitIdleAsync();
var sEntityManager = server.ResolveDependency<IEntityManager>();
var sMapManager = server.ResolveDependency<IMapManager>();
IEntity sDamageableEntity;
IDamageableComponent sDamageableComponent = null;
await server.WaitPost(() =>
{
var mapId = sMapManager.NextMapId();
var coordinates = new MapCoordinates(0, 0, mapId);
sMapManager.CreateMap(mapId);
sDamageableEntity = sEntityManager.SpawnEntity(DamageableEntityId, coordinates);
sDamageableComponent = sDamageableEntity.GetComponent<IDamageableComponent>();
});
await server.WaitAssertion(() =>
{
var damageType = DamageClass.Brute;
var damage = 10;
Assert.True(sDamageableComponent.ChangeDamage(DamageClass.Brute, damage, true));
Assert.That(sDamageableComponent.TotalDamage, Is.EqualTo(10));
var totalTypeDamage = 0;
foreach (var type in damageType.ToTypes())
{
Assert.True(sDamageableComponent.TryGetDamage(type, out var typeDamage));
Assert.That(typeDamage, Is.LessThanOrEqualTo(damage));
totalTypeDamage += typeDamage;
}
Assert.That(totalTypeDamage, Is.EqualTo(damage));
});
}
}

View File

@@ -1,4 +1,4 @@
using System.Threading.Tasks;
using System.Threading.Tasks;
using Content.Server.Destructible.Thresholds.Triggers;
using Content.Shared.Damage;
using Content.Shared.Damage.Components;
@@ -6,15 +6,14 @@ 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
{
[TestFixture]
[TestOf(typeof(DamageGroupTrigger))]
[TestOf(typeof(DamageClassTrigger))]
[TestOf(typeof(AndTrigger))]
public class DestructibleDamageGroupTest : ContentIntegrationTest
public class DestructibleDamageClassTest : ContentIntegrationTest
{
[Test]
public async Task AndTest()
@@ -32,7 +31,6 @@ namespace Content.IntegrationTests.Tests.Destructible
var sEntityManager = server.ResolveDependency<IEntityManager>();
var sMapManager = server.ResolveDependency<IMapManager>();
var sPrototypeManager = server.ResolveDependency<IPrototypeManager>();
IEntity sDestructibleEntity;
IDamageableComponent sDamageableComponent = null;
@@ -44,7 +42,7 @@ namespace Content.IntegrationTests.Tests.Destructible
var coordinates = new MapCoordinates(0, 0, mapId);
sMapManager.CreateMap(mapId);
sDestructibleEntity = sEntityManager.SpawnEntity(DestructibleDamageGroupEntityId, coordinates);
sDestructibleEntity = sEntityManager.SpawnEntity(DestructibleDamageClassEntityId, coordinates);
sDamageableComponent = sDestructibleEntity.GetComponent<IDamageableComponent>();
sThresholdListenerComponent = sDestructibleEntity.GetComponent<TestThresholdListenerComponent>();
});
@@ -58,23 +56,20 @@ namespace Content.IntegrationTests.Tests.Destructible
await server.WaitAssertion(() =>
{
var bruteDamageGroup = sPrototypeManager.Index<DamageGroupPrototype>("TestBrute");
var burnDamageGroup = sPrototypeManager.Index<DamageGroupPrototype>("TestBurn");
// Raise brute damage to 5
Assert.True(sDamageableComponent.TryChangeDamage(bruteDamageGroup, 5, true));
Assert.True(sDamageableComponent.ChangeDamage(DamageClass.Brute, 5, true));
// No thresholds reached yet, the earliest one is at 10 damage
Assert.IsEmpty(sThresholdListenerComponent.ThresholdsReached);
// Raise brute damage to 10
Assert.True(sDamageableComponent.TryChangeDamage(bruteDamageGroup, 5, true));
Assert.True(sDamageableComponent.ChangeDamage(DamageClass.Brute, 5, true));
// No threshold reached, burn needs to be 10 as well
Assert.IsEmpty(sThresholdListenerComponent.ThresholdsReached);
// Raise burn damage to 10
Assert.True(sDamageableComponent.TryChangeDamage(burnDamageGroup, 10, true));
Assert.True(sDamageableComponent.ChangeDamage(DamageClass.Burn, 10, true));
// One threshold reached, brute 10 + burn 10
Assert.That(sThresholdListenerComponent.ThresholdsReached.Count, Is.EqualTo(1));
@@ -91,52 +86,52 @@ namespace Content.IntegrationTests.Tests.Destructible
var trigger = (AndTrigger) threshold.Trigger;
Assert.IsInstanceOf<DamageGroupTrigger>(trigger.Triggers[0]);
Assert.IsInstanceOf<DamageGroupTrigger>(trigger.Triggers[1]);
Assert.IsInstanceOf<DamageClassTrigger>(trigger.Triggers[0]);
Assert.IsInstanceOf<DamageClassTrigger>(trigger.Triggers[1]);
sThresholdListenerComponent.ThresholdsReached.Clear();
// Raise brute damage to 20
Assert.True(sDamageableComponent.TryChangeDamage(bruteDamageGroup, 10, true));
Assert.True(sDamageableComponent.ChangeDamage(DamageClass.Brute, 10, true));
// No new thresholds reached
Assert.IsEmpty(sThresholdListenerComponent.ThresholdsReached);
// Raise burn damage to 20
Assert.True(sDamageableComponent.TryChangeDamage(burnDamageGroup, 10, true));
Assert.True(sDamageableComponent.ChangeDamage(DamageClass.Burn, 10, true));
// No new thresholds reached
Assert.IsEmpty(sThresholdListenerComponent.ThresholdsReached);
// Lower brute damage to 0
Assert.True(sDamageableComponent.TryChangeDamage(bruteDamageGroup, -20, true));
Assert.True(sDamageableComponent.ChangeDamage(DamageClass.Brute, -20, true));
// No new thresholds reached, healing should not trigger it
Assert.IsEmpty(sThresholdListenerComponent.ThresholdsReached);
// Raise brute damage back up to 10
Assert.True(sDamageableComponent.TryChangeDamage(bruteDamageGroup, 10, true));
Assert.True(sDamageableComponent.ChangeDamage(DamageClass.Brute, 10, true));
// 10 brute + 10 burn threshold reached, brute was healed and brought back to its threshold amount and burn stayed the same
// 10 brute + 10 burn threshold reached, brute was healed and brought back to its threshold amount and slash stayed the same
Assert.That(sThresholdListenerComponent.ThresholdsReached.Count, Is.EqualTo(1));
sThresholdListenerComponent.ThresholdsReached.Clear();
// Heal both classes of damage to 0
Assert.True(sDamageableComponent.TryChangeDamage(bruteDamageGroup, -10, true));
Assert.True(sDamageableComponent.TryChangeDamage(burnDamageGroup, -20, true));
Assert.True(sDamageableComponent.ChangeDamage(DamageClass.Brute, -10, true));
Assert.True(sDamageableComponent.ChangeDamage(DamageClass.Burn, -20, true));
// No new thresholds reached, healing should not trigger it
Assert.IsEmpty(sThresholdListenerComponent.ThresholdsReached);
// Raise brute damage to 10
Assert.True(sDamageableComponent.TryChangeDamage(bruteDamageGroup, 10, true));
Assert.True(sDamageableComponent.ChangeDamage(DamageClass.Brute, 10, true));
// No new thresholds reached
Assert.IsEmpty(sThresholdListenerComponent.ThresholdsReached);
// Raise burn damage to 10
Assert.True(sDamageableComponent.TryChangeDamage(burnDamageGroup, 10, true));
Assert.True(sDamageableComponent.ChangeDamage(DamageClass.Burn, 10, true));
// Both classes of damage were healed and then raised again, the threshold should have been reached as triggers once is default false
Assert.That(sThresholdListenerComponent.ThresholdsReached.Count, Is.EqualTo(1));
@@ -153,8 +148,8 @@ namespace Content.IntegrationTests.Tests.Destructible
trigger = (AndTrigger) threshold.Trigger;
Assert.IsInstanceOf<DamageGroupTrigger>(trigger.Triggers[0]);
Assert.IsInstanceOf<DamageGroupTrigger>(trigger.Triggers[1]);
Assert.IsInstanceOf<DamageClassTrigger>(trigger.Triggers[0]);
Assert.IsInstanceOf<DamageClassTrigger>(trigger.Triggers[1]);
sThresholdListenerComponent.ThresholdsReached.Clear();
@@ -162,20 +157,20 @@ namespace Content.IntegrationTests.Tests.Destructible
threshold.TriggersOnce = true;
// Heal brute and burn back to 0
Assert.True(sDamageableComponent.TryChangeDamage(bruteDamageGroup, -10, true));
Assert.True(sDamageableComponent.TryChangeDamage(burnDamageGroup, -10, true));
Assert.True(sDamageableComponent.ChangeDamage(DamageClass.Brute, -10, true));
Assert.True(sDamageableComponent.ChangeDamage(DamageClass.Burn, -10, true));
// No new thresholds reached from healing
Assert.IsEmpty(sThresholdListenerComponent.ThresholdsReached);
// Raise brute damage to 10
Assert.True(sDamageableComponent.TryChangeDamage(bruteDamageGroup, 10, true));
Assert.True(sDamageableComponent.ChangeDamage(DamageClass.Brute, 10, true));
// No new thresholds reached
Assert.IsEmpty(sThresholdListenerComponent.ThresholdsReached);
// Raise burn damage to 10
Assert.True(sDamageableComponent.TryChangeDamage(burnDamageGroup, 10, true));
Assert.True(sDamageableComponent.ChangeDamage(DamageClass.Burn, 10, true));
// No new thresholds reached as triggers once is set to true and it already triggered before
Assert.IsEmpty(sThresholdListenerComponent.ThresholdsReached);

View File

@@ -1,4 +1,4 @@
using System.Threading.Tasks;
using System.Threading.Tasks;
using Content.Server.Destructible.Thresholds.Triggers;
using Content.Shared.Damage;
using Content.Shared.Damage.Components;
@@ -6,7 +6,6 @@ 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
@@ -57,23 +56,20 @@ namespace Content.IntegrationTests.Tests.Destructible
await server.WaitAssertion(() =>
{
var bluntDamageType = IoCManager.Resolve<IPrototypeManager>().Index<DamageTypePrototype>("TestBlunt");
var slashDamageType = IoCManager.Resolve<IPrototypeManager>().Index<DamageTypePrototype>("TestSlash");
// Raise blunt damage to 5
Assert.True(sDamageableComponent.TryChangeDamage(bluntDamageType, 5, true));
Assert.True(sDamageableComponent.ChangeDamage(DamageType.Blunt, 5, true));
// No thresholds reached yet, the earliest one is at 10 damage
Assert.IsEmpty(sThresholdListenerComponent.ThresholdsReached);
// Raise blunt damage to 10
Assert.True(sDamageableComponent.TryChangeDamage(bluntDamageType, 5, true));
Assert.True(sDamageableComponent.ChangeDamage(DamageType.Blunt, 5, true));
// No threshold reached, slash needs to be 10 as well
Assert.IsEmpty(sThresholdListenerComponent.ThresholdsReached);
// Raise slash damage to 10
Assert.True(sDamageableComponent.TryChangeDamage(slashDamageType, 10, true));
Assert.True(sDamageableComponent.ChangeDamage(DamageType.Slash, 10, true));
// One threshold reached, blunt 10 + slash 10
Assert.That(sThresholdListenerComponent.ThresholdsReached.Count, Is.EqualTo(1));
@@ -96,25 +92,25 @@ namespace Content.IntegrationTests.Tests.Destructible
sThresholdListenerComponent.ThresholdsReached.Clear();
// Raise blunt damage to 20
Assert.True(sDamageableComponent.TryChangeDamage(bluntDamageType, 10, true));
Assert.True(sDamageableComponent.ChangeDamage(DamageType.Blunt, 10, true));
// No new thresholds reached
Assert.IsEmpty(sThresholdListenerComponent.ThresholdsReached);
// Raise slash damage to 20
Assert.True(sDamageableComponent.TryChangeDamage(slashDamageType, 10, true));
Assert.True(sDamageableComponent.ChangeDamage(DamageType.Slash, 10, true));
// No new thresholds reached
Assert.IsEmpty(sThresholdListenerComponent.ThresholdsReached);
// Lower blunt damage to 0
Assert.True(sDamageableComponent.TryChangeDamage(bluntDamageType, -20, true));
Assert.True(sDamageableComponent.ChangeDamage(DamageType.Blunt, -20, true));
// No new thresholds reached, healing should not trigger it
Assert.IsEmpty(sThresholdListenerComponent.ThresholdsReached);
// Raise blunt damage back up to 10
Assert.True(sDamageableComponent.TryChangeDamage(bluntDamageType, 10, true));
Assert.True(sDamageableComponent.ChangeDamage(DamageType.Blunt, 10, true));
// 10 blunt + 10 slash threshold reached, blunt was healed and brought back to its threshold amount and slash stayed the same
Assert.That(sThresholdListenerComponent.ThresholdsReached.Count, Is.EqualTo(1));
@@ -122,20 +118,20 @@ namespace Content.IntegrationTests.Tests.Destructible
sThresholdListenerComponent.ThresholdsReached.Clear();
// Heal both types of damage to 0
Assert.True(sDamageableComponent.TryChangeDamage(bluntDamageType, -10, true));
Assert.True(sDamageableComponent.TryChangeDamage(slashDamageType, -20, true));
Assert.True(sDamageableComponent.ChangeDamage(DamageType.Blunt, -10, true));
Assert.True(sDamageableComponent.ChangeDamage(DamageType.Slash, -20, true));
// No new thresholds reached, healing should not trigger it
Assert.IsEmpty(sThresholdListenerComponent.ThresholdsReached);
// Raise blunt damage to 10
Assert.True(sDamageableComponent.TryChangeDamage(bluntDamageType, 10, true));
Assert.True(sDamageableComponent.ChangeDamage(DamageType.Blunt, 10, true));
// No new thresholds reached
Assert.IsEmpty(sThresholdListenerComponent.ThresholdsReached);
// Raise slash damage to 10
Assert.True(sDamageableComponent.TryChangeDamage(slashDamageType, 10, true));
Assert.True(sDamageableComponent.ChangeDamage(DamageType.Slash, 10, true));
// Both types of damage were healed and then raised again, the threshold should have been reached as triggers once is default false
Assert.That(sThresholdListenerComponent.ThresholdsReached.Count, Is.EqualTo(1));
@@ -161,20 +157,20 @@ namespace Content.IntegrationTests.Tests.Destructible
threshold.TriggersOnce = true;
// Heal blunt and slash back to 0
Assert.True(sDamageableComponent.TryChangeDamage(bluntDamageType, -10, true));
Assert.True(sDamageableComponent.TryChangeDamage(slashDamageType, -10, true));
Assert.True(sDamageableComponent.ChangeDamage(DamageType.Blunt, -10, true));
Assert.True(sDamageableComponent.ChangeDamage(DamageType.Slash, -10, true));
// No new thresholds reached from healing
Assert.IsEmpty(sThresholdListenerComponent.ThresholdsReached);
// Raise blunt damage to 10
Assert.True(sDamageableComponent.TryChangeDamage(bluntDamageType, 10, true));
Assert.True(sDamageableComponent.ChangeDamage(DamageType.Blunt, 10, true));
// No new thresholds reached
Assert.IsEmpty(sThresholdListenerComponent.ThresholdsReached);
// Raise slash damage to 10
Assert.True(sDamageableComponent.TryChangeDamage(slashDamageType, 10, true));
Assert.True(sDamageableComponent.ChangeDamage(DamageType.Slash, 10, true));
// No new thresholds reached as triggers once is set to true and it already triggered before
Assert.IsEmpty(sThresholdListenerComponent.ThresholdsReached);

View File

@@ -1,4 +1,4 @@
using System.Linq;
using System.Linq;
using System.Threading.Tasks;
using Content.Server.Destructible.Thresholds;
using Content.Server.Destructible.Thresholds.Behaviors;
@@ -8,7 +8,6 @@ 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
@@ -31,7 +30,6 @@ namespace Content.IntegrationTests.Tests.Destructible
var sEntityManager = server.ResolveDependency<IEntityManager>();
var sMapManager = server.ResolveDependency<IMapManager>();
var sPrototypeManager = server.ResolveDependency<IPrototypeManager>();
IEntity sDestructibleEntity = null;
IDamageableComponent sDamageableComponent = null;
@@ -51,11 +49,10 @@ namespace Content.IntegrationTests.Tests.Destructible
await server.WaitAssertion(() =>
{
var coordinates = sDestructibleEntity.Transform.Coordinates;
var bruteDamageGroup = sPrototypeManager.Index<DamageGroupPrototype>("TestBrute");
Assert.DoesNotThrow(() =>
{
Assert.True(sDamageableComponent.TryChangeDamage(bruteDamageGroup, 50, true));
Assert.True(sDamageableComponent.ChangeDamage(DamageClass.Brute, 50, true));
});
Assert.That(sThresholdListenerComponent.ThresholdsReached.Count, Is.EqualTo(1));

View File

@@ -6,93 +6,9 @@ namespace Content.IntegrationTests.Tests.Destructible
public const string DestructibleEntityId = "DestructibleTestsDestructibleEntity";
public const string DestructibleDestructionEntityId = "DestructibleTestsDestructibleDestructionEntity";
public const string DestructibleDamageTypeEntityId = "DestructibleTestsDestructibleDamageTypeEntity";
public const string DestructibleDamageGroupEntityId = "DestructibleTestsDestructibleDamageGroupEntity";
public const string DestructibleDamageClassEntityId = "DestructibleTestsDestructibleDamageClassEntity";
public static readonly string Prototypes = $@"
- type: damageType
id: TestBlunt
- type: damageType
id: TestSlash
- type: damageType
id: TestPiercing
- type: damageType
id: TestHeat
- type: damageType
id: TestShock
- type: damageType
id: TestCold
- type: damageType
id: TestPoison
- type: damageType
id: TestRadiation
- type: damageType
id: TestAsphyxiation
- type: damageType
id: TestBloodloss
- type: damageType
id: TestCellular
- type: damageGroup
id: TestBrute
damageTypes:
- TestBlunt
- TestSlash
- TestPiercing
- type: damageGroup
id: TestBurn
damageTypes:
- TestHeat
- TestShock
- TestCold
- type: damageGroup
id: TestAirloss
damageTypes:
- TestAsphyxiation
- TestBloodloss
- type: damageGroup
id: TestToxin
damageTypes:
- TestPoison
- TestRadiation
- type: damageGroup
id: TestGenetic
damageTypes:
- TestCellular
- type: damageContainer
id: TestAllDamageContainer
supportAll: true
- type: damageContainer
id: TestBiologicalDamageContainer
supportedGroups:
- TestBrute
- TestBurn
- TestToxin
- TestAirloss
- TestGenetic
- type: damageContainer
id: TestMetallicDamageContainer
supportedGroups:
- TestBrute
- TestBurn
- type: entity
id: {SpawnedEntityId}
name: {SpawnedEntityId}
@@ -102,7 +18,6 @@ namespace Content.IntegrationTests.Tests.Destructible
name: {DestructibleEntityId}
components:
- type: Damageable
damageContainer: TestMetallicDamageContainer
- type: Destructible
thresholds:
- trigger:
@@ -131,7 +46,6 @@ namespace Content.IntegrationTests.Tests.Destructible
name: {DestructibleDestructionEntityId}
components:
- type: Damageable
damageContainer: TestMetallicDamageContainer
- type: Destructible
thresholds:
- trigger:
@@ -155,36 +69,34 @@ namespace Content.IntegrationTests.Tests.Destructible
name: {DestructibleDamageTypeEntityId}
components:
- type: Damageable
damageContainer: TestMetallicDamageContainer
- type: Destructible
thresholds:
- trigger:
!type:AndTrigger
triggers:
- !type:DamageTypeTrigger
damageType: TestBlunt
type: Blunt
damage: 10
- !type:DamageTypeTrigger
damageType: TestSlash
type: Slash
damage: 10
- type: TestThresholdListener
- type: entity
id: {DestructibleDamageGroupEntityId}
name: {DestructibleDamageGroupEntityId}
id: {DestructibleDamageClassEntityId}
name: {DestructibleDamageClassEntityId}
components:
- type: Damageable
damageContainer: TestMetallicDamageContainer
- type: Destructible
thresholds:
- trigger:
!type:AndTrigger
triggers:
- !type:DamageGroupTrigger
damageGroup: TestBrute
- !type:DamageClassTrigger
class: Brute
damage: 10
- !type:DamageGroupTrigger
damageGroup: TestBurn
- !type:DamageClassTrigger
class: Burn
damage: 10
- type: TestThresholdListener";
}

View File

@@ -10,7 +10,6 @@ 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
@@ -36,7 +35,6 @@ namespace Content.IntegrationTests.Tests.Destructible
var sEntityManager = server.ResolveDependency<IEntityManager>();
var sMapManager = server.ResolveDependency<IMapManager>();
var sPrototypeManager = server.ResolveDependency<IPrototypeManager>();
IEntity sDestructibleEntity;
IDamageableComponent sDamageableComponent = null;
@@ -64,14 +62,12 @@ namespace Content.IntegrationTests.Tests.Destructible
await server.WaitAssertion(() =>
{
var bluntDamageType = sPrototypeManager.Index<DamageTypePrototype>("TestBlunt");
Assert.True(sDamageableComponent.TryChangeDamage(bluntDamageType, 10, true));
Assert.True(sDamageableComponent.ChangeDamage(DamageType.Blunt, 10, true));
// No thresholds reached yet, the earliest one is at 20 damage
Assert.IsEmpty(sThresholdListenerComponent.ThresholdsReached);
Assert.True(sDamageableComponent.TryChangeDamage(bluntDamageType, 10, true));
Assert.True(sDamageableComponent.ChangeDamage(DamageType.Blunt, 10, true));
// Only one threshold reached, 20
Assert.That(sThresholdListenerComponent.ThresholdsReached.Count, Is.EqualTo(1));
@@ -87,7 +83,7 @@ namespace Content.IntegrationTests.Tests.Destructible
sThresholdListenerComponent.ThresholdsReached.Clear();
Assert.True(sDamageableComponent.TryChangeDamage(bluntDamageType, 30, true));
Assert.True(sDamageableComponent.ChangeDamage(DamageType.Blunt, 30, true));
// One threshold reached, 50, since 20 already triggered before and it has not been healed below that amount
Assert.That(sThresholdListenerComponent.ThresholdsReached.Count, Is.EqualTo(1));
@@ -116,16 +112,16 @@ namespace Content.IntegrationTests.Tests.Destructible
sThresholdListenerComponent.ThresholdsReached.Clear();
// Damage for 50 again, up to 100 now
Assert.True(sDamageableComponent.TryChangeDamage(bluntDamageType, 50, true));
Assert.True(sDamageableComponent.ChangeDamage(DamageType.Blunt, 50, true));
// No thresholds reached as they weren't healed below the trigger amount
Assert.IsEmpty(sThresholdListenerComponent.ThresholdsReached);
// Set damage to 0
sDamageableComponent.TrySetAllDamage(0);
// Heal down to 0
sDamageableComponent.Heal();
// Damage for 100, up to 100
Assert.True(sDamageableComponent.TryChangeDamage(bluntDamageType, 100, true));
Assert.True(sDamageableComponent.ChangeDamage(DamageType.Blunt, 100, true));
// Two thresholds reached as damage increased past the previous, 20 and 50
Assert.That(sThresholdListenerComponent.ThresholdsReached.Count, Is.EqualTo(2));
@@ -133,25 +129,25 @@ namespace Content.IntegrationTests.Tests.Destructible
sThresholdListenerComponent.ThresholdsReached.Clear();
// Heal the entity for 40 damage, down to 60
sDamageableComponent.TryChangeDamage(bluntDamageType, -40, true);
sDamageableComponent.ChangeDamage(DamageType.Blunt, -40, true);
// Thresholds don't work backwards
Assert.That(sThresholdListenerComponent.ThresholdsReached, Is.Empty);
// Damage for 10, up to 70
sDamageableComponent.TryChangeDamage(bluntDamageType, 10, true);
sDamageableComponent.ChangeDamage(DamageType.Blunt, 10, true);
// Not enough healing to de-trigger a threshold
Assert.That(sThresholdListenerComponent.ThresholdsReached, Is.Empty);
// Heal by 30, down to 40
sDamageableComponent.TryChangeDamage(bluntDamageType, -30, true);
sDamageableComponent.ChangeDamage(DamageType.Blunt, -30, true);
// Thresholds don't work backwards
Assert.That(sThresholdListenerComponent.ThresholdsReached, Is.Empty);
// Damage up to 50 again
sDamageableComponent.TryChangeDamage(bluntDamageType, 10, true);
sDamageableComponent.ChangeDamage(DamageType.Blunt, 10, true);
// The 50 threshold should have triggered again, after being healed
Assert.That(sThresholdListenerComponent.ThresholdsReached.Count, Is.EqualTo(1));
@@ -181,10 +177,10 @@ namespace Content.IntegrationTests.Tests.Destructible
sThresholdListenerComponent.ThresholdsReached.Clear();
// Heal all damage
sDamageableComponent.TrySetAllDamage(0);
sDamageableComponent.Heal();
// Damage up to 50
sDamageableComponent.TryChangeDamage(bluntDamageType, 50, true);
sDamageableComponent.ChangeDamage(DamageType.Blunt, 50, true);
// Check that the total damage matches
Assert.That(sDamageableComponent.TotalDamage, Is.EqualTo(50));
@@ -232,7 +228,7 @@ namespace Content.IntegrationTests.Tests.Destructible
sThresholdListenerComponent.ThresholdsReached.Clear();
// Heal the entity completely
sDamageableComponent.TrySetAllDamage(0);
sDamageableComponent.Heal();
// Check that the entity has 0 damage
Assert.That(sDamageableComponent.TotalDamage, Is.EqualTo(0));
@@ -245,7 +241,7 @@ namespace Content.IntegrationTests.Tests.Destructible
}
// Damage the entity up to 50 damage again
sDamageableComponent.TryChangeDamage(bluntDamageType, 50, true);
sDamageableComponent.ChangeDamage(DamageType.Blunt, 50, true);
// Check that the total damage matches
Assert.That(sDamageableComponent.TotalDamage, Is.EqualTo(50));