acdream/tests/AcDream.Core.Net.Tests/Messages/VendorRequestsTests.cs
Erik 97cf873870
Some checks are pending
Headless portability / portable-headless (ubuntu-latest) (push) Waiting to run
Headless portability / portable-headless (windows-latest) (push) Waiting to run
Headless portability / linux-graphical (push) Waiting to run
Headless portability / linux-vulkan (push) Waiting to run
feat(vendor): Slice 6 buy arc — shop items are real objects, vendor selection is THE selection, and Buy works (0x005F)
Three ordered pieces in one landing (the shared controller/composition
files carry all three; the internal order was 6.1 -> 6.2 -> 6.3):

6.1 VendorShopItemMaterializer diff-merges the shop list into the live
ClientObjectTable on VendorState transitions (so client-local close and
session teardown retire the entries too) and never claims a guid it did
not add — ACE's UniqueItemsForSale can re-list a guid a player once
held (AP-163 files the collision-skip; no retail counterpart traced).
Right-click examine on shop items now routes through the ordinary
appraisal path — the 5.4 F7c blocker dissolves with the table entries.

6.2 SelectionChangeSource.Vendor: row clicks, auto-select, and examine
all flow through the canonical SelectionState; the status bar and the
existing byte-faithful StackSplitQuantityState slider light up
unmodified. VendorSplitPolicy is the single 0xDC41CB0 mask owner; the
slider VALUE seeds to 1 for exempt items while maxSplitSize keeps the
stack (the splitSize/maxSplitSize distinction, research §B.3).
Selection clears at retail's actual site — VendorItemsUI::RemoveFromShop
(pc:202848), not a CloseVendor-level clear that does not exist.

6.3 BuildBuy (0x005F): vendorGuid, count, (i32 amount, u32 guid) pairs,
and the trailing alternateCurrencyId the REAL client sends
(CM_Vendor::Event_Buy pc:689288) though ACE's reader ignores it.
TryBuy rides the EXISTING J5.2 one-request-at-a-time reservation and
completes on UseDone; the Buy button disables while a request is in
flight. The reconciliation round-trip (money property update, inventory
CreateObject, ApproachVendor refresh -> panel rebuild) is proven by a
synthetic-inbound test against existing machinery — no new owner.

Register: AP-161 narrowed (selection + examine residuals close;
staging/Sell remain; double-click-to-buy confirmed ABSENT from retail
with negative evidence cited — we match retail). AP-162 files the
conscious no-client-side-affordability-precheck deferral.

Clean-room complete solution: 11,368 passed / 4 skipped / 0 failed.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-08-07 20:28:26 +02:00

127 lines
4.7 KiB
C#

