VendorTrade: allow vendors with 0 buy/sell rates #10

Closed
AwfulWaffle wants to merge 2 commits from AwfulWaffle/RynthCore:vendor-zero-rate into main
First-time contributor

Closed by the author: this change is already in main (checked against 418d80b). Thanks for taking it in.

Problem

Opening a vendor whose buy and sell rates are both 0 turns trading off:

VendorTrade: vendor 0x8007810B profile rates look wrong (buy=0 sell=0); trading with it is off.

The vendor window opens normally (layout=ok) and RynthAi's AutoVendor loads its profile, but every VendorBuy/VendorSell, from AutoVendor, RynthLua's vendor actions or /rc vendor, is refused with "vendor profile unreadable", because ProfileRead requires both rates to be > 0.

Why 0 is a legitimate rate

The vendor is a free storage vendor (a "vault") on a custom ACE server (DreamWeave). Its BuyPrice and SellPrice are 0 on purpose: depositing an item pays nothing and taking it back costs nothing. On that server the vault's GetSellCost/GetBuyCost return 0, so 0 is the real rate, not a misread profile.

Change

  • RateLooksSane now accepts finite rates in [0, 1000) (was (0, 1000)). Negative, NaN, infinite and huge values are still treated as a misread, and the warning still fires for them.
  • The check moves to a small pure file, Compatibility/VendorRatePolicy.cs, following the AmbientLightPolicy pattern, so a test can compile it in.
  • New tools/VendorRateTests (picked up by scripts/Run-AllTests.ps1, since its folder name contains "Test").

Rate consumers checked

Every use of BuyRate/SellRate in the engine:

  • PlayerPaysForStack, VendorPaysForStack, EstimateBuy, UnitPrice multiply by the rate and floor at 1 per stack (the stock ACE rule). With a 0 rate they give a 1-per-stack estimate. Nothing divides by a rate.
  • FillInfo copies the rates to plugins, and the /rc vendor info line and the open-vendor log line print them.
  • The payout pack-slot check divides by PyrealMaxStack, a constant.

One thing to note: because of that 1-per-stack floor, the estimates for a 0-rate vendor are slightly pessimistic. A deposit asks for one free pack slot for its estimated "payout", and a withdrawal asks the player to carry at least one pyreal per stack. This PR leaves the stock-ACE pricing alone, since a stock ACE vendor with a 0 rate still charges and pays the 1 minimum.

Testing

  • tools/VendorRateTests: dotnet run -c Release gives PASS (20 checks), exit 0. As a negative control, the same test against the old rate > 0f check fails 2 of 20 (rate 0 and -0).
  • Engine built with scripts/Publish-EngineCoreClr.ps1 -Target <scratch dir> -EngineOnly (exit 0), plus dotnet build src/RynthCore.Engine -c Release -p:EngineHost=coreclr: 0 Error(s).
  • Not yet tested in game against the vault vendor.

Generated with Claude Code

