Grab queue time for guild hall and forge
This commit is contained in:
parent
5611fe5713
commit
42feced06e
@ -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);
|
||||
}
|
||||
}
|
@ -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<Grabber> = [];
|
||||
@ -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() {
|
||||
|
20
src/Grabber/GuildHallPageGrabber.ts
Normal file
20
src/Grabber/GuildHallPageGrabber.ts
Normal file
@ -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);
|
||||
}
|
||||
}
|
@ -78,3 +78,8 @@ export function grabImprovementContracts(): Array<ImprovementContract> {
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
export function grabRemainingSeconds(): number {
|
||||
const $el = jQuery('.under_progress .timer');
|
||||
return getNumber($el.attr('value'));
|
||||
}
|
||||
|
@ -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'));
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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<ActionDefinition> {
|
||||
const actions: Array<ActionDefinition> = [];
|
||||
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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user