* 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>
51 lines
1.5 KiB
C#
51 lines
1.5 KiB
C#
using Content.Client.Audio;
|
|
using Content.Shared.Salvage;
|
|
using Content.Shared.Salvage.Expeditions;
|
|
using Robust.Client.Player;
|
|
using Robust.Shared.GameStates;
|
|
|
|
namespace Content.Client.Salvage;
|
|
|
|
public sealed class SalvageSystem : SharedSalvageSystem
|
|
{
|
|
[Dependency] private readonly IPlayerManager _playerManager = default!;
|
|
[Dependency] private readonly ContentAudioSystem _audio = default!;
|
|
|
|
public override void Initialize()
|
|
{
|
|
base.Initialize();
|
|
SubscribeLocalEvent<PlayAmbientMusicEvent>(OnPlayAmbientMusic);
|
|
SubscribeLocalEvent<SalvageExpeditionComponent, ComponentHandleState>(OnExpeditionHandleState);
|
|
}
|
|
|
|
private void OnExpeditionHandleState(EntityUid uid, SalvageExpeditionComponent component, ref ComponentHandleState args)
|
|
{
|
|
if (args.Current is not SalvageExpeditionComponentState state)
|
|
return;
|
|
|
|
component.Stage = state.Stage;
|
|
|
|
if (component.Stage >= ExpeditionStage.MusicCountdown)
|
|
{
|
|
_audio.DisableAmbientMusic();
|
|
}
|
|
}
|
|
|
|
private void OnPlayAmbientMusic(ref PlayAmbientMusicEvent ev)
|
|
{
|
|
if (ev.Cancelled)
|
|
return;
|
|
|
|
var player = _playerManager.LocalEntity;
|
|
|
|
if (!TryComp<TransformComponent>(player, out var xform) ||
|
|
!TryComp<SalvageExpeditionComponent>(xform.MapUid, out var expedition) ||
|
|
expedition.Stage < ExpeditionStage.MusicCountdown)
|
|
{
|
|
return;
|
|
}
|
|
|
|
ev.Cancelled = true;
|
|
}
|
|
}
|