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> {
|
async run(args: Args, task: Task): Promise<any> {
|
||||||
try {
|
try {
|
||||||
this.ensureSameVillage(args, task);
|
this.ensureSameVillage(args, task);
|
||||||
clickCelebrationButton();
|
clickCelebrationButton(args.celebrationIndex);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (e instanceof GrabError) {
|
if (e instanceof GrabError) {
|
||||||
throw new TryLaterError(aroundMinutes(60), e.message);
|
throw new TryLaterError(aroundMinutes(60), e.message);
|
||||||
|
@ -8,26 +8,30 @@ interface CelebrationClickHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function createCelebrationButtons(onClickHandler: CelebrationClickHandler) {
|
export function createCelebrationButtons(onClickHandler: CelebrationClickHandler) {
|
||||||
const $els = jQuery('.build_details.researches .research');
|
const $blocks = findBlocks();
|
||||||
if ($els.length === 0) {
|
if ($blocks.length === 0) {
|
||||||
throw new GrabError('No celebration research blocks');
|
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() {
|
export function clickCelebrationButton(celebrationIndex: number | undefined) {
|
||||||
const $els = jQuery('.build_details.researches .research');
|
const $blocks = findBlocks();
|
||||||
if ($els.length === 0) {
|
if ($blocks.length === 0) {
|
||||||
throw new GrabError('No celebration research blocks');
|
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');
|
const $btn = $first.find('.cta').find('button.green');
|
||||||
if ($btn.length !== 1) {
|
if ($btn.length !== 1) {
|
||||||
throw new GrabError('No celebration buttons');
|
throw new GrabError('No celebration button');
|
||||||
}
|
}
|
||||||
$btn.trigger('click');
|
$btn.trigger('click');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function findBlocks(): JQuery {
|
||||||
|
return jQuery('.build_details.researches .research');
|
||||||
|
}
|
||||||
|
|
||||||
function createCelebrationButton(
|
function createCelebrationButton(
|
||||||
$blockEl: JQuery,
|
$blockEl: JQuery,
|
||||||
idx: number,
|
idx: number,
|
||||||
@ -36,7 +40,6 @@ function createCelebrationButton(
|
|||||||
const resources = grabResources($blockEl);
|
const resources = grabResources($blockEl);
|
||||||
|
|
||||||
const id = uniqId();
|
const id = uniqId();
|
||||||
|
|
||||||
$blockEl.find('.information').append(`<div style="padding: 8px 0">
|
$blockEl.find('.information').append(`<div style="padding: 8px 0">
|
||||||
<a id="${id}" href="#">Праздновать</a>
|
<a id="${id}" href="#">Праздновать</a>
|
||||||
</div>`);
|
</div>`);
|
||||||
|
@ -84,7 +84,7 @@ export class BuildingPageController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (isGuildHallPage()) {
|
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`);
|
notify(`Researching ${unitId} scheduled`);
|
||||||
}
|
}
|
||||||
|
|
||||||
private onCelebration(resources: Resources) {
|
private onCelebration(resources: Resources, index: number) {
|
||||||
const villageId = grabActiveVillageId();
|
const villageId = grabActiveVillageId();
|
||||||
this.villageController.addTask(CelebrationTask.name, {
|
this.villageController.addTask(CelebrationTask.name, {
|
||||||
villageId,
|
villageId,
|
||||||
buildTypeId: this.attributes.buildTypeId,
|
buildTypeId: this.attributes.buildTypeId,
|
||||||
buildId: this.attributes.buildId,
|
buildId: this.attributes.buildId,
|
||||||
resources,
|
resources,
|
||||||
|
celebrationIndex: index,
|
||||||
});
|
});
|
||||||
notify(`Celebration scheduled`);
|
notify(`Celebration scheduled`);
|
||||||
}
|
}
|
||||||
|
@ -21,4 +21,5 @@ export interface Args {
|
|||||||
level?: number;
|
level?: number;
|
||||||
selector?: string;
|
selector?: string;
|
||||||
path?: string;
|
path?: string;
|
||||||
|
celebrationIndex?: number;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user