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; } /// 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; } } 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. 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; } /// Echoed in the draft so the popup knows the answer is to its latest ask. public int Seq { get; set; } } /// 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(); /// item_add went through; Message says what was added where. public bool Added { get; set; } public string Message { get; set; } = string.Empty; } /// 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(); 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(); } 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 { }