using System;
using System.Buffers.Binary;
using AcDream.Core.Net.Messages;
using Xunit;
namespace AcDream.Core.Net.Tests.Messages;
/// <summary>
/// Slice 6.3 golden-byte coverage for the outbound Buy (<c>0x005F</c>)
/// builder — research doc §A.1's four-way-confirmed wire layout, including
/// the trailing <c>alternateCurrencyId</c> field the real retail client
/// sends but ACE's reader currently ignores.
/// </summary>
public sealed class VendorRequestsTests
{
[Fact]
public void BuildBuy_SingleItem_WritesEnvelopeSequenceOpcodeVendorCountAndItem()
{
byte[] body = VendorRequests.BuildBuy(
gameActionSequence: 9,
vendorGuid: 0x40001000u,
amount: 1,
itemGuid: 0x50002000u,
alternateCurrencyId: 0u);
// envelope(4) + seq(4) + opcode(4) + vendorGuid(4) + itemCount(4)
// + 1*(amount(4)+guid(4)) + trailing currency(4) = 32.
Assert.Equal(32, body.Length);
Assert.Equal(VendorRequests.GameActionEnvelope,
BinaryPrimitives.ReadUInt32LittleEndian(body.AsSpan(0)));
Assert.Equal(9u,
BinaryPrimitives.ReadUInt32LittleEndian(body.AsSpan(4)));
Assert.Equal(VendorRequests.BuyOpcode,
BinaryPrimitives.ReadUInt32LittleEndian(body.AsSpan(8)));
Assert.Equal(0x005Fu, VendorRequests.BuyOpcode);
Assert.Equal(0x40001000u,
BinaryPrimitives.ReadUInt32LittleEndian(body.AsSpan(12)));
Assert.Equal(1u,
BinaryPrimitives.ReadUInt32LittleEndian(body.AsSpan(16)));
Assert.Equal(1,
BinaryPrimitives.ReadInt32LittleEndian(body.AsSpan(20)));
Assert.Equal(0x50002000u,
BinaryPrimitives.ReadUInt32LittleEndian(body.AsSpan(24)));
// Trailing alternateCurrencyId — present even for a pyreal (0) vendor,
// matching retail's CM_Vendor::Event_Buy which writes it unconditionally.
Assert.Equal(0u,
BinaryPrimitives.ReadUInt32LittleEndian(body.AsSpan(28)));
}
[Fact]
public void BuildBuy_StackedItem_WritesTheSplitSliderQuantityAsAPlainPositiveAmount()
{
// amount is NOT ItemProfile's packed sign-extended supply-count
// field -- it's a plain positive int32 (research doc §A.1).
byte[] body = VendorRequests.BuildBuy(
gameActionSequence: 1,
vendorGuid: 0x40001000u,
amount: 25,
itemGuid: 0x50002001u,
alternateCurrencyId: 0u);
Assert.Equal(25,
BinaryPrimitives.ReadInt32LittleEndian(body.AsSpan(20)));
}
[Fact]
public void BuildBuy_AlternateCurrencyVendor_WritesTheVendorsTradeWcidTrailing()
{
byte[] body = VendorRequests.BuildBuy(
gameActionSequence: 1,
vendorGuid: 0x40001000u,
amount: 1,
itemGuid: 0x50002000u,
alternateCurrencyId: 0x12345678u);
Assert.Equal(0x12345678u,
BinaryPrimitives.ReadUInt32LittleEndian(body.AsSpan(28)));
}
[Fact]
public void BuildBuy_ListOverload_MultipleItems_WritesEachAmountGuidPairInOrder()
{
byte[] body = VendorRequests.BuildBuy(
gameActionSequence: 4,
vendorGuid: 0x40001000u,
items: new (int Amount, uint ItemGuid)[]
{
(1, 0x50002000u),
(10, 0x50002001u),
},
alternateCurrencyId: 0u);
// 24 + 2*8 = 40.
Assert.Equal(40, body.Length);
Assert.Equal(2u,
BinaryPrimitives.ReadUInt32LittleEndian(body.AsSpan(16)));
Assert.Equal(1,
BinaryPrimitives.ReadInt32LittleEndian(body.AsSpan(20)));
Assert.Equal(0x50002000u,
BinaryPrimitives.ReadUInt32LittleEndian(body.AsSpan(24)));
Assert.Equal(10,
BinaryPrimitives.ReadInt32LittleEndian(body.AsSpan(28)));
Assert.Equal(0x50002001u,
BinaryPrimitives.ReadUInt32LittleEndian(body.AsSpan(32)));
// Trailing currency still lands after every item pair.
Assert.Equal(0u,
BinaryPrimitives.ReadUInt32LittleEndian(body.AsSpan(36)));
}
[Fact]
public void BuildBuy_SingleItemOverload_MatchesTheGeneralListOverload()
{
byte[] viaSingle = VendorRequests.BuildBuy(
gameActionSequence: 3,
vendorGuid: 0x40001000u,
amount: 5,
itemGuid: 0x50002000u,
alternateCurrencyId: 7u);
byte[] viaList = VendorRequests.BuildBuy(
gameActionSequence: 3,
vendorGuid: 0x40001000u,
items: new (int Amount, uint ItemGuid)[] { (5, 0x50002000u) },
alternateCurrencyId: 7u);
Assert.Equal(viaList, viaSingle);
}
}