Files
tbd-station-14/Content.Server/Damage/Systems/DamageOnHitSystem.cs
Hannah Giovanna Dawson cdbe92d37d 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>
2025-10-27 19:53:04 +00:00

25 lines
804 B
C#

using Content.Server.Damage.Components;
using Content.Shared.Weapons.Melee.Events;
using System.Linq;
using Content.Shared.Damage.Systems;
namespace Content.Server.Damage.Systems;
public sealed class DamageOnHitSystem : EntitySystem
{
[Dependency] private readonly DamageableSystem _damageableSystem = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<DamageOnHitComponent, MeleeHitEvent>(DamageItem);
}
// Looks for a hit, then damages the held item an appropriate amount.
private void DamageItem(EntityUid uid, DamageOnHitComponent component, MeleeHitEvent args)
{
if (args.HitEntities.Any()) {
_damageableSystem.TryChangeDamage(uid, component.Damage, component.IgnoreResistances);
}
}
}