Example #1
0
 public static bool AddEnchantment_Prefix(Tool __instance, BaseEnchantment enchantment, ref bool __result)
 {
     try
     {
         if (enchantment == null)
         {
             return(true);
         }
         if (!enchantment.IsForge() && !enchantment.IsSecondaryEnchantment())
         {
             // Enchantment is a primary enchantment.
             __instance.enchantments.Add(enchantment);
             enchantment.ApplyTo(__instance, __instance.getLastFarmerToUse());
             __result = true;
             return(false);  // don't run original logic
         }
         if (__instance is MeleeWeapon && enchantment.IsForge())
         {
             if (enchantment is DiamondEnchantment)
             {
                 // Skip adding diamond enchantments, they should result in 3 other enchantments getting added in Forge.
                 __result = true;
                 return(false);  // don't run original logic
             }
             // Enchantment is a Weapon forging or Galaxy Soul enchantment
         }
         return(true);  // run original logic
     }
     catch (Exception ex)
     {
         ModMonitor.Log($"Failed in {nameof(AddEnchantment_Prefix)}:\n{ex}", LogLevel.Error);
         return(true);  // run original logic
     }
 }
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 bool CanAddEnchantment_Prefix(Tool __instance, BaseEnchantment enchantment, ref bool __result)
 {
     try
     {
         if (enchantment == null)
         {
             return(true); // run original logic
         }
         if (__instance is MeleeWeapon && enchantment.IsForge())
         {
             if (enchantment is DiamondEnchantment && GetValidForgeEnchantmentsForTool(__instance).Count <= 0)
             {
                 // No more forge enchantments can be added.
                 __result = false;
                 return(false);
             }
             // Enchantment is a normal forge enchantment, check the existing level if there is one
             foreach (BaseEnchantment exisiting_enchantment in __instance.enchantments)
             {
                 if (enchantment.GetType() == exisiting_enchantment.GetType())
                 {
                     if (exisiting_enchantment.GetLevel() >= 3)
                     {
                         __result = false;
                         return(false);
                     }
                     break;
                 }
             }
             __result = true;
             return(false);
         }
         return(true);
     }
     catch (Exception ex)
     {
         ModMonitor.Log($"Failed in {nameof(CanAddEnchantment_Prefix)}:\n{ex}", LogLevel.Error);
         return(true); // run original logic
     }
 }
Example #4
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 #5
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
            }
        }