aorecomp

Anarchy Online classic in the browser

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


tools/client/test_stale_worn_deposit.mjs (5691B)


      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: 'stale-worn-deposit', 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   const cell = (state, page, slot) => state.grids.flatMap(grid => grid.cells).find(cell =>
     22     cell.identity[0] === page && cell.identity[1] === slot && !cell.dummy);
     23   const click = async (cell, button = 'left') => {
     24     assert(cell);
     25     await game.click((cell.bounds[0] + cell.bounds[2]) / 2, (cell.bounds[1] + cell.bounds[3]) / 2, button);
     26   };
     27   const armor = [5, 5, 1, 1, 5, 5, 1, 5];
     28   assert.deepEqual(game.local().effectiveArmor, armor);
     29   await game.key('i');
     30   await click(cell(game.state, 104, 49), 'right');
     31   await game.wait('empty bag open', state => state.grids.some(grid => grid.totalCells === 21));
     32   await page.keyboard.press('Control+1');
     33   assert((await page.request.post(url + '/test-stale-view')).ok());
     34   await click(cell(game.state, 104, 48));
     35   await game.click(867, 206);
     36   await game.wait('real axe equip request', () => game.events.some(event => event.direction === 'framesent' && event.opcode === '47537a24'));
     37   evidence.pending = await server();
     38   assert.equal(evidence.pending.pending.itemID, 1);
     39   assert.deepEqual(evidence.pending.armor, [0, 0, 0, 0, 0, 0, 0, 0]);
     40   await game.wait('local equip animation ended', state => !game.local(state).actions.includes(3) && !game.local(state).actions.includes(6));
     41   await game.click(953, 53);
     42   const sequence = game.sequence;
     43   await game.click(927, 148);
     44   await game.wait('actual stale vest pickup', state => state.dragged[0] === 102 && state.dragged[1] === 21);
     45   await click(game.state.grids.find(grid => grid.totalCells === 21).cells.find(cell => cell.identity[0] === 0));
     46   await game.wait('real stale worn deposit', () => game.events.some(event => event.sequence > sequence && event.direction === 'framesent' &&
     47     event.opcode === '47537a24' && Buffer.from(event.hex, 'hex').readUInt32BE(29) === 102 && Buffer.from(event.hex, 'hex').readUInt32BE(37) === 51017));
     48   evidence.refused = await server();
     49   assert.deepEqual(evidence.refused, evidence.pending);
     50   await game.save(output + '/requested');
     51   await game.wait('stale vest row and all eight effects cleared', state => !game.local(state).inventory.some(item => item.slot === 21) &&
     52     game.local(state).effectiveArmor.every(value => value === 0));
     53   const replies = game.events.filter(event => event.sequence > sequence && event.direction === 'framereceived' &&
     54     ['5e477770', '35505644'].includes(event.opcode)).map(event => [event.opcode,
     55       ...Array.from({length: event.opcode === '35505644' ? 9 : 5}, (_, index) => Buffer.from(event.hex, 'hex').readUInt32BE(29 + index * 4))]);
     56   assert.deepEqual(replies, [['5e477770', 146, 102, 21, 0, 0], ['35505644', 85481, 85481, 1, 1, 7, 102, 21, 0, 0],
     57     ['5e477770', 112, 102, 21, 0, 0]]);
     58   await game.save(output + '/corrected');
     59   assert((await page.request.post(url + '/test-complete')).ok());
     60   await game.wait('original pending axe completes', state => game.local(state).inventory.some(item => item.id === 1 && item.slot === 6));
     61   evidence.completed = await server();
     62   assert.equal(evidence.completed.pending, null);
     63 
     64   // Replay reveals the vest's actual bag placement; wear that same physical item.
     65   await page.reload();
     66   await game.ready();
     67   if (!cell(game.state, 104, 49)) await game.key('i');
     68   await click(cell(game.state, 104, 49), 'right');
     69   await game.wait('exact vest restored in its bag', state => cell(state, 107, 65536));
     70   await page.keyboard.press('Control+1');
     71   await game.click(953, 53);
     72   const retry = game.sequence;
     73   await click(cell(game.state, 107, 65536));
     74   await game.click(927, 148);
     75   await game.wait('real recovered vest wear', () => game.events.some(event => event.sequence > retry && event.direction === 'framesent' && event.opcode === '47537a24'));
     76   assert((await page.request.post(url + '/test-complete')).ok());
     77   await game.wait('retained vest effects applied exactly once', state => game.local(state).inventory.some(item => item.id === 2 && item.slot === 21) &&
     78     game.local(state).effectiveArmor.every((value, index) => value === armor[index]));
     79   evidence.final = await server();
     80   await page.reload();
     81   await game.ready();
     82   assert.deepEqual(await server(), evidence.final);
     83   assert.deepEqual(game.local().inventory.map(item => [item.id, item.slot]), [[1, 6], [2, 21], [3, 49]]);
     84   assert.deepEqual(game.local().effectiveArmor, armor);
     85   assert.deepEqual(game.errors, []);
     86   assert.equal(game.dropped, 0);
     87   console.log('PASS: stale worn deposit clears exact source/effects, preserves pending equip, and recovers all three identities');
     88 } finally {
     89   try {
     90     await fs.mkdir(output, {recursive: true});
     91     await fs.writeFile(output + '/verification.json', JSON.stringify(evidence, null, 2) + '\n');
     92     if (game) await game.save(output + '/final');
     93   } finally { await browser.close(); }
     94 }