diff --git a/CalamityConfig.cs b/CalamityConfig.cs index eedd4de7ed..2a46a809b2 100644 --- a/CalamityConfig.cs +++ b/CalamityConfig.cs @@ -175,6 +175,27 @@ namespace CalamityMod public float FlightBarPosY { get; set; } #endregion + #region Music Events + [Header("MusicEvents")] + + [BackgroundColor(192, 54, 64, 192)] + [DefaultValue(true)] + public bool Interlude1 { get; set; } + + [BackgroundColor(192, 54, 64, 192)] + [DefaultValue(true)] + public bool Interlude2 { get; set; } + + [BackgroundColor(192, 54, 64, 192)] + [DefaultValue(true)] + public bool Interlude3 { get; set; } + + [BackgroundColor(192, 54, 64, 192)] + [DefaultValue(true)] + public bool DevourerofGodsEulogy { get; set; } + + #endregion + #region General Gameplay Changes [Header("Gameplay")] diff --git a/Localization/en-US/Mods.CalamityMod.Configs.hjson b/Localization/en-US/Mods.CalamityMod.Configs.hjson index ac8eba1fec..eed2a12d65 100644 --- a/Localization/en-US/Mods.CalamityMod.Configs.hjson +++ b/Localization/en-US/Mods.CalamityMod.Configs.hjson @@ -8,6 +8,7 @@ CalamityConfig: { Revengeance: Revengeance Mode Changes UI: UI Changes BaseBoosts: Base Stat Boosts + MusicEvents: Music Events } AdrenalineMeterPosX: { @@ -130,6 +131,11 @@ CalamityConfig: { Tooltip: Adds an array of debuff icons above all bosses and minibosses. } + DevourerofGodsEulogy: { + Label: "[i:CalamityModMusic/DevourerofGodsEulogyMusicBox] Eulogy for the Ego" + Tooltip: Plays Calamity Mod OST - "Scourge of The Universe (Eulogy for The Ego)" after The Devourer of Gods has been defeated. + } + EarlyHardmodeProgressionRework: { Label: "[i:Pwnhammer] Early Hardmode Progression Rework" Tooltip: @@ -226,6 +232,21 @@ CalamityConfig: { ''' } + Interlude1: { + Label: "[i:CalamityModMusic/Interlude1MusicBox] Interlude 1" + Tooltip: Plays Calamity Mod OST - Interlude 1, "Silence before the storms", after The Calamitas Clone has been defeated. + } + + Interlude2: { + Label: "[i:CalamityModMusic/Interlude2MusicBox] Interlude 2" + Tooltip: Plays Calamity Mod OST - Interlude 2, "Storms before the catastrophes", after The Moon Lord has been defeated. + } + + Interlude3: { + Label: "[i:CalamityModMusic/Interlude3MusicBox] Interlude 3" + Tooltip: Plays Calamity Mod OST - Interlude 3, "Catastrophes before the calamity", after Yharon has been defeated. + } + MeterPosLock: { Label: "[i:GemLockTopaz] Lock Meter Positions" Tooltip: diff --git a/Systems/MusicEventSystem.cs b/Systems/MusicEventSystem.cs index 39e1baf3c9..803a27df18 100644 --- a/Systems/MusicEventSystem.cs +++ b/Systems/MusicEventSystem.cs @@ -10,7 +10,7 @@ using Terraria.ModLoader.IO; namespace CalamityMod.Systems { - public record class MusicEventEntry(string Id, int Song, TimeSpan Length, TimeSpan IntroSilence, TimeSpan OutroSilence, Func ShouldPlay); + public record class MusicEventEntry(string Id, int Song, TimeSpan Length, TimeSpan IntroSilence, TimeSpan OutroSilence, Func ShouldPlay, Func Enabled); public class MusicEventSystem : ModSystem { @@ -25,6 +25,8 @@ namespace CalamityMod.Systems public static int LastPlayedEvent { get; set; } = -1; + public static TimeSpan? OutroSilence { get; set; } = null; + // This allows skipping track fade in public static bool NoFade { get; set; } = false; @@ -43,18 +45,32 @@ namespace CalamityMod.Systems public override void OnModLoad() { - static void AddEntry(string eventId, string songName, TimeSpan length, Func shouldPlay, TimeSpan? introSilence = null, TimeSpan? outroSilence = null) + static void AddEntry(string eventId, string songName, TimeSpan length, Func shouldPlay, Func enabled, TimeSpan? introSilence = null, TimeSpan? outroSilence = null) { - MusicEventEntry entry = new(eventId, CalamityMod.Instance.GetMusicFromMusicMod(songName).Value, length, introSilence ?? TimeSpan.Zero, outroSilence ?? TimeSpan.FromSeconds(3), shouldPlay); + MusicEventEntry entry = new(eventId, CalamityMod.Instance.GetMusicFromMusicMod(songName).Value, length, introSilence ?? TimeSpan.Zero, outroSilence ?? TimeSpan.Zero, shouldPlay, enabled); EventCollection.Add(entry); } - AddEntry("CloneDefeated", "Interlude1", TimeSpan.FromSeconds(214.577d), () => DownedBossSystem.downedCalamitasClone, introSilence: TimeSpan.FromSeconds(5f)); - AddEntry("MLDefeated", "Interlude2", TimeSpan.FromSeconds(160.989d), () => NPC.downedMoonlord); - AddEntry("YharonDefeated", "Interlude3", TimeSpan.FromSeconds(295.932d), () => DownedBossSystem.downedYharon, outroSilence: TimeSpan.Zero); + AddEntry("CloneDefeated", "Interlude1", TimeSpan.FromSeconds(214.577d), + () => DownedBossSystem.downedCalamitasClone, () => CalamityConfig.Instance.Interlude1); - AddEntry("DoGDefeated", "DevourerofGodsEulogy", TimeSpan.FromSeconds(203.620d), () => DownedBossSystem.downedDoG, introSilence: TimeSpan.FromSeconds(5f)); - AddEntry("ScalDefeated", "CalamitasDefeat_LongFade", TimeSpan.FromSeconds(58.689d), () => CalamityGlobalNPC.SCalAcceptance != -1); + AddEntry("MLDefeated", "Interlude2", TimeSpan.FromSeconds(191.912d), () => NPC.downedMoonlord, + () => CalamityConfig.Instance.Interlude2, outroSilence: TimeSpan.FromSeconds(1f)); + + // Alternative Interlude 2 -> AddEntry("MLDefeated", "Interlude2_CutIntro", TimeSpan.FromSeconds(160.989d), + // () => NPC.downedMoonlord, () => CalamityConfig.Instance.Interlude2, + // outroSilence: TimeSpan.FromSeconds(1f)); + + AddEntry("YharonDefeated", "Interlude3", TimeSpan.FromSeconds(295.932d), + () => DownedBossSystem.downedYharon, () => CalamityConfig.Instance.Interlude3); + + AddEntry("DoGDefeated", "DevourerofGodsEulogy", TimeSpan.FromSeconds(203.620d), + () => DownedBossSystem.downedDoG, () => CalamityConfig.Instance.DevourerofGodsEulogy, + introSilence: TimeSpan.FromSeconds(7.5f)); + + // Acceptance is NOT toggleable in the config + AddEntry("ScalDefeated", "CalamitasDefeat_LongFade", TimeSpan.FromSeconds(58.689d), + () => CalamityGlobalNPC.SCalAcceptance != -1, () => true); } public override void Unload() => EventCollection.Clear(); @@ -84,7 +100,7 @@ namespace CalamityMod.Systems if (TrackEnd is not null) { // `silence` is the time after a track ends before music goes back to normal - TimeSpan silence = TimeSpan.FromSeconds(3); + TimeSpan silence = OutroSilence.Value; TimeSpan postTrack = DateTime.Now - TrackEnd.Value; // Play silence for the time specified @@ -98,6 +114,7 @@ namespace CalamityMod.Systems { LastPlayedEvent = -1; TrackEnd = null; + OutroSilence = null; } return; @@ -112,21 +129,28 @@ namespace CalamityMod.Systems // Make sure the event hasn't already played and SHOULD play if (!PlayedEvents.Contains(musicEvent.Id) && musicEvent.ShouldPlay()) { - // Assign the current event and start time - CurrentEvent = musicEvent; - TrackStart = DateTime.Now + musicEvent.IntroSilence; + // Even if an event isn't marked as enabled, it should be counted + // as "played" so it isn't played when the player doesn't expect it PlayedEvents.Add(musicEvent.Id); - - // On clients, use a background thread to make sure the track always plays for exactly - // the specified length, regardless of if the game gets minimized, lags, or time becomes - // detangled from a consistent 60fps in any other way - if (!Main.dedServ) + + // Events are always enabled on the server + if (Main.dedServ || musicEvent.Enabled()) { - EventTrackerThread = new(WatchMusicEvent); - EventTrackerThread.Start(); - } + // Assign the current event and start time + CurrentEvent = musicEvent; + TrackStart = DateTime.Now + musicEvent.IntroSilence; - break; + // On clients, use a background thread to make sure the track always plays for exactly + // the specified length, regardless of if the game gets minimized, lags, or time becomes + // detangled from a consistent 60fps in any other way + if (!Main.dedServ) + { + EventTrackerThread = new(WatchMusicEvent); + EventTrackerThread.Start(); + } + + break; + } } } } @@ -159,6 +183,7 @@ namespace CalamityMod.Systems TrackEnd = DateTime.Now; LastPlayedEvent = CurrentEvent.Song; + OutroSilence = CurrentEvent.OutroSilence; TrackStart = null; CurrentEvent = null; @@ -176,14 +201,14 @@ namespace CalamityMod.Systems while (CurrentEvent is not null) { - bool musicPaused = Main.instance.IsActive; + bool musicPaused = !Main.instance.IsActive; if (musicPaused && !minimized.HasValue) minimized = DateTime.Now; else if (!musicPaused && minimized.HasValue) { - TrackStart = TrackStart.Value + (DateTime.Now - minimized.Value); + TrackStart += DateTime.Now - minimized.Value; minimized = null; } }