Optimize scheduler timers
This commit is contained in:
parent
2d9c3f94e7
commit
a23872972e
@ -1,36 +0,0 @@
|
||||
import { ActionController, registerAction } from './ActionController';
|
||||
import { Args } from '../Common';
|
||||
import { Task } from '../Storage/TaskQueue';
|
||||
import { getNumber } from '../utils';
|
||||
import { ActionError } from '../Errors';
|
||||
|
||||
const LUMBER = 1;
|
||||
const CLAY = 2;
|
||||
const IRON = 3;
|
||||
const CROP = 4;
|
||||
|
||||
@registerAction
|
||||
export class GrabVillageResourcesAction extends ActionController {
|
||||
async run(args: Args, task: Task): Promise<any> {
|
||||
const lumber = this.grabResource(task, LUMBER);
|
||||
const clay = this.grabResource(task, CLAY);
|
||||
const iron = this.grabResource(task, IRON);
|
||||
const crop = this.grabResource(task, CROP);
|
||||
|
||||
this.state.set('resources', { [LUMBER]: lumber, [CLAY]: clay, [IRON]: iron, [CROP]: crop });
|
||||
}
|
||||
|
||||
private grabResource(task: Task, type: number): number {
|
||||
const stockBarElement = jQuery('#stockBar');
|
||||
if (stockBarElement.length !== 1) {
|
||||
throw new ActionError(task.id, 'Stock Bar not found');
|
||||
}
|
||||
|
||||
const resElement = stockBarElement.find(`#l${type}`);
|
||||
if (resElement.length !== 1) {
|
||||
throw new ActionError(task.id, `Resource #${type} not found`);
|
||||
}
|
||||
|
||||
return getNumber(resElement.text().replace(/[^0-9]/g, ''));
|
||||
}
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
import { markPage, sleepShort, timestamp } from './utils';
|
||||
import { markPage, sleepMicro, timestamp, waitForLoad } from './utils';
|
||||
import { UpgradeBuildingTask } from './Task/UpgradeBuildingTask';
|
||||
import { AbortTaskError, ActionError, BuildingQueueFullError, TryLaterError } from './Errors';
|
||||
import { Task, TaskId, TaskList, TaskQueue } from './Storage/TaskQueue';
|
||||
@ -25,7 +25,8 @@ export class Scheduler {
|
||||
}
|
||||
|
||||
async run() {
|
||||
await sleepShort();
|
||||
await waitForLoad();
|
||||
await sleepMicro();
|
||||
markPage('Executor', this.version);
|
||||
|
||||
this.renderTaskQueue();
|
||||
@ -55,7 +56,7 @@ export class Scheduler {
|
||||
}
|
||||
|
||||
private async doTaskProcessingStep() {
|
||||
await sleepShort();
|
||||
await sleepMicro();
|
||||
const currentTs = timestamp();
|
||||
const taskCommand = this.taskQueue.get(currentTs);
|
||||
|
||||
|
@ -6,6 +6,12 @@ export function sleep(ms: number) {
|
||||
return new Promise(resolve => setTimeout(resolve, ms));
|
||||
}
|
||||
|
||||
export async function sleepMicro() {
|
||||
let ms = 1000 + Math.random() * 1000;
|
||||
console.log('SLEEP SHORT', Math.round(ms / 1000));
|
||||
return await sleep(ms);
|
||||
}
|
||||
|
||||
export async function sleepShort() {
|
||||
let ms = 3000 + Math.random() * 1000;
|
||||
console.log('SLEEP SHORT', Math.round(ms / 1000));
|
||||
|
Loading…
Reference in New Issue
Block a user