Exemple #1
0
        static float GetMoonLordSpawnFade(BgmEntry current)
        {
            float ret = 1f;

            if (NPC.MoonLordCountdown > 0)
            {
                ret  = NPC.MoonLordCountdown / 3600f;
                ret *= ret; // fade out exponentially

                if (NPC.MoonLordCountdown > 720)
                {
                    ret = MathHelper.Lerp(0f, 1f, ret);
                }
                else // mute completely for the last 12 seconds
                {
                    ret     = 0f;
                    current = null;
                }

                // just spawned -> fade back in
                if (NPC.MoonLordCountdown == 1 && current != null /*&& curMusic < MusicAmt*/)
                {
                    current.fade = 0f;
                }
            }

            return(ret);
        }
Exemple #2
0
 internal static void Reset()
 {
     Title = FrostMoon = PumpkinMoon
                             = MoonLord = MartianMadness = LunarPillar = Plantera = Boss2 = Boss1 = Boss3 = Golem = QueenBee = Pirates = GoblinArmy
                                                                                                                                             = Underworld = Eclipse = Space = Lihzahrd = Mushrooms = UgCorruption = Corruption = UgCrimson = Crimson = Dungeon = Meteor = Jungle = Snow = Ice
                                                                                                                                                                                                                                                                                              = UgHallow = UgDesert = Underground = BloodMoon = Rain = Night = Hallow = Ocean = Desert = Day
                                                                                                                                                                                                                                                                                                                                                                                             = Ambient = null;
 }
Exemple #3
0
        static void UpdateAmbientEntry(BgmEntry current, BgmEntry e)
        {
            var m = e.Music;

            if (e.ShouldPlay())
            {
                // stop if playing & volume is zero
                if (Main.ambientVolume <= 0f)
                {
                    if (m.State == SoundState.Playing)
                    {
                        m.Stop();
                    }
                }
                // play if not already
                else if (m.State != SoundState.Playing)
                {
                    m.Play();
                }
                else if (m.State == SoundState.Paused)
                {
                    m.Play();
                }
                // fade in if needed
                else
                {
                    e.fade = MathHelper.Clamp(e.fade + fade_delta, 0f, 1f);
                }
            }
            else if (m.State == SoundState.Playing)
            {
                // fade out if needed
                if (current != null && current.fade > 0.25f)
                {
                    e.fade -= fade_delta;
                }
                // stop playing if nothing is
                else if (current == null)
                {
                    e.fade = 0f;
                }

                if (e.fade <= 0f)
                {
                    m.Stop();
                }
            }
            else
            {
                e.fade = 0f;
            }
        }
