From b1038628e7df2b828d4d127e596aa9ab05d893da Mon Sep 17 00:00:00 2001 From: Joonas Rikkonen Date: Tue, 23 Apr 2019 11:22:04 +0300 Subject: [PATCH] (f314ad2a3) New music track when the end of the level is reached, decrease the volume of the background music layer 0 when there's multiple tracks playing at the same time --- .../Source/Sounds/SoundPlayer.cs | 27 ++++++++++++++----- 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/Barotrauma/BarotraumaClient/Source/Sounds/SoundPlayer.cs b/Barotrauma/BarotraumaClient/Source/Sounds/SoundPlayer.cs index 0a1abe7ea..9753a9f4b 100644 --- a/Barotrauma/BarotraumaClient/Source/Sounds/SoundPlayer.cs +++ b/Barotrauma/BarotraumaClient/Source/Sounds/SoundPlayer.cs @@ -35,6 +35,7 @@ namespace Barotrauma { public readonly string File; public readonly string Type; + public readonly bool DuckVolume; public readonly Vector2 IntensityRange; @@ -43,6 +44,7 @@ namespace Barotrauma this.File = Path.GetFullPath(element.GetAttributeString("file", "")); this.Type = element.GetAttributeString("type", "").ToLowerInvariant(); this.IntensityRange = element.GetAttributeVector2("intensityrange", new Vector2(0.0f, 100.0f)); + this.DuckVolume = element.GetAttributeBool("duckvolume", false); } } @@ -277,6 +279,7 @@ namespace Barotrauma movementSoundVolume = 0.0f; } } + } if (waterAmbiences.Count > 1) { @@ -515,7 +518,7 @@ namespace Barotrauma //switch the music if nothing playing atm or the currently playing clip is not suitable anymore else if (targetMusic[0] == null || currentMusic[0] == null || !suitableMusic.Any(m => m.File == currentMusic[0].Filename)) { - targetMusic[0] = suitableMusic.GetRandom(); + targetMusic[0] = suitableMusic.GetRandom(); } //get the appropriate intensity layers for current situation @@ -550,6 +553,7 @@ namespace Barotrauma updateMusicTimer = UpdateMusicInterval; } + int activeTrackCount = targetMusic.Count(m => m != null); for (int i = 0; i < MaxMusicChannels; i++) { //nothing should be playing on this channel @@ -589,7 +593,12 @@ namespace Barotrauma musicChannel[i] = currentMusic[i].Play(0.0f, "music"); musicChannel[i].Looping = true; } - musicChannel[i].Gain = MathHelper.Lerp(musicChannel[i].Gain, 1.0f, MusicLerpSpeed * deltaTime); + float targetGain = 1.0f; + if (targetMusic[i].DuckVolume) + { + targetGain = (float)Math.Sqrt(1.0f / activeTrackCount); + } + musicChannel[i].Gain = MathHelper.Lerp(musicChannel[i].Gain, targetGain, MusicLerpSpeed * deltaTime); } } } @@ -657,8 +666,7 @@ namespace Barotrauma foreach (Character character in Character.CharacterList) { if (character.IsDead || !character.Enabled) continue; - EnemyAIController enemyAI = character.AIController as EnemyAIController; - if (enemyAI == null || (!enemyAI.AttackHumans && !enemyAI.AttackRooms)) continue; + if (!(character.AIController is EnemyAIController enemyAI) || (!enemyAI.AttackHumans && !enemyAI.AttackRooms)) continue; if (targetSubmarine != null) { @@ -676,9 +684,16 @@ namespace Barotrauma } } - if (GameMain.GameSession != null && Timing.TotalTime < GameMain.GameSession.RoundStartTime + 120.0) + if (GameMain.GameSession != null) { - return "start"; + if (Submarine.Loaded != null && Level.Loaded != null && Submarine.MainSub.AtEndPosition) + { + return "levelend"; + } + if (Timing.TotalTime < GameMain.GameSession.RoundStartTime + 120.0) + { + return "start"; + } } return "default";