Generalize ReagentUnit into FixedPoint2 and use it for damage calculations (#5151)

* Damage units

* sum ext method
This commit is contained in:
mirrorcult
2021-11-03 16:48:03 -07:00
committed by GitHub
parent 8165d8f38c
commit 3ab4a30a0f
100 changed files with 730 additions and 601 deletions

View File

@@ -2,6 +2,7 @@ using System.Threading.Tasks;
using Content.Server.Destructible.Thresholds.Triggers;
using Content.Shared.Damage;
using Content.Shared.Damage.Prototypes;
using Content.Shared.FixedPoint;
using NUnit.Framework;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
@@ -60,8 +61,8 @@ namespace Content.IntegrationTests.Tests.Destructible
var bruteDamageGroup = sPrototypeManager.Index<DamageGroupPrototype>("TestBrute");
var burnDamageGroup = sPrototypeManager.Index<DamageGroupPrototype>("TestBurn");
DamageSpecifier bruteDamage = new(bruteDamageGroup,5);
DamageSpecifier burnDamage = new(burnDamageGroup,5);
DamageSpecifier bruteDamage = new(bruteDamageGroup, FixedPoint2.New(5));
DamageSpecifier burnDamage = new(burnDamageGroup, FixedPoint2.New(5));
// Raise brute damage to 5
sDamageableSystem.TryChangeDamage(sDestructibleEntity.Uid, bruteDamage, true);
@@ -112,7 +113,7 @@ namespace Content.IntegrationTests.Tests.Destructible
// Lower brute damage to 0
sDamageableSystem.TryChangeDamage(sDestructibleEntity.Uid, bruteDamage * -10);
Assert.That(sDamageableComponent.TotalDamage,Is.EqualTo(20));
Assert.That(sDamageableComponent.TotalDamage,Is.EqualTo(FixedPoint2.New(20)));
// No new thresholds reached, healing should not trigger it
Assert.IsEmpty(sTestThresholdListenerSystem.ThresholdsReached);

View File

@@ -6,6 +6,7 @@ using Content.Server.Destructible.Thresholds.Behaviors;
using Content.Server.Destructible.Thresholds.Triggers;
using Content.Shared.Damage;
using Content.Shared.Damage.Prototypes;
using Content.Shared.FixedPoint;
using NUnit.Framework;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
@@ -186,7 +187,7 @@ namespace Content.IntegrationTests.Tests.Destructible
sDamageableSystem.TryChangeDamage(sDestructibleEntity.Uid, bluntDamage*5, true);
// Check that the total damage matches
Assert.That(sDamageableComponent.TotalDamage, Is.EqualTo(50));
Assert.That(sDamageableComponent.TotalDamage, Is.EqualTo(FixedPoint2.New(50)));
// Both thresholds should have triggered
Assert.That(sTestThresholdListenerSystem.ThresholdsReached, Has.Exactly(2).Items);
@@ -234,7 +235,7 @@ namespace Content.IntegrationTests.Tests.Destructible
sDamageableSystem.SetAllDamage(sDamageableComponent, 0);
// Check that the entity has 0 damage
Assert.That(sDamageableComponent.TotalDamage, Is.EqualTo(0));
Assert.That(sDamageableComponent.TotalDamage, Is.EqualTo(FixedPoint2.Zero));
// Set both thresholds to only trigger once
foreach (var destructibleThreshold in sDestructibleComponent.Thresholds)
@@ -247,7 +248,7 @@ namespace Content.IntegrationTests.Tests.Destructible
sDamageableSystem.TryChangeDamage(sDestructibleEntity.Uid, bluntDamage*5, true);
// Check that the total damage matches
Assert.That(sDamageableComponent.TotalDamage, Is.EqualTo(50));
Assert.That(sDamageableComponent.TotalDamage, Is.EqualTo(FixedPoint2.New(50)));
// No thresholds should have triggered as they were already triggered before, and they are set to only trigger once
Assert.That(sTestThresholdListenerSystem.ThresholdsReached, Is.Empty);
@@ -260,7 +261,7 @@ namespace Content.IntegrationTests.Tests.Destructible
}
// Check that the total damage matches
Assert.That(sDamageableComponent.TotalDamage, Is.EqualTo(50));
Assert.That(sDamageableComponent.TotalDamage, Is.EqualTo(FixedPoint2.New(50)));
// They shouldn't have been triggered by changing TriggersOnce
Assert.That(sTestThresholdListenerSystem.ThresholdsReached, Is.Empty);