diff --git a/src/Action/CelebrationAction.ts b/src/Action/CelebrationAction.ts index b6030ac..dce3d56 100644 --- a/src/Action/CelebrationAction.ts +++ b/src/Action/CelebrationAction.ts @@ -10,7 +10,7 @@ export class CelebrationAction extends ActionController { async run(args: Args, task: Task): Promise { try { this.ensureSameVillage(args, task); - clickCelebrationButton(); + clickCelebrationButton(args.celebrationIndex); } catch (e) { if (e instanceof GrabError) { throw new TryLaterError(aroundMinutes(60), e.message); diff --git a/src/Page/BuildingPage/GuildHallPage.ts b/src/Page/BuildingPage/GuildHallPage.ts index d7ab7f1..51e4e9d 100644 --- a/src/Page/BuildingPage/GuildHallPage.ts +++ b/src/Page/BuildingPage/GuildHallPage.ts @@ -8,26 +8,30 @@ interface CelebrationClickHandler { } export function createCelebrationButtons(onClickHandler: CelebrationClickHandler) { - const $els = jQuery('.build_details.researches .research'); - if ($els.length === 0) { + const $blocks = findBlocks(); + if ($blocks.length === 0) { throw new GrabError('No celebration research blocks'); } - $els.each((idx, el) => createCelebrationButton(jQuery(el), idx, onClickHandler)); + $blocks.each((idx, el) => createCelebrationButton(jQuery(el), idx, onClickHandler)); } -export function clickCelebrationButton() { - const $els = jQuery('.build_details.researches .research'); - if ($els.length === 0) { +export function clickCelebrationButton(celebrationIndex: number | undefined) { + const $blocks = findBlocks(); + if ($blocks.length === 0) { throw new GrabError('No celebration research blocks'); } - const $first = jQuery($els.get(0)); + const $first = jQuery($blocks.get(celebrationIndex || 0)); const $btn = $first.find('.cta').find('button.green'); if ($btn.length !== 1) { - throw new GrabError('No celebration buttons'); + throw new GrabError('No celebration button'); } $btn.trigger('click'); } +function findBlocks(): JQuery { + return jQuery('.build_details.researches .research'); +} + function createCelebrationButton( $blockEl: JQuery, idx: number, @@ -36,7 +40,6 @@ function createCelebrationButton( const resources = grabResources($blockEl); const id = uniqId(); - $blockEl.find('.information').append(`
Праздновать
`); diff --git a/src/Page/BuildingPageController.ts b/src/Page/BuildingPageController.ts index 3e637d2..7f2a486 100644 --- a/src/Page/BuildingPageController.ts +++ b/src/Page/BuildingPageController.ts @@ -84,7 +84,7 @@ export class BuildingPageController { } if (isGuildHallPage()) { - createCelebrationButtons(res => this.onCelebration(res)); + createCelebrationButtons((res, index) => this.onCelebration(res, index)); } } @@ -150,13 +150,14 @@ export class BuildingPageController { notify(`Researching ${unitId} scheduled`); } - private onCelebration(resources: Resources) { + private onCelebration(resources: Resources, index: number) { const villageId = grabActiveVillageId(); this.villageController.addTask(CelebrationTask.name, { villageId, buildTypeId: this.attributes.buildTypeId, buildId: this.attributes.buildId, resources, + celebrationIndex: index, }); notify(`Celebration scheduled`); } diff --git a/src/Queue/Args.ts b/src/Queue/Args.ts index d9da128..ae40773 100644 --- a/src/Queue/Args.ts +++ b/src/Queue/Args.ts @@ -21,4 +21,5 @@ export interface Args { level?: number; selector?: string; path?: string; + celebrationIndex?: number; }