using CalamityMod.World; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using Terraria; using Terraria.ModLoader; using CalamityMod.CalPlayer; using CalamityMod.Events; using System.Collections.Generic; using System.Linq; using Terraria.Localization; using static CalamityMod.CalamityUtils; using System; using Terraria.ID; using ReLogic.Content; using Terraria.Audio; using Terraria.ModLoader.IO; namespace CalamityMod.Systems { public class DifficultyModeSystem : ModSystem { internal static bool _hasCheckedItOutYet = false; //Simple variable to add a cool effect to the mode selector public static DifficultyMode[] Difficulties; //Difficulty modes ordered by ascending difficulty public static List DifficultyTiers; //Difficulty modes grouped together by difficulty public static int MostAlternateDifficulties; //The most alternate difficulties at any tier that exists. Used to know the widest space to take in the ui public override void Load() { MostAlternateDifficulties = 1; Difficulties = new DifficultyMode[] { new NoDifficulty(), new RevengeanceDifficulty(), new DeathDifficulty(), new MaliceDifficulty() }; //All of this should happen after a hook happens which lets other mods add their own difficulties Difficulties = Difficulties.OrderBy(d => d.DifficultyScale).ToArray(); DifficultyTiers = new List(); float currentTier = -1; int tierIndex = -1; for (int i = 0; i < Difficulties.Length; i++) { //if we are at a new tier, create a new list of difficulties at that tier. if (currentTier != Difficulties[i].DifficultyScale) { DifficultyTiers.Add(new DifficultyMode[] { Difficulties[i] }); currentTier = Difficulties[i].DifficultyScale; tierIndex++; } //if the tier already exists, just add it to the list of other difficulties at that tier. else { //ugly DifficultyTiers[tierIndex] = DifficultyTiers[tierIndex].Append(Difficulties[i]).ToArray(); MostAlternateDifficulties = Math.Max(DifficultyTiers[tierIndex].Length, MostAlternateDifficulties); } Difficulties[i]._difficultyTier = tierIndex; } } public override void Unload() { Difficulties = null; } public static DifficultyMode GetCurrentDifficulty { get { DifficultyMode mode = Difficulties[0]; for (int i = 1; i < Difficulties.Length; i++) { if (Difficulties[i].Enabled) mode = Difficulties[i]; } return mode; } } public override void SaveWorldData(TagCompound tag) { //Always save it as true tag["hasCheckedOutTheCoolDifficultyUI"] = true; } public override void OnWorldLoad() { _hasCheckedItOutYet = false; } public override void OnWorldUnload() { _hasCheckedItOutYet = false; } public override void LoadWorldData(TagCompound tag) { _hasCheckedItOutYet = tag.GetBool("hasCheckedOutTheCoolDifficultyUI"); //No need to check it out if rev is already on (Such as in old worlds) if (CalamityWorld.revenge) _hasCheckedItOutYet = true; } } public abstract class DifficultyMode { public abstract bool Enabled { get; set; } public abstract Asset Texture { get; } public virtual string ExpandedDescription => ""; public float DifficultyScale; public string Name; public string ShortDescription; public string ActivationTextKey; public string DeactivationTextKey; public SoundStyle ActivationSound; public Color ChatTextColor; internal int _difficultyTier; /// /// Used to know which difficulties to toggle on when selecting a particular difficulty. /// public virtual bool RequiresDifficulty(DifficultyMode mode) => false; public virtual int FavoredDifficultyAtTier(int tier) => 0; } public class NoDifficulty : DifficultyMode { public override bool Enabled { get => true; set { } } private Asset _texture; public override Asset Texture { get { if (_texture == null) _texture = ModContent.Request("CalamityMod/ExtraTextures/UI/ModeIndicator_None"); return _texture; } } public NoDifficulty() { DifficultyScale = 0; Name = "None"; ShortDescription = "The classic Terraria experience, with no Calamity difficulty changes."; ActivationTextKey = ""; DeactivationTextKey = ""; ActivationSound = SoundID.MenuTick with { Volume = 1f}; ChatTextColor = Color.White; } } public class RevengeanceDifficulty : DifficultyMode { public override bool Enabled { get => CalamityWorld.revenge; set => CalamityWorld.revenge = value; } private Asset _texture; public override Asset Texture { get { if (_texture == null) _texture = ModContent.Request("CalamityMod/ExtraTextures/UI/ModeIndicator_Rev"); return _texture; } } public override string ExpandedDescription { get { string rageKey = "[c/FFCE85:" + CalamityKeybinds.RageHotKey.TooltipHotkeyString() + "]"; string adrenKey = "[c/79DFBF:" + CalamityKeybinds.AdrenalineHotKey.TooltipHotkeyString() + "]"; return ("[c/D42B22:Enables the][c/47B290: Adrenaline] [c/D42B22:mechanic. You gain Adrenaline while fighting bosses.Getting hit drops Adrenaline back to 0.] \n" + "[c/D42B22: When Adrenaline is maxed press] " + adrenKey + " [c/D42B22:for a large damage boost.] \n" + "[c/D42B22:Enables the ][c/DE4C2B:Rage][c/D42B22: mechanic.] [c/D42B22:You gain Rage when in proximity of enemies or by using certain items.] \n" + "[c/D42B22: When Rage is maxed press] " + rageKey + " [c/D42B22:for a temporary damage boost.] \n" + "[c/D42B22:All foes have higher stats and deal more damage.] \n" + "[c/D42B22:Bosses have new AI mechanics and new phases.Enemies spawn more frequently.] \n" + "[c/F7342A:This mode is more difficult than Expert. Be sure to prepare for the challenge.]"); } } public RevengeanceDifficulty() { DifficultyScale = 0.25f; Name = "Revengeance"; ShortDescription = "[c/F54254:The intended Calamity experience!]"; ActivationTextKey = "Mods.CalamityMod.RevengeText"; DeactivationTextKey = "Mods.CalamityMod.RevengeText2"; ActivationSound = SoundID.Item119; ChatTextColor = Color.Crimson; } } public class DeathDifficulty : DifficultyMode { public override bool Enabled { get => CalamityWorld.death; set => CalamityWorld.death = value; } private Asset _texture; public override Asset Texture { get { if (_texture == null) _texture = ModContent.Request("CalamityMod/ExtraTextures/UI/ModeIndicator_Death"); return _texture; } } public override string ExpandedDescription { get { return ("[c/B834E0:All foes will pose a much larger threat with aggressive AI and increased damage.] \n" + "[c/B834E0:Bosses have substantially harder AI changes. Enemies are even more numerous and can easily overwhelm you.] \n" + "[c/B834E0:Debuffs are especially lethal and the Abyss is significantly more dangerous.] \n" + "[c/E945FF:Vigilance and tenacity are crucial to survival.]"); } } public DeathDifficulty() { DifficultyScale = 0.5f; Name = "Death"; ShortDescription = "[c/C82DF7:A tougher challenge for the more experienced, or for those that want a step up from Revengeance Mode.]"; ActivationTextKey = "Mods.CalamityMod.DeathText"; DeactivationTextKey = "Mods.CalamityMod.DeathText2"; ActivationSound = SoundID.NPCHit39; ChatTextColor = Color.MediumOrchid; } public override int FavoredDifficultyAtTier(int tier) { DifficultyMode[] tierList = DifficultyModeSystem.DifficultyTiers[tier]; for (int i = 0; i < tierList.Length; i++) { if (tierList[i].Name == "Revengeance") return i; } return 0; } } public class MaliceDifficulty : DifficultyMode { public override bool Enabled { get => CalamityWorld.malice; set => CalamityWorld.malice = value; } private Asset _texture; public override Asset Texture { get { if (_texture == null) _texture = ModContent.Request("CalamityMod/ExtraTextures/UI/ModeIndicator_Malice"); return _texture; } } public override string ExpandedDescription { get { return ("[c/F0BF1F:Bosses are far more aggressive and deal even more damage.] \n" + "[c/F0BF1F:Everything will try their best to kill you. Expect to fail over and over.] \n" + "[c/FADC1B:Steel yourself for the challenges ahead; do not let your overconfidence be your downfall.]"); } } public MaliceDifficulty() { DifficultyScale = 0.75f; Name = "Malice"; ShortDescription = "[c/F7CF2D:For the die-hard veteran who seeks an unrelenting trial of patience and mastery.]"; ActivationTextKey = "Mods.CalamityMod.MaliceText"; DeactivationTextKey = "Mods.CalamityMod.MaliceText2"; ActivationSound = SoundID.NPCDeath38; ChatTextColor = Color.Gold; } public override int FavoredDifficultyAtTier(int tier) { DifficultyMode[] tierList = DifficultyModeSystem.DifficultyTiers[tier]; for (int i = 0; i < tierList.Length; i++) { if (tierList[i].Name == "Revengeance" || tierList[i].Name == "Death") return i; } return 0; } } }