Improve build tasks

This commit is contained in:
Anton Vakhrushev 2020-05-02 13:27:26 +03:00
parent ed2102ce24
commit 53b325eee2
9 changed files with 55 additions and 52 deletions

View File

@ -4,6 +4,7 @@ import { grabActiveVillageId } from '../Page/VillageBlock';
import { aroundMinutes } from '../utils';
import { Args } from '../Queue/Args';
import { Task } from '../Queue/TaskProvider';
import { VillageStorage } from '../Storage/VillageStorage';
const actionMap: { [name: string]: Function | undefined } = {};
@ -39,4 +40,12 @@ export class ActionController {
throw new TryLaterError(aroundMinutes(1), 'Not same village');
}
}
ensureBuildingQueueIsEmpty() {
const storage = new VillageStorage(grabActiveVillageId());
const info = storage.getBuildingQueueInfo();
if (info.seconds > 0) {
throw new TryLaterError(info.seconds + 1, 'Building queue is full');
}
}
}

View File

@ -10,6 +10,7 @@ export class BuildBuildingAction extends ActionController {
async run(args: Args, task: Task): Promise<any> {
try {
this.ensureSameVillage(args, task);
this.ensureBuildingQueueIsEmpty();
const buildTypeId = args.buildTypeId || err('Undefined build type id');
clickBuildButton(buildTypeId);
} catch (e) {

View File

@ -6,7 +6,7 @@ import { Task } from '../Queue/TaskProvider';
import { clickResearchButton } from '../Page/BuildingPage/ForgePage';
@registerAction
export class ResearchAction extends ActionController {
export class ForgeImprovementAction extends ActionController {
async run(args: Args, task: Task): Promise<any> {
try {
this.ensureSameVillage(args, task);

View File

@ -10,6 +10,7 @@ export class UpgradeBuildingAction extends ActionController {
async run(args: Args, task: Task): Promise<any> {
try {
this.ensureSameVillage(args, task);
this.ensureBuildingQueueIsEmpty();
clickUpgradeButton();
} catch (e) {
if (e instanceof GrabError) {

View File

@ -69,7 +69,7 @@
<td></td>
</tr>
<tr class="required-line">
<td class="right">След:</td>
<td class="right">След. задача:</td>
<td class="right">
<resource
:value="villageState.required.resources.lumber"
@ -106,7 +106,7 @@
<td></td>
</tr>
<tr class="required-line">
<td class="right">Баланс:</td>
<td class="right">Баланс задачи:</td>
<td class="right">
<resource :value="villageState.required.balance.lumber"></resource>
</td>

View File

@ -14,7 +14,7 @@ import { BuildingPageAttributes, isForgePage, isMarketSendResourcesPage } from '
import { createTrainTroopButtons } from './BuildingPage/TrooperPage';
import { createSendResourcesButton } from './BuildingPage/MarketPage';
import { createResearchButtons } from './BuildingPage/ForgePage';
import { ResearchTask } from '../Task/ResearchTask';
import { ForgeImprovementTask } from '../Task/ForgeImprovementTask';
export class BuildingPageController {
private scheduler: Scheduler;
@ -107,7 +107,7 @@ export class BuildingPageController {
private onResearch(resources: Resources, unitId: number) {
const villageId = grabActiveVillageId();
this.scheduler.scheduleTask(ResearchTask.name, {
this.scheduler.scheduleTask(ForgeImprovementTask.name, {
villageId,
buildTypeId: this.attributes.buildTypeId,
buildId: this.attributes.buildId,

View File

@ -1,29 +1,27 @@
import { BuildBuildingAction } from '../Action/BuildBuildingAction';
import { CheckBuildingRemainingTimeAction } from '../Action/CheckBuildingRemainingTimeAction';
import { CompleteTaskAction } from '../Action/CompleteTaskAction';
import { GoToPageAction } from '../Action/GoToPageAction';
import { path } from '../utils';
import { TaskController, registerTask } from './TaskController';
import { Action } from '../Queue/ActionQueue';
import { Args } from '../Queue/Args';
import { TaskController, registerTask, ActionDefinition } from './TaskController';
import { Task } from '../Queue/TaskProvider';
@registerTask
export class BuildBuildingTask extends TaskController {
async run(task: Task) {
const args: Args = { ...task.args, taskId: task.id };
this.scheduler.scheduleActions([
new Action(GoToPageAction.name, {
...args,
defineActions(task: Task): Array<ActionDefinition> {
const args = task.args;
return [
[
GoToPageAction.name,
{
path: path('/dorf1.php', { newdid: args.villageId }),
}),
new Action(CheckBuildingRemainingTimeAction.name, args),
new Action(GoToPageAction.name, {
...args,
},
],
[
GoToPageAction.name,
{
path: path('/build.php', { newdid: args.villageId, id: args.buildId, category: args.categoryId }),
}),
new Action(BuildBuildingAction.name, args),
new Action(CompleteTaskAction.name, args),
]);
},
],
[BuildBuildingAction.name],
];
}
}

View File

@ -1,15 +1,11 @@
import { TaskController, registerTask, ActionDefinition } 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 { ResearchAction } from '../Action/ResearchAction';
import { ForgeImprovementAction } from '../Action/ForgeImprovementAction';
@registerTask
export class ResearchTask extends TaskController {
export class ForgeImprovementTask extends TaskController {
defineActions(task: Task): Array<ActionDefinition> {
const args = task.args;
@ -19,6 +15,6 @@ export class ResearchTask extends TaskController {
id: args.buildId || undefined,
};
return [[GoToPageAction.name, { ...args, path: path('/build.php', pathArgs) }], [ResearchAction.name]];
return [[GoToPageAction.name, { ...args, path: path('/build.php', pathArgs) }], [ForgeImprovementAction.name]];
}
}

View File

@ -1,29 +1,27 @@
import { UpgradeBuildingAction } from '../Action/UpgradeBuildingAction';
import { TaskController, registerTask } from './TaskController';
import { TaskController, registerTask, ActionDefinition } from './TaskController';
import { GoToPageAction } from '../Action/GoToPageAction';
import { CheckBuildingRemainingTimeAction } from '../Action/CheckBuildingRemainingTimeAction';
import { CompleteTaskAction } from '../Action/CompleteTaskAction';
import { path } from '../utils';
import { Action } from '../Queue/ActionQueue';
import { Args } from '../Queue/Args';
import { Task } from '../Queue/TaskProvider';
@registerTask
export class UpgradeBuildingTask extends TaskController {
async run(task: Task) {
const args: Args = { ...task.args, taskId: task.id };
this.scheduler.scheduleActions([
new Action(GoToPageAction.name, {
...args,
defineActions(task: Task): Array<ActionDefinition> {
const args = task.args;
return [
[
GoToPageAction.name,
{
path: path('/dorf1.php', { newdid: args.villageId }),
}),
new Action(CheckBuildingRemainingTimeAction.name, args),
new Action(GoToPageAction.name, {
...args,
},
],
[
GoToPageAction.name,
{
path: path('/build.php', { newdid: args.villageId, id: args.buildId }),
}),
new Action(UpgradeBuildingAction.name, args),
new Action(CompleteTaskAction.name, args),
]);
},
],
[UpgradeBuildingAction.name],
];
}
}