Ambient music fixes (#17685)
This commit is contained in:
@@ -1,8 +1,50 @@
|
||||
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.LocalPlayer?.ControlledEntity;
|
||||
|
||||
if (!TryComp<TransformComponent>(player, out var xform) ||
|
||||
!TryComp<SalvageExpeditionComponent>(xform.MapUid, out var expedition) ||
|
||||
expedition.Stage < ExpeditionStage.MusicCountdown)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
ev.Cancelled = true;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user