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 { grabActiveVillageId } from '../Page/VillageBlock';
|
||||||
import { getBuildingPageAttributes, isForgePage } from '../Page/PageDetectors';
|
import { getBuildingPageAttributes, isForgePage } from '../Page/PageDetectors';
|
||||||
import { ContractType } from '../Scheduler';
|
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 {
|
grab(): void {
|
||||||
if (!isForgePage()) {
|
if (!isForgePage()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const villageId = grabActiveVillageId();
|
const villageId = grabActiveVillageId();
|
||||||
|
|
||||||
|
this.grabContracts(villageId);
|
||||||
|
this.grabTimer(villageId);
|
||||||
|
}
|
||||||
|
|
||||||
|
private grabContracts(villageId: number): void {
|
||||||
const { buildId } = getBuildingPageAttributes();
|
const { buildId } = getBuildingPageAttributes();
|
||||||
const contracts = grabImprovementContracts();
|
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 { MarketPageGrabber } from './MarketPageGrabber';
|
||||||
import { Scheduler } from '../Scheduler';
|
import { Scheduler } from '../Scheduler';
|
||||||
import { BuildingContractGrabber } from './BuildingContractGrabber';
|
import { BuildingContractGrabber } from './BuildingContractGrabber';
|
||||||
import { ForgeContractGrabber } from './ForgeContractGrabber';
|
import { ForgePageGrabber } from './ForgePageGrabber';
|
||||||
|
import { GuildHallPageGrabber } from './GuildHallPageGrabber';
|
||||||
|
|
||||||
export class GrabberManager {
|
export class GrabberManager {
|
||||||
private readonly grabbers: Array<Grabber> = [];
|
private readonly grabbers: Array<Grabber> = [];
|
||||||
@ -17,7 +18,8 @@ export class GrabberManager {
|
|||||||
this.grabbers.push(new HeroPageGrabber(scheduler));
|
this.grabbers.push(new HeroPageGrabber(scheduler));
|
||||||
this.grabbers.push(new MarketPageGrabber(scheduler));
|
this.grabbers.push(new MarketPageGrabber(scheduler));
|
||||||
this.grabbers.push(new BuildingContractGrabber(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() {
|
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;
|
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 { Resources } from '../../Core/Resources';
|
||||||
import { grabResourcesFromList } from './BuildingPage';
|
import { grabResourcesFromList } from './BuildingPage';
|
||||||
import { GrabError } from '../../Errors';
|
import { GrabError } from '../../Errors';
|
||||||
@ -47,3 +47,8 @@ function grabResources($blockEl: JQuery) {
|
|||||||
const $resEls = $blockEl.find('.resourceWrapper .resource');
|
const $resEls = $blockEl.find('.resourceWrapper .resource');
|
||||||
return grabResourcesFromList($resEls);
|
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(UpdateResourceContracts.name, {}, timestamp());
|
||||||
// this.taskQueue.push(BalanceHeroResourcesTask.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(10 * 60, BalanceHeroResourcesTask.name);
|
||||||
this.createUniqTaskTimer(20 * 60, UpdateResourceContracts.name);
|
this.createUniqTaskTimer(20 * 60, UpdateResourceContracts.name);
|
||||||
this.createUniqTaskTimer(60 * 60, SendOnAdventureTask.name);
|
this.createUniqTaskTimer(60 * 60, SendOnAdventureTask.name);
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import { ActionDefinition } from './TaskController';
|
import { ActionDefinition } from './TaskController';
|
||||||
import { grabVillageList } from '../Page/VillageBlock';
|
import { grabVillageList } from '../Page/VillageBlock';
|
||||||
import { GoToPageAction } from '../Action/GoToPageAction';
|
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';
|
import { path } from '../Helpers/Path';
|
||||||
|
|
||||||
export function goToResourceViewPage(villageId: number): ActionDefinition {
|
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> {
|
export function scanAllVillagesBundle(): Array<ActionDefinition> {
|
||||||
const actions: Array<ActionDefinition> = [];
|
const actions: Array<ActionDefinition> = [];
|
||||||
const villages = grabVillageList();
|
const villages = grabVillageList();
|
||||||
for (let village of villages) {
|
for (let village of villages) {
|
||||||
actions.push(goToResourceViewPage(village.id));
|
actions.push(goToResourceViewPage(village.id));
|
||||||
actions.push(goToMarketSendResourcesPage(village.id));
|
actions.push(goToMarketSendResourcesPage(village.id));
|
||||||
|
actions.push(goToForgePage(village.id));
|
||||||
|
actions.push(goToGuildHallPage(village.id));
|
||||||
}
|
}
|
||||||
return actions;
|
return actions;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user