VendorTrade: allow vendors with 0 buy/sell rates #10
Loading…
Reference in a new issue
No description provided.
Delete branch "AwfulWaffle/RynthCore:vendor-zero-rate"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
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:
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", becauseProfileReadrequires 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
RateLooksSanenow 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.Compatibility/VendorRatePolicy.cs, following theAmbientLightPolicypattern, so a test can compile it in.tools/VendorRateTests(picked up byscripts/Run-AllTests.ps1, since its folder name contains "Test").Rate consumers checked
Every use of
BuyRate/SellRatein the engine:PlayerPaysForStack,VendorPaysForStack,EstimateBuy,UnitPricemultiply 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.FillInfocopies the rates to plugins, and the/rc vendorinfo line and the open-vendor log line print them.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 ReleasegivesPASS (20 checks), exit 0. As a negative control, the same test against the oldrate > 0fcheck fails 2 of 20 (rate 0 and -0).scripts/Publish-EngineCoreClr.ps1 -Target <scratch dir> -EngineOnly(exit 0), plusdotnet build src/RynthCore.Engine -c Release -p:EngineHost=coreclr:0 Error(s).Generated with Claude Code
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>Pull request closed