Fix bug with inconsistent building costs
This commit is contained in:
parent
a2b7ae1f94
commit
393bcb1960
|
@ -65,7 +65,7 @@ export default abstract class ResourceManager {
|
||||||
await this.calculateCurrentAvailableResources();
|
await this.calculateCurrentAvailableResources();
|
||||||
for(const res of resources) {
|
for(const res of resources) {
|
||||||
const resource = this.resources.find(r => r.id === res.id);
|
const resource = this.resources.find(r => r.id === res.id);
|
||||||
if(resource) resource.amount = res.amount;
|
if(resource) resource.amount += res.amount;
|
||||||
else this.resources.push({
|
else this.resources.push({
|
||||||
id: res.id,
|
id: res.id,
|
||||||
amount: res.amount,
|
amount: res.amount,
|
||||||
|
|
|
@ -60,7 +60,7 @@ export const POST: APIRoute = async({ request }) => {
|
||||||
const building = new Building(userPlanet.buildings, buildingObj, 1);
|
const building = new Building(userPlanet.buildings, buildingObj, 1);
|
||||||
|
|
||||||
const requirements = await building.checkRequirements();
|
const requirements = await building.checkRequirements();
|
||||||
const resources = await building.checkRequiredResources((userPlanet.buildings.getBuildingById(buildingId)?.level ?? 0) + 1);
|
const resources = await building.checkRequiredResources((userPlanet.buildings.getBuildingById(buildingId)?.level ?? 0));
|
||||||
|
|
||||||
if(!requirements.canBuild || !resources) {
|
if(!requirements.canBuild || !resources) {
|
||||||
return new Response(
|
return new Response(
|
||||||
|
@ -75,7 +75,7 @@ export const POST: APIRoute = async({ request }) => {
|
||||||
const resourcesDiff = await userPlanet.resources.getDifference(building.data.requirements.resources.map(res => {
|
const resourcesDiff = await userPlanet.resources.getDifference(building.data.requirements.resources.map(res => {
|
||||||
return {
|
return {
|
||||||
id: res.id,
|
id: res.id,
|
||||||
amount: Math.pow(building.data.multiplier, (userPlanet.buildings.getBuildingById(buildingId)?.level ?? 0) + 1) * res.amount
|
amount: Math.pow(building.data.multiplier, (userPlanet.buildings.getBuildingById(buildingId)?.level ?? 0)) * res.amount
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
@ -94,7 +94,7 @@ export const POST: APIRoute = async({ request }) => {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
userPlanet.resources.updateAmount(resourcesAfter.map(res => { return { id: res.id, amount: res.amount } }));
|
userPlanet.resources.setAmount(resourcesAfter.map(res => { return { id: res.id, amount: res.amount } }));
|
||||||
userPlanet.buildings.addBuilding(building);
|
userPlanet.buildings.addBuilding(building);
|
||||||
|
|
||||||
await userPlanet.buildings.sync();
|
await userPlanet.buildings.sync();
|
||||||
|
|
Loading…
Reference in New Issue