diff --git a/src/Core/ResourceStorage.ts b/src/Core/ResourceStorage.ts deleted file mode 100644 index 5c9bc4e..0000000 --- a/src/Core/ResourceStorage.ts +++ /dev/null @@ -1,9 +0,0 @@ -export class ResourceStorage { - readonly warehouse: number; - readonly granary: number; - - constructor(warehouse: number, granary: number) { - this.warehouse = warehouse; - this.granary = granary; - } -} diff --git a/src/Core/Resources.ts b/src/Core/Resources.ts index 3463e07..f070a56 100644 --- a/src/Core/Resources.ts +++ b/src/Core/Resources.ts @@ -1,5 +1,4 @@ import { ResourceList, ResourceMapping, ResourceType } from './ResourceType'; -import { ResourceStorage } from './ResourceStorage'; export interface ResourcesInterface { lumber: number; @@ -25,15 +24,6 @@ export class Resources implements ResourcesInterface { return new Resources(obj.lumber, obj.clay, obj.iron, obj.crop); } - static fromStorage(storage: ResourceStorage): Resources { - return new Resources( - storage.warehouse, - storage.warehouse, - storage.warehouse, - storage.granary - ); - } - static zero(): Resources { return new Resources(0, 0, 0, 0); } diff --git a/src/Grabber/VillageResourceGrabber.ts b/src/Grabber/VillageResourceGrabber.ts index 7f88ead..fd56503 100644 --- a/src/Grabber/VillageResourceGrabber.ts +++ b/src/Grabber/VillageResourceGrabber.ts @@ -1,9 +1,9 @@ import { Grabber } from './Grabber'; -import { grabVillageResources, grabVillageResourceStorage } from '../Page/ResourcesBlock'; +import { grabVillageResources, grabVillageWarehouseCapacity } from '../Page/ResourcesBlock'; export class VillageResourceGrabber extends Grabber { grab(): void { this.storage.storeResources(grabVillageResources()); - this.storage.storeResourceStorage(grabVillageResourceStorage()); + this.storage.storeWarehouseCapacity(grabVillageWarehouseCapacity()); } } diff --git a/src/Page/ResourcesBlock.ts b/src/Page/ResourcesBlock.ts index 7648208..a19dc64 100644 --- a/src/Page/ResourcesBlock.ts +++ b/src/Page/ResourcesBlock.ts @@ -1,7 +1,6 @@ import { GrabError } from '../Errors'; import { Resources } from '../Core/Resources'; import { ResourceType } from '../Core/ResourceType'; -import { ResourceStorage } from '../Core/ResourceStorage'; import { getNumber } from '../Helpers/Convert'; export function grabVillageResources(): Resources { @@ -9,14 +8,13 @@ export function grabVillageResources(): Resources { const clay = grabResource(ResourceType.Clay); const iron = grabResource(ResourceType.Iron); const crop = grabResource(ResourceType.Crop); - return new Resources(lumber, clay, iron, crop); } -export function grabVillageResourceStorage() { +export function grabVillageWarehouseCapacity(): Resources { const warehouse = grabCapacity('warehouse'); const granary = grabCapacity('granary'); - return new ResourceStorage(warehouse, granary); + return new Resources(warehouse, warehouse, warehouse, granary); } function findStockBarElement() { diff --git a/src/Storage/VillageStorage.ts b/src/Storage/VillageStorage.ts index 14e5b96..42caf18 100644 --- a/src/Storage/VillageStorage.ts +++ b/src/Storage/VillageStorage.ts @@ -1,6 +1,5 @@ import { DataStorage } from './DataStorage'; import { Resources, ResourcesInterface } from '../Core/Resources'; -import { ResourceStorage } from '../Core/ResourceStorage'; import { IncomingMerchant, MerchantsInfo } from '../Core/Market'; import { VillageSettings, VillageSettingsDefaults } from '../Core/Village'; import { ProductionQueue } from '../Core/ProductionQueue'; @@ -15,7 +14,7 @@ import { Task } from '../Queue/Task'; import { uniqTaskId } from '../Queue/TaskId'; const RESOURCES_KEY = 'resources'; -const CAPACITY_KEY = 'capacity'; +const WAREHOUSE_CAPACITY_KEY = 'warehouse_capacity'; const PERFORMANCE_KEY = 'performance'; const INCOMING_MERCHANTS_KEY = 'incoming_merchants'; const MERCHANTS_INFO_KEY = 'merchants_info'; @@ -35,7 +34,7 @@ export class VillageStorage { this.storage = new DataStorage(`village.${villageId}`); } - storeResources(resources: Resources) { + storeResources(resources: ResourcesInterface) { this.storage.set(RESOURCES_KEY, resources); } @@ -43,14 +42,12 @@ export class VillageStorage { return this.storage.getTyped(RESOURCES_KEY, ResourceOptions); } - storeResourceStorage(storage: ResourceStorage) { - this.storage.set(CAPACITY_KEY, storage); + storeWarehouseCapacity(warehouse: ResourcesInterface) { + this.storage.set(WAREHOUSE_CAPACITY_KEY, warehouse); } - getResourceStorage(): ResourceStorage { - let plain = this.storage.get(CAPACITY_KEY); - let res = new ResourceStorage(0, 0); - return Object.assign(res, plain) as ResourceStorage; + getWarehouseCapacity(): Resources { + return this.storage.getTyped(WAREHOUSE_CAPACITY_KEY, ResourceOptions); } storeResourcesPerformance(resources: Resources) { diff --git a/src/Village/VillageState.ts b/src/Village/VillageState.ts index 8d423f2..3da5780 100644 --- a/src/Village/VillageState.ts +++ b/src/Village/VillageState.ts @@ -123,24 +123,24 @@ function makeResourceState( }; } -function makeStorageState( +function makeWarehouseState( resources: Resources, - storage: Resources, + capacity: Resources, performance: Resources ): VillageWarehouseState { // @fixme Если у героя большая добыча ресурсов, а склад маленький, то значения получаются тож маленькими // @fixme с одной деревней это не прокатывает, и даже не построить склад - // const optimumFullness = storage.sub(performance.scale(3)); - // const criticalFullness = storage.sub(performance.scale(1)); - const optimumFullness = storage.scale(0.9); - const criticalFullness = storage.scale(0.98); + // const optimumFullness = capacity.sub(performance.scale(3)); + // const criticalFullness = capacity.sub(performance.scale(1)); + const optimumFullness = capacity.scale(0.9); + const criticalFullness = capacity.scale(0.98); return { resources, - capacity: storage, + capacity, performance, - balance: storage.sub(resources), + balance: capacity.sub(resources), timeToZero: timeToFastestResource(resources, Resources.zero(), performance), - timeToFull: timeToFastestResource(resources, storage, performance), + timeToFull: timeToFastestResource(resources, capacity, performance), optimumFullness: optimumFullness, criticalFullness: criticalFullness, isOverflowing: criticalFullness.anyLower(resources), @@ -281,9 +281,9 @@ function createVillageOwnState( ): VillageOwnState { const settings = storage.getSettings(); const resources = storage.getResources(); - const storageResources = Resources.fromStorage(storage.getResourceStorage()); + const capacity = storage.getWarehouseCapacity(); const performance = storage.getResourcesPerformance(); - const storageState = makeStorageState(resources, storageResources, performance); + const storageState = makeWarehouseState(resources, capacity, performance); const tasks = taskCollection .getTasks() .map((t) => makeTaskState(t, storageState.optimumFullness));