Files
tbd-station-14/Content.Server/Damage/Systems/DamageOnToolInteractSystem.cs
metalgearsloth 2166958bd0 AutoCompState + ItemToggle fixes (#23422)
* AutoCompState + ItemToggle fixes

Fix a lot of the comp states that are never actually networked and also cleaned up ItemToggle events a bunch. ItemToggle will still need some future work for lights and sounds.

* Also catch these
2024-01-03 17:24:02 +11:00

61 lines
2.4 KiB
C#

using Content.Server.Administration.Logs;
using Content.Server.Damage.Components;
using Content.Server.Tools.Components;
using Content.Shared.Item;
using Content.Shared.Damage;
using Content.Shared.Database;
using Content.Shared.Interaction;
using Content.Shared.Tools.Components;
using ItemToggleComponent = Content.Shared.Item.ItemToggle.Components.ItemToggleComponent;
namespace Content.Server.Damage.Systems
{
public sealed class DamageOnToolInteractSystem : EntitySystem
{
[Dependency] private readonly DamageableSystem _damageableSystem = default!;
[Dependency] private readonly IAdminLogManager _adminLogger = 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>(uid, out var itemToggle))
return;
if (component.WeldingDamage is {} weldingDamage
&& EntityManager.TryGetComponent(args.Used, out WelderComponent? welder)
&& itemToggle.Activated
&& !welder.TankSafe)
{
var dmg = _damageableSystem.TryChangeDamage(args.Target, weldingDamage, origin: args.User);
if (dmg != null)
_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
&& EntityManager.TryGetComponent(args.Used, out ToolComponent? tool)
&& tool.Qualities.ContainsAny(component.Tools))
{
var dmg = _damageableSystem.TryChangeDamage(args.Target, damage, origin: args.User);
if (dmg != null)
_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;
}
}
}
}