From ac8575e2f575eea7f278671f91280c8ba9010f2b Mon Sep 17 00:00:00 2001 From: Ozzatron Date: Thu, 7 Dec 2023 22:08:31 -0500 Subject: [PATCH] Implement all new Xeroc Boss Rush dialogue. Now adding delays. --- Enums/BossRushDialoguePhase.cs | 16 ++ Events/BossRushEvent.cs | 41 ++-- Items/SummonItems/Terminus.cs | 14 +- Projectiles/Typeless/BossRushEffectThing.cs | 9 +- Projectiles/Typeless/TerminusHoldout.cs | 1 - Systems/BossRushDialogueSystem.cs | 197 ++++++++++++++++++++ 6 files changed, 251 insertions(+), 27 deletions(-) create mode 100644 Enums/BossRushDialoguePhase.cs create mode 100644 Systems/BossRushDialogueSystem.cs diff --git a/Enums/BossRushDialoguePhase.cs b/Enums/BossRushDialoguePhase.cs new file mode 100644 index 0000000000..043e760215 --- /dev/null +++ b/Enums/BossRushDialoguePhase.cs @@ -0,0 +1,16 @@ +namespace CalamityMod.Enums +{ + public enum BossRushDialoguePhase : short + { + None = -1, + Start = 0, + TierOneComplete = 1, + TierTwoComplete = 2, + TierThreeComplete = 3, + TierFourComplete = 4, + End = 5, + + StartRepeat = 6, + EndRepeat = 7, + } +} diff --git a/Events/BossRushEvent.cs b/Events/BossRushEvent.cs index 9b420d00f5..c3cdb7d6a5 100644 --- a/Events/BossRushEvent.cs +++ b/Events/BossRushEvent.cs @@ -1,8 +1,10 @@ -using CalamityMod.Buffs.StatDebuffs; +using System; +using System.Collections.Generic; +using System.Linq; +using CalamityMod.Buffs.StatDebuffs; using CalamityMod.CalPlayer; +using CalamityMod.Enums; using CalamityMod.Items.SummonItems; -using CalamityMod.NPCs.Abyss; -using CalamityMod.NPCs.PrimordialWyrm; using CalamityMod.NPCs.AquaticScourge; using CalamityMod.NPCs.AstrumAureus; using CalamityMod.NPCs.AstrumDeus; @@ -17,8 +19,6 @@ using CalamityMod.NPCs.DevourerofGods; using CalamityMod.NPCs.ExoMechs; using CalamityMod.NPCs.ExoMechs.Ares; using CalamityMod.NPCs.ExoMechs.Thanatos; -using ApolloBoss = CalamityMod.NPCs.ExoMechs.Apollo.Apollo; -using ArtemisBoss = CalamityMod.NPCs.ExoMechs.Artemis.Artemis; using CalamityMod.NPCs.HiveMind; using CalamityMod.NPCs.Leviathan; using CalamityMod.NPCs.NormalNPCs; @@ -36,18 +36,17 @@ using CalamityMod.NPCs.SupremeCalamitas; using CalamityMod.NPCs.Yharon; using CalamityMod.Projectiles.Typeless; using CalamityMod.Skies; +using CalamityMod.Systems; using CalamityMod.UI.DraedonSummoning; -using CalamityMod.World; using Microsoft.Xna.Framework; -using System; -using System.Collections.Generic; -using System.Linq; using Terraria; using Terraria.Audio; using Terraria.DataStructures; using Terraria.GameContent.Events; using Terraria.ID; using Terraria.ModLoader; +using ApolloBoss = CalamityMod.NPCs.ExoMechs.Apollo.Apollo; +using ArtemisBoss = CalamityMod.NPCs.ExoMechs.Artemis.Artemis; namespace CalamityMod.Events { @@ -95,7 +94,7 @@ namespace CalamityMod.Events } } - internal static IEntitySource Source => new EntitySource_WorldEvent(); + internal static IEntitySource Source => new EntitySource_WorldEvent("CalamityMod_BossRush"); public static int HostileProjectileKillCounter; public static bool BossRushActive = false; // Whether Boss Rush is active or not. @@ -108,7 +107,7 @@ namespace CalamityMod.Events public static int StartTimer; public static int EndTimer; public static float WhiteDimness; - public static readonly Color XerocTextColor = Color.LightCoral; + public static readonly Color XerocTextColor = new(250, 213, 77); // #FAD54D public const int StartEffectTotalTime = 120; public const int EndVisualEffectTime = 340; public static int ClosestPlayerToWorldCenter => Player.FindClosest(new Vector2(Main.maxTilesX, Main.maxTilesY) * 16f * 0.5f, 1, 1); @@ -402,10 +401,11 @@ namespace CalamityMod.Events BossDeathEffects = new Dictionary>() { + // Wall of Flesh: End of Tier 1 [NPCID.WallofFlesh] = npc => { - CalamityUtils.DisplayLocalizedText("Mods.CalamityMod.Events.BossRushTierOneEndText", XerocTextColor); // "Hmm? Oh, you're still alive. Unexpected, but don't get complacent just yet." CreateTierAnimation(2); + BossRushDialogueSystem.StartDialogue(BossRushDialoguePhase.TierOneComplete); // Teleport players to where they came from for (int playerIndex = 0; playerIndex < Main.maxPlayers; playerIndex++) @@ -423,25 +423,32 @@ namespace CalamityMod.Events } } }, + // Plantera: End of Tier 2 [NPCID.Plantera] = npc => { - CalamityUtils.DisplayLocalizedText("Mods.CalamityMod.Events.BossRushTierTwoEndText", XerocTextColor); // "Hmm? Persistent aren't you? Perhaps you have some hope of prosperity, unlike past challengers." CreateTierAnimation(3); + BossRushDialogueSystem.StartDialogue(BossRushDialoguePhase.TierTwoComplete); }, + // Moon Lord: End of Tier 3 [NPCID.MoonLordCore] = npc => { - CalamityUtils.DisplayLocalizedText("Mods.CalamityMod.Events.BossRushTierThreeEndText", XerocTextColor); // "Hmm? Your perseverance is truly a trait to behold. You've come further than even the demigods in a short time." CreateTierAnimation(4); + BossRushDialogueSystem.StartDialogue(BossRushDialoguePhase.TierThreeComplete); }, + // Devourer of Gods: End of Tier 4 [ModContent.NPCType()] = npc => { - CalamityUtils.DisplayLocalizedText("Mods.CalamityMod.Events.BossRushTierFourEndText", XerocTextColor); // "Hmm? So you've made it to the final tier, a remarkable feat enviable by even the mightiest of the gods." CreateTierAnimation(5); + BossRushDialogueSystem.StartDialogue(BossRushDialoguePhase.TierFourComplete); }, + // Supreme Calamitas: Ends Boss Rush (also delete all hostile projectiles to be safe) [ModContent.NPCType()] = npc => { CalamityUtils.KillAllHostileProjectiles(); HostileProjectileKillCounter = 3; + + // Display short dialogue if BR has been beaten before. + BossRushDialogueSystem.StartDialogue(DownedBossSystem.downedBossRush ? BossRushDialoguePhase.EndRepeat : BossRushDialoguePhase.End); } }; } @@ -510,6 +517,9 @@ namespace CalamityMod.Events if (!BossRushActive) return; + // Handle dialogue as appropriate. + BossRushDialogueSystem.Tick(); + // Disable the stupid credits sequence. if (CreditsRollEvent.IsEventOngoing) CreditsRollEvent.SetRemainingTimeDirect(1); @@ -555,6 +565,7 @@ namespace CalamityMod.Events return; } + // Projectile deletion, preventing Credits and ML from spawning naturally, and dialogue. MiscUpdateEffects(); // Do boss rush countdown and shit if no boss is alive. diff --git a/Items/SummonItems/Terminus.cs b/Items/SummonItems/Terminus.cs index 48a69855c9..5b1248c360 100644 --- a/Items/SummonItems/Terminus.cs +++ b/Items/SummonItems/Terminus.cs @@ -1,6 +1,4 @@ -using System.Collections.Generic; -using CalamityMod.Projectiles.Typeless; -using CalamityMod.World; +using CalamityMod.Projectiles.Typeless; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using Terraria; @@ -58,10 +56,10 @@ namespace CalamityMod.Items.SummonItems return true; } - public override void ModifyResearchSorting(ref ContentSamples.CreativeHelper.ItemGroup itemGroup) - { - // The wiki classifies Boss Rush as an event - itemGroup = ContentSamples.CreativeHelper.ItemGroup.EventItem; - } + public override void ModifyResearchSorting(ref ContentSamples.CreativeHelper.ItemGroup itemGroup) + { + // The wiki classifies Boss Rush as an event + itemGroup = ContentSamples.CreativeHelper.ItemGroup.EventItem; + } } } diff --git a/Projectiles/Typeless/BossRushEffectThing.cs b/Projectiles/Typeless/BossRushEffectThing.cs index ef55aedaca..b91fdc6cfc 100644 --- a/Projectiles/Typeless/BossRushEffectThing.cs +++ b/Projectiles/Typeless/BossRushEffectThing.cs @@ -1,5 +1,7 @@ -using CalamityMod.Events; +using CalamityMod.Enums; +using CalamityMod.Events; using CalamityMod.NPCs.ExoMechs; +using CalamityMod.Systems; using Microsoft.Xna.Framework; using Terraria; using Terraria.GameContent.Events; @@ -61,8 +63,9 @@ namespace CalamityMod.Projectiles.Typeless BossRushEvent.BossRushStage = 0; BossRushEvent.BossRushActive = true; - string key = "Mods.CalamityMod.Events.BossRushStartText"; // "Hmm? Ah, another contender. Very well, may the ritual commence!" - CalamityUtils.DisplayLocalizedText(key, BossRushEvent.XerocTextColor); + + // Play startup dialogue + BossRushDialogueSystem.StartDialogue(DownedBossSystem.downedBossRush ? BossRushDialoguePhase.StartRepeat : BossRushDialoguePhase.Start); CalamityNetcode.SyncWorld(); if (Main.netMode == NetmodeID.Server) diff --git a/Projectiles/Typeless/TerminusHoldout.cs b/Projectiles/Typeless/TerminusHoldout.cs index 06bba85be1..ec89caa8ee 100644 --- a/Projectiles/Typeless/TerminusHoldout.cs +++ b/Projectiles/Typeless/TerminusHoldout.cs @@ -1,7 +1,6 @@ using System; using CalamityMod.Events; using CalamityMod.Items.SummonItems; -using CalamityMod.World; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using ReLogic.Utilities; diff --git a/Systems/BossRushDialogueSystem.cs b/Systems/BossRushDialogueSystem.cs new file mode 100644 index 0000000000..7e0a50ad58 --- /dev/null +++ b/Systems/BossRushDialogueSystem.cs @@ -0,0 +1,197 @@ +using System; +using System.Collections.Generic; +using CalamityMod.Enums; +using CalamityMod.Events; +using Terraria.ModLoader; + +namespace CalamityMod.Systems +{ + public class BossRushDialogueSystem : ModSystem + { + public static BossRushDialoguePhase Phase = BossRushDialoguePhase.None; + private static BossRushDialogueEvent[] currentSequence = null; + private static int currentSequenceIndex = 0; + + public static int CurrentDialogueDelay = 0; + + internal struct BossRushDialogueEvent + { + private const int DefaultFrameDelay = 180; + + internal int FrameDelay; + internal string LocalizationKey; + internal Func skipCondition; + + public BossRushDialogueEvent() { } + public BossRushDialogueEvent(string key) + { + LocalizationKey = key; + FrameDelay = DefaultFrameDelay; + skipCondition = null; + } + public BossRushDialogueEvent(string key, int delay = DefaultFrameDelay, Func skipFunc = null) + { + LocalizationKey = key; + FrameDelay = delay; + skipCondition = skipFunc; + } + + public readonly bool ShouldDisplay() + { + if (skipCondition is null) + return true; + return !skipCondition.Invoke(); + } + } + + internal static Dictionary BossRushDialogue; + + public override void Load() + { + // Dialogue that occurs the first time you start Boss Rush + BossRushDialogueEvent[] startDialogues = new BossRushDialogueEvent[] + { + new("Mods.CalamityMod.Events.BossRushStartText_1"), + new("Mods.CalamityMod.Events.BossRushStartText_2"), + new("Mods.CalamityMod.Events.BossRushStartText_3"), + new("Mods.CalamityMod.Events.BossRushStartText_4"), + new("Mods.CalamityMod.Events.BossRushStartText_5"), + new("Mods.CalamityMod.Events.BossRushStartText_6"), + new("Mods.CalamityMod.Events.BossRushStartText_7"), + new("Mods.CalamityMod.Events.BossRushStartText_8"), + new("Mods.CalamityMod.Events.BossRushStartText_9"), + new("Mods.CalamityMod.Events.BossRushStartText_DoG", skipFunc: () => !DownedBossSystem.downedDoG), + new("Mods.CalamityMod.Events.BossRushStartText_Yharon", skipFunc: () => !DownedBossSystem.downedYharon), + new("Mods.CalamityMod.Events.BossRushStartText_DraedonSCal", skipFunc: () => !DownedBossSystem.downedExoMechs || !DownedBossSystem.downedCalamitas), + new("Mods.CalamityMod.Events.BossRushStartText_10"), + new("Mods.CalamityMod.Events.BossRushStartText_11"), + new("Mods.CalamityMod.Events.BossRushStartText_12"), + }; + + // Dialogue that occurs when starting Boss Rush on repeat attempts + BossRushDialogueEvent[] startDialoguesShort = new BossRushDialogueEvent[] + { + new("Mods.CalamityMod.Events.BossRushStartText_Repeat"), + }; + + // Dialogue that occurs when beating Tier 1 of Boss Rush + BossRushDialogueEvent[] tierOneDialogues = new BossRushDialogueEvent[] + { + new("Mods.CalamityMod.Events.BossRushTierOneEndText_1"), + new("Mods.CalamityMod.Events.BossRushTierOneEndText_2"), + }; + + // Dialogue that occurs when beating Tier 2 of Boss Rush + BossRushDialogueEvent[] tierTwoDialogues = new BossRushDialogueEvent[] + { + new("Mods.CalamityMod.Events.BossRushTierTwoEndText_1"), + new("Mods.CalamityMod.Events.BossRushTierTwoEndText_2"), + }; + + // Dialogue that occurs when beating Tier 3 of Boss Rush + BossRushDialogueEvent[] tierThreeDialogues = new BossRushDialogueEvent[] + { + new("Mods.CalamityMod.Events.BossRushTierThreeEndText_1"), + new("Mods.CalamityMod.Events.BossRushTierThreeEndText_2"), + }; + + // Dialogue that occurs when beating Tier 4 of Boss Rush + BossRushDialogueEvent[] tierFourDialogues = new BossRushDialogueEvent[] + { + new("Mods.CalamityMod.Events.BossRushTierFourEndText_1"), + new("Mods.CalamityMod.Events.BossRushTierFourEndText_2"), + new("Mods.CalamityMod.Events.BossRushTierFourEndText_3"), + }; + + // Dialogue that occurs the first time you beat Boss Rush + BossRushDialogueEvent[] endDialogues = new BossRushDialogueEvent[] + { + new("Mods.CalamityMod.Events.BossRushEndText_1"), + new("Mods.CalamityMod.Events.BossRushEndText_2"), + new("Mods.CalamityMod.Events.BossRushEndText_3"), + new("Mods.CalamityMod.Events.BossRushEndText_4"), + new("Mods.CalamityMod.Events.BossRushEndText_5"), + new("Mods.CalamityMod.Events.BossRushEndText_6"), + new("Mods.CalamityMod.Events.BossRushEndText_7"), + new("Mods.CalamityMod.Events.BossRushEndText_8"), + }; + + // Dialogue that occurs the first time you beat Boss Rush + BossRushDialogueEvent[] endDialoguesShort = new BossRushDialogueEvent[] + { + new("Mods.CalamityMod.Events.BossRushEndText_Repeat"), + }; + + BossRushDialogue = new Dictionary() + { + { BossRushDialoguePhase.Start, startDialogues }, + { BossRushDialoguePhase.StartRepeat, startDialoguesShort }, + { BossRushDialoguePhase.TierOneComplete, tierOneDialogues }, + { BossRushDialoguePhase.TierTwoComplete, tierTwoDialogues }, + { BossRushDialoguePhase.TierThreeComplete, tierThreeDialogues }, + { BossRushDialoguePhase.TierFourComplete, tierFourDialogues }, + { BossRushDialoguePhase.End, endDialogues }, + { BossRushDialoguePhase.EndRepeat, endDialoguesShort }, + }; + } + + public override void Unload() + { + BossRushDialogue = null; + } + + public static void StartDialogue(BossRushDialoguePhase phaseToRun) + { + Phase = phaseToRun; + bool validDialogueFound = BossRushDialogue.TryGetValue(Phase, out var dialogueListToUse); + if (validDialogueFound) + { + currentSequence = dialogueListToUse; + currentSequenceIndex = 0; + } + + CurrentDialogueDelay = 4; + } + + internal static void Tick() + { + // If the phase isn't defined properly, don't do anything. + if (Phase == BossRushDialoguePhase.None) + return; + + if (currentSequenceIndex < currentSequence.Length) + { + // If it's time to display dialogue, do so. + if (CurrentDialogueDelay == 0 && currentSequenceIndex < currentSequence.Length) + { + BossRushDialogueEvent line = currentSequence[currentSequenceIndex]; + CalamityUtils.DisplayLocalizedText(line.LocalizationKey, BossRushEvent.XerocTextColor); + CurrentDialogueDelay = line.FrameDelay; + + // Move onto the next dialogue line. + ++currentSequenceIndex; + } + // Otherwise, decrement the existing delay. + else + --CurrentDialogueDelay; + + // Ensure a boss does not attack the player while they are reading dialogue. + // Indefinitely stall the countdown. + if (BossRushEvent.BossRushSpawnCountdown < 180) + BossRushEvent.BossRushSpawnCountdown = CurrentDialogueDelay + 180; + } + + // If the end of a sequence has been reached, stay in this state indefinitely. + // Allow the boss spawn countdown to hit zero and the next boss to appear without showing any dialogue or causing any delays. + + // However, if Boss Rush is not occurring, reset all variables. + if (!BossRushEvent.BossRushActive) + { + Phase = BossRushDialoguePhase.None; + currentSequence = null; + currentSequenceIndex = 0; + CurrentDialogueDelay = 0; + } + } + } +}