Improve send resources task
Reduce go to page actions
This commit is contained in:
parent
aa2c3c0fc0
commit
9e59c7b7cc
@ -1,5 +1,5 @@
|
|||||||
import { Scheduler } from '../Scheduler';
|
import { Scheduler } from '../Scheduler';
|
||||||
import { AbortTaskError, TryLaterError } from '../Errors';
|
import { taskError, TryLaterError } from '../Errors';
|
||||||
import { grabActiveVillageId } from '../Page/VillageBlock';
|
import { grabActiveVillageId } from '../Page/VillageBlock';
|
||||||
import { aroundMinutes } from '../utils';
|
import { aroundMinutes } from '../utils';
|
||||||
import { Args } from '../Queue/Args';
|
import { Args } from '../Queue/Args';
|
||||||
@ -26,10 +26,6 @@ export function createActionHandler(
|
|||||||
return new constructor(scheduler, villageStateRepository);
|
return new constructor(scheduler, villageStateRepository);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function taskError(msg: string): never {
|
|
||||||
throw new AbortTaskError(msg);
|
|
||||||
}
|
|
||||||
|
|
||||||
export class ActionController {
|
export class ActionController {
|
||||||
protected scheduler: Scheduler;
|
protected scheduler: Scheduler;
|
||||||
protected villageStateRepository: VillageStateRepository;
|
protected villageStateRepository: VillageStateRepository;
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { ActionController, taskError, registerAction } from './ActionController';
|
import { ActionController, registerAction } from './ActionController';
|
||||||
import { GrabError, TryLaterError } from '../Errors';
|
import { GrabError, taskError, TryLaterError } from '../Errors';
|
||||||
import { clickBuildButton } from '../Page/BuildingPage/BuildingPage';
|
import { clickBuildButton } from '../Page/BuildingPage/BuildingPage';
|
||||||
import { aroundMinutes } from '../utils';
|
import { aroundMinutes } from '../utils';
|
||||||
import { Args } from '../Queue/Args';
|
import { Args } from '../Queue/Args';
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { ActionController, taskError, registerAction } from './ActionController';
|
import { ActionController, registerAction } from './ActionController';
|
||||||
import { GrabError, TryLaterError } from '../Errors';
|
import { GrabError, taskError, TryLaterError } from '../Errors';
|
||||||
import { aroundMinutes } from '../utils';
|
import { aroundMinutes } from '../utils';
|
||||||
import { Args } from '../Queue/Args';
|
import { Args } from '../Queue/Args';
|
||||||
import { Task } from '../Queue/TaskProvider';
|
import { Task } from '../Queue/TaskProvider';
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { ActionController, taskError, registerAction } from './ActionController';
|
import { ActionController, registerAction } from './ActionController';
|
||||||
import { TryLaterError } from '../Errors';
|
import { taskError, TryLaterError } from '../Errors';
|
||||||
import { Resources } from '../Core/Resources';
|
import { Resources } from '../Core/Resources';
|
||||||
import { Coordinates } from '../Core/Village';
|
import { Coordinates } from '../Core/Village';
|
||||||
import { aroundMinutes, timestamp } from '../utils';
|
import { aroundMinutes, timestamp } from '../utils';
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { ActionController, taskError, registerAction } from './ActionController';
|
import { ActionController, registerAction } from './ActionController';
|
||||||
import { TryLaterError } from '../Errors';
|
import { taskError, TryLaterError } from '../Errors';
|
||||||
import { aroundMinutes, randomInRange } from '../utils';
|
import { aroundMinutes, randomInRange } from '../utils';
|
||||||
import { Args } from '../Queue/Args';
|
import { Args } from '../Queue/Args';
|
||||||
import { Task } from '../Queue/TaskProvider';
|
import { Task } from '../Queue/TaskProvider';
|
||||||
|
@ -36,3 +36,8 @@ export class Village {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export type VillageList = Array<Village>;
|
export type VillageList = Array<Village>;
|
||||||
|
|
||||||
|
// export interface VillageSettings {
|
||||||
|
// id: number;
|
||||||
|
//
|
||||||
|
// }
|
||||||
|
@ -35,3 +35,7 @@ export class TryLaterError extends Error {
|
|||||||
Object.setPrototypeOf(this, TryLaterError.prototype);
|
Object.setPrototypeOf(this, TryLaterError.prototype);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function taskError(msg: string): never {
|
||||||
|
throw new AbortTaskError(msg);
|
||||||
|
}
|
||||||
|
@ -4,22 +4,30 @@ import { GoToPageAction } from '../Action/GoToPageAction';
|
|||||||
import { MARKET_ID } from '../Core/Buildings';
|
import { MARKET_ID } from '../Core/Buildings';
|
||||||
import { path } from '../Helpers/Path';
|
import { path } from '../Helpers/Path';
|
||||||
|
|
||||||
|
export function goToResourceViewPage(villageId: number): ActionDefinition {
|
||||||
|
return [
|
||||||
|
GoToPageAction.name,
|
||||||
|
{
|
||||||
|
path: path('/dorf1.php', { newdid: villageId }),
|
||||||
|
},
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
export function goToMarketSendResourcesPage(villageId: number): ActionDefinition {
|
||||||
|
return [
|
||||||
|
GoToPageAction.name,
|
||||||
|
{
|
||||||
|
path: path('/build.php', { newdid: villageId, gid: MARKET_ID, t: 5 }),
|
||||||
|
},
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
export function scanAllVillagesBundle(): Array<ActionDefinition> {
|
export function scanAllVillagesBundle(): Array<ActionDefinition> {
|
||||||
const actions: Array<ActionDefinition> = [];
|
const actions: Array<ActionDefinition> = [];
|
||||||
const villages = grabVillageList();
|
const villages = grabVillageList();
|
||||||
for (let village of villages) {
|
for (let village of villages) {
|
||||||
actions.push([
|
actions.push(goToResourceViewPage(village.id));
|
||||||
GoToPageAction.name,
|
actions.push(goToMarketSendResourcesPage(village.id));
|
||||||
{
|
|
||||||
path: path('/dorf1.php', { newdid: village.id }),
|
|
||||||
},
|
|
||||||
]);
|
|
||||||
actions.push([
|
|
||||||
GoToPageAction.name,
|
|
||||||
{
|
|
||||||
path: path('/build.php', { newdid: village.id, gid: MARKET_ID, t: 5 }),
|
|
||||||
},
|
|
||||||
]);
|
|
||||||
}
|
}
|
||||||
return actions;
|
return actions;
|
||||||
}
|
}
|
||||||
|
@ -1,35 +1,24 @@
|
|||||||
import { TaskController, ActionDefinition } from './TaskController';
|
import { TaskController, ActionDefinition } from './TaskController';
|
||||||
import { GoToPageAction } from '../Action/GoToPageAction';
|
|
||||||
import { CompleteTaskAction } from '../Action/CompleteTaskAction';
|
|
||||||
import { SendResourcesAction } from '../Action/SendResourcesAction';
|
import { SendResourcesAction } from '../Action/SendResourcesAction';
|
||||||
import { ClickButtonAction } from '../Action/ClickButtonAction';
|
import { ClickButtonAction } from '../Action/ClickButtonAction';
|
||||||
import { scanAllVillagesBundle } from './ActionBundles';
|
import { goToMarketSendResourcesPage, goToResourceViewPage } from './ActionBundles';
|
||||||
import { Args } from '../Queue/Args';
|
|
||||||
import { Task } from '../Queue/TaskProvider';
|
import { Task } from '../Queue/TaskProvider';
|
||||||
import { path } from '../Helpers/Path';
|
|
||||||
import { registerTask } from './TaskMap';
|
import { registerTask } from './TaskMap';
|
||||||
|
import { taskError } from '../Errors';
|
||||||
|
|
||||||
@registerTask()
|
@registerTask()
|
||||||
export class SendResourcesTask extends TaskController {
|
export class SendResourcesTask extends TaskController {
|
||||||
defineActions(task: Task): Array<ActionDefinition> {
|
defineActions(task: Task): Array<ActionDefinition> {
|
||||||
return [...scanAllVillagesBundle(), ...this.sendResourcesActions(task.args)];
|
const targetVillageId = task.args.targetVillageId || taskError('Empty target village id');
|
||||||
}
|
const villageId = task.args.villageId || taskError('Empty village id');
|
||||||
|
|
||||||
sendResourcesActions(args: Args): Array<ActionDefinition> {
|
|
||||||
const pathArgs = {
|
|
||||||
newdid: args.villageId,
|
|
||||||
gid: args.buildTypeId || undefined,
|
|
||||||
id: args.buildId || undefined,
|
|
||||||
t: args.tabId,
|
|
||||||
};
|
|
||||||
|
|
||||||
const pagePath = path('/build.php', pathArgs);
|
|
||||||
|
|
||||||
return [
|
return [
|
||||||
[GoToPageAction.name, { path: pagePath }],
|
goToResourceViewPage(targetVillageId),
|
||||||
|
goToMarketSendResourcesPage(targetVillageId),
|
||||||
|
goToResourceViewPage(villageId),
|
||||||
|
goToMarketSendResourcesPage(villageId),
|
||||||
[SendResourcesAction.name],
|
[SendResourcesAction.name],
|
||||||
[ClickButtonAction.name, { selector: '#enabledButton.green.sendRessources' }],
|
[ClickButtonAction.name, { selector: '#enabledButton.green.sendRessources' }],
|
||||||
[CompleteTaskAction.name],
|
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user