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