Snapshot for release 2026.10.31.2 (internal 4a0710c)

This commit is contained in:
Tom Bohar 2026-10-31 19:00:25 -04:00
commit d54613aa63
50 changed files with 5824 additions and 179 deletions

View file

@ -19,10 +19,21 @@
// can pay for, and your packs and burden take (VendorQuote.MaxBuy).
// box a typed number stays as typed (1 .. MaxAmount); "max" and "half"
// are of what is selected: the whole stack, or the most you can buy.
//
// A server's bank (2026-10-31): some servers pay a pyreal vendor from the
// bank when the packs are short. The active server's plugin says so in its
// profile values (VendorBank.Read; RynthDefective names no server):
// no bank the pack's pyreals, as before;
// a bank that's read pack + bank pay ("price 1,200; pack 300 + bank 5,000"),
// and "max" counts both;
// a bank that isn't money isn't held against a buy: it goes, and the
// server decides ("the server's bank may cover it");
// "max" is the vendor's stock, your room and burden.
// ============================================================================
using System;
using System.Globalization;
using RynthCore.Plugin.Shared;
using RynthCore.PluginSdk;
namespace RynthCore.Plugin.RynthDefective.Model;
@ -160,13 +171,42 @@ internal static class QuantityRules
public static string N(long n) => n.ToString("N0", CultureInfo.InvariantCulture);
}
/// <summary>
/// The active server's bank, as its plugin says in its profile values: whether it pays a pyreal vendor
/// what the packs are short of (RynthServerProfile.ValueVendorBank), and the pyreals it can add
/// (ValueVendorBankPyreals; -1 = the balance can't be read). <see cref="None"/>: no bank (or no server
/// plugin saying so), and a buy counts the pack only.
/// </summary>
internal readonly record struct VendorBank(bool Pays, long Pyreals = -1)
{
/// <summary>The most a bank is taken to hold (anything above reads as this): far past any server's, and exact in the profile's numbers.</summary>
public const long MaxPyreals = 1_000_000_000_000_000;
public static readonly VendorBank None = new(false);
/// <summary>The bank's balance is read.</summary>
public bool Known => Pays && Pyreals >= 0;
/// <summary>A profile JSON's bank values; <see cref="None"/> without "vendorBank" above 0 (or for unusable text). Pure.</summary>
public static VendorBank Read(string? profileJson)
{
double pays = ServerProfileView.Value(profileJson, RynthServerProfile.ValueVendorBank, 0);
if (!(pays > 0)) return None;
double p = ServerProfileView.Value(profileJson, RynthServerProfile.ValueVendorBankPyreals, -1);
long pyreals = p >= 0 ? (long)Math.Floor(Math.Min(p, MaxPyreals)) : -1;
return new VendorBank(true, pyreals);
}
}
/// <summary>
/// One vendor item and what the player has: the box's price, its "max" and why a buy can't go. The
/// rules are ACE's, as the engine's VendorTrade.EstimateBuy applies them (the engine checks again
/// before it sends): a stackable item comes in stacks of MaxStack, each priced on its own
/// (max(1, ceil(value x rate - 0.1)), promissory notes at 1.15), anything else one per slot; a
/// limited listing (usually what another player sold, handed over whole) costs at least the whole
/// listing. Unknown funds, slots or burden (-1) aren't held against the buy.
/// listing. Unknown funds, slots or burden (-1) aren't held against the buy. A server's bank that
/// pays pyreal vendors (<see cref="BankPays"/>) adds its balance to the pack's, or, when the balance
/// can't be read, leaves the money to the server.
/// </summary>
internal sealed record VendorQuote
{
@ -193,14 +233,29 @@ internal sealed record VendorQuote
public int FreeItemSlots { get; init; } = -1;
public int FreeContainerSlots { get; init; } = -1;
public long FreeBurden { get; init; } = -1;
/// <summary>The server's bank pays this (pyreal) vendor what the pack is short of.</summary>
public bool BankPays { get; init; }
/// <summary>The pyreals the bank can add (with <see cref="BankPays"/>); -1 = its balance can't be read.</summary>
public long BankFunds { get; init; } = -1;
public bool Stackable => MaxStack > 0;
/// <summary>From the engine's vendor snapshot (API v67) and what the player has.</summary>
public static VendorQuote From(VendorInfo info, VendorItem item, int freeItemSlots, int freeContainerSlots, long freeBurden)
/// <summary>A bank pays, and its balance is read: pack + bank count.</summary>
public bool BankKnown => BankPays && BankFunds >= 0;
/// <summary>A bank pays, but its balance can't be read: the server decides about the money.</summary>
public bool BankUnknown => BankPays && BankFunds < 0;
/// <summary>What a buy may spend: the pack, plus a bank that's read; -1 = money isn't held against a buy (unknown, or an unread bank).</summary>
public long Spendable => Funds < 0 || BankUnknown ? -1 : BankKnown ? Funds + Math.Min(BankFunds, VendorBank.MaxPyreals) : Funds;
/// <summary>From the engine's vendor snapshot (API v67), what the player has, and the server's bank (pyreal vendors only).</summary>
public static VendorQuote From(VendorInfo info, VendorItem item, int freeItemSlots, int freeContainerSlots, long freeBurden,
VendorBank bank = default)
{
int stack = Math.Max(1, item.StackSize);
bool alt = info.UsesAltCurrency;
bool bankPays = !alt && bank.Pays;
return new VendorQuote
{
Name = item.Name,
@ -220,6 +275,8 @@ internal sealed record VendorQuote
FreeItemSlots = freeItemSlots,
FreeContainerSlots = freeContainerSlots,
FreeBurden = freeBurden,
BankPays = bankPays,
BankFunds = bankPays ? bank.Pyreals : -1,
};
}
@ -268,7 +325,8 @@ internal sealed record VendorQuote
private bool Fits(int n)
{
Estimate(n, out long cost, out long slots, out long burden);
if (Funds >= 0 && cost > Funds) return false;
long spend = Spendable;
if (spend >= 0 && cost > spend) return false;
if (FreeSlots >= 0 && slots > FreeSlots) return false;
if (FreeBurden >= 0 && burden > FreeBurden) return false;
return true;
@ -278,11 +336,12 @@ internal sealed record VendorQuote
/// The most you can buy now: what the vendor has, you can pay for, and your packs and burden take
/// (cost, slots and burden only grow with the count, so a halving search finds it). With nothing
/// known to limit an unlimited item, one full stack (one, for an item that doesn't stack). 0 = not even one.
/// With a bank: pack + bank pay when the bank is read; an unread bank leaves only stock, room and burden.
/// </summary>
public int MaxBuy()
{
int cap = Unlimited ? QuantityRules.MaxAmount : Math.Min(Stock, QuantityRules.MaxAmount);
if (Unlimited && Funds < 0 && FreeSlots < 0 && FreeBurden < 0) cap = Stackable ? Math.Max(1, MaxStack) : 1;
if (Unlimited && Spendable < 0 && FreeSlots < 0 && FreeBurden < 0) cap = Stackable ? Math.Max(1, MaxStack) : 1;
if (cap < 1 || !Fits(1)) return 0;
int lo = 1, hi = cap;
while (lo < hi)
@ -302,8 +361,11 @@ internal sealed record VendorQuote
return Stock < 1 ? $"The vendor has no {Name} left." : $"The vendor has only {QuantityRules.N(Stock)} {Name}.";
Estimate(n, out long cost, out long slots, out long burden);
string what = $"{QuantityRules.N(n)} {Name}";
if (Funds >= 0 && cost > Funds)
return $"Not enough {Currency}: {what} cost {QuantityRules.N(cost)}, you have {QuantityRules.N(Funds)}{CanBuy()}.";
long spend = Spendable;
if (spend >= 0 && cost > spend)
return BankKnown
? $"Not enough {Currency}: {what} cost {QuantityRules.N(cost)}, you have {QuantityRules.N(Funds)} in your pack + {QuantityRules.N(BankFunds)} in the bank{CanBuy()}."
: $"Not enough {Currency}: {what} cost {QuantityRules.N(cost)}, you have {QuantityRules.N(Funds)}{CanBuy()}.";
int free = FreeSlots;
if (free >= 0 && slots > free)
{
@ -324,12 +386,35 @@ internal sealed record VendorQuote
return max >= 1 ? $" (you can buy {QuantityRules.N(max)})" : string.Empty;
}
/// <summary>The price line under the Buy button: "300 pyreals · you have 1,250".</summary>
/// <summary>
/// The price line beside the Buy button: "300 pyreals · you have 1,250"; with a bank that's read
/// "price 1,200; pack 300 + bank 5,000"; with one that isn't "1,200 pyreals · pack 300 + the bank".
/// </summary>
public string PriceLine(int n)
{
string cost = n >= 1 ? QuantityRules.N(Cost(n)) + " " + Currency : "-";
string price = n >= 1 ? QuantityRules.N(Cost(n)) : "-";
if (Funds >= 0 && BankKnown) return $"price {price}; pack {QuantityRules.N(Funds)} + bank {QuantityRules.N(BankFunds)}";
string cost = n >= 1 ? price + " " + Currency : "-";
if (Funds >= 0 && BankUnknown) return $"{cost} · pack {QuantityRules.N(Funds)} + the bank";
return Funds >= 0 ? $"{cost} · you have {QuantityRules.N(Funds)}" : cost;
}
/// <summary>
/// What the bank does for buying <paramref name="n"/>, when the pack alone is short (null otherwise,
/// and always without a bank): the box's one-line note.
/// </summary>
public string? BankNote(int n)
{
if (!BankPays || Funds < 0 || n < 1) return null;
long cost = Cost(n);
if (cost <= Funds) return null;
if (BankUnknown)
return $"Your pack has {QuantityRules.N(Funds)} of the {QuantityRules.N(cost)} {Currency}: the server's bank may cover it (the server decides).";
return cost <= Spendable ? $"The bank pays the {QuantityRules.N(cost - Funds)} {Currency} your pack is short." : null;
}
/// <summary>What "max" counts, when that isn't plain: "" without a bank, or with one that's read.</summary>
public string MaxNote => BankUnknown ? "max counts the vendor's stock, your pack space and burden only (the bank's balance can't be read)" : string.Empty;
}
/// <summary>What the quantity box's actions say (chat and the Selection window). Pure.</summary>
@ -402,5 +487,23 @@ internal static class QtyReplies
return $"The vendor didn't sell it: {m}.";
}
/// <summary>
/// A buy's refusal when the server's bank was to pay part of it (<paramref name="bankMayPay"/>):
/// RynthCore's own money check ("costs ..., you have ...") counts only the pyreals the game shows,
/// so it says that and what to do; anything else as <see cref="VendorRefusal"/>.
/// </summary>
public static string BuyRefusal(string? message, bool bankMayPay)
{
string m = (message ?? string.Empty).Trim();
if (bankMayPay && m.StartsWith("costs ", StringComparison.Ordinal))
return $"RynthCore didn't send it: it {m}. RynthCore counts the pyreals the game shows, and the bank's aren't in them: take the rest out of the bank, then buy again.";
return VendorRefusal(m);
}
/// <summary>The server answered a buy without selling it.</summary>
public static string NotSold(int n, string name, bool bankMayPay, long cost, string currency) => bankMayPay
? $"The vendor didn't sell {QuantityRules.N(n)} {name}: the server said no (your pack and the bank may not cover {QuantityRules.N(cost)} {currency}, or there's no room)."
: $"The vendor didn't sell {QuantityRules.N(n)} {name}: the server said no (money, room, or too busy).";
private static string Cap(string s) => s.Length == 0 ? s : char.ToUpperInvariant(s[0]) + s[1..];
}

