Refactoring
This commit is contained in:
@ -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),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
@ -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),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
@ -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 {
|
||||
|
@ -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),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
@ -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 {
|
||||
|
@ -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<Command> = [];
|
||||
const commands: Array<Action> = [];
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@ -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),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
@ -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<Command> = [];
|
||||
const actions: Array<Action> = [];
|
||||
|
||||
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);
|
||||
}
|
||||
|
@ -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),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user