public BaseEnchantment GetEnchantment(Item item, BaseEnchantment ench) { if (item is Tool tool) { return(tool.enchantments.FirstOrDefault(e => e.GetName() == ench.GetName())); } return(null); }
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); } }
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; }