Ambient music fixes (#17685)

This commit is contained in:
metalgearsloth
2023-06-27 21:28:51 +10:00
committed by GitHub
parent 46a0f178e5
commit 1485666a23
16 changed files with 456 additions and 362 deletions

View File

@@ -13,8 +13,7 @@ using Robust.Shared.Utility;
using System.Linq; using System.Linq;
using Robust.Client.GameObjects; using Robust.Client.GameObjects;
namespace Content.Client.Audio namespace Content.Client.Audio;
{
//TODO: This is using a incomplete version of the whole "only play nearest sounds" algo, that breaks down a bit should the ambient sound cap get hit. //TODO: This is using a incomplete version of the whole "only play nearest sounds" algo, that breaks down a bit should the ambient sound cap get hit.
//TODO: This'll be fixed when GetEntitiesInRange produces consistent outputs. //TODO: This'll be fixed when GetEntitiesInRange produces consistent outputs.
@@ -313,4 +312,3 @@ namespace Content.Client.Audio
DebugTools.Assert(_playingCount.All(x => x.Value == PlayingCount(x.Key))); DebugTools.Assert(_playingCount.All(x => x.Value == PlayingCount(x.Key)));
} }
} }
}

View File

@@ -245,6 +245,12 @@ public sealed partial class ContentAudioSystem
if (player == null) if (player == null)
return null; return null;
var ev = new PlayAmbientMusicEvent();
RaiseLocalEvent(ref ev);
if (ev.Cancelled)
return null;
var ambiences = _proto.EnumeratePrototypes<AmbientMusicPrototype>().ToList(); var ambiences = _proto.EnumeratePrototypes<AmbientMusicPrototype>().ToList();
ambiences.Sort((x, y) => y.Priority.CompareTo(x.Priority)); ambiences.Sort((x, y) => y.Priority.CompareTo(x.Priority));
@@ -259,4 +265,13 @@ public sealed partial class ContentAudioSystem
_sawmill.Warning($"Unable to find fallback ambience track"); _sawmill.Warning($"Unable to find fallback ambience track");
return null; return null;
} }
/// <summary>
/// Fades out the current ambient music temporarily.
/// </summary>
public void DisableAmbientMusic()
{
FadeOut(_ambientMusicStream);
_ambientMusicStream = null;
}
} }

View File

@@ -122,3 +122,9 @@ public sealed partial class ContentAudioSystem : SharedContentAudioSystem
#endregion #endregion
} }
/// <summary>
/// Raised whenever ambient music tries to play.
/// </summary>
[ByRefEvent]
public record struct PlayAmbientMusicEvent(bool Cancelled = false);

View File

@@ -0,0 +1,9 @@
using Content.Shared.Salvage.Expeditions;
namespace Content.Client.Salvage;
[RegisterComponent]
public sealed class SalvageExpeditionComponent : SharedSalvageExpeditionComponent
{
}

View File

@@ -1,8 +1,50 @@
using Content.Client.Audio;
using Content.Shared.Salvage; using Content.Shared.Salvage;
using Content.Shared.Salvage.Expeditions;
using Robust.Client.Player;
using Robust.Shared.GameStates;
namespace Content.Client.Salvage; namespace Content.Client.Salvage;
public sealed class SalvageSystem : SharedSalvageSystem 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;
}
} }

View File

@@ -1,4 +1,5 @@
using Content.Shared.Salvage; using Content.Shared.Salvage;
using Content.Shared.Salvage.Expeditions;
using JetBrains.Annotations; using JetBrains.Annotations;
using Robust.Client.GameObjects; using Robust.Client.GameObjects;

View File

@@ -5,6 +5,7 @@ using Content.Client.UserInterface.Controls;
using Content.Shared.CCVar; using Content.Shared.CCVar;
using Content.Shared.Parallax.Biomes; using Content.Shared.Parallax.Biomes;
using Content.Shared.Salvage; using Content.Shared.Salvage;
using Content.Shared.Salvage.Expeditions;
using Content.Shared.Salvage.Expeditions.Modifiers; using Content.Shared.Salvage.Expeditions.Modifiers;
using Content.Shared.Shuttles.BUIStates; using Content.Shared.Shuttles.BUIStates;
using Robust.Client.AutoGenerated; using Robust.Client.AutoGenerated;

