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
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