2024-08-02 11:50:26 +00:00
|
|
|
using Content.Shared._White.Blocking;
|
2023-06-03 04:31:47 +01:00
|
|
|
using Content.Shared.Weapons.Melee.Events;
|
|
|
|
|
using Robust.Shared.Random;
|
2023-11-27 22:12:34 +11:00
|
|
|
using Robust.Shared.Audio.Systems;
|
2023-06-03 04:31:47 +01:00
|
|
|
|
|
|
|
|
namespace Content.Server.Weapons.Melee.WeaponRandom;
|
|
|
|
|
|
2023-12-18 19:42:57 +00:00
|
|
|
/// <summary>
|
|
|
|
|
/// This adds a random damage bonus to melee attacks based on damage bonus amount and probability.
|
|
|
|
|
/// </summary>
|
2023-06-03 04:31:47 +01:00
|
|
|
public sealed class WeaponRandomSystem : EntitySystem
|
|
|
|
|
{
|
|
|
|
|
[Dependency] private readonly IRobustRandom _random = default!;
|
|
|
|
|
[Dependency] private readonly SharedAudioSystem _audio = default!;
|
|
|
|
|
|
|
|
|
|
public override void Initialize()
|
|
|
|
|
{
|
|
|
|
|
base.Initialize();
|
|
|
|
|
|
|
|
|
|
SubscribeLocalEvent<WeaponRandomComponent, MeleeHitEvent>(OnMeleeHit);
|
|
|
|
|
}
|
2023-12-18 19:42:57 +00:00
|
|
|
/// <summary>
|
|
|
|
|
/// On Melee hit there is a possible chance of additional bonus damage occuring.
|
|
|
|
|
/// </summary>
|
2023-06-03 04:31:47 +01:00
|
|
|
private void OnMeleeHit(EntityUid uid, WeaponRandomComponent component, MeleeHitEvent args)
|
|
|
|
|
{
|
2023-12-18 19:42:57 +00:00
|
|
|
if (_random.Prob(component.RandomDamageChance))
|
2023-06-03 04:31:47 +01:00
|
|
|
{
|
2023-12-18 19:42:57 +00:00
|
|
|
_audio.PlayPvs(component.DamageSound, uid);
|
|
|
|
|
args.BonusDamage = component.DamageBonus;
|
2023-06-03 04:31:47 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|