diff --git a/src/Grabber/ForgeContractGrabber.ts b/src/Grabber/ForgePageGrabber.ts similarity index 51% rename from src/Grabber/ForgeContractGrabber.ts rename to src/Grabber/ForgePageGrabber.ts index 9a786ce..c2c3895 100644 --- a/src/Grabber/ForgeContractGrabber.ts +++ b/src/Grabber/ForgePageGrabber.ts @@ -2,15 +2,24 @@ import { Grabber } from './Grabber'; import { grabActiveVillageId } from '../Page/VillageBlock'; import { getBuildingPageAttributes, isForgePage } from '../Page/PageDetectors'; import { ContractType } from '../Scheduler'; -import { grabImprovementContracts } from '../Page/BuildingPage/ForgePage'; +import { grabImprovementContracts, grabRemainingSeconds } from '../Page/BuildingPage/ForgePage'; +import { VillageStorage } from '../Storage/VillageStorage'; +import { ProductionQueue } from '../Core/ProductionQueue'; +import { timestamp } from '../utils'; -export class ForgeContractGrabber extends Grabber { +export class ForgePageGrabber extends Grabber { grab(): void { if (!isForgePage()) { return; } const villageId = grabActiveVillageId(); + + this.grabContracts(villageId); + this.grabTimer(villageId); + } + + private grabContracts(villageId: number): void { const { buildId } = getBuildingPageAttributes(); const contracts = grabImprovementContracts(); @@ -23,4 +32,10 @@ export class ForgeContractGrabber extends Grabber { }); } } + + private grabTimer(villageId: number): void { + const state = new VillageStorage(villageId); + const seconds = grabRemainingSeconds(); + state.storeQueueTaskEnding(ProductionQueue.UpgradeUnit, seconds ? seconds + timestamp() : 0); + } } diff --git a/src/Grabber/GrabberManager.ts b/src/Grabber/GrabberManager.ts index 9a00a34..b91761d 100644 --- a/src/Grabber/GrabberManager.ts +++ b/src/Grabber/GrabberManager.ts @@ -5,7 +5,8 @@ import { HeroPageGrabber } from './HeroPageGrabber'; import { MarketPageGrabber } from './MarketPageGrabber'; import { Scheduler } from '../Scheduler'; import { BuildingContractGrabber } from './BuildingContractGrabber'; -import { ForgeContractGrabber } from './ForgeContractGrabber'; +import { ForgePageGrabber } from './ForgePageGrabber'; +import { GuildHallPageGrabber } from './GuildHallPageGrabber'; export class GrabberManager { private readonly grabbers: Array = []; @@ -17,7 +18,8 @@ export class GrabberManager { this.grabbers.push(new HeroPageGrabber(scheduler)); this.grabbers.push(new MarketPageGrabber(scheduler)); this.grabbers.push(new BuildingContractGrabber(scheduler)); - this.grabbers.push(new ForgeContractGrabber(scheduler)); + this.grabbers.push(new ForgePageGrabber(scheduler)); + this.grabbers.push(new GuildHallPageGrabber(scheduler)); } grab() { diff --git a/src/Grabber/GuildHallPageGrabber.ts b/src/Grabber/GuildHallPageGrabber.ts new file mode 100644 index 0000000..740f53d --- /dev/null +++ b/src/Grabber/GuildHallPageGrabber.ts @@ -0,0 +1,20 @@ +import { Grabber } from './Grabber'; +import { grabActiveVillageId } from '../Page/VillageBlock'; +import { VillageStorage } from '../Storage/VillageStorage'; +import { isGuildHallPage } from '../Page/PageDetectors'; +import { grabRemainingSeconds } from '../Page/BuildingPage/GuildHallPage'; +import { ProductionQueue } from '../Core/ProductionQueue'; +import { timestamp } from '../utils'; + +export class GuildHallPageGrabber extends Grabber { + grab(): void { + if (!isGuildHallPage()) { + return; + } + + const villageId = grabActiveVillageId(); + const state = new VillageStorage(villageId); + const seconds = grabRemainingSeconds(); + state.storeQueueTaskEnding(ProductionQueue.Celebration, seconds ? seconds + timestamp() : 0); + } +} diff --git a/src/Page/BuildingPage/ForgePage.ts b/src/Page/BuildingPage/ForgePage.ts index 015d661..604b804 100644 --- a/src/Page/BuildingPage/ForgePage.ts +++ b/src/Page/BuildingPage/ForgePage.ts @@ -78,3 +78,8 @@ export function grabImprovementContracts(): Array { }); return result; } + +export function grabRemainingSeconds(): number { + const $el = jQuery('.under_progress .timer'); + return getNumber($el.attr('value')); +} diff --git a/src/Page/BuildingPage/GuildHallPage.ts b/src/Page/BuildingPage/GuildHallPage.ts index a644cea..30e54f8 100644 --- a/src/Page/BuildingPage/GuildHallPage.ts +++ b/src/Page/BuildingPage/GuildHallPage.ts @@ -1,4 +1,4 @@ -import { elClassId, getNumber, uniqId } from '../../utils'; +import { getNumber, uniqId } from '../../utils'; import { Resources } from '../../Core/Resources'; import { grabResourcesFromList } from './BuildingPage'; import { GrabError } from '../../Errors'; @@ -47,3 +47,8 @@ function grabResources($blockEl: JQuery) { const $resEls = $blockEl.find('.resourceWrapper .resource'); return grabResourcesFromList($resEls); } + +export function grabRemainingSeconds(): number { + const $el = jQuery('.under_progress .timer'); + return getNumber($el.attr('value')); +} diff --git a/src/Scheduler.ts b/src/Scheduler.ts index 97dafda..4192057 100644 --- a/src/Scheduler.ts +++ b/src/Scheduler.ts @@ -50,7 +50,7 @@ export class Scheduler { // this.taskQueue.push(UpdateResourceContracts.name, {}, timestamp()); // this.taskQueue.push(BalanceHeroResourcesTask.name, {}, timestamp()); - this.createUniqTaskTimer(2 * 60, GrabVillageState.name); + this.createUniqTaskTimer(5 * 60, GrabVillageState.name); this.createUniqTaskTimer(10 * 60, BalanceHeroResourcesTask.name); this.createUniqTaskTimer(20 * 60, UpdateResourceContracts.name); this.createUniqTaskTimer(60 * 60, SendOnAdventureTask.name); diff --git a/src/Task/ActionBundles.ts b/src/Task/ActionBundles.ts index ed83203..bc34103 100644 --- a/src/Task/ActionBundles.ts +++ b/src/Task/ActionBundles.ts @@ -1,7 +1,7 @@ import { ActionDefinition } from './TaskController'; import { grabVillageList } from '../Page/VillageBlock'; import { GoToPageAction } from '../Action/GoToPageAction'; -import { MARKET_ID } from '../Core/Buildings'; +import { FORGE_ID, GUILD_HALL_ID, MARKET_ID } from '../Core/Buildings'; import { path } from '../Helpers/Path'; export function goToResourceViewPage(villageId: number): ActionDefinition { @@ -22,12 +22,32 @@ export function goToMarketSendResourcesPage(villageId: number): ActionDefinition ]; } +export function goToForgePage(villageId: number): ActionDefinition { + return [ + GoToPageAction.name, + { + path: path('/build.php', { newdid: villageId, gid: FORGE_ID }), + }, + ]; +} + +export function goToGuildHallPage(villageId: number): ActionDefinition { + return [ + GoToPageAction.name, + { + path: path('/build.php', { newdid: villageId, gid: GUILD_HALL_ID }), + }, + ]; +} + export function scanAllVillagesBundle(): Array { const actions: Array = []; const villages = grabVillageList(); for (let village of villages) { actions.push(goToResourceViewPage(village.id)); actions.push(goToMarketSendResourcesPage(village.id)); + actions.push(goToForgePage(village.id)); + actions.push(goToGuildHallPage(village.id)); } return actions; }