using System; using System.Collections.Generic; using CalamityMod.Buffs.DamageOverTime; using CalamityMod.Buffs.StatDebuffs; using CalamityMod.NPCs.Abyss; using CalamityMod.NPCs.AcidRain; using CalamityMod.NPCs.AquaticScourge; using CalamityMod.NPCs.Astral; using CalamityMod.NPCs.AstrumAureus; using CalamityMod.NPCs.AstrumDeus; using CalamityMod.NPCs.BrimstoneElemental; using CalamityMod.NPCs.Bumblebirb; using CalamityMod.NPCs.CalClone; using CalamityMod.NPCs.CeaselessVoid; using CalamityMod.NPCs.Crags; using CalamityMod.NPCs.Cryogen; using CalamityMod.NPCs.DevourerofGods; using CalamityMod.NPCs.ExoMechs.Thanatos; using CalamityMod.NPCs.HiveMind; using CalamityMod.NPCs.Leviathan; using CalamityMod.NPCs.NormalNPCs; using CalamityMod.NPCs.OldDuke; using CalamityMod.NPCs.Perforator; using CalamityMod.NPCs.PlaguebringerGoliath; using CalamityMod.NPCs.PlagueEnemies; using CalamityMod.NPCs.Polterghast; using CalamityMod.NPCs.PrimordialWyrm; using CalamityMod.NPCs.ProfanedGuardians; using CalamityMod.NPCs.Providence; using CalamityMod.NPCs.Ravager; using CalamityMod.NPCs.Signus; using CalamityMod.NPCs.SlimeGod; using CalamityMod.NPCs.StormWeaver; using CalamityMod.NPCs.SulphurousSea; using CalamityMod.NPCs.SunkenSea; using CalamityMod.NPCs.SupremeCalamitas; using CalamityMod.NPCs.Yharon; using Terraria; using Terraria.ID; using Terraria.ModLoader; namespace CalamityMod { public static partial class NPCStats { internal partial struct EnemyStats { public static SortedDictionary> DebuffImmunities; }; internal enum GeneralImmunityStatus : int { None = 0, ImmuneToRegularBuffs = 1, ImmuneToAllBuffs = 2, // This case is rather extreme and it is unlikely Calamity will ever use it. }; #region Stat Retrieval Methods // PORTING APOCRYPHA: 29SEP2023: Ozzatron: yeah okay this WHOLE SYSTEM has to go. NOW. public static void SetDebuffImmunities(this NPC npc) { // Safety check: If for some reason the debuff array is not initialized yet, return and do nothing. if (npc is null || EnemyStats.DebuffImmunities is null) return; // // PART 1: General Immunity Status and applying all data contained in EnemyStats.DebuffImmunities // // Also, can I just say that I hate Sorted Dictionaries and Tuples and want to make something explode? -Ben // I mean you can but sorted dicts and dicts in general are pre great -Amber // Neither of you are free of sin. In porting, we are all brothers in damnation. -Ozzatron bool hasEntry = EnemyStats.DebuffImmunities.TryGetValue(npc.type, out var buffSetTuple); if (hasEntry) { // Apply the NPC's General Immunity Status first. // General Immunity Status is used to make an NPC "immune to everything" by default. GeneralImmunityStatus gis = buffSetTuple.Item1; if (gis == GeneralImmunityStatus.ImmuneToRegularBuffs) NPCID.Sets.ImmuneToRegularBuffs[npc.type] = true; else if (gis == GeneralImmunityStatus.ImmuneToAllBuffs) NPCID.Sets.ImmuneToAllBuffs[npc.type] = true; // From here on out, all listed buff IDs are treated differently depending on what the General Immunity Status was. // If it was None, then the listed buffs are buffs that the NPC should be immune to. // If it was anything else, then the listed buffs are buffs that the NPC should be STILL VULNERABLE to (despite their General Immunity Status). bool providingExceptions = gis != GeneralImmunityStatus.None; for (int i = 0; i < buffSetTuple.Item2.Length; ++i) { int buffID = buffSetTuple.Item2[i]; NPCID.Sets.SpecificDebuffImmunity[npc.type][buffID] = !providingExceptions; } } // // PART 2: Specific other cases that can't be neatly fit into the database // // All bosses and several enemies are automatically immune to Pearl Aura. if (CalamityLists.enemyImmunityList.Contains(npc.type) || npc.boss) NPCID.Sets.SpecificDebuffImmunity[npc.type][ModContent.BuffType()] = true; // Make all Cal NPCs immune to confused unless otherwise specified // Extra note: Clams are not in this list as they initially immune to Confused, but are no longer immune once aggro'd. This is set in their AI(). bool cal = npc.ModNPC != null && npc.ModNPC.Mod.Name.Equals(ModContent.GetInstance().Name); if (!CalamityLists.confusionEnemyList.Contains(npc.type) && cal) NPCID.Sets.SpecificDebuffImmunity[npc.type][BuffID.Confused] = true; // Sets certain vanilla NPCs and all town NPCs to be immune to most debuffs. bool isConsideredSpecialTarget = npc.type == NPCID.SkeletronHead || npc.type == NPCID.DD2EterniaCrystal; bool isTownNPC = npc.townNPC || NPCID.Sets.ActsLikeTownNPC[npc.type]; bool applyRegularBuffImmunitySpecialCases = isConsideredSpecialTarget || isTownNPC; if (applyRegularBuffImmunitySpecialCases) { NPCID.Sets.ImmuneToRegularBuffs[npc.type] = true; // Town NPCs are kept vulnerable to cosmetic debuffs that are meant to affect them. if (isTownNPC) { NPCID.Sets.SpecificDebuffImmunity[npc.type][BuffID.Wet] = false; NPCID.Sets.SpecificDebuffImmunity[npc.type][BuffID.Slimed] = false; NPCID.Sets.SpecificDebuffImmunity[npc.type][BuffID.Lovestruck] = false; NPCID.Sets.SpecificDebuffImmunity[npc.type][BuffID.Stinky] = false; NPCID.Sets.SpecificDebuffImmunity[npc.type][BuffID.GelBalloonBuff] = false; // Additionally, "real" Town NPCs which transform in Shimmer are kept vulnerable to Shimmering. if (npc.townNPC && NPCID.Sets.ShimmerTownTransform[npc.type]) NPCID.Sets.SpecificDebuffImmunity[npc.type][BuffID.Shimmer] = false; } } // Extra Notes: // Shellfish minions set debuff immunity to Shellfish Claps on enemy hits, so most things are technically not immune. // The Spiteful Candle sets the debuff immunity of Spite to all nearby enemies in the tile file for an enemy with less than 99% DR. } #endregion #region Standard Enemy Immunity Sets private static readonly int[] slimeEnemyImmunities = new int[1] { BuffID.Poisoned }; private static readonly int[] iceEnemyImmunities = new int[3] { BuffID.Frostburn, BuffID.Frostburn2, ModContent.BuffType() }; private static readonly int[] sulphurEnemyImmunities = new int[4] { BuffID.Poisoned, BuffID.Venom, ModContent.BuffType(), ModContent.BuffType() }; private static readonly int[] sunkenSeaEnemyImmunities = new int[2] { ModContent.BuffType(), ModContent.BuffType() }; private static readonly int[] abyssEnemyImmunities = new int[2] { ModContent.BuffType(), ModContent.BuffType() }; private static readonly int[] cragEnemyImmunities = new int[3] { BuffID.OnFire, BuffID.OnFire3, ModContent.BuffType() }; private static readonly int[] scalImmunities = new int[5] { BuffID.OnFire, BuffID.OnFire3, ModContent.BuffType(), ModContent.BuffType(), ModContent.BuffType() }; private static readonly int[] astralEnemyImmunities = new int[2] { BuffID.Poisoned, ModContent.BuffType() }; private static readonly int[] plagueEnemyImmunities = new int[3] { BuffID.Poisoned, BuffID.Venom, ModContent.BuffType() }; private static readonly int[] holyEnemyImmunities = new int[4] { BuffID.OnFire, BuffID.OnFire3, ModContent.BuffType(), BuffID.Daybreak }; #endregion #region Load/Unload // A static function, called exactly once, which initializes the EnemyStats struct at a predictable time. // This is necessary to ensure this dictionary is populated as early as possible. // Any boss not listed in here is only immune to Confusion and Pearl Aura. internal static void LoadDebuffs() { // Various shorthands for NPCs which have very simple and common buff immunity sets. Tuple immuneToEverything = new(GeneralImmunityStatus.ImmuneToRegularBuffs, Array.Empty()); Tuple immuneToEverythingIncludingTags = new(GeneralImmunityStatus.ImmuneToAllBuffs, Array.Empty()); Tuple slime = new(GeneralImmunityStatus.None, slimeEnemyImmunities); Tuple ice = new(GeneralImmunityStatus.None, iceEnemyImmunities); Tuple sulphur = new(GeneralImmunityStatus.None, sulphurEnemyImmunities); Tuple sunkenSea = new(GeneralImmunityStatus.None, sunkenSeaEnemyImmunities); Tuple abyss = new(GeneralImmunityStatus.None, abyssEnemyImmunities); Tuple crags = new(GeneralImmunityStatus.None, cragEnemyImmunities); Tuple scal = new(GeneralImmunityStatus.None, scalImmunities); Tuple astral = new(GeneralImmunityStatus.None, astralEnemyImmunities); Tuple plague = new(GeneralImmunityStatus.None, plagueEnemyImmunities); Tuple holy = new(GeneralImmunityStatus.None, holyEnemyImmunities); // Please keep the bosses sorted based on boss progression. EnemyStats.DebuffImmunities = new SortedDictionary> { { ModContent.NPCType(), immuneToEverything }, { ModContent.NPCType(), immuneToEverything }, { ModContent.NPCType(), immuneToEverything }, { ModContent.NPCType(), new(GeneralImmunityStatus.None, new int[] { ModContent.BuffType() }) }, { ModContent.NPCType(), new(GeneralImmunityStatus.None, new int[] { ModContent.BuffType() }) }, { ModContent.NPCType(), new(GeneralImmunityStatus.None, new int[] { ModContent.BuffType() }) }, { ModContent.NPCType(), new(GeneralImmunityStatus.None, new int[] { ModContent.BuffType() }) }, { ModContent.NPCType(), new(GeneralImmunityStatus.None, new int[] { ModContent.BuffType() }) }, { ModContent.NPCType(), new(GeneralImmunityStatus.None, new int[] { ModContent.BuffType() }) }, { ModContent.NPCType(), new(GeneralImmunityStatus.None, new int[] { ModContent.BuffType() }) }, { ModContent.NPCType(), new(GeneralImmunityStatus.None, new int[] { ModContent.BuffType() }) }, { ModContent.NPCType(), new(GeneralImmunityStatus.None, new int[] { ModContent.BuffType() }) }, { ModContent.NPCType(), new(GeneralImmunityStatus.None, new int[] { ModContent.BuffType() }) }, { ModContent.NPCType(), new(GeneralImmunityStatus.None, new int[] { ModContent.BuffType() }) }, { NPCID.Deerclops, ice }, { ModContent.NPCType(), slime }, { ModContent.NPCType(), slime }, { ModContent.NPCType(), slime }, { ModContent.NPCType(), slime }, { ModContent.NPCType(), slime }, { ModContent.NPCType(), slime }, { ModContent.NPCType(), slime }, { ModContent.NPCType(), slime }, { ModContent.NPCType(), slime }, { ModContent.NPCType(), ice }, { ModContent.NPCType(), ice }, { ModContent.NPCType(), sulphur }, { ModContent.NPCType(), sulphur }, { ModContent.NPCType(), sulphur }, { ModContent.NPCType(), sulphur }, { ModContent.NPCType(), crags }, { ModContent.NPCType(), crags }, { ModContent.NPCType(), crags }, { ModContent.NPCType(), crags }, { ModContent.NPCType(), crags }, { ModContent.NPCType(), crags }, { NPCID.Plantera, new(GeneralImmunityStatus.None, new int[] { BuffID.Venom }) }, { NPCID.PlanterasTentacle, new(GeneralImmunityStatus.None, new int[] { BuffID.Venom }) }, { ModContent.NPCType(), new(GeneralImmunityStatus.None, new int[] { BuffID.Venom }) }, // She resists the cold because of her ice-related abilities. { ModContent.NPCType(), ice }, { ModContent.NPCType(), ice }, { ModContent.NPCType(), astral }, { ModContent.NPCType(), astral }, { ModContent.NPCType(), plague }, { ModContent.NPCType(), plague }, { ModContent.NPCType(), plague }, { NPCID.HallowBoss, holy }, { ModContent.NPCType(), immuneToEverything }, { ModContent.NPCType(), immuneToEverything }, { ModContent.NPCType(), astral }, { ModContent.NPCType(), astral }, { ModContent.NPCType(), astral }, { NPCID.MoonLordCore, new(GeneralImmunityStatus.None, new int[] { ModContent.BuffType() }) }, { NPCID.MoonLordHand, new(GeneralImmunityStatus.None, new int[] { ModContent.BuffType() }) }, { NPCID.MoonLordHead, new(GeneralImmunityStatus.None, new int[] { ModContent.BuffType() }) }, { NPCID.MoonLordLeechBlob, new(GeneralImmunityStatus.None, new int[] { ModContent.BuffType() }) }, { ModContent.NPCType(), holy }, { ModContent.NPCType(), holy }, { ModContent.NPCType(), holy }, { ModContent.NPCType(), holy }, { ModContent.NPCType(), new(GeneralImmunityStatus.None, new int[] { ModContent.BuffType() }) }, { ModContent.NPCType(), new(GeneralImmunityStatus.None, new int[] { ModContent.BuffType() }) }, { ModContent.NPCType(), new(GeneralImmunityStatus.None, new int[] { ModContent.BuffType() }) }, { ModContent.NPCType(), holy }, { ModContent.NPCType(), holy }, { ModContent.NPCType(), holy }, { ModContent.NPCType(), holy }, { ModContent.NPCType(), immuneToEverything }, { ModContent.NPCType(), immuneToEverything }, { ModContent.NPCType(), new(GeneralImmunityStatus.None, new int[] { BuffID.Electrified, ModContent.BuffType() }) }, { ModContent.NPCType(), new(GeneralImmunityStatus.None, new int[] { BuffID.Electrified, ModContent.BuffType() }) }, { ModContent.NPCType(), new(GeneralImmunityStatus.None, new int[] { BuffID.Electrified, ModContent.BuffType() }) }, { ModContent.NPCType(), new(GeneralImmunityStatus.None, new int[] { ModContent.BuffType() }) }, { ModContent.NPCType(), immuneToEverything }, { ModContent.NPCType(), immuneToEverything }, { ModContent.NPCType(), new(GeneralImmunityStatus.None, new int[] { ModContent.BuffType(), ModContent.BuffType(), ModContent.BuffType() }) }, { ModContent.NPCType(), immuneToEverything }, { ModContent.NPCType(), immuneToEverything }, { ModContent.NPCType(), immuneToEverything }, { ModContent.NPCType(), sulphur }, { ModContent.NPCType(), sulphur }, { ModContent.NPCType(), sulphur }, { ModContent.NPCType(), immuneToEverything }, { ModContent.NPCType(), immuneToEverything }, { ModContent.NPCType(), immuneToEverything }, { ModContent.NPCType(), immuneToEverything }, { ModContent.NPCType(), immuneToEverything }, { ModContent.NPCType(), immuneToEverything }, { ModContent.NPCType(), new(GeneralImmunityStatus.None, new int[] { BuffID.OnFire, ModContent.BuffType() }) }, { ModContent.NPCType(), immuneToEverything }, { ModContent.NPCType(), immuneToEverything }, { ModContent.NPCType(), immuneToEverything }, { ModContent.NPCType(), immuneToEverything }, { ModContent.NPCType(), scal }, { ModContent.NPCType(), scal }, { ModContent.NPCType(), scal }, { ModContent.NPCType(), scal }, { ModContent.NPCType(), scal }, { ModContent.NPCType(), immuneToEverything }, { ModContent.NPCType(), immuneToEverything }, { ModContent.NPCType(), immuneToEverything }, { ModContent.NPCType(), immuneToEverything }, { ModContent.NPCType(), abyss }, { ModContent.NPCType(), immuneToEverything }, { ModContent.NPCType(), immuneToEverything }, { ModContent.NPCType(), immuneToEverything }, { ModContent.NPCType(), sulphur }, { ModContent.NPCType(), sulphur }, { ModContent.NPCType(), sulphur }, { ModContent.NPCType(), sulphur }, { ModContent.NPCType(), sulphur }, { ModContent.NPCType(), sulphur }, { ModContent.NPCType(), sulphur }, { ModContent.NPCType(), sulphur }, { ModContent.NPCType(), sulphur }, { ModContent.NPCType(), sulphur }, { ModContent.NPCType(), sulphur }, { ModContent.NPCType(), sulphur }, { ModContent.NPCType(), sulphur }, { ModContent.NPCType(), sulphur }, { ModContent.NPCType(), sulphur }, { ModContent.NPCType(), sulphur }, { ModContent.NPCType(), sulphur }, { ModContent.NPCType(), sulphur }, { ModContent.NPCType(), sulphur }, { ModContent.NPCType(), sulphur }, { ModContent.NPCType(), sulphur }, { ModContent.NPCType(), sulphur }, { ModContent.NPCType(), sulphur }, { ModContent.NPCType(), sulphur }, { ModContent.NPCType(), sunkenSea }, { ModContent.NPCType(), sunkenSea }, { ModContent.NPCType(), sunkenSea }, { ModContent.NPCType(), sunkenSea }, { ModContent.NPCType(), sunkenSea }, { ModContent.NPCType(), sunkenSea }, { ModContent.NPCType(), sunkenSea }, { ModContent.NPCType(), sunkenSea }, { ModContent.NPCType(), abyss }, { ModContent.NPCType(), abyss }, { ModContent.NPCType(), abyss }, { ModContent.NPCType(), abyss }, { ModContent.NPCType(), abyss }, { ModContent.NPCType(), abyss }, { ModContent.NPCType(), abyss }, { ModContent.NPCType(), abyss }, { ModContent.NPCType(), abyss }, { ModContent.NPCType(), abyss }, { ModContent.NPCType(), abyss }, { ModContent.NPCType(), abyss }, { ModContent.NPCType(), abyss }, { ModContent.NPCType(), abyss }, { ModContent.NPCType(), abyss }, { ModContent.NPCType(), abyss }, { ModContent.NPCType(), abyss }, { ModContent.NPCType(), abyss }, { ModContent.NPCType(), abyss }, { ModContent.NPCType(), abyss }, { ModContent.NPCType(), abyss }, { ModContent.NPCType(), abyss }, { ModContent.NPCType(), abyss }, { ModContent.NPCType(), abyss }, { ModContent.NPCType(), abyss }, { ModContent.NPCType(), immuneToEverything }, { ModContent.NPCType(), immuneToEverything }, { ModContent.NPCType(), immuneToEverything }, { ModContent.NPCType(), abyss }, { ModContent.NPCType(), abyss }, { ModContent.NPCType(), crags }, { ModContent.NPCType(), crags }, { ModContent.NPCType(), crags }, { ModContent.NPCType(), crags }, { ModContent.NPCType(), crags }, { ModContent.NPCType(), crags }, { ModContent.NPCType(), crags }, { ModContent.NPCType(), crags }, { ModContent.NPCType(), astral }, { ModContent.NPCType(), astral }, { ModContent.NPCType(), astral }, { ModContent.NPCType(), astral }, { ModContent.NPCType(), astral }, { ModContent.NPCType(), astral }, { ModContent.NPCType(), astral }, { ModContent.NPCType(), astral }, { ModContent.NPCType(), astral }, { ModContent.NPCType(), astral }, { ModContent.NPCType(), astral }, { ModContent.NPCType(), astral }, { ModContent.NPCType(), astral }, { ModContent.NPCType(), astral }, { ModContent.NPCType(), astral }, { ModContent.NPCType(), plague }, { ModContent.NPCType(), plague }, { ModContent.NPCType(), plague }, { ModContent.NPCType(), plague }, { ModContent.NPCType(), plague }, { ModContent.NPCType(), plague }, { ModContent.NPCType(), plague }, { ModContent.NPCType(), holy }, { ModContent.NPCType(), holy }, { ModContent.NPCType(), holy }, { ModContent.NPCType(), holy }, { ModContent.NPCType(), immuneToEverything }, { ModContent.NPCType(), immuneToEverything }, { ModContent.NPCType(), immuneToEverything }, { ModContent.NPCType(), immuneToEverything }, { ModContent.NPCType(), new(GeneralImmunityStatus.None, new int[] { BuffID.Poisoned, BuffID.Venom }) }, { ModContent.NPCType(), new(GeneralImmunityStatus.None, new int[] { BuffID.Poisoned, BuffID.Venom }) }, { ModContent.NPCType(), new(GeneralImmunityStatus.None, new int[] { BuffID.Electrified, ModContent.BuffType() }) }, { ModContent.NPCType(), slime }, { ModContent.NPCType(), slime }, { ModContent.NPCType(), ice }, { ModContent.NPCType(), ice }, { ModContent.NPCType(), ice }, { ModContent.NPCType(), ice }, { ModContent.NPCType(), ice } }; } // Destroys the EnemyStats struct to save memory because mod assemblies will not be fully unloaded until TML 1.4. internal static void UnloadDebuffs() { EnemyStats.DebuffImmunities = null; } #endregion } }