aorecomp

Anarchy Online classic in the browser

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


tools/client/test_armor_requirements.mjs (3389B)


      1 import assert from 'node:assert/strict';
      2 import fs from 'node:fs/promises';
      3 import {createRequire} from 'node:module';
      4 import {GameTest} from './game_test.mjs';
      5 
      6 const {chromium} = createRequire(import.meta.url)('playwright');
      7 const [url, output] = process.argv.slice(2);
      8 const browser = await chromium.launch({executablePath: '/usr/bin/chromium', args: [
      9   '--enable-gpu', '--use-gl=angle', '--use-angle=gl', '--no-sandbox', '--disable-dev-shm-usage',
     10   '--disable-background-timer-throttling', '--disable-renderer-backgrounding']});
     11 const evidence = [];
     12 try {
     13   const cases = await (await fetch(url + '/test-cases')).json();
     14   for (const fixture of cases) {
     15     const context = await browser.newContext({viewport: {width: 1024, height: 768}});
     16     let game;
     17     try {
     18       await context.addCookies([{name: 'ao_client', value: fixture.token, url}]);
     19       const page = await context.newPage();
     20       game = await GameTest.attach(page);
     21       await page.goto(url);
     22       await game.ready();
     23       assert.equal(game.local().id, fixture.id);
     24       assert.equal(game.local().stats[20], fixture.sense);
     25       assert.equal(game.local().stats[17], fixture.agility);
     26       const state = async () => (await page.request.get(url + '/test-state/' + fixture.id)).json();
     27       const before = await state();
     28       await game.key('i');
     29       await page.keyboard.press('Control+1');
     30       await game.click(953, 53);
     31       await game.wait('exact carried vest available', snapshot => game.local(snapshot).inventory.some(item =>
     32         item.id === fixture.id && item.slot === 48 && item.quality === 2));
     33       const sequence = game.sequence;
     34       const source = game.state.grids.flatMap(grid => grid.cells).find(cell =>
     35         cell.identity[0] === 104 && cell.identity[1] === 48 && !cell.dummy);
     36       assert(source);
     37       await game.click((source.bounds[0] + source.bounds[2]) / 2, (source.bounds[1] + source.bounds[3]) / 2, 'right');
     38       if (fixture.eligible) {
     39         await game.wait('qualified native wear request', () => game.events.some(event => event.sequence > sequence &&
     40           event.direction === 'framesent' && event.opcode === '47537a24'));
     41         await game.wait('qualified exact vest worn', snapshot => game.local(snapshot).inventory.some(item =>
     42           item.id === fixture.id && item.slot === 21));
     43         assert.deepEqual(game.local().effectiveArmor, [9, 10, 2, 2, 9, 9, 2, 6]);
     44       } else {
     45         // Consumed mouse release and a later native frame establish local refusal.
     46         assert(!game.events.some(event => event.sequence > sequence && event.direction === 'framesent' && event.opcode === '47537a24'));
     47         assert.deepEqual(await state(), before);
     48         assert.deepEqual(game.local().effectiveArmor, [0, 0, 0, 0, 0, 0, 0, 0]);
     49       }
     50       evidence.push({fixture, inventory: await state()});
     51       assert.deepEqual(game.errors, []);
     52       assert.equal(game.dropped, 0);
     53       console.log('PASS: anchor' + fixture.anchor + ' Sense' + fixture.sense + '/Agility' + fixture.agility + ' eligible=' + fixture.eligible);
     54     } finally {
     55       try { if (game) await game.save(output + '/' + fixture.id); }
     56       finally { await context.close(); }
     57     }
     58   }
     59 } finally {
     60   try {
     61     await fs.mkdir(output, {recursive: true});
     62     await fs.writeFile(output + '/verification.json', JSON.stringify(evidence, null, 2) + '\n');
     63   } finally { await browser.close(); }
     64 }