Improve village state management

This commit is contained in:
2020-05-24 19:30:03 +03:00
parent 8bea617f5b
commit 301b1a6ca9
25 changed files with 328 additions and 275 deletions

View File

@ -20,7 +20,7 @@ export class BuildingContractGrabber extends Grabber {
const contract = grabContractResources();
this.controller.updateResources(contract, {
this.taskCollection.updateResources(contract, {
type: ContractType.UpgradeBuilding,
buildId: building.buildId,
});

View File

@ -20,7 +20,7 @@ export class ForgePageGrabber extends Grabber {
const contracts = grabImprovementContracts();
for (let { resources, unitId } of contracts) {
this.controller.updateResources(resources, {
this.taskCollection.updateResources(resources, {
type: ContractType.ImproveTrooper,
buildId,
unitId,
@ -29,8 +29,7 @@ export class ForgePageGrabber extends Grabber {
}
private grabTimer(): void {
const storage = this.controller.getStorage();
const seconds = grabRemainingSeconds();
storage.storeQueueTaskEnding(ProductionQueue.UpgradeUnit, seconds ? seconds + timestamp() : 0);
this.storage.storeQueueTaskEnding(ProductionQueue.UpgradeUnit, seconds ? seconds + timestamp() : 0);
}
}

View File

@ -1,10 +1,13 @@
import { VillageController } from '../VillageController';
import { VillageTaskCollection } from '../VillageTaskCollection';
import { VillageStorage } from '../Storage/VillageStorage';
export abstract class Grabber {
protected controller: VillageController;
protected taskCollection: VillageTaskCollection;
protected storage: VillageStorage;
constructor(controller: VillageController) {
this.controller = controller;
constructor(taskCollection: VillageTaskCollection, storage: VillageStorage) {
this.taskCollection = taskCollection;
this.storage = storage;
}
abstract grab(): void;

View File

@ -6,12 +6,12 @@ import { MarketPageGrabber } from './MarketPageGrabber';
import { BuildingContractGrabber } from './BuildingContractGrabber';
import { ForgePageGrabber } from './ForgePageGrabber';
import { GuildHallPageGrabber } from './GuildHallPageGrabber';
import { VillageControllerFactory } from '../VillageControllerFactory';
import { VillageFactory } from '../VillageFactory';
export class GrabberManager {
private factory: VillageControllerFactory;
private factory: VillageFactory;
constructor(factory: VillageControllerFactory) {
constructor(factory: VillageFactory) {
this.factory = factory;
}
@ -23,15 +23,16 @@ export class GrabberManager {
}
private createGrabbers(): Array<Grabber> {
const controller = this.factory.getActive();
const storage = this.factory.createStorageForActiveVillage();
const taskCollection = this.factory.createTaskCollectionForActiveVillage();
const grabbers: Array<Grabber> = [];
grabbers.push(new VillageResourceGrabber(controller));
grabbers.push(new VillageOverviewPageGrabber(controller));
grabbers.push(new HeroPageGrabber(controller));
grabbers.push(new MarketPageGrabber(controller));
grabbers.push(new BuildingContractGrabber(controller));
grabbers.push(new ForgePageGrabber(controller));
grabbers.push(new GuildHallPageGrabber(controller));
grabbers.push(new VillageResourceGrabber(taskCollection, storage));
grabbers.push(new VillageOverviewPageGrabber(taskCollection, storage));
grabbers.push(new HeroPageGrabber(taskCollection, storage));
grabbers.push(new MarketPageGrabber(taskCollection, storage));
grabbers.push(new BuildingContractGrabber(taskCollection, storage));
grabbers.push(new ForgePageGrabber(taskCollection, storage));
grabbers.push(new GuildHallPageGrabber(taskCollection, storage));
return grabbers;
}
}

View File

@ -11,7 +11,6 @@ export class GuildHallPageGrabber extends Grabber {
}
const seconds = grabRemainingSeconds();
const storage = this.controller.getStorage();
storage.storeQueueTaskEnding(ProductionQueue.Celebration, seconds ? seconds + timestamp() : 0);
this.storage.storeQueueTaskEnding(ProductionQueue.Celebration, seconds ? seconds + timestamp() : 0);
}
}

View File

@ -8,7 +8,6 @@ export class MarketPageGrabber extends Grabber {
return;
}
const storage = this.controller.getStorage();
storage.storeIncomingMerchants(grabIncomingMerchants());
this.storage.storeIncomingMerchants(grabIncomingMerchants());
}
}

View File

@ -12,13 +12,12 @@ export class VillageOverviewPageGrabber extends Grabber {
return;
}
const storage = this.controller.getStorage();
storage.storeResourcesPerformance(grabResourcesPerformance());
storage.storeBuildingQueueInfo(this.grabBuildingQueueInfoOrDefault());
this.storage.storeResourcesPerformance(grabResourcesPerformance());
this.storage.storeBuildingQueueInfo(this.grabBuildingQueueInfoOrDefault());
const buildingQueueInfo = this.grabBuildingQueueInfoOrDefault();
const buildingEndTime = buildingQueueInfo.seconds ? buildingQueueInfo.seconds + timestamp() : 0;
storage.storeQueueTaskEnding(ProductionQueue.Building, buildingEndTime);
this.storage.storeQueueTaskEnding(ProductionQueue.Building, buildingEndTime);
}
private grabBuildingQueueInfoOrDefault() {

View File

@ -3,8 +3,7 @@ import { grabVillageResources, grabVillageResourceStorage } from '../Page/Resour
export class VillageResourceGrabber extends Grabber {
grab(): void {
const storage = this.controller.getStorage();
storage.storeResources(grabVillageResources());
storage.storeResourceStorage(grabVillageResourceStorage());
this.storage.storeResources(grabVillageResources());
this.storage.storeResourceStorage(grabVillageResourceStorage());
}
}