From 929de98d8dca7dc6d8ca80e0e2a76fdf97a15c33 Mon Sep 17 00:00:00 2001 From: GinYuH <72181395+GinYuH@users.noreply.github.com> Date: Wed, 17 Apr 2024 02:57:05 -0700 Subject: [PATCH 1/5] Calamity difficulties on world select screen --- ILEditing/ILChangesLoading.cs | 2 + ILEditing/MechanicILChanges.cs | 95 ++++++++++++++++++++ Localization/en-US/Mods.CalamityMod.UI.hjson | 2 + Systems/WorldSelectionDifficultySystem.cs | 16 ++++ 4 files changed, 115 insertions(+) create mode 100644 Systems/WorldSelectionDifficultySystem.cs 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; + } + } +} From 3ea379edd0508f4c7619742301775e3aeca0b5a9 Mon Sep 17 00:00:00 2001 From: GinYuH <72181395+GinYuH@users.noreply.github.com> Date: Wed, 17 Apr 2024 18:43:43 -0700 Subject: [PATCH 2/5] saving code for later (does not compile) --- ILEditing/MechanicILChanges.cs | 18 ++++++++++++++++++ Systems/WorldSelectionDifficultySystem.cs | 21 ++++++++++++++++++++- 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/ILEditing/MechanicILChanges.cs b/ILEditing/MechanicILChanges.cs index 97868fac08..63bf370da0 100644 --- a/ILEditing/MechanicILChanges.cs +++ b/ILEditing/MechanicILChanges.cs @@ -1451,6 +1451,24 @@ namespace CalamityMod.ILEditing } } + for (int i = 0; i < WorldSelectionDifficultySystem.difficulties.Count; i++) + { + WorldSelectionDifficultySystem.WorldDifficulty dif = WorldSelectionDifficultySystem.difficulties[i]; + if (self.Data.TryGetHeaderData(out TagCompound tager)) + { + if (tager.ContainsKey(dif.name) && tager.GetBool(dif.name)) + { + death = true; + break; + } + } + if (dif.function(tager)) + { + expertText = dif.name; + gameModeColor = dif.color; + } + } + expertText = difficultyText; gameModeColor = difficultyColor; } diff --git a/Systems/WorldSelectionDifficultySystem.cs b/Systems/WorldSelectionDifficultySystem.cs index 421243a02c..51e60bc859 100644 --- a/Systems/WorldSelectionDifficultySystem.cs +++ b/Systems/WorldSelectionDifficultySystem.cs @@ -1,4 +1,10 @@ -using CalamityMod.World; +using System; +using System.Collections.Generic; +using CalamityMod.World; +using Microsoft.Xna.Framework; +using Terraria; +using Terraria.GameContent.UI.Elements; +using Terraria.IO; using Terraria.ModLoader; using Terraria.ModLoader.IO; @@ -6,11 +12,24 @@ namespace CalamityMod.Systems { public class WorldSelectionDifficultySystem : ModSystem { + public static bool GetShopOracle(AWorldListItem worldList, WorldFileData fileData, ModSystem system, string key) + { + return true; + } + public override void Load() + { + difficulties.Add(new WorldDifficulty(CalamityUtils.GetTextValue("UI.Revengeance"), new Func(GetShopOracle))); + } + // 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; } + + public record WorldDifficulty(Func function, string name, Color color); + + public static List difficulties = new List(); } } From f93fc3afc09949034379f7ffe6b01283aac70358 Mon Sep 17 00:00:00 2001 From: GinYuH <72181395+GinYuH@users.noreply.github.com> Date: Sat, 20 Apr 2024 00:41:39 -0700 Subject: [PATCH 3/5] rewrite --- ILEditing/MechanicILChanges.cs | 96 ++------------- Systems/WorldSelectionDifficultySystem.cs | 136 ++++++++++++++++++++-- 2 files changed, 135 insertions(+), 97 deletions(-) diff --git a/ILEditing/MechanicILChanges.cs b/ILEditing/MechanicILChanges.cs index 057d893774..470e7f6b4d 100644 --- a/ILEditing/MechanicILChanges.cs +++ b/ILEditing/MechanicILChanges.cs @@ -1373,108 +1373,25 @@ namespace CalamityMod.ILEditing { 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)) + for (int i = WorldSelectionDifficultySystem.difficulties.Count - 1; i >= 0; i--) { - if (tag.ContainsKey("DeathMode") && tag.GetBool("DeathMode")) + WorldSelectionDifficultySystem.WorldDifficulty d = WorldSelectionDifficultySystem.difficulties[i]; { - 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); - } - } - - for (int i = 0; i < WorldSelectionDifficultySystem.difficulties.Count; i++) - { - WorldSelectionDifficultySystem.WorldDifficulty dif = WorldSelectionDifficultySystem.difficulties[i]; - if (self.Data.TryGetHeaderData(out TagCompound tager)) - { - if (tager.ContainsKey(dif.name) && tager.GetBool(dif.name)) + if (d.function(self)) { - death = true; + difficultyText = d.name; + difficultyColor = d.color; break; } } - if (dif.function(tager)) - { - expertText = dif.name; - gameModeColor = dif.color; - } } expertText = difficultyText; gameModeColor = difficultyColor; } + #endregion #region Shimmer effect edits public static void ShimmerEffectEdits(Terraria.On_Item.orig_GetShimmered orig, Item self) @@ -1503,5 +1420,6 @@ namespace CalamityMod.ILEditing orig(self); } } + #endregion } } diff --git a/Systems/WorldSelectionDifficultySystem.cs b/Systems/WorldSelectionDifficultySystem.cs index 51e60bc859..d9c052d9dc 100644 --- a/Systems/WorldSelectionDifficultySystem.cs +++ b/Systems/WorldSelectionDifficultySystem.cs @@ -1,10 +1,11 @@ using System; using System.Collections.Generic; +using System.Reflection; using CalamityMod.World; using Microsoft.Xna.Framework; -using Terraria; using Terraria.GameContent.UI.Elements; using Terraria.IO; +using Terraria.Localization; using Terraria.ModLoader; using Terraria.ModLoader.IO; @@ -12,13 +13,21 @@ namespace CalamityMod.Systems { public class WorldSelectionDifficultySystem : ModSystem { - public static bool GetShopOracle(AWorldListItem worldList, WorldFileData fileData, ModSystem system, string key) + public override void PostSetupContent() { - return true; - } - public override void Load() - { - difficulties.Add(new WorldDifficulty(CalamityUtils.GetTextValue("UI.Revengeance"), new Func(GetShopOracle))); + string revenge = CalamityUtils.GetTextValue("UI.Revengeance"); + string death = CalamityUtils.GetTextValue("UI.Death"); + string rev = CalamityUtils.GetTextValue("UI.Rev"); + string master = Language.GetTextValue("UI.Master"); + string legend = CalamityUtils.GetTextValue("UI.Legend"); + string plus = "+"; + + difficulties.Add(new WorldDifficulty(revenge, GetRevengeance, new(211, 42, 42))); + difficulties.Add(new WorldDifficulty(death, GetDeath, new(192, 64, 219))); + difficulties.Add(new WorldDifficulty(rev + plus + master, GetMasterRevengeance, new(124, 153, 242))); + difficulties.Add(new WorldDifficulty(death + plus + master, GetMasterDeath, new(255, 25, 255))); + difficulties.Add(new WorldDifficulty(rev + plus + legend, GetLegendRevengeance, new(240, 128, 128))); + difficulties.Add(new WorldDifficulty(death + plus + legend, GetLegendDeath, new(220, 255, 132))); } // Since CalamityWorld is static, and therefore invalid for TryGetHeaderData, make copies for Rev and Death @@ -28,8 +37,119 @@ namespace CalamityMod.Systems tag["DeathMode"] = CalamityWorld.death; } - public record WorldDifficulty(Func function, string name, Color color); + public record WorldDifficulty(string name, Func function, Color color); public static List difficulties = new List(); + public static bool GetRevengeance(AWorldListItem item) + { + if (item.Data.TryGetHeaderData(out TagCompound tag)) + { + if (tag.ContainsKey("RevengeanceMode") && tag.GetBool("RevengeanceMode")) + { + return true; + } + } + return false; + } + + public static bool GetDeath(AWorldListItem item) + { + if (item.Data.TryGetHeaderData(out TagCompound tag)) + { + if (tag.ContainsKey("DeathMode") && tag.GetBool("DeathMode")) + { + return true; + } + } + return false; + } + + public static bool GetMasterRevengeance(AWorldListItem item) + { + // Grab data from the listed world + FieldInfo worldDataField = typeof(UIWorldListItem).GetField("_data", BindingFlags.NonPublic | BindingFlags.Instance); + WorldFileData worldData = (WorldFileData)worldDataField.GetValue(item); + + int trueGameMode = worldData.GameMode; + if (worldData.ForTheWorthy) + { + trueGameMode++; + } + + if (item.Data.TryGetHeaderData(out TagCompound tag)) + { + if (tag.ContainsKey("RevengeanceMode") && tag.GetBool("RevengeanceMode") && trueGameMode == 2) + { + return true; + } + } + return false; + } + + public static bool GetMasterDeath(AWorldListItem item) + { + // Grab data from the listed world + FieldInfo worldDataField = typeof(UIWorldListItem).GetField("_data", BindingFlags.NonPublic | BindingFlags.Instance); + WorldFileData worldData = (WorldFileData)worldDataField.GetValue(item); + + int trueGameMode = worldData.GameMode; + if (worldData.ForTheWorthy) + { + trueGameMode++; + } + + if (item.Data.TryGetHeaderData(out TagCompound tag)) + { + if (tag.ContainsKey("DeathMode") && tag.GetBool("DeathMode") && trueGameMode == 2) + { + return true; + } + } + return false; + } + + public static bool GetLegendRevengeance(AWorldListItem item) + { + // Grab data from the listed world + FieldInfo worldDataField = typeof(UIWorldListItem).GetField("_data", BindingFlags.NonPublic | BindingFlags.Instance); + WorldFileData worldData = (WorldFileData)worldDataField.GetValue(item); + + int trueGameMode = worldData.GameMode; + if (worldData.ForTheWorthy) + { + trueGameMode++; + } + + if (item.Data.TryGetHeaderData(out TagCompound tag)) + { + if (tag.ContainsKey("RevengeanceMode") && tag.GetBool("RevengeanceMode") && trueGameMode == 3) + { + return true; + } + } + return false; + } + + public static bool GetLegendDeath(AWorldListItem item) + { + // Grab data from the listed world + FieldInfo worldDataField = typeof(UIWorldListItem).GetField("_data", BindingFlags.NonPublic | BindingFlags.Instance); + WorldFileData worldData = (WorldFileData)worldDataField.GetValue(item); + + int trueGameMode = worldData.GameMode; + if (worldData.ForTheWorthy) + { + trueGameMode++; + } + + if (item.Data.TryGetHeaderData(out TagCompound tag)) + { + if (tag.ContainsKey("DeathMode") && tag.GetBool("DeathMode") && trueGameMode == 3) + { + return true; + } + } + return false; + } } } From 2255f86e2363d144e3a17db2fa18da161a0e0320 Mon Sep 17 00:00:00 2001 From: GinYuH <72181395+GinYuH@users.noreply.github.com> Date: Sat, 20 Apr 2024 01:32:04 -0700 Subject: [PATCH 4/5] mod call --- ILEditing/MechanicILChanges.cs | 4 +- ModSupport/ModCalls.cs | 48 +++++++++++++++++++++++ Systems/WorldSelectionDifficultySystem.cs | 14 +++---- 3 files changed, 57 insertions(+), 9 deletions(-) diff --git a/ILEditing/MechanicILChanges.cs b/ILEditing/MechanicILChanges.cs index 470e7f6b4d..b4e5a2a9ac 100644 --- a/ILEditing/MechanicILChanges.cs +++ b/ILEditing/MechanicILChanges.cs @@ -1375,9 +1375,9 @@ namespace CalamityMod.ILEditing string difficultyText = expertText; Color difficultyColor = gameModeColor; - for (int i = WorldSelectionDifficultySystem.difficulties.Count - 1; i >= 0; i--) + for (int i = WorldSelectionDifficultySystem.WorldDifficulties.Count - 1; i >= 0; i--) { - WorldSelectionDifficultySystem.WorldDifficulty d = WorldSelectionDifficultySystem.difficulties[i]; + WorldSelectionDifficultySystem.WorldDifficulty d = WorldSelectionDifficultySystem.WorldDifficulties[i]; { if (d.function(self)) { diff --git a/ModSupport/ModCalls.cs b/ModSupport/ModCalls.cs index ca2be1f1bb..e73f62e73c 100644 --- a/ModSupport/ModCalls.cs +++ b/ModSupport/ModCalls.cs @@ -16,6 +16,7 @@ using CalamityMod.World; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using Terraria; +using Terraria.GameContent.UI.Elements; using Terraria.Localization; using Terraria.ModLoader; @@ -553,6 +554,23 @@ namespace CalamityMod DifficultyModeSystem.Difficulties.Add(newMode); DifficultyModeSystem.CalculateDifficultyData(); } + + public static void AddWorldScreenDifficulty(string name, Func function, Color color, int index = -1) + { + // Construct the difficulty + WorldSelectionDifficultySystem.WorldDifficulty difficulty = new WorldSelectionDifficultySystem.WorldDifficulty(name, function, color); + + // Add the new difficulty + // If no index was provided, just add it to the end of the list, otherwise insert it at the desired spot on the list + if (index == -1) + { + WorldSelectionDifficultySystem.WorldDifficulties.Add(difficulty); + } + else + { + WorldSelectionDifficultySystem.WorldDifficulties.Insert(index, difficulty); + } + } #endregion #region Rogue Class @@ -1168,6 +1186,36 @@ namespace CalamityMod AddCustomDifficulty(mode); return null; + case "AddWorldScreenDifficulty": + case "AddWorldSelectionDifficulty": + { + if (args.Length < 2) + return new ArgumentNullException("ERROR: Must specify a difficulty mode name as a string."); + if (args.Length < 3) + return new ArgumentNullException("ERROR: Must specify a Func."); + if (args.Length < 4) + return new ArgumentNullException("ERROR: Must specify a Color."); + + if (args.Length >= 5) + { + if (!(args[4] is int)) + return new ArgumentException("ERROR: The fourth argument to \"AddWorldScreenDifficulty\" must be an int."); + } + if (!(args[3] is Color color)) + return new ArgumentException("ERROR: The third argument to \"AddWorldScreenDifficulty\" must be a Color."); + if (!(args[2] is Func worldFunction)) + return new ArgumentException("ERROR: The second argument to \"AddWorldScreenDifficulty\" must be a Func."); + if (!(args[1] is string)) + return new ArgumentException("ERROR: The first argument to \"AddWorldScreenDifficulty\" must be a string."); + + if (args.Length >= 5) + AddWorldScreenDifficulty(args[1].ToString(), worldFunction, color, (int)args[4]); + else + AddWorldScreenDifficulty(args[1].ToString(), worldFunction, color); + return null; + } + + case "GetLight": case "GetLightLevel": case "GetLightStrength": diff --git a/Systems/WorldSelectionDifficultySystem.cs b/Systems/WorldSelectionDifficultySystem.cs index d9c052d9dc..a8ac35bee0 100644 --- a/Systems/WorldSelectionDifficultySystem.cs +++ b/Systems/WorldSelectionDifficultySystem.cs @@ -22,12 +22,12 @@ namespace CalamityMod.Systems string legend = CalamityUtils.GetTextValue("UI.Legend"); string plus = "+"; - difficulties.Add(new WorldDifficulty(revenge, GetRevengeance, new(211, 42, 42))); - difficulties.Add(new WorldDifficulty(death, GetDeath, new(192, 64, 219))); - difficulties.Add(new WorldDifficulty(rev + plus + master, GetMasterRevengeance, new(124, 153, 242))); - difficulties.Add(new WorldDifficulty(death + plus + master, GetMasterDeath, new(255, 25, 255))); - difficulties.Add(new WorldDifficulty(rev + plus + legend, GetLegendRevengeance, new(240, 128, 128))); - difficulties.Add(new WorldDifficulty(death + plus + legend, GetLegendDeath, new(220, 255, 132))); + WorldDifficulties.Add(new WorldDifficulty(revenge, GetRevengeance, new(211, 42, 42))); + WorldDifficulties.Add(new WorldDifficulty(death, GetDeath, new(192, 64, 219))); + WorldDifficulties.Add(new WorldDifficulty(rev + plus + master, GetMasterRevengeance, new(124, 153, 242))); + WorldDifficulties.Add(new WorldDifficulty(death + plus + master, GetMasterDeath, new(255, 25, 255))); + WorldDifficulties.Add(new WorldDifficulty(rev + plus + legend, GetLegendRevengeance, new(240, 128, 128))); + WorldDifficulties.Add(new WorldDifficulty(death + plus + legend, GetLegendDeath, new(220, 255, 132))); } // Since CalamityWorld is static, and therefore invalid for TryGetHeaderData, make copies for Rev and Death @@ -39,7 +39,7 @@ namespace CalamityMod.Systems public record WorldDifficulty(string name, Func function, Color color); - public static List difficulties = new List(); + public static List WorldDifficulties = new List(); public static bool GetRevengeance(AWorldListItem item) { if (item.Data.TryGetHeaderData(out TagCompound tag)) From 7d55eed37cbe45484cba5ab3ed5c8a45a197e12c Mon Sep 17 00:00:00 2001 From: GinYuH <72181395+GinYuH@users.noreply.github.com> Date: Sat, 20 Apr 2024 09:44:00 -0700 Subject: [PATCH 5/5] comments --- ILEditing/MechanicILChanges.cs | 4 ++++ Systems/WorldSelectionDifficultySystem.cs | 5 ++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/ILEditing/MechanicILChanges.cs b/ILEditing/MechanicILChanges.cs index b4e5a2a9ac..1407494672 100644 --- a/ILEditing/MechanicILChanges.cs +++ b/ILEditing/MechanicILChanges.cs @@ -1371,10 +1371,13 @@ namespace CalamityMod.ILEditing #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) { + // Run the original code and pull out the original text and text color orig(self, out expertText, out gameModeColor); string difficultyText = expertText; Color difficultyColor = gameModeColor; + + // Go through the World Selection Difficulty System's World Difficulty list backwards and choose the latest difficulty that applies for (int i = WorldSelectionDifficultySystem.WorldDifficulties.Count - 1; i >= 0; i--) { WorldSelectionDifficultySystem.WorldDifficulty d = WorldSelectionDifficultySystem.WorldDifficulties[i]; @@ -1388,6 +1391,7 @@ namespace CalamityMod.ILEditing } } + // Set the text and text color expertText = difficultyText; gameModeColor = difficultyColor; } diff --git a/Systems/WorldSelectionDifficultySystem.cs b/Systems/WorldSelectionDifficultySystem.cs index a8ac35bee0..37f9bb3852 100644 --- a/Systems/WorldSelectionDifficultySystem.cs +++ b/Systems/WorldSelectionDifficultySystem.cs @@ -15,6 +15,9 @@ namespace CalamityMod.Systems { public override void PostSetupContent() { + // Load all of the World Difficulties to the World Difficulty list + // The difficulty the world uses will be the latest applicable one, so these are added in order from easiest to hardest + string revenge = CalamityUtils.GetTextValue("UI.Revengeance"); string death = CalamityUtils.GetTextValue("UI.Death"); string rev = CalamityUtils.GetTextValue("UI.Rev"); @@ -30,9 +33,9 @@ namespace CalamityMod.Systems WorldDifficulties.Add(new WorldDifficulty(death + plus + legend, GetLegendDeath, new(220, 255, 132))); } - // Since CalamityWorld is static, and therefore invalid for TryGetHeaderData, make copies for Rev and Death public override void SaveWorldHeader(TagCompound tag) { + // Since CalamityWorld is static, and therefore invalid for TryGetHeaderData, make copies for Rev and Death tag["RevengeanceMode"] = CalamityWorld.revenge; tag["DeathMode"] = CalamityWorld.death; }