Refactoring
This commit is contained in:
parent
f5077005d9
commit
0b159d2397
@ -1,9 +1,9 @@
|
|||||||
import { Args } from '../Command';
|
|
||||||
import { Task } from '../Queue/TaskQueue';
|
import { Task } from '../Queue/TaskQueue';
|
||||||
import { Scheduler } from '../Scheduler';
|
import { Scheduler } from '../Scheduler';
|
||||||
import { ActionError, TryLaterError } from '../Errors';
|
import { ActionError, TryLaterError } from '../Errors';
|
||||||
import { grabActiveVillageId } from '../Page/VillageBlock';
|
import { grabActiveVillageId } from '../Page/VillageBlock';
|
||||||
import { aroundMinutes } from '../utils';
|
import { aroundMinutes } from '../utils';
|
||||||
|
import { Args } from '../Args';
|
||||||
|
|
||||||
const actionMap: { [name: string]: Function | undefined } = {};
|
const actionMap: { [name: string]: Function | undefined } = {};
|
||||||
|
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
import { ActionController, registerAction } from './ActionController';
|
import { ActionController, registerAction } from './ActionController';
|
||||||
import { Args } from '../Command';
|
|
||||||
import { Task } from '../Queue/TaskQueue';
|
import { Task } from '../Queue/TaskQueue';
|
||||||
import { grabVillageResources, grabVillageResourceStorage } from '../Page/ResourcesBlock';
|
import { grabVillageResources, grabVillageResourceStorage } from '../Page/ResourcesBlock';
|
||||||
import { changeHeroResource, grabCurrentHeroResource } from '../Page/HeroPage';
|
import { changeHeroResource, grabCurrentHeroResource } from '../Page/HeroPage';
|
||||||
@ -7,6 +6,7 @@ import { grabActiveVillageId } from '../Page/VillageBlock';
|
|||||||
import { HeroState } from '../State/HeroState';
|
import { HeroState } from '../State/HeroState';
|
||||||
import { calcHeroResource } from '../Core/HeroBalance';
|
import { calcHeroResource } from '../Core/HeroBalance';
|
||||||
import { HeroAllResources } from '../Core/Hero';
|
import { HeroAllResources } from '../Core/Hero';
|
||||||
|
import { Args } from '../Args';
|
||||||
|
|
||||||
@registerAction
|
@registerAction
|
||||||
export class BalanceHeroResourcesAction extends ActionController {
|
export class BalanceHeroResourcesAction extends ActionController {
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
import { ActionController, registerAction } from './ActionController';
|
import { ActionController, registerAction } from './ActionController';
|
||||||
import { Args } from '../Command';
|
|
||||||
import { ActionError, GrabError, TryLaterError } from '../Errors';
|
import { ActionError, GrabError, TryLaterError } from '../Errors';
|
||||||
import { Task } from '../Queue/TaskQueue';
|
import { Task } from '../Queue/TaskQueue';
|
||||||
import { clickBuildButton } from '../Page/BuildingPage';
|
import { clickBuildButton } from '../Page/BuildingPage';
|
||||||
import { aroundMinutes } from '../utils';
|
import { aroundMinutes } from '../utils';
|
||||||
|
import { Args } from '../Args';
|
||||||
|
|
||||||
@registerAction
|
@registerAction
|
||||||
export class BuildBuildingAction extends ActionController {
|
export class BuildBuildingAction extends ActionController {
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
import { ActionController, registerAction } from './ActionController';
|
import { ActionController, registerAction } from './ActionController';
|
||||||
import { Args } from '../Command';
|
|
||||||
import { Task } from '../Queue/TaskQueue';
|
import { Task } from '../Queue/TaskQueue';
|
||||||
import { GrabError, TryLaterError } from '../Errors';
|
import { GrabError, TryLaterError } from '../Errors';
|
||||||
import { grabBuildingQueueInfo } from '../Page/VillageBlock';
|
import { grabBuildingQueueInfo } from '../Page/VillageBlock';
|
||||||
import { BuildingQueueInfo } from '../Game';
|
import { BuildingQueueInfo } from '../Game';
|
||||||
|
import { Args } from '../Args';
|
||||||
|
|
||||||
@registerAction
|
@registerAction
|
||||||
export class CheckBuildingRemainingTimeAction extends ActionController {
|
export class CheckBuildingRemainingTimeAction extends ActionController {
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import { ActionController, registerAction } from './ActionController';
|
import { ActionController, registerAction } from './ActionController';
|
||||||
import { Args } from '../Command';
|
|
||||||
import { Task } from '../Queue/TaskQueue';
|
import { Task } from '../Queue/TaskQueue';
|
||||||
import { AbortTaskError } from '../Errors';
|
import { AbortTaskError } from '../Errors';
|
||||||
|
import { Args } from '../Args';
|
||||||
|
|
||||||
@registerAction
|
@registerAction
|
||||||
export class ClickButtonAction extends ActionController {
|
export class ClickButtonAction extends ActionController {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import { ActionController, registerAction } from './ActionController';
|
import { ActionController, registerAction } from './ActionController';
|
||||||
import { Args } from '../Command';
|
|
||||||
import { Task } from '../Queue/TaskQueue';
|
import { Task } from '../Queue/TaskQueue';
|
||||||
|
import { Args } from '../Args';
|
||||||
|
|
||||||
@registerAction
|
@registerAction
|
||||||
export class CompleteTaskAction extends ActionController {
|
export class CompleteTaskAction extends ActionController {
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
import { ActionController, registerAction } from './ActionController';
|
import { ActionController, registerAction } from './ActionController';
|
||||||
import { Args } from '../Command';
|
|
||||||
import { Task } from '../Queue/TaskQueue';
|
import { Task } from '../Queue/TaskQueue';
|
||||||
import { grabVillageList } from '../Page/VillageBlock';
|
import { grabVillageList } from '../Page/VillageBlock';
|
||||||
import { grabHeroVillage } from '../Page/HeroPage';
|
import { grabHeroVillage } from '../Page/HeroPage';
|
||||||
import { path } from '../utils';
|
import { path } from '../utils';
|
||||||
import { HeroState } from '../State/HeroState';
|
import { HeroState } from '../State/HeroState';
|
||||||
|
import { Args } from '../Args';
|
||||||
|
|
||||||
@registerAction
|
@registerAction
|
||||||
export class GoToHeroVillageAction extends ActionController {
|
export class GoToHeroVillageAction extends ActionController {
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import { ActionController, registerAction } from './ActionController';
|
import { ActionController, registerAction } from './ActionController';
|
||||||
import { Args } from '../Command';
|
|
||||||
import { Task } from '../Queue/TaskQueue';
|
import { Task } from '../Queue/TaskQueue';
|
||||||
import { AbortTaskError } from '../Errors';
|
import { AbortTaskError } from '../Errors';
|
||||||
|
import { Args } from '../Args';
|
||||||
|
|
||||||
@registerAction
|
@registerAction
|
||||||
export class GoToPageAction extends ActionController {
|
export class GoToPageAction extends ActionController {
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
import { ActionController, registerAction } from './ActionController';
|
import { ActionController, registerAction } from './ActionController';
|
||||||
import { Args } from '../Command';
|
|
||||||
import { Task } from '../Queue/TaskQueue';
|
import { Task } from '../Queue/TaskQueue';
|
||||||
import { trimPrefix } from '../utils';
|
import { trimPrefix } from '../utils';
|
||||||
import { AbortTaskError } from '../Errors';
|
import { AbortTaskError } from '../Errors';
|
||||||
|
import { Args } from '../Args';
|
||||||
|
|
||||||
const CONFIG = [
|
const CONFIG = [
|
||||||
{ level: 0, health: 60 },
|
{ level: 0, health: 60 },
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
import { ActionController, registerAction } from './ActionController';
|
import { ActionController, registerAction } from './ActionController';
|
||||||
import { Args } from '../Command';
|
|
||||||
import { AbortTaskError, ActionError, TryLaterError } from '../Errors';
|
import { AbortTaskError, ActionError, TryLaterError } from '../Errors';
|
||||||
import { Task } from '../Queue/TaskQueue';
|
import { Task } from '../Queue/TaskQueue';
|
||||||
import { Resources } from '../Core/Resources';
|
import { Resources } from '../Core/Resources';
|
||||||
@ -10,6 +9,7 @@ import { grabActiveVillageId, grabVillageList } from '../Page/VillageBlock';
|
|||||||
import { SendResourcesTask } from '../Task/SendResourcesTask';
|
import { SendResourcesTask } from '../Task/SendResourcesTask';
|
||||||
import { aroundMinutes, timestamp } from '../utils';
|
import { aroundMinutes, timestamp } from '../utils';
|
||||||
import { VillageState } from '../State/VillageState';
|
import { VillageState } from '../State/VillageState';
|
||||||
|
import { Args } from '../Args';
|
||||||
|
|
||||||
function err(msg): never {
|
function err(msg): never {
|
||||||
throw new ActionError(msg);
|
throw new ActionError(msg);
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
import { ActionController, registerAction } from './ActionController';
|
import { ActionController, registerAction } from './ActionController';
|
||||||
import { Args } from '../Command';
|
|
||||||
import { ActionError, TryLaterError } from '../Errors';
|
import { ActionError, TryLaterError } from '../Errors';
|
||||||
import { Task } from '../Queue/TaskQueue';
|
import { Task } from '../Queue/TaskQueue';
|
||||||
import { getNumber, toNumber } from '../utils';
|
import { getNumber, toNumber } from '../utils';
|
||||||
|
import { Args } from '../Args';
|
||||||
|
|
||||||
@registerAction
|
@registerAction
|
||||||
export class TrainTrooperAction extends ActionController {
|
export class TrainTrooperAction extends ActionController {
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import { ActionController, registerAction } from './ActionController';
|
import { ActionController, registerAction } from './ActionController';
|
||||||
import { Args } from '../Command';
|
|
||||||
import { Task } from '../Queue/TaskQueue';
|
import { Task } from '../Queue/TaskQueue';
|
||||||
import { grabContractResources } from '../Page/BuildingPage';
|
import { grabContractResources } from '../Page/BuildingPage';
|
||||||
|
import { Args } from '../Args';
|
||||||
|
|
||||||
@registerAction
|
@registerAction
|
||||||
export class UpdateBuildingTaskResourcesAction extends ActionController {
|
export class UpdateBuildingTaskResourcesAction extends ActionController {
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
import { ActionController, registerAction } from './ActionController';
|
import { ActionController, registerAction } from './ActionController';
|
||||||
import { Args } from '../Command';
|
|
||||||
import { GrabError, TryLaterError } from '../Errors';
|
import { GrabError, TryLaterError } from '../Errors';
|
||||||
import { Task } from '../Queue/TaskQueue';
|
import { Task } from '../Queue/TaskQueue';
|
||||||
import { clickUpgradeButton } from '../Page/BuildingPage';
|
import { clickUpgradeButton } from '../Page/BuildingPage';
|
||||||
import { aroundMinutes } from '../utils';
|
import { aroundMinutes } from '../utils';
|
||||||
|
import { Args } from '../Args';
|
||||||
|
|
||||||
@registerAction
|
@registerAction
|
||||||
export class UpgradeBuildingAction extends ActionController {
|
export class UpgradeBuildingAction extends ActionController {
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
import { ActionController, registerAction } from './ActionController';
|
import { ActionController, registerAction } from './ActionController';
|
||||||
import { Args } from '../Command';
|
|
||||||
import { AbortTaskError, ActionError, TryLaterError } from '../Errors';
|
import { AbortTaskError, ActionError, TryLaterError } from '../Errors';
|
||||||
import { Task } from '../Queue/TaskQueue';
|
import { Task } from '../Queue/TaskQueue';
|
||||||
import { grabResourceDeposits } from '../Page/SlotBlock';
|
import { grabResourceDeposits } from '../Page/SlotBlock';
|
||||||
import { UpgradeBuildingTask } from '../Task/UpgradeBuildingTask';
|
import { UpgradeBuildingTask } from '../Task/UpgradeBuildingTask';
|
||||||
import { ResourceDeposit } from '../Game';
|
import { ResourceDeposit } from '../Game';
|
||||||
import { aroundMinutes, getNumber } from '../utils';
|
import { aroundMinutes, getNumber } from '../utils';
|
||||||
|
import { Args } from '../Args';
|
||||||
|
|
||||||
@registerAction
|
@registerAction
|
||||||
export class UpgradeResourceToLevel extends ActionController {
|
export class UpgradeResourceToLevel extends ActionController {
|
||||||
|
@ -19,13 +19,3 @@ export interface Args {
|
|||||||
selector?: string;
|
selector?: string;
|
||||||
path?: string;
|
path?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class Command {
|
|
||||||
readonly name: string;
|
|
||||||
readonly args: Args;
|
|
||||||
|
|
||||||
constructor(name: string, args: Args) {
|
|
||||||
this.name = name;
|
|
||||||
this.args = args;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,7 +1,6 @@
|
|||||||
import { markPage, sleepMicro, timestamp, waitForLoad } from './utils';
|
import { markPage, sleepMicro, timestamp, waitForLoad } from './utils';
|
||||||
import { AbortTaskError, ActionError, TryLaterError } from './Errors';
|
import { AbortTaskError, ActionError, TryLaterError } from './Errors';
|
||||||
import { Task } from './Queue/TaskQueue';
|
import { Task } from './Queue/TaskQueue';
|
||||||
import { Command } from './Command';
|
|
||||||
import { TaskQueueRenderer } from './TaskQueueRenderer';
|
import { TaskQueueRenderer } from './TaskQueueRenderer';
|
||||||
import { createActionHandler } from './Action/ActionController';
|
import { createActionHandler } from './Action/ActionController';
|
||||||
import { createTaskHandler } from './Task/TaskController';
|
import { createTaskHandler } from './Task/TaskController';
|
||||||
@ -10,6 +9,7 @@ import { GrabberManager } from './Grabber/GrabberManager';
|
|||||||
import { Scheduler } from './Scheduler';
|
import { Scheduler } from './Scheduler';
|
||||||
import { Statistics } from './Statistics';
|
import { Statistics } from './Statistics';
|
||||||
import { ExecutionState } from './State/ExecutionState';
|
import { ExecutionState } from './State/ExecutionState';
|
||||||
|
import { Action } from './Queue/ActionQueue';
|
||||||
|
|
||||||
export interface ExecutionSettings {
|
export interface ExecutionSettings {
|
||||||
pauseTs: number;
|
pauseTs: number;
|
||||||
@ -96,7 +96,7 @@ export class Executor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async processActionCommand(cmd: Command, task: Task) {
|
private async processActionCommand(cmd: Action, task: Task) {
|
||||||
const actionHandler = createActionHandler(cmd.name, this.scheduler);
|
const actionHandler = createActionHandler(cmd.name, this.scheduler);
|
||||||
this.logger.log('PROCESS ACTION', cmd.name, actionHandler);
|
this.logger.log('PROCESS ACTION', cmd.name, actionHandler);
|
||||||
if (cmd.args.taskId !== task.id) {
|
if (cmd.args.taskId !== task.id) {
|
||||||
|
@ -1,13 +1,23 @@
|
|||||||
import { Command } from '../Command';
|
|
||||||
import { ConsoleLogger, Logger } from '../Logger';
|
import { ConsoleLogger, Logger } from '../Logger';
|
||||||
import { DataStorage } from '../DataStorage';
|
import { DataStorage } from '../DataStorage';
|
||||||
|
import { Args } from '../Args';
|
||||||
|
|
||||||
const NAMESPACE = 'actions.v1';
|
const NAMESPACE = 'actions.v1';
|
||||||
const QUEUE_NAME = 'queue';
|
const QUEUE_NAME = 'queue';
|
||||||
|
|
||||||
type ActionList = Array<Command>;
|
export class Action {
|
||||||
|
readonly name: string;
|
||||||
|
readonly args: Args;
|
||||||
|
|
||||||
export type ImmutableActionList = ReadonlyArray<Command>;
|
constructor(name: string, args: Args) {
|
||||||
|
this.name = name;
|
||||||
|
this.args = args;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
type ActionList = Array<Action>;
|
||||||
|
|
||||||
|
export type ImmutableActionList = ReadonlyArray<Action>;
|
||||||
|
|
||||||
export class ActionQueue {
|
export class ActionQueue {
|
||||||
private storage: DataStorage;
|
private storage: DataStorage;
|
||||||
@ -18,14 +28,14 @@ export class ActionQueue {
|
|||||||
this.logger = new ConsoleLogger(this.constructor.name);
|
this.logger = new ConsoleLogger(this.constructor.name);
|
||||||
}
|
}
|
||||||
|
|
||||||
pop(): Command | undefined {
|
pop(): Action | undefined {
|
||||||
const commands = this.getCommands();
|
const commands = this.getCommands();
|
||||||
const first = commands.shift();
|
const first = commands.shift();
|
||||||
this.flushState(commands);
|
this.flushState(commands);
|
||||||
return first;
|
return first;
|
||||||
}
|
}
|
||||||
|
|
||||||
push(cmd: Command): void {
|
push(cmd: Action): void {
|
||||||
const commands = this.getCommands();
|
const commands = this.getCommands();
|
||||||
commands.push(cmd);
|
commands.push(cmd);
|
||||||
this.flushState(commands);
|
this.flushState(commands);
|
||||||
@ -52,7 +62,7 @@ export class ActionQueue {
|
|||||||
const items = serialized as Array<{ [key: string]: any }>;
|
const items = serialized as Array<{ [key: string]: any }>;
|
||||||
|
|
||||||
return items.map(i => {
|
return items.map(i => {
|
||||||
const command = new Command('', {});
|
const command = new Action('', {});
|
||||||
return Object.assign(command, i);
|
return Object.assign(command, i);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import { Args } from '../Command';
|
|
||||||
import { uniqId } from '../utils';
|
import { uniqId } from '../utils';
|
||||||
import { ConsoleLogger, Logger } from '../Logger';
|
import { ConsoleLogger, Logger } from '../Logger';
|
||||||
import { DataStorage } from '../DataStorage';
|
import { DataStorage } from '../DataStorage';
|
||||||
|
import { Args } from '../Args';
|
||||||
|
|
||||||
const NAMESPACE = 'tasks:v1';
|
const NAMESPACE = 'tasks:v1';
|
||||||
const QUEUE_NAME = 'queue';
|
const QUEUE_NAME = 'queue';
|
||||||
|
@ -1,17 +1,17 @@
|
|||||||
import { timestamp } from './utils';
|
import { timestamp } from './utils';
|
||||||
import { UpgradeBuildingTask } from './Task/UpgradeBuildingTask';
|
import { UpgradeBuildingTask } from './Task/UpgradeBuildingTask';
|
||||||
import { ImmutableTaskList, Task, TaskId, TaskQueue } from './Queue/TaskQueue';
|
import { ImmutableTaskList, Task, TaskId, TaskQueue } from './Queue/TaskQueue';
|
||||||
import { Args, Command } from './Command';
|
|
||||||
import { SendOnAdventureTask } from './Task/SendOnAdventureTask';
|
import { SendOnAdventureTask } from './Task/SendOnAdventureTask';
|
||||||
import { BalanceHeroResourcesTask } from './Task/BalanceHeroResourcesTask';
|
import { BalanceHeroResourcesTask } from './Task/BalanceHeroResourcesTask';
|
||||||
import { ConsoleLogger, Logger } from './Logger';
|
import { ConsoleLogger, Logger } from './Logger';
|
||||||
import { BuildBuildingTask } from './Task/BuildBuildingTask';
|
import { BuildBuildingTask } from './Task/BuildBuildingTask';
|
||||||
import { GrabVillageState } from './Task/GrabVillageState';
|
import { GrabVillageState } from './Task/GrabVillageState';
|
||||||
import { ActionQueue, ImmutableActionList } from './Queue/ActionQueue';
|
import { ActionQueue, Action, ImmutableActionList } from './Queue/ActionQueue';
|
||||||
import { UpdateResourceContracts } from './Task/UpdateResourceContracts';
|
import { UpdateResourceContracts } from './Task/UpdateResourceContracts';
|
||||||
import { TrainTroopTask } from './Task/TrainTroopTask';
|
import { TrainTroopTask } from './Task/TrainTroopTask';
|
||||||
import { Resources, ResourcesInterface } from './Core/Resources';
|
import { Resources, ResourcesInterface } from './Core/Resources';
|
||||||
import { SendResourcesTask } from './Task/SendResourcesTask';
|
import { SendResourcesTask } from './Task/SendResourcesTask';
|
||||||
|
import { Args } from './Args';
|
||||||
|
|
||||||
export class Scheduler {
|
export class Scheduler {
|
||||||
private taskQueue: TaskQueue;
|
private taskQueue: TaskQueue;
|
||||||
@ -106,7 +106,7 @@ export class Scheduler {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
scheduleActions(actions: Array<Command>): void {
|
scheduleActions(actions: Array<Action>): void {
|
||||||
this.actionQueue.assign(actions);
|
this.actionQueue.assign(actions);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -169,10 +169,6 @@ function withResources(task: Task, resources: ResourcesInterface): Task {
|
|||||||
return new Task(task.id, task.ts, task.name, { ...task.args, resources });
|
return new Task(task.id, task.ts, task.name, { ...task.args, resources });
|
||||||
}
|
}
|
||||||
|
|
||||||
function firstTaskTime(tasks: ImmutableTaskList, predicate: (t: Task) => boolean): number | undefined {
|
|
||||||
return tasks.find(predicate)?.ts;
|
|
||||||
}
|
|
||||||
|
|
||||||
function lastTaskTime(tasks: ImmutableTaskList, predicate: (t: Task) => boolean): number | undefined {
|
function lastTaskTime(tasks: ImmutableTaskList, predicate: (t: Task) => boolean): number | undefined {
|
||||||
const queuedTaskIndex = findLastIndex(tasks, predicate);
|
const queuedTaskIndex = findLastIndex(tasks, predicate);
|
||||||
if (queuedTaskIndex === undefined) {
|
if (queuedTaskIndex === undefined) {
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
import { Args, Command } from '../Command';
|
|
||||||
import { Task } from '../Queue/TaskQueue';
|
import { Task } from '../Queue/TaskQueue';
|
||||||
import { TaskController, registerTask } from './TaskController';
|
import { TaskController, registerTask } from './TaskController';
|
||||||
import { GoToPageAction } from '../Action/GoToPageAction';
|
import { GoToPageAction } from '../Action/GoToPageAction';
|
||||||
@ -6,19 +5,21 @@ import { CompleteTaskAction } from '../Action/CompleteTaskAction';
|
|||||||
import { BalanceHeroResourcesAction } from '../Action/BalanceHeroResourcesAction';
|
import { BalanceHeroResourcesAction } from '../Action/BalanceHeroResourcesAction';
|
||||||
import { path } from '../utils';
|
import { path } from '../utils';
|
||||||
import { GoToHeroVillageAction } from '../Action/GoToHeroVillageAction';
|
import { GoToHeroVillageAction } from '../Action/GoToHeroVillageAction';
|
||||||
|
import { Action } from '../Queue/ActionQueue';
|
||||||
|
import { Args } from '../Args';
|
||||||
|
|
||||||
@registerTask
|
@registerTask
|
||||||
export class BalanceHeroResourcesTask extends TaskController {
|
export class BalanceHeroResourcesTask extends TaskController {
|
||||||
async run(task: Task) {
|
async run(task: Task) {
|
||||||
const args: Args = { ...task.args, taskId: task.id };
|
const args: Args = { ...task.args, taskId: task.id };
|
||||||
this.scheduler.scheduleActions([
|
this.scheduler.scheduleActions([
|
||||||
new Command(GoToPageAction.name, {
|
new Action(GoToPageAction.name, {
|
||||||
...args,
|
...args,
|
||||||
path: path('/hero.php'),
|
path: path('/hero.php'),
|
||||||
}),
|
}),
|
||||||
new Command(GoToHeroVillageAction.name, args),
|
new Action(GoToHeroVillageAction.name, args),
|
||||||
new Command(BalanceHeroResourcesAction.name, args),
|
new Action(BalanceHeroResourcesAction.name, args),
|
||||||
new Command(CompleteTaskAction.name, args),
|
new Action(CompleteTaskAction.name, args),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
import { Args, Command } from '../Command';
|
|
||||||
import { BuildBuildingAction } from '../Action/BuildBuildingAction';
|
import { BuildBuildingAction } from '../Action/BuildBuildingAction';
|
||||||
import { CheckBuildingRemainingTimeAction } from '../Action/CheckBuildingRemainingTimeAction';
|
import { CheckBuildingRemainingTimeAction } from '../Action/CheckBuildingRemainingTimeAction';
|
||||||
import { CompleteTaskAction } from '../Action/CompleteTaskAction';
|
import { CompleteTaskAction } from '../Action/CompleteTaskAction';
|
||||||
@ -6,23 +5,25 @@ import { GoToPageAction } from '../Action/GoToPageAction';
|
|||||||
import { path } from '../utils';
|
import { path } from '../utils';
|
||||||
import { Task } from '../Queue/TaskQueue';
|
import { Task } from '../Queue/TaskQueue';
|
||||||
import { TaskController, registerTask } from './TaskController';
|
import { TaskController, registerTask } from './TaskController';
|
||||||
|
import { Action } from '../Queue/ActionQueue';
|
||||||
|
import { Args } from '../Args';
|
||||||
|
|
||||||
@registerTask
|
@registerTask
|
||||||
export class BuildBuildingTask extends TaskController {
|
export class BuildBuildingTask extends TaskController {
|
||||||
async run(task: Task) {
|
async run(task: Task) {
|
||||||
const args: Args = { ...task.args, taskId: task.id };
|
const args: Args = { ...task.args, taskId: task.id };
|
||||||
this.scheduler.scheduleActions([
|
this.scheduler.scheduleActions([
|
||||||
new Command(GoToPageAction.name, {
|
new Action(GoToPageAction.name, {
|
||||||
...args,
|
...args,
|
||||||
path: path('/dorf1.php', { newdid: args.villageId }),
|
path: path('/dorf1.php', { newdid: args.villageId }),
|
||||||
}),
|
}),
|
||||||
new Command(CheckBuildingRemainingTimeAction.name, args),
|
new Action(CheckBuildingRemainingTimeAction.name, args),
|
||||||
new Command(GoToPageAction.name, {
|
new Action(GoToPageAction.name, {
|
||||||
...args,
|
...args,
|
||||||
path: path('/build.php', { newdid: args.villageId, id: args.buildId, category: args.categoryId }),
|
path: path('/build.php', { newdid: args.villageId, id: args.buildId, category: args.categoryId }),
|
||||||
}),
|
}),
|
||||||
new Command(BuildBuildingAction.name, args),
|
new Action(BuildBuildingAction.name, args),
|
||||||
new Command(CompleteTaskAction.name, args),
|
new Action(CompleteTaskAction.name, args),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,11 @@
|
|||||||
import { Args, Command } from '../Command';
|
|
||||||
import { Task } from '../Queue/TaskQueue';
|
import { Task } from '../Queue/TaskQueue';
|
||||||
import { TaskController, registerTask, ActionDefinition } from './TaskController';
|
import { TaskController, registerTask, ActionDefinition } from './TaskController';
|
||||||
import { GoToPageAction } from '../Action/GoToPageAction';
|
import { GoToPageAction } from '../Action/GoToPageAction';
|
||||||
import { CompleteTaskAction } from '../Action/CompleteTaskAction';
|
import { CompleteTaskAction } from '../Action/CompleteTaskAction';
|
||||||
import { path } from '../utils';
|
import { path } from '../utils';
|
||||||
import { UpgradeResourceToLevel } from '../Action/UpgradeResourceToLevel';
|
import { UpgradeResourceToLevel } from '../Action/UpgradeResourceToLevel';
|
||||||
|
import { Action } from '../Queue/ActionQueue';
|
||||||
|
import { Args } from '../Args';
|
||||||
|
|
||||||
@registerTask
|
@registerTask
|
||||||
export class ResourcesToLevel extends TaskController {
|
export class ResourcesToLevel extends TaskController {
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
import { Args, Command } from '../Command';
|
|
||||||
import { Task } from '../Queue/TaskQueue';
|
import { Task } from '../Queue/TaskQueue';
|
||||||
import { TaskController, registerTask } from './TaskController';
|
import { TaskController, registerTask } from './TaskController';
|
||||||
import { GoToPageAction } from '../Action/GoToPageAction';
|
import { GoToPageAction } from '../Action/GoToPageAction';
|
||||||
@ -6,26 +5,28 @@ import { CompleteTaskAction } from '../Action/CompleteTaskAction';
|
|||||||
import { SendOnAdventureAction } from '../Action/SendOnAdventureAction';
|
import { SendOnAdventureAction } from '../Action/SendOnAdventureAction';
|
||||||
import { ClickButtonAction } from '../Action/ClickButtonAction';
|
import { ClickButtonAction } from '../Action/ClickButtonAction';
|
||||||
import { path } from '../utils';
|
import { path } from '../utils';
|
||||||
|
import { Action } from '../Queue/ActionQueue';
|
||||||
|
import { Args } from '../Args';
|
||||||
|
|
||||||
@registerTask
|
@registerTask
|
||||||
export class SendOnAdventureTask extends TaskController {
|
export class SendOnAdventureTask extends TaskController {
|
||||||
async run(task: Task) {
|
async run(task: Task) {
|
||||||
const args: Args = { ...task.args, taskId: task.id };
|
const args: Args = { ...task.args, taskId: task.id };
|
||||||
this.scheduler.scheduleActions([
|
this.scheduler.scheduleActions([
|
||||||
new Command(GoToPageAction.name, {
|
new Action(GoToPageAction.name, {
|
||||||
...args,
|
...args,
|
||||||
path: path('/hero.php'),
|
path: path('/hero.php'),
|
||||||
}),
|
}),
|
||||||
new Command(GoToPageAction.name, {
|
new Action(GoToPageAction.name, {
|
||||||
...args,
|
...args,
|
||||||
path: path('/hero.php', { t: 3 }),
|
path: path('/hero.php', { t: 3 }),
|
||||||
}),
|
}),
|
||||||
new Command(SendOnAdventureAction.name, args),
|
new Action(SendOnAdventureAction.name, args),
|
||||||
new Command(ClickButtonAction.name, {
|
new Action(ClickButtonAction.name, {
|
||||||
...args,
|
...args,
|
||||||
selector: '.adventureSendButton button',
|
selector: '.adventureSendButton button',
|
||||||
}),
|
}),
|
||||||
new Command(CompleteTaskAction.name, args),
|
new Action(CompleteTaskAction.name, args),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
import { Args } from '../Command';
|
|
||||||
import { Task } from '../Queue/TaskQueue';
|
import { Task } from '../Queue/TaskQueue';
|
||||||
import { TaskController, registerTask, ActionDefinition } from './TaskController';
|
import { TaskController, registerTask, ActionDefinition } from './TaskController';
|
||||||
import { GoToPageAction } from '../Action/GoToPageAction';
|
import { GoToPageAction } from '../Action/GoToPageAction';
|
||||||
@ -7,6 +6,7 @@ import { path } from '../utils';
|
|||||||
import { SendResourcesAction } from '../Action/SendResourcesAction';
|
import { SendResourcesAction } from '../Action/SendResourcesAction';
|
||||||
import { ClickButtonAction } from '../Action/ClickButtonAction';
|
import { ClickButtonAction } from '../Action/ClickButtonAction';
|
||||||
import { scanAllVillagesBundle } from './ActionBundles';
|
import { scanAllVillagesBundle } from './ActionBundles';
|
||||||
|
import { Args } from '../Args';
|
||||||
|
|
||||||
@registerTask
|
@registerTask
|
||||||
export class SendResourcesTask extends TaskController {
|
export class SendResourcesTask extends TaskController {
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
import { Task } from '../Queue/TaskQueue';
|
import { Task } from '../Queue/TaskQueue';
|
||||||
import { Scheduler } from '../Scheduler';
|
import { Scheduler } from '../Scheduler';
|
||||||
import { Args, Command } from '../Command';
|
|
||||||
import { CompleteTaskAction } from '../Action/CompleteTaskAction';
|
import { CompleteTaskAction } from '../Action/CompleteTaskAction';
|
||||||
|
import { Action } from '../Queue/ActionQueue';
|
||||||
|
import { Args } from '../Args';
|
||||||
|
|
||||||
const taskMap: { [name: string]: Function | undefined } = {};
|
const taskMap: { [name: string]: Function | undefined } = {};
|
||||||
|
|
||||||
@ -38,11 +39,11 @@ export class TaskController {
|
|||||||
|
|
||||||
private createCommands(task: Task) {
|
private createCommands(task: Task) {
|
||||||
const args: Args = { ...task.args, taskId: task.id };
|
const args: Args = { ...task.args, taskId: task.id };
|
||||||
const commands: Array<Command> = [];
|
const commands: Array<Action> = [];
|
||||||
for (let def of this.defineActions(task)) {
|
for (let def of this.defineActions(task)) {
|
||||||
commands.push(new Command(def[0], { ...args, ...def[1] }));
|
commands.push(new Action(def[0], { ...args, ...def[1] }));
|
||||||
}
|
}
|
||||||
commands.push(new Command(CompleteTaskAction.name, args));
|
commands.push(new Action(CompleteTaskAction.name, args));
|
||||||
return commands;
|
return commands;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,10 +1,11 @@
|
|||||||
import { Args, Command } from '../Command';
|
|
||||||
import { Task } from '../Queue/TaskQueue';
|
import { Task } from '../Queue/TaskQueue';
|
||||||
import { TaskController, registerTask } from './TaskController';
|
import { TaskController, registerTask } from './TaskController';
|
||||||
import { GoToPageAction } from '../Action/GoToPageAction';
|
import { GoToPageAction } from '../Action/GoToPageAction';
|
||||||
import { CompleteTaskAction } from '../Action/CompleteTaskAction';
|
import { CompleteTaskAction } from '../Action/CompleteTaskAction';
|
||||||
import { TrainTrooperAction } from '../Action/TrainTrooperAction';
|
import { TrainTrooperAction } from '../Action/TrainTrooperAction';
|
||||||
import { path } from '../utils';
|
import { path } from '../utils';
|
||||||
|
import { Action } from '../Queue/ActionQueue';
|
||||||
|
import { Args } from '../Args';
|
||||||
|
|
||||||
@registerTask
|
@registerTask
|
||||||
export class TrainTroopTask extends TaskController {
|
export class TrainTroopTask extends TaskController {
|
||||||
@ -21,9 +22,9 @@ export class TrainTroopTask extends TaskController {
|
|||||||
const pagePath = path('/build.php', pathArgs);
|
const pagePath = path('/build.php', pathArgs);
|
||||||
|
|
||||||
this.scheduler.scheduleActions([
|
this.scheduler.scheduleActions([
|
||||||
new Command(GoToPageAction.name, { ...args, path: pagePath }),
|
new Action(GoToPageAction.name, { ...args, path: pagePath }),
|
||||||
new Command(TrainTrooperAction.name, args),
|
new Action(TrainTrooperAction.name, args),
|
||||||
new Command(CompleteTaskAction.name, args),
|
new Action(CompleteTaskAction.name, args),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
import { Args, Command } from '../Command';
|
|
||||||
import { Task } from '../Queue/TaskQueue';
|
import { Task } from '../Queue/TaskQueue';
|
||||||
import { TaskController, registerTask } from './TaskController';
|
import { TaskController, registerTask } from './TaskController';
|
||||||
import { GoToPageAction } from '../Action/GoToPageAction';
|
import { GoToPageAction } from '../Action/GoToPageAction';
|
||||||
@ -6,29 +5,31 @@ import { path } from '../utils';
|
|||||||
import { UpgradeBuildingTask } from './UpgradeBuildingTask';
|
import { UpgradeBuildingTask } from './UpgradeBuildingTask';
|
||||||
import { UpdateBuildingTaskResourcesAction } from '../Action/UpdateBuildingTaskResourcesAction';
|
import { UpdateBuildingTaskResourcesAction } from '../Action/UpdateBuildingTaskResourcesAction';
|
||||||
import { CompleteTaskAction } from '../Action/CompleteTaskAction';
|
import { CompleteTaskAction } from '../Action/CompleteTaskAction';
|
||||||
|
import { Action } from '../Queue/ActionQueue';
|
||||||
|
import { Args } from '../Args';
|
||||||
|
|
||||||
@registerTask
|
@registerTask
|
||||||
export class UpdateResourceContracts extends TaskController {
|
export class UpdateResourceContracts extends TaskController {
|
||||||
async run(task: Task) {
|
async run(task: Task) {
|
||||||
const args: Args = { ...task.args, taskId: task.id };
|
const args: Args = { ...task.args, taskId: task.id };
|
||||||
|
|
||||||
const actions: Array<Command> = [];
|
const actions: Array<Action> = [];
|
||||||
|
|
||||||
const tasks = this.scheduler.getTaskItems();
|
const tasks = this.scheduler.getTaskItems();
|
||||||
for (let task of tasks) {
|
for (let task of tasks) {
|
||||||
const { villageId, buildId } = task.args;
|
const { villageId, buildId } = task.args;
|
||||||
if (task.name === UpgradeBuildingTask.name && villageId && buildId) {
|
if (task.name === UpgradeBuildingTask.name && villageId && buildId) {
|
||||||
actions.push(
|
actions.push(
|
||||||
new Command(GoToPageAction.name, {
|
new Action(GoToPageAction.name, {
|
||||||
...args,
|
...args,
|
||||||
path: path('/build.php', { newdid: villageId, id: buildId }),
|
path: path('/build.php', { newdid: villageId, id: buildId }),
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
actions.push(new Command(UpdateBuildingTaskResourcesAction.name, { ...args, targetTaskId: task.id }));
|
actions.push(new Action(UpdateBuildingTaskResourcesAction.name, { ...args, targetTaskId: task.id }));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
actions.push(new Command(CompleteTaskAction.name, args));
|
actions.push(new Action(CompleteTaskAction.name, args));
|
||||||
|
|
||||||
this.scheduler.scheduleActions(actions);
|
this.scheduler.scheduleActions(actions);
|
||||||
}
|
}
|
||||||
|
@ -1,28 +1,29 @@
|
|||||||
import { UpgradeBuildingAction } from '../Action/UpgradeBuildingAction';
|
import { UpgradeBuildingAction } from '../Action/UpgradeBuildingAction';
|
||||||
import { Args, Command } from '../Command';
|
|
||||||
import { Task } from '../Queue/TaskQueue';
|
import { Task } from '../Queue/TaskQueue';
|
||||||
import { TaskController, registerTask } from './TaskController';
|
import { TaskController, registerTask } from './TaskController';
|
||||||
import { GoToPageAction } from '../Action/GoToPageAction';
|
import { GoToPageAction } from '../Action/GoToPageAction';
|
||||||
import { CheckBuildingRemainingTimeAction } from '../Action/CheckBuildingRemainingTimeAction';
|
import { CheckBuildingRemainingTimeAction } from '../Action/CheckBuildingRemainingTimeAction';
|
||||||
import { CompleteTaskAction } from '../Action/CompleteTaskAction';
|
import { CompleteTaskAction } from '../Action/CompleteTaskAction';
|
||||||
import { path } from '../utils';
|
import { path } from '../utils';
|
||||||
|
import { Action } from '../Queue/ActionQueue';
|
||||||
|
import { Args } from '../Args';
|
||||||
|
|
||||||
@registerTask
|
@registerTask
|
||||||
export class UpgradeBuildingTask extends TaskController {
|
export class UpgradeBuildingTask extends TaskController {
|
||||||
async run(task: Task) {
|
async run(task: Task) {
|
||||||
const args: Args = { ...task.args, taskId: task.id };
|
const args: Args = { ...task.args, taskId: task.id };
|
||||||
this.scheduler.scheduleActions([
|
this.scheduler.scheduleActions([
|
||||||
new Command(GoToPageAction.name, {
|
new Action(GoToPageAction.name, {
|
||||||
...args,
|
...args,
|
||||||
path: path('/dorf1.php', { newdid: args.villageId }),
|
path: path('/dorf1.php', { newdid: args.villageId }),
|
||||||
}),
|
}),
|
||||||
new Command(CheckBuildingRemainingTimeAction.name, args),
|
new Action(CheckBuildingRemainingTimeAction.name, args),
|
||||||
new Command(GoToPageAction.name, {
|
new Action(GoToPageAction.name, {
|
||||||
...args,
|
...args,
|
||||||
path: path('/build.php', { newdid: args.villageId, id: args.buildId }),
|
path: path('/build.php', { newdid: args.villageId, id: args.buildId }),
|
||||||
}),
|
}),
|
||||||
new Command(UpgradeBuildingAction.name, args),
|
new Action(UpgradeBuildingAction.name, args),
|
||||||
new Command(CompleteTaskAction.name, args),
|
new Action(CompleteTaskAction.name, args),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user