tools/client/test_concrete_cushion.mjs (10335B)
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', 9 args: ['--enable-gpu', '--use-gl=angle', '--use-angle=gl', '--no-sandbox', '--disable-dev-shm-usage', 10 '--disable-background-timer-throttling', '--disable-renderer-backgrounding']}); 11 const games = [], evidence = {}; 12 async function bagClick(game, id) { 13 await game.wait('native equipment action finishes', state => 14 !game.local(state).actions.includes(3) && !game.local(state).actions.includes(6)); 15 const cell = game.local().inventory.find(item => item.id === id).slot - 48; 16 assert(cell >= 0 && cell < 9); 17 await game.click(681 + cell % 3 * 54, 45 + Math.floor(cell / 3) * 54, 'right'); 18 } 19 try { 20 for (const index of [0, 1]) { 21 const context = await browser.newContext({viewport: {width: 1024, height: 768}}); 22 await context.addCookies([{name: 'ao_client', value: 'concrete_cushion-' + index, url}]); 23 const page = await context.newPage(), game = await GameTest.attach(page); 24 games.push(game); 25 await page.goto(url); 26 await game.ready(); 27 } 28 const [owner, observer] = games; 29 const state = async () => (await owner.page.request.get(url + '/test-state')).json(); 30 evidence.initial = await state(); 31 if (evidence.initial.inventory.Items.length === 4) { 32 assert.equal(evidence.initial.health, 20); 33 assert.equal(owner.local().stats[4], 1); 34 assert.equal(owner.local().stats[102], 238); 35 assert.equal(owner.local().stats[110], 142); 36 assert.equal(owner.local().stats[146], 112); 37 assert.equal(owner.local().stats[147], 112); 38 assert.equal(owner.local().stats[142], 144); 39 assert.equal(owner.local().stats[144], 17); 40 await owner.key('KeyI'); 41 await owner.page.keyboard.press('Control+1'); 42 for (const id of [1, 2, 3]) { 43 const sequence = observer.sequence; 44 await bagClick(owner, id); 45 await owner.wait('selected Concrete Cushion worn', snapshot => owner.local(snapshot).inventory.some(item => item.id === id && item.slot === 6)); 46 await observer.wait('observer receives selected Concrete Cushion', () => observer.events.some(event => 47 event.sequence > sequence && event.direction === 'framereceived' && event.opcode === '3b1d2268' && 48 event.actor[0] === 51018 && event.actor[1] === id)); 49 const event = observer.events.find(event => event.sequence > sequence && event.direction === 'framereceived' && 50 event.opcode === '3b1d2268' && event.actor[0] === 51018 && event.actor[1] === id); 51 const packet = Buffer.from(event.hex, 'hex'), stats = new Map(); 52 for (let offset = 59; offset < packet.readUInt16BE(6) - 4; offset += 8) 53 stats.set(packet.readUInt32BE(offset), packet.readUInt32BE(offset + 4)); 54 const [quality, definition, minimum, maximum, critical, value, attack] = { 55 1: [11, 125456, 1, 11, 18, 854, 126], 2: [84, 125456, 1, 30, 81, 18978, 93], 56 3: [85, 125457, 1, 30, 81, 19471, 92], 57 }[id]; 58 assert.equal(stats.get(23), definition); 59 const base = { 60 125456: {74: 851, 284: 17, 285: 11, 286: 1, 294: 126}, 61 125457: {74: 74342, 284: 145, 285: 49, 286: 1, 294: 59}, 62 }[definition]; 63 for (const [stat, expected] of Object.entries({74: value, 284: critical, 285: maximum, 286: minimum, 294: attack, 64 701: quality, 702: 125456, 703: 125457})) 65 assert.equal(stats.get(Number(stat)) ?? base[stat], expected, 'selected native Concrete Cushion stat ' + stat); 66 evidence['worn' + id] = {native: owner.local().inventory, server: await state()}; 67 const worn = await state(); 68 assert.deepEqual(worn.abilities, [208, 208]); 69 assert.equal(worn.rating, 256); 70 assert.equal(worn.maxHealth, evidence.initial.maxHealth + 6); 71 assert.equal(worn.maxNano, evidence.initial.maxNano + 3); 72 await Promise.all(games.map(game => game.wait('ability-derived native foundations', snapshot => 73 snapshot.actors.some(actor => actor.id === 1 && actor.stats[1] === worn.maxHealth && 74 (game !== owner || actor.stats[221] === worn.maxNano && actor.stats[22] === 256))))); 75 await owner.save(output + '/worn-' + id); 76 if (id !== 3) { 77 await owner.click(867, 206, 'right'); 78 await owner.wait('same Concrete Cushion removed', snapshot => owner.local(snapshot).inventory.some(item => item.id === id && item.slot >= 48)); 79 const removed = await state(); 80 assert.deepEqual(removed.abilities, [200, 200]); 81 assert.equal(removed.maxHealth, evidence.initial.maxHealth); 82 assert.equal(removed.maxNano, evidence.initial.maxNano); 83 } 84 } 85 await owner.key('KeyU'); 86 await owner.save(output + '/abilities'); 87 await owner.key('KeyU'); 88 const rejected = await state(), rejectionSequence = owner.sequence; 89 await bagClick(owner, 4); 90 await owner.save(output + '/rejected-86'); 91 assert(!owner.events.some(event => event.sequence > rejectionSequence && event.direction === 'framesent' && event.opcode === '47537a24')); 92 assert.deepEqual((await state()).inventory, rejected.inventory); 93 94 // An ordinary Q attack uses the selected QL85 damage and consumes no ammunition. 95 const deadline = Date.now() + 10000; 96 while (owner.state.selected[0] !== 50000 || owner.state.selected[1] !== rejected.target) { 97 assert(Date.now() < deadline, 'Native Tab did not select the controlled Leet'); 98 const selected = owner.state.selected; 99 await owner.key('Tab'); 100 await owner.wait('native target cycle advances', snapshot => snapshot.selected[0] !== selected[0] || snapshot.selected[1] !== selected[1]); 101 } 102 const attack = owner.sequence; 103 await owner.key('KeyQ'); 104 await owner.wait('ordinary selected-quality hit', () => owner.events.some(event => event.sequence > attack && 105 event.direction === 'framereceived' && event.opcode === '46002f16' && event.actor[1] === owner.local().id)); 106 const result = owner.events.find(event => event.sequence > attack && event.direction === 'framereceived' && 107 event.opcode === '46002f16' && event.actor[1] === owner.local().id); 108 assert.equal(Buffer.from(result.hex, 'hex').readUInt32BE(33), 0xffffffff); 109 await owner.key('KeyQ'); 110 await Promise.all(games.map(game => game.wait('native selected-quality impact', snapshot => 111 snapshot.actors.some(actor => actor.id === rejected.target && actor.stats[27] === 19)))); 112 evidence.hit = await state(); 113 assert.equal(evidence.hit.health, 19); 114 assert.equal(evidence.hit.fighting, 0); 115 assert.equal(evidence.hit.inventory.Items[2].Ammo, 0); 116 await owner.save(output + '/hit'); 117 118 // Cancel, then accept the QL11 instance's sale at the original training machine. 119 await owner.page.keyboard.press('Control+1'); 120 await owner.wait('weapon panel closed', snapshot => !snapshot.regions.some(([left, top, right, bottom]) => 121 left === 832 && top === 0 && right === 1024 && bottom === 360)); 122 if (!owner.state.camera.firstPerson) await owner.key('F8'); 123 // Approach facing the machine with its mesh above the chat window. 124 await owner.walk(60, 57); 125 await owner.walk(60, 54.5); 126 const offered = await state(); 127 for (let attempt = 0; attempt < 2; ++attempt) { 128 await owner.click(...await owner.pick(51035, 3221226422), 'right'); 129 await owner.wait('training machine open', snapshot => snapshot.regions.some(([left, top, right, bottom]) => 130 left === 832 && top === 0 && right === 1024 && bottom === 494)); 131 const cell = owner.local().inventory.find(item => item.id === 1).slot - 48; 132 await owner.click(681 + cell % 3 * 54, 45 + Math.floor(cell / 3) * 54); 133 const sequence = owner.sequence; 134 await owner.click(864, 416); 135 await owner.wait('sale offered', () => owner.events.some(event => event.sequence > sequence && 136 event.direction === 'framesent' && event.opcode === '36284f6e')); 137 assert.deepEqual((await state()).inventory, offered.inventory); 138 await owner.save(output + '/sale-offer-' + attempt); 139 if (attempt === 0) { 140 await owner.click(945, 475); 141 await owner.wait('cancelled Concrete Cushion restored', snapshot => owner.local(snapshot).inventory.some(item => item.id === 1 && item.slot === 48)); 142 assert.deepEqual((await state()).inventory, offered.inventory); 143 } 144 } 145 await owner.click(874, 475); 146 await owner.wait('exact selected-quality sale', snapshot => owner.local(snapshot).stats[61] === 42); 147 evidence.sale = await state(); 148 await owner.page.reload(); 149 await owner.ready(); 150 } 151 assert.deepEqual(owner.local().inventory.map(item => [item.id, item.slot, item.quality, ...item.templates, item.count]).sort((a, b) => a[0] - b[0]), [ 152 [2, 49, 84, 125456, 125457, 1], [3, 6, 85, 125456, 125457, 1], [4, 51, 86, 125456, 125457, 1], 153 ]); 154 const retained = await state(); 155 assert.deepEqual(retained.abilities, [208, 208]); 156 assert.equal(retained.rating, 256); 157 await Promise.all(games.map(game => game.wait('retained native foundations', snapshot => snapshot.actors.some(actor => 158 actor.id === 1 && actor.stats[1] === retained.maxHealth && (game !== owner || actor.stats[221] === retained.maxNano && actor.stats[22] === 256))))); 159 assert.equal(owner.local().stats[61], 42); 160 assert.deepEqual(observer.local().inventory, []); 161 await owner.key('KeyU'); 162 await owner.save(output + '/retained-abilities'); 163 await owner.key('KeyU'); 164 evidence.final = {native: owner.local().inventory, server: await state()}; 165 assert.equal(evidence.final.server.inventory.Items[1].Ammo, 0); 166 assert(evidence.final.server.ownerHealth > 0); 167 assert(games.every(game => game.errors.length === 0)); 168 console.log('PASS: native Concrete Cushion qualities, wear/removal, strict refusal, ordinary melee, exact sale and page/cold ownership'); 169 } finally { 170 try { 171 await fs.mkdir(output, {recursive: true}); 172 await fs.writeFile(output + '/verification.json', JSON.stringify(evidence, null, 2)); 173 await Promise.all(games.map((game, index) => game.save(output + '/final-' + index))); 174 } finally { await browser.close(); } 175 }