diff --git a/src/Action/ActionController.ts b/src/Action/ActionController.ts index ca82f4d..a1bbf3f 100644 --- a/src/Action/ActionController.ts +++ b/src/Action/ActionController.ts @@ -1,9 +1,9 @@ -import { Args } from '../Command'; import { Task } from '../Queue/TaskQueue'; import { Scheduler } from '../Scheduler'; import { ActionError, TryLaterError } from '../Errors'; import { grabActiveVillageId } from '../Page/VillageBlock'; import { aroundMinutes } from '../utils'; +import { Args } from '../Args'; const actionMap: { [name: string]: Function | undefined } = {}; diff --git a/src/Action/BalanceHeroResourcesAction.ts b/src/Action/BalanceHeroResourcesAction.ts index 53e3b5d..bc39e45 100644 --- a/src/Action/BalanceHeroResourcesAction.ts +++ b/src/Action/BalanceHeroResourcesAction.ts @@ -1,5 +1,4 @@ import { ActionController, registerAction } from './ActionController'; -import { Args } from '../Command'; import { Task } from '../Queue/TaskQueue'; import { grabVillageResources, grabVillageResourceStorage } from '../Page/ResourcesBlock'; import { changeHeroResource, grabCurrentHeroResource } from '../Page/HeroPage'; @@ -7,6 +6,7 @@ import { grabActiveVillageId } from '../Page/VillageBlock'; import { HeroState } from '../State/HeroState'; import { calcHeroResource } from '../Core/HeroBalance'; import { HeroAllResources } from '../Core/Hero'; +import { Args } from '../Args'; @registerAction export class BalanceHeroResourcesAction extends ActionController { diff --git a/src/Action/BuildBuildingAction.ts b/src/Action/BuildBuildingAction.ts index 0349f24..218cefd 100644 --- a/src/Action/BuildBuildingAction.ts +++ b/src/Action/BuildBuildingAction.ts @@ -1,9 +1,9 @@ import { ActionController, registerAction } from './ActionController'; -import { Args } from '../Command'; import { ActionError, GrabError, TryLaterError } from '../Errors'; import { Task } from '../Queue/TaskQueue'; import { clickBuildButton } from '../Page/BuildingPage'; import { aroundMinutes } from '../utils'; +import { Args } from '../Args'; @registerAction export class BuildBuildingAction extends ActionController { diff --git a/src/Action/CheckBuildingRemainingTimeAction.ts b/src/Action/CheckBuildingRemainingTimeAction.ts index 5aaaa10..a3ad1f0 100644 --- a/src/Action/CheckBuildingRemainingTimeAction.ts +++ b/src/Action/CheckBuildingRemainingTimeAction.ts @@ -1,9 +1,9 @@ import { ActionController, registerAction } from './ActionController'; -import { Args } from '../Command'; import { Task } from '../Queue/TaskQueue'; import { GrabError, TryLaterError } from '../Errors'; import { grabBuildingQueueInfo } from '../Page/VillageBlock'; import { BuildingQueueInfo } from '../Game'; +import { Args } from '../Args'; @registerAction export class CheckBuildingRemainingTimeAction extends ActionController { diff --git a/src/Action/ClickButtonAction.ts b/src/Action/ClickButtonAction.ts index 22aca99..c5210b4 100644 --- a/src/Action/ClickButtonAction.ts +++ b/src/Action/ClickButtonAction.ts @@ -1,7 +1,7 @@ import { ActionController, registerAction } from './ActionController'; -import { Args } from '../Command'; import { Task } from '../Queue/TaskQueue'; import { AbortTaskError } from '../Errors'; +import { Args } from '../Args'; @registerAction export class ClickButtonAction extends ActionController { diff --git a/src/Action/CompleteTaskAction.ts b/src/Action/CompleteTaskAction.ts index 7300a20..8922d42 100644 --- a/src/Action/CompleteTaskAction.ts +++ b/src/Action/CompleteTaskAction.ts @@ -1,6 +1,6 @@ import { ActionController, registerAction } from './ActionController'; -import { Args } from '../Command'; import { Task } from '../Queue/TaskQueue'; +import { Args } from '../Args'; @registerAction export class CompleteTaskAction extends ActionController { diff --git a/src/Action/GoToHeroVillageAction.ts b/src/Action/GoToHeroVillageAction.ts index 33d358d..6a6c4aa 100644 --- a/src/Action/GoToHeroVillageAction.ts +++ b/src/Action/GoToHeroVillageAction.ts @@ -1,10 +1,10 @@ import { ActionController, registerAction } from './ActionController'; -import { Args } from '../Command'; import { Task } from '../Queue/TaskQueue'; import { grabVillageList } from '../Page/VillageBlock'; import { grabHeroVillage } from '../Page/HeroPage'; import { path } from '../utils'; import { HeroState } from '../State/HeroState'; +import { Args } from '../Args'; @registerAction export class GoToHeroVillageAction extends ActionController { diff --git a/src/Action/GoToPageAction.ts b/src/Action/GoToPageAction.ts index 27ab8ee..d6a7465 100644 --- a/src/Action/GoToPageAction.ts +++ b/src/Action/GoToPageAction.ts @@ -1,7 +1,7 @@ import { ActionController, registerAction } from './ActionController'; -import { Args } from '../Command'; import { Task } from '../Queue/TaskQueue'; import { AbortTaskError } from '../Errors'; +import { Args } from '../Args'; @registerAction export class GoToPageAction extends ActionController { diff --git a/src/Action/SendOnAdventureAction.ts b/src/Action/SendOnAdventureAction.ts index e078ad6..3f578fc 100644 --- a/src/Action/SendOnAdventureAction.ts +++ b/src/Action/SendOnAdventureAction.ts @@ -1,8 +1,8 @@ import { ActionController, registerAction } from './ActionController'; -import { Args } from '../Command'; import { Task } from '../Queue/TaskQueue'; import { trimPrefix } from '../utils'; import { AbortTaskError } from '../Errors'; +import { Args } from '../Args'; const CONFIG = [ { level: 0, health: 60 }, diff --git a/src/Action/SendResourcesAction.ts b/src/Action/SendResourcesAction.ts index f2a5bc3..163353a 100644 --- a/src/Action/SendResourcesAction.ts +++ b/src/Action/SendResourcesAction.ts @@ -1,5 +1,4 @@ import { ActionController, registerAction } from './ActionController'; -import { Args } from '../Command'; import { AbortTaskError, ActionError, TryLaterError } from '../Errors'; import { Task } from '../Queue/TaskQueue'; import { Resources } from '../Core/Resources'; @@ -10,6 +9,7 @@ import { grabActiveVillageId, grabVillageList } from '../Page/VillageBlock'; import { SendResourcesTask } from '../Task/SendResourcesTask'; import { aroundMinutes, timestamp } from '../utils'; import { VillageState } from '../State/VillageState'; +import { Args } from '../Args'; function err(msg): never { throw new ActionError(msg); diff --git a/src/Action/TrainTrooperAction.ts b/src/Action/TrainTrooperAction.ts index ef430ec..98d4500 100644 --- a/src/Action/TrainTrooperAction.ts +++ b/src/Action/TrainTrooperAction.ts @@ -1,8 +1,8 @@ import { ActionController, registerAction } from './ActionController'; -import { Args } from '../Command'; import { ActionError, TryLaterError } from '../Errors'; import { Task } from '../Queue/TaskQueue'; import { getNumber, toNumber } from '../utils'; +import { Args } from '../Args'; @registerAction export class TrainTrooperAction extends ActionController { diff --git a/src/Action/UpdateBuildingTaskResourcesAction.ts b/src/Action/UpdateBuildingTaskResourcesAction.ts index 9f64297..ea38b24 100644 --- a/src/Action/UpdateBuildingTaskResourcesAction.ts +++ b/src/Action/UpdateBuildingTaskResourcesAction.ts @@ -1,7 +1,7 @@ import { ActionController, registerAction } from './ActionController'; -import { Args } from '../Command'; import { Task } from '../Queue/TaskQueue'; import { grabContractResources } from '../Page/BuildingPage'; +import { Args } from '../Args'; @registerAction export class UpdateBuildingTaskResourcesAction extends ActionController { diff --git a/src/Action/UpgradeBuildingAction.ts b/src/Action/UpgradeBuildingAction.ts index 4ee57f8..a08da69 100644 --- a/src/Action/UpgradeBuildingAction.ts +++ b/src/Action/UpgradeBuildingAction.ts @@ -1,9 +1,9 @@ import { ActionController, registerAction } from './ActionController'; -import { Args } from '../Command'; import { GrabError, TryLaterError } from '../Errors'; import { Task } from '../Queue/TaskQueue'; import { clickUpgradeButton } from '../Page/BuildingPage'; import { aroundMinutes } from '../utils'; +import { Args } from '../Args'; @registerAction export class UpgradeBuildingAction extends ActionController { diff --git a/src/Action/UpgradeResourceToLevel.ts b/src/Action/UpgradeResourceToLevel.ts index ead02b0..0cc08a7 100644 --- a/src/Action/UpgradeResourceToLevel.ts +++ b/src/Action/UpgradeResourceToLevel.ts @@ -1,11 +1,11 @@ import { ActionController, registerAction } from './ActionController'; -import { Args } from '../Command'; import { AbortTaskError, ActionError, TryLaterError } from '../Errors'; import { Task } from '../Queue/TaskQueue'; import { grabResourceDeposits } from '../Page/SlotBlock'; import { UpgradeBuildingTask } from '../Task/UpgradeBuildingTask'; import { ResourceDeposit } from '../Game'; import { aroundMinutes, getNumber } from '../utils'; +import { Args } from '../Args'; @registerAction export class UpgradeResourceToLevel extends ActionController { diff --git a/src/Command.ts b/src/Args.ts similarity index 75% rename from src/Command.ts rename to src/Args.ts index d3161ab..1bb5390 100644 --- a/src/Command.ts +++ b/src/Args.ts @@ -19,13 +19,3 @@ export interface Args { selector?: string; path?: string; } - -export class Command { - readonly name: string; - readonly args: Args; - - constructor(name: string, args: Args) { - this.name = name; - this.args = args; - } -} diff --git a/src/Executor.ts b/src/Executor.ts index 228032a..93d927a 100644 --- a/src/Executor.ts +++ b/src/Executor.ts @@ -1,7 +1,6 @@ import { markPage, sleepMicro, timestamp, waitForLoad } from './utils'; import { AbortTaskError, ActionError, TryLaterError } from './Errors'; import { Task } from './Queue/TaskQueue'; -import { Command } from './Command'; import { TaskQueueRenderer } from './TaskQueueRenderer'; import { createActionHandler } from './Action/ActionController'; import { createTaskHandler } from './Task/TaskController'; @@ -10,6 +9,7 @@ import { GrabberManager } from './Grabber/GrabberManager'; import { Scheduler } from './Scheduler'; import { Statistics } from './Statistics'; import { ExecutionState } from './State/ExecutionState'; +import { Action } from './Queue/ActionQueue'; export interface ExecutionSettings { 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); this.logger.log('PROCESS ACTION', cmd.name, actionHandler); if (cmd.args.taskId !== task.id) { diff --git a/src/Queue/ActionQueue.ts b/src/Queue/ActionQueue.ts index 5614ac4..47edecf 100644 --- a/src/Queue/ActionQueue.ts +++ b/src/Queue/ActionQueue.ts @@ -1,13 +1,23 @@ -import { Command } from '../Command'; import { ConsoleLogger, Logger } from '../Logger'; import { DataStorage } from '../DataStorage'; +import { Args } from '../Args'; const NAMESPACE = 'actions.v1'; const QUEUE_NAME = 'queue'; -type ActionList = Array; +export class Action { + readonly name: string; + readonly args: Args; -export type ImmutableActionList = ReadonlyArray; + constructor(name: string, args: Args) { + this.name = name; + this.args = args; + } +} + +type ActionList = Array; + +export type ImmutableActionList = ReadonlyArray; export class ActionQueue { private storage: DataStorage; @@ -18,14 +28,14 @@ export class ActionQueue { this.logger = new ConsoleLogger(this.constructor.name); } - pop(): Command | undefined { + pop(): Action | undefined { const commands = this.getCommands(); const first = commands.shift(); this.flushState(commands); return first; } - push(cmd: Command): void { + push(cmd: Action): void { const commands = this.getCommands(); commands.push(cmd); this.flushState(commands); @@ -52,7 +62,7 @@ export class ActionQueue { const items = serialized as Array<{ [key: string]: any }>; return items.map(i => { - const command = new Command('', {}); + const command = new Action('', {}); return Object.assign(command, i); }); } diff --git a/src/Queue/TaskQueue.ts b/src/Queue/TaskQueue.ts index 249b444..4c9a576 100644 --- a/src/Queue/TaskQueue.ts +++ b/src/Queue/TaskQueue.ts @@ -1,7 +1,7 @@ -import { Args } from '../Command'; import { uniqId } from '../utils'; import { ConsoleLogger, Logger } from '../Logger'; import { DataStorage } from '../DataStorage'; +import { Args } from '../Args'; const NAMESPACE = 'tasks:v1'; const QUEUE_NAME = 'queue'; diff --git a/src/Scheduler.ts b/src/Scheduler.ts index 4541d64..923b3d8 100644 --- a/src/Scheduler.ts +++ b/src/Scheduler.ts @@ -1,17 +1,17 @@ import { timestamp } from './utils'; import { UpgradeBuildingTask } from './Task/UpgradeBuildingTask'; import { ImmutableTaskList, Task, TaskId, TaskQueue } from './Queue/TaskQueue'; -import { Args, Command } from './Command'; import { SendOnAdventureTask } from './Task/SendOnAdventureTask'; import { BalanceHeroResourcesTask } from './Task/BalanceHeroResourcesTask'; import { ConsoleLogger, Logger } from './Logger'; import { BuildBuildingTask } from './Task/BuildBuildingTask'; import { GrabVillageState } from './Task/GrabVillageState'; -import { ActionQueue, ImmutableActionList } from './Queue/ActionQueue'; +import { ActionQueue, Action, ImmutableActionList } from './Queue/ActionQueue'; import { UpdateResourceContracts } from './Task/UpdateResourceContracts'; import { TrainTroopTask } from './Task/TrainTroopTask'; import { Resources, ResourcesInterface } from './Core/Resources'; import { SendResourcesTask } from './Task/SendResourcesTask'; +import { Args } from './Args'; export class Scheduler { private taskQueue: TaskQueue; @@ -106,7 +106,7 @@ export class Scheduler { ); } - scheduleActions(actions: Array): void { + scheduleActions(actions: Array): void { 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 }); } -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 { const queuedTaskIndex = findLastIndex(tasks, predicate); if (queuedTaskIndex === undefined) { diff --git a/src/Task/BalanceHeroResourcesTask.ts b/src/Task/BalanceHeroResourcesTask.ts index 760c7f4..4a499df 100644 --- a/src/Task/BalanceHeroResourcesTask.ts +++ b/src/Task/BalanceHeroResourcesTask.ts @@ -1,4 +1,3 @@ -import { Args, Command } from '../Command'; import { Task } from '../Queue/TaskQueue'; import { TaskController, registerTask } from './TaskController'; import { GoToPageAction } from '../Action/GoToPageAction'; @@ -6,19 +5,21 @@ import { CompleteTaskAction } from '../Action/CompleteTaskAction'; import { BalanceHeroResourcesAction } from '../Action/BalanceHeroResourcesAction'; import { path } from '../utils'; import { GoToHeroVillageAction } from '../Action/GoToHeroVillageAction'; +import { Action } from '../Queue/ActionQueue'; +import { Args } from '../Args'; @registerTask export class BalanceHeroResourcesTask extends TaskController { async run(task: Task) { const args: Args = { ...task.args, taskId: task.id }; this.scheduler.scheduleActions([ - new Command(GoToPageAction.name, { + new Action(GoToPageAction.name, { ...args, path: path('/hero.php'), }), - new Command(GoToHeroVillageAction.name, args), - new Command(BalanceHeroResourcesAction.name, args), - new Command(CompleteTaskAction.name, args), + new Action(GoToHeroVillageAction.name, args), + new Action(BalanceHeroResourcesAction.name, args), + new Action(CompleteTaskAction.name, args), ]); } } diff --git a/src/Task/BuildBuildingTask.ts b/src/Task/BuildBuildingTask.ts index 37cd5c2..b7c0789 100644 --- a/src/Task/BuildBuildingTask.ts +++ b/src/Task/BuildBuildingTask.ts @@ -1,4 +1,3 @@ -import { Args, Command } from '../Command'; import { BuildBuildingAction } from '../Action/BuildBuildingAction'; import { CheckBuildingRemainingTimeAction } from '../Action/CheckBuildingRemainingTimeAction'; import { CompleteTaskAction } from '../Action/CompleteTaskAction'; @@ -6,23 +5,25 @@ import { GoToPageAction } from '../Action/GoToPageAction'; import { path } from '../utils'; import { Task } from '../Queue/TaskQueue'; import { TaskController, registerTask } from './TaskController'; +import { Action } from '../Queue/ActionQueue'; +import { Args } from '../Args'; @registerTask export class BuildBuildingTask extends TaskController { async run(task: Task) { const args: Args = { ...task.args, taskId: task.id }; this.scheduler.scheduleActions([ - new Command(GoToPageAction.name, { + new Action(GoToPageAction.name, { ...args, path: path('/dorf1.php', { newdid: args.villageId }), }), - new Command(CheckBuildingRemainingTimeAction.name, args), - new Command(GoToPageAction.name, { + new Action(CheckBuildingRemainingTimeAction.name, args), + new Action(GoToPageAction.name, { ...args, path: path('/build.php', { newdid: args.villageId, id: args.buildId, category: args.categoryId }), }), - new Command(BuildBuildingAction.name, args), - new Command(CompleteTaskAction.name, args), + new Action(BuildBuildingAction.name, args), + new Action(CompleteTaskAction.name, args), ]); } } diff --git a/src/Task/ResourcesToLevel.ts b/src/Task/ResourcesToLevel.ts index 454a27b..4da1529 100644 --- a/src/Task/ResourcesToLevel.ts +++ b/src/Task/ResourcesToLevel.ts @@ -1,10 +1,11 @@ -import { Args, Command } from '../Command'; import { Task } from '../Queue/TaskQueue'; import { TaskController, registerTask, ActionDefinition } from './TaskController'; import { GoToPageAction } from '../Action/GoToPageAction'; import { CompleteTaskAction } from '../Action/CompleteTaskAction'; import { path } from '../utils'; import { UpgradeResourceToLevel } from '../Action/UpgradeResourceToLevel'; +import { Action } from '../Queue/ActionQueue'; +import { Args } from '../Args'; @registerTask export class ResourcesToLevel extends TaskController { diff --git a/src/Task/SendOnAdventureTask.ts b/src/Task/SendOnAdventureTask.ts index d187775..ea6380a 100644 --- a/src/Task/SendOnAdventureTask.ts +++ b/src/Task/SendOnAdventureTask.ts @@ -1,4 +1,3 @@ -import { Args, Command } from '../Command'; import { Task } from '../Queue/TaskQueue'; import { TaskController, registerTask } from './TaskController'; import { GoToPageAction } from '../Action/GoToPageAction'; @@ -6,26 +5,28 @@ import { CompleteTaskAction } from '../Action/CompleteTaskAction'; import { SendOnAdventureAction } from '../Action/SendOnAdventureAction'; import { ClickButtonAction } from '../Action/ClickButtonAction'; import { path } from '../utils'; +import { Action } from '../Queue/ActionQueue'; +import { Args } from '../Args'; @registerTask export class SendOnAdventureTask extends TaskController { async run(task: Task) { const args: Args = { ...task.args, taskId: task.id }; this.scheduler.scheduleActions([ - new Command(GoToPageAction.name, { + new Action(GoToPageAction.name, { ...args, path: path('/hero.php'), }), - new Command(GoToPageAction.name, { + new Action(GoToPageAction.name, { ...args, path: path('/hero.php', { t: 3 }), }), - new Command(SendOnAdventureAction.name, args), - new Command(ClickButtonAction.name, { + new Action(SendOnAdventureAction.name, args), + new Action(ClickButtonAction.name, { ...args, selector: '.adventureSendButton button', }), - new Command(CompleteTaskAction.name, args), + new Action(CompleteTaskAction.name, args), ]); } } diff --git a/src/Task/SendResourcesTask.ts b/src/Task/SendResourcesTask.ts index 2dbcc62..2091aa9 100644 --- a/src/Task/SendResourcesTask.ts +++ b/src/Task/SendResourcesTask.ts @@ -1,4 +1,3 @@ -import { Args } from '../Command'; import { Task } from '../Queue/TaskQueue'; import { TaskController, registerTask, ActionDefinition } from './TaskController'; import { GoToPageAction } from '../Action/GoToPageAction'; @@ -7,6 +6,7 @@ import { path } from '../utils'; import { SendResourcesAction } from '../Action/SendResourcesAction'; import { ClickButtonAction } from '../Action/ClickButtonAction'; import { scanAllVillagesBundle } from './ActionBundles'; +import { Args } from '../Args'; @registerTask export class SendResourcesTask extends TaskController { diff --git a/src/Task/TaskController.ts b/src/Task/TaskController.ts index a583c72..8ce3e80 100644 --- a/src/Task/TaskController.ts +++ b/src/Task/TaskController.ts @@ -1,7 +1,8 @@ import { Task } from '../Queue/TaskQueue'; import { Scheduler } from '../Scheduler'; -import { Args, Command } from '../Command'; import { CompleteTaskAction } from '../Action/CompleteTaskAction'; +import { Action } from '../Queue/ActionQueue'; +import { Args } from '../Args'; const taskMap: { [name: string]: Function | undefined } = {}; @@ -38,11 +39,11 @@ export class TaskController { private createCommands(task: Task) { const args: Args = { ...task.args, taskId: task.id }; - const commands: Array = []; + const commands: Array = []; 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; } } diff --git a/src/Task/TrainTroopTask.ts b/src/Task/TrainTroopTask.ts index 25cb926..1730127 100644 --- a/src/Task/TrainTroopTask.ts +++ b/src/Task/TrainTroopTask.ts @@ -1,10 +1,11 @@ -import { Args, Command } from '../Command'; import { Task } from '../Queue/TaskQueue'; import { TaskController, registerTask } from './TaskController'; import { GoToPageAction } from '../Action/GoToPageAction'; import { CompleteTaskAction } from '../Action/CompleteTaskAction'; import { TrainTrooperAction } from '../Action/TrainTrooperAction'; import { path } from '../utils'; +import { Action } from '../Queue/ActionQueue'; +import { Args } from '../Args'; @registerTask export class TrainTroopTask extends TaskController { @@ -21,9 +22,9 @@ export class TrainTroopTask extends TaskController { const pagePath = path('/build.php', pathArgs); this.scheduler.scheduleActions([ - new Command(GoToPageAction.name, { ...args, path: pagePath }), - new Command(TrainTrooperAction.name, args), - new Command(CompleteTaskAction.name, args), + new Action(GoToPageAction.name, { ...args, path: pagePath }), + new Action(TrainTrooperAction.name, args), + new Action(CompleteTaskAction.name, args), ]); } } diff --git a/src/Task/UpdateResourceContracts.ts b/src/Task/UpdateResourceContracts.ts index 95861fb..6a2b2d1 100644 --- a/src/Task/UpdateResourceContracts.ts +++ b/src/Task/UpdateResourceContracts.ts @@ -1,4 +1,3 @@ -import { Args, Command } from '../Command'; import { Task } from '../Queue/TaskQueue'; import { TaskController, registerTask } from './TaskController'; import { GoToPageAction } from '../Action/GoToPageAction'; @@ -6,29 +5,31 @@ import { path } from '../utils'; import { UpgradeBuildingTask } from './UpgradeBuildingTask'; import { UpdateBuildingTaskResourcesAction } from '../Action/UpdateBuildingTaskResourcesAction'; import { CompleteTaskAction } from '../Action/CompleteTaskAction'; +import { Action } from '../Queue/ActionQueue'; +import { Args } from '../Args'; @registerTask export class UpdateResourceContracts extends TaskController { async run(task: Task) { const args: Args = { ...task.args, taskId: task.id }; - const actions: Array = []; + const actions: Array = []; const tasks = this.scheduler.getTaskItems(); for (let task of tasks) { const { villageId, buildId } = task.args; if (task.name === UpgradeBuildingTask.name && villageId && buildId) { actions.push( - new Command(GoToPageAction.name, { + new Action(GoToPageAction.name, { ...args, 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); } diff --git a/src/Task/UpgradeBuildingTask.ts b/src/Task/UpgradeBuildingTask.ts index 46a6b67..8bfd3ff 100644 --- a/src/Task/UpgradeBuildingTask.ts +++ b/src/Task/UpgradeBuildingTask.ts @@ -1,28 +1,29 @@ import { UpgradeBuildingAction } from '../Action/UpgradeBuildingAction'; -import { Args, Command } from '../Command'; import { Task } from '../Queue/TaskQueue'; import { TaskController, registerTask } from './TaskController'; import { GoToPageAction } from '../Action/GoToPageAction'; import { CheckBuildingRemainingTimeAction } from '../Action/CheckBuildingRemainingTimeAction'; import { CompleteTaskAction } from '../Action/CompleteTaskAction'; import { path } from '../utils'; +import { Action } from '../Queue/ActionQueue'; +import { Args } from '../Args'; @registerTask export class UpgradeBuildingTask extends TaskController { async run(task: Task) { const args: Args = { ...task.args, taskId: task.id }; this.scheduler.scheduleActions([ - new Command(GoToPageAction.name, { + new Action(GoToPageAction.name, { ...args, path: path('/dorf1.php', { newdid: args.villageId }), }), - new Command(CheckBuildingRemainingTimeAction.name, args), - new Command(GoToPageAction.name, { + new Action(CheckBuildingRemainingTimeAction.name, args), + new Action(GoToPageAction.name, { ...args, path: path('/build.php', { newdid: args.villageId, id: args.buildId }), }), - new Command(UpgradeBuildingAction.name, args), - new Command(CompleteTaskAction.name, args), + new Action(UpgradeBuildingAction.name, args), + new Action(CompleteTaskAction.name, args), ]); } }