Add research tasks
This commit is contained in:
@ -20,6 +20,10 @@ export function createActionHandler(name: string, scheduler: Scheduler): ActionC
|
||||
return new constructor(scheduler);
|
||||
}
|
||||
|
||||
export function err(msg: string): never {
|
||||
throw new ActionError(msg);
|
||||
}
|
||||
|
||||
export class ActionController {
|
||||
protected scheduler: Scheduler;
|
||||
constructor(scheduler: Scheduler) {
|
||||
@ -29,11 +33,7 @@ export class ActionController {
|
||||
async run(args: Args, task: Task) {}
|
||||
|
||||
ensureSameVillage(args: Args, task: Task) {
|
||||
let villageId = args.villageId;
|
||||
if (villageId === undefined) {
|
||||
throw new ActionError('Undefined village id');
|
||||
}
|
||||
|
||||
let villageId = args.villageId || err('Undefined village id');
|
||||
const activeVillageId = grabActiveVillageId();
|
||||
if (villageId !== activeVillageId) {
|
||||
throw new TryLaterError(aroundMinutes(1), 'Not same village');
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { ActionController, registerAction } from './ActionController';
|
||||
import { ActionError, GrabError, TryLaterError } from '../Errors';
|
||||
import { clickBuildButton } from '../Page/BuildingPage';
|
||||
import { ActionController, err, registerAction } from './ActionController';
|
||||
import { GrabError, TryLaterError } from '../Errors';
|
||||
import { clickBuildButton } from '../Page/BuildingPage/BuildingPage';
|
||||
import { aroundMinutes } from '../utils';
|
||||
import { Args } from '../Queue/Args';
|
||||
import { Task } from '../Queue/TaskProvider';
|
||||
@ -8,14 +8,9 @@ import { Task } from '../Queue/TaskProvider';
|
||||
@registerAction
|
||||
export class BuildBuildingAction extends ActionController {
|
||||
async run(args: Args, task: Task): Promise<any> {
|
||||
this.ensureSameVillage(args, task);
|
||||
|
||||
const buildTypeId = args.buildTypeId;
|
||||
if (buildTypeId === undefined) {
|
||||
throw new ActionError('Undefined build type id');
|
||||
}
|
||||
|
||||
try {
|
||||
this.ensureSameVillage(args, task);
|
||||
const buildTypeId = args.buildTypeId || err('Undefined build type id');
|
||||
clickBuildButton(buildTypeId);
|
||||
} catch (e) {
|
||||
if (e instanceof GrabError) {
|
||||
|
22
src/Action/ResearchAction.ts
Normal file
22
src/Action/ResearchAction.ts
Normal file
@ -0,0 +1,22 @@
|
||||
import { ActionController, err, registerAction } from './ActionController';
|
||||
import { GrabError, TryLaterError } from '../Errors';
|
||||
import { aroundMinutes } from '../utils';
|
||||
import { Args } from '../Queue/Args';
|
||||
import { Task } from '../Queue/TaskProvider';
|
||||
import { clickResearchButton } from '../Page/BuildingPage/ForgePage';
|
||||
|
||||
@registerAction
|
||||
export class ResearchAction extends ActionController {
|
||||
async run(args: Args, task: Task): Promise<any> {
|
||||
try {
|
||||
this.ensureSameVillage(args, task);
|
||||
const unitId = args.unitId || err('No unitId in args');
|
||||
clickResearchButton(unitId);
|
||||
} catch (e) {
|
||||
if (e instanceof GrabError) {
|
||||
throw new TryLaterError(aroundMinutes(15), e.message);
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,8 +1,7 @@
|
||||
import { ActionController, registerAction } from './ActionController';
|
||||
import { AbortTaskError, ActionError, TryLaterError } from '../Errors';
|
||||
import { ActionController, err, registerAction } from './ActionController';
|
||||
import { AbortTaskError, TryLaterError } from '../Errors';
|
||||
import { Resources } from '../Core/Resources';
|
||||
import { Coordinates, Village } from '../Core/Village';
|
||||
import { clickSendButton, fillSendResourcesForm, grabMerchantsInfo } from '../Page/BuildingPage';
|
||||
import { grabVillageResources } from '../Page/ResourcesBlock';
|
||||
import { grabActiveVillageId, grabVillageList } from '../Page/VillageBlock';
|
||||
import { SendResourcesTask } from '../Task/SendResourcesTask';
|
||||
@ -10,10 +9,7 @@ import { aroundMinutes, timestamp } from '../utils';
|
||||
import { VillageStorage } from '../Storage/VillageStorage';
|
||||
import { Args } from '../Queue/Args';
|
||||
import { Task } from '../Queue/TaskProvider';
|
||||
|
||||
function err(msg: string): never {
|
||||
throw new ActionError(msg);
|
||||
}
|
||||
import { clickSendButton, fillSendResourcesForm, grabMerchantsInfo } from '../Page/BuildingPage/MarketPage';
|
||||
|
||||
const TIMEOUT = 15;
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { ActionController, registerAction } from './ActionController';
|
||||
import { grabContractResources } from '../Page/BuildingPage';
|
||||
import { grabContractResources } from '../Page/BuildingPage/BuildingPage';
|
||||
import { Args } from '../Queue/Args';
|
||||
import { Task } from '../Queue/TaskProvider';
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { ActionController, registerAction } from './ActionController';
|
||||
import { GrabError, TryLaterError } from '../Errors';
|
||||
import { clickUpgradeButton } from '../Page/BuildingPage';
|
||||
import { clickUpgradeButton } from '../Page/BuildingPage/BuildingPage';
|
||||
import { aroundMinutes } from '../utils';
|
||||
import { Args } from '../Queue/Args';
|
||||
import { Task } from '../Queue/TaskProvider';
|
||||
@ -8,9 +8,8 @@ import { Task } from '../Queue/TaskProvider';
|
||||
@registerAction
|
||||
export class UpgradeBuildingAction extends ActionController {
|
||||
async run(args: Args, task: Task): Promise<any> {
|
||||
this.ensureSameVillage(args, task);
|
||||
|
||||
try {
|
||||
this.ensureSameVillage(args, task);
|
||||
clickUpgradeButton();
|
||||
} catch (e) {
|
||||
if (e instanceof GrabError) {
|
||||
|
Reference in New Issue
Block a user