diff --git a/docs/launcher.md b/docs/launcher.md index dfe1e5c..11a83ae 100644 --- a/docs/launcher.md +++ b/docs/launcher.md @@ -1414,16 +1414,22 @@ taskbar, with Minimize and Maximize, not kept in front of Waypoint's. It makes a write and gives it to the character in game. - **Base** (left): the item classes as icons (Material Design's, no game artwork), a search and the bases with their - class, drop level and attribute requirements. Choosing one puts its implicits on the item; explicit modifiers the new - base can have stay. + class, drop level and attribute requirements. Choosing one puts its implicits on the item, and the enchantments a new + item of that base has: a cluster jewel's "Adds N Passive Skills", which also holds its theme (what its small passives + grant), and its jewel sockets. Without them it adds no passive. Explicit modifiers the new base can have stay. - **Add modifiers** (left): one kind at a time: prefixes, suffixes, the bench's crafted modifiers, what each influence - on the item adds, corruption and Eldritch implicits, or any modifier without rules. Each shows its tier (T1 the best), + on the item adds, the base's enchantments (to put one back), corruption and Eldritch implicits, or any modifier + without rules. Each shows its tier (T1 the best), its range as the game words it, its affix name and the item level it needs; **Best tier only** keeps the best tier for the item level of each group, **Above item level** also lists those that need more. Double-click, Enter or **+** adds one. - The item (middle): rarity, item level, quality, sockets as `/sockets` takes them (shown as coloured, linked circles; empty for what a new item gets), the states and influences, a rare's name from the game's two word lists (or random), and the modifiers. Each modifier has its kind, a tier list to change tier, its line with the current values, a slider - and a box per value (any whole number is accepted), and up, down and remove. The prefix and suffix count for the rarity + and a box per value (any whole number is accepted), and up, down and remove. A base's enchantment has the range the + base gives it: 8 to 12 passives on a Large Cluster Jewel. On a cluster jewel, **Small passives grant** is a list of + the size's themes by name (the game's own value is a number), and the socket enchantment has a list of its socket + counts. The theme decides the jewel's affixes: Prefixes and Suffixes then list that theme's notables ("1 Added + Passive Skill is …") with the modifiers every theme has. The prefix and suffix count for the rarity shows above them, and two modifiers of one group are marked; neither is refused. - **Preview** (right): the item as text in the game's rarity and modifier colours (readable on every scheme), with its name, item level, requirements, sockets, implicits, modifiers and states. @@ -1440,8 +1446,10 @@ write and gives it to the character in game. Each line is matched to the modifier the game words that way: the Mods.dat Ids PoB writes for an item crafted in it, and the game's tier ranges and affix names (Ctrl+Alt+C, a header per modifier) come first, then the base's own pools; the values are the ones that give the line's numbers (outside the tier's range only when no tier gives them). - Enchantments and lines no modifier words are left out. Uniques are refused: the crafter makes normal, magic and rare - items. `ItemImport.cs`, `ItemImportWindow`. + The base's own enchantments go on as on a new item, each with what the item's lines say: a cluster jewel's passive + count ("Adds 10 Passive Skills"), its socket count and its theme ("Added Small Passive Skills grant: …"), whose + notables are then found among that theme's affixes. Other enchantments and lines no modifier words are left out. Uniques are refused: the + crafter makes normal, magic and rare items. `ItemImport.cs`, `ItemImportWindow`. - **Give item** gives the item to the character in game, into the main inventory, through the Waypoint Tools mod (LocalExile-Mods' `waypoint-tools`, `WaypointToolsMod.cs`), the same on a source copy and a release; it needs no other mod and no Frida. The mod counts as loaded when its `data/waypoint-tools/loaded.json` names a Gateway process that still @@ -1461,7 +1469,13 @@ write and gives it to the character in game. The data is the Gateway's own (`GameServer.Gateway crafter`, read once per Gateway build): the bases, the modifiers each can have (the server's own rolling rules), their stat descriptions in English (the checkout's -`data/stat-descriptions.txt`) and the name words. `CrafterCatalog.cs` reads it and words the modifiers. +`data/stat-descriptions.txt`) and the name words. `CrafterCatalog.cs` reads it and words the modifiers. A base's +enchantments are its `enchants` there, sent to `/item_give` in the `enchant` list; a cluster jewel base also has +`cluster`: the mod that holds the theme and the passive count, the mod for each socket count, and each theme with the +value that names it, what a small passive grants and the affix pool it opens (the server's +`Agents/docs/dev/item-crafter.md`, "Cluster jewels"). The game words a theme from its value alone, so Waypoint words it +from the theme's stats. A Gateway that does not list these yet shows a cluster jewel without enchantments; a server +with cluster jewel themes still gives such a jewel a random theme and count, an older one a jewel that adds no passive. A Gateway built before the hook does not know `crafter` and would start for real, so Waypoint first reads the Gateway's assembly (`GameServer.Gateway.dll`, beside a release's `app\GameServer.Gateway.exe`) without running it, and goes on only diff --git a/src/Launcher.Core/Resources/Strings.resx b/src/Launcher.Core/Resources/Strings.resx index 0384c9d..905ae4e 100644 --- a/src/Launcher.Core/Resources/Strings.resx +++ b/src/Launcher.Core/Resources/Strings.resx @@ -3583,6 +3583,9 @@ Search limits reached; other checkouts may exist. Browse to any location. Spell + + Jewel sockets + Sickle @@ -3816,6 +3819,9 @@ Switching to it builds and runs that code on this computer with your rights, liv Add to the item + + Small passives grant + Builds @@ -6843,6 +6849,9 @@ Owned servers will stop. Automatic backup is {2}. Source, client and login keys This client is incomplete and cannot be used. + + Enchantments + Back to My Mods @@ -8565,6 +8574,9 @@ The client must be a version this LocalExile runs. Or choose Game client in the Shrine + + Enchantment + Targets stronger text contrast and may adjust button fills. diff --git a/src/Launcher.Core/Resources/Strings.ru.resx b/src/Launcher.Core/Resources/Strings.ru.resx index 6861720..18d2887 100644 --- a/src/Launcher.Core/Resources/Strings.ru.resx +++ b/src/Launcher.Core/Resources/Strings.ru.resx @@ -3583,6 +3583,9 @@ Заклинание + + Гнёзда для самоцветов + Серп @@ -3816,6 +3819,9 @@ Добавить на предмет + + Малые умения даруют + Сборки @@ -6843,6 +6849,9 @@ Этот клиент неполный, использовать его нельзя. + + Зачарования + Назад к моим модам @@ -8565,6 +8574,9 @@ Святилище + + Зачарование + Усиливает контрастность текста; при необходимости меняет фон кнопок. diff --git a/src/Launcher.Core/Resources/Strings.zh-CN.resx b/src/Launcher.Core/Resources/Strings.zh-CN.resx index b70154c..833af69 100644 --- a/src/Launcher.Core/Resources/Strings.zh-CN.resx +++ b/src/Launcher.Core/Resources/Strings.zh-CN.resx @@ -3583,6 +3583,9 @@ 法术 + + 珠宝插槽 + 镰刀 @@ -3816,6 +3819,9 @@ 添加到物品 + + 小型天赋给予 + 构建 @@ -6843,6 +6849,9 @@ 此客户端不完整,无法使用。 + + 附魔 + 返回我的模组 @@ -8565,6 +8574,9 @@ Gateway 最近报告的事件。打开 Gateway 输出查看详情。 神殿 + + 附魔 + 追求更强的文字对比度,并可能调整按钮填充色。 diff --git a/src/Waypoint/CrafterCatalog.cs b/src/Waypoint/CrafterCatalog.cs index 0272dac..509da20 100644 --- a/src/Waypoint/CrafterCatalog.cs +++ b/src/Waypoint/CrafterCatalog.cs @@ -16,10 +16,28 @@ sealed record CraftMod(string Id, string Name, int Generation, int Domain, int L public string Group => $"{Generation}/{string.Join(',', Families)}/{string.Join(',', Stats.Select(s => s.Id))}"; } +/// A mod a new item of a base has in its enchant list (the catalog's "enchants"): a value per stat, and the +/// range the base gives each value. A cluster jewel's passives come from these. +sealed record CraftEnchant(string Id, IReadOnlyList Values, IReadOnlyList<(int Min, int Max)> Ranges); + +/// What a cluster jewel's small passives are: one of its base's "themes". +/// What the first value of the passives mod is for this theme. +/// What a small passive grants (each stat's Min and Max are its one value). +/// The affix pool of a jewel with this theme: its notables are in it. +sealed record CraftTheme(int Value, string Name, string Tag, IReadOnlyList Stats, int Pool); + +/// What a cluster jewel base's enchantments can be changed to (the catalog's "cluster"). +/// The mod whose values are the theme and the passive count. +/// The mod for each jewel socket count; none on a small jewel. +sealed record CraftCluster(int Size, string Passives, int Min, int Max, IReadOnlyList<(int Count, string Mod)> Sockets, + IReadOnlyList Themes); + /// "pool" (prefixes and suffixes), "crafted", "corrupted", "eldritch", and "shaper" … "warlord" (what /// an influence adds). +/// Empty for most bases, and for every base of a Gateway that does not list them yet. sealed record CraftBase(string Id, string Name, string Class, int Width, int Height, int DropLevel, IReadOnlyList Requirements, - int Sockets, bool Quality, IReadOnlyList Implicits, IReadOnlyDictionary Pools); + int Sockets, bool Quality, IReadOnlyList Implicits, IReadOnlyDictionary Pools, IReadOnlyList Enchants, + CraftCluster? Cluster = null); sealed record DescriptionVariant(IReadOnlyList When, string Text, IReadOnlyList<(string Name, int Stat)> Handlers); @@ -140,7 +158,9 @@ [.. e.GetProperty("tags").EnumerateArray().Select(t => t.GetString()!)], foreach (var i in influence.EnumerateObject()) pools[i.Name] = i.Value.GetInt32(); bases.Add(new CraftBase(Str(e, "id"), Str(e, "name"), Str(e, "class"), Int(e, "width"), Int(e, "height"), Int(e, "dropLevel"), [.. e.GetProperty("requirements").EnumerateArray().Select(r => r.GetInt32())], Int(e, "sockets"), - e.GetProperty("quality").GetBoolean(), [.. e.GetProperty("implicits").EnumerateArray().Select(m => m.GetString()!)], pools)); + e.GetProperty("quality").GetBoolean(), [.. e.GetProperty("implicits").EnumerateArray().Select(m => m.GetString()!)], pools, + e.TryGetProperty("enchants", out var enchants) ? [.. enchants.EnumerateArray().Select(Enchant)] : [], + e.TryGetProperty("cluster", out var cluster) ? Cluster(cluster) : null)); break; case "desc": var description = new StatDescription([.. e.GetProperty("stats").EnumerateArray().Select(s => s.GetString()!)], @@ -158,14 +178,84 @@ [.. v.GetProperty("when").EnumerateArray().Select(w => w.GetString()!)], Str(v, return new(classes, bases, mods, resolved, descriptions, words); } + /// One of a base's "enchants": {"id", "values", "ranges": [[min, max] …]}. + static CraftEnchant Enchant(JsonElement e) => new(Str(e, "id"), + [.. e.GetProperty("values").EnumerateArray().Select(v => v.GetInt32())], + e.TryGetProperty("ranges", out var ranges) ? [.. ranges.EnumerateArray().Select(r => (r[0].GetInt32(), r[1].GetInt32()))] : []); + + /// A base's "cluster": {"size", "passives": {"mod", "min", "max"}, "sockets": [{"count", "mod"}], + /// "themes": [{"value", "name", "tag", "stats": [{"id", "value"}], "pool"}]}. + static CraftCluster Cluster(JsonElement e) + { + var passives = e.GetProperty("passives"); + return new(Int(e, "size"), Str(passives, "mod"), Int(passives, "min"), Int(passives, "max"), + [.. e.GetProperty("sockets").EnumerateArray().Select(s => (Int(s, "count"), Str(s, "mod")))], + [.. e.GetProperty("themes").EnumerateArray().Select(t => new CraftTheme(Int(t, "value"), Str(t, "name"), Str(t, "tag"), + [.. t.GetProperty("stats").EnumerateArray().Select(s => new CraftStat(Str(s, "id"), Int(s, "value"), Int(s, "value")))], Int(t, "pool")))]); + } + static string Str(JsonElement e, string name) => e.GetProperty(name).GetString() ?? ""; static int Int(JsonElement e, string name) => e.GetProperty(name).GetInt32(); - public IReadOnlyList Pool(CraftBase b, string key) => - b.Pools.TryGetValue(key, out int id) && Pools.TryGetValue(id, out var pool) ? pool : []; + /// A base's pool, for an item with these mods: a cluster jewel's affixes ("pool") are its theme's, where its + /// notables are; without a theme, and for every other pool, the base's own. + public IReadOnlyList Pool(CraftBase b, string key, IEnumerable? mods = null) => + Pools.TryGetValue(PoolId(b, key, mods), out var pool) ? pool : []; + + /// The id of that pool, or -1 when the base has none of the kind. + public int PoolId(CraftBase b, string key, IEnumerable? mods = null) => + key == "pool" && mods is not null && Theme(b, mods) is { } theme ? theme.Pool : b.Pools.GetValueOrDefault(key, -1); + + /// The stat of a cluster jewel's passives mod whose value is the theme. + public const string ThemeStat = "local_jewel_expansion_passive_node_index"; + + /// Which of the passives mod's values is the theme, or -1 (not a cluster jewel, or a Gateway without it). + public int ThemeIndex(CraftBase b) => + b.Cluster is { } cluster && Mods.GetValueOrDefault(cluster.Passives) is { } mod ? mod.Stats.ToList().FindIndex(s => s.Id == ThemeStat) : -1; + + /// The theme a cluster jewel's mods name, or null: no cluster jewel, or a value that is no theme of its size. + public CraftTheme? Theme(CraftBase b, IEnumerable mods) + { + int at = ThemeIndex(b); + return at >= 0 && mods.FirstOrDefault(m => m.Id == b.Cluster!.Passives) is { } passives && at < passives.Values.Count + ? b.Cluster!.Themes.FirstOrDefault(t => t.Value == passives.Values[at]) : null; + } + + /// The lines the game shows for a theme, which it words from the theme's value alone: "Added Small Passive + /// Skills grant: 12% increased Fire Damage", one for each thing a small passive grants. + public IReadOnlyList ThemeLines(CraftTheme theme) => + [.. ModText.Lines(new CraftMod("", "", 0, 0, 0, [], [], theme.Stats), Description, null).Where(l => l.Length > 0).Select(l => "Added Small Passive Skills grant: " + l)]; + + /// The lines of a mod on an item of the base, with its values. A cluster jewel's passives mod also reads + /// with its theme's lines. + public IReadOnlyList Lines(CraftBase? b, CraftedMod m, CraftMod mod) => + b?.Cluster?.Passives == mod.Id && Theme(b, [m]) is { } theme ? [.. Lines(mod, m.Values), .. ThemeLines(theme)] : Lines(mod, m.Values); public StatDescription? Description(string stat) => _descriptions.GetValueOrDefault(stat); + /// The mods a new item of the base has: its enchantments with the base's values (a cluster jewel adds no + /// passive without them), then its implicits at their best. + public List NewMods(CraftBase b) => + [.. b.Enchants.Where(e => Mods.ContainsKey(e.Id)).Select(e => new CraftedMod { Id = e.Id, Section = "enchant", Values = [.. e.Values] }), + .. b.Implicits.Select(Mods.GetValueOrDefault).OfType().Select(m => NewMod(b, m, "implicit"))]; + + /// A mod as it is added to an item of the base: an enchantment of the base with the base's values, any other + /// at the top of its range. + public static CraftedMod NewMod(CraftBase? b, CraftMod mod, string section) => + section == "enchant" && b?.Enchants.FirstOrDefault(e => e.Id == mod.Id) is { } enchant + ? new() { Id = mod.Id, Section = section, Values = [.. enchant.Values] } + : new() { Id = mod.Id, Section = section, Values = [.. mod.Stats.Select(s => Math.Max(s.Min, s.Max))] }; + + /// The range of one value of a mod on an item of the base: the base's for one of its enchantments (the game's + /// data gives a cluster jewel's passive count no range of its own), else the mod's. + public static (int Min, int Max) Range(CraftBase? b, CraftedMod m, CraftMod mod, int index) + { + if (m.Section == "enchant" && b?.Enchants.FirstOrDefault(e => e.Id == m.Id) is { } enchant && index < enchant.Ranges.Count) + return enchant.Ranges[index]; + var stat = mod.Stats[index]; + return (Math.Min(stat.Min, stat.Max), Math.Max(stat.Min, stat.Max)); + } + /// The mod's tier among the pool's mods of its group: 1 the highest level. public int Tier(int pool, CraftMod mod) { @@ -233,6 +323,9 @@ static int IndexOf(CraftMod mod, string stat) var variant = d.Variants.FirstOrDefault(v => Matches(v, ranges.Select(r => r.Max).ToList())) ?? d.Variants.FirstOrDefault(v => Matches(v, ranges.Select(r => r.Min).ToList())); if (variant is null) return null; + // The game words this value as the passive of that number (a cluster jewel's "Added Small Passive Skills grant: …"), + // which the catalog does not hold: no line, rather than the bare number. + if (variant.Handlers.Any(h => h.Name == "tree_expansion_jewel_passive")) return null; int next = 0; // A line break in a description is written "\n", as in the client's file. return Placeholder.Replace(variant.Text.Replace("\\n", "\n"), m => diff --git a/src/Waypoint/ItemCrafterWindow.xaml.cs b/src/Waypoint/ItemCrafterWindow.xaml.cs index 8dbccee..76a863a 100644 --- a/src/Waypoint/ItemCrafterWindow.xaml.cs +++ b/src/Waypoint/ItemCrafterWindow.xaml.cs @@ -273,22 +273,23 @@ void BaseChosen(object sender, SelectionChangedEventArgs e) SetBase(row.Base); } - /// A new base: its implicits replace the old ones; explicit modifiers it can have stay. + /// A new base: its enchantments and implicits replace the old ones; explicit modifiers it can have stay. void SetBase(CraftBase b) { if (_catalog is null) return; - var kept = _item.Mods.Where(m => m.Section != "implicit" && b.Pools.Keys.Any(k => _catalog.Pool(b, k).Any(p => p.Id == m.Id))).ToList(); + // What the new base can have, with the theme a new item of it starts with. + var start = _catalog.NewMods(b); + var kept = _item.Mods.Where(m => m.Section == "explicit" && b.Pools.Keys.Any(k => _catalog.Pool(b, k, start).Any(p => p.Id == m.Id))).ToList(); _base = b; _item.Base = b.Id; - _item.Mods = [.. b.Implicits.Select(_catalog.Mods.GetValueOrDefault).OfType().Select(m => NewMod(m, "implicit")), .. kept]; + _item.Mods = [.. start, .. kept]; if (!b.Quality) _item.Quality = 0; if (b.Sockets == 0) _item.Sockets = null; ShowItem(); ShowModKinds(); } - static CraftedMod NewMod(CraftMod mod, string section) => - new() { Id = mod.Id, Section = section, Values = [.. mod.Stats.Select(s => Math.Max(s.Min, s.Max))] }; + CraftedMod NewMod(CraftMod mod, string section) => CrafterCatalog.NewMod(_base, mod, section); // --- The modifiers to add --- @@ -298,6 +299,9 @@ sealed record ModKindChoice(string Label, string Pool, string Section, Func Label; } + /// The kind that lists the base's own enchantments: not one of its pools. + const string BaseEnchants = "enchants"; + void ShowModKinds() { if (_catalog is null) return; @@ -311,6 +315,8 @@ void ShowModKinds() foreach (string influence in Influences) if (_base?.Pools.ContainsKey(influence) == true) kinds.Add(new(L.Text("{0} modifiers", StateName(influence)), influence, "explicit", _ => true)); + // What a new item of the base has in its enchant list (a cluster jewel's passives), to put one back. + if (_base?.Enchants.Count > 0) kinds.Add(new(L.Text("Enchantments"), BaseEnchants, "enchant", _ => true)); kinds.Add(new(L.Text("Corruption implicits"), "corrupted", "implicit", _ => true)); kinds.Add(new(L.Text("Eldritch implicits"), "eldritch", "implicit", _ => true)); kinds.Add(new(L.Text("Any modifier (no rules)"), "", "explicit", _ => true)); @@ -335,7 +341,8 @@ void ShowMods() int level = _item.ItemLevel; IEnumerable<(CraftMod Mod, int Pool)> mods = kind.Pool.Length == 0 ? _catalog.Mods.Values.Select(m => (m, -1)) - : _base.Pools.TryGetValue(kind.Pool, out int pool) ? _catalog.Pools[pool].Where(kind.Filter).Select(m => (m, pool)) : []; + : kind.Pool == BaseEnchants ? _base.Enchants.Select(e => _catalog.Mods.GetValueOrDefault(e.Id)).OfType().Select(m => (m, -1)) + : _catalog.PoolId(_base, kind.Pool, _item.Mods) is var pool && _catalog.Pools.TryGetValue(pool, out var listed) ? listed.Where(kind.Filter).Select(m => (m, pool)) : []; var rows = new List(); foreach (var group in mods.GroupBy(p => p.Mod.Group)) { @@ -345,7 +352,8 @@ void ShowMods() : tiers.Where(p => AnyLevel.IsChecked == true || p.Mod.Level <= level); foreach (var (mod, poolId) in shown) { - var lines = _catalog.Lines(mod); + // One of the base's enchantments reads with the values it is added with. + var lines = kind.Pool == BaseEnchants ? _catalog.Lines(mod, NewMod(mod, kind.Section).Values) : _catalog.Lines(mod); string text = lines.Count > 0 ? string.Join("\n", lines) : $"{mod.Id} ({string.Join(", ", mod.Stats.Select(s => s.Id))})"; if (search.Length > 0 && !text.Contains(search, StringComparison.OrdinalIgnoreCase) && !mod.Id.Contains(search, StringComparison.OrdinalIgnoreCase) && !mod.Name.Contains(search, StringComparison.OrdinalIgnoreCase) && !mod.Tags.Any(t => t.Contains(search, StringComparison.OrdinalIgnoreCase))) @@ -590,7 +598,7 @@ void ShowItem() _ => 0, }; - string KindOf(CraftMod mod, CraftedMod m) => mod.Generation switch + string KindOf(CraftMod mod, CraftedMod m) => m.Section == "enchant" ? L.Text("Enchantment") : mod.Generation switch { 1 => mod.Domain == 9 ? L.Text("Crafted prefix") : L.Text("Prefix"), 2 => mod.Domain == 9 ? L.Text("Crafted suffix") : L.Text("Suffix"), @@ -685,8 +693,27 @@ void Move(int by) DockPanel.SetDock(tierBox, Dock.Left); head.Children.Add(tierBox); } + // A cluster jewel's socket enchantment is one mod per socket count: choosing a count changes the mod. + if (_base?.Cluster is { Sockets.Count: > 1 } sized && sized.Sockets.Any(s => s.Mod == mod.Id)) + { + var socketBox = new ComboBox { Margin = new Thickness(0, 0, 8, 0), MinWidth = 48, VerticalAlignment = VerticalAlignment.Center, FontSize = 12, ToolTip = L.Text("Jewel sockets") }; + System.Windows.Automation.AutomationProperties.SetName(socketBox, L.Text("Jewel sockets")); + foreach (var (count, id) in sized.Sockets) + if (catalog.Mods.GetValueOrDefault(id) is { } socket) socketBox.Items.Add(new ComboBoxItem { Content = count.ToString(), Tag = socket }); + socketBox.SelectedIndex = socketBox.Items.Cast().ToList().FindIndex(i => ((CraftMod)i.Tag).Id == mod.Id); + socketBox.SelectionChanged += (_, _) => + { + if (socketBox.SelectedItem is ComboBoxItem { Tag: CraftMod chosen } && chosen.Id != m.Id) + { + _item.Mods[_item.Mods.IndexOf(m)] = new CraftedMod { Id = chosen.Id, Section = m.Section, Values = [.. chosen.Stats.Select(s => Math.Max(s.Min, s.Max))] }; + ShowItem(); + } + }; + DockPanel.SetDock(socketBox, Dock.Left); + head.Children.Add(socketBox); + } var text = new TextBlock { TextWrapping = TextWrapping.Wrap, VerticalAlignment = VerticalAlignment.Center, FontWeight = FontWeights.SemiBold }; - void ShowText() => text.Text = ModLine(mod, m.Values); + void ShowText() => text.Text = ModLine(m, mod); ShowText(); head.Children.Add(text); @@ -698,7 +725,31 @@ void Move(int by) var stat = mod.Stats[i]; int index = i; while (m.Values.Count <= index) m.Values.Add(stat.Max); - int min = Math.Min(stat.Min, stat.Max), max = Math.Max(stat.Min, stat.Max); + var (min, max) = CrafterCatalog.Range(_base, m, mod, index); + // A cluster jewel's theme is a value that names one: chosen by its name, not typed. It decides which + // notables the jewel can have, so the whole item is shown again. + if (_base?.Cluster is { } themed && themed.Passives == mod.Id && stat.Id == CrafterCatalog.ThemeStat && themed.Themes.Count > 0) + { + var themeRow = new DockPanel { Margin = new Thickness(0, 2, 6, 2) }; + var themeLabel = new TextBlock { Text = L.Text("Small passives grant"), Width = 190, FontSize = 11, VerticalAlignment = VerticalAlignment.Center, TextTrimming = TextTrimming.CharacterEllipsis, TextWrapping = TextWrapping.NoWrap }; + themeLabel.SetResourceReference(TextBlock.ForegroundProperty, "Shell.TextSecondary"); + DockPanel.SetDock(themeLabel, Dock.Left); + themeRow.Children.Add(themeLabel); + var themeBox = new ComboBox { FontSize = 12, VerticalAlignment = VerticalAlignment.Center }; + System.Windows.Automation.AutomationProperties.SetName(themeBox, L.Text("Small passives grant")); + foreach (var theme in themed.Themes) + themeBox.Items.Add(new ComboBoxItem { Content = theme.Name, Tag = theme, ToolTip = string.Join("\n", catalog.ThemeLines(theme)) }); + themeBox.SelectedIndex = themed.Themes.ToList().FindIndex(t => t.Value == m.Values[index]); + themeBox.SelectionChanged += (_, _) => + { + if (_updating || themeBox.SelectedItem is not ComboBoxItem { Tag: CraftTheme chosen } || chosen.Value == m.Values[index]) return; + m.Values[index] = chosen.Value; + ShowItem(); + }; + themeRow.Children.Add(themeBox); + sliders.Children.Add(themeRow); + continue; + } var row = new DockPanel { Margin = new Thickness(0, 2, 6, 0) }; var label = new TextBlock { Text = stat.Id.Replace('_', ' '), Width = 190, FontSize = 11, TextTrimming = TextTrimming.CharacterEllipsis, TextWrapping = TextWrapping.NoWrap, ToolTip = stat.Id }; label.SetResourceReference(TextBlock.ForegroundProperty, "Shell.TextSecondary"); @@ -752,17 +803,18 @@ Button IconButton(PackIconKind icon, string tip, Action click) int PoolOf(CraftMod mod, string section) { if (_base is null || _catalog is null) return -1; - foreach (var (key, id) in _base.Pools) - if ((section == "implicit") == (key is "corrupted" or "eldritch") && _catalog.Pools.TryGetValue(id, out var pool) && pool.Any(p => p.Id == mod.Id)) + foreach (string key in _base.Pools.Keys) + if ((section == "implicit") == (key is "corrupted" or "eldritch") && _catalog.PoolId(_base, key, _item.Mods) is var id + && _catalog.Pools.TryGetValue(id, out var pool) && pool.Any(p => p.Id == mod.Id)) return id; return -1; } - /// A mod with its values as one line of text, or its Id and values when the game has no words for it. - string ModLine(CraftMod mod, IReadOnlyList values) + /// A mod of the item with its values as text, or its Id and values when the game has no words for it. + string ModLine(CraftedMod m, CraftMod mod) { - var lines = _catalog!.Lines(mod, values); - return lines.Count > 0 ? string.Join("\n", lines) : $"{mod.Id}: {string.Join(", ", values)}"; + var lines = _catalog!.Lines(_base, m, mod); + return lines.Count > 0 ? string.Join("\n", lines) : $"{mod.Id}: {string.Join(", ", m.Values)}"; } // --- The preview --- @@ -855,15 +907,25 @@ void Separator() else if (_item.Sockets is null) Line(L.Text("Sockets: as a new item gets them"), size: 11.5); } - var implicits = _item.Mods.Where(m => m.Section != "explicit").ToList(); + // As the game lists them: enchantments, implicits, then the rest. + var enchants = _item.Mods.Where(m => m.Section == "enchant").ToList(); + var implicits = _item.Mods.Where(m => m.Section is not ("explicit" or "enchant")).ToList(); var explicits = _item.Mods.Where(m => m.Section == "explicit").ToList(); void Mods(IEnumerable list) { foreach (var m in list) if (_catalog.Mods.GetValueOrDefault(m.Id) is { } mod) - foreach (string line in ModLine(mod, m.Values).Split('\n')) + foreach (string line in ModLine(m, mod).Split('\n')) Line(line, GameColour(mod.Domain == 9 ? "crafted" : "mod")); } + if (enchants.Count > 0) + { + Separator(); + // A cluster jewel's theme reads after its passive count and its sockets, as on the game's item. + var lines = enchants.Where(m => _catalog.Mods.ContainsKey(m.Id)).SelectMany(m => ModLine(m, _catalog.Mods[m.Id]).Split('\n')).ToList(); + foreach (string line in lines.OrderBy(l => l.StartsWith("Added Small Passive Skills grant:", StringComparison.Ordinal))) + Line(line, GameColour("mod")); + } if (implicits.Count > 0) { Separator(); Mods(implicits); } if (explicits.Count > 0) { Separator(); Mods(explicits); } diff --git a/src/Waypoint/ItemImport.cs b/src/Waypoint/ItemImport.cs index d774f52..7af1378 100644 --- a/src/Waypoint/ItemImport.cs +++ b/src/Waypoint/ItemImport.cs @@ -214,8 +214,49 @@ bool Take(int i, string line) if (implicitCount < 0) throw new ImportException(NoItem); } + // The base's own enchantments (a cluster jewel's passives come from them) go on as a new item has them, each with + // the values of the item's line it words ("Adds 10 Passive Skills"). Other enchantments stay left out. + var enchants = catalog.NewMods(b).Where(m => m.Section == "enchant").ToList(); + var enchantLines = lines.Where(l => l.Enchant).ToList(); + ModLine? Reads(string text) => enchantLines.FirstOrDefault(l => string.Equals(l.Text.Trim(), text, StringComparison.OrdinalIgnoreCase)); + foreach (var enchant in enchants) + if (catalog.Mods.GetValueOrDefault(enchant.Id) is { } mod && Worded(catalog, b, enchant, mod, enchantLines) is var (line, values)) + { + enchant.Values = values; + enchantLines.Remove(line); + Note(line.Number, ImportStatus.Mod, Describe(mod, false)); + } + if (b.Cluster is { } cluster) + { + // Its theme is the one whose lines the item has ("Added Small Passive Skills grant: 12% increased Fire Damage"). + if (catalog.ThemeIndex(b) is var themeAt and >= 0 && enchants.FirstOrDefault(e => e.Id == cluster.Passives) is { } passives && themeAt < passives.Values.Count) + foreach (var theme in cluster.Themes) + { + var found = catalog.ThemeLines(theme).Select(Reads).ToList(); + if (found.Count == 0 || found.Any(l => l is null)) continue; + passives.Values[themeAt] = theme.Value; + foreach (var l in found.OfType()) + { + enchantLines.Remove(l); + Note(l.Number, ImportStatus.Mod, theme.Name); + } + break; + } + // Its jewel sockets are one mod per count: the one the item's line words takes the new jewel's place. + int socket = enchants.FindIndex(e => cluster.Sockets.Any(s => s.Mod == e.Id)); + foreach (var (_, id) in cluster.Sockets) + if (socket >= 0 && enchants[socket].Id != id && catalog.Mods.GetValueOrDefault(id) is { } other + && other.Stats.Select(s => Math.Max(s.Min, s.Max)).ToList() is var top + && catalog.Lines(other, top).Where(l => l.Length > 0).ToList() is [{ } worded] && Reads(worded) is { } l) + { + enchants[socket] = new CraftedMod { Id = id, Section = "enchant", Values = top }; + enchantLines.Remove(l); + Note(l.Number, ImportStatus.Mod, Describe(other, false)); + } + } + var mods = new List(); - var pools = b.Pools.ToDictionary(p => p.Key, p => catalog.Pool(b, p.Key).Select(m => m.Id).ToHashSet(StringComparer.Ordinal)); + var pools = b.Pools.ToDictionary(p => p.Key, p => catalog.Pool(b, p.Key, enchants).Select(m => m.Id).ToHashSet(StringComparer.Ordinal)); HashSet Pool(string key) => pools.GetValueOrDefault(key) ?? []; var baseImplicits = b.Implicits.ToHashSet(StringComparer.Ordinal); // The game's header names the affix and whether it is a prefix or a suffix. @@ -223,10 +264,12 @@ static int Hint(CraftMod mod, ModLine line) => (line.Affix is { Length: > 0 } affix && !string.Equals(affix, mod.Name, StringComparison.OrdinalIgnoreCase) ? 20 : 0) + (line.Kind is { } kind && ((kind.Contains("Prefix", StringComparison.Ordinal) && !mod.Prefix) || (kind.Contains("Suffix", StringComparison.Ordinal) && !mod.Suffix)) ? 20 : 0); - Match(catalog, [.. lines.Where(l => l.Implicit)], "implicit", mods, Note, (mod, line) => + // An enchantment line the base's own enchantments took is done; the others are told they are left out. + bool Left(ModLine l) => !l.Enchant || enchantLines.Contains(l); + Match(catalog, [.. lines.Where(l => l.Implicit && Left(l))], "implicit", mods, Note, (mod, line) => (baseImplicits.Contains(mod.Id) ? 1 : Pool("corrupted").Contains(mod.Id) ? 2 : Pool("eldritch").Contains(mod.Id) ? 3 : mod.Generation is 3 or 5 or 28 or 29 ? 4 : 5) + Hint(mod, line)); - Match(catalog, [.. lines.Where(l => !l.Implicit)], "explicit", mods, Note, (mod, line) => + Match(catalog, [.. lines.Where(l => !l.Implicit && Left(l))], "explicit", mods, Note, (mod, line) => (ids.ContainsKey(mod.Id) ? 0 : line.Crafted && Pool("crafted").Contains(mod.Id) ? 1 : Pool("pool").Contains(mod.Id) ? 2 @@ -248,7 +291,7 @@ static int Hint(CraftMod mod, ModLine line) => // A mod only an influence brings makes the item that influence's. foreach (var m in mods.Where(m => m.Section == "explicit" && !Pool("pool").Contains(m.Id))) if (Influences.FirstOrDefault(i => Pool(i).Contains(m.Id)) is { } influence && !item.States.Contains(influence)) item.States.Add(influence); - item.Mods = mods; + item.Mods = [.. enchants, .. mods]; // Without an item level the item gets one every modifier fits. int needed = mods.Select(m => catalog.Mods.GetValueOrDefault(m.Id)?.Level ?? 1).DefaultIfEmpty(1).Max(); @@ -263,6 +306,26 @@ static int Hint(CraftMod mod, ModLine line) => return new ImportedItem(item, name.Length > 0 ? name : baseLine, report); } + /// The line that words one of the base's enchantments, with the values that give its numbers: the ones a new + /// item has, or one of them anywhere in the range the base gives it. Null when no line does. + static (ModLine Line, List Values)? Worded(CrafterCatalog catalog, CraftBase b, CraftedMod enchant, CraftMod mod, List lines) + { + var tries = new List> { enchant.Values }; + for (int s = 0; s < enchant.Values.Count && s < mod.Stats.Count; s++) + { + var (min, max) = CrafterCatalog.Range(b, enchant, mod, s); + for (int v = min; v <= max && max - min <= 100; v++) + if (v != enchant.Values[s]) tries.Add([.. enchant.Values.Select((old, i) => i == s ? v : old)]); + } + foreach (var values in tries) + { + if (catalog.Lines(mod, values).Where(l => l.Length > 0).ToList() is not [var text]) continue; + var shape = ShapeOf(text); + if (lines.FirstOrDefault(l => Same(shape, l.Shape) && shape.Numbers.SequenceEqual(l.Shape.Numbers)) is { } line) return (line, values); + } + return null; + } + static string NoItem => L.Text("This is not an item: copy one with Ctrl+C in Path of Building or in the game."); static int Int(string value) => Number.Match(value) is { Success: true } m && int.TryParse(m.Value.TrimStart('+'), out int n) ? n : 0; diff --git a/tests/Waypoint.Tests/ClientExtractionFailureTests.cs b/tests/Waypoint.Tests/ClientExtractionFailureTests.cs index 890b7e2..638fdcf 100644 --- a/tests/Waypoint.Tests/ClientExtractionFailureTests.cs +++ b/tests/Waypoint.Tests/ClientExtractionFailureTests.cs @@ -34,10 +34,12 @@ public async Task Other_extraction_failures_keep_their_own_error() File.WriteAllText(Path.Combine(folder, "scripts", "dev", "extract-data.ps1"), "Write-Output 'Node is missing'\nexit 1\n"); var error = await Assert.ThrowsAsync(() => SetupSequence.ExtractAsync(folder, _ => { }, CancellationToken.None)); Assert.Equal("Node is missing", error.Message); - // The release and its 3.29.3.5 hotfix are both the 3.29.3c build. - Assert.Equal(2, ClientLocator.ExecutableHashesFor("3.29.3c").Length); + // The release and its 3.29.3.5 hotfix are both the 3.29.3c build. Waypoint's own rows come first and only they are + // looked at: a hash a LocalExile's list named in another test stays learned for the whole run, and follows them. + Assert.Equal(["cc8aa38345be2a837575215d2ce142ebecf7b007345843265b335ebb8ac5964c", "01a22facf36886b39bca74793c0d8c7295b1495f1625b4ebc7b23c2de32a70cf"], + ClientLocator.ExecutableHashesFor("3.29.3c")[..2]); Assert.Equal(ClientLocator.KnownExecutable, ClientLocator.ExecutableHashesFor(ClientLocator.Build)[0]); - Assert.Single(ClientLocator.ExecutableHashesFor("3.29.3b")); + Assert.Equal("78a0e227189c263658a7f65a02f086428b859bfc114ae8e7ce8aab721ebd48d5", ClientLocator.ExecutableHashesFor("3.29.3b")[0]); Assert.Empty(ClientLocator.ExecutableHashesFor("future build")); } diff --git a/tests/Waypoint.Tests/CrafterCatalogTests.cs b/tests/Waypoint.Tests/CrafterCatalogTests.cs index 04dcd39..da2d800 100644 --- a/tests/Waypoint.Tests/CrafterCatalogTests.cs +++ b/tests/Waypoint.Tests/CrafterCatalogTests.cs @@ -108,6 +108,98 @@ Hunter Item Assert.Equal(ImportStatus.Skipped, read.Lines.Single(l => l.Text.StartsWith('(')).Status); } + // A cluster jewel as the Gateway's crafter mode prints it: no implicit, the enchantments a tool starts with, and what + // they can be changed to. A theme opens its own pool, where its notables are. + const string ClusterLines = """ + {"type":"class","id":"Jewel","name":"Jewels"} + {"type":"pool","id":0,"mods":["AfflictionJewelSmallPassivesGrantLife_","AfflictionJewelSmallPassivesGrantLife2_"]} + {"type":"pool","id":1,"mods":["AfflictionJewelSmallPassivesGrantLife_","AfflictionJewelSmallPassivesGrantLife2_","AfflictionNotablePrismaticHeart__"]} + {"type":"pool","id":2,"mods":["AfflictionJewelSmallPassivesGrantLife_","AfflictionJewelSmallPassivesGrantLife2_"]} + {"type":"mod","id":"JewelExpansionPassiveNodes","name":"","generation":3,"domain":21,"level":1,"families":[3829],"tags":[],"stats":[{"id":"local_jewel_expansion_passive_node_index","min":0,"max":0},{"id":"local_jewel_expansion_passive_node_count","min":0,"max":0}]} + {"type":"mod","id":"JewelExpansionJewelNodesLarge1","name":"of Potential","generation":3,"domain":21,"level":1,"families":[3830],"tags":[],"stats":[{"id":"local_jewel_expansion_jewels_count","min":1,"max":1}]} + {"type":"mod","id":"JewelExpansionJewelNodesLarge2___","name":"of Possibility","generation":3,"domain":21,"level":1,"families":[3830],"tags":[],"stats":[{"id":"local_jewel_expansion_jewels_count","min":2,"max":2}]} + {"type":"mod","id":"AfflictionJewelSmallPassivesGrantLife_","name":"Hale","generation":1,"domain":21,"level":1,"families":[4150],"tags":["life"],"stats":[{"id":"local_affliction_jewel_small_nodes_grant_maximum_life","min":2,"max":3}]} + {"type":"mod","id":"AfflictionJewelSmallPassivesGrantLife2_","name":"Healthy","generation":1,"domain":21,"level":1,"families":[4150],"tags":["life"],"stats":[{"id":"local_affliction_jewel_small_nodes_grant_maximum_life","min":4,"max":7}]} + {"type":"mod","id":"AfflictionNotablePrismaticHeart__","name":"Notable","generation":1,"domain":21,"level":1,"families":[4200],"tags":[],"stats":[{"id":"local_affliction_notable_prismatic_heart","min":1,"max":1}]} + {"type":"base","id":"Metadata/Items/Jewels/JewelPassiveTreeExpansionLarge","name":"Large Cluster Jewel","class":"Jewel","width":1,"height":1,"dropLevel":1,"requirements":[0,0,0],"sockets":0,"quality":false,"implicits":[],"pool":0,"influence":{},"crafted":0,"corrupted":0,"eldritch":0,"enchants":[{"id":"JewelExpansionPassiveNodes","values":[1,8],"ranges":[[1,17],[8,12]]},{"id":"JewelExpansionJewelNodesLarge2___","values":[2],"ranges":[[2,2]]},{"id":"NotInTheCatalog","values":[1],"ranges":[[1,1]]}],"cluster":{"size":2,"passives":{"mod":"JewelExpansionPassiveNodes","min":8,"max":12},"sockets":[{"count":1,"mod":"JewelExpansionJewelNodesLarge1"},{"count":2,"mod":"JewelExpansionJewelNodesLarge2___"}],"themes":[{"value":1,"name":"Axe and Sword Damage","tag":"affliction_axe_and_sword_damage","stats":[{"id":"axe_damage_+%","value":12},{"id":"sword_damage_+%","value":12}],"pool":2},{"value":13,"name":"Fire Damage","tag":"affliction_fire_damage","stats":[{"id":"fire_damage_+%","value":12}],"pool":1}]}} + {"type":"desc","stats":["local_jewel_expansion_passive_node_index"],"variants":[{"when":["#"],"text":"{0}","handlers":[["tree_expansion_jewel_passive",1]]}]} + {"type":"desc","stats":["local_jewel_expansion_passive_node_count"],"variants":[{"when":["1"],"text":"Adds 1 Passive Skill","handlers":[]},{"when":["#"],"text":"Adds {0} Passive Skills","handlers":[]}]} + {"type":"desc","stats":["local_jewel_expansion_jewels_count"],"variants":[{"when":["1"],"text":"1 Added Passive Skill is a Jewel Socket","handlers":[]},{"when":["2|#"],"text":"{0} Added Passive Skills are Jewel Sockets","handlers":[]}]} + {"type":"desc","stats":["local_affliction_jewel_small_nodes_grant_maximum_life"],"variants":[{"when":["#"],"text":"Added Small Passive Skills also grant: {0:+d} to Maximum Life","handlers":[]}]} + {"type":"desc","stats":["local_affliction_notable_prismatic_heart"],"variants":[{"when":["#"],"text":"1 Added Passive Skill is Prismatic Heart","handlers":[]}]} + {"type":"desc","stats":["fire_damage_+%"],"variants":[{"when":["1|#"],"text":"{0}% increased Fire Damage","handlers":[]}]} + {"type":"desc","stats":["axe_damage_+%"],"variants":[{"when":["1|#"],"text":"Axe Attacks deal {0}% increased Damage","handlers":[]}]} + {"type":"desc","stats":["sword_damage_+%"],"variants":[{"when":["1|#"],"text":"Sword Attacks deal {0}% increased Damage","handlers":[]}]} + """; + + [Fact] + public void A_cluster_jewel_starts_with_its_enchantments_and_its_theme_opens_its_notables() + { + var catalog = CrafterCatalog.Parse(ClusterLines); + var large = Assert.Single(catalog.Bases); + var cluster = large.Cluster!; + Assert.Equal(("JewelExpansionPassiveNodes", 8, 12, 2), (cluster.Passives, cluster.Min, cluster.Max, cluster.Themes.Count)); + Assert.Equal([(1, "JewelExpansionJewelNodesLarge1"), (2, "JewelExpansionJewelNodesLarge2___")], cluster.Sockets); + + // No implicit and no pool names them: the base does, with the values of the jewel a tool starts with. + var mods = catalog.NewMods(large); + Assert.Equal([("JewelExpansionPassiveNodes", "enchant"), ("JewelExpansionJewelNodesLarge2___", "enchant")], mods.Select(m => (m.Id, m.Section))); + Assert.Equal([[1, 8], [2]], mods.Select(m => m.Values)); + var passives = catalog.Mods[mods[0].Id]; + // The passive count has no range in the game's data: the base's is used. + Assert.Equal(((1, 17), (8, 12)), (CrafterCatalog.Range(large, mods[0], passives, 0), CrafterCatalog.Range(large, mods[0], passives, 1))); + + // The mod's first value names the theme, which the game words as what the small passives grant; alone, the mod + // has no line for it rather than a bare number. + Assert.Equal(["Adds 8 Passive Skills"], catalog.Lines(passives, mods[0].Values)); + Assert.Equal("Axe and Sword Damage", catalog.Theme(large, mods)!.Name); + Assert.Equal(["Adds 8 Passive Skills", "Added Small Passive Skills grant: Axe Attacks deal 12% increased Damage", + "Added Small Passive Skills grant: Sword Attacks deal 12% increased Damage"], catalog.Lines(large, mods[0], passives)); + // A theme opens its own affixes: Fire Damage has a notable the first theme and a jewel without one do not. + Assert.DoesNotContain(catalog.Pool(large, "pool", mods), m => m.Id == "AfflictionNotablePrismaticHeart__"); + mods[0].Values[catalog.ThemeIndex(large)] = 13; + Assert.Equal(("Fire Damage", 1), (catalog.Theme(large, mods)!.Name, catalog.PoolId(large, "pool", mods))); + Assert.Contains(catalog.Pool(large, "pool", mods), m => m.Id == "AfflictionNotablePrismaticHeart__"); + Assert.DoesNotContain(catalog.Pool(large, "pool"), m => m.Id == "AfflictionNotablePrismaticHeart__"); + mods[0].Values[0] = 99; + Assert.Null(catalog.Theme(large, mods)); + Assert.Equal(0, catalog.PoolId(large, "pool", mods)); + mods[0].Values[0] = 13; + // What /item_give is sent names each in the enchant list. + string spec = new CraftedItem { Base = large.Id, Rarity = "normal", Mods = mods }.Spec(); + Assert.Contains("""{"id":"JewelExpansionPassiveNodes","section":"enchant","values":[13,8]}""", spec); + Assert.Equal(2, System.Text.RegularExpressions.Regex.Matches(spec, "\"section\":\"enchant\"").Count); + + // An item copied from the game: its count, its sockets and its theme are read from its enchantment lines, and its + // notable is found among the theme's affixes. + var read = ItemImport.Read(""" + Item Class: Jewels + Rarity: Rare + Armageddon Joy + Large Cluster Jewel + -------- + Item Level: 84 + -------- + Adds 10 Passive Skills (enchant) + 1 Added Passive Skill is a Jewel Socket (enchant) + Added Small Passive Skills grant: 12% increased Fire Damage (enchant) + Allocates something the crafter has no enchantment for (enchant) + -------- + Added Small Passive Skills also grant: +7 to Maximum Life + 1 Added Passive Skill is Prismatic Heart + """, catalog); + Assert.Equal([("JewelExpansionPassiveNodes", "enchant"), ("JewelExpansionJewelNodesLarge1", "enchant"), + ("AfflictionJewelSmallPassivesGrantLife2_", "explicit"), ("AfflictionNotablePrismaticHeart__", "explicit")], read.Item.Mods.Select(m => (m.Id, m.Section))); + Assert.Equal([[13, 10], [1], [7], [1]], read.Item.Mods.Select(m => m.Values)); + Assert.Equal(["Allocates something the crafter has no enchantment for (enchant)"], read.Unmatched.Select(l => l.Text.Trim())); + + // A Gateway that does not list them yet: the base has none, as before. + var ring = CrafterCatalog.Parse(Lines).Bases.Single(); + Assert.Empty(ring.Enchants); + Assert.Null(ring.Cluster); + Assert.Empty(CrafterCatalog.Parse(Lines).NewMods(ring)); + } + [Fact] public void A_line_break_in_a_description_makes_two_lines() {