From 8b5eef482f9f43dc2fe4c949092cc7dba7113c3e Mon Sep 17 00:00:00 2001 From: Aelita4 Date: Fri, 10 Jan 2025 19:33:56 +0100 Subject: [PATCH] Add basic functionality of raising mining rate --- .../classes/managers/SystemResourceManager.ts | 2 +- .../classes/managers/abstract/ResourceManager.ts | 2 +- src/pages/api/build/createBuilding.ts | 16 ++++++++++++++++ 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/lib/classes/managers/SystemResourceManager.ts b/src/lib/classes/managers/SystemResourceManager.ts index f6f738a..64e859d 100644 --- a/src/lib/classes/managers/SystemResourceManager.ts +++ b/src/lib/classes/managers/SystemResourceManager.ts @@ -65,7 +65,7 @@ export default class SystemResourceManager extends ResourceManager { id: resource.id, amount: resource.amount, lastUpdated: null, - perHourMiningRate: null, + perHourMiningRate: 0, data: resFromDB }) }); diff --git a/src/lib/classes/managers/abstract/ResourceManager.ts b/src/lib/classes/managers/abstract/ResourceManager.ts index 2e4829a..df5df74 100644 --- a/src/lib/classes/managers/abstract/ResourceManager.ts +++ b/src/lib/classes/managers/abstract/ResourceManager.ts @@ -4,7 +4,7 @@ export type Resource = { id: string, amount: number, lastUpdated: Date | null, - perHourMiningRate: number | null, + perHourMiningRate: number, data: DBResource } diff --git a/src/pages/api/build/createBuilding.ts b/src/pages/api/build/createBuilding.ts index 9c703f6..93ee57c 100644 --- a/src/pages/api/build/createBuilding.ts +++ b/src/pages/api/build/createBuilding.ts @@ -96,6 +96,22 @@ export const POST: APIRoute = async({ request }) => { userPlanet.resources.setAmount(resourcesAfter.map(res => { return { id: res.id, amount: res.amount } })); userPlanet.buildings.addBuilding(building); + if(building.data.category === "mines") { + switch(building.data.id) { + case 'coal-mine': + const coalResource = userPlanet.resources.resources.find(r => r.id === "coal"); + if(coalResource) coalResource.perHourMiningRate += 10; + break; + case 'iron-mine': + const ironResource = userPlanet.resources.resources.find(r => r.id === "iron"); + if(ironResource) ironResource.perHourMiningRate += 10; + break; + case 'gold-mine': + const goldResource = userPlanet.resources.resources.find(r => r.id === "gold"); + if(goldResource) goldResource.perHourMiningRate += 10; + break; + } + } await userPlanet.buildings.sync(); await userPlanet.resources.sync();