tools/client/test_omni_pol_armor.mjs (9399B)
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', headless: false, 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 = []; 12 async function bagClick(game, id) { 13 await game.wait('inventory actions finish', state => 14 !game.local(state).actions.includes(3) && !game.local(state).actions.includes(6)); 15 const item = game.local().inventory.find(item => item.id === id); 16 assert(item && item.slot >= 48 && item.slot < 57); 17 const cell = item.slot - 48; 18 await game.click(681 + cell % 3 * 54, 45 + Math.floor(cell / 3) * 54, 'right'); 19 } 20 try { 21 for (const token of ['omni-pol-owner', 'omni-pol-watch']) { 22 const context = await browser.newContext({viewport: {width: 1024, height: 768}}); 23 await context.addCookies([{name: 'ao_client', value: token, url}]); 24 const page = await context.newPage(); 25 const game = await GameTest.attach(page); 26 games.push(game); 27 await page.goto(url); 28 await game.ready(); 29 await page.waitForFunction(() => touchRegion(500, 400)?.world === true); 30 await game.snapshot(); 31 } 32 const [owner, observer] = games; 33 if (!observer.state.camera.firstPerson) await observer.key('F8'); 34 await observer.wait('armor wearer is visible to the observer', state => state.actors.some(actor => actor.id === 1 && 35 actor.screenPosition?.[0] > 0 && actor.screenPosition[0] < 1024 && actor.screenPosition[1] > 0 && 36 actor.screenPosition[1] < 748 && actor.screenPosition[2] >= 0 && actor.screenPosition[2] <= 1)); 37 const state = async () => (await owner.page.request.get(url + '/test-state')).json(); 38 const baseline = await state(); 39 assert.equal(baseline.inventory.Items.length, 10); 40 assert.deepEqual(baseline.armor, [32, 32, 32, 30, 30, 10, 28, 10]); 41 await owner.key('KeyI'); 42 await owner.page.keyboard.press('Control+1'); 43 await owner.click(953, 53); 44 await owner.page.keyboard.press('Control+9'); 45 await owner.save(output + '/initial'); 46 47 // Every piece uses native removal and wear, with explicit left-arm placement. 48 for (const [id, slot, x, y, armor] of [ 49 [1, 18, 927, 94, [7, 7, 7, 6, 6, 2, 6, 2]], 50 [2, 27, 927, 262, [6, 6, 6, 6, 6, 2, 5, 2]], 51 [3, 30, 927, 316, [3, 3, 3, 3, 3, 1, 2, 1]], 52 [4, 23, 867, 206, [2, 2, 2, 2, 2, 1, 2, 1]], 53 [5, 25, 987, 206, [2, 2, 2, 2, 2, 1, 2, 1]], 54 [6, 24, 927, 206, [2, 2, 2, 2, 2, 1, 2, 1]], 55 [7, 21, 927, 148, [10, 10, 10, 9, 9, 2, 9, 2]], 56 ]) { 57 const sequence = observer.sequence; 58 await owner.click(x, y, 'right'); 59 await owner.wait('exact piece removed', state => owner.local(state).inventory.some(item => item.id === id && item.slot >= 48)); 60 assert.deepEqual((await state()).armor, baseline.armor.map((value, index) => value - armor[index])); 61 if (slot === 23) { 62 await owner.wait('arm action finishes', state => !owner.local(state).actions.includes(3)); 63 const cell = owner.local().inventory.find(item => item.id === id).slot - 48; 64 await owner.click(681 + cell % 3 * 54, 45 + Math.floor(cell / 3) * 54); 65 await owner.click(x, y); 66 } else await bagClick(owner, id); 67 await owner.wait('exact piece worn', state => owner.local(state).inventory.some(item => item.id === id && item.slot === slot)); 68 await observer.wait('observer receives wear', () => observer.events.some(event => { 69 if (event.sequence <= sequence || event.direction !== 'framereceived' || event.opcode !== '35505644' || event.actor[1] !== 1) return false; 70 const packet = Buffer.from(event.hex, 'hex'); 71 return packet.readUInt32BE(45) === 6 && packet.readUInt32BE(53) === slot; 72 })); 73 assert.deepEqual((await state()).armor, baseline.armor); 74 } 75 await owner.save(output + '/all-pieces'); 76 await observer.save(output + '/observer-all-pieces'); 77 78 // The high stored endpoint must still deliver the selected QL100 contract. 79 await owner.click(927, 206, 'right'); 80 await owner.wait('QL2 gloves retained', state => owner.local(state).inventory.some(item => item.id === 6 && item.slot >= 48)); 81 await bagClick(owner, 8); 82 await owner.wait('QL100 gloves worn', state => owner.local(state).inventory.some(item => item.id === 8 && item.slot === 24)); 83 assert.deepEqual((await state()).armor, [155, 155, 155, 137, 137, 40, 120, 40]); 84 await owner.save(output + '/quality-100'); 85 await owner.click(927, 206, 'right'); 86 await owner.wait('QL100 gloves retained', state => owner.local(state).inventory.some(item => item.id === 8 && item.slot >= 48)); 87 const before = await state(), sequence = owner.sequence; 88 await bagClick(owner, 9); 89 await owner.save(output + '/quality-101-rejected'); 90 assert(!owner.events.some(event => event.sequence > sequence && event.direction === 'framesent' && event.opcode === '47537a24')); 91 assert.deepEqual((await state()).inventory, before.inventory); 92 assert.equal((await state()).pending, false); 93 94 // Train one Strength and Stamina point through the original ability form. 95 await owner.page.keyboard.press('Control+1'); 96 await owner.page.keyboard.press('Control+9'); 97 await owner.key('KeyU'); 98 await owner.click(334, 256); 99 await owner.click(835, 166); 100 await owner.click(835, 226); 101 await owner.click(445, 622); 102 await owner.wait('trained strict thresholds', state => owner.local(state).stats[16] === 252 && 103 owner.local(state).stats[18] === 277 && owner.local(state).stats[53] === 946); 104 await bagClick(owner, 9); 105 await owner.wait('QL101 gloves worn', state => owner.local(state).inventory.some(item => item.id === 9 && item.slot === 24)); 106 assert.deepEqual((await state()).armor, [156, 156, 156, 138, 138, 41, 120, 41]); 107 const high = await state(), highSequence = owner.sequence; 108 await bagClick(owner, 10); 109 await owner.save(output + '/quality-200-rejected'); 110 assert(!owner.events.some(event => event.sequence > highSequence && event.direction === 'framesent' && event.opcode === '47537a24')); 111 assert.deepEqual((await state()).inventory, high.inventory); 112 113 // Cancel, then accept one selected-quality sale at the original armor machine. 114 if (!owner.state.camera.firstPerson) await owner.key('F8'); 115 let offered = await state(); 116 for (let attempt = 0; attempt < 2; ++attempt) { 117 const [x, y] = await owner.pick(51035, 3221226655); 118 await owner.click(x, y, 'right'); 119 await owner.wait('armor machine open', state => state.regions.some(([left, top, right, bottom]) => 120 left === 832 && top === 0 && right === 1024 && bottom === 494)); 121 const cell = owner.local().inventory.find(item => item.id === 8).slot - 48; 122 await owner.click(681 + cell % 3 * 54, 45 + Math.floor(cell / 3) * 54); 123 const sequence = owner.sequence; 124 await owner.click(864, 416); 125 await owner.wait('sale offered', () => owner.events.some(event => event.sequence > sequence && 126 event.direction === 'framesent' && event.opcode === '36284f6e')); 127 assert.deepEqual((await state()).inventory, offered.inventory); 128 await owner.save(output + '/sale-offer-' + attempt); 129 if (attempt === 0) { 130 await owner.click(945, 475); 131 await owner.wait('cancelled glove restored', state => owner.local(state).inventory.some(item => item.id === 8 && item.slot === 48)); 132 assert.deepEqual((await state()).inventory, offered.inventory); 133 offered = await state(); 134 } 135 } 136 await owner.click(874, 475); 137 await owner.wait('exact selected-quality sale', state => owner.local(state).stats[61] === 5948); 138 const final = await state(); 139 const slots = {1: 18, 2: 27, 3: 30, 4: 23, 5: 25, 6: 67, 7: 21, 9: 24, 10: 66}; 140 const expected = baseline.inventory.Items.filter(item => item.ID !== 8).map(item => ({...item, Slot: slots[item.ID]})); 141 assert.deepEqual(final.inventory.Items, expected); 142 assert.deepEqual(final.observer, baseline.observer); 143 await fs.writeFile(output + '/ledger.json', JSON.stringify(final, null, 2)); 144 await owner.page.reload(); 145 await owner.ready(); 146 await owner.page.waitForFunction(() => touchRegion(500, 400)?.world === true); 147 await owner.snapshot(); 148 const pairs = {85552: [85552, 22246], 85505: [85505, 22331], 85631: [85631, 22142], 149 85735: [85735, 21955], 85591: [85591, 22196], 85679: [85679, 22064]}; 150 for (const item of expected) { 151 const pair = pairs[item.Template]; 152 assert.deepEqual(owner.local().inventory.find(actual => actual.id === item.ID), { 153 slot: item.Slot >= 64 ? item.Slot - 16 : item.Slot, type: item.Type, id: item.ID, 154 quality: item.Quality, templates: item.Quality === 200 ? [pair[1], pair[1]] : pair, count: 1}); 155 } 156 await owner.key('KeyI'); 157 await owner.page.keyboard.press('Control+1'); 158 await owner.click(953, 53); 159 await owner.page.keyboard.press('Control+9'); 160 await owner.save(output + '/reconnected'); 161 assert(games.every(game => game.errors.length === 0)); 162 console.log('PASS: OmniPol pieces, both sleeves, QL100/101 native gates/training, exact sale and page recovery'); 163 } finally { 164 try { await Promise.all(games.map((game, index) => game.save(output + '/final-' + index))); } 165 finally { await browser.close(); } 166 }