Files
tbd-station-14/Content.Server/Damage/Systems/DamageOnToolInteractSystem.cs
2021-11-28 14:34:44 +01:00

56 lines
2.0 KiB
C#

using Content.Server.Administration.Logs;
using Content.Server.Damage.Components;
using Content.Server.Tools.Components;
using Content.Shared.Administration.Logs;
using Content.Shared.Damage;
using Content.Shared.Interaction;
using Robust.Shared.GameObjects;
using Robust.Shared.IoC;
namespace Content.Server.Damage.Systems
{
public class DamageOnToolInteractSystem : EntitySystem
{
[Dependency] private readonly DamageableSystem _damageableSystem = default!;
[Dependency] private readonly AdminLogSystem _logSystem = 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 (component.WeldingDamage is {} weldingDamage
&& args.Used.TryGetComponent<WelderComponent>(out var welder)
&& welder.Lit)
{
var dmg = _damageableSystem.TryChangeDamage(args.Target.Uid, weldingDamage);
if (dmg != null)
_logSystem.Add(LogType.Damaged,
$"{args.User} used {args.Used} as a welder to deal {dmg.Total} damage to {args.Target}");
args.Handled = true;
}
else if (component.DefaultDamage is {} damage
&& args.Used.TryGetComponent<ToolComponent>(out var tool)
&& tool.Qualities.ContainsAny(component.Tools))
{
var dmg = _damageableSystem.TryChangeDamage(args.Target.Uid, damage);
if (dmg != null)
_logSystem.Add(LogType.Damaged,
$"{args.User} used {args.Used} as a tool to deal {dmg.Total} damage to {args.Target}");
args.Handled = true;
}
}
}
}