aorecomp

Anarchy Online classic in the browser

git clone https://aorecomp.ubeagle.com/code/aorecomp.git


tools/client/test_bau_cyber_armor.mjs (11677B)


      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 assert(url && output, 'Run through TestBrowserBauCyberArmorQualities');
      9 const browser = await chromium.launch({executablePath: '/usr/bin/chromium',
     10   args: ['--enable-gpu', '--use-gl=angle', '--use-angle=gl', '--no-sandbox', '--disable-dev-shm-usage',
     11     '--disable-background-timer-throttling', '--disable-renderer-backgrounding']});
     12 const games = [];
     13 
     14 async function bagClick(game, id) {
     15   await game.wait('native inventory actions finish', state =>
     16     !game.local(state).actions.includes(3) && !game.local(state).actions.includes(6));
     17   const item = game.local().inventory.find(item => item.id === id);
     18   assert(item && item.slot >= 48 && item.slot < 57, 'Fixture item is outside its visible inventory cells');
     19   const cell = item.slot - 48;
     20   await game.click(681 + cell % 3 * 54, 45 + Math.floor(cell / 3) * 54, 'right');
     21 }
     22 
     23 try {
     24   for (const token of ['bau-cyber-owner', 'bau-cyber-watch']) {
     25     const context = await browser.newContext({viewport: {width: 1024, height: 768}});
     26     await context.addCookies([{name: 'ao_client', value: token, url}]);
     27     const page = await context.newPage();
     28     const game = await GameTest.attach(page);
     29     games.push(game);
     30     await page.goto(url);
     31     await game.ready();
     32   }
     33   const [owner, observer] = games;
     34   assert.equal(owner.local().id, 1);
     35   assert.equal(observer.local().id, 2);
     36   const state = async () => (await owner.page.request.get(url + '/test-state')).json();
     37   const baseline = await state();
     38   const watched = observer.local().inventory;
     39   assert.equal(baseline.inventory.Items.length, 11);
     40   assert.deepEqual(baseline.armor, [32, 32, 30, 10, 26, 28, 10, 28]);
     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.wait('native armor stats window', state => state.regions.some(
     46     ([left, top, right, bottom]) => left === 832 && top === 380 && right === 1024 && bottom === 606));
     47   await owner.save(output + '/initial-set');
     48   await observer.save(output + '/observer-initial-set');
     49 
     50   // Remove and re-wear every initial piece, retaining each sleeve independently.
     51   for (const [id, slot, x, y, armor] of [
     52     [1, 18, 927, 94, [7, 7, 6, 2, 5, 6, 2, 6]],
     53     [2, 27, 927, 262, [6, 6, 6, 2, 5, 5, 2, 5]],
     54     [3, 30, 927, 316, [3, 3, 3, 1, 2, 2, 1, 2]],
     55     [4, 23, 867, 206, [2, 2, 2, 1, 2, 2, 1, 2]],
     56     [5, 25, 987, 206, [2, 2, 2, 1, 2, 2, 1, 2]],
     57     [6, 24, 927, 206, [2, 2, 2, 1, 2, 2, 1, 2]],
     58     [7, 21, 927, 148, [10, 10, 9, 2, 8, 9, 2, 9]],
     59   ]) {
     60     const sequence = observer.sequence;
     61     await owner.click(x, y, 'right');
     62     await owner.wait('exact piece removed', state => owner.local(state).inventory.some(item => item.id === id && item.slot >= 48));
     63     assert.deepEqual((await state()).armor, baseline.armor.map((value, index) => value - armor[index]));
     64     await owner.save(output + '/removed-' + id);
     65     if (slot === 23) {
     66       // Explicit placement keeps the other sleeve in its own arm.
     67       await owner.wait('native inventory actions finish', state =>
     68         !owner.local(state).actions.includes(3) && !owner.local(state).actions.includes(6));
     69       const item = owner.local().inventory.find(item => item.id === id);
     70       const cell = item.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 re-worn', state => owner.local(state).inventory.some(item => item.id === id && item.slot === slot));
     75     await observer.wait('observer receives worn piece', () => 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     await owner.save(output + '/worn-' + id);
     82     await observer.save(output + '/observer-worn-' + id);
     83   }
     84   console.log('PASS: all seven worn pieces remove/re-wear, with independent sleeves');
     85 
     86   // Wear an intermediate quality stored at the high endpoint, then reject equality at QL101.
     87   await owner.click(927, 206, 'right');
     88   await owner.wait('QL2 gloves retained in inventory', state => owner.local(state).inventory.some(item => item.id === 6 && item.slot >= 48));
     89   await bagClick(owner, 9);
     90   await owner.wait('QL100 gloves worn', state => owner.local(state).inventory.some(item => item.id === 9 && item.slot === 24));
     91   assert.deepEqual((await state()).armor, [155, 155, 137, 34, 102, 120, 34, 120]);
     92   await owner.save(output + '/quality-100');
     93   await owner.click(927, 206, 'right');
     94   await owner.wait('QL100 gloves retained in inventory', state => owner.local(state).inventory.some(item => item.id === 9 && item.slot >= 48));
     95   const untrained = await state();
     96   const untrainedAttempt = owner.sequence;
     97   await bagClick(owner, 10);
     98   await owner.save(output + '/quality-101-rejected');
     99   assert(!owner.events.some(event => event.sequence > untrainedAttempt &&
    100     event.direction === 'framesent' && event.opcode === '47537a24'), 'Native requirements admitted unqualified gloves');
    101   const rejected = await state();
    102   assert.deepEqual(rejected.inventory, untrained.inventory);
    103   assert.equal(rejected.pending, false);
    104   assert(owner.local().inventory.some(item => item.id === 10 && item.slot >= 48));
    105 
    106   // Train both strict ability thresholds through the original skill window.
    107   await owner.page.keyboard.press('Control+1');
    108   await owner.page.keyboard.press('Control+9');
    109   await owner.key('KeyU');
    110   await owner.click(334, 256);
    111   await owner.click(835, 256);
    112   await owner.click(835, 316);
    113   await owner.click(445, 622);
    114   await owner.wait('one trained ability point each', state => owner.local(state).stats[21] === 239 &&
    115     owner.local(state).stats[19] === 264 && owner.local(state).stats[53] === 1499);
    116   await bagClick(owner, 10);
    117   await owner.wait('QL101 gloves worn after training', state => owner.local(state).inventory.some(item => item.id === 10 && item.slot === 24));
    118   assert.deepEqual((await state()).armor, [156, 156, 138, 35, 103, 120, 35, 120]);
    119   await owner.page.keyboard.press('Control+1');
    120   await owner.click(953, 53);
    121   await owner.page.keyboard.press('Control+9');
    122   await owner.wait('trained native armor stats window', state => state.regions.some(
    123     ([left, top, right, bottom]) => left === 832 && top === 380 && right === 1024 && bottom === 606));
    124   await owner.save(output + '/quality-101-trained');
    125   const beforeHigh = await state();
    126   const highAttempt = owner.sequence;
    127   await bagClick(owner, 11);
    128   await owner.save(output + '/quality-200-rejected');
    129   assert(!owner.events.some(event => event.sequence > highAttempt &&
    130     event.direction === 'framesent' && event.opcode === '47537a24'), 'Native requirements admitted QL200 gloves');
    131   assert.deepEqual((await state()).inventory, beforeHigh.inventory);
    132 
    133   // Retain the original body instance while wearing the other authored style.
    134   await owner.click(927, 148, 'right');
    135   await owner.wait('original body retained', state => owner.local(state).inventory.some(item => item.id === 7 && item.slot >= 48));
    136   await bagClick(owner, 8);
    137   await owner.wait('alternate body style worn', state => owner.local(state).inventory.some(item => item.id === 8 && item.slot === 21));
    138   assert.deepEqual((await state()).armor, [156, 156, 138, 35, 103, 120, 35, 120]);
    139   await owner.save(output + '/vest');
    140 
    141   // Cancel and accept the exact QL100 sale through the original basic armor machine.
    142   await owner.page.keyboard.press('Control+1');
    143   await owner.page.keyboard.press('Control+9');
    144   if (!owner.state.camera.firstPerson) await owner.key('F8');
    145   let offerState = await state();
    146   for (let attempt = 0; attempt < 2; ++attempt) {
    147     const [x, y] = await owner.pick(51035, 3221226655);
    148     await owner.click(x, y, 'right');
    149     await owner.wait('original armor shop open', state => state.regions.some(
    150       ([left, top, right, bottom]) => left === 832 && top === 0 && right === 1024 && bottom === 494));
    151     const item = owner.local().inventory.find(item => item.id === 9);
    152     const cell = item.slot - 48;
    153     await owner.click(681 + cell % 3 * 54, 45 + Math.floor(cell / 3) * 54);
    154     const offered = owner.sequence;
    155     await owner.click(864, 416);
    156     await owner.wait('exact native sale offered', () => owner.events.some(event =>
    157       event.sequence > offered && event.direction === 'framesent' && event.opcode === '36284f6e'));
    158     assert.deepEqual((await state()).inventory, offerState.inventory);
    159     await owner.save(output + '/sale-offer-' + attempt);
    160     if (attempt === 0) {
    161       await owner.click(945, 475);
    162       await owner.wait('cancel restores QL100 identity in the first free cell', state => owner.local(state).inventory.some(item => item.id === 9 && item.slot === 48));
    163       const cancelled = await state();
    164       assert.deepEqual(cancelled.inventory, {...offerState.inventory,
    165         Items: offerState.inventory.Items.map(item => item.ID === 9 ? {...item, Slot: 64} : item)});
    166       offerState = cancelled;
    167       await owner.save(output + '/sale-cancelled');
    168       await fs.writeFile(output + '/sale-cancelled/server.json', JSON.stringify(cancelled, null, 2));
    169     }
    170   }
    171   await owner.click(874, 475);
    172   await owner.wait('selected-quality sale committed', state => owner.local(state).stats[61] === 5380);
    173   const final = await state();
    174   const slots = {1: 18, 2: 27, 3: 30, 4: 23, 5: 25, 6: 68, 7: 66, 8: 21, 10: 24, 11: 67};
    175   const expected = baseline.inventory.Items.filter(item => item.ID !== 9).map(item => ({...item, Slot: slots[item.ID]}));
    176   assert.deepEqual(final.inventory.Items, expected);
    177   assert.equal(final.stats.ImprovementPoints, 1499);
    178   assert.deepEqual(final.observer, baseline.observer);
    179   await owner.page.reload();
    180   await owner.ready();
    181   assert.equal(owner.local().inventory.length, 10);
    182   for (const item of expected) {
    183     const pair = {85571: [85571, 85570], 85530: [85530, 85529], 85654: [85654, 85653],
    184       85759: [85759, 85758], 85611: [85611, 85610], 85710: [85710, 85709], 85708: [85708, 85707]}[item.Template];
    185     assert.deepEqual(owner.local().inventory.find(actual => actual.id === item.ID), {
    186       slot: item.Slot >= 64 ? item.Slot - 16 : item.Slot, type: item.Type, id: item.ID,
    187       quality: item.Quality, templates: item.Quality === 200 ? [pair[1], pair[1]] : pair, count: 1});
    188   }
    189   await owner.key('KeyI');
    190   await owner.page.keyboard.press('Control+1');
    191   await owner.click(953, 53);
    192   await owner.page.keyboard.press('Control+9');
    193   await owner.wait('reconnected native armor stats window', state => state.regions.some(
    194     ([left, top, right, bottom]) => left === 832 && top === 380 && right === 1024 && bottom === 606));
    195   await owner.save(output + '/reconnected');
    196   await observer.snapshot();
    197   assert.deepEqual(observer.local().inventory, watched);
    198   for (const game of games) assert.deepEqual(game.errors, []);
    199   await fs.writeFile(output + '/ledger.json', JSON.stringify(final, null, 2));
    200   console.log('PASS: QL100/101 requirements, alternate body style, exact sale and page ownership');
    201 } finally {
    202   try {
    203     for (const [index, game] of games.entries()) await game.save(output + '/client-' + index);
    204   } finally { await browser.close(); }
    205 }