Improve unit training

This commit is contained in:
2020-05-09 20:44:07 +03:00
parent ea4deb6323
commit 0798e1dc3f
4 changed files with 72 additions and 68 deletions

View File

@ -30,3 +30,37 @@ export function createTrainTroopButtons(
});
});
}
function getTroopBlock(troopId: number): JQuery {
const $block = jQuery(`.innerTroopWrapper[data-troopid="${troopId}"]`);
if ($block.length !== 1) {
throw new GrabError(`Troop block not found`);
}
return $block;
}
export function getAvailableCount(troopId: number): number {
const $block = getTroopBlock(troopId);
const $countLink = $block.find('.cta a');
if ($countLink.length !== 1) {
throw new GrabError(`Link with max count not found`);
}
return getNumber($countLink.text());
}
export function fillTrainCount(troopId: number, trainCount: number): void {
const $block = getTroopBlock(troopId);
const input = $block.find(`input[name="t${troopId}"]`);
if (input.length !== 1) {
throw new GrabError(`Input element not found`);
}
input.val(trainCount);
}
export function clickTrainButton(): void {
const $trainButton = jQuery('.startTraining.green').first();
if ($trainButton.length !== 1) {
throw new GrabError('Train button not found');
}
$trainButton.trigger('click');
}

View File

@ -83,20 +83,18 @@ export class BuildingPageController {
notify(`Upgrading ${buildId} scheduled`);
}
private onScheduleTrainTroopers(troopId: number, resources: Resources, count: number) {
for (let chunk of split(count)) {
const args = {
villageId: grabActiveVillageId(),
buildId: this.attributes.buildId,
buildTypeId: this.attributes.buildTypeId,
sheetId: this.attributes.sheetId,
troopId,
resources: resources.scale(chunk),
trainCount: chunk,
};
this.scheduler.scheduleTask(TrainTroopTask.name, args);
}
notify(`Training ${count} troopers scheduled`);
private onScheduleTrainTroopers(troopId: number, resources: Resources, trainCount: number) {
const args = {
villageId: grabActiveVillageId(),
buildId: this.attributes.buildId,
buildTypeId: this.attributes.buildTypeId,
sheetId: this.attributes.sheetId,
troopId,
trainCount,
resources: resources.scale(trainCount),
};
this.scheduler.scheduleTask(TrainTroopTask.name, args);
notify(`Training ${trainCount} troopers scheduled`);
}
private onSendResources(resources: Resources, coordinates: Coordinates) {