aorecomp

Anarchy Online classic in the browser

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


tools/client/test_starter_mission_targets.mjs (4115B)


      1 import assert from 'node:assert/strict';
      2 import {createRequire} from 'node:module';
      3 import {GameTest} from './game_test.mjs';
      4 import {startStarter, finishStarter, enterOmniTraining} from './create_starter.mjs';
      5 
      6 const {chromium} = createRequire(import.meta.url)('playwright');
      7 const [url, output] = process.argv.slice(2);
      8 assert(url && output, 'Run through TestBrowserStarterMissionTargets');
      9 const browser = await chromium.launch({executablePath: '/usr/bin/chromium',
     10   args: ['--enable-gpu', '--use-gl=angle', '--use-angle=gl', '--no-sandbox', '--disable-dev-shm-usage']});
     11 let game;
     12 
     13 try {
     14   const context = await browser.newContext({viewport: {width: 1024, height: 768}});
     15   const page = await context.newPage();
     16   game = await GameTest.attach(page);
     17 
     18   // Create the normal starter, then reach its backyard through the training exit.
     19   await page.goto(url);
     20   await game.ready();
     21   await startStarter(game);
     22   await finishStarter(game, 'Missionpick', 'mission target regression password');
     23   await enterOmniTraining(game);
     24   assert.equal(game.local().playfield, 950);
     25   const issued = game.local().inventory;
     26   await game.save(output + '/created');
     27   await game.hold('KeyS', 'leave the training entrance', state =>
     28     game.local(state)?.playfield === 3000, 60000);
     29   await game.wait('backyard and its original mission statels', state =>
     30     game.local(state)?.playfield === 3000 &&
     31     state.actors.some(actor => actor.type === 56001 && actor.id === 3221228472) &&
     32     state.actors.some(actor => actor.type === 56006 && actor.id === 3221228472), 60000);
     33   await game.ready();
     34   const backyard = await (await page.request.get(url + '/test-state')).json();
     35   assert.equal(backyard.playfield, 3000);
     36 
     37   // Equal numeric IDs belong to separate native objects, including a third scene door.
     38   const booth = game.state.actors.find(actor => actor.type === 56001 && actor.id === 3221228472);
     39   const entrance = game.state.actors.find(actor => actor.type === 56006 && actor.id === 3221228472);
     40   const door = game.state.actors.find(actor => actor.type === 51005 && actor.id === 3221228472);
     41   assert(Math.hypot(booth.position[0] - 100.03333, booth.position[2] - 148.27986) < 0.01);
     42   assert(Math.hypot(entrance.position[0] - 89.30216, entrance.position[2] - 151.16087) < 0.01);
     43   assert(Math.hypot(door.position[0] - 102.95067, door.position[2] - 130.01703) < 0.01);
     44   await game.save(output + '/backyard');
     45 
     46   for (const [x, z] of [[102.5, 102], [102.5, 143], [104, 149.5], [103, 149.1]])
     47     await game.walk(x, z);
     48   assert.equal(game.local().playfield, 3000);
     49   if (!game.state.camera.firstPerson) await game.key('F8');
     50   await game.save(output + '/booth-approach');
     51   const [x, y] = await game.pick(56001, 3221228472);
     52   await game.click(x, y, 'right');
     53   // The targeted callback puts its success word after the actor and target flag.
     54   await game.wait('successful native mission-booth callback', () => game.events.some(event =>
     55     event.kind === 'packet' && event.direction === 'framereceived' && event.opcode === '52526858' &&
     56     Buffer.from(event.hex, 'hex').readUInt32BE(29) === 1));
     57   await game.wait('visible mission difficulty window', state => state.regions.some(
     58     ([left, top, right, bottom]) => left === 150 && top === 180 && right === 220 && bottom === 200));
     59   await game.save(output + '/booth-open');
     60   await game.click(183, 190);
     61   await game.wait('mission difficulty window closed', state => !state.regions.some(
     62     ([left, top, right, bottom]) => left === 150 && top === 180 && right === 220 && bottom === 200));
     63 
     64   // Inspection and cancellation preserve the complete issued loadout and all progress.
     65   await game.snapshot();
     66   assert.deepEqual(game.local().inventory, issued);
     67   const final = await (await page.request.get(url + '/test-state')).json();
     68   assert.deepEqual(final.inventory, backyard.inventory);
     69   assert.deepEqual(game.errors, []);
     70   assert.equal(game.dropped, 0);
     71   console.log('PASS: ordinary backyard travel, distinct typed mission statels and native booth Use');
     72 } finally {
     73   try { if (game) await game.save(output + '/final'); }
     74   finally { await browser.close(); }
     75 }