* Use new Subs.CVar helper Removes manual config OnValueChanged calls, removes need to remember to manually unsubscribe. This both reduces boilerplate and fixes many issues where subscriptions weren't removed on entity system shutdown. * Fix a bunch of warnings * More warning fixes * Use new DateTime serializer to get rid of ISerializationHooks in changelog code. * Get rid of some more ISerializationHooks for enums * And a little more * Apply suggestions from code review Co-authored-by: 0x6273 <0x40@keemail.me> --------- Co-authored-by: 0x6273 <0x40@keemail.me>
62 lines
1.9 KiB
C#
62 lines
1.9 KiB
C#
using System.Numerics;
|
|
using Content.Shared.Camera;
|
|
using Content.Shared.Gravity;
|
|
using Robust.Client.Player;
|
|
using Robust.Shared.Audio;
|
|
using Robust.Shared.Audio.Systems;
|
|
using Robust.Shared.Player;
|
|
using Robust.Shared.Random;
|
|
|
|
namespace Content.Client.Gravity;
|
|
|
|
public sealed partial class GravitySystem
|
|
{
|
|
[Dependency] private readonly IPlayerManager _playerManager = default!;
|
|
[Dependency] private readonly IRobustRandom _random = default!;
|
|
[Dependency] private readonly SharedAudioSystem _audio = default!;
|
|
[Dependency] private readonly SharedCameraRecoilSystem _sharedCameraRecoil = default!;
|
|
|
|
private void InitializeShake()
|
|
{
|
|
SubscribeLocalEvent<GravityShakeComponent, ComponentInit>(OnShakeInit);
|
|
}
|
|
|
|
private void OnShakeInit(EntityUid uid, GravityShakeComponent component, ComponentInit args)
|
|
{
|
|
var localPlayer = _playerManager.LocalEntity;
|
|
|
|
if (!TryComp<TransformComponent>(localPlayer, out var xform) ||
|
|
xform.GridUid != uid && xform.MapUid != uid)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (Timing.IsFirstTimePredicted && TryComp<GravityComponent>(uid, out var gravity))
|
|
{
|
|
_audio.PlayGlobal(gravity.GravityShakeSound, Filter.Local(), true, AudioParams.Default.WithVolume(-2f));
|
|
}
|
|
}
|
|
|
|
protected override void ShakeGrid(EntityUid uid, GravityComponent? gravity = null)
|
|
{
|
|
base.ShakeGrid(uid, gravity);
|
|
|
|
if (!Resolve(uid, ref gravity) || !Timing.IsFirstTimePredicted)
|
|
return;
|
|
|
|
var localPlayer = _playerManager.LocalEntity;
|
|
|
|
if (!TryComp<TransformComponent>(localPlayer, out var xform))
|
|
return;
|
|
|
|
if (xform.GridUid != uid ||
|
|
xform.GridUid == null && xform.MapUid != uid)
|
|
{
|
|
return;
|
|
}
|
|
|
|
var kick = new Vector2(_random.NextFloat(), _random.NextFloat()) * GravityKick;
|
|
_sharedCameraRecoil.KickCamera(localPlayer.Value, kick);
|
|
}
|
|
}
|