Fix insert build tasks, so order is matter
This commit is contained in:
@ -4,7 +4,7 @@ import { Scheduler } from '../Scheduler';
|
||||
import { TrainTroopTask } from '../Task/TrainTroopTask';
|
||||
import { grabActiveVillageId } from './VillageBlock';
|
||||
import { ConsoleLogger, Logger } from '../Logger';
|
||||
import { createBuildButton, createUpgradeButton } from './BuildingPage';
|
||||
import { createBuildButton, createUpgradeButton, grabContractResources } from './BuildingPage';
|
||||
import { BuildBuildingTask } from '../Task/BuildBuildingTask';
|
||||
|
||||
const QUARTERS_ID = 19;
|
||||
@ -38,14 +38,16 @@ export class BuildPage {
|
||||
const buildId = this.buildId;
|
||||
const categoryId = this.categoryId;
|
||||
const villageId = grabActiveVillageId();
|
||||
this.scheduler.scheduleTask(BuildBuildingTask.name, { villageId, buildId, categoryId, buildTypeId });
|
||||
const resources = grabContractResources();
|
||||
this.scheduler.scheduleTask(BuildBuildingTask.name, { villageId, buildId, categoryId, buildTypeId, resources });
|
||||
notify(`Building ${buildId} scheduled`);
|
||||
}
|
||||
|
||||
private onScheduleUpgradeBuilding() {
|
||||
const buildId = this.buildId;
|
||||
const villageId = grabActiveVillageId();
|
||||
this.scheduler.scheduleTask(UpgradeBuildingTask.name, { villageId, buildId });
|
||||
const resources = grabContractResources();
|
||||
this.scheduler.scheduleTask(UpgradeBuildingTask.name, { villageId, buildId, resources });
|
||||
notify(`Upgrading ${buildId} scheduled`);
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
import { GrabError } from '../Errors';
|
||||
import { getNumber, trimPrefix, uniqId } from '../utils';
|
||||
import { Resources } from '../Game';
|
||||
|
||||
export function clickBuildButton(typeId: number) {
|
||||
const section = jQuery(`#contract_building${typeId}`);
|
||||
@ -27,6 +28,11 @@ export function createBuildButton(onClickHandler: (buildTypeId: number) => void)
|
||||
});
|
||||
}
|
||||
|
||||
export function hasUpgradeButton(): boolean {
|
||||
const btn = jQuery('.upgradeButtonsContainer .section1 button.green.build');
|
||||
return btn.length === 1;
|
||||
}
|
||||
|
||||
export function clickUpgradeButton() {
|
||||
const btn = jQuery('.upgradeButtonsContainer .section1 button.green.build');
|
||||
if (btn.length !== 1) {
|
||||
@ -45,3 +51,17 @@ export function createUpgradeButton(onClickHandler: () => void) {
|
||||
onClickHandler();
|
||||
});
|
||||
}
|
||||
|
||||
export function grabContractResources(): Resources {
|
||||
const $els = jQuery('#contract .resource');
|
||||
if ($els.length === 0) {
|
||||
throw new GrabError('No resource contract element');
|
||||
}
|
||||
const grab = n =>
|
||||
getNumber(
|
||||
jQuery($els.get(n))
|
||||
.find('.value')
|
||||
.text()
|
||||
);
|
||||
return new Resources(grab(0), grab(1), grab(2), grab(3));
|
||||
}
|
||||
|
@ -47,7 +47,7 @@ function grabVillageInfo($el): Village {
|
||||
export function grabResourcesPerformance(): Resources {
|
||||
const $el = jQuery('#production');
|
||||
if ($el.length !== 1) {
|
||||
throw new GrabError();
|
||||
throw new GrabError('No production element');
|
||||
}
|
||||
|
||||
const $nums = $el.find('td.num');
|
||||
@ -63,7 +63,7 @@ export function grabResourcesPerformance(): Resources {
|
||||
export function grabBuildingQueueInfo(): BuildingQueueInfo {
|
||||
const timer = jQuery('.buildDuration .timer');
|
||||
if (timer.length !== 1) {
|
||||
throw new GrabError();
|
||||
throw new GrabError('No building queue timer element');
|
||||
}
|
||||
|
||||
const remainingSeconds = getNumber(timer.attr('value'));
|
||||
|
Reference in New Issue
Block a user