Automatic action resolving with decorators and magic

This commit is contained in:
2020-04-03 11:54:13 +03:00
parent 54fca1f4f4
commit 29485d233d
13 changed files with 92 additions and 111 deletions

View File

@ -2,11 +2,11 @@ import Scheduler from '../Scheduler';
import { Args, Command } from '../Common';
import { Task } from '../Storage/TaskQueue';
import TaskController from './TaskController';
import GoToPageAction from '../Action/GoToPageAction';
import GrabHeroAttributesAction from '../Action/GrabHeroAttributesAction';
import CompleteTaskAction from '../Action/CompleteTaskAction';
import SendOnAdventureAction from '../Action/SendOnAdventureAction';
import ClickButtonAction from '../Action/ClickButtonAction';
import { GoToPageAction } from '../Action/GoToPageAction';
import { GrabHeroAttributesAction } from '../Action/GrabHeroAttributesAction';
import { CompleteTaskAction } from '../Action/CompleteTaskAction';
import { SendOnAdventureAction } from '../Action/SendOnAdventureAction';
import { ClickButtonAction } from '../Action/ClickButtonAction';
export default class SendOnAdventureTask extends TaskController {
static NAME = 'send_on_adventure';
@ -17,25 +17,21 @@ export default class SendOnAdventureTask extends TaskController {
this.scheduler = scheduler;
}
name(): string {
return SendOnAdventureTask.NAME;
}
run(task: Task) {
const args: Args = { ...task.cmd.args, taskId: task.id };
this.scheduler.scheduleActions([
new Command(GoToPageAction.NAME, { ...args, path: 'hero.php' }),
new Command(GrabHeroAttributesAction.NAME, args),
new Command(GoToPageAction.NAME, {
new Command(GoToPageAction.name, { ...args, path: 'hero.php' }),
new Command(GrabHeroAttributesAction.name, args),
new Command(GoToPageAction.name, {
...args,
path: '/hero.php?t=3',
}),
new Command(SendOnAdventureAction.NAME, args),
new Command(ClickButtonAction.NAME, {
new Command(SendOnAdventureAction.name, args),
new Command(ClickButtonAction.name, {
...args,
selector: '.adventureSendButton button',
}),
new Command(CompleteTaskAction.NAME, args),
new Command(CompleteTaskAction.name, args),
]);
}
}

View File

@ -1,6 +1,5 @@
import { Task } from '../Storage/TaskQueue';
export default abstract class TaskController {
abstract name(): string;
abstract run(task: Task);
}

View File

@ -1,11 +1,11 @@
import Scheduler from '../Scheduler';
import UpgradeBuildingAction from '../Action/UpgradeBuildingAction';
import { UpgradeBuildingAction } from '../Action/UpgradeBuildingAction';
import { Args, Command } from '../Common';
import { Task } from '../Storage/TaskQueue';
import TaskController from './TaskController';
import GoToPageAction from '../Action/GoToPageAction';
import CheckBuildingRemainingTimeAction from '../Action/CheckBuildingRemainingTimeAction';
import CompleteTaskAction from '../Action/CompleteTaskAction';
import { GoToPageAction } from '../Action/GoToPageAction';
import { CheckBuildingRemainingTimeAction } from '../Action/CheckBuildingRemainingTimeAction';
import { CompleteTaskAction } from '../Action/CompleteTaskAction';
export default class UpgradeBuildingTask extends TaskController {
static NAME = 'upgrade_building';
@ -16,22 +16,18 @@ export default class UpgradeBuildingTask extends TaskController {
this.scheduler = scheduler;
}
name(): string {
return UpgradeBuildingTask.NAME;
}
run(task: Task) {
console.log('RUN', UpgradeBuildingTask.NAME, 'with', task);
const args: Args = { ...task.cmd.args, taskId: task.id };
this.scheduler.scheduleActions([
new Command(GoToPageAction.NAME, { ...args, path: '/dorf1.php' }),
new Command(CheckBuildingRemainingTimeAction.NAME, args),
new Command(GoToPageAction.NAME, {
new Command(GoToPageAction.name, { ...args, path: '/dorf1.php' }),
new Command(CheckBuildingRemainingTimeAction.name, args),
new Command(GoToPageAction.name, {
...args,
path: '/build.php?id=' + args.id,
}),
new Command(UpgradeBuildingAction.NAME, args),
new Command(CompleteTaskAction.NAME, args),
new Command(UpgradeBuildingAction.name, args),
new Command(CompleteTaskAction.name, args),
]);
}
}