Exemple #4
0
        internal static void FillVanilla()
        {
            // do not include ambient background
            MusicBoxes = Enumerable.Range(1, 37).Select(c => new BgmEntry(Bgm.VanillaBgmOf(MusicBoxIdToCueId(c)), BgmPriority.MusicBox, () => Main.musicBox == c)).ToArray();

            Title = new BgmEntry(Bgm.VanillaBgmOf(6), BgmPriority.Title, () => Main.gameMenu);

            FrostMoon   = new BgmEntry(Bgm.VanillaBgmOf(32), BgmPriority.Event, () => Main.snowMoon);
            PumpkinMoon = new BgmEntry(Bgm.VanillaBgmOf(30), BgmPriority.Event, () => Main.pumpkinMoon);

            MoonLord       = new BgmEntry(Bgm.VanillaBgmOf(38), BgmPriority.Boss, () => Bgm.justScanned ? (Bgm.bossMusicId & BossBgms.MoonLord) != 0 : Bgm.AnyNPCsForMusic(MoonLordNPCs));
            MartianMadness = new BgmEntry(Bgm.VanillaBgmOf(37), BgmPriority.Boss, () => Bgm.justScanned ? (Bgm.bossMusicId & BossBgms.MartianMadness) != 0 : Bgm.AnyNPCsForMusic(MartianMadnessNPCs));
            LunarPillar    = new BgmEntry(Bgm.VanillaBgmOf(34), BgmPriority.Boss, () => Bgm.justScanned ? (Bgm.bossMusicId & BossBgms.LunarPillar) != 0 : Bgm.AnyNPCsForMusic(LunarPillarNPCs));
            Plantera       = new BgmEntry(Bgm.VanillaBgmOf(24), BgmPriority.Boss, () => Bgm.justScanned ? (Bgm.bossMusicId & BossBgms.Plantera) != 0 : Bgm.AnyNPCsForMusic(PlanteraNPCs));
            Boss2          = new BgmEntry(Bgm.VanillaBgmOf(12), BgmPriority.Boss, () => Bgm.justScanned ? (Bgm.bossMusicId & BossBgms.Boss2) != 0 : Bgm.AnyNPCsForMusic(Boss2NPCs));
            Boss1          = new BgmEntry(Bgm.VanillaBgmOf(5), BgmPriority.Boss, () => Bgm.justScanned ? (Bgm.bossMusicId & BossBgms.Boss1) != 0 : Bgm.AnyNPCsForMusic(IsBoss1Boss));
            Boss3          = new BgmEntry(Bgm.VanillaBgmOf(13), BgmPriority.Boss, () => Bgm.justScanned ? (Bgm.bossMusicId & BossBgms.Boss3) != 0 : Bgm.AnyNPCsForMusic(Boss3NPCs));
            Golem          = new BgmEntry(Bgm.VanillaBgmOf(17), BgmPriority.Boss, () => Bgm.justScanned ? (Bgm.bossMusicId & BossBgms.Golem) != 0 : Bgm.AnyNPCsForMusic(GolemNPCs));
            QueenBee       = new BgmEntry(Bgm.VanillaBgmOf(25), BgmPriority.Boss, () => Bgm.justScanned ? (Bgm.bossMusicId & BossBgms.QueenBee) != 0 : Bgm.AnyNPCsForMusic(QueenBeeNPCs));
            Pirates        = new BgmEntry(Bgm.VanillaBgmOf(35), BgmPriority.Boss, () => Bgm.justScanned ? (Bgm.bossMusicId & BossBgms.Pirates) != 0 : Bgm.AnyNPCsForMusic(PiratesNPCs));
            GoblinArmy     = new BgmEntry(Bgm.VanillaBgmOf(39), BgmPriority.Boss, () => Bgm.justScanned ? (Bgm.bossMusicId & BossBgms.GoblinArmy) != 0 : Bgm.AnyNPCsForMusic(GoblinArmyNPCs));

            Underworld   = new BgmEntry(Bgm.VanillaBgmOf(36), BgmPriority.Biome, () => Main.player[Main.myPlayer].position.Y > (Main.maxTilesY - 200) * 16);
            Eclipse      = new BgmEntry(Bgm.VanillaBgmOf(27), BgmPriority.Biome, () => Main.eclipse && Main.player[Main.myPlayer].position.Y < Main.worldSurface * 16 + Main.screenHeight / 2);
            Space        = new BgmEntry(Bgm.VanillaBgmOf(15), BgmPriority.Biome, IsInSpace);
            Lihzahrd     = new BgmEntry(Bgm.VanillaBgmOf(26), BgmPriority.Biome, () => Main.tile[(int)(Main.player[Main.myPlayer].Center.X / 16f), (int)(Main.player[Main.myPlayer].Center.Y / 16f)].wall == WallID.LihzahrdBrickUnsafe);
            Mushrooms    = new BgmEntry(Bgm.VanillaBgmOf(29), BgmPriority.Biome, () => (Main.bgStyle == 9 && Main.player[Main.myPlayer].position.Y < Main.worldSurface * 16 + Main.screenHeight / 2) || Main.ugBack == 2);
            UgCorruption = new BgmEntry(Bgm.VanillaBgmOf(10), BgmPriority.Biome, () => Main.player[Main.myPlayer].ZoneCorrupt && IsUnderground());
            Corruption   = new BgmEntry(Bgm.VanillaBgmOf(8), BgmPriority.Biome, () => Main.player[Main.myPlayer].ZoneCorrupt);
            UgCrimson    = new BgmEntry(Bgm.VanillaBgmOf(33), BgmPriority.Biome, () => Main.player[Main.myPlayer].ZoneCrimson && IsUnderground());
            Crimson      = new BgmEntry(Bgm.VanillaBgmOf(16), BgmPriority.Biome, () => Main.player[Main.myPlayer].ZoneCrimson);
            Dungeon      = new BgmEntry(Bgm.VanillaBgmOf(23), BgmPriority.Biome, () => Main.player[Main.myPlayer].ZoneDungeon);
            Meteor       = new BgmEntry(Bgm.VanillaBgmOf(2), BgmPriority.Biome, () => Main.player[Main.myPlayer].ZoneMeteor);
            Jungle       = new BgmEntry(Bgm.VanillaBgmOf(7), BgmPriority.Biome, () => Main.player[Main.myPlayer].ZoneJungle);
            Snow         = new BgmEntry(Bgm.VanillaBgmOf(20), BgmPriority.Biome, () => Main.player[Main.myPlayer].ZoneSnow && IsUnderground());
            Ice          = new BgmEntry(Bgm.VanillaBgmOf(14), BgmPriority.Biome, () => Main.player[Main.myPlayer].ZoneSnow);

            UgHallow    = new BgmEntry(Bgm.VanillaBgmOf(11), BgmPriority.Environment, () => IsUnderground() && Main.player[Main.myPlayer].ZoneHoly);
            UgDesert    = new BgmEntry(Bgm.VanillaBgmOf(21), BgmPriority.Environment, () => IsUnderground() && Main.sandTiles > 2200);
            Underground = new BgmEntry(new AltSupportingBgm(Bgm.VanillaBgmOf(4), Bgm.VanillaBgmOf(31), SwitchMode.Alternate), BgmPriority.Environment, IsUnderground);
            BloodMoon   = new BgmEntry(Bgm.VanillaBgmOf(2), BgmPriority.Environment, () => Main.bloodMoon);
            Rain        = new BgmEntry(Bgm.VanillaBgmOf(19), BgmPriority.Environment, () => Main.cloudAlpha > 0f && !Main.gameMenu);
            Night       = new BgmEntry(Bgm.VanillaBgmOf(3), BgmPriority.Environment, () => !Main.dayTime);
            Hallow      = new BgmEntry(Bgm.VanillaBgmOf(9), BgmPriority.Environment, () => Main.player[Main.myPlayer].ZoneHoly);
            Ocean       = new BgmEntry(Bgm.VanillaBgmOf(22), BgmPriority.Environment, IsInOcean);
            Desert      = new BgmEntry(Bgm.VanillaBgmOf(21), BgmPriority.Environment, () => Main.sandTiles > 2200);
            Day         = new BgmEntry(new AltSupportingBgm(Bgm.VanillaBgmOf(1), Bgm.VanillaBgmOf(18), SwitchMode.Random), BgmPriority.Environment, () => Main.dayTime);

            Ambient = new BgmEntry(Bgm.VanillaBgmOf(28), BgmPriority.Ambient, () => Main.cloudAlpha > 0f && Main.player[Main.myPlayer].position.Y < Main.worldSurface * 16 + Main.screenHeight / 2 && !Main.player[Main.myPlayer].ZoneSnow);

            PopulateDict();
        }