View file

@ -6,13 +6,16 @@
//
// Every call is behind its Has* check: splitting (SplitStackInternal, as old
// as the plugin API), giving with a count (GiveObjectTo, v62), vendor trading
// (v67), the server's refusals (v70) and the pack column's order (v80) are
// each used only where the engine has them. Nothing here needs more than the
// live release's API 92, and the Selection window itself needs v90.
// (v67), the server's refusals (v70), the pack column's order (v80) and the
// active server's list (v86, for its plugin's bank values) are each used
// only where the engine has them. Nothing here needs more than the live
// release's API 92, and the Selection window itself needs v90.
// ============================================================================
using System;
using System.Collections.Generic;
using RynthCore.Plugin.RynthDefective.Model;
using RynthCore.Plugin.Shared;
using RynthCore.PluginSdk;
namespace RynthCore.Plugin.RynthDefective.Quantity;
@ -80,6 +83,8 @@ internal interface IQtyWorld
int FreeContainerSlots();
/// <summary>Burden you can still carry (three times your capacity, as ACE); -1 = unknown.</summary>
long FreeBurden();
/// <summary>The active server's bank, as its plugin says (VendorBank.None: none, or nobody says).</summary>
VendorBank Bank();
}
/// <summary>The engine host's side (RynthCoreHost). Plugin pump thread only.</summary>
@ -97,9 +102,21 @@ internal sealed class HostQtyWorld : IQtyWorld
private uint[] _order = new uint[16];
private uint _vendorId, _vendorGeneration;
private VendorItem[] _vendorItems = Array.Empty<VendorItem>();
// The active server and its plugin's profile (v86 + "RynthServer.Profile"), for its bank values.
private readonly ServerStateClient _server = new();
private int _bankRevision = -1;
private VendorBank _bank = VendorBank.None;
public HostQtyWorld(RynthCoreHost host) => _h = host;
/// <summary>Login or logout: the next server may be another (its bank read afresh).</summary>
public void Reset()
{
_server.Clear();
_bankRevision = -1;
_bank = VendorBank.None;
}
public long NowMs => Environment.TickCount64;
public uint PlayerId => _h.HasGetPlayerId ? _h.GetPlayerId() : 0;
public uint SelectedId => _h.HasGetSelectedItemId ? _h.GetSelectedItemId() : 0;
@ -249,4 +266,20 @@ internal sealed class HostQtyWorld : IQtyWorld
if (carried < 0 || cap <= 0) return -1; // unknown: the engine checks with its own reading
return Math.Max(0, 3L * cap - carried);
}
/// <summary>
/// The active server's plugin's "vendorBank" / "vendorBankPyreals" values (polled every 2 s; read
/// again only when the server or its profile changed). Before v86, or with no server plugin: none.
/// </summary>
public VendorBank Bank()
{
if (!_h.HasGetServerStateJson) return VendorBank.None;
_server.Poll(_h, NowMs);
if (_server.Revision != _bankRevision)
{
_bankRevision = _server.Revision;
_bank = VendorBank.Read(_server.ProfileJson);
}
return _bank;
}
}

