Files
tbd-station-14/Content.Server/Damage/Systems/DamageOnToolInteractSystem.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

60 lines
2.4 KiB
C#

using Content.Server.Administration.Logs;
using Content.Server.Damage.Components;
using Content.Shared.Damage;
using Content.Shared.Database;
using Content.Shared.Interaction;
using Content.Shared.Tools.Components;
using Content.Shared.Tools.Systems;
using ItemToggleComponent = Content.Shared.Item.ItemToggle.Components.ItemToggleComponent;
namespace Content.Server.Damage.Systems
{
public sealed class DamageOnToolInteractSystem : EntitySystem
{
[Dependency] private readonly Shared.Damage.Systems.DamageableSystem _damageableSystem = default!;
[Dependency] private readonly IAdminLogManager _adminLogger = default!;
[Dependency] private readonly SharedToolSystem _toolSystem = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<DamageOnToolInteractComponent, InteractUsingEvent>(OnInteracted);
}
private void OnInteracted(EntityUid uid, DamageOnToolInteractComponent component, InteractUsingEvent args)
{
if (args.Handled)
return;
if (!TryComp<ItemToggleComponent>(args.Used, out var itemToggle))
return;
if (component.WeldingDamage is {} weldingDamage
&& TryComp(args.Used, out WelderComponent? welder)
&& itemToggle.Activated
&& !welder.TankSafe)
{
if (_damageableSystem.TryChangeDamage(args.Target, weldingDamage, out var dmg, origin: args.User))
{
_adminLogger.Add(LogType.Damaged,
$"{ToPrettyString(args.User):user} used {ToPrettyString(args.Used):used} as a welder to deal {dmg.GetTotal():damage} damage to {ToPrettyString(args.Target):target}");
}
args.Handled = true;
}
else if (component.DefaultDamage is {} damage
&& _toolSystem.HasQuality(args.Used, component.Tools))
{
if (_damageableSystem.TryChangeDamage(args.Target, damage, out var dmg, origin: args.User))
{
_adminLogger.Add(LogType.Damaged,
$"{ToPrettyString(args.User):user} used {ToPrettyString(args.Used):used} as a tool to deal {dmg.GetTotal():damage} damage to {ToPrettyString(args.Target):target}");
}
args.Handled = true;
}
}
}
}