aorecomp

Anarchy Online classic in the browser

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


commit 6211b76b5d9f4ff4a6f679f31c8370a37baacc3d
parent 62d6871dee8eee8b9bd3e0c8cd6ef692ccdd56ae
Author: anon <anon@example.com>
Date:   Sat, 31 Oct 2026 09:09:13 +0000

Verify full earned starter leveling and recovery loop

Diffstat:
MDEVELOPERS.md | 13++++++++++---
MTODO.md | 33+++++++++++++++++++++++++++++----
Mdocs/starter-progression.md | 92+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mserver/browser_game_test.go | 22++++++++++++++--------
Mtools/client/test_starter_equipment.mjs | 364++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---------
5 files changed, 468 insertions(+), 56 deletions(-)

diff --git a/DEVELOPERS.md b/DEVELOPERS.md @@ -460,7 +460,7 @@ available (`node` on PATH, `playwright` installed locally or on NODE_PATH, `/usr/bin/chromium` installed): ```sh -AO_GAME_TEST=1 go test ./server -run '^TestBrowser(GameHarness|StarterEquipment|StarterMissionTargets)$' -count=1 -timeout=35m -v +AO_GAME_TEST=1 go test ./server -run '^TestBrowser(GameHarness|StarterEquipment|StarterMissionTargets)$' -count=1 -timeout=95m -v ``` This starts an HTTP server on a random loopback port and uses a disposable @@ -479,6 +479,12 @@ shirt and nano crystal, a full-health spawned Leet kill, an earned mission reque all five full-health private encounters and exact-book hand-in. It accounts for each corpse's single-award cash, any generated parts, laboratory use/locked retry, quiet recovery, the request fee and the advertised item/cash reward. +It trains the rolled reward's requirements, wears that exact instance, earns +level two through nine further full-health kills and spends the earned IP. +Ordinary travel reaches the medical shop for an unaffordable purchase, +cancelled/retried earned-part sale and funded Nano Kit purchase. Untrained use, +First Aid training, one successful charge and an immediate locked retry are +checked before returning to defeat a full-health authored level-two Leet. Native ownership is compared with server state, observer isolation, page reconnect and cold database loading, including final player poses and all five saved encounter deaths. @@ -487,8 +493,9 @@ The artifact directory retains `ledger.json`, native screenshots/traces and a browser run. Its forced final position checkpoint follows production shutdown. Skills and rewards use ordinary native commands and production random rolls, without grants or edited characters/enemies. -Earned levels, sales, purchases and actual reclaim remain broader -regression work. +Pre-attack and post-kill captures retain native and live server poses beside +their wire events. Funded health supplies, further levels, full inventory and +actual death/reclaim remain broader regression work. `TestBrowserStarterMissionTargets` walks a normally created starter through its training exit to Backyard1. It checks the distinct booth56001, entrance56006 and diff --git a/TODO.md b/TODO.md @@ -306,6 +306,10 @@ unverified mass/deletion/reclaim policies are in [backpacks](docs/backpacks.md). [earned creature upgrades](docs/earned-creature-upgrade.md), [early armor](docs/early-armor.md) and [early melee](docs/early-melee.md). + An independent original-DB audit also matches all fourteen records of seven + regular Leather candidate pairs at QL1/200, including appearance, AC and + strict Sense/Agility criteria. Intermediate quality, native use and acquisition + remain unverified; see `local/todo-progression-play/leather-audit/audit.json`. - [x] Admit the complete Low-Tech armor set through shared quality and shop data. Eight explicit original pairs cover QL1..200, including alternate body and leg styles and independent sleeves. All three basic armor factions offer the @@ -3033,6 +3037,15 @@ with payloads and known client/server provenance. its movement packets from the final trace's 2048-event window. Evidence: `local/game-tests/starter-continue-20261030-230715/earned-level2-final/` and `local/todo-progression-play/starter-pose-verification.json`. + Fresh pre-attack/post-kill captures now compare both native and live server + poses before quiet recovery. The first outdoor fight begins aligned, then + native facing differs by 177.14 degrees while live server rotation is unchanged; + position differs by only 0.076 m. Its retained wire window includes the attack + and no later player movement request. All five private fights remain aligned. + This narrows the mismatch to combat-time native turning for that outdoor + encounter; its canonical publication policy remains open. Evidence: + `local/game-tests/starter-20261031-011445/outdoor/` and + `local/todo-progression-play/starter-full-facing.json`. - [x] Keep browser rebuilds independent of reviewed server-world data. `make wasm` previously recopied ignored extraction output through its `assets` prerequisite, removing reviewed destination/arrival/requirement rows from `zone_links.yaml`. @@ -3507,8 +3520,17 @@ and server restarts. Turn every reproduced bug into a focused regression test. advertised item/cash reward. The book's simple native proxy is checked before zoning against exact pickup packets and server ownership. Page reconnect and cold loading retain the completed assignment and five saved deaths, using - production rolls and training-ground resources. Earned levels, sales/purchases - and actual reclaim remain broader regression work. See + production rolls and training-ground resources. It now also repeats qualified + wear of the rolled QL1 reward, nine further full-health kills, the earned + level-2/4000-IP award and health/weapon training. Normal travel verifies an + unaffordable purchase, cancelled/retried earned-part sale, funded Nano Kit, + rejected use, First Aid training, accepted use and locked retry. The return + defeats a full-health authored level-2 Leet, picks up its actual QL2 part and + recovers through sitting. The fresh run retains all 23 physical items, + 50 credits, current XP150 and 5006 IP through page/cold recovery. Funded + health supplies, further levels, full inventory and actual reclaim remain + broader regression work. See + [maintained earned loop](docs/starter-progression.md#maintained-fresh-earned-level-and-recovery-loop) and [maintained starter mission](docs/starter-progression.md#maintained-earned-starter-mission). An ordinary continuation of that same saved starter now verifies earned level 2, its 4000-IP award, qualified QL1 glove wear and further Body @@ -3526,8 +3548,8 @@ and server restarts. Turn every reproduced bug into a focused regression test. 67 HP to full 111 through sitting without a laboratory. Page/cold recovery retain all 22 physical items, kit28x24, 57 credits, current XP150 and 5006 IP; the replacement Leet retains its original definition, level and full health. - Inclusion of this continuation in the maintained fresh-character regression - remains open; see + The maintained fresh-character regression now includes this continuation; + see [next-level starter fight](docs/starter-progression.md#earned-starter-next-level-fight-and-passive-recovery), [funded starter recovery](docs/starter-progression.md#earned-starter-sale-and-nano-kit-recovery) and [earned starter level](docs/starter-progression.md#earned-starter-checkpoint-reaches-level-two). @@ -3746,6 +3768,9 @@ and server restarts. Turn every reproduced bug into a focused regression test. IP awards are separate work, despite the implemented paths documented in `docs/ip-training.md` and `docs/character-progression.md`. Keep unresolved balance and skill consumers explicit when updating these claims. + `docs/early-melee.md` also describes a fixed QL2/two-item mission reward + pool; current `missions.yaml` and `mission_offers.go` select from seven + reviewed families at the requested supported level/quality. - [x] Repair the browser-profile worker test fixture. Its VM context supplies `URL`/`location` and checks build/upload URLs relative to the worker location. `node client/tests/browser_profile.mjs` now exercises all existing assertions. diff --git a/docs/starter-progression.md b/docs/starter-progression.md @@ -1645,3 +1645,95 @@ pass integrity/foreign-key checks. Owned test browsers/servers are closed. The complete maintained fresh-character regression, funded health supplies, further levels and actual reclaim remain open. No game behavior change or full Go-suite rerun is claimed by this milestone. + +## Maintained fresh earned level and recovery loop + +`TestBrowserStarterEquipment` extends the maintained fresh two-client mission +scenario through qualified reward wear, nine further ordinary kills, the first +earned level, health/weapon training, a cancelled/retried sale, funded Nano Kit +use and an authored level-two encounter. The scenario uses production +initialization, resource data and random rolls. The read-only test endpoint +also records level, progress and live pose. Each encounter retains native +pre-attack/post-kill captures beside server JSON, keeping the attack and movement +window available before quiet recovery evicts it. + +Two initial attempts are retained. `starter-20261031-005807/` was deliberately +stopped after source review identified an invalid real-ID assertion for the +new armor proxy. The native proxy legitimately has identity0/type0 until +reconstruction; wear is checked by template, quality, count and slot alongside +the exact server instance. `starter-20261031-010257/` stalls at the private +doorway's [15,24.2] approach, reaching [15.01,1.9891,23.5735]. An unchanged +checkpoint continuation walks to [15,23.5], jumps the lip and reaches the next +room normally. That focused native/cold fixture passes in 147.83s, retaining +both players' ownership and progress. The maintained route uses the reachable +23.5 approach; no game geometry or movement behavior is changed. Its capture is +`starter-doorway-20261031-011139/`. + +The fresh run `starter-20261031-011445/` completes all five full-health private +encounters and returns the exact allocated book. It earns pants21, +type51022/template85512/QL1, and trains Agility6->8 for26IP before wearing that +instance in slot27. The issued bat4 and shirt7 remain worn. At the fifteenth +full-health kill, the native level-up payload is +`[2,5144,1500,1450,4050,0,2,100]`: cumulativeXP1500, current-levelXP50 and +exactly4000 earned IP. The issued laboratory is exhausted after25 total uses; +later recoveries use ordinary sitting. This run exercises the pants reward +branch; the other production reward families remain subject to their individual +native coverage. + +The outdoor pre-attack quaternion agrees with the live server, then native +rotation differs by177.14 degrees immediately after the kill while the live +server retains its earlier rotation. Position differs by0.076m; both native +and server HP are46. The retained event window includes the current attack +and no later player movement request. All five private fights remain aligned. +This narrows the facing investigation beyond checkpoint timing, without +establishing the original server's publication policy. The independent report +is `local/todo-progression-play/starter-full-facing.json`. + +Earned Body Development10->15 and 1h Blunt10->15 cost120IP, leaving5024, +maximumHP111 and buffed attack32. Recovery reaches full111 in both client and +server before normal travel to medical shop1183. Its150-credit laboratory is +unaffordable at59 credits and changes no ownership. Generated QL1 part17 is +offered, cancelled, restored to the same native cell, reoffered and sold once +for6 credits. One original Simple Nano Kit costs20: cash59->65->45, with +kit27/type51005/template85366/QL1/count25 in slot68. Page reconnect reconstructs +that exact owned identity before use. + +The ordinary buff recast consumes19 nano, leaving5. Untrained kit use retains +all25 charges and reports required First Aid8. Native training raises raw +First Aid5->7 for18 earned IP, leaving5006. Accepted use restores5->15 nano, +consumes exactly one charge and publishes FirstAid123/40seconds. A real locked +repeat receives rejection2 and leaves24 charges. This verifies nano recovery; +the complete health First Aid contract remains blocked by its separate delivery +gap. + +Normal return reaches full-health authored level-two Leet1067311. The player +begins with111HP and the enemy with100HP. The kill earns100XP, leaves serverHP83 +and produces5 credits plus part28/QL2. Native pickup retains that exact part in +slot76, with endpoints42640/42641. Sitting restores full111HP without another +consumable. Final cash is50, current-levelXP150/native cumulativeXP1600 and +IP5006. All sixteen owner items and seven observer items survive page reconnect +and two fresh cold native logins, including worn pants21, kit27x24, the issued +bat/shirt, nine retained parts and three untouched startup stims. Observer +cash/XP/IP remain0/0/1500. Native Stats shows111/111HP,24/24nano,AC3/13/3 and +attack32; error lists are empty. + +The maintained fixture passes in3091.90s; the separate unchanged-checkpoint +two-client cold fixture passes in30.21s. Cold capture: +`local/game-tests/starter-full-cold-20261031-020703/`. Independent scripts +`local/todo-progression-play/tmp_verify_starter_full.py` and +`tmp_verify_starter_full_cold.py` verify every item/location, wallet and earned +progress against the stopped stores. The completed mission and five recorded +deaths are unchanged; both stores pass integrity/foreign-key checks. Cold +position errors are0.000001m/0.098111m and quaternion dot products are effectively1. +Their reports are `starter-full-verified.json` and +`starter-full-cold-verified.json` in the same local directory. Owned browser +drivers and servers are closed. The provisional100HP/100XP enemy profiles, +historical reward/loot membership, funded health supplies, further progression, +full inventory and actual death/reclaim remain open. + +Focused Go verification passes24 roots/86 results in21.703s, covering the +ordinary training/level, medical/shop, regeneration, mission settlement and pose +checkpoint paths. The browser-control JavaScript regression passes126 cases. +Logs are `starter-full-go-focused.json` and `starter-full-js-unit-cases.log` +under `local/todo-progression-play/`. This milestone does not claim a full +Go-suite rerun or a change to original game rules. diff --git a/server/browser_game_test.go b/server/browser_game_test.go @@ -105,9 +105,9 @@ func TestBrowserStarterEquipment(t *testing.T) { corpses = append(corpses, map[string]any{"id": enemy.id, "items": enemy.corpse.items, "credits": enemy.corpse.credits}) } - if enemy.npc && enemy.playfield == player.playfield && enemy.monsterData == 17655 && enemy.level == 1 && enemy.health > 0 { + if enemy.npc && enemy.playfield == player.playfield && enemy.monsterData == 17655 && (enemy.level == 1 || enemy.level == 2) && enemy.health > 0 { enemies = append(enemies, map[string]any{"id": enemy.id, "position": enemy.position, - "health": enemy.health, "maximumHealth": enemy.maximumHealth()}) + "level": enemy.level, "health": enemy.health, "maximumHealth": enemy.maximumHealth()}) } } missions := []map[string]any{} @@ -124,7 +124,8 @@ func TestBrowserStarterEquipment(t *testing.T) { offer = client.missionOffer.definition } json.NewEncoder(w).Encode(map[string]any{"inventory": player.inventory, "health": player.health, - "maximumHealth": player.maximumHealth(), "stats": player.stats, "enemies": enemies, "corpses": corpses, + "maximumHealth": player.maximumHealth(), "nano": player.nano, "level": player.level, "experience": player.experience, + "position": player.position, "rotation": player.rotation, "stats": player.stats, "enemies": enemies, "corpses": corpses, "playfield": player.playfield, "missions": missions, "offer": offer}) }) host := httptest.NewServer(mux) @@ -132,7 +133,7 @@ func TestBrowserStarterEquipment(t *testing.T) { closeTestBrowserStreams(t, world) // Advance the ordinary world without changing characters, encounters or rolls. - ctx, cancel := context.WithTimeout(context.Background(), 30*time.Minute) + ctx, cancel := context.WithTimeout(context.Background(), 90*time.Minute) defer cancel() stopped := make(chan struct{}) go func() { @@ -209,7 +210,7 @@ func TestBrowserStarterEquipment(t *testing.T) { continue } players++ - if player.level != 1 || player.health != player.maximumHealth() || + if player.health != player.maximumHealth() || player.playfield != restored.characters[player.id].playfield || player.position != restored.characters[player.id].position || player.rotation != restored.characters[player.id].rotation || !reflect.DeepEqual(player.inventory.Items, restored.characters[player.id].inventory.Items) || @@ -221,13 +222,18 @@ func TestBrowserStarterEquipment(t *testing.T) { t.Fatalf("starter ownership changed across cold loading for %s: %+v", player.name, player.inventory) } if player.name == "Starterwatch" { - if len(player.inventory.Items) != 7 || player.inventory.Credits != 0 || player.experience != 0 || player.stats.ImprovementPoints != 1500 { + if player.level != 1 || len(player.inventory.Items) != 7 || player.inventory.Credits != 0 || player.experience != 0 || player.stats.ImprovementPoints != 1500 { t.Fatalf("observer received another player's progress: %+v", player) } continue } - if player.experience != 600 || player.stats.ImprovementPoints != 1170 || player.maximumHealth() != 84 || player.aggDef != 100 || - player.inventory.Credits < 25 || player.inventory.Credits > 49 || len(player.missions) != 0 || + wantIP := uint32(5006) + if len(world.missionExpiry) == 1 && world.missionExpiry[0].offer.definition.RewardItem == 122691 { + wantIP = 5003 + } + if player.level != 2 || player.experience < 150 || (player.experience-150)%100 != 0 || + player.stats.ImprovementPoints != wantIP || player.stats.Body.BodyDevelopment != 15 || player.stats.Melee.OneHandBlunt != 15 || + player.stats.NanoAiding.FirstAid != 7 || player.maximumHealth() != 111 || player.aggDef != 100 || len(player.missions) != 0 || !reflect.DeepEqual(player.inventory.LearnedNanos, []uint32{43371}) { t.Fatalf("ordinary starter mission, training or learning was not retained: %+v", player) } diff --git a/tools/client/test_starter_equipment.mjs b/tools/client/test_starter_equipment.mjs @@ -40,7 +40,7 @@ async function recover(game, label) { for (;;) { await game.snapshot(); const server = await (await game.page.request.get(url + '/test-state')).json(); - if (game.local().stats[27] === 84 && server.health === 84) break; + if (game.local().stats[27] === server.maximumHealth && server.health === server.maximumHealth) break; assert(Date.now() < deadline, 'Starter health did not recover in both client and server'); const unlocked = game.events.some(event => { if (event.sequence <= sequence || event.direction !== 'framereceived' || event.opcode !== '5e477770') return false; @@ -56,7 +56,7 @@ async function recover(game, label) { if (uses < count) await game.click(681, 45, 'right'); const locked = await (await game.page.request.get(url + '/test-state')).json(); assert.equal(locked.inventory.Items.find(item => item.Template === 116628)?.Count ?? 0, count - uses); - assert(locked.health >= Math.min(84, server.health + 15)); + assert(locked.health >= Math.min(server.maximumHealth, server.health + 15)); } assert.equal(game.local().inventory.find(item => item.templates[0] === 116628)?.count ?? 0, count - uses); await game.key('KeyX'); @@ -94,11 +94,12 @@ async function frame(game, type, id) { // Each encounter starts at full health and uses native targeting, attacks and loot. async function fight(game, enemy, label) { const experience = game.local().stats[52], credits = game.local().stats[61]; - if (game.local().stats[22] !== 27) { + const attackRating = game.local().stats[54] === 1 ? 27 : 32; + if (game.local().stats[22] !== attackRating) { await game.page.keyboard.press('Control+8'); await game.key('F1'); await game.click(857, 128, 'right'); - await game.wait("Thug's Delight active", state => game.local(state).stats[22] === 27); + await game.wait("Thug's Delight active", state => game.local(state).stats[22] === attackRating); await game.page.keyboard.press('Control+8'); } const targetingDeadline = Date.now() + 30000; @@ -111,10 +112,12 @@ async function fight(game, enemy, label) { } const beforeFight = await (await game.page.request.get(url + '/test-state')).json(); const healthyEnemy = beforeFight.enemies.find(actor => actor.id === enemy.id); - assert.equal(beforeFight.health, 84); - assert.equal(game.local().stats[27], 84); + assert.equal(beforeFight.health, beforeFight.maximumHealth); + assert.equal(game.local().stats[27], beforeFight.maximumHealth); assert.equal(healthyEnemy.health, 100); assert.equal(healthyEnemy.maximumHealth, 100); + await game.save(output + '/' + label + '/fight-start'); + await fs.writeFile(output + '/' + label + '/fight-start/server.json', JSON.stringify(beforeFight, null, 2)); const attack = game.sequence; await game.key('KeyQ'); await game.wait('native attack request', () => game.events.some(event => @@ -143,10 +146,21 @@ async function fight(game, enemy, label) { } } await game.wait('earned kill XP', state => game.local(state).stats[52] === experience + 100); + let levelAward = null; + if (game.local().stats[54] !== beforeFight.level) { + const event = game.events.find(event => event.sequence > attack && + event.direction === 'framereceived' && event.opcode === '7f405a16'); + assert(event, 'Earned level did not publish its native award'); + const packet = Buffer.from(event.hex, 'hex'); + levelAward = Array.from({length: 8}, (_, index) => packet.readUInt32BE(packet.length - 32 + index * 4)); + assert.deepEqual(levelAward, [game.local().id, beforeFight.stats.ImprovementPoints + 4000, + 1500, 1450, 4050, 0, 2, 100]); + } await game.save(output + '/' + label + '/earned-kill'); // Use the actual remains twice, then take any generated part exactly once. const killed = await (await game.page.request.get(url + '/test-state')).json(); + await fs.writeFile(output + '/' + label + '/earned-kill/server.json', JSON.stringify(killed, null, 2)); const corpse = killed.corpses.find(corpse => corpse.id === enemy.id); assert(corpse && corpse.credits >= 1 && corpse.credits <= 5); const corpseDistance = state => { @@ -186,8 +200,10 @@ async function fight(game, enemy, label) { ([left, top, right, bottom]) => left === 0 && top === 0 && right === 178 && bottom === 128)); await game.save(output + '/' + label + '/corpse-loot'); if (corpse.items?.length) { + assert.equal(corpse.items.length, 1); + assert(corpse.items[0].Quality >= 1 && corpse.items[0].Quality <= (healthyEnemy.level === 1 ? 1 : 3)); assert.deepEqual(corpse.items, [{ID: corpse.items[0].ID, Type: 51005, - Template: 42640, Quality: 1, Slot: 0, Count: 1, Ammo: 0}]); + Template: 42640, Quality: corpse.items[0].Quality, Slot: 0, Count: 1, Ammo: 0}]); await game.click(30, 45); await game.wait('generated part in native inventory', state => game.local(state).inventory.some(item => item.id === corpse.items[0].ID)); @@ -204,10 +220,38 @@ async function fight(game, enemy, label) { assert.deepEqual(after.inventory.Items.find(held => held.ID === item.ID), {...item, Slot: slot}); } console.log('PASS: ' + label + ', full-health kill, exact corpse ledger and recovery'); - return {fightStart: {health: beforeFight.health, enemy: healthyEnemy}, corpse, combatUses, + return {fightStart: {health: beforeFight.health, enemy: healthyEnemy}, corpse, combatUses, levelAward, parts: after.inventory.Items.filter(item => (corpse.items ?? []).some(part => part.ID === item.ID))}; } +// Approach an ordinary full-health outdoor encounter at the requested starter level. +async function outdoorFight(game, level, label) { + const population = await (await game.page.request.get(url + '/test-state')).json(); + const position = game.local().position; + const enemies = population.enemies.filter(enemy => enemy.level === level && enemy.health === 100); + enemies.sort((a, b) => Math.hypot(a.position[0] - position[0], a.position[2] - position[2]) - + Math.hypot(b.position[0] - position[0], b.position[2] - position[2])); + const enemy = enemies[0]; + assert(enemy, 'No full-health ordinary Leet at level ' + level); + const deadline = Date.now() + 30000; + for (;;) { + await game.snapshot(); + assert(Date.now() < deadline, 'Did not approach the ordinary Leet'); + const target = game.state.actors.find(actor => actor.type === 50000 && actor.id === enemy.id); + const position = game.local().position; + if (Math.hypot(target.position[0] - position[0], target.position[1] - position[1], + target.position[2] - position[2]) > 2.5) { + await game.walk(target.position[0], target.position[2] - 2); + continue; + } + const server = await (await game.page.request.get(url + '/test-state')).json(); + const actual = server.enemies.find(actor => actor.id === enemy.id); + if (Math.hypot(actual.position[0] - position[0], actual.position[1] - position[1], + actual.position[2] - position[2]) <= 3) break; + } + return fight(game, enemy, label); +} + try { // Create both characters through the same Options form used during ordinary play. for (const name of ['Starterowner', 'Starterwatch']) { @@ -335,34 +379,12 @@ try { } finally { await owner.page.mouse.up(); } await owner.wait('full aggression', state => owner.local(state).stats[51] === 100); await owner.page.keyboard.press('Control+9'); - const population = await (await owner.page.request.get(url + '/test-state')).json(); - const position = owner.local().position; - const distance = enemy => Math.hypot(enemy.position[0] - position[0], enemy.position[2] - position[2]); - const enemy = population.enemies.sort((a, b) => distance(a) - distance(b))[0]; - assert(enemy && distance(enemy) < 40); - assert.equal(enemy.health, enemy.maximumHealth); // Cross the authored opening before approaching the selected roaming Leet. for (const [x, z] of [[62, 65], [62, 74]]) await owner.walk(x, z); if (!owner.state.camera.firstPerson) await owner.key('F8'); - const approachDeadline = Date.now() + 30000; - for (;;) { - await owner.snapshot(); - assert(Date.now() < approachDeadline, 'Starter did not approach the moving Leet'); - const target = owner.state.actors.find(actor => actor.type === 50000 && actor.id === enemy.id); - const position = owner.local().position; - if (Math.hypot(target.position[0] - position[0], target.position[1] - position[1], - target.position[2] - position[2]) > 2.5) { - await owner.walk(target.position[0], target.position[2] - 2); - continue; - } - const beforeFight = await (await owner.page.request.get(url + '/test-state')).json(); - const healthyEnemy = beforeFight.enemies.find(actor => actor.id === enemy.id); - if (Math.hypot(healthyEnemy.position[0] - owner.local().position[0], - healthyEnemy.position[1] - owner.local().position[1], healthyEnemy.position[2] - owner.local().position[2]) <= 3) break; - } - const fights = [await fight(owner, enemy, 'outdoor')]; + const fights = [await outdoorFight(owner, 1, 'outdoor')]; // Spend one earned credit on the first advertised contract at the original booth. for (const [x, z] of [[62, 74], [62, 65], [52.5, 57.6], [52.5973, 55.1362]]) { @@ -422,7 +444,7 @@ try { await owner.walk(15, z); fights.push(await fight(owner, encounters[index], 'mission-' + (index + 1))); if (index === 0) { - for (const z of [16.6, 24.2]) { + for (const z of [16.6, 23.5]) { await owner.walk(15, z); await jump(owner); } @@ -483,7 +505,7 @@ try { [x, y] = await owner.pick(56001, 3221228472); const handIn = owner.sequence; await owner.click(x, y, 'right'); - const credits = fights.reduce((total, fight) => total + fight.corpse.credits, 0) - 1 + advertised.Credits; + let credits = fights.reduce((total, fight) => total + fight.corpse.credits, 0) - 1 + advertised.Credits; await owner.wait('exact book and key consumed with advertised cash', state => !owner.local(state).inventory.some(item => item.templates[0] === 28577 || item.templates[0] === 40822) && owner.local(state).stats[61] === credits); @@ -506,27 +528,286 @@ try { let rewardSlot = 64; while (occupied.has(rewardSlot)) ++rewardSlot; assert.equal(rewards[0].Slot, rewardSlot); + await owner.wait('awarded reward proxy in its native slot', state => owner.local(state).inventory.some(item => + item.slot === rewardSlot - 16 && item.templates[0] === rewards[0].Template && item.quality === 1 && item.count === 1)); await owner.save(output + '/mission-completed'); + // Train the actual rolled reward's requirements and retain any replaced starter item. + const rewardTrainingCost = rewards[0].Template === 122691 ? 29 : 26; + await owner.key('KeyU'); + await owner.click(334, 196); + if (rewards[0].Template === 122691) { + await owner.click(835, 286); + await owner.click(315, 233); + await owner.click(835, 256); + } else { + await owner.click(835, 196); + await owner.click(835, 196); + } + await owner.click(445, 622); + await owner.wait('earned reward requirements trained', state => + owner.local(state).stats[53] === 1170 - rewardTrainingCost); + let displaced; + if (rewards[0].Template === 122691 || rewards[0].Template === 85686) { + const original = completed.inventory.Items.find(item => item.ID === + (rewards[0].Template === 122691 ? bat.id : shirt.id)); + const occupied = new Set(completed.inventory.Items.map(item => item.Slot)); + let slot = 64; + while (occupied.has(slot)) ++slot; + displaced = {...original, Slot: slot}; + await owner.page.keyboard.press('Control+1'); + if (rewards[0].Template === 122691) await owner.click(867, 206, 'right'); + else { await owner.click(953, 53); await owner.click(927, 148, 'right'); } + await owner.wait('issued predecessor retained in inventory', state => + owner.local(state).inventory.some(item => item.id === original.ID && item.slot === slot - 16)); + await owner.page.keyboard.press('Control+1'); + } + const wornReward = {...rewards[0], Slot: { + 85596: 24, 85742: 25, 85638: 30, 85512: 27, 85557: 18, 85686: 21, 122691: 6, + }[rewards[0].Template]}; + assert(wornReward.Slot, 'Unexpected starter reward family'); + const rewardCell = rewards[0].Slot - 64; + await owner.click(681 + rewardCell % 3 * 54, 45 + Math.floor(rewardCell / 3) * 54, 'right'); + await owner.wait('earned reward worn in its native slot', state => owner.local(state).inventory.some(item => + item.slot === wornReward.Slot && item.templates[0] === wornReward.Template && item.quality === 1 && item.count === 1)); + const worn = await (await owner.page.request.get(url + '/test-state')).json(); + if (rewards[0].Template === 122691) { + assert.equal(worn.stats.Abilities.Sense, 4); + assert.equal(worn.stats.Body.Dimach, 6); + } else assert.equal(worn.stats.Abilities.Agility, 8); + assert.deepEqual(worn.inventory.Items, completed.inventory.Items.map(item => + item.ID === wornReward.ID ? wornReward : item.ID === displaced?.ID ? displaced : item)); + await owner.save(output + '/earned-reward-worn'); + + // Earn the first level from nine further full-health ordinary fights. + for (const [x, z] of [[102.5, 143], [102.5, 102], [109, 102], [112, 101]]) { + await owner.walk(x, z); + if (owner.local().playfield === 950) break; + } + await owner.wait('training return for earned leveling', state => owner.local(state)?.playfield === 950, 60000); + await owner.ready(); + for (const [x, z] of [[62, 65], [62, 74]]) await owner.walk(x, z); + while (owner.local().stats[52] < 1500) + fights.push(await outdoorFight(owner, 1, 'earned-kill-' + (fights.length + 1))); + assert.equal(owner.local().stats[52], 1500); + assert.equal(owner.local().stats[54], 2); + assert.equal(owner.local().stats[53], 5170 - rewardTrainingCost); + assert.equal(fights.filter(fight => fight.levelAward).length, 1); + await owner.save(output + '/earned-level-two'); + + // Spend earned IP on health and the worn weapon, then recover both native/server HP. + await owner.key('KeyU'); + await owner.click(334, 196); + for (let point = 0; point < 5; ++point) await owner.click(835, 346); + await owner.click(302, 272); + for (let point = 0; point < 5; ++point) await owner.click(835, 166); + await owner.click(445, 622); + await owner.wait('earned level-two health and weapon training', state => + owner.local(state).stats[53] === 5050 - rewardTrainingCost && owner.local(state).stats[1] === 111 && + owner.local(state).stats[22] === 32); + const levelTrainingUses = await recover(owner, 'earned-level-two-training'); + while (!owner.local().inventory.some(item => item.templates[0] === 42640)) + fights.push(await outdoorFight(owner, 1, 'earned-sale-part-' + fights.length)); + credits = fights.reduce((total, fight) => total + fight.corpse.credits, 0) - 1 + advertised.Credits; + const funded = await (await owner.page.request.get(url + '/test-state')).json(); + assert.equal(funded.inventory.Credits, credits); + assert.equal(funded.stats.Body.BodyDevelopment, 15); + assert.equal(funded.stats.Melee.OneHandBlunt, 15); + const sale = funded.inventory.Items.find(item => item.Template === 42640); + assert(sale && sale.Quality === 1 && credits >= 20 && credits < 150); + + // Walk the original streets to the medical shop without crossing unverified geometry. + for (const [x, z] of [[62, 74], [62, 65], [52.5, 57.6], [52.5973, 55.1362]]) { + await owner.walk(x, z); + if (owner.local().playfield === 3000) break; + } + assert.equal(owner.local().playfield, 3000); + for (const [x, z] of [[102.5, 102], [102.5, 143], [104, 149.5], [105.161, 155.124]]) { + await owner.walk(x, z); + if (owner.local().playfield === 705) break; + } + assert.equal(owner.local().playfield, 705); + for (const [x, z] of [[951, 843], [920.6, 843], [920.6, 860.2], [917.3, 860.5], + [900.94, 860.47], [886.05, 860.26], [885.6, 889], [859.05, 888.49], [830.7, 888.62], + [831.68, 872.85], [825.73, 872.65], [804, 865.2], [804, 855], [804, 835], [804, 815], + [804, 795], [804, 775], [804, 754.35], [784.07, 693.33], [784.04, 653.34], + [800.88, 624.31], [801.06, 549.34], [797.11, 524.32], [793.24, 521.24], [781.33, 517.08], [766, 515]]) { + await owner.walk(x, z); + if (owner.local().playfield === 1183) break; + } + assert.equal(owner.local().playfield, 1183); + for (const [x, z] of [[187, 129.66], [186.98, 135.26], [185.7, 135.7]]) await owner.walk(x, z); + await frame(owner, 51035, 3221423263); + [x, y] = await owner.pick(51035, 3221423263); + await owner.click(x, y, 'right'); + await owner.wait('original medical shop open', state => state.regions.some( + ([left, top, right, bottom]) => left === 832 && top === 0 && right === 1024 && bottom === 494)); + await owner.click(864, 85); + await owner.save(output + '/unaffordable-laboratory'); + assert.deepEqual((await (await owner.page.request.get(url + '/test-state')).json()).inventory, funded.inventory); + + // Cancel and retry the exact earned part sale before accepting its six-credit quote. + const saleCell = sale.Slot - 64; + for (let attempt = 0; attempt < 2; ++attempt) { + await owner.click(681 + saleCell % 3 * 54, 45 + Math.floor(saleCell / 3) * 54); + const offer = owner.sequence; + await owner.click(864, 416); + await owner.wait('native part sale offered', () => owner.events.some(event => + event.sequence > offer && event.direction === 'framesent' && event.opcode === '36284f6e')); + assert.deepEqual((await (await owner.page.request.get(url + '/test-state')).json()).inventory, funded.inventory); + if (attempt === 0) { + await owner.click(945, 475); + await owner.wait('cancelled sale restores exact native part', state => owner.local(state).inventory.some(item => + item.id === sale.ID && item.slot === sale.Slot - 16)); + await owner.save(output + '/earned-sale-cancelled'); + [x, y] = await owner.pick(51035, 3221423263); + await owner.click(x, y, 'right'); + await owner.wait('medical shop reopened', state => state.regions.some( + ([left, top, right, bottom]) => left === 832 && top === 0 && right === 1024 && bottom === 494)); + } + } + await owner.click(874, 475); + credits += 6; + await owner.wait('earned part sale committed once', state => owner.local(state).stats[61] === credits); + const sold = await (await owner.page.request.get(url + '/test-state')).json(); + assert.deepEqual(sold.inventory.Items, funded.inventory.Items.filter(item => item.ID !== sale.ID)); + await owner.save(output + '/earned-sale-accepted'); + + // Buy one original package, then reconstruct its owned identity before self-use. + [x, y] = await owner.pick(51035, 3221423263); + await owner.click(x, y, 'right'); + await owner.wait('medical stock ready for purchase', state => state.regions.some( + ([left, top, right, bottom]) => left === 832 && top === 0 && right === 1024 && bottom === 494)); + const purchase = owner.sequence; + await owner.click(924, 85); + await owner.wait('native Nano Kit purchase offered', () => owner.events.some(event => + event.sequence > purchase && event.direction === 'framesent' && event.opcode === '36284f6e')); + await owner.click(874, 475); + credits -= 20; + await owner.wait('one funded Nano Kit purchased', state => owner.local(state).stats[61] === credits); + const bought = await (await owner.page.request.get(url + '/test-state')).json(); + const kit = bought.inventory.Items.find(item => item.Template === 85366); + const occupiedAfterSale = new Set(sold.inventory.Items.map(item => item.Slot)); + let kitSlot = 64; + while (occupiedAfterSale.has(kitSlot)) ++kitSlot; + assert.deepEqual(kit, {ID: kit.ID, Type: 51005, Template: 85366, Quality: 1, Slot: kitSlot, Count: 25, Ammo: 0}); + assert.deepEqual(bought.inventory.Items, [...sold.inventory.Items, kit]); + await owner.page.reload(); + await owner.ready(); + await owner.key('KeyI'); + const kitCell = kit.Slot - 64; + assert(owner.local().inventory.some(item => item.id === kit.ID && item.count === 25)); + await owner.page.keyboard.press('Control+8'); + await owner.click(927, 96); + await owner.key('F1'); + const cast = owner.sequence; + await owner.click(857, 128, 'right'); + await owner.wait('ordinary buff recast completed', () => owner.events.some(event => { + if (event.sequence <= cast || event.direction !== 'framereceived' || event.opcode !== '5e477770') return false; + const packet = Buffer.from(event.hex, 'hex'); + return packet.readUInt32BE(packet.length - 20) === 107 && packet.readUInt32BE(packet.length - 4) === 43371; + })); + await owner.page.keyboard.press('Control+8'); + await owner.click(681 + kitCell % 3 * 54, 45 + Math.floor(kitCell / 3) * 54, 'right'); + await owner.save(output + '/untrained-kit-use'); + assert.deepEqual((await (await owner.page.request.get(url + '/test-state')).json()).inventory, bought.inventory); + await owner.key('KeyU'); + await owner.click(288, 504); + await owner.click(835, 346); + await owner.click(835, 346); + await owner.click(445, 622); + await owner.wait('earned First Aid training', state => owner.local(state).stats[53] === 5032 - rewardTrainingCost); + const kitUse = owner.sequence; + await owner.click(681 + kitCell % 3 * 54, 45 + Math.floor(kitCell / 3) * 54, 'right'); + await owner.wait('one bought kit charge and original lock', state => + owner.local(state).inventory.some(item => item.id === kit.ID && item.count === 24) && + owner.events.some(event => { + if (event.sequence <= kitUse || event.direction !== 'framereceived' || event.opcode !== '5e477770') return false; + const packet = Buffer.from(event.hex, 'hex'); + return packet.readUInt32BE(packet.length - 20) === 170 && packet.readUInt32BE(packet.length - 8) === 123 && + packet.readUInt32BE(packet.length - 4) === 40; + })); + const kitAck = owner.events.find(event => event.sequence > kitUse && event.direction === 'framereceived' && + event.opcode === '52526858'); + assert(kitAck, 'Bought-kit use did not receive its acknowledgement'); + await owner.wait('bought-kit nano restoration', () => owner.events.some(event => { + if (event.sequence <= kitAck.sequence || event.direction !== 'framereceived' || event.opcode !== '2b333d6e') return false; + const packet = Buffer.from(event.hex, 'hex'); + return packet.readUInt32BE(packet.length - 8) === 214; + })); + const nanoUpdates = owner.events.filter(event => event.direction === 'framereceived' && event.opcode === '2b333d6e') + .map(event => { + const packet = Buffer.from(event.hex, 'hex'); + return {sequence: event.sequence, stat: packet.readUInt32BE(packet.length - 8), + value: packet.readUInt32BE(packet.length - 4)}; + }).filter(event => event.stat === 214); + const nanoBefore = nanoUpdates.filter(event => event.sequence < kitAck.sequence).at(-1).value; + const nanoAfter = nanoUpdates.find(event => event.sequence > kitAck.sequence).value; + assert(nanoAfter - nanoBefore >= 10 && nanoAfter - nanoBefore <= 12); + const repeat = owner.sequence; + await owner.click(681 + kitCell % 3 * 54, 45 + Math.floor(kitCell / 3) * 54, 'right'); + await owner.wait('locked bought-kit use rejected', () => owner.events.some(event => { + if (event.sequence <= repeat || event.direction !== 'framereceived' || event.opcode !== '52526858') return false; + const packet = Buffer.from(event.hex, 'hex'); + return packet.readUInt32BE(packet.length - 32) === 2 && packet.readUInt32BE(packet.length - 4) === kit.Slot - 16; + })); + const used = await (await owner.page.request.get(url + '/test-state')).json(); + assert.deepEqual(used.inventory.Items, bought.inventory.Items.map(item => item.ID === kit.ID ? {...item, Count: 24} : item)); + assert.equal(used.stats.NanoAiding.FirstAid, 7); + await owner.save(output + '/earned-kit-used'); + + // Return along the observed narrow road, checking each arrival before indoor points. + if (!owner.state.camera.firstPerson) await owner.key('F8'); + for (const [x, z] of [[187, 124], [187, 116]]) { + await owner.walk(x, z); + if (owner.local().playfield === 705) break; + } + assert.equal(owner.local().playfield, 705); + for (const [x, z] of [[781, 517], [793, 521], [797, 524], [801, 549], [801, 624], + [784, 653], [784, 693], [804, 754], [804, 774], [804, 794], [804, 814], [804, 834], + [804, 854], [804, 865], [825, 872], [831, 872], [830.5, 888], [885, 888], [885, 860], + [900, 860], [920, 843], [938, 843], [945, 843.5], [951, 843.5], [968, 843], [983, 843], [990, 843]]) { + await owner.walk(x, z); + if (owner.local().playfield === 3000) break; + } + assert.equal(owner.local().playfield, 3000); + for (const [x, z] of [[104.3, 150.2], [102.5, 143], [102.5, 102], [109, 102], [112, 101]]) { + await owner.walk(x, z); + if (owner.local().playfield === 950) break; + } + assert.equal(owner.local().playfield, 950); + for (const [x, z] of [[62.8, 65], [63, 75], [85, 75], [120, 75], [160, 70], [176.3, 63.2]]) + await owner.walk(x, z); + fights.push(await outdoorFight(owner, 2, 'authored-level-two')); + assert.equal(fights.at(-1).fightStart.enemy.level, 2); + credits += fights.at(-1).corpse.credits; + // Account for every issued identity, consumed crystal, charge and generated item. const combatUses = fights.reduce((total, fight) => total + fight.combatUses, 0); const expected = before.Items.filter(item => item.ID !== crystal.id && - (item.Template !== 116628 || trainingUses + combatUses < 25)).map(item => { + (item.Template !== 116628 || trainingUses + combatUses + levelTrainingUses < 25)).map(item => { + if (item.ID === displaced?.ID) return displaced; if (item.ID === bat.id) return {...item, Slot: 6}; if (item.ID === shirt.id) return {...item, Slot: 21}; - if (item.Template === 116628) return {...item, Count: 25 - trainingUses - combatUses}; + if (item.Template === 116628) return {...item, Count: 25 - trainingUses - combatUses - levelTrainingUses}; return item; }); - for (const fight of fights) expected.push(...fight.parts); - expected.push(...rewards); + for (const fight of fights) expected.push(...fight.parts.filter(item => item.ID !== sale.ID)); + expected.push(wornReward, {...kit, Count: 24}); expected.sort((a, b) => a.ID - b.ID); const final = await (await owner.page.request.get(url + '/test-state')).json(); assert.deepEqual(final.inventory.Items, expected); assert.equal(final.inventory.Credits, credits); + assert.equal(final.level, 2); + assert.equal(final.experience, fights.length * 100 - 1450); + assert.equal(final.stats.ImprovementPoints, 5032 - rewardTrainingCost); + assert.equal(final.health, 111); assert.deepEqual(final.inventory.LearnedNanos, [43371]); await fs.writeFile(output + '/ledger.json', JSON.stringify({issued: before, trained: trained.stats, - fights, mission, advertised, rewards, trainingUses, combatUses, - inventory: final.inventory, health: final.health}, null, 2) + '\n'); + fights, mission, advertised, rewards, wornReward, displaced, rewardTrainingCost, sale, kit, + kitNano: {before: nanoBefore, after: nanoAfter}, + trainingUses, combatUses, levelTrainingUses, stats: final.stats, level: final.level, + experience: final.experience, inventory: final.inventory, health: final.health}, null, 2) + '\n'); const reconnectPose = {playfield: owner.local().playfield, position: owner.local().position}; await owner.page.reload(); await owner.ready(); @@ -541,7 +822,8 @@ try { assert.equal(actual.slot, item.Slot >= 64 ? item.Slot - 16 : item.Slot); assert.equal(actual.count, item.Count); assert.equal(actual.quality, item.Quality); - assert.deepEqual(actual.templates, [item.Template, item.Template]); + assert.deepEqual(actual.templates, item.Template === 42640 && item.Quality > 1 + ? [42640, 42641] : [item.Template, item.Template]); } await owner.key('KeyI'); await owner.page.keyboard.press('Control+1'); @@ -556,7 +838,7 @@ try { assert.equal(observer.local().stats[53], 1500); assert.equal(observer.local().stats[61], 0); for (const game of games) assert.deepEqual(game.errors, []); - console.log('PASS: ordinary starter mission, six kills, exact rewards, recovery and page ownership'); + console.log('PASS: ordinary starter level, earned reward wear, funded kit, next-level kill and page ownership'); } finally { try { for (const [index, game] of games.entries()) await game.save(output + '/client-' + index);