View file

@ -9,6 +9,9 @@
// open) or NPC you selected last
// an item in a vendor's list Buy N, with the price, your pyreals, the room
// in your packs and your burden checked first
// (a server's bank that pays vendors counts
// too, or leaves the money to the server when
// its balance can't be read: VendorQuote)
//
// The Selection window shows the box under what is selected (QuantityRow);
// /rdef qty, split, give and buy do the same from chat, hotkeys and metas.
@ -179,7 +182,7 @@ internal sealed class QuantityController
if (p.Free < 0) { free = -1; break; }
free += p.Free;
}
return VendorQuote.From(info, item, free, w.FreeContainerSlots(), w.FreeBurden());
return VendorQuote.From(info, item, free, w.FreeContainerSlots(), w.FreeBurden(), w.Bank());
}
/// <summary>
@ -256,7 +259,8 @@ internal sealed class QuantityController
private string About(QtySubject s) => s.Mode switch
{
QtyMode.Stack => $" (the selected {s.Name}: a stack of {QuantityRules.N(s.Stack)}; a split takes up to {QuantityRules.N(s.Stack - 1)})",
QtyMode.Vendor when s.Quote != null => $" (the vendor's {s.Name}: {s.Quote.PriceLine(Value)}; you can buy {QuantityRules.N(s.MaxBuy)})",
QtyMode.Vendor when s.Quote != null => $" (the vendor's {s.Name}: {s.Quote.PriceLine(Value)}; you can buy {QuantityRules.N(s.MaxBuy)}"
+ (s.Quote.MaxNote.Length > 0 ? "; " + s.Quote.MaxNote : string.Empty) + ")",
_ => string.Empty,
};
@ -401,16 +405,18 @@ internal sealed class QuantityController
string? refusal = q.Refusal(n);
if (refusal != null) { Say(w, false, refusal); return; }
// The bank is to pay what the pack is short of (read or not): the answers say so.
bool bankMayPay = q.BankPays && q.Funds >= 0 && q.Cost(n) > q.Funds;
uint request = w.Buy(info.VendorId, item.ObjectId, n);
if (request == 0)
{
Say(w, false, QtyReplies.VendorRefusal(w.TryGetTradeStatus(out VendorTradeStatus st) ? st.Message : null));
Say(w, false, QtyReplies.BuyRefusal(w.TryGetTradeStatus(out VendorTradeStatus st) ? st.Message : null, bankMayPay));
return;
}
_pending = new Pending
{
Kind = PendingKind.Buy, Id = item.ObjectId, Name = item.Name, N = n, RequestId = request,
Cost = q.Cost(n), Currency = q.Currency, AtMs = w.NowMs,
Cost = q.Cost(n), Currency = q.Currency, AtMs = w.NowMs, BankMayPay = bankMayPay,
};
}
@ -462,6 +468,8 @@ internal sealed class QuantityController
public uint RequestId;
public long Cost;
public string Currency = string.Empty;
/// <summary>Buy: the server's bank was to pay what the pack is short of.</summary>
public bool BankMayPay;
}
/// <summary>Plugin tick: the give target, and the answer to the action in flight.</summary>
@ -502,7 +510,7 @@ internal sealed class QuantityController
{
if (s.RequestId == p.RequestId)
{
if (s.State == VendorTradeState.Refused) { Finish(w, false, QtyReplies.VendorRefusal(s.Message)); return; }
if (s.State == VendorTradeState.Refused) { Finish(w, false, QtyReplies.BuyRefusal(s.Message, p.BankMayPay)); return; }
if (s.State == VendorTradeState.Done)
{
if (s.Result == VendorTradeResult.Accepted)
@ -510,7 +518,7 @@ internal sealed class QuantityController
else if (s.Result == VendorTradeResult.TimedOut)
Finish(w, false, $"No answer from the vendor about {QuantityRules.N(p.N)} {p.Name}: check your pack and {p.Currency} before trying again.");
else
Finish(w, false, $"The vendor didn't sell {QuantityRules.N(p.N)} {p.Name}: the server said no (money, room, or too busy).");
Finish(w, false, QtyReplies.NotSold(p.N, p.Name, p.BankMayPay, p.Cost, p.Currency));
return;
}
}

View file

@ -44,6 +44,11 @@
<Compile Include="..\Shared\RynthInstallPaths.cs" Link="Shared\RynthInstallPaths.cs" />
<!-- How a chat command answers (2026-10-28): the shared reply queue and colours. -->
<Compile Include="..\Shared\CommandReply.cs" Link="Shared\CommandReply.cs" />
<!-- The active server (plugin API v86 GetServerStateJson) and its owner's "RynthServer.Profile"
values (2026-10-31): whether its bank pays vendors, and how much, for the quantity box's buys. -->
<Compile Include="..\Shared\EngineServerState.cs" Link="Shared\EngineServerState.cs" />
<Compile Include="..\Shared\ServerStateClient.cs" Link="Shared\ServerStateClient.cs" />
<Compile Include="..\Shared\RynthServerProfileApi.cs" Link="Shared\RynthServerProfileApi.cs" />
</ItemGroup>
<ItemGroup>
<!-- Spell slots (2026-10-28): spell names and whom a spell is cast on, from RynthAi's spell table

View file

@ -117,6 +117,7 @@ public sealed partial class RynthDefectivePlugin : RynthPluginBase
_session.Use.ResetSession();
_world?.Reset();
_qty.Reset();
_qtyWorld?.Reset();
}
public override void OnLogout()
@ -129,6 +130,7 @@ public sealed partial class RynthDefectivePlugin : RynthPluginBase
_session.Use.ResetSession();
_world?.Reset();
_qty.Reset();
_qtyWorld?.Reset();
_barView = RynthCore.Plugin.RynthDefective.ShortcutBar.BarSnapshot.NotReady;
foreach (UiWindow? w in new[] { _barWindow, _pickerWindow, _settingsWindow })
if (w != null) { w.Visible = false; w.NeedsPass = true; }

