bitburner-src/src/PersonObjects/Player/PlayerObjectWorkMethods.ts

23 lines
670 B
TypeScript
Raw Normal View History

2022-07-07 08:00:23 +02:00
import { Work } from "../../Work/Work";
import { PlayerObject } from "./PlayerObject";
2022-07-07 08:00:23 +02:00
export function startWork(this: PlayerObject, w: Work): void {
2022-07-07 08:00:23 +02:00
if (this.currentWork !== null) {
2022-09-06 15:07:12 +02:00
this.currentWork.finish(true);
2022-07-07 08:00:23 +02:00
}
this.currentWork = w;
}
export function processWork(this: PlayerObject, cycles = 1): void {
2022-07-07 08:00:23 +02:00
if (this.currentWork === null) return;
2022-09-06 15:07:12 +02:00
const finished = this.currentWork.process(cycles);
2022-07-07 08:00:23 +02:00
if (finished) {
2022-07-14 23:43:08 +02:00
this.finishWork(false);
2022-07-07 08:00:23 +02:00
}
}
export function finishWork(this: PlayerObject, cancelled: boolean): void {
2022-07-07 08:00:23 +02:00
if (this.currentWork === null) return;
2022-09-06 15:07:12 +02:00
this.currentWork.finish(cancelled);
2022-07-07 08:00:23 +02:00
this.currentWork = null;
2022-07-22 00:27:23 +02:00
this.focus = false;
2022-07-07 08:00:23 +02:00
}