aorecomp

Anarchy Online classic in the browser

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


tools/client/test_tower_wear.mjs (4359B)


      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 = {attempts: []};
     13 try {
     14   const context = await browser.newContext({viewport: {width: 1024, height: 768}});
     15   await context.addCookies([{name: 'ao_client', value: 'tower-wear', url}]);
     16   const page = await context.newPage();
     17   game = await GameTest.attach(page);
     18   await page.goto(url);
     19   await game.ready();
     20   const server = async () => (await page.request.get(url + '/test-state')).json();
     21   evidence.initial = await server();
     22   await game.key('KeyI');
     23   await page.keyboard.press('Control+1');
     24   await game.click(953, 53);
     25 
     26   // Explicit placement exercises ordinary wear, independently of tower Use.
     27   for (let attempt = 0; attempt < 2; ++attempt) {
     28     await game.wait('native equipment action finishes', state =>
     29       !game.local(state).actions.includes(3) && !game.local(state).actions.includes(6));
     30     const sequence = game.sequence;
     31     await game.click(681, 45);
     32     await game.wait('tower picked from carried inventory', state => state.dragged[0] === 104 && state.dragged[1] === 48);
     33     await game.click(867, 262);
     34     await game.wait('actual tower wear request', () => game.events.some(event => event.sequence > sequence &&
     35       event.direction === 'framesent' && event.opcode === '47537a24'));
     36     const request = game.events.find(event => event.sequence > sequence && event.direction === 'framesent' && event.opcode === '47537a24');
     37     const bytes = Buffer.from(request.hex, 'hex');
     38     assert.deepEqual([29, 33, 37, 41, 45].map(offset => bytes.readUInt32BE(offset)), [104, 48, 50000, 1, 26]);
     39     await game.wait('tower wear response', () => game.events.filter(event => event.sequence > sequence &&
     40       event.direction === 'framereceived' && event.opcode === '47537a24').length === 2 ||
     41       game.local().inventory.some(item => item.id === 1 && item.slot === 26));
     42     evidence.attempts.push(await server());
     43     await game.save(output + '/refused-' + attempt);
     44     assert.deepEqual(evidence.attempts[attempt], evidence.initial);
     45     assert(game.local().inventory.some(item => item.id === 1 && item.slot === 48));
     46     assert.deepEqual(game.state.dragged, [0, 0]);
     47     assert.deepEqual(game.local().effectiveArmor, [0, 0, 0, 0, 0, 0, 0, 0]);
     48   }
     49 
     50   // Supported armor still wears, removes and wears again with its full effect.
     51   for (const remove of [true, false]) {
     52     await game.click(735, 45, 'right');
     53     await game.wait('original shirt worn', state => game.local(state).inventory.some(item => item.id === 2 && item.slot === 21));
     54     assert.deepEqual(game.local().effectiveArmor, [0, 10, 0, 0, 0, 0, 0, 0]);
     55     if (remove) {
     56       await game.wait('shirt wear action finishes', state =>
     57         !game.local(state).actions.includes(3) && !game.local(state).actions.includes(6));
     58       await game.click(927, 148, 'right');
     59       await game.wait('original shirt removed', state => game.local(state).inventory.some(item => item.id === 2 && item.slot === 49));
     60       assert.deepEqual(game.local().effectiveArmor, [0, 0, 0, 0, 0, 0, 0, 0]);
     61     }
     62   }
     63   evidence.after = await server();
     64   await game.save(output + '/supported');
     65   await page.reload();
     66   await game.ready();
     67   assert.deepEqual(game.local().inventory.map(item => [item.id, item.slot, item.quality]).sort((a, b) => a[0] - b[0]),
     68     [[1, 48, 125], [2, 21, 1]]);
     69   assert.deepEqual(game.local().effectiveArmor, [0, 10, 0, 0, 0, 0, 0, 0]);
     70   assert.deepEqual(await server(), evidence.after);
     71   assert.deepEqual(game.errors, []);
     72   console.log('PASS: tower wear refuses twice with usable source; supported shirt and page/cold ownership retain both instances');
     73 } finally {
     74   try {
     75     await fs.mkdir(output, {recursive: true});
     76     await fs.writeFile(output + '/verification.json', JSON.stringify(evidence, null, 2) + '\n');
     77     if (game) await game.save(output + '/final');
     78   } finally { await browser.close(); }
     79 }