Damageable Refactor 3: Revenge of the Instamerge (#4524)

* Add DamageType And DamageGroup Prototypes

* Remove DamageTypePrototype Field "name" as its redundant

* Change I/DamageableComponent to use prototypes

* Update DamageContainer, ReisistanceSet and DamageChangeData

* Change Barotrauma Component to use DamageType from DamageSystem

* Update AsteroidRockComponent

* update some more components

* update some more components

* Fix m o r e c o m p o n e n t s and their damageType

* all thats left is bug/missing node hunting then verification.

* push changes

* update submodule

* Merge fixes

* push DGP for example

* update damagecomponent across shared and server

* fix a few bugs

* Fix Merge issues

* Refactor damageablecomponent update (#4406)

* Fixing merge.

I messed up part of the merge. this should fix it?

* Barotrauma now uses prototypeManager

As System.Runtime.CompilerServices also has a [Dependency], I think I had to use the full path [Robust.Shared.IoC.Dependency]

* FlammableComponent now uses prototypeManager

* SuicideCommands now use prototypeManager

* Changed  many files to use prototypeManager to resolve damaege prototypes

Yeah.... prototype references would be very nice. maybe this was all a waste of time.

* Grouping prototypeManager.Index with datafield definitions

This will make it easier to eventually add prototype references

* removed unused variable

* Moved lines around.

Lines now consistent with other TODO PROTOTYPE blocks

* Grouping more prototypeManager.Index with datafield definitions

* Removed unnecessary code

* Added more prototypeManager indexing

These ones weren't pointed out by DrSmug. But I think this is all of them? That or my regex is shit.

* Remove redundant _damage field

* Remove redundant _currentTemperature

* Moved variables down

* Added prototypeManager indexing to TemperatureComponent

* WeaponComponent/System now use ProtptypeManager

And as far as I can tell damageType is required, and therefore should never have been null anyway?

* Make ranged weapon clumsy fire effects datafields

And yes, the order in which the clumsy effects occur is very important.

* Made damage on vital body part loss a datafield

* Renamed several damageGroup variables to group

* Capitalised DamageListToDamageGroup

* Make radiation and explosion damage types datafields

* Renamed _supportedDamageGroupIDs and _supportedDamageTypeIDs

* Fixed mistakes

Frogot to remove prototypeManager index DamageTypeTrigger, and wrong variable visibility in TemperatureComponent

* Added necessary code

Is something tragically wrong?

* MeleeWeapon damageType is not actually required

* Fixing someone else's mistakes

A search comes up with nothing in the yaml files, and its not a required field. So no one uses it? Hopefully?

* Changed and renamed damageTypeToDamageGroup

Previously would incorrectly return the total container damage for each group, not the total in the group

* renaming varitables

* Renamed variable DamageClasses

* Added dictionary converting functions

* Added ID-keyed dictionaries

* Making MedicalScanner use ID dictionaries, instead of prototype dictionaries

Oh oh no. I've been able to avoid UI & networking up until now. I have no Idea what I am doing.

* Fix Medical Scanner

* Summary (required)

The joke here is that this fixes the empty summary.

* Removed DamageableComponent.GetDamageGroup/Type

* Renamed "damage classes" to groups.

* Update ChangeDamage description

* Replaced Heal() with SettAllDamage()

Heal() was just a confusing name,

* More Class -> Group renaming

* Replace Class with Group in yaml files

DamageClassTrigger does not appear in any yaml? only in testing?
DamageTypeTrigger appears only in human.yaml?
HealthChangeMetabolism is Mostly in medicine.yml and one in soad.yaml

Why the hell is Cola metabolizable by plants? Who is pouring cola on their plants!?!?

* Fix _prototypeManager being null errors.

* Changing comments

Where are the prototype references

* MetabolismComponent doesn't give free heals anymore.

* Changes HungerComponent healing.

Previously I think it would actually damage you.  Only did this as I though it was causing the fast healing. Turns out that was just BREATHING.

* Generalised a function in DamageableComponent and moved it to DamageGroupPrototype

previously DamageTypesDictToDamageGroupDict was private to DamageableComponent, but was also quite general (nearly a static function). As this sort of function may be needed by other components using DamageGroupPrototypes in the future, I moved it there as a static function instead.

* modified DamageableComponent.ChangeDamage()

ignoreResistances was renamed to ignoreDamageResistances to make it clearer that it had no effect on healing.

Now uses default argument for ignoreDamageResistances, so when healing you are not forced to specify an argument that does nothing.

Also made some general changes to ignoreResistances()

* Changed class->group and added missing damage type functionality to DamageContainerPrototypes

* Added Comments to damage.yml

* Misc Changes to DamageableComponent

* Differentiated between group support and group applicability

So far, every damage type is a member of one, and only one, damage group. So this change has no real effect so far.

* Added proposed alternative to ChangeDamage()

* fixed error in DamageGroupPrototype

* Changes to DamageableComponent

Lots of changes to comments.
Some variables renamed in IDamageableComponent and DamageableComponent (also required renaming in other files)

Some minor logic changes, mostly for incorrect descirptions of boolean return values.

Also further differentiating between ApplicableGroups and SupportedGroups... if that will ever even matter

* Generalised MedicalScannerComponent

If needed, can print miscellaneous damage types now

* Fixed HealthChangeMetabolism bug

* Changing Comments around

* More questions

* Made Barotrauma default to blunt

* Fix RejuvenateTest.cs

* Comments

* Coments and variable names

* fix some master-merge issues

* Removed redundant fields

* Misc changes for readbility of PR diff

* Consistent naming

* Fixed atmos damage bug

* Removed Ranting

* Fixed Hunger after I broke it

* Fixing Bugs

* Removed stupid question

* Removed more stupid questions

* Fix potential null errors.

* Made boolean return values consistent

Also renamed several functions, to make it clear they return a bool. Docs were also updated.

* Removed IoCManager.InjectDependencies()

* Removed unnecessary 'suffocation' prefix

* Fixed Spelling

Also removed accidentally left in logger call

* Fixed Medical Scanner

* Apply suggestions from code review

Co-authored-by: ShadowCommander <10494922+ShadowCommander@users.noreply.github.com>

* Changing comments and whitespaces

* Made damage thresholds trigger  datafields required

* So many typos

* Changes to DamageableComponents

Changed documentation in IDamageableComponent

Made testing code more readable.

Relabelled groups as 'Applicable' either 'Fully Supported'

* Removed function and degeneralised

* Update DamageableComponent.cs

Removed unused parameters
Fixed Networking

* Added IoCManager.Resolve

* Now using alternative TryChangeDamage()

* Removed function from DamageGroupPrototype

* Removing comments

* Remove bad if statement?

* Fix damageChanged ordering

* Fix hurt server command

* Changed //TODO PROTOTYPE blocks

Now use PrototypeManager differently. Wherever possible, only retrieve the prototype once.

Also added default damage types to some more datafields

* Update Content.Shared/Damage/Container/DamageContainerPrototype.cs

Co-authored-by: ShadowCommander <10494922+ShadowCommander@users.noreply.github.com>

* renamed _accumulatedHealth -> _accumulatedDamage and added TODOs

* Another class-> group

* Fix bug in generalisation of damage container prototypes

* Addes Tests to make sure I dont keep adding bugs to my own code.

* Changed Return values when setting

* Removed unused class

* Added more tests, split tests into three files

* Made damage types public and VV read-write-able

* Minor changes to DamageableComponent

Replaced internal use of GetDamagePerType with _damageDict and removed some unnecessary fields

* Fix Suicide, by adding IoC Resolve()

* Fix DamageGroupTrigger bug

* Fix typos in tests

* Change comments./docstrings & spacing

* Merge tests, use test prototypes

Co-authored-by: Leon Friedrich <60421075+leonsfriedrich@users.noreply.github.com>
Co-authored-by: ShadowCommander <10494922+ShadowCommander@users.noreply.github.com>

* Fix merge issues

Co-authored-by: Silver <Silvertorch5@gmail.com>
Co-authored-by: DrSmugleaf <DrSmugleaf@users.noreply.github.com>
Co-authored-by: ShadowCommander <10494922+ShadowCommander@users.noreply.github.com>
Co-authored-by: Leon Friedrich <60421075+leonsfriedrich@users.noreply.github.com>
This commit is contained in:
Leon Friedrich
2021-08-25 03:06:27 +10:00
committed by GitHub
parent 2a8dc0e9c7
commit 32d99eaba9
71 changed files with 2048 additions and 983 deletions

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,14 +6,15 @@ 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(DamageClassTrigger))]
[TestOf(typeof(DamageGroupTrigger))]
[TestOf(typeof(AndTrigger))]
public class DestructibleDamageClassTest : ContentIntegrationTest
public class DestructibleDamageGroupTest : ContentIntegrationTest
{
[Test]
public async Task AndTest()
@@ -31,6 +32,7 @@ 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;
@@ -42,7 +44,7 @@ namespace Content.IntegrationTests.Tests.Destructible
var coordinates = new MapCoordinates(0, 0, mapId);
sMapManager.CreateMap(mapId);
sDestructibleEntity = sEntityManager.SpawnEntity(DestructibleDamageClassEntityId, coordinates);
sDestructibleEntity = sEntityManager.SpawnEntity(DestructibleDamageGroupEntityId, coordinates);
sDamageableComponent = sDestructibleEntity.GetComponent<IDamageableComponent>();
sThresholdListenerComponent = sDestructibleEntity.GetComponent<TestThresholdListenerComponent>();
});
@@ -56,20 +58,23 @@ 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.ChangeDamage(DamageClass.Brute, 5, true));
Assert.True(sDamageableComponent.TryChangeDamage(bruteDamageGroup, 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.ChangeDamage(DamageClass.Brute, 5, true));
Assert.True(sDamageableComponent.TryChangeDamage(bruteDamageGroup, 5, true));
// No threshold reached, burn needs to be 10 as well
Assert.IsEmpty(sThresholdListenerComponent.ThresholdsReached);
// Raise burn damage to 10
Assert.True(sDamageableComponent.ChangeDamage(DamageClass.Burn, 10, true));
Assert.True(sDamageableComponent.TryChangeDamage(burnDamageGroup, 10, true));
// One threshold reached, brute 10 + burn 10
Assert.That(sThresholdListenerComponent.ThresholdsReached.Count, Is.EqualTo(1));
@@ -86,52 +91,52 @@ namespace Content.IntegrationTests.Tests.Destructible
var trigger = (AndTrigger) threshold.Trigger;
Assert.IsInstanceOf<DamageClassTrigger>(trigger.Triggers[0]);
Assert.IsInstanceOf<DamageClassTrigger>(trigger.Triggers[1]);
Assert.IsInstanceOf<DamageGroupTrigger>(trigger.Triggers[0]);
Assert.IsInstanceOf<DamageGroupTrigger>(trigger.Triggers[1]);
sThresholdListenerComponent.ThresholdsReached.Clear();
// Raise brute damage to 20
Assert.True(sDamageableComponent.ChangeDamage(DamageClass.Brute, 10, true));
Assert.True(sDamageableComponent.TryChangeDamage(bruteDamageGroup, 10, true));
// No new thresholds reached
Assert.IsEmpty(sThresholdListenerComponent.ThresholdsReached);
// Raise burn damage to 20
Assert.True(sDamageableComponent.ChangeDamage(DamageClass.Burn, 10, true));
Assert.True(sDamageableComponent.TryChangeDamage(burnDamageGroup, 10, true));
// No new thresholds reached
Assert.IsEmpty(sThresholdListenerComponent.ThresholdsReached);
// Lower brute damage to 0
Assert.True(sDamageableComponent.ChangeDamage(DamageClass.Brute, -20, true));
Assert.True(sDamageableComponent.TryChangeDamage(bruteDamageGroup, -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.ChangeDamage(DamageClass.Brute, 10, true));
Assert.True(sDamageableComponent.TryChangeDamage(bruteDamageGroup, 10, true));
// 10 brute + 10 burn threshold reached, brute was healed and brought back to its threshold amount and slash stayed the same
// 10 brute + 10 burn threshold reached, brute was healed and brought back to its threshold amount and burn stayed the same
Assert.That(sThresholdListenerComponent.ThresholdsReached.Count, Is.EqualTo(1));
sThresholdListenerComponent.ThresholdsReached.Clear();
// Heal both classes of damage to 0
Assert.True(sDamageableComponent.ChangeDamage(DamageClass.Brute, -10, true));
Assert.True(sDamageableComponent.ChangeDamage(DamageClass.Burn, -20, true));
Assert.True(sDamageableComponent.TryChangeDamage(bruteDamageGroup, -10, true));
Assert.True(sDamageableComponent.TryChangeDamage(burnDamageGroup, -20, true));
// No new thresholds reached, healing should not trigger it
Assert.IsEmpty(sThresholdListenerComponent.ThresholdsReached);
// Raise brute damage to 10
Assert.True(sDamageableComponent.ChangeDamage(DamageClass.Brute, 10, true));
Assert.True(sDamageableComponent.TryChangeDamage(bruteDamageGroup, 10, true));
// No new thresholds reached
Assert.IsEmpty(sThresholdListenerComponent.ThresholdsReached);
// Raise burn damage to 10
Assert.True(sDamageableComponent.ChangeDamage(DamageClass.Burn, 10, true));
Assert.True(sDamageableComponent.TryChangeDamage(burnDamageGroup, 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));
@@ -148,8 +153,8 @@ namespace Content.IntegrationTests.Tests.Destructible
trigger = (AndTrigger) threshold.Trigger;
Assert.IsInstanceOf<DamageClassTrigger>(trigger.Triggers[0]);
Assert.IsInstanceOf<DamageClassTrigger>(trigger.Triggers[1]);
Assert.IsInstanceOf<DamageGroupTrigger>(trigger.Triggers[0]);
Assert.IsInstanceOf<DamageGroupTrigger>(trigger.Triggers[1]);
sThresholdListenerComponent.ThresholdsReached.Clear();
@@ -157,20 +162,20 @@ namespace Content.IntegrationTests.Tests.Destructible
threshold.TriggersOnce = true;
// Heal brute and burn back to 0
Assert.True(sDamageableComponent.ChangeDamage(DamageClass.Brute, -10, true));
Assert.True(sDamageableComponent.ChangeDamage(DamageClass.Burn, -10, true));
Assert.True(sDamageableComponent.TryChangeDamage(bruteDamageGroup, -10, true));
Assert.True(sDamageableComponent.TryChangeDamage(burnDamageGroup, -10, true));
// No new thresholds reached from healing
Assert.IsEmpty(sThresholdListenerComponent.ThresholdsReached);
// Raise brute damage to 10
Assert.True(sDamageableComponent.ChangeDamage(DamageClass.Brute, 10, true));
Assert.True(sDamageableComponent.TryChangeDamage(bruteDamageGroup, 10, true));
// No new thresholds reached
Assert.IsEmpty(sThresholdListenerComponent.ThresholdsReached);
// Raise burn damage to 10
Assert.True(sDamageableComponent.ChangeDamage(DamageClass.Burn, 10, true));
Assert.True(sDamageableComponent.TryChangeDamage(burnDamageGroup, 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,6 +6,7 @@ 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
@@ -56,20 +57,23 @@ 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.ChangeDamage(DamageType.Blunt, 5, true));
Assert.True(sDamageableComponent.TryChangeDamage(bluntDamageType, 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.ChangeDamage(DamageType.Blunt, 5, true));
Assert.True(sDamageableComponent.TryChangeDamage(bluntDamageType, 5, true));
// No threshold reached, slash needs to be 10 as well
Assert.IsEmpty(sThresholdListenerComponent.ThresholdsReached);
// Raise slash damage to 10
Assert.True(sDamageableComponent.ChangeDamage(DamageType.Slash, 10, true));
Assert.True(sDamageableComponent.TryChangeDamage(slashDamageType, 10, true));
// One threshold reached, blunt 10 + slash 10
Assert.That(sThresholdListenerComponent.ThresholdsReached.Count, Is.EqualTo(1));
@@ -92,25 +96,25 @@ namespace Content.IntegrationTests.Tests.Destructible
sThresholdListenerComponent.ThresholdsReached.Clear();
// Raise blunt damage to 20
Assert.True(sDamageableComponent.ChangeDamage(DamageType.Blunt, 10, true));
Assert.True(sDamageableComponent.TryChangeDamage(bluntDamageType, 10, true));
// No new thresholds reached
Assert.IsEmpty(sThresholdListenerComponent.ThresholdsReached);
// Raise slash damage to 20
Assert.True(sDamageableComponent.ChangeDamage(DamageType.Slash, 10, true));
Assert.True(sDamageableComponent.TryChangeDamage(slashDamageType, 10, true));
// No new thresholds reached
Assert.IsEmpty(sThresholdListenerComponent.ThresholdsReached);
// Lower blunt damage to 0
Assert.True(sDamageableComponent.ChangeDamage(DamageType.Blunt, -20, true));
Assert.True(sDamageableComponent.TryChangeDamage(bluntDamageType, -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.ChangeDamage(DamageType.Blunt, 10, true));
Assert.True(sDamageableComponent.TryChangeDamage(bluntDamageType, 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));
@@ -118,20 +122,20 @@ namespace Content.IntegrationTests.Tests.Destructible
sThresholdListenerComponent.ThresholdsReached.Clear();
// Heal both types of damage to 0
Assert.True(sDamageableComponent.ChangeDamage(DamageType.Blunt, -10, true));
Assert.True(sDamageableComponent.ChangeDamage(DamageType.Slash, -20, true));
Assert.True(sDamageableComponent.TryChangeDamage(bluntDamageType, -10, true));
Assert.True(sDamageableComponent.TryChangeDamage(slashDamageType, -20, true));
// No new thresholds reached, healing should not trigger it
Assert.IsEmpty(sThresholdListenerComponent.ThresholdsReached);
// Raise blunt damage to 10
Assert.True(sDamageableComponent.ChangeDamage(DamageType.Blunt, 10, true));
Assert.True(sDamageableComponent.TryChangeDamage(bluntDamageType, 10, true));
// No new thresholds reached
Assert.IsEmpty(sThresholdListenerComponent.ThresholdsReached);
// Raise slash damage to 10
Assert.True(sDamageableComponent.ChangeDamage(DamageType.Slash, 10, true));
Assert.True(sDamageableComponent.TryChangeDamage(slashDamageType, 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));
@@ -157,20 +161,20 @@ namespace Content.IntegrationTests.Tests.Destructible
threshold.TriggersOnce = true;
// Heal blunt and slash back to 0
Assert.True(sDamageableComponent.ChangeDamage(DamageType.Blunt, -10, true));
Assert.True(sDamageableComponent.ChangeDamage(DamageType.Slash, -10, true));
Assert.True(sDamageableComponent.TryChangeDamage(bluntDamageType, -10, true));
Assert.True(sDamageableComponent.TryChangeDamage(slashDamageType, -10, true));
// No new thresholds reached from healing
Assert.IsEmpty(sThresholdListenerComponent.ThresholdsReached);
// Raise blunt damage to 10
Assert.True(sDamageableComponent.ChangeDamage(DamageType.Blunt, 10, true));
Assert.True(sDamageableComponent.TryChangeDamage(bluntDamageType, 10, true));
// No new thresholds reached
Assert.IsEmpty(sThresholdListenerComponent.ThresholdsReached);
// Raise slash damage to 10
Assert.True(sDamageableComponent.ChangeDamage(DamageType.Slash, 10, true));
Assert.True(sDamageableComponent.TryChangeDamage(slashDamageType, 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,6 +8,7 @@ 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
@@ -30,6 +31,7 @@ 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;
@@ -49,10 +51,11 @@ namespace Content.IntegrationTests.Tests.Destructible
await server.WaitAssertion(() =>
{
var coordinates = sDestructibleEntity.Transform.Coordinates;
var bruteDamageGroup = sPrototypeManager.Index<DamageGroupPrototype>("TestBrute");
Assert.DoesNotThrow(() =>
{
Assert.True(sDamageableComponent.ChangeDamage(DamageClass.Brute, 50, true));
Assert.True(sDamageableComponent.TryChangeDamage(bruteDamageGroup, 50, true));
});
Assert.That(sThresholdListenerComponent.ThresholdsReached.Count, Is.EqualTo(1));

View File

@@ -6,9 +6,93 @@ namespace Content.IntegrationTests.Tests.Destructible
public const string DestructibleEntityId = "DestructibleTestsDestructibleEntity";
public const string DestructibleDestructionEntityId = "DestructibleTestsDestructibleDestructionEntity";
public const string DestructibleDamageTypeEntityId = "DestructibleTestsDestructibleDamageTypeEntity";
public const string DestructibleDamageClassEntityId = "DestructibleTestsDestructibleDamageClassEntity";
public const string DestructibleDamageGroupEntityId = "DestructibleTestsDestructibleDamageGroupEntity";
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}
@@ -18,6 +102,7 @@ namespace Content.IntegrationTests.Tests.Destructible
name: {DestructibleEntityId}
components:
- type: Damageable
damageContainer: TestMetallicDamageContainer
- type: Destructible
thresholds:
- trigger:
@@ -46,6 +131,7 @@ namespace Content.IntegrationTests.Tests.Destructible
name: {DestructibleDestructionEntityId}
components:
- type: Damageable
damageContainer: TestMetallicDamageContainer
- type: Destructible
thresholds:
- trigger:
@@ -69,34 +155,36 @@ namespace Content.IntegrationTests.Tests.Destructible
name: {DestructibleDamageTypeEntityId}
components:
- type: Damageable
damageContainer: TestMetallicDamageContainer
- type: Destructible
thresholds:
- trigger:
!type:AndTrigger
triggers:
- !type:DamageTypeTrigger
type: Blunt
damageType: TestBlunt
damage: 10
- !type:DamageTypeTrigger
type: Slash
damageType: TestSlash
damage: 10
- type: TestThresholdListener
- type: entity
id: {DestructibleDamageClassEntityId}
name: {DestructibleDamageClassEntityId}
id: {DestructibleDamageGroupEntityId}
name: {DestructibleDamageGroupEntityId}
components:
- type: Damageable
damageContainer: TestMetallicDamageContainer
- type: Destructible
thresholds:
- trigger:
!type:AndTrigger
triggers:
- !type:DamageClassTrigger
class: Brute
- !type:DamageGroupTrigger
damageGroup: TestBrute
damage: 10
- !type:DamageClassTrigger
class: Burn
- !type:DamageGroupTrigger
damageGroup: TestBurn
damage: 10
- type: TestThresholdListener";
}

View File

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