Exemple #5
0
        static void UpdateCurrentEntry(BgmEntry e)
        {
            var m = e.Music;

            // play if not already
            if (m.State != SoundState.Playing)
            {
                m.Play();
            }
            else // fade in if needed
            {
                e.fade = MathHelper.Clamp(e.fade + fade_delta, 0f, 1f);
            }
        }
Exemple #6
0
        static void UpdateOtherEntry(BgmEntry current, BgmEntry e)
        {
            var m = e.Music;

            if (m.State != SoundState.Playing)
            {
                e.fade = 0f;
                return;
            }

            if (e.fade > 0.25f)
            {
                e.fade -= fade_delta;
            }
            else //if (current == null)
            {
                e.fade = 0f;
            }

            if (e.fade <= 0f)
            {
                m.Stop();
            }
        }
Exemple #7
0
        internal static void Update(Main _)
        {
            if (Main.musicVolume <= 0f || Main.dedServ)
            {
                return;
            }

            if (current != null)
            {
                if (HandleInactiveWindow(Entries.Values))
                {
                    return;
                }
            }

            ScanForVanillaBossMusics();
            justScanned = true;

            var newEntry = Entries.Select(e => e.Value).Where(e =>
                                                              e.Priority == BgmPriority.Title == Main.gameMenu &&
                                                              e.Priority != BgmPriority.Ambient &&
                                                              e.ShouldPlay() // do not call ShouldPlay for ambient BGMs, those are managed in UpdateAmbientEntry
                                                              ).OrderByDescending(e =>
                                                                                  e.Priority
                                                                                  ).FirstOrDefault();

            if (newEntry.Priority < BgmPriority.Boss && bossMusicId != BossBgms.None)
            {
                if (bossMusicId == BossBgms.Custom)
                {
                    newEntry = bossMusic_custom.Resolve();
                }
            }

            Main.engine.Update();

            HookManager.GameBehaviour.UpdateMusic(ref newEntry);

            float moonLordSpawnFade = GetMoonLordSpawnFade(newEntry);

            foreach (var e in Entries.Values)
            {
                if (e.Priority == BgmPriority.Ambient)
                {
                    UpdateAmbientEntry(newEntry, e);
                }
                else if (e.Music == newEntry.Music)
                {
                    UpdateCurrentEntry(e);
                }
                else
                {
                    UpdateOtherEntry(newEntry, e);
                }

                var m = e.Music;
                if (m.State == SoundState.Playing)
                {
                    var nv = e.fade * Main.musicVolume * (e.Priority == BgmPriority.Ambient ? 1f : moonLordSpawnFade);

#pragma warning disable RECS0018
                    if (nv != m.Volume) // getting volume is way faster than setting using the XACT and XAudio APIs
#pragma warning restore RECS0018
                    {
                        m.Volume = nv;
                    }
                }
            }

            current = newEntry;

            justScanned = false;
        }