public static bool IsEnchantedOrEnchantable(Item item) { if (item != null && item is Tool) { foreach (BaseEnchantment enchantment in (item as Tool).enchantments) { if (!enchantment.IsForge() && !enchantment.IsSecondaryEnchantment()) { return(true); } } if (BaseEnchantment.GetAvailableEnchantmentsForItem(item as Tool).Count > 0) { return(true); } } return(false); }
// Lists the next several enchantments to be applied to the given tool, // up to the given limit. public static List <Prediction> ListForTool(Tool tool, uint limit, bool cumulative = false) { Utilities.CheckWorldReady(); if (!IsAvailable) { throw new UnavailableException("enchantments"); } List <Prediction> predictions = new (); Tool fakeTool = tool.getOne() as Tool; // Start from the next enchantment and continue to the limit. uint fromNumber = Game1.stats.getStat("timesEnchanted"); for (uint number = fromNumber; number < fromNumber + limit; ++number) { // Select a random available enchantment per the base game rules. Random rng = new ((int)number + (int)Game1.uniqueIDForThisGame); var candidates = BaseEnchantment.GetAvailableEnchantmentsForItem(fakeTool); var enchantment = Utility.GetRandom(candidates, rng); predictions.Add(new () { number = number, enchantment = enchantment, }); // If the enchantments are cumulative on the tool itself, // simulate applying this enchantment to be ready for the next. if (cumulative && enchantment != null) { fakeTool.AddEnchantment(enchantment); fakeTool.previousEnchantments.Insert(0, enchantment.GetName()); while (fakeTool.previousEnchantments.Count > 2) { fakeTool.previousEnchantments.RemoveAt(fakeTool.previousEnchantments.Count - 1); } } } return(predictions); }
public static void GetEnchantmentFromItem_Post(Item base_item, Item item, ref BaseEnchantment __result) { try { if (!mod.Config.EnchantableScythes) { return; } if (base_item is MeleeWeapon weapon && weapon.isScythe(-1)) { // actual enchantments if (Utility.IsNormalObjectAtParentSheetIndex(item, 74)) { var enchantmentRandom = new Random((int)(Game1.stats.getStat("timesEnchanted") + (uint)((int)Game1.uniqueIDForThisGame))); __result = Utility.GetRandom(BaseEnchantment.GetAvailableEnchantmentsForItem(base_item as Tool), enchantmentRandom); return; } // weapon forging if (Utility.IsNormalObjectAtParentSheetIndex(item, 60)) { __result = new EmeraldEnchantment(); return; } if (Utility.IsNormalObjectAtParentSheetIndex(item, 62)) { __result = new AquamarineEnchantment(); return; } if (Utility.IsNormalObjectAtParentSheetIndex(item, 64)) { __result = new RubyEnchantment(); return; } if (Utility.IsNormalObjectAtParentSheetIndex(item, 66)) { __result = new AmethystEnchantment(); return; } if (Utility.IsNormalObjectAtParentSheetIndex(item, 68)) { __result = new TopazEnchantment(); return; } if (Utility.IsNormalObjectAtParentSheetIndex(item, 70)) { __result = new JadeEnchantment(); return; } // deleted diamond case __result = null; } } catch (Exception e) { mod.ErrorLog("There was an exception in a patch", e); } }