2021-07-21 02:02:43 +10:00
|
|
|
using Content.Server.Damage.Components;
|
2021-10-10 12:47:26 +02:00
|
|
|
using Content.Server.Stunnable;
|
2021-07-21 02:02:43 +10:00
|
|
|
using Content.Shared.Audio;
|
2021-09-15 03:07:37 +10:00
|
|
|
using Content.Shared.Damage;
|
2021-07-21 02:02:43 +10:00
|
|
|
using JetBrains.Annotations;
|
|
|
|
|
using Robust.Shared.Audio;
|
|
|
|
|
using Robust.Shared.Physics.Dynamics;
|
2022-09-14 17:26:26 +10:00
|
|
|
using Robust.Shared.Physics.Events;
|
2021-07-21 02:02:43 +10:00
|
|
|
using Robust.Shared.Player;
|
|
|
|
|
using Robust.Shared.Random;
|
|
|
|
|
using Robust.Shared.Timing;
|
|
|
|
|
|
2021-09-12 16:22:58 +10:00
|
|
|
namespace Content.Server.Damage.Systems
|
2021-07-21 02:02:43 +10:00
|
|
|
{
|
|
|
|
|
[UsedImplicitly]
|
|
|
|
|
internal sealed class DamageOnHighSpeedImpactSystem: EntitySystem
|
|
|
|
|
{
|
|
|
|
|
[Dependency] private readonly IRobustRandom _robustRandom = default!;
|
|
|
|
|
[Dependency] private readonly IGameTiming _gameTiming = default!;
|
2021-09-15 03:07:37 +10:00
|
|
|
[Dependency] private readonly DamageableSystem _damageableSystem = default!;
|
2021-10-10 12:47:26 +02:00
|
|
|
[Dependency] private readonly StunSystem _stunSystem = default!;
|
2021-07-21 02:02:43 +10:00
|
|
|
|
|
|
|
|
public override void Initialize()
|
|
|
|
|
{
|
|
|
|
|
base.Initialize();
|
|
|
|
|
SubscribeLocalEvent<DamageOnHighSpeedImpactComponent, StartCollideEvent>(HandleCollide);
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-14 17:26:26 +10:00
|
|
|
private void HandleCollide(EntityUid uid, DamageOnHighSpeedImpactComponent component, ref StartCollideEvent args)
|
2021-07-21 02:02:43 +10:00
|
|
|
{
|
2021-09-28 13:35:29 +02:00
|
|
|
if (!EntityManager.HasComponent<DamageableComponent>(uid)) return;
|
2021-07-21 02:02:43 +10:00
|
|
|
|
|
|
|
|
var otherBody = args.OtherFixture.Body.Owner;
|
|
|
|
|
var speed = args.OurFixture.Body.LinearVelocity.Length;
|
|
|
|
|
|
|
|
|
|
if (speed < component.MinimumSpeed) return;
|
|
|
|
|
|
2022-06-12 19:45:47 -04:00
|
|
|
SoundSystem.Play(component.SoundHit.GetSound(), Filter.Pvs(otherBody), otherBody, AudioHelpers.WithVariation(0.125f).WithVolume(-0.125f));
|
2021-07-21 02:02:43 +10:00
|
|
|
|
|
|
|
|
if ((_gameTiming.CurTime - component.LastHit).TotalSeconds < component.DamageCooldown)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
component.LastHit = _gameTiming.CurTime;
|
|
|
|
|
|
2021-10-15 14:45:04 -07:00
|
|
|
if (_robustRandom.Prob(component.StunChance))
|
2021-12-07 09:18:07 +03:00
|
|
|
_stunSystem.TryStun(uid, TimeSpan.FromSeconds(component.StunSeconds), true);
|
2021-07-21 02:02:43 +10:00
|
|
|
|
2021-09-15 03:07:37 +10:00
|
|
|
var damageScale = (speed / component.MinimumSpeed) * component.Factor;
|
2021-11-29 02:34:44 +13:00
|
|
|
|
2022-02-07 14:52:58 +13:00
|
|
|
_damageableSystem.TryChangeDamage(uid, component.Damage * damageScale);
|
2021-07-21 02:02:43 +10:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|