aorecomp

Anarchy Online classic in the browser

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


tools/client/test_courtyard_insurance.mjs (2052B)


      1 import assert from 'node:assert/strict';
      2 import {createRequire} from 'node:module';
      3 import {GameTest} from './game_test.mjs';
      4 
      5 const {chromium} = createRequire(import.meta.url)('playwright');
      6 const [url, output] = process.argv.slice(2);
      7 const browser = await chromium.launch({executablePath: '/usr/bin/chromium',
      8   args: ['--enable-gpu', '--use-gl=angle', '--use-angle=gl', '--no-sandbox', '--disable-dev-shm-usage',
      9     '--disable-background-timer-throttling', '--disable-renderer-backgrounding']});
     10 const context = await browser.newContext({viewport: {width: 1024, height: 768}});
     11 await context.addCookies([{name: 'ao_client', value: 'courtyard-check', url}]);
     12 const page = await context.newPage();
     13 const game = await GameTest.attach(page);
     14 try {
     15   await page.goto(url);
     16   await game.ready();
     17   await game.save(output + '/start');
     18   for (const [index, [x, z]] of [[902.5, 565.5], [909, 565.5], [915, 575]].entries()) {
     19     await game.walk(x, z);
     20     const state = await (await page.request.get(url + '/test-state')).json();
     21     console.log('POINT', index, game.local().position, state.position);
     22     assert(Math.hypot(...state.position.map((value, axis) => value - game.local().position[axis])) < 0.5);
     23     const [minimum, maximum] = [[20, 20.1], [20.4, 20.5], [20.2, 20.3]][index];
     24     assert(game.local().position[1] >= minimum && game.local().position[1] <= maximum);
     25     await game.save(output + '/point-' + index);
     26   }
     27   const [x, y] = await game.pick(51005, 3221357249);
     28   await game.click(x, y, 'right');
     29   await game.wait('original courtyard scanner saves', () => game.events.some(event => event.direction === 'framereceived' &&
     30     event.opcode === '5e477770' && Buffer.from(event.hex, 'hex').readUInt32BE(29) === 79));
     31   assert.equal((await (await page.request.get(url + '/test-state')).json()).scanner, 3221357249);
     32   assert.equal(game.errors.length, 0);
     33   console.log('PASS: original courtyard stair entrance reaches and uses the scanner');
     34 } finally {
     35   try { await game.save(output + '/final'); }
     36   finally { await browser.close(); }
     37 }