Improve unit training
This commit is contained in:
@ -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');
|
||||
}
|
||||
|
@ -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) {
|
||||
|
Reference in New Issue
Block a user