Celebrations automation
This commit is contained in:
49
src/Page/BuildingPage/GuildHallPage.ts
Normal file
49
src/Page/BuildingPage/GuildHallPage.ts
Normal file
@ -0,0 +1,49 @@
|
||||
import { elClassId, getNumber, uniqId } from '../../utils';
|
||||
import { Resources } from '../../Core/Resources';
|
||||
import { grabResourcesFromList } from './BuildingPage';
|
||||
import { GrabError } from '../../Errors';
|
||||
|
||||
interface CelebrationClickHandler {
|
||||
(resources: Resources, id: number): void;
|
||||
}
|
||||
|
||||
export function createCelebrationButtons(onClickHandler: CelebrationClickHandler) {
|
||||
const $els = jQuery('.build_details.researches .research');
|
||||
if ($els.length === 0) {
|
||||
throw new GrabError('No celebration research blocks');
|
||||
}
|
||||
$els.each((idx, el) => createCelebrationButton(jQuery(el), idx, onClickHandler));
|
||||
}
|
||||
|
||||
export function clickCelebrationButton() {
|
||||
const $els = jQuery('.build_details.researches .research');
|
||||
if ($els.length === 0) {
|
||||
throw new GrabError('No celebration research blocks');
|
||||
}
|
||||
const $first = jQuery($els.get(0));
|
||||
const $btn = $first.find('.cta').find('button.green');
|
||||
if ($btn.length !== 1) {
|
||||
throw new GrabError('No celebration buttons');
|
||||
}
|
||||
$btn.trigger('click');
|
||||
}
|
||||
|
||||
function createCelebrationButton($blockEl: JQuery, idx: number, onClickHandler: CelebrationClickHandler) {
|
||||
const resources = grabResources($blockEl);
|
||||
|
||||
const id = uniqId();
|
||||
|
||||
$blockEl.find('.information').append(`<div style="padding: 8px 0">
|
||||
<a id="${id}" href="#">Праздновать</a>
|
||||
</div>`);
|
||||
|
||||
jQuery(`#${id}`).on('click', evt => {
|
||||
evt.preventDefault();
|
||||
onClickHandler(resources, idx);
|
||||
});
|
||||
}
|
||||
|
||||
function grabResources($blockEl: JQuery) {
|
||||
const $resEls = $blockEl.find('.resourceWrapper .resource');
|
||||
return grabResourcesFromList($resEls);
|
||||
}
|
@ -10,11 +10,13 @@ import { Resources } from '../Core/Resources';
|
||||
import { Coordinates } from '../Core/Village';
|
||||
import { SendResourcesTask } from '../Task/SendResourcesTask';
|
||||
import { EMBASSY_ID, HORSE_STABLE_ID, QUARTERS_ID } from '../Core/Buildings';
|
||||
import { BuildingPageAttributes, isForgePage, isMarketSendResourcesPage } from './PageDetectors';
|
||||
import { BuildingPageAttributes, isForgePage, isGuildHallPage, isMarketSendResourcesPage } from './PageDetectors';
|
||||
import { createTrainTroopButtons } from './BuildingPage/TrooperPage';
|
||||
import { createSendResourcesButton } from './BuildingPage/MarketPage';
|
||||
import { createResearchButtons } from './BuildingPage/ForgePage';
|
||||
import { ForgeImprovementTask } from '../Task/ForgeImprovementTask';
|
||||
import { createCelebrationButtons } from './BuildingPage/GuildHallPage';
|
||||
import { CelebrationTask } from '../Task/CelebrationTask';
|
||||
|
||||
export class BuildingPageController {
|
||||
private scheduler: Scheduler;
|
||||
@ -56,6 +58,10 @@ export class BuildingPageController {
|
||||
if (isForgePage()) {
|
||||
createResearchButtons((res, unitId) => this.onResearch(res, unitId));
|
||||
}
|
||||
|
||||
if (isGuildHallPage()) {
|
||||
createCelebrationButtons((res, idx) => this.onCelebration(res, idx));
|
||||
}
|
||||
}
|
||||
|
||||
private onScheduleBuildBuilding(buildTypeId: number, resources: Resources) {
|
||||
@ -115,4 +121,15 @@ export class BuildingPageController {
|
||||
});
|
||||
notify(`Researching ${unitId} scheduled`);
|
||||
}
|
||||
|
||||
private onCelebration(resources: Resources, idx: number) {
|
||||
const villageId = grabActiveVillageId();
|
||||
this.scheduler.scheduleTask(CelebrationTask.name, {
|
||||
villageId,
|
||||
buildTypeId: this.attributes.buildTypeId,
|
||||
buildId: this.attributes.buildId,
|
||||
resources,
|
||||
});
|
||||
notify(`Celebration scheduled`);
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { elClassId, getNumber, parseLocation } from '../utils';
|
||||
import { FORGE_ID, MARKET_ID } from '../Core/Buildings';
|
||||
import { FORGE_ID, GUILD_HALL_ID, MARKET_ID } from '../Core/Buildings';
|
||||
|
||||
export interface BuildingPageAttributes {
|
||||
buildTypeId: number;
|
||||
@ -51,3 +51,11 @@ export function isForgePage(): boolean {
|
||||
const { buildTypeId } = getBuildingPageAttributes();
|
||||
return buildTypeId === FORGE_ID;
|
||||
}
|
||||
|
||||
export function isGuildHallPage(): boolean {
|
||||
if (!isBuildingPage()) {
|
||||
return false;
|
||||
}
|
||||
const { buildTypeId } = getBuildingPageAttributes();
|
||||
return buildTypeId === GUILD_HALL_ID;
|
||||
}
|
||||
|
Reference in New Issue
Block a user