CatStation/Content.Server/Weapons/Melee/WeaponRandom/WeaponRandomSystem.cs
Pieter-Jan Briers 5168b5f3d4
IoC source gen compatibility (#43863)
* IoC source gen compatibility

Can be merged before or after https://github.com/space-wizards/RobustToolbox/pull/6549 doesn't really matter.

* Missed a spot
2026-05-09 03:29:58 +00:00

32 lines
1 KiB
C#

using Content.Shared.Weapons.Melee.Events;
using Robust.Shared.Random;
using Robust.Shared.Audio.Systems;
namespace Content.Server.Weapons.Melee.WeaponRandom;
/// <summary>
/// This adds a random damage bonus to melee attacks based on damage bonus amount and probability.
/// </summary>
public sealed partial class WeaponRandomSystem : EntitySystem
{
[Dependency] private IRobustRandom _random = default!;
[Dependency] private SharedAudioSystem _audio = default!;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<WeaponRandomComponent, MeleeHitEvent>(OnMeleeHit);
}
/// <summary>
/// On Melee hit there is a possible chance of additional bonus damage occuring.
/// </summary>
private void OnMeleeHit(EntityUid uid, WeaponRandomComponent component, MeleeHitEvent args)
{
if (_random.Prob(component.RandomDamageChance))
{
_audio.PlayPvs(component.DamageSound, uid);
args.BonusDamage = component.DamageBonus;
}
}
}