Update DamageableSystem to modern standards (#39417)
* Update DamageableSystem to modern standards * DamageContainerId -> DamageContainerID with lint flag * Replace strings with protoids * Make CVar subscription declarations all consistently whitespaced * ChangeDamage -> TryChangeDamage, cope with C# jank * Revert event signature changes * Restore a comment * Re-add two queries * Init the queries * Use appearanceQuery in DamageChanged * Use damageableQuery in TryChangeDamage * Use damageableQuery in SetDamageModifierSetId * Final cleanup, fix sandboxing * Rectify ExplosionSystem:::ProcessEntity's call to TryChangeDamage * Re-organize DamageableSystem * first big fuck you breaking change. * THATS A LOT OF DAMAGE!!! * Fix test fails * test fixes 2 * push it --------- Co-authored-by: Princess Cheeseballs <66055347+Pronana@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
cf66dd7b35
commit
cdbe92d37d
@@ -1,6 +1,6 @@
|
||||
using Content.Shared.Damage;
|
||||
using Content.Shared.Damage.Prototypes;
|
||||
using Robust.Shared.Audio;
|
||||
using Content.Shared.Damage.Components;
|
||||
using Content.Shared.Damage.Systems;
|
||||
using Robust.Shared.Audio.Systems;
|
||||
using Robust.Shared.Containers;
|
||||
|
||||
@@ -42,31 +42,31 @@ public sealed partial class BlockingSystem
|
||||
|
||||
private void OnUserDamageModified(EntityUid uid, BlockingUserComponent component, DamageModifyEvent args)
|
||||
{
|
||||
if (TryComp<BlockingComponent>(component.BlockingItem, out var blocking))
|
||||
if (component.BlockingItem is not { } item || !TryComp<BlockingComponent>(item, out var blocking))
|
||||
return;
|
||||
|
||||
if (args.Damage.GetTotal() <= 0)
|
||||
return;
|
||||
|
||||
// A shield should only block damage it can itself absorb. To determine that we need the Damageable component on it.
|
||||
if (!TryComp<DamageableComponent>(item, out var dmgComp))
|
||||
return;
|
||||
|
||||
var blockFraction = blocking.IsBlocking ? blocking.ActiveBlockFraction : blocking.PassiveBlockFraction;
|
||||
blockFraction = Math.Clamp(blockFraction, 0, 1);
|
||||
_damageable.TryChangeDamage((item, dmgComp), blockFraction * args.OriginalDamage);
|
||||
|
||||
var modify = new DamageModifierSet();
|
||||
foreach (var key in dmgComp.Damage.DamageDict.Keys)
|
||||
{
|
||||
if (args.Damage.GetTotal() <= 0)
|
||||
return;
|
||||
modify.Coefficients.TryAdd(key, 1 - blockFraction);
|
||||
}
|
||||
|
||||
// A shield should only block damage it can itself absorb. To determine that we need the Damageable component on it.
|
||||
if (!TryComp<DamageableComponent>(component.BlockingItem, out var dmgComp))
|
||||
return;
|
||||
args.Damage = DamageSpecifier.ApplyModifierSet(args.Damage, modify);
|
||||
|
||||
var blockFraction = blocking.IsBlocking ? blocking.ActiveBlockFraction : blocking.PassiveBlockFraction;
|
||||
blockFraction = Math.Clamp(blockFraction, 0, 1);
|
||||
_damageable.TryChangeDamage(component.BlockingItem, blockFraction * args.OriginalDamage);
|
||||
|
||||
var modify = new DamageModifierSet();
|
||||
foreach (var key in dmgComp.Damage.DamageDict.Keys)
|
||||
{
|
||||
modify.Coefficients.TryAdd(key, 1 - blockFraction);
|
||||
}
|
||||
|
||||
args.Damage = DamageSpecifier.ApplyModifierSet(args.Damage, modify);
|
||||
|
||||
if (blocking.IsBlocking && !args.Damage.Equals(args.OriginalDamage))
|
||||
{
|
||||
_audio.PlayPvs(blocking.BlockSound, uid);
|
||||
}
|
||||
if (blocking.IsBlocking && !args.Damage.Equals(args.OriginalDamage))
|
||||
{
|
||||
_audio.PlayPvs(blocking.BlockSound, uid);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user