Improve build tasks

This commit is contained in:
2020-05-02 13:27:26 +03:00
parent ed2102ce24
commit 53b325eee2
9 changed files with 55 additions and 52 deletions

View File

@ -4,6 +4,7 @@ import { grabActiveVillageId } from '../Page/VillageBlock';
import { aroundMinutes } from '../utils';
import { Args } from '../Queue/Args';
import { Task } from '../Queue/TaskProvider';
import { VillageStorage } from '../Storage/VillageStorage';
const actionMap: { [name: string]: Function | undefined } = {};
@ -39,4 +40,12 @@ export class ActionController {
throw new TryLaterError(aroundMinutes(1), 'Not same village');
}
}
ensureBuildingQueueIsEmpty() {
const storage = new VillageStorage(grabActiveVillageId());
const info = storage.getBuildingQueueInfo();
if (info.seconds > 0) {
throw new TryLaterError(info.seconds + 1, 'Building queue is full');
}
}
}

View File

@ -10,6 +10,7 @@ export class BuildBuildingAction extends ActionController {
async run(args: Args, task: Task): Promise<any> {
try {
this.ensureSameVillage(args, task);
this.ensureBuildingQueueIsEmpty();
const buildTypeId = args.buildTypeId || err('Undefined build type id');
clickBuildButton(buildTypeId);
} catch (e) {

View File

@ -6,7 +6,7 @@ import { Task } from '../Queue/TaskProvider';
import { clickResearchButton } from '../Page/BuildingPage/ForgePage';
@registerAction
export class ResearchAction extends ActionController {
export class ForgeImprovementAction extends ActionController {
async run(args: Args, task: Task): Promise<any> {
try {
this.ensureSameVillage(args, task);

View File

@ -10,6 +10,7 @@ export class UpgradeBuildingAction extends ActionController {
async run(args: Args, task: Task): Promise<any> {
try {
this.ensureSameVillage(args, task);
this.ensureBuildingQueueIsEmpty();
clickUpgradeButton();
} catch (e) {
if (e instanceof GrabError) {