Add basic functionality of raising mining rate

This commit is contained in:
Aelita4 2025-01-10 19:33:56 +01:00
parent 14f399659e
commit 8b5eef482f
Signed by: Aelita4
GPG Key ID: E44490C2025906C1
3 changed files with 18 additions and 2 deletions

View File

@ -65,7 +65,7 @@ export default class SystemResourceManager extends ResourceManager {
id: resource.id,
amount: resource.amount,
lastUpdated: null,
perHourMiningRate: null,
perHourMiningRate: 0,
data: resFromDB
})
});

View File

@ -4,7 +4,7 @@ export type Resource = {
id: string,
amount: number,
lastUpdated: Date | null,
perHourMiningRate: number | null,
perHourMiningRate: number,
data: DBResource
}

View File

@ -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();