View File

@@ -2,8 +2,8 @@ using Content.Server.Power.Components;
using Content.Server.Power.EntitySystems; using Content.Server.Power.EntitySystems;
using Content.Shared.Audio; using Content.Shared.Audio;
namespace Content.Server.Audio namespace Content.Server.Audio;
{
public sealed class AmbientSoundSystem : SharedAmbientSoundSystem public sealed class AmbientSoundSystem : SharedAmbientSoundSystem
{ {
public override void Initialize() public override void Initialize()
@@ -23,4 +23,3 @@ namespace Content.Server.Audio
SetAmbience(uid, args.Powered); SetAmbience(uid, args.Powered);
} }
} }
}

View File

@@ -1,9 +1,8 @@
using Content.Shared.Random;
using Content.Shared.Salvage; using Content.Shared.Salvage;
using Content.Shared.Salvage.Expeditions;
using Robust.Shared.Audio; using Robust.Shared.Audio;
using Robust.Shared.Prototypes; using Robust.Shared.Prototypes;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom; using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype.List; using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype.List;
namespace Content.Server.Salvage.Expeditions; namespace Content.Server.Salvage.Expeditions;
@@ -12,7 +11,7 @@ namespace Content.Server.Salvage.Expeditions;
/// Designates this entity as holding a salvage expedition. /// Designates this entity as holding a salvage expedition.
/// </summary> /// </summary>
[RegisterComponent] [RegisterComponent]
public sealed class SalvageExpeditionComponent : Component public sealed class SalvageExpeditionComponent : SharedSalvageExpeditionComponent
{ {
public SalvageMissionParams MissionParams = default!; public SalvageMissionParams MissionParams = default!;
@@ -36,9 +35,6 @@ public sealed class SalvageExpeditionComponent : Component
[ViewVariables] public bool Completed = false; [ViewVariables] public bool Completed = false;
[ViewVariables(VVAccess.ReadWrite), DataField("stage")]
public ExpeditionStage Stage = ExpeditionStage.Added;
/// <summary> /// <summary>
/// Countdown audio stream. /// Countdown audio stream.
/// </summary> /// </summary>
@@ -50,7 +46,7 @@ public sealed class SalvageExpeditionComponent : Component
[ViewVariables(VVAccess.ReadWrite), DataField("sound")] [ViewVariables(VVAccess.ReadWrite), DataField("sound")]
public SoundSpecifier Sound = new SoundPathSpecifier("/Audio/Misc/tension_session.ogg") public SoundSpecifier Sound = new SoundPathSpecifier("/Audio/Misc/tension_session.ogg")
{ {
Params = AudioParams.Default.WithVolume(-15), Params = AudioParams.Default.WithVolume(-5),
}; };
/// <summary> /// <summary>
@@ -65,12 +61,3 @@ public sealed class SalvageExpeditionComponent : Component
[ViewVariables(VVAccess.ReadWrite), DataField("rewards", customTypeSerializer: typeof(PrototypeIdListSerializer<EntityPrototype>))] [ViewVariables(VVAccess.ReadWrite), DataField("rewards", customTypeSerializer: typeof(PrototypeIdListSerializer<EntityPrototype>))]
public List<string> Rewards = default!; public List<string> Rewards = default!;
} }
public enum ExpeditionStage : byte
{
Added,
Running,
Countdown,
MusicCountdown,
FinalCountdown,
}

View File

@@ -1,4 +1,5 @@
using Content.Shared.Salvage; using Content.Shared.Salvage;
using Content.Shared.Salvage.Expeditions;
using Robust.Server.GameObjects; using Robust.Server.GameObjects;
namespace Content.Server.Salvage; namespace Content.Server.Salvage;

View File

