diff --git a/NPCs/Abyss/Reaper.cs b/NPCs/Abyss/Reaper.cs index ab184e4e51..3e59dba172 100644 --- a/NPCs/Abyss/Reaper.cs +++ b/NPCs/Abyss/Reaper.cs @@ -675,13 +675,7 @@ namespace CalamityMod.NPCs.Abyss DropHelper.DropItemCondition(npc, ModContent.ItemType(), CalamityWorld.downedPolterghast, 3, 1, 1); if (CalamityWorld.downedPolterghast) { - float f = Main.rand.NextFloat(); - bool replaceWithRare = f <= 0.01f; // 1/100 chance overall of getting The Reaper - if (f <= 0.3333f) // 1/3 chance of getting Valediction OR The Reaper replacing it - { - DropHelper.DropItemCondition(npc, ModContent.ItemType(), !replaceWithRare); - DropHelper.DropItemCondition(npc, ModContent.ItemType(), replaceWithRare); - } + DropHelper.DropItemRIV(npc, ModContent.ItemType(), ModContent.ItemType(), 0.3333f, 0.01f); } } diff --git a/NPCs/CalamityGlobalNPCLoot.cs b/NPCs/CalamityGlobalNPCLoot.cs index e4b11e3824..06a6652cd5 100644 --- a/NPCs/CalamityGlobalNPCLoot.cs +++ b/NPCs/CalamityGlobalNPCLoot.cs @@ -1414,14 +1414,7 @@ namespace CalamityMod.NPCs break; case NPCID.GiantTortoise: - float tortoiseDropRate = Main.expertMode ? 0.2f : 0.142857f; - float shellRoll = Main.rand.NextFloat(); - bool fabledShell = shellRoll <= 0.005f; // Exact 1/200 chance for rare regardless of difficulty - if (shellRoll < tortoiseDropRate) // 1/7 (1/5 EX) chance of getting Giant Tortoise Shell OR Fabled Tortoise Shell replacing it - { - DropHelper.DropItemCondition(npc, ModContent.ItemType(), !fabledShell); - DropHelper.DropItemCondition(npc, ModContent.ItemType(), fabledShell); - } + DropHelper.DropItemRIV(npc, ModContent.ItemType(), ModContent.ItemType(), Main.expertMode ? 0.2f : 0.142857f, 0.005f); break; case NPCID.GiantShelly: @@ -1477,18 +1470,11 @@ namespace CalamityMod.NPCs break; case NPCID.IchorSticker: - float spearDropRate = Main.expertMode ? 0.05f : 0.04f; - float spearRoll = Main.rand.NextFloat(); - bool spearOfDestiny = spearRoll <= 0.005f; // Exact 1/200 chance for rare regardless of difficulty - if (spearRoll < spearDropRate) // 1/25 (1/20 EX) chance of getting Ichor Spear OR Spear of Destiny replacing it - { - DropHelper.DropItemCondition(npc, ModContent.ItemType(), !spearOfDestiny); - DropHelper.DropItemCondition(npc, ModContent.ItemType(), spearOfDestiny); - } + DropHelper.DropItemRIV(npc, ModContent.ItemType(), ModContent.ItemType(), Main.expertMode ? 0.05f : 0.04f, 0.005f); break; case NPCID.Harpy: - int glazeDropRate = CalamityWorld.defiled ? 20 : Main.expertMode ? 60 : 80; + int glazeDropRate = CalamityWorld.defiled ? DropHelper.DefiledDropRateInt : Main.expertMode ? 60 : 80; DropHelper.DropItemCondition(npc, ModContent.ItemType(), NPC.downedBoss1, glazeDropRate, 1, 1); DropHelper.DropItemCondition(npc, ModContent.ItemType(), Main.hardMode && !npc.SpawnedFromStatue, Main.expertMode ? 2 : 3, 1, 1); break; @@ -1536,14 +1522,7 @@ namespace CalamityMod.NPCs break; case NPCID.PirateCrossbower: - float crossbowDropRate = Main.expertMode ? 0.05f : 0.04f; - float arbalestRoll = Main.rand.NextFloat(); - bool arbalest = arbalestRoll <= 0.005f; // Exact 1/200 chance for rare regardless of difficulty - if (arbalestRoll < crossbowDropRate) // 1/25 (1/20 EX) chance of getting Raider's Glory OR Arbalest replacing it - { - DropHelper.DropItemCondition(npc, ModContent.ItemType(), !arbalest); - DropHelper.DropItemCondition(npc, ModContent.ItemType(), arbalest); - } + DropHelper.DropItemRIV(npc, ModContent.ItemType(), ModContent.ItemType(), Main.expertMode ? 0.05f : 0.04f, 0.005f); break; case NPCID.GoblinSummoner: diff --git a/NPCs/CeaselessVoid/CeaselessVoid.cs b/NPCs/CeaselessVoid/CeaselessVoid.cs index 6fda92343c..470e72f160 100644 --- a/NPCs/CeaselessVoid/CeaselessVoid.cs +++ b/NPCs/CeaselessVoid/CeaselessVoid.cs @@ -139,13 +139,7 @@ namespace CalamityMod.NPCs.CeaselessVoid DropHelper.DropItemChance(npc, ModContent.ItemType(), Main.expertMode ? 3 : 4); // Equipment - float f = Main.rand.NextFloat(); - bool replaceWithRare = f <= DropHelper.RareVariantDropRateFloat; // 1/40 chance overall of getting The Evolution - if (f < 0.2f) // 1/5 chance of getting Arcanum of the Void OR The Evolution replacing it - { - DropHelper.DropItemCondition(npc, ModContent.ItemType(), !replaceWithRare); - DropHelper.DropItemCondition(npc, ModContent.ItemType(), replaceWithRare); - } + DropHelper.DropItemRIV(npc, ModContent.ItemType(), ModContent.ItemType(), 0.2f, DropHelper.RareVariantDropRateFloat); // Vanity DropHelper.DropItemChance(npc, ModContent.ItemType(), 10); diff --git a/NPCs/NormalNPCs/Cnidrion.cs b/NPCs/NormalNPCs/Cnidrion.cs index aee58dc0e3..d49b9e1c89 100644 --- a/NPCs/NormalNPCs/Cnidrion.cs +++ b/NPCs/NormalNPCs/Cnidrion.cs @@ -295,17 +295,11 @@ namespace CalamityMod.NPCs.NormalNPCs public override void NPCLoot() { - Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, ItemID.Coral, Main.rand.Next(1, 4)); - Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, ItemID.Starfish, Main.rand.Next(1, 4)); - Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, ItemID.Seashell, Main.rand.Next(1, 4)); - Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, ModContent.ItemType(), Main.rand.Next(1, 4)); - if (Main.rand.NextBool(4)) - { - if (Main.rand.NextBool(25)) - Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, ModContent.ItemType()); - else - Item.NewItem((int)npc.position.X, (int)npc.position.Y, npc.width, npc.height, ModContent.ItemType()); - } + DropHelper.DropItem(npc, ItemID.Coral, 1, 3); + DropHelper.DropItem(npc, ItemID.Starfish, 1, 3); + DropHelper.DropItem(npc, ItemID.Seashell, 1, 3); + DropHelper.DropItem(npc, ModContent.ItemType(), 1, 3); + DropHelper.DropItemRIV(npc, ModContent.ItemType(), ModContent.ItemType(), 0.25f, 0.01f); } } } diff --git a/NPCs/Signus/Signus.cs b/NPCs/Signus/Signus.cs index c162a24ea9..7df77f7d7a 100644 --- a/NPCs/Signus/Signus.cs +++ b/NPCs/Signus/Signus.cs @@ -769,13 +769,7 @@ namespace CalamityMod.NPCs.Signus // Weapons DropHelper.DropItemChance(npc, ModContent.ItemType(), Main.expertMode ? 3 : 4); - float f = Main.rand.NextFloat(); - bool replaceWithRare = f <= DropHelper.RareVariantDropRateFloat; // 1/40 chance overall of getting Guidelight of Oblivion - if (f <= (Main.expertMode ? 0.3333f : 0.25f)) // 1/3 (1/4 in normal) chance of getting Cosmilamp OR Guidelight of Oblivion replacing it - { - DropHelper.DropItemCondition(npc, ModContent.ItemType(), !replaceWithRare); - DropHelper.DropItemCondition(npc, ModContent.ItemType(), replaceWithRare); - } + DropHelper.DropItemRIV(npc, ModContent.ItemType(), ModContent.ItemType(), Main.expertMode ? 0.3333f : 0.25f, DropHelper.RareVariantDropRateFloat); //Equipment DropHelper.DropItemCondition(npc, ModContent.ItemType(), CalamityWorld.revenge, 4, 1, 1); diff --git a/Utilities/DropHelper.cs b/Utilities/DropHelper.cs index 2a80c9ee6c..f23c02ac3f 100644 --- a/Utilities/DropHelper.cs +++ b/Utilities/DropHelper.cs @@ -231,6 +231,25 @@ namespace CalamityMod return dropped; } + + /// + /// Drops an item that can be replaced by a given RIV + /// + /// The NPC which should drop the item(s). + /// The ID of the normal item to drop. + /// The ID of the RIV to drop. + /// The chance that one of the two will drop. A decimal number <= 1.0. + /// The chance that the RIV will drop. A decimal number <= 1.0. + public static void DropItemRIV(NPC npc, int itemID, int rareID, float itemChance, float rareChance) + { + float f = Main.rand.NextFloat(); + bool replaceWithRare = f <= rareChance; // 1/X chance overall of getting RIV + if (f <= itemChance) // 1/X chance of getting original OR the RIV replacing it + { + DropItemCondition(npc, itemID, !replaceWithRare); + DropItemCondition(npc, rareID, replaceWithRare); + } + } #endregion #region NPC Item Drops 100% Chance