// RingChain.cs - Infinite Leaftide's ring inscription chain (Crafting > Rings), from UB-IT's // ImbueSpellCraftDefinitions / SpellcraftInventoryPolicy. // // Step 1: Quill of Infliction used on a Trophy -> Enlightened Quill of Infliction // Step 2: Enlightened Quill used on Ink of Partition -> partition quill // Step 3: partition quill used on a Glyph -> "Inscription of ..." scroll // Then each scroll is used on a ring / jewelry / weapon. // // Pure: ingredient matching (case-insensitive substrings with alternates and one exclude), the // craft queue order and the scroll-to-target pairing. RingChainRunner does the using. using System; using System.Collections.Generic; using System.Linq; namespace RynthCore.Plugin.RynthAi.MiniRemote.Crafting; /// One ingredient: the first of found in an item's name, unless it also has . internal sealed record RingIngredient(string Label, string[] Names, string Exclude = ""); /// One combine: is used on . /// 1 quill + trophy, 2 + ink, 3 + glyph: the queue runs every tier-1 run first. /// Step 3: the words the resulting inscription scroll's name carries. internal sealed record RingRecipe(string Id, int Tier, string Name, string Notes, RingIngredient Tool, RingIngredient Target, string[] ScrollMarkers); internal static class RingChain { /// Every inscription scroll's name has this. public const string InscriptionMarker = "Inscription of"; /// Most runs of one recipe the tab queues. public const int MaxRuns = 99; private static readonly RingIngredient PartitionQuill = new("Enlightened Infliction Quill of Partition", new[] { "Enlightened Infliction Quill of Partition", "Enlightened Quill of Infliction of Partition" }); private static RingRecipe Glyph(string id, string element, string scroll) => new( id, 3, $"Step 3: {element} glyph - {scroll}", $"Partition quill used on Glyph of {element} -> Inscription of {scroll} scroll.", PartitionQuill, // The full glyph name: a short one can match the wrong stack. new RingIngredient($"Glyph of {element}", new[] { $"Glyph of {element}" }), new[] { scroll, element }); /// The chain, in UB-IT's order. public static readonly RingRecipe[] Recipes = { new("ring2_step1_quill_trophy", 1, "Step 1: Quill of Infliction + Trophy", "Quill of Infliction used on a Trophy -> Enlightened Quill of Infliction.", new RingIngredient("Quill of Infliction", new[] { "Quill of Infliction", "Infliction Quill" }, Exclude: "Enlightened"), // Not plain "Trophy": scrolls and kits carry that word too. new RingIngredient("Trophy", new[] { "Royal Summons", "Empyrean Trophy", "Summoning Gem" }), Array.Empty()), new("ring2_step2_ink", 2, "Step 2: Enlightened Quill + Ink of Partition", "Enlightened Quill of Infliction (from Step 1) used on Ink of Partition -> partition quill.", new RingIngredient("Enlightened Quill of Infliction", new[] { "Enlightened Quill of Infliction", "Enlightened Infliction Quill", "Enlightened Infliction Quill of" }, Exclude: "Partition"), new RingIngredient("Ink of Partition", new[] { "Ink of Partition", "Partition Ink" }), Array.Empty()), Glyph("ring2_glyph_bludgeoning", "Bludgeoning", "Tectonic Rifts"), Glyph("ring2_glyph_lightning", "Lightning", "Eye of the Storm"), Glyph("ring2_glyph_piercing", "Piercing", "Nuhmudira's Spines"), Glyph("ring2_glyph_nether", "Nether", "Clouded Soul"), Glyph("ring2_glyph_corrosion", "Corrosion", "Searing Disc"), Glyph("ring2_glyph_frost", "Frost", "Halo of Frost"), Glyph("ring2_glyph_slashing", "Slashing", "Horizon's Blades"), Glyph("ring2_glyph_flame", "Flame", "Cassius' Ring of Fire"), }; /// True when an item's name is this ingredient. public static bool Matches(string? name, RingIngredient ing) { if (string.IsNullOrEmpty(name)) return false; if (ing.Exclude.Length > 0 && name.IndexOf(ing.Exclude, StringComparison.OrdinalIgnoreCase) >= 0) return false; foreach (string n in ing.Names) if (n.Length > 0 && name.IndexOf(n, StringComparison.OrdinalIgnoreCase) >= 0) return true; return false; } /// /// The craft queue: every Step 1 run, then every Step 2 run, then the glyphs, each tier in /// definition order (a later tier's ingredients come out of the earlier one). /// public static List Expand(Func runs) { var queue = new List(); foreach (var r in Recipes.OrderBy(r => r.Tier)) { int n = Math.Clamp(runs(r.Id), 0, MaxRuns); for (int i = 0; i < n; i++) queue.Add(r); } return queue; } /// The glyph recipe a scroll came from (null when its name has no known marker). public static RingRecipe? GlyphOf(string? scrollName) { if (string.IsNullOrEmpty(scrollName)) return null; foreach (var r in Recipes) foreach (string m in r.ScrollMarkers) if (scrollName.IndexOf(m, StringComparison.OrdinalIgnoreCase) >= 0) return r; return null; } public static bool IsInscriptionScroll(string? name) => !string.IsNullOrEmpty(name) && name.IndexOf(InscriptionMarker, StringComparison.OrdinalIgnoreCase) >= 0; /// /// Pairs scrolls with targets the way UB-IT does: scrolls by glyph recipe id (unknown ones /// last, by name), targets by object id, one scroll per target. /// public static List<(int Scroll, int Target)> PairScrolls(IEnumerable<(int Id, string Name)> scrolls, IEnumerable targets) { var ordered = scrolls .OrderBy(s => GlyphOf(s.Name)?.Id ?? "zzz_" + s.Name, StringComparer.Ordinal) .ThenBy(s => s.Id) .ToList(); var pairs = new List<(int, int)>(); int i = 0; foreach (int t in targets.Distinct().OrderBy(x => x)) { if (i >= ordered.Count) break; pairs.Add((ordered[i++].Id, t)); } return pairs; } }