WeaponRandomSystem.cs 1.0 KB

1234567891011121314151617181920212223242526272829303132
  1. using Content.Shared.Weapons.Melee.Events;
  2. using Robust.Shared.Random;
  3. using Robust.Shared.Audio.Systems;
  4. namespace Content.Server.Weapons.Melee.WeaponRandom;
  5. /// <summary>
  6. /// This adds a random damage bonus to melee attacks based on damage bonus amount and probability.
  7. /// </summary>
  8. public sealed class WeaponRandomSystem : EntitySystem
  9. {
  10. [Dependency] private readonly IRobustRandom _random = default!;
  11. [Dependency] private readonly SharedAudioSystem _audio = default!;
  12. public override void Initialize()
  13. {
  14. base.Initialize();
  15. SubscribeLocalEvent<WeaponRandomComponent, MeleeHitEvent>(OnMeleeHit);
  16. }
  17. /// <summary>
  18. /// On Melee hit there is a possible chance of additional bonus damage occuring.
  19. /// </summary>
  20. private void OnMeleeHit(EntityUid uid, WeaponRandomComponent component, MeleeHitEvent args)
  21. {
  22. if (_random.Prob(component.RandomDamageChance))
  23. {
  24. _audio.PlayPvs(component.DamageSound, uid);
  25. args.BonusDamage = component.DamageBonus;
  26. }
  27. }
  28. }