From 83e8d4845a22b5fd1f14e593c1c5071340e98ba8 Mon Sep 17 00:00:00 2001 From: BlankenshipG Date: Wed, 7 Oct 2026 08:10:44 -0400 Subject: [PATCH] feat(loot): include T11 attributes when adding an item to a loot profile 'Add to loot profile' gains an Include T11 attributes option (popup checkbox, /ra loot add ... t11). The rule then also requires the item's T11 tier, grade, damage %, each catalogued modifier, slot special and Cast on Strike count, each at least the clicked item's, on RynthAi's virtual T11 keys. Needs the engine's matching checkbox (rynth/RynthCore) for the popup; the chat command works without it. Co-authored-by: Cursor --- .../Loot/LootEditorBridge.cs | 12 +- .../RynthAiCommands.cs | 22 +++- .../RynthCore.LootSdk/Editing/LootEditWire.cs | 9 ++ .../Editing/LootItemRules.cs | 75 ++++++++++- .../RynthCore.LootSdkTests/LootAddT11Tests.cs | 117 ++++++++++++++++++ Tools/RynthCore.LootSdkTests/Program.cs | 1 + 6 files changed, 223 insertions(+), 13 deletions(-) create mode 100644 Tools/RynthCore.LootSdkTests/LootAddT11Tests.cs diff --git a/Plugins/RynthCore.Plugin.RynthAi/Loot/LootEditorBridge.cs b/Plugins/RynthCore.Plugin.RynthAi/Loot/LootEditorBridge.cs index 22ca87f..e75a3b3 100644 --- a/Plugins/RynthCore.Plugin.RynthAi/Loot/LootEditorBridge.cs +++ b/Plugins/RynthCore.Plugin.RynthAi/Loot/LootEditorBridge.cs @@ -182,8 +182,10 @@ internal sealed class LootEditorBridge if (id == 0) return Refuse(d, "No item selected. Click an item first."); d.ItemId = id; var match = (LootItemMatch)Math.Clamp(req.Match, 0, 2); - LootItemFacts? facts = Items.Facts(id, match == LootItemMatch.Like); + d.IncludeT11 = req.IncludeT11; + LootItemFacts? facts = Items.Facts(id, match == LootItemMatch.Like, req.IncludeT11); if (facts == null) return Refuse(d, $"RynthAi doesn't know item 0x{id:X8} yet. Select it again in a moment."); + d.IsT11 = facts.T11?.IsT11 == true; d.ItemName = facts.Name; d.ClassName = LootItemRules.ClassName(facts.ObjectClass); d.Stackable = facts.Stackable; @@ -207,6 +209,7 @@ internal sealed class LootEditorBridge Action = req.Action == 0 ? null : (VTankLootAction)req.Action, KeepCount = req.KeepCount < 0 ? null : req.KeepCount, RuleName = req.RuleName, + IncludeT11 = req.IncludeT11, }; LootItemRuleDraft? draft = LootItemRules.Build(facts, options, out string error); if (draft == null) return Refuse(d, error); @@ -336,8 +339,11 @@ internal sealed class LootItemHooks { /// The item selected in the game, or 0. public Func SelectedItemId { get; set; } = () => 0; - /// The item's facts from the object cache, or null. The bool: "items like this" (ask for an ID if it isn't identified). - public Func Facts { get; set; } = (_, _) => null; + /// + /// The item's facts from the object cache, or null. The bools: "items like this" and + /// "include T11 attributes"; either asks for an ID when the item isn't identified. + /// + public Func Facts { get; set; } = (_, _, _) => null; /// The first rule of the .utl profile that matches the item now, or -1. public Func FirstMatchUtl { get; set; } = (_, _) => -1; /// The first rule of the native profile that matches the item now, or -1. diff --git a/Plugins/RynthCore.Plugin.RynthAi/RynthAiCommands.cs b/Plugins/RynthCore.Plugin.RynthAi/RynthAiCommands.cs index 485a9e9..20c66e0 100644 --- a/Plugins/RynthCore.Plugin.RynthAi/RynthAiCommands.cs +++ b/Plugins/RynthCore.Plugin.RynthAi/RynthAiCommands.cs @@ -1603,8 +1603,12 @@ public sealed partial class RynthAiPlugin if (inUse) ReloadLootProfileInUse(d.TargetPath); } - /// What a loot rule can be built from: the item's name, class, stack and key properties, from the object cache. - private RynthCore.Loot.Editing.LootItemFacts? BuildLootItemFacts(uint itemId, bool like) + /// + /// What a loot rule can be built from: the item's name, class, stack, key properties and + /// T11 reading, from the object cache. adds its spells; + /// asks for an ID when a T11 item's text hasn't arrived. + /// + private RynthCore.Loot.Editing.LootItemFacts? BuildLootItemFacts(uint itemId, bool like, bool t11) { WorldObject? wo = _objectCache?[unchecked((int)itemId)]; if (wo == null) return null; @@ -1634,6 +1638,10 @@ public sealed partial class RynthAiPlugin // Material, workmanship and spells need an ID: ask for one, so the next preview has them. if (Host.HasRequestId && Host.HasHasAppraisalData && !Host.HasAppraisalData(itemId)) Host.RequestId(itemId); } + // Always read (a cached parse), so the popup knows whether the T11 option applies. + f.T11 = Loot.T11ItemSupport.Get(wo); + // T11 tier, grade and modifiers are appraisal text: ask for it, so the next preview has them. + if (t11 && f.T11.IsT11 && !f.T11.HasText && Host.HasRequestId) Host.RequestId(itemId); return f; } @@ -1656,17 +1664,18 @@ public sealed partial class RynthAiPlugin } /// - /// /ra loot add [keep|keep N|salvage|sell|read] [name|like] [preview]: a rule for + /// /ra loot add [keep|keep N|salvage|sell|read] [name|like] [t11] [preview]: a rule for /// the selected item, straight into the loot profile in use (the defaults: exact /// name and class; Read for scrolls, Keep # one full stack for stacks, else Keep). + /// t11 also requires the item's T11 attributes. /// private void HandleLootCommand(string[] parts) { string sub = parts.Length >= 3 ? parts[2].ToLowerInvariant() : string.Empty; if (sub != "add") { - ChatLine("[RynthAi] /ra loot add [keep|keep N|salvage|sell|read] [name|like] [preview] — add a loot rule for the selected item to the loot profile in use"); - ChatLine("[RynthAi] default: exact name + class; Read for scrolls, Keep # (one full stack) for stacks, else Keep. name = name only, like = items like this. preview = show it, add nothing."); + ChatLine("[RynthAi] /ra loot add [keep|keep N|salvage|sell|read] [name|like] [t11] [preview] — add a loot rule for the selected item to the loot profile in use"); + ChatLine("[RynthAi] default: exact name + class; Read for scrolls, Keep # (one full stack) for stacks, else Keep. name = name only, like = items like this. t11 = also require its T11 tier, grade and modifiers (at least this good). preview = show it, add nothing."); ChatLine("[RynthAi] Also: right-click an item in the Inventory panel, or 'Add selected item' in the Loot Editor."); return; } @@ -1686,6 +1695,7 @@ public sealed partial class RynthAiPlugin case "name": req.Match = (int)RynthCore.Loot.Editing.LootItemMatch.Name; break; case "like": req.Match = (int)RynthCore.Loot.Editing.LootItemMatch.Like; break; case "exact": req.Match = (int)RynthCore.Loot.Editing.LootItemMatch.NameAndClass; break; + case "t11": req.IncludeT11 = true; break; case "preview": case "?": preview = true; break; default: @@ -1695,7 +1705,7 @@ public sealed partial class RynthAiPlugin req.KeepCount = n; break; } - ChatLine($"[RynthAi] loot add: '{parts[i]}'? Use keep, keep N, salvage, sell, read, name, like or preview."); + ChatLine($"[RynthAi] loot add: '{parts[i]}'? Use keep, keep N, salvage, sell, read, name, like, t11 or preview."); return; } } diff --git a/Shared/RynthCore.LootSdk/Editing/LootEditWire.cs b/Shared/RynthCore.LootSdk/Editing/LootEditWire.cs index 41afa86..ad658ce 100644 --- a/Shared/RynthCore.LootSdk/Editing/LootEditWire.cs +++ b/Shared/RynthCore.LootSdk/Editing/LootEditWire.cs @@ -133,6 +133,11 @@ public sealed class LootEditItemRequest public string RuleName { get; set; } = string.Empty; /// True: the profile open in the Loot Editor; false: the one RynthAi loots with. public bool ToOpenProfile { get; set; } + /// + /// Also require the item's T11 attributes (LootItemRuleOptions.IncludeT11). Added + /// 2026-10-07; an older engine never sends it, so it reads false. + /// + public bool IncludeT11 { get; set; } /// Echoed in the draft so the popup knows the answer is to its latest ask. public int Seq { get; set; } } @@ -156,6 +161,10 @@ public sealed class LootEditItemDraft public string Format { get; set; } = string.Empty; /// What was built (the defaults filled in). public int Match { get; set; } + /// The rule was asked to include the item's T11 attributes (added 2026-10-07). + public bool IncludeT11 { get; set; } + /// The item is T11 gear, so "Include T11 attributes" has something to add (added 2026-10-07). + public bool IsT11 { get; set; } public int Action { get; set; } public int KeepCount { get; set; } public string RuleName { get; set; } = string.Empty; diff --git a/Shared/RynthCore.LootSdk/Editing/LootItemRules.cs b/Shared/RynthCore.LootSdk/Editing/LootItemRules.cs index bd316ba..d6939c5 100644 --- a/Shared/RynthCore.LootSdk/Editing/LootItemRules.cs +++ b/Shared/RynthCore.LootSdk/Editing/LootItemRules.cs @@ -2,6 +2,7 @@ using System; using System.Collections.Generic; using System.Globalization; using System.Text; +using RynthCore.Loot.T11; using RynthCore.Loot.VTank; namespace RynthCore.Loot.Editing; @@ -26,6 +27,11 @@ public sealed class LootItemFacts public Dictionary Doubles { get; set; } = new(); /// The item's spell names (empty when none or not identified). public List Spells { get; set; } = new(); + /// + /// The item's T11 reading (ACECustom tier 11+ text), or null when it wasn't asked for. + /// for an item that isn't T11 gear. + /// + public T11ItemInfo? T11 { get; set; } public bool Stackable => MaxStackSize > 1 || StackSize > 1; @@ -53,6 +59,11 @@ public sealed class LootItemRuleOptions public int? KeepCount { get; set; } /// Null or blank: "Keep Copper Pea" and the like. public string? RuleName { get; set; } + /// + /// Also require the item's T11 attributes (tier, grade, damage %, each modifier, slot + /// special, Cast on Strike), each at least as good as this item's. Works with any match. + /// + public bool IncludeT11 { get; set; } } /// A built rule, ready to preview and insert. @@ -155,6 +166,7 @@ public static class LootItemRules }; bool hasClass = f.ObjectClass != (int)AcObjectClass.Unknown; LootItemMatch match = o.Match; + bool likeBare = false; if (match == LootItemMatch.NameAndClass && !hasClass) { match = LootItemMatch.Name; @@ -177,13 +189,15 @@ public static class LootItemRules return null; } rule.Conditions.Add(Cond(VTankNodeTypes.ObjectClass, Num(f.ObjectClass))); - int extra = AddLikeConditions(rule, f, notes); - if (extra == 0) - notes.Add($"Nothing but the class to go on: this rule matches every {ClassName(f.ObjectClass)}." - + (f.Ints.Count == 0 ? " (Assess the item first for its material, workmanship and stats.)" : string.Empty)); + likeBare = AddLikeConditions(rule, f, notes) == 0; break; } + int t11Added = o.IncludeT11 ? AddT11Conditions(rule, f, notes) : 0; + if (likeBare && t11Added == 0) + notes.Add($"Nothing but the class to go on: this rule matches every {ClassName(f.ObjectClass)}." + + (f.Ints.Count == 0 ? " (Assess the item first for its material, workmanship and stats.)" : string.Empty)); + string defaultName = DefaultRuleName(name.Length > 0 ? name : ClassName(f.ObjectClass), action, keep, match); string ruleName = OneLine(o.RuleName).Trim(); rule.Name = ruleName.Length > 0 ? ruleName : defaultName; @@ -248,6 +262,59 @@ public static class LootItemRules return rule.Conditions.Count - n; } + /// + /// The T11 conditions, on RynthAi's virtual T11 keys: Is T11, then tier, grade, damage %, + /// every catalogued modifier, slot special and Cast on Strike count, each at least this + /// item's. Left out on purpose: Can Wield (the character, not the item), Zone Locked + /// (where it was appraised), the wield gates (they follow from the tier) and the modifier + /// count / rating total / roll % (they follow from the per-modifier values). + /// How many it added. + /// + private static int AddT11Conditions(VTankLootRule rule, LootItemFacts f, List notes) + { + T11ItemInfo? t = f.T11; + if (t == null || !t.IsT11) + { + notes.Add("Not a T11 item, so there are no T11 attributes to add."); + return 0; + } + + int n = rule.Conditions.Count; + void Equal(int key, int v) => rule.Conditions.Add(Cond(VTankNodeTypes.LongValKeyE, Num(v), Num(key))); + void AtLeast(int key, int v) { if (v > 0) rule.Conditions.Add(Cond(VTankNodeTypes.LongValKeyGE, Num(v), Num(key))); } + + Equal(T11Keys.IsT11, 1); + if (!t.HasText) + { + notes.Add("The item hasn't been identified, so only \"Is T11\" could be added. Assess it and preview again for its tier, grade and modifiers."); + return rule.Conditions.Count - n; + } + + AtLeast(T11Keys.EstimatedTier, t.EstimatedTier); + AtLeast(T11Keys.WeaponGrade, t.GradeRank); + AtLeast(T11Keys.DamagePercent, t.DamagePercent); + + bool valuelessSpecial = false; + var unknown = new List(); + foreach (T11Modifier m in t.Modifiers) + { + if (T11Catalog.ModifierByKey(m.Key) == null) + { + unknown.Add(m.Name); + continue; + } + // A modifier's key reads 0 when it is absent, so a value-less one can't be required by value. + if (m.Value > 0) AtLeast(T11Keys.ForModifier(m.Key), m.Value); + else if (m.IsSlotSpecial) valuelessSpecial = true; + } + if (valuelessSpecial) Equal(T11Keys.HasSlotSpecial, 1); + AtLeast(T11Keys.CastOnStrikeCount, t.Procs.Count); + + if (unknown.Count > 0) + notes.Add("Left out (RynthAi has no loot key for these modifiers yet): " + string.Join(", ", unknown) + "."); + return rule.Conditions.Count - n; + } + private static VTankLootCondition Cond(int type, params string[] lines) => new(type, "0", lines); private static string Num(int v) => v.ToString(CultureInfo.InvariantCulture); diff --git a/Tools/RynthCore.LootSdkTests/LootAddT11Tests.cs b/Tools/RynthCore.LootSdkTests/LootAddT11Tests.cs new file mode 100644 index 0000000..975d404 --- /dev/null +++ b/Tools/RynthCore.LootSdkTests/LootAddT11Tests.cs @@ -0,0 +1,117 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using RynthCore.Loot; +using RynthCore.Loot.Editing; +using RynthCore.Loot.T11; +using RynthCore.Loot.VTank; + +namespace RynthCore.LootSdkTests; + +// "Add to loot profile" with "Include T11 attributes" (2026-10-07): the T11 conditions a +// clicked item adds, on the server-format weapon and armor text LootT11Tests parses. +internal static partial class Program +{ + private static void RunLootAddT11Tests() + { + Console.WriteLine("\n-- LootAdd: include T11 attributes --"); + TestAddT11Weapon(); + TestAddT11Armor(); + TestAddT11EdgeCases(); + } + + /// A condition as "type:line,line" for order-sensitive comparisons. + private static string CondText(VTankLootCondition c) => c.NodeType + ":" + string.Join(",", c.DataLines); + + private static string GE(int key, int v) => $"{VTankNodeTypes.LongValKeyGE}:{v},{key}"; + private static string EQ(int key, int v) => $"{VTankNodeTypes.LongValKeyE}:{v},{key}"; + + private static List T11Conds(VTankLootRule r) => + r.Conditions.Where(c => c.DataLines.Count == 2 && int.TryParse(c.DataLines[1], out int k) && T11Keys.IsVirtual(k)) + .Select(CondText).ToList(); + + private static LootItemFacts T11Facts(string name, AcObjectClass cls, string? longDesc, string? use) => new() + { + Id = 0x7000_0001, + Name = name, + ObjectClass = (int)cls, + T11 = T11ItemInfo.Parse(name, longDesc, use), + }; + + private static void TestAddT11Weapon() + { + LootItemFacts f = T11Facts("T11 - Tachi", AcObjectClass.MeleeWeapon, T11WeaponLongDesc, null); + + LootItemRuleDraft? off = LootItemRules.Build(f, new LootItemRuleOptions(), out _); + Eq(off == null ? -1 : T11Conds(off.Rule).Count, 0, "add t11: unchecked adds no T11 conditions"); + + LootItemRuleDraft? d = LootItemRules.Build(f, new LootItemRuleOptions { IncludeT11 = true }, out string err); + Check(d != null, "add t11: weapon builds (" + err + ")"); + if (d == null) return; + Eq(CondText(d.Rule.Conditions[0]), $"{VTankNodeTypes.ObjectClass}:{(int)AcObjectClass.MeleeWeapon}", "add t11: name + class first"); + Eq(string.Join(" | ", T11Conds(d.Rule)), string.Join(" | ", new[] + { + EQ(T11Keys.IsT11, 1), + GE(T11Keys.EstimatedTier, 13), + GE(T11Keys.WeaponGrade, 12), + GE(T11Keys.DamagePercent, 86), + GE(T11Keys.ForModifier(28), 41), // Damage Rating + GE(T11Keys.ForModifier(29), 10), // Crit Damage Rating + GE(T11Keys.ForModifier(44), 2), // Pct HP Damage: a slot special with a value + GE(T11Keys.CastOnStrikeCount, 1), + }), "add t11: weapon conditions, at least this item's"); + Check(d.Rule.Conditions.All(c => CondText(c) != EQ(T11Keys.HasSlotSpecial, 1)), "add t11: valued special needs no Has Slot Special"); + Check(d.Rule.Conditions.All(c => CondText(c) != EQ(T11Keys.ZoneLocked, 1)), "add t11: zone lock left out"); + Eq(d.Notes.Count, 0, "add t11: weapon has no notes"); + Check(LootItemRules.PreviewLines(d.Rule).Any(l => l.Contains("T11 Mod: Damage Rating")), "add t11: preview names the modifier key"); + + var dropped = new List(); + LootRule? native = LootItemRules.ToNative(d.Rule, dropped); + Eq(dropped.Count, 0, "add t11: native format keeps every T11 condition"); + Eq(native?.Conditions.Count ?? -1, d.Rule.Conditions.Count, "add t11: native condition count"); + } + + private static void TestAddT11Armor() + { + LootItemFacts f = T11Facts("T11 - Celdon Breastplate", AcObjectClass.Armor, T11ArmorLongDesc, T11ArmorUse); + LootItemRuleDraft? d = LootItemRules.Build(f, new LootItemRuleOptions { IncludeT11 = true }, out _); + Check(d != null, "add t11: armor builds"); + if (d == null) return; + List t = T11Conds(d.Rule); + Check(t.Contains(GE(T11Keys.EstimatedTier, 16)), "add t11: armor tier from the Triune Weave gate"); + Check(!t.Any(c => c.EndsWith("," + T11Keys.WeaponGrade)), "add t11: no grade on armor"); + Check(t.Contains(GE(T11Keys.ForModifier(50), 8)), "add t11: Damage Resist"); + Check(t.Contains(GE(T11Keys.ForModifier(19), 120)), "add t11: Max Health"); + Check(t.Contains(GE(T11Keys.ForModifier(47), 2)), "add t11: Max Health Pct"); + Check(!t.Any(c => c.EndsWith("," + T11Keys.ForModifier(60))), "add t11: unknown modifier has no condition"); + Check(d.Notes.Any(n => n.Contains("Modifier 60")), "add t11: unknown modifier named in a note"); + } + + private static void TestAddT11EdgeCases() + { + // Not T11 gear: a note, no conditions. + var plain = new LootItemFacts { Id = 2, Name = "Iron Mace", ObjectClass = (int)AcObjectClass.MeleeWeapon, T11 = T11ItemInfo.None }; + LootItemRuleDraft? p = LootItemRules.Build(plain, new LootItemRuleOptions { IncludeT11 = true }, out _); + Eq(p == null ? -1 : T11Conds(p.Rule).Count, 0, "add t11: non-T11 item adds nothing"); + Check(p != null && p.Notes.Any(n => n.StartsWith("Not a T11 item")), "add t11: non-T11 note"); + + // T11 by name but not identified yet: Is T11 only, and a note to assess it. + LootItemFacts unid = T11Facts("T11 - Tachi", AcObjectClass.MeleeWeapon, null, null); + LootItemRuleDraft? u = LootItemRules.Build(unid, new LootItemRuleOptions { IncludeT11 = true }, out _); + Eq(u == null ? "" : string.Join(" | ", T11Conds(u.Rule)), EQ(T11Keys.IsT11, 1), "add t11: unidentified gives Is T11 only"); + Check(u != null && u.Notes.Any(n => n.Contains("hasn't been identified")), "add t11: unidentified note"); + + // A value-less slot special is required through Has Slot Special. + LootItemFacts ring = T11Facts("T11 - Ring", AcObjectClass.Jewelry, null, "Modifiers:\n- Fortify Vitals\n"); + LootItemRuleDraft? r = LootItemRules.Build(ring, new LootItemRuleOptions { IncludeT11 = true }, out _); + Check(r != null && T11Conds(r.Rule).Contains(EQ(T11Keys.HasSlotSpecial, 1)), "add t11: value-less special -> Has Slot Special"); + + // "Items like this": T11 conditions count, so the "matches every X" warning goes away. + LootItemFacts like = T11Facts("T11 - Tachi", AcObjectClass.MeleeWeapon, T11WeaponLongDesc, null); + LootItemRuleDraft? l = LootItemRules.Build(like, new LootItemRuleOptions { Match = LootItemMatch.Like, IncludeT11 = true }, out _); + Check(l != null && !l.Notes.Any(n => n.StartsWith("Nothing but the class")), "add t11: like + T11 is not class-only"); + Check(l != null && l.Rule.Conditions.All(c => c.NodeType != VTankNodeTypes.StringValueMatch), "add t11: like still has no name"); + LootItemRuleDraft? bare = LootItemRules.Build(plain, new LootItemRuleOptions { Match = LootItemMatch.Like, IncludeT11 = true }, out _); + Check(bare != null && bare.Notes.Any(n => n.StartsWith("Nothing but the class")), "add t11: like + non-T11 still warns class-only"); + } +} diff --git a/Tools/RynthCore.LootSdkTests/Program.cs b/Tools/RynthCore.LootSdkTests/Program.cs index c0069ca..e12d48e 100644 --- a/Tools/RynthCore.LootSdkTests/Program.cs +++ b/Tools/RynthCore.LootSdkTests/Program.cs @@ -45,6 +45,7 @@ internal static partial class Program RunLootEditTests(args); RunLootAddTests(args); RunT11Tests(); + RunLootAddT11Tests(); Console.WriteLine($"\nGolden tests: {_asserts} assertions, {_fails} failed."); -- 2.43.0