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:
BlankenshipG 2026-11-23 00:08:38 -05:00
commit dc08e1abba
521 changed files with 47247 additions and 795 deletions

View 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;
}
}

View file

@ -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);
}

View file

@ -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;
}

View file

@ -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));
}
}
}
}

View 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\:
/// &lt;id&gt;.job.json the job; written only by the client that started it (start, cancel)
/// &lt;id&gt;.&lt;account&gt;.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;
}

View 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);
}
}