mirror of
https://github.com/space-syndicate/space-station-14.git
synced 2026-10-09 10:21:18 +03:00
* Replace WithVolume() with AddVolume(), Remove AudioHelpers.WithVariation(), Use specifier options for audio params * Undo switching to AudioParams.AddVariation() * Replace AudioHelpers.WithVariation with AudioParams.AddVariation() * Test AudioParams.AddVariation() and change input parameters to sound like previous AudioHelpers.WithVariation() * Fix build error * Fix build error v2 * Remove DoAfter * fixes --------- Co-authored-by: AJCM-git <ajcm_mail@disroot.org>
75 lines
2.8 KiB
C#
75 lines
2.8 KiB
C#
using Content.Shared.Stunnable;
|
|
using Content.Shared.Damage.Components;
|
|
using Content.Shared.Effects;
|
|
using Robust.Shared.Audio;
|
|
using Robust.Shared.Audio.Systems;
|
|
using Robust.Shared.Physics.Events;
|
|
using Robust.Shared.Player;
|
|
using Robust.Shared.Random;
|
|
using Robust.Shared.Timing;
|
|
|
|
namespace Content.Shared.Damage.Systems;
|
|
|
|
public sealed partial class DamageOnHighSpeedImpactSystem : EntitySystem
|
|
{
|
|
[Dependency] private IGameTiming _gameTiming = default!;
|
|
[Dependency] private IRobustRandom _robustRandom = default!;
|
|
[Dependency] private DamageableSystem _damageable = default!;
|
|
[Dependency] private SharedAudioSystem _audio = default!;
|
|
[Dependency] private SharedColorFlashEffectSystem _color = default!;
|
|
[Dependency] private SharedStunSystem _stun = default!;
|
|
|
|
public override void Initialize()
|
|
{
|
|
base.Initialize();
|
|
SubscribeLocalEvent<DamageOnHighSpeedImpactComponent, StartCollideEvent>(HandleCollide);
|
|
}
|
|
|
|
private void HandleCollide(EntityUid uid, DamageOnHighSpeedImpactComponent component, ref StartCollideEvent args)
|
|
{
|
|
if (!args.OurFixture.Hard || !args.OtherFixture.Hard)
|
|
return;
|
|
|
|
if (!HasComp<DamageableComponent>(uid))
|
|
return;
|
|
|
|
//TODO: This should solve after physics solves
|
|
var speed = args.OurBody.LinearVelocity.Length();
|
|
|
|
if (speed < component.MinimumSpeed)
|
|
return;
|
|
|
|
if (component.LastHit != null
|
|
&& (_gameTiming.CurTime - component.LastHit.Value).TotalSeconds < component.DamageCooldown)
|
|
return;
|
|
|
|
component.LastHit = _gameTiming.CurTime;
|
|
|
|
if (_robustRandom.Prob(component.StunChance))
|
|
_stun.TryUpdateStunDuration(uid, TimeSpan.FromSeconds(component.StunSeconds));
|
|
|
|
var damageScale = component.SpeedDamageFactor * speed / component.MinimumSpeed;
|
|
|
|
_damageable.TryChangeDamage(uid, component.Damage * damageScale);
|
|
|
|
if (_gameTiming.IsFirstTimePredicted)
|
|
{
|
|
var audioParams = component.SoundHit?.Params ?? AudioParams.Default;
|
|
audioParams = audioParams.WithVariation(0.125f).AddVolume(-0.125f);
|
|
_audio.PlayPvs(component.SoundHit, uid, audioParams);
|
|
}
|
|
_color.RaiseEffect(Color.Red, new List<EntityUid>() { uid }, Filter.Pvs(uid, entityManager: EntityManager));
|
|
}
|
|
|
|
public void ChangeCollide(EntityUid uid, float minimumSpeed, float stunSeconds, float damageCooldown, float speedDamage, DamageOnHighSpeedImpactComponent? collide = null)
|
|
{
|
|
if (!Resolve(uid, ref collide, false))
|
|
return;
|
|
|
|
collide.MinimumSpeed = minimumSpeed;
|
|
collide.StunSeconds = stunSeconds;
|
|
collide.DamageCooldown = damageCooldown;
|
|
collide.SpeedDamageFactor = speedDamage;
|
|
Dirty(uid, collide);
|
|
}
|
|
}
|