/// <summary>
 /// Function that substitutes in an enchantment.
 /// </summary>
 /// <param name="base_item">Tool.</param>
 /// <param name="item">Thing to enchant with.</param>
 /// <returns>Enchanment to substitute in.</returns>
 public static BaseEnchantment SubstituteEnchantment(Item base_item, Item item)
 {
     try
     {
         if (Utility.IsNormalObjectAtParentSheetIndex(item, 74) && ForgeMenuPatches.CurrentSelection is not null)
         {
             BaseEnchantment output = ForgeMenuPatches.CurrentSelection;
             ForgeMenuPatches.TrashMenu();
             return(output);
         }
     }
     catch (Exception ex)
     {
         ModEntry.ModMonitor.Log($"Failed in forcing selection of enchantment.\n\n{ex}", LogLevel.Error);
     }
     return(BaseEnchantment.GetEnchantmentFromItem(base_item, item));
 }
Example #2
0
        public static void Forge_Post(MeleeWeapon __instance, Item item, bool count_towards_stats, ref bool __result)
        {
            try
            {
                if (!mod.Config.EnchantableScythes || !__instance.isScythe(-1))
                {
                    return;
                }

                if (item is MeleeWeapon other_weapon && other_weapon.type == __instance.type)
                {
                    __instance.appearance.Value = (__instance.IndexOfMenuItemView = other_weapon.getDrawnItemIndex());
                    __result = true;
                    return;
                }

                BaseEnchantment enchantment = BaseEnchantment.GetEnchantmentFromItem(__instance, item);
                if (enchantment != null && __instance.AddEnchantment(enchantment))
                {
                    // deleted diamond case

                    if (count_towards_stats && !enchantment.IsForge())
                    {
                        __instance.previousEnchantments.Insert(0, enchantment.GetName());
                        while (__instance.previousEnchantments.Count > 2)
                        {
                            __instance.previousEnchantments.RemoveAt(__instance.previousEnchantments.Count - 1);
                        }
                        Game1.stats.incrementStat("timesEnchanted", 1);
                    }

                    __result = true;
                    return;
                }

                __result = false;
            }
            catch (Exception e)
            {
                mod.ErrorLog("There was an exception in a patch", e);
            }
        }
Example #3
0
        public static void Forge_Postfix(Tool __instance, ref bool __result, Item item, bool count_towards_stats = false)
        {
            BaseEnchantment enchantment = BaseEnchantment.GetEnchantmentFromItem(__instance, item);

            if (__instance is Slingshot && enchantment != null)
            {
                if (enchantment is GalaxySoulEnchantment && __instance is Slingshot sling && sling.CurrentParentTileIndex == 34 && sling.GetEnchantmentLevel <GalaxySoulEnchantment>() >= 3)
                {
                    __instance.CurrentParentTileIndex = ModEntry.Instance.config.InfinitySlingshotId;
                    __instance.InitialParentTileIndex = ModEntry.Instance.config.InfinitySlingshotId;
                    __instance.IndexOfMenuItemView    = ModEntry.Instance.config.InfinitySlingshotId;
                    string[] slingData = Game1.content.Load <Dictionary <int, string> >("Data\\weapons")[__instance.InitialParentTileIndex].Split('/');
                    __instance.BaseName    = slingData[0];
                    __instance.description = slingData[1];

                    GalaxySoulEnchantment enchant = __instance.GetEnchantmentOfType <GalaxySoulEnchantment>();
                    if (enchant != null)
                    {
                        __instance.RemoveEnchantment(enchant);
                    }
                }
                if (count_towards_stats && !enchantment.IsForge())
                {
                    __instance.previousEnchantments.Insert(0, enchantment.GetName());
                    while (__instance.previousEnchantments.Count > 2)
                    {
                        __instance.previousEnchantments.RemoveAt(__instance.previousEnchantments.Count - 1);
                    }
                    Game1.stats.incrementStat("timesEnchanted", 1);
                }
                __result = true;
                return;
            }
            __result = false;
            return;
        }
Example #4
0
        public static bool Forge_Prefix(Tool __instance, Item item, ref bool __result)
        {
            try
            {
                BaseEnchantment enchantment = BaseEnchantment.GetEnchantmentFromItem(__instance, item);
                // This gets displayed twice because the game does it once to display the "Result" item in the menu.
                ModMonitor.Log($"Adding {(enchantment != null ? (enchantment.IsForge() ? "forge enchantment" : enchantment.GetDisplayName()) : "null enchantment")} from item {(item != null ? item.Name : "null")} to tool {__instance.Name}", LogLevel.Debug);
                if (enchantment != null && enchantment is DiamondEnchantment)
                {
                    // Diamond Enchantment is now replaced with up to 3 other random enchantments. Still get a slight discount on the cost.
                    if (GetValidForgeEnchantmentsForTool(__instance).Count <= 0)
                    {
                        __result = false;
                        return(false);
                    }
                    for (int i = 0; i < 3; i++)
                    {
                        // Try to add 3 new enchantments.
                        List <int> valid_forges = GetValidForgeEnchantmentsForTool(__instance);
                        if (valid_forges.Count <= 0)
                        {
                            // Can't add enchantments
                            break;
                        }
                        int index          = Game1.random.Next(valid_forges.Count);
                        int random_enchant = valid_forges[index];
                        switch (random_enchant)
                        {
                        case 0:
                            ModMonitor.Log($"Adding Emerald Enchantment as part of Diamond Enchantment process", LogLevel.Trace);
                            __instance.AddEnchantment(new EmeraldEnchantment());
                            break;

                        case 1:
                            ModMonitor.Log($"Adding Emerald Aquamarine as part of Diamond Enchantment process", LogLevel.Trace);
                            __instance.AddEnchantment(new AquamarineEnchantment());
                            break;

                        case 2:
                            ModMonitor.Log($"Adding Ruby Enchantment as part of Diamond Enchantment process", LogLevel.Trace);
                            __instance.AddEnchantment(new RubyEnchantment());
                            break;

                        case 3:
                            ModMonitor.Log($"Adding Amethyst Enchantment as part of Diamond Enchantment process", LogLevel.Trace);
                            __instance.AddEnchantment(new AmethystEnchantment());
                            break;

                        case 4:
                            ModMonitor.Log($"Adding Topaz Enchantment as part of Diamond Enchantment process", LogLevel.Trace);
                            __instance.AddEnchantment(new TopazEnchantment());
                            break;

                        case 5:
                            ModMonitor.Log($"Adding Jade Enchantment as part of Diamond Enchantment process", LogLevel.Trace);
                            __instance.AddEnchantment(new JadeEnchantment());
                            break;
                        }
                    }
                    __result = true;
                    return(false); // don't run original logic
                }
                return(true);      // run original logic
            }
            catch (Exception ex)
            {
                ModMonitor.Log($"Failed in {nameof(Forge_Prefix)}:\n{ex}", LogLevel.Error);
                return(true); // run original logic
            }
        }