Improve build tasks
This commit is contained in:
@ -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');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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) {
|
||||
|
@ -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);
|
@ -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) {
|
||||
|
Reference in New Issue
Block a user