import { WindowManager } from './WindowManager.js'; import { InputSender, VK } from './InputSender.js'; import { sleep, randomDelay } from '../util/sleep.js'; import { writeClipboard } from '../util/clipboard.js'; import { logger } from '../util/logger.js'; import type { Config } from '../types.js'; export class GameController { private windowManager: WindowManager; private inputSender: InputSender; constructor(config: Config) { this.windowManager = new WindowManager(config.poe2WindowTitle); this.inputSender = new InputSender(); } async focusGame(): Promise { const result = this.windowManager.focusWindow(); if (result) { await sleep(300); // Wait for window to actually focus } return result; } isGameFocused(): boolean { return this.windowManager.isGameFocused(); } getWindowRect() { return this.windowManager.getWindowRect(); } async sendChat(message: string): Promise { logger.info({ message }, 'Sending chat message'); // Open chat await this.inputSender.pressKey(VK.RETURN); await randomDelay(100, 200); // Clear any existing text await this.inputSender.selectAll(); await sleep(50); await this.inputSender.pressKey(VK.BACK); await sleep(50); // Type the message await this.inputSender.typeText(message); await randomDelay(50, 100); // Send await this.inputSender.pressKey(VK.RETURN); await sleep(100); } async sendChatViaPaste(message: string): Promise { logger.info({ message }, 'Sending chat message via paste'); // Copy message to clipboard writeClipboard(message); await sleep(50); // Open chat await this.inputSender.pressKey(VK.RETURN); await randomDelay(100, 200); // Clear any existing text await this.inputSender.selectAll(); await sleep(50); await this.inputSender.pressKey(VK.BACK); await sleep(50); // Paste await this.inputSender.paste(); await randomDelay(100, 200); // Send await this.inputSender.pressKey(VK.RETURN); await sleep(100); } async goToHideout(): Promise { logger.info('Sending /hideout command'); await this.sendChatViaPaste('/hideout'); } async ctrlRightClickAt(x: number, y: number): Promise { await this.inputSender.ctrlRightClick(x, y); } async moveMouseTo(x: number, y: number): Promise { await this.inputSender.moveMouse(x, y); } moveMouseInstant(x: number, y: number): void { this.inputSender.moveMouseInstant(x, y); } async moveMouseFast(x: number, y: number): Promise { await this.inputSender.moveMouseFast(x, y); } async leftClickAt(x: number, y: number): Promise { await this.inputSender.leftClick(x, y); } async rightClickAt(x: number, y: number): Promise { await this.inputSender.rightClick(x, y); } async holdAlt(): Promise { await this.inputSender.keyDown(VK.MENU); } async releaseAlt(): Promise { await this.inputSender.keyUp(VK.MENU); } async pressEscape(): Promise { await this.inputSender.pressKey(VK.ESCAPE); } async openInventory(): Promise { logger.info('Opening inventory'); await this.inputSender.pressKey(VK.I); await sleep(300); } async ctrlLeftClickAt(x: number, y: number): Promise { await this.inputSender.ctrlLeftClick(x, y); } async holdCtrl(): Promise { await this.inputSender.keyDown(VK.CONTROL); } async releaseCtrl(): Promise { await this.inputSender.keyUp(VK.CONTROL); } }