View file

@ -71,6 +71,10 @@ internal sealed partial class SelectionWindow
: $"Half the stack ({QuantityRules.N(QuantityRules.HalfOf(max))}).";
if (Chip(dl, "##qty_half", "half", ref x, y, rowH, right, max >= 1, halfTip)) ctl.Value = QuantityRules.ForBox(QtyAmount.Half, max);
string maxTip = max < 1 ? none
: s.Mode == QtyMode.Vendor && s.Quote is { BankUnknown: true } bq
? $"The most your packs and burden take of what the vendor has ({QuantityRules.N(max)}): {bq.MaxNote}; the server decides about the money."
: s.Mode == QtyMode.Vendor && s.Quote is { BankKnown: true }
? $"The most you can buy now ({QuantityRules.N(max)}): what the vendor has, your pack and the bank pay for, and your packs take."
: s.Mode == QtyMode.Vendor ? $"The most you can buy now ({QuantityRules.N(max)}): what the vendor has, you can pay for and your packs take."
: $"The whole stack ({QuantityRules.N(max)}). A split still leaves one.";
if (Chip(dl, "##qty_max", "max", ref x, y, rowH, right, max >= 1, maxTip)) ctl.Value = QuantityRules.ForBox(QtyAmount.Max, max);
@ -184,8 +188,10 @@ internal sealed partial class SelectionWindow
QtySubject s = q.Subject;
VendorQuote? quote = s.Quote;
string? why = quote?.Refusal(value);
string? bank = quote?.BankNote(value);
string tip = q.Busy ? QtyReplies.Busy
: why ?? (quote != null ? $"Buy {QuantityRules.N(value)} {s.Name} for {QuantityRules.N(quote.Cost(value))} {quote.Currency}. The vendor checks again before it sells." : "Buy.");
: why ?? (quote != null ? $"Buy {QuantityRules.N(value)} {s.Name} for {QuantityRules.N(quote.Cost(value))} {quote.Currency}. "
+ (bank != null ? bank + " " : string.Empty) + "The vendor checks again before it sells." : "Buy.");
if (Chip(dl, "##qty_buy", "Buy " + QuantityRules.N(value), ref x, y, h, right, !q.Busy, tip, primary: why == null))
QuantityAction?.Invoke(QtyClick.Buy, value);
if (quote == null) return;
@ -202,6 +208,9 @@ internal sealed partial class SelectionWindow
{
string? why = s.Quote?.Refusal(value);
if (why != null) { line = why; color = WarnColor; return; }
// The bank's part: paid from a bank that's read, or the server's to decide.
string? bank = s.Quote?.BankNote(value);
if (bank != null) { line = bank; color = s.Quote!.BankUnknown ? WarnColor : _dim; return; }
line = s.Quote is { UnitPrice: > 0 } qq ? $"{QuantityRules.N(qq.UnitPrice)} {qq.Currency} each. /rdef buy N does the same." : "/rdef buy N does the same.";
return;
}