Improve send resources task
Reduce go to page actions
This commit is contained in:
@ -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],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user