2024-10-21 15:35:32 +00:00
|
|
|
import type { VillageState } from "../village";
|
|
|
|
|
|
|
|
|
|
|
|
export default function upgradeBuilding(V: VillageState, buildingId: number) {
|
|
|
|
const building = V.buildings.find(b => b.id === buildingId);
|
|
|
|
if (!building) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2024-10-22 15:15:35 +00:00
|
|
|
const cost = building.cost(building.level + 1);
|
2024-10-21 15:35:32 +00:00
|
|
|
|
|
|
|
if (
|
|
|
|
cost.wood > V.resources.wood
|
|
|
|
|| cost.stone > V.resources.stone
|
|
|
|
|| cost.iron > V.resources.iron
|
|
|
|
|| cost.food > V.resources.food
|
|
|
|
) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
V.resources.wood -= cost.wood;
|
|
|
|
V.resources.stone -= cost.stone;
|
|
|
|
V.resources.iron -= cost.iron;
|
|
|
|
V.resources.food -= cost.food;
|
|
|
|
|
|
|
|
building.level++;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|