cleanup
This commit is contained in:
parent
3d7a8aafdf
commit
c1892230b7
13 changed files with 1111 additions and 993 deletions
|
|
@ -18,6 +18,7 @@ export class ScrapExecutor {
|
|||
private tradeMonitor: TradeMonitor;
|
||||
private inventoryManager: InventoryManager;
|
||||
private config: Config;
|
||||
private _onStateChange?: (state: string) => void;
|
||||
|
||||
constructor(
|
||||
gameController: GameController,
|
||||
|
|
@ -33,10 +34,19 @@ export class ScrapExecutor {
|
|||
this.config = config;
|
||||
}
|
||||
|
||||
set onStateChange(cb: (state: string) => void) {
|
||||
this._onStateChange = cb;
|
||||
}
|
||||
|
||||
getState(): ScrapState {
|
||||
return this.state;
|
||||
}
|
||||
|
||||
private setState(s: ScrapState): void {
|
||||
this.state = s;
|
||||
this._onStateChange?.(s);
|
||||
}
|
||||
|
||||
/** Stop the scrap loop gracefully. */
|
||||
async stop(): Promise<void> {
|
||||
this.stopped = true;
|
||||
|
|
@ -44,7 +54,7 @@ export class ScrapExecutor {
|
|||
try { await this.activePage.close(); } catch { /* best-effort */ }
|
||||
this.activePage = null;
|
||||
}
|
||||
this.state = 'IDLE';
|
||||
this.setState('IDLE');
|
||||
logger.info('Scrap executor stopped');
|
||||
}
|
||||
|
||||
|
|
@ -81,7 +91,7 @@ export class ScrapExecutor {
|
|||
// Check if process succeeded (state is IDLE on success, FAILED otherwise)
|
||||
if (this.state === 'FAILED') {
|
||||
salvageFailed = true;
|
||||
this.state = 'IDLE';
|
||||
this.setState('IDLE');
|
||||
logger.warn('Process cycle failed, skipping remaining items that do not fit');
|
||||
continue;
|
||||
}
|
||||
|
|
@ -121,7 +131,7 @@ export class ScrapExecutor {
|
|||
}
|
||||
|
||||
this.activePage = null;
|
||||
this.state = 'IDLE';
|
||||
this.setState('IDLE');
|
||||
logger.info('Scrap loop ended');
|
||||
}
|
||||
|
||||
|
|
@ -135,7 +145,7 @@ export class ScrapExecutor {
|
|||
if (alreadyAtSeller) {
|
||||
logger.info({ itemId: item.id, account: item.account }, 'Already at seller hideout, skipping travel');
|
||||
} else {
|
||||
this.state = 'TRAVELING';
|
||||
this.setState('TRAVELING');
|
||||
|
||||
// Register listener BEFORE clicking, then click inside the callback
|
||||
const arrived = await this.inventoryManager.waitForAreaTransition(
|
||||
|
|
@ -149,7 +159,7 @@ export class ScrapExecutor {
|
|||
);
|
||||
if (!arrived) {
|
||||
logger.error({ itemId: item.id }, 'Timed out waiting for hideout arrival');
|
||||
this.state = 'FAILED';
|
||||
this.setState('FAILED');
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -158,7 +168,7 @@ export class ScrapExecutor {
|
|||
await sleep(1500); // Wait for hideout to render
|
||||
}
|
||||
|
||||
this.state = 'BUYING';
|
||||
this.setState('BUYING');
|
||||
|
||||
// CTRL+Click at seller stash position
|
||||
const sellerLayout = GRID_LAYOUTS.seller;
|
||||
|
|
@ -175,11 +185,11 @@ export class ScrapExecutor {
|
|||
}
|
||||
|
||||
logger.info({ itemId: item.id, free: this.inventoryManager.tracker.freeCells }, 'Item bought successfully');
|
||||
this.state = 'IDLE';
|
||||
this.setState('IDLE');
|
||||
return true;
|
||||
} catch (err) {
|
||||
logger.error({ err, itemId: item.id }, 'Error buying item');
|
||||
this.state = 'FAILED';
|
||||
this.setState('FAILED');
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
@ -187,13 +197,13 @@ export class ScrapExecutor {
|
|||
/** Process inventory: salvage/stash cycle via InventoryManager. */
|
||||
private async processItems(): Promise<void> {
|
||||
try {
|
||||
this.state = 'SALVAGING';
|
||||
this.setState('SALVAGING');
|
||||
await this.inventoryManager.processInventory();
|
||||
this.state = 'IDLE';
|
||||
this.setState('IDLE');
|
||||
logger.info('Process cycle complete');
|
||||
} catch (err) {
|
||||
logger.error({ err }, 'Process cycle failed');
|
||||
this.state = 'FAILED';
|
||||
this.setState('FAILED');
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue