Improve build tasks
This commit is contained in:
parent
ed2102ce24
commit
53b325eee2
@ -4,6 +4,7 @@ import { grabActiveVillageId } from '../Page/VillageBlock';
|
|||||||
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';
|
||||||
|
import { VillageStorage } from '../Storage/VillageStorage';
|
||||||
|
|
||||||
const actionMap: { [name: string]: Function | undefined } = {};
|
const actionMap: { [name: string]: Function | undefined } = {};
|
||||||
|
|
||||||
@ -39,4 +40,12 @@ export class ActionController {
|
|||||||
throw new TryLaterError(aroundMinutes(1), 'Not same village');
|
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');
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,6 +10,7 @@ export class BuildBuildingAction extends ActionController {
|
|||||||
async run(args: Args, task: Task): Promise<any> {
|
async run(args: Args, task: Task): Promise<any> {
|
||||||
try {
|
try {
|
||||||
this.ensureSameVillage(args, task);
|
this.ensureSameVillage(args, task);
|
||||||
|
this.ensureBuildingQueueIsEmpty();
|
||||||
const buildTypeId = args.buildTypeId || err('Undefined build type id');
|
const buildTypeId = args.buildTypeId || err('Undefined build type id');
|
||||||
clickBuildButton(buildTypeId);
|
clickBuildButton(buildTypeId);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
@ -6,7 +6,7 @@ import { Task } from '../Queue/TaskProvider';
|
|||||||
import { clickResearchButton } from '../Page/BuildingPage/ForgePage';
|
import { clickResearchButton } from '../Page/BuildingPage/ForgePage';
|
||||||
|
|
||||||
@registerAction
|
@registerAction
|
||||||
export class ResearchAction extends ActionController {
|
export class ForgeImprovementAction extends ActionController {
|
||||||
async run(args: Args, task: Task): Promise<any> {
|
async run(args: Args, task: Task): Promise<any> {
|
||||||
try {
|
try {
|
||||||
this.ensureSameVillage(args, task);
|
this.ensureSameVillage(args, task);
|
@ -10,6 +10,7 @@ export class UpgradeBuildingAction extends ActionController {
|
|||||||
async run(args: Args, task: Task): Promise<any> {
|
async run(args: Args, task: Task): Promise<any> {
|
||||||
try {
|
try {
|
||||||
this.ensureSameVillage(args, task);
|
this.ensureSameVillage(args, task);
|
||||||
|
this.ensureBuildingQueueIsEmpty();
|
||||||
clickUpgradeButton();
|
clickUpgradeButton();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (e instanceof GrabError) {
|
if (e instanceof GrabError) {
|
||||||
|
@ -69,7 +69,7 @@
|
|||||||
<td></td>
|
<td></td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr class="required-line">
|
<tr class="required-line">
|
||||||
<td class="right">След:</td>
|
<td class="right">След. задача:</td>
|
||||||
<td class="right">
|
<td class="right">
|
||||||
<resource
|
<resource
|
||||||
:value="villageState.required.resources.lumber"
|
:value="villageState.required.resources.lumber"
|
||||||
@ -106,7 +106,7 @@
|
|||||||
<td></td>
|
<td></td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr class="required-line">
|
<tr class="required-line">
|
||||||
<td class="right">Баланс:</td>
|
<td class="right">Баланс задачи:</td>
|
||||||
<td class="right">
|
<td class="right">
|
||||||
<resource :value="villageState.required.balance.lumber"></resource>
|
<resource :value="villageState.required.balance.lumber"></resource>
|
||||||
</td>
|
</td>
|
||||||
|
@ -14,7 +14,7 @@ import { BuildingPageAttributes, isForgePage, isMarketSendResourcesPage } from '
|
|||||||
import { createTrainTroopButtons } from './BuildingPage/TrooperPage';
|
import { createTrainTroopButtons } from './BuildingPage/TrooperPage';
|
||||||
import { createSendResourcesButton } from './BuildingPage/MarketPage';
|
import { createSendResourcesButton } from './BuildingPage/MarketPage';
|
||||||
import { createResearchButtons } from './BuildingPage/ForgePage';
|
import { createResearchButtons } from './BuildingPage/ForgePage';
|
||||||
import { ResearchTask } from '../Task/ResearchTask';
|
import { ForgeImprovementTask } from '../Task/ForgeImprovementTask';
|
||||||
|
|
||||||
export class BuildingPageController {
|
export class BuildingPageController {
|
||||||
private scheduler: Scheduler;
|
private scheduler: Scheduler;
|
||||||
@ -107,7 +107,7 @@ export class BuildingPageController {
|
|||||||
|
|
||||||
private onResearch(resources: Resources, unitId: number) {
|
private onResearch(resources: Resources, unitId: number) {
|
||||||
const villageId = grabActiveVillageId();
|
const villageId = grabActiveVillageId();
|
||||||
this.scheduler.scheduleTask(ResearchTask.name, {
|
this.scheduler.scheduleTask(ForgeImprovementTask.name, {
|
||||||
villageId,
|
villageId,
|
||||||
buildTypeId: this.attributes.buildTypeId,
|
buildTypeId: this.attributes.buildTypeId,
|
||||||
buildId: this.attributes.buildId,
|
buildId: this.attributes.buildId,
|
||||||
|
@ -1,29 +1,27 @@
|
|||||||
import { BuildBuildingAction } from '../Action/BuildBuildingAction';
|
import { BuildBuildingAction } from '../Action/BuildBuildingAction';
|
||||||
import { CheckBuildingRemainingTimeAction } from '../Action/CheckBuildingRemainingTimeAction';
|
|
||||||
import { CompleteTaskAction } from '../Action/CompleteTaskAction';
|
|
||||||
import { GoToPageAction } from '../Action/GoToPageAction';
|
import { GoToPageAction } from '../Action/GoToPageAction';
|
||||||
import { path } from '../utils';
|
import { path } from '../utils';
|
||||||
import { TaskController, registerTask } from './TaskController';
|
import { TaskController, registerTask, ActionDefinition } from './TaskController';
|
||||||
import { Action } from '../Queue/ActionQueue';
|
|
||||||
import { Args } from '../Queue/Args';
|
|
||||||
import { Task } from '../Queue/TaskProvider';
|
import { Task } from '../Queue/TaskProvider';
|
||||||
|
|
||||||
@registerTask
|
@registerTask
|
||||||
export class BuildBuildingTask extends TaskController {
|
export class BuildBuildingTask extends TaskController {
|
||||||
async run(task: Task) {
|
defineActions(task: Task): Array<ActionDefinition> {
|
||||||
const args: Args = { ...task.args, taskId: task.id };
|
const args = task.args;
|
||||||
this.scheduler.scheduleActions([
|
return [
|
||||||
new Action(GoToPageAction.name, {
|
[
|
||||||
...args,
|
GoToPageAction.name,
|
||||||
path: path('/dorf1.php', { newdid: args.villageId }),
|
{
|
||||||
}),
|
path: path('/dorf1.php', { newdid: args.villageId }),
|
||||||
new Action(CheckBuildingRemainingTimeAction.name, args),
|
},
|
||||||
new Action(GoToPageAction.name, {
|
],
|
||||||
...args,
|
[
|
||||||
path: path('/build.php', { newdid: args.villageId, id: args.buildId, category: args.categoryId }),
|
GoToPageAction.name,
|
||||||
}),
|
{
|
||||||
new Action(BuildBuildingAction.name, args),
|
path: path('/build.php', { newdid: args.villageId, id: args.buildId, category: args.categoryId }),
|
||||||
new Action(CompleteTaskAction.name, args),
|
},
|
||||||
]);
|
],
|
||||||
|
[BuildBuildingAction.name],
|
||||||
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,15 +1,11 @@
|
|||||||
import { TaskController, registerTask, ActionDefinition } from './TaskController';
|
import { TaskController, registerTask, ActionDefinition } from './TaskController';
|
||||||
import { GoToPageAction } from '../Action/GoToPageAction';
|
import { GoToPageAction } from '../Action/GoToPageAction';
|
||||||
import { CompleteTaskAction } from '../Action/CompleteTaskAction';
|
|
||||||
import { TrainTrooperAction } from '../Action/TrainTrooperAction';
|
|
||||||
import { path } from '../utils';
|
import { path } from '../utils';
|
||||||
import { Action } from '../Queue/ActionQueue';
|
|
||||||
import { Args } from '../Queue/Args';
|
|
||||||
import { Task } from '../Queue/TaskProvider';
|
import { Task } from '../Queue/TaskProvider';
|
||||||
import { ResearchAction } from '../Action/ResearchAction';
|
import { ForgeImprovementAction } from '../Action/ForgeImprovementAction';
|
||||||
|
|
||||||
@registerTask
|
@registerTask
|
||||||
export class ResearchTask extends TaskController {
|
export class ForgeImprovementTask extends TaskController {
|
||||||
defineActions(task: Task): Array<ActionDefinition> {
|
defineActions(task: Task): Array<ActionDefinition> {
|
||||||
const args = task.args;
|
const args = task.args;
|
||||||
|
|
||||||
@ -19,6 +15,6 @@ export class ResearchTask extends TaskController {
|
|||||||
id: args.buildId || undefined,
|
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]];
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,29 +1,27 @@
|
|||||||
import { UpgradeBuildingAction } from '../Action/UpgradeBuildingAction';
|
import { UpgradeBuildingAction } from '../Action/UpgradeBuildingAction';
|
||||||
import { TaskController, registerTask } from './TaskController';
|
import { TaskController, registerTask, ActionDefinition } from './TaskController';
|
||||||
import { GoToPageAction } from '../Action/GoToPageAction';
|
import { GoToPageAction } from '../Action/GoToPageAction';
|
||||||
import { CheckBuildingRemainingTimeAction } from '../Action/CheckBuildingRemainingTimeAction';
|
|
||||||
import { CompleteTaskAction } from '../Action/CompleteTaskAction';
|
|
||||||
import { path } from '../utils';
|
import { path } from '../utils';
|
||||||
import { Action } from '../Queue/ActionQueue';
|
|
||||||
import { Args } from '../Queue/Args';
|
|
||||||
import { Task } from '../Queue/TaskProvider';
|
import { Task } from '../Queue/TaskProvider';
|
||||||
|
|
||||||
@registerTask
|
@registerTask
|
||||||
export class UpgradeBuildingTask extends TaskController {
|
export class UpgradeBuildingTask extends TaskController {
|
||||||
async run(task: Task) {
|
defineActions(task: Task): Array<ActionDefinition> {
|
||||||
const args: Args = { ...task.args, taskId: task.id };
|
const args = task.args;
|
||||||
this.scheduler.scheduleActions([
|
return [
|
||||||
new Action(GoToPageAction.name, {
|
[
|
||||||
...args,
|
GoToPageAction.name,
|
||||||
path: path('/dorf1.php', { newdid: args.villageId }),
|
{
|
||||||
}),
|
path: path('/dorf1.php', { newdid: args.villageId }),
|
||||||
new Action(CheckBuildingRemainingTimeAction.name, args),
|
},
|
||||||
new Action(GoToPageAction.name, {
|
],
|
||||||
...args,
|
[
|
||||||
path: path('/build.php', { newdid: args.villageId, id: args.buildId }),
|
GoToPageAction.name,
|
||||||
}),
|
{
|
||||||
new Action(UpgradeBuildingAction.name, args),
|
path: path('/build.php', { newdid: args.villageId, id: args.buildId }),
|
||||||
new Action(CompleteTaskAction.name, args),
|
},
|
||||||
]);
|
],
|
||||||
|
[UpgradeBuildingAction.name],
|
||||||
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user