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; } const cost = building.cost(building.level + 1); 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; }