diff --git a/ILEditing/ILChangesLoading.cs b/ILEditing/ILChangesLoading.cs index d57155929a..93c842f281 100644 --- a/ILEditing/ILChangesLoading.cs +++ b/ILEditing/ILChangesLoading.cs @@ -142,6 +142,8 @@ namespace CalamityMod.ILEditing IL_UIWorldCreation.AddWorldSizeOptions += SwapSmallDescriptionKey; On_WorldGen.MakeDungeon += LimitDungeonEntranceXPosition; IL_WorldGen.DungeonHalls += LimitDungeonHallsXPosition; + IL_WorldGen.IslandHouse += MakeFledgingWingsMoreCommon; + IL_WorldGen.AddBuriedChest_int_int_int_bool_int_bool_ushort += DisableFledglingWingsSecondary; // Removal of vanilla stupidity IL_Player.StatusFromNPC += RemoveExpertBrainRandomDebuffs; diff --git a/ILEditing/WorldgenILChanges.cs b/ILEditing/WorldgenILChanges.cs index 6a11c74bec..63e1681843 100644 --- a/ILEditing/WorldgenILChanges.cs +++ b/ILEditing/WorldgenILChanges.cs @@ -208,5 +208,72 @@ namespace CalamityMod.ILEditing } #endregion Prevent Abyss/Dungeon Interactions + + #region Fledgling Wings Loot Changes + /// + /// Changes the primary loot of Floating Island chests to include Fledging Wings + /// + private static void MakeFledgingWingsMoreCommon(ILContext il) + { + var cursor = new ILCursor(il); + + // How the code we are moving to works: + // Set num13 equal to the number of islands generated. If greater than 3, set to a random number between 0-3 inclusive. Then use that value in a 4-branch switch statement. + // This makes num13 always be a value between 0-3, for the 4 primary items in island loot. + // To accomodate for Fledgling Wings, we must change this to check for being greater than 4, then to set to a random number between 0-4 inclusive, then make the switch have 5 branches. + if (!cursor.TryGotoNext(MoveType.After, i => i.MatchStloc(13))) + { + LogFailure("Fledgling Wings", "Could not move to the location of determining Floating Island primary loot 1."); + return; + } + + // Emit a delegate which reimplements the logic for choosing the primary loot of floating islands with Fledgling Wings, then return the ID of the item. + var label = il.DefineLabel(); + cursor.EmitDelegate>(() => + { + int island = GenVars.skyIslandHouseCount; + if (island > 4) + island = Main.rand.Next(5); + + return island switch + { + 1 => 65, // Starfury + 2 => 158, // Lucky Horseshoe + 3 => 2219, // Celestial Magnet + 4 => 4978, // Fledgling Wings + _ => 159, // Shiny Red Balloon + }; + }); + + // Store this value in the variable which holds the ID of the item, then branch past the original logic. + cursor.Emit(OpCodes.Stloc, 13); + cursor.Emit(OpCodes.Br, label); + + if (!cursor.TryGotoNext(MoveType.AfterLabel, i => i.MatchLdsfld("getGoodWorldGen"))) + { + LogFailure("Fledgling Wings", "Could not move after the switch statement."); + return; + } + cursor.MarkLabel(label); + } + + /// + /// Disables Fledgling Wings being added as secondary loot in floating island chests + /// + private static void DisableFledglingWingsSecondary(ILContext il) + { + var cursor = new ILCursor(il); + + if (!cursor.TryGotoNext(MoveType.After, i => i.MatchLdloc(9))) + { + LogFailure("Fledgling Wings", "Could not move to the code adding Fledgling Wings as secondary loot."); + return; + } + + // AND with 0 (false) so that the code to add Fledgling Wings as secondary loot never runs. + cursor.Emit(OpCodes.Ldc_I4_0); + cursor.Emit(OpCodes.And); + } + #endregion } } diff --git a/Items/CalamityGlobalItemLoot.cs b/Items/CalamityGlobalItemLoot.cs index 3d3ed8176e..ad89f62418 100644 --- a/Items/CalamityGlobalItemLoot.cs +++ b/Items/CalamityGlobalItemLoot.cs @@ -301,9 +301,17 @@ namespace CalamityMod.Items loot.Add(ModContent.ItemType(), 2, 2, 5); break; + // Reimplement primary loot rule to include Fledgling Wings + case ItemID.FloatingIslandFishingCrate: + RemoveLootRuleFromSkyCrates(loot); + loot.Add(ItemDropRule.OneFromOptionsNotScalingWithLuck(1, ItemID.ShinyRedBalloon, ItemID.LuckyHorseshoe, ItemID.Starfury, ItemID.CelestialMagnet, ItemID.CreativeWings)); + break; + // 2-5 Essences of Sunlight @ 50% // This is our equivalent to Souls of Light/Night case ItemID.FloatingIslandFishingCrateHard: + RemoveLootRuleFromSkyCrates(loot); + loot.Add(ItemDropRule.OneFromOptionsNotScalingWithLuck(1, ItemID.ShinyRedBalloon, ItemID.LuckyHorseshoe, ItemID.Starfury, ItemID.CelestialMagnet, ItemID.CreativeWings)); RemoveHardmodeOresFromBiomeCrates(loot); loot.AddHardmodeOresToCrates(HardmodeCrateType.Biome); loot.Add(ModContent.ItemType(), 2, 2, 5); @@ -584,6 +592,34 @@ namespace CalamityMod.Items ItemID.BandofRegeneration, ItemID.ShoeSpikes, ModContent.ItemType()); // Climbing Claws is in Wooden/Pearlwood (vanilla) in case you're curious + + private static void RemoveLootRuleFromSkyCrates(ItemLoot loot) + { + List rules = loot.Get(false); + AlwaysAtleastOneSuccessDropRule main = null; + foreach (IItemDropRule rule in rules) + { + if (rule is AlwaysAtleastOneSuccessDropRule a) + main = a; + } + if (main is null) + return; + + // Remove the primary loot rule and the rule for Fledgling Wings + foreach (IItemDropRule rule in main.rules) + { + if (rule is OneFromOptionsNotScaledWithLuckDropRule one && one.chanceDenominator == 1) + { + one.chanceNumerator = 0; + continue; + } + if (rule is CommonDrop c && c.itemId == ItemID.CreativeWings) + { + c.chanceNumerator = 0; + continue; + } + } + } #endregion #region Goodie Bag Bat Hook diff --git a/Systems/Mechanic/RecipeSystem.cs b/Systems/Mechanic/RecipeSystem.cs index 15b8ecb5a8..d2a19e76fa 100644 --- a/Systems/Mechanic/RecipeSystem.cs +++ b/Systems/Mechanic/RecipeSystem.cs @@ -1541,14 +1541,6 @@ namespace CalamityMod.Systems r.Register(); r.DisableDecraft(); - // Fledgling Wings - r = Recipe.Create(ItemID.CreativeWings); - r.AddIngredient(2); - r.AddIngredient(ItemID.Cloud, 5); - r.AddIngredient(ItemID.Feather, 10); - r.AddTile(TileID.Anvils); - r.Register(); - // Flying Carpet r = Recipe.Create(ItemID.FlyingCarpet); r.AddIngredient(ItemID.Silk, 10);