feat(loot): include T11 attributes when adding an item to a loot profile #4

Closed
Silentkelpie wants to merge 1 commit from Silentkelpie/SK-RynthSuite:feat/loot-add-t11 into main
6 changed files with 223 additions and 13 deletions

View file

@ -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
{
/// <summary>The item selected in the game, or 0.</summary>
public Func<uint> SelectedItemId { get; set; } = () => 0;
/// <summary>The item's facts from the object cache, or null. The bool: "items like this" (ask for an ID if it isn't identified).</summary>
public Func<uint, bool, LootItemFacts?> Facts { get; set; } = (_, _) => null;
/// <summary>
/// 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.
/// </summary>
public Func<uint, bool, bool, LootItemFacts?> Facts { get; set; } = (_, _, _) => null;
/// <summary>The first rule of the .utl profile that matches the item now, or -1.</summary>
public Func<uint, VTankLootProfile, int> FirstMatchUtl { get; set; } = (_, _) => -1;
/// <summary>The first rule of the native profile that matches the item now, or -1.</summary>

View file

@ -1603,8 +1603,12 @@ public sealed partial class RynthAiPlugin
if (inUse) ReloadLootProfileInUse(d.TargetPath);
}
/// <summary>What a loot rule can be built from: the item's name, class, stack and key properties, from the object cache.</summary>
private RynthCore.Loot.Editing.LootItemFacts? BuildLootItemFacts(uint itemId, bool like)
/// <summary>
/// What a loot rule can be built from: the item's name, class, stack, key properties and
/// T11 reading, from the object cache. <paramref name="like"/> adds its spells;
/// <paramref name="t11"/> asks for an ID when a T11 item's text hasn't arrived.
/// </summary>
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
}
/// <summary>
/// /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.
/// </summary>
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;
}
}

View file

@ -133,6 +133,11 @@ public sealed class LootEditItemRequest
public string RuleName { get; set; } = string.Empty;
/// <summary>True: the profile open in the Loot Editor; false: the one RynthAi loots with.</summary>
public bool ToOpenProfile { get; set; }
/// <summary>
/// Also require the item's T11 attributes (LootItemRuleOptions.IncludeT11). Added
/// 2026-10-07; an older engine never sends it, so it reads false.
/// </summary>
public bool IncludeT11 { get; set; }
/// <summary>Echoed in the draft so the popup knows the answer is to its latest ask.</summary>
public int Seq { get; set; }
}
@ -156,6 +161,10 @@ public sealed class LootEditItemDraft
public string Format { get; set; } = string.Empty;
/// <summary>What was built (the defaults filled in).</summary>
public int Match { get; set; }
/// <summary>The rule was asked to include the item's T11 attributes (added 2026-10-07).</summary>
public bool IncludeT11 { get; set; }
/// <summary>The item is T11 gear, so "Include T11 attributes" has something to add (added 2026-10-07).</summary>
public bool IsT11 { get; set; }
public int Action { get; set; }
public int KeepCount { get; set; }
public string RuleName { get; set; } = string.Empty;

View file

@ -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<int, double> Doubles { get; set; } = new();
/// <summary>The item's spell names (empty when none or not identified).</summary>
public List<string> Spells { get; set; } = new();
/// <summary>
/// The item's T11 reading (ACECustom tier 11+ text), or null when it wasn't asked for.
/// <see cref="T11ItemInfo.None"/> for an item that isn't T11 gear.
/// </summary>
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; }
/// <summary>Null or blank: "Keep Copper Pea" and the like.</summary>
public string? RuleName { get; set; }
/// <summary>
/// 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.
/// </summary>
public bool IncludeT11 { get; set; }
}
/// <summary>A built rule, ready to preview and insert.</summary>
@ -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;
}
/// <summary>
/// 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.
/// </summary>
private static int AddT11Conditions(VTankLootRule rule, LootItemFacts f, List<string> 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<string>();
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);

View file

@ -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();
}
/// <summary>A condition as "type:line,line" for order-sensitive comparisons.</summary>
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<string> 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<string>();
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<string> 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");
}
}

View file

@ -45,6 +45,7 @@ internal static partial class Program
RunLootEditTests(args);
RunLootAddTests(args);
RunT11Tests();
RunLootAddT11Tests();
Console.WriteLine($"\nGolden tests: {_asserts} assertions, {_fails} failed.");