aorecomp

Anarchy Online classic in the browser

git clone https://aorecomp.ubeagle.com/code/aorecomp.git


commit e1c1c51d31891f2ef31335d8d270ca16e8ebf930
parent 1cb422bfdd38ea74ec27361cbae92e58b25aad91
Author: anon <anon@example.com>
Date:   Sun, 25 Oct 2026 06:19:16 +0000

Support charged medical shop purchases

Diffstat:
MTODO.md | 19++++++++++++++++---
Mdocs/shops.md | 88+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------------
Mserver/gamedata/shop_stock.yaml | 12++++++++++--
Mserver/shop_purchases_test.go | 239++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
Mserver/shops.go | 5++++-
5 files changed, 343 insertions(+), 20 deletions(-)

diff --git a/TODO.md b/TODO.md @@ -602,11 +602,24 @@ introduction and starting-item gameplay remain open below. concurrent/repeated Accept, lost replies and SQLite failure/retry. Native purchase icons and removal use a distinct catalog GUI tag. Pending-funds checks prevent rapid Adds from creating invisible server selections. -- [ ] Extend purchases to charged/partially used stacks, weapons, backpacks - and interpolated stock. Establish package sizes, slot packing, native live - object delivery and any merging rules before admitting these categories. +- [x] Buy charged medical packages from a supported basic-terminal subset. + QL1 laboratories/rechargers retain 50 charges and nano kits 25; prices are + per package. One package creates one durable record and first-free slot. + Cover removal/cancel, existing partial stacks, insufficient funds/space, + second-package SQLite failure/retry, partial sales and purchase-to-use + persistence. Full historical stock and automatic merging remain unresolved; + the evidence and reconstruction policy are in [shops](docs/shops.md). +- [ ] Extend purchases to weapons, backpacks and interpolated stock. Establish + native live object delivery and any packing rules before admitting these categories. Cover full inventory, freed sale slots, partial failure and stable ownership across reconnect/restart without inventing extra packet identity fields. +- [ ] Recover medical and ammunition stock membership and QL generation beyond + the current basic QL1 recovery subset. Original medical descriptions establish + broad families, while tier descriptors differ; do not copy basic stock into + advanced/superior or starter terminals. Four ordinary ammo definitions have + 100-round packages, but their exact booth bindings remain unresolved. Reuse + the item/vendor hashes, descriptors and placements in + `local/charged-shop-research/catalog/README.md` and the period source audit. - [x] Sell one inventory item. Check: ownership and credits change once and repeating the request cannot sell the same item twice. The original Omni and Clan starter terminals and restored room terminals support atomic sales, diff --git a/docs/shops.md b/docs/shops.md @@ -4,7 +4,8 @@ The server restores the original vending-machine placements and accepts staged sales from ordinary inventory. An offer remains owned by the player until Accept commits its removal and the credit award in one SQLite transaction. Cancel and removing an offer restore the same item. Tools, Devices and General -Tools and Bases expose documented fixed entries and accept purchases. Complete historical +Tools and Bases expose documented fixed entries. Basic medical terminals offer +a supported QL1 subset with authored charges. Complete historical stock membership, random generation and stock rotation remain unresolved. ## Original placements and access @@ -65,13 +66,13 @@ resource payloads found category descriptors but no authoritative membership list. See `local/shop-research/stock/README.md`; starter-looking item names are insufficient evidence for a purchase catalog. -## Documented fixed stock and purchases +## Supported fixed stock and purchases The original Anarchy Arcanum NCU Hacker Interface guide, updated 19 February 2003 and [captured 7 March 2003](https://web.archive.org/web/20030307043050id_/http://home.c2i.net:80/ellusion/gadgets_ncuhackerinterface.html), explicitly places Lock Pick in the local Tools booth. Original item 95577 is Lock Pick, fixed QL 1, type 51005, price stat 74 equal to 230. -`shop_stock.yaml` binds documented fixed entries to original terminal templates: +`shop_stock.yaml` binds supported fixed entries to original terminal templates: | Terminal family | Templates | Item | Native type | QL | Base price | | --- | --- | --- | --- | --- | --- | @@ -79,6 +80,9 @@ Lock Pick, fixed QL 1, type 51005, price stat 74 equal to 230. | Devices | 9 | Nano Programming Interface 161699 | 51022 | 1 | 900 | | General Tools and Bases | 3 | Expendable Hologram Camera 156054 | 51005 | 1 | 1300 | | General Tools and Bases | 3 | ID-extractor 156339 | 51005 | 1 | 9500 | +| Basic medical supplies | 3 | Treatment Laboratory 25812 | 51005 | 1 | 150 | +| Basic medical supplies | 3 | Simple Nano Kit 85366 | 51005 | 1 | 20 | +| Basic medical supplies | 3 | Basic Nano Recharger 25820 | 51005 | 1 | 250 | The original Personal Lockpick guide, updated 28 August 2002 and [captured 7 March 2003](https://web.archive.org/web/20030307031410id_/http://home.c2i.net:80/ellusion/gadgets_personallockpick.html), @@ -104,6 +108,26 @@ HKJM and ABEG, respectively, but these opaque descriptors are not treated as recovered membership lists or QL rules. The bounded audit is retained under `local/shop-stock-expansion-research/`. +Medical stock is a bounded reconstruction, rather than a recovered exact list. +Original Budget MediStim Shop 25886 and AllOverYou MediStim Shop 27062 descriptions +explicitly sell First Aid Kits, Nano Recharging Kits and other stims. Their DMLA +category is shared only by medical vendors in the retained 428-template catalog. +The basic faction/neutral templates 99481/99508/99574 repeat descriptor byte pairs +1/1 through 20/20; advanced and superior descriptors differ. The current subset +selects the three supported regular QL1 recovery definitions for basic terminals +only. Family membership and the authored definitions support this inference; +neither the descriptions nor opaque descriptors enumerate these exact IDs. +Advanced/superior, starter and ammunition stock remain unresolved. + +The original Anarchy Arcanum treatment guide, updated 27 June 2003 and +[captured 10 September 2003](https://web.archive.org/web/20030910134725id_/http://home.c2i.net:80/ellusion/pharmacy_treatment.html), +independently describes 50-charge laboratories and 25-charge First-Aid packages +and the importance of matching qualities for stacking. It describes crafting +components, not the regular terminal's exact stock. The capture postdates the +target; its page date and limited corroborating use are retained explicitly. +The fresh original item/vendor records, hashes, descriptions and placement audit +are under `local/charged-shop-research/catalog/`; source bytes are under `sources/`. + ShopUpdate key 0x58362220 belongs to the selected machine. Its body is a count token `(entries + 1) * 1009`, followed by low template, high template and QL for each entry. It contains neither prices nor owned identities. The native @@ -144,9 +168,18 @@ Complete, AddTemplate for each purchase, and absolute cash stat 61. AddTemplate carries `{low,high,QL,count}` and initially creates a native template entry with null instance identity. The durable server item identity survives reconnect, whose full inventory supplies it. No extra ID word is invented in either -packet. Delivery and package packing for charged stacks, weapons, containers -and interpolated stock remain separate work; current stock admission tests -require exact, nonstacking template items of type 51005 or 51022. The interface +packet. Charged stackable type 51005 purchases carry the positive authored +stat 212 count: laboratories/rechargers 50 and nano kits 25. KKR 1005ef90/1002d580 +copies AddTemplate's count directly into one native row; it does not multiply +by 212 or expand packages. KKR 100a9710 displays selected packages times 212, +while the quote still prices whole packages. One selected package therefore +creates one durable record/slot and one AddTemplate with its full charge count. +This packing policy keeps native first-free allocation aligned with SQLite; +automatic merging, historical stack limits and original server packing remain +unknown. Existing partial stacks do not absorb purchases. Explicit joins remain +separate inventory actions. Admission tests require representable positive +counts and exact supported types; weapons, containers and interpolated stock +remain separate work. The interface uses the shared [stat-equipment path](stat-equipment.md) for HUD/utility wear. The buy quote recovered from KKR 0x100a9610 is: @@ -295,8 +328,11 @@ multiple selected packages and removal, cancellation, insufficient cash and space, forged catalog references, Unique acquisition, mixed sale funding and freed slots, concurrent/repeated confirmation, lost replies and SQLite failure with retry. Rapid unfunded Adds abort before they can leave a server purchase -absent from the native basket. Stock admission tests keep unverified charged, -weapon and container delivery outside the fixed template catalog. +absent from the native basket. Charged tests verify separate package records, +exact AddTemplate counts, unchanged partial stacks, second-package rollback, +charge-normalized sales and purchase-to-use persistence with cooldown rejection. +Stock admission tests require positive representable charge counts and keep +weapon/container delivery outside the fixed template catalog. Two headed Chromium WASM clients ran on the GPU. Before restoration, Omni room 1183 had the static identity but no native vending object or visible @@ -347,6 +383,29 @@ path are recorded in [stat equipment](stat-equipment.md). Native picking in world 1191 also opened Computers 3221292199 with no inferred Tools catalog and preserved both purchased tools and cash. +The charged-purchase run used two fresh GPU WASM clients. Two Simple Nano +Kit packages displayed 50 charges for 40 credits; removing one left 25 for 20, +and cancelling spent nothing. An Omni basket containing one laboratory, two +nano kits and one recharger cost 437 and delivered four separate stacks with +50/25/25/50 charges. Native count words, captured AddTemplate counts and SQLite +agreed. Using the supplies left 49/24/25/49 charges; a repeated nano-kit use +during cooldown and a standing laboratory attempt consumed nothing. Laboratory +and recharger use each restored exactly 30 to the appropriate resource. + +Selling the 24-charge kit for 1 and buying a fresh 25-charge package for 20 +reused its freed slot without merging into another existing kit. Both native +and durable cash became 19544. Neutral basic medical supplies sold a 50-charge +recharger for 260; Clan sold a 25-charge nano kit for 21. Cold server startup +followed by fresh clients retained every purchased instance, count and balance. + +An owned capacity fixture occupied 29 of 30 slots, including an existing nano +kit. Selecting two more packages for 42 and accepting rejected the whole draft: +cash, all 29 items and native rows stayed unchanged, the basket cleared, and no +AddTemplate was sent. After cold startup, one package filled the final slot +with the next unused durable ID, proving the rejected draft had published no +allocation. A subsequent purchase with all 30 slots occupied also rejected +without changing cash or merging stacks. Reconnect retained all 30 items. + `local/shop-room-research/` retains the independent catalog audit, reproducible extraction provenance and original-client access evidence. `local/shop-room-smoke/` retains screenshots, native memory snapshots, database @@ -358,10 +417,13 @@ the dummy-HDMI display's power-saving state is restored afterward. snapshots, WebSocket captures and assertion script. `local/shop-stock-expansion-smoke/` retains the additional terminal, multi-row purchase, worn Unique, observer-effect and cold-recovery checks. - -The complete tracked Go suite passed (server 707 seconds, gamedata 8 seconds), -as did shop/utility/belt/clothing race checks (184 seconds), the additional -catalog-belt/data-binding checks, and `go vet -stdversion=false`. -Cleanup removed only the two test-owned players. All unrelated database rows +`local/charged-shop-smoke/` retains charged package, partial-sale, medical-use, +three-faction, capacity and cold-recovery captures and assertions. + +The complete tracked Go suite passed (server 713 seconds, gamedata 8 seconds), +as did shop/medical race checks (179 seconds), the final focused shop suite +(27 seconds), and `go vet -stdversion=false`. +Cleanup removed only the two test-owned players and their 34 remaining items. +All unrelated database rows were unchanged, foreign-key and integrity checks passed, and the single shared HTTPS preview remains available on port 8443. diff --git a/server/gamedata/shop_stock.yaml b/server/gamedata/shop_stock.yaml @@ -1,6 +1,7 @@ -# Documented fixed stock by original terminal template, not opaque ACG code. +# Fixed supported stock by original terminal template, not opaque ACG code. # Anarchy Arcanum, NCU Hacker Interface (19 February 2003) and Personal Lockpick -# (28 August 2002). See docs/shops.md for source provenance and remaining gaps. +# (28 August 2002). Original medical-family descriptions support the basic +# medical subset. See docs/shops.md for source provenance and remaining gaps. # Tools: Lock Pick. 99491: [95577] @@ -28,3 +29,10 @@ 155284: [156054, 156339] 155285: [156054, 156339] 155286: [156054, 156339] + +# Basic medical supplies: supported QL1 subset. Original medical-family +# descriptions and package definitions; full generation is unresolved. +# See docs/shops.md for the reconstruction policy and evidence bounds. +99481: [25812, 85366, 25820] +99508: [25812, 85366, 25820] +99574: [25812, 85366, 25820] diff --git a/server/shop_purchases_test.go b/server/shop_purchases_test.go @@ -66,9 +66,27 @@ func TestShopKnownStockOnlyAdmitsSupportedFixedTemplateItems(t *testing.T) { } for _, template := range templates { definition := gamedata.ItemTemplates[template] - if definition == nil || definition.Quality == nil || (definition.HeaderWords[0] != 51005 && definition.HeaderWords[0] != 51022) || int32(itemStat(definition, 212)) > 0 { + if definition == nil || definition.Quality == nil || (definition.HeaderWords[0] != 51005 && definition.HeaderWords[0] != 51022) { t.Fatalf("stock %d needs a separately verified delivery/packing path", template) } + item := ownedItem{Type: definition.HeaderWords[0], Template: template} + charges := int32(itemStat(definition, 212)) + if (item.isStackable() && (charges < 1 || charges > 65535)) || (!item.isStackable() && charges > 0) { + t.Fatalf("stock %d cannot represent its authored package count %d", template, charges) + } + } + } +} + +func TestShopMedicalSubsetRetainsBasicTerminalBoundary(t *testing.T) { + for _, template := range []uint32{99481, 99508, 99574} { + if !slices.Equal(gamedata.ShopStock[template], []uint32{25812, 85366, 25820}) { + t.Fatal("basic medical stock changed", template) + } + } + for _, template := range []uint32{99482, 99483, 99509, 99529, 99575, 151975, 25885, 81799} { + if len(gamedata.ShopStock[template]) != 0 { + t.Fatal("basic medical subset leaked into an unresolved terminal", template) } } } @@ -373,3 +391,222 @@ func TestShopPendingSaleFundingRetainsNativeSignedRowArithmetic(t *testing.T) { } } } + +func newMedicalPurchaseWorld(t *testing.T) (*server, *combatTestConn) { + t.Helper() + world, conn := newPurchaseWorld(t) + player := world.characters[1] + player.position = [3]float32{185, 5.75, 135.6} + request := shopUseRequest(2) + binary.BigEndian.PutUint32(request[44:48], 3221423263) + if err := world.handleShopUse(world.clients[1], request); err != nil { + t.Fatal(err) + } + return world, conn +} + +func TestShopChargedPackagesKeepCountsSlotsPricesAndDurableIdentities(t *testing.T) { + world, conn := newMedicalPurchaseWorld(t) + client, player := world.clients[1], world.characters[1] + // An existing partial package must not silently absorb a new purchase. + player.inventory.Items[0] = ownedItem{ID: 1, Type: 51005, Template: 85366, Quality: 1, Slot: 64, Count: 7} + if err := world.saveInventory_locked(player, player.inventory); err != nil { + t.Fatal(err) + } + for _, index := range []uint32{1, 1, 0, 2} { + if err := world.handleShopTrade(client, shopTradePacket([2]uint32{50000, 1}, 4, [2]uint32{51035, 3221423263}, [2]uint32{111, index})[20:]); err != nil { + t.Fatal(err) + } + } + conn.packets = nil + + err := world.handleShopTrade(client, shopTradePacket([2]uint32{50000, 1}, 1, [2]uint32{}, [2]uint32{})[20:]) + world.handleShopTrade(client, shopTradePacket([2]uint32{50000, 1}, 1, [2]uint32{}, [2]uint32{})[20:]) + restored := newTestInventoryServer(t).characters[1].inventory + + expected := []ownedItem{ + {ID: 1, Type: 51005, Template: 85366, Quality: 1, Slot: 64, Count: 7}, + {ID: 2, Type: 51005, Template: 25812, Quality: 1, Slot: 65, Count: 50}, + {ID: 3, Type: 51005, Template: 85366, Quality: 1, Slot: 66, Count: 25}, + {ID: 4, Type: 51005, Template: 85366, Quality: 1, Slot: 67, Count: 25}, + {ID: 5, Type: 51005, Template: 25820, Quality: 1, Slot: 68, Count: 50}, + } + if err != nil || restored.Credits != 563 || world.nextItem != 5 || !reflect.DeepEqual(restored.Items, expected) || !reflect.DeepEqual(player.inventory.Items, expected) { + t.Fatalf("charged packages changed count, cost or ownership: %v %+v", err, restored) + } + if len(conn.packets) != 6 || binary.BigEndian.Uint32(conn.packets[0][33:37]) != 3 || binary.BigEndian.Uint32(conn.packets[5][33:37]) != 563 { + t.Fatal("charged completion/cash ordering changed") + } + for index, fields := range [][4]uint32{{25812, 25812, 1, 50}, {85366, 85366, 1, 25}, {85366, 85366, 1, 25}, {25820, 25820, 1, 50}} { + packet := conn.packets[index+1] + if len(packet) != 48 || binary.BigEndian.Uint32(packet[16:20]) != 0x052e2f0c { + t.Fatal("wrong charged delivery shape") + } + for field, value := range fields { + if binary.BigEndian.Uint32(packet[29+field*4:]) != value { + t.Fatal("charged delivery lost package count", fields) + } + } + } +} + +func TestShopChargedPurchaseRemoveAndCancelConsumeNoChargesOrCash(t *testing.T) { + for _, action := range []uint32{2, 5} { + t.Run(string(rune('0'+action)), func(t *testing.T) { + world, _ := newMedicalPurchaseWorld(t) + client, player := world.clients[1], world.characters[1] + before := slices.Clone(player.inventory.Items) + first, second := [2]uint32{51035, 3221423263}, [2]uint32{111, 1} + if err := world.handleShopTrade(client, shopTradePacket([2]uint32{50000, 1}, 4, first, second)[20:]); err != nil { + t.Fatal(err) + } + if action == 2 { + first, second = [2]uint32{}, [2]uint32{} + } + + err := world.handleShopTrade(client, shopTradePacket([2]uint32{50000, 1}, action, first, second)[20:]) + if action == 5 { + err = world.handleShopTrade(client, shopTradePacket([2]uint32{50000, 1}, 1, [2]uint32{}, [2]uint32{})[20:]) + } + restored := newTestInventoryServer(t).characters[1].inventory + + if err != nil || restored.Credits != 1000 || world.nextItem != 1 || !reflect.DeepEqual(restored.Items, before) { + t.Fatal("charged removal/cancel changed ownership", err, restored) + } + }) + } +} + +func TestShopChargedPurchaseCapacityAndFinalFundsRejectWholeBasket(t *testing.T) { + for _, scenario := range []string{"existing stack no slot", "two packages one slot", "cash changed"} { + t.Run(scenario, func(t *testing.T) { + world, _ := newMedicalPurchaseWorld(t) + client, player := world.clients[1], world.characters[1] + player.inventory.Items[0] = ownedItem{ID: 1, Type: 51005, Template: 85366, Quality: 1, Slot: 64, Count: 7} + add := shopTradePacket([2]uint32{50000, 1}, 4, [2]uint32{51035, 3221423263}, [2]uint32{111, 1})[20:] + world.handleShopTrade(client, add) + last := uint32(94) + if scenario == "two packages one slot" { + last = 93 + world.handleShopTrade(client, add) + } + if scenario == "cash changed" { + player.inventory.Credits, last = 18, 65 + } + for slot := uint32(65); slot < last; slot++ { + player.inventory.Items = append(player.inventory.Items, ownedItem{ID: slot - 63, Type: 51005, Template: 85366, Quality: 1, Slot: slot, Count: 7}) + } + player.inventory.LastID = uint32(len(player.inventory.Items)) + if err := world.saveInventory_locked(player, player.inventory); err != nil { + t.Fatal(err) + } + before := player.inventory + before.Items = slices.Clone(before.Items) + next := world.nextItem + + err := world.handleShopTrade(client, shopTradePacket([2]uint32{50000, 1}, 1, [2]uint32{}, [2]uint32{})[20:]) + restored := newTestInventoryServer(t).characters[1].inventory + + if err != nil || client.shop != nil || world.nextItem != next || !reflect.DeepEqual(player.inventory, before) || restored.Credits != before.Credits || !reflect.DeepEqual(restored.Items, before.Items) { + t.Fatal("rejected charged basket changed ownership", err, restored) + } + }) + } +} + +func TestShopPartialPackageSaleAndPurchaseUseWholePackageQuote(t *testing.T) { + world, _ := newMedicalPurchaseWorld(t) + client, player := world.clients[1], world.characters[1] + player.inventory.Items[0] = ownedItem{ID: 1, Type: 51005, Template: 25820, Quality: 1, Slot: 64, Count: 10} + player.inventory.Credits = 20 + if err := world.saveInventory_locked(player, player.inventory); err != nil { + t.Fatal(err) + } + for _, request := range [][]byte{ + shopTradePacket([2]uint32{50000, 1}, 4, [2]uint32{50000, 1}, [2]uint32{104, 64})[20:], + shopTradePacket([2]uint32{50000, 1}, 4, [2]uint32{51035, 3221423263}, [2]uint32{111, 1})[20:], + } { + if err := world.handleShopTrade(client, request); err != nil { + t.Fatal(err) + } + } + + err := world.handleShopTrade(client, shopTradePacket([2]uint32{50000, 1}, 1, [2]uint32{}, [2]uint32{})[20:]) + restored := newTestInventoryServer(t).characters[1].inventory + + if err != nil || restored.Credits != 3 || len(restored.Items) != 1 || restored.Items[0] != (ownedItem{ID: 2, Type: 51005, Template: 85366, Quality: 1, Slot: 64, Count: 25}) { + t.Fatalf("partial sale/package purchase did not settle atomically: %v %+v", err, restored) + } +} + +func TestShopChargedPurchaseRollbackThenRetryKeepsWholePackages(t *testing.T) { + world, conn := newMedicalPurchaseWorld(t) + client, player := world.clients[1], world.characters[1] + add := shopTradePacket([2]uint32{50000, 1}, 4, [2]uint32{51035, 3221423263}, [2]uint32{111, 1})[20:] + world.handleShopTrade(client, add) + world.handleShopTrade(client, add) + if _, err := world.db.Exec("CREATE TRIGGER reject_package BEFORE INSERT ON items WHEN NEW.id=3 BEGIN SELECT RAISE(FAIL, 'second package'); END"); err != nil { + t.Fatal(err) + } + conn.packets = nil + accept := shopTradePacket([2]uint32{50000, 1}, 1, [2]uint32{}, [2]uint32{})[20:] + + failed := world.handleShopTrade(client, accept) + rejected := newTestInventoryServer(t).characters[1].inventory + if failed == nil || player.inventory.Credits != 1000 || len(player.inventory.Items) != 1 || world.nextItem != 1 || client.shop == nil || rejected.Credits != 1000 || len(rejected.Items) != 1 || len(conn.packets) != 0 { + t.Fatal("failed second package published a partial basket") + } + if _, err := world.db.Exec("DROP TRIGGER reject_package"); err != nil { + t.Fatal(err) + } + err := world.handleShopTrade(client, accept) + restored := newTestInventoryServer(t).characters[1].inventory + + if err != nil || restored.Credits != 960 || len(restored.Items) != 3 || restored.Items[1].ID != 2 || restored.Items[2].ID != 3 || restored.Items[1].Count != 25 || restored.Items[2].Count != 25 || world.nextItem != 3 { + t.Fatal("charged retry lost or duplicated package ownership", err, restored) + } +} + +func TestShopPurchasedMedicalPackagesCanBeUsedAndPersistRemainingCharges(t *testing.T) { + for _, scenario := range []struct { + name string + index, template, credits, health, nanoLow, nanoHigh, skill uint32 + count uint16 + }{ + {"laboratory", 0, 25812, 851, 31, 1, 1, 124, 49}, + {"nano kit", 1, 85366, 980, 1, 11, 13, 123, 24}, + {"recharger", 2, 25820, 752, 1, 31, 31, 131, 49}, + } { + t.Run(scenario.name, func(t *testing.T) { + world, _ := newMedicalPurchaseWorld(t) + client, player := world.clients[1], world.characters[1] + player.level = 50 + player.stats.Body.BodyDevelopment, player.stats.Body.NanoPool = 100, 100 + player.stats.NanoAiding.Treatment, player.stats.NanoAiding.FirstAid, player.stats.NanoAiding.TimeAndSpace = 50, 50, 50 + player.health, player.nano, player.sitting = 1, 1, true + client.selectedTarget = [2]uint32{50000, 1} + if err := world.saveUser_locked(player); err != nil { + t.Fatal(err) + } + for _, request := range [][]byte{ + shopTradePacket([2]uint32{50000, 1}, 4, [2]uint32{51035, 3221423263}, [2]uint32{111, scenario.index})[20:], + shopTradePacket([2]uint32{50000, 1}, 1, [2]uint32{}, [2]uint32{})[20:], + } { + if err := world.handleShopTrade(client, request); err != nil { + t.Fatal(err) + } + } + + err := world.handleOwnedItemUse(client, backpackUseRequest(1, 65, 3)[20:]) + world.handleOwnedItemUse(client, backpackUseRequest(1, 65, 4)[20:]) + restored := newTestInventoryServer(t).characters[1] + + if err != nil || restored.inventory.Credits != scenario.credits || len(restored.inventory.Items) != 2 || + restored.inventory.Items[1] != (ownedItem{ID: 2, Type: 51005, Template: scenario.template, Quality: 1, Slot: 65, Count: scenario.count}) || + restored.health != scenario.health || restored.nano < scenario.nanoLow || restored.nano > scenario.nanoHigh || + !reflect.DeepEqual(restored.inventory.Items, player.inventory.Items) || restored.skillLocks[scenario.skill].IsZero() { + t.Fatal("purchased medical use, cooldown or durable charges mismatch", err, restored.inventory, restored.health, restored.nano) + } + }) + } +} diff --git a/server/shops.go b/server/shops.go @@ -313,6 +313,9 @@ func (server *server) handleShopTrade(client *worldClient, body []byte) error { for index, template := range client.shop.stock { definition := gamedata.ItemTemplates[template] item := ownedItem{Type: definition.HeaderWords[0], Template: template, Quality: *definition.Quality, Count: 1} + if item.isStackable() { + item.Count = uint16(itemStat(definition, 212)) + } count := client.shop.purchases[uint32(index)] cost += shopBuyPrice(item, itemStat(gamedata.ItemTemplates[machine.Template], 427), literacy) * uint64(count) for range count { @@ -358,7 +361,7 @@ func (server *server) handleShopTrade(client *worldClient, body []byte) error { // Native catalog entries have no instance identity; durable IDs live in SQLite. for _, item := range purchased { var body []byte - for _, value := range []uint32{item.Template, item.Template, item.Quality, 1} { + for _, value := range []uint32{item.Template, item.Template, item.Quality, uint32(item.Count)} { body = binary.BigEndian.AppendUint32(body, value) } if err := client.send(n3Packet(0x052e2f0c, 50000, client.id, body)); err != nil {