feat: SK backlog from test through 2026.11.22.48 (Trade Shop, Oracle, quests, loot, nav)
Squash of test/main-merge-2026-10-25 onto aelrynth main 2026.11.19.1 for the standing sk PR. Includes Trade Shop, Oracle wiki/ILT tracker, quest runs, loot checklist, RynthNav, VTank import. HandWrittenVersion remains 0.5.0-legacy-ui. See Changelog/2026-11-22-sk-backlog-test-merge.md.
This commit is contained in:
parent
660e6b5b1c
commit
dc08e1abba
521 changed files with 47247 additions and 795 deletions
78
Plugins/RynthCore.Plugin.RynthInventory/Data/BankRoster.cs
Normal file
78
Plugins/RynthCore.Plugin.RynthInventory/Data/BankRoster.cs
Normal file
|
|
@ -0,0 +1,78 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using RynthCore.Plugin.Shared;
|
||||
|
||||
namespace RynthCore.Plugin.RynthInventory.Data;
|
||||
|
||||
/// <summary>One character on the Banking tab: its saved balances (null = never read) and account.</summary>
|
||||
internal sealed record BankRosterEntry(string Name, string Account, bool Current, IltBankRow? Bank);
|
||||
|
||||
/// <summary>
|
||||
/// The Banking tab's character list (2026-10-13; the Mini Remote's Banking tab moved here). Every
|
||||
/// character RynthILT has bank balances for on this server (its saved per-character state, so every
|
||||
/// account played on this PC), plus every character Global Inventory has recorded on the same
|
||||
/// server without a balance yet, so the list covers the same characters as the inventory does.
|
||||
/// Pure: the tests feed it a parsed bank view and an index.
|
||||
/// </summary>
|
||||
internal static class BankRoster
|
||||
{
|
||||
/// <summary>
|
||||
/// The merged list: the logged-in character first, then by name. A name in both lists keeps
|
||||
/// RynthILT's balances and the inventory's account.
|
||||
/// </summary>
|
||||
public static List<BankRosterEntry> Build(IltBankView bank, InventoryIndex? index)
|
||||
{
|
||||
var byName = new Dictionary<string, BankRosterEntry>(StringComparer.OrdinalIgnoreCase);
|
||||
foreach (IltBankRow r in bank.Characters)
|
||||
byName[r.Name] = new BankRosterEntry(r.Name, string.Empty, r.Current, r);
|
||||
|
||||
if (index != null)
|
||||
{
|
||||
foreach (CharacterInfo ci in index.Characters)
|
||||
{
|
||||
// Same server only: a bank belongs to one world.
|
||||
if (!SameServer(ci, bank)) continue;
|
||||
string account = !string.IsNullOrEmpty(ci.Account) && ci.Account != "unknown" ? ci.Account : string.Empty;
|
||||
if (byName.TryGetValue(ci.Name, out BankRosterEntry? have))
|
||||
byName[ci.Name] = have with { Account = account, Current = have.Current || ci.IsCurrentCharacter };
|
||||
else
|
||||
byName[ci.Name] = new BankRosterEntry(ci.Name, account, ci.IsCurrentCharacter, null);
|
||||
}
|
||||
}
|
||||
|
||||
var list = new List<BankRosterEntry>(byName.Values);
|
||||
list.Sort((a, b) => a.Current != b.Current ? (a.Current ? -1 : 1) : string.Compare(a.Name, b.Name, StringComparison.OrdinalIgnoreCase));
|
||||
return list;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A recorded character is on the bank's server: the world RynthILT names when it gave one,
|
||||
/// otherwise the server Global Inventory says you are on now.
|
||||
/// </summary>
|
||||
private static bool SameServer(CharacterInfo ci, IltBankView bank) =>
|
||||
bank.World.Length > 0 ? InventoryIndex.SameName(ci.Server, bank.World) : ci.IsCurrentServer;
|
||||
|
||||
/// <summary>The sums over every character with a balance (one row of the same shape).</summary>
|
||||
public static IltBankRow Totals(IReadOnlyList<BankRosterEntry> roster)
|
||||
{
|
||||
long py = 0, lum = 0, lk = 0, mk = 0, ec = 0, wec = 0, pc = 0;
|
||||
foreach (BankRosterEntry e in roster)
|
||||
{
|
||||
if (e.Bank is not { } b) continue;
|
||||
py += b.Pyreals; lum += b.Luminance; lk += b.LegendaryKeys; mk += b.MythicalKeys;
|
||||
ec += b.EnlightenedCoins; wec += b.WeaklyEnlightenedCoins; pc += b.PrestigeCoins;
|
||||
}
|
||||
return new IltBankRow("Total", false, py, lum, lk, mk, ec, wec, pc, DateTime.MinValue);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The withdraw / transfer amount typed in the form: a positive whole number (commas and spaces
|
||||
/// allowed), or 0 when it isn't one.
|
||||
/// </summary>
|
||||
public static long ParseAmount(string? text)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(text)) return 0;
|
||||
string digits = text.Replace(",", string.Empty).Replace(" ", string.Empty).Trim();
|
||||
return long.TryParse(digits, System.Globalization.NumberStyles.None, System.Globalization.CultureInfo.InvariantCulture, out long n) && n > 0 ? n : 0;
|
||||
}
|
||||
}
|
||||
|
|
@ -56,6 +56,11 @@ internal sealed class InventoryQuery
|
|||
public bool SearchSpells;
|
||||
public InventorySort Sort = InventorySort.Name;
|
||||
public bool Descending;
|
||||
/// <summary>
|
||||
/// "Find like this" (/ginv like, 2026-10-24): 1 keeps the item, 0 drops it, -1 drops it as
|
||||
/// unknown (counted in <see cref="InventoryResult.LikeUnknown"/>). Null: no such filter.
|
||||
/// </summary>
|
||||
public Func<ItemRecord, int>? Like;
|
||||
}
|
||||
|
||||
/// <summary>A total for one item name over the results: "Pyreal: 12,345 across 4 characters".</summary>
|
||||
|
|
@ -76,6 +81,8 @@ internal sealed class InventoryResult
|
|||
public readonly List<InventoryTotal> Totals = new();
|
||||
public long TotalCount;
|
||||
public int CharacterCount;
|
||||
/// <summary>Items the like filter couldn't judge (not identified, or saved by an older RynthInventory).</summary>
|
||||
public int LikeUnknown;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -256,6 +263,12 @@ internal sealed class InventoryIndex
|
|||
if (!hay.Contains(term, StringComparison.Ordinal)) { all = false; break; }
|
||||
if (!all) continue;
|
||||
}
|
||||
if (q.Like != null)
|
||||
{
|
||||
int v = q.Like(r.Item);
|
||||
if (v < 0) result.LikeUnknown++;
|
||||
if (v <= 0) continue;
|
||||
}
|
||||
result.Rows.Add(r);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -118,9 +118,45 @@ internal static class InventoryJson
|
|||
}
|
||||
}
|
||||
if (it.Identified) sb.Append(", \"identified\": true");
|
||||
if (it.HasFacts)
|
||||
{
|
||||
sb.Append(", \"class\": ").Append(it.ObjectClass.ToString(Inv));
|
||||
if (it.Ints != null && it.Ints.Count > 0)
|
||||
{
|
||||
sb.Append(", \"ints\": {");
|
||||
bool first = true;
|
||||
foreach (KeyValuePair<int, int> kv in Sorted(it.Ints))
|
||||
{
|
||||
if (!first) sb.Append(", ");
|
||||
first = false;
|
||||
sb.Append('"').Append(kv.Key.ToString(Inv)).Append("\": ").Append(kv.Value.ToString(Inv));
|
||||
}
|
||||
sb.Append('}');
|
||||
}
|
||||
if (it.Doubles != null && it.Doubles.Count > 0)
|
||||
{
|
||||
sb.Append(", \"floats\": {");
|
||||
bool first = true;
|
||||
foreach (KeyValuePair<int, double> kv in Sorted(it.Doubles))
|
||||
{
|
||||
if (!first) sb.Append(", ");
|
||||
first = false;
|
||||
double v = double.IsFinite(kv.Value) ? kv.Value : 0;
|
||||
sb.Append('"').Append(kv.Key.ToString(Inv)).Append("\": ").Append(v.ToString("R", Inv));
|
||||
}
|
||||
sb.Append('}');
|
||||
}
|
||||
}
|
||||
sb.Append('}');
|
||||
}
|
||||
|
||||
private static List<KeyValuePair<int, T>> Sorted<T>(Dictionary<int, T> d)
|
||||
{
|
||||
var list = new List<KeyValuePair<int, T>>(d);
|
||||
list.Sort((a, b) => a.Key.CompareTo(b.Key));
|
||||
return list;
|
||||
}
|
||||
|
||||
private static void Time(StringBuilder sb, DateTime utc)
|
||||
{
|
||||
sb.Append('"');
|
||||
|
|
@ -258,6 +294,25 @@ internal static class InventoryJson
|
|||
}
|
||||
string[] names = GetStrings(e, "spellNames");
|
||||
it.SpellNames = names.Length == it.Spells.Length ? names : Array.Empty<string>();
|
||||
if (e.TryGetProperty("class", out JsonElement cls) && cls.ValueKind == JsonValueKind.Number && cls.TryGetInt32(out int oc))
|
||||
{
|
||||
it.HasFacts = true;
|
||||
it.ObjectClass = oc;
|
||||
if (e.TryGetProperty("ints", out JsonElement ints) && ints.ValueKind == JsonValueKind.Object)
|
||||
{
|
||||
it.Ints = new Dictionary<int, int>();
|
||||
foreach (JsonProperty p in ints.EnumerateObject())
|
||||
if (int.TryParse(p.Name, NumberStyles.Integer, Inv, out int k) && p.Value.ValueKind == JsonValueKind.Number && p.Value.TryGetInt32(out int v))
|
||||
it.Ints[k] = v;
|
||||
}
|
||||
if (e.TryGetProperty("floats", out JsonElement dbl) && dbl.ValueKind == JsonValueKind.Object)
|
||||
{
|
||||
it.Doubles = new Dictionary<int, double>();
|
||||
foreach (JsonProperty p in dbl.EnumerateObject())
|
||||
if (int.TryParse(p.Name, NumberStyles.Integer, Inv, out int k) && p.Value.ValueKind == JsonValueKind.Number && p.Value.TryGetDouble(out double v))
|
||||
it.Doubles[k] = v;
|
||||
}
|
||||
}
|
||||
return it;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -54,6 +54,18 @@ internal sealed class ItemRecord
|
|||
/// <summary>The client had appraisal data for it when scanned (spells, workmanship, set are then known).</summary>
|
||||
public bool Identified;
|
||||
|
||||
// "Find like this in Global Inventory" (2026-10-24): what a loot rule from the Inventory
|
||||
// panel's checklist tests, so it can be judged on this saved copy. Written by RynthInventory
|
||||
// 0.1.5 and later; an older file's items have HasFacts false (only the fields above).
|
||||
/// <summary>The facts below were read (the scanner is new enough).</summary>
|
||||
public bool HasFacts;
|
||||
/// <summary>AcObjectClass, as RynthAi classifies it (LootSdk AcItemClassifier).</summary>
|
||||
public int ObjectClass;
|
||||
/// <summary>Int properties a rule can test (LootItemAttributes.IntKeys, T11's virtual keys), non-zero only.</summary>
|
||||
public Dictionary<int, int>? Ints;
|
||||
/// <summary>Float properties a rule can test (LootItemAttributes.DoubleKeys), non-zero only.</summary>
|
||||
public Dictionary<int, double>? Doubles;
|
||||
|
||||
public string PathText => Path.Length == 0 ? string.Empty : string.Join(" > ", Path);
|
||||
}
|
||||
|
||||
|
|
@ -134,6 +146,25 @@ internal sealed class CharacterSnapshot
|
|||
h.Add((uint)i.Spells.Length);
|
||||
foreach (uint s in i.Spells) h.Add(s);
|
||||
h.Add(i.Identified ? 1u : 0u);
|
||||
if (!i.HasFacts) return;
|
||||
h.Add((uint)i.ObjectClass);
|
||||
if (i.Ints != null)
|
||||
{
|
||||
var keys = new List<int>(i.Ints.Keys);
|
||||
keys.Sort();
|
||||
foreach (int k in keys) { h.Add((uint)k); h.Add((uint)i.Ints[k]); }
|
||||
}
|
||||
h.Add(0xFACEu);
|
||||
if (i.Doubles != null)
|
||||
{
|
||||
var keys = new List<int>(i.Doubles.Keys);
|
||||
keys.Sort();
|
||||
foreach (int k in keys)
|
||||
{
|
||||
long bits = BitConverter.DoubleToInt64Bits(i.Doubles[k]);
|
||||
h.Add((uint)k); h.Add((uint)bits); h.Add((uint)(bits >> 32));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
278
Plugins/RynthCore.Plugin.RynthInventory/Data/TradeJobs.cs
Normal file
278
Plugins/RynthCore.Plugin.RynthInventory/Data/TradeJobs.cs
Normal file
|
|
@ -0,0 +1,278 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace RynthCore.Plugin.RynthInventory.Data;
|
||||
|
||||
/// <summary>
|
||||
/// A started trade, shared by every client through files (2026-10-25). Each account plays in its
|
||||
/// own AC client, so the client that built the list can't give another account's items: it
|
||||
/// writes the job, and the client logged into each account gives that account's items (logging
|
||||
/// onto the character that holds them with /rc switchchar) and writes back how each went.
|
||||
///
|
||||
/// Files, in %APPDATA%\RynthCore\inventory\trades\:
|
||||
/// <id>.job.json the job; written only by the client that started it (start, cancel)
|
||||
/// <id>.<account>.status.json one per giving account; written only by that account's client
|
||||
/// One writer per file, every write a temp file moved into place, so nothing is ever half read.
|
||||
/// Hand-written JSON read with JsonDocument, like the other RynthInventory files.
|
||||
/// </summary>
|
||||
internal sealed class TradeJob
|
||||
{
|
||||
public string Id = string.Empty;
|
||||
public string Server = string.Empty;
|
||||
public string Recipient = string.Empty;
|
||||
public string StartedBy = string.Empty;
|
||||
public DateTime StartedUtc;
|
||||
public bool Cancelled;
|
||||
public readonly List<TradeItem> Items = new();
|
||||
}
|
||||
|
||||
/// <summary>One account's report on a job: where its client is and each of its items.</summary>
|
||||
internal sealed class TradeAccountStatus
|
||||
{
|
||||
public string Account = string.Empty;
|
||||
/// <summary>The character that account's client is on (or switching to).</summary>
|
||||
public string Character = string.Empty;
|
||||
public string Message = string.Empty;
|
||||
public DateTime UpdatedUtc;
|
||||
/// <summary>Item index in the job -> (status, text).</summary>
|
||||
public readonly Dictionary<int, (TradeItemStatus Status, string Text)> Items = new();
|
||||
}
|
||||
|
||||
internal static class TradeJobs
|
||||
{
|
||||
/// <summary>Jobs (and their status files) this old are deleted by whichever client sees them.</summary>
|
||||
private static readonly TimeSpan MaxAge = TimeSpan.FromHours(24);
|
||||
|
||||
public static string Folder(string inventoryRoot) => Path.Combine(inventoryRoot, "trades");
|
||||
|
||||
public static string NewId() =>
|
||||
DateTime.UtcNow.ToString("yyyyMMdd-HHmmss", CultureInfo.InvariantCulture) + "-" +
|
||||
Guid.NewGuid().ToString("N").Substring(0, 6);
|
||||
|
||||
private static string JobPath(string folder, string id) => Path.Combine(folder, id + ".job.json");
|
||||
|
||||
private static string StatusPath(string folder, string id, string account) =>
|
||||
Path.Combine(folder, id + "." + SafeName(account) + ".status.json");
|
||||
|
||||
private static string SafeName(string s)
|
||||
{
|
||||
var sb = new StringBuilder();
|
||||
foreach (char ch in s.Trim().ToLowerInvariant())
|
||||
sb.Append(char.IsLetterOrDigit(ch) || ch is '-' or '_' ? ch : '_');
|
||||
return sb.Length > 0 ? sb.ToString() : "unknown";
|
||||
}
|
||||
|
||||
public static bool SameAccount(string a, string b) =>
|
||||
string.Equals(a.Trim(), b.Trim(), StringComparison.OrdinalIgnoreCase);
|
||||
|
||||
// ── Writing ───────────────────────────────────────────────────────────
|
||||
|
||||
public static void WriteJob(string folder, TradeJob job)
|
||||
{
|
||||
var sb = new StringBuilder();
|
||||
sb.Append("{\n \"id\": "); InventoryJson.Str(sb, job.Id);
|
||||
sb.Append(",\n \"server\": "); InventoryJson.Str(sb, job.Server);
|
||||
sb.Append(",\n \"recipient\": "); InventoryJson.Str(sb, job.Recipient);
|
||||
sb.Append(",\n \"startedBy\": "); InventoryJson.Str(sb, job.StartedBy);
|
||||
sb.Append(",\n \"startedUtc\": "); InventoryJson.Str(sb, job.StartedUtc.ToString("o", CultureInfo.InvariantCulture));
|
||||
sb.Append(",\n \"cancelled\": ").Append(job.Cancelled ? "true" : "false");
|
||||
sb.Append(",\n \"items\": [");
|
||||
for (int i = 0; i < job.Items.Count; i++)
|
||||
{
|
||||
TradeItem it = job.Items[i];
|
||||
sb.Append(i == 0 ? "\n {" : ",\n {");
|
||||
sb.Append("\"characterKey\": "); InventoryJson.Str(sb, it.CharacterKey);
|
||||
sb.Append(", \"character\": "); InventoryJson.Str(sb, it.CharacterName);
|
||||
sb.Append(", \"account\": "); InventoryJson.Str(sb, it.Account);
|
||||
sb.Append(", \"server\": "); InventoryJson.Str(sb, it.Server);
|
||||
sb.Append(", \"name\": "); InventoryJson.Str(sb, it.ItemName);
|
||||
sb.Append(", \"wcid\": ").Append(it.Wcid.ToString(CultureInfo.InvariantCulture));
|
||||
sb.Append(", \"qty\": ").Append(it.Quantity.ToString(CultureInfo.InvariantCulture));
|
||||
sb.Append(", \"itemId\": ").Append(it.ItemId.ToString(CultureInfo.InvariantCulture));
|
||||
sb.Append('}');
|
||||
}
|
||||
sb.Append("\n ]\n}\n");
|
||||
WriteAtomic(JobPath(folder, job.Id), sb.ToString());
|
||||
}
|
||||
|
||||
public static void WriteStatus(string folder, string jobId, TradeAccountStatus st)
|
||||
{
|
||||
var sb = new StringBuilder();
|
||||
sb.Append("{\n \"account\": "); InventoryJson.Str(sb, st.Account);
|
||||
sb.Append(",\n \"character\": "); InventoryJson.Str(sb, st.Character);
|
||||
sb.Append(",\n \"message\": "); InventoryJson.Str(sb, st.Message);
|
||||
sb.Append(",\n \"updatedUtc\": "); InventoryJson.Str(sb, st.UpdatedUtc.ToString("o", CultureInfo.InvariantCulture));
|
||||
sb.Append(",\n \"items\": [");
|
||||
bool first = true;
|
||||
foreach (var kv in st.Items)
|
||||
{
|
||||
sb.Append(first ? "\n {" : ",\n {");
|
||||
first = false;
|
||||
sb.Append("\"i\": ").Append(kv.Key.ToString(CultureInfo.InvariantCulture));
|
||||
sb.Append(", \"status\": "); InventoryJson.Str(sb, kv.Value.Status.ToString());
|
||||
sb.Append(", \"text\": "); InventoryJson.Str(sb, kv.Value.Text);
|
||||
sb.Append('}');
|
||||
}
|
||||
sb.Append("\n ]\n}\n");
|
||||
WriteAtomic(StatusPath(folder, jobId, st.Account), sb.ToString());
|
||||
}
|
||||
|
||||
private static void WriteAtomic(string path, string text)
|
||||
{
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(path)!);
|
||||
string tmp = path + "." + Environment.ProcessId.ToString(CultureInfo.InvariantCulture) + ".tmp";
|
||||
File.WriteAllText(tmp, text);
|
||||
File.Move(tmp, path, overwrite: true);
|
||||
}
|
||||
|
||||
/// <summary>Deletes a job and every status file of it (Clear / New on the client that started it).</summary>
|
||||
public static void Delete(string folder, string id)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!Directory.Exists(folder)) return;
|
||||
foreach (string f in Directory.GetFiles(folder, id + ".*"))
|
||||
try { File.Delete(f); } catch { }
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
|
||||
// ── Reading ───────────────────────────────────────────────────────────
|
||||
|
||||
/// <summary>Every job on <paramref name="server"/>, oldest first. Deletes jobs older than a day.</summary>
|
||||
public static List<TradeJob> ReadJobs(string folder, string server)
|
||||
{
|
||||
var jobs = new List<TradeJob>();
|
||||
try
|
||||
{
|
||||
if (!Directory.Exists(folder)) return jobs;
|
||||
foreach (string path in Directory.GetFiles(folder, "*.job.json"))
|
||||
{
|
||||
TradeJob? job = ReadJob(path);
|
||||
if (job == null) continue;
|
||||
if (DateTime.UtcNow - job.StartedUtc > MaxAge)
|
||||
{
|
||||
Delete(folder, job.Id);
|
||||
continue;
|
||||
}
|
||||
if (InventoryIndex.SameName(job.Server, server)) jobs.Add(job);
|
||||
}
|
||||
}
|
||||
catch { }
|
||||
jobs.Sort((a, b) => a.StartedUtc.CompareTo(b.StartedUtc));
|
||||
return jobs;
|
||||
}
|
||||
|
||||
public static TradeJob? ReadJob(string folder, string id) => ReadJob(JobPath(folder, id));
|
||||
|
||||
private static TradeJob? ReadJob(string path)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!File.Exists(path)) return null;
|
||||
using var doc = JsonDocument.Parse(File.ReadAllText(path));
|
||||
JsonElement r = doc.RootElement;
|
||||
if (r.ValueKind != JsonValueKind.Object) return null;
|
||||
var job = new TradeJob
|
||||
{
|
||||
Id = Str(r, "id"),
|
||||
Server = Str(r, "server"),
|
||||
Recipient = Str(r, "recipient"),
|
||||
StartedBy = Str(r, "startedBy"),
|
||||
Cancelled = r.TryGetProperty("cancelled", out JsonElement c) && c.ValueKind == JsonValueKind.True,
|
||||
};
|
||||
if (DateTime.TryParse(Str(r, "startedUtc"), CultureInfo.InvariantCulture,
|
||||
DateTimeStyles.RoundtripKind, out DateTime started))
|
||||
job.StartedUtc = started.ToUniversalTime();
|
||||
if (job.Id.Length == 0) return null;
|
||||
if (r.TryGetProperty("items", out JsonElement items) && items.ValueKind == JsonValueKind.Array)
|
||||
{
|
||||
foreach (JsonElement e in items.EnumerateArray())
|
||||
{
|
||||
if (e.ValueKind != JsonValueKind.Object) continue;
|
||||
job.Items.Add(new TradeItem
|
||||
{
|
||||
CharacterKey = Str(e, "characterKey"),
|
||||
CharacterName = Str(e, "character"),
|
||||
Account = Str(e, "account"),
|
||||
Server = Str(e, "server"),
|
||||
ItemName = Str(e, "name"),
|
||||
Wcid = (uint)Long(e, "wcid"),
|
||||
Quantity = (int)Long(e, "qty"),
|
||||
ItemId = (uint)Long(e, "itemId"),
|
||||
});
|
||||
}
|
||||
}
|
||||
return job;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return null; // half-moved or broken: read again next time
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Every account's status file for a job.</summary>
|
||||
public static List<TradeAccountStatus> ReadStatuses(string folder, string id)
|
||||
{
|
||||
var list = new List<TradeAccountStatus>();
|
||||
try
|
||||
{
|
||||
if (!Directory.Exists(folder)) return list;
|
||||
foreach (string path in Directory.GetFiles(folder, id + ".*.status.json"))
|
||||
{
|
||||
TradeAccountStatus? st = ReadStatus(path);
|
||||
if (st != null) list.Add(st);
|
||||
}
|
||||
}
|
||||
catch { }
|
||||
return list;
|
||||
}
|
||||
|
||||
public static TradeAccountStatus? ReadStatus(string folder, string id, string account) =>
|
||||
ReadStatus(StatusPath(folder, id, account));
|
||||
|
||||
private static TradeAccountStatus? ReadStatus(string path)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!File.Exists(path)) return null;
|
||||
using var doc = JsonDocument.Parse(File.ReadAllText(path));
|
||||
JsonElement r = doc.RootElement;
|
||||
if (r.ValueKind != JsonValueKind.Object) return null;
|
||||
var st = new TradeAccountStatus
|
||||
{
|
||||
Account = Str(r, "account"),
|
||||
Character = Str(r, "character"),
|
||||
Message = Str(r, "message"),
|
||||
};
|
||||
if (DateTime.TryParse(Str(r, "updatedUtc"), CultureInfo.InvariantCulture,
|
||||
DateTimeStyles.RoundtripKind, out DateTime updated))
|
||||
st.UpdatedUtc = updated.ToUniversalTime();
|
||||
if (r.TryGetProperty("items", out JsonElement items) && items.ValueKind == JsonValueKind.Array)
|
||||
{
|
||||
foreach (JsonElement e in items.EnumerateArray())
|
||||
{
|
||||
if (e.ValueKind != JsonValueKind.Object) continue;
|
||||
int i = (int)Long(e, "i");
|
||||
if (Enum.TryParse(Str(e, "status"), out TradeItemStatus s))
|
||||
st.Items[i] = (s, Str(e, "text"));
|
||||
}
|
||||
}
|
||||
return st;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private static string Str(JsonElement e, string name) =>
|
||||
e.TryGetProperty(name, out JsonElement v) && v.ValueKind == JsonValueKind.String ? v.GetString() ?? string.Empty : string.Empty;
|
||||
|
||||
private static long Long(JsonElement e, string name) =>
|
||||
e.TryGetProperty(name, out JsonElement v) && v.ValueKind == JsonValueKind.Number && v.TryGetInt64(out long l) ? l : 0;
|
||||
}
|
||||
173
Plugins/RynthCore.Plugin.RynthInventory/Data/TradeList.cs
Normal file
173
Plugins/RynthCore.Plugin.RynthInventory/Data/TradeList.cs
Normal file
|
|
@ -0,0 +1,173 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace RynthCore.Plugin.RynthInventory.Data;
|
||||
|
||||
/// <summary>Status of one item in the trade queue.</summary>
|
||||
internal enum TradeItemStatus
|
||||
{
|
||||
/// <summary>Waiting to be given (not yet attempted).</summary>
|
||||
Pending,
|
||||
/// <summary>GiveObjectTo sent, waiting for confirmation.</summary>
|
||||
Giving,
|
||||
/// <summary>Successfully given to the recipient.</summary>
|
||||
Given,
|
||||
/// <summary>Item not found on the character (moved, consumed or traded).</summary>
|
||||
NotFound,
|
||||
/// <summary>GiveObjectTo failed (target not nearby, API error, etc.).</summary>
|
||||
Failed,
|
||||
}
|
||||
|
||||
/// <summary>One item (or stack) to give to another player.</summary>
|
||||
internal sealed class TradeItem
|
||||
{
|
||||
/// <summary>CharacterSnapshot.Key (server\u001fcharacter, lowercase).</summary>
|
||||
public string CharacterKey = string.Empty;
|
||||
/// <summary>Display name of the character that owns the item.</summary>
|
||||
public string CharacterName = string.Empty;
|
||||
/// <summary>Account name the character belongs to.</summary>
|
||||
public string Account = string.Empty;
|
||||
/// <summary>Server name.</summary>
|
||||
public string Server = string.Empty;
|
||||
/// <summary>Display name of the item.</summary>
|
||||
public string ItemName = string.Empty;
|
||||
/// <summary>Weenie class id (for finding by class if the exact object is gone).</summary>
|
||||
public uint Wcid;
|
||||
/// <summary>How many to give (0 = give the whole object; positive = split this many off a stack).</summary>
|
||||
public int Quantity;
|
||||
/// <summary>The object id at the time it was added (may not exist when the character logs in).</summary>
|
||||
public uint ItemId;
|
||||
/// <summary>Current status.</summary>
|
||||
public TradeItemStatus Status = TradeItemStatus.Pending;
|
||||
/// <summary>A short message for the player (e.g. "not found", "given").</summary>
|
||||
public string StatusText = string.Empty;
|
||||
}
|
||||
|
||||
/// <summary>What the trade list is doing.</summary>
|
||||
internal enum TradePhase
|
||||
{
|
||||
/// <summary>The player is building the list (adding/removing items, typing a name).</summary>
|
||||
Building,
|
||||
/// <summary>Trade is running: giving items on the current character.</summary>
|
||||
Executing,
|
||||
/// <summary>Unused since the shared trade jobs (2026-10-25): each account's client switches itself.</summary>
|
||||
WaitSwitch,
|
||||
/// <summary>All items processed (some may have failed).</summary>
|
||||
Complete,
|
||||
/// <summary>Player cancelled the trade.</summary>
|
||||
Cancelled,
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A list of items to give to another player, built from the Global Inventory window.
|
||||
/// All items must be on the same server. The plugin executes it by giving each item
|
||||
/// via GiveObjectTo when the owning character is logged in.
|
||||
/// </summary>
|
||||
internal sealed class TradeList
|
||||
{
|
||||
/// <summary>The name the player typed as the recipient (resolved to a nearby player id at give time).</summary>
|
||||
public string Recipient = string.Empty;
|
||||
/// <summary>The server all items must be on (set from the first item added).</summary>
|
||||
public string Server = string.Empty;
|
||||
/// <summary>The items to trade.</summary>
|
||||
public readonly List<TradeItem> Items = new();
|
||||
/// <summary>Current phase.</summary>
|
||||
public TradePhase Phase = TradePhase.Building;
|
||||
/// <summary>Status message shown at the top of the trade window.</summary>
|
||||
public string Message = string.Empty;
|
||||
/// <summary>The shared job this list was started as (TradeJobs); empty while building.</summary>
|
||||
public string JobId = string.Empty;
|
||||
public DateTime StartedUtc;
|
||||
/// <summary>One line per giving account (where its client is, what it is doing), from the status files.</summary>
|
||||
public readonly List<string> AccountLines = new();
|
||||
|
||||
/// <summary>Adds an item from an inventory row. Returns null on success, an error message on failure.</summary>
|
||||
public string? Add(InventoryRow row, int quantity)
|
||||
{
|
||||
if (Phase != TradePhase.Building)
|
||||
return "Can't add items while a trade is running.";
|
||||
|
||||
string server = row.Owner.Server;
|
||||
if (Server.Length == 0)
|
||||
Server = server;
|
||||
else if (!InventoryIndex.SameName(Server, server))
|
||||
return $"All items must be from the same server. This list is for {Server}.";
|
||||
|
||||
Items.Add(new TradeItem
|
||||
{
|
||||
CharacterKey = row.Owner.Key,
|
||||
CharacterName = row.Owner.Name,
|
||||
Account = row.Owner.Account,
|
||||
Server = server,
|
||||
ItemName = row.Item.Name,
|
||||
Wcid = row.Item.Wcid,
|
||||
Quantity = quantity,
|
||||
ItemId = row.Item.Id,
|
||||
});
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>Removes the item at <paramref name="index"/>.</summary>
|
||||
public void RemoveAt(int index)
|
||||
{
|
||||
if (index >= 0 && index < Items.Count && Phase == TradePhase.Building)
|
||||
{
|
||||
Items.RemoveAt(index);
|
||||
if (Items.Count == 0) Server = string.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Returns the distinct character keys that still have pending items, grouped.</summary>
|
||||
public List<(string Key, string Name, string Account)> PendingCharacters()
|
||||
{
|
||||
var seen = new HashSet<string>(StringComparer.Ordinal);
|
||||
var result = new List<(string, string, string)>();
|
||||
foreach (TradeItem item in Items)
|
||||
{
|
||||
if (item.Status is TradeItemStatus.Pending or TradeItemStatus.Giving)
|
||||
{
|
||||
if (seen.Add(item.CharacterKey))
|
||||
result.Add((item.CharacterKey, item.CharacterName, item.Account));
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>Items on a specific character that are still pending.</summary>
|
||||
public List<TradeItem> PendingForCharacter(string characterKey)
|
||||
{
|
||||
var result = new List<TradeItem>();
|
||||
foreach (TradeItem item in Items)
|
||||
{
|
||||
if (item.Status == TradeItemStatus.Pending
|
||||
&& string.Equals(item.CharacterKey, characterKey, StringComparison.Ordinal))
|
||||
result.Add(item);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>True when every item has a terminal status (Given, NotFound, Failed).</summary>
|
||||
public bool AllDone()
|
||||
{
|
||||
foreach (TradeItem item in Items)
|
||||
if (item.Status is TradeItemStatus.Pending or TradeItemStatus.Giving) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>Counts by status.</summary>
|
||||
public (int Given, int NotFound, int Failed, int Pending) Counts()
|
||||
{
|
||||
int given = 0, notFound = 0, failed = 0, pending = 0;
|
||||
foreach (TradeItem item in Items)
|
||||
{
|
||||
switch (item.Status)
|
||||
{
|
||||
case TradeItemStatus.Given: given++; break;
|
||||
case TradeItemStatus.NotFound: notFound++; break;
|
||||
case TradeItemStatus.Failed: failed++; break;
|
||||
default: pending++; break;
|
||||
}
|
||||
}
|
||||
return (given, notFound, failed, pending);
|
||||
}
|
||||
}
|
||||
|
|
@ -2,7 +2,7 @@ using RynthCore.Plugin.Shared;
|
|||
|
||||
namespace RynthCore.Plugin.RynthInventory;
|
||||
|
||||
internal enum InventoryVerb { Window, Scan, Keep, Reload, Status, Help, Search }
|
||||
internal enum InventoryVerb { Window, Scan, Keep, Reload, Status, Help, Search, Bank, Trade }
|
||||
|
||||
/// <summary>
|
||||
/// A parsed "/ginv ..." and the lines it answers with (2026-10-28: every command answers,
|
||||
|
|
@ -22,12 +22,16 @@ internal readonly record struct InventoryCommand(InventoryVerb Verb, string Text
|
|||
"reload" => new(InventoryVerb.Reload),
|
||||
"status" => new(InventoryVerb.Status),
|
||||
"help" or "?" => new(InventoryVerb.Help),
|
||||
// The test branch's Banking tab (Infinite Leaftide) and trade list.
|
||||
"bank" or "banking" => new(InventoryVerb.Bank),
|
||||
"trade" => new(InventoryVerb.Trade),
|
||||
_ => new(InventoryVerb.Search, a),
|
||||
};
|
||||
}
|
||||
|
||||
public const string Usage =
|
||||
"/ginv (window), /ginv <text> (search), /ginv scan (rescan and save now), /ginv keep (record the open container as storage), /ginv reload, /ginv status";
|
||||
"/ginv (window), /ginv <text> (search), /ginv trade (trade list), /ginv bank (every character's bank, Infinite Leaftide), /ginv scan (rescan and save now), /ginv keep (record the open container as storage), /ginv reload, /ginv status. "
|
||||
+ "To find items like one you carry, right-click it in the Inventory panel: Find like this in Global Inventory (/ginv like clear removes that filter).";
|
||||
|
||||
public const string NoWindows =
|
||||
"This RynthCore engine can't show plugin windows (it needs script windows, API v71, with ImGui on). Scanning and saving still work; /ginv status shows what was saved.";
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
using System;
|
||||
using RynthCore.Plugin.Shared;
|
||||
using RynthCore.Plugin.RynthInventory.Data;
|
||||
using RynthCore.Plugin.Shared;
|
||||
using RynthCore.PluginSdk;
|
||||
|
|
@ -41,6 +42,24 @@ internal sealed class InventoryContext
|
|||
/// <summary>Forgets a character (moves its file aside). Returns a message for the player.</summary>
|
||||
public Func<CharacterInfo, string> Forget = _ => string.Empty;
|
||||
|
||||
// ── Trade ────────────────────────────────────────────────────────────
|
||||
/// <summary>The active trade list (null when none). Pump thread only.</summary>
|
||||
public TradeList? Trade;
|
||||
/// <summary>Action for trade commands from the trade view ("start", "cancel", "clear", "new").</summary>
|
||||
public Action<string>? TradeCommand;
|
||||
|
||||
/// <summary>
|
||||
/// RynthCore's active server is Infinite Leaftide (EngineServerState.IltId): the Banking page
|
||||
/// (RynthILT's bank) shows and is read only then. Re-read every couple of seconds.
|
||||
/// </summary>
|
||||
public bool Ilt;
|
||||
/// <summary>RynthILT's data interface (the bank).</summary>
|
||||
public readonly RynthIltDataClient IltData = new();
|
||||
/// <summary>The bank as RynthILT last reported it (None off Infinite Leaftide or before the first read).</summary>
|
||||
public IltBankView Bank = IltBankView.None;
|
||||
/// <summary>A Banking page action: a verb line for RynthILT (refresh, deposit, withdraw, transfer).</summary>
|
||||
public Func<string, bool> BankCommand = _ => false;
|
||||
|
||||
/// <summary>
|
||||
/// The plugin's chat lines, queued and written by the tick (Plugins/Shared/CommandReply.cs: the host
|
||||
/// drops a line within 100 ms of another plugin's). Null before Initialize.
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ public static unsafe class PluginExports
|
|||
[UnmanagedCallersOnly(EntryPoint = "RynthPluginVersion", CallConvs = new[] { typeof(CallConvCdecl) })]
|
||||
public static IntPtr GetVersion()
|
||||
{
|
||||
try { return LiteralPointer("0.1.1"u8); }
|
||||
try { return LiteralPointer("0.1.7"u8); } // = RynthInventoryPlugin.Version
|
||||
catch { return IntPtr.Zero; }
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -26,11 +26,15 @@
|
|||
highest API use NOT behind a Has*/version check. Script windows (v71, HasUi) draw the search window and instance ids (v73) fall back to ownership info; below v71 it still scans and saves (/ginv status), as with ImGui off. -->
|
||||
<RynthPluginMinEngineApi>66</RynthPluginMinEngineApi>
|
||||
<RynthPluginDescription>Search every character's items.</RynthPluginDescription>
|
||||
<!-- RynthServers (sibling repo): RynthILT's data interface, read for the Infinite Leaftide Banking page. -->
|
||||
<RynthServersRoot Condition="'$(RynthServersRoot)' == ''">$(MSBuildThisFileDirectory)..\..\..\RynthServers\</RynthServersRoot>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\..\RynthCore\src\RynthCore.PluginCore\RynthCore.PluginCore.csproj" />
|
||||
<ProjectReference Include="..\..\..\RynthCore\src\RynthCore.PluginSdk\RynthCore.PluginSdk.csproj" />
|
||||
<!-- "Find like this in Global Inventory" (/ginv like): the filter spec, its matcher and T11 parsing (2026-10-24). -->
|
||||
<ProjectReference Include="..\..\Shared\RynthCore.LootSdk\RynthCore.LootSdk.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
|
@ -41,6 +45,10 @@
|
|||
<ItemGroup>
|
||||
<!-- Storage another plugin reads for us ("storage" commands: Aelrynth's vault from RynthAelrynth). Also linked by RynthInventory.Tests. -->
|
||||
<Compile Include="..\Shared\StorageFeed.cs" Link="Shared\StorageFeed.cs" />
|
||||
<!-- Which server RynthCore says is active: the Banking page shows on Infinite Leaftide only. -->
|
||||
<Compile Include="..\Shared\EngineServerState.cs" Link="Shared\EngineServerState.cs" />
|
||||
<!-- RynthILT's "RynthILT.Data" interface (RynthServers): the Banking page's balances for every character on the server. -->
|
||||
<Compile Include="$(RynthServersRoot)Plugins\Shared\RynthIltDataApi.cs" Link="Shared\RynthIltDataApi.cs" />
|
||||
<!-- How a chat command answers (2026-10-28): the shared reply queue and colours. -->
|
||||
<Compile Include="..\Shared\CommandReply.cs" Link="Shared\CommandReply.cs" />
|
||||
</ItemGroup>
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
using RynthCore.Plugin.RynthInventory.Data;
|
||||
|
|
@ -29,8 +30,8 @@ namespace RynthCore.Plugin.RynthInventory;
|
|||
/// </summary>
|
||||
public sealed class RynthInventoryPlugin : RynthPluginBase
|
||||
{
|
||||
// Previous release: 0.1.0. Keep in step with PluginExports.GetVersion.
|
||||
public const string Version = "0.1.1";
|
||||
// Previous release: 0.1.6. Keep in step with PluginExports.GetVersion.
|
||||
public const string Version = "0.1.7";
|
||||
|
||||
private const long IdentityRetryMs = 1000;
|
||||
private const long AccountWaitMs = 15_000;
|
||||
|
|
@ -49,6 +50,8 @@ public sealed class RynthInventoryPlugin : RynthPluginBase
|
|||
private readonly UiHost _ui = new();
|
||||
private UiWindow? _window;
|
||||
private InventoryView? _view;
|
||||
private UiWindow? _tradeWindow;
|
||||
private TradeView? _tradeView;
|
||||
private readonly ConcurrentQueue<string> _commands = new();
|
||||
|
||||
// Storage other plugins read for us ("storage" plugin commands, StorageFeed.cs): queued by
|
||||
|
|
@ -58,6 +61,16 @@ public sealed class RynthInventoryPlugin : RynthPluginBase
|
|||
private const int MaxQueuedPushes = 8;
|
||||
private string _lastPush = string.Empty;
|
||||
|
||||
// RynthILT's bank JSON (Infinite Leaftide only): every BankTabReadMs on the Banking tab, every
|
||||
// BankIdleReadMs with the window on another tab, never with it closed or on another server.
|
||||
private const long BankTabReadMs = 2000, BankIdleReadMs = 10_000;
|
||||
private long _nextBankReadMs;
|
||||
private string _bankJson = string.Empty;
|
||||
// RynthCore's server list, read for the Infinite Leaftide gate every ServerStateReadMs.
|
||||
private const long ServerStateReadMs = 2000;
|
||||
private long _nextServerStateMs;
|
||||
private string _serverStateJson = string.Empty;
|
||||
|
||||
private bool _identityKnown;
|
||||
private long _loginMs;
|
||||
private long _nextIdentityTryMs;
|
||||
|
|
@ -92,6 +105,7 @@ public sealed class RynthInventoryPlugin : RynthPluginBase
|
|||
_c.RequestRescan = () => { _scheduler.RequestFullScan(); _forceWrite = true; };
|
||||
_c.RequestReload = () => { _reloadWanted = true; _files.Clear(); };
|
||||
_c.Forget = ForgetCharacter;
|
||||
_c.BankCommand = SendBankVerb;
|
||||
_ui.Log = msg => Host.Log(msg);
|
||||
|
||||
_view = new InventoryView(_c);
|
||||
|
|
@ -103,6 +117,14 @@ public sealed class RynthInventoryPlugin : RynthPluginBase
|
|||
BarButton = false,
|
||||
});
|
||||
|
||||
_tradeView = new TradeView(_c);
|
||||
_tradeWindow = _ui.Add(new UiWindow("RynthInventory/Trade", "Trade List")
|
||||
{
|
||||
DefaultWidth = 400f, DefaultHeight = 500f, MinWidth = 300f, MinHeight = 200f,
|
||||
BarButton = false,
|
||||
});
|
||||
_c.TradeCommand = RunTradeCommand;
|
||||
|
||||
Host.Log($"[RynthInventory] {Version} initialized. /ginv opens the window. Files: {_c.Store.Root}");
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -126,7 +148,68 @@ public sealed class RynthInventoryPlugin : RynthPluginBase
|
|||
_carriedIds.Clear();
|
||||
_carriedPacks.Clear();
|
||||
RefreshIconSupport();
|
||||
ClearBank();
|
||||
_nextServerStateMs = 0;
|
||||
if (_window != null) { _window.Visible = _c.Settings.MainWindowOpen; _window.NeedsPass = true; }
|
||||
// Trade: this character's part of a running trade is picked up by TickTrade.
|
||||
if (_tradeWindow != null) _tradeWindow.NeedsPass = true;
|
||||
}
|
||||
|
||||
/// <summary>Forgets the last bank read (login, logout, off Infinite Leaftide): the next comes fresh.</summary>
|
||||
private void ClearBank()
|
||||
{
|
||||
_c.Bank = IltBankView.None;
|
||||
_bankJson = string.Empty;
|
||||
_nextBankReadMs = 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Whether RynthCore's active server is Infinite Leaftide (the Banking page's gate), from the
|
||||
/// engine's server list. Leaving it drops the bank and moves the window off the Banking tab.
|
||||
/// </summary>
|
||||
private void TickServer(long now)
|
||||
{
|
||||
if (now < _nextServerStateMs) return;
|
||||
_nextServerStateMs = now + ServerStateReadMs;
|
||||
string json = _c.InWorld && Host.HasGetServerStateJson && Host.TryGetServerStateJson(out string j) ? j : string.Empty;
|
||||
if (string.Equals(json, _serverStateJson, StringComparison.Ordinal)) return;
|
||||
_serverStateJson = json;
|
||||
bool ilt = EngineServerState.Parse(json)?.IsActive(EngineServerState.IltId) == true;
|
||||
if (ilt == _c.Ilt) return;
|
||||
_c.Ilt = ilt;
|
||||
_scanner.Ilt = ilt; // T11 attributes are read only on Leaftide (2026-11-07)
|
||||
if (!ilt)
|
||||
{
|
||||
ClearBank();
|
||||
_view?.LeaveBanking();
|
||||
}
|
||||
if (_window != null) _window.NeedsPass = true;
|
||||
}
|
||||
|
||||
/// <summary>The Banking tab's actions: a verb line for RynthILT, then a quick re-read for its reply.</summary>
|
||||
private bool SendBankVerb(string verb)
|
||||
{
|
||||
long now = Environment.TickCount64;
|
||||
bool ok = _c.InWorld && _c.Ilt && _c.IltData.BankCommand(Host, now, verb);
|
||||
_nextBankReadMs = now + 500;
|
||||
if (_window != null) _window.NeedsPass = true;
|
||||
return ok;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// On Infinite Leaftide: reads RynthILT's bank JSON while the window is open (more often on the
|
||||
/// Banking tab) and redraws when it changed. Reading is what tells RynthILT someone is looking.
|
||||
/// </summary>
|
||||
private void TickBank(long now)
|
||||
{
|
||||
if (!_c.InWorld || !_c.Ilt || _window == null || _view == null || !_window.Visible) return;
|
||||
if (now < _nextBankReadMs) return;
|
||||
_nextBankReadMs = now + (_view.Tab == InventoryView.TabBanking ? BankTabReadMs : BankIdleReadMs);
|
||||
string json = _c.IltData.ReadBank(Host, now);
|
||||
if (string.Equals(json, _bankJson, StringComparison.Ordinal)) return;
|
||||
_bankJson = json;
|
||||
_c.Bank = IltBankView.Parse(json);
|
||||
_window.NeedsPass = true;
|
||||
}
|
||||
|
||||
public override void OnLogout()
|
||||
|
|
@ -138,10 +221,16 @@ public sealed class RynthInventoryPlugin : RynthPluginBase
|
|||
_scheduler.Logout();
|
||||
CloseStorage();
|
||||
if (_window != null) { _window.Visible = false; _window.NeedsPass = true; }
|
||||
// Trade window stays visible across logout so the player can see what's left.
|
||||
if (_tradeWindow != null) _tradeWindow.NeedsPass = true;
|
||||
_ui.SubmitEmpty(Host);
|
||||
_c.Live = null;
|
||||
_indexDirty = true;
|
||||
while (_storagePushes.TryDequeue(out _)) { } // the next character's come fresh
|
||||
ClearBank();
|
||||
_c.Ilt = false;
|
||||
_serverStateJson = string.Empty;
|
||||
_view?.LeaveBanking();
|
||||
_lastPush = string.Empty;
|
||||
}
|
||||
|
||||
|
|
@ -216,6 +305,25 @@ public sealed class RynthInventoryPlugin : RynthPluginBase
|
|||
|
||||
private void RunCommand(string arg)
|
||||
{
|
||||
// "Find like this in Global Inventory" (the Inventory panel's right-click): the rule as a spec.
|
||||
if (arg.StartsWith("like ", StringComparison.OrdinalIgnoreCase) || arg.Equals("like", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
string spec = arg.Length > 4 ? arg.Substring(4).Trim() : string.Empty;
|
||||
if (spec.Length == 0 || spec.Equals("clear", StringComparison.OrdinalIgnoreCase) || spec.Equals("off", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
_view?.SetLike(null);
|
||||
return;
|
||||
}
|
||||
Views.LikeFilter? like = Views.LikeFilter.Parse(spec, out string error);
|
||||
if (like == null)
|
||||
{
|
||||
_c.Print(error + " (Right-click an item in the Inventory panel: Find like this in Global Inventory.)");
|
||||
return;
|
||||
}
|
||||
_view?.SetLike(like);
|
||||
if (_window != null) { _window.Visible = true; _window.NeedsPass = true; }
|
||||
return;
|
||||
}
|
||||
// Every /ginv answers in chat (2026-10-28, InventoryCommand.cs; Plugins/Shared/CommandReply.cs).
|
||||
// RynthInventory can't tell a typed /ginv from a meta's, so each one does.
|
||||
InventoryCommand c = InventoryCommand.Parse(arg);
|
||||
|
|
@ -244,6 +352,23 @@ public sealed class RynthInventoryPlugin : RynthPluginBase
|
|||
case InventoryVerb.Status:
|
||||
PrintStatus();
|
||||
break;
|
||||
case InventoryVerb.Bank:
|
||||
// The Banking tab: every character's Infinite Leaftide bank (RynthILT), Infinite Leaftide only.
|
||||
if (!_c.Ilt)
|
||||
{
|
||||
_c.Print("The bank is an Infinite Leaftide feature; the active server isn't Infinite Leaftide.");
|
||||
break;
|
||||
}
|
||||
_view?.ShowBanking();
|
||||
_nextBankReadMs = 0;
|
||||
if (_window != null) { _window.Visible = true; _window.NeedsPass = true; }
|
||||
break;
|
||||
case InventoryVerb.Trade:
|
||||
// Toggle the trade list window and start a new trade if none is active.
|
||||
if (_c.Trade == null)
|
||||
_c.Trade = new TradeList();
|
||||
if (_tradeWindow != null) { _tradeWindow.Visible = !_tradeWindow.Visible; _tradeWindow.NeedsPass = true; }
|
||||
break;
|
||||
case InventoryVerb.Help:
|
||||
_c.Print(InventoryCommand.Usage);
|
||||
break;
|
||||
|
|
@ -313,9 +438,14 @@ public sealed class RynthInventoryPlugin : RynthPluginBase
|
|||
}
|
||||
TickWrite(now);
|
||||
TickIndex(now);
|
||||
TickServer(now);
|
||||
TickBank(now);
|
||||
TickTrade(now);
|
||||
|
||||
if (!Host.HasUi || _window == null || _view == null) return;
|
||||
Record(_window, now, 2000, _view.Draw);
|
||||
if (_tradeWindow != null && _tradeView != null && _tradeWindow.Visible)
|
||||
Record(_tradeWindow, now, 1000, _tradeView.Draw);
|
||||
_ui.Submit(Host, now);
|
||||
|
||||
if (_c.InWorld && _window.Visible != _c.Settings.MainWindowOpen)
|
||||
|
|
@ -728,4 +858,379 @@ public sealed class RynthInventoryPlugin : RynthPluginBase
|
|||
}
|
||||
|
||||
private int _lastDrawnRevision = -1;
|
||||
|
||||
// ── Trade execution ────────────────────────────────────────────────
|
||||
// A started trade is a shared job (Data/TradeJobs.cs), because every account plays in its
|
||||
// own client: the client that built the list writes the job; every client (that one too)
|
||||
// gives the items of the account it is logged into, logging that account onto the
|
||||
// character that holds them (/rc switchchar, RynthCore 2026.10.25+), and writes how each
|
||||
// went. The client that started the trade reads every account's status back into its list.
|
||||
|
||||
private const long TradeTickMs = 1000;
|
||||
private const long TradeGiveIntervalMs = 1500;
|
||||
/// <summary>After a login the pack scan has to land before items can be found.</summary>
|
||||
private const long TradeLoginSettleMs = 5000;
|
||||
private const long TradeRecipientRetryMs = 5000;
|
||||
/// <summary>A switch that didn't happen (old engine, char-select trouble) is asked for again after this.</summary>
|
||||
private const long TradeSwitchRetryMs = 60_000;
|
||||
private const long TradeHeartbeatMs = 10_000;
|
||||
private static readonly TimeSpan TradeStaleStatus = TimeSpan.FromSeconds(30);
|
||||
private static readonly TimeSpan TradeNoClientGrace = TimeSpan.FromSeconds(15);
|
||||
|
||||
private long _nextTradeTickMs;
|
||||
private long _nextTradeGiveMs;
|
||||
private long _lastSwitchRequestMs;
|
||||
private string _lastSwitchTarget = string.Empty;
|
||||
private long _lastTradeStatusWriteMs;
|
||||
// The job this client is giving for and its own report on it (this client is its only writer).
|
||||
private string _givingJobId = string.Empty;
|
||||
private TradeAccountStatus? _givingStatus;
|
||||
|
||||
private string TradeFolder => TradeJobs.Folder(_c.Store.Root);
|
||||
|
||||
private void RunTradeCommand(string cmd)
|
||||
{
|
||||
switch (cmd)
|
||||
{
|
||||
case "start":
|
||||
StartTrade();
|
||||
break;
|
||||
case "cancel":
|
||||
CancelTrade();
|
||||
break;
|
||||
case "clear":
|
||||
case "new":
|
||||
if (_c.Trade != null && _c.Trade.JobId.Length > 0 && _c.Trade.Phase != TradePhase.Executing)
|
||||
TradeJobs.Delete(TradeFolder, _c.Trade.JobId);
|
||||
_c.Trade = new TradeList();
|
||||
if (_tradeWindow != null) _tradeWindow.NeedsPass = true;
|
||||
break;
|
||||
case "toggle":
|
||||
if (_c.Trade == null)
|
||||
_c.Trade = new TradeList();
|
||||
if (_tradeWindow != null) { _tradeWindow.Visible = !_tradeWindow.Visible; _tradeWindow.NeedsPass = true; }
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void StartTrade()
|
||||
{
|
||||
TradeList? trade = _c.Trade;
|
||||
if (trade == null || trade.Items.Count == 0) return;
|
||||
string recipient = trade.Recipient.Trim();
|
||||
if (recipient.Length == 0)
|
||||
{
|
||||
trade.Message = "Enter a player name to send items to.";
|
||||
if (_tradeWindow != null) _tradeWindow.NeedsPass = true;
|
||||
return;
|
||||
}
|
||||
if (!_c.Host.HasGiveObjectTo)
|
||||
{
|
||||
trade.Message = "This engine doesn't support GiveObjectTo (needs API v62+).";
|
||||
if (_tradeWindow != null) _tradeWindow.NeedsPass = true;
|
||||
return;
|
||||
}
|
||||
|
||||
var job = new TradeJob
|
||||
{
|
||||
Id = TradeJobs.NewId(),
|
||||
Server = trade.Server,
|
||||
Recipient = recipient,
|
||||
StartedBy = _c.Character.Length > 0 ? $"{_c.Character} ({_c.Account})" : _c.Account,
|
||||
StartedUtc = DateTime.UtcNow,
|
||||
};
|
||||
foreach (TradeItem item in trade.Items)
|
||||
{
|
||||
item.Status = TradeItemStatus.Pending;
|
||||
item.StatusText = string.Empty;
|
||||
job.Items.Add(item);
|
||||
}
|
||||
try { TradeJobs.WriteJob(TradeFolder, job); }
|
||||
catch (Exception ex)
|
||||
{
|
||||
trade.Message = "Couldn't write the trade file: " + ex.Message;
|
||||
if (_tradeWindow != null) _tradeWindow.NeedsPass = true;
|
||||
return;
|
||||
}
|
||||
|
||||
trade.JobId = job.Id;
|
||||
trade.StartedUtc = job.StartedUtc;
|
||||
trade.Phase = TradePhase.Executing;
|
||||
trade.Message = $"Trade started. Each account's client logs onto the character holding the items and gives them to {recipient}: {recipient} has to stand next to where each of those characters logs in.";
|
||||
_nextTradeTickMs = 0;
|
||||
if (_tradeWindow != null) { _tradeWindow.Visible = true; _tradeWindow.NeedsPass = true; }
|
||||
_c.Print($"Trade started: {trade.Items.Count} item(s) to {recipient}.");
|
||||
}
|
||||
|
||||
private void CancelTrade()
|
||||
{
|
||||
TradeList? trade = _c.Trade;
|
||||
if (trade == null) return;
|
||||
if (trade.JobId.Length > 0)
|
||||
{
|
||||
TradeJob? job = TradeJobs.ReadJob(TradeFolder, trade.JobId);
|
||||
if (job != null && !job.Cancelled)
|
||||
{
|
||||
job.Cancelled = true;
|
||||
try { TradeJobs.WriteJob(TradeFolder, job); } catch { }
|
||||
}
|
||||
}
|
||||
trade.Phase = TradePhase.Cancelled;
|
||||
trade.Message = "Trade cancelled.";
|
||||
if (_tradeWindow != null) _tradeWindow.NeedsPass = true;
|
||||
}
|
||||
|
||||
private void TickTrade(long now)
|
||||
{
|
||||
if (now < _nextTradeTickMs) return;
|
||||
_nextTradeTickMs = now + TradeTickMs;
|
||||
try { TickTradeGiver(now); }
|
||||
catch (Exception ex) { Host.Log($"[RynthInventory] trade giver failed: {ex.GetType().Name}: {ex.Message}"); }
|
||||
try { MergeTradeStatus(); }
|
||||
catch (Exception ex) { Host.Log($"[RynthInventory] trade status read failed: {ex.GetType().Name}: {ex.Message}"); }
|
||||
}
|
||||
|
||||
/// <summary>The client that started the trade: every account's status file into its list.</summary>
|
||||
private void MergeTradeStatus()
|
||||
{
|
||||
TradeList? trade = _c.Trade;
|
||||
if (trade == null || trade.JobId.Length == 0 || trade.Phase == TradePhase.Building) return;
|
||||
|
||||
List<TradeAccountStatus> statuses = TradeJobs.ReadStatuses(TradeFolder, trade.JobId);
|
||||
for (int i = 0; i < trade.Items.Count; i++)
|
||||
{
|
||||
TradeItem item = trade.Items[i];
|
||||
foreach (TradeAccountStatus st in statuses)
|
||||
{
|
||||
if (!TradeJobs.SameAccount(st.Account, item.Account)) continue;
|
||||
if (st.Items.TryGetValue(i, out var v)) { item.Status = v.Status; item.StatusText = v.Text; }
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
trade.AccountLines.Clear();
|
||||
var accounts = new List<string>();
|
||||
foreach (TradeItem item in trade.Items)
|
||||
if (!accounts.Exists(a => TradeJobs.SameAccount(a, item.Account))) accounts.Add(item.Account);
|
||||
foreach (string account in accounts)
|
||||
{
|
||||
bool accountDone = trade.Items.TrueForAll(it => !TradeJobs.SameAccount(it.Account, account)
|
||||
|| it.Status is not (TradeItemStatus.Pending or TradeItemStatus.Giving));
|
||||
TradeAccountStatus? st = statuses.Find(s => TradeJobs.SameAccount(s.Account, account));
|
||||
string line;
|
||||
if (st == null)
|
||||
line = DateTime.UtcNow - trade.StartedUtc > TradeNoClientGrace
|
||||
? $"{account}: no client logged into this account has picked it up (is one running with RynthInventory?)"
|
||||
: $"{account}: waiting for its client...";
|
||||
else
|
||||
{
|
||||
line = $"{account}: " + (st.Character.Length > 0 ? st.Character + " - " : "") + st.Message;
|
||||
if (!accountDone && DateTime.UtcNow - st.UpdatedUtc > TradeStaleStatus)
|
||||
line += " (its client has gone quiet - logging in, or closed?)";
|
||||
}
|
||||
trade.AccountLines.Add(line);
|
||||
}
|
||||
|
||||
if (trade.Phase == TradePhase.Executing && trade.AllDone())
|
||||
{
|
||||
trade.Phase = TradePhase.Complete;
|
||||
var (given, notFound, failed, _) = trade.Counts();
|
||||
trade.Message = $"Trade complete: {given} given" +
|
||||
(notFound > 0 ? $", {notFound} not found" : "") +
|
||||
(failed > 0 ? $", {failed} failed" : "") + ".";
|
||||
_c.Print(trade.Message);
|
||||
}
|
||||
if (_tradeWindow != null) _tradeWindow.NeedsPass = true;
|
||||
}
|
||||
|
||||
/// <summary>Every client: gives the items of the account it is logged into.</summary>
|
||||
private void TickTradeGiver(long now)
|
||||
{
|
||||
if (!_c.InWorld || !_identityKnown || _c.Account.Length == 0 || _c.Account == "unknown") return;
|
||||
if (now - _loginMs < TradeLoginSettleMs) return;
|
||||
|
||||
List<TradeJob> jobs = TradeJobs.ReadJobs(TradeFolder, _c.Server);
|
||||
foreach (TradeJob job in jobs)
|
||||
{
|
||||
var mine = new List<int>();
|
||||
for (int i = 0; i < job.Items.Count; i++)
|
||||
if (TradeJobs.SameAccount(job.Items[i].Account, _c.Account)) mine.Add(i);
|
||||
if (mine.Count == 0) continue;
|
||||
|
||||
TradeAccountStatus st = GivingStatusFor(job.Id);
|
||||
var pending = mine.FindAll(i => !st.Items.TryGetValue(i, out var v) || v.Status is TradeItemStatus.Pending or TradeItemStatus.Giving);
|
||||
if (pending.Count == 0)
|
||||
{
|
||||
int given = mine.FindAll(i => st.Items[i].Status == TradeItemStatus.Given).Count;
|
||||
string done = $"done: {given} of {mine.Count} given.";
|
||||
if (!string.Equals(st.Message, done, StringComparison.Ordinal)) SetTradeStatus(job.Id, st, done, now, force: true);
|
||||
continue;
|
||||
}
|
||||
if (job.Cancelled)
|
||||
{
|
||||
if (!string.Equals(st.Message, "trade cancelled.", StringComparison.Ordinal)) SetTradeStatus(job.Id, st, "trade cancelled.", now, force: true);
|
||||
continue;
|
||||
}
|
||||
GiveForJob(job, st, pending, now);
|
||||
return; // one job at a time, oldest first
|
||||
}
|
||||
}
|
||||
|
||||
private TradeAccountStatus GivingStatusFor(string jobId)
|
||||
{
|
||||
if (_givingStatus != null && string.Equals(_givingJobId, jobId, StringComparison.Ordinal))
|
||||
return _givingStatus;
|
||||
_givingJobId = jobId;
|
||||
_givingStatus = TradeJobs.ReadStatus(TradeFolder, jobId, _c.Account) ?? new TradeAccountStatus { Account = _c.Account };
|
||||
_givingStatus.Account = _c.Account;
|
||||
_lastTradeStatusWriteMs = 0;
|
||||
return _givingStatus;
|
||||
}
|
||||
|
||||
private void GiveForJob(TradeJob job, TradeAccountStatus st, List<int> pending, long now)
|
||||
{
|
||||
// This account's only character online can't be someone else at the same time: when it is
|
||||
// the recipient, the items on its other characters can't be given from here.
|
||||
if (InventoryIndex.SameName(job.Recipient, _c.Character))
|
||||
{
|
||||
foreach (int i in pending)
|
||||
st.Items[i] = (TradeItemStatus.Failed, $"on {job.Items[i].CharacterName}, the recipient's own account (only one of its characters can be online)");
|
||||
SetTradeStatus(job.Id, st, "the recipient's account: these items can't be given while it is logged in.", now, force: true);
|
||||
return;
|
||||
}
|
||||
|
||||
string myKey = CharacterSnapshot.MakeKey(_c.Server, _c.Character);
|
||||
List<int> here = pending.FindAll(i => string.Equals(job.Items[i].CharacterKey, myKey, StringComparison.Ordinal));
|
||||
if (here.Count > 0)
|
||||
{
|
||||
if (now < _nextTradeGiveMs) { SetTradeStatus(job.Id, st, st.Message, now, force: false); return; }
|
||||
|
||||
uint target = ResolvePlayerByName(job.Recipient);
|
||||
if (target == 0)
|
||||
{
|
||||
_nextTradeGiveMs = now + TradeRecipientRetryMs;
|
||||
SetTradeStatus(job.Id, st, $"waiting for {job.Recipient} to come near {_c.Character} ({here.Count} item(s) to give).", now, force: false);
|
||||
return;
|
||||
}
|
||||
|
||||
int idx = here[0];
|
||||
TradeItem item = job.Items[idx];
|
||||
uint objId = FindItemOnCharacter(item);
|
||||
if (objId == 0)
|
||||
st.Items[idx] = (TradeItemStatus.NotFound, $"not found on {_c.Character}");
|
||||
else if (_c.Host.GiveObjectTo(objId, target, item.Quantity))
|
||||
{
|
||||
st.Items[idx] = (TradeItemStatus.Given, "given");
|
||||
_c.Print($"Trade: gave {item.ItemName}{(item.Quantity > 0 ? " x" + item.Quantity.ToString(CultureInfo.InvariantCulture) : "")} to {job.Recipient}.");
|
||||
}
|
||||
else
|
||||
st.Items[idx] = (TradeItemStatus.Failed, "the give was refused");
|
||||
_nextTradeGiveMs = now + TradeGiveIntervalMs;
|
||||
SetTradeStatus(job.Id, st, $"giving to {job.Recipient} ({here.Count - 1} left on {_c.Character}).", now, force: true);
|
||||
return;
|
||||
}
|
||||
|
||||
// The rest are on another character of this account: log onto it.
|
||||
TradeItem next = job.Items[pending[0]];
|
||||
bool sameTarget = InventoryIndex.SameName(_lastSwitchTarget, next.CharacterName);
|
||||
if (sameTarget && now - _lastSwitchRequestMs < TradeSwitchRetryMs)
|
||||
{
|
||||
SetTradeStatus(job.Id, st, st.Message, now, force: false);
|
||||
return;
|
||||
}
|
||||
if (sameTarget && _lastSwitchRequestMs != 0)
|
||||
Host.Log($"[RynthInventory] trade: still not on {next.CharacterName} {TradeSwitchRetryMs / 1000}s after asking; asking again.");
|
||||
_lastSwitchTarget = next.CharacterName;
|
||||
_lastSwitchRequestMs = now;
|
||||
SetTradeStatus(job.Id, st, $"logging onto {next.CharacterName} to give its items.", now, force: true);
|
||||
_c.Print($"Trade: logging {_c.Account} onto {next.CharacterName} to give its items to {job.Recipient}.");
|
||||
if (_c.Host.HasInvokeChatParser)
|
||||
_c.Host.InvokeChatParser("/rc switchchar " + next.CharacterName);
|
||||
}
|
||||
|
||||
/// <summary>Writes this account's status file when something changed (or as a heartbeat).</summary>
|
||||
private void SetTradeStatus(string jobId, TradeAccountStatus st, string message, long now, bool force)
|
||||
{
|
||||
bool changed = force || !string.Equals(st.Message, message, StringComparison.Ordinal)
|
||||
|| !string.Equals(st.Character, _c.Character, StringComparison.Ordinal);
|
||||
if (!changed && now - _lastTradeStatusWriteMs < TradeHeartbeatMs) return;
|
||||
st.Message = message;
|
||||
st.Character = _c.Character;
|
||||
st.UpdatedUtc = DateTime.UtcNow;
|
||||
try
|
||||
{
|
||||
TradeJobs.WriteStatus(TradeFolder, jobId, st);
|
||||
_lastTradeStatusWriteMs = now;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Host.Log($"[RynthInventory] trade status write failed: {ex.Message}");
|
||||
_lastTradeStatusWriteMs = now; // try again at the next heartbeat, not every tick
|
||||
}
|
||||
}
|
||||
|
||||
private const uint BitfieldPlayer = 0x00000008;
|
||||
|
||||
/// <summary>
|
||||
/// Resolves a player name to a nearby object id. Searches the live objects for a player
|
||||
/// whose name matches (case-insensitive).
|
||||
/// </summary>
|
||||
private uint ResolvePlayerByName(string name)
|
||||
{
|
||||
if (!Host.HasGetLiveObjectIds) return 0;
|
||||
uint[] ids = Host.GetLiveObjectIds();
|
||||
string trimmed = name.Trim();
|
||||
foreach (uint id in ids)
|
||||
{
|
||||
if (id == _c.Player) continue;
|
||||
if (!Host.TryGetObjectBitfield(id, out uint bf) || (bf & BitfieldPlayer) == 0) continue;
|
||||
if (Host.TryGetObjectName(id, out string objName)
|
||||
&& string.Equals(objName, trimmed, StringComparison.OrdinalIgnoreCase))
|
||||
return id;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Finds an item on the current character matching a trade item (by object id first, then by
|
||||
/// wcid + name). Returns 0 if not found.
|
||||
/// </summary>
|
||||
private uint FindItemOnCharacter(TradeItem item)
|
||||
{
|
||||
if (_c.Player == 0) return 0;
|
||||
// First, try the exact object id.
|
||||
if (item.ItemId != 0 && Host.TryGetObjectName(item.ItemId, out _))
|
||||
{
|
||||
if (Host.TryGetObjectOwnershipInfo(item.ItemId, out uint container, out uint wielder, out _)
|
||||
&& (container == _c.Player || wielder == _c.Player || IsCarriedPack(container)))
|
||||
return item.ItemId;
|
||||
}
|
||||
// Fall back to scanning inventory for matching wcid + name.
|
||||
if (item.Wcid == 0) return 0;
|
||||
if (!Host.HasGetContainerContents) return 0;
|
||||
uint found = FindItemInContainer(_c.Player, item);
|
||||
if (found != 0) return found;
|
||||
// Check carried containers (packs).
|
||||
foreach (uint packId in _carriedPacks)
|
||||
{
|
||||
found = FindItemInContainer(packId, item);
|
||||
if (found != 0) return found;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
private uint FindItemInContainer(uint containerId, TradeItem item)
|
||||
{
|
||||
uint[] buf = new uint[256];
|
||||
int count = Host.GetContainerContents(containerId, buf);
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
uint id = buf[i];
|
||||
if (Host.TryGetObjectWcid(id, out uint wcid) && wcid == item.Wcid
|
||||
&& Host.TryGetObjectName(id, out string name)
|
||||
&& string.Equals(name, item.ItemName, StringComparison.OrdinalIgnoreCase))
|
||||
return id;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,9 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using RynthCore.Loot;
|
||||
using RynthCore.Loot.Editing;
|
||||
using RynthCore.Loot.T11;
|
||||
using RynthCore.Plugin.RynthInventory.Data;
|
||||
using RynthCore.PluginSdk;
|
||||
|
||||
|
|
@ -18,6 +21,12 @@ namespace RynthCore.Plugin.RynthInventory.Scanning;
|
|||
/// </summary>
|
||||
internal sealed class InventoryScanner
|
||||
{
|
||||
/// <summary>
|
||||
/// On Infinite Leaftide (2026-11-07, "make sure all t11 attributes stuff is gated behind infinite
|
||||
/// leaftide"): only there is an item's text read for T11 attributes.
|
||||
/// </summary>
|
||||
public bool Ilt { get; set; }
|
||||
|
||||
// STypeInt
|
||||
private const uint StackSize = 12, MaxStackSize = 11, Value = 19, EncumbranceVal = 5, ItemsCapacity = 6,
|
||||
CurrentWieldedLocation = 10, MaterialType = 131, ItemWorkmanship = 105, ArmorLevel = 28,
|
||||
|
|
@ -35,12 +44,26 @@ internal sealed class InventoryScanner
|
|||
private readonly uint[] _contents = new uint[MaxContents];
|
||||
private readonly uint[] _spellBuf = new uint[64];
|
||||
private readonly Dictionary<uint, bool> _isPack = new();
|
||||
// T11 parses by item, redone only when the item's text changes (the periodic scan reads every item).
|
||||
private readonly Dictionary<uint, T11Entry> _t11 = new();
|
||||
|
||||
private sealed class T11Entry
|
||||
{
|
||||
public string Name = string.Empty, LongDesc = string.Empty, Use = string.Empty;
|
||||
public T11ServerProps Server;
|
||||
public T11ItemInfo Info = T11ItemInfo.None;
|
||||
}
|
||||
|
||||
// STypeInt / STypeString the facts need beyond the record's own fields.
|
||||
private const uint ValidLocations = 9, WeaponSkill = 48;
|
||||
private const uint StrName = 1, StrUse = 14, StrLongDesc = 16;
|
||||
|
||||
public bool Warmed;
|
||||
|
||||
public void Reset()
|
||||
{
|
||||
_isPack.Clear();
|
||||
_t11.Clear();
|
||||
Warmed = false;
|
||||
}
|
||||
|
||||
|
|
@ -229,9 +252,75 @@ internal sealed class InventoryScanner
|
|||
it.SpellNames = new string[it.Spells.Length];
|
||||
for (int i = 0; i < it.Spells.Length; i++) it.SpellNames[i] = SpellTable.Name(it.Spells[i]);
|
||||
}
|
||||
ReadFacts(host, id, it);
|
||||
return it;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// What a "like this" rule tests (2026-10-24, /ginv like): the item's class as RynthAi
|
||||
/// classifies it, every int and float property the Add to loot profile checklist offers, and
|
||||
/// for T11 gear its virtual T11 keys and the wield / rating values its appraisal strips.
|
||||
/// </summary>
|
||||
private void ReadFacts(RynthCoreHost host, uint id, ItemRecord it)
|
||||
{
|
||||
it.HasFacts = true;
|
||||
host.TryGetObjectIntProperty(id, ValidLocations, out int slots);
|
||||
host.TryGetObjectIntProperty(id, WeaponSkill, out int skill);
|
||||
bool spellDid = host.HasGetObjectDataIdProperty
|
||||
&& host.TryGetObjectDataIdProperty(id, DidSpell, out uint did) && did != 0;
|
||||
it.ObjectClass = (int)AcItemClassifier.Classify(it.ItemType, it.Name, spellDid, slots, skill);
|
||||
|
||||
var ints = new Dictionary<int, int>();
|
||||
foreach (int key in LootItemAttributes.IntKeys)
|
||||
if (host.TryGetObjectIntProperty(id, unchecked((uint)key), out int v) && v != 0) ints[key] = v;
|
||||
if (host.HasGetObjectDoubleProperty)
|
||||
{
|
||||
var doubles = new Dictionary<int, double>();
|
||||
foreach (int key in LootItemAttributes.DoubleKeys)
|
||||
if (host.TryGetObjectDoubleProperty(id, unchecked((uint)key), out double v) && v != 0 && double.IsFinite(v)) doubles[key] = v;
|
||||
if (doubles.Count > 0) it.Doubles = doubles;
|
||||
}
|
||||
|
||||
T11ItemInfo t = Ilt ? T11Of(host, id, it.Name) : T11ItemInfo.None;
|
||||
if (t.IsT11)
|
||||
{
|
||||
foreach (var (key, _) in T11Keys.Names())
|
||||
{
|
||||
if (key == T11Keys.CanWield) continue; // depends on the character looking
|
||||
if (T11Keys.TryGetValue(t, key, null, out int v) && v != 0) ints[key] = v;
|
||||
}
|
||||
foreach (int key in LootItemAttributes.IntKeys)
|
||||
if (T11Keys.IsStrippedKey(key) && !ints.ContainsKey(key) && T11Keys.TryGetStrippedValue(t, key, out int v) && v != 0)
|
||||
ints[key] = v;
|
||||
}
|
||||
if (ints.Count > 0) it.Ints = ints;
|
||||
}
|
||||
|
||||
/// <summary>The item's T11 reading (None for other items); only T11-named or T11-stamped items are parsed.</summary>
|
||||
private T11ItemInfo T11Of(RynthCoreHost host, uint id, string name)
|
||||
{
|
||||
host.TryGetObjectIntProperty(id, (uint)T11Catalog.PropZcTier, out int zc);
|
||||
host.TryGetObjectIntProperty(id, (uint)T11Catalog.PropWeaponAugScaleTier, out int wt);
|
||||
if (!host.TryGetObjectIntProperty(id, (uint)T11Catalog.PropWeaponAugScaleQuality, out int wq)) wq = -1;
|
||||
var server = new T11ServerProps(zc, wt, wq);
|
||||
if (!name.StartsWith(T11Catalog.NamePrefix, StringComparison.Ordinal) && server.Tier < T11Catalog.MinTier)
|
||||
return T11ItemInfo.None;
|
||||
string desc = string.Empty, use = string.Empty;
|
||||
if (host.HasGetObjectStringProperty)
|
||||
{
|
||||
host.TryGetObjectStringProperty(id, StrLongDesc, out desc);
|
||||
host.TryGetObjectStringProperty(id, StrUse, out use);
|
||||
}
|
||||
if (_t11.TryGetValue(id, out T11Entry? e) && e.Name == name && e.LongDesc == desc && e.Use == use && e.Server == server)
|
||||
return e.Info;
|
||||
if (_t11.Count > 4096) _t11.Clear();
|
||||
T11ItemInfo info;
|
||||
try { info = T11ItemInfo.Parse(name, desc, use, server); }
|
||||
catch (Exception) { info = T11ItemInfo.None; }
|
||||
_t11[id] = new T11Entry { Name = name, LongDesc = desc ?? string.Empty, Use = use ?? string.Empty, Server = server, Info = info };
|
||||
return info;
|
||||
}
|
||||
|
||||
// ── Storage ─────────────────────────────────────────────────────────────
|
||||
|
||||
/// <summary>Whether an opened container counts as storage worth remembering.</summary>
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ using System.Reflection;
|
|||
|
||||
namespace RynthCore.Plugin.RynthInventory.Scanning;
|
||||
|
||||
internal readonly record struct SpellInfo(string Name, double Duration, bool IsDebuff);
|
||||
internal readonly record struct SpellInfo(string Name, double Duration, bool IsDebuff, int Family = 0, int Power = 0);
|
||||
|
||||
/// <summary>
|
||||
/// Spell names and base durations from RynthAi's embedded spell table (SpellData.txt, linked
|
||||
|
|
@ -25,6 +25,15 @@ internal static class SpellTable
|
|||
|
||||
public static string Name(uint id) => TryGet(id, out SpellInfo s) ? s.Name : $"Spell {id}";
|
||||
|
||||
/// <summary>Every spell in the table with its family and power (Global Inventory's filter spell lists).</summary>
|
||||
public static List<RynthCore.Loot.Editing.LootSpellEntry> AllSpells()
|
||||
{
|
||||
EnsureLoaded();
|
||||
var list = new List<RynthCore.Loot.Editing.LootSpellEntry>(_spells!.Count);
|
||||
foreach (SpellInfo s in _spells.Values) list.Add(new RynthCore.Loot.Editing.LootSpellEntry(s.Name, s.Family, s.Power));
|
||||
return list;
|
||||
}
|
||||
|
||||
public static int Count
|
||||
{
|
||||
get { EnsureLoaded(); return _spells!.Count; }
|
||||
|
|
@ -46,7 +55,9 @@ internal static class SpellTable
|
|||
if (c.Length < 2 || !uint.TryParse(c[0].Trim(), NumberStyles.None, CultureInfo.InvariantCulture, out uint id)) continue;
|
||||
double duration = c.Length > 5 && double.TryParse(c[5].Trim(), NumberStyles.Float | NumberStyles.AllowLeadingSign, CultureInfo.InvariantCulture, out double d) ? d : -1;
|
||||
bool debuff = c.Length > 8 && c[8].Trim().Equals("True", StringComparison.OrdinalIgnoreCase);
|
||||
map[id] = new SpellInfo(c[1].Trim(), duration, debuff);
|
||||
int family = c.Length > 2 && int.TryParse(c[2].Trim(), NumberStyles.Integer, CultureInfo.InvariantCulture, out int fam) ? fam : 0;
|
||||
int power = c.Length > 6 && int.TryParse(c[6].Trim(), NumberStyles.Integer, CultureInfo.InvariantCulture, out int pw) ? pw : 0;
|
||||
map[id] = new SpellInfo(c[1].Trim(), duration, debuff, family, power);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
244
Plugins/RynthCore.Plugin.RynthInventory/Views/BankingTab.cs
Normal file
244
Plugins/RynthCore.Plugin.RynthInventory/Views/BankingTab.cs
Normal file
|
|
@ -0,0 +1,244 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using RynthCore.Plugin.RynthInventory.Data;
|
||||
using RynthCore.Plugin.RynthInventory.Ui;
|
||||
using RynthCore.Plugin.Shared;
|
||||
|
||||
namespace RynthCore.Plugin.RynthInventory.Views;
|
||||
|
||||
/// <summary>
|
||||
/// Banking (Infinite Leaftide only, InventoryContext.Ilt): the bank of every character on this server (the Mini Remote's Banking
|
||||
/// tab moved here 2026-10-13). Balances, form choices and the last reply come from RynthILT's
|
||||
/// "RynthILT.Data" bank JSON; the character list adds the inventory's characters on the same server
|
||||
/// (BankRoster). Deposits, withdrawals, transfers and balance reads go back to RynthILT as verb lines;
|
||||
/// a transfer is confirmed here first (RynthILT doesn't ask again).
|
||||
/// </summary>
|
||||
internal sealed partial class InventoryView
|
||||
{
|
||||
private const int MaxTransactionsShown = 20;
|
||||
private const float ColPyreals = 150f, ColLum = 270f, ColKeys = 380f, ColCoins = 450f, ColUpdated = 560f;
|
||||
|
||||
private int _depositIndex, _withdrawIndex, _withdrawNote, _transferIndex, _transferNote;
|
||||
private string _withdrawAmount = string.Empty, _transferAmount = string.Empty, _transferTo = string.Empty;
|
||||
/// <summary>The transfer waiting for "Yes, send": its verb line and the sentence shown.</summary>
|
||||
private (string Verb, string Text)? _confirmTransfer;
|
||||
private string _bankMessage = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// The Banking tab shows only while RynthCore's active server is Infinite Leaftide (it says what
|
||||
/// is missing when RynthILT isn't loaded); on every other server there is no Banking page.
|
||||
/// </summary>
|
||||
private bool BankingShown => _c.Ilt;
|
||||
|
||||
/// <summary>Off Infinite Leaftide (or logged out): back to the Search tab if Banking was showing.</summary>
|
||||
public void LeaveBanking()
|
||||
{
|
||||
if (Tab == TabBanking) Tab = TabSearch;
|
||||
_confirmTransfer = null;
|
||||
}
|
||||
|
||||
/// <summary>Opens on the Banking tab ("/ginv bank", RynthAi's and RynthILT's bank links).</summary>
|
||||
public void ShowBanking()
|
||||
{
|
||||
Tab = TabBanking;
|
||||
_confirmTransfer = null;
|
||||
}
|
||||
|
||||
private void DrawBanking(UiWindow w)
|
||||
{
|
||||
IltBankView b = _c.Bank;
|
||||
if (!b.Loaded)
|
||||
{
|
||||
w.TextDisabled("The bank comes from RynthILT (Infinite Leaftide). Load RynthILT to see every character's bank here.");
|
||||
return;
|
||||
}
|
||||
if (!b.Available)
|
||||
{
|
||||
w.TextDisabled("This isn't an Infinite Leaftide world, so there is no bank to show.");
|
||||
return;
|
||||
}
|
||||
|
||||
w.Text($"Bank on {(b.World.Length > 0 ? b.World : "this server")}");
|
||||
w.SameLine();
|
||||
w.SmallButton("Refresh", "b.refresh", () => SendBank(IltBankView.RefreshVerb(), "Reading the balance..."));
|
||||
w.Tooltip("A quiet /bank balance read for the character you're on (other characters update when they log in).");
|
||||
if (b.Enabled == 0) w.TextColored(UiColors.Red, "This server has no /bank command.");
|
||||
else if (b.Enabled < 0) w.TextDisabled("Whether this server has /bank isn't known yet.");
|
||||
if (b.Result.Length > 0) w.TextColored(UiColors.Gold, b.Result);
|
||||
if (_bankMessage.Length > 0) w.TextColored(UiColors.Yellow, _bankMessage);
|
||||
|
||||
List<BankRosterEntry> roster = BankRoster.Build(b, _c.Index);
|
||||
DrawBankTable(w, roster);
|
||||
if (b.Enabled != 0)
|
||||
{
|
||||
DrawDeposit(w, b);
|
||||
DrawWithdraw(w, b);
|
||||
DrawTransfer(w, b, roster);
|
||||
}
|
||||
DrawTransactions(w, b);
|
||||
}
|
||||
|
||||
private void DrawBankTable(UiWindow w, List<BankRosterEntry> roster)
|
||||
{
|
||||
w.SeparatorText($"Characters ({roster.Count})");
|
||||
w.TextDisabled("Character");
|
||||
w.SameLine(ColPyreals); w.TextDisabled("Pyreals");
|
||||
w.SameLine(ColLum); w.TextDisabled("Luminance");
|
||||
w.SameLine(ColKeys); w.TextDisabled("Keys L/M");
|
||||
w.SameLine(ColCoins); w.TextDisabled("Coins E/W/P");
|
||||
w.SameLine(ColUpdated); w.TextDisabled("Updated");
|
||||
foreach (BankRosterEntry e in roster)
|
||||
{
|
||||
string name = e.Current ? e.Name + " (you)" : e.Name;
|
||||
if (e.Bank is { } r)
|
||||
{
|
||||
w.Text(name);
|
||||
if (e.Account.Length > 0) w.Tooltip("Account: " + e.Account);
|
||||
BankCells(w, r);
|
||||
w.SameLine(ColUpdated);
|
||||
w.TextDisabled(r.UpdatedUtc == DateTime.MinValue ? "-" : InventoryIndex.Age(r.UpdatedUtc, _c.UtcNow));
|
||||
}
|
||||
else
|
||||
{
|
||||
w.TextDisabled(name);
|
||||
if (e.Account.Length > 0) w.Tooltip("Account: " + e.Account);
|
||||
w.SameLine(ColPyreals);
|
||||
w.TextDisabled("not read yet: log in with RynthILT loaded");
|
||||
}
|
||||
}
|
||||
if (roster.Count == 0) w.TextDisabled("No characters on this server yet.");
|
||||
else
|
||||
{
|
||||
w.TextColored(UiColors.Gold, "Total");
|
||||
BankCells(w, BankRoster.Totals(roster));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>The balance columns of one row (Pyreals .. Coins).</summary>
|
||||
private static void BankCells(UiWindow w, IltBankRow r)
|
||||
{
|
||||
w.SameLine(ColPyreals); w.Text(N(r.Pyreals));
|
||||
w.SameLine(ColLum); w.Text(N(r.Luminance));
|
||||
w.SameLine(ColKeys); w.Text($"{N(r.LegendaryKeys)}/{N(r.MythicalKeys)}");
|
||||
w.SameLine(ColCoins); w.Text($"{N(r.EnlightenedCoins)}/{N(r.WeaklyEnlightenedCoins)}/{N(r.PrestigeCoins)}");
|
||||
}
|
||||
|
||||
private void DrawDeposit(UiWindow w, IltBankView b)
|
||||
{
|
||||
if (b.Deposits.Count == 0) return;
|
||||
w.SeparatorText("Deposit");
|
||||
_depositIndex = Math.Clamp(_depositIndex, 0, b.Deposits.Count - 1);
|
||||
w.Combo("What", "b.dep.what", _depositIndex, b.Deposits, i => _depositIndex = i);
|
||||
w.SameLine();
|
||||
int di = _depositIndex;
|
||||
string label = b.Deposits[di];
|
||||
w.SmallButton("Deposit", "b.dep.go", () => SendBank(IltBankView.DepositVerb(di), "Depositing " + label + "..."));
|
||||
}
|
||||
|
||||
private void DrawWithdraw(UiWindow w, IltBankView b)
|
||||
{
|
||||
if (b.Withdrawals.Count == 0) return;
|
||||
w.SeparatorText("Withdraw");
|
||||
_withdrawIndex = Math.Clamp(_withdrawIndex, 0, b.Withdrawals.Count - 1);
|
||||
w.Combo("Currency", "b.wd.what", _withdrawIndex, Labels(b.Withdrawals), i => _withdrawIndex = i);
|
||||
IltBankChoice choice = b.Withdrawals[_withdrawIndex];
|
||||
w.InputText(choice.Notes ? "Notes" : "Amount", "b.wd.amt", _withdrawAmount, 20, v => _withdrawAmount = v);
|
||||
int note = NoteCombo(w, b, choice, "b.wd.note", _withdrawNote, i => _withdrawNote = i);
|
||||
w.SameLine();
|
||||
int wi = _withdrawIndex;
|
||||
w.SmallButton("Withdraw", "b.wd.go", () =>
|
||||
{
|
||||
long amount = BankRoster.ParseAmount(_withdrawAmount);
|
||||
if (amount <= 0) { _bankMessage = "Type a whole number to withdraw."; return; }
|
||||
SendBank(IltBankView.WithdrawVerb(wi, amount, note), $"Withdrawing {N(amount)} {choice.Label}...");
|
||||
});
|
||||
}
|
||||
|
||||
private void DrawTransfer(UiWindow w, IltBankView b, List<BankRosterEntry> roster)
|
||||
{
|
||||
if (b.Transfers.Count == 0) return;
|
||||
w.SeparatorText("Transfer");
|
||||
_transferIndex = Math.Clamp(_transferIndex, 0, b.Transfers.Count - 1);
|
||||
w.Combo("Currency", "b.tx.what", _transferIndex, Labels(b.Transfers), i => { _transferIndex = i; _confirmTransfer = null; });
|
||||
IltBankChoice choice = b.Transfers[_transferIndex];
|
||||
w.InputText(choice.Notes ? "Notes" : "Amount", "b.tx.amt", _transferAmount, 20, v => { _transferAmount = v; _confirmTransfer = null; });
|
||||
int note = NoteCombo(w, b, choice, "b.tx.note", _transferNote, i => { _transferNote = i; _confirmTransfer = null; });
|
||||
w.InputText("To", "b.tx.to", _transferTo, 40, v => { _transferTo = v; _confirmTransfer = null; });
|
||||
|
||||
// The other characters on this server, to fill "To" with one click.
|
||||
var others = new List<string> { "Pick a character..." };
|
||||
foreach (BankRosterEntry e in roster) if (!e.Current) others.Add(e.Name);
|
||||
if (others.Count > 1)
|
||||
{
|
||||
w.SameLine();
|
||||
w.Combo("##pick", "b.tx.pick", 0, others, i => { if (i > 0 && i < others.Count) { _transferTo = others[i]; _confirmTransfer = null; } });
|
||||
}
|
||||
|
||||
if (_confirmTransfer is { } pending)
|
||||
{
|
||||
w.TextColored(UiColors.Red, pending.Text);
|
||||
w.SmallButton("Yes, send", "b.tx.yes", () =>
|
||||
{
|
||||
_confirmTransfer = null;
|
||||
SendBank(pending.Verb, "Transfer sent...");
|
||||
});
|
||||
w.SameLine();
|
||||
w.SmallButton("Cancel", "b.tx.no", () => _confirmTransfer = null);
|
||||
return;
|
||||
}
|
||||
int ti = _transferIndex;
|
||||
w.SmallButton("Transfer...", "b.tx.go", () =>
|
||||
{
|
||||
long amount = BankRoster.ParseAmount(_transferAmount);
|
||||
string to = (_transferTo ?? string.Empty).Trim();
|
||||
if (amount <= 0) { _bankMessage = "Type a whole number to transfer."; return; }
|
||||
if (to.Length == 0) { _bankMessage = "Type (or pick) who gets the transfer."; return; }
|
||||
string what = choice.Notes && note < b.Notes.Count ? $"{N(amount)} x {b.Notes[note].Label}" : $"{N(amount)} {choice.Label}";
|
||||
_confirmTransfer = (IltBankView.TransferVerb(ti, amount, note, to), $"Send {what} to {to}? This can't be undone.");
|
||||
_bankMessage = string.Empty;
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The trade-note combo for a choice that counts notes; returns the note index in use (0 when
|
||||
/// the choice isn't notes). A pick arrives as an event and lands in <paramref name="set"/>.
|
||||
/// </summary>
|
||||
private static int NoteCombo(UiWindow w, IltBankView b, IltBankChoice choice, string id, int index, Action<int> set)
|
||||
{
|
||||
if (!choice.Notes || b.Notes.Count == 0) return 0;
|
||||
var labels = new List<string>(b.Notes.Count);
|
||||
foreach (IltBankNote n in b.Notes) labels.Add($"{n.Label} ({N(n.Value)} pyreals)");
|
||||
index = Math.Clamp(index, 0, b.Notes.Count - 1);
|
||||
w.Combo("Note", id, index, labels, set);
|
||||
return index;
|
||||
}
|
||||
|
||||
private void DrawTransactions(UiWindow w, IltBankView b)
|
||||
{
|
||||
if (b.Transactions.Count == 0) return;
|
||||
if (!w.CollapsingHeader($"Recent transfers ({b.Transactions.Count})", "b.txlog")) return;
|
||||
int shown = 0;
|
||||
foreach (IltBankTx t in b.Transactions)
|
||||
{
|
||||
if (shown++ >= MaxTransactionsShown) { w.TextDisabled($"...and {b.Transactions.Count - MaxTransactionsShown} more."); break; }
|
||||
string dir = t.Type.Length > 0 ? t.Type : "?";
|
||||
w.Text($"{t.When} {dir} {N(t.Amount)} {t.Currency}{(t.Player.Length > 0 ? " - " + t.Player : "")}");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Hands a verb to RynthILT; says so when it was refused.</summary>
|
||||
private void SendBank(string verb, string sending)
|
||||
{
|
||||
_bankMessage = _c.BankCommand(verb) ? sending : "RynthILT didn't take that (is it loaded, and are you logged in?).";
|
||||
}
|
||||
|
||||
private static List<string> Labels(IReadOnlyList<IltBankChoice> choices)
|
||||
{
|
||||
var list = new List<string>(choices.Count);
|
||||
foreach (IltBankChoice c in choices) list.Add(c.Label);
|
||||
return list;
|
||||
}
|
||||
|
||||
private static string N(long n) => n.ToString("N0", CultureInfo.InvariantCulture);
|
||||
}
|
||||
251
Plugins/RynthCore.Plugin.RynthInventory/Views/ChecklistFilter.cs
Normal file
251
Plugins/RynthCore.Plugin.RynthInventory/Views/ChecklistFilter.cs
Normal file
|
|
@ -0,0 +1,251 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using RynthCore.Loot.Editing;
|
||||
using RynthCore.Loot.VTank;
|
||||
using RynthCore.Plugin.RynthInventory.Scanning;
|
||||
using RynthCore.Plugin.RynthInventory.Ui;
|
||||
|
||||
namespace RynthCore.Plugin.RynthInventory.Views;
|
||||
|
||||
/// <summary>
|
||||
/// Global Inventory's own attribute filter (2026-10-24): the Inventory panel's checklist without
|
||||
/// an item (LootSdk LootItemAttributes.ForBlank) drawn in the script window, so a search across
|
||||
/// every character can require the same things a loot rule can: class, material, workmanship,
|
||||
/// damage, ratings, T11 grades, requirements, and spells and cantrips picked from the standard
|
||||
/// lists (LootSpellCatalog, from this plugin's spell table). Groups fold to keep the window's
|
||||
/// display list small; a ticked row shows its comparison and value under it. Every change
|
||||
/// rebuilds the rule (LootItemRules.BuildBlank) and the window filters with it at once.
|
||||
/// </summary>
|
||||
internal sealed class ChecklistFilter
|
||||
{
|
||||
private readonly Dictionary<string, LootEditItemChoice> _choices = new();
|
||||
private readonly Dictionary<string, LootEditItemExtra> _extras = new();
|
||||
// One group open at a time keeps the window's display list well inside the engine's limits.
|
||||
private string _openGroup = LootItemAttributes.GroupItem;
|
||||
private List<LootEditItemAttribute> _rows = new();
|
||||
private List<string> _notes = new();
|
||||
private LootSpellCatalog? _catalog;
|
||||
private int _pickSchool, _pickFamily, _pickLevel = 6, _pickTier = 3, _pickCantrip;
|
||||
|
||||
/// <summary>The rule's conditions now (empty: nothing ticked).</summary>
|
||||
public List<VTankLootCondition> Conditions { get; private set; } = new();
|
||||
|
||||
/// <summary>Bumped on every change (the view rebuilds its filter).</summary>
|
||||
public int Version { get; private set; }
|
||||
|
||||
public ChecklistFilter() => Rebuild();
|
||||
|
||||
private bool _ilt;
|
||||
|
||||
/// <summary>On Infinite Leaftide: the T11, weapon-card and pet rows are offered (2026-11-07). Rebuilds when it changes.</summary>
|
||||
public void SetIlt(bool ilt)
|
||||
{
|
||||
if (ilt == _ilt) return;
|
||||
_ilt = ilt;
|
||||
Rebuild();
|
||||
}
|
||||
|
||||
public void Clear()
|
||||
{
|
||||
_choices.Clear();
|
||||
_extras.Clear();
|
||||
Rebuild();
|
||||
}
|
||||
|
||||
private void Rebuild()
|
||||
{
|
||||
LootItemRuleDraft d = LootItemRules.BuildBlank(new LootItemRuleOptions
|
||||
{
|
||||
Ilt = _ilt,
|
||||
Choices = new List<LootEditItemChoice>(_choices.Values),
|
||||
Extras = new List<LootEditItemExtra>(_extras.Values),
|
||||
Spells = Catalog,
|
||||
});
|
||||
_rows = d.Attributes.ConvertAll(r => r.ToWire());
|
||||
_notes = d.Notes;
|
||||
Conditions = new List<VTankLootCondition>(d.Rule.Conditions);
|
||||
Version++;
|
||||
}
|
||||
|
||||
/// <summary>The standard spell lists from this plugin's spell table (built on first use).</summary>
|
||||
private LootSpellCatalog Catalog => _catalog ??= LootSpellCatalog.Build(SpellTable.AllSpells());
|
||||
|
||||
private void Set(LootEditItemAttribute r, bool? on = null, int? op = null, string? value = null)
|
||||
{
|
||||
if (!_choices.TryGetValue(r.Id, out LootEditItemChoice? c))
|
||||
_choices[r.Id] = c = new LootEditItemChoice { Id = r.Id, On = r.On, Op = r.Op, Value = string.Empty };
|
||||
if (on.HasValue) c.On = on.Value;
|
||||
if (op.HasValue) c.Op = op.Value;
|
||||
if (value != null) c.Value = value;
|
||||
Rebuild();
|
||||
}
|
||||
|
||||
private void SetQuiet(LootEditItemAttribute r, bool on)
|
||||
{
|
||||
if (!_choices.TryGetValue(r.Id, out LootEditItemChoice? c))
|
||||
_choices[r.Id] = c = new LootEditItemChoice { Id = r.Id, On = r.On, Op = r.Op, Value = string.Empty };
|
||||
c.On = on;
|
||||
}
|
||||
|
||||
private static string OpLabel(int op) => op switch
|
||||
{
|
||||
0 => "at least", 1 => "is", 2 => "at most", 3 => "is not", 4 => "has any", 5 => "any", 6 => "has all", 10 => "exact", 11 => "or better", 12 => "any tier", _ => "?",
|
||||
};
|
||||
|
||||
public void Draw(UiWindow w)
|
||||
{
|
||||
string? group = null;
|
||||
foreach (LootEditItemAttribute r in _rows)
|
||||
{
|
||||
if (r.Group != group)
|
||||
{
|
||||
group = r.Group;
|
||||
string g = group;
|
||||
bool open = _openGroup == g;
|
||||
int ticked = _rows.FindAll(x => x.Group == g && x.On).Count;
|
||||
w.ToggleButton((open ? "- " : "+ ") + g + (ticked > 0 ? " (" + ticked.ToString(CultureInfo.InvariantCulture) + ")" : ""),
|
||||
"cl.g." + g, open, () => _openGroup = _openGroup == g ? string.Empty : g, small: true);
|
||||
w.SameLine();
|
||||
w.SmallButton("all", "cl.all." + g, () => TickGroup(g, true));
|
||||
w.SameLine();
|
||||
w.SmallButton("none", "cl.none." + g, () => TickGroup(g, false));
|
||||
if (g == LootItemAttributes.GroupSpells && open) DrawSpellPickers(w);
|
||||
}
|
||||
if (_openGroup != r.Group && !r.On) continue;
|
||||
LootEditItemAttribute row = r;
|
||||
w.Checkbox(r.Label, "cl.on." + r.Id, r.On, v =>
|
||||
{
|
||||
if (!v && _extras.Remove(row.Id)) { _choices.Remove(row.Id); Rebuild(); }
|
||||
else Set(row, on: v);
|
||||
});
|
||||
if (r.Tip.Length > 0) w.Tooltip(r.Tip);
|
||||
if (!r.On) continue;
|
||||
// The comparison: a list, as the Loot Editor's popup has it (2026-11-07: one look for all).
|
||||
if (r.Ops.Count > 1)
|
||||
{
|
||||
w.SameLine();
|
||||
var opNames = r.Ops.ConvertAll(OpLabel);
|
||||
w.Combo("##op" + r.Label, "cl.op." + r.Id, Math.Max(0, r.Ops.IndexOf(r.Op)), opNames, i =>
|
||||
{
|
||||
if (i >= 0 && i < row.Ops.Count) Set(row, op: row.Ops[i], on: true);
|
||||
});
|
||||
}
|
||||
else if (r.Ops.Count == 1)
|
||||
{
|
||||
w.SameLine();
|
||||
w.TextDisabled(OpLabel(r.Ops[0]));
|
||||
}
|
||||
// The value: a list for named values, a box for numbers.
|
||||
if (r.Op == (int)LootItemAttributeOp.Any)
|
||||
w.TextDisabled("any value");
|
||||
else if (r.Flags && r.Op is (int)LootItemAttributeOp.HasAny or (int)LootItemAttributeOp.HasAll && r.Choices is { Count: > 0 })
|
||||
{
|
||||
// Several flags (multi imbues): a toggle per flag, the value their sum (2026-11-07).
|
||||
int cur = int.TryParse(r.Value, NumberStyles.Integer, CultureInfo.InvariantCulture, out int cv) ? cv : 0;
|
||||
int shown = 0;
|
||||
foreach (LootEditName c in r.Choices)
|
||||
{
|
||||
if (c.Id == 0 || (c.Id & (c.Id - 1)) != 0) continue; // single flags only
|
||||
int bit = c.Id;
|
||||
if (shown++ % 4 != 0) w.SameLine();
|
||||
w.ToggleButton(c.Name, "cl.f." + r.Id + "." + bit.ToString(CultureInfo.InvariantCulture), (cur & bit) != 0, () =>
|
||||
{
|
||||
int next = (cur & bit) != 0 ? cur & ~bit : cur | bit;
|
||||
if (next != 0) Set(row, value: next.ToString(CultureInfo.InvariantCulture), on: true);
|
||||
}, small: true);
|
||||
}
|
||||
}
|
||||
else if (r.Choices != null && r.Choices.Count > 0)
|
||||
{
|
||||
var names = new List<string>(r.Choices.Count);
|
||||
int cur = int.TryParse(r.Value, NumberStyles.Integer, CultureInfo.InvariantCulture, out int cv) ? cv : int.MinValue;
|
||||
int index = 0;
|
||||
for (int i = 0; i < r.Choices.Count; i++)
|
||||
{
|
||||
names.Add(r.Choices[i].Name);
|
||||
if (r.Choices[i].Id == cur) index = i;
|
||||
}
|
||||
w.Combo("##" + r.Label, "cl.v." + r.Id, index, names, i =>
|
||||
{
|
||||
if (i >= 0 && i < row.Choices!.Count) Set(row, value: row.Choices[i].Id.ToString(CultureInfo.InvariantCulture), on: true);
|
||||
});
|
||||
}
|
||||
else if (r.Editable)
|
||||
w.InputText("##" + r.Label, "cl.v." + r.Id, r.Value, 16, v => Set(row, value: v.Trim(), on: true));
|
||||
}
|
||||
foreach (string n in _notes) w.TextColored(UiColors.Stale, n);
|
||||
}
|
||||
|
||||
/// <summary>"all" / "none" on a group, as in the Loot Editor's popup.</summary>
|
||||
private void TickGroup(string group, bool on)
|
||||
{
|
||||
foreach (LootEditItemAttribute r in _rows)
|
||||
if (r.Group == group && r.On != on)
|
||||
{
|
||||
if (!on && _extras.Remove(r.Id)) { _choices.Remove(r.Id); continue; }
|
||||
SetQuiet(r, on);
|
||||
}
|
||||
Rebuild();
|
||||
}
|
||||
|
||||
private void DrawSpellPickers(UiWindow w)
|
||||
{
|
||||
LootSpellCatalog cat = Catalog;
|
||||
List<string> cantrips = cat.Cantrips;
|
||||
if (cat.Families.Count == 0) { w.TextDisabled("No spell table: the spell lists are empty."); return; }
|
||||
string[] schools = LootSpellCatalog.Schools;
|
||||
_pickSchool = Math.Clamp(_pickSchool, 0, schools.Length - 1);
|
||||
List<LootSpellFamily> fams = cat.Families.FindAll(f => f.School == schools[_pickSchool]);
|
||||
_pickFamily = fams.Count == 0 ? 0 : Math.Clamp(_pickFamily, 0, fams.Count - 1);
|
||||
LootSpellFamily? fam = fams.Count > 0 ? fams[_pickFamily] : null;
|
||||
|
||||
w.TextDisabled("Add spell:");
|
||||
for (int i = 0; i < schools.Length; i++)
|
||||
{
|
||||
int s = i;
|
||||
w.SameLine();
|
||||
w.ToggleButton(schools[i], "cl.sch." + i.ToString(CultureInfo.InvariantCulture), _pickSchool == i, () => { _pickSchool = s; _pickFamily = 0; }, small: true);
|
||||
}
|
||||
var famNames = fams.ConvertAll(f => f.Name);
|
||||
w.Combo("Spell##fam", "cl.fam", _pickFamily, famNames, i => _pickFamily = i);
|
||||
if (fam != null)
|
||||
{
|
||||
int lo = Math.Max(1, fam.MinLevel), hi = Math.Min(8, fam.MaxLevel);
|
||||
_pickLevel = Math.Clamp(_pickLevel, lo, hi);
|
||||
var levels = new List<string>();
|
||||
for (int l = lo; l <= hi; l++) levels.Add("Level " + LootItemAttributes.RomanLevel(l));
|
||||
w.Combo("Level##lvl", "cl.lvl", _pickLevel - lo, levels, i => _pickLevel = lo + i);
|
||||
w.SameLine();
|
||||
LootSpellFamily f = fam;
|
||||
w.SmallButton("Add spell", "cl.addspell", () =>
|
||||
{
|
||||
var x = new LootEditItemExtra { Kind = LootEditItemExtra.Spell, Name = f.Name, Level = _pickLevel };
|
||||
_extras[LootItemAttributes.ExtraId(x)] = x;
|
||||
Rebuild();
|
||||
});
|
||||
w.Tooltip("Require this spell (Self or Other) at this level or better; pick exact or any tier in its row.");
|
||||
}
|
||||
|
||||
if (cantrips.Count == 0) return;
|
||||
w.TextDisabled("Add cantrip:");
|
||||
string[] tiers = LootItemAttributes.CantripTiers;
|
||||
_pickTier = Math.Clamp(_pickTier, 0, tiers.Length - 1);
|
||||
for (int i = 0; i < tiers.Length; i++)
|
||||
{
|
||||
int t = i;
|
||||
w.SameLine();
|
||||
w.ToggleButton(tiers[i], "cl.tier." + i.ToString(CultureInfo.InvariantCulture), _pickTier == i, () => _pickTier = t, small: true);
|
||||
}
|
||||
_pickCantrip = Math.Clamp(_pickCantrip, 0, cantrips.Count - 1);
|
||||
w.Combo("Cantrip##can", "cl.can", _pickCantrip, cantrips, i => _pickCantrip = i);
|
||||
w.SameLine();
|
||||
w.SmallButton("Add cantrip", "cl.addcan", () =>
|
||||
{
|
||||
var x = new LootEditItemExtra { Kind = LootEditItemExtra.Cantrip, Name = cantrips[_pickCantrip], Level = _pickTier };
|
||||
_extras[LootItemAttributes.ExtraId(x)] = x;
|
||||
Rebuild();
|
||||
});
|
||||
w.Tooltip("Require this cantrip at this tier or better (Minor < Major < Epic < Legendary < Paragon).");
|
||||
}
|
||||
}
|
||||
|
|
@ -8,15 +8,15 @@ namespace RynthCore.Plugin.RynthInventory.Views;
|
|||
|
||||
/// <summary>
|
||||
/// The Global Inventory window: a search page (every character on every server, filters,
|
||||
/// totals, results, details) and a characters page (snapshot ages, forget). Recorded on the pump
|
||||
/// thread, replayed by the engine. (A server's own pages are its server plugin's: the Banking page
|
||||
/// that showed RynthILT's bank here is RynthILT's own Banking tab since 2026-10-21.)
|
||||
/// totals, results, details), a characters page (snapshot ages, forget) and, on Infinite Leaftide
|
||||
/// only (RynthCore's active server), a Banking page with RynthILT's bank for every character
|
||||
/// (Views\BankingTab.cs). Recorded on the pump thread, replayed by the engine.
|
||||
/// </summary>
|
||||
internal sealed partial class InventoryView
|
||||
{
|
||||
public const int TabSearch = 0, TabCharacters = 1;
|
||||
public const int TabSearch = 0, TabCharacters = 1, TabBanking = 2;
|
||||
private const int PageSize = 100;
|
||||
private const float RowIcon = 18f, DetailIcon = 32f, DetailsHeight = 190f;
|
||||
private const float RowIcon = 18f, DetailIcon = 32f, DetailsHeight = 260f;
|
||||
|
||||
private static readonly string[] SortNames = { "Name", "Character", "Count", "Value", "Burden", "Category", "Last seen" };
|
||||
|
||||
|
|
@ -31,10 +31,18 @@ internal sealed partial class InventoryView
|
|||
private string? _selectedKey;
|
||||
private string? _confirmForget;
|
||||
private string _message = string.Empty;
|
||||
/// <summary>Pending trade quantity text (for stackable items).</summary>
|
||||
private string _tradeQtyText = string.Empty;
|
||||
|
||||
private InventoryResult? _result;
|
||||
private int _resultRevision = -1;
|
||||
private bool _resultDirty = true;
|
||||
/// <summary>"Find like this" from the Inventory panel (/ginv like), or this window's checklist's, or null.</summary>
|
||||
private LikeFilter? _like;
|
||||
// The window's own attribute checklist (2026-10-24) and whether _like is its.
|
||||
private readonly ChecklistFilter _checklist = new();
|
||||
private bool _showChecklist, _likeIsChecklist;
|
||||
private int _checklistVersion;
|
||||
|
||||
public InventoryView(InventoryContext c) => _c = c;
|
||||
|
||||
|
|
@ -47,6 +55,16 @@ internal sealed partial class InventoryView
|
|||
_resultDirty = true;
|
||||
}
|
||||
|
||||
/// <summary>Opens on the search page showing only the items <paramref name="like"/> takes (null clears it).</summary>
|
||||
public void SetLike(LikeFilter? like)
|
||||
{
|
||||
_like = like;
|
||||
_likeIsChecklist = false;
|
||||
Tab = TabSearch;
|
||||
_selectedKey = null;
|
||||
Invalidate();
|
||||
}
|
||||
|
||||
private void Invalidate()
|
||||
{
|
||||
_resultDirty = true;
|
||||
|
|
@ -59,10 +77,30 @@ internal sealed partial class InventoryView
|
|||
w.SameLine();
|
||||
int chars = _c.Index?.Characters.Count ?? 0;
|
||||
w.ToggleButton($"Characters ({chars})", "tab.chars", Tab == TabCharacters, () => Tab = TabCharacters, small: true);
|
||||
if (BankingShown)
|
||||
{
|
||||
w.SameLine();
|
||||
w.ToggleButton("Banking", "tab.bank", Tab == TabBanking, () => Tab = TabBanking, small: true);
|
||||
}
|
||||
if (_c.TradeCommand != null)
|
||||
{
|
||||
w.SameLine();
|
||||
int tradeCount = _c.Trade?.Items.Count ?? 0;
|
||||
string tradeLabel = tradeCount > 0 ? $"Trade List ({tradeCount})" : "Trade List";
|
||||
w.SmallButton(tradeLabel, "tab.trade", () => _c.TradeCommand.Invoke("toggle"));
|
||||
}
|
||||
w.SameLine();
|
||||
w.TextDisabled(StatusLine());
|
||||
w.Separator();
|
||||
|
||||
// The bank comes from RynthILT, not the inventory files: it draws before they are read.
|
||||
if (Tab == TabBanking)
|
||||
{
|
||||
if (BankingShown) DrawBanking(w);
|
||||
else Tab = TabSearch;
|
||||
return;
|
||||
}
|
||||
|
||||
if (_c.Index == null)
|
||||
{
|
||||
w.TextDisabled(_c.Loading ? "Reading the inventory files..." : "No inventory read yet.");
|
||||
|
|
@ -87,7 +125,21 @@ internal sealed partial class InventoryView
|
|||
private void DrawSearch(UiWindow w, InventoryIndex index)
|
||||
{
|
||||
InventorySettings s = _c.Settings;
|
||||
TakeChecklist();
|
||||
if (_like != null) DrawLikeBar(w);
|
||||
w.InputText("Search", "q", _search, 128, v => { _search = v; Invalidate(); }, UiFormat.InputAutoSelectAll);
|
||||
w.SameLine();
|
||||
w.ToggleButton(_showChecklist ? "Attribute filter -" : "Attribute filter +", "cl.show", _showChecklist,
|
||||
() => _showChecklist = !_showChecklist, small: true);
|
||||
w.Tooltip("Filter every character's items by their attributes: the same checklist as the Inventory panel's (class, material, ratings, spells and cantrips from the standard lists...).");
|
||||
if (_showChecklist)
|
||||
{
|
||||
w.BeginChild("checklist", 0f, 260f, border: true);
|
||||
_checklist.SetIlt(_c.Ilt);
|
||||
_checklist.Draw(w);
|
||||
w.EndChild();
|
||||
w.SmallButton("Clear checklist", "cl.clear", () => _checklist.Clear());
|
||||
}
|
||||
|
||||
// Servers: the one you're on first, the others labelled.
|
||||
w.ToggleButton("All servers", "srv.all", _server == null, () => { _server = null; _characterKey = null; Invalidate(); }, small: true);
|
||||
|
|
@ -136,6 +188,11 @@ internal sealed partial class InventoryView
|
|||
|
||||
InventoryResult result = Result(index);
|
||||
w.Separator();
|
||||
if (_like != null && result.LikeUnknown > 0)
|
||||
{
|
||||
w.TextColored(UiColors.Stale, $"{result.LikeUnknown.ToString("N0", CultureInfo.InvariantCulture)} more item(s) can't be judged: not identified when saved, or saved by an older RynthInventory.");
|
||||
w.Tooltip("The filter needs what an identify tells (workmanship, ratings, spells...). Log that character in (identify the items if needed) and it is saved again with them.");
|
||||
}
|
||||
if (result.Rows.Count == 0)
|
||||
{
|
||||
w.TextDisabled(index.Rows.Count == 0 ? "No items recorded yet. Each character is scanned when it logs in with RynthInventory loaded." : "Nothing found.");
|
||||
|
|
@ -198,12 +255,44 @@ internal sealed partial class InventoryView
|
|||
SearchSpells = s.SearchSpells,
|
||||
Sort = (InventorySort)Math.Clamp(s.Sort, 0, SortNames.Length - 1),
|
||||
Descending = s.Descending,
|
||||
Like = _like == null ? null : _like.Judge,
|
||||
});
|
||||
_resultRevision = _c.IndexRevision;
|
||||
_resultDirty = false;
|
||||
return _result;
|
||||
}
|
||||
|
||||
/// <summary>The checklist changed: filter with its rule (nothing ticked drops its filter).</summary>
|
||||
private void TakeChecklist()
|
||||
{
|
||||
if (_checklistVersion == 0) _checklistVersion = 1; // the empty checklist built at start
|
||||
if (_checklist.Version == _checklistVersion) return;
|
||||
_checklistVersion = _checklist.Version;
|
||||
if (_checklist.Conditions.Count > 0)
|
||||
{
|
||||
_like = LikeFilter.From("attribute filter", _checklist.Conditions);
|
||||
_likeIsChecklist = true;
|
||||
}
|
||||
else if (_likeIsChecklist)
|
||||
{
|
||||
_like = null;
|
||||
_likeIsChecklist = false;
|
||||
}
|
||||
_selectedKey = null;
|
||||
Invalidate();
|
||||
}
|
||||
|
||||
/// <summary>The like filter's bar: what it is (its conditions on hover) and Clear.</summary>
|
||||
private void DrawLikeBar(UiWindow w)
|
||||
{
|
||||
LikeFilter like = _like!;
|
||||
w.TextColored(UiColors.Green, "Filter: " + like.Label);
|
||||
w.Tooltip(string.Join("\n", like.Lines));
|
||||
w.SameLine();
|
||||
w.SmallButton("Clear filter", "like.clear", () => { if (_likeIsChecklist) _checklist.Clear(); SetLike(null); });
|
||||
w.TextDisabled(string.Join(" ", like.Lines));
|
||||
}
|
||||
|
||||
private static string RowKey(InventoryRow r) => r.Owner.Key + "|" + (r.Storage?.Id ?? 0).ToString(CultureInfo.InvariantCulture) + "|" + r.Item.Id.ToString(CultureInfo.InvariantCulture);
|
||||
private static string GroupKey(InventoryTotal t) => "g|" + t.Name.ToLowerInvariant();
|
||||
|
||||
|
|
@ -248,6 +337,12 @@ internal sealed partial class InventoryView
|
|||
if (color != null) w.PushStyleColor(UiFormat.ColText, color.Value);
|
||||
w.Selectable(label, "r." + key, _selectedKey == key, () => { Select(key); SelectInGame(r); }, 0f, icons ? RowIcon : 0f);
|
||||
if (color != null) w.PopStyleColor();
|
||||
// Trade: add to trade list button.
|
||||
if (_c.Trade != null && _c.Trade.Phase == Data.TradePhase.Building)
|
||||
{
|
||||
w.SameLine();
|
||||
w.SmallButton("+", "t." + key, () => AddToTrade(r));
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawGroupRow(UiWindow w, InventoryTotal t)
|
||||
|
|
@ -299,6 +394,22 @@ internal sealed partial class InventoryView
|
|||
w.TextColored(UiColors.Gold, it.Name + StackText(it));
|
||||
w.SameLine();
|
||||
w.SmallButton("Close", "d.close", () => _selectedKey = null);
|
||||
if (_c.Trade != null && _c.Trade.Phase == Data.TradePhase.Building)
|
||||
{
|
||||
if (it.MaxStack > 1)
|
||||
{
|
||||
// Stackable: show a quantity input.
|
||||
w.SameLine();
|
||||
w.InputText("Qty", "d.tradeqty", _tradeQtyText, 12, v => _tradeQtyText = v);
|
||||
w.SameLine();
|
||||
w.SmallButton("Add to Trade", "d.trade", () => AddToTradeWithQty(r));
|
||||
}
|
||||
else
|
||||
{
|
||||
w.SameLine();
|
||||
w.SmallButton("Add to Trade", "d.trade", () => AddToTrade(r));
|
||||
}
|
||||
}
|
||||
|
||||
string who = r.Owner.Name + " on " + r.Owner.Server;
|
||||
if (!string.IsNullOrEmpty(r.Owner.Account) && r.Owner.Account != "unknown") who += $" (account {r.Owner.Account})";
|
||||
|
|
@ -331,9 +442,55 @@ internal sealed partial class InventoryView
|
|||
else if (it.Spells.Length > 0) w.TextWrapped("Spells: " + string.Join(", ", Array.ConvertAll(it.Spells, x => "#" + x.ToString(CultureInfo.InvariantCulture))));
|
||||
if (!it.Identified && it.Category is ItemCategory.Weapon or ItemCategory.Armor or ItemCategory.Clothing or ItemCategory.Jewelry or ItemCategory.Caster)
|
||||
w.TextDisabled("Not identified when scanned: spells, workmanship and set may be missing.");
|
||||
DrawAttributes(w, it);
|
||||
w.TextDisabled($"Item 0x{it.Id:X8}" + (it.Wcid != 0 ? $", class {it.Wcid}" : ""));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Every attribute the item was saved with (2026-10-24), grouped as the loot checklists show
|
||||
/// them: class, item (material, workmanship, value, set, imbue, slayer...), weapon / armor
|
||||
/// (skills, damage, modifiers, slots, armor level), ratings, pet essence, T11 and requirements.
|
||||
/// </summary>
|
||||
private static void DrawAttributes(UiWindow w, ItemRecord it)
|
||||
{
|
||||
if (!it.HasFacts)
|
||||
{
|
||||
w.TextDisabled("Full attributes: saved by an older RynthInventory. Log that character in to save them.");
|
||||
return;
|
||||
}
|
||||
RynthCore.Loot.Editing.LootItemFacts f = LikeFilter.Facts(it);
|
||||
var groups = new List<(string Group, List<string> Parts)>();
|
||||
void Add(string group, string part)
|
||||
{
|
||||
int i = groups.FindIndex(g => g.Group == group);
|
||||
if (i < 0) { groups.Add((group, new List<string>())); i = groups.Count - 1; }
|
||||
groups[i].Parts.Add(part);
|
||||
}
|
||||
Add(RynthCore.Loot.Editing.LootItemAttributes.GroupItem, "class " + RynthCore.Loot.Editing.LootItemRules.ClassName(f.ObjectClass));
|
||||
foreach (RynthCore.Loot.Editing.LootItemAttribute r in RynthCore.Loot.Editing.LootItemAttributes.For(f, like: false, includeT11: false))
|
||||
{
|
||||
if (r.Group == RynthCore.Loot.Editing.LootItemAttributes.GroupSpells) continue; // the spells are listed above
|
||||
Add(r.Group, r.Label.ToLowerInvariant() + " " + r.ItemText);
|
||||
}
|
||||
// T11: the virtual keys saved with the item.
|
||||
foreach (var (key, name) in RynthCore.Loot.T11.T11Keys.Names())
|
||||
{
|
||||
if (!f.Ints.TryGetValue(key, out int v) || v == 0 || key == RynthCore.Loot.T11.T11Keys.IsT11) continue;
|
||||
string label = name.StartsWith("T11: ", StringComparison.Ordinal) ? name.Substring(5)
|
||||
: name.StartsWith("T11 Mod: ", StringComparison.Ordinal) ? name.Substring(9) : name;
|
||||
string value = RynthCore.Loot.Editing.LootRuleText.ValueName(key, v.ToString(CultureInfo.InvariantCulture)) ?? v.ToString(CultureInfo.InvariantCulture);
|
||||
Add(RynthCore.Loot.Editing.LootItemAttributes.GroupT11, label.ToLowerInvariant() + " " + value);
|
||||
}
|
||||
foreach (var (group, parts) in groups)
|
||||
{
|
||||
w.TextColored(UiColors.Gold, group + ":");
|
||||
w.SameLine();
|
||||
w.TextWrapped(string.Join(", ", parts));
|
||||
}
|
||||
if (!it.Identified)
|
||||
w.TextDisabled("Not identified when saved: appraisal attributes (workmanship, ratings, damage...) may be missing.");
|
||||
}
|
||||
|
||||
private void DrawGroupDetails(UiWindow w, InventoryTotal t)
|
||||
{
|
||||
if (_c.Settings.ShowIcons && _c.IconsAvailable && t.Holders.Count > 0) { DrawIcon(w, t.Holders[0].Item, DetailIcon); w.SameLine(); }
|
||||
|
|
@ -381,6 +538,37 @@ internal sealed partial class InventoryView
|
|||
w.EndChild();
|
||||
}
|
||||
|
||||
// ── Trade ────────────────────────────────────────────────────────────
|
||||
|
||||
private void AddToTrade(InventoryRow r)
|
||||
{
|
||||
if (_c.Trade == null) return;
|
||||
// Use the full stack quantity for stackable items; 0 means "the whole object".
|
||||
int qty = r.Item.Stack > 1 ? r.Item.Stack : 0;
|
||||
string? error = _c.Trade.Add(r, qty);
|
||||
if (error != null) _message = error;
|
||||
else _message = $"Added {r.Item.Name} to trade list.";
|
||||
}
|
||||
|
||||
private void AddToTradeWithQty(InventoryRow r)
|
||||
{
|
||||
if (_c.Trade == null) return;
|
||||
int qty;
|
||||
string trimmed = _tradeQtyText.Trim();
|
||||
if (trimmed.Length == 0 || !int.TryParse(trimmed, out qty) || qty <= 0)
|
||||
qty = r.Item.Stack > 1 ? r.Item.Stack : 0; // default to full stack
|
||||
else if (r.Item.MaxStack > 1 && qty > r.Item.Stack)
|
||||
qty = r.Item.Stack; // clamp to available
|
||||
string? error = _c.Trade.Add(r, qty);
|
||||
if (error != null) _message = error;
|
||||
else
|
||||
{
|
||||
string qtyText = qty > 0 ? $" x{qty:N0}" : "";
|
||||
_message = $"Added {r.Item.Name}{qtyText} to trade list.";
|
||||
}
|
||||
_tradeQtyText = string.Empty;
|
||||
}
|
||||
|
||||
private void DrawCharacter(UiWindow w, CharacterInfo ci)
|
||||
{
|
||||
bool stale = IsStale(ci.ScannedUtc);
|
||||
|
|
|
|||
99
Plugins/RynthCore.Plugin.RynthInventory/Views/LikeFilter.cs
Normal file
99
Plugins/RynthCore.Plugin.RynthInventory/Views/LikeFilter.cs
Normal file
|
|
@ -0,0 +1,99 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.CompilerServices;
|
||||
using RynthCore.Loot;
|
||||
using RynthCore.Loot.Editing;
|
||||
using RynthCore.Plugin.RynthInventory.Data;
|
||||
|
||||
namespace RynthCore.Plugin.RynthInventory.Views;
|
||||
|
||||
/// <summary>
|
||||
/// "Find like this in Global Inventory" (2026-10-24): the Inventory panel's right-click builds a
|
||||
/// rule with the Add to loot profile checklist and sends it here as "/ginv like <spec>"
|
||||
/// (LootSdk LootFindSpec). The search page then lists only the saved items the rule takes,
|
||||
/// judged on what each item's file recorded (LootFactsMatcher). Items saved without the facts
|
||||
/// (by RynthInventory 0.1.4 or older) or not identified when saved can only be judged on what
|
||||
/// every item shows (class, name, value, burden, material...): when a rule needs more they are
|
||||
/// left out and counted as unknown, until their character logs in and is scanned again.
|
||||
/// </summary>
|
||||
internal sealed class LikeFilter
|
||||
{
|
||||
public string Label { get; }
|
||||
public List<string> Lines { get; }
|
||||
public bool NeedsIdentify { get; }
|
||||
|
||||
private readonly LootFindSpec _spec;
|
||||
// Facts per saved item: records never change once read (a rescan makes new ones).
|
||||
private readonly ConditionalWeakTable<ItemRecord, LootItemFacts> _facts = new();
|
||||
|
||||
private LikeFilter(LootFindSpec spec)
|
||||
{
|
||||
_spec = spec;
|
||||
Label = spec.Label.Length > 0 ? spec.Label : "like the item";
|
||||
Lines = spec.Describe();
|
||||
NeedsIdentify = LootFactsMatcher.NeedsIdentify(spec.Conditions);
|
||||
}
|
||||
|
||||
/// <summary>A filter from conditions made here (Global Inventory's own checklist).</summary>
|
||||
public static LikeFilter From(string label, IEnumerable<RynthCore.Loot.VTank.VTankLootCondition> conditions)
|
||||
{
|
||||
var spec = new LootFindSpec { Label = label };
|
||||
spec.Conditions.AddRange(conditions);
|
||||
return new LikeFilter(spec);
|
||||
}
|
||||
|
||||
public static LikeFilter? Parse(string text, out string error)
|
||||
{
|
||||
if (!LootFindSpec.TryDecode(text, out LootFindSpec spec, out error)) return null;
|
||||
return new LikeFilter(spec);
|
||||
}
|
||||
|
||||
/// <summary>1 the rule takes the item, 0 it doesn't, -1 it can't tell (not identified / no facts saved).</summary>
|
||||
public int Judge(ItemRecord it)
|
||||
{
|
||||
LootItemFacts f = _facts.GetValue(it, Facts);
|
||||
bool identified = it.HasFacts && it.Identified;
|
||||
return LootFactsMatcher.Match(_spec.Conditions, f, identified) switch
|
||||
{
|
||||
LootFactsVerdict.Match => 1,
|
||||
LootFactsVerdict.Unknown => -1,
|
||||
_ => 0,
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>The saved item as a loot rule sees it. An item saved without facts gets what its record has.</summary>
|
||||
internal static LootItemFacts Facts(ItemRecord it)
|
||||
{
|
||||
var f = new LootItemFacts
|
||||
{
|
||||
Id = unchecked((int)it.Id),
|
||||
Name = it.Name,
|
||||
StackSize = Math.Max(1, it.Stack),
|
||||
MaxStackSize = Math.Max(1, it.MaxStack),
|
||||
};
|
||||
if (it.HasFacts)
|
||||
{
|
||||
f.ObjectClass = it.ObjectClass;
|
||||
if (it.Ints != null) foreach (KeyValuePair<int, int> kv in it.Ints) f.Ints[kv.Key] = kv.Value;
|
||||
if (it.Doubles != null) foreach (KeyValuePair<int, double> kv in it.Doubles) f.Doubles[kv.Key] = kv.Value;
|
||||
}
|
||||
else
|
||||
{
|
||||
// An older file: the class from the item type alone, and the few properties it kept.
|
||||
f.ObjectClass = (int)AcItemClassifier.Classify(it.ItemType, it.Name, false, 0, 0);
|
||||
void Put(int key, int v) { if (v != 0) f.Ints[key] = v; }
|
||||
Put(1, unchecked((int)it.ItemType));
|
||||
Put(5, it.Burden);
|
||||
Put(19, it.Value);
|
||||
Put(131, it.Material);
|
||||
Put(105, it.Workmanship);
|
||||
Put(28, it.ArmorLevel);
|
||||
Put(91, it.MaxUses);
|
||||
Put(92, it.Uses);
|
||||
Put(265, it.SetId);
|
||||
}
|
||||
foreach (string s in it.SpellNames)
|
||||
if (!string.IsNullOrEmpty(s)) f.Spells.Add(s);
|
||||
return f;
|
||||
}
|
||||
}
|
||||
217
Plugins/RynthCore.Plugin.RynthInventory/Views/TradeView.cs
Normal file
217
Plugins/RynthCore.Plugin.RynthInventory/Views/TradeView.cs
Normal file
|
|
@ -0,0 +1,217 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using RynthCore.Plugin.RynthInventory.Data;
|
||||
using RynthCore.Plugin.RynthInventory.Ui;
|
||||
|
||||
namespace RynthCore.Plugin.RynthInventory.Views;
|
||||
|
||||
/// <summary>
|
||||
/// The Trade List window: shows the items queued for trading, the recipient name input,
|
||||
/// status of each item, and controls to start/cancel the trade. Drawn in its own UiWindow
|
||||
/// that stays open until the player closes it.
|
||||
/// </summary>
|
||||
internal sealed class TradeView
|
||||
{
|
||||
private readonly InventoryContext _c;
|
||||
|
||||
/// <summary>The pending recipient name typed by the player.</summary>
|
||||
private string _recipientInput = string.Empty;
|
||||
|
||||
public TradeView(InventoryContext c) => _c = c;
|
||||
|
||||
/// <summary>Draws the trade list window contents.</summary>
|
||||
public void Draw(UiWindow w)
|
||||
{
|
||||
TradeList? trade = _c.Trade;
|
||||
if (trade == null)
|
||||
{
|
||||
w.TextWrapped("Add items from Global Inventory to start building a trade list.");
|
||||
return;
|
||||
}
|
||||
|
||||
bool building = trade.Phase == TradePhase.Building;
|
||||
bool running = trade.Phase is TradePhase.Executing or TradePhase.WaitSwitch;
|
||||
|
||||
// ── Status message ──────────────────────────────────────────────
|
||||
if (trade.Message.Length > 0)
|
||||
{
|
||||
uint msgColor = trade.Phase switch
|
||||
{
|
||||
TradePhase.Complete => UiColors.Green,
|
||||
TradePhase.Cancelled => UiColors.Yellow,
|
||||
TradePhase.WaitSwitch => UiColors.Yellow,
|
||||
_ => UiColors.White,
|
||||
};
|
||||
// The running message is long (who has to stand where): wrap it; the end states are short.
|
||||
if (trade.Phase == TradePhase.Executing) w.TextWrapped(trade.Message);
|
||||
else w.TextColored(msgColor, trade.Message);
|
||||
}
|
||||
// Each giving account's client: which character it is on and what it is doing.
|
||||
foreach (string line in trade.AccountLines)
|
||||
w.TextDisabled(line);
|
||||
|
||||
// ── Recipient ───────────────────────────────────────────────────
|
||||
if (building)
|
||||
{
|
||||
w.InputText("Send to", "trade.to", _recipientInput, 64, v =>
|
||||
{
|
||||
_recipientInput = v;
|
||||
trade.Recipient = v.Trim();
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
w.Text("Sending to: " + trade.Recipient);
|
||||
}
|
||||
if (trade.Server.Length > 0)
|
||||
w.TextDisabled("Server: " + trade.Server);
|
||||
|
||||
w.Separator();
|
||||
|
||||
// ── Item list ───────────────────────────────────────────────────
|
||||
var (given, notFound, failed, pending) = trade.Counts();
|
||||
string header = $"Items ({trade.Items.Count})";
|
||||
if (!building)
|
||||
header += $" - {given} given, {pending} pending" +
|
||||
(notFound > 0 ? $", {notFound} not found" : "") +
|
||||
(failed > 0 ? $", {failed} failed" : "");
|
||||
w.Text(header);
|
||||
|
||||
w.BeginChild("tradeitems", 0f, building ? -60f : -30f, border: true);
|
||||
|
||||
// Group by character for readability.
|
||||
string? lastCharKey = null;
|
||||
for (int i = 0; i < trade.Items.Count; i++)
|
||||
{
|
||||
TradeItem item = trade.Items[i];
|
||||
if (!string.Equals(item.CharacterKey, lastCharKey, StringComparison.Ordinal))
|
||||
{
|
||||
lastCharKey = item.CharacterKey;
|
||||
string charLabel = item.CharacterName;
|
||||
if (!string.IsNullOrEmpty(item.Account) && item.Account != "unknown")
|
||||
charLabel += $" (account {item.Account})";
|
||||
w.SeparatorText(charLabel);
|
||||
}
|
||||
|
||||
// Status indicator.
|
||||
uint statusColor;
|
||||
string statusIcon;
|
||||
switch (item.Status)
|
||||
{
|
||||
case TradeItemStatus.Given:
|
||||
statusColor = UiColors.Green;
|
||||
statusIcon = "[OK] ";
|
||||
break;
|
||||
case TradeItemStatus.Giving:
|
||||
statusColor = UiColors.Yellow;
|
||||
statusIcon = "[..] ";
|
||||
break;
|
||||
case TradeItemStatus.NotFound:
|
||||
statusColor = UiColors.Red;
|
||||
statusIcon = "[??] ";
|
||||
break;
|
||||
case TradeItemStatus.Failed:
|
||||
statusColor = UiColors.Red;
|
||||
statusIcon = "[!!] ";
|
||||
break;
|
||||
default:
|
||||
statusColor = UiColors.White;
|
||||
statusIcon = "";
|
||||
break;
|
||||
}
|
||||
|
||||
string qty = item.Quantity > 0
|
||||
? " x" + item.Quantity.ToString("N0", CultureInfo.InvariantCulture)
|
||||
: "";
|
||||
string line = $"{statusIcon}{item.ItemName}{qty}";
|
||||
|
||||
if (item.Status != TradeItemStatus.Pending || !building)
|
||||
w.TextColored(statusColor, line);
|
||||
else
|
||||
w.Text(line);
|
||||
// Item info tooltip (hover to see details from the inventory index).
|
||||
ItemTooltip(w, item);
|
||||
|
||||
if (item.StatusText.Length > 0)
|
||||
{
|
||||
w.SameLine();
|
||||
w.TextDisabled(" - " + item.StatusText);
|
||||
}
|
||||
|
||||
// Remove button (only while building).
|
||||
if (building)
|
||||
{
|
||||
int idx = i; // capture for lambda
|
||||
w.SameLine();
|
||||
w.SmallButton("X", $"trade.rm.{i}", () =>
|
||||
{
|
||||
trade.RemoveAt(idx);
|
||||
w.NeedsPass = true;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if (trade.Items.Count == 0)
|
||||
w.TextDisabled("No items added yet. Use the [+] button on items in Global Inventory.");
|
||||
|
||||
w.EndChild();
|
||||
|
||||
// ── Action buttons ──────────────────────────────────────────────
|
||||
if (building)
|
||||
{
|
||||
bool canStart = trade.Items.Count > 0 && trade.Recipient.Trim().Length > 0;
|
||||
if (canStart)
|
||||
{
|
||||
w.Button("Start Trade", "trade.start", () => _c.TradeCommand?.Invoke("start"));
|
||||
w.SameLine();
|
||||
}
|
||||
w.Button("Clear All", "trade.clear", () => _c.TradeCommand?.Invoke("clear"));
|
||||
}
|
||||
else if (running)
|
||||
{
|
||||
w.Button("Cancel Trade", "trade.cancel", () => _c.TradeCommand?.Invoke("cancel"));
|
||||
}
|
||||
else // Complete or Cancelled
|
||||
{
|
||||
w.Button("New Trade", "trade.new", () => _c.TradeCommand?.Invoke("new"));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Shows a tooltip with item details from the inventory index when hovering over a trade item.
|
||||
/// </summary>
|
||||
private void ItemTooltip(UiWindow w, TradeItem item)
|
||||
{
|
||||
InventoryIndex? index = _c.Index;
|
||||
if (index == null) return;
|
||||
|
||||
// Find the item in the index by character key + object id, or character key + wcid + name.
|
||||
InventoryRow? row = null;
|
||||
foreach (InventoryRow r in index.Rows)
|
||||
{
|
||||
if (!string.Equals(r.Owner.Key, item.CharacterKey, StringComparison.Ordinal)) continue;
|
||||
if (item.ItemId != 0 && r.Item.Id == item.ItemId) { row = r; break; }
|
||||
if (item.Wcid != 0 && r.Item.Wcid == item.Wcid
|
||||
&& string.Equals(r.Item.Name, item.ItemName, StringComparison.OrdinalIgnoreCase))
|
||||
{ row = r; break; }
|
||||
}
|
||||
if (row == null) return;
|
||||
|
||||
ItemRecord it = row.Item;
|
||||
var lines = new List<string>();
|
||||
lines.Add(it.Name + (it.Stack > 1 ? $" (stack {it.Stack:N0}/{it.MaxStack:N0})" : ""));
|
||||
lines.Add(ItemCategory.Label(it.Category));
|
||||
string material = ItemNames.Material(it.Material);
|
||||
if (material.Length > 0) lines.Add(material);
|
||||
if (it.Workmanship > 0) lines.Add("Workmanship: " + it.Workmanship.ToString(CultureInfo.InvariantCulture));
|
||||
if (it.Value != 0) lines.Add("Value: " + it.Value.ToString("N0", CultureInfo.InvariantCulture));
|
||||
if (it.Burden != 0) lines.Add("Burden: " + it.Burden.ToString("N0", CultureInfo.InvariantCulture));
|
||||
if (it.ArmorLevel > 0) lines.Add("Armor Level: " + it.ArmorLevel.ToString(CultureInfo.InvariantCulture));
|
||||
string set = ItemNames.Set(it.SetId);
|
||||
if (set.Length > 0) lines.Add(set);
|
||||
if (it.SpellNames.Length > 0) lines.Add("Spells: " + string.Join(", ", it.SpellNames));
|
||||
lines.Add($"Owner: {row.Owner.Name} on {row.Owner.Server}");
|
||||
w.Tooltip(string.Join("\n", lines));
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue