tools/client/test_steel_ribbed_armor.mjs (8792B)
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 ['steel-owner', 'steel-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 } 30 const [owner, observer] = games; 31 const state = async () => (await owner.page.request.get(url + '/test-state')).json(); 32 const baseline = await state(); 33 assert.equal(baseline.inventory.Items.length, 10); 34 assert.deepEqual(baseline.armor, [32, 30, 32, 32, 10, 10, 30, 10]); 35 await owner.key('KeyI'); 36 await owner.page.keyboard.press('Control+1'); 37 await owner.click(953, 53); 38 await owner.page.keyboard.press('Control+9'); 39 await owner.save(output + '/initial'); 40 41 // Every piece uses native removal and wear, with explicit left-arm placement. 42 for (const [id, slot, x, y, armor] of [ 43 [1, 18, 927, 94, [7, 6, 7, 7, 2, 2, 6, 2]], 44 [2, 27, 927, 262, [6, 6, 6, 6, 2, 2, 6, 2]], 45 [3, 30, 927, 316, [3, 3, 3, 3, 1, 1, 3, 1]], 46 [4, 23, 867, 206, [2, 2, 2, 2, 1, 1, 2, 1]], 47 [5, 25, 987, 206, [2, 2, 2, 2, 1, 1, 2, 1]], 48 [6, 24, 927, 206, [2, 2, 2, 2, 1, 1, 2, 1]], 49 [7, 21, 927, 148, [10, 9, 10, 10, 2, 2, 9, 2]], 50 ]) { 51 const sequence = observer.sequence; 52 await owner.click(x, y, 'right'); 53 await owner.wait('exact piece removed', state => owner.local(state).inventory.some(item => item.id === id && item.slot >= 48)); 54 assert.deepEqual((await state()).armor, baseline.armor.map((value, index) => value - armor[index])); 55 if (slot === 23) { 56 await owner.wait('arm action finishes', state => !owner.local(state).actions.includes(3)); 57 const cell = owner.local().inventory.find(item => item.id === id).slot - 48; 58 await owner.click(681 + cell % 3 * 54, 45 + Math.floor(cell / 3) * 54); 59 await owner.click(x, y); 60 } else await bagClick(owner, id); 61 await owner.wait('exact piece worn', state => owner.local(state).inventory.some(item => item.id === id && item.slot === slot)); 62 await observer.wait('observer receives wear', () => observer.events.some(event => { 63 if (event.sequence <= sequence || event.direction !== 'framereceived' || event.opcode !== '35505644' || event.actor[1] !== 1) return false; 64 const packet = Buffer.from(event.hex, 'hex'); 65 return packet.readUInt32BE(45) === 6 && packet.readUInt32BE(53) === slot; 66 })); 67 assert.deepEqual((await state()).armor, baseline.armor); 68 } 69 await owner.save(output + '/all-pieces'); 70 await observer.save(output + '/observer-all-pieces'); 71 72 // The high stored endpoint must still deliver the selected QL100 contract. 73 await owner.click(927, 206, 'right'); 74 await owner.wait('QL2 gloves retained', state => owner.local(state).inventory.some(item => item.id === 6 && item.slot >= 48)); 75 await bagClick(owner, 8); 76 await owner.wait('QL100 gloves worn', state => owner.local(state).inventory.some(item => item.id === 8 && item.slot === 24)); 77 assert.deepEqual((await state()).armor, [155, 137, 155, 155, 34, 34, 137, 34]); 78 await owner.save(output + '/quality-100'); 79 await owner.click(927, 206, 'right'); 80 await owner.wait('QL100 gloves retained', state => owner.local(state).inventory.some(item => item.id === 8 && item.slot >= 48)); 81 const before = await state(), sequence = owner.sequence; 82 await bagClick(owner, 9); 83 await owner.save(output + '/quality-101-rejected'); 84 assert(!owner.events.some(event => event.sequence > sequence && event.direction === 'framesent' && event.opcode === '47537a24')); 85 assert.deepEqual((await state()).inventory, before.inventory); 86 assert.equal((await state()).pending, false); 87 88 // Train one Agility and Sense point through the original ability form. 89 await owner.page.keyboard.press('Control+1'); 90 await owner.page.keyboard.press('Control+9'); 91 await owner.key('KeyU'); 92 await owner.click(334, 256); 93 await owner.click(835, 196); 94 await owner.click(835, 286); 95 await owner.click(445, 622); 96 await owner.wait('trained strict thresholds', state => owner.local(state).stats[17] === 246 && 97 owner.local(state).stats[20] === 271 && owner.local(state).stats[53] === 970); 98 await bagClick(owner, 9); 99 await owner.wait('QL101 gloves worn', state => owner.local(state).inventory.some(item => item.id === 9 && item.slot === 24)); 100 assert.deepEqual((await state()).armor, [156, 138, 156, 156, 35, 35, 138, 35]); 101 const high = await state(), highSequence = owner.sequence; 102 await bagClick(owner, 10); 103 await owner.save(output + '/quality-200-rejected'); 104 assert(!owner.events.some(event => event.sequence > highSequence && event.direction === 'framesent' && event.opcode === '47537a24')); 105 assert.deepEqual((await state()).inventory, high.inventory); 106 107 // Cancel, then accept one selected-quality sale at the original armor machine. 108 if (!owner.state.camera.firstPerson) await owner.key('F8'); 109 let offered = await state(); 110 for (let attempt = 0; attempt < 2; ++attempt) { 111 const [x, y] = await owner.pick(51035, 3221226655); 112 await owner.click(x, y, 'right'); 113 await owner.wait('armor machine open', state => state.regions.some(([left, top, right, bottom]) => 114 left === 832 && top === 0 && right === 1024 && bottom === 494)); 115 const cell = owner.local().inventory.find(item => item.id === 8).slot - 48; 116 await owner.click(681 + cell % 3 * 54, 45 + Math.floor(cell / 3) * 54); 117 const sequence = owner.sequence; 118 await owner.click(864, 416); 119 await owner.wait('sale offered', () => owner.events.some(event => event.sequence > sequence && 120 event.direction === 'framesent' && event.opcode === '36284f6e')); 121 assert.deepEqual((await state()).inventory, offered.inventory); 122 await owner.save(output + '/sale-offer-' + attempt); 123 if (attempt === 0) { 124 await owner.click(945, 475); 125 await owner.wait('cancelled glove restored', state => owner.local(state).inventory.some(item => item.id === 8 && item.slot === 48)); 126 assert.deepEqual((await state()).inventory, offered.inventory); 127 offered = await state(); 128 } 129 } 130 await owner.click(874, 475); 131 await owner.wait('exact selected-quality sale', state => owner.local(state).stats[61] === 5239); 132 const final = await state(); 133 const slots = {1: 18, 2: 27, 3: 30, 4: 23, 5: 25, 6: 67, 7: 21, 9: 24, 10: 66}; 134 const expected = baseline.inventory.Items.filter(item => item.ID !== 8).map(item => ({...item, Slot: slots[item.ID]})); 135 assert.deepEqual(final.inventory.Items, expected); 136 assert.deepEqual(final.observer, baseline.observer); 137 await fs.writeFile(output + '/ledger.json', JSON.stringify(final, null, 2)); 138 await owner.page.reload(); 139 await owner.ready(); 140 const pairs = {85541: [85541, 22262], 85494: [85494, 22347], 85620: [85620, 22158], 141 85724: [85724, 21971], 85580: [85580, 22212], 85668: [85668, 22080]}; 142 for (const item of expected) { 143 const pair = pairs[item.Template]; 144 assert.deepEqual(owner.local().inventory.find(actual => actual.id === item.ID), { 145 slot: item.Slot >= 64 ? item.Slot - 16 : item.Slot, type: item.Type, id: item.ID, 146 quality: item.Quality, templates: item.Quality === 200 ? [pair[1], pair[1]] : pair, count: 1}); 147 } 148 await owner.key('KeyI'); 149 await owner.page.keyboard.press('Control+1'); 150 await owner.click(953, 53); 151 await owner.page.keyboard.press('Control+9'); 152 await owner.save(output + '/reconnected'); 153 assert(games.every(game => game.errors.length === 0)); 154 console.log('PASS: Steel-Ribbed pieces, both sleeves, QL100/101 native gates/training, exact sale and page recovery'); 155 } finally { 156 try { await Promise.all(games.map((game, index) => game.save(output + '/final-' + index))); } 157 finally { await browser.close(); } 158 }