aorecomp

Anarchy Online classic in the browser

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


tools/client/test_bank_attachment.mjs (4622B)


      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', args: [
      8   '--enable-gpu', '--use-gl=angle', '--use-angle=gl', '--no-sandbox', '--disable-dev-shm-usage',
      9   '--disable-background-timer-throttling', '--disable-renderer-backgrounding']});
     10 let game;
     11 try {
     12   const context = await browser.newContext({viewport: {width: 1024, height: 768}});
     13   await context.addCookies([{name: 'ao_client', value: 'bank-attachment', url}]);
     14   const page = await context.newPage();
     15   game = await GameTest.attach(page);
     16   const server = async () => (await page.request.get(url + '/test-state')).json();
     17   await page.goto(url);
     18   await game.ready();
     19   await page.waitForFunction(() => touchRegion(500, 400)?.world === true);
     20   await game.snapshot();
     21   assert.deepEqual(game.local().inventory.map(item => [item.id, item.type, item.slot]), [[1, 51018, 6]]);
     22   const before = await server();
     23   if (!game.state.camera.firstPerson) await game.key('F8');
     24   await game.click(...await game.pick(51005, 3221357727), 'right');
     25   await game.wait('bank opens', state => state.regions.some(region =>
     26     region[0] === 0 && region[1] === 0 && region[2] === 178 && region[3] === 128));
     27   await game.save(output + '/opened');
     28   assert.deepEqual(game.local().inventory.map(item => [item.id, item.type, item.slot]), [[1, 51018, 6]],
     29     'banked slot6 must not replace worn slot6');
     30   assert.deepEqual(await server(), before);
     31 
     32   // The uninstantiated banked bag must still withdraw and open through normal Use.
     33   await game.key('KeyI');
     34   await game.click(30, 45);
     35   await game.wait('exact backpack withdrawn', state => game.local(state).inventory.some(item => item.id === 2 && item.slot === 48));
     36   await game.click(170, 8);
     37   await game.wait('bank closes', state => !state.regions.some(region =>
     38     region[0] === 0 && region[1] === 0 && region[2] === 178 && region[3] === 128));
     39   const grids = game.state.grids.length, opened = game.sequence;
     40   await game.click(681, 45, 'right');
     41   await game.wait('withdrawn backpack opens its contents', state => state.grids.length > grids &&
     42     game.events.some(event => event.sequence > opened && event.direction === 'framereceived' && event.opcode === '4e536976'));
     43   await game.save(output + '/bag-open');
     44   const closing = game.sequence;
     45   await game.click(681, 45, 'right');
     46   await game.wait('backpack closes normally', () => game.events.some(event => event.sequence > closing &&
     47     event.direction === 'framereceived' && event.opcode === '2049527c' && event.actor[1] === 2));
     48   await game.click(...await game.pick(51005, 3221357727), 'right');
     49   await game.wait('bank reopens', state => state.regions.some(region =>
     50     region[0] === 0 && region[1] === 0 && region[2] === 178 && region[3] === 128));
     51   await game.click(681, 45);
     52   await game.click(30, 45);
     53   await game.wait('same backpack returned to bank', state => !game.local(state).inventory.some(item => item.id === 2));
     54   await game.click(170, 8);
     55   await page.keyboard.press('Control+1');
     56   await game.click(867, 206, 'right');
     57   await game.wait('same worn weapon removed', state => game.local(state).inventory.some(item => item.id === 1 && item.slot === 48));
     58   await game.wait('ordinary source usable', state => state.grids.some(grid => grid.cells.some(cell =>
     59     cell.identity[0] === 104 && cell.identity[1] === 48 && !cell.dummy)));
     60   await game.wait('equipment action ends', state => !game.local(state).actions.includes(3) && !game.local(state).actions.includes(6));
     61   await game.click(681, 45, 'right');
     62   await game.wait('same physical weapon worn again', state => game.local(state).inventory.some(item => item.id === 1 && item.slot === 6));
     63   await game.save(output + '/reworn');
     64   const expected = {...before, Bank: before.Bank.map(item => ({...item, Slot: 0}))};
     65   assert.deepEqual(await server(), expected);
     66   await page.reload();
     67   await game.ready();
     68   await page.waitForFunction(() => touchRegion(500, 400)?.world === true);
     69   await game.snapshot();
     70   assert.deepEqual(game.local().inventory.map(item => [item.id, item.type, item.slot]), [[1, 51018, 6]]);
     71   assert.deepEqual(await server(), expected);
     72   assert.deepEqual(game.errors, []);
     73   console.log('PASS: bank backpack preserves worn identity, normal withdrawal/Use, weapon removal/rewear and page/cold ownership');
     74 } finally {
     75   try { if (game) await game.save(output + '/final'); }
     76   finally { await browser.close(); }
     77 }