aorecomp

Anarchy Online classic in the browser

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


commit 324b4dccf928c66adc492b43195db6262d06a6f0
parent 420c822299146f332118f12c26d78dc3d2bed9c3
Author: anon <anon@example.com>
Date:   Thu,  5 Nov 2026 20:56:43 +0000

Add early weapon upgrades to faction basic shops

Diffstat:
MTODO.md | 13+++++++++----
Mdocs/early-shop-stock.md | 76+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-----
Aserver/basic_shop_weapons_test.go | 95+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Aserver/browser_basic_shop_weapons_test.go | 125+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mserver/gamedata/shop_stock.yaml | 22++++++++++++++++++----
Mserver/shop_ammunition_test.go | 2+-
Mserver/shop_purchases_test.go | 3++-
Atools/client/test_basic_shop_weapons.mjs | 142+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
8 files changed, 463 insertions(+), 15 deletions(-)

diff --git a/TODO.md b/TODO.md @@ -112,10 +112,15 @@ research separately. More screenshots and test cases do not count as new gamepla 1180/1183/1186. The four empty training terminals now carry seven original QL1 recovery/ammunition packages under an explicit provisional stock policy; all four pass native buy/sell, cancel, recovery use, bullet reload, reconnect - and cold recovery checks. 159 placements still have no catalog rows. Basic - weapon terminals supply ammunition but no weapons. Next fill basic upgrades and profession essentials, - explicitly identify deferred specialty terminals and verify affordability - against ordinary rewards. Funded fixtures do not establish affordability. + and cold recovery checks. 159 placements still have no catalog rows. The three + basic weapon terminals now add QL5/10 M-10 pistols, E-Beamers, Vektors and + Sledgehammers alongside ammunition. All three pass native purchase, equip, + reload/attack, cancellation, reconnect and cold recovery for these families. + Rifle/SMG upgrades, profession essentials, + visible specialty-terminal limitations and ordinary-reward affordability + remain open. Funded fixtures do not establish affordability; the stock ledger + also records unfinished weapon specials rather than claiming complete combat + support from a successful ordinary attack. ## P0: playable and releasable diff --git a/docs/early-shop-stock.md b/docs/early-shop-stock.md @@ -10,8 +10,8 @@ browse/buy/use behavior. Baseline: 163 placements had no catalog rows, including all four training-ground terminals. The training terminals now each carry seven recovery/ammunition rows, -leaving 159 empty placements. The three basic weapon terminals still contain four -ammunition packages and no weapons. Profession crystal terminals are also empty. +leaving 159 empty placements. The three basic weapon terminals now contain four +ammunition packages and eight weapon rows. Profession crystal terminals remain empty. ## Training-ground resupply @@ -63,6 +63,72 @@ its trace showed the correct treatment gain before that tick. The corrected per-use assertion passed. No historical stock research or ordinary-play funding check is claimed by this change. A5 remains open. +## Basic weapon upgrades + +The Omni, Clan and Neutral basic weapon terminals share a fixed QL5/10 subset +of four reviewed original families. Membership and fixed qualities are explicit +alpha policy, not recovered historical stock or rotation. The four existing +ammunition rows stay first; Budget ammunition terminals retain their separate +four-row catalog. Original requirements, quality interpolation, package sizes, +buy/sale modifiers and empty finite-weapon magazines are preserved. + +| Original weapon | Template | QL | Omni price | Clan/Neutral price | Ammunition | +| --- | --- | --- | --- | --- | --- | +| Rusty OT M-10 Flechette Pistol | 123742 | 5 | 2525 | 2651 | Bullets | +| Rusty OT M-10 Flechette Pistol | 123742 | 10 | 3354 | 3521 | Bullets | +| Ill-Treated E-Beamer | 122121 | 5 | 3181 | 3340 | Energy | +| Ill-Treated E-Beamer | 122121 | 10 | 4185 | 4394 | Energy | +| Vektor ND Shotgun | 124258 | 5 | 2610 | 2740 | Energy | +| Vektor ND Shotgun | 124258 | 10 | 2948 | 3095 | Energy | +| Cracked Sledgehammer | 129026 | 5 | 1256 | 1318 | None | +| Cracked Sledgehammer | 129026 | 10 | 1653 | 1735 | None | + +Prices precede Computer Literacy discounts. Original family audits and consumer +coverage are in [M-10 pistols](catalog-weapons.md), [E-Beamers](e-beamer.md), +[Vektors](vektor-shotguns.md) and [Sledgehammers](sledgehammer.md). All four support +ordinary attacks. M-10/E-Beamer Fling uses the existing handler. Sledgehammer +Brawl/Dimach remain unimplemented shared actions; stock does not complete them. +Rifle/SMG upgrades and profession nanos remain outstanding. These funded checks +do not establish that ordinary early rewards can pay the listed prices. + +### Weapon verification, November 5 + +The new production-stock regression first failed for all 24 faction/family/quality +combinations. All now pass purchase, exact price and identity, repeated Accept, +level-ten qualified wear and cold recovery. The checkpoint's raw skills and +abilities are checked against native training caps. It is not earned training. +Nine focused regression roots pass, including existing live-item rejected-write +and lost-reply checks, ammunition packages and selected-quality combat consumers. +The catalog guard now distinguishes weapon magazine capacity from charged-item +package counts. Budget terminals still contain only their four ammunition rows. + +`TestBrowserBasicShopWeapons` and `tools/client/test_basic_shop_weapons.mjs` pass +at all three basic weapon terminals. Each browses all 12 rows, buys the four +QL10 weapons plus Bullets/Energy packages, sells a controlled axe, reopens with E +and cancels a QL5 basket. Every purchased weapon equips and deals an ordinary hit +to a controlled Leet through real native input. The guns reload from purchased +ammunition and each shot consumes one round. Final clips are 19/19/39; the +remaining ammunition packages contain 80 Bullets and 40 Energy rounds. Page +reconnect and a cold database load preserve exact IDs, qualities, slots, clips, +package counts and cash: 38,512 Omni or 37,661 Clan/Neutral from fixture funds of +50,000. The Omni basic terminal's original sale modifier is 6%, versus 4% at the +other two. Catalog views were inspected; no client errors were recorded. + +Passing artifacts under `local/alpha-weapons/`: + +- Omni: `20261105-125448/c005049f` (`browser-omni-final.log`). +- Clan: `20261105-125250/c026049c` (`browser-omni-clan.log`). +- Neutral: `20261105-125039/c01204a2` (`browser-all.log`). +- Automated checks: `green.log`, `regressions.log`, `vet.log`. + +The browser fixture waits for recharge before swaps and uses deterministic +ordinary hits, including retaliation. It frames the nearby target by dragging +from clear wall space. Earlier setup failures were a sale-modifier assumption, +unframed target, premature weapon swap, forced critical retaliation and an +intermittently intercepted camera drag. The passing runs retain the full +purchase/use/recovery assertions. These checks close the missing stock for this +four-family subset, not A5's remaining content, specialty labels or affordability. + ## Placement census | Playfield | Terminal identity | Template | Original name | Stock rows | Position X, Y, Z | @@ -109,7 +175,7 @@ check is claimed by this change. A5 remains open. | 1180 | `0xc023049c` | 99513 | Clan Basic Augmentations | 0 | 194.07, 4.61, 181.14 | | 1180 | `0xc024049c` | 99508 | Clan Basic Medic Supplies | 3 | 191.89, 4.61, 163.94 | | 1180 | `0xc025049c` | 99527 | Clan Basic Tools | 2 | 207.15, 4.61, 162.87 | -| 1180 | `0xc026049c` | 99505 | Clan Basic Weapons | 4 | 209.83, 4.61, 163.72 | +| 1180 | `0xc026049c` | 99505 | Clan Basic Weapons | 12 | 209.83, 4.61, 163.72 | | 1180 | `0xc027049c` | 99526 | Clan Clothes | 0 | 191.44, 4.61, 180.06 | | 1180 | `0xc028049c` | 117749 | Clan Maps | 5 | 190.87, 4.61, 177.60 | | 1180 | `0xc029049c` | 155602 | Clan Basic Devices | 1 | 190.89, 4.61, 166.80 | @@ -131,7 +197,7 @@ check is claimed by this change. A5 remains open. | 1183 | `0xc002049f` | 99484 | OT Basic Augmentations | 0 | 182.00, 5.00, 131.60 | | 1183 | `0xc003049f` | 99481 | OT Basic Medical Supplies | 3 | 182.00, 5.00, 135.60 | | 1183 | `0xc004049f` | 99491 | OT Basic Tools | 2 | 192.00, 5.00, 135.50 | -| 1183 | `0xc005049f` | 99478 | OT Basic Weapons | 4 | 192.00, 5.00, 127.50 | +| 1183 | `0xc005049f` | 99478 | OT Basic Weapons | 12 | 192.00, 5.00, 127.50 | | 1183 | `0xc006049f` | 99490 | OT Clothes | 7 | 182.00, 5.00, 139.60 | | 1183 | `0xc007049f` | 117649 | OT Maps | 5 | 196.70, 5.00, 129.00 | | 1183 | `0xc008049f` | 155599 | Basic Bookstore | 0 | 192.00, 5.00, 131.00 | @@ -220,7 +286,7 @@ check is claimed by this change. A5 remains open. | 1186 | `0xc00f04a2` | 99598 | Basic Augmentations | 0 | 166.67, 5.00, 119.51 | | 1186 | `0xc01004a2` | 99574 | Basic Medic Supplies | 3 | 166.62, 5.00, 129.14 | | 1186 | `0xc01104a2` | 99601 | Basic Tools | 2 | 183.31, 5.00, 129.35 | -| 1186 | `0xc01204a2` | 99572 | Basic Weapons | 4 | 183.24, 5.00, 121.60 | +| 1186 | `0xc01204a2` | 99572 | Basic Weapons | 12 | 183.24, 5.00, 121.60 | | 1186 | `0xc01304a2` | 99637 | Clothes | 0 | 171.16, 5.00, 133.32 | | 1186 | `0xc01404a2` | 118050 | Maps | 5 | 179.03, 5.00, 133.33 | | 1186 | `0xc01504a2` | 155599 | Basic Bookstore | 0 | 180.75, 5.00, 116.68 | diff --git a/server/basic_shop_weapons_test.go b/server/basic_shop_weapons_test.go @@ -0,0 +1,95 @@ +package main + +import ( + "ao/server/gamedata" + "encoding/binary" + "fmt" + "reflect" + "slices" + "testing" +) + +func trainBasicShopWeaponFixture(t *testing.T, player *character) { + t.Helper() + player.level, player.profession = 10, 1 + player.stats.Abilities = characterAbilitiesStats{36, 36, 36, 36, 36, 36} + player.stats.Ranged.Pistol, player.stats.Ranged.Shotgun, player.stats.Ranged.RangedEnergy = 40, 40, 40 + player.stats.Ranged.AssaultRifle, player.stats.Ranged.FlingShot = 25, 22 + player.stats.Melee.TwoHandBlunt, player.stats.Body.Brawling, player.stats.Body.Dimach = 34, 20, 10 + player.stats.TradeRepair.ComputerLiteracy = 0 + for stat, raw := range map[uint32]uint16{16: 36, 17: 36, 18: 36, 19: 36, 20: 36, 21: 36, + 112: 40, 115: 40, 133: 40, 116: 25, 150: 22, 107: 34, 142: 20, 144: 10} { + if uint32(raw) > player.trainingMaximum(stat) { + t.Fatal("controlled level-ten skill exceeds native training cap", stat, raw, player.trainingMaximum(stat)) + } + } +} + +func TestBasicShopWeaponsPurchaseWearAndRecover(t *testing.T) { + for _, machineID := range []uint32{0xc005049f, 0xc026049c, 0xc01204a2} { + for index, row := range []gamedata.ShopItem{ + {Template: 123742, Quality: 5}, {Template: 123742, Quality: 10}, + {Template: 122121, Quality: 5}, {Template: 122121, Quality: 10}, + {Template: 124258, Quality: 5}, {Template: 124258, Quality: 10}, + {Template: 129026, Quality: 5}, {Template: 129026, Quality: 10}, + } { + t.Run(fmt.Sprintf("%x/%d/QL%d", machineID, row.Template, row.Quality), func(t *testing.T) { + world, _ := newPurchaseWorld(t) + player, client := world.characters[1], world.clients[1] + machine := gamedata.ShopMachines[machineID] + player.playfield, player.position = machine.Playfield, machine.Position + player.appearance = map[uint32]uint16{1183: 0x515, 1180: 0x315, 1186: 0x115}[machine.Playfield] + trainBasicShopWeaponFixture(t, player) + player.inventory.Credits = 10000 + if err := world.saveUser_locked(player); err != nil { + t.Fatal(err) + } + if err := world.saveInventory_locked(player, player.inventory); err != nil { + t.Fatal(err) + } + request := shopUseRequest(2) + binary.BigEndian.PutUint32(request[44:48], machineID) + + if err := world.handleShopUse(client, request); err != nil { + t.Fatal(err) + } + if client.shop == nil || len(client.shop.stock) != 12 || client.shop.stock[index+4] != row { + t.Fatal("basic weapon terminal lacks its early upgrade row") + } + if err := world.handleTrade(client, shopTradePacket([2]uint32{50000, 1}, 4, [2]uint32{51035, machineID}, [2]uint32{111, uint32(index + 4)})[20:]); err != nil { + t.Fatal(err) + } + accept := shopTradePacket([2]uint32{50000, 1}, 1, [2]uint32{}, [2]uint32{})[20:] + for range 2 { + if err := world.handleTrade(client, accept); err != nil { + t.Fatal(err) + } + } + if len(player.inventory.Items) != 2 || player.inventory.Items[1] != (ownedItem{ID: 2, Type: 51018, Template: row.Template, Quality: row.Quality, Slot: 65, Count: 1}) { + t.Fatal("purchase lost selected quality, live identity or empty clip", player.inventory) + } + if err := world.handleInventory(client, inventoryMovePacket(1, 65, 6)[20:]); err != nil || client.equipment == nil { + t.Fatal("level-ten checkpoint cannot wear purchased upgrade", err) + } + world.advanceEquipment(client.equipment.readyAt) + cold := newTestInventoryServer(t).characters[1] + prices := []uint32{2525, 3354, 3181, 4185, 2610, 2948, 1256, 1653} + if machine.Playfield != 1183 { + prices = []uint32{2651, 3521, 3340, 4394, 2740, 3095, 1318, 1735} + } + + if cold.inventory.Credits != 10000-prices[index] || cold.inventory.Items[1].Slot != 6 || cold.attackWeapon() == nil || *cold.attackWeapon().Quality != row.Quality || + !reflect.DeepEqual(cold.inventory, player.inventory) || world.nextItem != 2 { + t.Fatal("purchased upgrade changed during wear or cold recovery", cold.inventory) + } + }) + } + } + // Budget ammunition terminals keep their separate four-package scope. + if !slices.Equal(gamedata.ShopStock[25885], []gamedata.ShopItem{ + {Template: 21605, Quality: 1}, {Template: 21609, Quality: 1}, + {Template: 21613, Quality: 1}, {Template: 21601, Quality: 1}, + }) { + t.Fatal("basic weapon upgrades leaked into the budget ammunition catalog") + } +} diff --git a/server/browser_basic_shop_weapons_test.go b/server/browser_basic_shop_weapons_test.go @@ -0,0 +1,125 @@ +package main + +import ( + "ao/server/gamedata" + "context" + "crypto/sha256" + "encoding/json" + "fmt" + "math" + "net/http" + "net/http/httptest" + "os" + "os/exec" + "path/filepath" + "reflect" + "runtime" + "testing" + "time" +) + +func TestBrowserBasicShopWeapons(t *testing.T) { + if os.Getenv("AO_GAME_TEST") != "1" { + t.Skip("set AO_GAME_TEST=1 for the three basic weapon terminals") + } + _, source, _, _ := runtime.Caller(0) + root := filepath.Dir(filepath.Dir(source)) + output := filepath.Join(root, "local/alpha-weapons", time.Now().Format("20060102-150405")) + for _, identity := range []uint32{0xc005049f, 0xc026049c, 0xc01204a2} { + t.Run(fmt.Sprintf("%x", identity), func(t *testing.T) { + world := newTestServer(t) + machine := gamedata.ShopMachines[identity] + player := world.newCharacter() + player.playfield, player.position = machine.Playfield, machine.Position + player.appearance = map[uint32]uint16{1183: 0x515, 1180: 0x315, 1186: 0x115}[machine.Playfield] + forward, _ := bodyAxes(machine.Rotation) + player.position[0] += 3 * forward[0] + player.position[2] += 3 * forward[2] + player.position[1] += .5 + yaw := math.Atan2(float64(machine.Position[0]-player.position[0]), float64(machine.Position[2]-player.position[2])) + player.rotation = [4]float32{0, float32(math.Sin(yaw / 2)), 0, float32(math.Cos(yaw / 2))} + // Controlled level-ten checkpoint with sale loot and a nearby target. + // Funding and trained skills are fixtures, not earned-progression evidence. + trainBasicShopWeaponFixture(t, player) + player.health, player.nano = player.maximumHealth(), player.maximumNano() + player.browserTokenHash = fmt.Sprintf("%x", sha256.Sum256([]byte("basic-shop-weapons"))) + if err := world.saveUser_locked(player); err != nil { + t.Fatal(err) + } + inventory := playerInventory{Credits: 50000, LastID: 1, Items: []ownedItem{ + {ID: 1, Type: 51018, Template: 209283, Quality: 1, Slot: 64, Count: 1}, + }} + if err := world.saveInventory_locked(player, inventory); err != nil { + t.Fatal(err) + } + var target *character + for _, actor := range world.characters { + if actor.npc && actor.playfield == 950 && actor.monsterData == 17655 && actor.level == 1 && actor.combatProfile != nil && (target == nil || actor.id < target.id) { + target = actor + } + } + if target == nil { + t.Fatal("missing original Leet fixture") + } + target.playfield, target.position = player.playfield, player.position + target.position[0] -= 1.5*forward[0] + .6*forward[2] + target.position[2] += -1.5*forward[2] + .6*forward[0] + target.motion.home, target.health = target.position, 10000 + // Deterministic ordinary hits, including the target's retaliation. + world.combatRoll = func(limit uint32) uint32 { + if limit == 100 { + return 99 + } + return 0 + } + mux := http.NewServeMux() + mux.Handle("/", world.httpHandler()) + mux.HandleFunc("GET /test-state", func(w http.ResponseWriter, r *http.Request) { + world.mutex.Lock() + defer world.mutex.Unlock() + open, sales, purchases := false, 0, 0 + if client := world.clients[1]; client != nil && client.shop != nil { + open, sales = true, len(client.shop.items) + for _, count := range client.shop.purchases { + purchases += int(count) + } + } + json.NewEncoder(w).Encode(map[string]any{"machine": identity, "playfield": machine.Playfield, + "open": open, "sales": sales, "purchases": purchases, "inventory": player.inventory, + "target": target.id, "targetHealth": target.health, "fighting": player.fighting, + "recharging": time.Now().Before(player.rechargeUntil)}) + }) + host := httptest.NewServer(mux) + defer host.Close() + ctx, cancel := context.WithTimeout(context.Background(), 5*time.Minute) + stopped := make(chan struct{}) + go func() { + defer close(stopped) + clock := time.NewTicker(time.Second / 60) + defer clock.Stop() + for { + select { + case now := <-clock.C: + world.advancePlayerMovement(now) + world.advanceEquipment(now) + world.advanceCombat(now) + case <-ctx.Done(): + return + } + } + }() + defer func() { cancel(); <-stopped }() + command := exec.CommandContext(ctx, "node", filepath.Join(root, "tools/client/test_basic_shop_weapons.mjs"), host.URL, filepath.Join(output, fmt.Sprintf("%x", identity))) + command.Dir, command.Stdout, command.Stderr = root, os.Stdout, os.Stderr + err := command.Run() + t.Logf("Browser artifacts: %s", filepath.Join(output, fmt.Sprintf("%x", identity))) + if err != nil { + t.Fatal(err) + } + cold := newTestInventoryServer(t).characters[1] + if !reflect.DeepEqual(cold.inventory, player.inventory) { + t.Fatal("purchased weapon use changed during cold recovery") + } + }) + } +} diff --git a/server/gamedata/shop_stock.yaml b/server/gamedata/shop_stock.yaml @@ -46,14 +46,28 @@ # explicitly sells ammunition; basic weapon-shop membership is provisional. # This subset supplies finite early weapons; historical generation remains open. # See docs/ammunition-stock.md for the source and policy boundary. -25885: &ordinary_ammunition +25885: - {template: 21605, quality: 1} - {template: 21609, quality: 1} - {template: 21613, quality: 1} - {template: 21601, quality: 1} -99478: *ordinary_ammunition -99505: *ordinary_ammunition -99572: *ordinary_ammunition +# Basic weapon upgrades: fixed QL5/10 rows from reviewed original families. +# Membership is provisional alpha policy; docs/early-shop-stock.md. +99478: &basic_weapons + - {template: 21605, quality: 1} + - {template: 21609, quality: 1} + - {template: 21613, quality: 1} + - {template: 21601, quality: 1} + - {template: 123742, quality: 5} + - {template: 123742, quality: 10} + - {template: 122121, quality: 5} + - {template: 122121, quality: 10} + - {template: 124258, quality: 5} + - {template: 124258, quality: 10} + - {template: 129026, quality: 5} + - {template: 129026, quality: 10} +99505: *basic_weapons +99572: *basic_weapons # Maps: the five original reader upgrades. Fixed subset, not recovered TIAM stock. # Shipped map-window help and original upgrade contracts; see docs/shops.md. diff --git a/server/shop_ammunition_test.go b/server/shop_ammunition_test.go @@ -37,7 +37,7 @@ func TestShopAmmunitionProductionPackages(t *testing.T) { if err := world.handleShopUse(client, request); err != nil { t.Fatal(err) } - if client.shop == nil || !slices.Equal(client.shop.stock, []gamedata.ShopItem{ + if client.shop == nil || len(client.shop.stock) < 4 || !slices.Equal(client.shop.stock[:4], []gamedata.ShopItem{ {Template: 21605, Quality: 1}, {Template: 21609, Quality: 1}, {Template: 21613, Quality: 1}, {Template: 21601, Quality: 1}, }) { diff --git a/server/shop_purchases_test.go b/server/shop_purchases_test.go @@ -72,7 +72,8 @@ func TestShopKnownStockOnlyAdmitsSupportedItemQualities(t *testing.T) { } item := ownedItem{Type: definition.HeaderWords[0], Template: template, Quality: entry.Quality} charges := int32(itemStat(definition, 212)) - if (item.isStackable() && (charges < 1 || charges > 65535)) || (!item.isStackable() && charges > 1) { + // Live weapons use stat212 as magazine capacity, not purchase quantity. + if (item.isStackable() && (charges < 1 || charges > 65535)) || (!item.isStackable() && !item.isWieldableWeapon() && charges > 1) { t.Fatalf("stock %d cannot represent its authored package count %d", template, charges) } } diff --git a/tools/client/test_basic_shop_weapons.mjs b/tools/client/test_basic_shop_weapons.mjs @@ -0,0 +1,142 @@ +import assert from 'node:assert/strict'; +import fs from 'node:fs/promises'; +import {createRequire} from 'node:module'; +import {GameTest} from './game_test.mjs'; + +const {chromium} = createRequire(import.meta.url)('playwright'); +const [url, output] = process.argv.slice(2); +const browser = await chromium.launch({executablePath: '/usr/bin/chromium', args: [ + '--enable-gpu', '--use-gl=angle', '--use-angle=gl', '--no-sandbox', '--disable-dev-shm-usage', + '--disable-background-timer-throttling', '--disable-renderer-backgrounding']}); +let game; +const evidence = {}; +try { + const context = await browser.newContext({viewport: {width: 1024, height: 768}}); + await context.addCookies([{name: 'ao_client', value: 'basic-shop-weapons', url}]); + const page = await context.newPage(); + game = await GameTest.attach(page); + const server = async () => (await page.request.get(url + '/test-state')).json(); + const cell = (type, slot) => game.state.grids.flatMap(grid => grid.cells).find(cell => + cell.identity[0] === type && cell.identity[1] === slot && !cell.dummy); + const click = async (source, button = 'left') => { + assert(source, 'expected native inventory/catalog cell is present'); + await game.click((source.bounds[0] + source.bounds[2]) / 2, (source.bounds[1] + source.bounds[3]) / 2, button); + }; + const waitServer = (label, predicate) => game.waitFor(label, async () => predicate(await server())); + await page.goto(url); + await game.ready(); + if (!game.state.camera.firstPerson) await game.key('F8'); + await game.key('KeyI'); + evidence.before = await server(); + const open = async keyboard => { + await game.click(...await game.pick(51035, evidence.before.machine), keyboard ? 'left' : 'right'); + if (keyboard) await game.key('KeyE'); + await game.wait('twelve basic weapon catalog rows', () => + Array.from({length: 12}, (_, index) => cell(111, index)).every(Boolean)); + assert((await server()).open); + }; + await open(false); + await game.save(output + '/catalog'); + + // Buy each QL10 family with both required ammunition packages, selling loot. + for (const [count, index] of [0, 1, 5, 7, 9, 11].entries()) { + await click(cell(111, index)); + await waitServer('purchase row selected', state => state.purchases === count + 1); + } + await click(cell(104, 48)); + await game.wait('sale loot picked', state => state.dragged[0] === 104); + await game.click(860, 412); + await waitServer('loot offered', state => state.sales === 1); + await game.save(output + '/basket'); + await game.click(873, 475); + await waitServer('weapons committed', state => !state.open && state.inventory.Items.length === 6); + evidence.purchased = await server(); + assert.equal(evidence.purchased.inventory.Credits, evidence.before.playfield === 1183 ? 38512 : 37661); + assert.deepEqual(evidence.purchased.inventory.Items.map(item => [item.ID, item.Template, item.Quality, item.Count, item.Ammo]), [ + [2, 21605, 1, 100, 0], [3, 21609, 1, 100, 0], [4, 123742, 10, 1, 0], + [5, 122121, 10, 1, 0], [6, 124258, 10, 1, 0], [7, 129026, 10, 1, 0], + ]); + + // A cancelled QL5 basket leaves the completed transaction untouched. + await open(true); + await click(cell(111, 4)); + await waitServer('cancel draft selected', state => state.purchases === 1); + await game.click(945, 475); + await waitServer('draft cancelled', state => !state.open); + assert.deepEqual((await server()).inventory, evidence.purchased.inventory); + await page.keyboard.press('Control+1'); + + // Look down at the nearby Leet so the attack uses visible native picking. + const cameraPoint = await game.point(400, 200); + let mouseY = cameraPoint.y, sequence = game.sequence; + await page.mouse.move(cameraPoint.x, mouseY); + await game.snapshot(); + sequence = game.sequence; + await page.mouse.down({button: 'right'}); + try { + await game.waitInput(sequence, 1025); + const deadline = Date.now() + 10000; + for (;;) { + await game.snapshot(); + const y = game.state.actors.find(actor => actor.type === 50000 && actor.id === evidence.before.target).screenPosition[1]; + if (y >= 500 && y <= 600) break; + assert(Date.now() < deadline, 'Camera did not frame the controlled Leet'); + mouseY += y > 600 ? 20 : -20; + await page.mouse.move(cameraPoint.x, mouseY, {steps: 2}); + } + } finally { + sequence = game.sequence; + await page.mouse.up({button: 'right'}); + } + await game.wait('mouse look released', () => game.events.some(event => + event.sequence > sequence && event.kind === 'input' && event.stage === 'consumed' && event.type === 1026)); + + evidence.used = []; + for (const [id, ammoSlot, clip] of [[4, 48, 20], [5, 49, 20], [6, 49, 40], [7, null, null]]) { + await waitServer('previous weapon recharge finished', state => !state.recharging && state.fighting === 0); + await click(cell(104, game.local().inventory.find(item => item.id === id).slot), 'right'); + await game.wait('purchased weapon equipped', state => + game.local(state).inventory.some(item => item.id === id && item.slot === 6), 15000); + await waitServer('server agrees on equipped identity', state => state.inventory.Items.find(item => item.ID === id).Slot === 6); + if (ammoSlot !== null) { + await click(cell(104, ammoSlot)); + await game.wait('ammunition picked', state => state.dragged[0] === 104 && state.dragged[1] === ammoSlot); + await game.click(867, 206, 'right'); + await waitServer('purchased weapon loaded', state => state.inventory.Items.find(item => item.ID === id).Ammo === clip); + await game.wait('native loaded clip agrees', state => game.local(state).weapons.some(weapon => weapon.slot === 6 && weapon.loadedAmmo === clip)); + await game.wait('native reload action finished', state => !game.local(state).actions.includes(6)); + } + + // One ordinary attack must damage the controlled target and consume one round. + const before = await server(); + await game.click(...await game.pick(50000, before.target)); + await game.key('KeyQ'); + await waitServer('purchased weapon deals damage', state => state.targetHealth < before.targetHealth); + await game.key('KeyQ'); + await waitServer('attack stopped', state => state.fighting === 0); + const used = await server(); + assert.equal(used.inventory.Items.find(item => item.ID === id).Ammo, clip === null ? 0 : clip - 1); + await game.wait('native target damage agrees', state => + state.actors.find(actor => actor.type === 50000 && actor.id === used.target)?.stats[27] === used.targetHealth); + evidence.used.push(used); + await game.save(output + '/used-' + id); + } + const final = await server(); + assert.equal(final.inventory.Items.find(item => item.ID === 2).Count, 80); + assert.equal(final.inventory.Items.find(item => item.ID === 3).Count, 40); + await page.reload(); + await game.ready(); + evidence.reconnected = await server(); + assert.deepEqual(evidence.reconnected.inventory, final.inventory); + for (const [id, slot] of [[4, 51], [5, 52], [6, 53], [7, 6]]) { + assert(game.local().inventory.some(item => item.id === id && item.slot === slot && item.quality === 10)); + } + assert.deepEqual(game.errors, []); + console.log('PASS:', evidence.before.machine, 'QL5/10 catalog, four purchased QL10 weapons used, buy/sell, E/cancel and reconnect'); +} finally { + try { + await fs.mkdir(output, {recursive: true}); + await fs.writeFile(output + '/verification.json', JSON.stringify(evidence, null, 2) + '\n'); + if (game) await game.save(output + '/final'); + } finally { await browser.close(); } +}