diff --git a/ILEditing/ILChangesLoading.cs b/ILEditing/ILChangesLoading.cs index ee17c9dafe..756755e3ce 100644 --- a/ILEditing/ILChangesLoading.cs +++ b/ILEditing/ILChangesLoading.cs @@ -10,6 +10,7 @@ using Terraria.GameContent.Drawing; using Terraria.GameContent.Events; using Terraria.GameContent.ItemDropRules; using Terraria.GameContent.Liquid; +using Terraria.GameContent.UI.Elements; using Terraria.GameContent.UI.States; using Terraria.Graphics.Light; using Terraria.ModLoader; @@ -80,6 +81,7 @@ namespace CalamityMod.ILEditing On_NPC.Collision_DecideFallThroughPlatforms += EnableCalamityBossPlatformCollision; IL_Wiring.HitWireSingle += AddTwinklersToStatue; On_Player.UpdateItemDye += FindCalamityItemDyeShader; + On_AWorldListItem.GetDifficulty += GetDifficultyOverride; // Mana Burn (Chaos Stone) and Chalice of the Blood God IL_Player.ApplyLifeAndOrMana += ManaSicknessAndChaliceBufferHeal; diff --git a/ILEditing/MechanicILChanges.cs b/ILEditing/MechanicILChanges.cs index e5207bc4e2..97868fac08 100644 --- a/ILEditing/MechanicILChanges.cs +++ b/ILEditing/MechanicILChanges.cs @@ -32,13 +32,16 @@ using Terraria.GameContent; using Terraria.GameContent.Drawing; using Terraria.GameContent.Events; using Terraria.GameContent.Liquid; +using Terraria.GameContent.UI.Elements; using Terraria.GameInput; using Terraria.Graphics; using Terraria.Graphics.Light; using Terraria.Graphics.Shaders; using Terraria.ID; +using Terraria.IO; using Terraria.Localization; using Terraria.ModLoader; +using Terraria.ModLoader.IO; using Terraria.UI.Gamepad; namespace CalamityMod.ILEditing @@ -1360,5 +1363,97 @@ namespace CalamityMod.ILEditing // The next (untouched) instruction stores this value into Player.scope. } #endregion + + + #region Custom world selection difficulties + internal static void GetDifficultyOverride(Terraria.GameContent.UI.Elements.On_AWorldListItem.orig_GetDifficulty orig, AWorldListItem self, out string expertText, out Color gameModeColor) + { + orig(self, out expertText, out gameModeColor); + + // Uncomment this to prevent this from overriding other mods + /*if (expertText != Language.GetTextValue("UI.Legendary") + && expertText != Language.GetTextValue("UI.Normal") + && expertText != Language.GetTextValue("UI.Expert") + && expertText != Language.GetTextValue("UI.Master") + && expertText != Language.GetTextValue("UI.Creative")) + return;*/ + + string difficultyText = expertText; + Color difficultyColor = gameModeColor; + + bool rev = false; + bool death = false; + + // Grab data from the listed world + FieldInfo worldDataField = typeof(UIWorldListItem).GetField("_data", BindingFlags.NonPublic | BindingFlags.Instance); + WorldFileData worldData = (WorldFileData)worldDataField.GetValue(self); + + // Check if the world data contains Calamity's difficulties and mark them true if they are true + if (self.Data.TryGetHeaderData(out TagCompound tag)) + { + if (tag.ContainsKey("DeathMode") && tag.GetBool("DeathMode")) + { + death = true; + } + else if (tag.ContainsKey("RevengeanceMode") && tag.GetBool("RevengeanceMode")) + { + rev = true; + } + } + + // Increase difficulty by 1 in For The Worthy/Getfixedboi + int trueGameMode = worldData.GameMode; + if (worldData.ForTheWorthy) + { + trueGameMode++; + } + + // Change the difficulty names and colors based on Vanilla and Calamity difficulty combos + // The Expert and Master colors are from the wiki + // The Legendary colors are Malice and Defiled's wiki colors + if (trueGameMode == 3) + { + if (death) + { + difficultyText = CalamityUtils.GetTextValue("UI.Death") + "+" + CalamityUtils.GetTextValue("UI.Legend"); + difficultyColor = new Color(220, 255, 132); + } + else if (rev) + { + difficultyText = CalamityUtils.GetTextValue("UI.Rev") + "+" + CalamityUtils.GetTextValue("UI.Legend"); + difficultyColor = new Color(240, 128, 128); + } + } + else if (trueGameMode == 2) + { + if (death) + { + difficultyText = CalamityUtils.GetTextValue("UI.Death") + "+" + Language.GetTextValue("UI.Master"); + difficultyColor = new Color(255, 25, 255); + } + else if (rev) + { + difficultyText = CalamityUtils.GetTextValue("UI.Rev") + "+" + Language.GetTextValue("UI.Master"); + difficultyColor = new Color(124, 153, 242); + } + } + else if (trueGameMode == 1) + { + if (death) + { + difficultyText = CalamityUtils.GetTextValue("UI.Death"); + difficultyColor = new Color(192, 64, 219); + } + else if (rev) + { + difficultyText = CalamityUtils.GetTextValue("UI.Revengeance"); + difficultyColor = new Color(211, 42, 42); + } + } + + expertText = difficultyText; + gameModeColor = difficultyColor; + } + #endregion } } diff --git a/Localization/en-US/Mods.CalamityMod.UI.hjson b/Localization/en-US/Mods.CalamityMod.UI.hjson index 7c4de20acc..9978cae7fe 100644 --- a/Localization/en-US/Mods.CalamityMod.UI.hjson +++ b/Localization/en-US/Mods.CalamityMod.UI.hjson @@ -31,6 +31,7 @@ ChangingTheRules: "[c/919191:You cannot change the rules now!]" NoDifficulty: None NoDifficultyInfo: The classic Terraria experience, with no Calamity difficulty changes Revengeance: Revengeance +Rev: Rev RevengeanceShortInfo: "[c/F54254:The intended Calamity experience!]" RevengeanceExpandedInfo: ''' @@ -55,6 +56,7 @@ DeathExpandedInfo: ''' DeathActivate: Death is active; enjoy the fun. DeathDeactivate: Death is not active; not fun enough for you? +Legend: Legend // Calamity Health Bar ExoTwinsNameNormal: XS-01 Artemis and XS-03 Apollo ExoTwinsNameHekate: Eyes of XB-∞ Hekate diff --git a/Systems/WorldSelectionDifficultySystem.cs b/Systems/WorldSelectionDifficultySystem.cs new file mode 100644 index 0000000000..421243a02c --- /dev/null +++ b/Systems/WorldSelectionDifficultySystem.cs @@ -0,0 +1,16 @@ +using CalamityMod.World; +using Terraria.ModLoader; +using Terraria.ModLoader.IO; + +namespace CalamityMod.Systems +{ + public class WorldSelectionDifficultySystem : ModSystem + { + // Since CalamityWorld is static, and therefore invalid for TryGetHeaderData, make copies for Rev and Death + public override void SaveWorldHeader(TagCompound tag) + { + tag["RevengeanceMode"] = CalamityWorld.revenge; + tag["DeathMode"] = CalamityWorld.death; + } + } +}