Add bin celebration handling
This commit is contained in:
parent
a0cd916528
commit
3278a1071d
@ -10,7 +10,7 @@ export class CelebrationAction extends ActionController {
|
||||
async run(args: Args, task: Task): Promise<any> {
|
||||
try {
|
||||
this.ensureSameVillage(args, task);
|
||||
clickCelebrationButton();
|
||||
clickCelebrationButton(args.celebrationIndex);
|
||||
} catch (e) {
|
||||
if (e instanceof GrabError) {
|
||||
throw new TryLaterError(aroundMinutes(60), e.message);
|
||||
|
@ -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(`<div style="padding: 8px 0">
|
||||
<a id="${id}" href="#">Праздновать</a>
|
||||
</div>`);
|
||||
|
@ -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`);
|
||||
}
|
||||
|
@ -21,4 +21,5 @@ export interface Args {
|
||||
level?: number;
|
||||
selector?: string;
|
||||
path?: string;
|
||||
celebrationIndex?: number;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user