/**
* Одноразовая проба (трек 28): зайти в дом Ирвина и выйти — герой не должен
* застревать в стенах дома (дома штампуются шире тайла). Печатает позицию
* героя после возврата и solidAt вокруг неё.
*/
import { fileURLToPath } from 'node:url';
import { AgentClient, launchBrowser, startDevServer, parseArgs } from '@rpg/engine/tools/agent-lib.mjs';
const args = parseArgs(process.argv.slice(2));
const port = Number(args.port ?? 5332);
const server = startDevServer({ port, cwd: fileURLToPath(new URL('../', import.meta.url)) });
try {
await server.waitReady;
const browser = await launchBrowser();
try {
const page = await browser.newPage();
const pageErrors = [];
page.on('pageerror', (e) => pageErrors.push(String(e)));
await page.goto(`http://localhost:${port}/`, { waitUntil: 'domcontentloaded', timeout: 60000 });
await page.waitForFunction('window.__beacon === true', { timeout: 60000 });
await new Promise((r) => setTimeout(r, 1200));
const client = new AgentClient(page);
client.pageErrors = pageErrors;
await client.call('startGame', false);
await client.call('setManual', true);
// к двери дома Ирвина (13,12): телепорт на тайл югом, шаг к двери, E
await client.call('gotoArea', 'zvenets', { x: 13, y: 13 });
await client.call('stepTicks', 2);
await client.call('interact'); // клик-переход у двери
await client.call('stepTicks', 40); // полный фейд
const inside = await client.call('heroInfo');
console.log('внутри:', inside.area, inside.tile);
// к выходу: телепорт на тайл СЕВЕРНЕЕ спавна (5,6), шаг +z через
// спавн (5,7) в триггер выхода (5,8); +z = экранный стик (-1,1)
await client.call('heroTeleport', 5 * 10 + 5, 6 * 10 + 5);
await client.call('stepTicks', 2);
await client.call('setInput', -1, 1);
for (let i = 0; i < 20; i++) {
await client.call('stepTicks', 6); // держим стик, пока не выйдет
const info = await client.call('heroInfo');
if (info.area !== 'house_elder') break;
}
await client.call('setInput', null, null);
await client.call('stepTicks', 40); // фейд возврата
const out = await client.call('heroInfo');
console.log('после выхода:', out.area, out.tile, 'pos:', out.pos);
for (const [dx, dz] of [[0, 0], [1, 0], [-1, 0], [0, 1], [0, -1]])
console.log('solid', dx, dz, await client.call('solidAt', Math.round(out.pos[0]) + dx * 10, Math.round(out.pos[2]) + dz * 10));
await client.screenshot('/tmp/t28_house_out.png');
} finally {
await browser.close();
}
} catch (e) {
console.error(e);
process.exit(1);
}
process.exit(0);