aorecomp

Anarchy Online classic in the browser

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


tools/client/test_burst.mjs (4632B)


      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 let game;
     12 const evidence = {};
     13 try {
     14   const context = await browser.newContext({viewport: {width: 1024, height: 768}});
     15   await context.addCookies([{name: 'ao_client', value: 'burst', url}]);
     16   const page = await context.newPage();
     17   game = await GameTest.attach(page);
     18   const server = async () => (await page.request.get(url + '/test-state')).json();
     19   const waitServer = (label, predicate) => game.waitFor(label, async () => predicate(await server()));
     20   const checkNative = async health => game.wait('native Burst HP and ammunition agree', state =>
     21     state.actors.find(actor => actor.type === 50000 && actor.id === evidence.initial.target)?.stats[27] === health &&
     22     game.local(state).weapons.some(weapon => weapon.slot === 6 && weapon.loadedAmmo === (evidence.initial.weapon === 121571 ? -1 : 3)));
     23   await page.goto(url);
     24   await game.ready();
     25   if (!game.state.camera.firstPerson) await game.key('F8');
     26   await game.key('KeyI');
     27   evidence.initial = await server();
     28   const cell = game.state.grids.flatMap(grid => grid.cells).find(cell => cell.identity[0] === 104 && cell.identity[1] === 51 && !cell.dummy);
     29   assert(cell, 'issued or stocked SMG is visible');
     30   await game.click((cell.bounds[0]+cell.bounds[2])/2, (cell.bounds[1]+cell.bounds[3])/2, 'right');
     31   await waitServer('SMG equipped normally', state => state.inventory.Items.some(item =>
     32     item.ID === evidence.initial.inventory.Items[3].ID && item.Slot === 6));
     33   await game.wait('native equipped weapon ready', state => game.local(state).weapons.some(weapon => weapon.slot === 6));
     34   evidence.equipped = await server();
     35   assert.equal((await page.request.post(url + '/test-hold-attacks')).status(), 204);
     36   await game.key('Tab');
     37   await game.wait('original Leet selected', state => state.selected[0] === 50000 && state.selected[1] === evidence.initial.target);
     38   await game.key('KeyQ');
     39   await waitServer('normal fight started', state => state.fighting === evidence.initial.target);
     40   await game.key('KeyM');
     41   await waitServer('Burst damage and lock committed', state => state.health === 1000-state.damage && state.locked);
     42   await checkNative(1000-evidence.initial.damage);
     43   evidence.first = await server();
     44   assert.deepEqual(evidence.first.inventory, evidence.equipped.inventory);
     45   await game.save(output + '/first');
     46 
     47   await game.key('KeyM');
     48   assert.equal((await server()).health, evidence.first.health);
     49   await page.reload();
     50   await game.ready();
     51   evidence.reconnected = await server();
     52   assert(evidence.reconnected.locked);
     53   assert.equal(evidence.reconnected.health, evidence.first.health);
     54   assert.deepEqual(evidence.reconnected.inventory, evidence.first.inventory);
     55   await checkNative(evidence.first.health);
     56   await game.save(output + '/reconnected');
     57 
     58   // Wait for the real server deadline and native unlock rather than shortening it.
     59   await game.wait('native Burst unlock received', () => game.events.some(event => {
     60     if (event.direction !== 'framereceived' || event.opcode !== '5e477770') return false;
     61     const packet = Buffer.from(event.hex, 'hex');
     62     return packet.readUInt32BE(29) === 164 && packet.readUInt32BE(45) === 148;
     63   }), 60000);
     64   assert(!(await server()).locked);
     65   await game.click(...await game.pick(50000, evidence.initial.target));
     66   await game.key('KeyQ');
     67   await waitServer('fight resumed', state => state.fighting === evidence.initial.target);
     68   await game.key('KeyM');
     69   await waitServer('second Burst commits after expiry', state => state.health === 1000-2*state.damage && state.locked);
     70   await checkNative(1000-2*evidence.initial.damage);
     71   evidence.second = await server();
     72   assert.deepEqual(evidence.second.inventory, evidence.first.inventory);
     73   assert.deepEqual(game.errors, []);
     74   console.log('PASS:', evidence.initial.weapon, 'native equip, Burst, unchanged ammo, cooldown, reconnect and repeat');
     75 } finally {
     76   try {
     77     await fs.mkdir(output, {recursive: true});
     78     await fs.writeFile(output + '/verification.json', JSON.stringify(evidence, null, 2) + '\n');
     79     if (game) await game.save(output + '/final');
     80   } finally { await browser.close(); }
     81 }