using System.Collections.Generic;
using System.Text.Json.Serialization;
namespace RynthCore.Loot.Editing;
// The JSON contract between RynthAi's loot edit bridge and the engine's ImGui
// Loot Editor face (RynthCore docs/IMGUI_LOOT_EDITOR.md). The engine mirrors
// these types in UI\Data\LootEditData.cs; keep the two in step. Strings cross
// the export boundary as UTF-8.
/// The open profile: header, the rule list (one row per rule) and the last command's result.
public sealed class LootEditState
{
/// Changes whenever anything below changes.
public long Revision { get; set; }
/// On Infinite Leaftide (added 2026-11-07): the vocabulary to ask for (LootEditVocab.Ilt).
public bool Ilt { get; set; } = true;
/// Full path of the open profile; empty when none is open.
public string Path { get; set; } = string.Empty;
public string FileName { get; set; } = string.Empty;
/// "utl", "json", or empty.
public string Format { get; set; } = string.Empty;
/// False for a new profile that Save will create.
public bool Exists { get; set; }
public bool ReadOnly { get; set; }
public string ReadOnlyReason { get; set; } = string.Empty;
public bool Dirty { get; set; }
/// The file changed on disk while there were unsaved edits: Save refuses unless forced.
public bool ChangedOnDisk { get; set; }
/// RynthAi's loot profile (what looting uses now).
public string InUsePath { get; set; } = string.Empty;
public bool InUse { get; set; }
/// Result of the last command (or load); MessageSeq counts them.
public string Message { get; set; } = string.Empty;
public bool MessageOk { get; set; } = true;
public long MessageSeq { get; set; }
/// The rule the last command made or moved (to select it), or -1.
public int Focus { get; set; } = -1;
/// Profiles in the loot folder, for the picker.
public List Files { get; set; } = new();
public List Rules { get; set; } = new();
///
/// The "Add to loot profile" popup's rule (item_preview / item_add), or null.
/// Added 2026-10; an older engine ignores it.
///
public LootEditItemDraft? ItemDraft { get; set; }
///
/// The Inventory panel's "Filter like this" result (item_find / find_refresh), or null.
/// Added 2026-10-24; an older engine ignores it.
///
public LootEditItemFind? ItemFind { get; set; }
}
public sealed class LootEditFile
{
public string Path { get; set; } = string.Empty;
public string Display { get; set; } = string.Empty;
}
/// One rule in the list.
public sealed class LootEditRow
{
public string Name { get; set; } = string.Empty;
public bool Enabled { get; set; } = true;
/// VTank action code: 1 Keep, 2 Salvage, 3 Sell, 4 Read, 10 Keep #.
public int Action { get; set; }
public int KeepCount { get; set; }
/// Conditions in words (ASCII), shortened.
public string Summary { get; set; } = string.Empty;
public int Conditions { get; set; }
}
/// A whole rule: what the rule view edits and sends back with "update_rule".
public sealed class LootEditRule
{
public int Index { get; set; } = -1;
public string Name { get; set; } = string.Empty;
public bool Enabled { get; set; } = true;
public int Action { get; set; } = 1;
public int KeepCount { get; set; }
/// Passed through untouched (Phase 1 does not edit these).
public int Priority { get; set; }
/// Null for v0 files, which have no custom expression line.
public string? CustomExpression { get; set; }
/// Every condition node in file order, DisabledRule (9999) nodes included.
public List Conditions { get; set; } = new();
}
public sealed class LootEditCondition
{
/// VTank node type; -1 for a read-only JSON condition shown as text.
public int NodeType { get; set; }
/// The v1 length-code line, kept verbatim ("0" for new conditions).
public string LengthCode { get; set; } = "0";
/// The data lines, raw.
public List Lines { get; set; } = new();
}
/// An edit from the face. Commands that target a rule carry the name the face saw (Expect).
public sealed class LootEditCommand
{
///
/// open, reload, save, set_enabled, move, add, duplicate, delete, rename, update_rule;
/// item_preview, item_add, item_close (Add to loot profile); item_find, find_refresh,
/// find_close (Filter like this, 2026-10-24).
///
public string Op { get; set; } = string.Empty;
public int Index { get; set; } = -1;
/// move: the index the rule ends up at.
public int To { get; set; } = -1;
public string Value { get; set; } = string.Empty;
public string Path { get; set; } = string.Empty;
/// The rule's name as the face saw it; a mismatch means the list changed under it.
public string? Expect { get; set; }
/// open/reload: discard unsaved edits; save: overwrite a file that changed on disk.
public bool Force { get; set; }
public LootEditRule? Rule { get; set; }
/// item_preview / item_add: the item and the popup's choices (added 2026-10).
public LootEditItemRequest? Item { get; set; }
}
///
/// "Add to loot profile" from a clicked item (added 2026-10): what the popup
/// asks for. item_preview builds the rule into LootEditState.ItemDraft;
/// item_add builds it and adds it to the profile (saved, RynthAi reloads it);
/// item_close drops the draft.
///
public sealed class LootEditItemRequest
{
/// The item; 0 = the item selected in the game.
public uint ItemId { get; set; }
/// LootItemMatch: 0 name + class, 1 name only, 2 items like this.
public int Match { get; set; }
/// VTank action code (1 Keep, 2 Salvage, 3 Sell, 4 Read, 10 Keep #); 0 = the item's default.
public int Action { get; set; }
/// Keep # count; -1 = default (one full stack).
public int KeepCount { get; set; } = -1;
/// Empty = the default name ("Keep Copper Pea").
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; }
///
/// The attribute checklist's choices (added 2026-10-18), one per row the player changed; rows
/// without a choice keep their default (ticked for "items like this", T11 rows with
/// IncludeT11). Null from an older engine: every row at its default, as before.
///
public List? Choices { get; set; }
/// Echoed in the draft so the popup knows the answer is to its latest ask.
public int Seq { get; set; }
///
/// A filter, not a rule to add (added 2026-10-24): item_preview builds the draft without a
/// loot profile (no action, name or place in a list); item_find filters with it.
///
public bool Find { get; set; }
/// item_find: (the items in , or Global Inventory).
public string Scope { get; set; } = string.Empty;
/// item_find / find_refresh, scope inventory: the items to judge (what the panel lists).
public List? Candidates { get; set; }
///
/// No item (added 2026-10-24): the checklist lists every attribute (LootItemAttributes.ForBlank),
/// for the Inventory panel's own filter. ItemId is ignored.
///
public bool Blank { get; set; }
/// Spells and cantrips the player added from the standard lists (added 2026-10-24).
public List? Extras { get; set; }
///
/// Blank: edit this rule of the open profile (its index) instead of adding one (added 2026-11-07); -1 adds.
/// Without Choices the checklist starts from the rule's conditions.
///
public int EditIndex { get; set; } = -1;
/// EditIndex's rule name as the editor showed it (refused when the rule there changed).
public string EditName { get; set; } = string.Empty;
}
/// A spell picked from the standard lists (LootSpellCatalog), required by the rule.
public sealed class LootEditItemExtra
{
public const string Spell = "spell", Cantrip = "cantrip";
/// (a leveled family) or .
public string Kind { get; set; } = Spell;
/// The family ("Strength", "Aura of Defender") or the cantrip without its tier ("Coordination").
public string Name { get; set; } = string.Empty;
/// Spell: the level, 1-8. Cantrip: the tier, 0 Minor ... 4 Paragon.
public int Level { get; set; }
/// A LootItemAttributeOp (or better, exact, any tier); -1 = or better.
public int Op { get; set; } = -1;
}
/// Where "Filter like this" looks (LootEditItemRequest.Scope).
public static class LootFindScopes
{
/// The items the request lists (the Inventory panel's).
public const string Inventory = "inventory";
/// RynthInventory's Global Inventory: the result carries the spec for "/ginv like".
public const string Global = "global";
}
/// One checklist row as the player set it (LootEditItemAttribute.Id).
public sealed class LootEditItemChoice
{
public string Id { get; set; } = string.Empty;
public bool On { get; set; }
/// A LootItemAttributeOp code; -1 = the row's default.
public int Op { get; set; } = -1;
/// The edited value; empty = the item's own.
public string Value { get; set; } = string.Empty;
}
///
/// One row of the popup's attribute checklist (added 2026-10-18): something the item has that a
/// rule can require, its value, and how it is required now.
///
public sealed class LootEditItemAttribute
{
/// Stable within the item ("L:131", "D:152", "spell:Major Strength", "t11:tier").
public string Id { get; set; } = string.Empty;
/// Item, Weapon / Armor, Ratings, Spells, Pet essence, T11, Requirements.
public string Group { get; set; } = string.Empty;
public string Label { get; set; } = string.Empty;
/// The item's own value, for display ("Gold", "7", "1.12", "Major").
public string ItemValue { get; set; } = string.Empty;
/// The value the rule uses now (the item's, or the player's edit).
public string Value { get; set; } = string.Empty;
/// The row's comparison now (LootItemAttributeOp).
public int Op { get; set; }
/// The comparisons the row offers, the default first.
public List Ops { get; set; } = new();
/// The value can be typed (a number); named values and spells can't.
public bool Editable { get; set; }
///
/// The values a named row can take (added 2026-10-24): the popup offers them in a list and
/// sends the picked Id as the choice's Value. Null for typed and fixed rows.
///
public List? Choices { get; set; }
///
/// The Choices are flags (imbues, damage types; added 2026-11-07): with "has any" / "has all"
/// several can be picked, the Value is their sum.
///
public bool Flags { get; set; }
/// The rule requires this row now.
public bool On { get; set; }
public string Tip { get; set; } = string.Empty;
}
/// The rule an item makes, as the popup shows it, and what happened when it was added.
public sealed class LootEditItemDraft
{
public int Seq { get; set; }
/// False: Error says why there is no rule (no item selected, read-only profile...).
public bool Ok { get; set; }
public string Error { get; set; } = string.Empty;
public uint ItemId { get; set; }
public string ItemName { get; set; } = string.Empty;
public string ClassName { get; set; } = string.Empty;
public bool Stackable { get; set; }
public string TargetPath { get; set; } = string.Empty;
public string TargetFile { get; set; } = string.Empty;
/// The target is the profile RynthAi loots with.
public bool TargetInUse { get; set; }
/// "utl" or "json".
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;
public string DefaultRuleName { get; set; } = string.Empty;
/// The rule in words: name, action, one line per condition (ASCII).
public List Preview { get; set; } = new();
/// Where it goes (0-based) among RuleCount rules, and why there.
public int InsertAt { get; set; } = -1;
public int RuleCount { get; set; }
public string OrderNote { get; set; } = string.Empty;
///
/// Why RynthAi's own looting takes the item whatever the profile says, or empty: one of
/// its built-in keeps (Learn unknown spells, mana stones, Mana Tap), with where to change
/// it (2026-10-05). Also appended to OrderNote, which every engine's popup shows.
///
public string BuiltInReason { get; set; } = string.Empty;
public List Notes { get; set; } = new();
///
/// True from a RynthAi with the attribute checklist (added 2026-10-18): the popup shows
/// instead of its single "Include T11 attributes" box.
///
public bool AttributesSupported { get; set; }
/// The item's checklist rows, grouped in display order (added 2026-10-18).
public List Attributes { get; set; } = new();
/// item_add went through; Message says what was added where.
public bool Added { get; set; }
public string Message { get; set; } = string.Empty;
/// A filter's draft (the request's Find; added 2026-10-24): no profile, action or place.
public bool Find { get; set; }
///
/// A rule from the blank checklist (the request's Blank without Find; added 2026-11-07, the Loot
/// Editor's Add rule): no item; it goes in at the end. False from an older RynthAi.
///
public bool Blank { get; set; }
/// The rule this draft edits (the request's EditIndex), -1 when it adds one (added 2026-11-07).
public int EditIndex { get; set; } = -1;
}
///
/// "Filter like this" (added 2026-10-24): the rule the checklist made and, for the panel's
/// items, which match. item_find builds it from the item; find_refresh judges the panel's
/// items again with the same rule (new loot, identifies that came in); find_close drops it.
///
public sealed class LootEditItemFind
{
/// The request's Seq (item_find or find_refresh).
public int Seq { get; set; }
public bool Ok { get; set; }
public string Error { get; set; } = string.Empty;
/// .
public string Scope { get; set; } = string.Empty;
public uint ItemId { get; set; }
public string ItemName { get; set; } = string.Empty;
/// What the filter is called ("like Gold Ring").
public string Label { get; set; } = string.Empty;
/// The rule's conditions in words, one per line (ASCII).
public List Lines { get; set; } = new();
/// Scope inventory: the candidates the rule takes.
public List Ids { get; set; } = new();
///
/// Scope inventory: candidates that failed only on something an identify would tell
/// (not identified yet), or that RynthAi doesn't know yet.
///
public List Unknown { get; set; } = new();
/// How many candidates were judged.
public int Checked { get; set; }
/// Scope global: the "/ginv like" argument (LootFindSpec).
public string Spec { get; set; } = string.Empty;
/// Some condition needs an identify to judge (so unidentified items can be Unknown).
public bool NeedsIdentify { get; set; }
}
/// Names for the face's pickers. Sent once per plugin load.
public sealed class LootEditVocab
{
public List Actions { get; set; } = new();
public List NodeTypes { get; set; } = new();
public List ObjectClasses { get; set; } = new();
/// Built for Infinite Leaftide (ACECustom keys offered; added 2026-11-07).
public bool Ilt { get; set; } = true;
public List LongKeys { get; set; } = new();
public List DoubleKeys { get; set; } = new();
public List StringKeys { get; set; } = new();
public List Skills { get; set; } = new();
///
/// Names for long keys' values (WieldSkilltype's skills, MaterialType's
/// materials...), added 2026-10. An older engine ignores this; a newer engine
/// with an older RynthAi gets it empty and keeps the value a text box.
///
public List LongValueTables { get; set; } = new();
/// The standard spell lists (LootSpellCatalog, added 2026-10-24): leveled families by school.
public List SpellFamilies { get; set; } = new();
/// Cantrip names without their tier ("Coordination").
public List Cantrips { get; set; } = new();
/// The cantrip tiers, lowest first (Minor ... Paragon).
public List CantripTiers { get; set; } = new();
}
/// One leveled spell family the popup offers (LootSpellFamily).
public sealed class LootEditSpellFamily
{
public string Name { get; set; } = string.Empty;
public string School { get; set; } = string.Empty;
public int MinLevel { get; set; } = 1;
public int MaxLevel { get; set; } = 8;
}
public sealed class LootEditName
{
public int Id { get; set; }
public string Name { get; set; } = string.Empty;
}
/// What one long key's numbers mean (LootRuleText.ValueTableFor).
public sealed class LootEditValueTable
{
/// The long key (e.g. 159 WieldSkilltype).
public int Key { get; set; }
/// The value is a set of flags: a named value is one flag (or a common pair).
public bool Flags { get; set; }
public List Values { get; set; } = new();
}
public sealed class LootEditNodeType
{
public int Id { get; set; }
public string Name { get; set; } = string.Empty;
/// Data lines the node takes.
public int Lines { get; set; }
public List Labels { get; set; } = new();
public List Defaults { get; set; } = new();
///
/// The face's editor: "class" (object class), "keyval" (value, key), "keypattern"
/// (pattern, key), "text" (one string), "value" (one number), "raw" (the lines as text).
///
public string Editor { get; set; } = "raw";
/// For keyval/keypattern: "long", "double", "string" or "skill".
public string KeyTable { get; set; } = string.Empty;
///
/// keyval "long" only: the value is picked by name when the key has a
/// LongValueTables entry (GE/LE/E/NE and buffed GE; not "has flag"). Added 2026-10.
///
public bool NamedValues { get; set; }
}
[JsonSourceGenerationOptions(WriteIndented = false, PropertyNameCaseInsensitive = true)]
[JsonSerializable(typeof(LootEditState))]
[JsonSerializable(typeof(LootEditRule))]
[JsonSerializable(typeof(LootEditCommand))]
[JsonSerializable(typeof(LootEditVocab))]
public sealed partial class LootEditJsonContext : JsonSerializerContext { }