@@ -2,16 +2,15 @@ using Content.Server.Cargo.Components;
using Content.Server.Cargo.Systems; using Content.Server.Cargo.Systems;
using Content.Server.Salvage.Expeditions; using Content.Server.Salvage.Expeditions;
using Content.Server.Salvage.Expeditions.Structure; using Content.Server.Salvage.Expeditions.Structure;
using Content.Server.Station.Systems;
using Content.Shared.CCVar; using Content.Shared.CCVar;
using Content.Shared.Random;
using Content.Shared.Random.Helpers;
using Content.Shared.Examine; using Content.Shared.Examine;
using Content.Shared.Salvage; using Content.Shared.Salvage;
using Robust.Shared.CPUJob.JobQueues; using Robust.Shared.CPUJob.JobQueues;
using Robust.Shared.CPUJob.JobQueues.Queues; using Robust.Shared.CPUJob.JobQueues.Queues;
using System.Linq; using System.Linq;
using System.Threading; using System.Threading;
using Content.Shared.Salvage.Expeditions;
using Robust.Shared.GameStates;
namespace Content.Server.Salvage; namespace Content.Server.Salvage;
@@ -42,6 +41,7 @@ public sealed partial class SalvageSystem
SubscribeLocalEvent<SalvageExpeditionComponent, ComponentShutdown>(OnExpeditionShutdown); SubscribeLocalEvent<SalvageExpeditionComponent, ComponentShutdown>(OnExpeditionShutdown);
SubscribeLocalEvent<SalvageExpeditionComponent, EntityUnpausedEvent>(OnExpeditionUnpaused); SubscribeLocalEvent<SalvageExpeditionComponent, EntityUnpausedEvent>(OnExpeditionUnpaused);
SubscribeLocalEvent<SalvageExpeditionComponent, ComponentGetState>(OnExpeditionGetState);
SubscribeLocalEvent<SalvageStructureComponent, ExaminedEvent>(OnStructureExamine); SubscribeLocalEvent<SalvageStructureComponent, ExaminedEvent>(OnStructureExamine);
@@ -51,6 +51,14 @@ public sealed partial class SalvageSystem
_configurationManager.OnValueChanged(CCVars.SalvageExpeditionFailedCooldown, SetFailedCooldownChange); _configurationManager.OnValueChanged(CCVars.SalvageExpeditionFailedCooldown, SetFailedCooldownChange);
} }
private void OnExpeditionGetState(EntityUid uid, SalvageExpeditionComponent component, ref ComponentGetState args)
{
args.State = new SalvageExpeditionComponentState()
{
Stage = component.Stage
};
}
private void ShutdownExpeditions() private void ShutdownExpeditions()
{ {
_configurationManager.UnsubValueChanged(CCVars.SalvageExpeditionCooldown, SetCooldownChange); _configurationManager.UnsubValueChanged(CCVars.SalvageExpeditionCooldown, SetCooldownChange);

View File

@@ -8,9 +8,7 @@ using Content.Shared.Chat;
using Content.Shared.Humanoid; using Content.Shared.Humanoid;
using Content.Shared.Mobs.Components; using Content.Shared.Mobs.Components;
using Content.Shared.Mobs.Systems; using Content.Shared.Mobs.Systems;
using Content.Shared.Salvage; using Content.Shared.Salvage.Expeditions;
using Content.Shared.Shuttles.Components;
using Robust.Shared.Audio;
using Robust.Shared.Map.Components; using Robust.Shared.Map.Components;
using Robust.Shared.Player; using Robust.Shared.Player;
using Robust.Shared.Utility; using Robust.Shared.Utility;
@@ -110,6 +108,7 @@ public sealed partial class SalvageSystem
Announce(args.MapUid, Loc.GetString("salvage-expedition-announcement-dungeon", ("direction", component.DungeonLocation.GetDir()))); Announce(args.MapUid, Loc.GetString("salvage-expedition-announcement-dungeon", ("direction", component.DungeonLocation.GetDir())));
component.Stage = ExpeditionStage.Running; component.Stage = ExpeditionStage.Running;
Dirty(component);
} }
private void OnFTLStarted(ref FTLStartedEvent ev) private void OnFTLStarted(ref FTLStartedEvent ev)
@@ -158,6 +157,7 @@ public sealed partial class SalvageSystem
if (comp.Stage < ExpeditionStage.FinalCountdown && remaining < TimeSpan.FromSeconds(30)) if (comp.Stage < ExpeditionStage.FinalCountdown && remaining < TimeSpan.FromSeconds(30))
{ {
comp.Stage = ExpeditionStage.FinalCountdown; comp.Stage = ExpeditionStage.FinalCountdown;
Dirty(comp);
Announce(uid, Loc.GetString("salvage-expedition-announcement-countdown-seconds", ("duration", TimeSpan.FromSeconds(30).Seconds))); Announce(uid, Loc.GetString("salvage-expedition-announcement-countdown-seconds", ("duration", TimeSpan.FromSeconds(30).Seconds)));
} }
else if (comp.Stage < ExpeditionStage.MusicCountdown && remaining < TimeSpan.FromMinutes(2)) else if (comp.Stage < ExpeditionStage.MusicCountdown && remaining < TimeSpan.FromMinutes(2))
@@ -165,11 +165,13 @@ public sealed partial class SalvageSystem
// TODO: Some way to play audio attached to a map for players. // TODO: Some way to play audio attached to a map for players.
comp.Stream = _audio.PlayGlobal(comp.Sound, Filter.BroadcastMap(Comp<MapComponent>(uid).MapId), true); comp.Stream = _audio.PlayGlobal(comp.Sound, Filter.BroadcastMap(Comp<MapComponent>(uid).MapId), true);
comp.Stage = ExpeditionStage.MusicCountdown; comp.Stage = ExpeditionStage.MusicCountdown;
Dirty(comp);
Announce(uid, Loc.GetString("salvage-expedition-announcement-countdown-minutes", ("duration", TimeSpan.FromMinutes(2).Minutes))); Announce(uid, Loc.GetString("salvage-expedition-announcement-countdown-minutes", ("duration", TimeSpan.FromMinutes(2).Minutes)));
} }
else if (comp.Stage < ExpeditionStage.Countdown && remaining < TimeSpan.FromMinutes(5)) else if (comp.Stage < ExpeditionStage.Countdown && remaining < TimeSpan.FromMinutes(5))
{ {
comp.Stage = ExpeditionStage.Countdown; comp.Stage = ExpeditionStage.Countdown;
Dirty(comp);
Announce(uid, Loc.GetString("salvage-expedition-announcement-countdown-minutes", ("duration", TimeSpan.FromMinutes(5).Minutes))); Announce(uid, Loc.GetString("salvage-expedition-announcement-countdown-minutes", ("duration", TimeSpan.FromMinutes(5).Minutes)));
} }
// Auto-FTL out any shuttles // Auto-FTL out any shuttles

