Add research tasks
This commit is contained in:
24
src/Task/ResearchTask.ts
Normal file
24
src/Task/ResearchTask.ts
Normal file
@ -0,0 +1,24 @@
|
||||
import { TaskController, registerTask, ActionDefinition } 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 '../Queue/Args';
|
||||
import { Task } from '../Queue/TaskProvider';
|
||||
import { ResearchAction } from '../Action/ResearchAction';
|
||||
|
||||
@registerTask
|
||||
export class ResearchTask extends TaskController {
|
||||
defineActions(task: Task): Array<ActionDefinition> {
|
||||
const args = task.args;
|
||||
|
||||
const pathArgs = {
|
||||
newdid: args.villageId,
|
||||
gid: args.buildTypeId || undefined,
|
||||
id: args.buildId || undefined,
|
||||
};
|
||||
|
||||
return [[GoToPageAction.name, { ...args, path: path('/build.php', pathArgs) }], [ResearchAction.name]];
|
||||
}
|
||||
}
|
@ -1,10 +1,7 @@
|
||||
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 '../Queue/Args';
|
||||
import { Task } from '../Queue/TaskProvider';
|
||||
|
||||
@registerTask
|
||||
@ -12,7 +9,7 @@ export class ResourcesToLevel extends TaskController {
|
||||
defineActions(task: Task): Array<ActionDefinition> {
|
||||
return [
|
||||
[GoToPageAction.name, { path: path('/dorf1.php', { newdid: task.args.villageId }) }],
|
||||
[UpgradeResourceToLevel.name, {}],
|
||||
[UpgradeResourceToLevel.name],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
@ -26,9 +26,9 @@ export class SendResourcesTask extends TaskController {
|
||||
|
||||
return [
|
||||
[GoToPageAction.name, { path: pagePath }],
|
||||
[SendResourcesAction.name, {}],
|
||||
[SendResourcesAction.name],
|
||||
[ClickButtonAction.name, { selector: '#enabledButton.green.sendRessources' }],
|
||||
[CompleteTaskAction.name, {}],
|
||||
[CompleteTaskAction.name],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
@ -19,7 +19,7 @@ export function createTaskHandler(name: string, scheduler: Scheduler): TaskContr
|
||||
return new constructor(scheduler);
|
||||
}
|
||||
|
||||
export type ActionDefinition = [string, Args];
|
||||
export type ActionDefinition = [string] | [string, Args];
|
||||
|
||||
export class TaskController {
|
||||
protected scheduler: Scheduler;
|
||||
@ -41,7 +41,11 @@ export class TaskController {
|
||||
const args: Args = { ...task.args, taskId: task.id };
|
||||
const commands: Array<Action> = [];
|
||||
for (let def of this.defineActions(task)) {
|
||||
commands.push(new Action(def[0], { ...args, ...def[1] }));
|
||||
if (def.length === 1) {
|
||||
commands.push(new Action(def[0], args));
|
||||
} else {
|
||||
commands.push(new Action(def[0], { ...args, ...def[1] }));
|
||||
}
|
||||
}
|
||||
commands.push(new Action(CompleteTaskAction.name, args));
|
||||
return commands;
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { TaskController, registerTask } from './TaskController';
|
||||
import { registerTask, TaskController } from './TaskController';
|
||||
import { GoToPageAction } from '../Action/GoToPageAction';
|
||||
import { CompleteTaskAction } from '../Action/CompleteTaskAction';
|
||||
import { TrainTrooperAction } from '../Action/TrainTrooperAction';
|
||||
@ -19,10 +19,8 @@ export class TrainTroopTask extends TaskController {
|
||||
s: args.sheetId,
|
||||
};
|
||||
|
||||
const pagePath = path('/build.php', pathArgs);
|
||||
|
||||
this.scheduler.scheduleActions([
|
||||
new Action(GoToPageAction.name, { ...args, path: pagePath }),
|
||||
new Action(GoToPageAction.name, { ...args, path: path('/build.php', pathArgs) }),
|
||||
new Action(TrainTrooperAction.name, args),
|
||||
new Action(CompleteTaskAction.name, args),
|
||||
]);
|
||||
|
Reference in New Issue
Block a user