Closed by the author: this change is already in main (checked against 418d80b). Thanks for taking it in. ## Problem Opening a vendor whose buy and sell rates are both 0 turns trading off: ``` VendorTrade: vendor 0x8007810B profile rates look wrong (buy=0 sell=0); trading with it is off. ``` The vendor window opens normally (`layout=ok`) and RynthAi's AutoVendor loads its profile, but every VendorBuy/VendorSell, from AutoVendor, RynthLua's vendor actions or `/rc vendor`, is refused with "vendor profile unreadable", because `ProfileRead` requires both rates to be `> 0`. ## Why 0 is a legitimate rate The vendor is a free storage vendor (a "vault") on a custom ACE server (DreamWeave). Its BuyPrice and SellPrice are 0 on purpose: depositing an item pays nothing and taking it back costs nothing. On that server the vault's GetSellCost/GetBuyCost return 0, so 0 is the real rate, not a misread profile. ## Change - `RateLooksSane` now accepts finite rates in `[0, 1000)` (was `(0, 1000)`). Negative, NaN, infinite and huge values are still treated as a misread, and the warning still fires for them. - The check moves to a small pure file, `Compatibility/VendorRatePolicy.cs`, following the `AmbientLightPolicy` pattern, so a test can compile it in. - New `tools/VendorRateTests` (picked up by `scripts/Run-AllTests.ps1`, since its folder name contains "Test"). ## Rate consumers checked Every use of `BuyRate`/`SellRate` in the engine: - `PlayerPaysForStack`, `VendorPaysForStack`, `EstimateBuy`, `UnitPrice` multiply by the rate and floor at 1 per stack (the stock ACE rule). With a 0 rate they give a 1-per-stack estimate. Nothing divides by a rate. - `FillInfo` copies the rates to plugins, and the `/rc vendor` info line and the open-vendor log line print them. - The payout pack-slot check divides by `PyrealMaxStack`, a constant. One thing to note: because of that 1-per-stack floor, the estimates for a 0-rate vendor are slightly pessimistic. A deposit asks for one free pack slot for its estimated "payout", and a withdrawal asks the player to carry at least one pyreal per stack. This PR leaves the stock-ACE pricing alone, since a stock ACE vendor with a 0 rate still charges and pays the 1 minimum. ## Testing - `tools/VendorRateTests`: `dotnet run -c Release` gives `PASS (20 checks)`, exit 0. As a negative control, the same test against the old `rate > 0f` check fails 2 of 20 (rate 0 and -0). - Engine built with `scripts/Publish-EngineCoreClr.ps1 -Target <scratch dir> -EngineOnly` (exit 0), plus `dotnet build src/RynthCore.Engine -c Release -p:EngineHost=coreclr`: `0 Error(s)`. - Not yet tested in game against the vault vendor. Generated with Claude Code
A custom server can run a free storage vendor whose BuyPrice and
SellPrice are both 0: it pays nothing for items handed to it and charges
nothing to take them back. The profile check required rate > 0, so
opening such a vendor logged

  VendorTrade: vendor 0x8007810B profile rates look wrong (buy=0 sell=0);
  trading with it is off.

and every VendorBuy/VendorSell (RynthAi AutoVendor, RynthLua vendor
actions, /rc vendor) was refused with "vendor profile unreadable".

The rate check now accepts finite rates in [0, 1000). Negative, NaN,
infinite and huge values are still treated as a misread profile, and
the warning still fires for them. The check moves to
VendorRatePolicy.cs so tools\VendorRateTests can compile it in.

Rate consumers checked: PlayerPaysForStack, VendorPaysForStack,
EstimateBuy and UnitPrice multiply by the rate and floor at 1 per stack
(the stock ACE rule), so a 0 rate gives a 1-per-stack estimate; there
is no division by a rate anywhere. FillInfo and the /rc vendor info
line only copy or print the rates.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Review follow-up to the 0-rate fix.

- A vendor rate of exactly 0 now means free: PlayerPaysForStack and
  VendorPaysForStack return 0 instead of the 1-per-stack floor (notes
  included). Every rate above 0 keeps the stock ACE floor. With the
  floor, a free storage vendor refused withdrawals to a player with no
  pyreals ("costs N pyreals, you have 0") and deposits with no free pack
  slot (the estimated "payout" needed one), though the vault charges and
  pays nothing. The server stays the authority on the real price.
- The two price helpers move to VendorRatePolicy.cs; VendorTrade keeps
  thin forwarders so its call sites are unchanged.
- A vendor with buy=0 and sell=0 is logged once per vendor id as a
  zero-rate (free) vendor.
- tools\VendorRateTests covers the pricing (rate 0 -> cost 0 and payout
  0; rate 0.001, value 1 -> still 1) and reads VendorTrade.cs to pin that
  it calls VendorRatePolicy, so reverting the wiring fails the test.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
AwfulWaffle closed this pull request 2026-11-07 14:00:19 -05:00

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
rynth/RynthCore!10
No description provided.