View File

@@ -1,7 +1,7 @@
using Robust.Shared.GameStates; using Robust.Shared.GameStates;
namespace Content.Shared.Audio namespace Content.Shared.Audio;
{
public abstract class SharedAmbientSoundSystem : EntitySystem public abstract class SharedAmbientSoundSystem : EntitySystem
{ {
public override void Initialize() public override void Initialize()
@@ -63,4 +63,3 @@ namespace Content.Shared.Audio
}; };
} }
} }
}

View File

@@ -0,0 +1,10 @@
namespace Content.Shared.Salvage.Expeditions;
public enum ExpeditionStage : byte
{
Added,
Running,
Countdown,
MusicCountdown,
FinalCountdown,
}

View File

@@ -1,10 +1,9 @@
using Content.Shared.Salvage.Expeditions;
using Content.Shared.Salvage.Expeditions.Modifiers; using Content.Shared.Salvage.Expeditions.Modifiers;
using Robust.Shared.GameStates; using Robust.Shared.GameStates;
using Robust.Shared.Serialization; using Robust.Shared.Serialization;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom; using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom;
namespace Content.Shared.Salvage; namespace Content.Shared.Salvage.Expeditions;
[Serializable, NetSerializable] [Serializable, NetSerializable]
public sealed class SalvageExpeditionConsoleState : BoundUserInterfaceState public sealed class SalvageExpeditionConsoleState : BoundUserInterfaceState

View File

@@ -0,0 +1,17 @@
using Robust.Shared.GameStates;
using Robust.Shared.Serialization;
namespace Content.Shared.Salvage.Expeditions;
[NetworkedComponent]
public abstract class SharedSalvageExpeditionComponent : Component
{
[ViewVariables(VVAccess.ReadWrite), DataField("stage")]
public ExpeditionStage Stage = ExpeditionStage.Added;
}
[Serializable, NetSerializable]
public sealed class SalvageExpeditionComponentState : ComponentState
{
public ExpeditionStage Stage;
}