Move action and task handlers in their own space
This commit is contained in:
parent
b6cda983c7
commit
a74a26896c
@ -1,46 +0,0 @@
|
|||||||
import { Scheduler } from '../Scheduler';
|
|
||||||
import { taskError, TryLaterError } from '../Errors';
|
|
||||||
import { grabActiveVillageId } from '../Page/VillageBlock';
|
|
||||||
import { Args } from '../Queue/Args';
|
|
||||||
import { Task } from '../Queue/TaskProvider';
|
|
||||||
import { VillageStorage } from '../Storage/VillageStorage';
|
|
||||||
import { VillageFactory } from '../Village/VillageFactory';
|
|
||||||
import { aroundMinutes } from '../Helpers/Time';
|
|
||||||
|
|
||||||
const actionMap: { [name: string]: Function | undefined } = {};
|
|
||||||
|
|
||||||
export function registerAction(constructor: Function) {
|
|
||||||
actionMap[constructor.name] = constructor;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function createActionHandler(
|
|
||||||
name: string,
|
|
||||||
scheduler: Scheduler,
|
|
||||||
villageFactory: VillageFactory
|
|
||||||
): ActionController | undefined {
|
|
||||||
const storedFunction = actionMap[name];
|
|
||||||
if (storedFunction === undefined) {
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
const constructor = (storedFunction as unknown) as typeof ActionController;
|
|
||||||
return new constructor(scheduler, villageFactory);
|
|
||||||
}
|
|
||||||
|
|
||||||
export class ActionController {
|
|
||||||
protected readonly scheduler: Scheduler;
|
|
||||||
protected readonly villageFactory: VillageFactory;
|
|
||||||
constructor(scheduler: Scheduler, villageFactory: VillageFactory) {
|
|
||||||
this.scheduler = scheduler;
|
|
||||||
this.villageFactory = villageFactory;
|
|
||||||
}
|
|
||||||
|
|
||||||
async run(args: Args, task: Task) {}
|
|
||||||
|
|
||||||
ensureSameVillage(args: Args, task: Task) {
|
|
||||||
let villageId = args.villageId || taskError('Undefined village id');
|
|
||||||
const activeVillageId = grabActiveVillageId();
|
|
||||||
if (villageId !== activeVillageId) {
|
|
||||||
throw new TryLaterError(aroundMinutes(1), 'Not same village');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,22 +0,0 @@
|
|||||||
import { ActionController, registerAction } from './ActionController';
|
|
||||||
import { GrabError, taskError, TryLaterError } from '../Errors';
|
|
||||||
import { clickBuildButton } from '../Page/BuildingPage/BuildingPage';
|
|
||||||
import { Args } from '../Queue/Args';
|
|
||||||
import { Task } from '../Queue/TaskProvider';
|
|
||||||
import { aroundMinutes } from '../Helpers/Time';
|
|
||||||
|
|
||||||
@registerAction
|
|
||||||
export class BuildBuildingAction extends ActionController {
|
|
||||||
async run(args: Args, task: Task): Promise<any> {
|
|
||||||
try {
|
|
||||||
this.ensureSameVillage(args, task);
|
|
||||||
const buildTypeId = args.buildTypeId || taskError('Undefined build type id');
|
|
||||||
clickBuildButton(buildTypeId);
|
|
||||||
} catch (e) {
|
|
||||||
if (e instanceof GrabError) {
|
|
||||||
throw new TryLaterError(aroundMinutes(5), 'No upgrade button, try later');
|
|
||||||
}
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,21 +0,0 @@
|
|||||||
import { ActionController, registerAction } from './ActionController';
|
|
||||||
import { GrabError, TryLaterError } from '../Errors';
|
|
||||||
import { Args } from '../Queue/Args';
|
|
||||||
import { Task } from '../Queue/TaskProvider';
|
|
||||||
import { clickCelebrationButton } from '../Page/BuildingPage/GuildHallPage';
|
|
||||||
import { aroundMinutes } from '../Helpers/Time';
|
|
||||||
|
|
||||||
@registerAction
|
|
||||||
export class CelebrationAction extends ActionController {
|
|
||||||
async run(args: Args, task: Task): Promise<any> {
|
|
||||||
try {
|
|
||||||
this.ensureSameVillage(args, task);
|
|
||||||
clickCelebrationButton(args.celebrationIndex);
|
|
||||||
} catch (e) {
|
|
||||||
if (e instanceof GrabError) {
|
|
||||||
throw new TryLaterError(aroundMinutes(60), e.message);
|
|
||||||
}
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,10 +0,0 @@
|
|||||||
import { ActionController, registerAction } from './ActionController';
|
|
||||||
import { Args } from '../Queue/Args';
|
|
||||||
import { Task } from '../Queue/TaskProvider';
|
|
||||||
|
|
||||||
@registerAction
|
|
||||||
export class CompleteTaskAction extends ActionController {
|
|
||||||
async run(args: Args, task: Task): Promise<any> {
|
|
||||||
this.scheduler.completeTask(task.id);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,22 +0,0 @@
|
|||||||
import { ActionController, registerAction } from './ActionController';
|
|
||||||
import { GrabError, taskError, TryLaterError } from '../Errors';
|
|
||||||
import { Args } from '../Queue/Args';
|
|
||||||
import { Task } from '../Queue/TaskProvider';
|
|
||||||
import { clickResearchButton } from '../Page/BuildingPage/ForgePage';
|
|
||||||
import { aroundMinutes } from '../Helpers/Time';
|
|
||||||
|
|
||||||
@registerAction
|
|
||||||
export class ForgeImprovementAction extends ActionController {
|
|
||||||
async run(args: Args, task: Task): Promise<any> {
|
|
||||||
try {
|
|
||||||
this.ensureSameVillage(args, task);
|
|
||||||
const unitId = args.unitId || taskError('No unitId in args');
|
|
||||||
clickResearchButton(unitId);
|
|
||||||
} catch (e) {
|
|
||||||
if (e instanceof GrabError) {
|
|
||||||
throw new TryLaterError(aroundMinutes(15), e.message);
|
|
||||||
}
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,12 +0,0 @@
|
|||||||
import { ActionController, registerAction } from './ActionController';
|
|
||||||
import { taskError } from '../Errors';
|
|
||||||
import { Args } from '../Queue/Args';
|
|
||||||
import { Task } from '../Queue/TaskProvider';
|
|
||||||
|
|
||||||
@registerAction
|
|
||||||
export class GoToPageAction extends ActionController {
|
|
||||||
async run(args: Args, task: Task): Promise<any> {
|
|
||||||
const path = args.path || taskError('Empty path');
|
|
||||||
window.location.assign(path);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,21 +0,0 @@
|
|||||||
import { ActionController, registerAction } from './ActionController';
|
|
||||||
import { GrabError, TryLaterError } from '../Errors';
|
|
||||||
import { clickUpgradeButton } from '../Page/BuildingPage/BuildingPage';
|
|
||||||
import { Args } from '../Queue/Args';
|
|
||||||
import { Task } from '../Queue/TaskProvider';
|
|
||||||
import { aroundMinutes } from '../Helpers/Time';
|
|
||||||
|
|
||||||
@registerAction
|
|
||||||
export class UpgradeBuildingAction extends ActionController {
|
|
||||||
async run(args: Args, task: Task): Promise<any> {
|
|
||||||
try {
|
|
||||||
this.ensureSameVillage(args, task);
|
|
||||||
clickUpgradeButton();
|
|
||||||
} catch (e) {
|
|
||||||
if (e instanceof GrabError) {
|
|
||||||
throw new TryLaterError(aroundMinutes(5), 'No upgrade button, try later');
|
|
||||||
}
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,6 +1,6 @@
|
|||||||
import { Scheduler } from './Scheduler';
|
import { Scheduler } from './Scheduler';
|
||||||
import { BuildingPageController } from './Page/BuildingPageController';
|
import { BuildingPageController } from './Page/BuildingPageController';
|
||||||
import { UpgradeBuildingTask } from './Task/UpgradeBuildingTask';
|
import { UpgradeBuildingTask } from './Handler/Task/UpgradeBuildingTask';
|
||||||
import { grabActiveVillageId } from './Page/VillageBlock';
|
import { grabActiveVillageId } from './Page/VillageBlock';
|
||||||
import {
|
import {
|
||||||
onBuildingSlotCtrlClick,
|
onBuildingSlotCtrlClick,
|
||||||
|
@ -7,7 +7,6 @@ import {
|
|||||||
VillageNotFound,
|
VillageNotFound,
|
||||||
} from './Errors';
|
} from './Errors';
|
||||||
import { TaskQueueRenderer } from './TaskQueueRenderer';
|
import { TaskQueueRenderer } from './TaskQueueRenderer';
|
||||||
import { createActionHandler } from './Action/ActionController';
|
|
||||||
import { Logger } from './Logger';
|
import { Logger } from './Logger';
|
||||||
import { GrabberManager } from './Grabber/GrabberManager';
|
import { GrabberManager } from './Grabber/GrabberManager';
|
||||||
import { Scheduler } from './Scheduler';
|
import { Scheduler } from './Scheduler';
|
||||||
@ -15,10 +14,11 @@ import { Statistics } from './Statistics';
|
|||||||
import { ExecutionStorage } from './Storage/ExecutionStorage';
|
import { ExecutionStorage } from './Storage/ExecutionStorage';
|
||||||
import { Action } from './Queue/ActionQueue';
|
import { Action } from './Queue/ActionQueue';
|
||||||
import { Task } from './Queue/TaskProvider';
|
import { Task } from './Queue/TaskProvider';
|
||||||
import { createTaskHandler } from './Task/TaskMap';
|
import { createTaskHandler } from './Handler/TaskMap';
|
||||||
import { VillageFactory } from './Village/VillageFactory';
|
import { VillageFactory } from './Village/VillageFactory';
|
||||||
import { sleepMicro, timestamp } from './Helpers/Time';
|
import { sleepMicro, timestamp } from './Helpers/Time';
|
||||||
import { markPage, waitForLoad } from './Helpers/Browser';
|
import { markPage, waitForLoad } from './Helpers/Browser';
|
||||||
|
import { createActionHandler } from './Handler/ActionMap';
|
||||||
|
|
||||||
export interface ExecutionSettings {
|
export interface ExecutionSettings {
|
||||||
pauseTs: number;
|
pauseTs: number;
|
||||||
@ -27,11 +27,11 @@ export interface ExecutionSettings {
|
|||||||
export class Executor {
|
export class Executor {
|
||||||
private readonly version: string;
|
private readonly version: string;
|
||||||
private readonly scheduler: Scheduler;
|
private readonly scheduler: Scheduler;
|
||||||
private villageFactory: VillageFactory;
|
private readonly villageFactory: VillageFactory;
|
||||||
private grabberManager: GrabberManager;
|
private readonly grabberManager: GrabberManager;
|
||||||
private statistics: Statistics;
|
private readonly statistics: Statistics;
|
||||||
private executionState: ExecutionStorage;
|
private readonly executionState: ExecutionStorage;
|
||||||
private logger: Logger;
|
private readonly logger: Logger;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
version: string,
|
version: string,
|
||||||
@ -101,18 +101,18 @@ export class Executor {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
if (task && action) {
|
if (task && action) {
|
||||||
return await this.processActionCommand(action, task);
|
return await this.processAction(action, task);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (task) {
|
if (task) {
|
||||||
return await this.processTaskCommand(task);
|
return await this.processTask(task);
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
this.handleError(e, task);
|
this.handleError(e, task);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async processActionCommand(action: Action, task: Task) {
|
private async processAction(action: Action, task: Task) {
|
||||||
const actionHandler = createActionHandler(action.name, this.scheduler, this.villageFactory);
|
const actionHandler = createActionHandler(action.name, this.scheduler, this.villageFactory);
|
||||||
this.logger.info('Process action', action.name, actionHandler);
|
this.logger.info('Process action', action.name, actionHandler);
|
||||||
if (actionHandler) {
|
if (actionHandler) {
|
||||||
@ -123,7 +123,7 @@ export class Executor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async processTaskCommand(task: Task) {
|
private async processTask(task: Task) {
|
||||||
const taskHandler = createTaskHandler(task.name, this.scheduler, this.villageFactory);
|
const taskHandler = createTaskHandler(task.name, this.scheduler, this.villageFactory);
|
||||||
this.logger.info('Process task', task.name, task, taskHandler);
|
this.logger.info('Process task', task.name, task, taskHandler);
|
||||||
if (taskHandler) {
|
if (taskHandler) {
|
||||||
|
@ -1,14 +1,15 @@
|
|||||||
import { ActionController, registerAction } from './ActionController';
|
import { BaseAction } from './BaseAction';
|
||||||
import { changeHeroResource, grabCurrentHeroResource } from '../Page/HeroPage';
|
import { changeHeroResource, grabCurrentHeroResource } from '../../Page/HeroPage';
|
||||||
import { grabActiveVillageId } from '../Page/VillageBlock';
|
import { grabActiveVillageId } from '../../Page/VillageBlock';
|
||||||
import { HeroStorage } from '../Storage/HeroStorage';
|
import { HeroStorage } from '../../Storage/HeroStorage';
|
||||||
import { calcHeroResource } from '../Core/HeroBalance';
|
import { calcHeroResource } from '../../Core/HeroBalance';
|
||||||
import { HeroAllResources } from '../Core/Hero';
|
import { HeroAllResources } from '../../Core/Hero';
|
||||||
import { Args } from '../Queue/Args';
|
import { Args } from '../../Queue/Args';
|
||||||
import { Task } from '../Queue/TaskProvider';
|
import { Task } from '../../Queue/TaskProvider';
|
||||||
|
import { registerAction } from '../ActionMap';
|
||||||
|
|
||||||
@registerAction
|
@registerAction
|
||||||
export class BalanceHeroResourcesAction extends ActionController {
|
export class BalanceHeroResourcesAction extends BaseAction {
|
||||||
async run(args: Args, task: Task): Promise<any> {
|
async run(args: Args, task: Task): Promise<any> {
|
||||||
const thisVillageId = grabActiveVillageId();
|
const thisVillageId = grabActiveVillageId();
|
||||||
const heroVillageId = new HeroStorage().getVillageId();
|
const heroVillageId = new HeroStorage().getVillageId();
|
26
src/Handler/Action/BaseAction.ts
Normal file
26
src/Handler/Action/BaseAction.ts
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
import { Scheduler } from '../../Scheduler';
|
||||||
|
import { taskError, TryLaterError } from '../../Errors';
|
||||||
|
import { grabActiveVillageId } from '../../Page/VillageBlock';
|
||||||
|
import { Args } from '../../Queue/Args';
|
||||||
|
import { Task } from '../../Queue/TaskProvider';
|
||||||
|
import { VillageFactory } from '../../Village/VillageFactory';
|
||||||
|
import { aroundMinutes } from '../../Helpers/Time';
|
||||||
|
|
||||||
|
export class BaseAction {
|
||||||
|
protected readonly scheduler: Scheduler;
|
||||||
|
protected readonly villageFactory: VillageFactory;
|
||||||
|
constructor(scheduler: Scheduler, villageFactory: VillageFactory) {
|
||||||
|
this.scheduler = scheduler;
|
||||||
|
this.villageFactory = villageFactory;
|
||||||
|
}
|
||||||
|
|
||||||
|
async run(args: Args, task: Task) {}
|
||||||
|
|
||||||
|
ensureSameVillage(args: Args) {
|
||||||
|
let villageId = args.villageId || taskError('Undefined village id');
|
||||||
|
const activeVillageId = grabActiveVillageId();
|
||||||
|
if (villageId !== activeVillageId) {
|
||||||
|
throw new TryLaterError(aroundMinutes(1), 'Not same village');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
23
src/Handler/Action/BuildBuildingAction.ts
Normal file
23
src/Handler/Action/BuildBuildingAction.ts
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
import { BaseAction } from './BaseAction';
|
||||||
|
import { GrabError, taskError, TryLaterError } from '../../Errors';
|
||||||
|
import { clickBuildButton } from '../../Page/BuildingPage/BuildingPage';
|
||||||
|
import { Args } from '../../Queue/Args';
|
||||||
|
import { Task } from '../../Queue/TaskProvider';
|
||||||
|
import { aroundMinutes } from '../../Helpers/Time';
|
||||||
|
import { registerAction } from '../ActionMap';
|
||||||
|
|
||||||
|
@registerAction
|
||||||
|
export class BuildBuildingAction extends BaseAction {
|
||||||
|
async run(args: Args, task: Task): Promise<any> {
|
||||||
|
try {
|
||||||
|
this.ensureSameVillage(args);
|
||||||
|
const buildTypeId = args.buildTypeId || taskError('Undefined build type id');
|
||||||
|
clickBuildButton(buildTypeId);
|
||||||
|
} catch (e) {
|
||||||
|
if (e instanceof GrabError) {
|
||||||
|
throw new TryLaterError(aroundMinutes(5), 'No upgrade button, try later');
|
||||||
|
}
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
22
src/Handler/Action/CelebrationAction.ts
Normal file
22
src/Handler/Action/CelebrationAction.ts
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
import { BaseAction } from './BaseAction';
|
||||||
|
import { GrabError, TryLaterError } from '../../Errors';
|
||||||
|
import { Args } from '../../Queue/Args';
|
||||||
|
import { Task } from '../../Queue/TaskProvider';
|
||||||
|
import { clickCelebrationButton } from '../../Page/BuildingPage/GuildHallPage';
|
||||||
|
import { aroundMinutes } from '../../Helpers/Time';
|
||||||
|
import { registerAction } from '../ActionMap';
|
||||||
|
|
||||||
|
@registerAction
|
||||||
|
export class CelebrationAction extends BaseAction {
|
||||||
|
async run(args: Args, task: Task): Promise<any> {
|
||||||
|
try {
|
||||||
|
this.ensureSameVillage(args);
|
||||||
|
clickCelebrationButton(args.celebrationIndex);
|
||||||
|
} catch (e) {
|
||||||
|
if (e instanceof GrabError) {
|
||||||
|
throw new TryLaterError(aroundMinutes(60), e.message);
|
||||||
|
}
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,12 +1,13 @@
|
|||||||
import { ActionController, registerAction } from './ActionController';
|
import { BaseAction } from './BaseAction';
|
||||||
import { GrabError, TryLaterError } from '../Errors';
|
import { GrabError, TryLaterError } from '../../Errors';
|
||||||
import { grabBuildingQueueInfo } from '../Page/VillageBlock';
|
import { grabBuildingQueueInfo } from '../../Page/VillageBlock';
|
||||||
import { Args } from '../Queue/Args';
|
import { Args } from '../../Queue/Args';
|
||||||
import { Task } from '../Queue/TaskProvider';
|
import { Task } from '../../Queue/TaskProvider';
|
||||||
import { BuildingQueueInfo } from '../Core/BuildingQueueInfo';
|
import { BuildingQueueInfo } from '../../Core/BuildingQueueInfo';
|
||||||
|
import { registerAction } from '../ActionMap';
|
||||||
|
|
||||||
@registerAction
|
@registerAction
|
||||||
export class CheckBuildingRemainingTimeAction extends ActionController {
|
export class CheckBuildingRemainingTimeAction extends BaseAction {
|
||||||
async run(args: Args, task: Task): Promise<any> {
|
async run(args: Args, task: Task): Promise<any> {
|
||||||
const info = this.grabBuildingQueueInfoOrDefault();
|
const info = this.grabBuildingQueueInfoOrDefault();
|
||||||
if (info.seconds > 0) {
|
if (info.seconds > 0) {
|
@ -1,10 +1,11 @@
|
|||||||
import { ActionController, registerAction } from './ActionController';
|
import { BaseAction } from './BaseAction';
|
||||||
import { taskError } from '../Errors';
|
import { taskError } from '../../Errors';
|
||||||
import { Args } from '../Queue/Args';
|
import { Args } from '../../Queue/Args';
|
||||||
import { Task } from '../Queue/TaskProvider';
|
import { Task } from '../../Queue/TaskProvider';
|
||||||
|
import { registerAction } from '../ActionMap';
|
||||||
|
|
||||||
@registerAction
|
@registerAction
|
||||||
export class ClickButtonAction extends ActionController {
|
export class ClickButtonAction extends BaseAction {
|
||||||
async run(args: Args, task: Task): Promise<any> {
|
async run(args: Args, task: Task): Promise<any> {
|
||||||
const selector = args.selector || taskError('No selector');
|
const selector = args.selector || taskError('No selector');
|
||||||
const el = jQuery(selector);
|
const el = jQuery(selector);
|
11
src/Handler/Action/CompleteTaskAction.ts
Normal file
11
src/Handler/Action/CompleteTaskAction.ts
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
import { BaseAction } from './BaseAction';
|
||||||
|
import { Args } from '../../Queue/Args';
|
||||||
|
import { Task } from '../../Queue/TaskProvider';
|
||||||
|
import { registerAction } from '../ActionMap';
|
||||||
|
|
||||||
|
@registerAction
|
||||||
|
export class CompleteTaskAction extends BaseAction {
|
||||||
|
async run(args: Args, task: Task): Promise<any> {
|
||||||
|
this.scheduler.completeTask(task.id);
|
||||||
|
}
|
||||||
|
}
|
@ -1,25 +1,26 @@
|
|||||||
import { ActionController, registerAction } from './ActionController';
|
import { BaseAction } from './BaseAction';
|
||||||
import { FailTaskError, taskError, TryLaterError } from '../Errors';
|
import { FailTaskError, taskError, TryLaterError } from '../../Errors';
|
||||||
import { Resources } from '../Core/Resources';
|
import { Resources } from '../../Core/Resources';
|
||||||
import { Coordinates } from '../Core/Village';
|
import { Coordinates } from '../../Core/Village';
|
||||||
import { Args } from '../Queue/Args';
|
import { Args } from '../../Queue/Args';
|
||||||
import { Task } from '../Queue/TaskProvider';
|
import { Task } from '../../Queue/TaskProvider';
|
||||||
import { clickSendButton, fillSendResourcesForm } from '../Page/BuildingPage/MarketPage';
|
import { clickSendButton, fillSendResourcesForm } from '../../Page/BuildingPage/MarketPage';
|
||||||
import { VillageState } from '../Village/VillageState';
|
import { VillageState } from '../../Village/VillageState';
|
||||||
import { MerchantsInfo } from '../Core/Market';
|
import { MerchantsInfo } from '../../Core/Market';
|
||||||
import { goToMarketSendResourcesPage, goToResourceViewPage } from '../Task/ActionBundles';
|
import { goToMarketSendResourcesPage, goToResourceViewPage } from '../ActionBundles';
|
||||||
import {
|
import {
|
||||||
compareReports,
|
compareReports,
|
||||||
ResourceTransferCalculator,
|
ResourceTransferCalculator,
|
||||||
ResourceTransferReport,
|
ResourceTransferReport,
|
||||||
} from '../Village/ResourceTransfer';
|
} from '../../Village/ResourceTransfer';
|
||||||
import { ResourceTransferStorage } from '../Storage/ResourceTransferStorage';
|
import { ResourceTransferStorage } from '../../Storage/ResourceTransferStorage';
|
||||||
import { path } from '../Helpers/Path';
|
import { path } from '../../Helpers/Path';
|
||||||
import { MARKET_ID } from '../Core/Buildings';
|
import { MARKET_ID } from '../../Core/Buildings';
|
||||||
import { aroundMinutes, timestamp } from '../Helpers/Time';
|
import { aroundMinutes, timestamp } from '../../Helpers/Time';
|
||||||
|
import { registerAction } from '../ActionMap';
|
||||||
|
|
||||||
@registerAction
|
@registerAction
|
||||||
export class FindSendResourcesPath extends ActionController {
|
export class FindSendResourcesPathAction extends BaseAction {
|
||||||
async run(args: Args, task: Task): Promise<any> {
|
async run(args: Args, task: Task): Promise<any> {
|
||||||
const reports: Array<ResourceTransferReport> = [];
|
const reports: Array<ResourceTransferReport> = [];
|
||||||
const calculator = new ResourceTransferCalculator(this.villageFactory);
|
const calculator = new ResourceTransferCalculator(this.villageFactory);
|
23
src/Handler/Action/ForgeImprovementAction.ts
Normal file
23
src/Handler/Action/ForgeImprovementAction.ts
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
import { BaseAction } from './BaseAction';
|
||||||
|
import { GrabError, taskError, TryLaterError } from '../../Errors';
|
||||||
|
import { Args } from '../../Queue/Args';
|
||||||
|
import { Task } from '../../Queue/TaskProvider';
|
||||||
|
import { clickResearchButton } from '../../Page/BuildingPage/ForgePage';
|
||||||
|
import { aroundMinutes } from '../../Helpers/Time';
|
||||||
|
import { registerAction } from '../ActionMap';
|
||||||
|
|
||||||
|
@registerAction
|
||||||
|
export class ForgeImprovementAction extends BaseAction {
|
||||||
|
async run(args: Args, task: Task): Promise<any> {
|
||||||
|
try {
|
||||||
|
this.ensureSameVillage(args);
|
||||||
|
const unitId = args.unitId || taskError('No unitId in args');
|
||||||
|
clickResearchButton(unitId);
|
||||||
|
} catch (e) {
|
||||||
|
if (e instanceof GrabError) {
|
||||||
|
throw new TryLaterError(aroundMinutes(15), e.message);
|
||||||
|
}
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,13 +1,14 @@
|
|||||||
import { ActionController, registerAction } from './ActionController';
|
import { BaseAction } from './BaseAction';
|
||||||
import { grabVillageList } from '../Page/VillageBlock';
|
import { grabVillageList } from '../../Page/VillageBlock';
|
||||||
import { grabHeroVillage } from '../Page/HeroPage';
|
import { grabHeroVillage } from '../../Page/HeroPage';
|
||||||
import { HeroStorage } from '../Storage/HeroStorage';
|
import { HeroStorage } from '../../Storage/HeroStorage';
|
||||||
import { Args } from '../Queue/Args';
|
import { Args } from '../../Queue/Args';
|
||||||
import { Task } from '../Queue/TaskProvider';
|
import { Task } from '../../Queue/TaskProvider';
|
||||||
import { path } from '../Helpers/Path';
|
import { path } from '../../Helpers/Path';
|
||||||
|
import { registerAction } from '../ActionMap';
|
||||||
|
|
||||||
@registerAction
|
@registerAction
|
||||||
export class GoToHeroVillageAction extends ActionController {
|
export class GoToHeroVillageAction extends BaseAction {
|
||||||
async run(args: Args, task: Task): Promise<any> {
|
async run(args: Args, task: Task): Promise<any> {
|
||||||
const heroVillageId = this.getHeroVillageId();
|
const heroVillageId = this.getHeroVillageId();
|
||||||
if (heroVillageId) {
|
if (heroVillageId) {
|
13
src/Handler/Action/GoToPageAction.ts
Normal file
13
src/Handler/Action/GoToPageAction.ts
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
import { BaseAction } from './BaseAction';
|
||||||
|
import { taskError } from '../../Errors';
|
||||||
|
import { Args } from '../../Queue/Args';
|
||||||
|
import { Task } from '../../Queue/TaskProvider';
|
||||||
|
import { registerAction } from '../ActionMap';
|
||||||
|
|
||||||
|
@registerAction
|
||||||
|
export class GoToPageAction extends BaseAction {
|
||||||
|
async run(args: Args, task: Task): Promise<any> {
|
||||||
|
const path = args.path || taskError('Empty path');
|
||||||
|
window.location.assign(path);
|
||||||
|
}
|
||||||
|
}
|
@ -1,8 +1,9 @@
|
|||||||
import { ActionController, registerAction } from './ActionController';
|
import { BaseAction } from './BaseAction';
|
||||||
import { AbortTaskError } from '../Errors';
|
import { AbortTaskError } from '../../Errors';
|
||||||
import { Args } from '../Queue/Args';
|
import { Args } from '../../Queue/Args';
|
||||||
import { Task } from '../Queue/TaskProvider';
|
import { Task } from '../../Queue/TaskProvider';
|
||||||
import { trimPrefix } from '../Helpers/Convert';
|
import { trimPrefix } from '../../Helpers/Convert';
|
||||||
|
import { registerAction } from '../ActionMap';
|
||||||
|
|
||||||
const CONFIG = [
|
const CONFIG = [
|
||||||
{ level: 0, health: 60 },
|
{ level: 0, health: 60 },
|
||||||
@ -19,7 +20,7 @@ interface Adventure {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@registerAction
|
@registerAction
|
||||||
export class SendOnAdventureAction extends ActionController {
|
export class SendOnAdventureAction extends BaseAction {
|
||||||
async run(args: Args, task: Task): Promise<any> {
|
async run(args: Args, task: Task): Promise<any> {
|
||||||
const adventures = this.findAdventures();
|
const adventures = this.findAdventures();
|
||||||
|
|
@ -1,14 +1,15 @@
|
|||||||
import { ActionController, registerAction } from './ActionController';
|
import { BaseAction } from './BaseAction';
|
||||||
import { Args } from '../Queue/Args';
|
import { Args } from '../../Queue/Args';
|
||||||
import { Task } from '../Queue/TaskProvider';
|
import { Task } from '../../Queue/TaskProvider';
|
||||||
import { clickSendButton, fillSendResourcesForm } from '../Page/BuildingPage/MarketPage';
|
import { clickSendButton, fillSendResourcesForm } from '../../Page/BuildingPage/MarketPage';
|
||||||
import { ResourceTransferCalculator } from '../Village/ResourceTransfer';
|
import { ResourceTransferCalculator } from '../../Village/ResourceTransfer';
|
||||||
import { ResourceTransferStorage } from '../Storage/ResourceTransferStorage';
|
import { ResourceTransferStorage } from '../../Storage/ResourceTransferStorage';
|
||||||
import { Resources } from '../Core/Resources';
|
import { Resources } from '../../Core/Resources';
|
||||||
import { AbortTaskError } from '../Errors';
|
import { AbortTaskError } from '../../Errors';
|
||||||
|
import { registerAction } from '../ActionMap';
|
||||||
|
|
||||||
@registerAction
|
@registerAction
|
||||||
export class SendResourcesAction extends ActionController {
|
export class SendResourcesAction extends BaseAction {
|
||||||
async run(args: Args, task: Task): Promise<any> {
|
async run(args: Args, task: Task): Promise<any> {
|
||||||
const storage = new ResourceTransferStorage();
|
const storage = new ResourceTransferStorage();
|
||||||
const savedReport = storage.getReport();
|
const savedReport = storage.getReport();
|
@ -1,19 +1,20 @@
|
|||||||
import { ActionController, registerAction } from './ActionController';
|
import { BaseAction } from './BaseAction';
|
||||||
import { taskError, TryLaterError } from '../Errors';
|
import { taskError, TryLaterError } from '../../Errors';
|
||||||
import { Args } from '../Queue/Args';
|
import { Args } from '../../Queue/Args';
|
||||||
import { Task } from '../Queue/TaskProvider';
|
import { Task } from '../../Queue/TaskProvider';
|
||||||
import {
|
import {
|
||||||
clickTrainButton,
|
clickTrainButton,
|
||||||
fillTrainCount,
|
fillTrainCount,
|
||||||
getAvailableCount,
|
getAvailableCount,
|
||||||
} from '../Page/BuildingPage/TrooperPage';
|
} from '../../Page/BuildingPage/TrooperPage';
|
||||||
import { TrainTroopTask } from '../Task/TrainTroopTask';
|
import { TrainTroopTask } from '../Task/TrainTroopTask';
|
||||||
import { Resources } from '../Core/Resources';
|
import { Resources } from '../../Core/Resources';
|
||||||
import { randomInRange } from '../Helpers/Random';
|
import { randomInRange } from '../../Helpers/Random';
|
||||||
import { aroundMinutes } from '../Helpers/Time';
|
import { aroundMinutes } from '../../Helpers/Time';
|
||||||
|
import { registerAction } from '../ActionMap';
|
||||||
|
|
||||||
@registerAction
|
@registerAction
|
||||||
export class TrainTrooperAction extends ActionController {
|
export class TrainTrooperAction extends BaseAction {
|
||||||
async run(args: Args, task: Task): Promise<any> {
|
async run(args: Args, task: Task): Promise<any> {
|
||||||
const troopId = args.troopId || taskError('No troop id');
|
const troopId = args.troopId || taskError('No troop id');
|
||||||
const trainCount = args.trainCount || taskError('No troop train count');
|
const trainCount = args.trainCount || taskError('No troop train count');
|
22
src/Handler/Action/UpgradeBuildingAction.ts
Normal file
22
src/Handler/Action/UpgradeBuildingAction.ts
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
import { BaseAction } from './BaseAction';
|
||||||
|
import { GrabError, TryLaterError } from '../../Errors';
|
||||||
|
import { clickUpgradeButton } from '../../Page/BuildingPage/BuildingPage';
|
||||||
|
import { Args } from '../../Queue/Args';
|
||||||
|
import { Task } from '../../Queue/TaskProvider';
|
||||||
|
import { aroundMinutes } from '../../Helpers/Time';
|
||||||
|
import { registerAction } from '../ActionMap';
|
||||||
|
|
||||||
|
@registerAction
|
||||||
|
export class UpgradeBuildingAction extends BaseAction {
|
||||||
|
async run(args: Args, task: Task): Promise<any> {
|
||||||
|
try {
|
||||||
|
this.ensureSameVillage(args);
|
||||||
|
clickUpgradeButton();
|
||||||
|
} catch (e) {
|
||||||
|
if (e instanceof GrabError) {
|
||||||
|
throw new TryLaterError(aroundMinutes(5), 'No upgrade button, try later');
|
||||||
|
}
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,15 +1,16 @@
|
|||||||
import { ActionController, registerAction } from './ActionController';
|
import { BaseAction } from './BaseAction';
|
||||||
import { ActionError, taskError, TryLaterError } from '../Errors';
|
import { ActionError, taskError, TryLaterError } from '../../Errors';
|
||||||
import { grabResourceSlots } from '../Page/SlotBlock';
|
import { grabResourceSlots } from '../../Page/SlotBlock';
|
||||||
import { UpgradeBuildingTask } from '../Task/UpgradeBuildingTask';
|
import { UpgradeBuildingTask } from '../Task/UpgradeBuildingTask';
|
||||||
import { Args } from '../Queue/Args';
|
import { Args } from '../../Queue/Args';
|
||||||
import { Task } from '../Queue/TaskProvider';
|
import { Task } from '../../Queue/TaskProvider';
|
||||||
import { ResourceSlot } from '../Core/Slot';
|
import { ResourceSlot } from '../../Core/Slot';
|
||||||
import { getNumber } from '../Helpers/Convert';
|
import { getNumber } from '../../Helpers/Convert';
|
||||||
import { aroundMinutes } from '../Helpers/Time';
|
import { aroundMinutes } from '../../Helpers/Time';
|
||||||
|
import { registerAction } from '../ActionMap';
|
||||||
|
|
||||||
@registerAction
|
@registerAction
|
||||||
export class UpgradeResourceToLevel extends ActionController {
|
export class UpgradeResourceToLevelAction extends BaseAction {
|
||||||
async run(args: Args, task: Task): Promise<any> {
|
async run(args: Args, task: Task): Promise<any> {
|
||||||
const deposits = grabResourceSlots();
|
const deposits = grabResourceSlots();
|
||||||
if (deposits.length === 0) {
|
if (deposits.length === 0) {
|
@ -1,5 +1,5 @@
|
|||||||
import { ActionDefinition } from './TaskController';
|
import { ActionDefinition } from './Task/BaseTask';
|
||||||
import { GoToPageAction } from '../Action/GoToPageAction';
|
import { GoToPageAction } from './Action/GoToPageAction';
|
||||||
import { FORGE_ID, GUILD_HALL_ID, MARKET_ID } from '../Core/Buildings';
|
import { FORGE_ID, GUILD_HALL_ID, MARKET_ID } from '../Core/Buildings';
|
||||||
import { path } from '../Helpers/Path';
|
import { path } from '../Helpers/Path';
|
||||||
import { Village } from '../Core/Village';
|
import { Village } from '../Core/Village';
|
22
src/Handler/ActionMap.ts
Normal file
22
src/Handler/ActionMap.ts
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
import { Scheduler } from '../Scheduler';
|
||||||
|
import { VillageFactory } from '../Village/VillageFactory';
|
||||||
|
import { BaseAction } from './Action/BaseAction';
|
||||||
|
|
||||||
|
const actionMap: { [name: string]: Function | undefined } = {};
|
||||||
|
|
||||||
|
export function registerAction(constructor: Function) {
|
||||||
|
actionMap[constructor.name] = constructor;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function createActionHandler(
|
||||||
|
name: string,
|
||||||
|
scheduler: Scheduler,
|
||||||
|
villageFactory: VillageFactory
|
||||||
|
): BaseAction | undefined {
|
||||||
|
const storedFunction = actionMap[name];
|
||||||
|
if (storedFunction === undefined) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
const constructor = (storedFunction as unknown) as typeof BaseAction;
|
||||||
|
return new constructor(scheduler, villageFactory);
|
||||||
|
}
|
@ -1,14 +1,14 @@
|
|||||||
import { ActionDefinition, TaskController } from './TaskController';
|
import { ActionDefinition, BaseTask } from './BaseTask';
|
||||||
import { GoToPageAction } from '../Action/GoToPageAction';
|
import { GoToPageAction } from '../Action/GoToPageAction';
|
||||||
import { CompleteTaskAction } from '../Action/CompleteTaskAction';
|
import { CompleteTaskAction } from '../Action/CompleteTaskAction';
|
||||||
import { BalanceHeroResourcesAction } from '../Action/BalanceHeroResourcesAction';
|
import { BalanceHeroResourcesAction } from '../Action/BalanceHeroResourcesAction';
|
||||||
import { GoToHeroVillageAction } from '../Action/GoToHeroVillageAction';
|
import { GoToHeroVillageAction } from '../Action/GoToHeroVillageAction';
|
||||||
import { Task } from '../Queue/TaskProvider';
|
import { Task } from '../../Queue/TaskProvider';
|
||||||
import { path } from '../Helpers/Path';
|
import { path } from '../../Helpers/Path';
|
||||||
import { registerTask } from './TaskMap';
|
import { registerTask } from '../TaskMap';
|
||||||
|
|
||||||
@registerTask()
|
@registerTask()
|
||||||
export class BalanceHeroResourcesTask extends TaskController {
|
export class BalanceHeroResourcesTask extends BaseTask {
|
||||||
defineActions(task: Task): Array<ActionDefinition> {
|
defineActions(task: Task): Array<ActionDefinition> {
|
||||||
return [
|
return [
|
||||||
{
|
{
|
@ -1,16 +1,16 @@
|
|||||||
import { Scheduler } from '../Scheduler';
|
import { Scheduler } from '../../Scheduler';
|
||||||
import { CompleteTaskAction } from '../Action/CompleteTaskAction';
|
import { CompleteTaskAction } from '../Action/CompleteTaskAction';
|
||||||
import { Action } from '../Queue/ActionQueue';
|
import { Action } from '../../Queue/ActionQueue';
|
||||||
import { Args } from '../Queue/Args';
|
import { Args } from '../../Queue/Args';
|
||||||
import { Task } from '../Queue/TaskProvider';
|
import { Task } from '../../Queue/TaskProvider';
|
||||||
import { VillageFactory } from '../Village/VillageFactory';
|
import { VillageFactory } from '../../Village/VillageFactory';
|
||||||
|
|
||||||
export interface ActionDefinition {
|
export interface ActionDefinition {
|
||||||
name: string;
|
name: string;
|
||||||
args?: Args;
|
args?: Args;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class TaskController {
|
export class BaseTask {
|
||||||
protected readonly scheduler: Scheduler;
|
protected readonly scheduler: Scheduler;
|
||||||
protected readonly factory: VillageFactory;
|
protected readonly factory: VillageFactory;
|
||||||
|
|
@ -1,15 +1,15 @@
|
|||||||
import { BuildBuildingAction } from '../Action/BuildBuildingAction';
|
import { BuildBuildingAction } from '../Action/BuildBuildingAction';
|
||||||
import { GoToPageAction } from '../Action/GoToPageAction';
|
import { GoToPageAction } from '../Action/GoToPageAction';
|
||||||
import { ActionDefinition, TaskController } from './TaskController';
|
import { ActionDefinition, BaseTask } from './BaseTask';
|
||||||
import { Task } from '../Queue/TaskProvider';
|
import { Task } from '../../Queue/TaskProvider';
|
||||||
import { path } from '../Helpers/Path';
|
import { path } from '../../Helpers/Path';
|
||||||
import { registerTask } from './TaskMap';
|
import { registerTask } from '../TaskMap';
|
||||||
import { taskError } from '../Errors';
|
import { taskError } from '../../Errors';
|
||||||
import { goToResourceViewPage } from './ActionBundles';
|
import { goToResourceViewPage } from '../ActionBundles';
|
||||||
import { ProductionQueue } from '../Core/ProductionQueue';
|
import { ProductionQueue } from '../../Core/ProductionQueue';
|
||||||
|
|
||||||
@registerTask({ queue: ProductionQueue.Building })
|
@registerTask({ queue: ProductionQueue.Building })
|
||||||
export class BuildBuildingTask extends TaskController {
|
export class BuildBuildingTask extends BaseTask {
|
||||||
defineActions(task: Task): Array<ActionDefinition> {
|
defineActions(task: Task): Array<ActionDefinition> {
|
||||||
const args = task.args;
|
const args = task.args;
|
||||||
const villageId = args.villageId || taskError('No village id');
|
const villageId = args.villageId || taskError('No village id');
|
@ -1,13 +1,13 @@
|
|||||||
import { ActionDefinition, TaskController } from './TaskController';
|
import { ActionDefinition, BaseTask } from './BaseTask';
|
||||||
import { GoToPageAction } from '../Action/GoToPageAction';
|
import { GoToPageAction } from '../Action/GoToPageAction';
|
||||||
import { Task } from '../Queue/TaskProvider';
|
import { Task } from '../../Queue/TaskProvider';
|
||||||
import { path } from '../Helpers/Path';
|
import { path } from '../../Helpers/Path';
|
||||||
import { CelebrationAction } from '../Action/CelebrationAction';
|
import { CelebrationAction } from '../Action/CelebrationAction';
|
||||||
import { registerTask } from './TaskMap';
|
import { registerTask } from '../TaskMap';
|
||||||
import { ProductionQueue } from '../Core/ProductionQueue';
|
import { ProductionQueue } from '../../Core/ProductionQueue';
|
||||||
|
|
||||||
@registerTask({ queue: ProductionQueue.Celebration })
|
@registerTask({ queue: ProductionQueue.Celebration })
|
||||||
export class CelebrationTask extends TaskController {
|
export class CelebrationTask extends BaseTask {
|
||||||
defineActions(task: Task): Array<ActionDefinition> {
|
defineActions(task: Task): Array<ActionDefinition> {
|
||||||
const args = task.args;
|
const args = task.args;
|
||||||
|
|
@ -1,13 +1,13 @@
|
|||||||
import { ActionDefinition, TaskController } from './TaskController';
|
import { ActionDefinition, BaseTask } from './BaseTask';
|
||||||
import { GoToPageAction } from '../Action/GoToPageAction';
|
import { GoToPageAction } from '../Action/GoToPageAction';
|
||||||
import { Task } from '../Queue/TaskProvider';
|
import { Task } from '../../Queue/TaskProvider';
|
||||||
import { ForgeImprovementAction } from '../Action/ForgeImprovementAction';
|
import { ForgeImprovementAction } from '../Action/ForgeImprovementAction';
|
||||||
import { path } from '../Helpers/Path';
|
import { path } from '../../Helpers/Path';
|
||||||
import { registerTask } from './TaskMap';
|
import { registerTask } from '../TaskMap';
|
||||||
import { ProductionQueue } from '../Core/ProductionQueue';
|
import { ProductionQueue } from '../../Core/ProductionQueue';
|
||||||
|
|
||||||
@registerTask({ queue: ProductionQueue.UpgradeUnit })
|
@registerTask({ queue: ProductionQueue.UpgradeUnit })
|
||||||
export class ForgeImprovementTask extends TaskController {
|
export class ForgeImprovementTask extends BaseTask {
|
||||||
defineActions(task: Task): Array<ActionDefinition> {
|
defineActions(task: Task): Array<ActionDefinition> {
|
||||||
const args = task.args;
|
const args = task.args;
|
||||||
|
|
12
src/Handler/Task/GrabVillageStateTask.ts
Normal file
12
src/Handler/Task/GrabVillageStateTask.ts
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
import { BaseTask, ActionDefinition } from './BaseTask';
|
||||||
|
import { scanAllVillagesBundle } from '../ActionBundles';
|
||||||
|
import { Task } from '../../Queue/TaskProvider';
|
||||||
|
import { registerTask } from '../TaskMap';
|
||||||
|
|
||||||
|
@registerTask()
|
||||||
|
export class GrabVillageStateTask extends BaseTask {
|
||||||
|
defineActions(task: Task): Array<ActionDefinition> {
|
||||||
|
const villages = this.factory.getAllVillages();
|
||||||
|
return scanAllVillagesBundle(villages);
|
||||||
|
}
|
||||||
|
}
|
15
src/Handler/Task/ResourcesToLevelTask.ts
Normal file
15
src/Handler/Task/ResourcesToLevelTask.ts
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
import { BaseTask, ActionDefinition } from './BaseTask';
|
||||||
|
import { UpgradeResourceToLevelAction } from '../Action/UpgradeResourceToLevelAction';
|
||||||
|
import { Task } from '../../Queue/TaskProvider';
|
||||||
|
import { registerTask } from '../TaskMap';
|
||||||
|
import { goToResourceViewPage } from '../ActionBundles';
|
||||||
|
import { taskError } from '../../Errors';
|
||||||
|
|
||||||
|
@registerTask()
|
||||||
|
export class ResourcesToLevelTask extends BaseTask {
|
||||||
|
defineActions(task: Task): Array<ActionDefinition> {
|
||||||
|
const villageId = task.args.villageId || taskError('No village id');
|
||||||
|
|
||||||
|
return [goToResourceViewPage(villageId), { name: UpgradeResourceToLevelAction.name }];
|
||||||
|
}
|
||||||
|
}
|
10
src/Handler/Task/RunVillageProductionTask.ts
Normal file
10
src/Handler/Task/RunVillageProductionTask.ts
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
import { BaseTask, ActionDefinition } from './BaseTask';
|
||||||
|
import { Task } from '../../Queue/TaskProvider';
|
||||||
|
import { registerTask } from '../TaskMap';
|
||||||
|
|
||||||
|
@registerTask()
|
||||||
|
export class RunVillageProductionTask extends BaseTask {
|
||||||
|
defineActions(task: Task): Array<ActionDefinition> {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
}
|
@ -1,13 +1,13 @@
|
|||||||
import { ActionDefinition, TaskController } from './TaskController';
|
import { ActionDefinition, BaseTask } from './BaseTask';
|
||||||
import { GoToPageAction } from '../Action/GoToPageAction';
|
import { GoToPageAction } from '../Action/GoToPageAction';
|
||||||
import { SendOnAdventureAction } from '../Action/SendOnAdventureAction';
|
import { SendOnAdventureAction } from '../Action/SendOnAdventureAction';
|
||||||
import { ClickButtonAction } from '../Action/ClickButtonAction';
|
import { ClickButtonAction } from '../Action/ClickButtonAction';
|
||||||
import { Task } from '../Queue/TaskProvider';
|
import { Task } from '../../Queue/TaskProvider';
|
||||||
import { path } from '../Helpers/Path';
|
import { path } from '../../Helpers/Path';
|
||||||
import { registerTask } from './TaskMap';
|
import { registerTask } from '../TaskMap';
|
||||||
|
|
||||||
@registerTask()
|
@registerTask()
|
||||||
export class SendOnAdventureTask extends TaskController {
|
export class SendOnAdventureTask extends BaseTask {
|
||||||
defineActions(task: Task): Array<ActionDefinition> {
|
defineActions(task: Task): Array<ActionDefinition> {
|
||||||
return [
|
return [
|
||||||
{
|
{
|
@ -1,13 +1,13 @@
|
|||||||
import { TaskController, ActionDefinition } from './TaskController';
|
import { BaseTask, ActionDefinition } from './BaseTask';
|
||||||
import { SendResourcesAction } from '../Action/SendResourcesAction';
|
import { SendResourcesAction } from '../Action/SendResourcesAction';
|
||||||
import { ClickButtonAction } from '../Action/ClickButtonAction';
|
import { ClickButtonAction } from '../Action/ClickButtonAction';
|
||||||
import { goToMarketSendResourcesPage, goToResourceViewPage } from './ActionBundles';
|
import { goToMarketSendResourcesPage, goToResourceViewPage } from '../ActionBundles';
|
||||||
import { Task } from '../Queue/TaskProvider';
|
import { Task } from '../../Queue/TaskProvider';
|
||||||
import { registerTask } from './TaskMap';
|
import { registerTask } from '../TaskMap';
|
||||||
import { FindSendResourcesPath } from '../Action/FindSendResourcesPath';
|
import { FindSendResourcesPathAction } from '../Action/FindSendResourcesPathAction';
|
||||||
|
|
||||||
@registerTask()
|
@registerTask()
|
||||||
export class SendResourcesTask extends TaskController {
|
export class SendResourcesTask extends BaseTask {
|
||||||
defineActions(task: Task): Array<ActionDefinition> {
|
defineActions(task: Task): Array<ActionDefinition> {
|
||||||
const actions: Array<ActionDefinition> = [];
|
const actions: Array<ActionDefinition> = [];
|
||||||
|
|
||||||
@ -17,7 +17,7 @@ export class SendResourcesTask extends TaskController {
|
|||||||
actions.push(goToMarketSendResourcesPage(village.id));
|
actions.push(goToMarketSendResourcesPage(village.id));
|
||||||
}
|
}
|
||||||
|
|
||||||
actions.push({ name: FindSendResourcesPath.name });
|
actions.push({ name: FindSendResourcesPathAction.name });
|
||||||
actions.push({ name: SendResourcesAction.name });
|
actions.push({ name: SendResourcesAction.name });
|
||||||
actions.push({
|
actions.push({
|
||||||
name: ClickButtonAction.name,
|
name: ClickButtonAction.name,
|
@ -1,13 +1,13 @@
|
|||||||
import { ActionDefinition, TaskController } from './TaskController';
|
import { ActionDefinition, BaseTask } from './BaseTask';
|
||||||
import { GoToPageAction } from '../Action/GoToPageAction';
|
import { GoToPageAction } from '../Action/GoToPageAction';
|
||||||
import { TrainTrooperAction } from '../Action/TrainTrooperAction';
|
import { TrainTrooperAction } from '../Action/TrainTrooperAction';
|
||||||
import { Task } from '../Queue/TaskProvider';
|
import { Task } from '../../Queue/TaskProvider';
|
||||||
import { path } from '../Helpers/Path';
|
import { path } from '../../Helpers/Path';
|
||||||
import { registerTask } from './TaskMap';
|
import { registerTask } from '../TaskMap';
|
||||||
import { ProductionQueue } from '../Core/ProductionQueue';
|
import { ProductionQueue } from '../../Core/ProductionQueue';
|
||||||
|
|
||||||
@registerTask({ queue: ProductionQueue.TrainUnit })
|
@registerTask({ queue: ProductionQueue.TrainUnit })
|
||||||
export class TrainTroopTask extends TaskController {
|
export class TrainTroopTask extends BaseTask {
|
||||||
defineActions(task: Task): Array<ActionDefinition> {
|
defineActions(task: Task): Array<ActionDefinition> {
|
||||||
const args = task.args;
|
const args = task.args;
|
||||||
|
|
@ -1,13 +1,13 @@
|
|||||||
import { ActionDefinition, TaskController } from './TaskController';
|
import { ActionDefinition, BaseTask } from './BaseTask';
|
||||||
import { GoToPageAction } from '../Action/GoToPageAction';
|
import { GoToPageAction } from '../Action/GoToPageAction';
|
||||||
import { UpgradeBuildingTask } from './UpgradeBuildingTask';
|
import { UpgradeBuildingTask } from './UpgradeBuildingTask';
|
||||||
import { ImmutableTaskList, Task } from '../Queue/TaskProvider';
|
import { ImmutableTaskList, Task } from '../../Queue/TaskProvider';
|
||||||
import { ForgeImprovementTask } from './ForgeImprovementTask';
|
import { ForgeImprovementTask } from './ForgeImprovementTask';
|
||||||
import { path, PathList, uniqPaths } from '../Helpers/Path';
|
import { path, PathList, uniqPaths } from '../../Helpers/Path';
|
||||||
import { registerTask } from './TaskMap';
|
import { registerTask } from '../TaskMap';
|
||||||
|
|
||||||
@registerTask()
|
@registerTask()
|
||||||
export class UpdateResourceContracts extends TaskController {
|
export class UpdateResourceContractsTask extends BaseTask {
|
||||||
defineActions(task: Task): Array<ActionDefinition> {
|
defineActions(task: Task): Array<ActionDefinition> {
|
||||||
const villages = this.factory.getAllVillages();
|
const villages = this.factory.getAllVillages();
|
||||||
|
|
@ -1,15 +1,15 @@
|
|||||||
import { UpgradeBuildingAction } from '../Action/UpgradeBuildingAction';
|
import { UpgradeBuildingAction } from '../Action/UpgradeBuildingAction';
|
||||||
import { TaskController, ActionDefinition } from './TaskController';
|
import { BaseTask, ActionDefinition } from './BaseTask';
|
||||||
import { GoToPageAction } from '../Action/GoToPageAction';
|
import { GoToPageAction } from '../Action/GoToPageAction';
|
||||||
import { Task } from '../Queue/TaskProvider';
|
import { Task } from '../../Queue/TaskProvider';
|
||||||
import { path } from '../Helpers/Path';
|
import { path } from '../../Helpers/Path';
|
||||||
import { registerTask } from './TaskMap';
|
import { registerTask } from '../TaskMap';
|
||||||
import { goToResourceViewPage } from './ActionBundles';
|
import { goToResourceViewPage } from '../ActionBundles';
|
||||||
import { taskError } from '../Errors';
|
import { taskError } from '../../Errors';
|
||||||
import { ProductionQueue } from '../Core/ProductionQueue';
|
import { ProductionQueue } from '../../Core/ProductionQueue';
|
||||||
|
|
||||||
@registerTask({ queue: ProductionQueue.Building })
|
@registerTask({ queue: ProductionQueue.Building })
|
||||||
export class UpgradeBuildingTask extends TaskController {
|
export class UpgradeBuildingTask extends BaseTask {
|
||||||
defineActions(task: Task): Array<ActionDefinition> {
|
defineActions(task: Task): Array<ActionDefinition> {
|
||||||
const args = task.args;
|
const args = task.args;
|
||||||
const villageId = args.villageId || taskError('No village id');
|
const villageId = args.villageId || taskError('No village id');
|
@ -1,5 +1,5 @@
|
|||||||
import { Scheduler } from '../Scheduler';
|
import { Scheduler } from '../Scheduler';
|
||||||
import { TaskController } from './TaskController';
|
import { BaseTask } from './Task/BaseTask';
|
||||||
import {
|
import {
|
||||||
OrderedProductionQueues,
|
OrderedProductionQueues,
|
||||||
ProductionQueue,
|
ProductionQueue,
|
||||||
@ -43,12 +43,12 @@ export function createTaskHandler(
|
|||||||
name: string,
|
name: string,
|
||||||
scheduler: Scheduler,
|
scheduler: Scheduler,
|
||||||
factory: VillageFactory
|
factory: VillageFactory
|
||||||
): TaskController | undefined {
|
): BaseTask | undefined {
|
||||||
const taskDescription = taskMap[name];
|
const taskDescription = taskMap[name];
|
||||||
if (taskDescription === undefined) {
|
if (taskDescription === undefined) {
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
const constructor = (taskDescription.ctor as unknown) as typeof TaskController;
|
const constructor = (taskDescription.ctor as unknown) as typeof BaseTask;
|
||||||
return new constructor(scheduler, factory);
|
return new constructor(scheduler, factory);
|
||||||
}
|
}
|
||||||
|
|
@ -1,13 +1,13 @@
|
|||||||
import { UpgradeBuildingTask } from '../Task/UpgradeBuildingTask';
|
import { UpgradeBuildingTask } from '../Handler/Task/UpgradeBuildingTask';
|
||||||
import { Scheduler } from '../Scheduler';
|
import { Scheduler } from '../Scheduler';
|
||||||
import { TrainTroopTask } from '../Task/TrainTroopTask';
|
import { TrainTroopTask } from '../Handler/Task/TrainTroopTask';
|
||||||
import { grabActiveVillageId, grabVillageList } from './VillageBlock';
|
import { grabActiveVillageId, grabVillageList } from './VillageBlock';
|
||||||
import { ConsoleLogger, Logger } from '../Logger';
|
import { ConsoleLogger, Logger } from '../Logger';
|
||||||
import { createBuildButton, createUpgradeButton } from './BuildingPage/BuildingPage';
|
import { createBuildButton, createUpgradeButton } from './BuildingPage/BuildingPage';
|
||||||
import { BuildBuildingTask } from '../Task/BuildBuildingTask';
|
import { BuildBuildingTask } from '../Handler/Task/BuildBuildingTask';
|
||||||
import { Resources } from '../Core/Resources';
|
import { Resources } from '../Core/Resources';
|
||||||
import { Coordinates } from '../Core/Village';
|
import { Coordinates } from '../Core/Village';
|
||||||
import { SendResourcesTask } from '../Task/SendResourcesTask';
|
import { SendResourcesTask } from '../Handler/Task/SendResourcesTask';
|
||||||
import { EMBASSY_ID, HORSE_STABLE_ID, PALACE_ID, QUARTERS_ID } from '../Core/Buildings';
|
import { EMBASSY_ID, HORSE_STABLE_ID, PALACE_ID, QUARTERS_ID } from '../Core/Buildings';
|
||||||
import {
|
import {
|
||||||
BuildingPageAttributes,
|
BuildingPageAttributes,
|
||||||
@ -18,9 +18,9 @@ import {
|
|||||||
import { createTrainTroopButtons } from './BuildingPage/TrooperPage';
|
import { createTrainTroopButtons } from './BuildingPage/TrooperPage';
|
||||||
import { createSendResourcesButton } from './BuildingPage/MarketPage';
|
import { createSendResourcesButton } from './BuildingPage/MarketPage';
|
||||||
import { createResearchButtons } from './BuildingPage/ForgePage';
|
import { createResearchButtons } from './BuildingPage/ForgePage';
|
||||||
import { ForgeImprovementTask } from '../Task/ForgeImprovementTask';
|
import { ForgeImprovementTask } from '../Handler/Task/ForgeImprovementTask';
|
||||||
import { createCelebrationButtons } from './BuildingPage/GuildHallPage';
|
import { createCelebrationButtons } from './BuildingPage/GuildHallPage';
|
||||||
import { CelebrationTask } from '../Task/CelebrationTask';
|
import { CelebrationTask } from '../Handler/Task/CelebrationTask';
|
||||||
import { VillageController } from '../Village/VillageController';
|
import { VillageController } from '../Village/VillageController';
|
||||||
import { notify } from '../Helpers/Browser';
|
import { notify } from '../Helpers/Browser';
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import { Args } from './Args';
|
import { Args } from './Args';
|
||||||
import { ResourcesInterface } from '../Core/Resources';
|
import { ResourcesInterface } from '../Core/Resources';
|
||||||
import { ProductionQueue } from '../Core/ProductionQueue';
|
import { ProductionQueue } from '../Core/ProductionQueue';
|
||||||
import { getProductionQueue } from '../Task/TaskMap';
|
import { getProductionQueue } from '../Handler/TaskMap';
|
||||||
import { uniqId } from '../Helpers/Identity';
|
import { uniqId } from '../Helpers/Identity';
|
||||||
|
|
||||||
export type TaskId = string;
|
export type TaskId = string;
|
||||||
|
@ -1,16 +1,16 @@
|
|||||||
import { TaskQueue } from './Queue/TaskQueue';
|
import { TaskQueue } from './Queue/TaskQueue';
|
||||||
import { BalanceHeroResourcesTask } from './Task/BalanceHeroResourcesTask';
|
import { BalanceHeroResourcesTask } from './Handler/Task/BalanceHeroResourcesTask';
|
||||||
import { Logger } from './Logger';
|
import { Logger } from './Logger';
|
||||||
import { GrabVillageState } from './Task/GrabVillageState';
|
import { GrabVillageStateTask } from './Handler/Task/GrabVillageStateTask';
|
||||||
import { Action, ActionQueue, ImmutableActionList } from './Queue/ActionQueue';
|
import { Action, ActionQueue, ImmutableActionList } from './Queue/ActionQueue';
|
||||||
import { UpdateResourceContracts } from './Task/UpdateResourceContracts';
|
import { UpdateResourceContractsTask } from './Handler/Task/UpdateResourceContractsTask';
|
||||||
import { SendResourcesTask } from './Task/SendResourcesTask';
|
import { SendResourcesTask } from './Handler/Task/SendResourcesTask';
|
||||||
import { Args } from './Queue/Args';
|
import { Args } from './Queue/Args';
|
||||||
import { ImmutableTaskList, Task, TaskId, uniqTaskId, withTime } from './Queue/TaskProvider';
|
import { ImmutableTaskList, Task, TaskId, uniqTaskId, withTime } from './Queue/TaskProvider';
|
||||||
import { VillageRepositoryInterface } from './Village/VillageRepository';
|
import { VillageRepositoryInterface } from './Village/VillageRepository';
|
||||||
import { VillageFactory } from './Village/VillageFactory';
|
import { VillageFactory } from './Village/VillageFactory';
|
||||||
import { RunVillageProductionTask } from './Task/RunVillageProductionTask';
|
import { RunVillageProductionTask } from './Handler/Task/RunVillageProductionTask';
|
||||||
import { isProductionTask } from './Task/TaskMap';
|
import { isProductionTask } from './Handler/TaskMap';
|
||||||
import { around } from './Helpers/Random';
|
import { around } from './Helpers/Random';
|
||||||
import { timestamp } from './Helpers/Time';
|
import { timestamp } from './Helpers/Time';
|
||||||
|
|
||||||
@ -39,8 +39,8 @@ export class Scheduler {
|
|||||||
this.villageControllerFactory = villageControllerFactory;
|
this.villageControllerFactory = villageControllerFactory;
|
||||||
this.logger = logger;
|
this.logger = logger;
|
||||||
|
|
||||||
// this.taskQueue.push(GrabVillageState.name, {}, timestamp());
|
// this.taskQueue.push(GrabVillageStateTask.name, {}, timestamp());
|
||||||
// this.taskQueue.push(UpdateResourceContracts.name, {}, timestamp());
|
// this.taskQueue.push(UpdateResourceContractsTask.name, {}, timestamp());
|
||||||
// this.taskQueue.push(BalanceHeroResourcesTask.name, {}, timestamp());
|
// this.taskQueue.push(BalanceHeroResourcesTask.name, {}, timestamp());
|
||||||
|
|
||||||
const villages = this.villageRepository.all();
|
const villages = this.villageRepository.all();
|
||||||
@ -50,10 +50,10 @@ export class Scheduler {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
this.createUniqTaskTimer(10 * 60, GrabVillageState.name);
|
this.createUniqTaskTimer(10 * 60, GrabVillageStateTask.name);
|
||||||
this.createUniqTaskTimer(10 * 60, SendResourcesTask.name);
|
this.createUniqTaskTimer(10 * 60, SendResourcesTask.name);
|
||||||
this.createUniqTaskTimer(10 * 60, BalanceHeroResourcesTask.name);
|
this.createUniqTaskTimer(10 * 60, BalanceHeroResourcesTask.name);
|
||||||
this.createUniqTaskTimer(20 * 60, UpdateResourceContracts.name);
|
this.createUniqTaskTimer(20 * 60, UpdateResourceContractsTask.name);
|
||||||
// this.createUniqTaskTimer(60 * 60, SendOnAdventureTask.name);
|
// this.createUniqTaskTimer(60 * 60, SendOnAdventureTask.name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,12 +0,0 @@
|
|||||||
import { TaskController, ActionDefinition } from './TaskController';
|
|
||||||
import { scanAllVillagesBundle } from './ActionBundles';
|
|
||||||
import { Task } from '../Queue/TaskProvider';
|
|
||||||
import { registerTask } from './TaskMap';
|
|
||||||
|
|
||||||
@registerTask()
|
|
||||||
export class GrabVillageState extends TaskController {
|
|
||||||
defineActions(task: Task): Array<ActionDefinition> {
|
|
||||||
const villages = this.factory.getAllVillages();
|
|
||||||
return scanAllVillagesBundle(villages);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,15 +0,0 @@
|
|||||||
import { TaskController, ActionDefinition } from './TaskController';
|
|
||||||
import { UpgradeResourceToLevel } from '../Action/UpgradeResourceToLevel';
|
|
||||||
import { Task } from '../Queue/TaskProvider';
|
|
||||||
import { registerTask } from './TaskMap';
|
|
||||||
import { goToResourceViewPage } from './ActionBundles';
|
|
||||||
import { taskError } from '../Errors';
|
|
||||||
|
|
||||||
@registerTask()
|
|
||||||
export class ResourcesToLevel extends TaskController {
|
|
||||||
defineActions(task: Task): Array<ActionDefinition> {
|
|
||||||
const villageId = task.args.villageId || taskError('No village id');
|
|
||||||
|
|
||||||
return [goToResourceViewPage(villageId), { name: UpgradeResourceToLevel.name }];
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,10 +0,0 @@
|
|||||||
import { TaskController, ActionDefinition } from './TaskController';
|
|
||||||
import { Task } from '../Queue/TaskProvider';
|
|
||||||
import { registerTask } from './TaskMap';
|
|
||||||
|
|
||||||
@registerTask()
|
|
||||||
export class RunVillageProductionTask extends TaskController {
|
|
||||||
defineActions(task: Task): Array<ActionDefinition> {
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
}
|
|
@ -7,7 +7,7 @@ import { MerchantsInfo } from '../Core/Market';
|
|||||||
import { VillageStorage } from '../Storage/VillageStorage';
|
import { VillageStorage } from '../Storage/VillageStorage';
|
||||||
import { ReceiveResourcesMode } from '../Core/Village';
|
import { ReceiveResourcesMode } from '../Core/Village';
|
||||||
import { ResourceType } from '../Core/ResourceType';
|
import { ResourceType } from '../Core/ResourceType';
|
||||||
import { UpgradeBuildingTask } from '../Task/UpgradeBuildingTask';
|
import { UpgradeBuildingTask } from '../Handler/Task/UpgradeBuildingTask';
|
||||||
import { GARNER_ID, WAREHOUSE_ID } from '../Core/Buildings';
|
import { GARNER_ID, WAREHOUSE_ID } from '../Core/Buildings';
|
||||||
import { first } from '../Helpers/Collection';
|
import { first } from '../Helpers/Collection';
|
||||||
|
|
||||||
|
@ -7,7 +7,7 @@ import { VillageNotFound } from '../Errors';
|
|||||||
import { OrderedProductionQueues, ProductionQueue } from '../Core/ProductionQueue';
|
import { OrderedProductionQueues, ProductionQueue } from '../Core/ProductionQueue';
|
||||||
import { isInQueue, TaskCore, TaskId } from '../Queue/TaskProvider';
|
import { isInQueue, TaskCore, TaskId } from '../Queue/TaskProvider';
|
||||||
import { VillageTaskCollection } from './VillageTaskCollection';
|
import { VillageTaskCollection } from './VillageTaskCollection';
|
||||||
import { TrainTroopTask } from '../Task/TrainTroopTask';
|
import { TrainTroopTask } from '../Handler/Task/TrainTroopTask';
|
||||||
import { Args } from '../Queue/Args';
|
import { Args } from '../Queue/Args';
|
||||||
import { timestamp } from '../Helpers/Time';
|
import { timestamp } from '../Helpers/Time';
|
||||||
|
|
||||||
|
@ -3,9 +3,9 @@ import { Task, TaskId, uniqTaskId, withResources, withTime } from '../Queue/Task
|
|||||||
import { Args } from '../Queue/Args';
|
import { Args } from '../Queue/Args';
|
||||||
import { Resources } from '../Core/Resources';
|
import { Resources } from '../Core/Resources';
|
||||||
import { ContractAttributes, ContractType } from '../Core/Contract';
|
import { ContractAttributes, ContractType } from '../Core/Contract';
|
||||||
import { UpgradeBuildingTask } from '../Task/UpgradeBuildingTask';
|
import { UpgradeBuildingTask } from '../Handler/Task/UpgradeBuildingTask';
|
||||||
import { ForgeImprovementTask } from '../Task/ForgeImprovementTask';
|
import { ForgeImprovementTask } from '../Handler/Task/ForgeImprovementTask';
|
||||||
import { isProductionTask } from '../Task/TaskMap';
|
import { isProductionTask } from '../Handler/TaskMap';
|
||||||
import { timestamp } from '../Helpers/Time';
|
import { timestamp } from '../Helpers/Time';
|
||||||
|
|
||||||
export class VillageTaskCollection {
|
export class VillageTaskCollection {
|
||||||
|
Loading…
Reference in New Issue
Block a user