Files
tbd-station-14/Content.Server/Shuttles/Systems/ShuttleSystem.Impact.cs
Mervill c6d291968f Replace obsolete code in shuttle systems. (#31408)
* Format DockingSystem.Shuttle

* arrivals system

* docking system

* shuttle console system

* emergency shuttle system

* shuttle system

* thruster system

* Fix compile error

---------

Co-authored-by: Pieter-Jan Briers <pieterjan.briers+git@gmail.com>
2024-08-26 17:48:37 +02:00

61 lines
2.1 KiB
C#

using System.Numerics;
using Content.Server.Shuttles.Components;
using Content.Shared.Audio;
using Robust.Shared.Audio;
using Robust.Shared.Map;
using Robust.Shared.Physics.Dynamics;
using Robust.Shared.Physics.Events;
using Robust.Shared.Player;
namespace Content.Server.Shuttles.Systems;
public sealed partial class ShuttleSystem
{
/// <summary>
/// Minimum velocity difference between 2 bodies for a shuttle "impact" to occur.
/// </summary>
private const int MinimumImpactVelocity = 10;
private readonly SoundCollectionSpecifier _shuttleImpactSound = new("ShuttleImpactSound");
private void InitializeImpact()
{
SubscribeLocalEvent<ShuttleComponent, StartCollideEvent>(OnShuttleCollide);
}
private void OnShuttleCollide(EntityUid uid, ShuttleComponent component, ref StartCollideEvent args)
{
if (!HasComp<ShuttleComponent>(args.OtherEntity))
return;
var ourBody = args.OurBody;
var otherBody = args.OtherBody;
// TODO: Would also be nice to have a continuous sound for scraping.
var ourXform = Transform(uid);
if (ourXform.MapUid == null)
return;
var otherXform = Transform(args.OtherEntity);
var ourPoint = Vector2.Transform(args.WorldPoint, _transform.GetInvWorldMatrix(ourXform));
var otherPoint = Vector2.Transform(args.WorldPoint, _transform.GetInvWorldMatrix(otherXform));
var ourVelocity = _physics.GetLinearVelocity(uid, ourPoint, ourBody, ourXform);
var otherVelocity = _physics.GetLinearVelocity(args.OtherEntity, otherPoint, otherBody, otherXform);
var jungleDiff = (ourVelocity - otherVelocity).Length();
if (jungleDiff < MinimumImpactVelocity)
{
return;
}
var coordinates = new EntityCoordinates(ourXform.MapUid.Value, args.WorldPoint);
var volume = MathF.Min(10f, 1f * MathF.Pow(jungleDiff, 0.5f) - 5f);
var audioParams = AudioParams.Default.WithVariation(SharedContentAudioSystem.DefaultVariation).WithVolume(volume);
_audio.PlayPvs(_shuttleImpactSound, coordinates, audioParams);
}
}