From 6e079dd706b13bbe7e67779e66fe23a17e02eb7a Mon Sep 17 00:00:00 2001 From: Ozzatron Date: Wed, 12 Jul 2023 16:05:05 -0400 Subject: [PATCH] 1 - Removed Voodoo Demon IL edit. 2 - Reduced Calamity's Voodoo Demon PHM spawn chance boost by 5x. 3 - Added an OnSpawn effect which changes Voodoo Demons into normal Demons if they are within 2000 pixels of someone using the doll. --- ILEditing/ILChangesLoading.cs | 3 -- ILEditing/VanillaStupidityFixingILChanges.cs | 27 ------------- NPCs/CalamityGlobalNPC.cs | 42 +++++++++++++------- 3 files changed, 28 insertions(+), 44 deletions(-) diff --git a/ILEditing/ILChangesLoading.cs b/ILEditing/ILChangesLoading.cs index 499537117e..ccd01ddf82 100644 --- a/ILEditing/ILChangesLoading.cs +++ b/ILEditing/ILChangesLoading.cs @@ -119,9 +119,6 @@ namespace CalamityMod.ILEditing IL_Item.TryGetPrefixStatMultipliersForItem += RelaxPrefixRequirements; On_NPC.SlimeRainSpawns += PreventBossSlimeRainSpawns; - // ERROR - //Terraria.IL_NPC.SpawnNPC += MakeVoodooDemonDollWork; - // TODO -- Beat Lava Slimes once and for all // IL.Terraria.NPC.VanillaHitEffect += RemoveLavaDropsFromExpertLavaSlimes; IL_Projectile.CanExplodeTile += MakeMeteoriteExplodable; diff --git a/ILEditing/VanillaStupidityFixingILChanges.cs b/ILEditing/VanillaStupidityFixingILChanges.cs index b2c78ef3d6..41ca19f79f 100644 --- a/ILEditing/VanillaStupidityFixingILChanges.cs +++ b/ILEditing/VanillaStupidityFixingILChanges.cs @@ -117,33 +117,6 @@ namespace CalamityMod.ILEditing } #endregion Prevention of Slime Rain Spawns When Near Bosses - #region Voodoo Demon Doll Spawn Manipulations - // This may seem absolutely obscene, but vanilla spawn behavior does not occur within the spawn pool that TML provides, only modded - // spawns do. Pretty much everything else is simply a fuckton of manual conditional NPC.NewNPC calls. As such, the only way to bypass - // vanilla spawn behaviors is the IL edit them out of existence. Here, simply replacing the voodoo demon ID with an empty one is performed. - // Something cleaner could probably be done, such as getting rid of the entire NPC.NewNPC call, but this is the easiest solution I can come up with. - private static void MakeVoodooDemonDollWork(ILContext il) - { - var cursor = new ILCursor(il); - - if (!cursor.TryGotoNext(MoveType.Before, i => i.MatchLdcI4(NPCID.VoodooDemon))) - { - LogFailure("Voodoo Demon Doll Mechanic", "Could not locate the Voodoo Demon ID."); - return; - } - - cursor.Remove(); - cursor.Emit(OpCodes.Ldloc, 10); - cursor.EmitDelegate>(spawnPlayerIndex => - { - if (Main.player[spawnPlayerIndex].active && Main.player[spawnPlayerIndex].Calamity().disableVoodooSpawns) - return NPCID.None; - - return NPCID.VoodooDemon; - }); - } - #endregion Voodoo Demon Doll Spawn Manipulations - #region Remove Feral Bite Random Debuffs private static void RemoveFeralBiteRandomDebuffs(ILContext il) { diff --git a/NPCs/CalamityGlobalNPC.cs b/NPCs/CalamityGlobalNPC.cs index a393c73503..c467242452 100644 --- a/NPCs/CalamityGlobalNPC.cs +++ b/NPCs/CalamityGlobalNPC.cs @@ -5128,33 +5128,47 @@ namespace CalamityMod.NPCs if (spawnInfo.PlayerSafe) return; - // Voodoo Demon changes (including Voodoo Demon Voodoo Doll implementation) + // Voodoo Demon changes (including partial Voodoo Demon Voodoo Doll implementation) bool voodooDemonDollActive = spawnInfo.Player.Calamity().disableVoodooSpawns; - if (!voodooDemonDollActive) + + // If the doll is active, Voodoo Demons cannot spawn (via modded means). + if (voodooDemonDollActive) + pool.Remove(NPCID.VoodooDemon); + // Otherwise, if it's pre-Hardmode, provide a modded spawn entry that makes them much more common. + else if (!Main.hardMode && spawnInfo.Player.ZoneUnderworldHeight && !calamityBiomeZone) { - // Nearby players with the doll apply it to anyone within 500 pixels + pool[NPCID.VoodooDemon] = SpawnCondition.Underworld.Chance * 0.15f; + } + } + #endregion + + #region On Spawn + public override void OnSpawn(NPC npc, IEntitySource source) + { + if (npc.type != NPCID.VoodooDemon) + return; + + // This entity source does not provide a player. So we have to find out if anyone close enough has a doll. + if (source is EntitySource_SpawnNPC) + { + bool voodooDemonDollActive = false; + Vector2 v = npc.Center; for (int i = 0; i < Main.maxPlayers; ++i) { Player p = Main.player[i]; if (p is null || !p.active) continue; - float distsq = p.Center.DistanceSQ(spawnInfo.Player.Center); - if (distsq < 25000f) + if (p.DistanceSQ(v) < 4000000f && p.Calamity().disableVoodooSpawns) // 2000 pixel radius { voodooDemonDollActive = true; break; } } - } + if (!voodooDemonDollActive) + return; - // If the doll is active, Voodoo Demons cannot spawn. - // NOTE: This doesn't fully work! There is an IL edit to truly force them to stop spawning. - if (voodooDemonDollActive) - pool.Remove(NPCID.VoodooDemon); - // Otherwise, if it's pre-Hardmode, boost their spawn rate by 1.25x. - else if (!Main.hardMode && spawnInfo.Player.ZoneUnderworldHeight && !calamityBiomeZone) - { - pool[NPCID.VoodooDemon] *= 1.25f; + npc.Transform(NPCID.Demon); + npc.netUpdate = true; } } #endregion