Improve resource scan

Walk only unique paths
This commit is contained in:
2020-05-04 11:04:29 +03:00
parent d350603c48
commit 789c5aba3e
20 changed files with 113 additions and 58 deletions

View File

@ -1,8 +1,8 @@
import { ActionDefinition } from './TaskController';
import { grabVillageList } from '../Page/VillageBlock';
import { GoToPageAction } from '../Action/GoToPageAction';
import { path } from '../utils';
import { MARKET_ID } from '../Core/Buildings';
import { path } from '../Helpers/Path';
export function scanAllVillagesBundle(): Array<ActionDefinition> {
const actions: Array<ActionDefinition> = [];

View File

@ -2,11 +2,11 @@ import { TaskController, registerTask } from './TaskController';
import { GoToPageAction } from '../Action/GoToPageAction';
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 '../Queue/Args';
import { Task } from '../Queue/TaskProvider';
import { path } from '../Helpers/Path';
@registerTask
export class BalanceHeroResourcesTask extends TaskController {

View File

@ -1,8 +1,8 @@
import { BuildBuildingAction } from '../Action/BuildBuildingAction';
import { GoToPageAction } from '../Action/GoToPageAction';
import { path } from '../utils';
import { TaskController, registerTask, ActionDefinition } from './TaskController';
import { Task } from '../Queue/TaskProvider';
import { path } from '../Helpers/Path';
@registerTask
export class BuildBuildingTask extends TaskController {

View File

@ -1,8 +1,8 @@
import { TaskController, registerTask, ActionDefinition } from './TaskController';
import { GoToPageAction } from '../Action/GoToPageAction';
import { path } from '../utils';
import { Task } from '../Queue/TaskProvider';
import { ForgeImprovementAction } from '../Action/ForgeImprovementAction';
import { path } from '../Helpers/Path';
@registerTask
export class ForgeImprovementTask extends TaskController {

View File

@ -1,8 +1,8 @@
import { TaskController, registerTask, ActionDefinition } from './TaskController';
import { GoToPageAction } from '../Action/GoToPageAction';
import { path } from '../utils';
import { UpgradeResourceToLevel } from '../Action/UpgradeResourceToLevel';
import { Task } from '../Queue/TaskProvider';
import { path } from '../Helpers/Path';
@registerTask
export class ResourcesToLevel extends TaskController {

View File

@ -3,10 +3,10 @@ import { GoToPageAction } from '../Action/GoToPageAction';
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 '../Queue/Args';
import { Task } from '../Queue/TaskProvider';
import { path } from '../Helpers/Path';
@registerTask
export class SendOnAdventureTask extends TaskController {

View File

@ -1,12 +1,12 @@
import { TaskController, registerTask, ActionDefinition } from './TaskController';
import { GoToPageAction } from '../Action/GoToPageAction';
import { CompleteTaskAction } from '../Action/CompleteTaskAction';
import { path } from '../utils';
import { SendResourcesAction } from '../Action/SendResourcesAction';
import { ClickButtonAction } from '../Action/ClickButtonAction';
import { scanAllVillagesBundle } from './ActionBundles';
import { Args } from '../Queue/Args';
import { Task } from '../Queue/TaskProvider';
import { path } from '../Helpers/Path';
@registerTask
export class SendResourcesTask extends TaskController {

View File

@ -2,10 +2,10 @@ import { registerTask, TaskController } 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 { path } from '../Helpers/Path';
@registerTask
export class TrainTroopTask extends TaskController {

View File

@ -1,33 +1,36 @@
import { TaskController, registerTask, ActionDefinition } from './TaskController';
import { GoToPageAction } from '../Action/GoToPageAction';
import { path } from '../utils';
import { UpgradeBuildingTask } from './UpgradeBuildingTask';
import { ImmutableTaskList, Task } from '../Queue/TaskProvider';
import { ForgeImprovementTask } from './ForgeImprovementTask';
import { path, PathList, uniqPaths } from '../Helpers/Path';
@registerTask
export class UpdateResourceContracts extends TaskController {
defineActions(task: Task): Array<ActionDefinition> {
const tasks = this.scheduler.getTaskItems();
return [...this.walkUpgradeTasks(tasks), ...this.walkImprovementTask(tasks)];
const paths = [...this.walkUpgradeTasks(tasks), ...this.walkImprovementTask(tasks)];
const uniq = uniqPaths(paths);
return uniq.map(p => [GoToPageAction.name, { path: path(p.name, p.query) }]);
}
private walkUpgradeTasks(tasks: ImmutableTaskList): Array<ActionDefinition> {
private walkUpgradeTasks(tasks: ImmutableTaskList): PathList {
return tasks
.filter(t => t.name === UpgradeBuildingTask.name && t.args.villageId && t.args.buildId)
.map(t => [
GoToPageAction.name,
{ path: path('/build.php', { newdid: t.args.villageId, id: t.args.buildId }) },
]);
.map(t => ({
name: '/build.php',
query: { newdid: t.args.villageId, id: t.args.buildId },
}));
}
private walkImprovementTask(tasks: ImmutableTaskList): Array<ActionDefinition> {
private walkImprovementTask(tasks: ImmutableTaskList): PathList {
return tasks
.filter(t => t.name === ForgeImprovementTask.name && t.args.villageId && t.args.buildId)
.map(t => [
GoToPageAction.name,
{ path: path('/build.php', { newdid: t.args.villageId, id: t.args.buildId }) },
]);
.map(t => ({
name: '/build.php',
query: { newdid: t.args.villageId, id: t.args.buildId },
}));
}
}

View File

@ -1,8 +1,8 @@
import { UpgradeBuildingAction } from '../Action/UpgradeBuildingAction';
import { TaskController, registerTask, ActionDefinition } from './TaskController';
import { GoToPageAction } from '../Action/GoToPageAction';
import { path } from '../utils';
import { Task } from '../Queue/TaskProvider';
import { path } from '../Helpers/Path';
@registerTask
export class UpgradeBuildingTask extends TaskController {