tools/client/test_aimed_shot.mjs (4551B)
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: 'aimed_shot', 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 Aimed Shot HP agrees', state => 21 state.actors.find(actor => actor.type === 50000 && actor.id === evidence.initial.target)?.stats[27] === health); 22 await page.goto(url); 23 await game.ready(); 24 if (!game.state.camera.firstPerson) await game.key('F8'); 25 await game.key('KeyI'); 26 evidence.initial = await server(); 27 const cell = game.state.grids.flatMap(grid => grid.cells).find(cell => cell.identity[0] === 104 && cell.identity[1] === 51 && !cell.dummy); 28 assert(cell, 'issued or stocked rifle is visible'); 29 await game.click((cell.bounds[0]+cell.bounds[2])/2, (cell.bounds[1]+cell.bounds[3])/2, 'right'); 30 await waitServer('rifle equipped normally', state => state.inventory.Items.some(item => 31 item.ID === evidence.initial.inventory.Items[3].ID && item.Slot === 6)); 32 await game.wait('native equipped weapon ready', state => game.local(state).weapons.some(weapon => weapon.slot === 6)); 33 evidence.equipped = await server(); 34 assert.equal((await page.request.post(url + '/test-hold-attacks')).status(), 204); 35 await page.keyboard.press('Control+2'); 36 await game.wait('native command grid opens', state => state.grids.some(grid => grid.cells.some(cell => cell.identity[0] === 57008 && cell.identity[1] === 49575 && !cell.dummy))); 37 await game.save(output + '/commands'); 38 const sneak = game.state.grids.flatMap(grid => grid.cells).find(cell => cell.identity[0] === 57008 && cell.identity[1] === 49575 && !cell.dummy); 39 assert(sneak, 'native Sneak command is visible'); 40 await game.click((sneak.bounds[0]+sneak.bounds[2])/2, (sneak.bounds[1]+sneak.bounds[3])/2, 'right'); 41 await waitServer('server approves concealment', state => state.sneaking); 42 await game.wait('native sneak feature set', state => (game.local(state).stats[224] & 128) !== 0); 43 evidence.sneaking = await server(); 44 await game.save(output + '/sneaking'); 45 await game.key('Tab'); 46 await game.wait('original Leet selected', state => state.selected[0] === 50000 && state.selected[1] === evidence.initial.target); 47 await game.key('KeyO'); 48 await waitServer('opening shot damage and lock committed', state => state.health === 1000-state.damage && state.locked && !state.sneaking && state.fighting === state.target); 49 await checkNative(1000-evidence.initial.damage); 50 await game.wait('native sneak feature cleared', state => (game.local(state).stats[224] & 128) === 0); 51 evidence.first = await server(); 52 assert(evidence.first.remaining > 25 && evidence.first.remaining <= 52); 53 assert.deepEqual(evidence.first.inventory, evidence.equipped.inventory); 54 await game.save(output + '/first'); 55 56 await game.key('KeyO'); 57 assert.equal((await server()).health, evidence.first.health); 58 await page.reload(); 59 await game.ready(); 60 evidence.reconnected = await server(); 61 assert(evidence.reconnected.locked && !evidence.reconnected.sneaking); 62 assert.equal(evidence.reconnected.health, evidence.first.health); 63 assert.deepEqual(evidence.reconnected.inventory, evidence.first.inventory); 64 await checkNative(evidence.first.health); 65 await game.save(output + '/reconnected'); 66 assert.deepEqual(game.errors, []); 67 console.log('PASS:', evidence.initial.weapon, 'native sneak, opening Aimed Shot, reveal, cooldown, unchanged inventory and reconnect'); 68 } finally { 69 try { 70 await fs.mkdir(output, {recursive: true}); 71 await fs.writeFile(output + '/verification.json', JSON.stringify(evidence, null, 2) + '\n'); 72 if (game) await game.save(output + '/final'); 73 } finally { await browser.close(); } 74 }