tools/client/test_faction_progression.mjs (7222B)
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: 'faction-progression', 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 frame = async (type, id) => { 20 const point = await game.point(512, 300); 21 let mouseY = point.y, sequence = game.sequence; 22 await page.mouse.move(point.x, mouseY); 23 await page.mouse.down({button: 'right'}); 24 try { 25 await game.waitInput(sequence, 1025); 26 const deadline = Date.now() + 10000; 27 for (;;) { 28 await game.snapshot(); 29 const y = game.state.actors.find(actor => actor.type === type && actor.id === id).screenPosition[1]; 30 if (y >= 350 && y <= 550) break; 31 assert(Date.now() < deadline, 'Could not frame faction checkpoint target'); 32 mouseY += y > 550 ? 10 : -10; 33 await page.mouse.move(point.x, mouseY, {steps: 2}); 34 } 35 } finally { 36 sequence = game.sequence; 37 await page.mouse.up({button: 'right'}); 38 } 39 await game.waitInput(sequence, 1026); 40 }; 41 await page.goto(url); 42 await game.ready(); 43 await page.waitForFunction(() => touchRegion(500, 400)?.world === true); 44 if (!game.state.camera.firstPerson) await game.key('F8'); 45 const initial = evidence.initial = await server(); 46 if (initial.phase === 0) { 47 assert.equal(initial.targetHealth, 20); 48 assert.equal(initial.level, 1); 49 await frame(50000, initial.target); 50 await game.click(...await game.pick(50000, initial.target)); 51 await game.wait('enemy selected', state => state.selected[1] === initial.target); 52 await game.key('q'); 53 await game.wait('native level-two award', state => { 54 assert(game.local(state).stats[27] > 0, 'Faction checkpoint died'); 55 return game.local(state).stats[54] === 2; 56 }, 120000); 57 evidence.levelled = await server(); 58 assert.equal(evidence.levelled.targetHealth, 0); 59 assert.equal(evidence.levelled.experience, 0); 60 assert.equal(evidence.levelled.stats.ImprovementPoints, initial.stats.ImprovementPoints + 4000); 61 await game.save(output + '/level-two'); 62 63 // Spend the newly awarded IP beyond the level-one Body Development cap. 64 await game.key('KeyU'); 65 await game.click(334, 196); 66 for (let point = 0; point < 6; ++point) await game.click(835, 346); 67 await game.click(445, 622); 68 await game.wait('level-two Body Development purchase', state => 69 game.local(state).stats[152] === 15 && game.local(state).stats[53] === initial.stats.ImprovementPoints + 4000 - 69); 70 evidence.trained = await server(); 71 assert.equal(evidence.trained.stats.Body.BodyDevelopment, 15); 72 await game.save(output + '/trained'); 73 } 74 75 // Return the exact prepared book through native item-on-booth Use. 76 await frame(56001, initial.booth); 77 await game.key('KeyI'); 78 const book = initial.inventory.Items.find(item => item.ID === initial.missions[0].objective); 79 assert(book && book.Template === 40822); 80 await game.wait('prepared book visible in inventory', state => state.grids.some(grid => 81 grid.cells.some(cell => cell.identity[0] === 104 && cell.identity[1] === book.Slot - 16 && !cell.dummy))); 82 const cell = game.state.grids.flatMap(grid => grid.cells).find(cell => 83 cell.identity[0] === 104 && cell.identity[1] === book.Slot - 16 && !cell.dummy); 84 await game.click((cell.bounds[0] + cell.bounds[2]) / 2, (cell.bounds[1] + cell.bounds[3]) / 2); 85 await game.wait('prepared book picked', state => state.dragged[0] === 104); 86 await game.click(...await game.pick(56001, initial.booth), 'right'); 87 const paid = initial.inventory.Credits + initial.definition.Credits; 88 await game.wait('native saved reward paid', state => game.local(state).stats[61] === paid); 89 evidence.completed = await server(); 90 assert(evidence.completed.completed); 91 assert.equal(evidence.completed.experience, 0); 92 assert.equal(evidence.completed.level, 2); 93 const retained = initial.inventory.Items.filter(item => item.ID !== initial.missions[0].id && item.ID !== book.ID); 94 const reward = evidence.completed.inventory.Items.find(item => !retained.some(old => old.ID === item.ID)); 95 assert(reward); 96 assert.equal(reward.Template, initial.definition.RewardItem); 97 assert.equal(reward.Quality, initial.definition.RewardQuality); 98 assert.deepEqual(evidence.completed.inventory.Items.filter(item => item.ID !== reward.ID), retained); 99 await game.save(output + '/completed'); 100 await game.key('KeyI'); 101 102 if (initial.phase === 0) { 103 await game.click(...await game.pick(56001, initial.booth), 'right'); 104 await game.wait('repeat mission request form', state => state.regions.some(region => 105 region[0] === 150 && region[1] === 180 && region[2] === 220 && region[3] === 200)); 106 await game.click(100, 163); 107 await game.wait('level-two repeat request fee', state => game.local(state).stats[61] === paid - 2); 108 evidence.offer = (await server()).offer; 109 assert.equal(evidence.offer.Credits, 1000); 110 assert.equal(evidence.offer.RewardQuality, 2); 111 assert.equal(evidence.offer.Entrance, initial.booth); 112 await game.click(30, 45); 113 await game.click(74, 190); 114 await game.wait('repeat mission key delivered', state => game.local(state).inventory.some(item => item.templates[0] === 28577)); 115 evidence.accepted = await server(); 116 assert.equal(evidence.accepted.missions.length, 1); 117 assert.notEqual(evidence.accepted.missions[0].id, initial.missions[0].id); 118 assert.deepEqual(evidence.accepted.missions[0].definition, 119 {...evidence.offer, RewardItems: null, Encounters: null, PassageDoor: 0}); 120 await game.save(output + '/repeat-accepted'); 121 } 122 const beforeReload = await server(); 123 await page.reload(); 124 await game.ready(); 125 await page.waitForFunction(() => touchRegion(500, 400)?.world === true); 126 evidence.reconnected = await server(); 127 assert.deepEqual(evidence.reconnected.inventory, beforeReload.inventory); 128 assert.deepEqual(evidence.reconnected.stats, beforeReload.stats); 129 assert.deepEqual(evidence.reconnected.missions, beforeReload.missions); 130 assert.equal(game.local().stats[54], 2); 131 assert.deepEqual(game.errors, []); 132 console.log('PASS:', initial.booth, 'phase', initial.phase, 'level/training, saved settlement and repeat contract retained'); 133 } finally { 134 try { 135 await fs.mkdir(output, {recursive: true}); 136 await fs.writeFile(output + '/verification.json', JSON.stringify(evidence, null, 2) + '\n'); 137 if (game) await game.save(output + '/final'); 138 } finally { await browser.close(); } 139 }