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 { AbortTaskError, TryLaterError } from '../Errors';
|
||||
import { taskError, TryLaterError } from '../Errors';
|
||||
import { grabActiveVillageId } from '../Page/VillageBlock';
|
||||
import { aroundMinutes } from '../utils';
|
||||
import { Args } from '../Queue/Args';
|
||||
@ -26,10 +26,6 @@ export function createActionHandler(
|
||||
return new constructor(scheduler, villageStateRepository);
|
||||
}
|
||||
|
||||
export function taskError(msg: string): never {
|
||||
throw new AbortTaskError(msg);
|
||||
}
|
||||
|
||||
export class ActionController {
|
||||
protected scheduler: Scheduler;
|
||||
protected villageStateRepository: VillageStateRepository;
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { ActionController, taskError, registerAction } from './ActionController';
|
||||
import { GrabError, TryLaterError } from '../Errors';
|
||||
import { ActionController, registerAction } from './ActionController';
|
||||
import { GrabError, taskError, TryLaterError } from '../Errors';
|
||||
import { clickBuildButton } from '../Page/BuildingPage/BuildingPage';
|
||||
import { aroundMinutes } from '../utils';
|
||||
import { Args } from '../Queue/Args';
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { ActionController, taskError, registerAction } from './ActionController';
|
||||
import { GrabError, TryLaterError } from '../Errors';
|
||||
import { ActionController, registerAction } from './ActionController';
|
||||
import { GrabError, taskError, TryLaterError } from '../Errors';
|
||||
import { aroundMinutes } from '../utils';
|
||||
import { Args } from '../Queue/Args';
|
||||
import { Task } from '../Queue/TaskProvider';
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { ActionController, taskError, registerAction } from './ActionController';
|
||||
import { TryLaterError } from '../Errors';
|
||||
import { ActionController, registerAction } from './ActionController';
|
||||
import { taskError, TryLaterError } from '../Errors';
|
||||
import { Resources } from '../Core/Resources';
|
||||
import { Coordinates } from '../Core/Village';
|
||||
import { aroundMinutes, timestamp } from '../utils';
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { ActionController, taskError, registerAction } from './ActionController';
|
||||
import { TryLaterError } from '../Errors';
|
||||
import { ActionController, registerAction } from './ActionController';
|
||||
import { taskError, TryLaterError } from '../Errors';
|
||||
import { aroundMinutes, randomInRange } from '../utils';
|
||||
import { Args } from '../Queue/Args';
|
||||
import { Task } from '../Queue/TaskProvider';
|
||||
|
@ -36,3 +36,8 @@ export class 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);
|
||||
}
|
||||
}
|
||||
|
||||
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 { 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> {
|
||||
const actions: Array<ActionDefinition> = [];
|
||||
const villages = grabVillageList();
|
||||
for (let village of villages) {
|
||||
actions.push([
|
||||
GoToPageAction.name,
|
||||
{
|
||||
path: path('/dorf1.php', { newdid: village.id }),
|
||||
},
|
||||
]);
|
||||
actions.push([
|
||||
GoToPageAction.name,
|
||||
{
|
||||
path: path('/build.php', { newdid: village.id, gid: MARKET_ID, t: 5 }),
|
||||
},
|
||||
]);
|
||||
actions.push(goToResourceViewPage(village.id));
|
||||
actions.push(goToMarketSendResourcesPage(village.id));
|
||||
}
|
||||
return actions;
|
||||
}
|
||||
|
@ -1,35 +1,24 @@
|
||||
import { TaskController, ActionDefinition } from './TaskController';
|
||||
import { GoToPageAction } from '../Action/GoToPageAction';
|
||||
import { CompleteTaskAction } from '../Action/CompleteTaskAction';
|
||||
import { SendResourcesAction } from '../Action/SendResourcesAction';
|
||||
import { ClickButtonAction } from '../Action/ClickButtonAction';
|
||||
import { scanAllVillagesBundle } from './ActionBundles';
|
||||
import { Args } from '../Queue/Args';
|
||||
import { goToMarketSendResourcesPage, goToResourceViewPage } from './ActionBundles';
|
||||
import { Task } from '../Queue/TaskProvider';
|
||||
import { path } from '../Helpers/Path';
|
||||
import { registerTask } from './TaskMap';
|
||||
import { taskError } from '../Errors';
|
||||
|
||||
@registerTask()
|
||||
export class SendResourcesTask extends TaskController {
|
||||
defineActions(task: Task): Array<ActionDefinition> {
|
||||
return [...scanAllVillagesBundle(), ...this.sendResourcesActions(task.args)];
|
||||
}
|
||||
|
||||
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);
|
||||
const targetVillageId = task.args.targetVillageId || taskError('Empty target village id');
|
||||
const villageId = task.args.villageId || taskError('Empty village id');
|
||||
|
||||
return [
|
||||
[GoToPageAction.name, { path: pagePath }],
|
||||
goToResourceViewPage(targetVillageId),
|
||||
goToMarketSendResourcesPage(targetVillageId),
|
||||
goToResourceViewPage(villageId),
|
||||
goToMarketSendResourcesPage(villageId),
|
||||
[SendResourcesAction.name],
|
||||
[ClickButtonAction.name, { selector: '#enabledButton.green.sendRessources' }],
|
||||
[CompleteTaskAction.name],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user